:root {
  --ground: #f6f6f3;
  --card: #ffffff;
  --ink: #1b1f24;
  --muted: #4b5563;
  --faint: #6b7280;
  --line: #e2e5ea;
  --line-strong: #c9ced6;
  --accent: #0b5f7a;
  --accent-dark: #08465a;
  --accent-soft: #e3f0f4;
  --info: #eaf3f6;
  --good: #2f855a;
  --good-soft: #edf7f0;
  --warn: #b45309;
  --bad: #9a3412;
  --bad-soft: #fdf0e9;
  --warn-soft: #fdf4e3;
  --critical: #b42318;
  --critical-soft: #fbeceb;
  --zero: #a1a7b0;
  /* Fixed colours that were written inline, now named so dark mode can change them. */
  --on-accent: #ffffff;   /* text on an accent background */
  --surface: #ffffff;     /* inputs and unselected buttons */
  --header-bg: rgba(246, 246, 243, .86);  /* the fixed header: the page ground, slightly see-through */
  --scrim: rgba(27, 31, 36, .35);         /* behind the phone menu */
  --panel: #f5f6f4;       /* figure boxes inside cards */
  --subtle: #fbfbf9;      /* recipe rows, text areas */
  --th: #f1f3f5;          /* table headings */
  --body: #374151;        /* longer body text in cards */
  --good-ink: #1e5b3a;
  --warn-ink: #7a3d06;
  --bad-ink: #8a1c13;
  --focus: #7cc4dc;
  /* Charts: the bands are neutral so the coloured lines stand out. Checked with the dataviz
     palette validator (hardest vs typical vs what you want vs ran out, and against the bands). */
  --band-mid: #d3d9e0;
  --band-range: #eef1f4;
  --chart-hi: #0e7490;
  --chart-median: #374151;
  --chart-want: #3d9a50;
  --chart-floor: #8a939e;
  --mix-s: #0b5f7a;      /* mix bars: shares teal, bonds violet, cash grey (dark to light) */
  --mix-b: #8b7fd1;
  --mix-c: #cfd4da;
  --person-you: #e1f5ee;       /* the You card's person badge */
  --person-you-ink: #085041;
  --person-partner: #eeedfe;   /* the partner card's person badge */
  --person-partner-ink: #3c3489;
  --shadow: rgba(0, 0, 0, .10);
  --shadow-strong: rgba(0, 0, 0, .2);
  --backdrop: rgba(27, 31, 36, .45);
  color-scheme: light;
  --radius: 12px;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Space Grotesk", Inter, system-ui, sans-serif;
}

/* Dark mode: soft dark grey. Set on <html data-theme="dark"> by the switch (Auto follows the
   device). Status colours keep their meaning, lightened to stay clear on dark grey. */
