:root {
  --font-display: "Bricolage Grotesque", "Arial Narrow", sans-serif;
  --font-sans: "Instrument Sans", "Avenir Next", sans-serif;
  --font-mono: "Space Mono", "Courier New", monospace;
  --ink: #09080c;
  --night: #07060c;
  --paper: #efe4d2;
  --paper-deep: #e4d3bc;
  --ink-on-paper: #1c140e;
  --mute: rgba(239, 228, 210, 0.66);
  --ember: #ff4d1a;
  --ember-hot: #ffb15a;
  --gold: #f0c24b;
  --ash: #8a7d70;
  --char: #16110e;
}

* { box-sizing: border-box; }

html { height: 100%; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-sans);
  color-scheme: dark;
}

body.page-lesson {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  background: #07060c;
}

body.page-hub {
  min-height: 100%;
  overflow-x: hidden;
  touch-action: manipulation;
  background:
    radial-gradient(ellipse 48% 42% at 100% 100%, rgba(255, 77, 26, 0.18), transparent 62%),
    radial-gradient(ellipse 30% 28% at 0% 0%, rgba(240, 194, 75, 0.06), transparent 70%),
    var(--ink);
}

::selection { background: var(--ember); color: var(--char); }

a:focus-visible,
button:focus-visible,
.rail:focus-visible,
.world summary:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 20;
  background: var(--paper);
  color: var(--ink-on-paper);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.skip:focus { left: 72px; top: 12px; }

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

.stage-fade {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 68% 60% at 54% 46%, transparent 36%, rgba(0, 0, 0, 0.42) 100%);
}

.page-sky .stage-fade {
  background: radial-gradient(ellipse 78% 72% at 52% 42%, transparent 50%, rgba(0, 0, 0, 0.2) 100%);
}

.page-sky .ticket,
.page-sky .ticket:has(.world[open]) {
  max-height: min(42vh, 390px);
  overflow: hidden;
}

.page-color .stage-fade {
  background: radial-gradient(ellipse 74% 70% at 56% 42%, transparent 46%, rgba(0, 0, 0, 0.32) 100%);
}

.page-color .ticket,
.page-color .ticket:has(.world[open]) {
  max-height: min(50vh, 470px);
  overflow: hidden;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.spine {
  position: fixed;
  z-index: 5;
  left: 0;
  top: 0;
  bottom: 0;
  width: 46px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 0 max(16px, env(safe-area-inset-bottom));
  background: var(--paper);
  color: var(--ink-on-paper);
  writing-mode: vertical-rl;
  pointer-events: none;
}

.spine span {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.spine-idx { letter-spacing: 0.18em; }

.spine::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(transparent, var(--ember) 18%, var(--ember-hot) 50%, var(--ember) 82%, transparent);
}

.lesson-head {
  position: fixed;
  z-index: 4;
  top: max(18px, env(safe-area-inset-top));
  left: max(64px, calc(env(safe-area-inset-left) + 58px));
  /* 400px leaves room for the lesson jumps. 15.5cqw still sizes the title to this column. */
  width: min(920px, calc(100vw - 64px - 400px));
  max-width: none;
  container-type: inline-size;
  pointer-events: none;
}

.lesson-head .kicker {
  margin: 0 0 8px 14%;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mute);
}

.lesson-head h1 {
  margin: 0;
  max-width: 100%;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 740;
  /* 15.5cqw keeps the longest title, Polarization, inside the column. */
  font-size: clamp(1.7rem, 15.5cqw, 6rem);
  line-height: 0.88;
  letter-spacing: -0.05em;
  hyphens: manual;
  -webkit-hyphens: manual;
  overflow-wrap: normal;
  word-break: normal;
  padding-inline-end: 0.06em;
  animation: wipe 0.75s cubic-bezier(.16, .84, .28, 1) both;
}

.define {
  margin: 14px 0 0;
  max-width: 38ch;
  padding: 12px 14px 13px;
  background: linear-gradient(180deg, rgba(247, 241, 230, 0.96), rgba(228, 211, 188, 0.96));
  color: var(--ink-on-paper);
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  pointer-events: auto;
}

.jumps {
  position: fixed;
  z-index: 5;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 10px;
  max-width: min(540px, calc(100vw - 420px));
  pointer-events: auto;
}

.jumps a {
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 77, 26, 0.85);
  padding-bottom: 3px;
}

