/* ═══════════════════════════════════════════════════════════════════
   READ THE WATER — "Plate & Margin"

   The product is a printed angling monograph and the river simulation is
   the engraved plate bound into it. Warm rag paper, hairline rules, an
   oldstyle serif set to a real measure, and one rubricated red as the
   press's second colour. The dark painterly canvas is mounted into that
   paper on a tone-block mat and captioned like a figure in a book.

   Two rules hold the whole thing together:
     · There is no sans-serif. Prose is serif, apparatus is monospace.
     · border-radius is 0 on everything except the score dial, because
       instruments are round.

   The dark palette is not invented — every value is lifted from the
   DEPTH_RAMP in src/river/render.js, so the chrome is literally the same
   colours the river is painted with.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  /* ── paper & ink ─────────────────────────────────────────────── */
  --paper:    #F4EFE4;   /* the leaf */
  --paper-2:  #EDE6D8;   /* tone block: plate mats, hover beds */
  --paper-3:  #E2D9C6;   /* recessed: gauge troughs */
  --ink:      #1C1A16;   /* body text — 15.2:1 on paper */
  --ink-2:    #4A463D;   /* secondary prose — 8.2:1 */
  --ink-3:    #6E6858;   /* apparatus labels — 4.8:1 */
  --rule:     #C9BFA9;   /* hairline */
  --rule-2:   #A79A7E;   /* second hairline, gauge ticks */

  /* ── the second ink, and the metals ──────────────────────────── */
  --red:      #9C3520;   /* rubric: plate numerals, cast mode, focus */
  --red-deep: #7E2917;
  /* The warm CTA carries its own ink, because --red flips in dark mode and a
     hardcoded light ink on it measured 2.98:1 there. 6.3:1 / 8.4:1 here. */
  --warm-bg:  #9C3520;
  --warm-hov: #7E2917;
  --warm-ink: #F6F1E7;
  --brass:    #8A5A2B;   /* earned marks, XP */
  --green:    #3C6B3A;   /* gauge: good */
  --amber:    #8A6212;   /* gauge: fair */

  /* ── measure & rhythm ────────────────────────────────────────── */
  --measure:  34em;
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --hair: 1px;

  /* ── families. There is no sans-serif in this design. ────────── */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
           "Noto Serif", Georgia, serif;
  --mono:  ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
           "Roboto Mono", monospace;
}

/* The dark leaf: every surface colour sampled from the river's own depth
   ramp — deep pool, run, riffle, gravel. Follows the system, and can be
   pinned with data-theme on the root element. */
:root[data-theme="dark"] {
  --paper: #0A1D26; --paper-2: #0E2531; --paper-3: #14323C;
  --ink: #E9EFEA; --ink-2: #B2C3C0; --ink-3: #86999A;
  --rule: #21414B; --rule-2: #33606C;
  --red: #DA6D45; --red-deep: #C4542E; --brass: #C9A227;
  --green: #6FBF6A; --amber: #D9A62E;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:    #0A1D26;
    --paper-2:  #0E2531;
    --paper-3:  #14323C;
    --ink:      #E9EFEA;
    --ink-2:    #B2C3C0;
    --ink-3:    #86999A;
    --rule:     #21414B;
    --rule-2:   #33606C;
    --red:      #DA6D45;
    --red-deep: #C4542E;
    --warm-bg:  #DA6D45;
    --warm-hov: #E5825C;
    --warm-ink: #0A1D26;  /* 5.1:1 / 6.3:1 */
    --brass:    #C9A227;
    --green:    #6FBF6A;
    --amber:    #D9A62E;
  }
}

/* ═══ base ═══════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }

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

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; }
p { margin: 0; }
canvas { display: block; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
/* Headings and verdicts we focus on purpose, to announce a change, carry
   tabindex="-1". Tab can never reach them and they are not operable, so the
   ring says nothing a sighted user needs — it just reads as an error box
   around the headline. Real controls, including the canvas, keep theirs. */
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; }

