/* Palette: the dataviz reference instance. Categorical slots 1–4 validated
   (validate_palette.js) in both modes on the adjacent pairlist. Aqua and yellow
   sit under 3:1 on the light surface, so every chart ships with legend chips,
   direct labels where they fit, and a table view. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --link: #1c5cab;
  --wash: rgba(42, 120, 214, 0.12);
  --focus: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  /* Ordinal blue ramp for the mosaic, most concentrated darkest. Steps from the
     palette's sequential blue; the lightest ordinal step clears 2:1. */
  --tier-0: #1c5cab;
  --tier-1: #3987e5;
  --tier-2: #86b6ef;
  --tier-rest: #e1e0d9;
  --tier-ink-0: #ffffff;
  --tier-ink-1: #ffffff;
  --tier-ink-2: #0b0b0b;
  --tier-ink-rest: #52514e;
  /* Quantised sequential blue for heatmaps: least (q0) recedes toward the
     surface, most (q6) is darkest. The palette's sequential steps 100–700. */
  --q0: #eeeeea;
  --q1: #cde2fb;
  --q2: #9ec5f4;
  --q3: #6da7ec;
  --q4: #3987e5;
  --q5: #256abf;
  --q6: #0d366b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --link: #86b6ef;
    --wash: rgba(57, 135, 229, 0.2);
    --focus: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    /* On the dark surface, more concentrated reads as brighter. */
    --tier-0: #86b6ef;
    --tier-1: #3987e5;
    --tier-2: #184f95;
    --tier-rest: #2c2c2a;
    --tier-ink-0: #0b0b0b;
    --tier-ink-1: #0b0b0b;
    --tier-ink-2: #ffffff;
    --tier-ink-rest: #c3c2b7;
    /* On dark, least recedes into the surface and most is brightest. */
    --q0: #242423;
    --q1: #104281;
    --q2: #184f95;
    --q3: #256abf;
    --q4: #3987e5;
    --q5: #6da7ec;
    --q6: #b7d3f6;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.top, main, footer { max-width: 1120px; margin-inline: auto; padding-inline: 16px; }

.top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 24px; padding-block: 20px 4px; }
.brand { color: var(--ink); font-size: 18px; font-weight: 650; text-decoration: none; }
.brand span { color: var(--ink-2); font-weight: 400; }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav a { padding: 5px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; }
nav a:hover { color: var(--ink); }
nav a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: 0 0 0 1px var(--border); }

