#essay[hidden] { display: none; }
html[data-guided] { overflow: hidden; }
html[data-guided] .top { z-index: 6; pointer-events: none; }
html[data-guided] .top :is(.brand, .about-menu) { pointer-events: auto; }
html[data-guided] main { min-height: 0; height: 100dvh; }
html[data-guided] .top .palette-actions { display: none; }

html[data-guided] #notifications { visibility: hidden; }
html[data-guided] .stage-foot,
html[data-guided] .linked,
html[data-guided] .palette-controls { opacity: var(--studio-reveal, 0); }
html[data-guided] .palette { opacity: var(--show-palette, 0); }
html[data-guided] .palette :is(.section-head, .weight-control) { display: none; }
#essay { position: fixed; inset: 0; z-index: 5; color: #eae8e5; }
#essay-scroll { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
#essay-scroll:focus { outline: none; }
.essay-frame h2:focus-visible { outline: 1px solid #ffffff60; outline-offset: 5px; }
#essay-scroll > section { min-height: 100%; }
#essay-scroll > section[data-demonstration]::after {
  content: '';
  display: block;
  height: clamp(240px, 62dvh, 580px);
}
#essay-scroll :is(#begin, #values, #routes)::after { height: clamp(2000px, 400dvh, 4800px); }
#essay-scroll :is(#third, #rgb-red, #rgb-green, #rgb-blue, #rgb-pair)::after { height: clamp(560px, 125dvh, 1600px); }
#essay-scroll :is(#hue, #saturation, #lightness, #pair)::after { height: clamp(2000px, 320dvh, 3800px); }
/* Touch navigation handles vertical travel. Keep browser pinch zoom and
   native snap for keyboard navigation and programmatic chapter links. */
#essay-scroll[data-touch-story] {
  --entrance-height: 100dvh;
  touch-action: pan-x pinch-zoom;
  scroll-snap-type: y mandatory;
  overflow-anchor: none;
}
#essay-scroll[data-touch-story] > :is(section, #essay-entrance) {
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
#essay-scroll[data-touch-story] > section::after { display: none !important; }
#essay-scroll[data-touch-story] .essay-frame { position: relative; }
#essay-plot > span {
  position: absolute;
  left: -22px;
  top: -22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  touch-action: none;
}
#essay-scroll > section:not([data-demonstration]):not(#studio)::after {
  content: '';
  display: block;
  height: 26dvh;
}
.essay-frame {
  position: sticky;
  top: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  padding: 4rem clamp(22px, 3vw, 56px);
  pointer-events: none;
}
#essay-scroll[data-caption-layout] > section::before {
  content: '';
  display: block;
  height: var(--caption-height, 100dvh);
}
#essay-scroll[data-caption-layout] .essay-frame {
  position: fixed;
  left: 0;
  width: var(--caption-width);
}
.essay-frame > div { width: min(24vw, 340px); pointer-events: auto; }
#essay h2 { margin: 0; font: 400 clamp(26px, 2.8vw, 46px)/1.05 var(--heading-font); letter-spacing: -.025em; text-wrap: balance; }
#essay p { color: #c2bfbd; margin: 14px 0 0; font-size: clamp(14px, 1.08vw, 18px); line-height: 1.55; }
#essay .essay-frame a, #skip-essay { color: #eee; font: 600 13px/1.5 var(--body-font); }
#essay .essay-frame a { display: inline-block; margin-top: 18px; text-underline-offset: 5px; }
.story-shortcuts {
  position: absolute;
  z-index: 2;
  bottom: calc(max(clamp(24px, 5vh, 54px), var(--cue-room, 0px) * (1 - var(--shortcut, 1))) + env(safe-area-inset-bottom));
  right: calc(clamp(22px, 4vw, 68px) + env(safe-area-inset-right));
}

