/* --- ARCADE UI: title screen, settings panel, in-game settings key ---
   Retro bowling-alley cabinet: walnut + bakelite surfaces, marquee bulbs,
   amber/cherry keycaps that physically travel, teal neon readouts, Dymo labels. */

:root {
  --am-ink: #120a06;
  --am-walnut: #24170f;
  --am-walnut-deep: #150d08;
  --am-cream: #f6ead2;
  --am-cream-dim: #c9b89a;
  --am-amber: #ffb31a;
  --am-amber-hi: #ffd36b;
  --am-amber-lip: #7a3f05;
  --am-cherry: #ef3a2d;
  --am-cherry-hi: #ff5b47;
  --am-cherry-lip: #6d0d07;
  --am-teal: #35f0cf;
  --am-steel: #3d3d42;
  --am-display: 'Aileron', sans-serif;
  --am-script: 'Aileron', sans-serif;
  --am-label: 'Aileron', sans-serif;
  --am-mono: 'Aileron', sans-serif;
  --am-hud: 'Aileron', sans-serif;
}

/* ===== Shared parts ===== */

.dymo {
  display: inline-block;
  padding: 5px 9px 4px;
  font: 400 10px/1 var(--am-label);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #f4f4ef;
  background: #111;
  border-radius: 2px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.7);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.9);
  transform: rotate(-1.2deg);
}

