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%;
  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;
  width: 62px;
  height: 44px;
  margin: 0;
  padding: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font: 700 13px/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.empty { color: rgba(156, 196, 138, 0.4); border-right-color: rgba(142, 219, 54, 0.15); }
#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,
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;
}

body.layout-desktop #stage,
body.desktop #stage,
body[data-layout="desktop"] #stage {
  display: grid;
  grid-template-rows: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  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 {
  grid-row: 1;
  grid-column: 2;
}

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%;
}

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);
}
