:root {
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --muted: #767676;
  --line: #e4e4e4;
  --line-strong: #cfcfcf;
  --paper: #ffffff;
  --paper-alt: #fafaf8;
  --accent: #1d4e89;
  --accent-soft: #e8eef5;
  --us: #111111;
  /* error-rate / tier ramp */
  --t0: #4a9c6d;
  --t5: #d9a441;
  --t10: #d9743f;
  --t15: #c23b34;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .kicker, .controls, .tabbar, button, select, label, table, .stat, .note { font-family: var(--sans); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
.wide { max-width: 1240px; }

/* ---------- Masthead ---------- */
header.masthead { border-bottom: 2px solid var(--ink); padding: 48px 0 32px; }
.kicker { text-transform: uppercase; letter-spacing: 0.12em; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 14px; }
h1 { font-size: 44px; line-height: 1.12; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em; }
.dek { font-size: 21px; line-height: 1.5; color: var(--ink-soft); max-width: none; margin: 0; }
.byline { margin-top: 20px; font-family: var(--sans); font-size: 13px; color: var(--muted); }

/* ---------- Prose ---------- */
.fn { font-size: 0.62em; vertical-align: super; line-height: 0; font-family: var(--sans); }
.fn a { color: var(--accent); text-decoration: none; font-weight: 700; }
details.method[id] { scroll-margin-top: 70px; }
.prose { max-width: 680px; margin: 0 auto; }
.prose.leftcol { margin: 0; max-width: none; }
.prose p { font-size: 19px; margin: 0 0 22px; }
.prose h2 { font-size: 15px; }
section { padding: 40px 0; border-top: 1px solid var(--line); scroll-margin-top: 58px; }
section:first-of-type { border-top: none; }
.section-head { margin: 0 0 8px; max-width: 760px; text-align: left; }
.section-head .kicker { color: var(--muted); }
h2 { font-size: 28px; line-height: 1.2; margin: 0 0 10px; font-weight: 700; letter-spacing: -0.01em; }
.section-sub { font-family: var(--serif); font-size: 18px; color: var(--ink-soft); max-width: none; margin: 0 0 22px; }

/* ---------- Sticky control bar ---------- */
.stickybar { position: sticky; top: 0; z-index: 40; background: rgba(255,255,255,0.96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line-strong); }
.stickybar .inner { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 24px; max-width: 1240px; margin: 0 auto; }
.stickybar .brand { font-weight: 700; font-size: 13px; letter-spacing: 0.02em; }
.stickybar .spacer { flex: 1; }
.tabbar { display: flex; gap: 2px; flex-wrap: wrap; }
.tabbar a { font-size: 12.5px; color: var(--ink-soft); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.tabbar a:hover { background: var(--paper-alt); }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.ctl { display: flex; flex-direction: column; gap: 5px; }
.ctl label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; }
select, input[type="number"], .btn {
  font-family: var(--sans); font-size: 14px; padding: 7px 10px; border: 1px solid var(--line-strong);
  border-radius: 7px; background: var(--paper); color: var(--ink); cursor: pointer;
}
input[type="number"] { width: 78px; cursor: text; }
.btn { font-weight: 600; }
.btn:hover, select:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.toggle-group { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.toggle-group button { border: none; border-radius: 0; padding: 7px 12px; background: var(--paper); font-size: 13px; }
.toggle-group button.on { background: var(--accent); color: #fff; }

/* state picker */
.statepicker { position: relative; }
.statepicker .menu {
  display: none; position: absolute; z-index: 50; top: 100%; left: 0; margin-top: 4px;
  width: 320px; max-height: 360px; overflow: auto; background: #fff; border: 1px solid var(--line-strong);
  border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,0.12); padding: 10px;
}
.statepicker.open .menu { display: block; }
.statepicker .menu .quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.statepicker .menu .quick button { font-size: 11.5px; padding: 4px 8px; }
.statepicker .menu input.search { width: 100%; margin-bottom: 8px; cursor: text; }
.checkrow { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; font-family: var(--sans); font-size: 13.5px; }
.checkrow:hover { background: var(--paper-alt); }
.checkrow .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* ---------- Chart frames ---------- */
.chart-frame { position: relative; width: 100%; }
.quad-list { position: absolute; width: 196px; max-height: 84%; overflow: auto; font-family: var(--sans); font-size: 12px; background: rgba(255,255,255,0.95); border: 1px solid var(--line-strong); border-radius: 9px; padding: 11px 13px; box-shadow: 0 4px 16px rgba(0,0,0,0.07); }
.quad-list.left { left: 56px; }   /* clear the y-axis labels */
.quad-list.right { right: 16px; }
.quad-list.top { top: 12px; }
.quad-list.bottom { bottom: 34px; } /* clear the x-axis labels */
.quad-list h4 { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 7px; font-weight: 700; }
.quad-list .row { display: flex; justify-content: space-between; gap: 12px; padding: 2.5px 0; }
.quad-list .row .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-frame.tall { height: 520px; }
.chart-frame.mid { height: 440px; }
.legend-note { font-family: var(--sans); font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* typology tabs + per-quadrant explanation */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 6px; }
.tabs button { font-family: var(--sans); font-size: 13px; padding: 8px 14px; border: 1px solid var(--line-strong); background: #fff; border-radius: 8px; cursor: pointer; color: var(--ink-soft); font-weight: 600; }
.tabs button:hover { border-color: var(--accent); }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.quad-explain { font-family: var(--serif); font-size: 17px; line-height: 1.55; color: var(--ink); max-width: 780px; margin: 6px 0 16px; }

/* closing coda — set apart and weightier */
.coda { max-width: none; margin: 36px 0 0; padding-top: 28px; border-top: 2px solid var(--ink); }
.coda p { font-family: var(--serif); font-size: 23px; line-height: 1.45; color: var(--ink); margin: 0 0 18px; }
.coda p:last-child { font-weight: 600; }

/* ---------- Stat strip ---------- */
.statstrip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 24px 0; }
.stat { background: #fff; padding: 18px 16px; }
.stat .num { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.stat .lab { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.35; }
.stat .num.alert { color: var(--t15); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); user-select: none; position: sticky; top: 0; background: #fff; box-shadow: 0 1px 0 var(--line); }
th.sorted::after { content: " \25BC"; font-size: 9px; color: var(--accent); }
th.sorted.asc::after { content: " \25B2"; }
#penaltyTable thead th { cursor: pointer; }
#penaltyTable thead th.sorted { color: var(--ink); }
body.editing #penaltyTable thead th { cursor: text; }
tbody tr:hover { background: var(--paper-alt); }
.tier-pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 700; color: #fff; }
.table-scroll { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.delay-row td { opacity: 0.62; font-style: italic; }
.delay-tag { font-size: 10px; background: #efe7d6; color: #876a1b; padding: 1px 6px; border-radius: 10px; margin-left: 6px; font-style: normal; font-weight: 700; }

/* ---------- What-if panel ---------- */
.whatif { background: var(--paper-alt); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 22px; }
.whatif h3 { margin: 0 0 4px; font-size: 15px; }
.whatif .sub { font-family: var(--serif); font-size: 14.5px; color: var(--muted); margin: 0 0 16px; }
.tier-editor { display: flex; gap: 10px; flex-wrap: wrap; }
.tier-card { border: 1px solid var(--line-strong); border-radius: 9px; padding: 10px 12px; min-width: 150px; }
.tier-card .tlab { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.tier-card .fld { display: flex; align-items: center; gap: 6px; font-size: 12.5px; margin-top: 4px; }
.tier-card .fld input { width: 64px; }
.whatif .extra { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }

/* ---------- callouts / methodology ---------- */
.callout { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 16px 20px; border-radius: 0 8px 8px 0; margin: 22px 0; max-width: none; font-size: 16px; }
.caveat { border-left: 3px solid var(--t10); background: #fdf4ee; }
.sources { font-family: var(--sans); font-size: 13.5px; }
.sources li { margin-bottom: 8px; }
.sources a { color: var(--accent); }
details.method { border: 1px solid var(--line); border-radius: 10px; padding: 4px 18px; margin: 14px 0; max-width: none; background: #fff; }
details.method summary { font-family: var(--sans); font-weight: 700; cursor: pointer; padding: 12px 0; font-size: 14px; }
footer { border-top: 2px solid var(--ink); padding: 30px 0 60px; font-family: var(--sans); font-size: 13px; color: var(--muted); }
.dl-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0; }

@media (max-width: 720px) {
  h1 { font-size: 32px; } .dek { font-size: 18px; }
  .prose p { font-size: 17px; }
  .statstrip { grid-template-columns: repeat(2, 1fr); }
  th { position: static; }
  .stickybar .tabbar { display: none; }
  .section-sub, .dek, .prose.leftcol { font-size: 16px; }
  /* quad-list drops below the chart on phones instead of overlaying it */
  .quad-list { position: static; width: auto; transform: none; max-height: none; margin-top: 10px; box-shadow: none; }
  .quad-list.left, .quad-list.right { left: auto; right: auto; }
}
