/* Steady Money v2 — calm, low-clutter, AuDHD-friendly.
   Layout is chosen by device.js (width breakpoints + pointer/hover media queries)
   and written to <html data-device="phone|tablet|desktop" data-orient="...">.
   Each device has its own layout below, not a squeezed desktop page. */

:root {
  --bg: #0f1720;
  --bg-2: #141e29;
  --card: #18232f;
  --card-2: #1c2836;
  --line: rgba(220, 232, 245, 0.08);
  --line-2: rgba(220, 232, 245, 0.14);
  --text: #e6edf5;
  --muted: #9aabbd;
  --faint: #6c7d90;
  --ok: #7fd1a8;          /* calm green */
  --ok-bg: rgba(127, 209, 168, 0.10);
  --ok-line: rgba(127, 209, 168, 0.35);
  --short: #f2998c;       /* soft red, not alarm red */
  --short-bg: rgba(242, 153, 140, 0.10);
  --short-line: rgba(242, 153, 140, 0.38);
  --info: #9db7f5;
  --info-bg: rgba(157, 183, 245, 0.10);
  --info-line: rgba(157, 183, 245, 0.35);
  --old: #e3c27a;
  --focus: #b9d4ff;
  --radius: 20px;
  --radius-sm: 14px;
  --tap: 52px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, "Inter", Roboto, sans-serif;
  --num: "SF Pro Display", -apple-system, "Segoe UI", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --bg-2: #eef2f5; --card: #ffffff; --card-2: #f7f9fb;
    --line: rgba(20, 35, 50, 0.08); --line-2: rgba(20, 35, 50, 0.14);
    --text: #18232f; --muted: #52637a; --faint: #7a8a9c;
    --ok: #1f7a54; --ok-bg: rgba(31, 122, 84, 0.08); --ok-line: rgba(31, 122, 84, 0.30);
    --short: #b4483a; --short-bg: rgba(180, 72, 58, 0.07); --short-line: rgba(180, 72, 58, 0.30);
    --info: #3557a8; --info-bg: rgba(53, 87, 168, 0.07); --info-line: rgba(53, 87, 168, 0.28);
    --old: #8a6a1c; --focus: #2a5bd7;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--info); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.demo-banner {
  position: sticky; top: 0; z-index: 60;
  background: #e8c97a; color: #241a00;
  font-weight: 700; font-size: 0.82rem; letter-spacing: 0.04em; text-align: center;
  padding: calc(0.4rem + var(--safe-t)) 1rem 0.4rem;
}

/* ---------- shared pieces ---------- */
.shell { padding: 16px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 9px; background: linear-gradient(135deg, var(--ok), var(--info)); display: inline-block; }
.actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  font: inherit; font-size: 0.95rem; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--card); color: var(--text);
}
.btn-quiet { background: transparent; color: var(--muted); white-space: nowrap; }
.lbl-short { display: none; }
html[data-device="phone"] .lbl-long { display: none; }
html[data-device="phone"] .lbl-short { display: inline; }
.btn-quiet:hover { color: var(--text); border-color: var(--line-2); }
.btn-big { min-height: var(--tap); padding: 0 24px; font-size: 1.02rem; background: var(--card-2); }

.switch { display: flex; gap: 6px; }
.switch-btn {
  font: inherit; font-weight: 600; font-size: 0.98rem; color: var(--muted);
  min-height: var(--tap); padding: 0 18px; border-radius: 16px; cursor: pointer;
  border: 1px solid transparent; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.switch-btn[aria-selected="true"] { color: var(--text); background: var(--card-2); border-color: var(--line-2); }
.switch-btn .ico { font-size: 0.8rem; color: var(--faint); }
.switch-btn[aria-selected="true"] .ico { color: var(--ok); }
.switch-btn--all { display: none; }

.rail-key { display: none; }

.view-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; }
.view-head h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.view-tag { font-size: 0.82rem; color: var(--faint); }
.view-tag--private { color: var(--info); }

