/* Layout concept: a single reading column (~66ch) of "rides"; each ride's
   figure breaks out wider than the text, like a ride sign over a midway. */
:root {
  --paper: #f3f4f9;
  --panel: #ffffff;
  --ink: #16182f;
  --muted: #5d6180;
  --rule: #d8dae7;
  --accent: #e0352b;      /* carnival red: the one loud colour */
  --gold: #e7a21c;        /* marquee bulbs */
  --lo: #138f86;          /* low-dimension end of the ramp */
  --hi: #d6336c;          /* high-dimension end of the ramp */
  --good: #1f9d55;
  --shadow: 0 1px 0 rgba(22, 24, 47, .04), 0 8px 30px -12px rgba(22, 24, 47, .18);

  --f-display: "Anybody", "Arial Narrow", system-ui, sans-serif;
  --f-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --text: 40rem;
  --wide: 62rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e0f1d; --panel: #171932; --ink: #ecebf6; --muted: #9a9dbb;
    --rule: #2b2e4c; --accent: #ff5b4d; --gold: #ffc456; --lo: #35c9bb; --hi: #ff5f97;
    --good: #45d483;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 40px -14px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e0f1d; --panel: #171932; --ink: #ecebf6; --muted: #9a9dbb;
  --rule: #2b2e4c; --accent: #ff5b4d; --gold: #ffc456; --lo: #35c9bb; --hi: #ff5f97;
  --good: #45d483;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 40px -14px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 1.125rem;
  line-height: 1.62;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 4rem;
  overflow-x: hidden;
}
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
em { font-style: italic; }
strong { font-weight: 650; }
sup, sub { line-height: 0; }

.col { max-width: var(--text); margin-inline: auto; }
.wide { max-width: var(--wide); margin-inline: auto; }