/* Apparatus: every label, numeral and control in the monospace voice. */
.kicker, .lvl .no, .tag, .mode-badge, .chip, .meter .k, .readout-label,
.best, .xp, .note-no, .plate-cap, .lbl {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums lining-nums;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: var(--s5) var(--s5) var(--s8); }
.wrap.narrow { max-width: 860px; }

/* ═══ running head ═══════════════════════════════════════════════ */
/* Not a nav bar — a running head, closed by the oldest device in book
   typography: a double rule. */

.topbar {
  display: flex; align-items: center; gap: var(--s3);
  padding-bottom: var(--s3);
  border-bottom: var(--hair) solid var(--ink);
  position: relative;
  margin-bottom: var(--s6);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -4px;
  height: var(--hair); background: var(--rule);
}
.topbar .spacer { flex: 1; }

.brand {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-family: var(--serif); font-size: 15px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink);
}
.brand .ico { color: var(--red); display: inline-flex; }

.xp { display: inline-flex; align-items: baseline; gap: var(--s2); color: var(--ink-3); }
.xp .rank-chip { color: var(--red); }
.xp b { color: var(--brass); font-weight: 500; }

/* ═══ buttons ════════════════════════════════════════════════════ */

.btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 12px 20px;
  border: var(--hair) solid var(--ink);
  background: transparent; color: var(--ink);
  font-family: var(--serif); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.10em;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }

.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--ink-2); }
.btn.warm { background: var(--warm-bg); border-color: var(--warm-bg); color: var(--warm-ink); }
.btn.warm:hover { background: var(--warm-hov); border-color: var(--warm-hov); }

.btn.ghost {
  border: 0; padding: 4px 0; text-transform: none; letter-spacing: 0;
  font-size: 15px; font-style: italic; font-weight: 400; color: var(--ink-2);
  text-decoration: underline; text-decoration-thickness: var(--hair);
  text-underline-offset: 3px; text-decoration-color: var(--rule);
}
.btn.ghost:hover { background: none; color: var(--ink); text-decoration-color: var(--ink); }
.btn.ghost .ico { color: var(--ink-3); }

.btn.sm { padding: 8px 13px; font-size: 11px; }
.btn.big { padding: 15px 26px; font-size: 14px; }

/* ═══ home ═══════════════════════════════════════════════════════ */

.hero {
  position: relative; padding: 0 0 var(--s6); margin-bottom: var(--s6);
  border-bottom: var(--hair) solid var(--rule); background: none;
  border-radius: 0; box-shadow: none; overflow: visible;
}
.hero canvas { display: none; }        /* the decorative flow field — deleted */
.hero-in { max-width: 30em; }
.kicker { color: var(--red); display: block; margin-bottom: var(--s4); }
.hero h1 {
  font-size: 44px; line-height: 1.06; letter-spacing: -0.015em;
  font-weight: 400; margin-bottom: var(--s4); font-family: var(--serif);
}
.hero p { font-size: 19px; line-height: 1.6; color: var(--ink-2); margin: 0 0 var(--s5); }
.hero .cta-row { display: flex; gap: var(--s3); flex-wrap: wrap; }

.section-h {
  display: flex; align-items: baseline; gap: var(--s3);
  margin: var(--s7) 0 var(--s4); padding-bottom: var(--s2);
  border-bottom: var(--hair) solid var(--ink);
}
.section-h h1, .section-h h2 { font-size: 27px; font-weight: 400; letter-spacing: -0.01em; }
.section-h span { font-style: italic; font-size: 15px; color: var(--ink-3); }
.section-h .spacer { flex: 1; }

.grid { display: grid; gap: 0 var(--s6); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }

/* Mode cards are ruled entries, not boxes. */
.card {
  display: block; text-align: left; background: none;
  border: 0; border-top: var(--hair) solid var(--rule); border-radius: 0;
  padding: var(--s4) 0 var(--s5); overflow: visible;
  transition: background .14s ease, box-shadow .14s ease;
}
button.card:hover {
  transform: none; background: var(--paper-2);
  box-shadow: -10px 0 0 var(--paper-2), 10px 0 0 var(--paper-2);
}
.card .ico { display: block; color: var(--red); margin-bottom: var(--s3); font-size: 0; }
.card h3 { font-size: 22px; font-weight: 600; margin-bottom: var(--s2); }
.card p { font-size: 15px; line-height: 1.55; color: var(--ink-2); }
.card .meta {
  margin-top: var(--s3); color: var(--ink-3); font-family: var(--mono);
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  font-variant-numeric: tabular-nums lining-nums;
}