#release-cursor {
  position: absolute;
  right: 16px;
  bottom: calc(100% - 8px);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: #deddda;
  font: 600 13px/1.5 var(--body-font);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, visibility 0s linear 160ms;
}
html[data-story-demo] #release-cursor {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}
@media (prefers-reduced-motion: reduce) {
  #release-cursor { transition: none; }
}
#skip-essay {
  --card: calc(1 - var(--shortcut, 1));
  display: flex;
  align-items: center;
  gap: calc(6px + 6px * var(--card));
  border: 1px solid rgb(255 255 255 / calc(.19 * var(--card)));
  border-radius: 6px;
  background: rgb(32 32 32 / calc(.95 * var(--card)));
  padding-block: calc(8px + 23px * var(--card));
  padding-inline: calc(4px + 22px * var(--card)) calc(16px + 22px * var(--card));
  min-height: calc(58px + 58px * var(--card));
  color: #deddda;
  font-size: clamp(12px, 1vw, 14px);
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
  overflow: hidden;
}
.play-symbol {
  position: relative;
  display: grid;
  place-items: center;
  width: calc(84px + 12px * var(--card));
  height: 52px;
  grid-template-rows: minmax(0, 1fr);
}
#play-cube, .hold-prefix { grid-area: 1 / 1; }
#play-cube {
  width: 80px;
  height: 64px;
  position: relative;
  top: calc(-6px * var(--shortcut, 1));
  opacity: clamp(0, calc(1 - 1.8 * var(--shortcut, 1)), 1);
}
.hold-prefix {
  opacity: clamp(0, calc(1.8 * var(--shortcut, 1) - .8), 1);
  transform: translateY(calc(5px * var(--card)));
  color: inherit;
  font: inherit;
  white-space: nowrap;
}
.keyboard-hold { display: inline-flex; align-items: center; gap: 5px; }
@media (hover: none) and (pointer: coarse) {
  .keyboard-hold { display: none; }
  #skip-essay { gap: calc(12px * var(--card)); }
  #skip-essay .play-symbol {
    width: calc(96px * var(--card));
    height: calc(52px * var(--card));
  }
  html[data-guided] #story-scroll-reminder {
    bottom: calc(clamp(24px, 5vh, 54px) + 14px + env(safe-area-inset-bottom));
  }
}
.play-label { white-space: nowrap; }
.story-shortcuts kbd {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-grid;
  place-items: center;
  padding: 3px 6px;
  border: 1px solid #777;
  border-bottom-width: 2px;
  border-radius: 4px;
  color: #efeeeb;
  font: 11px/1.2 var(--mono);
}
#skip-essay kbd::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #686868;
  transform: scaleX(0);
  transform-origin: left;
}
#skip-essay[data-holding] kbd::before {
  transform: scaleX(1);
  transition: transform var(--skip-hold-duration) linear;
}
#essay .essay-frame a:hover { color: white; text-decoration: underline; }
#skip-essay:hover { color: white; }
/* The same ink and paper drive every mark, including the knockouts in the illustration. */
.pair-studies {
  width: min(35vw, 430px);
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}
.pair-print {
  container-type: inline-size;
  position: relative;
  aspect-ratio: 1.26;
  overflow: hidden;
  border-radius: 3px;
  color: var(--mark-ink);
  background: var(--mark-paper);
}
.fold-logo { display: flex; align-items: center; justify-content: center; gap: 4%; }
.fold-logo i {
  width: 25%;
  height: 37%;
  background: currentColor;
  clip-path: polygon(0 32%, 47% 0, 100% 0, 53% 32%, 100% 32%, 54% 64%, 32% 64%, 32% 86%, 0 100%);
}
.fold-logo b { font: 700 25cqw/1 Georgia, serif; letter-spacing: -.08em; }
.coast-print i { position: absolute; display: block; background: currentColor; }
.coast-sun { width: 28%; aspect-ratio: 1; border-radius: 50%; top: 17%; right: 21%; }
.coast-land {
  inset: 0;
  clip-path: polygon(0 28%, 12% 34%, 24% 47%, 35% 50%, 42% 60%, 62% 65%, 66% 70%, 100% 70%, 100% 73%, 0 73%);
}
.coast-water {
  inset: 77% 0 0;
  clip-path: polygon(0 0, 73% 0, 42% 10%, 12% 14%, 48% 22%, 85% 26%, 29% 36%, 10% 40%, 55% 49%, 29% 55%, 0 60%);
}
.type-poster { display: flex; flex-direction: column; justify-content: space-between; padding: 6% 7%; }
.type-poster b { font: 900 25cqw/.77 Arial, sans-serif; letter-spacing: -.075em; }
.type-poster small { border-top: 1px solid; padding-top: 2%; font: 700 7cqw/1 var(--mono); letter-spacing: .12em; }
#essay-scroll #hypothesis::after { height: clamp(840px, 170dvh, 2100px); }
#hypothesis .essay-frame { justify-content: center; align-items: center; padding: 64px 20px; }
#hypothesis .essay-frame > div { width: min(100%, 1120px); text-align: center; pointer-events: none; }
#hypothesis .essay-frame h2 {
  font-size: clamp(32px, 5.5vw, 83px);
  line-height: 1.05;
  text-shadow: 0 2px 12px #1c1c1c;
}
html[data-guided] #plot { filter: var(--question-blur, none); }
#hypothesis h2 span { display: inline-block; }
#hypothesis p { max-width: 52ch; margin: 20px auto 0; text-wrap: pretty; }

