:root {
  --bg-top: #d8e6f4;
  --bg-mid: #b8cce3;
  --bg-bottom: #7a96b8;
  --card: #f4f0e8;
  --ink: #2c3340;
  --ink-soft: #4a5568;
  --muted: #8a94a3;
  --line: rgba(255, 255, 255, 0.35);
  --seg-bg: rgba(255, 255, 255, 0.55);
  --seg-on: #c5daf0;
  --seg-on-ink: #355a7a;
  --summary-1: #3a5a70;
  --summary-2: #243849;
  --accent-ink: #3d5f7a;
  --remain: #a0522d;
  --remain-gold: #e8c48a;
  --ring-track: #5a6578;
  --ring-fill: #d4a84b;
  --ring-center: #f4f0e8;
  --danger: #c0392b;
  --radius: 18px;
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --shadow: 0 4px 14px rgba(40, 60, 90, 0.12), 0 1px 3px rgba(40, 60, 90, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(
      165deg,
      var(--bg-top) 0%,
      var(--bg-mid) 42%,
      var(--bg-bottom) 100%
    );
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 14px 14px 88px;
}

/* ----- top ----- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.seg {
  display: inline-flex;
  background: var(--seg-bg);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  backdrop-filter: blur(8px);
  box-shadow: 0 1px 4px rgba(40, 60, 90, 0.08);
}

.seg button {
  border: none;
  background: transparent;
  color: #5c6b7c;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.seg button.on {
  background: var(--seg-on);
  color: var(--seg-on-ink);
  box-shadow: 0 1px 2px rgba(44, 74, 110, 0.1);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name {
  font-size: 0.82rem;
  color: #4a6075;
  font-weight: 500;
}

.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--accent-ink);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
  font-family: inherit;
}

.add-btn .plus {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  line-height: 1;
  font-weight: 500;
  color: var(--accent-ink);
}

.icon-btn, .text-btn {
  border: none;
  background: transparent;
  color: var(--accent-ink);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
  font-family: inherit;
}

.summary-manage {
  color: rgba(255, 255, 255, 0.75) !important;
  padding: 0 !important;
  font-size: 0.84rem !important;
  font-weight: 500 !important;
}

.site-back,
.back-link {
  display: inline-block;
  color: #3d5570;
  font-size: 0.88rem;
  font-weight: 600;
}

.site-back {
  margin-bottom: 10px;
}

.back-link { margin-bottom: 0; }

.nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 10px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #243246;
}

.page-sub {
  margin: 0 0 14px;
  color: #4a6075;
  font-size: 0.8rem;
}

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 2px 10px;
  color: #3d5570;
  font-size: 0.88rem;
  font-weight: 600;
}

/* ----- summary ----- */
.summary {
  background: linear-gradient(150deg, var(--summary-1) 0%, var(--summary-2) 100%);
  color: #fff;
  border-radius: 16px;
  padding: 18px 16px 16px;
  margin-bottom: 16px;
  box-shadow: 0 10px 28px rgba(30, 50, 70, 0.28);
}

.summary-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.95);
}

.summary-top .link {
  font-size: 0.84rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
}

.summary-grid {
  display: grid;
  grid-template-columns: 0.7fr 1.15fr 1.15fr;
  gap: 8px;
  text-align: left;
}

.summary-grid .lab {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 6px;
}

.summary-grid .num {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: rgba(255, 255, 255, 0.92);
}

.summary-grid .num.remain {
  color: var(--remain-gold);
}

/* ----- cards ----- */
.goal-card, .task-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.goal-card:active, .task-card:active {
  transform: scale(0.985);
}

.task-card.drag-ready {
  transform: scale(1.02);
  box-shadow: 0 10px 28px rgba(30, 55, 80, 0.18);
}

.task-card.dragging {
  transform: scale(1.03) rotate(0.6deg);
  box-shadow: 0 16px 36px rgba(30, 55, 80, 0.22);
  cursor: grabbing;
  touch-action: none;
  opacity: 0.96;
}

