/* ABSOLUTE ARCADE — shared game-page shell (cabinet frame + HUD + overlay) */

body.game-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  --cab: var(--c-cobalt);
  background:
    linear-gradient(135deg, rgba(255, 194, 59, 0.18), transparent 26%),
    linear-gradient(225deg, rgba(20, 209, 163, 0.16), transparent 28%),
    repeating-linear-gradient(90deg, rgba(23, 20, 42, 0.035) 0 1px, transparent 1px 18px),
    repeating-linear-gradient(0deg, rgba(23, 20, 42, 0.028) 0 1px, transparent 1px 18px),
    var(--bg);
}

/* ---------- Top bar ---------- */
.gbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px clamp(16px, 4vw, 32px);
  background:
    linear-gradient(90deg, rgba(255, 61, 127, 0.2), transparent 22%, rgba(20, 209, 163, 0.14) 78%, transparent),
    var(--ink);
  color: var(--bg);
  border-bottom: var(--border);
  box-shadow: 0 4px 0 rgba(23, 20, 42, 0.24);
}
.gbar__back {
  font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.1em;
  text-transform: uppercase; text-decoration: none; color: var(--bg);
  border: 2px solid rgba(251, 250, 255, 0.88); border-radius: 999px; padding: 6px 14px;
  background: rgba(255,255,255,0.06);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.26);
  transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
  white-space: nowrap;
}
.gbar__back:hover { background: var(--c-sun); color: var(--ink); border-color: var(--c-sun); transform: translateY(-1px); }
.gbar__title {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 3.5vw, 1.7rem);
  text-transform: uppercase; letter-spacing: 0.01em;
  color: var(--cab);
  text-shadow:
    0 0 16px color-mix(in srgb, var(--cab) 64%, transparent),
    2px 2px 0 rgba(0,0,0,0.52);
}
.gbar__hud { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.stat {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em;
  text-transform: uppercase;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,255,255,0.32);
  border-radius: 8px; padding: 5px 10px; white-space: nowrap;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.22), 0 1px 0 rgba(255,255,255,0.08);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.stat b {
  color: var(--c-sun);
  font-weight: 700;
  text-shadow: 0 0 12px rgba(255, 194, 59, 0.55);
}
.stat--rise {
  background: rgba(20, 209, 163, 0.2);
  border-color: rgba(20, 209, 163, 0.58);
  animation: statpop 0.34s ease;
}
.stat--fall {
  background: rgba(215, 38, 88, 0.22);
  border-color: rgba(215, 38, 88, 0.58);
  animation: statpop 0.34s ease;
}