@media (max-width: 760px) {
  .pair-studies { width: 100%; max-width: 350px; margin-top: 10px; }
  #hypothesis p { max-width: 36ch; }
}
@media (max-width: 760px) {
  html[data-guided] #plot { height: var(--guide-plot-height, 60%); top: var(--guide-plot-top, 5%); }
  html[data-guided] #plot {
    top: calc(var(--guide-plot-top, 5%) + (max(5dvh, calc(54px + 2dvh)) - 5dvh) * var(--story-pair-frame, 0));
  }
  html[data-guided][data-story-rgb-chapter] #plot { top: max(var(--guide-plot-top, 5%), calc(60px * (1 - var(--studio-reveal, 0)))); }
  html[data-guided] .palette { bottom: calc(82px + env(safe-area-inset-bottom)); }
  html[data-guided] .palette .palette-controls { display: flex; }
  #pair .essay-frame { padding-top: 40dvh; }
  :is(#rgb-red, #rgb-green, #rgb-blue, #rgb-pair, #studio) .essay-frame { padding-top: 46dvh; padding-bottom: 140px; }
  .essay-frame { padding: 55dvh 18px 18px; align-items: flex-start; }
  .essay-frame > div { width: min(100%, 420px); }
  #essay h2 { font-size: clamp(21px, 5.8vw, 29px); }
  #essay p { font-size: 14px; line-height: 1.4; margin-top: 7px; }
  #essay .essay-frame a { margin-top: 9px; }
}