main { padding-block: 8px 32px; transition: opacity 0.15s; }
main.busy { opacity: 0.6; }
footer { padding-block: 0 32px; color: var(--ink-2); font-size: 12px; }
.error { color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.loading, .muted { color: var(--ink-2); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-block: 16px; }
.panel h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.note { margin: 2px 0 12px; color: var(--ink-2); font-size: 13px; }
.note.wide { margin: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 0 16px; }
.intro p { margin-top: 0; }
.intro ol { margin: 0; padding-left: 1.4em; }

/* controls */
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 16px; margin-block: 8px; }
.field { display: grid; gap: 2px; font-size: 12px; color: var(--ink-2); }
select, input, button { font: inherit; color: var(--ink); }
select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; color: var(--ink-2); font-size: 13px; }
.pager button { padding: 5px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.pager button:disabled { color: var(--muted); cursor: default; }

/* search */
.search { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-block: 8px; }
.combo { position: relative; flex: 1 1 280px; }
.combo input {
  width: 100%; padding: 9px 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.combo input:disabled { color: var(--muted); }
.results {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
.results li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 12px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.results li[aria-selected="true"] { background: var(--wash); }
.r-name { font-weight: 600; }
.r-meta { color: var(--ink-2); font-size: 13px; }
.r-empty { color: var(--ink-2); cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.chip button { border: 0; background: none; color: var(--ink-2); font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 999px; cursor: pointer; }
.chip button:hover { background: var(--wash); color: var(--ink); }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; flex: none; }
.chip .key { margin-right: 0; }

/* summary cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 0 16px; }
.card { margin-block: 16px 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0 0; }
.stat dt { color: var(--ink-2); font-size: 12px; }
.stat dd { margin: 0; }
.stat .v { display: block; font-size: 22px; font-weight: 600; line-height: 1.3; }
.stat .sub { display: block; color: var(--ink-2); font-size: 12px; }

/* charts */
.chart { position: relative; border-radius: 6px; }
.chart svg { display: block; touch-action: pan-y; }
.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--surface); stroke-width: 2; }
.end-label { fill: var(--ink-2); font-size: 12px; }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.tip {
  position: absolute; z-index: 3; pointer-events: none; min-width: 150px;
  padding: 8px 10px; font-size: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.tip-title { color: var(--ink-2); margin-bottom: 2px; }
.tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tip-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tip-v { font-weight: 600; color: var(--ink); }
.tip-l { color: var(--ink-2); }

/* tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--grid); text-align: left; }
thead th { color: var(--ink-2); font-size: 12px; font-weight: 500; }
tbody th { font-weight: 500; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.change { color: var(--ink-2); }
.new { font-size: 12px; color: var(--ink-2); }
.table-view summary { cursor: pointer; font-weight: 600; }
.table-view table { margin-top: 12px; }

.eras { font-size: 13px; }
.eras th, .eras td { padding: 1px 2px; border-bottom: 0; }
.eras thead th { padding: 4px; }
.eras a { display: block; padding: 1px 4px; border-radius: 4px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.eras.tracing a:not(.hl) { color: var(--muted); }
.eras a.hl { background: var(--wash); font-weight: 600; }
.tie { color: var(--muted); font-size: 11px; font-weight: 400; }
.mark { stroke: var(--ink-2); stroke-width: 1; opacity: 0.35; }

/* stories */
.lede { max-width: 72ch; margin-block: 20px 12px; }
.lede .kicker { margin: 0; color: var(--ink-2); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.lede h1 { margin: 4px 0 8px; font-size: clamp(26px, 4.2vw, 38px); line-height: 1.12; font-weight: 700; letter-spacing: -0.01em; }
.lede p { margin: 0; color: var(--ink-2); font-size: 16px; }
.section-title { margin: 28px 0 10px; font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.06em; text-transform: uppercase; }
.button { padding: 7px 14px; border: 1px solid var(--ink); border-radius: 8px; background: var(--ink); color: var(--surface); cursor: pointer; }
.button:hover { opacity: 0.85; }

.hub { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 12px; }
.tile { display: block; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); text-decoration: none; }
.tile:hover { box-shadow: 0 0 0 2px var(--focus); }
.tile h3 { margin: 0 0 4px; font-size: 17px; }
.tile p { margin: 0; color: var(--ink-2); font-size: 14px; }

/* a class of 30 */
.classes { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 0 16px; }
.desks { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 10px 8px; margin: 0; padding: 0; list-style: none; }
.desk {
  position: relative; display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 8px; align-items: center;
  padding: 7px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--page);
}
.initial { grid-row: span 2; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--wash); font-weight: 600; }
.desk-name a { color: var(--ink); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.desk-name a:hover { text-decoration: underline; }
.desk-meta { color: var(--ink-2); font-size: 12px; }
.desk.twin { border-color: transparent; box-shadow: 0 0 0 2px var(--s2); }
/* name comets */
.jump { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: 13px; cursor: pointer; }
.chip-btn:hover { color: var(--ink); border-color: var(--ink-2); }
.shape { scroll-margin-top: 12px; }
.shape-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-bottom: 12px; }
.shape-head .note { margin-bottom: 0; }
.hero-spark { display: block; width: 240px; max-width: 100%; height: 72px; }
.sparks { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.spark-card { display: grid; gap: 1px; height: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--page); color: var(--ink); text-decoration: none; }
.spark-card:hover, .spark-card:focus-visible { border-color: var(--s1); }
.mini-spark { display: block; width: 100%; height: 34px; margin-bottom: 4px; }
.spark-area { fill: var(--s1); opacity: 0.12; }
.spark-line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.spark-name { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.spark-meta { color: var(--ink-2); font-size: 11px; }
.spark-compare { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; opacity: 0.7; }

/* the scattering */
.scatter-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-bottom: 8px; }
.big-year { font-size: clamp(40px, 8vw, 64px); font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.scrub { display: flex; flex: 1 1 280px; align-items: center; gap: 12px; }
.slider { flex: 1; accent-color: var(--s1); }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 10px; color: var(--ink-2); font-size: 12px; }
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 3px; vertical-align: -2px; }
.swatch.tier-0 { background: var(--tier-0); }
.swatch.tier-1 { background: var(--tier-1); }
.swatch.tier-2 { background: var(--tier-2); }
.swatch.tier-rest { background: var(--tier-rest); }
.mosaic-wrap { width: 100%; }
.mosaic { display: block; }
.tile.tier-0 rect { fill: var(--tier-0); }
.tile.tier-1 rect { fill: var(--tier-1); }
.tile.tier-2 rect { fill: var(--tier-2); }
.tile.tier-rest rect { fill: var(--tier-rest); }
.tile text { font-weight: 600; pointer-events: none; }
.tile.tier-0 text { fill: var(--tier-ink-0); }
.tile.tier-1 text { fill: var(--tier-ink-1); }
.tile.tier-2 text { fill: var(--tier-ink-2); }
.tile.tier-rest text { fill: var(--tier-ink-rest); }
.tile .tile-sub { font-weight: 400; opacity: 0.85; }
.tile:hover rect { opacity: 0.85; }
.kpis { margin-top: 16px; }

