html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
}

:root {
  --accent: #00ff88;
  --accent-dim: rgba(0, 255, 136, 0.22);
  --text: #f5f5f5;
  --panel-bg: #050505;
  --panel-border: #232323;
  --tv-safe: 5%;
  --panel-width: 340px;
}

/* -------------------------------------------------------------------------
   Shared stage
------------------------------------------------------------------------- */
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;   /* so the safe-area padding below cannot push the stage wider than the screen */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

@supports (height: 100dvh) {
  #stage {
    height: 100dvh;
  }
}

/* Pause, for touch players: two fingers on the board already toggles pause in js/input.js, but nothing on
   screen says so. The HUD strip reserves its right-hand end for this button, and the 44px hit area only
   reaches into the board's top-right corner - which the maze validator guarantees is closed wall, never a
   corridor (build/validate_maze.js asserts the borders are closed). */
#pause-chip {
  position: absolute;
  top: 0;
  right: 0;
  width: 56px;
  height: 44px;
  margin: 0;
  padding: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: linear-gradient(rgba(5, 8, 5, 0.85), rgba(14, 20, 14, 0.55));
  border: 0;
  border-left: 1px solid rgba(142, 219, 54, 0.35);
  cursor: pointer;
  z-index: 60;
}
#bomb-chip {
  position: absolute;
  left: 0;
  bottom: 0;
  /* Phone testers could not find this control or hit it. Third pass: 62x44 -> 104x68, an explicit BOMB label
     under the icon and count, and no longer fading to 40% when empty (which made it invisible on a dark board
     exactly when the player needed to know it exists). */
  width: 104px;
  height: 68px;
  margin: 0;
  padding: 0 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font: 700 17px/1 ui-monospace, Menlo, monospace;
  color: #9CC48A;
  background: linear-gradient(rgba(14, 20, 14, 0.55), rgba(5, 8, 5, 0.85));
  border: 0;
  border-right: 1px solid rgba(142, 219, 54, 0.35);
  cursor: pointer;
  z-index: 60;
}
#bomb-chip svg { width: 25px; height: 25px; }
#bomb-chip .bomb-count { font: 800 19px/1 ui-monospace, Menlo, monospace; }
#bomb-chip .bomb-face { display: inline-flex; align-items: center; gap: 8px; }
#bomb-chip .bomb-word { font: 800 11px/1 ui-monospace, Menlo, monospace; letter-spacing: 0.14em; opacity: 0.92; }
/* Fourth pass. A vision read of the previous one: "not obviously a button ... could easily be mistaken for a
   status/ammo indicator or decorative HUD". A control has to use the vocabulary of a control, so: an opaque
   fill instead of a see-through dark panel, a solid border on every visible edge, a drop shadow that lifts it
   off the board, and a real pressed state. */
#bomb-chip {
  border-radius: 20px 20px 0 0;
  border: 2px solid rgba(184, 242, 61, 0.75);
  border-bottom: 0;
  background: linear-gradient(#2c3d1c, #121a0b);
  box-shadow: 0 -5px 16px rgba(0, 0, 0, 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.14);
}
#bomb-chip svg { width: 28px; height: 28px; }
#bomb-chip .bomb-word { font-size: 12px; letter-spacing: 0.18em; }
#bomb-chip:active { transform: translateY(2px); box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.55); }
#bomb-chip.empty { color: rgba(190, 216, 172, 0.75); border-color: rgba(142, 219, 54, 0.30); }

/* The teaching moment. Testers knew neither that a mushroom arms this nor where the control was, so the first
   bomb a player is granted announces itself and points down at the button; it leaves when they fire, after
   seven seconds, or once seen. pointer-events:none so it can never eat a TV remote's pointer steering. */
