/* ================================================================
 *  404 game page (Midnight Siege)
 *  Pixel-perfect retro styling for the arcade game 404 page.
 *  Full-viewport "Twilight Zone" portal vignette.
 * ================================================================ */

/* Void color — extends to infinity beyond the portal edge */
html:has(.game404) {
  background: #08030f;
}

.game404 {
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport height — accounts for mobile browser chrome */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #fff;
  padding: 1rem;
  padding-bottom: 70px; /* clearance for fixed footer player (36px strip + 18px + 16px air) */
  gap: 1.5rem;
  font-family: var(--font-accent, "Oxanium", "Share Tech Mono", monospace);
}

/* ================================================================
 *  PORTAL — full-viewport radial gradient that swallows the page.
 *  Header, game, footer, everything lives inside the oval.
 *  The void color (#08030f) bleeds to infinity beyond the edge.
 *  z-index 90: above header (50), below crack overlay (9999).
 * ================================================================ */

.game404::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  /* Landscape oval — wide horizontal, slightly raised center */
  background: radial-gradient(
    ellipse 92% 82% at 50% 46%,
    transparent 55%,
    rgba(8, 3, 15, 0.12) 62%,
    rgba(8, 3, 15, 0.35) 71%,
    rgba(8, 3, 15, 0.65) 80%,
    rgba(8, 3, 15, 0.88) 88%,
    #08030f 96%
  );
  transition: background 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Tunnel vision — portal tightens when game starts */
.game404--tunneled::before {
  background: radial-gradient(
    ellipse 88% 76% at 50% 46%,
    transparent 48%,
    rgba(8, 3, 15, 0.15) 56%,
    rgba(8, 3, 15, 0.4) 66%,
    rgba(8, 3, 15, 0.7) 76%,
    rgba(8, 3, 15, 0.92) 86%,
    #08030f 94%
  );
}

/* ---- Header text — NEON SIGN ---- */

.game404__header {
  text-align: center;
  max-width: 600px;
}

.game404__title {
  font-family: var(--font-title, "Orbitron", monospace);
  font-size: clamp(1.1rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin: 0;
  color: #b7ff00;
  white-space: nowrap;
  text-shadow:
    0 0 2px #fff,
    0 0 8px #b7ff00,
    0 0 20px #b7ff00,
    0 0 40px rgba(183, 255, 0, 0.4),
    0 0 80px rgba(183, 255, 0, 0.15);
}

.game404__subtitle {
  font-size: clamp(0.85rem, 2vw, 1.1rem);
  margin: 0.5rem 0 0;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.85);
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.5),
    0 0 6px rgba(183, 255, 0, 0.3),
    0 0 15px rgba(183, 255, 0, 0.15);
}

/* ---- Neon sign character-level effects ---- */

.game404__title-char {
  display: inline-block;
  position: relative;
  animation: neonFlicker 4s infinite;
  transition: color 0.3s, text-shadow 0.3s, opacity 0.3s;
}

/* Irregular neon tube buzz — holds full brightness most of the time */
@keyframes neonFlicker {
  0%, 19%, 23%, 25%, 55%, 57%, 100% {
    opacity: 1;
    text-shadow:
      0 0 2px #fff,
      0 0 8px #b7ff00,
      0 0 20px #b7ff00,
      0 0 40px rgba(183, 255, 0, 0.4);
  }
  20%, 24%, 56% {
    opacity: 0.93;
    text-shadow:
      0 0 1px #fff,
      0 0 4px #b7ff00,
      0 0 10px rgba(183, 255, 0, 0.3);
  }
}

/* Hit once — light flickers out rapidly then goes dark */
.game404__title-char--flickering-out {
  animation: neonFlickerOut 400ms ease-out forwards !important;
}

