/* ============ Design tokens (light first, dark via media query + toggle) ============ */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --c-oki: #2a78d6;      /* categorical slot 1 */
  --c-reg: #eb6834;      /* categorical slot 2 */
  --c-hyb: #1baf7a;      /* categorical slot 3: hybrid strategy */
  --c-pos: #2a78d6;      /* diverging pole: OKI ahead */
  --c-neg: #e34948;      /* diverging pole: OKI behind */
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --wash: rgba(42, 120, 214, 0.08);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --c-oki: #3987e5;
    --c-reg: #d95926;
    --c-hyb: #199e70;
    --c-pos: #3987e5;
    --c-neg: #e66767;
    --accent: #3987e5;
    --wash: rgba(57, 135, 229, 0.14);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --c-oki: #3987e5;
  --c-reg: #d95926;
  --c-hyb: #199e70;
  --c-pos: #3987e5;
  --c-neg: #e66767;
  --accent: #3987e5;
  --wash: rgba(57, 135, 229, 0.14);
  --shadow: none;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.35em; }
h1 { font-size: 1.7rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.7em; }
a { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }
pre {
  background: var(--wash);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.wrap { max-width: 1060px; margin: 0 auto; padding: 0 16px; }
/* minmax(0,…) so wide intrinsic content (tables) scrolls inside its card
   instead of stretching the page */
main.wrap { display: grid; gap: 20px; padding-bottom: 40px; grid-template-columns: minmax(0, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card > h2 { margin-top: 0; }
.card-sub { color: var(--ink-2); margin-top: -0.2em; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

/* ============ Header ============ */
.site-header { padding: 26px 0 8px; }
.site-header .head-row {
  display: flex; flex-wrap: wrap; gap: 12px 20px;
  align-items: flex-start; justify-content: space-between;
}
.tagline { color: var(--ink-2); max-width: 46em; margin: 0; }
.site-tools { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.site-tools select {
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-height: 44px;
}
.theme-seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-seg button {
  font: inherit; font-size: 0.85rem; color: var(--ink-2);
  background: var(--surface); border: 0; padding: 0 12px; min-height: 42px;
  cursor: pointer;
}
.theme-seg button + button { border-left: 1px solid var(--border); }
.theme-seg button[aria-pressed="true"] { background: var(--wash); color: var(--ink); font-weight: 600; }

/* ============ Controls ============ */
.fields { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .fields { grid-template-columns: 1fr 1fr; column-gap: 32px; } }

.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.field-head label { font-weight: 600; }
.field-head output { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.field-row { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.field-row input[type="number"] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; width: 7.5em; min-height: 44px;
  font-variant-numeric: tabular-nums;
}

/* Range inputs: 44px touch target, themed track/thumb */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 44px; margin: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: var(--grid);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%; background: var(--accent);
  border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--grid); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border);
}

.check-row { display: flex; align-items: flex-start; gap: 10px; }
.check-row input[type="checkbox"] { width: 20px; height: 20px; margin: 3px 0 0; accent-color: var(--accent); }

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.presets .preset-label { color: var(--muted); font-size: 0.85rem; align-self: center; margin: 0; }
.presets button {
  font: inherit; font-size: 0.85rem; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; min-height: 36px; cursor: pointer;
}
.presets button:hover { background: var(--wash); }
.presets button[aria-pressed="true"] {
  background: var(--wash); border-color: var(--accent); color: var(--ink); font-weight: 600;
}

/* ============ Law status + news ============ */
.status-asof { color: var(--muted); font-size: 0.85rem; }
.news-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.news-list li {
  display: grid; grid-template-columns: 9.5em 1fr; gap: 12px; align-items: baseline;
}
.news-list time { color: var(--muted); font-size: 0.85rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.news-list a { color: var(--ink); }
@media (max-width: 560px) {
  .news-list li { grid-template-columns: 1fr; gap: 2px; }
}

/* ============ FAQ ============ */
/* Scoped to the FAQ card: details.sub is also used for the year table and
   formulas, whose children have their own styling. */
.faq details.sub > p { margin: 0 0 6px; color: var(--ink-2); }

/* "Today's money" badge: marks every place where amounts are deflated */
.today-badge { font-weight: 400; font-size: 0.85em; color: var(--muted); }

/* Payout phase: control + inline result (verdict sentence + two bars) */
.payout-block { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.payout-block > h3 { margin: 0 0 12px; font-size: 1rem; }
.payout-result { align-self: center; }
.payout-verdict { margin: 0 0 10px; font-weight: 600; }
.payout-bars { display: grid; gap: 8px; }
.payout-bar-row { display: grid; grid-template-columns: minmax(72px, auto) 1fr auto; gap: 10px; align-items: center; }
.payout-bar-name { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--ink-2); white-space: nowrap; }
.payout-bar-name .key-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.payout-bar { height: 12px; border-radius: 6px; background: var(--wash); overflow: hidden; }
.payout-bar-fill { height: 100%; border-radius: 6px; width: 0; transition: width 0.25s ease; }
.payout-bar-fill.oki { background: var(--c-oki); }
.payout-bar-fill.reg { background: var(--c-reg); }
.payout-bar-years { font-size: 0.85rem; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

details.advanced { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 4px; }
details.advanced > summary {
  cursor: pointer; font-weight: 600; padding: 10px 0; list-style-position: inside;
}
details.advanced[open] > summary { margin-bottom: 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.actions button {
  font: inherit; cursor: pointer; min-height: 44px;
  border-radius: 8px; padding: 8px 16px;
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--border);
}
.actions button:hover { background: var(--wash); color: var(--ink); }
.actions button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600;
}

/* ============ Verdict hero ============ */
.verdict { text-align: center; padding: 28px 20px; }
.verdict-after { color: var(--muted); margin-bottom: 2px; }
.verdict-main {
  font-size: clamp(1.5rem, 4.5vw, 2.3rem);
  font-weight: 700; letter-spacing: -0.01em; margin: 0 0 6px;
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
}
.verdict-main .win-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.verdict-main .win-dot.oki { background: var(--c-oki); }
.verdict-main .win-dot.reg { background: var(--c-reg); }
.verdict-detail { color: var(--ink-2); margin-bottom: 4px; }
.verdict-be { color: var(--muted); font-size: 0.9rem; max-width: 40em; margin: 0 auto; }

/* ============ Stat tiles ============ */
.stats-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-top: 12px;
}
.stat {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
.stat .stat-label { color: var(--muted); font-size: 0.8rem; margin: 0 0 4px; }
.stat .stat-value { font-size: 1.15rem; font-weight: 650; margin: 0; overflow-wrap: anywhere; }
.stat .stat-value .key-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 6px; vertical-align: 6%;
}
.key-dot.oki { background: var(--c-oki); }
.key-dot.reg { background: var(--c-reg); }
.key-dot.hyb { background: var(--c-hyb); }

/* ============ Charts ============ */
.chart-figure { margin: 10px 0 0; position: relative; }
.chart-figure svg { display: block; width: 100%; height: auto; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  font-size: 0.85rem; color: var(--ink-2); margin: 8px 0 0; padding: 0; list-style: none;
}
.chart-legend li { display: flex; align-items: center; gap: 7px; }
.legend-key { width: 16px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.legend-key.oki { background: var(--c-oki); }
.legend-key.reg { background: var(--c-reg); }
.legend-key.hyb { background: repeating-linear-gradient(90deg, var(--c-hyb) 0 5px, transparent 5px 8px); }
.chart-hint { color: var(--muted); font-size: 0.78rem; margin: 8px 0 0; }

/* SVG parts (colors via tokens so theme switches need no re-render) */
.gridline { stroke: var(--grid); stroke-width: 1; }
.axisline { stroke: var(--baseline); stroke-width: 1; }
.zeroline { stroke: var(--baseline); stroke-width: 1.5; }
.axis-text { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.marker-text { fill: var(--ink-2); font-size: 11.5px; }
.line-oki { stroke: var(--c-oki); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.line-reg { stroke: var(--c-reg); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
/* Dashed: marks the derived strategy and doubles as a non-color cue. */
.line-hyb { stroke: var(--c-hyb); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: butt; stroke-dasharray: 5 4; }
.area-pos { fill: var(--c-pos); opacity: 0.12; }
.area-neg { fill: var(--c-neg); opacity: 0.12; }
.line-adv { stroke: var(--c-oki); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.vline-threshold { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 4; }
.vline-horizon { stroke: var(--accent); stroke-width: 1.5; }
.peak-dot { stroke: var(--surface); stroke-width: 2; }
.peak-dot.pos { fill: var(--c-pos); }
.end-dot { stroke: var(--surface); stroke-width: 2; }
.end-dot.oki { fill: var(--c-oki); }
.end-dot.reg { fill: var(--c-reg); }
.end-dot.hyb { fill: var(--c-hyb); }
.crosshair { stroke: var(--baseline); stroke-width: 1; }
.hover-dot { stroke: var(--surface); stroke-width: 2; }

.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.13);
  padding: 8px 11px; font-size: 0.82rem; min-width: 150px; max-width: 240px;
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip .tt-title { color: var(--muted); margin: 0 0 4px; }
.chart-tooltip .tt-row { display: flex; align-items: baseline; gap: 8px; margin: 2px 0; }
.chart-tooltip .tt-key { width: 12px; height: 3px; border-radius: 2px; flex-shrink: 0; align-self: center; }
.chart-tooltip .tt-val { font-weight: 650; font-variant-numeric: tabular-nums; margin-left: auto; white-space: nowrap; }
.chart-tooltip .tt-name { color: var(--ink-2); }

/* ============ Break-even heatmap ============ */
.heat-scroll { overflow-x: auto; margin-top: 12px; -webkit-overflow-scrolling: touch; }
table.heat { border-collapse: separate; border-spacing: 2px; font-size: 0.8rem; }
table.heat th {
  font-weight: 600; color: var(--ink-2); padding: 4px 6px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
table.heat thead th { text-align: center; }
table.heat tbody th { text-align: right; position: sticky; left: 0; background: var(--surface); z-index: 2; }
table.heat td { padding: 0; }
table.heat td button {
  display: block; width: 100%; min-width: 46px; min-height: 34px;
  font: inherit; font-variant-numeric: tabular-nums;
  border: 0; border-radius: 4px; cursor: pointer; padding: 6px 4px;
}
table.heat td button:hover { filter: brightness(0.93); }
table.heat td button[aria-pressed="true"] {
  outline: 2px solid var(--ink); outline-offset: -2px; font-weight: 700;
}
.heat-legend {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
  font-size: 0.8rem; color: var(--muted);
}
.heat-legend .ramp {
  height: 10px; width: 140px; border-radius: 5px;
  background: linear-gradient(90deg, #cde2fb, #86b6ef, #3987e5, #1c5cab, #0d366b);
}

/* ============ Explain section ============ */
.explain-cols { display: grid; gap: 16px; grid-template-columns: 1fr; margin: 12px 0; }
@media (min-width: 760px) { .explain-cols { grid-template-columns: 1fr 1fr; } }
.explain-col { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.explain-col h3 { display: flex; align-items: center; gap: 8px; }
.steps { padding-left: 1.3em; margin: 8px 0; }
.steps li { margin: 6px 0; }

details.sub { border: 1px solid var(--border); border-radius: 10px; padding: 0 16px; margin-top: 12px; }
details.sub > summary { cursor: pointer; font-weight: 600; padding: 12px 0; }
details.sub[open] { padding-bottom: 14px; }

.ybreak-scroll { overflow-x: auto; }
table.ybreak { border-collapse: collapse; font-size: 0.82rem; width: 100%; min-width: 640px; }
table.ybreak th, table.ybreak td { padding: 5px 10px; text-align: right; white-space: nowrap; }
table.ybreak th:first-child, table.ybreak td:first-child { text-align: left; }
table.ybreak thead th { color: var(--ink-2); border-bottom: 1px solid var(--baseline); font-weight: 600; }
table.ybreak tbody tr { border-bottom: 1px solid var(--grid); }
table.ybreak td { font-variant-numeric: tabular-nums; }
table.ybreak tr.milestone { background: var(--wash); font-weight: 600; }
td.pos { color: var(--c-oki); }
td.neg { color: var(--c-neg); }

/* ============ Assumptions & footer ============ */
.formulas h4 { display: flex; align-items: center; gap: 8px; margin: 16px 0 6px; font-size: 0.95rem; }
.formulas .frow { margin: 10px 0 14px; }
.formulas .frow code {
  display: inline-block; max-width: 100%; overflow-x: auto;
  background: var(--wash); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px;
}
.formulas .frow p { margin: 5px 0 0; color: var(--muted); font-size: 0.85rem; }

.assumptions ul { padding-left: 1.2em; margin: 8px 0; }
.assumptions li { margin: 6px 0; color: var(--ink-2); font-size: 0.9rem; }
.disclaimer { color: var(--muted); font-size: 0.82rem; }
.privacy { color: var(--muted); font-size: 0.82rem; }
.site-footer {
  color: var(--muted); font-size: 0.85rem;
  padding: 18px 16px 32px; text-align: center;
}
.site-footer a { color: var(--ink-2); }

.toast-inline { color: var(--accent); font-weight: 600; }

/* ============ Cookie consent banner ============ */
.consent-banner {
  position: fixed; left: 16px; right: 16px; bottom: 16px;
  margin-inline: auto; max-width: 560px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.consent-banner p { margin: 0; font-size: 0.88rem; color: var(--ink-2); }
.consent-actions { display: flex; gap: 10px; }
.consent-actions button {
  font: inherit; cursor: pointer; min-height: 44px;
  border-radius: 8px; padding: 8px 18px;
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--border);
}
.consent-actions button:hover { background: var(--wash); color: var(--ink); }
.consent-actions button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600;
}

/* ============ Print: the PDF report ============ */
.print-only { display: none; }
@media print {
  :root, :root[data-theme="dark"] {
    color-scheme: light;
    --page: #ffffff; --surface: #ffffff;
    --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
    --grid: #e1e0d9; --baseline: #c3c2b7; --border: rgba(11, 11, 11, 0.18);
    --c-oki: #2a78d6; --c-reg: #eb6834; --c-hyb: #1baf7a; --c-pos: #2a78d6; --c-neg: #e34948;
    --accent: #2a78d6; --wash: rgba(42, 120, 214, 0.08); --shadow: none;
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { font-size: 12px; }
  .no-print, .site-tools, .actions, .chart-hint, #controls, .heatmap-section { display: none !important; }
  .print-only { display: block; }
  .card { border: 0; box-shadow: none; padding: 8px 0; break-inside: avoid; }
  .verdict { text-align: left; }
  .verdict-main { justify-content: flex-start; }
  main.wrap, .wrap { max-width: none; padding: 0; }
  details.sub, details.advanced { border: 0; padding: 0; }
  details.sub > summary { list-style: none; }
  details.sub[open] { padding-bottom: 0; }
  a { color: var(--ink); text-decoration: none; }
  .print-params { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
  .print-params dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 18px; margin: 0; }
  .print-params dt { color: var(--ink-2); }
  .print-params dd { margin: 0; font-variant-numeric: tabular-nums; }
  .print-meta { color: var(--muted); font-size: 11px; }
}
