/* The Lucky Country Ledger — shared styles.
   Light palette on :root; dark under prefers-color-scheme guarded by
   :root:not([data-theme="light"]) and again under :root[data-theme="dark"]. */

:root {
  color-scheme: light;
  /* ground + surfaces */
  --ground: #fafaf8;
  --surface: #fcfcfb;
  --surface-2: #f2f1ec;
  --border: rgba(11, 11, 11, 0.10);
  /* ink */
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  /* chart chrome */
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  /* accent: eucalypt green (UI only, never a data series) */
  --accent: #0f6b48;
  --accent-strong: #0a5236;
  --accent-wash: rgba(15, 107, 72, 0.08);
  --gold: #9a6700;
  /* validated categorical series (dataviz reference palette) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --diverge-neutral: #f0efec;
  /* type */
  --sans: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --ground: #121210;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: rgba(255, 255, 255, 0.10);
    --ink: #f4f4ef;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --accent: #3dbd8a;
    --accent-strong: #5fd4a5;
    --accent-wash: rgba(61, 189, 138, 0.10);
    --gold: #d9a62e;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --diverge-neutral: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #121210;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: rgba(255, 255, 255, 0.10);
  --ink: #f4f4ef;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --accent: #3dbd8a;
  --accent-strong: #5fd4a5;
  --accent-wash: rgba(61, 189, 138, 0.10);
  --gold: #d9a62e;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --diverge-neutral: #383835;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.075rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- shell ---------- */
.shell { max-width: 76rem; margin: 0 auto; padding-inline: clamp(16px, 4vw, 40px); }
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .shell {
  display: flex; align-items: baseline; gap: 1.25rem; flex-wrap: wrap;
  padding-block: 0.7rem;
}
.wordmark {
  font-family: var(--sans); font-weight: 800; font-size: 1rem;
  letter-spacing: 0.01em; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.wordmark .tick { color: var(--accent); }
.site-nav { display: flex; gap: 0.25rem 1rem; flex-wrap: wrap; margin-left: auto; }
.site-nav a {
  font-family: var(--sans); font-size: 0.85rem; font-weight: 600;
  color: var(--ink-2); text-decoration: none; padding: 0.2rem 0;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  font: 600 0.75rem var(--sans); border-radius: 999px; padding: 0.25rem 0.7rem;
  cursor: pointer; white-space: nowrap;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 5rem; padding-block: 2rem 3rem;
  font-family: var(--sans); font-size: 0.85rem; color: var(--ink-3);
}
.site-footer a { color: var(--ink-2); }
.site-footer p { margin: 0.3rem 0; }

/* ---------- typography ---------- */
h1, h2, h3, h4 { font-family: var(--sans); line-height: 1.15; text-wrap: balance; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 800; letter-spacing: -0.015em; margin: 0 0 1rem; }
h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 800; letter-spacing: -0.01em; margin: 3rem 0 0.75rem; }
h3 { font-size: 1.15rem; font-weight: 700; margin: 2rem 0 0.5rem; }
p { margin: 0 0 1.1rem; }
.prose { max-width: 44rem; }
.prose p { max-width: 42rem; }
.lede { font-size: 1.25rem; line-height: 1.55; color: var(--ink); max-width: 40rem; }
.kicker {
  font-family: var(--sans); font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 0.6rem;
}
.byline { font-family: var(--sans); font-size: 0.9rem; color: var(--ink-3); }
strong { font-weight: 600; }
.mono, .num { font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--border); margin: 3rem 0; }
blockquote {
  margin: 1.5rem 0; padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 3px solid var(--accent); color: var(--ink-2); font-style: italic;
}

