/* Ink on paper, like the game's cards. Okabe-Ito accents. */
:root {
  --paper: #efe8d9;
  --card: #fbf8f1;
  --ink: #1a1a1a;
  --ink-2: #4a463f;
  --ink-3: #7a7468;
  --rule: #d6ccb8;
  --blue: #0072b2;
  --on-accent: #ffffff;
  --vermilion: #d55e00;
  --pink: #cc79a7;
  --orange: #e69f00;
  --code-bg: #f6f1e6;
  --c-comment: #7a7468;
  --c-keyword: #0060a0;
  --c-type: #8a4b00;
  --c-string: #2f7d32;
  --c-number: #b04a00;
  --c-attr: #9b4f80;
  --shadow: 3px 3px 0 var(--ink);
  --wave: #1a1a1a;
  --spec-lo: 239, 232, 217;
  --spec-hi: 0, 114, 178;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b1a17;
    --card: #24221e;
    --ink: #ece5d6;
    --ink-2: #c9c1b0;
    --ink-3: #958d7d;
    --rule: #3a362f;
    --blue: #56b4e9;
    --on-accent: #1b1a17;
    --vermilion: #ef7b2d;
    --code-bg: #201e1a;
    --c-comment: #8f887a;
    --c-keyword: #6cc0f0;
    --c-type: #f0b45a;
    --c-string: #8fd18f;
    --c-number: #f5a26b;
    --c-attr: #e3a3cc;
    --shadow: 3px 3px 0 #000;
    --wave: #ece5d6;
    --spec-lo: 27, 26, 23;
    --spec-hi: 86, 180, 233;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #1b1a17;
  --card: #24221e;
  --ink: #ece5d6;
  --ink-2: #c9c1b0;
  --ink-3: #958d7d;
  --rule: #3a362f;
  --blue: #56b4e9;
  --on-accent: #1b1a17;
  --vermilion: #ef7b2d;
  --code-bg: #201e1a;
  --c-comment: #8f887a;
  --c-keyword: #6cc0f0;
  --c-type: #f0b45a;
  --c-string: #8fd18f;
  --c-number: #f5a26b;
  --c-attr: #e3a3cc;
  --shadow: 3px 3px 0 #000;
  --wave: #ece5d6;
  --spec-lo: 27, 26, 23;
  --spec-hi: 86, 180, 233;
  color-scheme: dark;
}


* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 18px/1.65 "Atkinson Hyperlegible", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 760px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--vermilion); }

h1, h2, h3 { font-family: "Young Serif", Georgia, serif; font-weight: 400; line-height: 1.2; text-wrap: balance; }
h1 { font-size: clamp(2.4rem, 7vw, 3.6rem); margin: 0.2em 0 0.3em; }
h2 { font-size: 1.85rem; margin: 2.4em 0 0.6em; }
h3 { font-size: 1.2rem; margin: 1.6em 0 0.4em; }
.shout { font-family: "Luckiest Guy", "Young Serif", serif; letter-spacing: 0.02em; }

code { font: 0.86em/1.5 "JetBrains Mono", ui-monospace, monospace; background: var(--code-bg); padding: 0.05em 0.3em; border-radius: 4px; }

/* ---- masthead ---- */
.masthead { padding: 56px 0 24px; border-bottom: 2px solid var(--ink); background:
  radial-gradient(circle at 1px 1px, var(--rule) 1px, transparent 1.4px) 0 0 / 18px 18px; }
.kicker { margin: 0; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.8rem; color: var(--vermilion); }
.lede { font-size: 1.2rem; color: var(--ink-2); }
.byline { color: var(--ink-3); font-size: 0.92rem; }

