/* ============================================================
   Coin Jar — design tokens

   Chart colours come from the validated data-viz palette:
   a single blue hue for every quantitative mark, and the blue
   ordinal ramp for the heatmap. Both were run through
   validate_palette.js against these exact surfaces
   (light #FFFBF5 / dark #1A1917) and pass in both modes.
   Gold and cream are brand decoration only — they never
   encode a value.
   ============================================================ */
:root {
  color-scheme: light;

  --surface-0:      #FFFBF5;   /* page plane */
  --surface-1:      #FFFFFF;   /* card + chart surface */
  --surface-2:      #F6F1E8;   /* subtle fill / track */
  --surface-3:      #EDE6D9;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --shadow:         0 1px 2px rgba(11,11,11,.05), 0 8px 24px rgba(11,11,11,.06);

  --series-1:       #2a78d6;   /* the one data hue */
  --series-1-wash:  rgba(42,120,214,.10);

  --heat-0:         #EDE6D9;   /* no activity */
  --heat-1:         #86b6ef;
  --heat-2:         #5598e7;
  --heat-3:         #2a78d6;
  --heat-4:         #184f95;

  --good:           #0ca30c;   /* status: always shipped with icon + label */
  --warning:        #fab219;
  --critical:       #d03b3b;

  --gold:           #F2B23E;   /* decoration */
  --gold-deep:      #D9902A;
  --gold-wash:      #FDF0D6;

  --radius:   16px;
  --radius-l: 22px;
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #131211;
    --surface-1: #1A1917;
    --surface-2: #242220;
    --surface-3: #2E2B27;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255,255,255,0.10);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --series-1: #3987e5;
    --series-1-wash: rgba(57,135,229,.14);
    --heat-0: #26241F;
    --heat-1: #184f95;
    --heat-2: #256abf;
    --heat-3: #3987e5;
    --heat-4: #86b6ef;
    --gold-wash: #38301F;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #131211;
  --surface-1: #1A1917;
  --surface-2: #242220;
  --surface-3: #2E2B27;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255,255,255,0.10);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --series-1: #3987e5;
  --series-1-wash: rgba(57,135,229,.14);
  --heat-0: #26241F;
  --heat-1: #184f95;
  --heat-2: #256abf;
  --heat-3: #3987e5;
  --heat-4: #86b6ef;
  --gold-wash: #38301F;
}

