html {
  height: 100%;
  overflow: hidden;
  /* No double-tap zoom: a second tap on plain text (the title's intro line included — three quick taps
     there open the speedrun card) would zoom the mobile visual viewport out of the game's fixed layout.
     `manipulation` keeps panning and pinch zoom, which is the accessibility-relevant half. */
  touch-action: manipulation;
}

body {
  background: #0a0a1a;
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f0f0f0;
  font-family: monospace;
}

#game-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: var(--scene-height, 50%) minmax(0, 1fr);
  gap: 6px;
}

#playfield {
  position: relative;
  width: var(--scene-width, 100%);
  height: var(--scene-height, auto);
  aspect-ratio: 800 / 450;
  place-self: center;
  min-width: 0;
  min-height: 0;
}

#game-wrap[data-layout="landscape"] {
  grid-template-columns: var(--sword-column-width, 0px) var(--scene-width) var(--answer-width, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  justify-content: center;
}

/* Landscape places its three blocks explicitly: the sword column
 * (encounter-swords.js) owns the first grid column for the full height under
 * the chrome row, the scene the second and the answers the third. */
#game-wrap[data-layout="landscape"] > #playfield { grid-column: 2; grid-row: 1; }
#game-wrap[data-layout="landscape"] > #input-zone { grid-column: 3; grid-row: 1; }
#game-wrap[data-layout="landscape"]:has(#gameplay-chrome:not([hidden])) > #playfield,
#game-wrap[data-layout="landscape"]:has(#gameplay-chrome:not([hidden])) > #input-zone { grid-row: 2; }

#game-wrap:has(#gameplay-chrome:not([hidden])) {
  grid-template-rows: auto var(--scene-height) minmax(0, 1fr);
}

#game-wrap[data-layout="landscape"]:has(#gameplay-chrome:not([hidden])) {
  grid-template-rows: auto minmax(0, 1fr);
}

#game-wrap[data-layout="landscape"]:has(#gameplay-chrome:not([hidden])) > .app-encounter-swords-column {
  grid-row: 2;
}

#gameplay-chrome {
  position: relative;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  padding: 4px 8px;
  background: #10172d;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  line-height: 20px;
  min-width: 0;
}

/* The level bonus notice (gameplay-chrome.js) is absolutely positioned so it
 * adds no grid row: the answer buttons and the scene keep their layout while
 * the pill floats over the top of the playfield. pointer-events:none keeps it
 * non-blocking, and [hidden] (see the global rule) removes it entirely. */
#bonus-notice {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  z-index: 2;
  max-width: calc(100% - 16px);
  margin: 0;
  padding: 4px 12px;
  overflow: hidden;
  border: 2px solid var(--brass-light);
  border-radius: 999px;
  background: rgba(16, 23, 45, 0.94);
  color: var(--ivory);
  font: bold 15px/20px system-ui, sans-serif;
  white-space: nowrap;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  pointer-events: none;
}

/* Landscape puts the answers in their own column beside the scene, but the
 * notice's host spans both columns, so a pill centred on the header ran under
 * the answer panel (z-index 20 beats the pill's 2) and lost its right end —
 * worst for the long German sentences. Anchor it to the scene column instead:
 * the bonus belongs to the playfield the spells are cast from. */
#game-wrap[data-layout="landscape"] #bonus-notice {
  left: calc(var(--sword-column-width, 0px) + 6px);
  right: calc(var(--answer-width) + 12px);
  width: fit-content;
  max-width: calc(var(--scene-width) - 8px);
  margin-inline: auto;
  transform: none;
  text-align: center;
}

#active-question {
  grid-column: 1 / -1;
  min-height: 28px;
  font: bold 22px/28px monospace;
  overflow-wrap: normal;
}

/* The question row is reserved per mode: Shapes needs two rows (the
 * "Count the shapes" instruction and the shapes themselves), the campaign
 * needs one (the problem). gameplay-chrome.js publishes the marker for the
 * whole level, so the row keeps its height between problems and during the
 * reveal. The campaign's single row never wraps: a second line would grow the
 * header and rescale the scene (see viewport-layout.js). */
#gameplay-chrome[data-question-rows="2"] #active-question { min-height: 56px; }
/* Shapes writes its question as two block rows (instruction, shapes) - see
 * gameplay-chrome.js. Each row stays on one line, so the mode's two reserved
 * rows are exactly what is drawn. */
#active-question[data-shapes-header="two-rows"] {
  display: grid;
  grid-template-rows: auto auto;
  align-content: start;
  row-gap: 0;
}
#active-question[data-shapes-header="two-rows"] > span {
  display: block;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
  font: bold 22px/28px monospace;
}

/* Runestones: the one counting image (see game/runestone.js), sized from the
 * row's font so it scales with the header like the glyphs it replaced. */
.runestone {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  margin: 0 0.3em 0 0;
  vertical-align: -0.12em;
  image-rendering: pixelated;
}
#active-question[data-stone-sum] { font: bold 22px/28px monospace; }
#active-question .stone-sum-stones { white-space: nowrap; }
#active-question .stone-sum-stones .runestone { margin-right: 0.3em; }

#gameplay-chrome[data-question-rows="1"] #active-question {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Campaign II: stacked maths (a fraction, a power over a fraction, a root) is
 * taller than the 28px line. gameplay-chrome.js measures the tallest question a
 * level can ask when it starts (campaign2/question-reserve.js) and publishes it
 * as --question-row-height with the marker "math". The row is exactly that high
 * for the whole level - fixed, not a minimum, so no question, correction or
 * empty pause between problems can grow or shrink the header (viewport-layout.js
 * sizes the scene from it). The maths sits centred in the row; the plain-text
 * correction keeps its 28px line, padded to the middle of the row, so it keeps
 * its ellipsis. The line height itself never changes: the measurement copies
 * it. Both stay on one line and are clipped at the row's edge. */
#gameplay-chrome[data-question-rows="math"] #active-question {
  box-sizing: border-box;
  height: var(--question-row-height, 28px);
  min-height: var(--question-row-height, 28px);
  padding-block: calc((var(--question-row-height, 28px) - 28px) / 2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#gameplay-chrome[data-question-rows="math"] #active-question[data-math-key] {
  display: flex;
  align-items: center;
  padding-block: 0;
}
#gameplay-chrome[data-question-rows="math"] #active-question[data-math-key] > .m2-expr {
  flex: none;
}

/* The correction is plain text in either mode, so it needs the same guard: it
 * must stop at the help/pause buttons instead of running under them. */
#active-question:not([data-shapes-header]) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A wrong answer or a timeout writes the correction into #active-question, in
 * place of the problem. There is deliberately no separate reveal row: it would
 * either stand empty (an unexplained gap in the header) or grow the header on
 * the reveal, and viewport-layout.js lays the scene out from the measured
 * header.
 */
/* The readouts are a grid, not a wrapping flex row: as flex, a shorter value
 * ("Time —" between problems instead of "Time 12s") packed one more marker
 * into the first line and shifted every later marker up, so the header lost a
 * line (22px) and viewport-layout.js laid the scene out again. A fixed minimum
 * column makes the column count depend only on the available width, so the
 * line count stays the same for every problem and every value length. Empty
 * markers keep their cell for the same reason. */
.gameplay-readouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(106px, 1fr));
  align-content: center;
  gap: 2px 8px;
  min-width: 0;
  font-size: 16px;
  line-height: 20px;
}

.gameplay-readouts > span:empty { visibility: hidden; }
.gameplay-readouts > span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  overflow-wrap: normal;
  text-overflow: ellipsis;
}
#accessible-timer-progress { width: 20px; height: 8px; margin-left: 4px; }
#btn-pause-game {
  align-self: center;
  min-width: 68px;
  min-height: 44px;
  padding: 4px 8px;
  font: inherit;
  background: #252952;
  color: #fff;
  border: 2px solid #a9b9ed;
  touch-action: manipulation;
}

/* Three-slot ability orbs (ability-bar.js). They are a normal-flow line of the
 * answer zone, placed by `order` directly under the portrait sword row, so they
 * cost the gameplay header nothing. Each slot is a 58px glass ball with the
 * artwork suspended in it and the cooldown seconds drawn over the middle; the
 * bonus-aware readout is a small caption under the ball. Two dragon ornaments
 * frame the row from the bar's own edges, so they never take layout space from
 * the balls or the answers.
 *
 * The glass is built only from gradients and insets: a translucent body that
 * lets the blurred stage behind it show through (backdrop-filter), a rim light,
 * a specular cap in `::before`, and a lit base. The cooling sweep is a static
 * conic gradient driven by the 0-1 --ability-progress property, and the ready
 * light is a pulsing layer the module fills in; neither owns a clock. */
#ability-bar {
  /* The laid dragons must never reach into the orbs, so their size is derived
   * from the space that is actually free beside the orb row (bar width minus
   * the three orbs and their two gaps), capped at 84px and floored at 34px.
   * The row is deliberately tight between the balls: every pixel of gap taken
   * from between the orbs is a pixel the dragons gain on the outside, and the
   * dragons keep --ornament-gap of air between their snout and the outer orb so
   * the frame reads as a frame instead of touching the glass.
   * Keep --orb-size in sync with .ability-slot's own width below: the slot
   * states its size literally so the tests and the layout stay readable. */
  --orb-gap: clamp(6px, 2.6vw, 12px);
  /* The ceiling is the design size; the width formula is the ceiling of the
   * answer column. Three orbs plus their gaps must always fit the row the
   * answers occupy — in a narrow landscape column the row used to spill over
   * the playfield. */
  --orb-cap: 58px;
  --orb-size: min(var(--orb-cap), calc((100% - 2 * var(--orb-gap)) / 3));
  --ornament-gap: 12px;
  /* Floored at zero, not at a minimum width: when the column cannot spare a
   * dragon *and* its air, the dragon collapses to nothing instead of shrinking
   * under the orb and poking out behind it (which is what a narrow landscape
   * column did). */
  --ornament-size: clamp(0px, calc((100% - 3 * var(--orb-size) - 2 * var(--orb-gap)) / 2 - var(--ornament-gap)), 76px);
  position: relative;
  order: -1;
  flex: 0 0 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: var(--orb-gap);
  width: 100%;
  min-width: 0;
  padding: 0 0 13px; /* reserves the readout caption line under the circles */
}

/* Ornate dragon framing, mirrored from one sprite. Decorative only.
 *
 * The dragons lie flat in the empty space between the orb row and the column
 * edges: heads turned inward toward the balls, bellies down, tails out. The
 * sprite is 97x222 (one creature standing), so a square box plus a 90deg turn
 * lays it down at about box-width wide by box-width x 0.43 tall, and the box is
 * exactly as wide as the free space beside the orbs.
 *
 * Centring uses `margin-top` rather than a translate on purpose: a translate in
 * the same transform list as the rotation would be rotated with it and push the
 * dragon sideways instead of up. */
.ability-ornament {
  position: absolute;
  top: 29px; /* the row's vertical centre: half the orb */
  width: var(--ornament-size);
  aspect-ratio: 1;
  height: auto;
  margin-top: calc(var(--ornament-size) / -2);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  opacity: 0.92;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.55));
}

/* Heads inward: the left bracket turns clockwise, so the head ends up on the
 * right, facing the first orb; the right bracket is that same turn mirrored, so
 * its head faces left, toward the last orb. Both keep wing up and belly down. */
.ability-ornament--left { left: 0; transform: rotate(90deg); }
.ability-ornament--right { right: 0; transform: scaleX(-1) rotate(90deg); }



.ability-slot {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  /* The width is derived from the row the answers occupy; the height follows it
   * through aspect-ratio, never through the same percentage, because a
   * percentage height would resolve against the row's *height* and squash the
   * ball into an ellipse. */
  width: var(--orb-size);
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  font: inherit;
  line-height: 1;
  color: #f0f0f0;
  /* Glass: the body is translucent so the stage behind it blurs through, the
   * top-left highlight is the specular spot, and the warm base is the light
   * the ball picks up from the floor. */
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.2) 13%, rgba(255, 255, 255, 0) 36%),
    radial-gradient(circle at 50% 108%, rgba(122, 214, 255, 0.5) 0%, rgba(122, 214, 255, 0) 54%),
    radial-gradient(circle at 50% 44%, rgba(46, 68, 126, 0.72) 0%, rgba(22, 34, 72, 0.78) 60%, rgba(8, 14, 36, 0.86) 100%);
  border: 0;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1.5px rgba(216, 240, 255, 0.55),
    inset 0 3px 9px rgba(255, 255, 255, 0.32),
    inset 0 -9px 16px rgba(86, 188, 255, 0.32),
    0 7px 16px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(3px) saturate(1.3);
  backdrop-filter: blur(3px) saturate(1.3);
  cursor: pointer;
  touch-action: manipulation;
  overflow: visible;
}

/* The specular cap: the one shape that says "polished sphere" rather than
 * "gradient circle". Sits above the artwork so the glass is in front of it. */
.ability-slot::before {
  content: "";
  position: absolute;
  top: 7%;
  left: 15%;
  width: 54%;
  height: 28%;
  z-index: 3;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.06));
  filter: blur(1.2px);
  opacity: 0.62;
  pointer-events: none;
}

/* Only the fallback name sits inside the circle; it stays out of sight while
 * the artwork is showing (see the [data-icon="loaded"] rule below). */
.ability-slot-name {
  font-weight: 700;
  font-size: 10px;
  line-height: 1.15;
  padding: 0 4px;
  text-align: center;
}

/* Cooldown seconds while cooling, "Ready" when it is up and the artwork is
 * missing: both are drawn across the middle of the circle. */
.ability-slot-cooldown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.9);
  /* A frosted disc under the digits: the number has to stay readable over a
   * bright icon and through the rim light. */
  background: radial-gradient(circle, rgba(4, 10, 26, 0.66) 0%, rgba(4, 10, 26, 0.4) 52%, rgba(4, 10, 26, 0) 76%);
  pointer-events: none;
}
.ability-slot[data-state="ready"] .ability-slot-cooldown { font-size: 11px; font-weight: 700; }
.ability-slot[data-state="ready"][data-icon="loaded"] .ability-slot-cooldown { display: none; }
.ability-slot[data-state="locked"] .ability-slot-cooldown { display: none; }

/* The bonus-aware caption ("3", "30% · ×3") is a number line under the
 * circle: it never pushes the circle size around, and its width is capped at
 * the orb plus half of each neighbouring gap, so two captions of one row can
 * never overlap. */