#bomb-hint {
  position: absolute;
  left: 12px;
  bottom: calc(68px + 12px);
  display: flex;
  align-items: flex-start;
  gap: 11px;
  max-width: min(80vw, 430px);
  padding: 11px 16px 12px 12px;
  background: rgba(6, 12, 8, 0.94);
  border: 2px solid #B8F23D;
  border-radius: 16px;
  color: #EAFFC9;
  font: 700 15px/1.35 ui-monospace, Menlo, monospace;
  pointer-events: none;
  z-index: 70;
  opacity: 0;
  transform: translateY(7px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
#bomb-hint.on { opacity: 1; transform: none; }
#bomb-hint[hidden] { display: none; }
#bomb-hint b { color: #B8F23D; }
#bomb-hint .bh-arrow {
  flex: 0 0 auto;
  margin-top: 3px;
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 12px solid #B8F23D;
  animation: bh-point 1s ease-in-out infinite;
}
@keyframes bh-point {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(4px); }
}
@media (prefers-reduced-motion: reduce) {
  #bomb-hint .bh-arrow { animation: none; }
  #bomb-hint { transition: none; }
}
/* on a television the callout has to be readable from the sofa */
body.layout-tv #bomb-hint, body.tv #bomb-hint { font-size: 22px; padding: 15px 22px 16px 16px; border-radius: 20px; }
/* armed: one mushroom in hand and this becomes the loudest thing on the screen edge, so the new ability is
   discoverable the moment it is granted rather than after an experiment */
#bomb-chip:not(.empty) {
  /* Armed: a SOLID, bright, dark-on-lime button. Every previous pass kept it a dark panel with pale text, and a
     vision read twice described that as "a status readout" rather than a control. Filled and high-contrast is
     the one shape nobody mistakes for an indicator. */
  color: #10160a;
  border-color: #EAFFC9;
  background: #B8F23D;
  animation: bomb-ready 1.15s ease-in-out infinite;
}
@keyframes bomb-ready {
  0%, 100% { box-shadow: 0 -5px 16px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(184, 242, 61, 0.85); transform: translateY(0); }
  50%      { box-shadow: 0 -5px 16px rgba(0, 0, 0, 0.55), 0 0 26px 6px rgba(184, 242, 61, 0.75); transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
  #bomb-chip:not(.empty) { animation: none; box-shadow: 0 -5px 16px rgba(0, 0, 0, 0.55), 0 0 20px 4px rgba(184, 242, 61, 0.7); }
}
#bomb-chip:active { color: #F2F8EC; }
#bomb-chip:focus-visible { outline: 2px solid #8EDB36; outline-offset: -2px; }

#pause-chip[hidden] { display: none !important; }
#pause-chip span { display: block; width: 4px; height: 15px; background: #9CC48A; }
#pause-chip:active span { background: #F2F8EC; }
#pause-chip:focus-visible { outline: 2px solid #8EDB36; outline-offset: -2px; }

#game {
  display: block;
  width: calc(var(--vvh, 100vh) * 1200 / 530);
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1200 / 530;
  object-fit: contain;
  flex: none;
  image-rendering: pixelated;
  touch-action: none;
  background: #000;
  margin: 0;
}

@supports (height: 100dvh) {
  #game {
    width: calc(100dvh * 1200 / 530);
  }
}

#hint {
  display: none;
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  max-width: 100%;
  max-height: 100%;
  color: #fff;
  background: #000;
  font: bold 20px/1.4 sans-serif;
  text-align: center;
  padding: 24px;
  overflow-wrap: break-word;
  z-index: 50;
}

/* -------------------------------------------------------------------------
   Rotate gate
------------------------------------------------------------------------- */
#rotate-gate,
.rotate-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  color: #fff;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  box-sizing: border-box;
  gap: 18px;
}

body.layout-portrait-gate #stage,
body.portrait-gate #stage,
body[data-layout="portrait-gate"] #stage,
body.portrait-gate.locked #stage {
  display: none !important;
}

body.layout-portrait-gate #rotate-gate,
body.portrait-gate #rotate-gate,
body.portrait-gate .rotate-gate,
body[data-layout="portrait-gate"] #rotate-gate {
  display: flex;
}

#rotate-gate .game-title,
.rotate-gate .game-title {
  font-size: clamp(36px, 8vw, 72px);
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(0, 255, 136, 0.35);
}

#rotate-gate .rotate-title,
.rotate-gate .rotate-title {
  font-size: clamp(24px, 5vh, 40px);
  margin: 0;
}