.dymo--red { background: #b3170f; }

.arcade-btn {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 22px 2px;
  font: 900 22px/1 var(--am-display);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #1b0f08;
  background: linear-gradient(var(--am-amber-hi), var(--am-amber) 62%, #f29a0c);
  border: 2px solid var(--am-ink);
  border-radius: 6px;
  box-shadow:
    0 6px 0 var(--am-amber-lip),
    0 12px 20px rgba(0, 0, 0, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform 0.07s ease, box-shadow 0.07s ease, filter 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.arcade-btn:hover { filter: brightness(1.07); }

.arcade-btn:active {
  transform: translateY(5px);
  box-shadow:
    0 1px 0 var(--am-amber-lip),
    0 4px 8px rgba(0, 0, 0, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(0, 0, 0, 0.12);
}

.arcade-btn:focus-visible { outline: none; }

.arcade-btn--go {
  color: #fff6e6;
  background: linear-gradient(var(--am-cherry-hi), #e3281b 62%, #c71c11);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  box-shadow:
    0 6px 0 var(--am-cherry-lip),
    0 12px 22px rgba(0, 0, 0, 0.5),
    0 0 26px rgba(239, 58, 45, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

.arcade-btn--go:active {
  box-shadow: 0 1px 0 var(--am-cherry-lip), 0 4px 8px rgba(0, 0, 0, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.arcade-btn--steel {
  color: var(--am-cream);
  background: linear-gradient(#55555b, var(--am-steel) 60%, #2a2a2e);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.6);
  box-shadow:
    0 6px 0 #0c0c0e,
    0 12px 20px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.arcade-btn--steel:active {
  box-shadow: 0 1px 0 #0c0c0e, 0 4px 8px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.arcade-btn[hidden] { display: none; }

/* Toggle switch: bakelite slot, cream lever */
.arcade-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.arcade-switch input,
.arcade-key input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.arcade-switch__body {
  position: relative;
  flex: none;
  width: 48px;
  height: 26px;
  border-radius: 4px;
  background: #0b0705;
  box-shadow: inset 0 2px 5px #000, 0 1px 0 rgba(255, 255, 255, 0.08);
}

.arcade-switch__body::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px) center / 8px 10px no-repeat,
    linear-gradient(#f2ecdf, #a69e90);
  box-shadow: 0 2px 0 #000, 0 3px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.14s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.arcade-switch input:checked + .arcade-switch__body {
  background: #0c3a33;
  box-shadow: inset 0 2px 5px #000, inset 0 0 10px rgba(53, 240, 207, 0.35), 0 1px 0 rgba(255, 255, 255, 0.08);
}

.arcade-switch input:checked + .arcade-switch__body::before { transform: translateX(22px); }

.arcade-switch input:focus-visible + .arcade-switch__body { outline: none; }

.arcade-label {
  font: 900 15px/1.1 var(--am-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--am-cream);
}

/* ===== Title screen ===== */

.arcade-menu {
  position: fixed;
  inset: 0;
  z-index: 115;
  display: grid;
  grid-template-columns: minmax(0, 600px) 1fr;
  grid-template-rows: 1fr auto auto 1fr;
  grid-template-areas: '. .' 'sign .' 'deck .' '. .';
  column-gap: 40px;
  row-gap: 44px;
  padding:
    max(28px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom)) max(clamp(28px, 6vw, 88px), env(safe-area-inset-left));
  color: var(--am-cream);
  background:
    linear-gradient(90deg, rgba(14, 8, 4, 0.94) 0%, rgba(14, 8, 4, 0.82) 34%, rgba(14, 8, 4, 0.2) 66%, rgba(14, 8, 4, 0) 100%),
    radial-gradient(120% 80% at 0% 100%, rgba(239, 58, 45, 0.18), transparent 60%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  overflow-y: auto;
}

.arcade-menu.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease;
}

.arcade-menu__rail { display: contents; }

.arcade-menu__sign,
.arcade-deck {
  /* Continue is wider than Play: content must never enlarge the menu track. */
  min-width: 0;
  max-width: 100%;
}

.arcade-menu__sign { grid-area: sign; align-self: end; }

/* Logo sign (src/images/logo.webp). "BOWLING" is cut out of the image, so a neon tube layer
   sits behind it (--tube) and shows through the letters. The halo also stays behind
   the image so its colours never wash over the opaque logo artwork. */
.marquee {
  --neon: #2f8cff;
  position: relative;
  width: min(600px, 100%, 110vh);
  margin-inline: auto;
  /* Apply the shadow after compositing so it cannot darken the neon through the letters. */
  filter: drop-shadow(0 22px 34px rgba(0, 0, 0, 0.65));
}

.marquee__title { margin: 0; }

.marquee__logo {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* Wrapper: placement, fade on/off and surges. ::before: the light itself (power-on + breathing). */
.marquee__neon {
  position: absolute;
  /* Cover the full letter cutouts, including B and G's lower, slanted edges.
     Keep the light's rectangular boundary behind the opaque sign artwork. */
  inset: 60% 18% 17% 18%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.marquee__neon::before {
  content: '';
  position: absolute;
  inset: 0;
}

/* Rainbow band (first stop = last, sized 200%) slides one full period per cycle so the loop is
   seamless; --neon follows the band's colours for the outer glow. Both layers keep the band
   second so am-neon-flow's background-position list fits both. */
@property --neon {
  syntax: '<color>';
  inherits: true;
  initial-value: #2f8cff;
}

.marquee__neon--tube::before,
.marquee__neon--halo::before {
  --band: linear-gradient(90deg, #00f0ff, #2f7bff 17%, #9b4dff 33%, #ff36d2 50%, #ff7a2f 67%, #ffe23f 83%, #00f0ff);
}

.marquee__neon--tube { overflow: hidden; }

.marquee__neon--tube::before {
  background:
    linear-gradient(transparent, transparent),
    var(--band) 0 0 / 200% 100%;
  box-shadow: 0 0 8px 3px var(--neon), 0 0 22px 10px var(--neon);
}

.marquee__neon--halo {
  z-index: 0;
  inset: 50% 12% 12% 12%;
  mix-blend-mode: screen;
}

.marquee__neon--halo::before {
  background: linear-gradient(transparent, transparent), var(--band) 0 0 / 200% 100%;
  -webkit-mask: radial-gradient(50% 50% at 50% 50%, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.25) 55%, transparent 78%);
  mask: radial-gradient(50% 50% at 50% 50%, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.25) 55%, transparent 78%);
}

/* Lit state (src/ui/arcade-menu.js): buzz-flicker power-on, then a slow breathing glow. */
.marquee.is-lit .marquee__neon { opacity: 1; transition: none; }

.marquee.is-lit .marquee__neon::before {
  animation: am-neon-on 1.5s linear both, am-neon-breathe 3.8s ease-in-out 1.5s infinite alternate,
    am-neon-flow 9s linear infinite;
}

/* Occasional arcade surge */
.marquee.is-surging .marquee__neon { animation: am-neon-surge 0.42s linear; }

@keyframes am-neon-on {
  0%, 6% { opacity: 0; filter: brightness(0.4); }
  7% { opacity: 0.7; }
  9%, 18% { opacity: 0.06; }
  19% { opacity: 0.85; }
  21% { opacity: 0.15; }
  23% { opacity: 0.6; }
  25%, 36% { opacity: 0.1; }
  37% { opacity: 0.95; filter: brightness(1.2); }
  39% { opacity: 0.35; }
  41% { opacity: 1; filter: brightness(1.4) saturate(1.5); }
  60% { opacity: 1; filter: brightness(1.3) saturate(1.5); }
  100% { opacity: 1; filter: brightness(1.25) saturate(1.5); }
}

@keyframes am-neon-breathe {
  from { opacity: 1; filter: brightness(1.25) saturate(1.5); }
  to { opacity: 1; filter: brightness(1.1) saturate(1.5); }
}

@keyframes am-neon-flow {
  0%, 100% { --neon: #00f0ff; }
  17% { --neon: #2f7bff; }
  33% { --neon: #9b4dff; }
  50% { --neon: #ff36d2; }
  67% { --neon: #ff7a2f; }
  83% { --neon: #ffe23f; }
  from { background-position: 0 0, 0 0; }
  to { background-position: 0 0, -200% 0; }
}

@keyframes am-neon-surge {
  0%, 100% { filter: none; }
  15% { filter: brightness(0.75); }
  25% { filter: brightness(1.35) saturate(1.2); }
  40% { filter: brightness(0.9); }
  60% { filter: brightness(1.2); }
}

/* Control deck: sci-fi HUD panel. Chamfered shapes are two clipped layers behind the
   content (::before = edge, ::after = fill, inset by --bw); glow comes from the host's
   drop-shadow, which follows the clipped outline. --cl / --cr = left / right corner cuts. */
.arcade-deck,
.hud-btn,
.hud-switch {
  position: relative;
  isolation: isolate;
  --bw: 2px;
}

.arcade-deck::before,
.arcade-deck::after,
.hud-btn::before,
.hud-btn::after,
.hud-switch::before,
.hud-switch::after {
  content: '';
  position: absolute;
  z-index: -1;
  pointer-events: none;
  clip-path: polygon(
    var(--a) 0, calc(100% - var(--b)) 0, 100% var(--b), 100% calc(100% - var(--b)),
    calc(100% - var(--b)) 100%, var(--a) 100%, 0 calc(100% - var(--a)), 0 var(--a));
}

.arcade-deck::before,
.hud-btn::before,
.hud-switch::before { inset: 0; --a: var(--cl); --b: var(--cr); background: var(--edge); }

/* Inner cut shrinks by bw·(2-√2) so the diagonal edge is as thick as the straight ones */
.arcade-deck::after,
.hud-btn::after,
.hud-switch::after {
  inset: var(--bw);
  --a: calc(var(--cl) - var(--bw) * 0.59);
  --b: calc(var(--cr) - var(--bw) * 0.59);
  background: var(--fill);
}

.arcade-deck {
  --cl: 26px;
  --cr: 26px;
  --bw: 3px;
  --edge: linear-gradient(#ffe7a3, #e08d16 14%, #6e430f 50%, #e08d16 86%, #ffe7a3);
  --fill:
    radial-gradient(110% 50% at 50% 0%, rgba(255, 170, 40, 0.12), transparent 70%),
    radial-gradient(110% 50% at 50% 100%, rgba(255, 170, 40, 0.1), transparent 70%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 6px),
    linear-gradient(#151b27, #0a0e16);
  grid-area: deck;
  align-self: start;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  width: min(480px, 100%);
  padding: 32px 30px 28px;
  filter: drop-shadow(0 0 8px rgba(255, 160, 30, 0.5)) drop-shadow(0 24px 40px rgba(0, 0, 0, 0.65));
  justify-self: center;
  transform: translateX(-14px);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.1) 0.08s, opacity 0.3s ease 0.08s;
}

.arcade-menu.is-open .arcade-deck { transform: none; opacity: 1; }

/* All menu controls share PLAY's symmetric chamfered outline. */
.hud-btn,
.hud-switch {
  --cl: 18px;
  --cr: 18px;
  --bw: 3px;
}

.hud-btn {
  --edge: linear-gradient(#b9d3f7, #4f6f9e 50%, #93b4e2);
  --fill:
    radial-gradient(120% 120% at 50% 0%, rgba(130, 170, 230, 0.16), transparent 60%),
    linear-gradient(#24324b, #121a2a);
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 20px;
  min-height: 62px;
  margin: 0 12px;
  padding: 0 30px 0 28px;
  font: 700 26px/1 var(--am-hud);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #e8edf5;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  background: none;
  border: 0;
  cursor: pointer;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
  transition: transform 0.08s ease, filter 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hud-btn[hidden] { display: none; }

/* Opponent selector: bot level / "next game" tag beside the name */
.hud-btn__note {
  margin-left: auto;
  font-size: 0.5em;
  letter-spacing: 0.08em;
  color: #9fb6d8;
  white-space: nowrap;
}
.hud-btn__note[hidden] { display: none; }

.hud-btn:hover,
.hud-btn:focus-visible {
  outline: none;
  filter: brightness(1.15) drop-shadow(0 0 8px rgba(150, 190, 245, 0.55));
}

.hud-btn:active { transform: translateY(2px) scale(0.99); }

.hud-btn__icon {
  flex: none;
  width: 40px;
  height: 34px;
  fill: #dfe5ee;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.55));
}

.hud-pin-front { stroke: #1a2438; stroke-width: 1.6; paint-order: stroke; }

/* PLAY: glowing amber plate with side tabs */
.hud-btn--play {
  --edge: linear-gradient(#fff2c0, #ffb320 40%, #ff8c0a);
  --fill:
    radial-gradient(80% 110% at 50% 50%, rgba(255, 140, 20, 0.32), transparent 75%),
    linear-gradient(#5c2d08, #261103 55%, #401e05);
  min-height: 76px;
  font-size: 44px;
  letter-spacing: 0.12em;
  color: #ffe6a0;
  text-shadow: 0 0 12px rgba(255, 190, 60, 0.75), 0 2px 0 #4a2200;
  filter: drop-shadow(0 0 8px rgba(255, 165, 30, 0.8)) drop-shadow(0 0 22px rgba(255, 120, 10, 0.35));
}

.hud-btn--play:hover,
.hud-btn--play:focus-visible {
  filter: brightness(1.12) drop-shadow(0 0 10px rgba(255, 190, 60, 0.95)) drop-shadow(0 0 30px rgba(255, 130, 20, 0.5));
}

.hud-btn__icon--outline { fill: none; }
.hud-btn--play .hud-btn__icon { fill: #ffc934; filter: drop-shadow(0 0 6px rgba(255, 200, 60, 0.8)); }

.hud-btn__tabs { display: none; }

/* Sound / music cards with glowing pill switches */
.hud-audio {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  margin-inline: 12px;
}

.hud-audio__divider {
  width: 2px;
  height: 38px;
  background: linear-gradient(transparent, #ff9e1a, transparent);
}

.hud-switch {
  --edge: linear-gradient(#8faed9, #3f5a82 50%, #7b9bc8);
  --fill: linear-gradient(#1d283c, #111827);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 54px;
  padding: 0 12px 0 14px;
  font: 700 18px/1 var(--am-hud);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #e8edf5;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hud-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.hud-switch__icon { flex: none; width: 24px; height: 24px; fill: #dfe5ee; color: #dfe5ee; }

.hud-switch__label { flex: 1; min-width: 0; }

.hud-switch__track {
  position: relative;
  flex: none;
  width: 46px;
  height: 24px;
  border: 2px solid #4b5568;
  border-radius: 12px;
  background: #0a0e16;
  box-shadow: inset 0 2px 4px #000;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.hud-switch__track::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d8dde5, #7c8493);
  transition: transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1), background 0.18s ease, box-shadow 0.18s ease;
}

.hud-switch input:checked + .hud-switch__track {
  border-color: #ff9a12;
  box-shadow: inset 0 2px 4px #000, 0 0 8px rgba(255, 150, 20, 0.45);
}

.hud-switch input:checked + .hud-switch__track::before {
  transform: translateX(22px);
  background: radial-gradient(circle at 35% 30%, #fffbe0, #ffd43a 55%, #ffa000);
  box-shadow: 0 0 8px #ffcf3a, 0 0 16px rgba(255, 190, 40, 0.6);
}

.hud-switch input:focus-visible + .hud-switch__track { outline: 2px solid #ffe08a; outline-offset: 3px; }

/* Dip to black between cinematic shots; sits under the sign and deck */
.arcade-menu__fade {
  position: fixed;
  inset: 0;
  z-index: 114;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s ease;
}

.arcade-menu__fade.is-dark { opacity: 1; }

/* Hide the title UI immediately; its camera fade continues in the shared overlay. */
.arcade-menu.is-starting-game {
  opacity: 0;
  visibility: hidden;
  transition: none;
}

/* Gameplay chrome stays out of the way of the title screen */
.arcade-menu.is-selecting-ball { background: none; }
.arcade-menu.is-selecting-ball .arcade-menu__rail { visibility: hidden; }

body.arcade-ball-picker-open #ball-selection-modal {
  background: linear-gradient(180deg, rgba(6, 10, 20, 0.48), rgba(3, 5, 10, 0.62));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.arcade-menu-open #btn-select-ball,
body.arcade-menu-open #btn-graphics-settings { visibility: hidden; }

/* ===== Settings panel (engine's #pause-overlay) ===== */

#pause-overlay {
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: radial-gradient(90% 70% at 50% 40%, rgba(20, 12, 6, 0.6), rgba(6, 3, 2, 0.9));
  transition: opacity 0.22s ease;
}

.arcade-panel {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: 100%;
  overflow: hidden;
  color: var(--am-cream);
  background: linear-gradient(var(--am-walnut), var(--am-walnut-deep));
  border: 2px solid #000;
  border-radius: 6px;
  box-shadow: 0 0 0 5px #3b2616, 0 0 0 7px #000, 0 30px 80px rgba(0, 0, 0, 0.75);
  transform: translateY(14px) scale(0.98);
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

#pause-overlay.visible .arcade-panel { transform: none; }

.arcade-panel__plate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px 12px;
  color: #1b0f08;
  background: linear-gradient(var(--am-amber-hi), var(--am-amber) 70%, #e8930b);
  border-bottom: 3px solid #000;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.arcade-panel__title {
  margin: 0;
  font: 900 38px/1 var(--am-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.arcade-panel__body {
  display: grid;
  gap: 22px;
  padding: 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.arcade-group {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 22px 16px 16px;
  border: 1px solid rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.arcade-group > legend { margin-left: -4px; padding: 5px 9px 4px; }

.arcade-help {
  margin: 0;
  color: var(--am-cream-dim);
  font: 14px/1.5 var(--am-body, sans-serif);
}

.arcade-row {
  display: grid;
  grid-template-columns: 104px 1fr;
  align-items: center;
  gap: 12px;
}

.arcade-row > .arcade-switch { justify-self: start; }

.arcade-keys {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 6px 6px 9px;
  background: #0b0705;
  border-radius: 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.85), 0 1px 0 rgba(255, 255, 255, 0.06);
}

.arcade-key { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.arcade-key span {
  position: relative;
  display: block;
  padding: 11px 0 10px;
  text-align: center;
  font: 900 19px/1 var(--am-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--am-cream-dim);
  background: linear-gradient(#3d2c20, #2a1d14);
  border-radius: 4px;
  box-shadow: 0 4px 0 #050302, inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.15s ease, color 0.15s ease;
}

/* Indicator lamp in each key */
.arcade-key span::after {
  content: '';
  position: absolute;
  top: 5px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #1a0f09;
}

.arcade-key:active span { transform: translateY(3px); box-shadow: 0 1px 0 #050302, inset 0 1px 0 rgba(255, 255, 255, 0.1); }

.arcade-key input:checked + span {
  color: #1b0f08;
  background: linear-gradient(var(--am-amber-hi), var(--am-amber) 70%, #ec960c);
  transform: translateY(3px);
  box-shadow: 0 1px 0 #050302, 0 0 18px rgba(255, 179, 26, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.arcade-key input:checked + span::after { background: var(--am-cherry); box-shadow: 0 0 6px var(--am-cherry); }

.arcade-key input:focus-visible + span { outline: none; }

/* Faders */
.arcade-fader {
  display: grid;
  grid-template-columns: auto 82px 1fr 54px;
  align-items: center;
  gap: 12px;
  transition: opacity 0.2s ease;
}

.arcade-fader.is-muted .arcade-range,
.arcade-fader.is-muted .arcade-readout { opacity: 0.38; }

.arcade-range {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 32px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

.arcade-range:focus { outline: none; }

.arcade-range::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--am-teal) 0 var(--fill), #070504 var(--fill));
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.9), 0 1px 0 rgba(255, 255, 255, 0.07);
}

.arcade-range::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: #070504;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.9);
}

.arcade-range::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--am-teal); }

.arcade-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 32px;
  margin-top: -12px;
  border: 1px solid #000;
  border-radius: 3px;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px) center / 12px 14px no-repeat,
    linear-gradient(#f2ecdf, #a69e90);
  box-shadow: 0 3px 0 #000, 0 5px 10px rgba(0, 0, 0, 0.6);
}

.arcade-range::-moz-range-thumb {
  width: 20px;
  height: 32px;
  border: 1px solid #000;
  border-radius: 3px;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px) center / 12px 14px no-repeat,
    linear-gradient(#f2ecdf, #a69e90);
  box-shadow: 0 3px 0 #000, 0 5px 10px rgba(0, 0, 0, 0.6);
}

.arcade-range:focus-visible::-webkit-slider-thumb { outline: none; }
.arcade-range:focus-visible::-moz-range-thumb { outline: none; }

.arcade-readout {
  padding: 7px 8px 6px;
  font: 500 15px/1 var(--am-mono);
  text-align: right;
  color: var(--am-teal);
  background: #040302;
  border-radius: 3px;
  box-shadow: inset 0 1px 4px #000, 0 1px 0 rgba(255, 255, 255, 0.06);
  text-shadow: 0 0 6px rgba(53, 240, 207, 0.75);
}

.arcade-panel__actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 14px;
  padding: 16px 22px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.75);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.arcade-panel__actions .arcade-btn[hidden] + .arcade-btn { grid-column: 1 / -1; }

/* ===== In-game HUD keys (engine's ⚙ and ball buttons) ===== */

#btn-select-ball,
#btn-graphics-settings {
  --cl: 12px;
  --cr: 12px;
  --bw: 2px;
  --edge: linear-gradient(#ffe7a3, #e08d16 30%, #6e430f 55%, #e08d16 85%, #ffe7a3);
  --fill:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 170, 40, 0.16), transparent 65%),
    linear-gradient(#1a2233, #0a0e16);
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  color: var(--am-amber-hi);
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 0 5px rgba(255, 160, 30, 0.35)) drop-shadow(0 5px 10px rgba(0, 0, 0, 0.55));
  transition: transform 0.08s ease, filter 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

#btn-select-ball::before,
#btn-select-ball::after,
#btn-graphics-settings::before,
#btn-graphics-settings::after {
  content: '';
  position: absolute;
  z-index: -1;
  pointer-events: none;
  clip-path: polygon(
    var(--a) 0, calc(100% - var(--b)) 0, 100% var(--b), 100% calc(100% - var(--b)),
    calc(100% - var(--b)) 100%, var(--a) 100%, 0 calc(100% - var(--a)), 0 var(--a));
}

#btn-select-ball::before,
#btn-graphics-settings::before { inset: 0; --a: var(--cl); --b: var(--cr); background: var(--edge); }

#btn-select-ball::after,
#btn-graphics-settings::after {
  inset: var(--bw);
  --a: calc(var(--cl) - var(--bw) * 0.59);
  --b: calc(var(--cr) - var(--bw) * 0.59);
  background: var(--fill);
}

#btn-select-ball svg,
#btn-graphics-settings svg { filter: drop-shadow(0 0 4px rgba(255, 179, 26, 0.55)); }

@media (hover: hover) {
  #btn-select-ball:hover,
  #btn-graphics-settings:hover {
    color: #fff3cf;
    filter: drop-shadow(0 0 9px rgba(255, 160, 30, 0.6)) drop-shadow(0 5px 10px rgba(0, 0, 0, 0.55));
  }
}

#btn-select-ball:active,
#btn-graphics-settings:active { transform: translateY(2px) scale(0.96); }

#btn-select-ball:focus-visible,
#btn-graphics-settings:focus-visible { outline: none; }

@media (min-width: 1025px) and (hover: hover) and (pointer: fine) {
  #btn-select-ball,
  #btn-graphics-settings {
    width: 72px;
    height: 72px;
    --cl: 16px;
    --cr: 16px;
  }

  #btn-select-ball svg { width: 36px; height: 36px; }
  #btn-graphics-settings svg { width: 33px; height: 33px; }

  #btn-select-ball {
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 88px);
  }
}

@media (min-width: 1025px) and (hover: hover) and (pointer: fine) and (orientation: portrait) {
  #btn-select-ball { top: calc(50% - 80px); bottom: auto; }
  #btn-graphics-settings { top: calc(50% + 8px); }
}

/* ===== Small / portrait screens ===== */

/* On every landscape viewport the logo and controls share one centred rail.
   The rail itself provides the full-height dark backdrop without dimming the scene. */
@media (orientation: landscape) {
  .arcade-menu {
    display: block;
    padding: 0;
    background: none;
    overflow: hidden;
  }

  .arcade-menu__rail {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: 'sign' 'deck';
    justify-items: center;
    align-items: center;
    justify-content: flex-start;
    gap: clamp(20px, 4vh, 44px);
    width: min(100%, 688px);
    height: 100%;
    padding:
      max(20px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right))
      max(20px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
    background: transparent;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .arcade-menu__sign,
  .arcade-deck {
    flex: none;
    align-self: auto;
    justify-self: auto;
  }

  /* Reserve the complete deck, including New Game after returning.
     The logo uses only the remaining space and retains its neon alignment. */
  .arcade-menu__sign { width: 100%; min-height: 0; height: 100%; display: grid; place-items: center; container-type: size; }
  .marquee { width: min(600px, 100cqw, calc(100cqh * 2)); }
}

@media (max-width: 760px) and (orientation: portrait) {
  .arcade-menu {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: 'sign' 'deck';
    row-gap: 24px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    background:
      linear-gradient(180deg, rgba(14, 8, 4, 0.92) 0%, rgba(14, 8, 4, 0.35) 34%, rgba(14, 8, 4, 0.35) 52%, rgba(14, 8, 4, 0.95) 80%);
  }

  .arcade-menu__sign { min-height: 0; height: 100%; align-self: start; justify-self: center; container-type: size; }
  /* Keep the logo and its neon layers at the artwork's actual aspect ratio. */
  .marquee { width: min(600px, 100cqw, calc(100cqh * 2)); }
  .arcade-deck { padding-inline: 0; filter: none; }
  .arcade-deck::before,
  .arcade-deck::after { content: none; }
  .hud-btn { padding: 0 16px; gap: 12px; font-size: clamp(18px, 5vw, 26px); }
  .hud-btn__icon { width: 32px; height: 28px; }
  .hud-btn--play { font-size: clamp(24px, 7vw, 44px); }
  .arcade-menu__sign { justify-self: stretch; }
  .arcade-deck { justify-self: center; transform: translateY(14px); }
}

@media (max-width: 1024px) and (orientation: landscape), (max-height: 520px) and (orientation: landscape) {
  .arcade-deck { filter: none; gap: 18px; }
  .arcade-deck::before,
  .arcade-deck::after { content: none; }
}

/* Mid-height landscape tablets and small laptop windows need a shorter sign,
   while retaining the full-size, comfortably tappable controls. */
@media (min-height: 521px) and (max-height: 700px) and (orientation: landscape) {
  .arcade-menu__rail {
    gap: 20px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .marquee { width: min(380px, 100cqw, calc(100cqh * 2)); }
  .arcade-deck { padding-block: 22px 20px; }
}

/* Compact control rows: narrow screens and short landscape phones */
@media (max-width: 760px), (max-height: 520px) {
  .arcade-row { grid-template-columns: 1fr; gap: 8px; }
  .arcade-fader { grid-template-columns: auto 1fr 54px; row-gap: 4px; }
  .arcade-fader .arcade-label { grid-column: 2 / -1; grid-row: 1; }
  .arcade-fader .arcade-switch { grid-row: 1 / 3; }
  .arcade-fader .arcade-range { grid-column: 2; grid-row: 2; }
  .arcade-fader .arcade-readout { grid-column: 3; grid-row: 2; }
  .arcade-panel__title { font-size: 30px; }
}

/* Short landscape phones: compact single rail */
@media (max-height: 520px) and (orientation: landscape) {
  .arcade-menu__rail {
    gap: 8px;
    width: min(100%, 410px);
    padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .marquee { width: min(275px, 76vh, 100cqw, calc(100cqh * 2)); }
  .arcade-deck { width: min(340px, 100%); gap: clamp(4px, 1.4vh, 8px); padding: 9px 12px 8px; --cl: 18px; --cr: 18px; }
  /* Shared 18px corner cuts also fit the compact controls without intersecting. */
  .hud-btn { min-height: 37px; padding-inline: 15px; gap: 11px; font-size: 18px; }
  .hud-btn__icon { width: 27px; height: 22px; }
  .hud-btn--play { min-height: 44px; font-size: 27px; }
  .hud-audio { gap: 12px; margin-top: 0; }
  /* Shallower cuts: 18px on a 36px card meets mid-height and pinches the ends into points. */
  .hud-switch { --cl: 10px; --cr: 10px; min-height: 36px; gap: 8px; padding: 0 12px 0 16px; font-size: 14px; letter-spacing: 0.06em; }
  .hud-switch__track { width: 40px; height: 22px; }
  .hud-switch__track::before { width: 14px; height: 14px; }
  .hud-switch input:checked + .hud-switch__track::before { transform: translateX(18px); }
  .hud-switch__icon { display: none; }
  .arcade-btn { min-height: 44px; font-size: 18px; }

  /* Display and Audio side by side so the panel fits without scrolling */
  .arcade-panel { width: min(760px, 100%); }
  .arcade-panel__plate { padding: 8px 18px 7px; }
  .arcade-panel__title { font-size: 26px; }
  .arcade-panel__body { grid-template-columns: 1fr 1fr; align-items: start; padding: 12px 16px; gap: 12px; }
  .arcade-group { padding: 18px 12px 12px; gap: 10px; }
  .arcade-key span { padding: 9px 0 8px; font-size: 17px; }
  .arcade-panel__actions { padding: 10px 16px 14px; }
  .arcade-panel__actions .arcade-btn { min-height: 44px; }
}

/* Keep the returned menu inside short portrait screens as well. */
@media (max-width: 760px) and (max-height: 760px) and (orientation: portrait) {
  .arcade-menu {
    row-gap: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .arcade-deck { gap: 8px; padding-block: 12px; }
  .hud-btn { min-height: 44px; }
  .hud-btn--play { min-height: 52px; }
}

/* Compact portrait audio controls share one row, including narrow phones. */
@media (max-width: 760px) and (orientation: portrait) {
  .hud-audio { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-inline: 12px; }
  .hud-audio__divider { display: none; }
  .hud-switch {
    --cl: 10px;
    --cr: 10px;
    min-height: 44px;
    gap: 6px;
    padding-inline: 10px;
    font-size: clamp(12px, 3.2vw, 14px);
    letter-spacing: 0.04em;
  }
  .hud-switch__icon { display: none; }
  .hud-switch__track { width: 34px; height: 22px; }
  .hud-switch__track::before { width: 14px; height: 14px; }
  .hud-switch input:checked + .hud-switch__track::before { transform: translateX(12px); }
}

@media (prefers-reduced-motion: reduce) {
  /* Neon still fades on/off, without flicker, breathing or surges */
  .marquee.is-lit .marquee__neon,
  .marquee.is-lit .marquee__neon::before { animation: none; }
  .marquee.is-lit .marquee__neon { transition: opacity 0.6s ease; }
  .arcade-menu,
  .arcade-deck,
  .arcade-panel { transition: none; }
}

/* Nothing on a closed title screen should keep animating */
.arcade-menu:not(.is-open) *,
.arcade-menu:not(.is-open) *::before,
.arcade-menu:not(.is-open) *::after { animation-play-state: paused; }
