:root {
	color-scheme: light;
	--page: #f9f9f7;
	--surface: #fcfcfb;
	--ink: #0b0b0b;
	--ink-2: #52514e;
	--muted: #6f6d68;
	--axis-ink: #898781;
	--grid: #e1e0d9;
	--baseline: #c3c2b7;
	--border: rgba(11, 11, 11, 0.10);
	--wash: rgba(11, 11, 11, 0.04);

	--us: #2a78d6;          /* series 1 — the U.S., ages at/above the pick */
	--us-dim: #b7d3f6;      /* same ramp, lighter step — ages below the pick */
	--c1: #eb6834;          /* comparison 1 */
	--c2: #1baf7a;          /* comparison 2 */
	--proj-band: rgba(11, 11, 11, 0.035);
	--gen-a: rgba(11, 11, 11, 0.045);
	--gen-b: rgba(11, 11, 11, 0.09);

	--radius: 12px;
	font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--page: #0d0d0d;
		--surface: #1a1a19;
		--ink: #f0efec;
		--ink-2: #c3c2b7;
		--muted: #a3a29b;
		--axis-ink: #898781;
		--grid: #2c2c2a;
		--baseline: #383835;
		--border: rgba(255, 255, 255, 0.10);
		--wash: rgba(255, 255, 255, 0.05);
		--us: #3987e5;
		--us-dim: #173d6e;
		--c1: #d95926;
		--c2: #199e70;
		--proj-band: rgba(255, 255, 255, 0.035);
		--gen-a: rgba(255, 255, 255, 0.04);
		--gen-b: rgba(255, 255, 255, 0.085);
	}
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--page: #0d0d0d;
	--surface: #1a1a19;
	--ink: #f0efec;
	--ink-2: #c3c2b7;
	--muted: #a3a29b;
	--axis-ink: #898781;
	--grid: #2c2c2a;
	--baseline: #383835;
	--border: rgba(255, 255, 255, 0.10);
	--wash: rgba(255, 255, 255, 0.05);
	--us: #3987e5;
	--us-dim: #173d6e;
	--c1: #d95926;
	--c2: #199e70;
	--proj-band: rgba(255, 255, 255, 0.035);
	--gen-a: rgba(255, 255, 255, 0.04);
	--gen-b: rgba(255, 255, 255, 0.085);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--page);
	color: var(--ink);
	font-size: 15px;
	line-height: 1.5;
}
main {
	max-width: 1080px;
	margin: 0 auto;
	padding: 28px 16px 40px;
}
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: clamp(26px, 5vw, 36px); line-height: 1.15; }
h2 { font-size: 17px; }
p { margin: 0; }
.muted { color: var(--muted); }
.lede { color: var(--ink-2); margin-top: 6px; max-width: 46em; }
.masthead { margin-bottom: 20px; }