/* ═══ catalogue of plates ════════════════════════════════════════ */

.lvl-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0 var(--s6); counter-reset: plate;
}
.lvl {
  counter-increment: plate;
  display: block; text-align: left; background: none; padding: var(--s4) 0 var(--s5);
  border: 0; border-top: var(--hair) solid var(--rule); border-radius: 0;
  overflow: visible; transition: background .14s ease, box-shadow .14s ease;
}
.lvl:hover {
  transform: none; background: var(--paper-2);
  box-shadow: -10px 0 0 var(--paper-2), 10px 0 0 var(--paper-2);
}
.lvl .no { color: var(--red); display: block; margin-bottom: var(--s3); }
.lvl .no::before { content: "Plate " counter(plate, upper-roman); }
.lvl .thumb {
  width: 100%; height: 92px; display: block;
  border: var(--hair) solid var(--ink); margin-bottom: var(--s3); background: var(--paper-2);
}
.lvl h3 { font-size: 19px; font-weight: 600; margin: 0 0 2px; }
.lvl .river { font-style: italic; font-size: 14px; color: var(--ink-2); }
.lvl .row { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s3); }
.lvl .best { margin-left: auto; color: var(--ink-3); font-size: 12px; letter-spacing: .04em; }
.lvl.locked { opacity: .45; pointer-events: none; }

.hooks { display: inline-flex; gap: 3px; align-items: center; }
.hooks .hook { color: var(--rule-2); display: inline-flex; }
.hooks .hook.on { color: var(--brass); }

.tag {
  display: inline-block; padding: 3px 7px; font-size: 10px;
  border: var(--hair) solid currentColor; color: var(--ink); background: none;
  border-radius: 0;
}
.tag.cast { color: var(--red); }

/* ═══ play screen ════════════════════════════════════════════════ */

.play-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; }
.play-head .where {
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
  font-variant-numeric: tabular-nums lining-nums;
}
.play-head .where b { color: var(--ink); font-weight: 500; }

.prompt {
  display: flex; align-items: flex-start; gap: var(--s4);
  padding: 0 0 var(--s4); margin-bottom: var(--s4);
  border: 0; border-bottom: var(--hair) solid var(--rule);
  background: none; border-radius: 0;
}
.prompt .q { font-size: 22px; font-weight: 600; line-height: 1.25; }
.prompt .sub { font-size: 15px; line-height: 1.55; color: var(--ink-2); margin-top: var(--s2); max-width: 40em; }
.prompt .spacer { flex: 1; }

.mode-badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 5px 9px; border: var(--hair) solid currentColor; color: var(--ink);
  font-size: 10px; background: none; border-radius: 0;
}
.mode-badge.cast { color: var(--red); }
.mode-badge .ico { display: inline-flex; }

/* The plate: a dark canvas mounted on a tone block inside a hairline. */
.stage {
  background: var(--paper-2); padding: 10px;
  border: var(--hair) solid var(--rule); border-radius: 0;
  box-shadow: none; line-height: 0; overflow: visible;
}
.stage canvas {
  width: 100%; height: auto; border: var(--hair) solid var(--ink);
  cursor: crosshair; touch-action: manipulation;
}

/* Instruction above the plate; caption beneath it, on the paper. */
.stage-tip {
  display: block; position: static; margin: 0 0 var(--s2);
  padding: 0; background: none; border: 0; border-radius: 0;
  backdrop-filter: none; font-family: var(--serif); font-style: italic;
  font-size: 15px; letter-spacing: 0; text-transform: none; color: var(--ink-2);
}
.stage-tip .ico { vertical-align: -3px; margin-right: 5px; color: var(--ink-3); }
.plate-cap {
  display: flex; flex-wrap: wrap; gap: 3px var(--s3);
  margin-top: var(--s2); color: var(--ink-3); font-size: 10px; line-height: 1.5;
}
.plate-cap .lead { color: var(--red); }
.rotate-hint { display: none; }

