/* CHW Charts. Tokens match DESIGN-GUIDELINES.md §12 (and src/chw_charts/tokens.py). */
:root {
  --blue: #274490;  --blue-dark: #1E3574;  --deep: #16264F;
  --tint: #EAEEF9;  --paper: #FFF;         --paper-warm: #F4F2EB;
  --live: #D8402A;  --archive: #B98A2E;    --archive-ink: #8F6A1E;
  --card: #FFF;  --ink: #16264F;  --body: #38415A;
  --muted: #5C6478;  --faint: #61697D;
  --rule: #E3E0D6;   --rule-soft: #EDEAE0;
  --f-display: 'Schibsted Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --f-body:    'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --f-mono:    'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --wrap: 760px;  --gut: 20px;
  --r-sm: 6px;  --r: 10px;  --r-lg: 16px;
  --card-pad: 22px;
}
@media (min-width: 768px) { :root { --gut: 32px; } }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--body);
  font: 16px/1.6 var(--f-body);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--blue-dark); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 3px; }

.kicker {
  font: 500 .72rem/1.4 var(--f-mono); letter-spacing: .16em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 .5rem;
}

/* ── The chart card: identical in page, embed and PNG ─────────────────────── */
.chw-card { margin: 0; background: var(--card); overflow: hidden; }
.chw-card__head { padding: var(--card-pad) var(--card-pad) 0; }
.chw-card__title {
  font: 800 1.5rem/1.15 var(--f-display); letter-spacing: -.02em;
  color: var(--ink); margin: 0; text-wrap: balance;
}
.chw-card__sub {
  margin: .5rem 0 0; color: var(--body); font-size: 1rem; line-height: 1.5;
  text-wrap: pretty; max-width: 62ch;
}
.chw-card__plot { padding: 18px var(--card-pad) 0; min-height: 120px; }
#vis { width: 100%; }
#vis.vega-embed { display: block; }
.chw-card__plot svg { display: block; overflow: visible; }
.chw-card__meta {
  padding: 14px var(--card-pad) 16px;
  font: 400 .72rem/1.6 var(--f-mono); letter-spacing: .02em; color: var(--faint);
}
.chw-card__meta span + span::before { content: " · "; }
.chw-card__meta a { color: var(--faint); }
.chw-card__meta a:hover { color: var(--blue); }
.chw-card__brand {
  display: flex; align-items: center; gap: 8px;
  background: var(--blue); color: #fff; padding: 8px var(--card-pad);
}
.chw-card__brand img { border-radius: 5px; display: block; }
.chw-card__wordmark { font: 800 .9rem/1 var(--f-display); letter-spacing: -.01em; }
.chw-card__url {
  margin-left: auto; font: 500 .68rem/1 var(--f-mono); letter-spacing: .04em; color: #C9D4F0;
}
@media (max-width: 420px) {
  :root { --card-pad: 16px; }
  .chw-card__title { font-size: 1.3rem; }
  .chw-card__url { display: none; }
}

/* Map legend (HTML, above the plot) */
.chw-legend { margin: 0 0 14px; font: 400 .72rem/1.4 var(--f-mono); color: var(--muted); }
.chw-legend__title { margin: 0 0 6px; font-weight: 500; color: var(--body); }
.chw-legend__scale { list-style: none; margin: 0; padding: 0; display: flex; gap: 2px; }
.chw-legend__scale li { flex: 1 1 0; min-width: 0; max-width: 76px; }
.chw-legend__sw { display: block; height: 10px; margin-bottom: 4px; }
.chw-legend__scale li:first-child .chw-legend__sw { box-shadow: inset 0 0 0 1px var(--rule); }
.chw-legend__nodata { margin-left: 8px; }
.chw-legend__nodata .chw-legend__sw { box-shadow: inset 0 0 0 1px var(--rule); }
.chw-legend__marker { margin: 8px 0 0; }
.chw-legend__marker span { color: var(--ink); font-family: var(--f-body); font-size: .9rem; }

/* Series key (line charts): always present for 2+ series, so colour is never the only cue */
.chw-keys { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px;
  font: 400 .72rem/1.4 var(--f-mono); color: var(--body); }
