:root {
  --bg: #0e141f;
  --panel: #161f2d;
  --panel-2: #1c283a;
  --ink: #eef1f6;
  --ink-dim: #a7b2c4;
  --ink-faint: #66748c;
  --line: #26324a;
  --contributor: #4fa3a0;
  --pensioner: #c97a5a;
  --highlight: #e3b23c;
  --danger: #d9695f;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --wrap: 800px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f8f5f0;
    --panel: #ffffff;
    --panel-2: #efe9df;
    --ink: #171b22;
    --ink-dim: #4b5563;
    --ink-faint: #71798a;
    --line: #e0d9cc;
    --contributor: #2e7d78;
    --pensioner: #a8562f;
    --highlight: #96700f;
    --danger: #b23b30;
  }
}

:root[data-theme="light"] {
  --bg: #f8f5f0;
  --panel: #ffffff;
  --panel-2: #efe9df;
  --ink: #171b22;
  --ink-dim: #4b5563;
  --ink-faint: #71798a;
  --line: #e0d9cc;
  --contributor: #2e7d78;
  --pensioner: #a8562f;
  --highlight: #96700f;
  --danger: #b23b30;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
.tier, .instrument, .stat, .result-panel, button, .theme-toggle, .top, .year-scrub, .method {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 22px; }

.top { padding: 16px 22px; font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top a { color: var(--ink-faint); text-decoration: none; }
.top a:hover { color: var(--highlight); }
.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--highlight); border-color: var(--highlight); }

.masthead { padding-top: 8px; padding-bottom: 12px; }
.kicker {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--highlight);
  margin: 0 0 16px;
}
h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 48px;
  line-height: 1.1;
  margin: 0 0 18px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.deck {
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.5;
  color: var(--ink-dim);
  margin: 0 0 6px;
  font-weight: 500;
  font-style: italic;
}

article { padding-bottom: 8px; }
p { margin: 0 0 22px; color: var(--ink); }
p.lede { font-size: 19px; }
a { color: var(--highlight); }
strong { color: var(--ink); font-weight: 600; }
ul, ol { padding-left: 22px; }
li { margin-bottom: 10px; }

h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  margin: 36px 0 14px;
  color: var(--ink);
}
h3 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 16.5px;
  margin: 22px 0 10px;
  color: var(--ink);
}

.langbar { margin: 18px 0 6px; font-size: 14px; color: var(--ink-faint); }
.langbar a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid var(--line); }
.langbar a:hover { color: var(--highlight); border-color: var(--highlight); }
.langbar .current { color: var(--highlight); }

.tiers { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 4px 0 30px; }
.tier {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.tier .tier-name { font-family: var(--mono); font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--highlight); margin-bottom: 4px; }
.tier p { margin-bottom: 0; font-size: 15.5px; color: var(--ink-dim); }

/* --- Instrument --- */
.instrument {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 18px 24px;
  margin: 8px 0 32px;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  margin-bottom: 20px;
}
.control label {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.control .control-value {
  font-family: var(--mono);
  color: var(--highlight);
  font-weight: 600;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--highlight);
  height: 26px;
}

.instrument-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
button {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--highlight); color: var(--highlight); }
button[aria-pressed="true"] { color: var(--highlight); border-color: var(--highlight); }

.pyramid-wrap { margin-bottom: 8px; }
.pyramid-wrap svg, .chart-wrap svg { width: 100%; height: auto; display: block; }
.pyramid-r-label, .axis-text { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-faint); }
.ceiling-text { fill: var(--highlight); }
.gridline { stroke: var(--line); stroke-width: 1; }
.ceiling-line { stroke: var(--highlight); stroke-width: 1.3; stroke-dasharray: 4,3; }
.cursor-line { stroke: var(--ink-faint); stroke-width: 1; opacity: 0.5; }
.line-contrib { fill: none; stroke: var(--contributor); stroke-width: 2.2; }
.line-pension { fill: none; stroke: var(--pensioner); stroke-width: 2.2; }
.line-burden { fill: none; stroke: var(--danger); stroke-width: 2.4; }
.line-burden-ref { fill: none; stroke: var(--ink-faint); stroke-width: 2; stroke-dasharray: 5,4; opacity: 0.85; }
.cross-dot { fill: var(--highlight); stroke: var(--bg); stroke-width: 1.5; }

.chart-caption {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  margin: 4px 0 20px;
  text-align: center;
}

.year-scrub {
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.year-scrub-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.year-scrub-head .year { font-family: var(--serif); font-size: 26px; color: var(--highlight); font-weight: 600; }

.result-panel {
  margin-top: 18px;
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  color: var(--ink);
}
.result-panel strong { color: var(--danger); font-family: var(--mono); }

.legend-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 10px 0 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.legend-swatch { display: inline-block; width: 12px; height: 3px; margin-right: 5px; vertical-align: 2px; }
.legend-swatch-dashed { display: inline-block; width: 12px; height: 0; border-top: 2px dashed var(--ink-faint); margin-right: 5px; vertical-align: 3px; }

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 4px 0 28px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}
.stat .num {
  font-family: var(--serif);
  font-size: 30px;
  color: var(--highlight);
  font-weight: 600;
  line-height: 1.05;
  margin-bottom: 6px;
}
.stat .lbl { font-size: 13.5px; color: var(--ink-faint); }

.method {
  font-size: 15px;
  color: var(--ink-dim);
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 6px;
}
.method p { margin-bottom: 16px; }
.method h3 { color: var(--ink-dim); }
.source-list { font-size: 14px; }
.source-list li { margin-bottom: 8px; }

footer {
  border-top: 1px solid var(--line);
  margin-top: 30px;
  padding: 22px 0 40px;
  font-size: 13.5px;
  color: var(--ink-faint);
}
footer a { color: var(--ink-dim); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 560px) {
  h1 { font-size: 34px; }
  .deck { font-size: 17.5px; }
  .stat-row { grid-template-columns: 1fr; }
  .controls-grid { grid-template-columns: 1fr; }
  .instrument { padding: 16px 12px 18px; }
  .year-scrub-head .year { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