.controls { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s4); flex-wrap: wrap; }
.controls .spacer { flex: 1; }
.controls .where {
  font-family: var(--mono); font-size: 12px; color: var(--ink-3);
  letter-spacing: .04em; font-variant-numeric: tabular-nums lining-nums;
}

/* ═══ the verdict, set as a broadside ════════════════════════════ */

.verdict {
  margin-top: var(--s6); padding: var(--s5) 0 0;
  border: 0; border-top: 2px solid var(--ink); background: none; border-radius: 0;
  animation: rise .3s cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.verdict-top { display: flex; align-items: flex-start; gap: var(--s5); }
.verdict h3 { font-size: 27px; font-weight: 400; letter-spacing: -0.01em; margin-bottom: var(--s3); }
.verdict .lede { font-size: 19px; line-height: 1.55; color: var(--ink); max-width: 30em; }
.verdict .lede::first-line { font-variant-caps: small-caps; }

/* The dial — the one round thing, because instruments are round. */
.score-ring { position: relative; flex: none; width: 96px; height: 96px; }
.score-ring svg { transform: rotate(-90deg); display: block; }
.score-ring .val {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--serif); font-size: 30px; font-weight: 400;
  font-variant-numeric: lining-nums;
}

/* ═══ gauge strips ═══════════════════════════════════════════════ */

.readout-label {
  display: block; margin: var(--s5) 0 0; padding-bottom: 6px;
  border-bottom: var(--hair) solid var(--rule); color: var(--ink-3);
  font-weight: 500;
}
.readout { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 var(--s5); }
.meter {
  background: none; border: 0; border-top: var(--hair) solid var(--rule);
  border-radius: 0; padding: var(--s3) 0 var(--s4);
}
.meter .k { display: block; color: var(--ink-3); }
.meter .bar {
  height: 4px; margin: var(--s2) 0 6px; border-radius: 0; overflow: hidden;
  background-color: var(--paper-3);
  background-image: repeating-linear-gradient(90deg,
    transparent 0 calc(25% - 1px), var(--rule-2) calc(25% - 1px) 25%);
}
.meter .bar i { display: block; height: 100%; border-radius: 0; transition: width .7s cubic-bezier(.2,.8,.3,1); }
.meter .v { font-style: italic; font-size: 13px; line-height: 1.4; color: var(--ink-2); }

/* ═══ marginalia ═════════════════════════════════════════════════ */

.lesson {
  margin-top: var(--s5); padding: 0 0 0 var(--s4);
  background: none; border-radius: 0; border-left: 2px solid var(--ink);
}
.lesson .h {
  color: var(--red); display: block; margin-bottom: 6px; font-family: var(--mono);
  font-size: 10px; letter-spacing: .16em; text-transform: uppercase; font-weight: 500;
}
.lesson p { font-size: 16px; line-height: 1.6; color: var(--ink-2); max-width: var(--measure); }

/* Key to the plate */
.spot-list { margin-top: var(--s5); display: block; }
.spot {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) 0; background: none; border: 0;
  border-bottom: var(--hair) solid var(--rule); border-radius: 0;
}
.spot .pin {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: none;
  border: var(--hair) solid var(--ink); color: var(--ink);
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  font-variant-numeric: lining-nums;
}
.spot .n { font-size: 17px; font-weight: 600; font-variant-caps: small-caps; letter-spacing: .02em; margin-bottom: 2px; }
.spot .d { font-size: 15px; line-height: 1.6; color: var(--ink-2); max-width: var(--measure); }

/* ═══ quizzes ════════════════════════════════════════════════════ */

