/* Self-hosted character fonts — no third-party CDN request, works fully offline once
   the service worker has precached the files (see sw.js ASSETS). Space Grotesk is the
   variable display/heading/number face (weight 300-700 — its tabular numerals suit a
   money app); Bricolage Grotesque is the body face. Both are SIL Open Font License —
   free for commercial use. */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../assets/fonts/space-grotesk-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../assets/fonts/space-grotesk-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Named FALLBACK faces, tuned with metric-override properties so the system font that
   briefly shows during font-display:swap occupies (almost) the same box as the real
   webfont — this is what keeps CLS low on swap, not just font-display itself. Pure
   metrics on a local system font — never downloaded. */
@font-face {
  font-family: "Space Grotesk Fallback";
  src: local("Arial"), local("Helvetica");
  size-adjust: 104%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../assets/fonts/bricolage-grotesque-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Bricolage Grotesque Fallback";
  src: local("Arial"), local("Helvetica"), local("Segoe UI");
  size-adjust: 105.43%;
  ascent-override: 88.21%;
  descent-override: 25.61%;
  line-gap-override: 0%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; line-height: 1.45; padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
[data-reduce="1"] * { transition: none !important; animation: none !important; }
/* Always honour the OS-level reduced-motion preference, independent of the in-app
   toggle (that toggle is also seeded FROM this same media query at boot — see
   js/app.js boot() — but this rule is a hard floor so motion never leaks through
   before JS runs, or for a person who never opens Settings). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
h1, h2 { letter-spacing: -0.4px; font-family: var(--font-heading); }

/* Inline SVG icon set (replaces the old Material Symbols webfont + emoji-as-icon).
   Every <svg class="ic"> is generated by the icon() helper in js/app.js with
   aria-hidden="true" — the control that wraps it always carries the real accessible
   name via aria-label/visible text, so the icon itself stays purely decorative. */
.ic { width: 20px; height: 20px; display: inline-block; flex: 0 0 auto; vertical-align: middle; }
.tab .ic { width: 22px; height: 22px; }
.stat-ic { width: 20px; height: 20px; color: var(--primary); display: block; margin: 0 auto 2px; }
.tip-ic { width: 18px; height: 18px; color: var(--accent); flex: 0 0 auto; }
.select-btn .ic { color: var(--ink-soft); }
.cur-row .ic { color: var(--primary); }
.cat-edit button .ic, .badge-lock .ic { width: 18px; height: 18px; }
.key .ic, .nav-btn .ic { width: 22px; height: 22px; }
.sheet-ic { width: 32px; height: 32px; color: var(--primary); }
.lock-ic { width: 16px; height: 16px; vertical-align: -3px; color: var(--ink-soft); }

.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 12px; top: 12px; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.app { max-width: var(--maxw); margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) var(--space) 24px; }
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-head { margin: 4px 0 14px; }
.view-head h1 { font-size: 30px; margin: 0; }
.sub { color: var(--ink-soft); font-size: 14px; margin: 3px 0 0; }
.muted { color: var(--ink-soft); font-weight: 400; font-size: 12px; }
.mini-h { font-size: 14px; color: var(--ink-soft); margin: 24px 0 8px; font-weight: 600; font-family: var(--font-heading); }
.hint { font-size: 12px; color: var(--ink-soft); line-height: 1.5; margin: 8px 0 2px; }

/* buttons / fields */
.btn { font: inherit; font-size: 15px; cursor: pointer; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 16px; min-height: 44px; transition: transform .08s ease; }
.btn:active { transform: scale(.96); }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.big { width: 100%; padding: 15px; font-size: 17px; font-weight: 600; margin-top: 8px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-top { margin-top: 16px; }
.btn-half { flex: 1; }
.confirm-actions { margin-top: 16px; }
.field { width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); min-height: 44px; }
.field-label { display: block; font-size: 14px; margin: 16px 0 6px; color: var(--ink-soft); }
select.field { appearance: none; }
.toggle-top { margin-top: 16px; }

