/* Letters in the Ivy: a cut-and-paste zine page. Torn paper, tape, a black halftone ivy sheet,
   one orange lantern. Kit colours and fonts only. Motion is slow and lives in the media block. */

:root {
  --torn-a: polygon(0% 2%, 4% 0%, 9% 1.5%, 15% 0.3%, 22% 1.8%, 30% 0.4%, 38% 1.6%, 47% 0.2%, 55% 1.4%, 63% 0.1%, 71% 1.7%, 79% 0.5%, 86% 1.9%, 93% 0.3%, 100% 1.5%, 99.2% 10%, 100% 22%, 99% 35%, 100% 48%, 99.3% 61%, 100% 74%, 99% 87%, 100% 98.5%, 94% 100%, 87% 98.6%, 79% 99.8%, 70% 98.4%, 61% 99.9%, 52% 98.5%, 43% 99.7%, 34% 98.3%, 25% 99.8%, 16% 98.6%, 8% 99.9%, 0% 98.4%, 0.8% 86%, 0% 73%, 1% 60%, 0% 46%, 0.9% 33%, 0% 20%, 0.7% 9%);
  --torn-b: polygon(1% 0%, 12% 3%, 24% 0%, 37% 4%, 50% 1%, 63% 4%, 76% 0%, 88% 3%, 100% 0%, 97% 25%, 100% 50%, 96% 75%, 100% 100%, 86% 96%, 72% 100%, 58% 97%, 44% 100%, 30% 96%, 16% 100%, 0% 97%, 3% 72%, 0% 48%, 4% 24%);
  --torn-c: polygon(0% 6%, 18% 0%, 40% 5%, 62% 0%, 84% 6%, 100% 1%, 98% 50%, 100% 96%, 78% 100%, 56% 94%, 34% 100%, 12% 95%, 0% 100%, 2% 52%);
  --torn-d: polygon(3% 0%, 100% 4%, 97% 100%, 0% 96%);
  --paper-shadow: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.55));
  --tape: color-mix(in srgb, var(--ak-bg) 72%, var(--ak-link) 28%);
  --amber: var(--ak-link);
  --ink-deep: color-mix(in srgb, var(--ak-link) 40%, var(--ak-ink) 60%);
  --halftone: radial-gradient(color-mix(in srgb, var(--ak-ink-muted) 70%, var(--ak-ink)) 1.3px, transparent 1.8px);
  --gap: 8px;
  --edge-l: max(10px, env(safe-area-inset-left));
  --edge-r: max(10px, env(safe-area-inset-right));
  --edge-b: max(10px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible { outline: 3px solid var(--ak-focus); outline-offset: 2px; }

[hidden] { display: none !important; }

/* ---------- The page ---------- */

.play {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "tabs" "coach" "scene" "dock";
  gap: var(--gap);
  padding: calc(var(--ac-status-h, 72px) + 6px) var(--edge-r) var(--edge-b) var(--edge-l);
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, none);
  background-size: cover;
  background-position: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.play > * { width: min(100%, 600px); justify-self: center; }

/* ---------- Tabs: cut-out labels, mismatched on purpose ---------- */

.tabs {
  grid-area: tabs;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 2px 4px;
}

.tab-notes { display: flex; gap: 6px; }

.tab {
  position: relative;
  min-width: 48px;
  min-height: 48px;
  padding: 0 12px;
  border: 0;
  background: var(--ak-surface);
  color: var(--ak-ink);
  clip-path: var(--torn-c);
  filter: none;
  line-height: 1;
}

.tab-note:nth-child(1) { font-family: var(--ak-font-display); font-size: 24px; rotate: -2deg; background: var(--ak-bg); }
.tab-note:nth-child(2) { font-family: var(--ak-font-body); font-weight: 600; font-size: 22px; letter-spacing: 0.12em; rotate: 1.5deg; clip-path: var(--torn-b); }
.tab-note:nth-child(3) { font-family: var(--ak-font-display); font-size: 22px; rotate: -1deg; background: var(--ak-choice-bg); clip-path: var(--torn-d); }

.tab-note[aria-selected="true"] {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  translate: 0 3px;
}

.tab-note[aria-selected="true"] .tab-word {
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 5px;
}

.tab-moth {
  position: absolute;
  right: 1px;
  top: 1px;
  width: 24px;
  height: 24px;
  object-fit: contain;
  pointer-events: none;
}

.tab-note:has(.tab-moth:not([hidden])) { padding-right: 24px; }

.tab-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-weight: 600;
  font-size: 18px;
  font-variant: small-caps;
  letter-spacing: 0.06em;
  rotate: 1deg;
  clip-path: var(--torn-b);
}