.quiz-head { margin-bottom: var(--s5); text-align: left; }
.quiz-head h1, .quiz-head h2 { font-size: 27px; font-weight: 400; margin-bottom: 4px; }
.quiz-head p { color: var(--ink-3); font-style: italic; font-size: 15px; }
.streak-bar {
  display: flex; flex-wrap: wrap; justify-content: flex-start;
  gap: 2px var(--s5); margin-bottom: var(--s4);
  padding-bottom: var(--s2); border-bottom: var(--hair) solid var(--rule);
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
  font-variant-numeric: tabular-nums lining-nums;
}
.streak-bar b { color: var(--brass); font-weight: 500; }

.fly-stage {
  background: var(--paper-2); border: var(--hair) solid var(--rule);
  border-radius: 0; padding: 10px; margin-bottom: var(--s4);
  display: grid; place-items: center;
}
.fly-stage canvas {
  width: 100%; max-width: 520px; height: auto;
  border: var(--hair) solid var(--ink); background: var(--paper);
}

.opt-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 var(--s5); }
.opt {
  display: flex; align-items: center; gap: var(--s3); text-align: left;
  background: none; border: 0; border-top: var(--hair) solid var(--rule);
  border-radius: 0; padding: var(--s3) 0; font-family: var(--serif);
  font-size: 17px; font-weight: 600; color: var(--ink);
  transition: background .14s ease, box-shadow .14s ease;
}
.opt:hover:not(:disabled) {
  transform: none; background: var(--paper-2);
  box-shadow: -10px 0 0 var(--paper-2), 10px 0 0 var(--paper-2);
}
.opt .sub {
  display: block; font-family: var(--mono); font-size: 10px; font-weight: 400;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-top: 4px;
}
.opt canvas { flex: none; width: 108px; height: 62px; border: var(--hair) solid var(--rule); background: var(--paper); }
.opt.tall { flex-direction: column; align-items: stretch; gap: var(--s2); }
.opt.tall canvas { width: 100%; height: auto; }
.opt:disabled { cursor: default; }
.opt.right { border-top: 3px solid var(--green); background: none; }
.opt.wrong { border-top: 3px solid var(--red); background: none; }

