:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5b6573;
  --border: #dde1e7;
  --accent: #1d6fd8;
  --accent-ink: #ffffff;
  --warn: #a65b00;
  --warn-bg: #fff4e5;
  --good: #137a3a;
  --hl: #eef5ff;
  --s-none: #8a94a3;
  --s-recast: #1d6fd8;
  --s-norecast: #d9730d;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --border: #2a313b;
    --accent: #5b9dff;
    --accent-ink: #0b1220;
    --warn: #ffb35c;
    --warn-bg: #2b2110;
    --good: #4ccb7a;
    --hl: #16243a;
    --s-none: #7d8794;
    --s-recast: #5b9dff;
    --s-norecast: #f0913a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --text: #e6e9ee; --muted: #9aa4b2; --border: #2a313b;
  --accent: #5b9dff; --accent-ink: #0b1220; --warn: #ffb35c; --warn-bg: #2b2110; --good: #4ccb7a;
  --hl: #16243a; --s-none: #7d8794; --s-recast: #5b9dff; --s-norecast: #f0913a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.75rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.site-header { padding: 28px 0 8px; }
.lede { color: var(--muted); margin: 0; max-width: 60ch; }

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 16px;
  padding-top: 16px;
  padding-bottom: 16px;
  align-items: start;
}
.page-foot { padding-bottom: 40px; }
.inputs, .results { display: grid; gap: 16px; min-width: 0; }
/* Sticky sidebar scrolls on its own when it's taller than the window. */
@media (min-width: 861px) {
  .inputs { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; }
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }

.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 500; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 .field { margin-bottom: 12px; }
input, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--warn); }
.affix { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.affix:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.affix > span { padding: 0 0 0 10px; color: var(--muted); }
.affix.suffix > span { padding: 0 10px 0 0; }
.affix input { border: 0; outline: none; }
.hint { font-size: .82rem; color: var(--muted); margin: 0 0 10px; }
.stat { margin: 4px 0 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: .9rem; }

.btn {
  font: inherit; font-weight: 600; font-size: .85rem;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 8px; padding: 7px 12px; cursor: pointer;
}

.lumps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: lump; }
.lump {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
  padding: 12px 12px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.lump::before {
  counter-increment: lump;
  content: "#" counter(lump);
  position: absolute; top: -9px; left: 10px;
  background: var(--surface); padding: 0 4px;
  font-size: .75rem; color: var(--muted);
}
.lump .amt, .lump .when { grid-column: 1 / -1; }
.lump .when .row2 { gap: 8px; }
.lump .remove {
  position: absolute; top: 4px; right: 4px;
  width: 28px; height: 28px;
  border: 0; background: transparent; color: var(--muted);
  font-size: 1.2rem; line-height: 1; cursor: pointer; border-radius: 6px;
}
.lump .remove:hover { background: var(--hl); color: var(--text); }
.lump-warn { grid-column: 1 / -1; margin: 0 0 8px; font-size: .8rem; color: var(--warn); }

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
.compare thead th { font-size: .82rem; color: var(--muted); font-weight: 600; vertical-align: bottom; white-space: normal; }
.compare tbody th { font-weight: 500; color: var(--muted); font-size: .88rem; }
.compare td.best { color: var(--good); font-weight: 600; }
.compare small { display: block; color: var(--muted); font-size: .75rem; }

.notices { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.notices li { background: var(--warn-bg); color: var(--warn); padding: 6px 10px; border-radius: 6px; font-size: .85rem; }
.notices:empty { display: none; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.timeline li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 8px 10px; background: var(--hl); border-radius: 6px; font-size: .9rem; }
.timeline .date { font-weight: 600; min-width: 72px; }
.timeline .muted { color: var(--muted); }

.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .l-none { stroke: var(--s-none); }
.chart .l-recast { stroke: var(--s-recast); }
.chart .l-norecast { stroke: var(--s-norecast); stroke-dasharray: 6 4; }
.chart path { fill: none; stroke-width: 2.25; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.legend .sw { display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; border-radius: 2px; }
.s-none { background: var(--s-none); }
.s-recast { background: var(--s-recast); }
.s-norecast { background: var(--s-norecast); }

.schedule { max-height: 560px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.schedule table { font-size: .85rem; }
.schedule thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; color: var(--muted); font-weight: 600; }
.schedule tr.year { cursor: pointer; font-weight: 600; }
.schedule tr.year td:first-child::before { content: "▸ "; color: var(--muted); }
.schedule tr.year.open td:first-child::before { content: "▾ "; }
.schedule tr.month td:first-child { padding-left: 26px; color: var(--muted); }
.schedule tr.month[hidden] { display: none; }
.schedule tr.has-lump { background: var(--hl); }

.explainer p { max-width: 80ch; }
.disclaimer { font-size: .8rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; }
