:root {
  --paper: #f6f8fa;
  --paper-warm: #eef2f5;
  --card: #ffffff;
  --ink: #101820;
  --ink-muted: #47535e;
  --ink-dim: #485360;
  --border: #dde5ea;
  --border-strong: #c3d0d8;

  --river-deep: #0b3050;
  --river-mid: #14507a;
  --river-bright: #2f7ba6;
  --ice: #d7ecf4;
  --ice-bright: #eef8fb;
  --ember: #c05a3c;
  --ember-bright: #d97757;
  --ember-pale: #ffe8dd;
  --ember-on-dark: #ffc4b0;
  --ember-text: #a8462c;

  --font-serif: "Iowan Old Style", "Sitka Text", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Roboto Mono", Menlo, Monaco, Consolas, monospace;

  --max-w: 760px;
  --max-w-wide: 1040px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(11, 48, 80, 0.08);
  --shadow-md: 0 8px 30px rgba(11, 48, 80, 0.10);

  --header-bg: rgba(246, 248, 250, 0.9);
  --hero-glow: var(--ice-bright);
  --accent-text: var(--river-deep);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0c141f;
    --paper-warm: #111c29;
    --card: #142132;
    --ink: #eef4f8;
    --ink-muted: #a9bbcb;
    --ink-dim: #7c90a3;
    --border: #26364a;
    --border-strong: #37495e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.45);
    --header-bg: rgba(12, 20, 31, 0.85);
    --hero-glow: #101d2c;
    --accent-text: #7fc7e8;
    --ember-text: #ff9370;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0c141f;
  --paper-warm: #111c29;
  --card: #142132;
  --ink: #eef4f8;
  --ink-muted: #a9bbcb;
  --ink-dim: #7c90a3;
  --border: #26364a;
  --border-strong: #37495e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.45);
  --header-bg: rgba(12, 20, 31, 0.85);
  --hero-glow: #101d2c;
  --accent-text: #7fc7e8;
  --ember-text: #ff9370;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background: var(--paper);
  color: var(--ink);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  line-height: 1.7;
  background:
    linear-gradient(180deg, var(--hero-glow) 0%, var(--paper) 340px);
  min-height: 100vh;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.site-container { max-width: var(--max-w); margin: 0 auto; padding: 0 1.5rem; }
.site-container-wide { max-width: var(--max-w-wide); margin: 0 auto; padding: 0 1.5rem; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.header-controls { display: flex; align-items: center; gap: 0.6rem; }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--ink-muted); cursor: pointer; padding: 0;
}
.theme-toggle:hover { border-color: var(--river-bright); color: var(--accent-text); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.5rem;
}
.brand-link {
  display: flex; align-items: center; gap: 0.6rem;
  text-decoration: none; color: var(--ink);
  font-family: var(--font-sans); font-size: 0.9rem; font-weight: 600;
}
.brand-badge {
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 500;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--river-mid); background: var(--ice);
  padding: 0.2rem 0.55rem; border-radius: 999px;
}
.lang-nav { display: flex; gap: 0.35rem; }
.lang-btn {
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 600;
  text-decoration: none; color: var(--ink-dim);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 0.3rem 0.75rem;
}
.lang-btn.active { color: var(--river-deep); border-color: var(--river-bright); background: var(--ice); }
.lang-btn:hover { border-color: var(--river-bright); color: var(--accent-text); }
.lang-btn.active:hover { color: var(--river-deep); }

/* Hero */
main.site-container, main.site-container-wide { padding-top: 3rem; padding-bottom: 5rem; }
.hero { padding-bottom: 2.5rem; }
.hero-tag {
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-text);
  margin-bottom: 1rem;
}
.hero-title {
  font-family: var(--font-serif); font-weight: 600;
  font-size: clamp(2.1rem, 5vw, 3.1rem); line-height: 1.12;
  color: var(--ink); letter-spacing: -0.01em; margin-bottom: 1.1rem;
}
.hero-subtitle {
  font-family: var(--font-serif); font-size: 1.2rem; line-height: 1.6;
  color: var(--ink-muted); max-width: 42em;
}

/* Metrics */
.metrics-banner {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--border); border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden; margin: 2.5rem 0;
}
.metric-card { background: var(--card); padding: 1.35rem 1.1rem; }
.metric-val {
  font-family: var(--font-serif); font-size: 1.65rem; font-weight: 600;
  color: var(--accent-text); line-height: 1.1; margin-bottom: 0.4rem;
}
.metric-card.accent .metric-val { color: var(--ember-text); }
.metric-label { font-size: 0.8rem; font-weight: 600; color: var(--ink); margin-bottom: 0.3rem; }
.metric-desc { font-size: 0.78rem; color: var(--ink-dim); line-height: 1.4; }

/* Interactive section */
.interactive-section {
  background: var(--river-deep);
  border-radius: var(--radius-lg);
  padding: 2.2rem 1.6rem 2.4rem;
  margin: 3rem 0;
  box-shadow: var(--shadow-md);
  color: var(--ice-bright);
}
.section-header { margin-bottom: 1.4rem; }
.section-tag {
  display: inline-block; font-family: var(--font-mono); font-size: 0.7rem;
  font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ice); opacity: 0.85; margin-bottom: 0.6rem;
}
.section-title {
  font-family: var(--font-serif); font-size: 1.5rem; font-weight: 600;
  color: #fff; margin-bottom: 0.5rem;
}
.section-intro { font-size: 0.98rem; color: var(--ice); max-width: 46em; line-height: 1.55; }