.scenario {
  border: 0; border-bottom: var(--hair) solid var(--rule); background: none;
  border-radius: 0; padding: 0 0 var(--s4); margin-bottom: var(--s4);
}
.scenario h3 { font-size: 22px; font-weight: 600; }
.scenario .loc {
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--red); margin: 4px 0 var(--s4); font-weight: 500;
}
.scenario .facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 0 var(--s4); }
.fact { background: none; border: 0; border-top: var(--hair) solid var(--rule); border-radius: 0; padding: var(--s2) 0 var(--s3); }
.fact .k { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.fact .v {
  font-family: var(--mono); font-size: 14px; margin-top: 4px; color: var(--ink);
  font-variant-numeric: tabular-nums lining-nums;
}
.scenario .obs { margin-top: var(--s4); font-size: 17px; line-height: 1.6; font-style: italic; color: var(--ink-2); max-width: var(--measure); }

.explain {
  margin-top: var(--s5); padding: var(--s4) 0 0; background: none;
  border: 0; border-top: 2px solid var(--ink); border-radius: 0;
  animation: rise .28s cubic-bezier(.2,.8,.3,1);
}
.explain .verd {
  font-family: var(--serif); font-size: 22px; font-weight: 600;
  text-transform: none; letter-spacing: 0; margin-bottom: var(--s3);
}
.explain .verd.ok { color: var(--green); }
.explain .verd.no { color: var(--red); }
.explain p { font-size: 17px; line-height: 1.62; color: var(--ink-2); max-width: var(--measure); }
.explain p + p { margin-top: var(--s3); }
.explain b { color: var(--ink); font-weight: 600; }

/* ═══ field notes ════════════════════════════════════════════════ */

.notes { counter-reset: note; display: block; }
.note {
  border: 0; border-top: var(--hair) solid var(--rule); background: none;
  border-radius: 0; counter-increment: note; overflow: visible;
}
.note > summary {
  display: flex; align-items: baseline; gap: var(--s3);
  padding: var(--s4) 0; cursor: pointer; list-style: none;
  font-family: var(--serif); font-size: 19px; font-weight: 600;
}
.note > summary::-webkit-details-marker { display: none; }
.note > summary::before {
  content: counter(note, decimal-leading-zero);
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  color: var(--red); flex: none; width: 2.6em; font-weight: 500;
}
.note > summary::after { content: "+"; margin-left: auto; color: var(--ink-3); font-family: var(--mono); font-size: 15px; }
.note[open] > summary::after { content: "–"; }
.note > summary .term { color: var(--ink); }
.note .body {
  padding: 0 0 var(--s5) 2.6em; max-width: calc(var(--measure) + 2.6em);
  font-size: 17px; line-height: 1.68; color: var(--ink-2);
}
.note .body > p:first-of-type::first-line { font-variant-caps: small-caps; color: var(--ink); }
.note .body b { color: var(--ink); font-weight: 600; }
.note .body p { margin-bottom: var(--s3); }
.note .body p:last-child { margin-bottom: 0; }
.note .body ul, .note .body ol { margin: var(--s3) 0 0; padding-left: 1.1em; }
.note .body li { margin-bottom: var(--s2); }
.note .body li::marker { color: var(--rule-2); }
.note .body canvas { border: var(--hair) solid var(--rule); background: var(--paper-2); }

/* ═══ footer ═════════════════════════════════════════════════════ */

.footer {
  margin-top: var(--s8); padding-top: var(--s4);
  border-top: var(--hair) solid var(--ink); position: relative;
  font-size: 14px; line-height: 1.65; color: var(--ink-3); max-width: var(--measure);
}
.footer::before { content: ""; position: absolute; left: 0; right: 0; top: 3px; height: var(--hair); background: var(--rule); }
.footer b { color: var(--ink-2); font-weight: 600; }
.footer p + p { margin-top: var(--s3); }

.empty { padding: var(--s7) 0; color: var(--ink-3); font-style: italic; }

.toast {
  position: fixed; left: 50%; bottom: var(--s5);
  transform: translateX(-50%) translateY(60px);
  background: var(--ink); color: var(--paper);
  padding: 11px 18px; border: 0; border-radius: 0;
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  box-shadow: none; opacity: 0;
  transition: all .3s cubic-bezier(.2,.8,.3,1); z-index: 50; pointer-events: none;
}
.toast.on { transform: translateX(-50%); opacity: 1; }

/* ═══ mobile ═════════════════════════════════════════════════════ */

@media (max-width: 900px) { .grid.c3 { grid-template-columns: repeat(2, 1fr); } }

@media (max-width: 700px) {
  .wrap {
    padding: var(--s4) var(--s4) var(--s7);
    padding-left: max(var(--s4), env(safe-area-inset-left));
    padding-right: max(var(--s4), env(safe-area-inset-right));
  }
  .topbar { margin-bottom: var(--s5); }
  .brand { font-size: 13px; letter-spacing: .1em; padding: 12px 6px; margin: -12px 0 -12px -6px; }
  .btn.sm { padding: 13px; }
  .xp { font-size: 10px; }

  .hero h1 { font-size: 34px; }
  .hero p { font-size: 17px; }
  .hero .cta-row .btn { flex: 1 1 100%; justify-content: center; }

  .grid.c3, .grid.c2 { grid-template-columns: 1fr; }
  .section-h { margin: var(--s6) 0 var(--s3); }
  .section-h h2 { font-size: 22px; }
  .lvl-grid { grid-template-columns: 1fr; }

  .prompt { flex-wrap: wrap; gap: var(--s3); }
  .prompt .spacer { display: none; }
  .prompt .q { font-size: 19px; }
  .mode-badge { order: -1; }
  .prompt .btn { margin-left: auto; }

  /* the plate bleeds to the edges; the caption stays in the gutter */
  .stage {
    padding: 0; border-left: 0; border-right: 0;
    margin-left: calc(-1 * max(var(--s4), env(safe-area-inset-left)));
    margin-right: calc(-1 * max(var(--s4), env(safe-area-inset-right)));
  }
  .stage canvas { border-left: 0; border-right: 0; }

  .verdict-top { gap: var(--s4); }
  .verdict h3 { font-size: 22px; }
  .verdict .lede { font-size: 17px; }
  .score-ring { width: 72px; height: 72px; }
  .score-ring svg { width: 72px; height: 72px; }
  .score-ring .val { font-size: 23px; }

  .readout { grid-template-columns: repeat(2, 1fr); column-gap: var(--s4); }
  .opt-grid { grid-template-columns: 1fr; }
  .note .body { padding-left: 0; }
  .note > summary { font-size: 17px; }
  .controls .btn { flex: 1 1 auto; justify-content: center; }
  .controls .where { flex: 1 1 100%; text-align: right; }

  .rotate-hint {
    display: block; margin-top: var(--s3);
    font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
    text-transform: uppercase; color: var(--ink-3);
  }
}

@media (max-width: 700px) and (orientation: landscape) { .rotate-hint { display: none; } }

/* Landscape phones are wider than 700px but still have notches. */
@media (max-height: 500px) and (orientation: landscape) {
  .wrap {
    padding-left: max(var(--s5), env(safe-area-inset-left));
    padding-right: max(var(--s5), env(safe-area-inset-right));
  }
}

/* The hint, given room to be read instead of flashed in a toast. */
.hint-note {
  margin: 0 0 var(--s4); padding: var(--s3) 0 var(--s3) var(--s4);
  border-left: 2px solid var(--red); max-width: var(--measure);
}
.hint-note .h {
  display: block; font-family: var(--mono); font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--red); margin-bottom: 4px; font-weight: 500;
}
.hint-note p { font-size: 16px; line-height: 1.55; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* The hero's outer margin, set as a colophon — a book would not leave it blank. */
.hero { display: grid; grid-template-columns: minmax(0, 32em) 1fr; gap: var(--s8); align-items: start; }
.hero-colophon { padding-top: 6px; border-left: var(--hair) solid var(--rule); padding-left: var(--s5); }
.hero-colophon .lbl { display: block; color: var(--ink-3); margin-bottom: var(--s2); }
.hero-colophon .lbl + ul { margin: 0 0 var(--s5); }
.hero-colophon ul { padding: 0; list-style: none; }
.hero-colophon li { font-size: 14px; line-height: 1.5; color: var(--ink-2); margin-bottom: 3px; }
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: var(--s5); }
  .hero-colophon { border-left: 0; border-top: var(--hair) solid var(--rule); padding: var(--s4) 0 0; }
  .hero-colophon ul { columns: 2; column-gap: var(--s5); }
}