@media (max-width: 1000px) {
  html[data-story-pair] .palette { bottom: calc(clamp(24px, 5vh, 54px) + 78px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  html[data-guided] .palette {
    bottom: calc(82px + (clamp(24px, 5vh, 54px) - 43px - var(--compact-pair-offset, 0px)) * var(--story-pair-frame, 0) + env(safe-area-inset-bottom));
  }
}
@media (max-width: 760px) and (max-height: 700px) {
  html[data-guided] #plot {
    top: calc(var(--guide-plot-top, 5%) + (max(5dvh, 54px) - 5dvh) * var(--story-pair-frame, 0));
  }
  #pair .essay-frame { padding-top: 36dvh; }
  #routes .essay-frame { padding-top: 48dvh; }
  .pair-studies { max-width: 300px; }
}

html[data-welcome] { --entry-arrival: 0; --shortcut: 0; }
html[data-welcome] #plot { visibility: hidden; }
#begin .essay-frame { opacity: var(--entry-arrival, 1); }
html[data-opening] :is(.palette-actions, .stage-foot, .linked, .palette, #notifications) {
  opacity: var(--entry-arrival, 0);
  pointer-events: none;
}
html[data-opening] #essay, html[data-opening] main { pointer-events: none; }
#essay-scroll { --entrance-height: clamp(320px, 72dvh, 650px); }
#essay-entrance { height: var(--entrance-height); }
.essay-opening-position {
  position: absolute;
  inset: 0 0 auto;
  height: calc(var(--entrance-height) + 100dvh);
  overflow-x: clip;
  pointer-events: none;
}
.essay-opening-position #welcome {
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow: visible;
}
#essay-entrance[hidden], #essay-entrance[hidden] + .essay-opening-position, #welcome[hidden] { display: none; }
html[data-entry-scroll] #welcome { pointer-events: none; }
html[data-welcome] #welcome button { pointer-events: auto; }
#welcome {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
}
#hero-surface, #hero-foreground { position: absolute; inset: 0; width: 100%; height: 100%; }
#hero-foreground { pointer-events: none; }
#welcome-title {
  position: relative;
  margin: 0;
  max-width: min(22ch, 92vw);
  padding: 0 12px;
  font: 400 clamp(39.1px, 6.29vw, 100.3px)/1.08 var(--heading-font);
  letter-spacing: -.035em;
  text-wrap: balance;
  text-align: left;
  text-shadow: 0 2px 16px #181818;
}
#welcome-title small {
  display: block;
  font: inherit;
  letter-spacing: inherit;
}
#welcome-title span { display: block; color: #c7c3c0; }
#welcome-title em { font-style: italic; font-weight: 300; }
#welcome-story {
  position: absolute;
  z-index: 1;
  bottom: var(--cue-bottom, 8dvh);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #efeeea;
  font: 600 14px/1.4 var(--body-font);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.scroll-icon {
  position: relative;
  width: 14px;
  height: 21px;
  flex: none;
  border: 1.5px solid currentColor;
  border-radius: 8px;
}
.scroll-icon::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 50%;
  width: 2px;
  height: 5px;
  margin-left: -1px;
  border-radius: 2px;
  background: currentColor;
}
@media (prefers-reduced-motion: no-preference) {
  html[data-welcome] .scroll-icon::after, #story-scroll-reminder[data-visible] .scroll-icon::after { animation: story-wheel 1.9s ease-in-out infinite; }
  @keyframes story-wheel {
    0%, 18% { transform: translateY(0); opacity: 1; }
    64% { transform: translateY(6px); opacity: 1; }
    80% { transform: translateY(6px); opacity: 0; }
    81% { transform: translateY(0); opacity: 0; }
    100% { opacity: 1; }
  }
}
#story-scroll-reminder {
  position: absolute;
  z-index: 2;
  left: clamp(18px, 3vw, 52px);
  bottom: calc(clamp(24px, 5vh, 54px) + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 9px;
  color: #c2bfbd;
  font: 600 13px/1.4 var(--body-font);
  opacity: 0;
  pointer-events: none;
}
html[data-guided] #story-scroll-reminder[data-placement="gap"] {
  left: var(--cue-x);
  top: var(--cue-y);
  bottom: auto;
  translate: -50% -50%;
  white-space: nowrap;
}
#story-scroll-reminder[data-compact] .scroll-icon { scale: .65; }
#story-scroll-reminder[data-visible] { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  #story-scroll-reminder { transition: opacity 180ms ease-out; }
}
#welcome-story:hover { color: #fff; }
#skip-essay[data-open]:hover { background: #292929; }
#welcome-story:focus-visible, #skip-essay:focus-visible { outline: 2px solid white; outline-offset: 4px; }
.essay-interaction-layer { position: sticky; top: 0; height: 0; z-index: 1; }
#essay-plot { position: absolute; z-index: 1; touch-action: none; cursor: var(--plot-cursor, crosshair); }
html[data-story-cursor],
html[data-story-cursor] :not(#story-cursor-refresh) { cursor: none !important; }
#story-cursor-refresh {
  position: fixed;
  inset: -2px auto auto -2px;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
#story-cursor {
  position: fixed;
  width: 28px;
  height: 40px;
  transform: translate(-5px, -5px);
  pointer-events: none;
  z-index: 20;
}
#story-cursor[hidden] { display: none; }
#story-cursor[data-shape]:not([data-shape="default"]) { transform: translate(-14px, -20px); }
#essay-plot:focus { outline: none; }
#essay-plot:focus-visible:not([data-pointer-focus])::after {
  content: 'Arrow keys to move';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  color: #deddda;
  font: 12px var(--body-font);
  pointer-events: none;
}
@media (max-width: 760px) {
  #welcome-title { max-width: min(15ch, 96vw); }
}