/* ---------- panels & cards ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: clamp(1rem, 2.5vw, 1.75rem);
  margin: 1.75rem 0;
}
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.chart-title { font-family: var(--sans); font-weight: 700; font-size: 1.02rem; margin: 0 0 0.15rem; }
.chart-sub { font-family: var(--sans); font-size: 0.85rem; color: var(--ink-2); margin: 0 0 1rem; }
.chart-note { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-3); margin: 0.75rem 0 0; }
.chart-note a { color: var(--ink-2); }

/* headline sentence that updates with the sliders */
.headline-sentence {
  font-family: var(--serif); font-size: clamp(1.15rem, 2.6vw, 1.5rem); line-height: 1.5;
  background: var(--accent-wash);
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 1rem 1.25rem; margin: 1.5rem 0;
}
.headline-sentence .hl { font-family: var(--sans); font-weight: 700; color: var(--accent-strong); white-space: nowrap; }
:root[data-theme="dark"] .headline-sentence .hl { color: var(--accent-strong); }
.headline-sentence .hl-bad { font-family: var(--sans); font-weight: 700; color: var(--critical); white-space: nowrap; }

/* stat tiles */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin: 1.5rem 0; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.9rem 1rem;
}
.stat .label { font-family: var(--sans); font-size: 0.78rem; font-weight: 600; color: var(--ink-2); margin: 0 0 0.25rem; }
.stat .value { font-family: var(--sans); font-size: 1.7rem; font-weight: 800; line-height: 1.1; margin: 0; }
.stat .detail { font-family: var(--sans); font-size: 0.78rem; color: var(--ink-3); margin: 0.25rem 0 0; }
.stat .value.bad { color: var(--critical); }
.stat .value.good { color: var(--good); }

/* hero number */
.hero-figure { font-family: var(--sans); font-weight: 800; font-size: clamp(3rem, 8vw, 4.5rem); line-height: 1; }

/* ---------- controls ---------- */
.controls {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem 2rem; margin: 1.25rem 0;
  font-family: var(--sans);
}
.control label { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; font-size: 0.88rem; font-weight: 600; color: var(--ink-2); margin-bottom: 0.35rem; }
.control output { font-weight: 800; color: var(--ink); font-size: 1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.control .ticks { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--ink-3); margin-top: 0.15rem; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; margin: 0; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), var(--surface-2) var(--fill, 50%));
  border: 1px solid var(--border);
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border);
}
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  margin-top: -8px;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-family: var(--sans); }
.seg button {
  border: 0; background: var(--surface); color: var(--ink-2);
  font: 600 0.82rem var(--sans); padding: 0.4rem 0.8rem; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { color: #0b0b0b; }

button.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }

/* preset chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; font-family: var(--sans); }
.chips button {
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--ink-2); font: 600 0.8rem var(--sans); padding: 0.35rem 0.85rem; cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--ink); }
.chips button[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--accent); color: var(--accent-strong); }

/* ---------- charts ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; font-family: var(--sans); }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  padding: 0.5rem 0.7rem; font-family: var(--sans); font-size: 0.8rem;
  min-width: 9rem; opacity: 0; transition: opacity 80ms linear;
}
.chart-tooltip .tt-title { font-weight: 700; color: var(--ink-2); margin-bottom: 0.25rem; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 0.45rem; margin-top: 2px; }
.chart-tooltip .tt-key { width: 12px; height: 3px; border-radius: 2px; flex: 0 0 auto; }
.chart-tooltip .tt-val { font-weight: 700; margin-left: auto; font-variant-numeric: tabular-nums; }
.chart-tooltip .tt-name { color: var(--ink-2); }
.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1.1rem; font-family: var(--sans); font-size: 0.8rem; color: var(--ink-2); margin: 0.4rem 0 0.5rem; }
.legend .key { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend .swatch-line { width: 14px; height: 3px; border-radius: 2px; }
.legend .swatch-rect { width: 11px; height: 11px; border-radius: 3px; }

/* table twin for every chart */
details.data-table { margin-top: 0.75rem; font-family: var(--sans); font-size: 0.82rem; }
details.data-table summary { cursor: pointer; color: var(--ink-3); font-weight: 600; }
details.data-table table { border-collapse: collapse; margin-top: 0.5rem; width: 100%; max-width: 36rem; }
details.data-table th, details.data-table td {
  text-align: right; padding: 0.25rem 0.6rem; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
details.data-table th:first-child, details.data-table td:first-child { text-align: left; }
details.data-table th { color: var(--ink-2); font-weight: 600; }
.table-scroll { overflow-x: auto; }

/* assumptions disclosure on each model */
details.assumptions {
  margin-top: 1rem; border-top: 1px dashed var(--baseline); padding-top: 0.75rem;
  font-family: var(--sans); font-size: 0.85rem; color: var(--ink-2);
}
details.assumptions summary { cursor: pointer; font-weight: 700; color: var(--ink-2); }
details.assumptions summary::marker { color: var(--accent); }
details.assumptions .formula {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.8rem; background: var(--surface-2); border-radius: 6px;
  padding: 0.6rem 0.8rem; margin: 0.6rem 0; overflow-x: auto; white-space: pre;
}
.flag-assert {
  display: inline-block; font: 700 0.68rem var(--sans); letter-spacing: 0.06em;
  color: var(--gold); border: 1px solid currentColor; border-radius: 4px;
  padding: 0.05rem 0.35rem; text-transform: uppercase; vertical-align: 0.1em;
}
.flag-data {
  display: inline-block; font: 700 0.68rem var(--sans); letter-spacing: 0.06em;
  color: var(--accent); border: 1px solid currentColor; border-radius: 4px;
  padding: 0.05rem 0.35rem; text-transform: uppercase; vertical-align: 0.1em;
}

/* generic content tables */
table.content {
  border-collapse: collapse; font-family: var(--sans); font-size: 0.9rem; width: 100%;
}
table.content th, table.content td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--grid); text-align: left; }
table.content td.num, table.content th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.content th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); }

