/* Clarity Money Lab — Apple HIG structure, Robinhood palette */
:root, [data-theme="dark"] {
  --bg: #000000;
  --bg-2: #1c1c1e;
  --bg-3: #2c2c2e;
  --text: #ffffff;
  --muted: #8e8e93;
  --line: rgba(255, 255, 255, 0.08);
  --bad: #ff5000;
  --good: #00c805;
  --accent: #0a84ff;
  --on-good: #00230a;
}
[data-theme="light"] {
  --bg: #f2f2f7;
  --bg-2: #ffffff;
  --bg-3: #e9e9ee;
  --text: #000000;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --bad: #d63a00;
  --good: #008a05;
  --accent: #007aff;
  --on-good: #ffffff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  transition: background .25s, color .25s;
}
main { max-width: 700px; margin: 0 auto; padding: 20px 16px calc(60px + env(safe-area-inset-bottom)); }

h1 {
  font-size: 2.1rem; font-weight: 700; letter-spacing: -0.022em;
  margin: .3em 0 .4em; line-height: 1.15;
}
h2 {
  font-size: 1.06rem; font-weight: 600; letter-spacing: -0.01em;
  margin: 1.1em 0 .5em;
}
p { margin: .5em 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.bad { color: var(--bad); font-weight: 600; }
.good { color: var(--good); font-weight: 600; }
.big {
  font-size: 2.6rem; font-weight: 700; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

/* header — iOS nav bar */
.site-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px calc(10px);
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
}
.brand {
  color: var(--text); text-decoration: none; font-weight: 600;
  font-size: 1.02rem; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px;
}
.brand-logo { width: 26px; height: 26px; border-radius: 7px; display: block; }
.brand:hover { text-decoration: none; }
.theme-toggle {
  margin-left: auto; background: var(--bg-2); border: none;
  color: var(--text); border-radius: 50%; width: 36px; height: 36px;
  cursor: pointer; font-size: 1rem;
}
.burger {
  background: none; border: none; cursor: pointer; padding: 10px 6px;
  display: flex; flex-direction: column; gap: 4.5px;
}
.burger span { width: 19px; height: 1.8px; background: var(--text); border-radius: 2px; }

/* drawer — iOS sheet feel */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
  width: min(300px, 82vw);
  background: var(--bg-2);
  padding: calc(64px + env(safe-area-inset-top)) 12px 20px;
  transform: translateX(-102%);
  transition: transform .28s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column; gap: 2px;
  border-radius: 0 16px 16px 0;
}
.drawer.open { transform: translateX(0); }
.drawer a {
  color: var(--text); text-decoration: none; padding: 13px 14px;
  font-size: 1.05rem; border-radius: 10px; font-weight: 500;
}
.drawer a:hover { background: var(--bg-3); text-decoration: none; }
.drawer a.active { color: var(--good); background: color-mix(in srgb, var(--good) 10%, transparent); }
.scrim {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .28s;
}
.scrim.open { opacity: 1; pointer-events: auto; }

/* cards — iOS inset grouped */
.card {
  background: var(--bg-2);
  border: none;
  border-radius: 16px;
  padding: 16px 18px;
  margin: 12px 0;
}
.card h2 { margin-top: 0; }

/* madlib editing — tinted tappable values */
.ml-edit {
  cursor: pointer;
  border-bottom: 1.5px solid color-mix(in srgb, currentColor 35%, transparent);
  padding: 0 1px;
  border-radius: 2px;
  white-space: nowrap;
  transition: background .15s;
  min-height: 28px; display: inline-block;
}
.ml-edit:hover, .ml-edit:focus-visible {
  background: color-mix(in srgb, currentColor 10%, transparent);
  outline: none;
}
.ml-input {
  font: inherit; color: inherit; background: var(--bg-3);
  border: none; border-bottom: 1.5px solid currentColor;
  border-radius: 4px; padding: 0 3px; outline: none;
  font-variant-numeric: tabular-nums;
}
.poem { font-size: 1.15rem; line-height: 2.1; letter-spacing: -0.01em; }

/* buttons — iOS filled + tinted pills */
.btn {
  font: inherit; font-size: 1rem; font-weight: 600; cursor: pointer;
  border-radius: 999px; padding: 11px 20px; border: none;
  background: var(--bg-3); color: var(--text);
  min-height: 44px;
  transition: transform .1s, opacity .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn-good { background: var(--good); color: var(--on-good); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 7px 14px; font-size: .9rem; min-height: 34px; }
.btn.selected {
  background: color-mix(in srgb, var(--good) 15%, transparent);
  color: var(--good);
}
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }

/* trend */
.trend-up { color: var(--good); }
.trend-down { color: var(--bad); }
.trend { font-size: 1.05rem; font-weight: 600; }