.ability-slot-readout {
  position: absolute;
  top: calc(100% + 1px);
  left: 50%;
  display: block;
  max-width: calc(100% + var(--orb-gap) - 4px);
  transform: translateX(-50%);
  overflow: hidden;
  font-size: 10px;
  line-height: 12px;
  color: #cdd6f4;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* Owner-delivered artwork (game/assets/ability-<id>.webp). Decorative: the
 * slot's aria-label names the ability, so the icon carries an empty alt. It is
 * inset rather than full-bleed so the glass body, the rim and the specular cap
 * all stay visible around it. */
.ability-slot-icon {
  width: 80%;
  height: 80%;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}

/* A locked slot is a dimmed silhouette: never any artwork. */
.ability-slot[data-state="locked"] .ability-slot-icon { display: none; }
.ability-slot-icon[hidden] { display: none; }

/* While the artwork is showing it replaces the visible name (the name stays
 * in the accessibility tree); if the file is missing the name becomes the
 * visible fallback instead of a broken-image box. */
.ability-slot[data-icon="loaded"] .ability-slot-name {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.ability-slot[data-icon="error"] .ability-slot-name {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Descriptions stay in the accessibility tree but not in the 44px slot. */
.ability-slot-description {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.ability-slot[data-state="locked"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.ability-slot[data-state="ready"] {
  box-shadow:
    inset 0 0 0 1.5px rgba(160, 255, 197, 0.85),
    inset 0 3px 9px rgba(255, 255, 255, 0.32),
    inset 0 -9px 16px rgba(86, 255, 190, 0.34),
    0 0 10px rgba(127, 224, 138, 0.5),
    0 7px 16px rgba(0, 0, 0, 0.5);
}
.ability-slot[data-state="cooling"] {
  box-shadow:
    inset 0 0 0 1.5px rgba(170, 186, 226, 0.5),
    inset 0 3px 9px rgba(255, 255, 255, 0.18),
    inset 0 -9px 16px rgba(80, 120, 200, 0.25),
    0 7px 16px rgba(0, 0, 0, 0.5);
}

/* The ready light. A spell that can be cast breathes: a halo outside the ball
 * and a lit core inside it. The animation lives on this layer and never on the
 * button, because animating the button's box-shadow would wipe the glass rim
 * every frame. Reduced motion keeps the light and drops the breathing. */
.ability-slot-glow {
  position: absolute;
  inset: -7px;
  z-index: 4;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(160, 255, 205, 0.42) 0%, rgba(160, 255, 205, 0.14) 48%, rgba(160, 255, 205, 0) 72%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms linear;
}

.ability-slot-glow::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.6) 0%, rgba(198, 255, 226, 0.2) 42%, rgba(198, 255, 226, 0) 70%);
  opacity: 0.55;
}

.ability-slot[data-state="ready"] .ability-slot-glow { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .ability-slot[data-state="ready"] .ability-slot-glow {
    animation: ability-orb-breathe 2.2s ease-in-out infinite;
  }
  .ability-slot[data-state="ready"] .ability-slot-glow::after {
    animation: ability-orb-core 2.2s ease-in-out infinite;
  }
}

@keyframes ability-orb-breathe {
  0%, 100% { opacity: 0.5; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.07); }
}

@keyframes ability-orb-core {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 0.85; transform: scale(1.1); }
}

/* Press feedback: glass shards thrown out of the ball (dom-burst.js). One CSS
 * animation flies each shard to its own offset, then the module removes it on
 * animationend. */
.dom-burst-shard {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 6;
  width: var(--burst-size, 6px);
  height: var(--burst-size, 6px);
  margin: calc(var(--burst-size, 6px) / -2) 0 0 calc(var(--burst-size, 6px) / -2);
  border-radius: 1.5px;
  pointer-events: none;
  animation: dom-burst-fly 620ms cubic-bezier(0.18, 0.72, 0.3, 1) forwards;
  animation-delay: var(--burst-delay, 0ms);
}

/* The score readout's sparks are the warm twin of the orb shards. */
#accessible-score-wrap { position: relative; }
#accessible-score-wrap .dom-burst-shard {
  background: linear-gradient(150deg, #fff8d8, #ffd96b 55%, #c98f21);
  box-shadow: 0 0 6px rgba(255, 214, 120, 0.85);
  animation-duration: 700ms;
}

.ability-slot .dom-burst-shard {
  background: linear-gradient(150deg, #ffffff, #d5edff 45%, #80b8ff);
  box-shadow: 0 0 7px rgba(178, 224, 255, 0.9);
}

@keyframes dom-burst-fly {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 1;
  }
  70% { opacity: 0.85; }
  100% {
    transform: translate(var(--burst-x, 0px), var(--burst-y, -30px)) scale(0.3)
      rotate(var(--burst-rot, 120deg));
    opacity: 0;
  }
}

/* Reduced motion: the sparks appear and fade where they are born. */
@media (prefers-reduced-motion: reduce) {
  .dom-burst-shard {
    animation: dom-burst-fade 320ms ease-out forwards;
  }
  .dom-burst-shard[data-reduced="true"] {
    animation: dom-burst-fade 320ms ease-out forwards;
  }
}

@keyframes dom-burst-fade {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.4); opacity: 0; }
}

.ability-slot[data-state="cooling"]::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
  background: conic-gradient(
    from -90deg,
    rgba(4, 8, 18, 0.72) calc((1 - var(--ability-progress, 0)) * 1turn),
    transparent 0
  );
}

/* Layering inside the ball: artwork (1), cooling sweep (2), specular cap (3),
 * ready light (4), cooldown seconds (5), shards (6). The number has to stay on
 * top of every glass layer or the pulse swallows it. */
.ability-slot-name,
.ability-slot-icon {
  position: relative;
  z-index: 1;
}
.ability-slot-cooldown { z-index: 5; }

@media (orientation: landscape) and (max-height: 400px) {
  #gameplay-chrome { padding: 2px 6px; gap: 2px 6px; }
  #active-question { font-size: 22px; line-height: 28px; min-height: 28px; }
  .gameplay-readouts { font-size: 16px; line-height: 20px; gap: 2px 6px; }
  #btn-pause-game { grid-column: 2; grid-row: 1 / span 3; }
  #active-question { grid-column: 1; }

  /* Landscape has no vertical slack to spare: the row caps at 44px, the gap
   * between the balls tightens, the caption line gets shorter and the dragons
   * sit on the smaller row centre. The orbs still shrink *below* the cap when
   * the answer column is narrow, so three of them always fit the row the
   * answers occupy instead of spilling over the playfield. */
  #ability-bar { --orb-cap: 44px; --orb-gap: 8px; padding-bottom: 11px; }
  .ability-ornament { top: 22px; }
  .ability-slot-cooldown { font-size: 17px; }
  .ability-slot-readout { font-size: 9px; line-height: 10px; }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  /* Holding a finger down for the hold-to-heal mechanic (see main.js
     'pointerdown' on #game) must not trigger scrolling/pull-to-refresh/
     double-tap-zoom on mobile while the player holds still. */
  touch-action: none;
  /* A sustained press/hold is exactly the gesture browsers use for text
     selection (desktop click-drag) and the long-press selection
     loupe/callout menu (mobile Safari/Chrome). Without suppressing this,
     holding to heal shows a text-selection cursor and can let the native
     selection UI hijack the touch, visually freezing the canvas until the
     finger lifts even though the game loop keeps running underneath. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* The frame and canvas share the exact same playfield bounds. */
#combo-frame {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  pointer-events: none;
  box-sizing: border-box;
  border: 0 solid transparent;
  opacity: 0;
}

#input-zone {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: rgba(5, 5, 20, 0.88);
  z-index: 20;
  box-sizing: border-box;
}

#game-wrap[data-layout="portrait"] #input-zone {
  width: min(100%, var(--answer-portrait-width, 620px));
  justify-self: center;
}

#mc-buttons {
  display: grid;
  width: 100%;
  height: min(100%, calc(var(--answer-rows, 2) * 70px - 6px));
  min-width: 0;
  min-height: 0;
  grid-template-columns: repeat(var(--answer-columns, 5), minmax(var(--answer-min-width, 44px), 1fr));
  grid-template-rows: repeat(var(--answer-rows, 2), minmax(44px, 1fr));
  gap: 6px;
}

/* Portrait encounter swords, injected by encounter-swords.js into #input-zone
 * immediately before #mc-buttons. The module is shared by the website and both
 * apps, so these rules live in the shared stylesheet rather than the app-only
 * overlay.
 *
 * The row only exists in portrait: the default is display:none, so landscape
 * shows nothing and reserves no space on either channel. In portrait the row
 * always owns its full-width 22px flex line, even before the first count
 * arrives, so #mc-buttons never shifts when the swords appear; an empty row is
 * hidden with visibility:hidden rather than display:none. It holds one little
 * sword per enemy; beaten enemies fill green from left to right. Each sword is
 * a clip-path silhouette (tip, blade, cross-guard, grip, pommel), so it scales
 * with the slot and needs no image. Reduced motion drops the fill pop. */
.app-encounter-swords {
  display: none;
  visibility: hidden;
  flex: 0 0 100%;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 22px;
  order: -2; /* first line of the answer zone, above the ability circles */
  margin: 0 calc(var(--safe-area-right, 0px) + 2px) 0 calc(var(--safe-area-left, 0px) + 2px);
  padding: 0 2px;
  pointer-events: none;
  user-select: none;
}

/* Landscape shows the same swords as a vertical column at the left edge of
 * #game-wrap instead (created by encounter-swords.js; no markup). The slots
 * shrink evenly (min size 0) so 30 swords fit a 320px-high window. The column
 * fills its own grid track (--sword-column-width, set by viewport-layout.js)
 * and adds no margin: body already pads #game-wrap by the left safe-area
 * inset, so the track itself sits inside the safe area. */
.app-encounter-swords-column {
  display: none;
}

#game-wrap[data-layout="landscape"] .app-encounter-swords-column {
  display: flex;
  flex-direction: column;
  grid-column: 1;
  grid-row: 1 / -1;
  box-sizing: border-box;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  width: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 2px 0;
  pointer-events: none;
  user-select: none;
  visibility: visible;
}

#game-wrap[data-layout="landscape"] .app-encounter-swords-column[hidden] {
  visibility: hidden;
}

/* In the column the swords lie on their side with the tip towards the hero
 * (to the right, where the scene starts), so each slot is only a blade's width
 * tall: 30 of them stack in a short landscape window at a readable size, and
 * the column itself shrinks to one sword's length (viewport-layout.js). */
#game-wrap[data-layout="landscape"] .app-encounter-swords-column .app-encounter-sword {
  flex: 1 1 0;
  min-height: 0;
  max-height: 9px;
  width: 18px;
}

#game-wrap[data-layout="portrait"] .app-encounter-swords {
  display: flex !important;
}

#game-wrap[data-layout="portrait"] .app-encounter-swords[hidden] {
  visibility: hidden;
}

#game-wrap[data-layout="portrait"] .app-encounter-swords:not([hidden]) {
  visibility: visible;
}

.app-encounter-sword {
  flex: 0 1 12px;
  min-width: 0;
  height: 20px;
}

/* The sword silhouette, declared once: the portrait bar and the difficulty
 * picker icons both draw it. */
.diff-sword::before,
.app-encounter-sword::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  clip-path: polygon(50% 0, 62% 9%, 62% 62%, 90% 62%, 90% 71%, 58% 71%, 58% 88%,
    66% 88%, 66% 100%, 34% 100%, 34% 88%, 42% 88%, 42% 71%, 10% 71%, 10% 62%,
    38% 62%, 38% 9%);
}

.app-encounter-sword::before {
  background: rgba(255, 255, 255, 0.24);
}

.app-encounter-sword--filled {
  filter: drop-shadow(0 0 2px #4caf50);
  animation: ffm-sword-fill 0.35s ease-out;
}

.app-encounter-sword--filled::before {
  background: linear-gradient(180deg, #c8f7c5 0%, #5fd068 45%, #2e8b3a 100%);
}

/* A slot a storm emptied: the space stays in the row, the sword is gone. The
 * silhouette keeps a trace so the gap reads as "taken", not as "never there",
 * but it stays far dimmer than a pending sword (0.24) and the fill sparkles. */
.app-encounter-sword--lost::before {
  background: rgba(255, 255, 255, 0.07);
}

/* The landscape column's swords lie on their side, tip towards the hero. */
#game-wrap[data-layout="landscape"] .app-encounter-swords-column .app-encounter-sword::before {
  /* The upright silhouette turned 90 degrees clockwise: (x, y) -> (100 - y, x). */
  clip-path: polygon(100% 50%, 91% 62%, 38% 62%, 38% 90%, 29% 90%, 29% 58%, 12% 58%,
    12% 66%, 0 66%, 0 34%, 12% 34%, 12% 42%, 29% 42%, 29% 10%, 38% 10%,
    38% 38%, 91% 38%);
}
#game-wrap[data-layout="landscape"] .app-encounter-swords-column .app-encounter-sword--filled::before {
  /* The bright end of the fill stays at the tip. */
  background: linear-gradient(270deg, #c8f7c5 0%, #5fd068 45%, #2e8b3a 100%);
}

@keyframes ffm-sword-fill {
  0% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .app-encounter-sword--filled { animation: none; }
}

.mc-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 4px;
  background: #1a1a3a;
  color: #f0f0f0;
  border: 2px solid #4040a0;
  cursor: pointer;
  font-size: clamp(18px, 2.5vw, 24px);
  white-space: nowrap;
  font-family: monospace;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mc-btn:hover {
  background: #2a2a5a;
}

.mc-btn:focus {
  outline: 3px solid #fff;
  outline-offset: -5px;
}

#btn-pause-game:focus-visible { outline: 3px solid #fff; outline-offset: -5px; }

#free-text-zone {
  display: none;
  gap: 8px;
  align-items: center;
}

#answer-input {
  background: #1a1a3a;
  color: #f0f0f0;
  border: 2px solid #4040a0;
  padding: 8px;
  font-size: 18px;
  font-family: monospace;
  width: 120px;
}

#answer-input:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
  border-color: #6060d0;
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}

#strike-btn {
  background: #4040c0;
  color: white;
  padding: 8px 16px;
  min-height: 44px;
  border: none;
  cursor: pointer;
  font-family: monospace;
  font-size: 16px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#strike-btn:hover {
  background: #5050d0;
}

#strike-btn:focus {
  outline: 2px solid #8080e0;
  outline-offset: 2px;
}

/* Menu typography defaults. :where() keeps these at zero specificity, so any
 * deliberate rule still overrides them; these only fill in what a rule leaves
 * unset, and they are the reason the menus share one scale. */
:where(.overlay) {
  font-family: var(--font-prose);
  font-size: var(--text-body);
  line-height: var(--line-body);
  color: var(--ivory-muted);
}
:where(.overlay) :where(button, summary, select) {
  font-family: var(--font-ui);
  font-size: var(--text-button);
  font-weight: 400;
}
:where(.overlay) :where(h2, h3) {
  font-family: var(--font-prose);
  font-size: var(--text-heading);
  font-weight: 700;
  line-height: 1.25;
  color: var(--ivory);
}
/* Subtitles inside a dialog are one step below its title. */
:where(.overlay) :where(h3) { font-size: var(--text-subheading); }
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* ── Loading screen ───────────────────────────────────────────────────────
   Fully opaque black, above every other overlay (including the splash
   screen, z-index 100), shown from first paint until asset-preload.js
   finishes fetching every sprite the game can show. This replaces the old
   behavior where each sprite's procedural pixel-art fallback (see
   entities.js's `.complete`/`.naturalWidth` checks) rendered first and got
   replaced by the real PNG whenever it finished downloading — visible as a
   flicker of "wrong" placeholder art on a slow connection. */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.loading-title {
  color: #f0f0f0;
  font-family: monospace;
  font-size: clamp(20px, 5vw, 28px);
  margin: 0 0 8px 0;
  letter-spacing: 2px;
}