html[data-guided] .palette:not([inert]) { z-index: 6; }
html[data-guided] .palette .palette-controls { pointer-events: none; }
html[data-opening] .palette { pointer-events: none; }

.finish-action { position: relative; width: max-content; margin: 26px 0 0 auto; }
#finish-story {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: block;
  margin: 0;
  padding: 11px 17px;
  border: 1px solid #686661;
  border-radius: 7px;
  background: transparent;
  color: #dbd9d4;
  font: 600 14px/1.4 var(--body-font);
  cursor: pointer;
}
#finish-story::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #ffffff34;
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 90ms ease-out;
}
#finish-story[data-holding="pointer"]::before {
  transform: scaleX(1);
  transition: transform var(--finish-hold) linear;
}
#finish-story[data-holding="wheel"]::before {
  transform: scaleX(var(--wheel-fill, 0));
  transition: none;
}
@media (prefers-reduced-motion: reduce) {
  #finish-story[data-holding="pointer"]::before { transition-timing-function: steps(5, end); }
  #finish-story::before { transition-duration: 0s; }
}
#finish-story:hover { background: #ffffff0c; border-color: #95928c; }
#finish-story:focus-visible { outline: 2px solid white; outline-offset: 4px; }
#finish-story span { margin-left: 8px; }
html[data-story-exit] #studio .essay-frame {
  opacity: calc(1 - var(--caption-exit));
  transform: translateY(calc(-84px * var(--caption-exit)));
}
html[data-story-exit] .story-shortcuts {
  opacity: calc(1 - var(--caption-exit));
  pointer-events: none;
}
html[data-story-exit] .palette { translate: 0 var(--swatch-offset); }
html[data-story-exit] .palette .section-head { display: flex; }
html[data-story-exit] .palette .weight-control {
  display: block;
  opacity: calc(.5 * var(--palette-entry));
  transition: none;
}
html[data-story-exit] .linked {
  opacity: var(--tool-entry);
  translate: calc(-30px * (1 - var(--tool-entry))) 0;
}
html[data-story-exit] .stage-foot {
  opacity: var(--hint-entry);
  translate: 0 calc(-10px * (1 - var(--hint-entry)));
}
html[data-story-exit] :is(.palette .section-head, .palette-controls) {
  opacity: var(--palette-entry);
}
html[data-story-exit] :is(.palette .section-head, .palette .weight-control) {
  translate: 0 calc(16px * (1 - var(--palette-entry)));
}
html[data-story-exit] .palette-controls { translate: 0 calc(-12px * (1 - var(--palette-entry))); }
@media (max-width: 760px), (hover: none) and (pointer: coarse) and (max-width: 1024px) and (max-height: 540px) {
  html[data-story-exit] .linked { translate: 0 calc(-18px * (1 - var(--tool-entry))); }
}
@media (max-width: 760px) {
  html[data-story-exit] .palette { bottom: 20px; }
}
@media (prefers-reduced-motion: no-preference) {
  html[data-playground-arrival] .palette-actions {
    animation: playground-arrival 200ms ease-out both;
  }
  @keyframes playground-arrival {
    from { opacity: 0; translate: 0 -4px; }
    to { opacity: 1; translate: 0 0; }
  }
}

@media (max-width: 760px), (hover: none) and (pointer: coarse) and (max-width: 1024px) and (max-height: 540px) {
  /* Let swipes over fixed captions reach the native scroller underneath. */
  .essay-frame > div { pointer-events: none; }
  .essay-frame :is(a, button) { pointer-events: auto; }
  #essay-plot, #essay .scrub-label { touch-action: pan-y pinch-zoom; }
  .story-touch-controls {
    position: absolute;
    inset: 0 0 auto;
    height: 100dvh;
    z-index: 2;
    pointer-events: none;
  }
  .story-touch-controls .story-shortcuts,
  .story-touch-controls .palette:not([inert]) { pointer-events: auto; }
}

