:root {
  --bg: #F5F1E8;
  --card: #FFFFFF;
  --ink: #1E2A3A;
  --muted: #7C8594;
  --line: #E8E2D5;
  --primary: #23466B;
  --primary-soft: #E3EAF2;
  --pending: #C9862B;
  --pending-soft: #FBF0DC;
  --pending-ink: #8A5A14;
  --done: #2F7D5B;
  --done-soft: #E2F1EA;
  --danger: #B4483C;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { background: #DDD7CA; }
body {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  display: flex; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.phone {
  width: 100%; max-width: 440px; min-height: 100dvh;
  background: var(--bg); position: relative;
}
main { padding: calc(20px + env(safe-area-inset-top)) 18px calc(100px + env(safe-area-inset-bottom)); }

/* 頁首 */
.head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; }
.head .sub { font-size: 13px; color: var(--muted); }
.head h1 { font-size: 24px; font-weight: 700; margin-top: 2px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0; overflow: hidden;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.back { font-size: 14px; color: var(--primary); display: inline-block; margin-bottom: 12px; }

/* 日期列 */
.days { display: flex; gap: 6px; margin-bottom: 16px; }
.days button {
  flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 6px 0; font-size: 11px; color: var(--muted); line-height: 1.3;
}
.days button b { display: block; font-size: 15px; color: var(--ink); }
.days button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.days button.on b { color: #fff; }

/* 目標卡片 */
.goals { display: flex; gap: 12px; overflow-x: auto; margin: 0 -18px; padding: 0 18px 4px; scroll-snap-type: x mandatory; }
.goals::-webkit-scrollbar { display: none; }
.goal {
  display: block; flex: 0 0 88%; scroll-snap-align: center;
  background: var(--primary); color: #fff;
  border-radius: 22px; padding: 18px 18px 16px;
}
.goals .goal:only-child { flex-basis: 100%; }
.goal.alt { background: #5A4A6B; }
.goal.closed { background: #8A8F98; }
.goal.block { margin-bottom: 12px; }
.goal .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal .name { font-size: 14px; opacity: .88; }
.tag { font-size: 11px; background: rgba(255,255,255,.18); padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.goal .amount { font-size: 32px; font-weight: 700; margin-top: 8px; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.goal .amount small { font-size: 14px; font-weight: 400; opacity: .7; margin-left: 6px; }
.bar { height: 8px; background: rgba(255,255,255,.2); border-radius: 99px; margin-top: 12px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #fff; border-radius: 99px; transition: width .4s; }
.goal .foot { font-size: 12px; opacity: .82; margin-top: 10px; }

/* 待存入提醒 */
.pending {
  margin-top: 14px; background: var(--pending-soft);
  border-radius: 16px; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.pending .label { font-size: 12px; color: var(--pending); }
.pending .sum { font-size: 18px; font-weight: 700; color: var(--pending-ink); font-variant-numeric: tabular-nums; }

/* 按鈕 */
.btn {
  border: 0; background: var(--primary); color: #fff;
  font-size: 14px; font-weight: 600; padding: 11px 18px; border-radius: 99px;
}
.btn.amber { background: var(--pending); font-size: 13px; padding: 9px 14px; white-space: nowrap; }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn.wide { width: 100%; padding: 14px; font-size: 15px; }
.btn.line { background: #06C755; }
.btn:disabled { opacity: .45; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1; }
.link { border: 0; background: none; color: var(--primary); font-size: 13px; padding: 4px 0; }
.link.danger { color: var(--danger); }

/* 區塊標題 */
.section { display: flex; justify-content: space-between; align-items: baseline; margin: 24px 2px 10px; }
.section h2 { font-size: 17px; }
.section h2 span { color: var(--muted); font-weight: 400; font-size: 14px; }

/* 任務列 */
.task {
  background: var(--card); border-radius: 18px; padding: 14px;
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
  border: 1px solid var(--line);
  transition: background .2s, border-color .2s;
}
.task .icon {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  background: var(--primary-soft); display: grid; place-items: center; font-size: 20px;
}
.task .body { flex: 1; min-width: 0; display: block; }
.task .title { font-size: 15px; font-weight: 600; }
.task .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dots { display: flex; gap: 5px; margin-top: 8px; }
.dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--done); }
.dots span.today { outline: 2px solid var(--primary); outline-offset: 1px; }
.task .side { text-align: center; flex: none; }
.task .money { font-size: 13px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.check {
  margin-top: 6px; width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid var(--primary); background: transparent; color: var(--primary);
  font-size: 20px; display: grid; place-items: center; transition: all .2s;
}
.task .times { font-size: 11px; color: var(--muted); margin-top: 3px; }
.task.done { background: var(--done-soft); border-color: transparent; }
.task.done .check { background: var(--done); border-color: var(--done); color: #fff; }
.task.done .money { color: var(--done); }
.task.done .icon { background: #fff; }
.task.off { opacity: .55; }

/* 空狀態 */
.empty {
  background: var(--card); border: 1px dashed var(--line); border-radius: 18px;
  padding: 28px 20px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7;
}
.empty .btn { margin-top: 14px; }

/* 目標明細 */
.ring-wrap { display: grid; place-items: center; margin: 6px 0 4px; position: relative; }
.ring-wrap svg { width: 190px; height: 190px; transform: rotate(-90deg); }
.ring-wrap circle { fill: none; stroke-width: 14; stroke-linecap: round; }
.ring-wrap .track { stroke: var(--line); }
.ring-wrap .fill { stroke: var(--primary); transition: stroke-dashoffset .5s; }
.ring-center { position: absolute; text-align: center; }
.ring-center .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring-center .small { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stats { display: flex; gap: 10px; margin-top: 14px; }
.stat { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }
.stat.amber b { color: var(--pending-ink); }
.note { font-size: 13px; color: var(--muted); text-align: center; margin-top: 12px; line-height: 1.6; }
.pill { display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); }
.pill.good { background: var(--done-soft); color: var(--done); }
.pill.warn { background: var(--pending-soft); color: var(--pending-ink); }

/* 存入明細 */
.ledger { background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.ledger .day { font-size: 12px; color: var(--muted); padding: 10px 14px 4px; background: var(--bg); }
.entry { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; }
.entry .what { flex: 1; min-width: 0; }
.entry .what div { font-size: 14px; font-weight: 600; }
.entry .what small { font-size: 12px; color: var(--muted); }
.entry .amt { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.entry .amt small { display: block; font-size: 11px; font-weight: 400; }
.entry .amt.p { color: var(--pending-ink); }
.entry .amt.d { color: var(--done); }
.entry input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--pending); }

/* 月曆 */
.cal { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }
.cal-head button { border: 0; background: var(--primary-soft); color: var(--primary); width: 32px; height: 32px; border-radius: 50%; font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid .w { font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal-grid .d { aspect-ratio: 1; display: grid; place-items: center; font-size: 13px; border-radius: 50%; color: var(--ink); }
.cal-grid .d.on { background: var(--done); color: #fff; font-weight: 700; }
.cal-grid .d.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-grid .d.future { color: #C6C2B8; }

/* 底部導覽 */
nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 440px;
  background: rgba(255,255,255,.94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex; padding: 10px 0 calc(14px + env(safe-area-inset-bottom));
}
nav a { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
nav a b { display: block; font-size: 20px; font-weight: 400; margin-bottom: 2px; }
nav a.active { color: var(--primary); font-weight: 600; }

/* 底部表單 */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(30,42,58,.45); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 440px; max-height: 88dvh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}
.sheet h3 { font-size: 18px; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field input[type=date] {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px; font-size: 16px;
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { margin: 0; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-block; padding: 8px 13px; border-radius: 99px; font-size: 14px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
}
.chips.icons span { padding: 7px 10px; font-size: 20px; }
.chips input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 登入 */
.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 14px; }
.login img { width: 96px; height: 96px; border-radius: 24px; margin: 0 auto 6px; }
.login h1 { font-size: 30px; }
.login p { color: var(--muted); font-size: 15px; line-height: 1.7; margin-bottom: 14px; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 14px; padding: 11px 18px; border-radius: 99px;
  z-index: 30; width: max-content; max-width: 88%; text-align: center;
}