.loading-bar-track {
  width: min(80vw, 360px);
  height: 18px;
  border: 2px solid #6060d0;
  background: #1a1a3a;
  box-sizing: border-box;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: #30f060;
  transition: width 0.15s ease-out;
}

.loading-percent {
  color: #d0d0d0;
  font-family: monospace;
  font-size: 14px;
  margin: 0;
}

/* ── Splash screen ────────────────────────────────────── */
.splash-screen {
  background: #0a0a1a;
  flex-direction: column;
  justify-content: flex-start;
  overflow-y: hidden;
  overflow-x: hidden;
  overscroll-behavior: contain;
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  padding-top: max(18px, env(safe-area-inset-top));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.splash-bg {
  position: absolute;
  inset: 0;
  background: url('game/splash-bg.webp') center center / cover no-repeat;
  background-position: center center;
  filter: brightness(0.55) saturate(1.1);
  transform: scale(1.05);
}

.splash-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vw, 18px);
  padding: clamp(18px, 4vw, 30px) clamp(14px, 3vw, 22px);
  max-width: none;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
  flex-shrink: 1;
  margin: 0 auto;
}

.splash-title {
  font-family: monospace;
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffe080;
  text-shadow:
    0 0 12px #ff9000,
    0 0 28px #ff4400,
    2px 3px 0 #000;
  margin: 0;
  line-height: 1.1;
}

.splash-intro {
  margin: 0;
  color: #dfe8ff;
  text-shadow: 1px 1px 4px #000;
  max-width: 36ch;
}

.splash-login-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.splash-greeting {
  color: #a0e0a0;
}

.splash-subtitle {
  color: #c0c0e0;
  margin: 0;
  text-shadow: 1px 1px 4px #000;
}

.splash-leaderboard {
  width: 100%;
  max-width: none;
  background: rgba(10, 10, 40, 0.82);
  border: 2px solid #6060c0;
  padding: 10px 12px;
  box-sizing: border-box;
}

.leaderboard-header {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.leaderboard-title {
  margin: 0;
  color: #f0f0ff;
}

.leaderboard-filter {
  background: #2a2a5a;
  color: #f0f0f0;
  border: 1px solid #6060d0;
}

.leaderboard-note {
  margin: 0 0 8px 0;
  color: #c8d2ff;
}

.leaderboard-list {
  margin: 0;
  padding-left: 20px;
  max-height: none;
  overflow: visible;
}

.leaderboard-list li {
  margin-bottom: 4px;
  color: #d0d0f0;
}

.leaderboard-list li.current-user {
  color: #a0f0a0;
  font-weight: bold;
}

.leaderboard-profile-prompt {
  color: #f0d080;
  margin: 0 0 8px 0;
}

.leaderboard-personal-best {
  color: #a0f0a0;
  margin: 0 0 8px 0;
}

.score-history-chart {
  margin: 4px 0 8px;
}

#leaderboard-complete-profile {
  width: 100%;
  margin-bottom: 8px;
}

.splash-diff-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.splash-btn {
  padding: 8px 20px;
  cursor: pointer;
  border: 2px solid;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.splash-btn--secondary {
  background: rgba(20, 20, 60, 0.85);
  color: #a0c0ff;
  border-color: #4060c0;
}

.splash-btn--secondary:hover {
  background: rgba(40, 40, 100, 0.9);
}

.splash-btn:focus {
  outline: 2px solid #8080e0;
  outline-offset: 2px;
}

.splash-diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(10, 10, 40, 0.82);
  backdrop-filter: blur(4px);
  border-color: #6060c0;
  padding: 12px 16px;
  text-shadow: 1px 1px 3px #000;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.splash-diff-btn:hover {
  background: rgba(40, 40, 90, 0.92);
  border-color: #9090f0;
  transform: scale(1.02);
}

.diff-label {
  font-weight: 400;
  color: var(--ivory);
}

.diff-detail {
  color: #9090c0;
}

[data-difficulty="easy"] .diff-label  { color: #80f080; }
[data-difficulty="easy"]              { border-color: #408040; }
[data-difficulty="easy"]:hover        { border-color: #60c060; }

[data-difficulty="hard"] .diff-label  { color: #ff8080; }
[data-difficulty="hard"]              { border-color: #803030; }
[data-difficulty="hard"]:hover        { border-color: #d06060; }

.overlay-card {
  background: #1a1a3a;
  border: 2px solid #4040a0;
  padding: 32px;
  box-sizing: border-box;
  width: calc(100% - 32px);
  max-width: none;
  max-height: 100%;
  overflow-y: hidden;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
  position: relative;
}

.overlay-card h2 {
  margin: 0 0 16px 0;
  color: #f0f0f0;
}

.overlay-card p {
  margin: 0 0 16px 0;
  color: #d0d0d0;
}

.diff-btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px;
  background: #2a2a5a;
  color: #f0f0f0;
  border: 2px solid #6060d0;
  cursor: pointer;
  /* No font here: dialog buttons take the shared button face and size from the
   * :where(.overlay) defaults, so a pause or result button reads like every
   * other menu button. The difficulty options set their own (.splash-diff-btn). */
}

.diff-btn:hover {
  background: #3a3a6a;
}

.diff-btn:focus {
  outline: 2px solid #8080e0;
  outline-offset: 2px;
}

#btn-next-level {
  border-color: #60d060;
  color: #c0f0c0;
}

#btn-next-level:hover {
  background: #2a4a2a;
}

#btn-replay-level {
  border-color: #d0a040;
  color: #f0e0a0;
}

#btn-replay-level:hover {
  background: #3a3020;
}

#btn-retry-level {
  border-color: #d0a040;
  color: #f0e0a0;
}

#btn-retry-level:hover {
  background: #3a3020;
}

#btn-return-title {
  border-color: #60a0d0;
  color: #c0e8ff;
}

#btn-return-title:hover {
  background: #20384a;
}

#top-bar {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 200;
  display: flex;
  gap: 8px;
}

#top-bar.behind-modal {
  z-index: 99;
  pointer-events: none;
}

/* A dialog whose text and actions the bar cannot change (title-bar.js). */
#top-bar.behind-dialog { visibility: hidden; }

#top-bar button,
#top-bar span {
  background: #1a1a3a;
  color: #f0f0f0;
  border: 2px solid #4040a0;
  padding: 8px 12px;
  cursor: pointer;
  font-family: monospace;
  font-size: 14px;
}

#top-bar button:hover {
  background: #2a2a5a;
}

#top-bar button:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

#username-display {
  cursor: pointer;
  padding: 8px 16px;
}

#close-auth {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: #f0f0f0;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
}

#close-auth:hover {
  color: #ff6060;
}

#close-auth:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

.close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: #f0f0f0;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
}

.close-btn:hover {
  color: #ff6060;
}

.close-btn:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

#auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#account-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

#account-tabs .tab-btn {
  flex: 1 1 110px;
  min-width: 0;
  overflow-wrap: anywhere;
}

#account-modal form input {
  min-width: 0;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  background: #2a2a5a;
  color: #a0a0a0;
  border: 2px solid #4040a0;
  cursor: pointer;
}

.tab-btn.active {
  background: #4040a0;
  color: #f0f0f0;
  border-color: #6060d0;
}

.tab-btn:hover {
  background: #3a3a6a;
}

.tab-btn:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

form input {
  background: #2a2a5a;
  color: #f0f0f0;
  border: 2px solid #4040a0;
  padding: 8px;
  font-size: 14px;
  font-family: monospace;
}

form input:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
  border-color: #6060d0;
}

.turnstile-container {
  margin: 4px 0;
}

form button {
  background: #4040c0;
  color: white;
  padding: 10px;
  border: none;
  cursor: pointer;
}

form button:hover {
  background: #5050d0;
}

form button:focus {
  outline: 2px solid #8080e0;
  outline-offset: 2px;
}

.error-msg {
  color: #ff6060;
  font-size: 12px;
  margin: 0;
  min-height: 16px;
}

.success-msg {
  color: #a0f0a0;
}

.pending-email-note {
  color: #f0d080;
  font-size: 12px;
  margin: 0 0 8px 0;
}

.danger-warning {
  color: #ff8080;
  margin: 0 0 4px 0;
}

.danger-confirm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d0d0d0;
  cursor: pointer;
}

.danger-btn {
  background: #a02020;
}

.danger-btn:hover {
  background: #c03030;
}

.danger-btn:disabled {
  background: #4a2a2a;
  color: #a08080;
  cursor: not-allowed;
}

.link-btn {
  background: transparent;
  border: none;
  color: #8080e0;
  text-decoration: underline;
  cursor: pointer;
  font-family: monospace;
  font-size: 12px;
  padding: 0;
  align-self: flex-start;
}

.link-btn:hover {
  color: #a0a0ff;
}

.link-btn:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

#login-verify-resend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

/* ── Legal links (splash footer) ─────────────────────────────── */
.splash-legal-links {
  margin: 0;
  color: #8080a0;
  text-align: center;
}

.splash-legal-links a {
  color: #a0c0ff;
  text-decoration: underline;
}

.splash-legal-links a:hover {
  color: #d0e0ff;
}

.splash-legal-link-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: #a0c0ff;
  text-decoration: underline;
  cursor: pointer;
}

.splash-legal-link-btn:hover {
  color: #d0e0ff;
}

/* ── Consent checkbox (registration form) ──────────────────── */
.consent-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 12px 0;
  font-family: monospace;
  font-size: 12px;
  line-height: 1.4;
  color: #c0c0e0;
  cursor: pointer;
}

.consent-checkbox input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #8080e0;
}

.consent-checkbox input[type="checkbox"]:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

/* ── Cookie banner (fixed, bottom) ───────────────────────────── */
#cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: max(16px, env(safe-area-inset-bottom));
  padding-top: 16px;
  background: rgba(10, 10, 40, 0.95);
  border-top: 1px solid #6060c0;
  z-index: 150;
  display: flex;
  justify-content: center;
  box-sizing: border-box;
}

.cookie-banner-content {
  max-width: 500px;
  color: #dfe8ff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.cookie-banner-content p {
  margin: 0;
  line-height: 1.4;
}

.cookie-banner-content a {
  color: #a0c0ff;
  text-decoration: underline;
}

.cookie-banner-content a:hover {
  color: #d0e0ff;
}

.cookie-banner-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.cookie-btn {
  padding: 6px 12px;
  border: 1px solid #6060c0;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.cookie-btn--accept {
  background: #4040c0;
  color: white;
}

.cookie-btn--accept:hover {
  background: #5050d0;
}

.cookie-btn--accept:focus {
  outline: 2px solid #8080e0;
  outline-offset: 2px;
}

.cookie-btn--decline {
  background: transparent;
  color: #a0c0ff;
}

.cookie-btn--decline:hover {
  background: rgba(80, 80, 160, 0.3);
  color: #d0e0ff;
}

.cookie-btn--decline:focus {
  outline: 2px solid #6060d0;
  outline-offset: 2px;
}

/* ── Billing UI ──────────────────────────────────────────── */
#billing-status-display {
  padding: 12px;
  text-align: center;
  color: #a0a0a0;
}

#billing-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#billing-status-text {
  text-align: center;
  color: #d0d0d0;
  margin: 0;
}

#btn-open-portal,
#btn-start-checkout {
  width: 100%;
}

#billing-redeem-section {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

#billing-redeem-code {
  flex: 1;
  padding: 8px;
  background: #1a1a3a;
  border: 1px solid #6060c0;
  color: #f0f0f0;
  font-family: monospace;
  border-radius: 4px;
}

#billing-redeem-code:focus {
  outline: none;
  border-color: #a0a0ff;
  box-shadow: 0 0 8px rgba(160, 160, 255, 0.3);
}

#btn-redeem-code {
  padding: 8px 16px;
  background: #404080;
  border: 1px solid #6060c0;
  color: #f0f0f0;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
}

#btn-redeem-code:hover {
  background: #505090;
  border-color: #a0a0ff;
}

.billing-disclosure {
  font-size: 12px;
  color: #a0a0a0;
  margin-top: 12px;
  text-align: center;
  line-height: 1.4;
}

.billing-disclosure a {
  color: #a0c0ff;
  text-decoration: underline;
}

#checkout-modal {
  display: none;
}

#checkout-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#checkout-form button[type="submit"] {
  margin-top: 12px;
}

/* ── Legal pages (impressum, datenschutz) ──────────────────── */
/* The game's global `html`/`body` rules (top of this file) fix the
   viewport to exactly 100% with overflow:hidden and center a fixed-size
   canvas — perfect for the game screen, but it also silently applied to
   these plain-scrolling document pages, clipping content top/bottom with
   no way to scroll and vertically centering it instead of starting at
   the top. `body.legal-body` (set on these pages only) overrides that. */