/* chapter cards on the index */
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin: 2rem 0; }
.chapter-card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem 1.25rem 1.1rem; text-decoration: none; color: var(--ink);
  transition: border-color 120ms, transform 120ms;
}
.chapter-card:hover { border-color: var(--accent); transform: translateY(-2px); color: var(--ink); }
.chapter-card .ch-num { font: 800 0.75rem var(--sans); letter-spacing: 0.1em; color: var(--accent); text-transform: uppercase; }
.chapter-card h3 { margin: 0.4rem 0 0.4rem; font-size: 1.2rem; }
.chapter-card p { font-family: var(--sans); font-size: 0.88rem; color: var(--ink-2); margin: 0; line-height: 1.5; }
.chapter-card .ch-stat { font: 800 1.5rem var(--sans); margin: 0.5rem 0 0.35rem; color: var(--ink); }

/* footnote-ish source line under stats */
.source-line { font-family: var(--sans); font-size: 0.75rem; color: var(--ink-3); }

/* incapacity exhibits (the "state that can't" ledger) */
.exhibit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 0.75rem; margin: 1.5rem 0; }
.exhibit {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem 1.1rem; font-family: var(--sans);
}
.exhibit .ex-name { font-weight: 800; font-size: 0.95rem; margin: 0 0 0.5rem; }
.exhibit .ex-line { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.82rem; color: var(--ink-2); margin: 0.15rem 0; }
.exhibit .ex-line .ex-val { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; text-align: right; }
.exhibit .ex-line .ex-val.bad { color: var(--critical); }
.exhibit .ex-verdict { font-size: 0.8rem; color: var(--ink-3); margin: 0.6rem 0 0; border-top: 1px dashed var(--baseline); padding-top: 0.5rem; }
.exhibit .ex-verdict a { color: var(--ink-3); }

/* skip link */
.skip { position: absolute; left: -9999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 100; }
.skip:focus { left: 0; }

@media (max-width: 640px) {
  body { font-size: 1rem; }
  .site-nav { gap: 0.15rem 0.8rem; }
  .controls { grid-template-columns: 1fr; }
}