.pips { display: inline-flex; gap: 3px; }
.pips i {
  width: 7px;
  height: 7px;
  border: 1.5px solid var(--ak-btn-ink);
  border-radius: 50%;
}
.pips i.on { background: var(--ak-btn-ink); }

.tab-lights {
  max-width: 84px;
  font-family: var(--ak-font-display);
  font-size: 16px;
  line-height: 1.05;
  rotate: -1.5deg;
  clip-path: var(--torn-a);
  background: var(--ak-choice-bg);
}

/* ---------- The scene: a black halftone sheet pasted on the page ---------- */

.scene {
  grid-area: scene;
  position: relative;
  z-index: 0;
  container-type: inline-size;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "key logo" "note note" "pots pots";
  gap: 6px 10px;
  padding: 12px 12px 4px;
}

.sheet {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--ak-ink);
  background-image: var(--halftone);
  background-size: 7px 7px;
  clip-path: var(--torn-a);
  rotate: -0.6deg;
}

.lantern {
  position: absolute;
  left: -6%;
  bottom: 14%;
  width: min(34%, 170px);
  aspect-ratio: 1;
  background: var(--ak-accent);
  clip-path: polygon(50% 0%, 66% 6%, 82% 4%, 90% 20%, 100% 36%, 94% 52%, 100% 68%, 86% 82%, 74% 96%, 56% 92%, 40% 100%, 26% 88%, 10% 84%, 6% 66%, 0% 50%, 8% 34%, 4% 18%, 20% 10%, 34% 2%);
}

.ivy {
  position: absolute;
  width: 22%;
  max-width: 120px;
  fill: color-mix(in srgb, var(--ak-ink-muted) 55%, var(--ak-ink));
}
.ivy .vein, .ivy use { stroke: var(--ak-ink); stroke-width: 2.5; }
.ivy-a { top: -4%; left: -3%; rotate: 150deg; }
.ivy-b { top: 2%; right: -5%; rotate: -140deg; width: 18%; }
.ivy-c { bottom: 8%; right: -4%; rotate: -70deg; }
.ivy-d { top: 38%; left: -7%; rotate: 80deg; width: 16%; }
.ivy-e { bottom: -6%; left: 30%; rotate: 10deg; width: 15%; }

.logo {
  grid-area: logo;
  position: relative;
  align-self: start;
  height: clamp(32px, 6dvh, 56px);
  width: auto;
  max-width: 40vw;
  object-fit: contain;
  rotate: 2deg;
  filter: var(--paper-shadow);
}

/* The key: a smaller torn frame, taped, leaning the other way. */
.keyframe {
  --kh: clamp(52px, 9.5dvh, 92px);
  position: relative;
  display: block;
  width: min(calc(var(--kh) * var(--key-ratio, 1)), 60cqw);
  height: auto;
  aspect-ratio: var(--key-ratio, 1);
  padding: 6px;
  border: 0;
  background: var(--ak-surface);
  clip-path: var(--torn-b);
  rotate: -1deg;
}
.keyframe img, .keyframe svg { display: block; width: 100%; height: 100%; object-fit: contain; }

.key-holder {
  grid-area: key;
  position: relative;
  justify-self: start;
  align-self: start;
  filter: var(--paper-shadow);
}

.keyframe-tape {
  position: absolute;
  top: -8px;
  left: calc(50% - 28px);
  width: 56px;
  height: 18px;
  rotate: 4deg;
  background: var(--tape);
  clip-path: polygon(0 8%, 6% 0, 12% 10%, 18% 0, 82% 0, 88% 10%, 94% 0, 100% 8%, 100% 92%, 94% 100%, 88% 90%, 82% 100%, 18% 100%, 12% 90%, 6% 100%, 0 92%);
  pointer-events: none;
}

.key-holder.pointed .keyframe-ring {
  display: block;
}
.keyframe-ring {
  display: none;
  position: absolute;
  inset: -9px;
  border: 3px solid var(--ak-bg);
  border-radius: 46% 54% 50% 50% / 52% 46% 54% 48%;
  rotate: -4deg;
  pointer-events: none;
}

/* The note: the big foxed scrap, taped, tilted. */
.note-wrap {
  grid-area: note;
  position: relative;
  min-height: 0;
  display: grid;
  filter: var(--paper-shadow);
}

