:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #5d6677;
  --line: #dde1e8;
  --accent: #0a76c4;
  --accent-soft: #e3f0fa;
  --warn: #a35a00;
  --grid: #e7eaef;
  --good: #1d7a4a; --good-soft: #e2f4ea;
  --watch: #8a5a00; --watch-soft: #fbf0d9;
  --bad: #b03a2e; --bad-soft: #fbe5e2;
  /* chart series */
  --c-take: #66c2ea;
  --c-ptake: #a9dcf3;
  --c-draw: #0b4f8a;
  --c-pdraw: #3a7cbf;
  --c-ap: #a687cf;
  --c-other: #4caf8a;
  --c-bal: #1a9ad8;
  --c-pbal: #8ccbea;
  --c-short: #e0a33b;
  --c-sav: #1f6f78;
  --c-oth: #a8875a;
  --c-home: #7d8799;
  /* extra income streams */
  --c-s1: #c46a8a; --c-s2: #8a9a3a; --c-s3: #c8643c; --c-s4: #8c7a6b;
  /* timeline pills */
  --p-retire: #e3f0fa; --p-retire-t: #0b4f8a;
  --p-stream: #f6e3ea; --p-stream-t: #8a3558;
  --p-in: #e2f4ea; --p-in-t: #1d6b44;
  --p-out: #fbeedb; --p-out-t: #8a5300;
  --p-outp: #ece6f7; --p-outp-t: #5a3d99; /* money out of a partner's super */
  --p-job: #eceef2; --p-job-t: #3d4555;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --panel: #1b2029; --text: #e6e9ef; --muted: #a3acbb; --line: #2c3340;
    --accent: #4fb0f0; --accent-soft: #1c2e40; --warn: #f0b35a; --grid: #262c37;
    --good: #6fd19c; --good-soft: #17301f; --watch: #f0c06a; --watch-soft: #33280f; --bad: #f08a7e; --bad-soft: #3a1c18;
    --c-take: #4fb6e3; --c-ptake: #2f7fa6; --c-draw: #6aa8e8; --c-pdraw: #3f78b8;
    --c-ap: #b49ae0; --c-other: #5cc29b; --c-bal: #3aa9e5; --c-pbal: #2a6f99; --c-short: #e8b04f; --c-sav: #8ad6dc; --c-oth: #cfae80; --c-home: #a3adbf;
    --c-s1: #e08aa6; --c-s2: #aabb55; --c-s3: #e0835a; --c-s4: #b09d8c;
    --p-retire: #1c2e40; --p-retire-t: #9fd0f5; --p-stream: #3a2030; --p-stream-t: #f0b3c8;
    --p-in: #17301f; --p-in-t: #8fdcb0; --p-out: #33260f; --p-out-t: #f0c27a; --p-outp: #2a2140; --p-outp-t: #c9b6f0; --p-job: #262c37; --p-job-t: #c9d0dc;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --panel: #1b2029; --text: #e6e9ef; --muted: #a3acbb; --line: #2c3340;
  --accent: #4fb0f0; --accent-soft: #1c2e40; --warn: #f0b35a; --grid: #262c37;
  --good: #6fd19c; --good-soft: #17301f; --watch: #f0c06a; --watch-soft: #33280f; --bad: #f08a7e; --bad-soft: #3a1c18;
  --c-take: #4fb6e3; --c-ptake: #2f7fa6; --c-draw: #6aa8e8; --c-pdraw: #3f78b8;
  --c-ap: #b49ae0; --c-other: #5cc29b; --c-bal: #3aa9e5; --c-pbal: #2a6f99; --c-short: #e8b04f; --c-sav: #8ad6dc; --c-oth: #cfae80; --c-home: #a3adbf;
  --c-s1: #e08aa6; --c-s2: #aabb55; --c-s3: #e0835a; --c-s4: #b09d8c;
  --p-retire: #1c2e40; --p-retire-t: #9fd0f5; --p-stream: #3a2030; --p-stream-t: #f0b3c8;
  --p-in: #17301f; --p-in-t: #8fdcb0; --p-out: #33260f; --p-out-t: #f0c27a; --p-outp: #2a2140; --p-outp-t: #c9b6f0; --p-job: #262c37; --p-job-t: #c9d0dc;
}