.jumps a:hover { color: var(--ember-hot); }

.stamps {
  position: fixed;
  z-index: 4;
  top: max(96px, calc(env(safe-area-inset-top) + 80px));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.stamp {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ember-hot);
  border: 1px solid rgba(255, 77, 26, 0.7);
  outline: 1px solid rgba(255, 77, 26, 0.28);
  outline-offset: 2px;
  padding: 5px 7px;
  transform: rotate(-1.5deg);
  background: transparent;
}

.stamp + .stamp { transform: rotate(1.4deg); }

.dock {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.ticket {
  position: absolute;
  display: flex;
  flex-direction: column;
  left: max(62px, calc(env(safe-area-inset-left) + 56px));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(430px, calc(100% - 210px));
  padding: 16px 18px 14px;
  background: linear-gradient(180deg, #f7f1e6 0%, var(--paper) 40%, var(--paper-deep) 100%);
  color: var(--ink-on-paper);
  pointer-events: auto;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    10px 22px 40px rgba(0, 0, 0, 0.38);
  transform-origin: 0% 100%;
  animation: unfold 0.95s cubic-bezier(.16, .84, .28, 1) 0.05s both;
}

.ticket h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: -0.04em;
  line-height: 1;
}

.ticket-body {
  min-height: 0;
  overflow: auto;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0 0 10px;
}

.tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: #8d2c12;
  border-bottom: 1px solid var(--ember);
  padding-bottom: 2px;
}

.note,
.readout {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: #3a3128;
}

.note a { color: #8d2c12; }

.readout {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  color: #3a2a22;
}

.keys {
  flex: 0 0 auto;
  margin: 12px 0 0;
  padding-top: 8px;
  border-top: 1px solid rgba(28, 20, 14, 0.16);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5c5148;
}

.keys strong { color: var(--ink-on-paper); font-weight: 400; }

.world {
  flex: 0 0 auto;
  margin: 12px 0 0;
  border-top: 1px solid rgba(28, 20, 14, 0.16);
  padding-top: 8px;
}

.world-copy {
  max-height: min(24vh, 220px);
  overflow: auto;
}

.world summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5c5148;
  cursor: pointer;
  list-style: none;
}

.world summary::-webkit-details-marker { display: none; }

.world summary::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--ember);
  border-bottom: 1.5px solid var(--ember);
  transform: translateY(-2px) rotate(45deg);
}

.world[open] summary::before {
  transform: translateY(1px) rotate(-135deg);
}

.world p {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: #3a3128;
}

.ticket:has(.world[open]) {
  max-height: min(48vh, 460px);
  overflow: hidden;
}

.ticket .burn {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  background: linear-gradient(90deg, transparent 0%, #2a110c 12%, var(--ember) 42%, #ffe1b0 52%, transparent 72%);
  transform-origin: left center;
  animation: sear 1.05s ease 0.08s both;
  pointer-events: none;
}

.dogear {
  position: absolute;
  top: 0;
  right: 0;
  width: 26px;
  height: 26px;
  background: linear-gradient(225deg, var(--ember) 0 50%, #d9cbb8 50% 100%);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
  pointer-events: none;
}

.shape {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-52%);
  width: 96px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.modes { display: flex; flex-direction: column; }

.modes button {
  appearance: none;
  border: none;
  margin: 0;
  background: var(--paper-deep);
  color: var(--ink-on-paper);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 8px;
  cursor: pointer;
  text-align: left;
}

.modes button + button { border-top: 1px solid rgba(28, 20, 14, 0.16); }

.modes button[aria-pressed="true"] {
  background: var(--char);
  color: var(--paper);
  box-shadow: inset 3px 0 0 var(--ember);
}

.rail {
  --t: 0.47;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: min(38vh, 280px);
  min-height: 160px;
  padding: 8px 6px;
  background: var(--paper);
  color: var(--ink-on-paper);
  cursor: ns-resize;
  touch-action: none;
}

.rail-name {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
}

.rail-groove {
  position: relative;
  flex: 1;
  width: 10px;
  background: var(--char);
}

.rail-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--t) * 100%);
  background: linear-gradient(var(--ember-hot), var(--ember));
}