.task-card-placeholder {
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1.5px dashed rgba(61, 95, 122, 0.28);
  background: rgba(255, 255, 255, 0.35);
  box-sizing: border-box;
}

body.is-dragging-goal {
  overflow: hidden;
  touch-action: none;
  cursor: grabbing;
}

body.is-dragging-goal .task-card:active {
  transform: none;
}

.card-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.card-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 2px;
}

.card-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.card-tag {
  display: inline-block;
  margin-top: 5px;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.35;
}

.recur-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: #3d5f7a;
  background: rgba(61, 95, 122, 0.12);
  border-radius: 999px;
  padding: 2px 8px;
  line-height: 1.3;
  white-space: nowrap;
}

.recur-badge.off {
  color: #9ca3af;
  background: rgba(156, 163, 175, 0.18);
}

.ring-wrap {
  position: relative;
  width: 54px;
  height: 54px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.ring {
  --p: 0;
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--ring-fill) calc(var(--p) * 1%), var(--ring-track) 0);
}

.ring::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--ring-center);
}

.ring-wrap .pct {
  position: relative;
  z-index: 1;
  font-size: 0.72rem;
  font-weight: 800;
  color: #5c6778;
}

.card-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.01em;
  line-height: 1.4;
}

.card-hero {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--remain);
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin: 2px 0 0;
}

.card-hero small {
  font-size: 0.85rem;
  font-weight: 700;
  margin-right: 4px;
  color: #b86a42;
}

.card-foot {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.45;
}

.card-foot-money {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
}

.summary-note {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
}

.empty {
  text-align: center;
  padding: 48px 16px;
  color: #3d5570;
  font-size: 0.95rem;
  line-height: 1.6;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* ----- modal ----- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 35, 50, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 12px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .15s ease;
}

.modal-mask.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal {
  width: min(420px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: #fff;
  border-radius: 20px 20px 16px 16px;
  padding: 20px 16px 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
  color: var(--ink);
}

.modal h3 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--ink);
}

label {
  display: block;
  font-size: 0.78rem;
  color: #6b7280;
  margin: 10px 0 4px;
}

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font: inherit;
  background: #fafafa;
  color: var(--ink);
}

textarea { min-height: 68px; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

button.primary, .btn.primary {
  appearance: none;
  border: none;
  background: var(--summary-2);
  color: #fff;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

button.ghost,
.btn-secondary {
  appearance: none;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

button.danger {
  appearance: none;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.sheet-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: -6px 0 8px;
}

.sheet-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid #eef0f3;
  background: #fff;
  padding: 14px 4px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
}

.sheet-item:last-child { border-bottom: none; }
.sheet-item.danger { color: var(--danger); }
.sheet-item .sub {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ----- detail panels / chart / ledger ----- */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.55);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
}

.panel-meta {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--muted);
}

.chart-wrap {
  margin: 0 -4px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-grid {
  stroke: rgba(90, 110, 130, 0.18);
  stroke-width: 1;
}

.chart-line {
  stroke: #3a5a70;
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-dot {
  fill: #d4a84b;
  stroke: #3a5a70;
  stroke-width: 1;
}

.chart-axis {
  fill: #8a94a3;
  font-size: 9px;
}

.chart-empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.action-row {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.action-row button {
  width: 100%;
  min-height: 44px;
  position: relative;
  z-index: 6;
  pointer-events: auto;
  touch-action: manipulation;
}

.chart-wrap,
.chart-svg {
  pointer-events: none;
}

.dir-seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 4px;
}

.dir-btn {
  appearance: none;
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  font-family: inherit;
}

.dir-btn.on[data-dir="in"] {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #047857;
}

.dir-btn.on[data-dir="out"] {
  background: #fff7ed;
  border-color: #fdba74;
  color: #c2410c;
}

.ledger-list {
  max-height: 360px;
  overflow: auto;
}

.ledger-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid rgba(90, 110, 130, 0.1);
}

.ledger-row:last-child { border-bottom: none; }

.ledger-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.ledger-date {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.ledger-amt {
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
}

.ledger-amt.in { color: #0f766e; }
.ledger-amt.out { color: var(--remain); }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}