#rotate-gate .rotate-copy,
.rotate-gate .rotate-copy {
  font-size: clamp(13px, 2.4vh, 16px);
  color: rgba(255, 255, 255, 0.66);
  max-width: min(620px, 86vw);
  line-height: 1.45;
}

#rotate-gate .escape-line,
.rotate-gate .escape-line {
  margin-top: 20px;
  opacity: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: underline;
  cursor: pointer;
  animation: rotateEscapeFade 0.6s ease 6s forwards;
}

@keyframes rotateEscapeFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* -------------------------------------------------------------------------
   Phone landscape -- two side pads
------------------------------------------------------------------------- */
/* Variant C has no visible thumb pads, so the three-column grid that reserved their side bands is gone:
   the base #stage flex centring puts the board across the full width. Flip shouldHavePads back on in
   js/viewport.js and the pads still work - they are position:fixed, not grid items. */

body.layout-phone.landscape #game,
body.phone.landscape #game,
body[data-layout="phone"][data-orientation="landscape"] #game,
/* iPhone landscape puts the sensor island over one edge of the screen. The stage is fixed at inset 0, so the
   board was drawn under it and the maze's left-hand lanes disappeared behind the hardware. Reserving the inset
   on the stage shifts the whole grid - board and both thumb pads - clear of the island, and js/game.js measures
   the stage's padding already, so the board shrinks to fit rather than sliding under. The reserved side is the
   island's side, which depends on how the phone was turned, so both insets are honoured. */
body.layout-phone.landscape #stage,
body.phone.landscape #stage,
body[data-layout="phone"][data-orientation="landscape"] #stage,
body.phone-landscape #stage {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  /* Do NOT reserve the chips' height here. A vision read claimed the bottom-left pickup was hidden behind the
     bomb button and reserving 76px cost the board 16% of the screen (share 96% -> 64%, tile 14.07 -> 11.85).
     Pixel geometry says otherwise: the board ends at 373px and row 21, where the pickup sits, is at ~313px,
     with the chip's top edge at 322px, so nothing was ever covered - only the maze's own bottom border wall.
     Measure the element rects before trusting a vision read about overlap. */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

body.phone-landscape #game {
  grid-area: game;
  align-self: center;
  justify-self: center;
}

body.layout-phone.landscape .virtual-pad.left,
body.phone.landscape .virtual-pad.left,
body[data-layout="phone"][data-orientation="landscape"] .virtual-pad.left,
body.phone-landscape .virtual-pad.left {
  grid-area: leftpad;
}

body.layout-phone.landscape .virtual-pad.right,
body.phone.landscape .virtual-pad.right,
body[data-layout="phone"][data-orientation="landscape"] .virtual-pad.right,
body.phone-landscape .virtual-pad.right {
  grid-area: rightpad;
}

/* Compact upright fallback: board on top, pads below. */
body.layout-phone.portrait-compact #stage,
body.portrait-compact #stage,
body[data-layout="phone"][data-orientation="portrait"][data-upright="true"] #stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "game game"
    "leftpad rightpad";
  align-items: stretch;
  justify-items: stretch;
}

body.layout-phone.portrait-compact #game,
/* Upright play: the landscape fit centres the canvas with inline styles (position, left/top 50%, a translate).
   In this layout those put the top of the board - and the HUD strip - above the viewport, so take the canvas
   out of the JS-driven positioning entirely and let the stage centre it. !important beats the inline styles. */
body.portrait-compact #stage {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.portrait-compact #game {
  position: static !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  width: 100% !important;
  max-width: 100%;
  height: auto !important;
  max-height: calc(100vw * 530 / 1200);
}

body.layout-phone.portrait-compact .virtual-pad.left,
body.portrait-compact .virtual-pad.left {
  grid-area: leftpad;
}

body.layout-phone.portrait-compact .virtual-pad.right,
body.portrait-compact .virtual-pad.right {
  grid-area: rightpad;
}

/* -------------------------------------------------------------------------
   Virtual pad
------------------------------------------------------------------------- */
.virtual-pad {
  position: relative;
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  background: transparent;
  pointer-events: auto;
  outline: none;
}