/* the sound of a generation */
.heat { position: relative; }
.heat svg { display: block; touch-action: pan-y; }
.heat .q0, .swatch.q0 { fill: var(--q0); background: var(--q0); }
.heat .q1, .swatch.q1 { fill: var(--q1); background: var(--q1); }
.heat .q2, .swatch.q2 { fill: var(--q2); background: var(--q2); }
.heat .q3, .swatch.q3 { fill: var(--q3); background: var(--q3); }
.heat .q4, .swatch.q4 { fill: var(--q4); background: var(--q4); }
.heat .q5, .swatch.q5 { fill: var(--q5); background: var(--q5); }
.heat .q6, .swatch.q6 { fill: var(--q6); background: var(--q6); }
.heat-legend { align-items: center; gap: 3px; }
.heat-legend .swatch { margin: 0; border-radius: 2px; }
.heat-legend > span:first-child { margin-right: 6px; }
.heat-legend > span:last-child { margin-left: 6px; }
.heat-letter { font-weight: 600; }
.heat-hl { fill: none; stroke: var(--ink); stroke-width: 2; pointer-events: none; }
.chip.static { padding-right: 10px; }
.heat-cols .panel { margin-block: 16px 0; }

/* century echoes */
.bars, .matrix { display: block; width: 100%; height: auto; }
.chip-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.jump.tight { margin-block: 4px 12px; }
.bar { fill: var(--s1); }
.bar-low { fill: var(--s2); }
.bar-label { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.matrix rect.q0 { fill: var(--q0); } .matrix rect.q1 { fill: var(--q1); } .matrix rect.q2 { fill: var(--q2); }
.matrix rect.q3 { fill: var(--q3); } .matrix rect.q4 { fill: var(--q4); } .matrix rect.q5 { fill: var(--q5); }
.matrix rect.q6 { fill: var(--q6); }
.cell-num { fill: var(--ink); font-size: 10px; font-variant-numeric: tabular-nums; pointer-events: none; }
.cell-num.on-strong { fill: var(--tier-ink-0); }
.controls.tight { margin-block: 4px 12px; }
.river { position: relative; }
.river svg { display: block; touch-action: pan-y; }
.river-bg path { fill: none; stroke: var(--grid); stroke-width: 1; }
.river-name .line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; opacity: 0.55; }
.river-name .hit { fill: none; stroke: transparent; stroke-width: 12; }
.river-name .dot { fill: var(--s1); opacity: 0.7; }
.river-name.active .line, .river-name:focus .line { stroke: var(--ink); opacity: 1; stroke-width: 3; }
.river-name.active .dot { fill: var(--ink); opacity: 1; }
.river-name:focus { outline: none; }
.echo-list { columns: 16em; column-gap: 24px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 13px; }
.echo-list li { break-inside: avoid; padding: 2px 0; }