.swipe-copy, .swipe-hand { display: none; }
@media (max-width: 760px) {
  .story-shortcuts {
    right: auto;
    left: calc(50% * (1 - var(--shortcut, 1)) + (100% - clamp(22px, 4vw, 68px) - env(safe-area-inset-right)) * var(--shortcut, 1));
    transform: translateX(calc(-50% - 50% * var(--shortcut, 1)));
  }
}
@media (hover: none) and (pointer: coarse) {
  .scroll-copy { display: none; }
  .swipe-copy { display: inline; }
  .scroll-icon { width: 24px; height: 30px; border: 0; border-radius: 0; }
  .scroll-icon::after { display: none; animation: none !important; }
  .swipe-hand {
    display: block;
    width: 24px;
    height: 30px;
    overflow: visible;
    /* The wrist is at the base of the palm in the 24 × 30 viewBox. */
    transform-origin: 13px 27px;
    transform: translate(4px, 3px) rotate(-34deg);
  }
}
@media (hover: none) and (pointer: coarse) and (prefers-reduced-motion: no-preference) {
  html[data-welcome] .swipe-hand, #story-scroll-reminder[data-visible] .swipe-hand {
    animation: story-swipe 2.25s infinite;
  }
  @keyframes story-swipe {
    0%, 14% {
      transform: translate(4px, 3px) rotate(-34deg);
      animation-timing-function: cubic-bezier(.32, 0, .18, 1);
    }
    49%, 62% {
      transform: translate(2px, -7px) rotate(-16deg);
      animation-timing-function: cubic-bezier(.42, 0, .3, 1);
    }
    91%, 100% { transform: translate(4px, 3px) rotate(-34deg); }
  }
}

.finish-hint { display: none; }
@media (hover: none) and (pointer: coarse) {
  .finish-hint {
    display: block; position: absolute; right: 0; top: calc(100% + 6px);
    color: #c2bfbd; font: 500 12px/1.4 var(--body-font);
    opacity: 0; transform: translateY(-3px); pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
  }
  #finish-story[data-holding="pointer"] + .finish-hint { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .finish-hint { transition: none; } }

@media (max-width: 380px) and (max-height: 700px) {
  #welcome-title { font-size: clamp(29px, 9vw, 34px); transform: translateY(-12px); }
}

@media (max-width: 380px) and (max-height: 600px) {
  html[data-guided] .palette { --compact-pair-offset: 22px; }
}

.swipe-contact { opacity: 0; transform-box: fill-box; transform-origin: center; }
@media (hover: none) and (pointer: coarse) and (prefers-reduced-motion: no-preference) {
  html[data-welcome] .swipe-contact, #story-scroll-reminder[data-visible] .swipe-contact {
    animation: swipe-contact 2.25s infinite;
  }
  @keyframes swipe-contact {
    0%, 6% { opacity: 0; transform: scale(.55); }
    14%, 30% { opacity: .65; transform: scale(1); }
    49%, 100% { opacity: 0; transform: scale(1.45); }
  }
}

@media (max-width: 380px) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  #studio .finish-action {
    position: fixed;
    left: 18px;
    right: auto;
    bottom: calc(clamp(24px, 5vh, 54px) + env(safe-area-inset-bottom));
    margin: 0;
  }
}

/* This temporary middle swatch is an example, not a palette edit. */
html[data-story-third] #swatches {
  grid-template-columns: minmax(0, 1fr) minmax(0, calc(33.333% * var(--third-presence, 0))) minmax(0, 1fr) !important;
}
html[data-story-third] #swatches .swatch:last-child { grid-column: 3; grid-row: 1; }
html[data-story-third] #swatches .num { visibility: hidden; }
html[data-story-third] #swatches::after {
  content: var(--third-value, '');
  grid-column: 2; grid-row: 1;
  min-width: 0; overflow: hidden; white-space: nowrap;
  display: flex; align-items: end; padding: 8px;
  color: var(--third-ink, #222); background: var(--third-color, transparent);
  opacity: var(--third-presence, 0);
  font: 11px var(--mono);
}

@media (max-width: 380px) and (max-height: 600px) {
  #third .essay-frame { padding-top: 39dvh; }
}