/* bar chart (investments) */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 180px; margin: 16px 0 4px; }
.chart .bar {
  flex: 1; background: var(--good); border-radius: 3px 3px 0 0;
  min-height: 2px; opacity: .9; position: relative; transition: height .3s;
}
.chart .bar.base { background: var(--muted); opacity: .45; }
.chart .bar:hover { opacity: 1; }
.chart-labels { display: flex; gap: 3px; font-size: .7rem; color: var(--muted); }
.chart-labels span { flex: 1; text-align: center; }

/* sliders — iOS style */
input[type=range] {
  width: 100%; accent-color: var(--good); height: 28px;
}
.slider-row { margin: 16px 0; }
.slider-row .lab { display: flex; justify-content: space-between; font-size: .95rem; margin-bottom: 2px; }

/* debt rows */
.debt-row {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline;
  padding: 12px 0; border-bottom: 0.5px solid var(--line);
}
.debt-row:last-child { border-bottom: none; }
.debt-row .del { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px 6px; }
.debt-row .del:hover { color: var(--bad); }

/* celebration */
.cele-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.cele-card {
  background: var(--bg-2); border-radius: 22px;
  padding: 32px 28px; max-width: 420px; text-align: center;
  animation: pop .4s cubic-bezier(.32,1.6,.4,1);
}
.cele-burst { font-size: 3rem; }
.cele-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.75); opacity: 0; } }
.confetti {
  position: fixed; top: -12px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall 2.6s linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: .2; }
}

/* check-in deltas */
.delta-row {
  display: flex; justify-content: space-between; padding: 10px 0;
  border-bottom: 0.5px solid var(--line);
}
.delta-row:last-child { border-bottom: none; }

.sample-note {
  font-size: .88rem; color: var(--muted); background: var(--bg-2);
  border-radius: 12px; padding: 10px 14px; margin: 10px 0;
}

/* net worth chart */
.nwchart .nwc-svgwrap { margin: 4px -6px 0; }
.nwchart svg { width: 100%; height: 190px; display: block; touch-action: none; cursor: crosshair; }
.nwchart .nwc-dates { display: flex; justify-content: space-between; font-size: .72rem; padding: 2px 2px 0; }
.nwchart .nwc-pills { display: flex; gap: 4px; margin-top: 12px; }
.nwc-pill {
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  border: none; border-radius: 999px; padding: 6px 14px; min-height: 32px;
  background: transparent; color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
.nwc-pill:disabled { opacity: .3; cursor: default; }
.nwchart[data-dir="up"] .nwc-pill.selected { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.nwchart[data-dir="down"] .nwc-pill.selected { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.nwc-delta { font-weight: 600; font-size: .95rem; }
.nwc-demo {
  font-size: .66rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  background: var(--bg-3); color: var(--muted); border-radius: 6px; padding: 2px 7px; vertical-align: middle;
}

/* accounts — iOS grouped list */
.acct-group { padding: 10px 0; border-bottom: 0.5px solid var(--line); }
.acct-group:last-child { border-bottom: none; padding-bottom: 2px; }
.acct-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-bottom: 2px;
}
.acct-head b { font-size: 1.02rem; text-transform: none; letter-spacing: 0; }
.acct-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0; gap: 10px; min-height: 40px;
}
.acct-row .del { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px 6px; }
.acct-row .del:hover { color: var(--bad); }

/* summary bars */
.sum-row { margin: 12px 0; }
.sum-lab { display: flex; justify-content: space-between; margin-bottom: 5px; }
.sum-bar { height: 7px; border-radius: 999px; background: var(--bg-3); overflow: hidden; }
.sum-fill { height: 100%; border-radius: 999px; transition: width .4s cubic-bezier(.32,.72,0,1); }
.good-bg { background: var(--good); }
.bad-bg { background: var(--bad); }

/* onboarding */
.ob { max-width: 480px; padding-top: 7vh; }
.ob-q { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.022em; margin: 0 0 4px; line-height: 1.2; }
.ob-input { font-size: 2.8rem; font-weight: 700; letter-spacing: -0.03em; margin: 20px 0; }
.ob-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 30px; }
.ob-big { padding: 15px 22px; font-size: 1.05rem; width: 100%; min-height: 50px; }
.ob-debt { font-size: 1.05rem; line-height: 2.1; padding: 14px 16px; }
.ob-debt .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }
.ob-dots { display: flex; gap: 8px; justify-content: center; margin-top: 36px; }
.ob-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--bg-3); transition: background .25s; }
.ob-dot.on { background: var(--good); }
.ob-ticker {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 20px calc(13px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
  font-size: 1.05rem;
}

/* ---------- dashboard widget grid ---------- */
main.dash { max-width: 960px; }
.dash-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
  align-items: start;
}
.dcol { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.dcol .card { margin: 0; }

.w-head {
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); margin: 0 0 4px;
}
.w-title-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.w-title-row h2 { margin: 0; flex: 1; }
.w-ico {
  width: 36px; height: 36px; border-radius: 9px; background: var(--bg-3);
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  flex-shrink: 0;
}
.w-amt { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* progress bar (emergency fund) */
.pbar { height: 8px; border-radius: 999px; background: var(--bg-3); overflow: hidden; margin: 10px 0; }
.pfill { height: 100%; border-radius: 999px; background: var(--good); transition: width .4s cubic-bezier(.32,.72,0,1); }
.pmeta { display: flex; justify-content: space-between; align-items: baseline; font-size: .9rem; }

/* emergency fund quick add */
.ef-add-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ef-add-input {
  font: inherit; font-variant-numeric: tabular-nums;
  background: var(--bg-3); color: var(--text);
  border: none; border-radius: 10px; padding: 9px 12px;
  width: 110px; outline: none;
}
.ef-add-input:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--good) 55%, transparent); }