body.legal-body {
  display: block;
  align-items: initial;
  justify-content: initial;
  /* Match html's fixed 100% height (not auto/min-height) so this element
     is itself a bounded scroll container — its own overflow-y:auto only
     takes effect on a constrained box, and html above still has
     overflow:hidden from the game rules, so this is what actually makes
     the page scrollable rather than clipped. */
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

html:has(body.legal-body) {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
}

.legal-page {
  background: #0a0a1a;
  color: #f0f0f0;
  font-family: monospace;
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
}

.legal-content {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.6;
}

.legal-content h1 {
  font-size: 28px;
  margin: 24px 0 16px;
  color: #ffe080;
}

.legal-content h2 {
  font-size: 18px;
  margin: 20px 0 12px;
  color: #c0c0e0;
}

.legal-content p {
  margin: 12px 0;
  font-size: 14px;
}

.legal-content ul, .legal-content ol {
  margin: 12px 0;
  padding-left: 24px;
  font-size: 14px;
}

.legal-content li {
  margin: 6px 0;
}

.legal-content a {
  color: #a0c0ff;
  text-decoration: underline;
}

.legal-content a:hover {
  color: #d0e0ff;
}

.legal-content hr {
  border: none;
  border-top: 1px solid #6060c0;
  margin: 24px 0;
}

.legal-footer-nav {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid #6060c0;
  text-align: center;
  font-size: 12px;
}

.legal-footer-nav a {
  margin: 0 8px;
}

/* The visible viewport, not the layout viewport, also contains keyboard UI. */
:root {
  --viewport-width: 100vw;
  --viewport-height: 100dvh;
  --viewport-left: 0px;
  --viewport-top: 0px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
}

[hidden] { display: none !important; }

body:not(.legal-body) {
  position: fixed;
  left: var(--viewport-left);
  top: var(--viewport-top);
  width: var(--viewport-width);
  height: var(--viewport-height);
  box-sizing: border-box;
  padding: calc(var(--safe-area-top) + 60px)
    calc(var(--safe-area-right) + 8px)
    calc(var(--safe-area-bottom) + 8px)
    calc(var(--safe-area-left) + 8px);
}

body[data-gameplay="true"]:not(.legal-body) {
  padding-top: calc(var(--safe-area-top) + 8px);
}
body[data-gameplay="true"] #top-bar { display: none; }

button, input, select, .splash-legal-links a {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
}

/* Interface words stay intact and sentences wrap at spaces. `break-word` is the
 * safety net only: a single word wider than its button (a long German label on
 * a 320px phone) wraps inside the border instead of spilling over the edge. */
button { overflow-wrap: break-word; word-break: normal; hyphens: none; }

.overlay, #loading-overlay {
  /* --viewport-* follows the visual viewport: an on-screen keyboard shrinks it
     and the dialog should shrink with it. But a zoomed-out visual viewport
     reports a larger area than the screen, and sizing a dialog from it blew
     every overlay up until its actions were out of reach. Clamp the box to the
     layout viewport and keep the visual offsets inside it, so a dialog is
     always on screen - over the keyboard case, which still wins. */
  --overlay-width: min(var(--viewport-width, 100vw), 100vw);
  --overlay-height: min(var(--viewport-height, 100vh), 100vh);
  left: max(0px, min(var(--viewport-left, 0px), calc(100vw - var(--overlay-width))));
  top: max(0px, min(var(--viewport-top, 0px), calc(100vh - var(--overlay-height))));
  width: var(--overlay-width);
  height: var(--overlay-height);
  box-sizing: border-box;
  padding: calc(var(--safe-area-top) + 8px)
    calc(var(--safe-area-right) + 8px)
    calc(var(--safe-area-bottom) + 8px)
    calc(var(--safe-area-left) + 8px);
  overflow: hidden;
}

.overlay-card {
  width: 100%;
  max-width: none;
  max-height: 100%;
  padding: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.overlay-card h2 {
  margin: 0;
}

.overlay-card p { margin: 0; line-height: 1.35; }

/* Running text in dialogs and panels reads left-aligned, inset from the card
 * edge, and keeps air before the action that ends the passage. Centred copy is
 * reserved for the welcome text, headings and one-line labels (a player name,
 * the "choose your difficulty" prompt). The Players page's purchase panel is
 * centred too: it is a status card of short lines under the centred player
 * list, not a passage (mobile-ui.css). */
:is(.overlay-card, .paywall-card, .parental-gate-card,
    .practice-controls, .app-help-card, .first-open-notice-card) p:not(.player-identity),
:is(.overlay-card, .paywall-card, .parental-gate-card,
    .practice-controls, .app-help-card, .first-open-notice-card) :is(ul, ol) {
  text-align: left;
  padding-inline: 8px;
  margin-block-end: 8px;
}
#level-clear .overlay-card, #game-over .overlay-card { overflow-y: auto; }
#level-clear .overlay-card > *, #game-over .overlay-card > * { flex-shrink: 0; }
/* The web account dialog scrolls as one card: its Profile tab (email form, campaign switch,
 * hero picker) is taller than a phone screen held sideways, and a short window or the phone
 * frame (phone-frame.js) must not cut its lower half off unreachably. The panels keep their
 * height instead of being squeezed. */
#account-modal .overlay-card { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#account-modal .overlay-card > * { flex-shrink: 0; }
#level-attempt-summary, #defeat-attempt-summary { white-space: pre-line; overflow-wrap: normal; }
#level-attempt-summary:empty, #defeat-attempt-summary:empty { display: none; }
/* Next-scene preview: the upcoming level's art above its title. The inline
   display:none in the markup keeps it out of the first paint and the renderer
   reveals it once a level is cleared. */
#level-clear-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 1px solid rgba(196, 154, 72, 0.55);
  border-radius: 6px;
  background: rgba(9, 20, 17, 0.55);
}
#level-clear-preview-image {
  display: block;
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: 4px;
}
#level-clear-preview-title { margin: 0; font-size: 0.9em; text-align: center; color: var(--ivory-muted); }
.overlay-card .diff-btn { margin: 0; padding: 6px; }
/* The first-open thank-you notice sits above the app top bar (z-index 200) so
   no edge of the game frame floats over the dialog, and its card scrolls
   instead of clipping the continue button on short screens or large text.
   It is sized from the layout viewport, never from --viewport-*: those follow
   the visual viewport (pinch or double-tap zoom, the iOS URL bar), and a
   zoomed-out value would blow the dialog up and push its action off the
   screen, leaving no way out. */
#first-open-notice {
  z-index: 900;
  inset: 0;
  width: auto;
  height: auto;
  /* A little air between the card and the screen edges, on top of the safe area. */
  padding: calc(var(--safe-area-top) + 16px)
    calc(var(--safe-area-right) + 16px)
    calc(var(--safe-area-bottom) + 16px)
    calc(var(--safe-area-left) + 16px);
}
.first-open-notice-card {
  overflow-y: auto;
  padding: clamp(16px, 5vw, 28px);
  gap: 10px;
}
.first-open-notice-card > * { flex-shrink: 0; }
/* Centred copy with a little air above the single action: a calm note rather
   than a wall of left-aligned text. */
.first-open-notice-card p { text-align: left; }
.first-open-notice-card [data-notice-action="continue"] {
  margin-top: 10px;
  /* No double-tap zoom on the one action that closes the dialog. */
  touch-action: manipulation;
}
/* Pause actions wrap into equal-width rows: every button in a row shares one
   width, and a short last row stretches its button to the full row instead of
   leaving a gap (the save button is hidden for guests, practice and shapes). */
#pause-actions, #pause-quit-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#pause-actions > button, #pause-quit-actions > button { flex: 1 1 220px; }
#pause-quit-actions > p { flex: 1 1 100%; }
.screen-actions, .paywall-actions { display: grid; gap: 6px; }
.parental-gate-form { min-width: 0; gap: 6px; }
.parental-gate-actions { display: flex; gap: 6px; }
.parental-gate-actions button { flex: 1; min-width: 44px; }
.parental-gate-form input { width: 100%; min-width: 0; }
.screen-status, .profile-status, .paywall-status, .gate-status {
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.25;
  margin: 0;
}
.screen-status:empty, .profile-status:empty, .paywall-status:empty,
.gate-status:empty, #pause-save-error:empty, #pause-save-notice:empty { display: none; }

/* The title bar is right-anchored and grows leftwards, so the number of
   utility buttons (app: replay/mute/language, web: replay/login/mute/
   language) never pushes it off the right edge. */
#top-bar {
  top: calc(var(--viewport-top) + var(--safe-area-top) + 8px);
  left: auto;
  right: calc(100vw - var(--viewport-left) - var(--viewport-width) + var(--safe-area-right) + 8px);
  gap: 6px;
}
#top-bar button, #top-bar span { padding: 4px 8px; }
/* Round control that replays the prologue diorama (see ../story/), first in the
   title bar so it sits left of Login. The art is a brass dragon curled into a
   circular arrow (game/intro-replay.webp), so the button is only the 44px frame
   it sits in. Two IDs keep it clear of the `#top-bar button` box rules. */
#top-bar #btn-replay-intro {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(9, 20, 17, 0.55), rgba(9, 20, 17, 0) 72%);
  cursor: pointer;
  touch-action: manipulation;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}
.intro-replay-icon { display: block; width: 100%; height: 100%; object-fit: contain; }
#top-bar #btn-replay-intro:hover {
  background: radial-gradient(circle, rgba(32, 70, 58, 0.8), rgba(9, 20, 17, 0) 72%);
}
#top-bar #btn-replay-intro:hover .intro-replay-icon { filter: brightness(1.15); }
#top-bar #btn-replay-intro:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
#username-display { display: flex; align-items: center; justify-content: center; }

.splash-screen { justify-content: center; overflow: hidden; }
.splash-bg { transform: none; }
.splash-content {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 0;
  margin: 0;
  flex-shrink: 1;
  display: grid;
  /* The old flex rule's justify-content: center still applies to this grid and
   * would shrink the implicit column to each page's content, so the app's menu
   * pages were narrower than the play page. Both platforms fill the band now. */
  grid-template-columns: minmax(0, 1fr);
  justify-content: stretch;
  grid-template-rows: 88px minmax(0, 1fr) minmax(44px, auto);
  gap: 6px;
}
.splash-title {
  justify-self: center;
  align-self: end;
  text-align: center;
  font-size: clamp(16px, 4vw, 32px);
  letter-spacing: 0;
  padding-right: 0;
}
.title-logo {
  display: block;
  width: auto;
  height: 44px;
  max-width: 100%;
  object-fit: contain;
}
@media (orientation: portrait) {
  .splash-content { grid-template-rows: 112px minmax(0, 1fr) minmax(44px, auto); }
  .title-logo { height: 64px; }
}
@media (orientation: portrait) and (min-width: 380px) and (min-height: 700px) {
  .splash-content { grid-template-rows: 184px minmax(0, 1fr) minmax(44px, auto); }
  .title-logo { height: 136px; }
}
.title-pages, .title-page, #profile-root, .profile-ui {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.title-pages { display: grid; }
.title-page { display: flex; flex-direction: column; gap: 6px; }
/* Every title page except Play is one menu sheet: a single framed surface that
 * fills the band when its content needs the room and shrinks to a centred card
 * when it does not. The sheet itself is the scroll container, so a long
 * leaderboard scrolls to its pagination instead of clipping, and every menu
 * page scrolls the same way instead of each nested list deciding on its own.
 * Play keeps its own split layout below. */
.title-page:not(.title-play) {
  height: auto;
  max-height: 100%;
  align-self: center;
  justify-self: center;
  width: min(100%, 640px);
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--brass-deep);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(33, 65, 53, 0.94), rgba(13, 30, 24, 0.96));
  box-shadow: inset 0 1px 0 rgba(243, 234, 214, 0.08), 0 8px 24px rgba(0, 0, 0, 0.38);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* The sheet already draws the frame, so a list card inside it drops its own. */
.title-page:not(.title-play) .splash-leaderboard {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}
.title-play { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.title-play-intro { display: grid; align-content: center; justify-items: center; gap: 6px; min-width: 0; }
.splash-intro { max-width: none; }
.splash-login-row { flex-direction: row; gap: 6px; }
.splash-login-row .splash-btn { flex: none; }
.splash-greeting { min-width: 0; overflow-wrap: break-word; text-align: center; }
.splash-diff-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(88px, 128px));
  gap: 6px;
  width: 100%;
  min-height: 0;
  align-self: center;
  align-content: center;
}
.splash-diff-btn {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 4px;
  justify-content: center;
  /* The difficulty options are cards of prose (name and rules), not menu buttons. */
  font-family: var(--font-prose);
}
.diff-label { font-size: var(--text-option); }
/* .splash-diff-btn sets display:flex, which would beat the hidden attribute (Shapes is hidden in Genius). */
.splash-diff-btn[hidden] { display: none; }
.diff-detail { display: block; font-size: var(--text-body); color: var(--ivory-muted); }
/* Web only: the two store listings are announced before they are live, so the
 * row is a quiet badge pair, not a call to action. The app build omits it. */
.splash-store-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.splash-store-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid rgba(196, 154, 72, 0.45);
  border-radius: 999px;
  background: rgba(9, 20, 17, 0.45);
  color: var(--ivory-muted);
  text-align: left;
}
/* Not in the stores yet: a dashed outline says "announced, not available".
 * A live listing drops the modifier and becomes a solid link chip. */