/* Base size is 16px; "Larger text" bumps everything (rem-based) up. */
html { font-size: 16px; }
html.large { font-size: 19px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h2 { font-size: 1.35rem; font-weight: 600; margin: 0 0 0.3rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin: 0 0 0.6rem; }
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.4rem 0.8rem; cursor: pointer; min-height: 2.4rem;
}
button:hover, .btn-link:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-link {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.4rem 0.8rem; color: inherit; text-decoration: none; display: inline-flex; align-items: center;
}
select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.4rem 0.6rem; min-height: 2.4rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.2rem 0 0.6rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.25rem; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.2rem; font-weight: 600; }
.ver { font-size: 0.8rem; color: var(--muted); font-weight: 400; margin-left: 6px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Set-up ---- */
.setup { max-width: 760px; margin: 0 auto; padding: 20px 16px; }
.step-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.step-nav button { font-size: 0.85rem; min-height: 2rem; padding: 0.25rem 0.6rem; color: var(--muted); }
.step-nav button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.step-count { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.2rem; }
.lead { color: var(--muted); margin: 0 0 1rem; }
.step { display: flex; flex-direction: column; gap: 1.1rem; }
.step-actions { display: flex; justify-content: space-between; margin-top: 14px; }
.step-actions button { min-width: 8rem; min-height: 2.8rem; }
.stream-list { display: flex; flex-direction: column; gap: 8px; }
.stream-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.75rem; }
.add-btn { align-self: flex-start; }