.rail-knob {
  position: absolute;
  left: 50%;
  bottom: calc(var(--t) * (100% - 16px));
  width: 16px;
  height: 16px;
  transform: translateX(-50%);
  background: var(--paper);
  border: 1px solid var(--ember);
  box-shadow: 0 0 0 3px rgba(255, 77, 26, 0.18);
}

.error {
  position: fixed;
  z-index: 9;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: none;
  background: #3a1212;
  color: #ffd6d6;
  padding: 12px 14px;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Hub ---------------------------------------------------------------- */

.sheet {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(28px, env(safe-area-inset-top)) 28px 32px 78px;
}

.mast { position: relative; z-index: 1; max-width: min(24ch, 36vw); padding-top: 4vh; }

.eyebrow,
.colophon {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mute);
}

.eyebrow { margin: 0 0 12px; }

.mast-title {
  margin: 0;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 760;
  font-size: clamp(4.6rem, 9vw, 8.4rem);
  line-height: 0.76;
  letter-spacing: -0.065em;
}

.mast-title span { display: block; }

.mast-title .ghost {
  margin-left: 0.42em;
  color: transparent;
  -webkit-text-stroke: 1.5px var(--paper);
}

.deck {
  margin: 18px 0 0;
  max-width: 38ch;
  font-size: 1.05rem;
  line-height: 1.45;
  color: rgba(239, 228, 210, 0.92);
}

.stack {
  position: absolute;
  z-index: 2;
  right: max(28px, 4vw);
  bottom: 3.5vh;
  width: min(460px, 42vw);
}

.folios {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  perspective: 1200px;
}

.folio {
  position: relative;
  display: block;
  padding: 8px 14px 8px;
  text-decoration: none;
  color: var(--ink-on-paper);
  background: linear-gradient(180deg, #f7f1e6, var(--paper-deep));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 14px 30px rgba(0, 0, 0, 0.22);
  transform-origin: top center;
  transform: perspective(1100px) rotateX(0deg);
  transition: transform 0.9s cubic-bezier(.16, .84, .28, 1);
}

.folio-b { margin-left: 8px; transition-delay: 0.06s; }
.folio-c { margin-left: 16px; transition-delay: 0.1s; }
.folio-d { margin-left: 24px; transition-delay: 0.14s; }
.folio-e { margin-left: 32px; transition-delay: 0.18s; }
.folio-f { margin-left: 40px; transition-delay: 0.22s; }
.folio-g { margin-left: 48px; transition-delay: 0.26s; }
.folio-h { margin-left: 56px; transition-delay: 0.3s; }
.folio-i { margin-left: 64px; transition-delay: 0.34s; }
.folio-j { margin-left: 72px; transition-delay: 0.38s; }
.folio-k { margin-left: 80px; transition-delay: 0.42s; }

.folio-name { white-space: nowrap; }

.folio-e .folio-name,
.folio-f .folio-name,
.folio-h .folio-name,
.folio-j .folio-name { font-size: clamp(1.35rem, 1.7vw, 1.7rem); }

html.is-locked body.page-hub {
  background:
    radial-gradient(ellipse 58% 52% at 74% 58%, rgba(255, 186, 120, 0.28), transparent 70%),
    radial-gradient(ellipse 46% 40% at 8% 12%, rgba(239, 228, 210, 0.14), transparent 72%),
    radial-gradient(ellipse 50% 44% at 100% 100%, rgba(255, 77, 26, 0.26), transparent 64%),
    #141218;
}

html.is-locked .deck {
  color: rgba(239, 228, 210, 0.9);
}

html.is-locked .eyebrow,
html.is-locked .colophon {
  color: rgba(239, 228, 210, 0.78);
}

html.is-locked .folio {
  transform: perspective(1100px) rotateX(-34deg);
  transition: none;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.75) inset,
    0 10px 22px rgba(0, 0, 0, 0.28);
}

.folio-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.folio-idx {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.folio-name {
  font-family: var(--font-display);
  font-weight: 720;
  font-size: clamp(1.45rem, 1.85vw, 1.8rem);
  letter-spacing: -0.045em;
  line-height: 0.9;
}

.folio-tag,
.folio-go {
  display: block;
  opacity: 1;
  transition: opacity 0.4s ease 0.18s;
}

.folio-tag {
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  color: #8d2c12;
}

.folio-go {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

html.is-locked .folio-tag,
html.is-locked .folio-go {
  opacity: 0;
  max-height: 0;
  margin: 0;
  overflow: hidden;
  transition: none;
}

.folio::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--ember), #ffe1b0, transparent);
  transform: scaleX(0);
  transform-origin: left center;
  pointer-events: none;
}