.hero {
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  border: 1px solid var(--line-2);
  background: var(--card);
  margin-bottom: 12px;
}
.hero--covered { background: var(--ok-bg); border-color: var(--ok-line); }
.hero--short { background: var(--short-bg); border-color: var(--short-line); }
.hero--neutral .hero-amount { color: var(--text); }
.hero--owed { background: var(--info-bg); border-color: var(--info-line); }
.hero-label { margin: 0; font-weight: 700; font-size: 1.02rem; }
.hero--covered .hero-label, .hero--covered .hero-amount { color: var(--ok); }
.hero--short .hero-label, .hero--short .hero-amount { color: var(--short); }
.hero--owed .hero-label, .hero--owed .hero-amount { color: var(--info); }
.hero-amount { margin: 4px 0 0; font-family: var(--num); font-weight: 700; font-size: 3.1rem; line-height: 1.05; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-sub { margin: 2px 0 10px; color: var(--muted); font-size: 0.98rem; }
.hero-math { margin: 6px 0; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.cushion-line { margin: 8px 0; font-size: 0.9rem; color: var(--text); opacity: 0.85; }
.cushion-line span { color: var(--ok); letter-spacing: -2px; }

.nudge { margin: 0 0 14px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--bg-2); border: 1px dashed var(--line-2); color: var(--text); font-size: 0.95rem; }
.nudge-k { display: inline-block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ok); font-weight: 700; margin-right: 6px; }