.splash-store-badge.store-badge--pending { border-style: dashed; }
.splash-store-icon { flex: 0 0 auto; width: 18px; height: 18px; }
/* Phones: both badges stay on one line only with the smaller chip metrics. */
@media (max-width: 420px) {
  .splash-store-badge {
    gap: 4px;
    min-height: 28px;
    padding: 3px 8px;
  }
  .splash-store-icon { width: 16px; height: 16px; }
}
.player-identity { margin: 0; overflow-wrap: anywhere; }
.playing-as-row { display: flex; align-items: center; gap: 6px; min-width: 0; width: 100%; }
.playing-as-row .player-identity { flex: 1; min-width: 0; }
.playing-as-row button {
  background: #1a1a3a;
  color: #dfe8ff;
  border: 2px solid #6060c0;
  padding: 4px;
}
#continue-level { margin: 0; }
#continue-level:empty { display: none; }
.title-level-numerals {
  --numeral-height: 44px;
  --numeral-width: calc(var(--numeral-height) * (var(--level-numeral-digits, 1) * 30 + 22) / 86);
  position: absolute;
  top: calc(var(--safe-area-top, env(safe-area-inset-top, 0px)) + 8px);
  left: calc(var(--safe-area-left, env(safe-area-inset-left, 0px)) + 8px);
  z-index: 3;
  /* Same 44px height as the title-bar controls and the player badge. */
  height: var(--numeral-height);
  width: var(--numeral-width);
  /* Clickable on purpose: three taps here open the speedrun card (see
     speedrun-ui.js), and this numeral is the level display the title screen
     always shows — the intro sentence under it is hidden on small phones. */
  pointer-events: auto;
  user-select: none;
  filter: drop-shadow(0 2px 3px #070e0b);
}
.title-level-numerals svg { display: block; width: 100%; height: 100%; }
.title-level-numerals[hidden] { display: none; }
/* The player's hero portrait sits right of the level numerals and opens the hero picker (web) or Players page (app). */
.title-player-badge {
  position: absolute;
  top: calc(var(--safe-area-top, env(safe-area-inset-top, 0px)) + 8px);
  left: calc(var(--safe-area-left, env(safe-area-inset-left, 0px)) + 16px + 44px * (var(--level-numeral-digits, 1) * 30 + 22) / 86);
  z-index: 3;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--brass, #b8923a);
  border-radius: 50%;
  background: rgba(9, 20, 17, 0.7);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  filter: drop-shadow(0 2px 3px #070e0b);
}
.title-player-badge[hidden] { display: none; }
.title-player-badge .hero-identity-portrait { display: block; width: 100%; height: 100%; margin: 0; border-radius: 0; object-fit: cover; }
.title-player-badge:focus-visible { outline: 3px solid var(--focus-ring, #fff0bd); outline-offset: 2px; }
/* Tabs take the width their label needs and wrap onto a second row when six
 * of them (plus help) do not fit. A pressed tab is bold and therefore wider, so
 * a fixed six-column grid used to clip "Training" on 320px phones. */
.title-navigation {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
}
.title-navigation button { flex: 1 1 auto; min-width: 44px; }
.title-navigation button, .screen-pagination button,
.profile-ui button, .title-page > button {
  background: #1a1a3a;
  color: #dfe8ff;
  border: 2px solid #6060c0;
  padding: 4px;
  touch-action: manipulation;
}
.title-navigation button[aria-pressed="true"] {
  background: #394a8c;
  border-color: #e2eaff;
  color: var(--ivory);
  font-weight: 700;
}
.screen-pagination, .profile-pagination, .profile-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  flex-shrink: 0;
}
.screen-pagination { margin-top: auto; }
/* Paging controls draw a small brass triangle instead of showing a glyph, so
 * the direction reads at a glance and in every language. The triangle is an
 * empty pseudo-element: the button's spoken label stays "Previous page" /
 * "Next page" and its text content stays empty. */
.screen-pagination button, .profile-pagination button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
:is(.screen-pagination, .profile-pagination) button[data-page-direction]::before {
  content: '';
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}
:is(.screen-pagination, .profile-pagination) button[data-page-direction="previous"]::before {
  border-right: 7px solid var(--brass-light);
}
:is(.screen-pagination, .profile-pagination) button[data-page-direction="next"]::before {
  border-left: 7px solid var(--brass-light);
}
:is(.screen-pagination, .profile-pagination) button[data-page-direction]:disabled::before {
  opacity: 0.4;
}
.splash-leaderboard {
  max-width: none;
  padding: 6px;
  min-height: 0;
  flex: 0 0 auto;
  display: grid;
  align-content: start;
  gap: 6px;
}
.leaderboard-header { flex-direction: row; margin: 0; min-width: 0; }
.leaderboard-filter { width: auto; min-width: 44px; flex: 1; }
/* The menu sheet scrolls, so the list must not clip its own rows: an eighth
   place used to be cut off silently instead of extending the page. */
.leaderboard-list {
  max-height: none;
  margin: 0;
  padding-left: 24px;
  overflow: visible;
}
.leaderboard-list li { padding: 4px; overflow-wrap: anywhere; }
.leaderboard-list li:last-child { margin-bottom: 0; }
.title-page[data-title-page="history"] { justify-content: center; }
.title-page[data-title-page="history"] .score-history-chart {
  margin: 0;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.title-page[data-title-page="history"] .score-history-chart svg {
  flex: 1;
  min-height: 0;
}
.leaderboard-note, .leaderboard-personal-best { margin: 0; }
.score-history-chart { min-height: 0; max-height: 100%; }
.score-history-chart svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 180px;
  background: rgba(6, 18, 13, 0.9);
  border-radius: 6px;
}
.score-history-chart .score-history-summary {
  margin: 6px 0;
  color: var(--ivory);
  text-align: center;
  flex-shrink: 0;
}
.title-page[data-title-page="levels"] { align-items: center; }
.level-jump-row {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  gap: 6px;
}
.level-jump-label { margin: 0; color: var(--ivory); text-align: center; text-shadow: 1px 1px 4px #000, 0 0 6px #000; }
.level-jump-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  grid-auto-rows: 56px;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px;
  border-radius: 6px;
  background: rgba(6, 18, 13, 0.84);
}
.level-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 9px;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
.level-tile svg { display: block; width: auto; height: 100%; max-width: 100%; }
.level-tile[data-state="default"] { border-color: rgba(95, 208, 104, 0.55); }
.level-tile:hover:not(:disabled) svg { filter: drop-shadow(0 0 4px rgba(228, 197, 119, 0.7)); }
.level-tile[aria-pressed="true"] {
  border-color: var(--brass-light);
  box-shadow: 0 0 10px rgba(228, 197, 119, 0.65);
}
.level-tile:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 1px; }
.level-tile:disabled { cursor: default; opacity: 0.32; filter: grayscale(1); }

.profile-ui { display: flex; flex-direction: column; gap: 6px; }
.profile-list { display: grid; gap: 6px; min-height: 0; }
.profile-row { display: flex; gap: 4px; min-height: 44px; min-width: 0; }
.profile-select { flex: 1; min-width: 44px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-row button[aria-pressed="true"] { border-color: #80f080; }
.profile-form, .profile-confirmation { display: grid; gap: 6px; min-height: 0; align-content: center; flex: 1; }
.profile-form label { display: grid; gap: 4px; min-width: 0; }
.profile-name-input { width: 100%; min-width: 0; font-size: 16px; }
.parental-gate-form input { font-size: 16px; }
.profile-actions { flex-wrap: nowrap; }
.profile-status { color: #ffe080; }
.profile-status.error-msg { color: #ff8080; }

/* Web only: .splash-content still carries the old flex rule's
 * justify-content: center, which shrinks its implicit grid column to each
 * page's content. Give every title page the same centred width instead. */
:root[data-platform="web"] .splash-content {
  grid-template-columns: minmax(0, 1fr);
  justify-content: stretch;
}
:root[data-platform="web"] .title-pages,
:root[data-platform="web"] .title-navigation {
  width: min(100%, 560px);
  justify-self: center;
  box-sizing: border-box;
}

/* Legal text is deliberately the sole scrollable title page. */
.title-legal { overflow-y: auto; overscroll-behavior: contain; }

/* Web build: the Terms tab mirrors the app's legal navigation — a vertical
 * stack of forest/brass chips instead of a faint inline link row. The app
 * gets the same look from its runtime overlay (mobile/game/mobile-ui.css),
 * so these rules stay web-only. */
:root[data-platform="web"] .splash-legal-links {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin: 0;
  width: min(100%, 560px);
  align-self: center;
  font-size: var(--text-button);
  color: var(--ivory-muted);
}
:root[data-platform="web"] .splash-legal-links a,
:root[data-platform="web"] .splash-legal-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--brass-deep);
  border-radius: 5px;
  background: linear-gradient(145deg, #203e32, #10241c);
  color: var(--ivory);
  text-decoration: none;
  cursor: pointer;
}
:root[data-platform="web"] .splash-legal-links a:hover,
:root[data-platform="web"] .splash-legal-link-btn:hover {
  border-color: var(--brass-light);
  color: var(--focus-ring);
  background: linear-gradient(145deg, #315641, #19372b);
}
:root[data-platform="web"] .splash-legal-links a:focus-visible,
:root[data-platform="web"] .splash-legal-link-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
.legal-body button, .legal-body input, .legal-body select { min-height: 44px; }

/* Keyboard editing is its own stage; form save/cancel remain available. */
:root[data-viewport-keyboard="true"] .splash-content {
  grid-template-rows: minmax(0, 1fr);
}
:root[data-viewport-keyboard="true"] .splash-title,
:root[data-viewport-keyboard="true"] .title-navigation { display: none; }
/* main.js sets the bar's display inline for gameplay and menu screens, so the
   keyboard stage has to override it explicitly: with the keyboard open the page
   moves up under the bar and its mute/language buttons covered the form. */
:root[data-viewport-keyboard="true"] #top-bar { display: none !important; }
:root[data-viewport-keyboard="true"] body:not(.legal-body) {
  padding-top: calc(var(--safe-area-top) + 8px);
}
/* On a short screen the name field keeps the full width and Save and Cancel
   share one row below it. Beside the field, the narrow action column wrapped
   Save above Cancel and put Save underneath the top bar, where the mute button
   covered it. */
:root[data-viewport-compact="true"] .profile-form {
  grid-template-columns: minmax(0, 1fr);
}
:root[data-viewport-compact="true"] .profile-form .profile-actions button {
  flex: 1;
  min-width: 44px;
}
:root[data-viewport-compact="true"] .title-play .splash-intro { display: none; }
:root[data-viewport-compact="true"] .playing-as-row .player-identity { flex-basis: 100%; }
:root[data-viewport-compact="true"] .playing-as-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
:root[data-viewport-keyboard="true"] .parental-gate-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  padding: 6px;
}
:root[data-viewport-keyboard="true"] .parental-gate-card h2,
:root[data-viewport-keyboard="true"] #parental-gate-question { grid-column: 1; }
:root[data-viewport-keyboard="true"] .parental-gate-form { grid-column: 2; grid-row: 1 / span 3; }
:root[data-viewport-keyboard="true"] #parental-gate-description,
:root[data-viewport-keyboard="true"] #parental-gate-hint { display: none; }

@media (orientation: landscape), (max-height: 400px) {
  .title-play {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: stretch;
  }
  /* The store badges belong to the whole page, not to either column. */
  .title-play .splash-store-row { grid-column: 1 / -1; grid-row: 2; }
  .splash-store-badge { min-height: 28px; padding: 3px 8px; }
  .splash-diff-buttons { height: 100%; grid-template-rows: repeat(2, minmax(44px, 128px)); }
  .title-play-intro { gap: 4px; }
  /* Compact heights force the player line onto its own row (see
     [data-viewport-compact] below), which drops "Switch player" onto a second
     flex line: centre it like the rest of the intro instead of leaving it at
     the left edge. */
  .playing-as-row { flex-wrap: wrap; justify-content: center; gap: 4px; }
  .splash-login-row { flex-wrap: wrap; row-gap: 2px; }
  .splash-login-row .splash-btn { padding: 4px; }
  .profile-ui {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: center;
  }
  .profile-list { grid-column: 1; grid-row: 1; }
  .profile-ui > .profile-actions { grid-column: 2; grid-row: 1; flex-direction: column; }
  .profile-status { grid-column: 1 / -1; grid-row: 2; }
  .profile-form, .profile-confirmation { grid-column: 1 / -1; grid-row: 1; }
  .profile-form { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: end; }
  .profile-form .profile-actions { flex-wrap: wrap; align-items: flex-end; }
  .paywall-card, .parental-gate-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-content: center;
  }
  .paywall-card h2, .parental-gate-card h2 { grid-column: 1; }
  .paywall-card > p:not(.paywall-status), .parental-gate-card > p:not(.gate-status) { grid-column: 1; }
  .paywall-actions, .parental-gate-form { grid-column: 2; grid-row: 1 / span 3; }
  .paywall-status, .gate-status { grid-column: 1 / -1; }
  #level-clear .overlay-card, #game-over .overlay-card { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #level-clear .overlay-card h2, #level-clear .overlay-card p, #level-clear .overlay-card figure,
  #game-over .overlay-card h2, #game-over .overlay-card p { grid-column: 1 / -1; }
  /* Two buttons share the row; the third (Return to Title) takes its own full row. */
  #btn-save-score-return-title { grid-column: 1 / -1; }
}

:root {
  color-scheme: dark;
  --ink-950: #091411;
  --ink-900: #10211b;
  --forest-850: #18352d;
  --forest-800: #20463a;
  --ivory: #f3ead6;
  --ivory-muted: #d3ccb9;
  --brass: #c49a48;
  --brass-light: #e4c577;
  --brass-deep: #80602d;
  --focus-ring: #fff0bd;

  /* Menu typography. Two defaults carry every menu: buttons use the title-page
   * tab metrics, body copy uses the difficulty-explanation metrics
   * ("15 seconds · 7 hearts"). Option names, screen headings and dialog
   * subtitles (h3) are the only larger steps; --text-small is the one smaller
   * step, for a caption line under a heading. Bold and ivory are reserved for
   * headings, the selected tab and the primary action. Every dialog takes these
   * through the :where(.overlay) defaults, so a dialog never sets its own. */
  --font-ui: system-ui, sans-serif;
  --font-prose: monospace;
  --text-button: clamp(11px, 1.5vw, 15px);
  --text-body: 12px;
  --text-small: 11px;
  --line-body: 1.35;
  --text-option: clamp(15px, 2.5vw, 22px);
  --text-heading: clamp(16px, 3.4vw, 28px);
  --text-subheading: 14px;
}

/* WKWebView inflates paragraph text in landscape but leaves buttons alone, so
 * 12px body copy rendered ~18px next to 11px button labels. Pin it to 100% so
 * the menu type scale below is the size that actually shows. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { background: var(--ink-950); }
body { color: var(--ivory); }
#loading-overlay { background: var(--ink-950); }
.loading-title { color: var(--ivory); }
.loading-bar-track { border-color: var(--brass); background: var(--forest-850); }
.loading-bar-fill { background: linear-gradient(90deg, #9e7735, var(--brass-light)); }
.loading-percent { color: var(--ivory-muted); }

.splash-screen {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(196, 154, 72, 0.13), transparent 58%),
    linear-gradient(145deg, rgba(20, 47, 38, 0.98), rgba(7, 18, 15, 0.98) 62%, rgba(18, 34, 29, 0.98));
}

.splash-bg {
  inset: 0;
  background:
    linear-gradient(180deg, rgba(3, 10, 20, 0.12), transparent 40%, rgba(3, 10, 20, 0.22)),
    url('game/title-art.webp') center / cover no-repeat;
  background-color: #030a14;
  filter: none;
  transform: none;
  pointer-events: none;
}

.splash-title {
  color: var(--ivory);
  font-family: monospace;
  font-weight: 700;
  letter-spacing: 0.035em;
  text-shadow: 0 2px 0 #070e0b, 0 4px 16px rgba(0, 0, 0, 0.85), 0 0 20px rgba(196, 154, 72, 0.35);
}

.splash-intro, .splash-subtitle, .diff-detail, .player-identity { color: var(--ivory-muted); }
.splash-subtitle { text-shadow: none; }

.splash-diff-btn, .splash-leaderboard, #gameplay-chrome, .overlay-card,
.compact-disclosure {
  background:
    linear-gradient(145deg, rgba(33, 65, 53, 0.96), rgba(13, 30, 24, 0.97));
  border-color: var(--brass-deep);
  box-shadow: inset 0 1px 0 rgba(243, 234, 214, 0.08), 0 8px 24px rgba(0, 0, 0, 0.38);
}

.splash-diff-btn {
  border: 1px solid var(--brass-deep);
  border-radius: 7px;
  text-shadow: 0 1px 2px #000;
}
.splash-diff-btn:hover {
  background: linear-gradient(145deg, #2c5846, #18372d);
  border-color: var(--brass-light);
  box-shadow: inset 0 1px 0 rgba(243, 234, 214, 0.12), 0 10px 24px rgba(0, 0, 0, 0.5);
  transform: translateY(-1px);
}
.diff-label { color: var(--ivory); }
[data-difficulty="easy"] .diff-label { color: #b7e5a0; }
[data-difficulty="hard"] .diff-label { color: #ffb1a3; }
[data-difficulty="shapes"] .diff-label { color: var(--brass-light); }
[data-difficulty="medium"] .diff-label { color: #e9d39a; }

#gameplay-chrome {
  color: var(--ivory);
  background: linear-gradient(105deg, rgba(19, 42, 34, 0.98), rgba(11, 25, 20, 0.98));
  border: 1px solid rgba(196, 154, 72, 0.7);
  border-radius: 6px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  font-size: 16px;
  line-height: 20px;
}
#active-question {
  color: var(--ivory);
  font-size: 22px;
  line-height: 28px;
  min-height: 28px;
  text-shadow: 0 1px 2px #000;
}
.gameplay-readouts { color: var(--ivory-muted); font-size: 16px; line-height: 20px; }
.gameplay-readouts strong { color: var(--brass-light); }
#btn-pause-game {
  border-color: var(--brass);
  border-radius: 5px;
  background: linear-gradient(#315744, #173428);
  color: var(--ivory);
}

#input-zone {
  background: linear-gradient(180deg, rgba(13, 28, 22, 0.97), rgba(7, 17, 14, 0.99));
  border: 1px solid rgba(196, 154, 72, 0.3);
  border-radius: 6px;
}
.mc-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--brass-deep);
  border-radius: 5px;
  background: linear-gradient(145deg, #204638, #132d24);
  color: var(--ivory);
  font-size: 18px;
  box-shadow: inset 0 1px 0 rgba(243, 234, 214, 0.08), 0 2px 5px rgba(0, 0, 0, 0.28);
}
.mc-btn:hover { background: linear-gradient(145deg, #32634c, #1d4434); }
.mc-btn:focus-visible, #btn-pause-game:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Press feedback. A tap used to change nothing on the control itself: the
 * native tap highlight is off (see the -webkit-tap-highlight-color rules) and
 * the first visible answer is the canvas effect on the next frame, which reads
 * as lag on a phone. The scale is compositor-only and the global
 * prefers-reduced-motion block neutralises it, so the colour change is what
 * still confirms the press for a player who asked for less motion. */
.mc-btn:active:not(:disabled) {
  background: linear-gradient(145deg, #2a5747, #0f241c);
  transform: scale(0.96);
}
.ability-slot:active:not(:disabled) { transform: scale(0.94); }
#btn-pause-game:active:not(:disabled),
.diff-btn:active:not(:disabled),
.splash-btn:active:not(:disabled) { transform: scale(0.97); }

.overlay {
  background: rgba(3, 10, 7, 0.82);
  /* No backdrop-filter: every overlay paints an opaque backdrop of its own
     (.splash-bg, or the ::before artwork below), so a blur of the playfield
     underneath was never visible — while WebKit re-blurred the full screen on
     every frame the game canvas repainted, and the splash, pause, level-clear
     and game-over cards are exactly where a phone sits idle. */
  isolation: isolate;
}
.overlay:not(.splash-screen)::before {
  content: "";
  position: absolute;
  inset: -8px;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(9, 20, 17, 0.68), rgba(9, 20, 17, 0.86)),
    url('game/title-art.webp') center / cover no-repeat;
  filter: blur(5px) saturate(0.7);
}
.overlay-card {
  color: var(--ivory);
  background:
    linear-gradient(150deg, rgba(32, 66, 52, 0.99), rgba(11, 25, 20, 0.99) 72%);
  border: 1px solid var(--brass);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.62), inset 0 1px 0 rgba(243, 234, 214, 0.1);
}
.overlay-card h2, .title-page h2, .title-page h3 {
  color: var(--ivory);
  font-family: monospace;
  text-align: center;
}
.overlay-card p { color: var(--ivory-muted); }
.diff-btn, .splash-btn, #top-bar button, .title-navigation button,
.screen-pagination button, .profile-ui button, .title-page > button {
  border-radius: 5px;
}
.diff-btn {
  background: linear-gradient(145deg, #284c3c, #173126);
  color: var(--ivory);
  border: 1px solid var(--brass-deep);
}
.diff-btn:hover { background: linear-gradient(145deg, #386248, #214231); border-color: var(--brass-light); }
/* Button hierarchy. Every button in the game is one of three tiers, so the
 * important control on a screen is recognisable before the label is read:
 *
 *   primary  brass fill, a thicker 2px line and a diamond marker. Gold is
 *            reserved for the "proceed" half of a proceed/abort choice
 *            (select vs cancel, start vs back, resume vs leave, buy vs not
 *            now), so a gold button always means "this goes ahead". A button
 *            that only opens a page or a submenu is quiet, however important.
 *            A primary button with its own glyph (Select's ▶) drops the
 *            diamond, so it never carries two icons.
 *   danger   red 2px line for the irreversible half of a confirmation:
 *            discard a score, delete a player.
 *   quiet    everything else (navigation tabs, pagination, secondary
 *            actions): brass-deep hairline, muted label.
 *
 * The tier rules use :is() with one id each, so they also win over the
 * element-qualified quiet rules below (e.g. .profile-ui button) without
 * repeating the tier declarations for every host element. */
:is(.action-primary, #btn-next-level, #btn-resume-game, #btn-pause-save, #btn-skill-intro-continue) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(145deg, #d5b05c, #a77a34);
  color: #15140f;
  border: 2px solid #f7e2a4;
  font-weight: 700;
  text-shadow: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 3px 8px rgba(0, 0, 0, 0.3);
}
:is(.action-primary, #btn-next-level, #btn-resume-game, #btn-pause-save, #btn-skill-intro-continue)::before {
  content: '';
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  background: currentColor;
  opacity: 0.55;
}
:is(.action-primary, #btn-next-level, #btn-resume-game, #btn-pause-save, #btn-skill-intro-continue):hover {
  background: linear-gradient(145deg, #ecd07d, #c09446);
}
#btn-level-select.action-primary::before { content: none; }
:is(.action-danger, #btn-pause-discard) {
  background: linear-gradient(145deg, #4a2620, #2c1613);
  color: #ffd9d2;
  border: 2px solid #d0675c;
  font-weight: 700;
}
:is(.action-danger, #btn-pause-discard):hover {
  background: linear-gradient(145deg, #5d2f27, #3a1d18);
  border-color: #f0847a;
}
#btn-replay-level, #btn-retry-level, #btn-return-title, #btn-quit-game,
#btn-skill-intro-skip { border-color: #9e895e; }

.title-navigation button, .screen-pagination button, .profile-ui button, .title-page > button {
  border-color: var(--brass-deep);
  background: linear-gradient(145deg, #203e32, #10241c);
  color: var(--ivory-muted);
}
.title-navigation button:hover, .screen-pagination button:hover,
.profile-ui button:hover, .title-page > button:hover {
  border-color: var(--brass);
  color: var(--ivory);
  background: linear-gradient(145deg, #315641, #19372b);
}
.title-navigation button[aria-pressed="true"], .profile-row button[aria-pressed="true"] {
  border-color: var(--brass-light);
  background: linear-gradient(145deg, #3e6247, #203b2e);
  color: var(--ivory);
}
/* The web dialogs' tab rows (account: Profile/Password/High Scores/Billing/Delete; login:
 * Login/Register) are menu tabs like the title navigation, so they wear the same states:
 * forest with a dark brass edge, and the selected tab lighter green with a gold edge,
 * not the indigo of the first web build. */
.tab-btn {
  border: 2px solid var(--brass-deep);
  border-radius: 6px;
  background: linear-gradient(145deg, #203e32, #10241c);
  color: var(--ivory-muted);
  font-family: var(--font-ui);
  font-size: var(--text-button);
}
.tab-btn:hover {
  border-color: var(--brass);
  background: linear-gradient(145deg, #315641, #19372b);
  color: var(--ivory);
}
.tab-btn.active {
  border-color: var(--brass-light);
  background: linear-gradient(145deg, #3e6247, #203b2e);
  color: var(--ivory);
  font-weight: 700;
}
.tab-btn:focus { outline: none; }
.tab-btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
/* The dialogs' close X has a row of its own: the first row of the card, right-aligned, a
 * 44px square. It is a normal flex item (the cards are flex columns), not an absolutely
 * placed button, so no tab, heading or field can ever be laid out underneath it, however
 * the tabs wrap (account: 5 tabs, login: 2) or the card scrolls. */
:is(#account-modal, #auth-modal, #checkout-modal, #auth-status-modal) .overlay-card {
  position: relative;
  display: flex;
  flex-direction: column;
}
:is(#account-modal, #auth-modal, #checkout-modal, #auth-status-modal) :is(.close-btn, #close-auth) {
  position: static;
  align-self: flex-end;
  flex: 0 0 auto;
  order: -1;
  width: 44px;
  height: 44px;
  margin: -4px -4px 0 0;
  padding: 0;
  line-height: 1;
  color: var(--ivory);
}
:is(.close-btn, #close-auth):hover { color: var(--brass-light); }
:is(.close-btn, #close-auth):focus { outline: none; }
:is(.close-btn, #close-auth):focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
/* The rest of the old indigo inside those dialogs: text links ("Forgot password?", the
 * billing Terms links) read brass, and Redeem is a secondary forest button. */
.link-btn, .billing-disclosure a { color: var(--brass-light); }
.link-btn:hover, .billing-disclosure a:hover { color: var(--focus-ring); }
.link-btn:focus { outline: none; }
.link-btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
/* Billing's plain buttons (Refresh access status, Retry pending code grant, Cancel future
 * renewals) had no style at all and showed the browser's grey: same secondary forest. */
#btn-redeem-code, #billing-actions > button:not(.splash-btn) {
  border: 2px solid var(--brass-deep);
  border-radius: 6px;
  background: linear-gradient(145deg, #203e32, #10241c);
  color: var(--ivory);
  font-family: var(--font-ui);
  cursor: pointer;
}
#btn-redeem-code:hover, #billing-actions > button:not(.splash-btn):hover {
  border-color: var(--brass);
  background: linear-gradient(145deg, #315641, #19372b);
}
.title-navigation button:focus-visible, .screen-pagination button:focus-visible,
.profile-ui button:focus-visible, .title-page > button:focus-visible,
.diff-btn:focus-visible, .splash-btn:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

#top-bar button, #top-bar span, .tab-btn, form input, .leaderboard-filter,
.profile-name-input, #answer-input, #billing-redeem-code, .profile-select {
  background: var(--ink-900);
  color: var(--ivory);
  border-color: var(--brass-deep);
  border-radius: 4px;
}
#top-bar button:hover, .tab-btn:hover { background: var(--forest-800); }
form button, .splash-btn:not(.splash-btn--secondary) {
  background: linear-gradient(145deg, #315c44, #1a3a2d);
  color: var(--ivory);
  border: 1px solid var(--brass);
}
.splash-btn--secondary {
  background: linear-gradient(145deg, #1c3c30, #10271e);
  color: var(--ivory-muted);
  border-color: var(--brass-deep);
}
.splash-btn--secondary:hover { background: var(--forest-800); border-color: var(--brass); }
a { color: var(--brass-light); }
a:hover { color: var(--ivory); }
input:focus-visible, select:focus-visible, button:focus-visible,
.profile-select:focus-visible, .leaderboard-filter:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
.error-msg { color: #ffaaa0; }
.success-msg { color: #c4e7a9; }
.profile-status, .leaderboard-personal-best { color: var(--brass-light); }
.cookie-banner {
  background: rgba(10, 28, 21, 0.97);
  border-color: var(--brass-deep);
}
.cookie-btn { border-color: var(--brass-deep); border-radius: 4px; }
.cookie-btn--accept { background: linear-gradient(145deg, #d5b05c, #a77a34); color: #15140f; }

.compact-disclosure {
  min-width: 0;
  border: 1px solid rgba(196, 154, 72, 0.55);
  border-radius: 5px;
  color: var(--ivory-muted);
  box-sizing: border-box;
}
.compact-disclosure > summary {
  display: flex;
  align-items: center;
  /* Every disclosure label is centred in its bar: the summary is a button, and
   * its text should read like the button label it is (practice sessions and
   * audio settings share this rule). */
  justify-content: center;
  min-height: 44px;
  padding: 4px 10px;
  color: var(--brass-light);
  cursor: pointer;
  touch-action: manipulation;
}
.compact-disclosure > summary::marker { color: var(--brass-light); }
.practice-controls, .audio-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
  align-items: center;
  gap: 4px;
  padding: 0 8px 4px;
  min-width: 0;
  box-sizing: border-box;
}
.practice-controls label, .audio-controls label {
  color: var(--ivory-muted);
  overflow-wrap: anywhere;
}
.practice-controls select, .audio-controls input {
  width: 100%;
  min-width: 0;
}
.practice-controls select {
  padding: 4px;
  color: var(--ivory);
  border: 1px solid var(--brass-deep);
  border-radius: 4px;
  background: var(--ink-900);
}
#practice-description, #practice-unscored, #practice-badges, #practice-status, #btn-start-practice, #music-volume-status {
  grid-column: 1 / -1;
}
/* Basics Math: one inline row (the grid pairs belong to the two selectors
 * above), and the completed-run list under the hint. */
.practice-duration-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}
.practice-duration-row select { width: auto; flex: 0 0 auto; }
.practice-tables-row {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.practice-tables-label { color: var(--ivory-muted); }
.practice-tables-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}
/* One chip per table; pressed means "practise this one". The size keeps a
 * 15-chip row tappable at 320px without the panel growing a scrollbar of its
 * own (the submenu already scrolls). */
.practice-table-chip {
  min-width: 34px;
  min-height: 34px;
  padding: 2px 6px;
  color: var(--ivory);
  background: var(--ink-900);
  border: 1px solid var(--brass-deep);
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.practice-table-chip[aria-pressed="true"] {
  color: var(--ink-900);
  background: var(--brass-light);
  border-color: var(--brass-light);
}
.practice-basics-results { grid-column: 1 / -1; min-width: 0; }
.practice-results-heading {
  margin: 0;
  color: var(--ivory-muted);
  text-align: center;
}
.practice-results-list {
  margin: 0;
  padding-left: 18px;
  color: var(--ivory);
  max-height: 104px;
  overflow-y: auto;
}
.practice-results-list li { overflow-wrap: anywhere; }
/* The practice panel is opened by the real #btn-open-practice button (primary
 * tier); the <summary> stays in the DOM only because <details> needs it. */
#practice-panel > summary { display: none; }
#btn-open-practice { width: 100%; min-height: 44px; flex-shrink: 0; }
.title-page:has(#practice-panel[open]) #btn-open-practice { display: none; }
/* The level hint sits under the level selector and spans the control column.
 * It is a one-line label for the chosen level, not running text, so it stays
 * centred (the dialog-wide left alignment for passages does not apply to it). */
#practice-level-hint {
  grid-column: 1 / -1;
  margin: 0 0 4px;
  color: var(--brass-light);
  text-align: center;
}
#practice-level-hint:empty { display: none; }
/* Back out of the submenu to the Training tab it belongs to. Quiet, full width,
 * and the last control, mirroring the audio settings' own back button. */
#btn-close-practice {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 44px;
}
#practice-badges { min-width: 0; overflow-wrap: anywhere; color: var(--brass-light); }
#practice-description, #practice-unscored {
  margin: 4px 0;
}
#music-volume:disabled { opacity: 0.62; }
.audio-controls input[type="range"] { accent-color: var(--brass-light); }
#haptics-toggle {
  width: auto;
  min-width: 24px;
  min-height: 24px;
  justify-self: start;
  accent-color: var(--brass-light);
}
#pause-overlay:has(#audio-settings[open]) #pause-actions { display: none; }
#pause-overlay:has(#audio-settings[open]) .player-identity { display: none; }
/* #pause-quit-actions is shown by an inline display from script, so only
 * !important can keep the save prompt from stacking under the sound panel. */
#pause-overlay:has(#audio-settings[open]) #pause-quit-actions { display: none !important; }
#btn-audio-back { grid-column: 1 / -1; width: 100%; }
/* The pause dialog keeps the title screen's 560px control column, so the
   action buttons and the audio disclosure share one width on wide screens. */
#pause-overlay .overlay-card {
  position: relative;
  align-items: stretch;
  text-align: center;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
}
/* The pause dialog is a short centred stack (title, "Playing as", prompt,
 * buttons). The shared rule that left-aligns dialog paragraphs is for passages;
 * here it left only the prompt and save notice off the centre line. */
#pause-overlay .overlay-card p { text-align: center; }
/* The title keeps clear of the speaker button in the corner, and its row is as
 * tall as the button, so the content below never slides under it. */
#pause-overlay .overlay-card > h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding-inline: 52px;
}
#audio-settings { width: 100%; align-self: center; }
/* Closed, the disclosure is only its speaker button; the frame belongs to the
 * open settings panel. */
#audio-settings:not([open]) { border: 0; background: none; box-shadow: none; }
/* The sound settings open from a speaker in the card's top-right corner (the
 * corner where the title bar keeps its speaker), not from a full-width row
 * among the pause actions. The same 44px box and brass hairline as the title
 * bar's speaker; the summary stays the disclosure's real toggle. */
#pause-overlay .audio-settings-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid var(--brass-deep);
  border-radius: 4px;
  background: var(--ink-900);
  list-style: none;
}
#pause-overlay .audio-settings-toggle::-webkit-details-marker { display: none; }
#pause-overlay .audio-settings-toggle::marker { content: ''; }
#pause-overlay .audio-settings-toggle:hover,
#audio-settings[open] > .audio-settings-toggle { border-color: var(--brass-light); background: var(--forest-800); }
.audio-settings-icon { font-size: 18px; line-height: 1; }
.audio-controls { grid-template-columns: minmax(0, 1fr); justify-items: stretch; text-align: left; row-gap: 8px; }
.audio-controls label { width: 100%; }
.audio-controls input[type="range"] { max-width: 400px; }
.audio-controls .screen-status { grid-column: 1 / -1; }
/* "Music volume control is available." is a live-region message for screen
 * readers; it only needs to be seen when the control is not available. */
#music-volume:not(:disabled) + #music-volume-status {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
#btn-audio-back { margin-top: 8px; }
.playing-as-row button {
  background: linear-gradient(145deg, #203e32, #10241c);
  color: var(--ivory);
  border: 1px solid var(--brass-deep);
  border-radius: 5px;
}
.playing-as-row button:hover { border-color: var(--brass-light); background: var(--forest-800); }
.title-play-intro {
  padding: 24px 28px;
  box-sizing: border-box;
  align-self: center;
  height: auto;
  gap: 10px;
  background: none;
  text-shadow: 0 2px 3px #000, 0 0 8px #000, 0 0 16px #000;
}
.title-play-intro .splash-intro { max-width: min(46ch, 100%); }
.title-play-intro .splash-subtitle, #continue-level { max-width: 26ch; }
.title-play-intro .splash-intro { color: var(--ivory); }
.title-play-intro .splash-subtitle,
.title-play-intro .player-identity,
.title-play-intro #continue-level {
  color: var(--ivory-muted);
}
.title-play-intro .splash-intro, .title-play-intro .splash-subtitle,
.title-play-intro .player-identity, .title-play-intro #continue-level {
  /* Stacked, tight-to-wide shadow keeps the white text legible over the bright moon. */
  text-shadow:
    0 1px 1px #000, 0 2px 3px #000, 0 3px 6px rgba(0, 0, 0, 0.95),
    0 0 6px #000, 0 0 12px #000, 0 0 22px rgba(0, 0, 0, 0.95), 0 0 34px rgba(0, 0, 0, 0.8);
}
.splash-diff-buttons {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: repeat(4, minmax(44px, 1fr));
  height: 100%;
  max-height: 312px;
  align-content: stretch;
  width: min(100%, 560px);
  justify-self: center;
  gap: 8px;
}
.splash-diff-btn {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
  text-align: left;
  background: linear-gradient(110deg, rgba(15, 36, 30, 0.96), rgba(12, 27, 23, 0.84));
}
.splash-diff-btn .diff-label { flex: 0 0 25%; }
.splash-diff-btn .diff-detail { text-align: right; }
.diff-swords { display: flex; flex: 0 0 auto; align-items: center; gap: 2px; height: 20px; }
.diff-sword { flex: 0 0 12px; width: 12px; height: 20px; }
.diff-sword::before { background: linear-gradient(180deg, #c8f7c5 0%, #5fd068 45%, #2e8b3a 100%); }
#game-wrap[data-layout="portrait"] #input-zone {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: #091411;
}
/* Portrait stacks the answer zone into one column: the sword row sits directly
 * under the playfield, the ability orbs directly under the swords, and the
 * answers form a single row that floats in whatever height is left — the auto
 * margins above and below it take all the slack, so it is centred instead of
 * pinned to the bottom. The two full-width lines stop claiming `100%` here,
 * because in a column that would mean 100% of the height. */
#game-wrap[data-layout="portrait"] #input-zone {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

#game-wrap[data-layout="portrait"] #input-zone > .app-encounter-swords,
#game-wrap[data-layout="portrait"] #input-zone > #ability-bar {
  flex: 0 0 auto;
}

#game-wrap[data-layout="portrait"] #input-zone > #mc-buttons {
  margin-block: auto;
}

/* Landscape stacks the answer zone exactly like portrait: the circle row keeps
 * its natural height and the grid takes whatever is left. Previously the grid
 * sized itself from the whole answer zone (rows * 70px), so on a short phone
 * the ability row pushed the last answer rows off-screen. The auto margins
 * centre a grid that is capped on a roomy tablet; on a short screen `100%`
 * wins and the rows share the remaining height instead of overflowing it. */
#game-wrap[data-layout="landscape"] #input-zone {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: flex-start;
}

#game-wrap[data-layout="landscape"] #input-zone > #ability-bar {
  flex: 0 0 auto;
}

/* The empty timer slot is not a flex item here, so it cannot cost a gap out of
 * the answers. Nothing in the game writes into it. */
#game-wrap[data-layout="landscape"] #input-zone > #timer-bar-container:empty {
  display: none;
}

#game-wrap[data-layout="landscape"] #input-zone > #mc-buttons {
  flex: 0 1 auto;
  height: min(100%, calc(var(--answer-rows, 2) * var(--answer-row-max, 84px)
    + (var(--answer-rows, 2) - 1) * 6px));
  min-height: 0;
  margin-block: auto;
  grid-template-columns: repeat(var(--answer-columns, 5), minmax(0, 1fr));
  grid-template-rows: repeat(var(--answer-rows, 2), minmax(0, 1fr));
}

/* The layout still keeps every answer at 44px wherever the screen allows it.
 * These floors only stop a single impossible cell (a 10-choice level on a
 * 480×240 window) from pushing the whole grid off-screen; the label size above
 * shrinks with the cell instead. */
#game-wrap[data-layout="landscape"] .mc-btn {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  font-size: var(--answer-font-size, 18px);
}

#game-wrap[data-layout="portrait"] #input-zone::before {
  content: "";
  position: absolute;
  inset: -10px;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(rgba(9, 20, 17, 0.55), rgba(9, 20, 17, 0.78)),
    url('game/title-art.webp') center 70% / cover no-repeat;
  filter: blur(6px);
}

.title-page:has(#practice-panel[open]) #personal-development,
.title-page:has(#practice-panel[open]) .screen-pagination { display: none; }
/* The open practice submenu is the page: the sheet scrolls, so the panel must
 * not pin its own height. A flex row here sized the <details> from its
 * ::details-content wrapper instead of its children, which clipped the Start
 * and Back buttons on short landscape screens. The sheet is the only surface
 * on a title page, so the panel never draws a second frame around itself —
 * a hairline above the summary is what separates the submenu from the list. */
.title-page #practice-panel {
  padding: 0;
  border: 0;
  border-top: 1px solid rgba(196, 154, 72, 0.35);
  background: none;
  box-shadow: none;
}
#practice-panel[open] {
  display: block;
  flex: 0 0 auto;
  min-height: 0;
}
#practice-panel[open] .practice-controls { align-content: start; }

/* The per-level scores are one scrolling list instead of pages. The Practice
 * sheet is as tall as the band (minus the footer navigation and the title bar,
 * which sit outside it); the list takes what the heading, the Practice button
 * and the chart button leave, and scrolls inside that. While the practice
 * submenu is open the whole sheet scrolls again, as on every other menu page. */
.title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) {
  height: 100%;
  max-height: calc(100dvh - env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}
.title-page[data-title-page="progress"] #personal-development:not([style*="display: none"]):not([style*="display:none"]) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.title-page[data-title-page="progress"] #personal-best-list {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
/* The scores are body text: the standard prose size in compact, left-aligned
 * rows (the leaderboard's 4px padding plus 4px margin made every level a 28px
 * row, so a landscape phone showed one level at a time). The "Practice for"
 * line under the heading is one step smaller than body text. */
/* Room for a two-digit marker ("45.") inside the scroll box, which clips anything outside it. */
.title-page[data-title-page="progress"] #personal-best-list { padding-left: 4.5ch; font-size: var(--text-body); }
.title-page[data-title-page="progress"] #personal-best-list li {
  margin: 0;
  padding: 1px 4px;
  font-size: var(--text-body);
  line-height: var(--line-body);
  text-align: left;
}
.title-page[data-title-page="progress"] .player-identity { font-size: var(--text-small); }
/* The chart button names what it opens; the icon is decoration. */
#personal-history-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; }
.history-toggle-icon { font-size: 1.2em; line-height: 1; }
/* Short landscape: the scores take the left column at full height, and the two
 * page buttons stack as a narrow column on the right instead of eating the rows
 * the list needs. */
@media (orientation: landscape) and (max-height: 460px) {
  .title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, max-content);
    grid-template-rows: auto auto minmax(0, 1fr);
    column-gap: 10px;
    row-gap: 6px;
    align-content: stretch;
  }
  .title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) > #personal-development {
    grid-column: 1;
    grid-row: 1 / -1;
  }
  .title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) > #btn-open-practice {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    max-width: 34vw;
  }
  .title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) > .screen-pagination {
    grid-column: 2;
    grid-row: 2;
    margin: 0;
  }
  .title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) > .screen-pagination button {
    width: 100%;
    max-width: 34vw;
  }
  .title-page[data-title-page="progress"]:not(:has(#practice-panel[open])) > #practice-panel {
    grid-column: 2;
    grid-row: 3;
    border-top: 0;
  }
}
.level-jump-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  flex-shrink: 0;
}
.level-jump-actions button { min-height: 44px; margin: 0; }