/* ---- buttons ---- */
button, .big {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: 10px; padding: 0.45em 0.9em;
  box-shadow: var(--shadow); cursor: pointer; text-decoration: none; display: inline-block;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
button:hover, .big:hover { color: var(--ink); background: var(--paper); }
button:active, .big:active, button.hit { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.big { font-size: 1.15rem; padding: 0.6em 1.2em; background: var(--blue); color: var(--on-accent); }
.big:hover { background: var(--vermilion); color: var(--on-accent); }

/* ---- the live forest ---- */
.forest-section { margin-top: 32px; }
.forest { background: var(--card); border: 2px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; display: grid; gap: 16px; }
.forest-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.forest-head .big { flex: 0 0 auto; }
.forest-state { margin: 0; flex: 1 1 260px; color: var(--ink-2); font-size: 0.95rem; }
.weather { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; }
.weather .rain input { accent-color: #0072b2; }
.weather .fog input { accent-color: #cc79a7; }
.weather .mild input { accent-color: #e69f00; }
.weather .rain span, .weather .fog span, .weather .mild span { font-weight: 700; }
.weather .rain span { color: #0072b2; }
.weather .fog span { color: #b5639a; }
.weather .mild span { color: #b77d00; }
.odds { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 6px 22px; font-size: 0.88rem; }
.odd { display: grid; grid-template-columns: 6.5em 1fr 2.6em; align-items: center; gap: 8px; }
.odd .bar { height: 10px; border: 1.5px solid var(--ink); border-radius: 6px; overflow: hidden; background: var(--paper); }
.odd .bar i { display: block; height: 100%; background: var(--ink); transition: width 200ms ease; }
.odd b { font-family: "JetBrains Mono", monospace; font-size: 0.8rem; text-align: right; }
.odd.none { color: var(--ink-3); }
.stream-scope { width: 100%; height: 60px; display: block; opacity: 0.25; }
.stream-scope.on { opacity: 1; }
.aside { font-size: 0.9rem; color: var(--ink-3); }
.creatures { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 0; }
.creatures button, .cue-row button { border-left: 6px solid var(--blue); }
.head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--vermilion); pointer-events: none; }
.note { border-left: 4px solid var(--vermilion); padding: 4px 0 4px 14px; font-size: 1.05rem; }
.game .banner { margin-bottom: 8px; }

/* ---- the board ---- */
.board-section { margin-top: 32px; }
.board-section h2 { margin-top: 0.8em; }
.sound-on { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; padding: 16px; border: 2px dashed var(--ink-3); border-radius: 14px; }
.sound-on p { margin: 0; flex: 1 1 220px; color: var(--ink-2); font-size: 0.95rem; }
.sound-on.on { display: none; }
.board { display: grid; gap: 14px; }
.board .group h3 { margin: 0.4em 0 0.5em; font-size: 1rem; color: var(--ink-2); }
.board .keys, .cue-row { display: flex; flex-wrap: wrap; gap: 10px; }
.cue-row { margin: 18px 0; }
.board button, .cue-row button { font-size: 0.92rem; padding: 0.35em 0.75em; }
.board .voice button { border-color: var(--ink); background: var(--card); }
.board button[data-kind="menu"] { border-left: 6px solid var(--pink); }
.board button[data-kind="card"] { border-left: 6px solid var(--orange); }
.board button[data-kind="voice"], .cue-row button { border-left: 6px solid var(--blue); }

/* ---- scopes and demos ---- */
.scope, .demo { margin: 22px 0; background: var(--card); border: 2px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.scope canvas, .demo canvas { display: block; width: 100%; border-radius: 6px; }
canvas.wave { height: 90px; }
canvas.spec { height: 110px; margin-top: 6px; }
.scope figcaption, .demo figcaption { font-size: 0.9rem; color: var(--ink-2); margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.demo figcaption { display: block; }
.demo h3 { margin: 0 0 10px; font-size: 1.05rem; }
.demo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.demo-head h3 { margin: 0; }
.voices { margin: 0; font-size: 0.9rem; color: var(--ink-2); }
.voices b { font-family: "Luckiest Guy", serif; font-size: 1.3rem; color: var(--vermilion); display: inline-block; min-width: 1.6em; text-align: right; }
.demo-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 18px; margin: 10px 0; }
.demo-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; }
.slider { display: grid; grid-template-columns: 1fr auto; font-size: 0.88rem; color: var(--ink-2); }
.slider output { font-family: "JetBrains Mono", monospace; font-size: 0.82rem; color: var(--ink); }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--blue); }
.toggle { font-size: 0.9rem; display: flex; gap: 8px; align-items: center; color: var(--ink-2); }
.toggle input { accent-color: var(--blue); width: 18px; height: 18px; }
select { font: inherit; font-size: 0.9rem; background: var(--card); color: var(--ink); border: 2px solid var(--ink); border-radius: 8px; padding: 2px 6px; }
.play { background: var(--blue); color: var(--on-accent); }
.play:hover { background: var(--vermilion); color: var(--on-accent); }
.meta { font-size: 0.82rem; color: var(--ink-3); font-family: "JetBrains Mono", monospace; }

/* ---- code ---- */
figure.code { margin: 18px 0; border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
figure.code figcaption { font: 600 0.78rem/1 "JetBrains Mono", monospace; padding: 8px 12px; border-bottom: 1px solid var(--rule); background: var(--card); }
figure.code figcaption a { color: var(--ink-3); text-decoration: none; }
figure.code figcaption a:hover { color: var(--blue); text-decoration: underline; }
figure.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; max-height: 34em; }
figure.code code { background: none; padding: 0; font-size: 0.8rem; line-height: 1.55; white-space: pre; }
.c { color: var(--c-comment); font-style: italic; }
.k { color: var(--c-keyword); font-weight: 600; }
.t { color: var(--c-type); }
.s { color: var(--c-string); }
.n { color: var(--c-number); }
.a, .m { color: var(--c-attr); }

/* ---- prose bits ---- */
.toc { margin: 40px 0 0; padding: 14px 18px; border: 2px solid var(--ink); border-radius: 14px; background: var(--card); }
.toc ol { margin: 0; padding-left: 1.4em; columns: 2 220px; font-size: 0.95rem; }
.reasons, .rules { padding-left: 1.2em; }
.reasons li, .rules li { margin: 0.4em 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 16px; align-items: center; }
.split figure.code { margin: 0; }
@media (max-width: 620px) { .split { grid-template-columns: 1fr; } .split .plot { max-width: 240px; } }
.plot { margin: 0; }
.plot svg { width: 100%; height: auto; }
.plot figcaption { font-size: 0.8rem; color: var(--ink-3); text-align: center; }

/* ---- diagram ---- */
.diagram { margin: 26px 0; }
.diagram svg { width: 100%; height: auto; }
.diagram figcaption { font-size: 0.88rem; color: var(--ink-3); text-align: center; }
.diagram .box { fill: var(--card); stroke: var(--ink); stroke-width: 2; }
.diagram .box.accent { stroke: var(--blue); stroke-width: 2.5; }
.diagram .box.dashed { stroke-dasharray: 6 5; }
.diagram .ink { stroke: var(--ink); stroke-width: 2; }
.diagram .ink-fill { fill: var(--ink); }
.diagram text { fill: var(--ink); text-anchor: middle; font-family: "Atkinson Hyperlegible", sans-serif; }
.diagram .h { font-family: "Young Serif", serif; font-size: 17px; }
.diagram .t { font-size: 13px; fill: var(--ink-2); font-family: "JetBrains Mono", monospace; }
.diagram .s { font-size: 12px; fill: var(--ink-3); font-style: italic; }

/* ---- the game ---- */
.game { margin-top: 72px; padding-top: 32px; border-top: 2px solid var(--ink); }
.game .banner { width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow); }
.media { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.media > * { width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 10px; background: var(--card); }
.media video, .media img:first-child:nth-last-child(odd) { grid-column: 1 / -1; }
@media (max-width: 560px) { .media { grid-template-columns: 1fr; } }
.facts { padding-left: 1.2em; }
.cta { text-align: center; margin: 28px 0 10px; }
.cta .big { font-size: 1.3rem; }
.small { font-size: 0.9rem; color: var(--ink-3); text-align: center; }
.foot { padding-block: 40px 120px; color: var(--ink-3); font-size: 0.88rem; border-top: 1px solid var(--rule); margin-top: 60px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .odd .bar i { transition: none; }
  button, .big { transition: none; }
}

/* ---- words used here, and further reading ---- */
a.term { color: inherit; text-decoration: underline dotted var(--ink-3); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a.term:hover { color: var(--blue); text-decoration-color: var(--blue); }
.glossary { display: grid; grid-template-columns: minmax(9em, 13em) minmax(0, 1fr); gap: 10px 20px; margin: 18px 0; }
.glossary dt { font-family: "Young Serif", Georgia, serif; font-size: 1rem; line-height: 1.4; padding-top: 2px; }
.glossary dd { margin: 0; font-size: 0.95rem; color: var(--ink-2); }
.glossary dt:target, .glossary dt:target + dd { background: var(--code-bg); box-shadow: 0 0 0 6px var(--code-bg); border-radius: 4px; }
@media (max-width: 560px) { .glossary { grid-template-columns: 1fr; gap: 2px; } .glossary dd { margin-bottom: 12px; } }
.reading { padding-left: 1.1em; }
.reading li { margin: 0.55em 0; }
.cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.big.quiet { background: var(--card); color: var(--ink); }
.big.quiet:hover { background: var(--paper); color: var(--ink); }
.hero-cta { justify-content: flex-start; margin: 22px 0 6px; }

/* ---- code, folded: the text reads on without it ---- */
details.code { margin: 14px 0; border: 1.5px solid var(--rule); border-radius: 10px; background: var(--card); }
details.code > summary { list-style: none; cursor: pointer; display: flex; gap: 12px; align-items: baseline; justify-content: space-between; padding: 9px 14px; font-size: 0.92rem; }
details.code > summary::-webkit-details-marker { display: none; }
details.code > summary .code-what::before { content: "▸"; display: inline-block; width: 1.1em; color: var(--blue); transition: transform 120ms ease; }
details.code[open] > summary .code-what::before { transform: rotate(90deg); }
details.code > summary .code-what { font-weight: 700; color: var(--ink); }
details.code > summary .code-meta { font: 0.78rem "JetBrains Mono", monospace; color: var(--ink-3); white-space: nowrap; }
details.code > summary:hover .code-what { color: var(--blue); }
details.code[open] { border-color: var(--ink); }
.code-body { border-top: 1px solid var(--rule); background: var(--code-bg); border-radius: 0 0 10px 10px; }
.code-file { margin: 0; padding: 8px 14px 0; font: 600 0.76rem "JetBrains Mono", monospace; }
.code-file a { color: var(--ink-3); text-decoration: none; }
.code-file a:hover { color: var(--blue); text-decoration: underline; }
.code-body pre { margin: 0; padding: 10px 14px 14px; overflow-x: auto; max-height: 36em; }
.code-body code { background: none; padding: 0; font-size: 0.8rem; line-height: 1.55; white-space: pre; }
.split details.code { margin: 0; }

/* ---- recipes: source, shape, filter, place ---- */
.recipes { margin: 22px 0; display: grid; gap: 10px; }
.recipe { display: grid; grid-template-columns: 7.5em repeat(4, minmax(0, 1fr)); gap: 10px; align-items: stretch; }
.recipe ol { display: contents; list-style: none; }
.recipe-name { font-family: "Young Serif", Georgia, serif; font-weight: 400; font-size: 1rem; align-self: center; }
.recipe li { position: relative; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: 8px 10px; font-size: 0.86rem; line-height: 1.4; color: var(--ink-2); }
.recipe li + li::before { content: "→"; position: absolute; left: -11px; top: 50%; transform: translate(-50%, -50%); color: var(--ink-3); font-size: 0.9rem; }
.recipe-head li { background: none; border: 0; padding: 0 10px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.recipe-head li + li::before { content: none; }
@media (max-width: 700px) {
  /* Each creature as a small card: its name, then its four stages two by two, each labelled. */
  .recipe { display: block; }
  .recipe.recipe-head { display: none; }
  .recipe ol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 6px 0 4px; padding: 0; }
  .recipe-name { font-size: 1.1rem; }
  .recipe li::before, .recipe li + li::before { content: attr(data-step); position: static; transform: none; display: block; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 2px; }
}
@media (prefers-reduced-motion: reduce) { details.code > summary .code-what::before { transition: none; } }
