:root {
  --ink: #0e1c2f;
  --ink-deep: #08111d;
  --ink-mid: #173257;
  --ink-soft: #2b4a75;
  --paper: #f2ead9;
  --paper-soft: #e8ddc7;
  --paper-line: #d8c9a4;
  --rule-blue: #93a9c8;
  --red-ink: #a6342a;
  --red-ink-soft: #c9564a;
  --ink-text: #f6f1e2;
  --ink-text-dim: #c7d2df;
  --paper-text: #1c2b3d;
  --paper-text-dim: #4c5a6c;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --body: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, monospace;
  --radius: 3px;
  --max: 1180px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--paper-text);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; color: inherit; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }
a { color: inherit; }
img, svg { max-width: 100%; display: block; }
button { font: inherit; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--red-ink); color: var(--ink-text); padding: 0.75em 1.25em; border-radius: var(--radius);
}
.skip-link:focus { left: 1em; top: 1em; }

:focus-visible { outline: 3px solid var(--red-ink); outline-offset: 2px; }

/* ---------- Header ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1em;
  max-width: var(--max); margin: 0 auto; padding: 1.4em 1.5em;
  font-family: var(--mono); font-size: 0.82rem; letter-spacing: 0.02em;
}
.site-mark { text-decoration: none; font-weight: 500; color: var(--paper-text); }
.site-nav { display: flex; align-items: center; gap: 1.4em; flex-wrap: wrap; }
.site-nav a { text-decoration: none; color: var(--paper-text-dim); border-bottom: 1px solid transparent; padding-bottom: 2px; }
.site-nav a:hover, .site-nav a:focus-visible { color: var(--red-ink); border-color: currentColor; }
.language-link { color: var(--paper-text) !important; font-weight: 500; }

/* ---------- Hero ---------- */
.hero {
  background: var(--ink); color: var(--ink-text);
  padding: 2.4em 1.5em 3em;
  position: relative;
}
.hero-grid {
  max-width: var(--max); margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 2.5em; align-items: center;
}
.eyebrow {
  font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--red-ink-soft); margin: 0 0 0.9em;
}
.scene .eyebrow, .closing-scene .eyebrow, .sources-scene .eyebrow { color: var(--red-ink); }
.hero h1 {
  font-size: clamp(2.6rem, 8vw, 4.6rem); line-height: 1.02; letter-spacing: -0.01em;
  margin: 0 0 0.4em;
}
.hero-standfirst { font-size: clamp(1.02rem, 2.2vw, 1.2rem); color: var(--ink-text-dim); max-width: 34em; margin: 0 0 1.4em; }
.hero-instruction {
  display: inline-flex; align-items: center; gap: 0.5em; text-decoration: none;
  color: var(--ink-text); font-family: var(--mono); font-size: 0.85rem;
  border-bottom: 1px solid var(--ink-soft); padding-bottom: 0.3em;
}
.hero-instruction:hover, .hero-instruction:focus-visible { border-color: var(--red-ink-soft); color: var(--red-ink-soft); }
.instruction-mark { display: inline-block; }
@media (prefers-reduced-motion: no-preference) {
  .hero-instruction:hover .instruction-mark { animation: bob 0.9s ease-in-out infinite; }
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }

.hero-visual { position: relative; }
.hero-ink { width: 100%; height: auto; }
.rule-lines path { stroke: var(--ink-soft); stroke-width: 1; opacity: 0.4; }
.rule-lines .rule-slant { stroke: var(--ink-soft); opacity: 0.22; stroke-width: 1; }
.ink-blot { opacity: 0.96; }
.ink-tail { opacity: 0.85; }
.mark-era { font-family: var(--mono); font-size: 22px; fill: var(--ink-text-dim); letter-spacing: 0.08em; }
.mark-era-right { fill: var(--red-ink-soft); text-anchor: end; }
.hero-caption {
  display: flex; justify-content: space-between; font-family: var(--mono); font-size: 0.78rem;
  color: var(--ink-text-dim); margin-top: 0.6em; padding: 0 0.2em;
}