html.is-open .folio::before { animation: sear 0.85s ease forwards; }
html.is-open .folio-b::before { animation-delay: 0.06s; }
html.is-open .folio-c::before { animation-delay: 0.1s; }
html.is-open .folio-d::before { animation-delay: 0.14s; }
html.is-open .folio-e::before { animation-delay: 0.18s; }
html.is-open .folio-f::before { animation-delay: 0.22s; }
html.is-open .folio-g::before { animation-delay: 0.26s; }
html.is-open .folio-h::before { animation-delay: 0.3s; }
html.is-open .folio-i::before { animation-delay: 0.34s; }
html.is-open .folio-j::before { animation-delay: 0.38s; }
html.is-open .folio-k::before { animation-delay: 0.42s; }

.folio:hover { transform: perspective(1100px) rotateX(0deg) translateY(-3px); }
html.is-locked .folio:hover { transform: perspective(1100px) rotateX(-28deg); }

.seal {
  --strike: 0;
  position: absolute;
  z-index: 4;
  left: 0;
  right: 18px;
  top: 36%;
  overflow: hidden;
  width: auto;
  text-align: left;
  background: linear-gradient(180deg, #f6efe4 0%, #e7d3b8 100%);
  color: var(--ink-on-paper);
  border: none;
  padding: 16px 18px 15px;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 18px 36px rgba(0, 0, 0, 0.38);
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 0 100%);
}

.seal-heat {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--strike) * 100%);
  background: linear-gradient(90deg, rgba(255, 77, 26, 0.15) 0%, var(--ember) 70%, #ffe1b0 100%);
  mix-blend-mode: multiply;
  pointer-events: none;
}

.seal-title,
.seal-hint { position: relative; z-index: 1; display: block; }

.seal-title {
  margin-top: 0;
  font-family: var(--font-display);
  font-weight: 720;
  font-size: 1.85rem;
  letter-spacing: -0.04em;
  line-height: 0.95;
  color: var(--ink-on-paper);
}

.seal-hint {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.01em;
  line-height: 1.35;
  text-transform: none;
  color: #5c4538;
}

html.is-open .seal {
  animation: char-away 0.7s ease forwards;
  pointer-events: none;
}

.colophon {
  margin: 28px 0 0;
  max-width: 42ch;
}

@media (min-width: 861px) {
  .colophon {
    position: absolute;
    left: 78px;
    bottom: max(20px, 3vh);
    margin: 0;
  }

  .folios { gap: 2px; }

  .folio { padding: 3px 12px 2px; }

  .folio-name { font-size: clamp(1.08rem, 1.22vw, 1.26rem); line-height: 0.86; }

  .folio-e .folio-name,
  .folio-f .folio-name,
  .folio-h .folio-name,
  .folio-j .folio-name { font-size: clamp(1.05rem, 1.18vw, 1.2rem); }

  .folio-tag { margin-top: 0; font-size: 10px; line-height: 1.2; }

  .folio-go { margin-top: 1px; }
}

/* Motion ------------------------------------------------------------- */