.skill-intro-card { gap: 10px; }
.skill-intro-example {
  padding: 10px;
  border-left: 3px solid var(--brass);
  background: rgba(6, 18, 13, 0.55);
  color: var(--ivory);
  white-space: pre-line;
}
.skill-intro-example:empty { display: none; }
.skill-intro-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.skill-intro-actions button { min-width: 44px; min-height: 44px; margin: 0; }

body:not(.legal-body) {
  word-break: normal;
  hyphens: none;
}
.splash-intro, .splash-subtitle, .diff-detail, .overlay-card p,
.screen-status, .paywall-status, .gate-status, .practice-controls label,
.audio-controls label, .compact-disclosure > summary {
  overflow-wrap: normal;
}
.title-navigation button {
  white-space: nowrap;
  /* Six tabs (plus help) share the title width; a 2px side padding is what
   * keeps an eight-character label like "Practice"/"Training" inside its
   * button at 390px instead of spilling over the border. */
  padding-inline: 2px;
}

@media (orientation: landscape) {
  .splash-bg {
    background-image: linear-gradient(rgba(3, 10, 20, 0.12), rgba(3, 10, 20, 0.22)),
      url('game/title-art-wide.webp');
    background-size: auto, cover;
    background-position: center;
  }
  .overlay:not(.splash-screen)::before {
    background-image: linear-gradient(rgba(9, 20, 17, 0.68), rgba(9, 20, 17, 0.86)),
      url('game/title-art-wide.webp');
  }
  .splash-diff-buttons { gap: 6px; }
  /* The band is only ~240px high, so the practice form puts its selector pairs
     side by side and the two actions share one row, which is the space the
     short band cannot spare for four stacked rows. */
  #practice-panel[open] .practice-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    column-gap: 10px;
    row-gap: 4px;
  }
  /* Labels sit above their controls so the two selector pairs share two rows
     instead of four; the description, hint and actions then follow. */
  #practice-panel[open] .practice-controls > label[for="practice-kind"] { grid-area: 1 / 1; }
  #practice-panel[open] .practice-controls > #practice-kind { grid-area: 2 / 1; }
  #practice-panel[open] .practice-controls > label[for="practice-level-select"] { grid-area: 1 / 2; }
  #practice-panel[open] .practice-controls > #practice-level-select { grid-area: 2 / 2; }
  /* Basics Math swaps the level pair for the exercise-set pair; only one of the
     two is visible, so they share the second column. */
  #practice-panel[open] .practice-controls > label[for="practice-set"] { grid-area: 1 / 2; }
  #practice-panel[open] .practice-controls > #practice-set { grid-area: 2 / 2; }
  #practice-panel[open] #btn-start-practice { grid-column: 1; }
  #practice-panel[open] #btn-close-practice { grid-column: 2; }
}