:root[data-theme="dark"] {
  --ground: #1b1e22;
  --card: #24282d;
  --ink: #e6e8eb;
  --muted: #b0b6be;
  --faint: #959ba4;
  --line: #363b42;
  --line-strong: #4b525b;
  --accent: #5bbad6;
  --accent-dark: #8fd3e8;
  --accent-soft: #1d3a44;
  --info: #1e333b;
  --good: #5cc28c;
  --good-soft: #1c3428;
  --warn: #e3a34f;
  --bad: #ec9168;
  --bad-soft: #3c271e;
  --warn-soft: #3a2f1c;
  --critical: #f2786d;
  --critical-soft: #3e2426;
  --zero: #6f7680;
  --on-accent: #0e1b20;
  --surface: #1e2226;
  --header-bg: rgba(27, 30, 34, .86);
  --scrim: rgba(0, 0, 0, .45);
  --panel: #2c3136;
  --subtle: #212529;
  --th: #2c3136;
  --body: #ccd0d6;
  --good-ink: #a9e5c3;
  --warn-ink: #f4d199;
  --bad-ink: #f8b9b2;
  --focus: #5bbad6;
  --band-mid: #444b53;
  --band-range: #30353b;
  --chart-hi: #5bbad6;
  --chart-median: #e3e6ea;
  --chart-want: #9ad66a;
  --chart-floor: #8d949c;
  --mix-s: #5bbad6;
  --mix-b: #a99ce6;
  --mix-c: #5d646e;
  --person-you: #163f37;       /* the You card's person badge */
  --person-you-ink: #9fe1cb;
  --person-partner: #302c5e;   /* the partner card's person badge */
  --person-partner-ink: #cecbf6;
  --shadow: rgba(0, 0, 0, .35);
  --shadow-strong: rgba(0, 0, 0, .55);
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* Navy: the .wealth palette (navy grounds, violet accent, mint / coral / red status). */
:root[data-theme="navy"] {
  --ground: #25253f;
  --card: #303050;
  --ink: #ffffff;
  --muted: #c8c8e8;
  --faint: #a9abcf;
  --line: #44446a;
  --line-strong: #56568a;
  --accent: #a8a3ff;
  --accent-dark: #c9c6ff;
  --accent-soft: #3e3d6a;
  --info: #353560;
  --good: #4eedb0;
  --good-soft: #26404a;
  --warn: #f5c46b;
  --bad: #ff9f6b;
  --bad-soft: #4a3346;
  --warn-soft: #463d48;
  --critical: #ff8080;
  --critical-soft: #4c2f48;
  --zero: #7a7ba3;
  --on-accent: #1d1c3a;
  --surface: #2a2a47;
  --header-bg: rgba(37, 37, 63, .86);
  --scrim: rgba(12, 12, 30, .5);
  --panel: #3e3d6a;
  --subtle: #2c2c4a;
  --th: #393862;
  --body: #dcdcf2;
  --good-ink: #a6f5d6;
  --warn-ink: #fbe0ad;
  --bad-ink: #ffc4c4;
  --focus: #a8a3ff;
  --band-mid: #4b4f70;
  --band-range: #393b5c;
  --chart-hi: #a8a3ff;
  --chart-median: #e6e6f5;
  --chart-want: #4eedb0;
  --chart-floor: #9a9ab8;
  --mix-s: #a8a3ff;
  --mix-b: #60a5fa;
  --mix-c: #6e6f96;
  --person-you: #174a43;       /* the You card's person badge */
  --person-you-ink: #a6e8d2;
  --person-partner: #3d3880;   /* the partner card's person badge */
  --person-partner-ink: #dcd9fb;
  --shadow: rgba(0, 0, 0, .35);
  --shadow-strong: rgba(0, 0, 0, .55);
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ======================================================================
   Will it last? Phone first: one column, at most 640px wide on bigger screens.
   Colour is used only for status (good / lean / short), always with an icon and words.
   ====================================================================== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; overflow-anchor: none; } /* the answer page keeps its slider still itself */
body { margin: 0; background: var(--ground); color: var(--ink); font: 16px/1.5 var(--sans); }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 40; background: var(--header-bg); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top-in { max-width: 640px; margin: 0 auto; height: 60px; padding: 0 8px 0 16px; display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); border-radius: 8px; min-height: 44px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.brand-mark circle { fill: currentColor; }
.brand-name { font: 600 17px/1 var(--display); }
/* On inner pages the arrow and the page title are one link back to the answer. */
.back { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; min-height: 44px; margin-left: -10px; padding-right: 8px; border-radius: 10px; color: var(--ink); text-decoration: none; }
.back-arrow { width: 44px; height: 44px; display: grid; place-items: center; flex: none; color: var(--accent); }
.back-arrow svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.brand { margin-right: auto; }
.top-title { font: 600 17px/1.2 var(--display); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 10px; background: none; color: var(--accent); display: grid; place-items: center; cursor: pointer; flex: none; text-decoration: none; }
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#menu-btn { margin-left: auto; }
.icon-btn.small { width: 40px; height: 40px; color: var(--muted); }
.icon-btn.small svg { width: 16px; height: 16px; }
.icon-btn.confirm { background: var(--critical-soft); color: var(--critical); }

/* ---------- page ---------- */
.page { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
.view { display: flex; flex-direction: column; gap: 16px; }
h1 { font: 600 30px/1.15 var(--display); letter-spacing: -.01em; }
.lead { font-size: 16px; color: var(--body); }
.hint { font-size: 14px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { font-size: 17px; line-height: 1.3; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.link { background: none; border: 0; padding: 0; min-height: 44px; display: inline-flex; align-items: center; color: var(--accent); font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; align-self: flex-start; }
.link:hover { text-decoration: underline; }
.link.inline { min-height: 0; display: inline; font-size: inherit; }
.link.danger { color: var(--bad); }
.primary { min-height: 52px; padding: 0 22px; border: 0; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px; cursor: pointer; }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: .7; cursor: progress; }
.secondary { min-height: 48px; padding: 0 18px; border: 1px solid var(--accent); border-radius: 12px; background: transparent; color: var(--accent); font-weight: 600; font-size: 15px; cursor: pointer; }
.secondary:hover { background: var(--accent-soft); }
.secondary[aria-disabled="true"] { border-color: var(--line-strong); color: var(--muted); cursor: default; background: transparent; }
.spinner { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---------- 1. three questions ---------- */
.intro { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.questions { gap: 18px; padding: 20px; }
.q { display: flex; flex-direction: column; gap: 6px; }
.q label { font-weight: 600; font-size: 16px; }
input { font: inherit; font-size: 16px; padding: 11px 12px; min-height: 48px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); width: 100%; }
input[aria-invalid="true"] { border-color: var(--critical); }
.big-input { font-size: 20px; font-weight: 600; min-height: 54px; padding: 12px 14px; }
input.short { max-width: 140px; }
.field-err { color: var(--critical); font-size: 14px; font-weight: 500; }
/* "Your details": a card for you, one for your partner, one for the plan. Each row shows its
   value (a guess we made says so). */
.details { display: flex; flex-direction: column; gap: 12px; }
.details-hint { font-size: 13px; margin-bottom: -4px; }
.person { gap: 0; padding: 14px 18px 6px; }
.person-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; min-height: 40px; }
.person-head h2 { font-size: 17px; flex: 1; min-width: 0; }
.person-head .link { min-height: 40px; font-size: 14px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.avatar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
/* You and your partner: the same person shape in two colours, kept clear of the status colours. */
.avatar.you { background: var(--person-you); color: var(--person-you-ink); }
.avatar.partner { background: var(--person-partner); color: var(--person-partner-ink); }
.person.empty { padding: 0; border-style: dashed; border-color: var(--line-strong); background: transparent; }
.add-partner { width: 100%; min-height: 56px; border: 0; border-radius: 16px; background: none; color: var(--accent); font-weight: 600; font-size: 16px; cursor: pointer; }
.add-partner:hover { background: var(--accent-soft); }
.detail-row { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 0; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; color: var(--ink); font-size: 15px; }
.detail-row > svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.detail-row:hover .d-label { color: var(--accent); }
.d-label { flex: 1 1 auto; min-width: 0; }
.d-value { flex: 0 1 auto; max-width: 58%; text-align: right; font-weight: 600; }
.d-guess { display: block; font-size: 12px; font-weight: 400; color: var(--muted); line-height: 1.3; } /* "(assumed)" sits under the value */
.d-add { color: var(--accent); font-weight: 600; }
.person .field-err { margin: 4px 0 8px; }
.details > .field-err { margin: -4px 4px 0; }
.saved-link { align-self: flex-start; min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--card); color: var(--accent); font-weight: 600; font-size: 14px; cursor: pointer; }
/* The button stays at the bottom of the screen on the first page. */
.go-bar { position: sticky; bottom: 0; z-index: 20; margin: 8px -16px calc(-40px - env(safe-area-inset-bottom)); padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.go { width: 100%; min-height: 54px; font-size: 17px; }

/* When the market history cannot be downloaded: plain words and a way to try again. */
.load-fail { border-color: var(--warn); background: var(--warn-soft); }
.load-fail-head { display: flex; align-items: center; gap: 12px; }
.load-fail-head h2 { font: 600 20px/1.25 var(--display); color: var(--warn-ink); }
.load-fail-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--warn); display: grid; place-items: center; flex: none; }
.load-fail-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--card); stroke-width: 2.4; stroke-linecap: round; }
.load-fail .primary { align-self: flex-start; }
.load-fail .hint { color: var(--body); }
/* Until the data arrives there is nothing to fill in, so the form and details stay hidden. */
.not-ready #start-form, .not-ready #details, .not-ready .go-bar, .not-ready #saved-link { display: none; }