@keyframes wipe {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

@keyframes unfold {
  from { transform: perspective(800px) rotateX(64deg); opacity: 0; }
  to { transform: perspective(800px) rotateX(0deg); opacity: 1; }
}

@keyframes sear {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes char-away {
  0% { opacity: 1; clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 0 100%); filter: none; }
  40% { box-shadow: inset 0 0 28px var(--ember); }
  100% { opacity: 0; clip-path: inset(42% 0 42% 0); filter: blur(4px); }
}

html.is-still .ticket,
html.is-still .lesson-head h1,
html.is-still .folio,
html.is-still .folio::before,
html.is-still .ticket .burn,
html.is-still .seal {
  animation: none !important;
  transition: none !important;
}

html.is-still .ticket {
  transform: none;
  opacity: 1;
}

html.is-still .lesson-head h1 { clip-path: none; }

html.is-still .folio {
  transform: none;
}

html.is-still .folio-tag,
html.is-still .folio-go { opacity: 1; }

html.is-still .seal { display: none !important; }

html.is-still .folio::before,
html.is-still .ticket .burn { transform: scaleX(1); }

@media (prefers-reduced-motion: reduce) {
  .folio,
  .ticket,
  .lesson-head h1,
  .seal,
  .folio::before,
  .ticket .burn {
    animation: none !important;
    transition: none !important;
  }
  .folio { transform: none !important; }
  .folio-tag, .folio-go { opacity: 1 !important; }
  .seal { display: none !important; }
  .ticket { transform: none !important; opacity: 1 !important; }
  .lesson-head h1 { clip-path: none !important; }
  .folio::before,
  .ticket .burn { transform: scaleX(1) !important; }
}

/* Embed -------------------------------------------------------------- */

html.embed .spine,
html.embed .lesson-head,
html.embed .jumps,
html.embed .stamps,
html.embed .dock,
html.embed .grain,
html.embed .stage-fade,
html.embed .error { display: none !important; }

html.embed,
html.embed body { background: transparent !important; }

html.embed.wall,
html.embed.wall body { background: #07060c !important; }

/* Narrow ------------------------------------------------------------- */

@media (max-width: 860px) {
  .spine {
    writing-mode: horizontal-tb;
    flex-direction: row;
    width: auto;
    height: 42px;
    right: 0;
    bottom: auto;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top);
    height: calc(42px + env(safe-area-inset-top));
  }

  .spine::after {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    height: 2px;
  }

  .page-lesson .spine {
    height: calc(56px + env(safe-area-inset-top));
  }

  .lesson-head {
    top: calc(68px + env(safe-area-inset-top));
    left: 14px;
    width: calc(100vw - 28px);
    max-width: none;
  }

  .lesson-head h1 { font-size: clamp(1.7rem, 15.5cqw, 3.35rem); }

  .define {
    max-width: none;
    font-size: 14px;
    padding: 10px 12px;
  }

  .jumps {
    top: calc(10px + env(safe-area-inset-top));
    gap: 12px;
  }

  .stamps {
    top: calc(160px + env(safe-area-inset-top));
    left: 14px;
    right: auto;
    align-items: flex-start;
    flex-direction: row;
  }

  .ticket,
  .ticket:has(.world[open]) {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(74px + env(safe-area-inset-bottom));
    max-height: 46vh;
    overflow: hidden;
  }

  .shape {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    width: auto;
    transform: none;
    flex-direction: row;
    align-items: stretch;
  }

  .modes { flex-direction: row; flex: 0 0 auto; }
  .modes button { text-align: center; padding: 12px 10px; }
  .modes button[aria-pressed="true"] { box-shadow: inset 0 -3px 0 var(--ember); }

  .rail {
    flex: 1;
    flex-direction: row;
    height: auto;
    min-height: 0;
    cursor: ew-resize;
  }

  .rail-name { writing-mode: horizontal-tb; }

  .rail-groove { width: auto; height: 10px; flex: 1; }

  .rail-fill {
    top: 0;
    bottom: 0;
    right: auto;
    width: calc(var(--t) * 100%);
    height: auto;
  }

  .rail-knob {
    top: 50%;
    bottom: auto;
    left: calc(var(--t) * (100% - 16px));
    transform: translateY(-50%);
  }

  .sheet { padding: calc(58px + env(safe-area-inset-top)) 16px 28px; }

  .mast { max-width: none; padding-top: 12px; }

  .mast-title { font-size: clamp(4.2rem, 22vw, 6rem); }

  .mast-title .ghost { margin-left: 0.28em; }

  .stack {
    position: relative;
    right: auto;
    bottom: auto;
    width: auto;
    margin-top: 28px;
  }

  .folio-b,
  .folio-c,
  .folio-d,
  .folio-e,
  .folio-f,
  .folio-g,
  .folio-h,
  .folio-i,
  .folio-j,
  .folio-k { margin-left: 0; }

  .jumps {
    gap: 4px 8px;
    max-width: calc(100vw - 132px);
    justify-content: flex-end;
  }

  .jumps a {
    color: var(--ink-on-paper);
    border-bottom-color: var(--ember);
    font-size: 10px;
    letter-spacing: 0.06em;
  }

  .jumps a:hover { color: #8d2c12; }

  .page-film .stamps,
  .page-slits .stamps {
    top: calc(214px + env(safe-area-inset-top));
  }

  .page-mirror .shape,
  .page-sky .shape {
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-mirror .modes,
  .page-sky .modes { flex: 1 0 100%; }

  .page-mirror .rails,
  .page-sky .rails {
    display: flex;
    flex: 1 1 100%;
    gap: 6px;
    min-width: 0;
  }

  .page-mirror .rails .rail,
  .page-sky .rails .rail {
    flex: 1 1 0;
    min-width: 0;
    height: auto;
    min-height: 0;
  }

  .page-mirror .rail-name,
  .page-sky .rail-name {
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  .page-mirror .ticket,
  .page-mirror .ticket:has(.world[open]),
  .page-sky .ticket,
  .page-sky .ticket:has(.world[open]) {
    bottom: calc(124px + env(safe-area-inset-bottom));
    max-height: 38vh;
  }

  .page-slits .shape,
  .page-color .shape {
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-slits .modes,
  .page-color .modes { flex: 1 0 100%; }

  .page-slits .rails,
  .page-color .rails {
    display: flex;
    flex: 1 1 100%;
    gap: 6px;
    min-width: 0;
  }

  .page-slits .rails .rail,
  .page-color .rails .rail {
    flex: 1 1 0;
    min-width: 0;
    height: auto;
    min-height: 0;
  }

  .page-slits .rail-name,
  .page-color .rail-name {
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  .page-slits .ticket,
  .page-slits .ticket:has(.world[open]),
  .page-color .ticket,
  .page-color .ticket:has(.world[open]) {
    bottom: calc(124px + env(safe-area-inset-bottom));
    max-height: 38vh;
  }

  .mast-title { font-size: clamp(3.15rem, 14vw, 4.2rem); }

  .deck { margin-top: 10px; font-size: 0.98rem; line-height: 1.35; }

  .stack { margin-top: 12px; }

  .folios { gap: 6px; }

  .folio { padding: 8px 12px 8px; }

  .folio-name { font-size: 1.55rem; }

  .folio-e .folio-name,
  .folio-f .folio-name,
  .folio-h .folio-name,
  .folio-j .folio-name { font-size: 1.28rem; }

  .folio-tag { margin-top: 2px; font-size: 11px; }

  .folio-go { margin-top: 5px; }

  .sheet { padding-bottom: 16px; }

  .colophon { position: relative; left: auto; bottom: auto; margin-top: 14px; }
}

@media (min-width: 861px) and (max-height: 860px) {
  .stack {
    position: relative;
    right: auto;
    bottom: auto;
    width: min(440px, 46vw);
    margin: 28px 0 0 auto;
  }

  .mast { padding-top: 2vh; }
  .colophon { position: relative; left: auto; bottom: auto; margin-top: 22px; }
}

@media (min-width: 861px) {
  .page-slits .shape {
    width: 148px;
    gap: 8px;
  }

  .page-color .shape {
    width: 176px;
    gap: 8px;
  }

  .page-slits .rails,
  .page-color .rails {
    display: flex;
    gap: 4px;
    height: min(34vh, 240px);
    min-height: 168px;
  }

  .page-slits .rails .rail,
  .page-color .rails .rail {
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    padding: 6px 3px;
  }

  .page-slits .rail-name,
  .page-color .rail-name {
    font-size: 9px;
    letter-spacing: 0.05em;
  }

  .page-mirror .shape,
  .page-sky .shape {
    width: 168px;
    gap: 8px;
  }

  .page-mirror .rails,
  .page-sky .rails {
    display: flex;
    gap: 4px;
    height: min(34vh, 240px);
    min-height: 168px;
  }

  .page-mirror .rails .rail,
  .page-sky .rails .rail {
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    padding: 6px 4px;
  }

  .page-mirror .rail-name,
  .page-sky .rail-name {
    font-size: 9px;
    letter-spacing: 0.06em;
  }
}

@media (max-width: 860px) and (max-height: 700px) {
  .lesson-head h1 { font-size: clamp(1.55rem, 13cqw, 2.35rem); }
  .define { font-size: 13px; padding: 8px 10px; }
  .stamps { display: none; }
  .ticket,
  .ticket:has(.world[open]) { max-height: 34vh; }
  .page-slits .ticket,
  .page-slits .ticket:has(.world[open]),
  .page-mirror .ticket,
  .page-mirror .ticket:has(.world[open]),
  .page-sky .ticket,
  .page-sky .ticket:has(.world[open]),
  .page-color .ticket,
  .page-color .ticket:has(.world[open]),
  .page-absorb .ticket,
  .page-absorb .ticket:has(.world[open]) { max-height: 28vh; }
  .world-copy { max-height: 16vh; }
}

/* Absorption --------------------------------------------------------- */

.page-absorb .stage-fade {
  background: radial-gradient(ellipse 74% 70% at 54% 40%, transparent 44%, rgba(0, 0, 0, 0.36) 100%);
}

.page-absorb .ticket,
.page-absorb .ticket:has(.world[open]) {
  max-height: min(52vh, 500px);
  overflow: hidden;
}

.page-absorb .ticket-body {
  min-height: 0;
  overflow: auto;
}

.page-absorb .pick-set { background: var(--paper-deep); }

.page-absorb .set-name {
  margin: 0;
  padding: 7px 8px 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #5c5148;
}

.page-absorb .swatches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: rgba(28, 20, 14, 0.16);
}

.page-absorb .swatches button {
  appearance: none;
  border: none;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--paper-deep);
  color: var(--ink-on-paper);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 8px;
  cursor: pointer;
  text-align: left;
}

.page-absorb .swatches button[aria-pressed="true"] {
  background: var(--char);
  color: var(--paper);
  box-shadow: inset 3px 0 0 var(--ember);
}

.page-absorb .modes button {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-absorb .chip {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border: 1px solid rgba(28, 20, 14, 0.28);
}

.chip-leaf { background: #2c6b34; }
.chip-white { background: #f3ecdf; }
.chip-black { background: #161311; }
.chip-red { background: #c4281a; }
.chip-yellow { background: #e2b423; }
.chip-blue { background: #2a4fa8; }
.chip-green { background: #1f8a3a; }

.page-absorb button[aria-pressed="true"] .chip {
  border-color: var(--ember);
}

@media (min-width: 861px) {
  .page-absorb .shape {
    width: 196px;
    gap: 8px;
  }

  .page-absorb .world-copy { max-height: min(30vh, 280px); }
}

@media (max-width: 860px) {
  .jumps {
    right: 8px;
    max-width: calc(100vw - 156px);
    gap: 2px 6px;
  }

  .jumps a {
    font-size: 9px;
    letter-spacing: 0.03em;
  }
}

@media (max-width: 860px) {
  .page-absorb .shape {
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-absorb .pick-set { flex: 1 0 100%; }

  .page-absorb .swatches {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-absorb .swatches button {
    justify-content: center;
    padding: 9px 4px;
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  .page-absorb .modes { flex-direction: row; }

  .page-absorb .modes button {
    flex: 1 1 0;
    justify-content: center;
    padding: 10px 4px;
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  .page-absorb .modes button + button {
    border-top: none;
    border-left: 1px solid rgba(28, 20, 14, 0.16);
  }

  .page-absorb .modes button[aria-pressed="true"] {
    box-shadow: inset 0 -3px 0 var(--ember);
  }

  .page-absorb .ticket,
  .page-absorb .ticket:has(.world[open]) {
    bottom: calc(168px + env(safe-area-inset-bottom));
    max-height: 32vh;
  }
}

/* Shadows ----------------------------------------------------------- */

.page-shadow .stage-fade {
  background: radial-gradient(ellipse 72% 68% at 58% 42%, transparent 42%, rgba(0, 0, 0, 0.38) 100%);
}

.page-shadow .ticket,
.page-shadow .ticket:has(.world[open]) {
  max-height: min(50vh, 480px);
  overflow: hidden;
}

.page-shadow .ticket-body {
  min-height: 0;
  overflow: auto;
}

@media (min-width: 861px) {
  .page-shadow .shape {
    width: 188px;
    gap: 8px;
  }

  .page-shadow .rails {
    display: flex;
    gap: 4px;
    height: min(32vh, 220px);
    min-height: 156px;
  }

  .page-shadow .rails .rail {
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    padding: 6px 3px;
  }

  .page-shadow .rail-name {
    font-size: 9px;
    letter-spacing: 0.05em;
  }

  .page-shadow .stamps { top: 112px; }
}

@media (max-width: 860px) {
  .page-shadow .shape {
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-shadow .modes { flex: 1 0 100%; }

  .page-shadow .rails {
    display: flex;
    flex: 1 1 100%;
    gap: 6px;
    min-width: 0;
  }

  .page-shadow .rails .rail {
    flex: 1 1 0;
    min-width: 0;
    height: auto;
    min-height: 0;
  }

  .page-shadow .rail-name {
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  .page-shadow .ticket,
  .page-shadow .ticket:has(.world[open]) {
    bottom: calc(124px + env(safe-area-inset-bottom));
    max-height: 34vh;
  }
}

@media (max-width: 860px) and (max-height: 700px) {
  .page-shadow .ticket,
  .page-shadow .ticket:has(.world[open]) { max-height: 26vh; }
}

/* Phone: the stage is its own band. The lesson reads underneath it. */

.keys-touch { display: none; }

@media (pointer: coarse) {
  .keys-board { display: none; }
  .keys-touch { display: inline; }
}

@media (max-width: 860px) {
  html:has(body.page-lesson) {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.page-lesson {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100%;
    overflow: visible;
    touch-action: manipulation;
    overscroll-behavior: auto;
    padding-top: calc(44px + env(safe-area-inset-top));
  }

  body.page-lesson .spine {
    z-index: 8;
    height: calc(44px + env(safe-area-inset-top));
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-left: 14px;
    padding-right: 14px;
  }

  body.page-lesson .spine-mark,
  body.page-lesson .spine-idx {
    flex: 0 0 auto;
  }

  body.page-lesson .jumps {
    order: 1;
    position: sticky;
    top: calc(44px + env(safe-area-inset-top));
    right: auto;
    left: auto;
    z-index: 7;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 10px 14px 8px;
    justify-content: flex-start;
    align-items: center;
    gap: 8px 12px;
    background: #07060c;
  }

  body.page-lesson .jumps a {
    color: var(--paper);
    border-bottom-color: rgba(255, 77, 26, 0.85);
    font-size: 11px;
    letter-spacing: 0.06em;
    line-height: 1.3;
    padding: 4px 0 5px;
  }

  body.page-lesson .jumps a:hover { color: var(--ember-hot); }

  body.page-lesson #stage {
    order: 2;
    position: relative;
    inset: auto;
    z-index: 0;
    flex: none;
    width: 100%;
    height: clamp(210px, 36dvh, 380px);
    overflow: hidden;
    touch-action: none;
  }

  body.page-lesson #stage canvas {
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
  }

  body.page-lesson .stage-fade { display: none; }

  body.page-lesson .lesson-head {
    order: 3;
    position: relative;
    top: auto;
    left: auto;
    z-index: 2;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 16px 16px 0;
    pointer-events: none;
  }

  body.page-lesson .lesson-head .kicker { margin-left: 0; }

  body.page-lesson .lesson-head h1 {
    font-size: clamp(2.4rem, 12vw, 3.35rem);
  }

  body.page-lesson .define {
    max-width: none;
    margin-top: 12px;
    pointer-events: auto;
  }

  body.page-lesson .stamps {
    order: 4;
    position: relative;
    top: auto;
    right: auto;
    left: auto;
    z-index: 2;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 8px;
    margin: 0;
    padding: 12px 16px 0;
  }

  body.page-lesson .dock {
    order: 5;
    position: relative;
    inset: auto;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: auto;
    margin: 0;
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
    pointer-events: auto;
  }

  body.page-lesson .dock .ticket,
  body.page-lesson .dock .ticket:has(.world[open]) {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    width: auto;
    max-height: none;
    overflow: visible;
    transform: none;
    animation: none;
    padding: 18px 28px 16px 16px;
  }

  body.page-lesson .ticket-body,
  body.page-lesson .world-copy {
    overflow: visible;
    max-height: none;
  }

  body.page-lesson .ticket h2 {
    line-height: 1.15;
  }

  body.page-lesson .shape {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    width: auto;
    transform: none;
  }

  body.page-lesson .modes button,
  body.page-lesson .swatches button {
    min-height: 44px;
  }

  body.page-lesson .rail {
    min-height: 48px;
    height: auto;
  }

  body.page-lesson .world summary {
    min-height: 44px;
  }

  body.page-lesson .error { order: 6; }

  html.embed body.page-lesson {
    display: block;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    padding-top: 0;
    touch-action: none;
  }

  html.embed body.page-lesson #stage {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    order: 0;
  }

  .page-hub .seal {
    position: relative;
    top: auto;
    right: auto;
    left: auto;
    width: 100%;
    margin: 0 0 12px;
  }
}