.year-controls {
  display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
  margin: 1.6rem 0 1.1rem;
}
.year-input-wrap { display: flex; align-items: center; gap: 0.55rem; }
.year-input-wrap label { font-family: var(--font-mono); font-size: 0.75rem; color: var(--ice); }
#yearInput {
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 600;
  width: 6.5rem; padding: 0.4rem 0.6rem; border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.08);
  color: #fff;
}
#yearInput:focus { outline: 2px solid var(--ice); outline-offset: 1px; }
.chip-row { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.chip {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  color: var(--ice-bright); background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2); border-radius: 999px;
  padding: 0.3rem 0.7rem; cursor: pointer;
}
.chip:hover, .chip:focus-visible { background: rgba(255,255,255,0.18); }
.chip.active { background: var(--ember-pale); border-color: var(--ember-pale); color: var(--river-deep); }

.ribbon-wrap { position: relative; margin: 1.6rem 0 0.6rem; }
.ribbon {
  position: relative; height: 68px; border-radius: var(--radius-sm);
  overflow: hidden; display: flex; align-items: stretch;
  border: 1px solid rgba(255,255,255,0.15);
}
.ribbon-tick { flex: 1 1 auto; }
.ribbon-tick.frozen { background: linear-gradient(180deg, #e8f6fb, #b9dcea); }
.ribbon-tick.open { background: linear-gradient(180deg, #123b5c, #0a2338); }
.ribbon-seam {
  position: absolute; top: -6px; bottom: -6px; width: 2px;
  background: var(--ember-bright); pointer-events: none;
}
.ribbon-seam::after {
  content: attr(data-label); position: absolute; top: -1.35rem; left: 50%;
  transform: translateX(-50%); font-family: var(--font-mono); font-size: 0.62rem;
  color: var(--ember-bright); white-space: nowrap; font-weight: 700;
}
.ribbon-marker {
  position: absolute; top: -9px; width: 3px; height: 86px;
  background: #fff; box-shadow: 0 0 0 2px var(--river-deep); pointer-events: none;
  transition: left 0.15s ease;
}
#yearRange {
  position: absolute; inset: 0; width: 100%; height: 68px;
  opacity: 0; cursor: pointer; margin: 0;
}
.ribbon-scale {
  display: flex; justify-content: space-between; margin-top: 0.4rem;
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--ice); opacity: 0.75;
}

.readout {
  margin-top: 1.5rem; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15); border-radius: var(--radius-md);
  padding: 1.1rem 1.3rem;
}
.readout-regime {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 0.5rem;
}
.readout-regime.pre { color: var(--ice); }
.readout-regime.post { color: var(--ember-on-dark); }
.readout-text { font-size: 1rem; line-height: 1.6; color: var(--ice-bright); }
.readout-text strong { color: #fff; }

.pretext-band { margin-top: 1.4rem; padding-top: 1.1rem; border-top: 1px dashed rgba(255,255,255,0.2); }
.pretext-label { font-family: var(--font-mono); font-size: 0.68rem; color: var(--ice); opacity: 0.75; margin-bottom: 0.5rem; }
.pretext-dots { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.pretext-dot {
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--ice-bright);
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 999px; padding: 0.25rem 0.6rem;
}

/* Essay */
.essay { margin-top: 3rem; }
.essay h2 {
  font-family: var(--font-serif); font-size: 1.55rem; font-weight: 600;
  color: var(--ink); margin: 2.6rem 0 1rem; letter-spacing: -0.005em;
}
.essay h2:first-child { margin-top: 0; }
.essay p {
  font-family: var(--font-serif); font-size: 1.08rem; line-height: 1.75;
  color: var(--ink); max-width: 42em; margin-bottom: 1.2rem;
}
.essay strong { color: var(--accent-text); }
.essay .cap { font-size: 0.95rem; color: var(--ink-muted); }

.method-note {
  margin-top: 3rem; padding: 1.3rem 1.4rem; background: var(--paper-warm);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: 0.88rem; color: var(--ink-muted); line-height: 1.65;
}
.method-note strong { color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-family: var(--font-sans); font-size: 0.85rem; font-weight: 600;
  text-decoration: none; padding: 0.55rem 1.1rem; border-radius: 999px;
  border: 1px solid var(--border-strong);
}
.btn-primary { background: var(--river-deep); color: #fff; border-color: var(--river-deep); }

.site-footer { border-top: 1px solid var(--border); margin-top: 4rem; }
.footer-inner {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.75rem; padding: 1.6rem 1.5rem;
  font-size: 0.82rem; color: var(--ink-dim);
}
.footer-links { display: flex; gap: 1.1rem; }
.footer-links a { color: var(--ink-muted); text-decoration: none; }
.footer-links a:hover { color: var(--accent-text); text-decoration: underline; }

@media (max-width: 720px) {
  .metrics-banner { grid-template-columns: repeat(2, 1fr); }
  .hero-subtitle, .essay p { max-width: 100%; }
}
@media (max-width: 480px) {
  .metrics-banner { grid-template-columns: 1fr 1fr; }
  .interactive-section { padding: 1.6rem 1.1rem 1.8rem; }
  .ribbon { height: 54px; }
  #yearRange { height: 54px; }
  .ribbon-marker { height: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ribbon-marker { transition: none; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