.note-wrap::before {
  content: '';
  position: absolute;
  z-index: 2;
  top: -9px;
  left: 50%;
  width: 96px;
  height: 24px;
  translate: -50% 0;
  rotate: -3deg;
  background: var(--tape);
  clip-path: polygon(0 8%, 5% 0, 10% 10%, 15% 0, 85% 0, 90% 10%, 95% 0, 100% 8%, 100% 92%, 95% 100%, 90% 90%, 85% 100%, 15% 100%, 10% 90%, 5% 100%, 0 92%);
  pointer-events: none;
}

.note {
  position: relative;
  min-height: 0;
  overflow: hidden;
  padding: 16px 14px 12px;
  background-color: var(--ak-surface);
  background-image:
    radial-gradient(circle at 18% 24%, color-mix(in srgb, var(--ak-link) 10%, transparent) 0 3px, transparent 6px),
    radial-gradient(circle at 74% 62%, color-mix(in srgb, var(--ak-link) 9%, transparent) 0 4px, transparent 8px),
    radial-gradient(circle at 46% 88%, color-mix(in srgb, var(--ak-link) 8%, transparent) 0 2px, transparent 5px),
    radial-gradient(circle at 88% 14%, color-mix(in srgb, var(--ak-link) 8%, transparent) 0 3px, transparent 7px);
  clip-path: var(--torn-a);
  rotate: 1.5deg;
}

.note-text {
  --f: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: calc(var(--f) * 0.32);
}

.line {
  display: flex;
  flex-wrap: wrap;
  column-gap: calc(var(--f) * 0.5);
  row-gap: calc(var(--f) * 0.32);
}

.word { display: inline-flex; gap: calc(var(--f) * 0.05); white-space: nowrap; }

.cell, .mark {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: calc(var(--f) * 0.74);
  height: calc(var(--f) * 2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--ak-ink);
}

.mark { width: auto; font-size: var(--f); font-weight: 600; line-height: 1.1; }

.cell .g {
  display: block;
  width: 100%;
  height: calc(var(--f) * 1.02);
  border-bottom: 2px dashed color-mix(in srgb, var(--ak-ink-muted) 70%, transparent);
  color: var(--amber);
  font-family: var(--ak-font-display);
  font-size: calc(var(--f) * 0.88);
  line-height: 1.12;
  text-align: center;
}

.cell .g.has { border-bottom-style: solid; border-bottom-color: color-mix(in srgb, var(--ak-ink-muted) 45%, transparent); }

.cell .c {
  display: grid;
  place-items: center;
  width: 100%;
  height: calc(var(--f) * 1.1);
  font-size: var(--f);
  font-weight: 600;
  line-height: 1;
}

.cell .c svg, .chip-code svg, .tray-glyph svg { width: 0.95em; height: 0.95em; overflow: visible; }

.note.pens .cell { width: calc(var(--f) * 1.05); }
.note.pens .word { gap: calc(var(--f) * 0.12); }
.note.pens .cell .c svg { width: 0.85em; height: 0.85em; }
.pp line { stroke: currentColor; stroke-width: 0.13; stroke-linecap: round; }
.pp circle { fill: currentColor; }
.pp circle { r: 0.1; }
.chip-code svg { width: 28px; height: 28px; }
.tray-glyph svg { width: 30px; height: 30px; }

.cell.sel { background: color-mix(in srgb, var(--ak-ink-muted) 22%, transparent); }
.cell.sel .c { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 2px; }
.cell.sel .c svg { outline: 2px solid var(--ak-ink); outline-offset: 2px; }

.cell.wrong .g::after, .chip.wrong .chip-guess::after {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  background: var(--ak-ink);
  rotate: -24deg;
}
.cell.wrong .g, .chip.wrong .chip-guess { position: relative; }

.note.done .cell { cursor: default; }
.note.done .cell .g { color: var(--ink-deep); border-bottom-color: transparent; }

.note-moth {
  position: absolute;
  z-index: 3;
  right: -4px;
  bottom: -8px;
  width: clamp(52px, 11dvh, 84px);
  height: auto;
  rotate: -14deg;
  pointer-events: none;
}