@keyframes neonFlickerOut {
  0%   { opacity: 1; text-shadow: 0 0 8px #b7ff00, 0 0 20px #b7ff00; }
  10%  { opacity: 0.2; text-shadow: none; }
  18%  { opacity: 0.9; text-shadow: 0 0 6px #b7ff00; }
  28%  { opacity: 0.1; text-shadow: none; }
  35%  { opacity: 0.5; text-shadow: 0 0 3px #b7ff00; }
  48%  { opacity: 0.05; text-shadow: none; }
  55%  { opacity: 0.3; text-shadow: 0 0 2px #b7ff00; }
  65%  { opacity: 0.05; text-shadow: none; }
  100% { opacity: 0.4; text-shadow: none; color: #2a3a1a; }
}

/* Dark state — unlit neon tube */
.game404__title-char--dark {
  color: #2a3a1a !important;
  text-shadow: none !important;
  animation: none !important;
  opacity: 0.4 !important;
}

/* Spark on break — pseudo-element shower */
.game404__title-char--sparking::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 20%, #ffaa00 60%, transparent 100%);
  box-shadow: 0 0 6px #ffaa00, 0 0 12px #ff6600;
  animation: sparkFall 600ms ease-out forwards;
  pointer-events: none;
}

@keyframes sparkFall {
  0%   { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(-50%, 18px) scale(0.3); opacity: 0; }
}

/* Fallen letter — detached from sign, tumbling down */
.game404__title-char--fallen {
  position: fixed !important;
  z-index: 9998;
  pointer-events: none !important;
  transition: transform 1.5s cubic-bezier(.2,.6,.35,1), opacity 1.5s ease !important;
  animation: neonFinalPulse 1s ease-out forwards !important;
}

/* Final death pulse — one last flash of neon glory */
@keyframes neonFinalPulse {
  0% {
    color: #b7ff00;
    text-shadow: 0 0 8px #b7ff00, 0 0 20px #b7ff00;
  }
  30% {
    color: #ffffff;
    text-shadow: 0 0 15px #fff, 0 0 30px #b7ff00, 0 0 50px #b7ff00;
  }
  60% {
    color: #b7ff00;
    text-shadow: 0 0 6px #b7ff00;
  }
  100% {
    color: #2a3a1a;
    text-shadow: none;
  }
}

/* ---- Canvas wrapper ---- */

.game404__canvas-wrap {
  position: relative;
  z-index: 91;  /* above portal vignette (z:90) so score popups show */
  /* Width-led, but never taller than the room: state.js _fitTunnelZoom() sets --g4-fit-h to the height
     that fits the title and the whole game in what the page's scroll container shows. Sized by width
     alone, a 640px canvas sat in 621px of room at 1366x768 — HUD under the header, lives under the
     footer. (A max-height + width:auto here shrank the game to its 224px bitmap instead.) */
  width: min(100%, calc(var(--g4-fit-h, 100000px) * 224 / 256));
  max-width: 560px;
  aspect-ratio: 224 / 256;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Tunnel zoom — scales the game on start */
  transform: scale(1);
  transition: transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Tunnel vision zoom — triggered by JS on game start.
   The zoom scales about the centre, so it grows UP as well as down — and a transform moves no
   layout. At a fixed 1.15 it covered the tagline at every desktop size and the neon title itself
   from 1920x1080 up (measured 2026-09-25: 7px at 1920, 19px at 2560). The title is a target —
   bullets leaving the top of the game knock its letters out — so it must stay clear.
   So the zoom is FITTED: state.js _fitTunnelZoom() sets --g4-zoom to the largest scale, up to
   --g4-zoom-max (per breakpoint below), that keeps the scaled top edge below the title, and sets
   --g4-zoom-pad on the section to the bottom overflow, which pushes the legend clear. */
.game404__canvas-wrap { --g4-zoom-max: 1.15; }
.game404__canvas-wrap--zoomed {
  /* --g4-zoom-ty: shifted up into the tagline's room when the bottom of the room is the limit */
  transform: translateY(var(--g4-zoom-ty, 0px)) scale(var(--g4-zoom, var(--g4-zoom-max)));
}

/* The tagline gives its room to the zoom while a game is on, and comes back after it. */
.game404__subtitle { transition: opacity 0.4s ease; }
.game404--tunneled .game404__subtitle { opacity: 0; }

.game404__controls,
.game404__controls-touch { transition: margin-top 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94); }
.game404--tunneled .game404__controls,
.game404--tunneled .game404__controls-touch { margin-top: var(--g4-zoom-pad, 0px); }

.game404__canvas {
  position: relative;
  z-index: 1;                   /* below score popup overlay (z:10) */
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: -moz-crisp-edges;
  border: none;
  border-radius: 8px;           /* CRT rounded glass corners */
  outline: none;
  cursor: crosshair;
  touch-action: none;           /* prevent browser scroll/zoom on canvas */
  -webkit-touch-callout: none;  /* prevent long-press context menu */
  user-select: none;
  -webkit-user-select: none;
  /* CRT bezel — inner vignette shadow + faint phosphor spill */
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.25),
    0 0 20px rgba(100, 80, 255, 0.08),
    0 0 60px rgba(100, 80, 255, 0.04);
}

/* ---- Drone score popup overlay ----
 * HTML layer on top of the canvas — renders at native resolution
 * so text is always crisp regardless of canvas pixelated scaling. */

.game404__score-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 8px;
  z-index: 10;  /* above canvas within the canvas-wrap stacking context */
}

.game404__score-popup {
  position: absolute;
  font-family: "Orbitron", "Oxanium", "Share Tech Mono", monospace;
  font-weight: 900;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  letter-spacing: 0.08em;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
  padding: 0.2em 0.6em;
  border-radius: 6px;
  border: 2px solid rgba(255, 170, 0, 0.6);
  text-shadow:
    0 0 8px  #ffaa00,
    0 0 20px #ffaa00;
  box-shadow:
    0 0 20px rgba(255, 170, 0, 0.4),
    0 0 40px rgba(255, 100, 0, 0.2);
  transform: translate(-50%, 0);
  animation: droneScoreFloat 8s ease-out forwards;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}

@keyframes droneScoreFloat {
  0%   { opacity: 1; transform: translate(-50%, 0) scale(1.3); }   /* pop in big */
  12%  { opacity: 1; transform: translate(-50%, 0) scale(1); }     /* settle to normal */
  72%  { opacity: 1; transform: translate(-50%, -50%); }            /* float up */
  100% { opacity: 0; transform: translate(-50%, -70%); }            /* fade out */
}

/* Reduced motion — skip animation, just fade */
@media (prefers-reduced-motion: reduce) {
  .game404__score-popup {
    animation: droneScoreFade 2s ease-out forwards;
  }
  .game404__score-popup::after {
    animation: none;
    opacity: 0;
  }
  @keyframes droneScoreFade {
    0%   { opacity: 1; }
    70%  { opacity: 1; }
    100% { opacity: 0; }
  }
}

/* Keyboard focus must show: the game takes focus on load, and after a pause (Tab away) this ring is
   how a keyboard player finds their way back to it. */
@media (pointer: fine) {
  .game404__canvas:focus-visible {
    outline: 2px solid #00ffff;
    outline-offset: 3px;
  }
}

/* ---- Controls hint ---- */

.game404__controls {
  display: flex;
  gap: 0.75rem 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 40rem;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.72);   /* ≥7:1 on the page background (AAA); 0.5 was ~5.6:1 */
  letter-spacing: 0.06em;
}

/* Sound toggle — outside .game404__controls so touch players (who never see the key legend)
   can still reach it. Label stays "Sound"; state is aria-pressed, shown by the icon. */
.game404__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
/* Weapon / Grenade: touch screens only — a keyboard has 1–4 and Shift+Space (space-invaders/input.js) */
.game404__sound.game404__touch-action { display: none; }   /* beats .game404__sound's inline-flex */
.game404__touch-action { min-width: 10.5rem; justify-content: center; touch-action: manipulation; }  /* fixed width: no reflow under a thumb */
.game404__touch-action[aria-disabled="true"] { opacity: 0.45; }
.game404__sound {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.game404__sound:hover { border-color: #b7ff00; }
.game404__sound:focus-visible { outline: 2px solid #00ffff; outline-offset: 3px; }
.game404__sound-icon::before { content: "\1F50A"; }                       /* speaker */
.game404__sound[aria-pressed="false"] .game404__sound-icon::before { content: "\1F507"; } /* muted */
.game404__sound[aria-pressed="false"] { color: rgba(255, 255, 255, 0.72); }

.game404__key-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.game404__controls kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.4;
}

/* ---- Leaderboard ---- */

.game404__leaderboard {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

/* ---- Footer / CTA ---- */

.game404__footer {
  text-align: center;
  max-width: 500px;
}

.game404__desc {
  font-size: 0.85rem;
  opacity: 0.6;
  margin: 0 0 1rem;
  line-height: 1.5;
}

.game404__cta {
  display: inline-block;
  padding: 0.7rem 2rem;
  background: var(--lime, #b7ff00);
  color: #000;
  text-decoration: none;
  border-radius: 6px;
  font-family: var(--font-title, "Orbitron", monospace);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: opacity 0.15s ease;
}

.game404__cta:hover,
.game404__cta:focus-visible {
  opacity: 0.85;
}

/* ---- Simple fallback (game disabled) ---- */

.game404--simple {
  gap: 0;
}

.game404__simple-wrap {
  text-align: center;
  padding: 3rem 1rem;
}

.game404__simple-code {
  font-family: var(--font-title, "Orbitron", monospace);
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 900;
  letter-spacing: 0.2em;
  margin: 0;
  color: var(--lime, #b7ff00);
  line-height: 1;
}

.game404__simple-title {
  font-family: var(--font-title, "Orbitron", monospace);
  font-size: clamp(1rem, 3vw, 1.5rem);
  font-weight: 600;
  letter-spacing: 0.1em;
  margin: 1rem 0 0.5rem;
}

.game404__simple-desc {
  font-size: 0.9rem;
  opacity: 0.6;
  margin: 0.5rem 0 2rem;
  max-width: 400px;
  line-height: 1.5;
}

/* ================================================================
 *  RESPONSIVE — Mobile, Tablet, Laptop, Desktop, Ultra-wide
 * ================================================================ */

/* -- Touch device controls swap -- */
.game404__controls-touch { display: none; }

@media (pointer: coarse) {
  .game404__controls { display: none; }
  .game404__sound.game404__touch-action { display: inline-flex; }
  /* The action row (Sound, Weapon, Grenade) sits right under the game, where a thumb can reach it in
     play; _fitTunnelZoom keeps room for it. Below the hint it ended up under the footer on 4 of 5
     touch screens (2026-09-30). */
  .game404__actions { order: 1; }
  .game404__controls-touch, .game404__leaderboard, .game404__footer { order: 2; }
  .game404--tunneled .game404__actions { margin-top: var(--g4-zoom-pad, 0px); }
  .game404--tunneled .game404__controls-touch { margin-top: 0; }
  .game404__controls-touch {
    display: block;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.72);
    letter-spacing: 0.06em;
    text-align: center;
  }
}

/* -- Touch screens held sideways: height is scarce, width is not — the action row floats as a stack
      beside the game instead of taking room under it. -- */
@media (pointer: coarse) and (orientation: landscape) {
  .game404__actions {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    z-index: 95;  /* above the portal vignette (90) */
  }
  .game404--tunneled .game404__actions { margin-top: 0; }
  .game404__touch-action { min-width: 9rem; }
}

/* -- Small phones (≤480px) -- */
@media (max-width: 480px) {
  .game404 {
    padding: 0.5rem;
    padding-bottom: 60px;
    gap: 0.75rem;
  }

  .game404__canvas-wrap {
    max-width: 100%;
  }

  .game404__controls,
  .game404__controls-touch {
    gap: 1rem;
  }

  /* Reduce zoom on tight screens (a cap — _fitTunnelZoom may go lower) */
  .game404__canvas-wrap { --g4-zoom-max: 1.05; }

  .game404__header {
    max-width: 100%;
  }
}

/* -- Ultra-narrow (≤360px, iPhone SE) -- */
@media (max-width: 360px) {
  .game404__title {
    white-space: normal;
    word-spacing: 100vw; /* clean stacked wrapping */
    line-height: 1.3;
    font-size: clamp(1rem, 5vw, 1.5rem);
  }

  .game404__subtitle {
    font-size: 0.75rem;
  }
}

/* -- Short viewports (laptops, landscape tablets) -- */
@media (max-height: 750px) {
  .game404 {
    gap: 0.5rem;
    padding-top: 0.25rem;
    justify-content: flex-start;
  }

  .game404__canvas-wrap { --g4-zoom-max: 1.05; }

  .game404__footer {
    gap: 0.5rem;
  }

  .game404__desc {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
  }
}

/* -- Very short (landscape mobile) -- */
@media (max-height: 500px) {
  .game404 {
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    padding-bottom: 50px;
  }

  .game404__header {
    margin: 0;
  }

  .game404__title {
    font-size: clamp(0.9rem, 3vw, 1.3rem);
  }

  .game404__subtitle {
    display: none; /* save space */
  }

  .game404__canvas-wrap { --g4-zoom-max: 1; } /* no zoom in landscape mobile */

  .game404__desc {
    display: none; /* game is the focus — but the way home stays (it was the only one on the page) */
  }
}

/* -- Tablet (600–1024px) -- */
@media (min-width: 600px) and (max-width: 1024px) {
  .game404__canvas-wrap {
    max-width: min(560px, 72vw);
  }
}

/* -- Large desktop (≥1600px) -- */
@media (min-width: 1600px) and (min-height: 900px) {
  .game404__canvas-wrap {
    max-width: 700px;
  }

  .game404__header {
    max-width: 750px;
  }
}

/* -- Ultra-wide (≥2200px) -- */
@media (min-width: 2200px) and (min-height: 1100px) {
  .game404__canvas-wrap {
    max-width: 840px;
  }

  .game404__header {
    max-width: 900px;
  }

  .game404__title {
    font-size: clamp(2rem, 3vw, 3rem);
  }
}

/* Portrait screens — flip the portal oval to vertical */
@media (orientation: portrait) {
  .game404::before {
    background: radial-gradient(
      ellipse 80% 92% at 50% 46%,
      transparent 55%,
      rgba(8, 3, 15, 0.12) 62%,
      rgba(8, 3, 15, 0.35) 71%,
      rgba(8, 3, 15, 0.65) 80%,
      rgba(8, 3, 15, 0.88) 88%,
      #08030f 96%
    );
  }

  .game404--tunneled::before {
    background: radial-gradient(
      ellipse 74% 86% at 50% 46%,
      transparent 48%,
      rgba(8, 3, 15, 0.15) 56%,
      rgba(8, 3, 15, 0.4) 66%,
      rgba(8, 3, 15, 0.7) 76%,
      rgba(8, 3, 15, 0.92) 86%,
      #08030f 94%
    );
  }
}

/* ---- Laser Beam 4th Wall Break ---- */

.game404__title-char {
  display: inline-block;
  position: relative;
}

/* A letter shot out of the sign keeps its place (a copy tumbles away), so the heading never
   collapses and jumps the page mid-game. */
.game404__title-char--gone {
  visibility: hidden;
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  .game404__cta {
    transition: none;
  }

  .game404__canvas-wrap {
    transition: none;
  }

  .game404::before {
    transition: none;
  }

  .game404__title-char {
    transition: none !important;
    animation: none !important;
  }
  .game404__title-char--sparking::after {
    animation: none !important;
    display: none;
  }
  .game404__title-char--fallen {
    transition: opacity 0.3s !important;
    animation: none !important;
  }
}