.sound-control {
  display: inline-flex;
  align-items: center;
  position: relative;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sound-control__mute {
  appearance: none;
  border: 0;
  border-radius: 6px;
  padding: 4px 7px;
  background: var(--c-sun);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.sound-control__mute[aria-pressed="false"] {
  background: rgba(255,255,255,0.16);
  color: var(--bg);
}
.sound-control__volume {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sound-control__volume span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sound-control input[type="range"] {
  width: 76px;
  accent-color: var(--c-mint);
}
.sound-control__hint {
  display: none;
  flex-basis: 100%;
  width: 100%;
  font-size: 10px;
  line-height: 1.25;
  letter-spacing: 0.04em;
  text-transform: none;
  color: rgba(255,255,255,0.82);
}
.sound-control--hint .sound-control__hint {
  display: block;
}
.level-control__pause {
  appearance: none;
  min-height: 38px;
  border: 1px solid rgba(255,255,255,0.32);
  border-radius: 8px;
  padding: 7px 10px;
  background: linear-gradient(180deg, var(--c-sun), #E8A92C);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.24), 0 1px 0 rgba(255,255,255,0.08);
  white-space: nowrap;
}
.level-control__pause[aria-disabled="true"],
.level-control__pause:disabled {
  cursor: default;
  opacity: 0.62;
}

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 22px; padding: clamp(20px, 4vw, 40px) 16px 44px;
  position: relative;
  overflow: hidden;
}
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 61, 127, 0.12), transparent 20% 80%, rgba(61, 90, 254, 0.12)),
    linear-gradient(180deg, rgba(251, 250, 255, 0.48), transparent 34%);
  opacity: 0.86;
}
.cab {
  position: relative;
  isolation: isolate;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.34), transparent 20% 68%, rgba(0,0,0,0.16)),
    var(--cab);
  border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg), inset 0 0 0 5px rgba(255,255,255,0.14), inset 0 -16px 0 rgba(0,0,0,0.12);
  padding: 18px 18px 24px;
  max-width: 96vw;
  transform: translateZ(0);
}
.cab::before,
.cab::after {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  pointer-events: none;
  z-index: -1;
}
.cab::before {
  top: 8px;
  height: 9px;
  border-radius: 999px;
  background: repeating-linear-gradient(90deg, rgba(251,250,255,0.78) 0 9px, rgba(23,20,42,0.5) 9px 14px);
  opacity: 0.52;
}
.cab::after {
  bottom: 9px;
  height: 8px;
  border: 2px solid rgba(23,20,42,0.78);
  border-inline: 0;
  opacity: 0.42;
}
.cab__screen {
  position: relative;
  background:
    linear-gradient(180deg, var(--screen-2), var(--screen));
  border-radius: 14px;
  overflow: hidden;
  contain: layout paint;
  border: 3px solid rgba(0,0,0,0.72);
  box-shadow:
    inset 0 0 0 4px rgba(255,255,255,0.06),
    inset 0 0 42px rgba(0,0,0,0.54),
    0 6px 0 rgba(23,20,42,0.38);
  display: grid; place-items: center;
}
.cab__screen--canvas {
  inline-size: var(--game-intrinsic-width);
  max-inline-size: calc(96vw - 42px);
  aspect-ratio: var(--game-aspect);
}
.cab__screen > :not(.game-polish__aura):not(.game-polish__bezel-lights):not(.game-polish__screen-grid):not(.scan):not(.overlay) {
  position: relative;
  z-index: 1;
}
.cab__screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(255,255,255,0.22), transparent 17% 58%, rgba(255,255,255,0.08) 60%, transparent 70%),
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 16% 70%, rgba(0,0,0,0.28));
  mix-blend-mode: screen;
  opacity: 0.62;
}
.cab__screen canvas {
  display: block;
  inline-size: min(100%, var(--game-intrinsic-width, 100%));
  block-size: auto;
  max-inline-size: 100%;
  height: auto;
  touch-action: none;
  filter: saturate(1.08) contrast(1.04);
}
.cab__screen--canvas canvas {
  inline-size: 100%;
}
.game-polish__aura {
  position: absolute;
  inset: -12%;
  z-index: 0;
  pointer-events: none;
  background:
    conic-gradient(from 120deg at 50% 48%, rgba(255, 61, 127, 0.14), rgba(20, 209, 163, 0.12), rgba(255, 194, 59, 0.13), rgba(61, 90, 254, 0.11), rgba(255, 61, 127, 0.14)),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.025) 0 2px, transparent 2px 10px);
  opacity: 0.68;
  animation: screenaura 7s ease-in-out infinite alternate;
}
.game-polish__bezel-lights {
  position: absolute;
  inset: 8px;
  z-index: 2;
  pointer-events: none;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.38),
    inset 0 16px 24px rgba(255,255,255,0.04),
    inset 0 -18px 24px rgba(0,0,0,0.26);
}
.game-polish__screen-grid {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.026) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.36;
  mask-image: linear-gradient(180deg, transparent, #000 14%, #000 86%, transparent);
}
.cab__screen--shake {
  animation: screenshake 0.22s ease;
}
.scan {
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background: repeating-linear-gradient(
    to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.13) 2px 4px);
  opacity: 0.82;
}