/* Keep the final action inside its chapter even on short phones. */
@media (max-height: 700px) and (orientation: portrait) {
  #essay-scroll[data-touch-story] #studio .essay-frame { padding: 46dvh 18px 0; }
  #essay-scroll[data-touch-story] #studio .finish-action {
    position: absolute;
    left: 18px;
    right: auto;
    bottom: calc(var(--story-footer) + 7px);
    margin: 0;
  }
}

/* A short landscape screen has room for the demonstration beside the copy. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 540px) and (max-width: 1024px) {
  html[data-guided] .top { height: 48px; min-height: 48px; }
  #essay-scroll[data-touch-story] section:not(#hypothesis) .essay-frame {
    padding: 54px 0 48px max(22px, env(safe-area-inset-left));
    align-items: center;
  }
  #essay-scroll[data-touch-story] section:not(#hypothesis) .essay-frame > div { width: 41vw; }
  #essay h2 { font-size: clamp(19px, 3vw, 27px); }
  #essay p { font-size: 13px; line-height: 1.38; margin-top: 7px; }
  #essay .essay-frame a, #essay .finish-action { margin-top: 10px; }
  #essay .pair-studies { width: min(40vw, 74vh); margin-top: 9px; }
  #hypothesis .essay-frame { padding-bottom: 108px; }
  #hypothesis .essay-frame h2 { font-size: clamp(24px, 4vw, 38px); }
  #welcome-title { font-size: min(5vw, 9vh); max-width: 18ch; }
  #welcome-story { left: 16px; bottom: 6px; }
  #essay .story-shortcuts { left: auto; right: max(18px, env(safe-area-inset-right)); bottom: 6px; transform: none; }
  html[data-guided] #story-scroll-reminder { bottom: 20px; }
  html[data-guided] main #plot, html[data-guided][data-story-rgb-chapter] main #plot {
    left: 47%;
    width: 52%;
    top: calc(53px - 5px * var(--studio-reveal, 0));
    height: calc(100% - 146px + 98px * var(--studio-reveal, 0));
  }
  html[data-guided] .story-touch-controls .palette {
    left: 73%; width: 46%; bottom: 70px;
  }
  html[data-guided]:not([data-story-exit]) .story-touch-controls .palette-controls { display: none; }
  html[data-story-exit] .story-touch-controls .palette {
    left: calc(73% - 49% * var(--studio-reveal));
    width: calc(46% - 3% * var(--studio-reveal));
    bottom: max(2px, calc(50% - 145px));
  }
  html[data-story-exit] .linked { left: 24%; top: max(52px, calc(50% - 118px)); }
  html[data-guided] .story-touch-controls .swatch { height: 42px; }
  html[data-guided] .story-touch-controls .swatch .value { font-size: 9px; }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) and (max-width: 760px) {
  /* Keep a footer fallback for short chapters without room below the copy. */
  html[data-guided] {
    --footer-inset: clamp(2px, calc(4dvh - 21px), 16px);
    --story-footer: calc(var(--footer-inset) + env(safe-area-inset-bottom));
  }
  #essay .story-shortcuts {
    bottom: calc(var(--story-footer) + (clamp(24px, 5vh, 54px) - var(--footer-inset)) * (1 - var(--shortcut, 1)));
  }
  html[data-guided] #story-scroll-reminder { bottom: calc(var(--story-footer) + 14px); }
  html[data-guided]:not([data-story-exit]) .story-touch-controls .palette {
    bottom: calc(var(--story-footer) + clamp(55px, 10dvh, 79px));
  }
  /* Reclaim the invisible count row while the story only shows swatches. */
  html[data-guided]:not([data-story-exit]) .story-touch-controls .palette-controls { display: none; }
}
@media (hover: none) and (pointer: coarse) and (orientation: portrait) and (max-height: 640px) {
  #essay-scroll[data-touch-story] :is(#linear, #path, #handles, #routes, #rgb) .essay-frame { padding-top: 46dvh; }
  #essay-scroll[data-touch-story] #hypothesis .essay-frame { padding-bottom: 136px; }
  #essay-scroll[data-touch-story] #hypothesis h2 { font-size: 26px; }
  #essay-scroll[data-touch-story] #routes p { font-size: 13px; }
}
