:root {
  color-scheme: light dark;
  --paper: #f4f1e8;
  --ink: #182323;
  --muted: #5f6b68;
  --surface: #fffdf7;
  --line: #c9cec8;
  --grid: #d9ddd7;
  --teal: #086f70;
  --teal-soft: #c9e1dd;
  --blue: #244e78;
  --orange: #c15c28;
  --orange-soft: #f3c9aa;
  --purple: #6a4d8a;
  --shadow: 0 16px 50px rgb(24 35 35 / 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101615;
    --ink: #edf4f1;
    --muted: #aebbb7;
    --surface: #17211f;
    --line: #3b4945;
    --grid: #2d3a37;
    --teal: #6fd0c7;
    --teal-soft: #244945;
    --blue: #8db7df;
    --orange: #ff9a62;
    --orange-soft: #5d3523;
    --purple: #c4a2e8;
    --shadow: 0 18px 60px rgb(0 0 0 / 0.24);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 3%, color-mix(in srgb, var(--teal) 12%, transparent), transparent 32rem),
    var(--paper);
  color: var(--ink);
  line-height: 1.58;
}

a { color: var(--teal); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -5rem;
  z-index: 10;
  padding: 0.65rem 0.8rem;
  background: var(--ink);
  color: var(--paper);
}
.skip-link:focus { top: 1rem; }

main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; }

.hero { padding: clamp(4rem, 9vw, 8rem) 0 3.5rem; max-width: 920px; }
.eyebrow, .section-kicker {
  margin: 0 0 0.6rem;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
h1, h2, h3 { line-height: 1.1; margin-top: 0; text-wrap: balance; }
h1 { margin-bottom: 1.2rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.6rem, 7vw, 5.9rem); letter-spacing: -0.045em; }
h2 { margin-bottom: 0.8rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.8rem, 3.7vw, 3rem); letter-spacing: -0.025em; }
h3 { font-size: 1.05rem; }
.dek { max-width: 760px; color: var(--muted); font-size: clamp(1.08rem, 2vw, 1.35rem); }
.hero-links { display: flex; flex-wrap: wrap; gap: 0.75rem 1.3rem; margin-top: 1.5rem; }

.orientation, .reading-guide, .analogy {
  margin: 0 0 3.5rem;
  padding: clamp(1.4rem, 3vw, 2.4rem) 0;
  border-top: 1px solid var(--line);
}
.orientation { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr); gap: clamp(2rem, 7vw, 6rem); align-items: start; }
.orientation p:not(.section-kicker), .analogy p { color: var(--muted); max-width: 820px; }
.shape-key { margin: 0; display: grid; gap: 0.7rem; }
.shape-key div { padding: 0.9rem 1rem; background: color-mix(in srgb, var(--surface) 72%, transparent); border-left: 4px solid var(--teal); }
.shape-key dt { font-weight: 700; }
.shape-key dd { margin: 0.15rem 0 0; color: var(--muted); }

.lab {
  position: relative;
  margin: 0 0 4rem;
  padding: clamp(1.1rem, 2.6vw, 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.lab-heading { display: flex; justify-content: space-between; align-items: end; gap: 1.5rem; margin-bottom: 1.5rem; }
.lab-heading h2 { margin-bottom: 0; }
.lab-provenance { max-width: 430px; margin: 0; color: var(--muted); text-align: right; font-size: 0.9rem; }

.controls { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.9rem; margin-bottom: 1.2rem; }
.controls label { display: grid; align-content: start; gap: 0.45rem; min-width: 0; color: var(--muted); font-size: 0.88rem; }
.controls label span { display: flex; justify-content: space-between; gap: 0.5rem; }
.controls output { color: var(--ink); font-variant-numeric: tabular-nums; }
.controls select, .controls input { width: 100%; }
.controls select { min-height: 2.45rem; padding: 0.4rem 0.55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit; }
.controls input[type="range"] { accent-color: var(--teal); min-height: 2rem; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.8rem; margin-bottom: 1.4rem; }
.stats > div { padding: 1rem; background: color-mix(in srgb, var(--paper) 72%, transparent); border-radius: 12px; }
.stats span, .stats small { display: block; color: var(--muted); }
.stats strong { display: block; margin: 0.1rem 0; font-size: 1.55rem; font-variant-numeric: tabular-nums; }

.plots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.2rem; }
figure { min-width: 0; margin: 0; }
figcaption { min-height: 4.2rem; }
figcaption strong, figcaption span { display: block; }
figcaption span { color: var(--muted); font-size: 0.86rem; }
.chart-wrap { position: relative; width: 100%; min-height: 320px; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap text { fill: var(--ink); font-family: inherit; font-size: 12px; }
.chart-wrap .muted-label { fill: var(--muted); }
.chart-wrap .axis-line, .chart-wrap .tick-line, .chart-wrap .frame { stroke: var(--line); }
.chart-wrap .grid-line { stroke: var(--grid); }
.legend { display: flex; flex-wrap: wrap; gap: 0.55rem 1rem; margin-top: 0.4rem; color: var(--muted); font-size: 0.82rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.38rem; }
.swatch { display: inline-block; width: 1.1rem; height: 0.75rem; }
.swatch.hatch { background: repeating-linear-gradient(45deg, var(--orange), var(--orange) 2px, var(--orange-soft) 2px, var(--orange-soft) 5px); }
.swatch.source { height: 0; border-top: 2px solid var(--purple); }
.swatch.curve { height: 0; border-top: 2px solid var(--teal); }
.swatch.cutoff { height: 0; border-top: 2px dashed var(--orange); }
.detail { min-height: 1.5rem; margin: 0.9rem 0 0; color: var(--muted); font-size: 0.88rem; }
.tooltip { position: absolute; z-index: 4; max-width: 250px; padding: 0.55rem 0.65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--ink); color: var(--paper); box-shadow: var(--shadow); font-size: 0.8rem; pointer-events: none; font-variant-numeric: tabular-nums; }
.noscript { color: var(--orange); }

.guide-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.2rem; }
.guide-grid article { border-top: 3px solid var(--teal); padding-top: 1rem; }
.guide-grid p { color: var(--muted); }
.boundary { padding: 1rem 1.1rem; border-left: 4px solid var(--orange); background: color-mix(in srgb, var(--orange-soft) 34%, transparent); color: var(--ink) !important; }
code { font-size: 0.92em; }
footer { margin: 0 0 5rem; padding: 1.4rem 0; border-top: 1px solid var(--line); color: var(--muted); }

@media (max-width: 940px) {
  .controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .plots { grid-template-columns: 1fr; }
  figcaption { min-height: auto; margin-bottom: 0.55rem; }
}

@media (max-width: 680px) {
  main { width: min(100% - 1rem, 1180px); }
  .hero { padding-top: 3.5rem; }
  .orientation { grid-template-columns: 1fr; gap: 1.25rem; }
  .lab-heading { display: block; }
  .lab-provenance { margin-top: 0.55rem; text-align: left; }
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats, .guide-grid { grid-template-columns: 1fr; }
  .chart-wrap { min-height: 285px; }
}

@media (max-width: 410px) {
  .controls { grid-template-columns: 1fr; }
  .lab { padding: 0.85rem; border-radius: 12px; }
  .hero-links { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