/* The pots along the bottom, the door at the right. */
.pots {
  grid-area: pots;
  position: relative;
  width: 100%;
  height: clamp(22px, 4dvh, 36px);
}
.pots .pot { fill: var(--ak-link); stroke: var(--ak-ink); stroke-width: 2; }
.pots .rim { fill: color-mix(in srgb, var(--ak-link) 80%, var(--ak-ink)); stroke: var(--ak-ink); stroke-width: 2; }
.pots .door { fill: var(--ak-bg); stroke: var(--ak-ink); stroke-width: 2; }
.pots .knob { fill: var(--ak-ink); }
.pots .halo { fill: var(--ak-accent); opacity: 0; }
.scene.all-done .pots .glow .pot { fill: var(--ak-accent); }
.scene.all-done .pots .halo { opacity: 0.85; }

/* The key up close: a big sheet over the scene; the dock stays live below it. */
.zoom {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 8px;
  background: color-mix(in srgb, var(--ak-ink) 88%, transparent);
}

.zoom-sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  padding: 18px 16px 14px;
  background: var(--ak-surface);
  clip-path: var(--torn-a);
  rotate: -0.8deg;
  overflow: hidden;
}

.zoom-art {
  position: relative;
  flex: 1 1 0;
  min-height: 60px;
  width: 100%;
}
.zoom-art img, .zoom-art svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }

.zoom-side { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }

.zoom-caption {
  margin: 0;
  max-width: 34em;
  font-size: 17px;
  font-style: italic;
  line-height: 1.35;
  text-align: center;
  color: var(--ak-ink);
}

.zoom-legend { width: 100%; }
.legend-grid {
  --pp: min(42cqw, 13dvh);
  display: grid;
  grid-template-columns: repeat(2, var(--pp));
  justify-content: center;
  gap: 8px 12px;
}
.legend-grid svg { display: block; width: var(--pp); height: var(--pp); }

.zoom.pens .zoom-art { flex: 0 0 auto; height: 9dvh; }
.zoom.pens .zoom-sheet { gap: 6px; padding: 14px 12px 10px; }
.zoom.pens .zoom-caption { font-size: 16px; }

.legend text { font-family: var(--ak-font-body); font-weight: 600; fill: var(--ak-ink); text-anchor: middle; dominant-baseline: central; }
.legend line { stroke: var(--ak-ink); stroke-width: 3; stroke-linecap: round; }
.legend circle { fill: var(--ak-ink); }
.legend .panel { fill: var(--ak-bg); stroke: var(--ak-ink-muted); stroke-width: 1; }

.paper-btn {
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--ak-ink);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-weight: 600;
  clip-path: var(--torn-d);
}

/* ---------- The dock: strip, tray and hints share one place ---------- */

.dock {
  grid-area: dock;
  position: relative;
  display: grid;
  grid-template-areas: "stack";
  min-height: 0;
}

.dock > .strip-wrap { grid-area: stack; }
.play > .tray { grid-area: dock; align-self: end; }
.play > .hints { grid-area: dock; align-self: stretch; contain: size; }
/* Upright, the tray keeps its room under the note even while closed, so it never covers a line. */
@media (orientation: portrait) {
  .play > .tray[hidden] { display: flex !important; visibility: hidden; }
}

.strip-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dock-label {
  align-self: flex-start;
  margin: 0;
  padding: 3px 10px;
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-size: 15px;
  font-style: italic;
  clip-path: var(--torn-d);
  rotate: -0.6deg;
}

.strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px 4px;
}

.chip {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 48px;
  height: 58px;
  padding: 0;
  border: 2px solid var(--ak-ink);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
}
.chip:nth-child(4n + 1) { rotate: -1.5deg; }
.chip:nth-child(4n + 2) { rotate: 1deg; }
.chip:nth-child(4n + 3) { rotate: -0.5deg; }
.chip:nth-child(4n) { rotate: 2deg; }

.chip-code { display: grid; place-items: center; height: 28px; font-size: 22px; font-weight: 600; line-height: 1; }
.chip-guess {
  display: block;
  min-width: 26px;
  height: 22px;
  border-top: 2px dashed var(--ak-ink-muted);
  color: var(--amber);
  font-family: var(--ak-font-display);
  font-size: 18px;
  line-height: 22px;
  text-align: center;
}
.chip.has .chip-guess { border-top-style: solid; }
.chip[aria-pressed="true"] { background: var(--ak-btn-fill); color: var(--ak-btn-ink); }
.chip[aria-pressed="true"] .chip-guess { color: var(--ak-btn-ink); border-top-color: var(--ak-btn-ink); }
.chip:disabled { cursor: default; }
.strip.done .chip .chip-guess { color: var(--ink-deep); }

