/* =====================================================================
   Pac-Man Arcade
   1. Tokens   2. Base   3. Menu   4. Game layout   5. HUD / controls
   6. Board overlays   7. Dialogs   8. Responsive modes   9. Themes   10. Motion
   ===================================================================== */

/* ------------------------------------------------------------- 1. Tokens */
:root {
  --bg: #060811;
  --bg-2: #101733;
  --accent-text: #ffffff; /* text on --blue (selected options) */
  --btn-text: #1a1500;    /* text on the primary button */
  --panel: rgba(14, 19, 38, 0.86);
  --panel-solid: #0e1326;
  --panel-2: rgba(30, 40, 78, 0.7);
  --line: rgba(130, 150, 230, 0.24);
  --text: #eef2ff;
  --muted: #a7b3d1;
  --yellow: #ffe600;
  --yellow-deep: #b8a400;
  --blue: #3b5bff;
  --cyan: #38e1ff;
  --danger: #ff6b81;
  --good: #4ade80;

  --phase: #2121ff;
  --phase-glow: rgba(33, 70, 255, 0.5);

  --font-pixel: 'Press Start 2P', ui-monospace, monospace;
  --font-ui: 'Rajdhani', system-ui, -apple-system, 'Segoe UI', sans-serif;
  /* Display sizes below are tuned for Press Start 2P, a very wide font; themes with narrower
     display fonts scale them up instead of restating every size. */
  --display-scale: 1;
  --display-weight: 400;

  /* Layout budget. The board size is derived from these fixed heights, so nothing
     depends on guessing how tall the header happens to be. */
  --vh: 100vh;
  --pad: 10px;
  --gap: 8px;
  --hud-h: 58px;
  --bar-h: 46px;
  --ctrl-h: 30px; /* key hints strip; becomes the D-pad height on touch */
  --dpad-h: 180px;
  --dpad-gap: clamp(5px, 1.6vw, 8px);
  --side-w: clamp(120px, 24vw, 230px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --avail-h: calc(var(--vh) - var(--safe-t) - var(--safe-b) - 2 * var(--pad) - var(--hud-h) - var(--bar-h) - var(--ctrl-h) - 3 * var(--gap));
  --board-w: min(100vw - var(--safe-l) - var(--safe-r) - 2 * var(--pad), var(--avail-h) * 19 / 21, 880px);
}

@supports (height: 100dvh) {
  :root { --vh: 100dvh; }
}

html[data-dpad='on'] { --ctrl-h: var(--dpad-h); }

/* ------------------------------------------------------------- 2. Base */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: var(--vh);
  background: radial-gradient(ellipse at 50% 30%, var(--bg-2) 0%, var(--bg) 70%);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed; left: 8px; top: -60px; z-index: 100;
  background: var(--yellow); color: #000; padding: 8px 14px; border-radius: 8px; font-weight: 700;
}
.skip-link:focus { top: 8px; }

.noscript { padding: 24px; text-align: center; }

kbd {
  display: inline-block; min-width: 1.7em; padding: 0 6px; margin: 0 1px;
  font: 700 0.85em var(--font-ui); text-align: center;
  color: var(--text); background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
}

.app { position: relative; min-height: var(--vh); }
.game, .menu { user-select: none; -webkit-user-select: none; }
/* No double-tap zoom anywhere on the game screen (quick repeated taps are normal in play) */
.game { touch-action: manipulation; }

/* Shared buttons */
.btn-primary {
  font-family: var(--font-pixel); font-weight: var(--display-weight);
  font-size: calc(15px * var(--display-scale)); letter-spacing: 1px;
  min-height: 56px; padding: 0 28px;
  color: var(--btn-text); background: var(--yellow);
  border: 0; border-radius: 12px;
  box-shadow: 0 5px 0 var(--yellow-deep), 0 0 24px color-mix(in srgb, var(--yellow) 35%, transparent);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}