/* ---------- Hero ---------- */
.hero { padding-block: clamp(2rem, 6vw, 4.5rem) 1rem; }
.kicker {
  font-family: var(--f-mono); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); display: flex; gap: .75rem; align-items: center; flex-wrap: wrap;
}
.kicker .bulbs { display: inline-flex; gap: 5px; }
.kicker .bulbs i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); display: block; animation: bulb 1.6s infinite; }
.kicker .bulbs i:nth-child(2) { animation-delay: .2s } .kicker .bulbs i:nth-child(3) { animation-delay: .4s }
.kicker .bulbs i:nth-child(4) { animation-delay: .6s } .kicker .bulbs i:nth-child(5) { animation-delay: .8s }
@keyframes bulb { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

h1 {
  font-family: var(--f-display);
  font-weight: 850;
  font-stretch: 62%;
  font-size: clamp(3rem, 10.5vw, 7.4rem);
  line-height: .86;
  letter-spacing: -.01em;
  text-transform: uppercase;
  margin: .9rem 0 1.2rem;
  text-wrap: balance;
}
h1 .stretch { display: inline-block; font-stretch: 150%; font-weight: 900; color: var(--accent); }
.lede { font-size: clamp(1.15rem, 2.2vw, 1.4rem); line-height: 1.5; max-width: 38rem; margin: 0 0 1rem; }
.lede-small { color: var(--muted); font-size: 1rem; max-width: 38rem; }

/* ---------- Figures ---------- */
.fig {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: clamp(.75rem, 2.4vw, 1.4rem);
  margin-block: 1.6rem;
  display: grid;
  gap: 1rem;
}
.fig canvas { width: 100%; display: block; border-radius: 8px; touch-action: pan-y; }
.fig-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.fig-grid > * { min-width: 0; }
.cap { font-family: var(--f-mono); font-size: .76rem; line-height: 1.5; color: var(--muted); margin: 0; }
.cap b { color: var(--ink); font-weight: 600; }
.panel-label {
  font-family: var(--f-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 .35rem;
}

/* ---------- Stats ---------- */
.stats { display: grid; gap: .6rem 1.2rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }
.stat { min-width: 0; border-top: 2px solid var(--rule); padding-top: .45rem; }
.stat .v {
  font-family: var(--f-display); font-weight: 800; font-stretch: 75%;
  font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat .k { font-family: var(--f-mono); font-size: .72rem; color: var(--muted); line-height: 1.4; margin-top: .3rem; }
.stat.hot { border-top-color: var(--accent); }
.stat.hot .v { color: var(--accent); }

/* ---------- Dial ---------- */
.controls { display: flex; flex-wrap: wrap; gap: .8rem 1.6rem; align-items: end; }
.dial { flex: 1 1 18rem; min-width: 0; display: grid; gap: .35rem; }
.dial-top { display: flex; align-items: baseline; gap: .6rem; justify-content: space-between; }
.dial-readout {
  font-family: var(--f-display); font-weight: 800; font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.dial-readout .nm { font-style: italic; font-family: var(--f-body); font-weight: 600; font-size: .8em; color: var(--muted); }
.dial-readout .val { display: inline-block; transition: font-stretch .25s; }
.dial-sub { font-family: var(--f-mono); font-size: .72rem; color: var(--muted); }
.btn {
  font: 600 .78rem/1 var(--f-mono); letter-spacing: .04em;
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  border-radius: 999px; padding: .5rem .85rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.solid:hover { filter: brightness(1.08); color: #fff; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 34px; background: transparent; margin: 0; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 99px;
  background: linear-gradient(90deg, var(--lo), #7a5cd6 50%, var(--hi));
}
input[type="range"]::-moz-range-track {
  height: 8px; border-radius: 99px;
  background: linear-gradient(90deg, var(--lo), #7a5cd6 50%, var(--hi));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%;
  background: var(--panel); border: 3px solid var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--panel); border: 3px solid var(--ink);
}
input[type="range"].plain::-webkit-slider-runnable-track { background: var(--rule); }
input[type="range"].plain::-moz-range-track { background: var(--rule); }

.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  font: 600 .76rem/1 var(--f-mono); padding: .5rem .75rem; border: 0; background: transparent; color: var(--ink); cursor: pointer;
}
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.ctl { display: grid; gap: .35rem; }
.ctl > label, .ctl > .lbl { font-family: var(--f-mono); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* ---------- Ride headers ---------- */
.land { margin-top: clamp(4rem, 9vw, 7rem); }
.land-head { border-top: 3px solid var(--ink); padding-top: .8rem; }
.land-head .no { font-family: var(--f-mono); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.land-head h2 {
  font-family: var(--f-display); font-weight: 850; font-stretch: 70%; text-transform: uppercase;
  font-size: clamp(2.2rem, 6vw, 3.6rem); line-height: .95; margin: .3rem 0 .6rem; text-wrap: balance;
}
.land-head p { color: var(--muted); margin: 0; }

.ride { margin-top: clamp(3rem, 7vw, 5rem); scroll-margin-top: 1rem; }
.ride-head { display: grid; gap: .5rem; }
.ride-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.ride-no { font-family: var(--f-mono); font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.tall {
  display: inline-flex; align-items: center; gap: .45rem;
  font-family: var(--f-mono); font-size: .72rem; font-weight: 600;
  border: 1.5px dashed var(--gold); color: var(--ink); border-radius: 6px; padding: .2rem .55rem .2rem .4rem;
}
.tall svg { width: 14px; height: 14px; flex: none; }
.tall b { font-family: var(--f-display); font-stretch: 80%; font-size: .95rem; color: var(--accent); }
h3 {
  font-family: var(--f-display); font-weight: 800; font-stretch: 78%;
  font-size: clamp(1.8rem, 4.6vw, 2.7rem); line-height: 1; margin: 0; text-wrap: balance;
}
.ride p, .snack p { text-wrap: pretty; }
.ride .col > p:first-child { margin-top: 0; }
.why {
  border-left: 3px solid var(--gold); padding: .1rem 0 .1rem 1rem; color: var(--ink);
}
.why > :first-child { margin-top: 0; } .why > :last-child { margin-bottom: 0; }
.why-label { font-family: var(--f-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: .2rem; }
.math { font-family: var(--f-mono); font-size: .92em; white-space: nowrap; }

/* ---------- Quiz ---------- */
.quiz { border: 1.5px solid var(--ink); border-radius: 12px; padding: 1rem 1.1rem; display: grid; gap: .75rem; background: var(--panel); }
.quiz-q { font-weight: 600; margin: 0; }
.quiz-q::before { content: "Guess first. "; font-family: var(--f-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.quiz-opts { display: flex; flex-wrap: wrap; gap: .5rem; }
.quiz-opts button { font: 500 .95rem/1.2 var(--f-body); border: 1.5px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: 8px; padding: .55rem .8rem; cursor: pointer; }
.quiz-opts button:hover:not(:disabled) { border-color: var(--ink); }
.quiz-opts button.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--panel)); }
.quiz-opts button.wrong { border-color: var(--accent); text-decoration: line-through; opacity: .7; }
.quiz-opts button:disabled { cursor: default; }
.quiz-a { margin: 0; }
.quiz-tally { font-family: var(--f-mono); font-size: .72rem; color: var(--muted); }

/* ---------- Snack bar ---------- */
.snacks { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17.5rem), 1fr)); margin-block: 2rem; }
.snack { border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.1rem 1.1rem; background: var(--panel); min-width: 0; display: grid; align-content: start; gap: .35rem; }
.snack .tag { font-family: var(--f-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.snack .big { font-family: var(--f-display); font-weight: 850; font-stretch: 70%; font-size: 2.6rem; line-height: .95; color: var(--accent); overflow-wrap: anywhere; }
.snack h4 { font-family: var(--f-display); font-weight: 750; font-stretch: 85%; font-size: 1.2rem; line-height: 1.15; margin: 0; }
.snack p { margin: 0; font-size: 1rem; line-height: 1.5; color: var(--muted); }

/* ---------- Footer ---------- */
footer { margin-top: 6rem; border-top: 3px solid var(--ink); padding-top: 1.2rem; font-size: 1rem; }
footer h2 { font-family: var(--f-display); font-stretch: 75%; font-weight: 800; font-size: 1.8rem; margin: 0 0 .6rem; }
footer ol { padding-left: 1.2rem; color: var(--muted); }
footer li { margin-bottom: .3rem; }
.toc { display: flex; flex-wrap: wrap; gap: .4rem .5rem; margin-top: 1.4rem; }
.toc a {
  font-family: var(--f-mono); font-size: .74rem; text-decoration: none; border: 1px solid var(--rule); border-radius: 999px;
  padding: .3rem .65rem; background: var(--panel);
}
.toc a:hover { border-color: var(--accent); }

@media (max-width: 560px) {
  body { font-size: 1.05rem; }
  .fig { border-radius: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .kicker .bulbs i { animation: none; }
  .dial-readout .val { transition: none; }
}