/* ---------- 2. the answer ---------- */
/* The answer page's summary of your answers: one tappable card, back to the details. */
.ans-top { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 10px 12px 10px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); text-decoration: none; }
.ans-top:hover, .ans-top:focus-visible { border-color: var(--accent); }
.ans-top-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ans-top-label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.ans-top-main { font-weight: 600; font-size: 15px; }
.ans-top-sub { color: var(--muted); font-size: 14px; }
.ans-top-edit { flex: none; color: var(--accent); font-weight: 600; font-size: 15px; }
.ans-top svg { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#ans-top, #ans-rest { display: flex; flex-direction: column; gap: 16px; }
.picked { font-size: 14px; color: var(--muted); }
.verdict { border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 10px; transition: opacity .15s; }
.busy .verdict, .busy .figs, .busy .chart-card { opacity: .55; }
.verdict.good { background: var(--good-soft); }
.verdict.warn { background: var(--warn-soft); }
.verdict.bad { background: var(--critical-soft); }
.verdict-head { display: flex; align-items: center; gap: 12px; }
.verdict-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.verdict-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--card); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.good .verdict-icon { background: var(--good); }
.warn .verdict-icon { background: var(--warn); }
.bad .verdict-icon { background: var(--critical); }
.verdict h1 { font-size: 26px; }
.verdict.good h1 { color: var(--good-ink); }
.verdict.warn h1 { color: var(--warn-ink); }
.verdict.bad h1 { color: var(--bad-ink); }
.verdict p { font-size: 16px; }
.verdict-extra { color: var(--body); }
.fix h2 { font-size: 17px; }
.fix-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.fix-list li { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.fix-list li:first-child { border-top: 0; padding-top: 0; }
.fix-list .secondary { align-self: flex-start; }
.fix-wait { color: var(--muted); font-size: 14px; flex-direction: row !important; align-items: center; }
.slider-card { gap: 6px; }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.slider-head label { font-weight: 600; }
.slider-head output { font: 600 22px/1 var(--display); color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] { padding: 0; border: 0; background: none; min-height: 44px; accent-color: var(--accent); width: 100%; }
.slider-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: -6px; }
.figs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.figs.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fig { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.card .fig, .way .fig, .story-body .fig { background: var(--panel); border: 0; }
.fig .k { font-size: 12px; color: var(--muted); }
.fig .v { font: 600 19px/1.25 var(--display); font-variant-numeric: tabular-nums; }
.fig .s { font-size: 12px; color: var(--muted); }
.figs.small .fig .v { font-size: 16px; }
.how { border: 2px solid var(--accent); }
.how h2 { font: 600 20px/1.25 var(--display); margin-top: -6px; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 12px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 26px 1fr; gap: 12px; align-items: start; color: var(--body); }
.steps li::before { content: counter(step); width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; font-size: 14px; display: grid; place-items: center; }
.steps strong { color: var(--ink); }
.steps.small { gap: 8px; font-size: 14px; }
.steps.small li { grid-template-columns: 22px 1fr; gap: 10px; }
.steps.small li::before { width: 22px; height: 22px; font-size: 12px; }
.next-links { display: flex; flex-direction: column; gap: 10px; }
.next-link { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 12px 0 18px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; }
.next-link svg { width: 20px; height: 20px; margin-left: auto; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.next-link .count { margin-left: auto; font-size: 15px; font-weight: 500; color: var(--muted); }
.next-link .count + svg { margin-left: 2px; }
.save { width: 100%; }
/* Shown in place of "Save this plan" once it is saved. */
.saved-done { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.saved-done-title { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; font-size: 16px; color: var(--good-ink, var(--ink)); }
.saved-done-title svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.saved-done-text { margin: 0; color: var(--muted); font-size: 14px; }
.saved-done .link { margin-top: 4px; min-height: 40px; }

/* ---------- charts (ui/charts.js) ---------- */
.chart-card { padding: 18px 14px; }
.chart-card h2 { padding: 0 4px; }
.chart-wrap { position: relative; }
.chart-wrap > svg { width: 100%; height: auto; display: block; }
.chart-wrap svg { touch-action: pan-y; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
.chart-wrap svg:focus { outline: none; }
.chart-wrap svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart-tip { position: absolute; top: 8px; min-width: 190px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 4px 16px var(--shadow); padding: 10px 12px; font-size: 13px; pointer-events: none; display: flex; flex-direction: column; gap: 3px; z-index: 2; }
.tip-head { font-weight: 600; color: var(--muted); font-size: 12px; }
.tip-head .tip-note { font-weight: 400; }
/* The readout: the year, then the two lines (hardest start, typical) side by side, then the bands. */
.tip-main { display: flex; flex-wrap: wrap; gap: 2px 18px; align-items: baseline; }
.tip-main > span { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; color: var(--muted); }
.tip-main strong { color: var(--ink); font-size: 15px; font-variant-numeric: tabular-nums; }
.tip-main .tip-hi strong { color: var(--chart-hi); }
.tip-main .tip-hi.ran-out strong { color: var(--critical); }
:root[data-theme="navy"] .tip-main .tip-hi:not(.ran-out) strong { color: #b6b2ff; }
:root[data-theme="navy"] .tip-main .tip-hi.ran-out strong { color: #ffa3a3; } /* the readout's panel is darker than a card */
.tip-sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-wrap.is-phone .chart-tip { position: static; min-width: 0; box-shadow: none; background: var(--panel); border: 0; margin-bottom: 8px; padding: 8px 12px; gap: 3px; min-height: 100px; justify-content: center; } /* tall enough for a wrapped line, so the chart never jumps */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); padding: 0 4px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend .key { display: inline-block; width: 18px; height: 0; border-top: 3px solid; }
.legend .key.accent { border-color: var(--chart-hi); }
.legend .key.median { border-top-width: 1.5px; border-color: var(--chart-median); }
.legend .key.bad { border-top-width: 1.5px; border-color: var(--critical); }
.legend .key.bad-strong { border-color: var(--critical); }
.legend .key.k-dash { border-top: 2px dashed var(--chart-want); }
.legend .key.k-dot { border-top: 3px dotted var(--chart-floor); }
.legend .box { display: inline-block; width: 14px; height: 9px; border-radius: 2px; }
.legend .box.mid { background: var(--band-mid); }
.legend .box.range { background: var(--band-range); }
.wide-only { display: block; }
@media (max-width: 600px) { .wide-only { display: none; } }

/* ---------- 3. other ways ---------- */
/* Cards swipe sideways, one at a time, with the next one peeking in. */
.ways { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 4px 16px 8px; scroll-padding: 0 16px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.ways::-webkit-scrollbar { display: none; }
.way { flex: 0 0 86%; scroll-snap-align: start; background: var(--card); border: 1px solid var(--line-strong); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.way-head { display: flex; flex-direction: column; gap: 4px; }
.way-head h2 { font: 600 21px/1.2 var(--display); }
.way-head p { color: var(--body); font-size: 15px; }
.way-verdict { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.way-verdict svg { width: 18px; height: 18px; flex: none; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.way-verdict.good { color: var(--good-ink); } .way-verdict.good svg { stroke: var(--good); }
.way-verdict.warn { color: var(--warn-ink); } .way-verdict.warn svg { stroke: var(--warn); }
.way-verdict.bad { color: var(--bad-ink); } .way-verdict.bad svg { stroke: var(--critical); }
.trade { font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--panel); color: var(--body); }
.use { margin-top: auto; width: 100%; }
.dots { display: flex; justify-content: center; gap: 8px; }
.dots span { width: 8px; height: 8px; border-radius: 4px; background: var(--line-strong); transition: width .15s; }
.dots span.on { width: 22px; background: var(--accent); }
.glance { padding: 6px 16px; }
.glance table { width: 100%; border-collapse: collapse; font-size: 14px; }
.glance th, .glance td { text-align: left; padding: 10px 6px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.glance thead th { font-size: 12px; font-weight: 400; color: var(--muted); }
.glance tbody th { font-weight: 500; }
.glance tbody tr:last-child > * { border-bottom: 0; }
.glance td { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.glance tr.current > * { background: var(--accent-soft); }
.glance tr.current th { padding-left: 8px; }
/* Each row of "At a glance" takes you to that card above. */
.glance tbody tr { cursor: pointer; }
.glance tbody tr:hover > * { background: var(--accent-soft); }
.glance-go { all: unset; display: block; font-weight: 500; cursor: pointer; }
.glance-go:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.glance .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.warn-text { color: var(--bad) !important; }

/* ---------- 4. every past retirement ---------- */
/* Counts first, then only the years that went wrong (in words), then a bar for every year. */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile.good { background: var(--good-soft); color: var(--good-ink); }
.tile.warn { background: var(--warn-soft); color: var(--warn-ink); }
.tile.bad { background: var(--critical-soft); color: var(--bad-ink); }
.tile-n { display: flex; align-items: center; gap: 8px; }
.tile-n strong { font: 600 24px/1 var(--display); }
.tile-k { font-size: 13px; }
.yr-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.yr-icon.small { width: 22px; height: 22px; }
.yr-icon svg { width: 14px; height: 14px; fill: none; stroke: var(--card); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.yr-icon.small svg { width: 11px; height: 11px; }
.yr-icon.good { background: var(--good); } .yr-icon.warn { background: var(--warn); } .yr-icon.bad { background: var(--critical); }
.yr-list { gap: 0; padding-bottom: 6px; }
.yr-list h2 { margin-bottom: 8px; }
.yr-list .yr-sub { margin-top: 16px; }
.yr-list > .hint { margin-bottom: 4px; }
.yr-row { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 0; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; color: var(--ink); }
.yr-row > svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.yr-row:hover .yr-name strong { color: var(--accent); }
.yr-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.yr-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.yr-name strong { font-size: 16px; }
.yr-line { font-size: 14px; color: var(--muted); }
.yr-line.warn { color: var(--warn-ink); } .yr-line.bad { color: var(--bad-ink); }
.more-years summary { min-height: 48px; display: flex; align-items: center; border-top: 1px solid var(--line); color: var(--accent); font-weight: 600; cursor: pointer; }
.bars-wrap { display: flex; flex-direction: column; gap: 8px; }
.bars-readout { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--panel); font-size: 14px; }
.bars-idle { color: var(--muted); }
.bars-pick { display: flex; flex-direction: column; min-width: 0; }
.bars-pick strong { font: 600 17px/1.2 var(--display); }
.b-line { color: var(--muted); } .b-line.warn { color: var(--warn-ink); } .b-line.bad { color: var(--bad-ink); }
.small-btn { min-height: 40px; padding: 0 12px; font-size: 14px; flex: none; }
.bars-svg { width: 100%; }
.bars-svg svg { display: block; touch-action: pan-y; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; cursor: pointer; }
.bars-svg svg:focus { outline: none; }
.bars-svg svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.b-grid { stroke: var(--line); }
.b-axis { font-size: 12px; fill: var(--muted); }
.b-good { fill: var(--accent); fill-opacity: .75; }
.b-warn { fill: var(--warn); }
.b-bad { fill: var(--critical); }
.b-sel { fill: var(--accent-soft); stroke: var(--ink); stroke-width: 1.2; }
.b-bracket { fill: none; stroke: var(--bad-ink); stroke-width: 1.2; }
.b-bracket-text { font-size: 12px; font-weight: 600; fill: var(--bad-ink); }
.legend .box.b-good { background: var(--accent); opacity: .75; width: 10px; height: 14px; }
.legend .box.b-warn { background: var(--warn); width: 10px; height: 14px; }
.legend .box.b-bad { background: var(--critical); width: 10px; height: 6px; }
.story-body { display: flex; flex-direction: column; gap: 12px; }
.story-body h2 { font: 600 22px/1.2 var(--display); }
.story-label { margin: -36px 48px 0 0; min-height: 26px; display: flex; align-items: center; color: var(--muted); }
/* The result line, with the same icon and colour as the row it was opened from. */
.story-status { display: flex; align-items: center; gap: 8px; margin: -4px 0 0; font-weight: 600; font-size: 15px; color: var(--good-ink); }
.story-status.warn { color: var(--warn-ink); } .story-status.bad { color: var(--bad-ink); }
.by-year summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none; border-top: 1px solid var(--line); }
.by-year[open] summary { margin-bottom: 4px; }
.table-box { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.year-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.year-table th { text-align: left; font-weight: 600; background: var(--th); padding: 8px 10px; }
.year-table td { padding: 7px 10px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.year-table .num { text-align: right; }
.year-table tr.warn td { background: var(--warn-soft); }
.year-table tr.bad td { background: var(--critical-soft); }

/* ---------- sheets (bottom sheets on phones, centred on wider screens) ---------- */
.sheet { border: 0; padding: 0; margin: auto auto var(--kb, 0px); width: 100%; max-width: 640px; max-height: 88vh; max-height: calc(92dvh - var(--kb, 0px)); overflow-y: auto; overscroll-behavior: contain; border-radius: 20px 20px 0 0; background: var(--card); color: var(--ink); box-shadow: 0 -8px 30px var(--shadow-strong); }
.sheet::backdrop { background: var(--backdrop); }
/* A long sheet (a past retirement) grows to fit what it shows, up to nearly the full height. */
.sheet.tall { max-height: 92vh; max-height: 92dvh; }
.sheet.tall .sheet-in { padding-top: 8px; }
.sheet-close { position: sticky; top: 0; z-index: 3; display: flex; justify-content: flex-end; margin: 0 -10px -6px 0; }
.sheet-close .icon-btn { background: var(--card); border-radius: 50%; }
.sheet-in { padding: 22px 18px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.sheet h2 { font: 600 21px/1.25 var(--display); }
.sheet-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.sheet-actions .primary { min-width: 100px; margin-left: auto; }
.sheet-actions .cancel { margin-left: auto; min-height: 52px; }
.sheet-actions .cancel + .primary { margin-left: 0; }
.row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { min-height: 48px; min-width: 64px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-size: 16px; }
.opt[aria-checked="true"] { border: 2px solid var(--accent); background: var(--accent-soft); }
.opt.wide { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; }
.opt-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt-label { font-weight: 600; }
.opt-about { font-size: 13px; color: var(--muted); }
.mix-bar { display: flex; width: 64px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); flex: none; }
.mix-bar .s { background: var(--mix-s); } .mix-bar .b { background: var(--mix-b); } .mix-bar .c { background: var(--mix-c); }
.tip { padding: 10px 12px; border-radius: 10px; background: var(--info); color: var(--body); }
.own { display: flex; flex-direction: column; gap: 10px; }
.menu-sec { display: flex; flex-direction: column; gap: 8px; }
/* A menu row looks like the rows on the first page: something to tap, not a heading. */
.menu-sec h3 { font-size: 15px; }
.saved { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.saved li { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line); }
.saved li:first-child { border-top: 0; }
.saved-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 10px 0; cursor: pointer; display: flex; flex-direction: column; }
.saved-open strong { font-size: 15px; }
.saved-open span { font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; align-self: flex-start; }
.seg button { min-height: 44px; padding: 8px 16px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-size: 14px; }
.seg button:first-child { border-radius: 10px 0 0 10px; }
.seg button:last-child { border-radius: 0 10px 10px 0; }
.seg button + button { margin-left: -1px; }
.seg button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); position: relative; }
@media (min-width: 700px) {
  /* On wider screens sheets float in the middle, kept to about a phone's width. */
  .sheet { margin: auto; border-radius: 20px; max-width: 460px; }
  .sheet.tall { max-width: 460px; max-height: 88vh; }
}

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 20px var(--shadow-strong); }

/* "How it works" on the result pages */
#help-body { display: flex; flex-direction: column; gap: 18px; }
.help-lead { margin: 0; }
.help-sec { display: flex; flex-direction: column; }
.help-sec-label { color: var(--muted); margin-bottom: 2px; }
.help-list { list-style: none; margin: 0; padding: 0; }
.help-item { display: flex; align-items: flex-start; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.help-item:last-child { border-bottom: 0; }
.help-mark { flex: none; width: 24px; min-height: 22px; padding: 0; display: flex; align-items: center; justify-content: center; }
.help-mark .key { width: 22px; }
.help-mark .box { width: 18px; height: 12px; }
.help-mark .box.b-good { width: 10px; height: 16px; }
.help-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.help-text strong { font-weight: 600; color: var(--ink); }
.help-text > span { color: var(--body); line-height: 1.45; }
/* Terms shown in the style they have on screen */
.help-k-tag { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent) !important; }
.help-k-warn { color: var(--warn-ink) !important; }
.help-k-guess { font-weight: 400 !important; color: var(--muted) !important; }
/* The method, folded away */
.help-method { border-top: 1px solid var(--line); padding-top: 4px; font-size: 14px; color: var(--muted); line-height: 1.6; }
.help-method summary { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-weight: 600; font-size: 15px; color: var(--accent); list-style: none; }
.help-method summary::-webkit-details-marker, .by-year summary::-webkit-details-marker { display: none; }
/* A chevron that points down when folded and up when open, so it reads as something to open. */
.help-method summary::after, .by-year summary::after { content: ""; width: 9px; height: 9px; margin-right: 6px; border-right: 2.2px solid currentColor; border-bottom: 2.2px solid currentColor; transform: translateY(-3px) rotate(45deg); transition: transform .15s; }
.help-method[open] summary::after, .by-year[open] summary::after { transform: translateY(2px) rotate(-135deg); }
@media (prefers-reduced-motion: reduce) { .help-method summary::after, .by-year summary::after { transition: none; } }
.help-method p { margin: 0 0 8px; }
.help-source { font-size: 13px; }
.help-title { margin-top: -40px; padding-right: 48px; min-height: 30px; }

@media (min-width: 700px) {
  h1 { font-size: 34px; }
  .page { padding-top: 28px; }
  .way { flex-basis: 80%; }
}

/* ---------- welcome screen (first visit only) ----------
   Always dark, whatever the theme, to sit on its picture. On wider screens the picture stays a
   phone-shaped column in the middle. */
.intro-on .top, .intro-on #page, .intro-on .toast { display: none !important; }
.welcome { position: relative; min-height: 100vh; min-height: 100dvh; background: #1c1b37; color: #ffffff; }
.welcome-in { position: relative; max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; box-sizing: border-box;
  padding: calc(40px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 22px;
  background: #1c1b37 url("img/intro.webp?v=10e0ee5") center bottom / cover no-repeat; }
.welcome-mark { width: 44px; height: 44px; border-radius: 12px; background: #3e3d6a; display: grid; place-items: center; }
.welcome-mark svg { width: 26px; height: 26px; fill: none; stroke: #a8a3ff; stroke-width: 2.4; stroke-linecap: round; }
.welcome-mark circle { fill: #a8a3ff; }
.welcome h1 { font: 600 32px/1.12 var(--display); color: #ffffff; }
.welcome h1:focus { outline: none; }
.welcome-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 20px; }
.welcome-steps li { display: grid; grid-template-columns: 34px 1fr; gap: 14px; align-items: start; }
.welcome-n { width: 34px; height: 34px; border-radius: 50%; background: #3e3d6a; color: #a8a3ff; font-weight: 700; display: grid; place-items: center; }
.welcome-steps li > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.welcome-steps strong { font-size: 17px; color: #ffffff; }
.welcome-steps li > span:last-child > span { font-size: 15px; line-height: 1.45; color: #c8c8e8; }
.welcome-foot { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.welcome-private { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; color: #c8c8e8; }
.welcome-private svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.welcome-go { min-height: 56px; border: 0; border-radius: 14px; background: #a8a3ff; color: #1d1c3a; font-size: 18px; font-weight: 600; cursor: pointer; }
.welcome-go:hover { background: #c9c6ff; }
.welcome-go:focus-visible { outline: 3px solid #ffffff; outline-offset: 3px; }

/* "A newer version is ready. Refresh": shown when an upload goes live while the page is open. */
.update-bar { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 16px; border-radius: 12px; background: var(--ink); color: var(--ground); font-size: 14px; box-shadow: 0 6px 20px var(--shadow-strong); max-width: calc(100% - 32px); }
/* keep the message on one line */
.update-bar span { white-space: nowrap; }
.update-go { flex: none; min-height: 40px; padding: 0 14px; border: 0; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer; }
#clear-all.confirm { color: var(--critical); }

/* The ? in the header (see ui/app.js help-btn): the welcome screen on the first page, the page's help elsewhere. */
.help-btn { margin-left: auto; margin-right: -4px; }
.help-btn + #menu-btn { margin-left: 0; }
.help-title:focus { outline: none; }
