:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #5b636b;
  --line: #e1e4e8;
  --accent: #2e7012;
  --accent-ink: #1d4a0b;
  --input-bg: #ffffff;
  --input-border: #e1e4e8;
  --hover: #f3f6f1;        /* row / table hover */
  --soft: #f0f4ee;         /* active row + add-button tint */
  --soft-hover: #e7efe2;
  --code-bg: #eef1ee;
  --warn: #b54708;
  --grid: rgba(0,0,0,0.08); /* chart gridlines */
  color-scheme: light;       /* native widgets (number spinners, scrollbars, selects) */
}
/* Automatic dark theme based on the OS/browser preference. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;      /* flips the native number up/down arrows, scrollbars, selects */
    --bg: #15181b;
    --panel: #1c2025;
    --ink: #e4e8eb;
    --muted: #98a1a9;
    --line: #2d343b;
    --accent: #6bb544;     /* lighter green so it reads on dark */
    --accent-ink: #93d36e;
    --input-bg: #0f1317;     /* darker than the panel so fields read as recessed (more contrast) */
    --input-border: #3c454d;
    --hover: #262d33;
    --soft: rgba(107,181,68,0.14);
    --soft-hover: rgba(107,181,68,0.22);
    --code-bg: #23282e;
    --warn: #e8915a;
    --grid: rgba(255,255,255,0.10);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
header {
  /* Shared top bar on all three pages: brand title left, site nav right. */
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 24px;
  flex-wrap: wrap;
  padding: 18px 28px 0;
  max-width: 1400px;   /* match <main> so the title left-aligns with the content */
  margin: 0 auto;
}
h1 { font-size: 22px; margin: 0; }
h1 a { color: inherit; text-decoration: none; }
h1 a:hover { color: var(--accent-ink); }
h1 .sub { font-weight: 400; color: var(--muted); font-size: 16px; }

main {
  /* Simple stacked layout: inputs at the top, wide chart + numbers below. */
  display: block;
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 28px 48px;
}