.tray, .hints {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 8px;
  background: var(--ak-surface);
  clip-path: var(--torn-a);
}

.tray { z-index: 6; }
.play.tray-open .strip-wrap, .play.hints-open .strip-wrap { visibility: hidden; }

.hints {
  z-index: 6;
  overflow-y: auto;
}

.tray-head, .hints-head { display: flex; align-items: center; gap: 8px; }

.tray-title, .hints-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto 0 0;
  font-size: 18px;
  font-style: normal;
  font-weight: 600;
}

.hints-title { font-family: var(--ak-font-display); font-style: normal; font-size: 20px; }

.tray-glyph {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 6px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-size: 26px;
  font-weight: 600;
  font-style: normal;
}

.tray-clear {
  min-width: 64px;
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid var(--ak-ink);
  background: var(--ak-bg);
  font-weight: 600;
}

.tray-close {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--ak-ink);
  background: var(--ak-bg);
}
.tray-close, .tray-clear { flex: 0 0 auto; }
.tray-close svg { width: 22px; height: 22px; fill: none; stroke: var(--ak-ink); stroke-width: 3; stroke-linecap: round; }

.tray-keys {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.key {
  position: relative;
  min-width: 44px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--ak-ink);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 22px;
}
.key.used::after {
  content: '';
  position: absolute;
  left: 30%;
  right: 30%;
  bottom: 5px;
  height: 3px;
  background: var(--ak-ink-muted);
}
.key[aria-pressed="true"] { background: var(--ak-btn-fill); color: var(--ak-btn-ink); }
.tray-keys.pens .key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 54px;
  font-family: var(--ak-font-body);
  font-weight: 600;
}
.key.from { outline: 3px dashed var(--ak-ink); outline-offset: -7px; }
.tray-help { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 16px; font-style: italic; line-height: 1.25; }
.ruler { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto; }
.ruler text { font-family: var(--ak-font-body); font-weight: 600; fill: var(--ak-ink); text-anchor: middle; dominant-baseline: central; }
.ruler .panel { fill: var(--ak-bg); stroke: var(--ak-ink-muted); stroke-width: 1; }
.ruler .hop { fill: none; stroke: var(--ak-ink-muted); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.ruler .hop-word { font-style: italic; font-weight: 500; fill: var(--ak-ink-muted); }
.zoom.shift .zoom-art { flex: 1 1 0; }
.tab-lights[aria-pressed="true"] { background: var(--ak-btn-fill); color: var(--ak-btn-ink); }
.tray-keys.mapped .key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 54px;
}
.tray-keys.mapped .key-letter { font-family: var(--ak-font-display); font-size: 21px; }
.key-code {
  min-width: 22px;
  padding-top: 2px;
  border-top: 2px dashed var(--ak-ink-muted);
  font-family: var(--ak-font-body);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  color: var(--ak-ink-muted);
}
.key[aria-pressed="true"] .key-code { color: var(--ak-btn-ink); border-top-color: var(--ak-btn-ink); }
.dock-label b { font-style: normal; font-weight: 600; }
.tray-clear { grid-column: span 2; min-height: 0; height: 100%; }
.key-sym { display: grid; place-items: center; height: 26px; }
.key-sym svg { width: 26px; height: 26px; overflow: visible; }
.key-letter { font-size: 16px; line-height: 1; }