/* ---------- Stat band ---------- */
.stat-band {
  background: var(--paper-soft); border-top: 1px solid var(--paper-line); border-bottom: 1px solid var(--paper-line);
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: var(--max); margin: 0 auto;
}
.stat-item {
  padding: 1.6em 1.4em; border-left: 1px solid var(--paper-line);
  container-type: inline-size;
  display: flex; flex-direction: column; gap: 0.3em;
}
.stat-item:first-child { border-left: none; }
.stat-item strong {
  font-family: var(--mono); font-weight: 500; color: var(--red-ink);
  font-size: clamp(1.5rem, 13cqi, 2.1rem); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.stat-item span { font-size: 0.92rem; line-height: 1.3; }
.stat-item small { font-size: 0.78rem; color: var(--paper-text-dim); line-height: 1.35; }

/* ---------- Scenes ---------- */
.scene { padding: 4.4em 1.5em; }
.scene-ink { background: var(--ink); color: var(--ink-text); }
.scene-ink .eyebrow { color: var(--red-ink-soft); }
.scene-ink .scene-index { color: var(--ink-soft); }
.scene-paper { background: var(--paper); }
.scene-grid {
  max-width: var(--max); margin: 0 auto;
  display: grid; grid-template-columns: 3.4em minmax(0, 1fr); column-gap: 1.6em; row-gap: 1.6em;
}
.scene-index { font-family: var(--mono); font-size: 0.85rem; color: var(--paper-line); padding-top: 0.3em; }
.scene-intro { grid-column: 2; max-width: 42em; }
.scene-intro h2 { font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.08; margin-bottom: 0.5em; }
.scene-intro p { color: inherit; }
.scene-body { grid-column: 2; max-width: 42em; display: flex; flex-direction: column; gap: 1.1em; font-size: 1.04rem; }
.scene-body p { margin: 0; }
.inline-source { color: var(--red-ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.scene-ink .inline-source { color: var(--red-ink-soft); }

/* ---------- Timeline ---------- */
.timeline {
  grid-column: 2; margin-top: 0.8em; max-width: 52em;
  display: flex; align-items: stretch; flex-wrap: wrap; gap: 0.4em 0;
}
.timeline-station {
  flex: 1 1 12em; background: var(--paper); border: 1px solid var(--paper-line); border-radius: var(--radius);
  padding: 1.2em 1.3em; display: flex; flex-direction: column; gap: 0.3em; min-width: 12em;
  container-type: inline-size;
}
.station-index { font-family: var(--mono); font-size: 0.72rem; color: var(--paper-text-dim); }
.station-value { font-family: var(--mono); font-size: clamp(1.5rem, 15cqi, 2rem); color: var(--red-ink); font-variant-numeric: tabular-nums; }
.station-year { font-weight: 600; font-size: 0.98rem; }
.station-note { color: var(--paper-text-dim); font-size: 0.82rem; }
.timeline-station .inline-source { font-size: 0.78rem; margin-top: 0.2em; }
.timeline-arrow {
  align-self: center; font-family: var(--mono); color: var(--paper-text-dim); padding: 0 0.5em; font-size: 1.1rem;
}
@media (max-width: 640px) { .timeline-arrow { display: none; } .timeline-station { flex-basis: 100%; } }

/* ---------- EHI test form ---------- */
.ehi-form { grid-column: 2; max-width: 46em; }
.ehi-questions { display: flex; flex-direction: column; gap: 0.9em; }
.ehi-question {
  border: 1px solid var(--paper-line); border-radius: var(--radius); padding: 1.1em 1.2em;
  margin: 0; background: var(--paper);
}
.ehi-question legend {
  font-family: var(--display); font-weight: 600; font-size: 1.05rem; padding: 0 0.3em 0.6em 0;
  display: flex; align-items: baseline; gap: 0.6em;
}
.question-index { font-family: var(--mono); font-size: 0.78rem; font-weight: 400; color: var(--red-ink); }
.scale-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.4em; }
.scale-option {
  display: flex; flex-direction: column; align-items: center; gap: 0.35em; text-align: center;
  padding: 0.6em 0.3em; border-radius: var(--radius); cursor: pointer; font-size: 0.72rem; color: var(--paper-text-dim);
  border: 1px solid transparent;
}
.scale-option:hover { background: var(--paper-soft); }
.scale-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.scale-option:has(input:focus-visible) { outline: 2px solid var(--red-ink); outline-offset: 1px; }
.scale-dot {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--paper-line); background: var(--paper);
}
.scale-option:has(input:checked) { color: var(--paper-text); font-weight: 600; }
.scale-option:has(input:checked) .scale-dot { background: var(--red-ink); border-color: var(--red-ink); }
.scale-option:nth-child(3):has(input:checked) .scale-dot { background: var(--ink-mid); border-color: var(--ink-mid); }

.ehi-actions { display: flex; align-items: center; gap: 1em; flex-wrap: wrap; margin-top: 1.4em; }
.ehi-submit, .ehi-reset {
  font-family: var(--mono); font-size: 0.85rem; padding: 0.75em 1.4em; border-radius: var(--radius); border: none;
  cursor: pointer; background: var(--ink); color: var(--ink-text);
}
.ehi-submit:disabled { background: var(--paper-line); color: var(--paper-text-dim); cursor: not-allowed; }
.ehi-submit:not(:disabled):hover { background: var(--red-ink); }
.ehi-reset { background: transparent; border: 1px solid var(--paper-line); color: var(--paper-text); }
.ehi-reset:hover { border-color: var(--red-ink); color: var(--red-ink); }
.ehi-progress { font-family: var(--mono); font-size: 0.78rem; color: var(--paper-text-dim); margin: 0; }

.ehi-result {
  margin-top: 1.8em; padding: 1.6em; border-radius: var(--radius); background: var(--ink); color: var(--ink-text);
  container-type: inline-size;
}
.result-headline { display: flex; align-items: baseline; gap: 0.5em; flex-wrap: wrap; }
.result-label { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-text-dim); letter-spacing: 0.08em; }
.result-lq { font-family: var(--mono); font-size: clamp(2.2rem, 16cqi, 3.2rem); color: var(--red-ink-soft); font-variant-numeric: tabular-nums; }
.result-lq-unit { font-family: var(--mono); font-size: 0.85rem; color: var(--ink-text-dim); }
.result-axis {
  position: relative; height: 14px; border-radius: 7px; overflow: hidden; margin: 1em 0 0.6em; display: flex;
}
.axis-zone { height: 100%; }
.axis-zone-left { width: 20%; background: var(--red-ink); }
.axis-zone-mixed { width: 60%; background: var(--ink-soft); }
.axis-zone-right { width: 20%; background: var(--ink-mid); }
.axis-marker {
  position: absolute; top: -5px; left: var(--marker-position, 50%); width: 3px; height: 24px; background: var(--ink-text);
  transform: translateX(-50%); border-radius: 2px;
}
.axis-marker::after {
  content: ''; position: absolute; top: -6px; left: 50%; width: 8px; height: 8px; background: var(--ink-text);
  border-radius: 50%; transform: translateX(-50%);
}
.result-band { font-size: 0.98rem; margin-top: 0.6em; }
.result-band strong { color: var(--red-ink-soft); }
.result-reflection { color: var(--ink-text-dim); font-size: 0.95rem; }
.population-title { font-family: var(--display); font-size: 1.05rem; margin: 1.4em 0 0.6em; }
.population-bar { display: flex; height: 34px; border-radius: var(--radius); overflow: hidden; }
.bar-segment { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 0.7rem; }
/* Widths mirror POPULATION_SHAPE in src/content.mjs (86.9 / 11.0 / 2.1) — update both together. */
.bar-right { width: 86.9%; background: var(--ink-mid); }
.bar-left { width: 11%; background: var(--red-ink); }
.bar-ambi { width: 2.1%; background: var(--ink-soft); }
.population-legend { display: flex; gap: 1.2em; margin-top: 0.6em; font-size: 0.78rem; color: var(--ink-text-dim); flex-wrap: wrap; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 0.4em; }
.legend-right { background: var(--ink-mid); } .legend-left { background: var(--red-ink); } .legend-ambi { background: var(--ink-soft); }
.population-note { font-size: 0.78rem; color: var(--ink-text-dim); margin-top: 0.8em; }
.ehi-method { font-size: 0.82rem; color: var(--paper-text-dim); margin-top: 1.2em; }

