:root {
  --bg: #f3f6f3; --card: #ffffff; --ink: #14201a; --muted: #5a6a61; --line: #e1e8e3;
  --accent: #258a3d; --accent-ink: #ffffff; --accent-soft: #e4f4e8;
  --warn: #9a5b00; --warn-soft: #fff1d6; --bad: #b3261e; --bad-soft: #fde7e5;
  --info: #1d5fa8; --info-soft: #e3effb; --track: #e3e9e5;
  --banner-bg: #14201a; --banner-ink: #ffe27a;
  --shadow: 0 1px 2px rgba(20,32,26,.06), 0 2px 8px rgba(20,32,26,.05);
  --banner-h: 30px; --header-h: 56px; --tab-h: 64px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="dark"] {
  --bg: #0e1511; --card: #18221c; --ink: #ecf3ee; --muted: #9fb0a5; --line: #26332b;
  --accent: #4cc26a; --accent-ink: #08210f; --accent-soft: #1c3a26;
  --warn: #f2b84b; --warn-soft: #3a2d10; --bad: #ff8a80; --bad-soft: #3d1b19;
  --info: #7fb6ee; --info-soft: #172b40; --track: #2a3830;
  --banner-bg: #ffe27a; --banner-ink: #1a1500; --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1511; --card: #18221c; --ink: #ecf3ee; --muted: #9fb0a5; --line: #26332b;
    --accent: #4cc26a; --accent-ink: #08210f; --accent-soft: #1c3a26;
    --warn: #f2b84b; --warn-soft: #3a2d10; --bad: #ff8a80; --bad-soft: #3d1b19;
    --info: #7fb6ee; --info-soft: #172b40; --track: #2a3830;
    --banner-bg: #ffe27a; --banner-ink: #1a1500; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-top: calc(var(--sat) + var(--banner-h));
  padding-bottom: calc(var(--tab-h) + var(--sab) + 16px);
  -webkit-font-smoothing: antialiased;
}
svg { width: 24px; height: 24px; flex: none; }
button { font: inherit; color: inherit; }
.mock-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; height: calc(var(--banner-h) + var(--sat));
  padding: var(--sat) 12px 0; background: var(--banner-bg); color: var(--banner-ink);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 12px; letter-spacing: .02em;
}
.mock-banner svg { width: 16px; height: 16px; }
.mock-banner strong { letter-spacing: .08em; }
.mock-banner span { opacity: .9; }
.app-header {
  display: flex; align-items: center; justify-content: space-between; height: var(--header-h);
  max-width: 520px; margin: 0 auto; padding: 0 16px;
}
.app-header h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.icon-btn { width: 48px; height: 48px; border: 0; background: transparent; border-radius: 50%; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.icon-btn:active { background: var(--line); }
main { max-width: 520px; margin: 0 auto; padding: 0 16px; outline: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 22px 4px 8px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.section-title svg { width: 18px; height: 18px; }
.section-note { margin: -2px 4px 10px; font-size: 14px; color: var(--muted); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* Left to budget hero */
.hero { text-align: center; padding: 22px 16px 18px; background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.hero .label { font-size: 14px; font-weight: 600; opacity: .9; }
.hero .big { font-size: 48px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; margin: 4px 0; }
.hero .sub { font-size: 14px; opacity: .92; display: flex; justify-content: center; gap: 6px; align-items: center; }
.hero .sub svg { width: 18px; height: 18px; }
.hero.over { background: var(--bad); color: #fff; }
.hero.some { background: var(--info); color: #fff; }
:root[data-theme="dark"] .hero.over, :root[data-theme="dark"] .hero.some { color: #08140c; }
.hero-split { display: flex; justify-content: space-around; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.28); font-size: 13px; }
.hero-split b { display: block; font-size: 17px; }

/* Budget groups */
.group { padding: 0; overflow: hidden; }
.group-head { width: 100%; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 8px 16px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.group-head h3 { margin: 0; font-size: 17px; flex: 1; }
.group-head .left { font-size: 14px; color: var(--muted); }
.group-head .chev { transition: transform .15s; color: var(--muted); width: 20px; height: 20px; }
.group.closed .chev { transform: rotate(-90deg); }
.group.closed .rows { display: none; }
.rows { border-top: 1px solid var(--line); }
.row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; padding: 8px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--accent-soft); }
.row .nm { font-weight: 600; }
.row .sm { font-size: 13px; color: var(--muted); }
.row .amt { text-align: right; }
.row .amt b { display: block; }
.row .amt span { font-size: 13px; color: var(--muted); }
.linked { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--info); }
.linked svg { width: 14px; height: 14px; }
.ok { color: var(--accent); }

/* Chips and badges */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--track); color: var(--ink); white-space: nowrap; }
.chip svg { width: 14px; height: 14px; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.good { background: var(--accent-soft); color: var(--accent); }
.chip.dash { background: transparent; border: 1.5px dashed var(--warn); color: var(--warn); }

/* Debt rows */
.debt { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer; }
.debt:active { transform: scale(.995); }
.debt.priority { border: 2px solid var(--warn); background: var(--card); }
.debt.target { border: 2px solid var(--accent); }
.debt-top { display: flex; gap: 10px; align-items: flex-start; }
.rank { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--accent-soft); color: var(--accent); flex: none; }
.rank svg { width: 18px; height: 18px; }
.rank.warn { background: var(--warn-soft); color: var(--warn); }
.rank.info { background: var(--info-soft); color: var(--info); }
.debt-title { flex: 1; min-width: 0; }
.debt-title b { font-size: 17px; display: block; }
.debt-title span { font-size: 13px; color: var(--muted); }
.debt-bal { text-align: right; font-weight: 800; font-size: 18px; }
.debt-bal small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; }
.progress { height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.dashed { background: repeating-linear-gradient(45deg, var(--track), var(--track) 6px, transparent 6px, transparent 12px); }
.pfoot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.countdown { display: flex; gap: 10px; margin-top: 10px; }
.countdown > div { flex: 1; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 8px 10px; }
.countdown b { display: block; font-size: 22px; line-height: 1.1; }
.countdown span { font-size: 12px; font-weight: 600; }
.callout { display: flex; gap: 10px; background: var(--info-soft); color: var(--ink); border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 10px; }
.callout svg { color: var(--info); margin-top: 1px; }
.callout.warn { background: var(--warn-soft); }
.callout.warn svg { color: var(--warn); }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.summary .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.summary .v { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.summary .full { grid-column: 1 / -1; }
.paid-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; }
.paid-row b { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; width: 100%; }
.btn:active { filter: brightness(.92); }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn svg { width: 20px; height: 20px; }

/* Rewards */
.streak { display: flex; align-items: center; gap: 14px; }
.streak .flame { width: 64px; height: 64px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; }
.streak .flame svg { width: 34px; height: 34px; }
.streak .n { font-size: 40px; font-weight: 800; line-height: 1; }
.dots { display: flex; gap: 6px; margin-top: 8px; }
.dots i { width: 18px; height: 18px; border-radius: 50%; background: var(--track); }
.dots i.on { background: var(--accent); }
.badges { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 10px; text-align: center; box-shadow: var(--shadow); }
.badge .ic { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.badge .ic svg { width: 30px; height: 30px; }
.badge b { display: block; font-size: 14px; }
.badge span { font-size: 12px; color: var(--muted); }
.badge.locked { opacity: .75; }
.badge.locked .ic { background: var(--track); color: var(--muted); }
.badge.new { border: 2px solid var(--accent); }

/* Tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--sab); }
.tabbar a { flex: 1; max-width: 174px; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.4; }

/* Sheet */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(8,16,11,.5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; background: var(--card); border-radius: 22px 22px 0 0; padding: 12px 16px calc(var(--sab) + 20px); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet h2 { margin: 4px 0 2px; font-size: 22px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.notice { display: flex; gap: 10px; background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin: 10px 0; }
.notice svg { color: var(--warn); width: 20px; height: 20px; }
.field { display: block; margin: 12px 0; }
.field > span { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input[type=number], .field input[type=text] { width: 100%; min-height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); padding: 0 14px; font: inherit; font-size: 17px; }
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field input[readonly] { opacity: .7; }
.field.need input { border-color: var(--warn); background: var(--warn-soft); }
.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.seg { display: flex; background: var(--track); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.celebrate { text-align: center; padding-top: 8px; }
.celebrate .ic { width: 84px; height: 84px; margin: 6px auto 8px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.celebrate .ic svg { width: 46px; height: 46px; }
.celebrate h2 { font-size: 26px; }
.celebrate .earned { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 70; pointer-events: none; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--sab) + 16px); z-index: 65; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90%; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 700px) { body { background: var(--bg); } .overlay { align-items: center; } .sheet { border-radius: 22px; } }
/* utility classes (no inline styles, for a strict CSP) */
.mt8 { margin-top: 8px; } .mt0 { margin-top: 0; } .m0 { margin: 0; } .gap12 { height: 12px; }
.small { font-size: 13px; } .small14 { font-size: 14px; }
.chip.plain { font-style: normal; }
.streak.mini { justify-content: center; margin: 8px 0 14px; }
.streak.mini .flame { width: 44px; height: 44px; }
.streak.mini .flame svg { width: 24px; height: 24px; }
.streak.mini .n { font-size: 28px; }
.streak.mini .tl { text-align: left; }