.rungs { display: flex; flex-direction: column; gap: 8px; }
.ladder { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.rung-btn {
  min-height: 52px;
  padding: 0 6px;
  border: 2px dashed var(--ak-ink-muted);
  background: var(--ak-bg);
  color: var(--ak-ink-muted);
  font-size: 17px;
  font-weight: 600;
}
.rung-btn.next { border-style: solid; border-color: var(--ak-ink); background: var(--ak-btn-fill); color: var(--ak-btn-ink); }
.rung-btn:not(.next):not(.taken):not(:disabled) { border-style: solid; border-color: var(--ak-ink); color: var(--ak-ink); }
.rung-btn.taken { border-style: solid; border-color: var(--ak-ink); color: var(--ak-ink); text-decoration: line-through; text-decoration-thickness: 2px; }
.rung-btn:disabled { cursor: default; }
.rung-notes { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0 0 0 22px; }
.rung-notes li { font-size: 18px; line-height: 1.35; }
.rung-lead { margin: 0; color: var(--ak-ink-muted); font-size: 16px; font-style: italic; }
.tab-hint[aria-expanded="true"] { background: var(--ak-surface); color: var(--ak-ink); text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 5px; }
.tab-hint[aria-expanded="true"] .pips i { border-color: var(--ak-ink); }
.tab-hint[aria-expanded="true"] .pips i.on { background: var(--ak-ink); }

/* ---------- Teaching: ring, arrow, caption ---------- */

.coach { position: fixed; inset: 0; z-index: 31; pointer-events: none; }

.coach-ring {
  position: fixed;
  border: 4px solid var(--ak-accent);
  border-radius: 14px;
  box-shadow: 0 0 0 3px var(--ak-ink);
}

.coach-arrow { position: fixed; inset: 0; width: 100%; height: 100%; overflow: visible; }
.coach-arrow path { fill: none; stroke: var(--ak-ink); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.coach-arrow #coach-path { stroke-dasharray: 2 9; }
.coach-arrow #coach-head { stroke-width: 4; }

.coach-slip {
  grid-area: coach;
  position: relative;
  z-index: 4;
  margin: 0;
  padding: 10px 14px;
  border: 2px solid var(--ak-ink);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  rotate: -0.6deg;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

/* The house toast can sit over the strip; taps go through it to the letter underneath. */
#activity-chrome-toast { pointer-events: none; }

/* ---------- Sideways: the scene on one side, controls on the other ---------- */

@media (orientation: landscape) {
  .play {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 40%);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "scene tabs" "scene dock";
    column-gap: 14px;
    padding-top: calc(var(--ac-status-h, 64px) + 4px);
  }
  .play > * { width: 100%; }
  .play { width: min(100%, 1120px); margin: 0 auto; }
  .dock { align-self: start; }
  .scene {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "key note" "logo note" "pots pots";
    padding: 10px 10px 2px;
  }
  .keyframe { width: clamp(64px, 11vw, 124px); }
  .logo { height: auto; width: clamp(64px, 11vw, 124px); max-width: none; align-self: end; }
  .pots { height: clamp(26px, 8dvh, 48px); }
  .tabs { flex-wrap: nowrap; gap: 4px; }
  .tab-notes { gap: 4px; }
  .tab { padding: 0 9px; }
  .tab-hint { font-size: 16px; gap: 6px; }
  .tab-lights { max-width: 72px; font-size: 14px; line-height: 1.05; }
  .dock-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .chip { height: 54px; }
  .chip-code { height: 26px; font-size: 20px; }
  .chip-code svg { width: 24px; height: 24px; }
  .key { height: 46px; }
  .tray-keys.pens .key { height: 50px; }
  .tray-help { font-size: 14px; line-height: 1.2; }
  .tray { padding: 6px 8px; gap: 3px; }
  .tray-keys { gap: 3px; }
  .tray-keys.mapped .key { height: 46px; gap: 1px; }
  .tray-keys.mapped .key-letter { font-size: 17px; }
  .key-code { font-size: 12px; padding-top: 1px; }
  /* The ending docks on the controls' side, so the solved note and the glowing pot stay in view. */
  html #activity-chrome-ending.site-shriversify { align-items: flex-end; justify-content: flex-end; padding: 70px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) 12px; background: rgba(0, 0, 0, 0.3); }
  html #activity-chrome-ending.site-shriversify .ac-card { width: min(52vw, 420px); max-height: 100%; overflow-y: auto; padding: 14px 18px 8px; }
  html #activity-chrome-ending.site-shriversify .ac-number { margin-bottom: 2px; }
  html #activity-chrome-ending.site-shriversify .ac-line { margin-bottom: 4px; }
  html #activity-chrome-ending.site-shriversify .ac-actions { gap: 12px; }
  html #activity-chrome-ending.site-shriversify .ac-verdict { font-size: 22px; margin-bottom: 8px; padding-bottom: 8px; }
  html #activity-chrome-ending.site-shriversify .ac-lines { font-size: 15px; line-height: 1.35; }
  html #activity-chrome-ending.site-shriversify .ac-actions { margin-top: 8px; }
  .tray-keys { gap: 4px; }
  /* The lamp opens on the controls' side, so the note stays in view. */
  html #activity-chrome-settings.site-shriversify { justify-content: flex-end; align-items: center; background: rgba(0, 0, 0, 0.35); padding-right: max(14px, env(safe-area-inset-right)); }
  html #activity-chrome-settings.site-shriversify .ac-panel { width: min(40vw, 360px); padding: 16px 20px 10px; }
  html #activity-chrome-settings.site-shriversify .ac-sheet-title { margin-bottom: 6px; padding-bottom: 6px; font-size: 20px; }
  .key-sym, .key-sym svg { height: 24px; width: 24px; }
  .hints { padding: 12px 14px 10px; gap: 10px; }
  .rung-notes li { font-size: 17px; }
  /* The pen chart sits beside the trellis, two by two, as big as the scene's height allows. */
  .zoom.pens .zoom-sheet {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas: "legend art" "legend cap" "legend btn";
    align-items: center;
    gap: 8px 14px;
  }
  .zoom.pens .zoom-side { display: contents; }
  .zoom.pens .zoom-art { grid-area: art; height: 100%; min-height: 50px; }
  .zoom.pens .zoom-caption { grid-area: cap; font-size: 15px; }
  .zoom.pens .zoom-legend { grid-area: legend; width: auto; }
  .zoom.pens .zoom-close { grid-area: btn; justify-self: center; }
  .zoom.pens .legend-grid { --pp: min(27cqw, calc((100dvh - var(--ac-status-h, 64px) - 64px) / 2)); }
  .play > .tray { grid-column: 2; grid-row: 1 / -1; }
  /* Hints keep the tabs in view and fill the controls' side below them. */
  .play > .hints { grid-column: 2; grid-row: 2 / -1; align-self: stretch; contain: size; }
  /* While teaching, the caption takes the top of the scene's side and the dock keeps its height. */
  .play.coaching {
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "coach tabs" "coach dock" "scene dock";
  }
  .coach-slip { align-self: start; font-size: 18px; padding: 8px 12px; }
  .tab { min-height: 52px; }
}

@media (orientation: landscape) and (max-height: 440px) {
  .dock-label { font-size: 14px; padding: 2px 8px; }
  .tray { padding: 8px 8px 6px; gap: 4px; }
  .tray-close { width: 48px; height: 48px; }
  .tray-title { font-size: 16px; gap: 6px; }
  .tray-keys.mapped .key, .tray-keys.pens .key, .key { height: 44px; }
  .tray-help { font-size: 13px; }
  .tray-head { gap: 6px; }
  .tray-glyph { height: 34px; min-width: 34px; font-size: 22px; }
}

@media (orientation: portrait) and (max-height: 720px) {
  .keyframe { --kh: clamp(48px, 9dvh, 70px); }
  .logo { height: 30px; }
  .pots { height: 24px; }
  .chip { height: 50px; }
  .chip-code { height: 24px; font-size: 19px; }
  .chip-code svg { width: 24px; height: 24px; }
  .chip-guess { height: 20px; line-height: 20px; font-size: 16px; }
  .dock-label { font-size: 14px; }
  .scene { padding: 8px 10px 2px; }
  .tabs { padding-bottom: 0; }
}

@media (min-width: 700px) and (orientation: portrait) {
  .play > * { width: min(100%, 640px); }
}

/* ---------- Motion: slow, nothing flashes ---------- */

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .cell .g.inking,
  :root:not(.ac-still) .chip-guess.inking { animation: ink-bleed 900ms ease-out both; }
  :root:not(.ac-still) .note.done .cell .g { transition: color 1600ms ease-in-out; transition-delay: calc(var(--i, 0) * 18ms); }
  :root:not(.ac-still) .note.settle .cell { animation: settle 700ms ease-out both; animation-delay: calc(var(--i, 0) * 18ms); }
  :root:not(.ac-still) .note-moth.landing { animation: moth-drift 2200ms cubic-bezier(0.22, 1, 0.36, 1) both; }
  :root:not(.ac-still) .coach-ring { animation: ring-breathe 1800ms ease-in-out infinite; }
  :root:not(.ac-still) .scene.all-done .pots .halo { animation: pot-glow 3200ms ease-in-out infinite; }
  :root:not(.ac-still) .zoom:not([hidden]) .zoom-sheet { animation: paper-in 500ms ease-out both; }
  :root:not(.ac-still) .tray:not([hidden]) { animation: tray-up 360ms ease-out both; }
  :root:not(.ac-still) .play.arriving .note-wrap { animation: paper-in 700ms ease-out both; }
}

@keyframes ink-bleed {
  0% { opacity: 0; filter: blur(3px); transform: scale(1.18); }
  60% { opacity: 1; filter: blur(0.6px); }
  100% { opacity: 1; filter: none; transform: none; }
}

@keyframes settle {
  0% { transform: translateY(-3px); }
  100% { transform: none; }
}

@keyframes moth-drift {
  0% { opacity: 0; transform: translate(-60px, -46dvh) rotate(-38deg) scale(1.2); }
  35% { opacity: 1; transform: translate(24px, -26dvh) rotate(10deg) scale(1.1); }
  70% { transform: translate(-10px, -8dvh) rotate(-22deg) scale(1.03); }
  100% { opacity: 1; transform: none; }
}

@keyframes ring-breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.75; }
}