/* Hidden entirely on non-touch devices. */
body.no-touch .virtual-pad,
body[data-touch="false"] .virtual-pad,
body:not(.touch):not(.force-touch) .virtual-pad {
  display: none !important;
}

/* Pads should never appear on desktop/TV layouts, even if a stray element exists. */
body.layout-desktop .virtual-pad,
body.desktop .virtual-pad,
body[data-layout="desktop"] .virtual-pad,
body.layout-tv .virtual-pad,
body.tv .virtual-pad,
body[data-layout="tv"] .virtual-pad {
  display: none !important;
}

@media (hover: hover) and (pointer: fine) {
  body:not(.touch):not(.force-touch) .virtual-pad {
    display: none !important;
  }
}

.pad-base,
.virtual-pad .pad-base {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25),
    inset 0 0 30px rgba(0, 0, 0, 0.4);
  opacity: 0.6;
  transition: opacity 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.virtual-pad.held .pad-base,
.virtual-pad.active .pad-base,
.virtual-pad.touching .pad-base {
  opacity: 0.95;
  border-color: var(--accent);
  transform: scale(0.98);
}

.pad-ring,
.virtual-pad .pad-ring {
  position: absolute;
  width: 70px;
  height: 70px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: var(--accent-dim);
  opacity: 0;
  transition: opacity 0.1s ease, transform 0.1s ease;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.virtual-pad.held .pad-ring,
.virtual-pad.active .pad-ring,
.virtual-pad.touching .pad-ring {
  opacity: 1;
}

.pad-direction-name,
.virtual-pad .pad-direction-label {
  position: absolute;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  font: bold 16px/1 monospace;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent);
  opacity: 0;
  transition: opacity 0.1s ease;
  pointer-events: none;
  white-space: nowrap;
}

.virtual-pad.held .pad-direction-name,
.virtual-pad.active .pad-direction-name,
.virtual-pad.touching .pad-direction-name {
  opacity: 1;
}

.pad-direction {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: bold;
  pointer-events: none;
}

.pad-direction.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 0 18px var(--accent);
}

/* -------------------------------------------------------------------------
   Top controls (pause / records / mute)
------------------------------------------------------------------------- */
.top-controls,
#topControls {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  z-index: 40;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 14px;
}

.top-controls button,
#topControls button {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 7px 12px;
  font: bold 13px/1 system-ui, sans-serif;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

.top-controls button:focus-visible,
#topControls button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* -------------------------------------------------------------------------
   Desktop side panel
------------------------------------------------------------------------- */
.side-panel,
#sidePanel {
  display: flex;
  flex-direction: column;
  width: var(--panel-width);
  min-width: var(--panel-width);
  height: 100%;
  background: var(--panel-bg);
  color: #fff;
  border-left: 1px solid var(--panel-border);
  padding: 18px 16px;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 30;
  font-size: 14px;
  line-height: 1.45;
}

.side-panel h2,
#sidePanel h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}

.side-panel section,
#sidePanel section {
  margin: 0 0 20px;
}

.side-panel button,
#sidePanel button {
  font: inherit;
  color: #fff;
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.side-panel button:hover,
#sidePanel button:hover {
  background: #262626;
}

.side-panel button:focus-visible,
#sidePanel button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Full-width desktop, the way the TV and phone layouts already work. The board is 1200x530 (2.26:1), so a 340px
   side column ate a quarter of the width and left the game using 41% of a 1440x900 window while 207px sat empty
   above and below it. The column's two useful panels are not lost: the controls are on the pause screen and the
   records are on R. */
body.layout-desktop #stage,
body.desktop #stage,
body[data-layout="desktop"] #stage {
  display: grid;
  grid-template-rows: 100%;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  justify-items: stretch;
}

body.layout-desktop #game,
body.desktop #game,
body[data-layout="desktop"] #game {
  grid-row: 1;
  grid-column: 1;
  align-self: center;
  justify-self: center;
}

body.layout-desktop .side-panel,
body.layout-desktop #sidePanel,
body.desktop .side-panel,
body.desktop #sidePanel,
body[data-layout="desktop"] .side-panel,
body[data-layout="desktop"] #sidePanel {
  display: none;
}