/* ── base ─────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-0);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; }
.muted { color: var(--text-muted); font-weight: 400; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ── layout shell ─────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--surface-0) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(160deg, var(--gold), var(--gold-deep));
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.12);
}
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-1);
  font-size: 14px; font-weight: 640; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip-streak.is-hot { background: var(--gold-wash); border-color: transparent; }
.chip-icon { font-size: 14px; line-height: 1; }
.chip-streak.is-cold .chip-icon { filter: grayscale(1); opacity: .5; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-1); cursor: pointer;
  color: var(--text-secondary);
}

.view {
  flex: 1;
  width: 100%; max-width: 520px; margin: 0 auto;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
  outline: none;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface-0) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1 1 0; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: var(--tap); padding: 6px 4px;
  border: 0; border-radius: 12px; background: none;
  color: var(--text-muted); font-size: 11px; font-weight: 600;
  cursor: pointer;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-selected="true"] { color: var(--series-1); }

/* ── cards & type ─────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-title { font-size: 15px; font-weight: 640; }
.card-sub { margin: 4px 0 14px; font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.section-title {
  margin: 22px 4px 10px; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted);
}

/* ── buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid transparent; border-radius: 12px;
  font-size: 15px; font-weight: 640; cursor: pointer;
  transition: transform .08s ease, background-color .15s ease;
}
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--series-1); color: #fff; }
.btn-gold { background: linear-gradient(165deg, var(--gold), var(--gold-deep)); color: #3A2A08; }
.btn-ghost { background: var(--surface-2); color: var(--text-primary); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--critical); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }

/* ── forms ────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }
.field-narrow { flex: 0 0 118px; }
.input {
  width: 100%; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-1); color: var(--text-primary);
  font: inherit; font-size: 16px;
}
select.input { padding-right: 8px; }
.input-affix { position: relative; }
.input-affix .affix {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 16px; pointer-events: none;
}
.input-affix .input { padding-left: 34px; }

/* ── onboarding ───────────────────────────────────────────── */
.onboarding {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 70% at 50% 0%, var(--gold-wash) 0%, transparent 62%),
    var(--surface-0);
}
.ob-card { width: 100%; max-width: 420px; }
.ob-jar { display: flex; justify-content: center; margin-bottom: 10px; }
.ob-jar svg { width: 120px; height: auto; }
.ob-title { text-align: center; font-size: 30px; letter-spacing: -0.02em; }
.ob-sub { margin: 8px 0 22px; text-align: center; color: var(--text-secondary); font-size: 15px; line-height: 1.45; }
.ob-note { margin: 0 0 10px; font-size: 13px; color: var(--critical); font-weight: 600; }
.ob-fine { margin: 12px 0 0; text-align: center; font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── jar hero ─────────────────────────────────────────────── */
.hero {
  position: relative;
  display: grid; grid-template-columns: 132px 1fr; gap: 16px; align-items: center;
  background: linear-gradient(170deg, var(--gold-wash), var(--surface-1) 72%);
  border: 1px solid var(--border); border-radius: var(--radius-l);
  padding: 18px 18px 20px; margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero-jar { display: grid; place-items: center; }
.hero-jar svg { width: 126px; height: auto; display: block; }
/* the one hero number on the screen — scales up with the viewport
   but never wraps beside the jar on a narrow phone */
.hero-figure { font-size: clamp(30px, 9vw, 42px); font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; }
.hero-label { margin-top: 2px; font-size: 13px; color: var(--text-secondary); }
.hero-meta { margin-top: 12px; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.hero-bar { margin-top: 10px; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.hero-bar > i { display: block; height: 100%; border-radius: 999px; background: var(--series-1); transition: width .6s cubic-bezier(.2,.7,.3,1); }

/* ── challenge card ───────────────────────────────────────── */
.challenge { position: relative; overflow: hidden; }
.challenge-flavor { font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--gold-deep); }
.challenge-emoji { font-size: 30px; line-height: 1; margin: 8px 0 6px; }
.challenge-title { font-size: 19px; font-weight: 680; letter-spacing: -0.015em; }
.challenge-blurb { margin: 6px 0 14px; font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.challenge-amount {
  display: inline-flex; align-items: baseline; gap: 5px; margin-bottom: 14px;
  padding: 5px 11px; border-radius: 999px; background: var(--surface-2);
  font-size: 13px; color: var(--text-secondary);
}
.challenge-amount b { font-size: 15px; color: var(--text-primary); }
.challenge.is-done { background: linear-gradient(170deg, var(--gold-wash), var(--surface-1) 60%); }
.done-mark { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 640; color: var(--good); }
.done-mark svg { width: 18px; height: 18px; flex: none; }

/* ── entry list ───────────────────────────────────────────── */
.entries { list-style: none; margin: 0; padding: 0; }
.entry { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 11px; background: var(--surface-2); font-size: 17px; }
.entry-main { flex: 1; min-width: 0; }
.entry-title { display: block; font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub { display: block; font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.entry-amount { font-size: 15px; font-weight: 660; font-variant-numeric: tabular-nums; }
.entry-del { border: 0; background: none; padding: 8px; color: var(--text-muted); cursor: pointer; border-radius: 8px; line-height: 0; }
.entry-del svg { width: 16px; height: 16px; }

.empty { text-align: center; padding: 26px 12px; color: var(--text-muted); font-size: 14px; line-height: 1.6; }
.empty-emoji { font-size: 30px; display: block; margin-bottom: 8px; }

/* ── stat tiles ───────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 13px 14px; }
.tile-label { font-size: 12px; color: var(--text-muted); }
.tile-value { margin-top: 3px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.tile-note { margin-top: 3px; font-size: 12px; color: var(--text-muted); }
.tile-note.good { color: var(--good); font-weight: 600; }

/* ── filter row (scopes every chart below it) ─────────────── */
.filterbar { display: flex; gap: 6px; margin-bottom: 14px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.filterbar button {
  flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: none;
  font-size: 13px; font-weight: 620; color: var(--text-secondary); cursor: pointer;
}
.filterbar button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(11,11,11,.08); }

/* ── charts ───────────────────────────────────────────────── */
.viz { width: 100%; display: block; touch-action: pan-y; }
/* the calendar keeps its natural width and scrolls when a year
   of weeks cannot fit the screen */
.viz.is-wide { width: auto; max-width: none; }
.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
.viz text { font-family: var(--font); }
.viz .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.viz .axis-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.viz .tick { fill: var(--text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.viz .value-label { fill: var(--text-primary); font-size: 11.5px; font-weight: 640; }
.viz .row-label { fill: var(--text-secondary); font-size: 12.5px; }
.viz .mark { fill: var(--series-1); }
.viz .area { fill: var(--series-1-wash); }
.viz .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .end-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.viz .crosshair { stroke: var(--axis); stroke-width: 1; }
.viz .hit { fill: transparent; cursor: pointer; outline: none; }
.viz .focus-ring { fill: none; stroke: var(--text-primary); stroke-width: 2; }

.chart-wrap { position: relative; }
.viz-tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  padding: 7px 10px; border-radius: 9px;
  background: var(--text-primary); color: var(--surface-1);
  font-size: 12.5px; font-weight: 600; line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  max-width: 200px;
}
.viz-tooltip .tt-sub { display: block; font-weight: 400; opacity: .75; font-size: 11.5px; }

.table-toggle {
  margin-top: 10px; border: 0; background: none; padding: 6px 0;
  color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.data-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.data-table th, .data-table td { padding: 7px 6px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 700; }
.data-table td:last-child, .data-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { max-height: 260px; overflow-y: auto; }

/* heatmap legend */
.heat-legend { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 11.5px; color: var(--text-muted); }
.heat-legend i { width: 12px; height: 12px; border-radius: 3px; display: block; }

/* ── goal ring ────────────────────────────────────────────── */
.ring-wrap { display: grid; place-items: center; padding: 6px 0 2px; }
.ring-wrap svg { width: 210px; height: 210px; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 14; }
.ring-fill { fill: none; stroke: var(--series-1); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset .8s cubic-bezier(.2,.7,.3,1); }
.ring-figure { fill: var(--text-primary); font-size: 32px; font-weight: 700; text-anchor: middle; }
.ring-caption { fill: var(--text-muted); font-size: 12px; text-anchor: middle; }

/* ── badges ───────────────────────────────────────────────── */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 13px 8px; border-radius: 14px;
  background: var(--surface-2); text-align: center;
}
.badge.is-on { background: var(--gold-wash); }
.badge-emoji { font-size: 26px; line-height: 1; }
.badge.is-off .badge-emoji { filter: grayscale(1); opacity: .35; }
.badge-name { font-size: 11.5px; font-weight: 640; line-height: 1.3; }
.badge.is-off .badge-name { color: var(--text-muted); font-weight: 500; }
.badge-hint { font-size: 10.5px; color: var(--text-muted); line-height: 1.25; }
.badge-strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.badge-strip::-webkit-scrollbar { display: none; }
.badge-strip .badge { flex: 0 0 96px; }

/* ── bottom sheet ─────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(11,11,11,.42); backdrop-filter: blur(2px); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 88vh; overflow-y: auto;
  background: var(--surface-1);
  border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0,0,0,.22);
  animation: sheet-in .26s cubic-bezier(.2,.8,.3,1);
}
@keyframes sheet-in { from { transform: translateY(14px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }
@media (min-width: 560px) {
  .sheet { left: 50%; margin-left: -240px; right: auto; width: 480px; border-radius: 22px; bottom: 24px; }
}
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--surface-3); margin: 4px auto 12px; }
.sheet-title { font-size: 18px; font-weight: 660; margin-bottom: 4px; }
.sheet-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 16px; line-height: 1.45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pick {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 13px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-1); font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.pick[aria-pressed="true"] { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.amount-row { display: flex; gap: 8px; margin-bottom: 14px; }
.amount-row .pick { flex: 1; justify-content: center; }

/* ── toast, confetti, install ─────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 70;
  padding: 11px 16px; border-radius: 12px;
  background: var(--text-primary); color: var(--surface-1);
  font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 28px rgba(0,0,0,.25);
  animation: toast-in .22s ease;
  max-width: calc(100vw - 32px); text-align: center;
}
@keyframes toast-in { from { transform: translate(-50%, 10px); opacity: 0 } to { transform: translate(-50%, 0); opacity: 1 } }
.confetti { position: fixed; inset: 0; z-index: 65; pointer-events: none; }

.install-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 12px 11px 16px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); font-size: 13.5px;
}
.install-actions { display: flex; gap: 6px; flex: none; }
@media (min-width: 560px) {
  .install-bar { width: 496px; left: 50%; margin-left: -248px; right: auto; }
}

/* jar coin drop */
@keyframes coin-drop {
  0%   { transform: translateY(-70px) scale(.6); opacity: 0 }
  55%  { opacity: 1 }
  100% { transform: translateY(0) scale(1); opacity: 1 }
}
.coin-anim { animation: coin-drop .55s cubic-bezier(.3,1.4,.5,1) backwards; }
@keyframes jar-pop { 0%, 100% { transform: scale(1) } 40% { transform: scale(1.05) } }
.jar-pop { animation: jar-pop .4s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* forced-colors / print: identity must not rest on hue alone */
@media (forced-colors: active) {
  .viz .mark, .viz .line { forced-color-adjust: none; fill: CanvasText; stroke: CanvasText; }
  .card, .tile { border: 1px solid CanvasText; }
}