@media (max-width: 680px) {
  .dash-grid { grid-template-columns: 1fr; }
}

/* ---------- goal kit: chips, jars, picker, celebrations ---------- */
.chip {
  font: inherit; font-weight: 700; font-size: .98rem; cursor: pointer;
  border: none; border-radius: 999px; padding: 10px 17px; min-height: 44px;
  background: var(--bg-3); color: var(--text);
  transition: transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: scale(.93); }
.chip.go { background: var(--good); color: var(--on-good); }
.chip.ghost { background: transparent; color: var(--accent); }
.chip.mini { padding: 7px 13px; min-height: 36px; font-size: .88rem; }
.chip.selected { box-shadow: 0 0 0 2px var(--good); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; align-items: center; }
.amt-input {
  font: inherit; font-weight: 700; font-size: .98rem;
  background: var(--bg-3); color: var(--text);
  border: none; border-radius: 999px; padding: 10px 16px;
  width: 120px; outline: none; min-height: 44px;
  font-variant-numeric: tabular-nums;
}
.amt-input:focus { box-shadow: 0 0 0 2px var(--good); }

.jar-row {
  display: flex; gap: 10px; margin: 14px 0 6px;
  overflow-x: auto; padding: 6px 2px 10px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.jar-row:empty { display: none; }
.jar {
  flex: 0 0 auto; width: 102px; text-align: center; cursor: pointer;
  scroll-snap-align: start; -webkit-tap-highlight-color: transparent;
  transition: transform .15s;
}
.jar:active { transform: scale(.95); }
.jar svg { width: 100%; height: auto; display: block; overflow: visible; }
.jar .jpct { fill: var(--text); paint-order: stroke; stroke: var(--bg-2); stroke-width: 3px; }
.jar-name {
  font-size: .8rem; color: var(--muted); margin-top: 2px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.jar.done svg { filter: drop-shadow(0 0 14px color-mix(in srgb, var(--good) 55%, transparent)); }
.jar.done .jar-name { color: var(--good); }
.goal.flash { animation: goalflash 1.2s; }
@keyframes goalflash { 0%, 40% { box-shadow: 0 0 0 3px var(--good); } }

.goal { background: var(--bg-3); border-radius: 18px; padding: 14px 16px; margin: 10px 0; }
.goal-top { display: flex; align-items: center; gap: 10px; }
.goal-emoji {
  font-size: 1.6rem; cursor: pointer; line-height: 1;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: 1.5px dashed color-mix(in srgb, var(--text) 25%, transparent);
  border-radius: 12px; padding: 4px 7px;
  transition: transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.goal-emoji:active { transform: scale(.9); }
.goal-name { font-weight: 700; flex: 1; min-width: 0; }
.goal-cost { color: var(--muted); white-space: nowrap; }
.gbar { height: 12px; border-radius: 999px; background: color-mix(in srgb, var(--text) 8%, transparent); overflow: hidden; margin: 10px 0 6px; }
.gfill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width .5s cubic-bezier(.32,.72,0,1);
}
.gfill.drain { background: linear-gradient(90deg, #ff9f0a, var(--bad)); }
.goal-meta { display: flex; justify-content: space-between; font-size: .88rem; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.goal-meta .left { color: var(--muted); }
.goal-add-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.goal-add-row .lab { font-size: .85rem; color: var(--muted); margin-right: 2px; }
.goal-plan { font-size: .9rem; color: var(--muted); margin-top: 10px; }
.goal-plan b { color: var(--good); }
.goal .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px 8px; }
.goal .del:hover { color: var(--bad); }
.ontrack {
  display: inline-block; font-size: .78rem; font-weight: 700;
  border-radius: 999px; padding: 3px 10px; vertical-align: middle;
}
.ontrack.ok { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.ontrack.behind { background: color-mix(in srgb, #ff9f0a 18%, transparent); color: #ff9f0a; }

.trophy {
  display: inline-flex; align-items: center; gap: 6px;
  background: color-mix(in srgb, #ff9f0a 13%, transparent);
  border: 1px solid color-mix(in srgb, #ff9f0a 35%, transparent);
  color: var(--text); font-weight: 700; font-size: .9rem;
  border-radius: 999px; padding: 7px 13px; margin: 3px 4px 3px 0;
}
.trophy .tcost { color: var(--muted); font-weight: 600; font-size: .8rem; }

.pill-note {
  display: inline-block; background: var(--bg-3); color: var(--muted);
  font-size: .84rem; border-radius: 999px; padding: 5px 12px; margin-top: 8px;
}

.momentum {
  background: linear-gradient(135deg, color-mix(in srgb, var(--good) 13%, transparent), color-mix(in srgb, var(--accent) 11%, transparent));
  border-radius: 14px; padding: 12px 15px; margin: 10px 0 4px; font-size: .95rem;
}
.momentum b { color: var(--good); }
.allbar-wrap { margin: 12px 0 2px; }

/* emoji picker sheet */
.ep-overlay {
  position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: epfade .2s;
}
@keyframes epfade { from { opacity: 0; } }
.ep-sheet {
  background: var(--bg-2); border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  width: min(560px, 100%); max-height: 72vh; overflow-y: auto;
  animation: epup .3s cubic-bezier(.32,.72,0,1);
}
@keyframes epup { from { transform: translateY(60px); opacity: .4; } }
.ep-title { font-weight: 800; font-size: 1.05rem; margin: 0 0 10px; }
.ep-custom { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.ep-custom input {
  font: inherit; font-size: 1.3rem; text-align: center;
  background: var(--bg-3); color: var(--text);
  border: none; border-radius: 12px; padding: 8px; width: 74px; outline: none;
}
.ep-custom input:focus { box-shadow: 0 0 0 2px var(--accent); }
.ep-custom .lab { font-size: .85rem; color: var(--muted); }
.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.ep-grid button {
  font-size: 1.55rem; background: var(--bg-3); border: none; border-radius: 12px;
  padding: 8px 0; cursor: pointer; line-height: 1.3; min-height: 48px;
  transition: transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.ep-grid button:active { transform: scale(.85); }
.ep-grid button.current { box-shadow: 0 0 0 2px var(--accent); }

/* celebrations */
.win-overlay {
  position: fixed; inset: 0; z-index: 130; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: epfade .2s;
}
.win-card {
  background: var(--bg-2); border-radius: 26px; padding: 30px 26px;
  max-width: 380px; text-align: center;
  animation: winpop .45s cubic-bezier(.32,1.7,.4,1);
}
.win-card h2 { margin: 8px 0 4px; }
.win-card p { color: var(--muted); margin: 0; }
.win-card p b { color: var(--good); }
.win-emoji { font-size: 3.4rem; animation: winpop .6s cubic-bezier(.32,1.9,.4,1); }
@keyframes winpop { from { transform: scale(.5); opacity: 0; } }

.plus-fly {
  position: fixed; font-weight: 800; color: var(--good); z-index: 95;
  animation: fly 1s ease-out forwards; pointer-events: none; font-size: 1.3rem;
}
.plus-fly.bad-fly { color: var(--bad); }
@keyframes fly { to { transform: translateY(-70px); opacity: 0; } }

/* sparkline */
.spark { width: 100%; height: 110px; display: block; margin-top: 10px; }

/* site footer — disclosure */
.site-footer {
  max-width: 700px; margin: 0 auto;
  padding: 8px 20px calc(28px + env(safe-area-inset-bottom));
}
.site-footer p {
  font-size: .78rem; color: var(--muted); line-height: 1.6; margin: 0;
  border-top: 0.5px solid var(--line); padding-top: 16px;
}
.site-footer a { color: var(--muted); text-decoration: underline; }

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

@media (max-width: 420px) {
  body { font-size: 16px; }
  h1 { font-size: 1.85rem; }
  .big { font-size: 2.2rem; }
  .poem { font-size: 1.05rem; }
  main { padding: 12px 12px calc(64px + env(safe-area-inset-bottom)); }
  .card { padding: 15px 16px; border-radius: 14px; margin: 10px 0; }
  .ob { padding-top: 4vh; }
  .ob-input { font-size: 2.3rem; }
  .btn-row .btn { flex: 1; text-align: center; }
}