/* the tip's inline mark, and separators in the figure caption */
.stage-tip svg { vertical-align: -3px; margin-right: 7px; color: var(--ink-3); }
.plate-cap > span + span::before {
  content: "·"; margin-right: var(--s3); color: var(--rule-2);
}

@media (max-width: 700px) {
  .hero .cta-row .btn.ghost { flex: 0 0 auto; justify-content: flex-start; }
}

/* ═══ what is that? — streamside identification ══════════════════ */

.key-q { margin: var(--s5) 0 0; }
.key-q h3 { font-size: 19px; font-weight: 600; padding-bottom: var(--s2); border-bottom: var(--hair) solid var(--ink); }
.key-table { display: block; }
.key-row {
  display: flex; align-items: baseline; gap: var(--s3); width: 100%; text-align: left;
  padding: var(--s3) 0; border-bottom: var(--hair) solid var(--rule);
  font-family: var(--serif); font-size: 16px; line-height: 1.5; color: var(--ink-2);
  transition: background .14s ease, box-shadow .14s ease;
}
.key-row:hover { background: var(--paper-2); box-shadow: -10px 0 0 var(--paper-2), 10px 0 0 var(--paper-2); }
.key-row .sees { flex: 1 1 auto; }
.key-row .is { flex: 0 0 auto; color: var(--ink); font-weight: 600; font-variant-caps: small-caps; letter-spacing: .02em; }
.key-row .ico { color: var(--red); flex: none; }