/* ---------- Overlay (start / pause / game over) ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 6;
  display: grid; place-content: center; text-align: center; gap: 14px;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(16, 14, 31, 0.78), rgba(16, 14, 31, 0.9)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 18px);
  backdrop-filter: blur(3px) saturate(1.08);
  color: var(--bg);
  transform-origin: center;
  animation: overlayin 0.2s ease both;
}
.overlay[hidden] { display: none; }
.overlay--show { animation: overlayin 0.2s ease both; }
.overlay__title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 6vw, 3rem);
  text-transform: uppercase; color: var(--cab);
  text-shadow:
    0 0 18px color-mix(in srgb, var(--cab) 64%, transparent),
    3px 3px 0 rgba(0,0,0,0.58);
}
.overlay__msg {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.88);
  max-width: 34ch;
  margin-inline: auto;
  text-shadow: 0 1px 0 rgba(0,0,0,0.55);
}
.overlay__msg .hi { color: var(--c-sun); }
.overlay .btn { justify-self: center; margin-top: 6px; }
.blink-coin { animation: coinblink 1s steps(2) infinite; }
@keyframes coinblink { 50% { opacity: 0.25; } }
@keyframes overlayin {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes statpop {
  45% { transform: translateY(-1px) scale(1.04); }
}
@keyframes screenaura {
  from { transform: translate3d(-1.5%, -1%, 0) scale(1); }
  to { transform: translate3d(1.5%, 1%, 0) scale(1.03); }
}
@keyframes screenshake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-4px, 2px, 0); }
  40% { transform: translate3d(4px, -2px, 0); }
  60% { transform: translate3d(-3px, -1px, 0); }
  80% { transform: translate3d(3px, 1px, 0); }
}

.score-pop {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 4vw, 1.55rem);
  color: var(--c-sun);
  text-shadow: 2px 2px 0 var(--ink);
  animation: scorepop 0.72s ease-out forwards;
}
.score-pop--bad { color: var(--c-magenta); }
@keyframes scorepop {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.8); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.92); }
}
.effect-particle {
  position: absolute;
  z-index: 5;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--particle-color, var(--c-sun));
  box-shadow: 1px 1px 0 var(--ink);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: particleburst 0.56s ease-out forwards;
}
.effect-particle--bad {
  width: 8px;
  height: 5px;
  border-radius: 2px;
}
@keyframes particleburst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.35); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--particle-x)), calc(-50% + var(--particle-y))) scale(0.2); }
}

.btn, .chip, .tbtn {
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.14s ease;
}
.btn:hover, .tbtn:hover {
  filter: saturate(1.12) brightness(1.04);
}
.is-pressed {
  animation: presspop 0.18s ease;
}
@keyframes presspop {
  50% { transform: translate(2px, 2px) scale(0.97); filter: brightness(1.08); }
}

/* ---------- Controls help + touch ---------- */
.controls { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.keys {
  font-family: var(--font-mono); font-size: 12.5px; letter-spacing: 0.04em;
  color: var(--ink-soft); text-align: center; line-height: 1.9;
  background: rgba(251,250,255,0.62);
  border: 1px solid rgba(23,20,42,0.12);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 2px 2px 0 rgba(23,20,42,0.12);
}
.keys kbd {
  font-family: var(--font-mono); font-size: 11px;
  background: linear-gradient(180deg, var(--paper), var(--bg-2)); border: 2px solid var(--ink);
  border-bottom-width: 3px; border-radius: 6px; padding: 1px 7px;
  color: var(--ink); box-shadow: 1px 1px 0 var(--ink);
}
.status-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* On-screen D-pad / action buttons (shown on touch + small screens) */
.touch { display: none; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; width: 100%; }
/* Action-row buttons (direct children of .touch, i.e. not inside a d-pad) get a
   comfortable, consistent touch target so a row of controls stays aligned. */
.touch > .tbtn {
  min-width: 56px;
  min-height: 56px;
  padding: 10px 18px;
}
.dpad {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 7px;
  padding: 12px 14px;
  border: 3px solid var(--ink);
  border-radius: 42px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.16) 0 18px, transparent 19px),
    linear-gradient(160deg, rgba(255,255,255,0.34), transparent 34% 66%, rgba(0,0,0,0.18)),
    color-mix(in srgb, var(--cab) 74%, var(--paper));
  box-shadow:
    var(--shadow-sm),
    inset 0 4px 0 rgba(255,255,255,0.18),
    inset 0 -7px 0 rgba(0,0,0,0.16);
}
.dpad::after {
  content: "";
  grid-area: 2 / 2;
  place-self: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(23,20,42,0.34);
  box-shadow: inset 0 3px 0 rgba(0,0,0,0.22), 0 1px 0 rgba(255,255,255,0.18);
}
.dpad button { all: unset; }
.tbtn {
  display: grid; place-items: center;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, var(--paper), var(--bg-2)); border: var(--border); border-radius: 14px;
  box-shadow: var(--shadow-sm); cursor: pointer; font-size: 1.4rem; color: var(--ink);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.tbtn:active { transform: translate(2px, 2px); box-shadow: none; }