@keyframes pot-glow {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 0.95; }
}

@keyframes paper-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes tray-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------- The opening: the glasshouse at night, her letter on foxed paper, a wax seal ----------
   start.js draws the screen; this only dresses it in the same collage the play screen wears. */

html body #activity-start.site-shriversify { background-color: var(--ak-ink); }
html body #activity-start.site-shriversify.has-backdrop::before {
  background-image:
    radial-gradient(ellipse 70% 60% at 50% 48%, rgba(23, 19, 17, 0.2), rgba(23, 19, 17, 0.82) 100%),
    url("art/ivy-page.jpg");
  background-size: cover, cover;
  background-position: center, center;
}
html body #activity-start.site-shriversify.has-backdrop::after { background-image: none; }

html body #activity-start.site-shriversify .ak-scene {
  position: relative;
  width: min(86%, 460px);
  min-height: 0;
  margin: max(4vh, 16px) auto;
  padding: 36px 26px 26px;
  gap: 22px;
  background-color: var(--ak-surface);
  background-image:
    radial-gradient(circle at 16% 22%, color-mix(in srgb, var(--ak-link) 10%, transparent) 0 3px, transparent 7px),
    radial-gradient(circle at 82% 68%, color-mix(in srgb, var(--ak-link) 9%, transparent) 0 4px, transparent 9px),
    radial-gradient(circle at 40% 90%, color-mix(in srgb, var(--ak-link) 8%, transparent) 0 2px, transparent 6px);
  clip-path: var(--torn-a);
  rotate: -1deg;
  overflow: hidden;
}
html body #activity-start.site-shriversify .ak-scene .ak-logo { max-height: 15dvh; }
html body #activity-start.site-shriversify .ak-scene-line {
  color: var(--ak-ink);
  text-shadow: none;
  font-size: clamp(19px, 4.8vw, 25px);
}
html body #activity-start.site-shriversify .ak-scene-lines { gap: 14px; }
html body #activity-start.site-shriversify .ak-jump {
  color: var(--ak-ink-muted);
  font-size: 16px;
  text-decoration-color: var(--ak-ink-muted);
}
/* The seal: dark wax with a pressed rim, the button the letter is closed with. */
html body #activity-start.site-shriversify .ak-go {
  width: 116px;
  height: 116px;
  border: 3px solid var(--ak-btn-active);
  border-radius: 46% 54% 49% 51% / 53% 47% 53% 47%;
  box-shadow:
    0 0 0 5px color-mix(in srgb, var(--ak-btn-active) 55%, var(--ak-ink)),
    0 0 0 8px color-mix(in srgb, var(--ak-ink) 70%, transparent),
    0 8px 16px rgba(0, 0, 0, 0.55);
}
html body #activity-start.site-shriversify .ak-sheet { box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7); }
@media (orientation: landscape) and (max-height: 500px) {
  /* Sideways the letter reads left to right: her words, then the seal beside them. */
  html body #activity-start.site-shriversify .ak-scene {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 190px);
    grid-template-areas: "head actions" "lines actions";
    align-items: center;
    width: min(92%, 740px);
    margin: max(2vh, 8px) auto;
    padding: 22px 26px 18px;
    gap: 8px 24px;
  }
  html body #activity-start.site-shriversify .ak-scene .ak-head { grid-area: head; }
  html body #activity-start.site-shriversify .ak-scene-lines { grid-area: lines; max-width: none; gap: 8px; }
  html body #activity-start.site-shriversify .ak-scene-actions { grid-area: actions; }
  html body #activity-start.site-shriversify .ak-scene .ak-jump { white-space: normal; text-align: center; }
  html body #activity-start.site-shriversify .ak-scene .ak-logo { max-height: 20dvh; }
  html body #activity-start.site-shriversify .ak-scene-line { font-size: 18px; }
  html body #activity-start.site-shriversify .ak-go { width: 92px; height: 92px; font-size: 12px; }
}