body.layout-desktop.panel-folded #stage,
body.desktop.panel-folded #stage,
body[data-layout="desktop"][data-panel="folded"] #stage {
  grid-template-columns: minmax(0, 1fr);
}

body.layout-desktop.panel-folded .side-panel,
body.layout-desktop.panel-folded #sidePanel,
body.desktop.panel-folded .side-panel,
body.desktop.panel-folded #sidePanel,
body[data-layout="desktop"][data-panel="folded"] .side-panel,
body[data-layout="desktop"][data-panel="folded"] #sidePanel {
  display: none;
}

/* -------------------------------------------------------------------------
   TV overscan-safe layout and focus
------------------------------------------------------------------------- */
body.layout-tv #stage,
body.tv #stage,
body[data-layout="tv"] #stage {
  padding: var(--tv-safe, 5%);
  box-sizing: border-box;
}

body.overscan-0,
body.tv-overscan-0,
body.layout-tv[data-overscan="0"] {
  --tv-safe: 0%;
}

/* 2% is the default on a modern panel: every point of margin is board the 16:9 screen cannot show */
body.overscan-2,
body.tv-overscan-2,
body.layout-tv[data-overscan="2"] {
  --tv-safe: 2%;
}

body.overscan-5,
body.tv-overscan-5,
body.layout-tv[data-overscan="5"] {
  --tv-safe: 5%;
}

body.overscan-10,
body.tv-overscan-10,
body.layout-tv[data-overscan="10"] {
  --tv-safe: 10%;
}

body.layout-tv .overlay,
body.tv .overlay,
body[data-layout="tv"] .overlay {
  padding: var(--tv-safe, 5%);
}

#hud,
.hud,
.hud-safe {
  position: absolute;
  inset: var(--tv-safe, 0px);
  pointer-events: none;
}

body.layout-tv :focus-visible,
body.tv :focus-visible,
body[data-layout="tv"] :focus-visible,
body.layout-tv :focus,
body.tv :focus,
body[data-layout="tv"] :focus {
  outline: 3px solid var(--accent) !important;
  outline-offset: 3px;
  background-color: rgba(0, 255, 136, 0.07);
  color: #fff;
  border-radius: 10px;
}

/* -------------------------------------------------------------------------
   Overlays, records, options
------------------------------------------------------------------------- */
.overlay,
#recordsOverlay,
#optionsOverlay,
#pauseOverlay,
#helpOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  padding: 24px;
  box-sizing: border-box;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay[hidden],
#recordsOverlay[hidden],
#optionsOverlay[hidden],
#pauseOverlay[hidden],
#helpOverlay[hidden] {
  display: none;
}

.overlay-panel,
.records-panel,
.options-panel {
  width: min(94vw, 720px);
  max-height: 100%;
  background: #0a0a0a;
  border: 1px solid #2b2b2b;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
  overflow: auto;
  box-sizing: border-box;
}

.overlay-panel h2,
.records-panel h2,
.options-panel h2 {
  margin: 0 0 16px;
  color: var(--accent);
  font-size: 22px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.records-row,
.option-row,
.settings-row {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  box-sizing: border-box;
}

.records-row:hover,
.option-row:hover,
.settings-row:hover {
  background: rgba(255, 255, 255, 0.06);
}

.records-row:focus-visible,
.option-row:focus-visible,
.settings-row:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
  background: rgba(0, 255, 136, 0.08);
}

/* -------------------------------------------------------------------------
   Title screen / PRESS OK TO START
------------------------------------------------------------------------- */
.title-screen,
#titleScreen {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
  padding: 32px;
  box-sizing: border-box;
  text-align: center;
}

#titleScreen[hidden],
.title-screen[hidden] {
  display: none;
}

#titleScreen .press-ok,
.title-screen .press-ok {
  font-size: clamp(28px, 8vw, 52px);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--accent);
  animation: titlePulse 1.6s ease-in-out infinite;
  margin: 18px 0 0;
}

#titleScreen .title-small,
.title-screen .title-small {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  margin: 12px 0 0;
}