.dpad .tbtn {
  position: relative;
  z-index: 1;
  border-radius: 999px;
  font-size: 1.22rem;
  font-weight: 700;
  box-shadow:
    2px 3px 0 rgba(23,20,42,0.8),
    inset 0 4px 0 rgba(255,255,255,0.3),
    inset 0 -5px 0 rgba(0,0,0,0.14);
}
.dpad .up    { grid-area: 1 / 2; }
.dpad .left  { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down  { grid-area: 3 / 2; }
.dpad .mid   {
  grid-area: 2 / 2;
  background: linear-gradient(180deg, color-mix(in srgb, var(--cab) 58%, var(--paper)), var(--cab));
  color: var(--bg);
  font-size: 1rem;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.36);
}
.dpad .level-control__pause {
  display: none;
}

.game-polish-ready .cab {
  animation: cabinetin 0.22s ease both;
}

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

@media (hover: none), (max-width: 640px) {
  .touch { display: flex; }
}

/* ---- Compact status bar on phones / small tablets ----
   Title stays on the top line; the HUD (stats + pause + sound) drops to its own
   row and wraps tidily. The sound control stays a single cohesive chip so the
   volume slider never detaches from its label. */
@media (max-width: 720px) {
  .gbar {
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px clamp(12px, 4vw, 28px);
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .gbar__title { font-size: clamp(1.05rem, 4.4vw, 1.5rem); }
  .gbar__hud {
    flex-basis: 100%;
    justify-content: flex-start;
    margin-left: 0;
    gap: 8px;
    min-width: 0;
  }
  .stat { font-size: 11px; padding: 4px 8px; }
  .sound-control {
    flex: 0 1 auto;
    min-width: 0;
  }
  .sound-control input[type="range"] {
    width: clamp(56px, 22vw, 96px);
    min-width: 48px;
  }
}

@media (max-width: 420px) {
  .gbar { gap: 6px 8px; }
  .gbar__hud { gap: 6px; }
  .stat { font-size: 10.5px; letter-spacing: 0.05em; padding: 4px 7px; }
  .sound-control { padding: 4px 7px; gap: 6px; }
  .sound-control input[type="range"] { width: clamp(48px, 26vw, 84px); }
}

/* ---- Landscape phones ----
   When a phone is rotated, a portrait/square canvas playfield is otherwise tall
   enough to push the on-screen joycon below the fold. Center the cabinet and
   dock the touch controls beside it so the playfield and its controls stay on
   screen together. Only canvas games reflow; DOM-board games keep scrolling. */
@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  .stage:has(.cab__screen--canvas) {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(10px, 3vw, 26px);
    padding: 8px clamp(8px, 3vw, 22px);
  }
  .cab__screen--canvas {
    block-size: min(var(--game-intrinsic-height, 80vh), calc(100dvh - 36px));
    inline-size: auto;
    max-inline-size: 60vw;
  }
  .cab__screen--canvas canvas {
    block-size: 100%;
    inline-size: auto;
    height: 100%;
    max-inline-size: 100%;
  }
  .stage:has(.cab__screen--canvas) .controls {
    width: auto;
    max-width: 42vw;
    flex: 0 1 auto;
    gap: 12px;
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
  }
  /* Reclaim vertical space for the playfield + joycon. The keyboard hint is the
     least useful element on a touch device in landscape; the sr-only status-live
     region is left intact for screen readers. */
  .stage:has(.cab__screen--canvas) .controls .keys {
    display: none;
  }
}

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