.bug { margin-top: var(--s7); scroll-margin-top: var(--s4); }
.bug-head { padding-bottom: var(--s4); border-bottom: 2px solid var(--ink); }
.bug-head h3 { font-size: 27px; font-weight: 400; display: inline; }
.bug-head .latin {
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--red); margin-left: var(--s3);
}
.bug-head .one-line { font-size: 19px; font-style: italic; color: var(--ink); margin-top: var(--s3); max-width: var(--measure); }
.bug-head .matters { font-size: 16px; color: var(--ink-2); margin-top: var(--s2); max-width: var(--measure); }

.bug-stage {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: var(--s5);
  padding: var(--s5) 0; border-bottom: var(--hair) solid var(--rule); align-items: start;
}
.bug-stage.nophoto { grid-template-columns: 1fr; }

.bug-photo { margin: 0; }
.bug-photo img {
  width: 100%; height: 210px; object-fit: contain; display: block;
  border: var(--hair) solid var(--ink); background: var(--paper-2);
}
.bug-photo .credit {
  margin-top: 5px; font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3); line-height: 1.4;
}

.bug-body .stage-name {
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--red); margin-bottom: var(--s2);
}
.bug-body p { font-size: 16px; line-height: 1.6; color: var(--ink-2); margin-bottom: var(--s2); max-width: var(--measure); }
.bug-body p b { color: var(--ink); font-weight: 600; }

.bug-flies { display: flex; align-items: flex-end; gap: var(--s4); flex-wrap: wrap; margin-top: var(--s3); padding-top: var(--s3); border-top: var(--hair) solid var(--rule); }
.bug-flies > .lbl { color: var(--ink-3); align-self: center; }
.bug-fly { display: flex; flex-direction: column; }
.bug-fly canvas { width: 170px; height: auto; border: var(--hair) solid var(--rule); background: var(--paper-2); }
.bug-fly span { font-size: 14px; margin-top: 4px; color: var(--ink); }
.bug-fly .sz { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-top: 1px; }

@media (max-width: 700px) {
  .bug-stage { grid-template-columns: 1fr; gap: var(--s3); }
  .bug-photo img { height: 200px; }
  .key-row { flex-wrap: wrap; gap: 4px var(--s3); font-size: 15px; }
  .key-row .is { flex-basis: 100%; }
  .key-row .ico { display: none; }
  .bug-head h3 { font-size: 22px; }
  .bug-head .one-line { font-size: 17px; }
  .bug-fly canvas { width: 140px; }
}

/* ═══ name that bug ══════════════════════════════════════════════ */

.bug-quiz-photo {
  background: var(--paper-2); border: var(--hair) solid var(--rule);
  padding: 10px; margin-bottom: var(--s4);
}
.bug-quiz-photo img {
  width: 100%; height: 340px; object-fit: contain; display: block;
  border: var(--hair) solid var(--ink); background: var(--paper);
}
.bug-quiz-photo .credit {
  margin-top: 6px; font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
}
.bug-q { margin-bottom: var(--s3); }
.bug-q .lbl { display: block; color: var(--red); margin-bottom: 4px; }
.bug-q h3 { font-size: 22px; font-weight: 600; padding-bottom: var(--s2); border-bottom: var(--hair) solid var(--ink); }

@media (max-width: 700px) {
  .bug-quiz-photo img { height: 240px; }
  .bug-q h3 { font-size: 19px; }
}

/* ═══ failure screens ════════════════════════════════════════════ */
/* Both hardcoded near-black ink before, which is invisible on the dark
   leaf. They inherit the theme like everything else now. */
.fallback {
  max-width: var(--measure); margin: 12vh auto; padding: 0 var(--s5);
  font-family: var(--serif); font-size: 17px; line-height: 1.6; color: var(--ink);
}
.fallback .lbl { display: block; color: var(--red); margin-bottom: var(--s4); }
.fallback h1 { font-size: 34px; font-weight: 400; margin: 0 0 var(--s4); }
.fallback p { margin-bottom: var(--s3); }
.fallback p:last-child { color: var(--ink-2); }

/* Visible to assistive technology only. */
.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;
}