/* drifting names */
.seesaw { position: relative; }
.seesaw svg { display: block; touch-action: pan-y; }
.midline { stroke: var(--axis); stroke-width: 1; }
.axis-label { font-weight: 600; }
.seesaw-dot { transition: transform 0.7s ease; cursor: default; }
.seesaw-dot circle { stroke: var(--surface); stroke-width: 1.5; opacity: 0.85; }
.seesaw-dot.absent { opacity: 0; pointer-events: none; }
.seesaw-dot.active circle { stroke: var(--ink); stroke-width: 2; opacity: 1; }
.seesaw-dot:focus { outline: none; }
/* A surface-coloured halo keeps names legible where they cross dots. */
.seesaw-label { fill: var(--ink-2); font-size: 11px; pointer-events: none; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.label-follow { pointer-events: none; }
.label-follow.active .seesaw-label { fill: var(--ink); font-weight: 600; }
.label-follow.active .seesaw-label.hidden-label { display: inline; }
.seesaw-dot.active .seesaw-label { fill: var(--ink); font-weight: 600; }
.trail { fill: none; stroke-width: 2; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.trail.on { opacity: 0.6; }
@media (prefers-reduced-motion: reduce) { .seesaw-dot { transition: none; } }
.swatch.round { border-radius: 50%; }
.drifts { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
/* Fixed track and number columns, so every dumbbell shares one 0–100% scale. */
.drifts li { display: grid; grid-template-columns: minmax(64px, 1fr) minmax(100px, 200px) 92px; align-items: center; gap: 10px; font-size: 14px; }
.drifts .drift-nums { text-align: right; }
.seesaw-label.hidden-label { display: none; }
.seesaw-dot.active .seesaw-label.hidden-label { display: inline; }
.dumbbell { width: 100%; height: 16px; display: block; }
.dumbbell .track { stroke: var(--grid); stroke-width: 2; }
.dumbbell .mid { stroke: var(--axis); stroke-width: 1; }
.dumbbell .span { stroke-width: 3; stroke-linecap: round; }
.dumbbell .from { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.5; }
.dumbbell .to { stroke: var(--surface); stroke-width: 2; }
.drift-nums { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* name families */
.slope { display: block; width: 100%; min-width: 560px; height: auto; }
.slope-head { fill: var(--ink-2); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.slope-label { fill: var(--ink); font-size: 13px; }
.slope-num { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.slope-line { stroke: var(--axis); stroke-width: 1.5; }
.slope-line.up { stroke: var(--s1); stroke-width: 2.5; }
.compact-fams { margin: 0; padding: 0; list-style: none; }
.compact-fams li {
  display: grid; grid-template-columns: 2em minmax(0, 1fr) auto; grid-template-areas: "rank name num" ". was was";
  column-gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--grid);
}
.cf-rank { grid-area: rank; color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }
.cf-name { grid-area: name; font-weight: 600; overflow-wrap: anywhere; }
.cf-num { grid-area: num; font-variant-numeric: tabular-nums; }
.cf-was { grid-area: was; font-size: 12px; }
.fam-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.fam-card { margin: 0; padding: 12px; background: var(--page); }
.fam-head { margin-bottom: 8px; }
.fam-head a { font-weight: 600; }
.fam-bar { display: block; width: 100%; height: 14px; }
.fam-bar .seg-lead { fill: var(--tier-0); }
.fam-bar .seg-rest { fill: var(--tier-2); }
.fam-members { margin: 8px 0 0; font-size: 13px; }
.fam-members .lead { font-weight: 600; }

/* before they're everywhere */
.love-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.love-form input { flex: 1 1 220px; padding: 7px 12px; font-size: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--page); }
.legend-line { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--s1); vertical-align: middle; }
.legend-line.compare { border-top-color: var(--muted); }

.badge { position: absolute; top: -8px; right: -6px; padding: 0 6px; border-radius: 999px; background: var(--ink); color: var(--surface); font-size: 11px; font-weight: 600; line-height: 18px; }