/* ---------- controls: one row above everything they scope ---------- */
.controls {
	display: grid;
	grid-template-columns: minmax(220px, 1.3fr) minmax(220px, 1.3fr) minmax(180px, 1fr) auto;
	gap: 14px 22px;
	align-items: start;
	padding: 14px 16px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	position: sticky;
	top: 0;
	z-index: 5;
}
.control > label:first-child {
	display: block;
	font-size: 12px;
	font-weight: 600;
	color: var(--ink-2);
	margin-bottom: 4px;
}
.year-row, .age-row, .compare-row { display: flex; align-items: center; gap: 8px; }
.compare-row + .compare-row { margin-top: 6px; }
output {
	min-width: 3.4em;
	font-weight: 650;
	font-size: 17px;
	font-variant-numeric: tabular-nums;
	text-align: right;
}
input[type="range"] { flex: 1; min-width: 0; accent-color: var(--us); }
select {
	flex: 1;
	min-width: 0;
	font: inherit;
	font-size: 14px;
	color: var(--ink);
	background: var(--page);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 5px 8px;
}
.check { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--ink-2); padding-top: 22px; white-space: nowrap; cursor: pointer; }
.check input { accent-color: var(--us); width: 16px; height: 16px; margin: 0; }
.key { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.key-c1 { background: var(--c1); }
.key-c2 { background: var(--c2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chips button, .seg button, .text-btn, .icon-btn {
	font: inherit;
	color: var(--ink-2);
	background: transparent;
	border: 1px solid var(--border);
	border-radius: 999px;
	cursor: pointer;
}
.chips button { font-size: 12px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
.chips button:hover, .seg button:hover, .text-btn:hover, .icon-btn:hover { background: var(--wash); }
.chips button[aria-pressed="true"] { color: var(--ink); border-color: var(--us); box-shadow: inset 0 0 0 1px var(--us); font-weight: 600; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; padding: 0; flex: none; }
.icon-btn svg { width: 14px; height: 14px; fill: var(--ink); }
.icon-btn .i-pause { display: none; }
.icon-btn.playing .i-play { display: none; }
.icon-btn.playing .i-pause { display: inline; }
:focus-visible { outline: 2px solid var(--us); outline-offset: 2px; }

/* ---------- hero + tiles ---------- */
.hero {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 12px 28px;
	margin: 26px 0 16px;
}
.hero-main { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.hero-figure { font-size: clamp(52px, 11vw, 76px); font-weight: 650; line-height: 0.95; letter-spacing: -0.03em; }
.hero-figure.na, .hero-compare .na { color: var(--muted); }
.hero-text { padding-bottom: 6px; }
.hero-text p:first-child { font-size: 19px; font-weight: 550; }
.hero-compare { display: flex; flex-wrap: wrap; gap: 6px 22px; padding-bottom: 6px; }
.hero-compare .cmp { display: flex; flex-direction: column; }
.hero-compare .cmp-v { font-size: 22px; font-weight: 650; }
.hero-compare .cmp-n { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.pill {
	display: inline-block;
	font-size: 11px;
	font-weight: 650;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	padding: 1px 7px;
	border-radius: 999px;
	border: 1px solid var(--border);
	color: var(--ink-2);
	vertical-align: 2px;
}

.tiles {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 12px;
	margin-bottom: 16px;
}
.tile {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 12px 14px;
}
.tile-label { font-size: 13px; color: var(--ink-2); }
.tile-value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.tile-cmp { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; }
.tile-cmp span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- cards & charts ---------- */
.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px;
	margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head .muted { font-size: 13px; margin-top: 2px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.seg button { border: 0; font-size: 13px; padding: 3px 12px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.text-btn { font-size: 13px; padding: 4px 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; color: var(--ink-2); margin: 2px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.ln { width: 16px; height: 2px; border-radius: 1px; display: inline-block; flex: none; }
.ln.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px) !important; }

.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: inherit; }
.tick { font-size: 11px; fill: var(--axis-ink); font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.axisline { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.lbl { font-size: 12px; fill: var(--ink-2); }
.lbl-strong { font-size: 12px; font-weight: 650; fill: var(--ink); }
.gen-lbl { font-size: 11px; fill: var(--ink-2); }
.note { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 1em; }
.note:empty { display: none; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 12px; font-weight: 600; color: var(--ink-2); border-bottom-color: var(--baseline); vertical-align: bottom; }
thead th span { display: inline-flex; align-items: center; gap: 6px; }
tbody td { font-variant-numeric: tabular-nums; }
tbody tr.sel td { background: var(--wash); font-weight: 650; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--wash); }
td.na { color: var(--muted); }

/* ---------- tooltip ---------- */
.tooltip {
	position: fixed;
	z-index: 20;
	pointer-events: none;
	background: var(--surface);
	color: var(--ink);
	border: 1px solid var(--border);
	border-radius: 8px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
	padding: 8px 10px;
	font-size: 13px;
	min-width: 150px;
	max-width: 280px;
}
.tooltip .tt-h { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-r .k { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .tt-r b { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt-f { margin-top: 5px; color: var(--muted); font-size: 12px; }

/* ---------- notes ---------- */
.notes ul { margin: 8px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.notes li + li { margin-top: 6px; }
.foot { font-size: 12px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 4px 2px; }
.ver { font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
	.controls { grid-template-columns: 1fr 1fr; }
	.tiles { grid-template-columns: repeat(2, 1fr); }
	.check { padding-top: 0; }
}
@media (max-width: 560px) {
	main { padding-top: 18px; }
	.controls { grid-template-columns: 1fr; position: static; gap: 12px; }
	.hero-figure { font-size: 54px; }
	.tile-value { font-size: 20px; }
	th, td { padding: 6px 7px; }
}