.cards { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card--quiet { background: transparent; }
.card h3 { margin: 0 0 10px; font-size: 1rem; font-weight: 700; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.h-amt { font-family: var(--num); font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.sub-h { margin: 8px 0 4px; font-size: 0.82rem; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }

.rows { list-style: none; margin: 0 0 10px; padding: 0; }
.rows li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px;
  padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 44px; align-items: baseline;
}
.rows li:last-child { border-bottom: 0; }
.rows--num { counter-reset: n; }
.rows--num li .r-name::before { counter-increment: n; content: counter(n) ". "; color: var(--faint); }
.r-name { overflow-wrap: anywhere; }
.r-amt { font-family: var(--num); font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; white-space: nowrap; }
.r-amt--text { font-family: var(--font); font-weight: 500; color: var(--muted); font-size: 0.92rem; white-space: normal; }
.r-amt.neg { color: var(--short); }
.r-meta { grid-column: 1 / -1; font-size: 0.84rem; color: var(--faint); }
.mask { color: var(--faint); font-size: 0.88em; }
.empty { color: var(--muted); margin: 4px 0 10px; }
.unknown { color: var(--faint); font-style: italic; font-weight: 500; }
.note { font-size: 0.88rem; color: var(--muted); margin: 6px 0 10px; }

.kv { margin: 0 0 10px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--num); font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.kv-strong dt { color: var(--text); font-weight: 600; }
.kv-strong.neg dd { color: var(--short); }
.kv-strong.pos dd { color: var(--ok); }

.stamp { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--faint); }
.stamp .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.stamp--fresh .dot { background: var(--ok); }
.stamp--old { color: var(--old); }
.stamp--old .dot { background: var(--old); }

details.more summary { cursor: pointer; color: var(--info); min-height: 44px; display: flex; align-items: center; font-weight: 600; font-size: 0.95rem; }

.pipeline { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pipeline li { background: var(--bg-2); border-radius: 12px; padding: 8px 4px; text-align: center; color: var(--faint); }
.pipeline li.on { color: var(--text); background: var(--info-bg); }
.p-n { display: block; font-family: var(--num); font-weight: 700; font-size: 1.15rem; }
.p-l { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* privacy curtain */
.view { position: relative; }
.curtain { display: none; }
.is-curtained .curtain {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 48px 20px; border-radius: var(--radius); border: 1px dashed var(--info-line); background: var(--info-bg); text-align: center;
}
.is-curtained .curtain p { margin: 0; color: var(--muted); }
.is-curtained .curtain-body { display: none; }
.hide-again { margin-top: 12px; }

.foot { margin-top: 24px; color: var(--faint); font-size: 0.84rem; }
.foot p { margin: 4px 0; }

/* view enter animation (skipped with reduced motion) */
.slide-l { animation: slideL 0.22s ease-out; }
.slide-r { animation: slideR 0.22s ease-out; }
@keyframes slideL { from { opacity: 0.4; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes slideR { from { opacity: 0.4; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* no-JS fallback: every view stacked */
html[data-device="unknown"] .switch { display: none; }

/* ======================= PHONE (iPhone 18 Pro Max ~440×956) ======================= */
html[data-device="phone"] .shell {
  padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) calc(104px + var(--safe-b)) calc(16px + var(--safe-l));
}
html[data-device="phone"] .demo-banner + .shell { padding-top: 10px; }
html[data-device="phone"] .topbar { margin-bottom: 12px; }
html[data-device="phone"] .actions .btn { min-height: 40px; padding: 0 12px; font-size: 0.88rem; }
html[data-device="phone"] .switch {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-2);
  gap: 6px;
}
html[data-device="phone"] .switch-btn { flex: 1 1 0; flex-direction: column; gap: 2px; min-height: 60px; padding: 4px; font-size: 0.8rem; border-radius: 14px; line-height: 1.15; }
html[data-device="phone"] .switch-btn .ico { font-size: 1rem; }
html[data-device="phone"] .view:not(.is-active) { display: none; }
html[data-device="phone"] .hero-amount { font-size: 3.2rem; }
html[data-device="phone"] .view-head { margin-bottom: 10px; }

/* ======================= TABLET (iPad Pro, 1024×1366 / 1366×1024) ======================= */
html[data-device="tablet"] body { font-size: 1.125rem; }
html[data-device="tablet"] .shell { padding: calc(20px + var(--safe-t)) calc(28px + var(--safe-r)) calc(32px + var(--safe-b)) calc(28px + var(--safe-l)); }
html[data-device="tablet"] .view:not(.is-active) { display: none; }
html[data-device="tablet"] .switch { background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px; padding: 5px; }
html[data-device="tablet"] .switch-btn { min-height: 56px; padding: 0 22px; font-size: 1.02rem; }
html[data-device="tablet"] .hero { padding: 28px 30px 22px; }
html[data-device="tablet"] .hero-amount { font-size: 4rem; }
html[data-device="tablet"] .cards { display: block; columns: 2; column-gap: 16px; }
html[data-device="tablet"] .cards > .card { break-inside: avoid; margin-bottom: 16px; }
html[data-device="tablet"] .card { padding: 22px; }

/* tablet portrait: header row, then a full-width segmented switch */
html[data-device="tablet"][data-orient="portrait"] .topbar { flex-wrap: wrap; }
html[data-device="tablet"][data-orient="portrait"] .switch { order: 3; width: 100%; }
html[data-device="tablet"][data-orient="portrait"] .switch-btn { flex: 1 1 0; }
html[data-device="tablet"][data-orient="portrait"] .hero { display: grid; grid-template-columns: 1fr auto; column-gap: 24px; }
html[data-device="tablet"][data-orient="portrait"] .hero > * { grid-column: 1; }
html[data-device="tablet"][data-orient="portrait"] .hero .hero-amount { grid-column: 1; }

/* tablet landscape: left rail with the switch and the key number, content to the right */
html[data-device="tablet"][data-orient="landscape"] .shell {
  display: grid; grid-template-columns: 290px minmax(0, 1fr); column-gap: 28px;
  grid-template-areas: "top main" "key main" "foot main";
  grid-template-rows: auto auto 1fr;
  align-items: start;
}
html[data-device="tablet"][data-orient="landscape"] .topbar {
  grid-area: top; flex-direction: column; align-items: stretch; gap: 16px;
  position: sticky; top: calc(16px + var(--safe-t));
}
html[data-device="tablet"][data-orient="landscape"] .switch { flex-direction: column; }
html[data-device="tablet"][data-orient="landscape"] .switch-btn { justify-content: flex-start; min-height: 60px; }
html[data-device="tablet"][data-orient="landscape"] .actions { margin-left: 0; flex-wrap: wrap; }
html[data-device="tablet"][data-orient="landscape"] .rail-key {
  grid-area: key; display: block; margin-top: 16px; padding: 16px 18px; border-radius: var(--radius-sm);
  background: var(--bg-2); border: 1px solid var(--line);
}
html[data-device="tablet"][data-orient="landscape"] .views { grid-area: main; }
html[data-device="tablet"][data-orient="landscape"] .foot { grid-area: foot; }
.rail-key-label { margin: 0; font-size: 0.85rem; color: var(--muted); }
.rail-key-amount { margin: 2px 0; font-family: var(--num); font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.rail-key--covered { color: var(--ok); } .rail-key--short { color: var(--short); }
.rail-key-sub { margin: 0; font-size: 0.78rem; color: var(--faint); }

/* ======================= DESKTOP / big monitor ======================= */
html[data-device="desktop"] .shell { max-width: 2400px; margin: 0 auto; padding: 24px 32px 40px; }
html[data-device="desktop"] .topbar { margin-bottom: 24px; padding: 10px 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 22px; }
html[data-device="desktop"] .switch { margin: 0 auto; }
html[data-device="desktop"] .switch-btn--all { display: inline-flex; }
html[data-device="desktop"] .switch-btn { min-height: 48px; }
html[data-device="desktop"] .switch-btn:hover { color: var(--text); }
html[data-device="desktop"] .btn-quiet:hover { background: var(--card); }

/* all three side by side */
html[data-device="desktop"] .views[data-active="all"] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; align-items: start; }
html[data-device="desktop"] .views[data-active="all"] .view {
  background: color-mix(in srgb, var(--bg-2) 60%, transparent); border: 1px solid var(--line); border-radius: 26px; padding: 20px;
}
html[data-device="desktop"] .views[data-active="all"] .hero-amount { font-size: 3.3rem; }

/* one view, full width */
html[data-device="desktop"] .views:not([data-active="all"]) .view:not(.is-active) { display: none; }
html[data-device="desktop"] .views:not([data-active="all"]) .hero-amount { font-size: 4.4rem; }
html[data-device="desktop"] .views:not([data-active="all"]) .cards { display: block; columns: 380px 4; column-gap: 18px; }
html[data-device="desktop"] .views:not([data-active="all"]) .cards > .card { break-inside: avoid; margin-bottom: 18px; }
html[data-device="desktop"] .views:not([data-active="all"]) .hero,
html[data-device="desktop"] .views:not([data-active="all"]) .nudge { max-width: 980px; }

/* desktop single view: key number and next step side by side, cards below */
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); column-gap: 18px; align-items: stretch;
}
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .view-head,
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .cards,
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .curtain,
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .curtain-body { grid-column: 1 / -1; }
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .hero,
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .nudge { max-width: none; margin-bottom: 18px; }
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .nudge { display: flex; flex-direction: column; justify-content: center; font-size: 1.1rem; padding: 24px; }
html[data-device="desktop"] .views:not([data-active="all"]) .view.is-active > .hero:not(:has(+ .nudge)) { grid-column: 1 / -1; }
.p-l { white-space: nowrap; font-size: 0.6rem; letter-spacing: 0.02em; }
/* the rail repeats the key number only while another view is open */
html[data-device="tablet"][data-orient="landscape"] .shell:has(.views[data-active="personal"]) .rail-key { display: none; }

/* big monitors: scale type with the screen (16px at 1920 wide, about 20px at 2560) */
html[data-device="desktop"] { font-size: clamp(16px, 0.625vw + 4px, 22px); }

/* lock screen */
.lock-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b)); }
.lock-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line-2); border-radius: 26px; padding: 32px 28px; }
.lock-card h1 { margin: 22px 0 4px; font-size: 1.8rem; }
.lock-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.lock-card input {
  font: inherit; font-size: 1.2rem; min-height: 56px; padding: 0 16px; border-radius: 16px;
  border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text);
}
.lock-card .btn-big { width: 100%; min-height: 56px; background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.lock-msg { margin: 14px 0 0; padding: 12px 14px; border-radius: 14px; background: var(--bg-2); color: var(--text); }