/* A landscape phone spends 88px on the logo, which leaves too little height for
 * a menu sheet. While a page other than Play is showing, the logo row drops to
 * tab height so the sheet gets the room its content needs. */
@media (orientation: landscape) and (max-height: 460px) {
  .splash-content:has(> .title-pages > .title-page:not([hidden]):not(.title-play)) {
    grid-template-rows: 44px minmax(0, 1fr) minmax(44px, auto);
  }
  .splash-content:has(> .title-pages > .title-page:not([hidden]):not(.title-play)) .title-logo {
    height: 36px;
  }
  /* The web build stacks the same chips; six of them do not fit a short band,
     so the stack becomes two columns like the app's. */
  :root[data-platform="web"] .splash-legal-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
}

@media (orientation: portrait) {
  .title-pages { padding-inline: clamp(4px, 2vw, 20px); box-sizing: border-box; }
  .splash-diff-buttons { padding-inline: 4px; box-sizing: border-box; }
  /* Portrait stacks each practice label above its control: side by side, the
     select was squeezed into half the card and the two-word labels wrapped. */
  .practice-controls { grid-template-columns: minmax(0, 1fr); }
}
/* Only genuinely short portrait screens drop the introduction hint; phones
   with room keep it, so the title screen reads as a welcome rather than a
   bare menu. */