.btn-primary:hover { background: color-mix(in srgb, var(--yellow) 70%, #fff); transform: translateY(-2px); box-shadow: 0 7px 0 var(--yellow-deep), 0 0 34px color-mix(in srgb, var(--yellow) 55%, transparent); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--yellow-deep); }
.btn-primary.small { font-size: calc(11px * var(--display-scale)); min-height: 48px; padding: 0 20px; width: 100%; }
.btn-primary:disabled { opacity: 0.5; }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 16px;
  font-weight: 700; font-size: 16px; letter-spacing: 0.4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.btn-ghost:hover { background: rgba(60, 80, 160, 0.55); border-color: rgba(170, 190, 255, 0.5); transform: translateY(-1px); }
.btn-ghost:active { transform: translateY(1px); }
.btn-ghost:disabled { opacity: 0.4; pointer-events: none; }
.btn-ghost.block { width: 100%; }
.btn-ghost.danger { color: var(--danger); border-color: rgba(255, 107, 129, 0.45); }
.btn-ghost.danger.armed { background: rgba(255, 107, 129, 0.25); }
.btn-ghost svg, .icon-btn svg, .dpad-btn svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: rgba(60, 80, 160, 0.55); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.active { border-color: var(--cyan); }
.icon-btn .i-play { display: none; fill: currentColor; }
.icon-btn[data-paused='true'] .i-play { display: block; }
.icon-btn[data-paused='true'] .i-pause { display: none; }
#btnSound .mute { display: none; }
#btnSound[aria-pressed='false'] .wave { display: none; }
#btnSound[aria-pressed='false'] .mute { display: block; }
#btnSound[aria-pressed='false'] { color: var(--muted); }

/* ------------------------------------------------------------- 3. Menu */
.menu {
  position: relative; min-height: var(--vh); height: var(--vh);
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 28px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  overflow-y: auto;
}

/* Fixed to the viewport: the menu scrolls (the game-mode screen is taller than a phone) and the
   background must keep covering the whole screen instead of scrolling away with the first page */
.menu-bg { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.menu-card {
  position: relative; z-index: 1;
  width: min(100%, 440px); margin: auto; /* auto margins center when there is room and never clip the top when there is not */
  padding: 26px 22px 20px;
  display: flex; flex-direction: column; align-items: stretch; gap: 16px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(59, 91, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.menu-hero, .menu-options { display: flex; flex-direction: column; gap: 16px; min-width: 0; animation: rise 0.55s cubic-bezier(0.16, 1, 0.3, 1) both; }
.menu-options { animation-delay: 0.15s; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.logo {
  font-family: var(--font-pixel); font-weight: var(--display-weight);
  font-size: calc(clamp(30px, 10vw, 52px) * var(--display-scale)); line-height: 1; letter-spacing: 2px;
  display: flex; justify-content: center; flex-wrap: wrap;
}
.logo-pac { color: var(--yellow); text-shadow: 0 0 22px rgba(255, 230, 0, 0.7), 0 4px 0 var(--yellow-deep); }
.logo-man {
  color: #fff; text-shadow: 0 0 22px rgba(56, 225, 255, 0.8), 0 4px 0 #1b6a86;
  animation: flicker 5s infinite;
}
@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.55; } 94% { opacity: 1; } 96% { opacity: 0.7; } 97% { opacity: 1; }
}

.tagline { color: var(--muted); font-size: 17px; letter-spacing: 0.4px; }

.lane { display: block; width: 100%; height: auto; max-height: 64px; margin: -4px 0; }

.menu .btn-primary { width: 100%; font-size: calc(clamp(15px, 4vw, 18px) * var(--display-scale)); min-height: 62px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-family: var(--font-pixel); font-size: calc(9px * var(--display-scale)); letter-spacing: 1.5px; color: var(--muted); }
.field-hint { min-height: 1.4em; font-size: 15px; color: var(--muted); }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 14px;
}
.segmented button {
  min-height: 44px; padding: 0 10px;
  font-weight: 700; font-size: 17px; letter-spacing: 0.4px; color: var(--muted);
  background: transparent; border: 0; border-radius: 10px;
  transition: background 0.18s, color 0.18s, transform 0.1s;
}
.segmented button:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.segmented button[aria-checked='true'] {
  color: var(--accent-text);
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue) 82%, #fff), color-mix(in srgb, var(--blue) 88%, #000));
  box-shadow: 0 0 16px color-mix(in srgb, var(--blue) 55%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.segmented button:active { transform: scale(0.97); }

#diffPicker button[data-diff='easy'][aria-checked='true'] { background: linear-gradient(180deg, #34d399, #0f9d6c); box-shadow: 0 0 16px rgba(52, 211, 153, 0.5); }
#diffPicker button[data-diff='hard'][aria-checked='true'] { background: linear-gradient(180deg, #ff6b81, #d12a48); box-shadow: 0 0 16px rgba(255, 107, 129, 0.5); }
#diffPicker button[data-diff='hardcore'][aria-checked='true'] { color: #fff; background: linear-gradient(180deg, #3a0a12, #0a0000); box-shadow: 0 0 0 2px #ff2a2a inset, 0 0 18px rgba(255, 42, 42, 0.6); }
.segmented.four button { padding: 0 4px; font-size: 16px; }

/* Theme picker: five mini previews of the maze style */
.segmented.themes { grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.segmented.themes button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 62px; padding: 6px 2px; font-size: 14px; line-height: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.swatch {
  --sw-bg: #02030a; --sw-wall: #2b5bff; --sw-pac: #ffe600; --sw-dot: #ffdedb;
  position: relative; flex: none; width: 34px; height: 22px;
  background: radial-gradient(circle, var(--sw-dot) 0 1.5px, transparent 2px) 16px 50% / 7px 7px repeat-x, var(--sw-bg);
  border: 2px solid var(--sw-wall); border-radius: 6px;
}
.swatch::after {
  content: ''; position: absolute; left: 3px; top: 50%; width: 10px; height: 10px; margin-top: -5px;
  background: var(--sw-pac); border-radius: 50%;
  clip-path: polygon(100% 15%, 50% 50%, 100% 85%, 100% 100%, 0 100%, 0 0, 100% 0);
}
.swatch[data-sw='classic'] { --sw-bg: #000; --sw-wall: #2121de; --sw-pac: #ffff00; --sw-dot: #ffb8ae; border-radius: 7px; }
.swatch[data-sw='retro'] { --sw-bg: #000; --sw-wall: #2038ec; --sw-pac: #f8d800; --sw-dot: #fca044; border-width: 3px; border-radius: 0; box-shadow: inset 1px 1px 0 #8fa0ff; }
.swatch[data-sw='retro']::after { border-radius: 0; }
.swatch[data-sw='pastel'] { --sw-bg: #2a2140; --sw-wall: #ff9aa8; --sw-pac: #ffd76e; --sw-dot: #fff1e6; border-width: 3px; border-radius: 9px; }
.swatch[data-sw='minimal'] { --sw-bg: #000; --sw-wall: #fff; --sw-pac: #fff; --sw-dot: #fff; border-width: 3px; border-radius: 0; box-shadow: 3px 3px 0 #fff; }
.swatch[data-sw='minimal']::after { border-radius: 50%; }

.menu-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.menu-links .btn-ghost { flex-direction: column; gap: 4px; min-height: 64px; padding: 8px 4px; font-size: 14px; line-height: 1.1; }

/* ---- Game-mode screen ---- */
/* The logo and lane step aside so the choices fit; wide screens lay them out in two columns */
.menu-card[data-view='setup'] { width: min(100%, 480px); flex-direction: column; }
.menu-card[data-view='setup'] .menu-hero { display: none; }
.setup-cols { display: flex; flex-direction: column; gap: 14px; }
.setup-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.setup-foot { display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 760px) {
  .menu-card[data-view='setup'] { width: min(100%, 880px); }
  .setup-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
}

/* Mode: two cards with icon, pitch and personal best */
.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0;
  padding: 12px 12px 10px; text-align: left; color: var(--muted);
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 14px;
  transition: border-color 0.18s, background 0.18s, color 0.18s, transform 0.1s;
}
.mode-card:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }
.mode-card:active { transform: scale(0.98); }
.mode-card[aria-checked='true'] {
  color: #fff; border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 22%, rgba(0, 0, 0, 0.4));
  box-shadow: 0 0 18px color-mix(in srgb, var(--blue) 45%, transparent), inset 0 0 0 1px var(--blue);
}
.mode-icon { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mode-card[aria-checked='true'] .mode-icon { stroke: var(--yellow); }
.mode-name { font-weight: 700; font-size: 18px; line-height: 1.1; }
.mode-desc { font-size: 14px; line-height: 1.2; color: var(--muted); }
.mode-best { margin-top: 2px; font-size: 13px; color: var(--muted); }
.mode-best.has-record { color: var(--yellow); }

/* Difficulty: name + lives (dots) + ghost speed (bars); Custom spans the full row */
.segmented.diff-grid { grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.diff-grid button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px 2px; font-size: clamp(13px, 4vw, 16px); min-height: 58px; }
.diff-grid button > span:first-child { max-width: 100%; overflow-wrap: anywhere; line-height: 1.05; } /* long names (Difficile) shrink, then wrap, instead of overflowing */
.diff-grid .diff-custom { grid-column: 1 / -1; flex-direction: row; gap: 8px; min-height: 44px; font-size: 15px; }
.diff-custom svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.diff-meta { display: flex; align-items: center; gap: 6px; }
.pips { display: flex; gap: 2px; }
.pips i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.bars { display: flex; align-items: flex-end; gap: 1.5px; height: 9px; }
.bars i { width: 3px; background: currentColor; opacity: 0.25; }
.bars i:nth-child(1) { height: 3px; } .bars i:nth-child(2) { height: 5px; } .bars i:nth-child(3) { height: 7px; } .bars i:nth-child(4) { height: 9px; }
.bars i.on { opacity: 1; }
#diffPicker button[data-diff='hardcore'][aria-checked='true'] { animation: hc-pulse 1.6s ease-in-out infinite; }
@keyframes hc-pulse {
  0%, 100% { box-shadow: 0 0 0 2px #ff2a2a inset, 0 0 10px rgba(255, 42, 42, 0.4); }
  50% { box-shadow: 0 0 0 2px #ff2a2a inset, 0 0 24px rgba(255, 42, 42, 0.85); }
}

/* Custom difficulty sliders */
.custom-panel { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 12px; }
.custom-row { display: grid; grid-template-columns: 7.5em 1fr 44px; align-items: center; gap: 10px; text-align: left; }
.custom-label { font-size: 15px; font-weight: 700; line-height: 1.1; }
.custom-row .vol-val { font-size: 15px; text-align: right; color: var(--muted); }

/* Start stage (Endless): dots in each stage's color, locked ones dimmed */
.segmented.stages button { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 4px; }
.stage-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--stage, var(--blue)); box-shadow: 0 0 8px var(--stage, transparent); }
.segmented.stages button.locked { opacity: 0.38; cursor: not-allowed; }
.segmented.stages button.locked .stage-dot { background: transparent; border: 2px solid currentColor; box-shadow: none; }

/* Character picker: each button shows the character drawn in the current theme */
.segmented.chars { grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.segmented.chars button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 64px; padding: 4px 2px; font-size: 14px; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-cv { width: 34px; height: 34px; flex: none; }

.theme-preview { display: block; width: 100%; height: 88px; border: 1px solid var(--line); border-radius: 12px; background: #000; }

.setup-summary { font-size: 14px; color: var(--muted); letter-spacing: 0.3px; }
.best-line.muted { color: var(--muted); }
.quick-play { justify-content: center; gap: 10px; }
.quick-play svg { width: 18px; height: 18px; fill: currentColor; }
.qp-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; text-align: left; }
.qp-text small { font-size: 13px; font-weight: 600; color: var(--muted); }

/* Bounce on the option just picked */
.pop { animation: pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop { 0% { transform: scale(0.92); } 100% { transform: scale(1); } }

/* Game-mode screen: back arrow + title, then the pickers and PLAY */
.setup-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; }
.setup-head .icon-btn { width: 44px; height: 44px; }
.setup-title {
  font-family: var(--font-pixel); font-weight: var(--display-weight);
  font-size: calc(clamp(12px, 3.6vw, 15px) * var(--display-scale)); letter-spacing: 1.5px; line-height: 1.3;
  color: var(--yellow);
}

.best-line { font-size: 15px; color: var(--yellow); letter-spacing: 0.5px; }
.best-line.has-record::before {
  content: ''; display: inline-block; width: 1.1em; height: 1.1em; margin-right: 6px; vertical-align: -0.2em; background: currentColor;
  -webkit-mask: var(--trophy) center / contain no-repeat; mask: var(--trophy) center / contain no-repeat;
}
.menu-foot { position: relative; z-index: 1; margin-top: 12px; font-size: 14px; color: var(--muted); text-align: center; }

/* ------------------------------------------------------------- 4. Game layout */
.game {
  min-height: var(--vh); height: var(--vh);
  padding: calc(var(--safe-t) + var(--pad)) calc(var(--safe-r) + var(--pad)) calc(var(--safe-b) + var(--pad)) calc(var(--safe-l) + var(--pad));
  display: grid;
  grid-template-columns: var(--board-w);
  grid-template-areas: 'hud' 'board' 'bar' 'ctrl';
  justify-content: center;
  align-content: center;
  row-gap: var(--gap);
}

.hud { grid-area: hud; height: var(--hud-h); }
.board-wrap { grid-area: board; width: var(--board-w); }
.toolbar { grid-area: bar; height: var(--bar-h); }
.dpad, .key-hints { grid-area: ctrl; }

/* ------------------------------------------------------------- 5. HUD and controls */
.hud {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: var(--gap);
}
.stat {
  display: flex; flex-direction: column; justify-content: center; gap: 4px; min-width: 0;
  padding: 6px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.stat-best { align-items: flex-end; text-align: right; }
.stat-label { font-family: var(--font-pixel); font-size: calc(8px * var(--display-scale)); letter-spacing: 1px; color: var(--muted); line-height: 1; }
.stat-val { font-family: var(--font-pixel); font-size: calc(clamp(11px, 3.4vw, 15px) * var(--display-scale)); line-height: 1.1; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.stat-score .stat-val { color: var(--yellow); display: inline-block; transform-origin: left center; }
.stat-score .stat-val.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 50% { transform: scale(1.18); } }

.stage-badge {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; max-width: 34vw;
  padding: 6px 12px; text-align: center;
  background: color-mix(in srgb, var(--phase) 18%, transparent);
  border: 1px solid var(--phase); border-radius: 12px;
  box-shadow: 0 0 18px var(--phase-glow);
  transition: border-color 0.4s, box-shadow 0.4s;
}
.stage-num { font-family: var(--font-pixel); font-size: calc(8px * var(--display-scale)); letter-spacing: 1px; color: var(--text); white-space: nowrap; }
.stage-name { font-size: 15px; font-weight: 700; color: color-mix(in srgb, var(--phase) 55%, #fff); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.board {
  position: relative; width: 100%; aspect-ratio: 19 / 21;
  background: #000; border: 3px solid var(--phase); border-radius: 12px; overflow: hidden;
  box-shadow: 0 0 28px var(--phase-glow), 0 18px 40px rgba(0, 0, 0, 0.6);
  transition: border-color 0.4s, box-shadow 0.4s;
  touch-action: none;
}
#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.lives { display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 72px; padding: 6px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; height: 100%; }
.lives-icons { display: flex; gap: 4px; align-items: center; min-height: 14px; }
.life-icon {
  width: 14px; height: 14px; background: var(--yellow); border-radius: 50%;
  clip-path: polygon(100% 0, 100% 28%, 50% 50%, 100% 72%, 100% 100%, 0 100%, 0 0);
  transform: rotate(-14deg);
}
.life-more { font-family: var(--font-pixel); font-size: calc(8px * var(--display-scale)); color: var(--yellow); }
.fruit-chip { width: 26px; height: 26px; filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.35)); }
.tool-buttons { display: flex; gap: 6px; }

.dpad {
  position: relative; width: var(--dpad-h); height: var(--dpad-h);
  display: none; justify-self: center; margin-top: 0; /* centered: both thumbs can reach it */
  touch-action: none; -webkit-tap-highlight-color: transparent; /* the gaps belong to the pad too: no zoom or scroll */
}
html[data-dpad='on'] .dpad { display: block; }
html[data-dpad='on'] .key-hints { display: none; }
/* The four arrows sit slightly apart (--dpad-gap), so a thumb on one never brushes its neighbour */
.dpad-btn {
  --size: calc((100% - 2 * var(--dpad-gap)) / 3);
  position: absolute; width: var(--size); height: var(--size);
  display: grid; place-items: center; color: #dbe4ff;
  background: rgba(36, 48, 96, 0.85); border: 1px solid rgba(190, 205, 255, 0.28); border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  touch-action: none; -webkit-tap-highlight-color: transparent;
  transition: background 0.06s, transform 0.06s;
}
.dpad-btn svg { width: 46%; height: 46%; fill: currentColor; stroke: none; }
.dpad-btn.pressed { background: var(--blue); color: var(--accent-text); transform: scale(0.94); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.dpad-btn.up { top: 0; left: calc(var(--size) + var(--dpad-gap)); }
.dpad-btn.left { top: calc(var(--size) + var(--dpad-gap)); left: 0; }
.dpad-btn.right { top: calc(var(--size) + var(--dpad-gap)); right: 0; }
.dpad-btn.down { bottom: 0; left: calc(var(--size) + var(--dpad-gap)); }

.key-hints {
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 4px 16px;
  height: var(--ctrl-h); overflow: hidden;
  font-size: 14px; color: var(--muted);
}

/* ------------------------------------------------------------- 6. Board overlays */
.power-bar { position: absolute; left: 0; right: 0; top: 0; height: 5px; background: rgba(0, 0, 0, 0.5); z-index: 3; }
.power-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), #8b5cf6); transform-origin: left center; }
.power-bar.ending i { animation: blink 0.4s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

.coach {
  position: absolute; left: 8%; right: 8%; top: 7%; z-index: 4; padding: 10px 14px;
  text-align: center; font-size: clamp(14px, 3.8vw, 18px); font-weight: 700; line-height: 1.25; color: #fff;
  background: rgba(8, 12, 30, 0.88); border: 1px solid var(--cyan); border-radius: 12px;
  box-shadow: 0 0 20px rgba(56, 225, 255, 0.3);
  pointer-events: none; animation: rise 0.35s ease-out;
}

.overlay {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px;
  background: rgba(4, 6, 16, 0.82); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  touch-action: manipulation;
}

.modal {
  width: min(100%, 320px); max-height: 100%; overflow-y: auto; padding: 18px 16px;
  text-align: center; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.7);
  animation: pop 0.22s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(0.93); } to { opacity: 1; transform: none; } }
.modal h2 { font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(clamp(12px, 4vw, 16px) * var(--display-scale)); line-height: 1.4; color: var(--yellow); text-shadow: 0 0 14px rgba(255, 230, 0, 0.6); margin-bottom: 14px; }
.modal-icon { font-size: 40px; line-height: 1; margin-bottom: 8px; color: var(--yellow); filter: drop-shadow(0 0 10px color-mix(in srgb, currentColor 45%, transparent)); }
.modal-icon[data-icon='ghost'] { color: var(--danger); }
.modal-text { margin-bottom: 12px; font-size: 17px; color: var(--muted); }
.new-best { margin-bottom: 12px; font-family: var(--font-pixel); font-size: calc(9px * var(--display-scale)); line-height: 1.5; color: var(--good); animation: blink 1s steps(2) infinite; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.modal.briefing { border: 2px solid var(--next, var(--blue)); box-shadow: 0 0 34px var(--next-glow, rgba(59, 91, 255, 0.5)); }
.modal.briefing h2 { color: var(--next, var(--cyan)); text-shadow: 0 0 14px currentColor; margin-bottom: 12px; }
.briefing-badge { margin-bottom: 4px; font-size: 14px; font-weight: 700; letter-spacing: 1.2px; color: #facc15; }
.features { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.features li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.feat-icon { flex: none; width: 30px; font-size: 22px; text-align: center; color: var(--next, var(--cyan)); display: grid; place-items: center; }
.fruit-cv { width: 30px; height: 30px; display: block; }
.feat-info { display: flex; flex-direction: column; min-width: 0; }
.feat-info small { font-size: 11px; letter-spacing: 1px; color: var(--muted); }
.feat-info b { font-size: 16px; line-height: 1.15; }
.bonus-line { margin-bottom: 12px; padding: 6px 10px; font-size: 15px; color: #fde68a; background: rgba(234, 179, 8, 0.14); border: 1px dashed rgba(234, 179, 8, 0.45); border-radius: 10px; }
.bonus-line b { font-family: var(--font-pixel); font-size: calc(10px * var(--display-scale)); color: #facc15; }
#btnStartPhase { background: var(--next, var(--yellow)); color: var(--next-text, #0b0d1a); }

.toasts { position: fixed; top: calc(var(--safe-t) + 12px); left: 0; right: 0; z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  padding: 8px 16px; font-weight: 700; font-size: 16px;
  background: rgba(10, 14, 32, 0.95); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: rise 0.25s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast.good { border-color: var(--good); color: var(--good); }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* ------------------------------------------------------------- 7. Dialogs */
.dialog {
  width: min(94vw, 560px); max-height: min(88dvh, 720px); padding: 0; overflow: hidden;
  color: var(--text); background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.75), 0 0 50px rgba(59, 91, 255, 0.2);
}
.dialog[open] { display: flex; flex-direction: column; animation: pop 0.22s ease-out; }
.dialog::backdrop { background: rgba(2, 4, 12, 0.78); backdrop-filter: blur(5px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(clamp(11px, 3.4vw, 14px) * var(--display-scale)); color: var(--yellow); line-height: 1.4; }

.steps { flex: 1; overflow-y: auto; padding: 18px 20px; user-select: text; }
.step h3 { margin-bottom: 8px; font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(12px * var(--display-scale)); line-height: 1.5; color: var(--cyan); }
.step > p { margin-bottom: 14px; font-size: 18px; color: var(--text); }
.step .note { margin-top: 12px; color: var(--yellow); font-size: 16px; }

.control-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.control-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px; text-align: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.control-card svg { width: 56px; height: 56px; fill: none; stroke: var(--cyan); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.control-card b { font-size: 17px; }
.control-card small { font-size: 14px; color: var(--muted); line-height: 1.2; }
.keycaps { min-height: 56px; display: grid; place-items: center; line-height: 1.5; }
.swipe-demo .finger { fill: var(--yellow); stroke: none; animation: swipe 1.8s ease-in-out infinite; }
@keyframes swipe { 0%, 15% { transform: translateX(0); opacity: 1; } 70% { transform: translateX(30px); opacity: 1; } 100% { transform: translateX(34px); opacity: 0; } }

.sprite-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.sprite-card { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 88px; padding: 10px 8px; text-align: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.sprite-card b { font-size: 16px; }
.sprite-card small { color: var(--yellow); font-weight: 700; }

.ghost-list { display: flex; flex-direction: column; gap: 8px; }
.ghost-list li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.ghost-list span { display: flex; flex-direction: column; }
.ghost-list b { font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(10px * var(--display-scale)); margin-bottom: 4px; }
.ghost-list small { font-size: 16px; color: var(--text); line-height: 1.2; }
.g-blinky { color: #ff2a2a; } .g-pinky { color: #ffb8ff; } .g-inky { color: #22e6ff; } .g-clyde { color: #ffb852; }

.tips { display: flex; flex-direction: column; gap: 10px; }
.tips li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; font-size: 17px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.tip-icon { flex: none; font-size: 24px; width: 30px; text-align: center; color: var(--cyan); display: grid; place-items: center; }

.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.dialog-foot .btn-primary.small { width: auto; min-width: 120px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); transition: background 0.2s, transform 0.2s; }
.dots i.on { background: var(--yellow); transform: scale(1.35); }

.settings-list { overflow-y: auto; padding: 8px 20px 18px; user-select: none; }
.setting { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting-text { display: flex; flex-direction: column; min-width: 0; }
.setting-text b { font-size: 18px; }
.setting-text small { font-size: 14px; color: var(--muted); line-height: 1.2; }
.setting .segmented { flex: none; min-width: 150px; }
.setting .segmented button { font-size: 15px; }
/* Collapsible section (Languages): the arrow next to the title opens or closes it */
.setting-group { border-bottom: 1px solid var(--line); }
.setting-group > summary {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 10px 0;
  list-style: none; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}
.setting-group > summary::-webkit-details-marker { display: none; }
.setting-group > summary b { font-size: 18px; }
.setting-group > summary:focus-visible { outline: 3px solid #fff; outline-offset: 2px; border-radius: 8px; }
.setting-group .chevron {
  flex: none; width: 20px; height: 20px; color: var(--muted);
  fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 0.2s ease-out;
}
.setting-group[open] .chevron { transform: rotate(90deg); color: var(--yellow); }
.group-value { margin-left: auto; font-size: 15px; color: var(--muted); }
.lang-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; padding: 0 0 14px; }
.lang-list button {
  min-height: 44px; padding: 0 14px; text-align: left;
  font-weight: 700; font-size: 16px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  transition: background 0.15s, color 0.15s;
}
.lang-list button:hover { color: var(--text); }
.lang-list button[aria-checked='true'] { color: var(--accent-text); background: var(--blue); border-color: transparent; }
.setting.stacked { flex-direction: column; align-items: stretch; gap: 10px; text-align: left; }
.setting.stacked .segmented { min-width: 0; }
.setting .segmented.themes button { font-size: 14px; }

.setting input[type='checkbox'] { position: absolute; right: 0; top: 50%; width: 52px; height: 30px; margin: -15px 0 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch { flex: none; position: relative; width: 52px; height: 30px; background: rgba(255, 255, 255, 0.14); border-radius: 999px; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); transition: transform 0.2s; }
input:checked + .switch { background: var(--blue); }
input:checked + .switch::after { transform: translateX(22px); }
input:focus-visible + .switch { outline: 3px solid #fff; outline-offset: 2px; }
input:disabled { cursor: not-allowed; }
input:disabled + .switch { opacity: 0.35; }

/* Volume sliders sit right under their on/off switch */
.setting:has(+ .volume) { border-bottom: 0; padding-bottom: 6px; }
.setting.volume { padding: 0 0 14px; gap: 12px; }
.volume input[type='range'] {
  --fill: 100%;
  flex: 1; min-width: 0; height: 30px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.volume input[type='range']::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: linear-gradient(to right, var(--blue) var(--fill), rgba(255, 255, 255, 0.14) var(--fill)); }
.volume input[type='range']::-moz-range-track { height: 8px; border-radius: 999px; background: linear-gradient(to right, var(--blue) var(--fill), rgba(255, 255, 255, 0.14) var(--fill)); }
.volume input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -8px; background: #fff; border: 0; border-radius: 50%; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
.volume input[type='range']::-moz-range-thumb { width: 24px; height: 24px; background: #fff; border: 0; border-radius: 50%; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
.volume input[type='range']:focus-visible { outline: 3px solid #fff; outline-offset: 2px; border-radius: 999px; }
.vol-val { flex: none; width: 4ch; text-align: right; font-size: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }

.scores-filters { display: flex; flex-direction: column; gap: 8px; padding: 14px 20px 0; }
.scores-body { overflow-y: auto; padding: 10px 20px 20px; user-select: text; }
.scores-table { width: 100%; border-collapse: collapse; font-size: 17px; }
.scores-table th { padding: 6px 8px; font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(8px * var(--display-scale)); letter-spacing: 1px; color: var(--muted); text-align: left; }
.scores-table td { padding: 7px 8px; border-top: 1px solid var(--line); }
.scores-table td:nth-child(1) { width: 2.4em; font-weight: 700; color: var(--muted); }
.scores-table td:nth-child(2) { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; overflow-wrap: anywhere; line-height: 1.15; }
.scores-table td:nth-child(3) { font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(11px * var(--display-scale)); color: var(--yellow); }
.scores-table td:nth-child(4) { color: var(--muted); }
.scores-table tbody tr:nth-child(1) td:nth-child(1) { color: #ffd54a; }
.scores-table tbody tr:nth-child(2) td:nth-child(1) { color: #cfd8e3; }
.scores-table tbody tr:nth-child(3) td:nth-child(1) { color: #d9985f; }
.scores-table tr.empty td { opacity: 0.4; }
.scores-foot { margin-top: 14px; font-size: 15px; color: var(--muted); }

.rank-line { margin-bottom: 12px; font-size: 18px; font-weight: 700; color: var(--cyan); }
.initials-field { display: block; margin-bottom: 14px; }
.initials-field .field-label { display: block; margin-bottom: 8px; }
#initialsInput {
  width: min(100%, 14em); padding: 10px 12px;
  font-weight: 700; font-size: 24px;
  letter-spacing: 0.5px; text-align: center;
  color: var(--yellow); caret-color: var(--yellow); background: var(--panel-2);
  border: 2px solid var(--line); border-radius: 12px;
}
#initialsInput:focus { outline: 0; border-color: var(--yellow); box-shadow: 0 0 18px color-mix(in srgb, var(--yellow) 40%, transparent); }
/* Credits */
.credits-row .btn-ghost { flex: none; width: auto; min-width: 96px; min-height: 44px; padding: 0 16px; }
.credits { flex: 1; overflow-y: auto; padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 16px; user-select: text; }
.credits-hero { display: flex; align-items: center; gap: 14px; }
.credits-hero canvas { flex: none; width: 56px; height: 56px; }
.credits-by { font-size: 15px; color: var(--muted); }
.credits-name { font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(clamp(12px, 3.6vw, 15px) * var(--display-scale)); line-height: 1.4; color: var(--yellow); }
.credits-block h3 { margin-bottom: 6px; font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(10px * var(--display-scale)); letter-spacing: 1px; line-height: 1.5; color: var(--cyan); }
.credits-block p { font-size: 17px; line-height: 1.35; }
.credits-block p + p { margin-top: 8px; }
.credits-links { display: flex; flex-wrap: wrap; gap: 8px; }
.credits-links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; font-weight: 700; color: var(--text); text-decoration: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.credits-links a:hover, .credits-links a:focus-visible { border-color: var(--yellow); color: var(--yellow); }
.credits-foot { font-size: 14px; color: var(--muted); line-height: 1.3; }
html:is([data-theme='retro'], [data-theme='minimal']) .credits-links a { border-radius: 0; }

/* Theme switch (View Transitions API, see MenuUI.switchTheme). Discreet on purpose: the old
   picture stays still and only the new one comes in, each theme with an effect in its own style. */
::view-transition-old(root) { animation: none; }
::view-transition-new(root) { mix-blend-mode: normal; animation: vt-fade 0.25s ease-out both; }
/* Classic: drawn from top to bottom, like the beam of an arcade monitor */
html[data-vt='classic']::view-transition-new(root) { animation: vt-scan 0.3s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
/* Retro: the same sweep in chunky 8-bit steps */
html[data-vt='retro']::view-transition-new(root) { animation: vt-scan 0.28s steps(8, end) both; }
/* Pastel: a soft, dreamy dissolve */
html[data-vt='pastel']::view-transition-new(root) { animation: vt-dream 0.32s ease-out both; }
/* Minimal: a hard, straight cut from left to right */
html[data-vt='minimal']::view-transition-new(root) { animation: vt-cut 0.22s linear both; }
@keyframes vt-fade { from { opacity: 0; } }
@keyframes vt-scan { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes vt-dream { from { opacity: 0; filter: blur(6px); transform: scale(0.985); } }
@keyframes vt-cut { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.install-steps { padding: 18px 20px 22px 44px; list-style: decimal; display: flex; flex-direction: column; gap: 12px; font-size: 18px; }
.install-btn { margin-top: 4px; }

/* ------------------------------------------------------------- 8. Responsive modes */

/* Touch-sized targets */
@media (pointer: coarse) {
  .icon-btn { width: 48px; height: 48px; }
  .btn-ghost { min-height: 48px; }
  .segmented button { min-height: 48px; }
  .menu-foot { display: none; } /* keyboard hints are noise on a phone */
  .segmented.themes button { min-height: 56px; }
}

/* Very narrow phones */
@media (max-width: 380px) {
  :root { --pad: 6px; --gap: 6px; --hud-h: 54px; }
  .stat { padding: 5px 8px; }
  .stage-name { font-size: 13px; }
  .menu-card { padding: 20px 14px 16px; gap: 14px; }
  .tool-buttons { gap: 4px; }
  .icon-btn { width: 44px; height: 44px; }
  .menu-links .btn-ghost { font-size: 13px; }
  .segmented.themes button { font-size: 12px; }
  .swatch { width: 30px; }
}

/* Laptops and other wide, short windows: menu in two columns so it fits without scrolling */
@media (min-width: 600px) and (max-height: 860px) {
  .menu-card { width: min(100%, 860px); flex-direction: row; align-items: center; gap: 28px; padding: 22px 26px; }
  .menu-hero, .menu-options { flex: 1 1 0; gap: 14px; }
  .logo { font-size: clamp(28px, 4.2vw, 44px); }
  .menu .btn-primary { min-height: 56px; }
  .field-hint { min-height: 0; }
}
/* Phones in portrait: slightly tighter rhythm so every theme fits without scrolling */
@media (max-width: 480px) {
  .menu-card { gap: 13px; }
  .menu-hero, .menu-options { gap: 13px; }
  .field { gap: 6px; }
  html[data-theme='pastel'] .lane { padding: 3px 6px; }
}
@media (max-height: 700px) {
  .menu { padding-top: calc(var(--safe-t) + 14px); padding-bottom: calc(var(--safe-b) + 10px); }
  .menu-foot { display: none; }
  .lane { max-height: 44px; }
  .tagline { display: none; }
  .menu-card { padding-top: 18px; padding-bottom: 14px; gap: 12px; }
  .menu-hero, .menu-options { gap: 12px; }
  .menu .btn-primary { min-height: 54px; }
  .field { gap: 6px; }
  .segmented.themes button { min-height: 52px; gap: 4px; }
}
/* Short phones in portrait: the selected option already says enough */
@media (max-height: 700px) and (max-width: 599px) {
  .field-hint { display: none; }
  .segmented button { min-height: 44px; }
  .lane { max-height: 38px; }
}
@media (max-height: 480px) {
  .menu { padding-top: calc(var(--safe-t) + 10px); padding-bottom: calc(var(--safe-b) + 6px); }
  .menu-card { padding: 10px 16px; gap: 18px; }
  .menu-hero, .menu-options { gap: 8px; }
  .field { gap: 4px; }
  .field-hint { display: none; }
  .segmented button { min-height: 38px; }
  .segmented.themes button { min-height: 42px; gap: 3px; font-size: 12px; }
  .swatch { width: 26px; height: 15px; border-width: 2px; }
  .swatch::after { width: 7px; height: 7px; margin-top: -3.5px; left: 2px; }
  .menu-links .btn-ghost { min-height: 48px; }
  .menu .btn-primary { min-height: 48px; }
}
@media (max-height: 400px) {
  .menu { padding-top: calc(var(--safe-t) + 8px); }
  .menu-links .btn-ghost { min-height: 44px; padding: 4px; }
  .menu-hero, .menu-options { gap: 6px; }
  .best-line { font-size: 14px; }
}

/* Phones in landscape / any short, wide window: board in the middle, HUD and controls on the sides */
@media (orientation: landscape) and (max-height: 640px) {
  :root {
    --pad: 8px;
    --board-w: min((var(--vh) - var(--safe-t) - var(--safe-b) - 2 * var(--pad)) * 19 / 21,
                   100vw - var(--safe-l) - var(--safe-r) - 2 * var(--side-w) - 2 * var(--pad) - 2 * var(--gap));
  }
  .game {
    grid-template-columns: var(--side-w) var(--board-w) var(--side-w);
    grid-template-rows: auto 1fr;
    grid-template-areas: 'hud board ctrl' 'bar board ctrl';
    column-gap: var(--gap);
    row-gap: var(--gap);
    align-content: stretch;
  }
  .hud { height: auto; grid-template-columns: 1fr; grid-auto-flow: row; }
  .stat, .stat-best { align-items: flex-start; text-align: left; flex-direction: row; justify-content: space-between; align-items: center; }
  .stat-val { font-size: 12px; }
  .stage-badge { max-width: none; }
  .toolbar { height: auto; flex-direction: column; align-items: stretch; align-self: end; }
  .lives { height: auto; }
  .fruit-chip { display: none; }
  .tool-buttons { justify-content: space-between; }
  .dpad, .key-hints { align-self: center; justify-self: center; }
  .dpad { --dpad-h: min(180px, calc(var(--vh) - 2 * var(--pad) - var(--safe-t) - var(--safe-b))); width: var(--dpad-h); height: var(--dpad-h); }
  .key-hints { flex-direction: column; height: auto; }
  .board-wrap { grid-area: board; align-self: center; }
}

/* Large desktop windows: let the HUD breathe a little more */
@media (min-width: 900px) and (min-height: 760px) {
  :root { --hud-h: 66px; --bar-h: 52px; --pad: 16px; --gap: 10px; }
  .stat-val { font-size: 17px; }
  .stage-num { font-size: 9px; }
  .stage-name { font-size: 17px; }
  .key-hints { font-size: 15px; }
}

/* ------------------------------------------------------------- 9. Themes
   The tokens in :root are the shared base; each theme overrides them below.
   The board itself is drawn by src/game.js from src/themes.js. */

/* Classic: arcade black and blue, double-ruled panels */
html[data-theme='classic'] {
  --bg: #000000; --bg-2: #000000;
  --panel: rgba(0, 0, 0, 0.9); --panel-solid: #000000; --panel-2: rgba(33, 33, 222, 0.16);
  --line: rgba(70, 70, 255, 0.55); --text: #ffffff; --muted: #c4c4ea;
  --yellow: #ffff00; --yellow-deep: #a39a00; --blue: #2121de; --cyan: #00ffff;
}
html[data-theme='classic'] .menu-card { border: 4px double #3a3aff; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7); backdrop-filter: none; -webkit-backdrop-filter: none; }
html[data-theme='classic'] .logo-pac { text-shadow: 0 4px 0 #a39a00; }
html[data-theme='classic'] .logo-man { color: #ffb8ff; text-shadow: 0 4px 0 #8a3c8a; }

/* Retro: square 8-bit panels, hard drop shadows, CRT scanlines on the board */
html[data-theme='retro'] {
  --bg: #0c0c14; --bg-2: #161628;
  --panel: #14142a; --panel-solid: #14142a; --panel-2: #222248;
  --line: #3e3e80; --text: #fcfcfc; --muted: #bcbcfc;
  --yellow: #f8d800; --yellow-deep: #ac7c00; --blue: #2038ec; --cyan: #3cbcfc;
  /* 8-bit console: a blocky pixel display face and a CRT terminal font for reading */
  --font-pixel: 'Silkscreen', ui-monospace, monospace;
  --font-ui: 'VT323', ui-monospace, monospace;
  --display-scale: 1.3;
}
html:is([data-theme='retro'], [data-theme='minimal']) #initialsInput { border-radius: 0; }
html:is([data-theme='retro'], [data-theme='minimal']) .volume input[type='range']::-webkit-slider-runnable-track,
html:is([data-theme='retro'], [data-theme='minimal']) .volume input[type='range']::-webkit-slider-thumb { border-radius: 0; }
html:is([data-theme='retro'], [data-theme='minimal']) .volume input[type='range']::-moz-range-track,
html:is([data-theme='retro'], [data-theme='minimal']) .volume input[type='range']::-moz-range-thumb { border-radius: 0; }
html:is([data-theme='retro'], [data-theme='minimal']) :is(.menu-card, .setting-group, .lang-list button, .stat, .stage-badge, .board, .lives, .icon-btn, .btn-ghost,
  .btn-primary, .segmented, .segmented button, .modal, .dialog, .dpad-btn, .features li, .bonus-line, .control-card,
  .sprite-card, .ghost-list li, .tips li, .toast, .coach, .switch, .switch::after, kbd,
  .mode-card, .theme-preview, .custom-panel) { border-radius: 0; }
html[data-theme='retro'] .menu-card { border: 3px solid var(--line); box-shadow: 8px 8px 0 #000; backdrop-filter: none; -webkit-backdrop-filter: none; }
html[data-theme='retro'] .btn-primary { box-shadow: 5px 5px 0 #000; }
html[data-theme='retro'] .btn-primary:hover { box-shadow: 7px 7px 0 #000; }
html[data-theme='retro'] .btn-primary:active { box-shadow: 1px 1px 0 #000; transform: translate(4px, 4px); }
html[data-theme='retro'] .segmented button[aria-checked='true'] { background: var(--blue); box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.25); }
html[data-theme='retro'] .logo-pac { text-shadow: 4px 4px 0 #ac3800; }
html[data-theme='retro'] .logo-man { text-shadow: 4px 4px 0 #2038ec; animation: none; }
html[data-theme='retro'] .board { border-width: 4px; box-shadow: 8px 8px 0 #000; }
html[data-theme='retro'] .board::after {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
}
html[data-theme='retro'] #gameCanvas { image-rendering: pixelated; }
html[data-theme='retro'] body { font-synthesis: none; } /* VT323 has one weight; fake bold smears the pixels */

html[data-theme='retro'] .power-bar i { background: #3cbcfc; }

/* Pastel: "candy night". Same dark family as the other themes, but with its own shapes:
   bubbly pill controls, a sticker logo, floating bubbles and the attract lane on a rounded screen. */
html[data-theme='pastel'] {
  --bg: #171126; --bg-2: #2a1d40; --screen: #120d1f;
  --panel: rgba(42, 30, 64, 0.86); --panel-solid: #2a1e40; --panel-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 186, 214, 0.26); --text: #fff4f8; --muted: #cfbdd9;
  --yellow: #ff8fb1; --yellow-deep: #c95a82; --blue: #b79cff; --cyan: #9be7d8;
  --accent-text: #22123a; --btn-text: #2e0c1f;
  /* Candy: round, bubbly letters to match the pill shapes */
  --font-pixel: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-ui: 'Nunito', system-ui, sans-serif;
  --display-scale: 1.45;
  --display-weight: 700;
}
html[data-theme='pastel'] body { background: radial-gradient(ellipse at 30% 20%, #3a2552 0%, transparent 60%), radial-gradient(ellipse at 80% 90%, #1d3045 0%, transparent 55%), var(--bg); }
html[data-theme='pastel'] .menu-card {
  border: 2px solid rgba(255, 186, 214, 0.35); border-radius: 36px;
  box-shadow: 0 6px 0 rgba(255, 143, 177, 0.25), 0 30px 70px rgba(0, 0, 0, 0.45), 0 0 80px rgba(183, 156, 255, 0.15);
}
html[data-theme='pastel'] .logo-pac,
html[data-theme='pastel'] .logo-man {
  text-shadow: 2px 0 #fff4f8, -2px 0 #fff4f8, 0 2px #fff4f8, 0 -2px #fff4f8, 0 7px 0 var(--sticker);
}
html[data-theme='pastel'] .logo-pac { --sticker: #8e3b5e; color: #ff8fb1; }
html[data-theme='pastel'] .logo-man { --sticker: #4b3d8c; color: #a8bcff; animation: none; }
html[data-theme='pastel'] .lane { padding: 6px 8px; background: var(--screen); border-radius: 20px; box-shadow: inset 0 0 0 2px rgba(255, 186, 214, 0.3); }
html[data-theme='pastel'] .btn-primary { border-radius: 999px; }
html[data-theme='pastel'] .segmented { border-radius: 999px; }
html[data-theme='pastel'] .segmented button { border-radius: 999px; }
html[data-theme='pastel'] :is(.segmented.themes, .segmented.diff-grid, .segmented.chars) { border-radius: 26px; }
html[data-theme='pastel'] :is(.segmented.themes, .segmented.diff-grid, .segmented.chars) button { border-radius: 20px; }
html[data-theme='pastel'] :is(.mode-card, .theme-preview, .custom-panel) { border-radius: 22px; }
html[data-theme='pastel'] .segmented button[aria-checked='true'] { box-shadow: 0 3px 0 #7a5fd0, 0 0 18px rgba(183, 156, 255, 0.4); }
html[data-theme='pastel'] .btn-ghost { border-radius: 22px; }
html[data-theme='pastel'] .icon-btn { border-radius: 16px; }
html[data-theme='pastel'] :is(.btn-ghost, .icon-btn):hover { background: rgba(255, 143, 177, 0.16); border-color: rgba(255, 186, 214, 0.6); }
html[data-theme='pastel'] .menu-links .btn-ghost:nth-child(1) svg { color: #ff8fb1; }
html[data-theme='pastel'] .menu-links .btn-ghost:nth-child(2) svg { color: #ffd76e; }
html[data-theme='pastel'] .menu-links .btn-ghost:nth-child(3) svg { color: #9be7d8; }
html[data-theme='pastel'] :is(.stat, .lives, .stage-badge) { border-radius: 18px; }
html[data-theme='pastel'] .board { border-radius: 26px; }
html[data-theme='pastel'] .life-icon { background: #ffd76e; }
html[data-theme='pastel'] .dpad-btn { color: #b79cff; border-radius: 20px; }
html[data-theme='pastel'] :is(.modal, .dialog) { border-radius: 26px; }
html[data-theme='pastel'] :is(.sprite-card, .ghost-list li) canvas { background: var(--screen); border-radius: 14px; }
html[data-theme='pastel'] .power-bar i { background: linear-gradient(90deg, #9be7d8, #ff9ab0); }

/* Minimal: brutalist black and white. Hard edges, solid white rules, monospace type, offset shadows, no glow. */
html[data-theme='minimal'] {
  --bg: #000000; --bg-2: #000000;
  --panel: #000000; --panel-solid: #000000; --panel-2: #0d0d0d;
  --line: #ffffff; --text: #ffffff; --muted: #a3a3a3;
  --yellow: #ffffff; --yellow-deep: #ffffff; --blue: #ffffff; --cyan: #ffffff;
  --accent-text: #000000; --btn-text: #000000; --danger: #ff4d4d; --good: #ffffff;
  /* Brutalist: a typewriter-like mono for headings and numbers, a grotesk for everything else */
  --font-pixel: 'Space Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --font-ui: 'Space Grotesk', system-ui, sans-serif;
}
html[data-theme='minimal'] body { background: #000000; }
html[data-theme='minimal'] :is(.field-label, .stat-label, .stage-num, .scores-table th) { font-size: 12px; font-weight: 700; letter-spacing: 2px; }
html[data-theme='minimal'] .stat-val { font-size: clamp(17px, 4.6vw, 21px); font-weight: 700; }
html[data-theme='minimal'] .logo { font-size: clamp(30px, 9vw, 56px); font-weight: 800; letter-spacing: 2px; line-height: 1; }
html[data-theme='minimal'] .logo-pac { color: #ffffff; text-shadow: none; }
html[data-theme='minimal'] .logo-man { color: transparent; -webkit-text-stroke: 2px #ffffff; text-shadow: none; animation: none; }
html[data-theme='minimal'] .menu-card { border: 2px solid #ffffff; box-shadow: 6px 6px 0 #ffffff; background: #000000; backdrop-filter: none; -webkit-backdrop-filter: none; animation: none; }
html[data-theme='minimal'] .lane { border-top: 2px solid #fff; border-bottom: 2px solid #fff; }
html[data-theme='minimal'] .btn-primary { font-size: 20px; font-weight: 800; letter-spacing: 6px; border: 2px solid #ffffff; box-shadow: 5px 5px 0 #6b6b6b; }
html[data-theme='minimal'] .btn-primary:hover { background: #000000; color: #ffffff; transform: none; box-shadow: 5px 5px 0 #ffffff; }
html[data-theme='minimal'] .btn-primary:active { transform: translate(4px, 4px); box-shadow: 1px 1px 0 #ffffff; }
html[data-theme='minimal'] .btn-primary.small { font-size: 15px; letter-spacing: 2px; }
html[data-theme='minimal'] .menu .btn-primary { font-size: 20px; }
html[data-theme='minimal'] .segmented { border-width: 2px; background: #000000; }
html[data-theme='minimal'] .segmented button[aria-checked='true'],
html[data-theme='minimal'] #diffPicker button[aria-checked='true'] { color: #000000; background: #ffffff; box-shadow: none; }
html[data-theme='minimal'] .segmented button:not([aria-checked='true']):hover { background: #1c1c1c; }
html[data-theme='minimal'] :is(.btn-ghost, .icon-btn) { border-width: 2px; background: #000000; }
html[data-theme='minimal'] :is(.btn-ghost, .icon-btn):hover { background: #ffffff; color: #000000; transform: none; }
html[data-theme='minimal'] :is(.modal h2, .dialog-head h2, .setup-title) { font-size: 18px; font-weight: 800; letter-spacing: 3px; color: #ffffff; text-shadow: none; }
html[data-theme='minimal'] .step h3 { font-size: 16px; font-weight: 800; }
html[data-theme='minimal'] :is(.new-best, .ghost-list b) { font-size: 13px; font-weight: 800; letter-spacing: 1px; }
html[data-theme='minimal'] :is(.life-more, .bonus-line b, .scores-table td:nth-child(2), .scores-table td:nth-child(3)) { font-size: 15px; font-weight: 800; }
html[data-theme='minimal'] .stage-badge { background: #000000; box-shadow: none; border: 2px solid #ffffff; }
html[data-theme='minimal'] .stage-name { color: #ffffff; }
html[data-theme='minimal'] .board { border: 2px solid #ffffff; box-shadow: 6px 6px 0 #ffffff; }
html[data-theme='minimal'] .coach { background: #000000; border: 2px solid #ffffff; box-shadow: none; }
html[data-theme='minimal'] :is(.modal, .dialog) { border: 2px solid #ffffff; box-shadow: 6px 6px 0 #ffffff; }
html[data-theme='minimal'] .modal.briefing { border: 2px solid #ffffff; box-shadow: 6px 6px 0 #ffffff; }
html[data-theme='minimal'] .modal.briefing h2 { color: #ffffff; text-shadow: none; }
html[data-theme='minimal'] .briefing-badge { color: #ffffff; }
html[data-theme='minimal'] .bonus-line { color: #ffffff; background: #000000; border-color: #ffffff; }
html[data-theme='minimal'] .bonus-line b { color: #ffffff; }
html[data-theme='minimal'] #btnStartPhase { color: #000000; background: #ffffff; text-shadow: none; }
html[data-theme='minimal'] .dpad-btn { color: #ffffff; background: #000000; border: 2px solid #ffffff; box-shadow: 4px 4px 0 #6b6b6b; }
html[data-theme='minimal'] .life-icon { background: #ffffff; }
html[data-theme='minimal'] .power-bar i { background: #ffffff; }
html[data-theme='minimal'] .switch { background: #333333; }
html[data-theme='minimal'] input:checked + .switch::after { background: #000000; }

/* ------------------------------------------------------------- Opening animation (src/intro.js) */
.intro { position: fixed; inset: 0; z-index: 60; overflow: hidden; cursor: pointer; }
.intro::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 44%, color-mix(in srgb, var(--bg) 35%, transparent) 0%, color-mix(in srgb, var(--bg) 92%, transparent) 75%);
  transition: opacity var(--fly-ms, 600ms) ease;
}
.intro canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; transition: opacity calc(var(--fly-ms, 600ms) * 0.6) ease; }
.intro.leaving::before, .intro.leaving canvas { opacity: 0; }
.intro.flash::after {
  content: ''; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(circle at 50% 44%, #ffffff 0%, var(--yellow) 30%, transparent 70%);
  animation: intro-flash 0.55s ease-out forwards;
}
.intro-logo { position: fixed; z-index: 1; margin: 0; transform-origin: 50% 50%; pointer-events: none; will-change: transform; }
.intro-ch { display: inline-block; opacity: 0; transform: translateY(30%) scale(0.2); }
.intro-ch.on { animation: intro-pop 0.5s cubic-bezier(0.2, 1.7, 0.4, 1) forwards; }
.intro-logo.charged { animation: intro-charge 0.8s ease-out; }
@keyframes intro-pop {
  0% { opacity: 0; transform: translateY(30%) scale(0.2); }
  55% { opacity: 1; transform: translateY(-12%) scale(1.25); }
  100% { opacity: 1; transform: none; }
}
@keyframes intro-flash { from { opacity: 0.65; } to { opacity: 0; } }
@keyframes intro-charge { 0% { filter: brightness(2.4) saturate(1.4); } 100% { filter: none; } }
@keyframes intro-card { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }

/* While the intro plays only the animated background is visible; then the menu cascades in */
.menu.intro-active > :not(.menu-bg) { opacity: 0; animation: none; }
.menu.intro-active :is(.menu-hero, .menu-options) { animation: none; }
.menu.intro-reveal .menu-card { animation: intro-card 0.55s cubic-bezier(0.16, 1, 0.3, 1) both; }
.menu.intro-reveal :is(.menu-hero, .menu-options) { animation: none; }
.menu.intro-reveal :is(.menu-hero, .menu-options) > * { animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; animation-delay: calc(var(--i, 0) * 55ms + 120ms); }
.menu.intro-reveal .menu-hero > .logo { animation: none; }
/* The game-mode screen keeps its own short cascade: it must not inherit the home screen's long
   delays, or PLAY would only show up a second after the screen opens */
.menu.intro-reveal .menu-setup > * { animation-delay: 0s; }
.menu.intro-reveal .menu-setup > :nth-child(2) { animation-delay: 40ms; }
.menu.intro-reveal .menu-setup > :nth-child(3) { animation-delay: 80ms; }
.menu.intro-reveal .menu-foot { animation: rise 0.5s 0.45s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* ------------------------------------------------------------- 10. Motion */
html[data-motion='reduced'] *,
html[data-motion='reduced'] *::before,
html[data-motion='reduced'] *::after {
  animation-duration: 0.001ms !important;
  animation-delay: 0s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* Japanese: the game's fonts are Latin-only, so Japanese text uses the system's Japanese fonts
   (nothing is downloaded) right after each theme's own font */
html:lang(ja) { --jp: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', 'Yu Gothic', Meiryo, 'Noto Sans JP'; }
html:lang(ja)[data-theme='classic'] { --font-pixel: 'Press Start 2P', var(--jp), monospace; --font-ui: 'Rajdhani', var(--jp), sans-serif; }
html:lang(ja)[data-theme='retro'] { --font-pixel: 'Silkscreen', var(--jp), monospace; --font-ui: 'VT323', var(--jp), monospace; }
html:lang(ja)[data-theme='pastel'] { --font-pixel: 'Fredoka', var(--jp), sans-serif; --font-ui: 'Nunito', var(--jp), sans-serif; }
html:lang(ja)[data-theme='minimal'] { --font-pixel: 'Space Mono', var(--jp), monospace; --font-ui: 'Space Grotesk', var(--jp), sans-serif; }

/* Shown instead of the game when another site tries to embed it in a frame (see src/main.js) */
.frame-notice {
  min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 20px;
  padding: 24px; text-align: center; font-size: 18px; color: var(--text); background: var(--bg, #060811);
}
.frame-notice .btn-primary { width: auto; padding: 0 28px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* Line icons from the inline sprite in index.html (no emoji, so they look the same on every device) */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.15em; }
:root { --trophy: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27%23000%27 stroke-width=%272%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3E%3Cpath d=%27M6 9H4.5a2.5 2.5 0 0 1 0-5H6M18 9h1.5a2.5 2.5 0 0 0 0-5H18M4 22h16M10 14.7V17c0 .6-.5 1-1 1.2C7.9 18.8 7 20.2 7 22M14 14.7V17c0 .6.5 1 1 1.2 1.1.6 2 2 2 3.8M18 2H6v7a6 6 0 0 0 12 0V2z%27/%3E%3C/svg%3E"); }

/* Until main.js has translated and themed the menu, keep it out of sight (see src/boot.js) */
html.booting .menu > :not(.menu-bg) { visibility: hidden; }

/* Japanese glyphs need more room than the pixel font the label sizes were tuned for */
html:lang(ja) { --display-scale: 1.5; }
html:lang(ja)[data-theme] { --display-scale: 1.5; }

/* One capitalization style for titles and main buttons in every language (instead of upper-casing
   the translations themselves); text-transform respects each language's rules */
.dialog-head h2, .modal h2, .modal .btn-primary { text-transform: uppercase; }

/* Computers with a mouse/keyboard and the D-pad on: keep the keyboard hints under it as well.
   (Short landscape windows use the side layout above, so they are left out.) */
@media (min-width: 900px) and (min-height: 641px) and (hover: hover) and (pointer: fine) {
  html[data-dpad='on'] { --ctrl-h: calc(var(--dpad-h) + 30px + var(--gap)); }
  html[data-dpad='on'] .game { grid-template-areas: 'hud' 'board' 'bar' 'ctrl' 'keys'; }
  html[data-dpad='on'] .key-hints { display: flex; grid-area: keys; height: 30px; }
}

/* Pause menu: where the run stands, and quick music / effects switches */
.pause-status { margin: -4px 0 14px; font-family: var(--font-pixel); font-weight: var(--display-weight); font-size: calc(10px * var(--display-scale)); line-height: 1.5; color: var(--yellow); }
.pause-audio { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.pause-audio .toggle { width: 100%; min-height: 44px; font-size: 15px; }
.pause-audio .toggle[aria-pressed='false'] { opacity: 0.55; text-decoration: line-through; }

/* 404 page (404.html, served by GitHub Pages for missing addresses) */
.not-found {
  min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 24px; text-align: center; color: var(--text); background: radial-gradient(circle at 50% 40%, #14204a, #060811 70%);
}
.not-found h1 { font-family: var(--font-pixel); font-size: 48px; color: var(--yellow); text-shadow: 0 0 18px rgba(255, 230, 0, 0.45); }
.not-found p { font-size: 20px; }
.not-found p + p { color: var(--muted); font-size: 17px; }
.not-found .btn-primary { width: auto; margin-top: 10px; padding: 0 28px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.not-found-ghost { width: 72px; height: 72px; fill: none; stroke: #ff2a2a; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 12px rgba(255, 42, 42, 0.5)); }

/* "A new version is ready" bar (src/main.js) */
.update-notice {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 12px); transform: translateX(-50%); z-index: 95;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  width: min(94vw, 520px); padding: 10px 14px; font-size: 16px; color: var(--text);
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}
.update-notice span { flex: 1 1 200px; }
.update-notice .btn-primary.small, .update-notice .btn-ghost { width: auto; min-height: 44px; padding: 0 16px; }

.scores-empty { margin-top: 12px; padding: 12px 14px; font-size: 16px; color: var(--text); text-align: center; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 12px; }
.group-body { padding-bottom: 6px; }
.group-body .setting:first-child { padding-top: 4px; }