/* Two columns: key params on the left, wide chart + results on the right. */
#inputs {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.left, .right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.extras { display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 900px) {
  #inputs { grid-template-columns: 1fr; }
  .extras { grid-template-columns: 1fr; }
  .taxgrid { grid-template-columns: 1fr; }
  #taxparams { border-left: none; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; }
}
section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
}
section.box3 { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(46,112,18,.08); }
h2 { font-size: 12px; margin: 0 0 7px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
[hidden] { display: none !important; } /* `hidden` must beat the display rules above */
label.check input { width: auto; }
input, select {
  width: 100%;
  margin-top: 2px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: var(--input-bg);
  color: var(--ink);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.note { font-size: 12px; color: var(--muted); margin: 3px 0 0; line-height: 1.4; }
.fmt { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; min-height: 13px; }
/* CAGR/vol stats under the stock/bond dropdowns: same accent green as the spending-rate hint. */
#stockStat, #bondStat { color: var(--accent-ink); }
.note.warn { color: var(--warn); }
.warn { color: var(--warn); }

button.add {
  background: var(--soft); border: 1px dashed var(--accent); color: var(--accent-ink);
  padding: 7px; border-radius: 7px; cursor: pointer; font: inherit; width: 100%;
}
button.add:hover { background: var(--soft-hover); }
/* Secondary action button (copy link, find spending). */
button.btn {
  background: var(--input-bg); border: 1px solid var(--accent); color: var(--accent-ink);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; font: inherit; font-size: 13px;
}
button.btn:hover { background: var(--soft); }
button.btn:disabled { opacity: 0.6; cursor: progress; }
/* "Find best mix" action: button beside its result/explanation note. */
.allocact { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.allocact button.btn { flex: none; white-space: nowrap; }
.allocact .note { margin: 0; flex: 1 1 60%; }
.allocact .note.found { color: var(--accent-ink); } /* green once a better mix is found (grey while placeholder) */
.applyspend { cursor: pointer; text-decoration: underline; font-weight: 600; } /* click to fill the spending box */
.applyspend:hover { text-decoration: none; }
.stream { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto; gap: 6px; align-items: end; margin-bottom: 8px; }
.stream > label { margin-bottom: 0; }   /* else align-items:end offsets inputs vs the X button */
.stream .infl { grid-column: 1 / -1; margin: 0; }
.stream button.del {
  width: 100%; margin: 0; padding: 5px 8px; font: inherit; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; background: var(--input-bg); color: var(--muted);
}
.stream button.del:hover { background: #fbecec; border-color: #d64545; color: #d64545; }

.results { display: flex; flex-direction: column; gap: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.card .d { font-size: 12px; margin-top: 2px; }
.card .d.bad { color: #b42318; }
.card .d.good { color: var(--accent); }
.card.hl { border-color: var(--accent); }

#compare .k { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 14px; }
table.cmp th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px 6px; }
table.cmp th:first-child { text-align: left; }
table.cmp td { text-align: right; padding: 7px 6px; border-top: 1px solid var(--line); }
table.cmp td:first-child { text-align: left; }
table.cmp tbody tr { cursor: pointer; }
table.cmp tbody tr:hover { background: var(--hover); }
table.cmp tr.act { background: var(--soft); font-weight: 600; }
table.cmp tr.act td:first-child { color: var(--accent-ink); }
table.cmp .q { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
table.cmp .hdr2 { font-weight: 400; }
/* The tax panel: picker table (wide, left) beside the selected model's settings (right). */
.taxgrid { display: grid; grid-template-columns: 2.2fr 1fr; gap: 16px; align-items: start; }
#taxparams { border-left: 1px solid var(--line); padding-left: 16px; }
/* Withdrawal-rate % pinned to the label's top-right so it never wraps to a new line
   (which would push the spending input out of line with the savings input). */
.row label { position: relative; }
.hint { position: absolute; top: 0; right: 0; font-size: 11px; font-weight: 600; color: var(--accent-ink); }
.paramtitle { font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
/* Title left, the Compare control pinned top-right. Only two items, so it never shifts. */
.taxhead { display: flex; justify-content: space-between; align-items: center; gap: 6px 18px; flex-wrap: wrap; margin-bottom: 12px; }
.taxhead h2 { margin-bottom: 0; }
.cmpmode { margin: 0; font-size: 13px; color: var(--accent-ink); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cmpmode select { width: auto; padding: 5px 10px; font-size: 13px; margin: 0; border: 1px solid var(--accent); box-shadow: 0 0 0 1px rgba(46,112,18,.08); }

.chartwrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; height: 470px;
}
.disclaimer { font-size: 11px; color: var(--muted); }
a { color: var(--accent-ink); }

/* Site navigation, lives top-right in the shared header on every page. */
.sitenav {
  display: flex; gap: 20px; align-items: center;
  font-size: 14px;
}
.sitenav a { color: var(--muted); text-decoration: none; }
.sitenav a:hover { color: var(--accent-ink); }
.sitenav a.active { color: var(--ink); font-weight: 600; }

/* Shared site footer (attribution), centered under the content on every page. */
.sitefoot {
  max-width: 1180px; margin: 28px auto 20px; padding: 14px 16px 0;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted); text-align: center;
}

/* Dataset / method pages: readable single-column content. */
.page { max-width: 1000px; margin: 0 auto; padding: 18px 28px 48px; }
.page section { margin-bottom: 16px; }
.datatable-wrap { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 4px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-size: 12px; z-index: 1; }
table.data tbody tr:hover { background: var(--hover); }
.controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; margin-bottom: 10px; }
.controls label { margin: 0; }
.controls select { width: auto; min-width: 150px; }
.controls input[type="range"] { width: 160px; accent-color: #2e7012; vertical-align: middle; }
.controls output { font-weight: 600; color: #2e7012; }
.explore { margin-top: 18px; }
.explore > h2 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.exgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 8px; }
.excard h3 { font-size: 13px; margin: 0 0 6px; color: var(--ink); }
.excard canvas { cursor: pointer; }
.excard .chartwrap { border: none; background: none; padding: 0; } /* the .explore section already frames them */
.exlegend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 2px 0 12px; font-size: 12px; }
.exlegend .lg { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--ink); user-select: none; }
.exlegend .lg.off { opacity: 0.4; text-decoration: line-through; }
.exlegend .lg i { width: 12px; height: 12px; border-radius: 2px; }

/* Method article: figures, captions, and the yearly-loop diagram. */
.article { max-width: 760px; }
.article p, .article li { color: var(--ink); }
.article .lead { font-size: 17px; color: var(--ink); }
figure { margin: 22px 0; }
figure .chartwrap { height: 360px; }
figcaption { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 2px; vertical-align: baseline; margin-right: 3px; }
.loop { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; margin: 18px 0; }
.loop .step {
  flex: 1 1 0; min-width: 120px; background: var(--soft); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
}
.loop .step b { display: block; font-size: 13px; color: var(--accent-ink); margin-bottom: 3px; }
.loop .step span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.loop .arrow { align-self: center; color: var(--accent); font-size: 18px; }
@media (max-width: 620px) { .loop .arrow { display: none; } }
.keyrow { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; margin: 8px 0 0; }

/* Rendered markdown (method page). */
.md h1 { font-size: 22px; }
.md h2 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); margin-top: 26px; }
.md h3 { font-size: 14px; color: var(--ink); margin-top: 18px; }
.md table { border-collapse: collapse; font-size: 13px; margin: 10px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.md pre { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line); margin: 10px 0; padding: 2px 14px; color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 22px 0; }

/* Phones: stack the multi-column field rows so nothing runs off-screen.
   Placed last so it overrides the base .row/.row3/.stream grid definitions. */
@media (max-width: 560px) {
  main { padding: 14px 16px 40px; }
  header { padding: 16px 16px 0; }
  h1 { font-size: 20px; }
  h1 .sub { font-size: 14px; }
  .row, .row3 { grid-template-columns: 1fr; }
  .planactions { flex-wrap: wrap; }
  .stream { grid-template-columns: 1fr 1fr; }
  .stream .del { grid-column: 1 / -1; }
  /* Stack the tax panel (picker table above its settings); the base .taxgrid rule
     sits later in the file, so this override must come last to win. */
  .taxgrid { grid-template-columns: 1fr; }
  #taxparams { border-left: none; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; }
  #compare { overflow-x: auto; }       /* dense 5-col table scrolls instead of clipping the page */
  table.cmp { font-size: 13px; min-width: 380px; }
  table.cmp th, table.cmp td { padding: 5px 4px; }
}