@media (orientation: portrait) and (max-height: 700px) {
  .splash-diff-buttons { gap: 6px; }
  .title-play-intro { padding: 6px 10px; gap: 4px; }
  .title-play-intro .splash-intro { display: none; }
}
@media (orientation: landscape) and (min-height: 500px) {
  .splash-content { grid-template-rows: 232px minmax(0, 1fr) minmax(44px, auto); }
  .title-logo { height: 184px; }
  .title-play-intro { padding: 20px 24px; }
  .playing-as-row { flex-direction: column; gap: 10px; }
}
@media (orientation: portrait) and (min-width: 700px) {
  .splash-content { grid-template-rows: 232px minmax(0, 1fr) minmax(44px, auto); }
  .title-logo { height: 184px; }
}

@media (orientation: landscape) and (max-height: 400px) {
  .splash-content { grid-template-rows: 44px minmax(0, 1fr) minmax(44px, auto); }
  .splash-title { align-self: center; }
  .splash-diff-buttons { grid-template-rows: repeat(4, minmax(44px, 1fr)); gap: 2px; }
  .splash-diff-btn { padding: 4px 8px; gap: 6px; }
  .title-play-intro { padding: 4px 8px; gap: 4px; }
  .audio-controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); }
  #active-question { font-size: 22px; line-height: 28px; min-height: 28px; }
  .gameplay-readouts { font-size: 16px; line-height: 20px; }
  .compact-disclosure > summary { min-height: 44px; }
}

@media (max-width: 380px) {
  .title-navigation { gap: 3px; }
  .title-navigation button { padding: 3px 1px; }
  .compact-disclosure > summary { padding-inline: 8px; }
  .practice-controls, .audio-controls { gap: 4px; padding-inline: 6px; }
  /* Keep the bonus readout on one line on the narrowest phones. */
  .ability-slot { padding: 4px 5px; }
  .ability-slot-readout { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    transform: none !important;
  }
}

/* Fade to black between the intro and the menu pages (see showTitlePage in
   main.js). Sits above every overlay so the swap is never visible. */
#screen-fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 170ms ease;
  z-index: 300;
}

#screen-fade.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* Late override: the phone-width readout size. Earlier rules in this file set
 * 16px for the readouts (and a landscape block repeats it), so this has to come
 * last to win. Three ~108px columns fit the longest marker ("Defeated: 0/30")
 * at 15px; at 16px it clipped by a pixel and showed an ellipsis. */
@media (max-width: 430px) {
  .gameplay-readouts { font-size: 15px; }
}

/* ── Speedrun ──────────────────────────────────────────────────────────────
 * The run clock is opt-in (see speedrun-ui.js): it appears in the readouts row
 * only once the player turned it on, so the default HUD is unchanged. Tabular
 * figures keep the width steady as the tenths tick over.
 */
#speedrun-readout {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* The records card: a fixed dialog whose level list is the only scroll
 * region. A finished playthrough records all 60 levels, so the list scrolls
 * between a standing header and the Close button. The whole card used to
 * scroll, which pushed the button below three screens of rows and left the
 * dialog looking like a dead end. */
.speedrun-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 420px;
  max-height: min(80vh, 620px);
  overflow: hidden;
}

.speedrun-card > * { flex-shrink: 0; }

.speedrun-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.speedrun-toggle input {
  width: 22px;
  height: 22px;
  accent-color: #7f8cff;
  touch-action: manipulation;
}

.speedrun-best-run {
  margin: 0;
  font-size: var(--text-option);
  font-variant-numeric: tabular-nums;
}

.speedrun-heading {
  margin: 0;
  font-size: var(--text-subheading);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
}

.speedrun-levels {
  position: relative;
  margin: 0;
  /* Bounded so the list scrolls even when the card is not height-limited. */
  max-height: min(45dvh, 320px);
  padding: 0 2px 0 0;
  list-style: none;
  display: grid;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  /* The one scroll region: it takes whatever height the header and the Close
   * button leave, and scrolls its rows instead of overflowing the card. */
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(169, 185, 237, 0.55) transparent;
}

.speedrun-levels li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(169, 185, 237, 0.18);
}

.speedrun-levels strong {
  font-weight: 600;
}

.speedrun-empty {
  margin: 0;
  opacity: 0.75;
}

/* ── Speedrun records on the ranking page ────────────────────────────────
 * Web only (the block is dropped from the app bundle). It sits under the high
 * score board and reads as a second board rather than a second screen.
 */
.speedrun-board {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(169, 185, 237, 0.22);
  font-variant-numeric: tabular-nums;
}

.speedrun-board-personal {
  margin: 0;
  font-size: 15px;
  opacity: 0.9;
}

.speedrun-board-levels {
  margin: 4px 0 0;
}

.speedrun-board-levels > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 15px;
  cursor: pointer;
}

.speedrun-board-levels .speedrun-levels li {
  align-items: baseline;
}

.speedrun-board-levels em {
  margin-left: auto;
  font-style: normal;
  font-size: 13px;
  opacity: 0.7;
}

/* Web hero picker (account modal) and the hero portrait beside player names. */
.hero-picker-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.hero-picker-actions .diff-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.hero-picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin: 8px 0; }
.hero-picker-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 44px; min-height: 44px; padding: 6px; border: 2px solid transparent; border-radius: 8px; background: rgba(255, 255, 255, 0.06); color: inherit; cursor: pointer; }
.hero-picker-item:focus-visible { outline: 3px solid #ffd54a; outline-offset: 2px; }
/* The worn hero has the thick gold frame of a selected row or tab; a different
 * hero highlighted as the next choice gets the thin gold hairline beside it, so
 * the player sees both "now" and "after Change hero" (hero-picker.js). */
.hero-picker-item.is-current { border-color: var(--brass-light); }
.hero-picker-item.is-prospective { border-color: transparent; box-shadow: inset 0 0 0 1px var(--brass-light); background: rgba(228, 197, 119, 0.1); }
.hero-picker-item.is-locked { opacity: 0.8; }
.hero-picker-portrait, .hero-picker-placeholder, .hero-identity-portrait { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: rgba(255, 255, 255, 0.15); }
.hero-picker-placeholder, .hero-identity-portrait-placeholder { display: inline-block; }
.hero-identity-portrait { width: 28px; height: 28px; vertical-align: middle; margin-right: 12px; }
.hero-picker-lock { position: absolute; top: 2px; right: 2px; min-width: 22px; padding: 0 4px; border-radius: 4px; background: #000; color: #fff; font-size: 14px; line-height: 22px; text-align: center; }
.hero-picker-name { font-size: 12px; text-align: center; }
.hero-picker-status { min-height: 16px; margin: 0; font-size: 12px; color: #f0d080; }

/* Campaign 2 (Arithmoslayer II) maths: stacked fractions and mixed numbers (campaign2/math-render.js). */
.m2-expr { display: inline-flex; align-items: center; gap: 0.35em; white-space: nowrap; }
.m2-mixed { display: inline-flex; align-items: center; gap: 0.15em; }
.m2-frac { display: inline-flex; flex-direction: column; align-items: center; line-height: 1.05; font-size: 0.8em; }
.m2-frac .m2-num { padding: 0 0.2em 0.08em; border-bottom: 0.09em solid currentColor; }
.m2-frac .m2-den { padding: 0.08em 0.2em 0; }
.m2-blank { opacity: 0.85; }
.m2-int { font-variant-numeric: tabular-nums; }
.m2-pow { display: inline-flex; align-items: flex-start; }
.m2-sup, .m2-sub { font-size: 0.62em; line-height: 1; }
.m2-sup { align-self: flex-start; margin-left: 0.08em; position: relative; top: -0.15em; }
.m2-sub { position: relative; top: 0.35em; margin-right: 0.12em; }
.m2-sup .m2-expr, .m2-sup .m2-frac { font-size: 1em; }
.m2-root { display: inline-flex; align-items: flex-end; }
.m2-idx { font-size: 0.55em; align-self: flex-start; margin-right: -0.1em; }
.m2-rad { border-top: 0.09em solid currentColor; padding: 0.04em 0.15em 0; margin-left: -0.05em; }
.m2-surd { display: inline-flex; align-items: flex-end; gap: 0.05em; }
.m2-paren { opacity: 0.9; }
.m2-log { margin-right: 0.15em; }

/* The campaign switch (Players page in the app, account profile on the web) and the
 * Campaign II picture on the title screen. They wear the menu colours: a forest panel
 * inside the thick-and-thin brass frame of the level numerals. A pair of dragons frames
 * the button, one curled around each end: a young dragon while it names Campaign I, an
 * ancient one for Campaign II (data-dragon, swapped by main.js; art in game/art/ui/). The
 * text is the game's own: the heading monospace for the campaign name, the UI face for the
 * small lines.
 *
 * Both are one piece of art at one size. Everything is derived from one height, --switch-h,
 * set once for both below: it follows the shorter viewport side (vmin), so the switch on
 * the Players page or in the profile and the picture on the title are the same size on the
 * same screen, and a 320px phone or a short landscape band shrinks both alike. The switch
 * used to have its own height (from its column width, clamp(56px, min(16cqi, 13vh), 80px))
 * and was left with twice the picture's dragons when #594 made the picture smaller. The
 * dragons are that height times --dragon-scale tall, sit half outside the button and
 * overhang above and below; the button reserves exactly that room (side padding so the
 * text clears them, a narrower width so their outer halves stay inside the column,
 * vertical margin for the overhang). */
.campaign-switch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
}
.campaign-switch[hidden] { display: none; }
.campaign-switch-btn, .campaign-emblem {
  /* The one size: 75% of the picture's first size, clamp(38px, 9vmin, 60px) (#594). */
  --switch-h: clamp(28.5px, 6.75vmin, 45px);
  /* Young dragon (Campaign I): 402x480 art, 1.75x the button tall. */
  --dragon-scale: 1.75;
  --dragon-aspect: 0.8375;
  --dragon-w: calc(var(--switch-h) * var(--dragon-scale) * var(--dragon-aspect));
  /* How far each piece reaches out of the button: 45% of its width. */
  --dragon-out: calc(var(--dragon-w) * 0.45);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 0;
  width: auto;
  max-width: calc(100% - 2 * var(--dragon-out));
  height: var(--switch-h);
  /* The frame is 33px at the least (75% of 44px); the tap area stays 44px (::after). */
  min-height: 33px;
  /* The overhang room is reserved for the taller pair (--dragon-room), not for the pair on
   * show: the switch swaps young (1.75x) for ancient (2.1x) dragons, and a margin that
   * followed --dragon-scale moved everything below the switch by 20px on every tap. */
  --dragon-room: 2.1;
  margin-block: calc(var(--switch-h) * (var(--dragon-room) - 1) / 2);
  margin-inline: auto;
  padding-block: 0;
  padding-inline: calc(var(--dragon-w) * 0.55);
  overflow: visible;
  border: 2px solid var(--brass-light);
  border-radius: 8px;
  background:
    radial-gradient(120% 140% at 50% 0%, rgba(228, 197, 119, 0.18), transparent 62%),
    linear-gradient(145deg, #284c3c, #10241c);
  /* The thin inner line of the double frame, 3px inside the thick one. */
  box-shadow: inset 0 0 0 3px #10241c, inset 0 0 0 4px var(--brass), 0 6px 18px rgba(0, 0, 0, 0.45);
  color: var(--ivory);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
}
/* A tap area at least 44px tall however small the frame is, centred on it. 100% is the
 * padding box, which is why the old `inset: -6px 0` on the 33px frame only reached 41px. */
:is(.campaign-switch-btn, .campaign-emblem)::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: max(100%, 44px);
  translate: 0 -50%;
}
/* Ancient dragon (Campaign II): 354x480 art, 2.1x the button tall. */
:is(.campaign-switch-btn, .campaign-emblem)[data-dragon="ancient"] {
  --dragon-scale: 2.1;
  --dragon-aspect: 0.7375;
}
.campaign-switch-btn:hover { border-color: var(--focus-ring); background: radial-gradient(120% 140% at 50% 0%, rgba(228, 197, 119, 0.26), transparent 62%), linear-gradient(145deg, #315641, #19372b); }
.campaign-switch-btn:active { scale: 0.98; }
.campaign-switch-btn:focus-visible, .campaign-emblem:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
/* The pieces are decoration over the frame: absolutely placed, vertically centred, half
 * outside. `translate`, not `transform`: the reduced-motion rule resets transform on every
 * element and would pull the dragons back into the text. */
.campaign-switch-dragon {
  position: absolute;
  top: 50%;
  height: calc(var(--switch-h) * var(--dragon-scale));
  width: auto;
  max-width: none;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.campaign-switch-dragon--left { left: 0; translate: -45% -50%; }
.campaign-switch-dragon--right { right: 0; translate: 45% -50%; }
.campaign-switch-text {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 0;
  line-height: 1.15;
}
/* The lines follow --switch-h as well, with the picture's readable floor: 7px for the
 * small line, 11px for the name. */
.campaign-switch-eyebrow {
  font-family: var(--font-ui);
  font-size: max(7px, calc(var(--switch-h) * 0.2));
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ivory-muted);
}
/* What a tap on the switch does ("Switch to Genius"). A third line would not fit the
 * picture's 33px frame at a readable size, so it is the caption under the switch (the
 * button's aria-describedby) and keeps a size of its own that is easy to read. */
.campaign-switch-status {
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  color: var(--brass-light);
}
.campaign-switch-title {
  font-family: var(--font-prose);
  font-size: max(11px, calc(var(--switch-h) * 0.38));
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--brass-light);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 0 12px rgba(228, 197, 119, 0.35);
}
/* Campaign II is the one being played: the dragons glow a little brighter. */
.campaign-switch-btn[aria-pressed="true"] .campaign-switch-dragon { filter: drop-shadow(0 0 6px rgba(228, 197, 119, 0.7)); }
.campaign-emblem[hidden] { display: none; }
/* A phone held sideways has no height to spare (the title's intro column, the Players
 * page): the ancient dragons barely overhang there, so the picture does not push "Choose
 * your difficulty" under the navigation. The switch follows it, so the two stay one size. */
@media (orientation: landscape) and (max-height: 460px) {
  :is(.campaign-switch-btn, .campaign-emblem)[data-dragon="ancient"] { --dragon-scale: 1.3; }
  /* Here the young pair (1.75x) is the taller one. The picture is always ancient. */
  .campaign-switch-btn { --dragon-room: 1.75; }
  .campaign-emblem { --dragon-room: 1.3; }
}
/* end campaign switch */
.m2-intro-math { font-size: 1.8em; text-align: center; margin: 0.4em 0; }
.mc-btn .m2-expr { font-size: 1.15em; justify-content: center; }
.mc-btn .m2-frac { font-size: 0.85em; }