/* ADD view */
.add-head { display: flex; justify-content: space-between; align-items: flex-start; }
.month-total { font-size: 30px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.amount-display { text-align: center; font-size: 52px; font-weight: 700; letter-spacing: -1px; margin: 8px 0 4px; font-variant-numeric: tabular-nums; font-family: var(--num-font, inherit); min-height: 60px; }
.type-toggle { display: flex; gap: 0; background: var(--surface-2); border-radius: 999px; padding: 4px; margin: 8px auto 16px; max-width: 280px; }
.seg { flex: 1; font: inherit; font-size: 14px; border: none; background: transparent; color: var(--ink-soft); padding: 9px; min-height: 44px; border-radius: 999px; cursor: pointer; }
.seg.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px -2px rgba(0,0,0,.4); }
.cat-chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; -webkit-overflow-scrolling: touch; }
.cat-chip { flex: 0 0 auto; font: inherit; font-size: 14px; padding: 9px 14px; min-height: 44px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.cat-chip.active { background: var(--surface-2); border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.note { margin: 8px 0 16px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { font: inherit; font-size: 24px; font-weight: 600; padding: 16px; min-height: 56px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.key:active { transform: scale(.95); background: var(--surface-2); }

/* lists / items */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.tx { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 14px; cursor: pointer; }
.tx-emoji { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; flex: 0 0 auto; }
.tx-main { flex: 1; min-width: 0; }
.tx-cat { font-size: 15px; font-weight: 600; }
.tx-note { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 700; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.tx-amt.income { color: var(--good); }
.empty { color: var(--ink-soft); text-align: center; padding: 24px 8px; }

/* spending */
.donut-wrap { position: relative; width: 240px; height: 240px; margin: 8px auto; }
.chart-tip { position: absolute; transform: translate(-50%, -135%); background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: 12px; white-space: nowrap; pointer-events: none; z-index: 5; box-shadow: 0 6px 16px -8px rgba(0,0,0,.6); }
.chart-tip .tip-pct { opacity: .75; }
.tx-meta { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; font-family: var(--num-font); }
#donut { width: 240px; height: 240px; display: block; }
.vs { text-align: center; color: var(--ink-soft); font-size: 13px; margin: 4px 0 16px; }
.vs .good, .delta.good { color: var(--good); }
.vs .bad, .delta.bad { color: var(--danger); }
.delta { font-size: 11px; font-weight: 600; margin-left: 8px; }
.delta.new { color: var(--ink-soft); }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend-dot { width: 14px; height: 14px; border-radius: 4px; flex: 0 0 auto; }
.legend-ic { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; flex: 0 0 auto; }
.tx-note.good { color: var(--good); } .tx-note.bad { color: var(--danger); }
.trend-summary { text-align: center; font-size: 13px; color: var(--ink-soft); margin: 8px 0 2px; }
.trend-summary .good { color: var(--good); } .trend-summary .bad { color: var(--danger); }
.legend-name { flex: 1; }
.legend-val { font-weight: 600; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.legend-pct { color: var(--ink-soft); font-size: 12px; width: 42px; text-align: right; }

/* budgets */
.safe-card { background: var(--primary); color: var(--primary-ink); border-radius: var(--radius); padding: 24px; text-align: center; margin-bottom: 8px; }
.safe-card .big-n { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; font-family: var(--num-font); margin: 4px 0; }
.safe-card .small { opacity: .85; font-size: 13px; }
.safe-empty { background: var(--surface); color: var(--ink); border: 1px dashed var(--line); }
.safe-card .tiny { font-size: 11px; opacity: .7; margin-top: 4px; }
.tip-card { display: flex; gap: 8px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); box-shadow: inset 3px 0 0 var(--accent); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 16px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; cursor: pointer; }
.budget-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; }
.budget-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.budget-name { font-weight: 600; }
.budget-vals { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }

/* stats / wins */
.stats { display: flex; gap: 8px; margin-bottom: 8px; }
.stat { flex: 1; background: var(--surface-2); border-radius: var(--radius-sm); padding: 16px 8px; text-align: center; }
.stat-n { display: block; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.stat-l { font-size: 11px; color: var(--ink-soft); }
#trend-chart { width: 100%; height: 144px; display: block; }
.net-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: linear-gradient(135deg, var(--primary), var(--accent)); color: var(--primary-ink); border-radius: var(--radius); padding: 16px 24px; margin-bottom: 16px; box-shadow: 0 12px 30px -16px var(--primary); }
.net-top { font-size: 12px; opacity: .85; }
.net-big { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; font-family: var(--num-font); margin: 2px 0; line-height: 1.1; }
.net-sub { font-size: 12px; opacity: .85; }
.net-ring { position: relative; width: 80px; height: 80px; flex: 0 0 auto; }
.net-ring svg { width: 80px; height: 80px; transform: rotate(-90deg); }
.net-ring .ring-bg { fill: none; stroke: rgba(255,255,255,.28); stroke-width: 7; }
.net-ring .ring-fg { fill: none; stroke: var(--primary-ink); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring-val { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 18px; font-weight: 800; font-family: var(--num-font); }
.ring-val small { font-size: 9px; font-weight: 400; opacity: .85; font-family: var(--font); }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 8px; opacity: .35; }
.badge.earned { opacity: 1; }
.badge-ic { width: 46px; height: 46px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
.badge-ic .ic { width: 22px; height: 22px; color: var(--ink-soft); }
.badge.earned .badge-ic { background: var(--primary); box-shadow: 0 6px 14px -6px var(--primary); }
.badge.earned .badge-ic .ic { color: var(--primary-ink); }
.badge-l { font-size: 10px; color: var(--ink-soft); text-align: center; line-height: 1.2; }
.affirm { color: var(--ink-soft); font-size: 15px; text-align: center; margin-top: 16px; font-style: italic; }

/* settings */
.setting-group { margin: 24px 0; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.setting-group h2 { font-size: 16px; margin: 0 0 8px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 15px; min-height: 44px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.theme-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--line); cursor: pointer; }
.swatch[aria-pressed="true"] { outline: 3px solid var(--primary); outline-offset: 2px; }
.cat-edit { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 8px 8px 12px; }
.cat-edit .em { font-size: 18px; }
.cat-edit .nm { flex: 1; font-size: 15px; }
.cat-edit button { background: none; border: none; color: var(--ink-soft); cursor: pointer; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }
.cat-edit button:hover { background: var(--surface-2); }
.version { color: var(--ink-soft); font-size: 12px; text-align: center; margin-top: 16px; }

/* tabbar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: var(--maxw); z-index: 20; display: flex; background: var(--surface); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 24px -18px rgba(0,0,0,.5); }
.tab { flex: 1; background: none; border: none; cursor: pointer; color: var(--ink-soft); padding: 8px 2px 8px; min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font: inherit; font-size: 10px; }
.tab[aria-current="true"] { color: var(--primary); font-weight: 600; }
.tab:active { transform: scale(.92); }

/* overlay / sheet */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { position: relative; background: var(--bg); width: 100%; max-width: var(--maxw); border-radius: 22px; max-height: 88vh; overflow-y: auto; padding: 24px 24px calc(24px + env(safe-area-inset-bottom)); animation: rise .3s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 8px 0; font-size: 22px; }
.sheet-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer; display: grid; place-items: center; }
.legend-help { list-style: none; padding: 0; margin: 8px 0; }
.legend-help li { font-size: 14px; line-height: 1.5; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* help fab + banner + toast */
.help-fab { position: fixed; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 25; width: 44px; height: 44px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); color: var(--primary); font-size: 20px; font-weight: 700; cursor: pointer; box-shadow: 0 6px 18px -8px rgba(0,0,0,.5); }
.banner { background: var(--primary); color: var(--primary-ink); padding: 12px 16px; font-size: 14px; text-align: center; }
.banner button { margin-left: 8px; background: var(--primary-ink); color: var(--primary); border: none; border-radius: 8px; padding: 6px 10px; min-height: 32px; font: inherit; cursor: pointer; }
.banner .close { background: transparent; color: var(--primary-ink); float: right; display: inline-flex; align-items: center; justify-content: center; min-width: 32px; min-height: 32px; padding: 0; }
.banner .close .ic { width: 16px; height: 16px; }
.toast { position: fixed; left: 50%; bottom: 98px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-size: 14px; z-index: 70; max-width: 90%; text-align: center; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); }

/* quick amounts + keypad polish */
.quick-amounts { display: flex; gap: 8px; margin: 2px 0 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.qa { flex: 1 0 auto; font: inherit; font-size: 14px; font-weight: 600; padding: 9px 14px; min-height: 44px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; white-space: nowrap; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.qa:active { transform: scale(.95); }
.key { box-shadow: 0 1px 0 var(--line); }
.key-soft { color: var(--ink-soft); background: var(--surface-2); }

/* segmented period */
.seg-group { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; margin: 0 auto 16px; max-width: 320px; }
.seg2 { flex: 1; font: inherit; font-size: 14px; border: none; background: transparent; color: var(--ink-soft); padding: 9px; min-height: 44px; border-radius: 999px; cursor: pointer; }
.seg2.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px -2px rgba(0,0,0,.4); }
.spend-sub { text-align: center; margin-bottom: 8px; }
.sub-seg { max-width: 260px; }
.nav-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 8px; }
.nav-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: grid; place-items: center; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.per-label { font: inherit; font-size: 15px; font-weight: 600; background: none; border: none; color: var(--ink); cursor: pointer; min-width: 150px; min-height: 44px; text-align: center; }

/* custom select button */
.select-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; font: inherit; font-size: 16px; padding: 12px 14px; min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); cursor: pointer; }

/* entry sheet category grid */
.entry-amount { text-align: center; font-size: 38px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 8px; font-family: var(--num-font, inherit); }
.entry-sub { text-align: center; color: var(--ink-soft); font-size: 13px; margin-bottom: 4px; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 16px; }
.cat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 4px; min-height: 44px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font: inherit; }
.cat-tile.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cat-tile:active { transform: scale(.95); }
.cat-tile-em { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 19px; background: var(--surface-2); }
.cat-tile-nm { font-size: 11px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cat-tile.add .cat-tile-em { color: var(--ink-soft); }

/* currency list + small confirm */
.cur-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.cur-row { display: flex; align-items: center; justify-content: space-between; font: inherit; font-size: 15px; padding: 13px 14px; min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); cursor: pointer; }
.cur-row.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.sheet-sm { max-width: 380px; text-align: center; }