@keyframes titlePulse {
  0%,
  100% {
    opacity: 0.65;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.04);
  }
}

/* -------------------------------------------------------------------------
   Install button and toast
------------------------------------------------------------------------- */
.install-button {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
}

.install-button.available,
body.install-prompt-available .install-button,
body.install-available .install-button {
  display: inline-flex;
}

.ios-install-line {
  display: none;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.5;
}

body.install-unavailable .ios-install-line,
.ios-install-line.visible {
  display: block;
}

#updateToast,
.update-toast {
  position: fixed;
  bottom: max(24px, var(--tv-safe, 24px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: #0b0b0b;
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 14px;
  display: none;
  box-shadow: 0 12px 40px rgba(0, 255, 136, 0.15);
  box-sizing: border-box;
}

#updateToast.visible,
.update-toast.visible {
  display: flex;
  align-items: center;
  gap: 10px;
}

#updateToast button,
.update-toast button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 700;
}

/* -------------------------------------------------------------------------
   Reduced motion
------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #stage,
  #stage *,
  #rotate-gate,
  #rotate-gate *,
  .virtual-pad,
  .virtual-pad *,
  .overlay,
  .overlay *,
  .title-screen,
  #titleScreen,
  #titleScreen * {
    animation: none !important;
    transition: none !important;
  }

  #rotate-gate .escape-line,
  .rotate-gate .escape-line {
    animation: none !important;
    opacity: 1 !important;
  }
}

/* [hidden] must win over any display rule we set elsewhere, or the desktop panel shows up on phones */
#panel[hidden],
.side-panel[hidden] {
  display: none !important;
}

/* =====================================================================
   Two-thumb virtual pads (created by js/viewport.js). The zones are the
   dark bands that a 16:9 board leaves on a wider phone: they never touch
   the maze, and each side is driven by its own thumb, independently.
   ===================================================================== */
.vp-pad-zone {
  position: fixed;
  z-index: 100;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.vp-pad-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84px;
  height: 84px;
  margin: -42px 0 0 -42px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(16, 24, 32, 0.55), rgba(16, 24, 32, 0.22) 70%, rgba(16, 24, 32, 0.04));
  opacity: 0.6;
  transition: opacity 0.14s linear, border-color 0.14s linear, box-shadow 0.14s linear;
}
.vp-pad-ring::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.34);
  transition: transform 0.1s linear, background 0.1s linear, box-shadow 0.1s linear;
}
.vp-pad-ring.vp-active {
  opacity: 1;
  border-color: #8edb36;
  box-shadow: 0 0 0 3px rgba(142, 219, 54, 0.16);
}
.vp-pad-ring.vp-active::after {
  background: #8edb36;
  box-shadow: 0 0 14px rgba(142, 219, 54, 0.75);
}
.vp-pad-ring.vp-dir-up::after { transform: translateY(-24px); }
.vp-pad-ring.vp-dir-down::after { transform: translateY(24px); }
.vp-pad-ring.vp-dir-left::after { transform: translateX(-24px); }
.vp-pad-ring.vp-dir-right::after { transform: translateX(24px); }
.vp-pad-label {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84px;
  margin: 52px 0 0 -42px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.42);
}
.vp-pad-label:empty { display: none; }

/* js/multiscreen.js publishes the real visible height (iOS toolbars); fall back to 100dvh. */
#stage,
body.layout-phone #stage,
body.layout-desktop #stage,
body.layout-tv #stage {
  height: var(--vvh, 100dvh);
}

/* iOS cannot hide Safari's chrome from a normal page; the only true fullscreen is the installed
   app, so the player is told once how to get there (js/multiscreen.js). */