/* ---- Dashboard ---- */
.dash { max-width: 1120px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.about { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 0.7rem 1.25rem; }
.about p { margin: 0; color: var(--muted); }
.about .dates { font-size: 0.85rem; margin-top: 0.15rem; }
.about .dates:empty { display: none; }
.answer { padding: 1.1rem 1.25rem; }
.answer-big { font-size: 1.6rem; font-weight: 600; margin: 0.4rem 0 0.3rem; }
.answer-sub { margin: 0; color: var(--muted); max-width: 75ch; }
.chip { display: inline-block; font-size: 0.85rem; font-weight: 600; padding: 0.15rem 0.7rem; border-radius: 999px; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.watch { background: var(--watch-soft); color: var(--watch); }
.chip.short { background: var(--bad-soft); color: var(--bad); }
.warnings { color: var(--warn); padding-left: 18px; margin: 0.6rem 0 0; font-size: 0.9rem; }
.warnings:empty { display: none; }

.results { position: relative; min-width: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; display: block; touch-action: none; user-select: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: center; font-size: 0.85rem; margin-top: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-toggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; padding-left: 8px; border-left: 1px solid var(--line); }

.chart text { fill: var(--muted); font-size: 11px; }
.chart .axis-age { fill: var(--text); }
.chart .axis line, .chart .grid line { stroke: var(--grid); }
.chart .marker-line { stroke: var(--muted); stroke-dasharray: 4 3; pointer-events: none; }
.chart text { pointer-events: none; }
.chart .handle { fill: var(--muted); cursor: ew-resize; }
.chart .handle.v { cursor: ns-resize; }
.chart .handle-grip { stroke: var(--panel); stroke-width: 1.5; pointer-events: none; }
.chart .label-strong { fill: var(--text); font-weight: 600; }
.chart .survival-text { fill: var(--text); font-size: 11px; }
.chart .lump-label { fill: var(--text); font-size: 11px; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 180px;
}
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tot { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; font-weight: 600; }

/* ---- Timeline ---- */
.timeline { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.timeline h3 { margin-bottom: 0; }
.tl-track { position: relative; min-height: 50px; border-bottom: 2px solid var(--line); margin-bottom: 10px; }
.pill {
  position: absolute; white-space: nowrap; border: none; min-height: 2rem;
  padding: 0.2rem 0.75rem; font-size: 0.85rem; cursor: grab; touch-action: none;
  border-left: 3px solid currentColor; border-radius: 0 999px 999px 0;
  display: flex; align-items: center; max-width: 100%; box-sizing: border-box;
}
.pill .pl-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pill:active { cursor: grabbing; }
.tl-tick { position: absolute; bottom: 2px; transform: translateX(-50%); font-size: 0.75rem; color: var(--muted); pointer-events: none; }
.pill.retire { background: var(--p-retire); color: var(--p-retire-t); }
.pill.stream { background: var(--p-stream); color: var(--p-stream-t); }
.pill.in { background: var(--p-in); color: var(--p-in-t); }
.pill.out { background: var(--p-out); color: var(--p-out-t); }
.pill.out.partner { background: var(--p-outp); color: var(--p-outp-t); }
.pill.job { background: var(--p-job); color: var(--p-job-t); }
/* Key for whose super a one-off cost comes from (couples only). */
.tl-key { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; font-size: 0.8rem; color: var(--muted); margin: 0 0 10px; }
.tl-key .sw { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; border-left: 3px solid; margin-right: 5px; vertical-align: -1px; }
.tl-key .sw.you { background: var(--p-out); border-color: var(--p-out-t); }
.tl-key .sw.partner { background: var(--p-outp); border-color: var(--p-outp-t); }
.tl-add { display: flex; flex-wrap: wrap; gap: 6px; }
.tl-add button { font-size: 0.9rem; }

.editor { border-color: var(--accent); margin-top: 12px; }
.editor-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.editor-head h3 { margin: 0; }
.editor-btns { display: flex; gap: 6px; }
#editorBody > div { display: flex; flex-direction: column; gap: 1rem; }

/* ---- Plan levers ---- */
.plan h2 { margin-top: 6px; }
.levers { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.lever { display: flex; flex-direction: column; gap: 1rem; transition: box-shadow .3s; }
.lever h3 { margin: 0; }
.lever.flash { box-shadow: 0 0 0 3px var(--accent); }
.advanced summary { cursor: pointer; font-weight: 600; }
.advanced[open] summary { margin-bottom: 1rem; }
#advancedBody { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem 1.5rem; }

/* ---- Fields: label on top, control underneath ---- */
.field label { display: block; font-weight: 500; margin-bottom: 0.35rem; }
.field .help { color: var(--muted); font-size: 0.88rem; margin-top: 0.3rem; }
.field .links { color: var(--muted); font-size: 0.82rem; margin-top: 0.3rem; line-height: 1.5; }
.field .links a { color: var(--accent); }
.field.sub { border-left: 3px solid var(--accent-soft); padding-left: 12px; }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stepper button { border: none; border-radius: 0; width: 2.8rem; font-size: 1.3rem; line-height: 1; background: var(--bg); }
.stepper button:hover { background: var(--accent-soft); }
.stepper input.num {
  width: 8.5rem; text-align: center; border: none; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background: var(--panel); font-size: 1.05rem; padding: 0.35rem 0.4rem;
}
.stepper input.num:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button { padding: 0.4rem 0.9rem; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.field select { width: 100%; }
.field input.text {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.45rem 0.7rem;
}
.field input.text:focus { outline: none; border-color: var(--accent); }

/* ---- Year by year ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 4px 0 14px; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.tile .k { color: var(--muted); font-size: 0.8rem; }
.tile .v { font-size: 1.25rem; font-weight: 600; margin-top: 2px; }
.tile .s { color: var(--muted); font-size: 0.8rem; }
.table-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; color: var(--muted); font-size: 0.85rem; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 6px; }
table { border-collapse: collapse; font-size: 0.8rem; width: 100%; }
th, td { padding: 4px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { position: sticky; top: 0; background: var(--panel); font-weight: 600; }
tr.retire td { background: var(--accent-soft); }

.foot { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 8px 16px 20px; }

@media (max-width: 700px) {
  .top { padding: 10px 16px; }
  .levers, #advancedBody { grid-template-columns: minmax(0, 1fr); }
  .answer-big { font-size: 1.35rem; }
}

/* ---- Printable report ----
   Built by app.js on beforeprint and only shown in print. A4 portrait:
   page 1 answer, inputs and assumptions; then income; then super balance. */
.report { display: none; }
@media print {
  @page { size: A4 portrait; margin: 13mm 13mm 14mm; }
  html, html.large { font-size: 9.5pt; }
  body { background: #fff; color: var(--text); }
  body > :not(.report) { display: none !important; }
  .report { display: block; line-height: 1.35; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .r-page { break-after: page; }
  .r-page:last-child { break-after: auto; }
  .r-head { border-bottom: 2px solid var(--accent); padding-bottom: 4px; margin-bottom: 8px; }
  .r-head h1 { font-size: 17pt; margin: 0; color: var(--accent); }
  .r-lead { margin: 2px 0 0; color: var(--muted); }
  .report h2 { font-size: 12pt; margin: 10px 0 4px; border-bottom: 1px solid var(--line); padding-bottom: 2px; }
  .report h3 { font-size: 9.5pt; margin: 6px 0 3px; }
  .r-answer { border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; break-inside: avoid; }
  .r-answer p { margin: 2px 0; }
  .r-big { font-size: 13pt; font-weight: 600; }
  .r-chip { display: inline-block; font-weight: 600; font-size: 8.5pt; padding: 1px 8px; border-radius: 999px; }
  .r-chip.good { background: var(--good-soft); color: var(--good); }
  .r-chip.watch { background: var(--watch-soft); color: var(--watch); }
  .r-chip.short { background: var(--bad-soft); color: var(--bad); }
  .r-warn { color: var(--warn); margin: 3px 0 0; padding-left: 16px; }
  .r-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin: 8px 0 2px; }
  .r-tile { border: 1px solid var(--line); border-radius: 5px; padding: 4px 7px; break-inside: avoid; }
  .r-tile .k, .r-tile .s { color: var(--muted); font-size: 8pt; }
  .r-tile .v { font-size: 11pt; font-weight: 600; }
  .r-cols { columns: 2; column-gap: 16px; }
  .r-block { break-inside: avoid; margin-bottom: 6px; }
  .r-group { break-inside: avoid; }
  .report h2, .report h3 { break-after: avoid; }
  .report table { font-size: 8.5pt; width: 100%; }
  .report th { position: static; }
  .r-kv th { text-align: left; font-weight: 400; color: var(--muted); white-space: normal; width: 58%; padding: 1.5px 6px 1.5px 0; }
  .r-kv td { text-align: right; white-space: normal; padding: 1.5px 0; }
  .r-notes ul { margin: 0; padding-left: 14px; }
  .r-notes li { margin-bottom: 2px; }
  .r-notes a { color: var(--accent); }
  .report .chart { margin: 4px 0 0; }
  .report .chart text { font-size: 12.5px; }
  .report .chart .lump-label { stroke: #fff; }
  .report .legend { font-size: 8.5pt; margin: 2px 0 6px; }
  .r-data { margin-top: 2px; }
  .r-data th { border-bottom: 1.5px solid var(--text); white-space: normal; vertical-align: bottom; padding: 3px 4px; }
  .r-data td { padding: 2px 4px; }
  .r-data tr:nth-child(even) td { background: #f6f7f9; }
  .r-data tr.retire td { background: var(--accent-soft); font-weight: 600; }
  .r-small { color: var(--muted); font-size: 8pt; margin: 4px 0 0; }
  .r-foot { margin-top: 10px; padding-top: 4px; color: var(--muted); font-size: 7.5pt; border-top: 1px solid var(--line); }
}