/* ---------- Closing ---------- */
.closing-scene { background: var(--ink); color: var(--ink-text); padding: 5em 1.5em; text-align: center; }
.closing-grid { max-width: 34em; margin: 0 auto; display: flex; flex-direction: column; gap: 0.7em; align-items: center; }
.closing-scene h2 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.12; }
.closing-scene p { color: var(--ink-text-dim); font-size: 1.05rem; }
.closing-link { color: var(--ink-text); font-family: var(--mono); font-size: 0.85rem; text-decoration: none; border-bottom: 1px solid var(--ink-soft); padding-bottom: 0.2em; margin-top: 0.4em; }
.closing-link:hover { border-color: var(--red-ink-soft); color: var(--red-ink-soft); }

/* ---------- Sources ---------- */
.sources-scene { background: var(--paper); padding: 4.4em 1.5em; }
.sources-wrap { max-width: var(--max); margin: 0 auto; }
.sources-heading { max-width: 42em; margin-bottom: 2em; }
.sources-heading h2 { font-size: clamp(1.7rem, 4vw, 2.2rem); margin-bottom: 0.5em; }
.method-note { color: var(--paper-text-dim); font-size: 0.9rem; margin-top: 0.8em; }
.source-list { display: flex; flex-direction: column; }
.source-row {
  display: grid; grid-template-columns: 3em minmax(0, 1fr) auto; gap: 1em; align-items: start;
  padding: 1.1em 0; border-top: 1px solid var(--paper-line);
}
.source-row:last-child { border-bottom: 1px solid var(--paper-line); }
.source-number { font-family: var(--mono); font-size: 0.78rem; color: var(--paper-text-dim); padding-top: 0.2em; }
.source-type { font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--red-ink); }
.source-copy h3 { font-family: var(--body); font-weight: 600; font-size: 0.98rem; margin: 0.2em 0 0.2em; }
.source-copy p { font-size: 0.88rem; color: var(--paper-text-dim); margin: 0; }
.source-link { font-family: var(--mono); font-size: 0.8rem; text-decoration: none; color: var(--paper-text); white-space: nowrap; align-self: center; }
.source-link:hover { color: var(--red-ink); }