.install-hint {
  position: fixed;
  left: 50%;
  top: calc(6px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 460px);
  padding: 7px 8px 7px 14px;
  border: 1px solid rgba(142, 219, 54, 0.45);
  border-radius: 999px;
  background: rgba(8, 12, 16, 0.92);
  color: #d8f5b4;
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: 0.02em;
  transition: opacity 0.4s ease;
}
.install-hint b { color: #8edb36; }
.install-hint.gone { opacity: 0; pointer-events: none; }
.install-hint-close {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.update-bar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(8, 12, 16, 0.94);
  color: #eaeaea;
  font-size: 12px;
}
.update-bar button {
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  background: #8edb36;
  color: #0b1206;
  font-weight: 700;
  cursor: pointer;
}

/* ?debug=1 readout: the measured sizes, so a phone screenshot is enough to diagnose a bad fit */
.fit-debug {
  position: fixed;
  left: 4px;
  top: calc(4px + env(safe-area-inset-top, 0px));
  z-index: 300;
  max-width: 60vw;
  padding: 4px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #9ef01a;
  font: 10px/1.35 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

/* Full-screen button (js/multiscreen.js): real fullscreen where the browser allows it, and the
   Add-to-Home-Screen steps on iPhone Safari, which cannot hide its own toolbar. */
.fs-button {
  position: fixed;
  right: calc(8px + env(safe-area-inset-right, 0px));
  top: calc(8px + env(safe-area-inset-top, 0px));
  z-index: 190;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  background: rgba(8, 12, 16, 0.72);
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  transition: border-color 0.15s linear, color 0.15s linear, background 0.15s linear;
}
.fs-button:hover,
.fs-button:focus-visible {
  border-color: #8edb36;
  color: #8edb36;
  background: rgba(8, 12, 16, 0.9);
  outline: none;
}

.fs-help {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
  opacity: 1;
  transition: opacity 0.2s linear;
}
.fs-help.gone { opacity: 0; }
.fs-help-card {
  max-width: 380px;
  padding: 18px 20px 16px;
  border: 1px solid rgba(142, 219, 54, 0.4);
  border-radius: 14px;
  background: #0b0f12;
  color: #e6e6e6;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}
.fs-help-card h2 {
  margin: 0 0 8px;
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8edb36;
}
.fs-help-card p { margin: 0 0 10px; font-size: 13px; line-height: 1.5; color: #b9c2c7; }
.fs-help-card ol { margin: 0 0 14px; padding-left: 20px; font-size: 13px; line-height: 1.7; }
.fs-help-card b { color: #fff; }
.fs-help-close {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #a4e84a 0%, #76c022 100%);
  color: #0b1206;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}

/* In the phone landscape layout the thumb pads own the side bands, so keep the button clear of
   the pad ring: bottom corner of the band instead of the top. */
body.layout-phone-landscape .fs-button,
body.phone-landscape .fs-button {
  top: auto;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
body.layout-phone-landscape .install-hint,
body.phone-landscape .install-hint {
  max-width: min(70vw, 420px);
}

/* TV information band.
   A 16:9 screen is wider than the 60x25 board, so the TV layout always leaves a strip below the canvas. The
   canvas HUD is a 30px strip drawn for a desktop glance, and at living-room distance it is unreadable, so the
   same numbers are repeated here in the space the board cannot use. Position and size are set from the canvas
   rect by syncBand(), because the leftover strip depends on the safe-margin setting. */
#tv-band { display: none; }
body.layout-tv #tv-band,
body.tv #tv-band,
body.layout-desktop #tv-band,
body.desktop #tv-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0 2.2vw;
  position: fixed;
  background: linear-gradient(#121a12, #060906);
  border: 1px solid rgba(142, 219, 54, 0.35);
  border-radius: 10px;
  color: #8EDB36;
  font: 600 30px/1 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 1.5px;
  white-space: nowrap;
  overflow: hidden;
  z-index: 5;
  /* the D-pad drives a pointer in TV mode: never let the band swallow that movement */
  pointer-events: none;
}
#tv-band span { flex: 0 0 auto; }
#tv-band span:nth-child(3) { color: #F2F8EC; }

/* the band needs a smaller type step on a 720p panel, where 30px would not fit seven values */
@media (max-height: 800px) {
  body.layout-tv #tv-band,
  body.tv #tv-band { font-size: 22px; padding: 0 1.4vw; }
}

/* a laptop window is much taller than the 2.26:1 board, so the strip below it is far deeper than a TV's: cap the
   band and centre it in that strip rather than stretching it to 260px */
body.layout-desktop #tv-band,
body.desktop #tv-band { max-height: 120px; }