.chw-keys li { display: inline-flex; align-items: center; gap: 6px; }
.chw-keys__line { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.chw-keys__square { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* Tables (presets/table.py) */
.chw-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chw-grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; line-height: 1.4; }
.chw-grid th {
  font: 500 .68rem/1.3 var(--f-mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); vertical-align: bottom; padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--rule); background: var(--card);
}
.chw-grid th button {
  all: unset; cursor: pointer; display: inline; /* inline so long headers wrap */
}
.chw-grid th button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 3px; }
.chw-grid th button::after { content: " ↕"; opacity: .35; font-size: .9em; white-space: nowrap; }
.chw-grid th[aria-sort="ascending"] button::after { content: " ↑"; opacity: 1; }
.chw-grid th[aria-sort="descending"] button::after { content: " ↓"; opacity: 1; }
.is-static .chw-grid th button::after { content: none; }
.chw-grid td {
  padding: 8px 12px 8px 0; border-bottom: 1px solid var(--rule-soft);
  vertical-align: baseline; color: var(--body); background: var(--card);
}
.chw-grid tbody tr:last-child td { border-bottom: 0; }
.chw-grid tbody tr:hover td:not(.heat):not(.fill) { background: #FAFAF6; }
.chw-grid .al-left { text-align: left; }
.chw-grid .al-right { text-align: right; }
.chw-grid .al-center { text-align: center; }
.chw-grid td.mono { font-family: var(--f-mono); font-size: .82rem; font-variant-numeric: tabular-nums; }
.chw-grid td.bold { font-weight: 700; color: var(--ink); }
.chw-grid td.small { font-size: .78rem; line-height: 1.45; }
.chw-grid .wide { min-width: 16em; }
.chw-grid td.heat, .chw-grid td.fill { padding-left: 8px; padding-right: 8px; border-bottom-color: var(--card); }
.chw-grid th:last-child, .chw-grid td:last-child { padding-right: 0; }
.chw-grid td.heat:last-child, .chw-grid td.fill:last-child { padding-right: 8px; }
/* Heat steps: the §7 ramp without its middle step, so text passes AA on every fill. */
.chw-grid td.heat-0 { background: #EAEEF9; color: var(--ink); }
.chw-grid td.heat-1 { background: #A4B4D7; color: var(--ink); }
.chw-grid td.heat-2 { background: #274490; color: #fff; }
.chw-grid td.heat-3 { background: #16264F; color: #fff; }
.chw-grid td.fill { background: var(--tint); color: var(--ink); font-weight: 600; }
.chw-grid.is-sticky tr > :first-child { position: sticky; left: 0; z-index: 1; }
.badge {
  display: inline-block; font: 600 .66rem/1.2 var(--f-mono); letter-spacing: .08em;
  text-transform: uppercase; padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.badge--neutral { background: #EDEAE0; color: #38415A; }
.badge--blue { background: #EAEEF9; color: #274490; }
.badge--green { background: #E3EFE6; color: #2A6B3D; }
.badge--gold { background: #F6EEDC; color: #8A6516; }
/* red = the §3 error pair: white on brand red (4.48:1) fails AA at badge size */
.badge--red { background: #FBEAE7; color: #8C2718; }

/* badge_style: "cell" (vote grids): the same §3 pairs, tinting the whole cell */
.chw-grid td.tone {
  font: 600 .7rem/1.3 var(--f-mono); letter-spacing: .06em; text-transform: uppercase;
  text-align: center; padding-left: 8px; padding-right: 8px; border-bottom-color: var(--card);
}
.chw-grid td.tone--neutral { background: #EDEAE0; color: #38415A; }
.chw-grid td.tone--blue { background: #EAEEF9; color: #274490; }
.chw-grid td.tone--green { background: #E3EFE6; color: #2A6B3D; }
.chw-grid td.tone--gold { background: #F6EEDC; color: #8A6516; }
.chw-grid td.tone--red { background: #FBEAE7; color: #8C2718; }

/* Rank column */
.chw-grid .rank { width: 2.5rem; min-width: 2.5rem; max-width: 2.5rem; color: var(--faint); padding-right: 10px; }
/* rem, not em: the rank cell and the pinned cell beside it have different font sizes */
.chw-grid.is-sticky.has-rank tr > :nth-child(2) { position: sticky; left: 2.5rem; z-index: 1; }

/* Bars in cells */
.cellbar { display: flex; align-items: center; gap: 8px; }
.cellbar__num { min-width: 3.5em; text-align: right; flex: none; }
.cellbar__track { position: relative; flex: 1 1 auto; min-width: 72px; height: 10px; }
.cellbar__fill { position: absolute; top: 0; bottom: 0; background: var(--blue); border-radius: 2px; }
.cellbar__zero { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.chw-grid td.has-bar { min-width: 11em; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.chw-search { margin: 0 0 12px; }
.chw-search input {
  width: 100%; max-width: 320px; font: 400 .95rem/1.2 var(--f-body); color: var(--body);
  background: #FCFCFA; border: 1px solid #CFD3D9; border-radius: var(--r-sm); padding: 10px 12px;
}
.chw-search input:focus { outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(39,68,144,.16); }
.chw-search__empty { font: 400 .8rem var(--f-mono); color: var(--faint); margin: 10px 0 0; }

/* PNG export (?static): nothing interactive, nothing that only works on screen. */
.is-static .interactive-only { display: none !important; }

/* Tooltip (vega-tooltip, theme "custom") */
#vg-tooltip-element.custom-theme {
  font: 400 12px/1.5 var(--f-mono); color: var(--body);
  background: #fff; border: 1px solid var(--rule); border-radius: var(--r-sm);
  box-shadow: 0 2px 4px rgba(22,38,79,.06), 0 12px 32px rgba(22,38,79,.10);
  padding: 8px 10px; pointer-events: none; position: fixed; z-index: 1000;
  visibility: hidden;
}
#vg-tooltip-element.custom-theme.visible { visibility: visible; }
#vg-tooltip-element.custom-theme table { border-spacing: 0; }
#vg-tooltip-element.custom-theme td { padding: 1px 0; vertical-align: top; }
#vg-tooltip-element.custom-theme td.key { color: var(--muted); padding-right: 10px; max-width: 160px; text-align: left; }
#vg-tooltip-element.custom-theme td.value { color: var(--ink); font-weight: 600; text-align: left; max-width: 300px; white-space: normal; }
#vg-tooltip-element.custom-theme h2 { font: 800 .95rem/1.2 var(--f-display); color: var(--ink); margin: 0 0 6px; }

/* ── Chart page chrome (mode-page only) ───────────────────────────────────── */
.mode-page { background: var(--paper-warm); }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 50; background: #fff; padding: 8px 12px; }
.masthead { background: var(--blue); position: sticky; top: 0; z-index: 30; }
.masthead__in {
  max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gut);
  min-height: 56px; display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 11px; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand img { border-radius: 7px; }
.brand__name { font: 800 1.05rem/1 var(--f-display); letter-spacing: -.01em; }
.chip {
  font: 600 .68rem/1 var(--f-mono); letter-spacing: .1em; text-transform: uppercase;
  background: rgba(255,255,255,.18); color: #fff; border-radius: 4px; padding: 5px 7px;
}
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 28px var(--gut) 48px; }
.mode-page .chw-card { border: 1px solid var(--rule); border-radius: var(--r-lg); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
.btn {
  display: inline-flex; align-items: center; min-height: 40px;
  font: 700 .9rem/1 var(--f-body); text-decoration: none; border-radius: var(--r);
  padding: 9px 16px; transition: background-color .15s ease, border-color .15s ease;
}
.btn--ghost { color: var(--blue); border: 1px solid #C7CEE4; background: transparent; }
.btn--ghost:hover { background: var(--tint); color: var(--blue); }
.btn:active { transform: translateY(1px); }
.panel {
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--r);
  margin: 10px 0; padding: 0 18px;
}
.panel summary {
  cursor: pointer; font: 700 .95rem/1 var(--f-display); color: var(--ink);
  padding: 14px 0; min-height: 40px;
}
.panel[open] { padding-bottom: 16px; }
.panel p { margin: 0 0 10px; font-size: .95rem; }
.panel textarea {
  width: 100%; font: 400 .76rem/1.5 var(--f-mono); color: var(--body);
  background: #FCFCFA; border: 1px solid #CFD3D9; border-radius: var(--r-sm); padding: 10px 12px;
  resize: vertical;
}
.table-scroll { overflow-x: auto; }
.chw-table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.chw-table th {
  font: 500 .68rem/1.3 var(--f-mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--rule);
}
.chw-table td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--rule-soft); }
.chw-table .num { text-align: right; font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
/* Gallery (site home page) */
.wrap--wide { max-width: 1080px; }
.chip { text-decoration: none; }
.chip:hover { color: #fff; background: rgba(255,255,255,.28); }
.gallery__title { font: 800 clamp(2.1rem, 5.4vw, 3.4rem)/1.12 var(--f-display); letter-spacing: -.02em; color: var(--ink); margin: 0; }
.gallery__lede { font-size: clamp(1.05rem, 2vw, 1.2rem); max-width: 62ch; margin: .75rem 0 2rem; text-wrap: pretty; }
.gallery { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.gallery__card {
  position: relative; background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg);
  overflow: hidden; transition: box-shadow .15s ease, transform .15s ease;
}
.gallery__card:hover { box-shadow: var(--shadow-lift, 0 2px 4px rgba(22,38,79,.06), 0 12px 32px rgba(22,38,79,.10)); transform: translateY(-2px); }
.gallery__thumb { aspect-ratio: 16 / 10; background: var(--tint); border-bottom: 1px solid var(--rule-soft); overflow: hidden; }
.gallery__thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.gallery__body { padding: 16px 18px 18px; }
.gallery__body .kicker { margin-bottom: .4rem; }
.gallery__name { font: 700 1.05rem/1.25 var(--f-display); letter-spacing: -.01em; margin: 0; text-wrap: balance; }
.gallery__name a { color: var(--ink); text-decoration: none; }
.gallery__name a::after { content: ""; position: absolute; inset: 0; }
.gallery__card:hover .gallery__name a { color: var(--blue); }
.gallery__date { font: 400 .74rem/1.4 var(--f-mono); color: var(--faint); margin: .6rem 0 0; letter-spacing: .02em; }
.site-foot { text-align: center; padding: 0 var(--gut) 40px; font-size: .9rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