/* ---------- Footer ---------- */
.site-footer {
  max-width: var(--max); margin: 0 auto; padding: 2em 1.5em 3em;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1em;
  font-family: var(--mono); font-size: 0.8rem; color: var(--paper-text-dim);
}
.site-footer a { text-decoration: none; color: inherit; margin-right: 1.2em; }
.site-footer a:hover { color: var(--red-ink); }
.site-footer div:last-child a:last-child { margin-right: 0; }

.back-top {
  position: fixed; right: 1.2em; bottom: 1.2em; z-index: 20;
  background: var(--ink); color: var(--ink-text); font-family: var(--mono); font-size: 0.78rem;
  padding: 0.6em 0.9em; border-radius: 999px; text-decoration: none; opacity: 0; pointer-events: none;
  transform: translateY(6px); transition: opacity 0.2s ease, transform 0.2s ease;
}
.back-top.is-enhanced.is-visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .back-top { transition: none; } }
.back-top span { display: inline; }

/* ---------- 404 ---------- */
.not-found {
  min-height: 100vh; display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: 2em; background: var(--ink); color: var(--ink-text); font-family: var(--body);
}
.not-found h1 { font-family: var(--display); font-size: 2.2rem; margin: 0.2em 0; }
.text-link { color: var(--red-ink-soft); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .hero-grid { grid-template-columns: 1fr; }
  .hero-visual { order: -1; max-width: 26em; margin: 0 auto; }
  .scene-grid { grid-template-columns: 1fr; }
  .scene-index { display: none; }
  .scene-intro, .scene-body, .timeline, .ehi-form { grid-column: 1; }
  .stat-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-item:nth-child(3) { border-left: none; }
  .stat-item:nth-child(1), .stat-item:nth-child(3) { border-left: none; }
  .stat-item:nth-child(2n) { border-left: 1px solid var(--paper-line); }
}

@media (max-width: 640px) {
  .site-header { flex-direction: column; align-items: flex-start; gap: 0.6em; }
  .site-nav { gap: 1em; }
  .hero { padding: 2em 1.1em 2.4em; }
  .scene, .closing-scene, .sources-scene { padding: 3em 1.1em; }
  .scale-row { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.2em; }
  .scale-option { font-size: 0.62rem; padding: 0.4em 0.1em; }
  .scale-dot { width: 16px; height: 16px; }
  .source-row { grid-template-columns: 1fr; gap: 0.3em; }
  .source-number { display: none; }
  .source-link { justify-self: start; }
}

@media (max-width: 400px) {
  .stat-band { grid-template-columns: 1fr; }
  .stat-item { border-left: none !important; border-top: 1px solid var(--paper-line); }
  .stat-item:first-child { border-top: none; }
}
