* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --cyan: #00f0ff;
  --cyan-dim: rgba(0, 240, 255, 0.5);
  --cyan-faint: rgba(0, 240, 255, 0.15);
  --amber: #ffb000;
  --amber-dim: rgba(255, 176, 0, 0.5);
  --red: #ff2244;
  --red-dim: rgba(255, 34, 68, 0.5);
  --green: #00ff88;
  --bg-panel: rgba(5, 15, 30, 0.65);
  --font-display: 'Audiowide', 'Courier New', monospace;
  --font-ui: 'Chakra Petch', 'Segoe UI', sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: var(--font-ui);
  color: #fff;
  user-select: none;
}

/* Only hide the cursor while actually flying with the mouse — menus and the
   pause screen always keep a pointer. */
body.in-game.cursor-hidden,
body.in-game.cursor-hidden * {
  cursor: none !important;
}

#game-container { position: relative; width: 100%; height: 100%; }
#game-canvas { display: block; width: 100%; height: 100%; }

/* ═══════════════════════════════════════════════════════════════════════════
   HUD
   ═══════════════════════════════════════════════════════════════════════════ */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-family: var(--font-ui);
}

/* ── Top bar ── */
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 28px;
}

.hud-top-left {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* ── Health ── */
.hud-health {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-health-label {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--cyan-dim);
  text-transform: uppercase;
}

.hud-health-bar-bg {
  width: 260px;
  height: 18px;
  background: rgba(0, 20, 40, 0.8);
  border: 1px solid var(--cyan-faint);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 100%, 8px 100%);
  overflow: hidden;
  position: relative;
}

.hud-health-bar-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0, transparent 22px, rgba(0, 240, 255, 0.08) 22px, rgba(0, 240, 255, 0.08) 23px);
  z-index: 1;
}

.hud-health-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red) 0%, var(--amber) 50%, var(--green) 100%);
  transition: width 0.25s ease;
  box-shadow: 0 0 16px var(--cyan-dim);
}

/* ── Shields ── */
.hud-shields {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-shield-icon {
  width: 16px;
  height: 16px;
  background: var(--cyan);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  box-shadow: 0 0 8px var(--cyan-dim);
  transition: all 0.2s;
}

.hud-shield-icon.empty {
  background: transparent;
  border: 1px solid rgba(0, 240, 255, 0.15);
  box-shadow: none;
}

/* ── Score (big display font, glitch on change) ── */
.hud-top-right {
  text-align: right;
}

.hud-score {
  font-family: var(--font-display);
  font-size: 38px;
  color: var(--amber);
  text-shadow: 0 0 16px var(--amber-dim), 0 0 32px rgba(255, 176, 0, 0.2);
  letter-spacing: 3px;
  line-height: 1;
}

.hud-score::before {
  content: 'SCORE';
  display: block;
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--amber-dim);
  margin-bottom: 4px;
}

/* Glitch animation when score changes */
.score-glitch {
  animation: scoreGlitch 0.45s steps(1) 1;
}

@keyframes scoreGlitch {
  0%   { text-shadow: 0 0 16px var(--amber-dim); transform: translate(0); }
  15%  { text-shadow: 3px 0 0 var(--cyan), -3px 0 0 var(--red), 0 0 16px var(--amber-dim); transform: translate(-2px, 1px); }
  25%  { text-shadow: -3px 0 0 var(--cyan), 3px 0 0 var(--red); transform: translate(2px, -1px); }
  35%  { text-shadow: 2px 0 0 var(--red), -2px 0 0 var(--cyan); transform: translate(-1px, 2px); }
  50%  { text-shadow: -2px 0 0 var(--cyan), 2px 0 0 var(--red); transform: translate(1px, 0); }
  65%  { text-shadow: 1px 0 0 var(--red), -1px 0 0 var(--cyan); transform: translate(0, -1px); }
  80%  { text-shadow: 0 0 20px var(--amber); transform: translate(0); }
  100% { text-shadow: 0 0 16px var(--amber-dim), 0 0 32px rgba(255, 176, 0, 0.2); transform: translate(0); }
}

/* ── Combo ── */
.hud-combo {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--red);
  text-shadow: 0 0 12px var(--red-dim);
  letter-spacing: 3px;
  min-height: 24px;
  margin-top: 6px;
}

.hud-combo:not(:empty) {
  animation: comboPulse 0.3s ease-out;
}

@keyframes comboPulse {
  0%   { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Bottom bar: wave + bombs ── */
.hud-bottom {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 24px;
  align-items: center;
}

.hud-wave {
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--amber);
  letter-spacing: 4px;
  background: var(--bg-panel);
  padding: 10px 24px;
  border: 1px solid var(--amber-dim);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 100%, 10px 100%);
  text-shadow: 0 0 10px var(--amber-dim);
  backdrop-filter: blur(4px);
}

/* ── Bombs ── */
.hud-bombs {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  padding: 8px 20px;
  border: 1px solid rgba(255, 102, 0, 0.3);
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 100%, 0 100%);
  backdrop-filter: blur(4px);
}

.hud-bomb-label {
  font-family: var(--font-display);
  font-size: 13px;
  color: rgba(255, 102, 0, 0.6);
  letter-spacing: 4px;
  text-transform: uppercase;
}

.hud-bomb-icons {
  display: flex;
  gap: 5px;
}

.hud-bomb-icon {
  width: 12px;
  height: 18px;
  background: linear-gradient(180deg, #ff8800, #ff3300);
  clip-path: polygon(50% 0, 100% 30%, 100% 100%, 0 100%, 0 30%);
  box-shadow: 0 0 8px rgba(255, 102, 0, 0.5);
  transition: all 0.2s;
}

.hud-bomb-icon.empty {
  background: transparent;
  border: 1px solid rgba(255, 102, 0, 0.15);
  box-shadow: none;
  clip-path: none;
  border-radius: 1px;
}

/* ── Boss bar ── */
.hud-boss-bar {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  width: 520px;
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--red-dim);
  padding: 12px 24px 10px;
  backdrop-filter: blur(4px);
}

.hud-boss-name {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 8px;
  margin-bottom: 8px;
  text-shadow: 0 0 16px var(--red-dim);
  animation: bossNameGlitch 3s infinite;
}

@keyframes bossNameGlitch {
  0%, 92%, 100% { text-shadow: 0 0 16px var(--red-dim); }
  93% { text-shadow: 3px 0 0 var(--cyan), -3px 0 0 var(--red); }
  95% { text-shadow: -3px 0 0 var(--cyan), 3px 0 0 var(--red); }
  97% { text-shadow: 0 0 16px var(--red-dim); }
}

.hud-boss-health-bg {
  width: 100%;
  height: 12px;
  background: rgba(40, 0, 10, 0.8);
  border: 1px solid var(--red-dim);
  overflow: hidden;
  position: relative;
}

.hud-boss-health-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0, transparent 18px, rgba(255, 34, 68, 0.12) 18px, rgba(255, 34, 68, 0.12) 19px);
  z-index: 1;
}

.hud-boss-health {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--amber));
  transition: width 0.3s ease;
  box-shadow: 0 0 12px var(--red-dim);
}

/* ── Crosshair ── */
#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -44px;
  margin-top: -44px;
  width: 88px;
  height: 88px;
  pointer-events: none;
  z-index: 20;
  transition: transform 0.18s cubic-bezier(.2, 1.6, .4, 1);
}

.crosshair-dot {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  background: var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 14px var(--cyan), 0 0 2px #000;
}

.crosshair-ring {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 72px; height: 72px;
  border: 4px solid var(--cyan-dim);
  border-radius: 50%;
  animation: crosshairSpin 8s linear infinite;
}

.crosshair-ring::before, .crosshair-ring::after {
  content: '';
  position: absolute;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan), 0 0 2px #000;
}

.crosshair-ring::before  { top: -3px; left: 50%; transform: translateX(-50%); width: 6px; height: 20px; }
.crosshair-ring::after   { bottom: -3px; left: 50%; transform: translateX(-50%); width: 6px; height: 20px; }

@keyframes crosshairSpin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to   { transform: translate(-50%, -50%) rotate(360deg); }
}

.crosshair-line {
  position: absolute;
  background: var(--cyan-dim);
  box-shadow: 0 0 6px var(--cyan-dim), 0 0 2px #000;
}

.crosshair-line.top    { top: 0;    left: 50%; transform: translateX(-50%); width: 6px; height: 24px; }
.crosshair-line.bottom { bottom: 0; left: 50%; transform: translateX(-50%); width: 6px; height: 24px; }
.crosshair-line.left   { left: 0;   top: 50%; transform: translateY(-50%); width: 24px; height: 6px; }
.crosshair-line.right  { right: 0;  top: 50%; transform: translateY(-50%); width: 24px; height: 6px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Screens
   ═══════════════════════════════════════════════════════════════════════════ */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  /* Translucent so the live 3D scene (menu ship orbit) shows through. */
  background:
    radial-gradient(ellipse at 50% 45%, rgba(2, 8, 22, 0.35) 0%, rgba(1, 4, 12, 0.78) 60%, rgba(0, 0, 0, 0.94) 100%);
  pointer-events: auto;
}

.screen.hidden { display: none; }

.menu-content {
  text-align: center;
  max-width: 560px;
  padding: 40px;
}

.game-title {
  font-family: var(--font-display);
  font-size: 84px;
  background: linear-gradient(135deg, var(--cyan) 0%, var(--amber) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 8px;
  margin-bottom: 28px;
  filter: drop-shadow(0 0 30px rgba(0, 240, 255, 0.4));
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  from { filter: drop-shadow(0 0 20px rgba(0, 240, 255, 0.3)); }
  to   { filter: drop-shadow(0 0 40px rgba(255, 176, 0, 0.5)); }
}

.menu-button {
  display: block;
  margin: 20px auto;
  padding: 18px 64px;
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 5px;
  color: var(--cyan);
  background: transparent;
  border: 2px solid var(--cyan-dim);
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 100%, 0 100%);
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.2s;
  text-shadow: 0 0 12px var(--cyan-dim);
}

.menu-button:hover {
  background: var(--cyan-faint);
  border-color: var(--cyan);
  box-shadow: 0 0 40px var(--cyan-dim);
  letter-spacing: 7px;
}

.menu-button:active { transform: scale(0.96); }

.controls-info {
  margin-top: 40px;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  color: rgba(0, 240, 255, 0.4);
  line-height: 2;
  letter-spacing: 1px;
}

.score-display {
  font-family: var(--font-display);
  font-size: 32px;
  color: var(--amber);
  margin: 16px 0;
  text-shadow: 0 0 16px var(--amber-dim);
}

h2 {
  font-family: var(--font-display);
  font-size: 60px;
  color: var(--red);
  text-shadow: 0 0 28px var(--red-dim);
  letter-spacing: 10px;
  margin-bottom: 32px;
}

/* ── Damage flash ── */
.damage-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 0, 30, 0.3) 100%);
  opacity: 0;
  transition: opacity 0.1s;
}

.damage-flash.visible { opacity: 1; }
.damage-flash.hidden  { opacity: 0; }

/* ── Enemy fire flash: quick subtle blue pulse when an enemy shoots ── */
#enemy-fire-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 49;
  background: rgba(120, 180, 255, 0.12);
  opacity: 0;
}

/* ── Glitch overlay (RGB-split + scanlines) on player damage ── */
#glitch-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 55;
  opacity: 0;
  mix-blend-mode: screen;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 2px,
      rgba(255, 255, 255, 0.04) 2px,
      rgba(255, 255, 255, 0.04) 3px
    );
}

#glitch-overlay::before,
#glitch-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 35%, rgba(255, 0, 60, 0.18) 100%),
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 6px,
      rgba(0, 255, 255, 0.05) 6px,
      rgba(0, 255, 255, 0.05) 7px
    );
}

#glitch-overlay::before { background-color: rgba(255, 0, 60, 0.08); }
#glitch-overlay::after  { background-color: rgba(0, 255, 255, 0.08); }

#glitch-overlay.glitch-active {
  animation: glitchFlicker 0.22s steps(8, end) 1;
}

#glitch-overlay.glitch-active::before {
  animation: glitchShiftRed 0.22s steps(4, end) 1;
}

#glitch-overlay.glitch-active::after {
  animation: glitchShiftCyan 0.22s steps(4, end) 1;
}

@keyframes glitchFlicker {
  0%, 100% { opacity: 0; }
  20%, 60% { opacity: 1; }
  40%, 80% { opacity: 0.6; }
}

@keyframes glitchShiftRed {
  0%   { transform: translate(-6px, 0); }
  25%  { transform: translate( 8px, -2px); }
  50%  { transform: translate(-4px, 3px); }
  75%  { transform: translate( 5px,  0); }
  100% { transform: translate( 0, 0); }
}

@keyframes glitchShiftCyan {
  0%   { transform: translate( 6px, 0); }
  25%  { transform: translate(-8px,  2px); }
  50%  { transform: translate( 4px, -3px); }
  75%  { transform: translate(-5px,  0); }
  100% { transform: translate( 0, 0); }
}

.hidden { display: none !important; }

/* ── Speed lines ── */
#speed-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
  opacity: 0.2;
}

#speed-lines::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background-image:
    linear-gradient(0deg, transparent 48%, rgba(200, 220, 255, 0.15) 49%, rgba(200, 220, 255, 0.15) 50%, transparent 51%),
    linear-gradient(0deg, transparent 48%, rgba(200, 220, 255, 0.1) 49%, rgba(200, 220, 255, 0.1) 50%, transparent 51%);
  background-size: 100% 8px, 100% 12px;
  animation: speedLinesScroll 0.15s linear infinite;
  transform: perspective(400px) rotateX(10deg) scaleY(2);
  transform-origin: center;
}

@keyframes speedLinesScroll {
  from { transform: perspective(400px) rotateX(10deg) scaleY(2) translateY(0); }
  to   { transform: perspective(400px) rotateX(10deg) scaleY(2) translateY(12px); }
}

/* ── Vignette ── */
#vignette-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(ellipse at center, transparent 70%, rgba(0, 0, 10, 0.35) 100%);
}

/* ── Fade to black overlay ── */
#fade-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  background: #000;
  opacity: 0;
  transition: opacity 0.8s ease;
}

#fade-overlay.visible {
  opacity: 1;
}

/* ── ENGAGE text ── */
#engage-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 96px;
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 40px var(--cyan-dim), 0 0 80px rgba(0, 240, 255, 0.3);
  letter-spacing: 12px;
  z-index: 65;
  opacity: 0;
  pointer-events: none;
}



/* ── Lives display ── */
#lives-display {
  position: absolute;
  top: 80px;
  right: 28px;
  display: flex;
  gap: 6px;
  z-index: 10;
  pointer-events: none;
}

.life-icon {
  width: 18px;
  height: 18px;
  background: var(--cyan);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  box-shadow: 0 0 8px var(--cyan-dim);
}

.life-icon.empty {
  background: transparent;
  border: 1px solid rgba(0, 240, 255, 0.15);
  box-shadow: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOTION DESIGN LAYER
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --ease-out-back: cubic-bezier(.2, 1.6, .4, 1);
  --ease-out-expo: cubic-bezier(.16, 1, .3, 1);
  --ease-in-expo: cubic-bezier(.7, 0, .84, 0);
}

kbd {
  display: inline-block;
  min-width: 28px;
  padding: 3px 8px;
  margin-right: 6px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.07);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-bottom-width: 3px;
  border-radius: 4px;
  text-align: center;
}

/* ── Menu ───────────────────────────────────────────────────────────────── */

#menu-screen .menu-content { max-width: 680px; }

.menu-kicker {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 8px;
  color: var(--amber);
  opacity: 0;
  animation: fadeUp .8s var(--ease-out-expo) .15s forwards;
}

.game-title {
  font-size: clamp(56px, 11vw, 120px);
  margin: 6px 0 4px;
  letter-spacing: 6px;
  white-space: nowrap;
  background: none;
  -webkit-text-fill-color: initial;
  filter: none;
  animation: none;
}

.title-ch {
  display: inline-block;
  background: linear-gradient(160deg, #eaffff 0%, var(--cyan) 35%, #6af 60%, var(--amber) 100%);
  background-size: 100% 220%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 18px rgba(0, 240, 255, 0.45));
  opacity: 0;
  transform: translateY(-80px) rotateX(90deg) scale(1.4);
  animation:
    titleDrop .9s var(--ease-out-back) calc(.25s + var(--i) * .07s) forwards,
    titleShine 4s ease-in-out calc(1.6s + var(--i) * .08s) infinite;
}

@keyframes titleDrop {
  60% { opacity: 1; }
  to  { opacity: 1; transform: none; }
}

@keyframes titleShine {
  0%, 70%, 100% { background-position: 0 0; filter: drop-shadow(0 0 18px rgba(0, 240, 255, 0.45)); }
  80% { background-position: 0 100%; filter: drop-shadow(0 0 34px rgba(255, 210, 120, 0.8)); }
}

.menu-sub {
  font-size: 15px;
  letter-spacing: 3px;
  color: rgba(200, 240, 255, 0.7);
  margin-bottom: 26px;
  opacity: 0;
  animation: fadeUp .8s var(--ease-out-expo) 1s forwards;
}

.menu-button {
  position: relative;
  overflow: hidden;
}

.menu-button::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 40%;
  left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: skewX(-20deg);
  animation: btnSweep 3.2s ease-in-out infinite;
}

.menu-button.primary {
  color: #001018;
  background: linear-gradient(90deg, var(--cyan), #7af);
  border-color: transparent;
  text-shadow: none;
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.35);
  animation: btnBreath 2.4s ease-in-out infinite;
}

.menu-button.primary:hover {
  background: linear-gradient(90deg, #8ff, #adf);
  box-shadow: 0 0 60px rgba(0, 240, 255, 0.7);
}

#menu-screen .menu-button { opacity: 0; animation: fadeUp .7s var(--ease-out-back) 1.2s forwards, btnBreath 2.4s ease-in-out 2s infinite; }

@keyframes btnSweep {
  0%, 55% { left: -60%; }
  80%, 100% { left: 130%; }
}

@keyframes btnBreath {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

.press-hint {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 5px;
  color: rgba(0, 240, 255, 0.55);
  animation: blinkSoft 1.4s ease-in-out infinite;
}

.menu-best {
  margin-top: 14px;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--amber);
  text-shadow: 0 0 14px var(--amber-dim);
  min-height: 18px;
}

@keyframes blinkSoft {
  0%, 100% { opacity: .25; }
  50% { opacity: 1; }
}

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

.controls-info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 26px;
  margin-top: 30px;
  text-align: left;
  font-size: 13px;
  line-height: 1.4;
  color: rgba(200, 240, 255, 0.65);
}

.controls-info > div {
  display: flex;
  align-items: center;
  opacity: 0;
  animation: fadeUp .6s var(--ease-out-expo) forwards;
}
.controls-info > div:nth-child(1) { animation-delay: 1.4s; }
.controls-info > div:nth-child(2) { animation-delay: 1.48s; }
.controls-info > div:nth-child(3) { animation-delay: 1.56s; }
.controls-info > div:nth-child(4) { animation-delay: 1.64s; }
.controls-info > div:nth-child(5) { animation-delay: 1.72s; }
.controls-info > div:nth-child(6) { animation-delay: 1.8s; }
.controls-info span { margin-left: 4px; }

@media (max-width: 640px) {
  .controls-info { grid-template-columns: 1fr; }
  .menu-content { padding: 24px 16px; }
}

/* Every screen panel springs in. */
.screen:not(.hidden) .menu-content {
  animation: panelIn .55s var(--ease-out-expo);
}

@keyframes panelIn {
  from { opacity: 0; transform: scale(.92) translateY(10px); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: none; }
}

.score-display.small { font-size: 20px; opacity: .8; }

.record-badge {
  display: none;
  font-family: var(--font-display);
  letter-spacing: 6px;
  color: #001018;
  background: var(--amber);
  padding: 6px 16px;
  margin: 8px auto 18px;
  width: fit-content;
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
}
.record-badge.visible { display: block; animation: recordPop .8s var(--ease-out-back) 1.4s both, blinkSoft 1s ease-in-out 2.2s infinite; }

@keyframes recordPop {
  from { opacity: 0; transform: scale(2.4) rotate(-6deg); }
  to   { opacity: 1; transform: none; }
}

.glitch-title { position: relative; animation: glitchJitter 2.4s steps(1) infinite; }
.glitch-title::before, .glitch-title::after {
  content: attr(data-text);
  position: absolute; inset: 0;
  pointer-events: none;
}
.glitch-title::before { color: var(--cyan); transform: translate(-3px, 0); clip-path: inset(0 0 55% 0); opacity: .7; }
.glitch-title::after  { color: #ff0; transform: translate(3px, 0); clip-path: inset(55% 0 0 0); opacity: .5; }

@keyframes glitchJitter {
  0%, 88%, 100% { transform: none; }
  90% { transform: translate(-4px, 1px) skewX(8deg); }
  93% { transform: translate(3px, -2px) skewX(-6deg); }
  96% { transform: translate(-1px, 0); }
}

.victory-title {
  color: var(--amber);
  text-shadow: 0 0 30px var(--amber-dim), 0 0 80px rgba(255, 176, 0, 0.4);
  animation: victoryPulse 1.6s ease-in-out infinite;
}

@keyframes victoryPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ── HUD entrance + reactions ───────────────────────────────────────────── */

.hud-slide-left  { animation: hudLeft .8s var(--ease-out-expo) .2s both; }
.hud-slide-right { animation: hudRight .8s var(--ease-out-expo) .3s both; }
.hud-slide-up    { animation: hudUp .8s var(--ease-out-expo) .4s both; }

@keyframes hudLeft  { from { opacity: 0; transform: translateX(-60px); } }
@keyframes hudRight { from { opacity: 0; transform: translateX(60px); } }
@keyframes hudUp    { from { opacity: 0; transform: translate(-50%, 50px); } to { transform: translate(-50%, 0); } }

.hud-kick { animation: hudKick .35s var(--ease-out-back); }
@keyframes hudKick {
  0% { transform: translateX(0); }
  20% { transform: translateX(-7px) scale(1.04); }
  45% { transform: translateX(5px); }
  70% { transform: translateX(-2px); }
  100% { transform: none; }
}

.hud-health-bar-bg { position: relative; }
.hud-health-bar { position: relative; z-index: 2; transition: width .18s var(--ease-out-expo); }
.hud-health-trail {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.85);
  z-index: 1;
}

.hud-health.critical .hud-health-label { color: var(--red); animation: blinkSoft .5s ease-in-out infinite; }
.hud-health.critical .hud-health-bar-bg { box-shadow: 0 0 18px rgba(255, 34, 68, .6); animation: critPulse .6s ease-in-out infinite; }
@keyframes critPulse { 50% { border-color: var(--red); } }

.score-pop-anim { animation: scorePop .3s var(--ease-out-back); }
@keyframes scorePop {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); color: #fff; text-shadow: 0 0 24px var(--amber); }
  100% { transform: scale(1); }
}
.hud-score { transform-origin: right center; display: inline-block; }

/* Combo meter */
.hud-combo {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 2px;
  font-size: 30px;
  min-height: 40px;
  opacity: 0;
  transform: scale(.6);
  transform-origin: right center;
  transition: opacity .2s, transform .25s var(--ease-out-back);
  position: relative;
  animation: none;
}
.hud-combo.active { opacity: 1; transform: scale(1); }
.hud-combo-x { font-size: 18px; opacity: .8; }
.hud-combo-timer {
  position: absolute;
  right: 0; bottom: -2px;
  width: 90px; height: 3px;
  background: rgba(255, 255, 255, .1);
}
.hud-combo-timer > div {
  height: 100%;
  background: currentColor;
  transform-origin: right center;
  box-shadow: 0 0 8px currentColor;
}
.hud-combo[data-tier="1"] { color: #ffd84a; text-shadow: 0 0 14px rgba(255, 216, 74, .6); }
.hud-combo[data-tier="2"] { color: #ff8a2a; text-shadow: 0 0 18px rgba(255, 138, 42, .7); }
.hud-combo[data-tier="3"] { color: #ff2fd0; text-shadow: 0 0 24px rgba(255, 47, 208, .8), 0 0 4px #fff; animation: comboHot .4s ease-in-out infinite alternate; }
.combo-bump { animation: comboBump .28s var(--ease-out-back) !important; }
.combo-break { animation: comboBreak .45s ease-out !important; }
@keyframes comboBump { 0% { transform: scale(1.6) rotate(-6deg); } 100% { transform: scale(1); } }
@keyframes comboBreak { 0% { opacity: 1; transform: scale(1); filter: none; } 100% { opacity: 0; transform: scale(.4) translateY(20px); filter: blur(4px); } }
@keyframes comboHot { from { filter: hue-rotate(0deg); } to { filter: hue-rotate(40deg); } }

.wave-flash { animation: waveFlash .6s ease-out; }
@keyframes waveFlash {
  0% { background: rgba(255, 176, 0, .55); color: #fff; transform: scale(1.12); }
  100% { background: var(--bg-panel); transform: none; }
}

/* Boost meter */
.hud-boost {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  padding: 10px 18px;
  border: 1px solid rgba(0, 240, 255, 0.3);
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 100%, 0 100%);
  backdrop-filter: blur(4px);
}
.hud-boost .hud-bomb-label { color: rgba(0, 240, 255, .7); }
.hud-boost-bg { width: 110px; height: 8px; background: rgba(0, 40, 60, .8); overflow: hidden; }
.hud-boost-bar {
  height: 100%;
  background: linear-gradient(90deg, #08f, var(--cyan), #fff);
  transform-origin: left center;
  box-shadow: 0 0 10px var(--cyan);
}
.hud-boost.boosting { border-color: var(--cyan); box-shadow: 0 0 24px rgba(0, 240, 255, .5); }
.hud-boost.boosting .hud-boost-bar { animation: boostShimmer .25s linear infinite; }
.hud-boost.empty .hud-bomb-label { color: var(--red); animation: blinkSoft .6s infinite; }
@keyframes boostShimmer { 50% { filter: brightness(1.8); } }

/* Boss bar */
.hud-boss-health { position: relative; z-index: 2; transition: width .12s ease-out; }
.hud-boss-trail { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255, 240, 220, .85); z-index: 1; }
.hud-boss-tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: rgba(255, 255, 255, .5); z-index: 3; }
.hud-boss-bar { top: 74px; bottom: auto; width: min(520px, 70vw); }
.boss-in { animation: bossIn .9s var(--ease-out-back); }
.boss-hit .hud-boss-health-bg { animation: bossHit .12s linear; }
@keyframes bossIn { from { opacity: 0; transform: translate(-50%, -60px) scaleX(.2); } to { transform: translate(-50%, 0); } }
@keyframes bossHit { 50% { transform: translateX(3px); filter: brightness(1.8); } }

/* Crosshair states */
.crosshair-ring, .crosshair-dot, .crosshair-line { transition: border-color .15s, background .15s, width .2s var(--ease-out-back), height .2s var(--ease-out-back); }
#crosshair.locked { transform: scale(.82) rotate(45deg); }
#crosshair.locked .crosshair-ring { border-color: rgba(255, 60, 90, .9); animation-duration: 1.2s; }
#crosshair.locked .crosshair-dot,
#crosshair.locked .crosshair-ring::before,
#crosshair.locked .crosshair-ring::after { background: #ff3c5a; box-shadow: 0 0 14px #ff3c5a; }
#crosshair.locked .crosshair-line { background: rgba(255, 60, 90, .8); }

.crosshair-hit { position: absolute; inset: 0; opacity: 0; }
.crosshair-hit i {
  position: absolute;
  left: 50%; top: 50%;
  width: 4px; height: 18px;
  margin: -9px 0 0 -2px;
  background: #fff;
  box-shadow: 0 0 8px #fff;
}
.crosshair-hit i:nth-child(1) { transform: rotate(45deg) translateY(-26px); }
.crosshair-hit i:nth-child(2) { transform: rotate(135deg) translateY(-26px); }
.crosshair-hit i:nth-child(3) { transform: rotate(225deg) translateY(-26px); }
.crosshair-hit i:nth-child(4) { transform: rotate(315deg) translateY(-26px); }
#crosshair.hit .crosshair-hit { animation: hitMark .14s ease-out; }
#crosshair.kill .crosshair-hit { animation: killMark .26s ease-out; }
#crosshair.kill .crosshair-hit i { background: #ffcf4a; box-shadow: 0 0 10px #ffcf4a; }
@keyframes hitMark { 0% { opacity: 1; transform: scale(.7); } 100% { opacity: 0; transform: scale(1.1); } }
@keyframes killMark { 0% { opacity: 1; transform: scale(.6) rotate(0); } 100% { opacity: 0; transform: scale(1.5) rotate(20deg); } }

/* Lives */
#lives-display.life-lost .life-icon:not(.empty) { animation: lifeShake .5s ease-out; }
#lives-display.life-lost { animation: hudKick .5s ease-out; }
@keyframes lifeShake { 30% { transform: scale(1.4); background: #fff; } }

/* ── ENGAGE ────────────────────────────────────────────────────────────── */
#engage-text { display: flex; gap: 2px; top: 72%; font-size: clamp(48px, 9vw, 96px); }
#engage-text span {
  display: inline-block;
  opacity: 0;
}
#engage-text.visible { opacity: 1; }
#engage-text.visible span {
  animation:
    engageSlam .5s var(--ease-out-back) calc(var(--i) * .06s) both,
    engageFlicker 2.9s steps(1) calc(.5s + var(--i) * .06s) both;
}
@keyframes engageSlam {
  from { opacity: 0; transform: scale(3) translateY(-20px); filter: blur(12px); }
  to   { opacity: 1; transform: none; filter: none; }
}
@keyframes engageFlicker {
  0%, 60%, 64%, 80% { opacity: 1; }
  62%, 78%, 82% { opacity: .2; }
  92% { opacity: 1; transform: none; filter: none; letter-spacing: 0; }
  100% { opacity: 0; transform: scaleX(2.2); filter: blur(10px); }
}

/* ── Announcer ─────────────────────────────────────────────────────────── */
#announcer { position: absolute; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.ann { position: absolute; left: 0; right: 0; text-align: center; }
.ann-ch { display: inline-block; opacity: 0; animation: chIn .5s var(--ease-out-expo) both; }
@keyframes chIn { from { opacity: 0; transform: translateY(24px) scale(.6); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

/* Stage intro */
.ann-stage { top: 24%; animation: annOut .6s var(--ease-in-expo) 2.9s forwards; }
.ann-stage-kicker {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 10px;
  color: var(--amber);
  text-shadow: 0 0 14px var(--amber-dim);
}
.ann-stage-name {
  font-family: var(--font-display);
  font-size: clamp(30px, 6vw, 64px);
  letter-spacing: 6px;
  color: #fff;
  text-shadow: 0 0 24px var(--cyan), 0 0 60px rgba(0, 240, 255, .4);
  margin: 10px 0;
}
.ann-stage-line {
  height: 2px;
  width: min(560px, 80vw);
  margin: 0 auto;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  transform: scaleX(0);
  animation: lineWipe .9s var(--ease-out-expo) .1s forwards;
}
.ann-stage-line.l2 { animation-delay: .35s; }
@keyframes lineWipe { to { transform: scaleX(1); } }
@keyframes annOut { to { opacity: 0; transform: translateY(-30px) scale(1.05); filter: blur(8px); } }

/* Mission complete */
.ann-clear { top: 32%; animation: annOut .6s var(--ease-in-expo) 3.5s forwards; }
.ann-clear-title {
  font-family: var(--font-display);
  font-size: clamp(32px, 6.5vw, 72px);
  letter-spacing: 5px;
  color: var(--amber);
  text-shadow: 0 0 28px var(--amber-dim), 0 0 80px rgba(255, 176, 0, .35);
}
.ann-clear-bonus {
  margin-top: 14px;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 6px;
  color: rgba(255, 255, 255, .8);
  opacity: 0;
  animation: fadeUp .5s var(--ease-out-expo) .6s forwards;
}
.ann-tally { color: #fff; text-shadow: 0 0 16px var(--cyan); }
.ann-tally.done { animation: scorePop .4s var(--ease-out-back); display: inline-block; }

/* Boss warning */
.ann-warn { top: 36%; animation: annOut .4s var(--ease-in-expo) 2.8s forwards; }
.ann-warn-stripes {
  height: 16px;
  background: repeating-linear-gradient(-45deg, #ff2244 0 18px, #1a0006 18px 36px);
  background-size: 51px 100%;
  animation: stripeScroll .6s linear infinite, stripeIn .5s var(--ease-out-expo) both;
  box-shadow: 0 0 30px rgba(255, 34, 68, .6);
}
.ann-warn-stripes.bottom { animation-direction: reverse, normal; }
.ann-warn-body { background: rgba(40, 0, 8, .65); padding: 14px 0; backdrop-filter: blur(3px); }
.ann-warn-title {
  font-family: var(--font-display);
  font-size: clamp(40px, 8vw, 92px);
  letter-spacing: 18px;
  color: #ff2244;
  text-shadow: 0 0 30px rgba(255, 34, 68, .9), 0 0 4px #fff;
  animation: blinkSoft .5s ease-in-out infinite;
}
.ann-warn-sub { font-family: var(--font-display); letter-spacing: 8px; font-size: 14px; color: #ffb3bf; }
@keyframes stripeScroll { to { background-position: 51px 0; } }
@keyframes stripeIn { from { transform: scaleX(0); } to { transform: scaleX(1); } }

#game-container.alarm::after {
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 69;
  box-shadow: inset 0 0 120px rgba(255, 20, 50, .55);
  animation: alarmPulse .55s ease-in-out infinite;
}
@keyframes alarmPulse { 50% { box-shadow: inset 0 0 40px rgba(255, 20, 50, .15); } }

/* Toasts */
.ann-toast {
  top: 22%;
  animation: toastLife 1.4s var(--ease-out-expo) forwards;
}
.ann-toast span {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 8px;
  padding: 8px 26px;
  border: 1px solid currentColor;
  background: rgba(0, 10, 20, .55);
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
  text-shadow: 0 0 14px currentColor;
}
.ann-toast.tone-cyan  { color: var(--cyan); }
.ann-toast.tone-amber { color: var(--amber); }
.ann-toast.tone-red   { color: #ff3355; }
.ann-toast.tone-green { color: var(--green); }
@keyframes toastLife {
  0%   { opacity: 0; transform: scale(1.8); filter: blur(6px); }
  15%  { opacity: 1; transform: scale(1); filter: none; }
  75%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-24px); }
}

/* ── Score popups ──────────────────────────────────────────────────────── */
#score-popups { position: absolute; inset: 0; pointer-events: none; z-index: 18; overflow: hidden; }
.score-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 18px;
  color: #fff;
  text-shadow: 0 0 10px var(--amber), 0 2px 0 rgba(0, 0, 0, .6);
  white-space: nowrap;
  opacity: 0;
}
.score-pop small { font-size: .7em; margin-left: 4px; color: var(--amber); }
.score-pop.live { animation: popRise 1s var(--ease-out-expo) forwards; }
.score-pop.tier-1 { font-size: 21px; }
.score-pop.tier-2 { font-size: 25px; color: #ffd84a; }
.score-pop.tier-3 { font-size: 30px; color: #ff6ae0; text-shadow: 0 0 16px #ff2fd0, 0 2px 0 rgba(0, 0, 0, .6); }
@keyframes popRise {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  15%  { opacity: 1; transform: translate(-50%, -80%) scale(1.25); }
  30%  { transform: translate(-50%, -90%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--drift, 0px)), -260%) scale(.9); }
}

@media (prefers-reduced-motion: reduce) {
  .title-ch, .menu-button, .press-hint, .ann, .ann-ch, #engage-text.visible span { animation-duration: .01s !important; animation-iteration-count: 1 !important; }
}

/* Wide screens: menu panel on the left, the orbiting ship on the right. */
@media (min-width: 1000px) and (min-aspect-ratio: 13/10) {
  #menu-screen { justify-content: flex-start; padding-left: 6vw;
    background: linear-gradient(90deg, rgba(1, 4, 12, 0.88) 0%, rgba(1, 4, 12, 0.55) 45%, rgba(0, 0, 0, 0) 75%); }
  #menu-screen .menu-content { text-align: left; padding: 40px 0; }
  #menu-screen .menu-button { margin-left: 0; }
}

/* Reticle and score popups only exist while actually flying. */
body:not(.in-game) #crosshair,
body:not(.in-game) #score-popups { display: none; }

h2 { white-space: nowrap; font-size: clamp(36px, 8vw, 60px); }

/* ═══════════════════════════════════════════════════════════════════════════
   TOUCH CONTROLS + MOBILE LAYOUT
   ═══════════════════════════════════════════════════════════════════════════ */

html, body { overscroll-behavior: none; }
#game-container { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }

.touch-only { display: none !important; }
body.touch .touch-only { display: grid !important; }
body.touch .desktop-only { display: none !important; }

#touch-controls { display: none; position: absolute; inset: 0; z-index: 12; pointer-events: none; }
body.touch.in-game #touch-controls { display: block; }

.tc-zone {
  position: absolute; left: 0; bottom: 0; width: 55%; height: 62%;
  pointer-events: auto; touch-action: none;
}
.tc-hint {
  position: absolute; left: calc(18px + env(safe-area-inset-left)); bottom: calc(26px + env(safe-area-inset-bottom));
  font-family: var(--font-display); font-size: 9px; letter-spacing: 2px; color: rgba(0, 240, 255, .45); white-space: nowrap;
  transition: opacity .3s;
}
#touch-controls.stick-on .tc-hint { opacity: 0; }
.tc-base {
  position: absolute; left: 30%; top: 62%; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%; border: 2px solid rgba(0, 240, 255, .28);
  background: radial-gradient(circle, rgba(0, 240, 255, .10) 0%, rgba(0, 240, 255, .03) 60%, transparent 70%);
  opacity: .35; transition: opacity .2s;
}
#touch-controls.stick-on .tc-base { opacity: 1; transition: none; }
.tc-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(180, 250, 255, .9), rgba(0, 200, 255, .55) 60%, rgba(0, 120, 200, .4));
  box-shadow: 0 0 18px rgba(0, 240, 255, .55);
}

.tc-btn {
  pointer-events: auto; touch-action: none;
  position: relative; display: grid; place-items: center;
  border-radius: 50%; border: 2px solid rgba(0, 240, 255, .45);
  background: rgba(2, 16, 30, .45); backdrop-filter: blur(3px);
  color: var(--cyan); font-family: var(--font-display); font-size: 11px; letter-spacing: 2px;
  transition: transform .08s, background .08s, box-shadow .08s;
}
.tc-btn.pressed { transform: scale(.9); background: rgba(0, 240, 255, .28); box-shadow: 0 0 22px rgba(0, 240, 255, .6); }
.tc-actions {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 210px; height: 210px;
}
.tc-actions .tc-btn { position: absolute; }
.tc-fire  { right: 0; bottom: 0; width: 96px; height: 96px; font-size: 13px; color: #fff; border-color: rgba(255, 60, 90, .8); background: rgba(80, 0, 20, .45); }
.tc-fire.pressed { background: rgba(255, 40, 80, .4); box-shadow: 0 0 26px rgba(255, 40, 80, .7); }
.tc-boost { right: 108px; bottom: 6px; width: 70px; height: 70px; }
.tc-bomb  { right: 8px; bottom: 108px; width: 70px; height: 70px; color: var(--amber); border-color: rgba(255, 140, 0, .7); }
.tc-roll  { width: 52px; height: 52px; font-size: 24px; letter-spacing: 0; }
.tc-roll[data-tap="rollLeft"]  { right: 150px; bottom: 92px; }
.tc-roll[data-tap="rollRight"] { right: 92px; bottom: 132px; }
.tc-pause {
  position: absolute; top: calc(62px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: 42px; height: 42px; font-size: 14px; letter-spacing: 1px;
}
.tc-pause.pressed { transform: translateX(-50%) scale(.9); }

/* Compact HUD for phones (portrait, or short landscape). */
@media (max-width: 640px), (max-height: 500px) {
  .hud-top { padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left)); }
  .hud-top-left { gap: 8px; flex-wrap: wrap; }
  .hud-health-label { font-size: 10px; letter-spacing: 2px; }
  .hud-health-bar-bg { width: min(38vw, 220px); height: 12px; }
  .hud-shield-icon { width: 11px; height: 11px; }
  .hud-score { font-size: 22px; letter-spacing: 1px; }
  .hud-score::before { font-size: 8px; letter-spacing: 3px; margin-bottom: 2px; }
  .hud-combo { font-size: 14px; }
  #lives-display { top: calc(52px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); transform: scale(.75); transform-origin: right top; }
  .hud-bottom { gap: 6px; bottom: auto; top: calc(112px + env(safe-area-inset-top)); transform: translateX(-50%) scale(.9); transform-origin: center top; max-width: 100vw; }
  .hud-bottom .hud-bomb-label { display: none; }
  .hud-bomb-icon { width: 9px; height: 14px; }
  body:not(.touch) .hud-bottom { top: auto; bottom: 12px; transform-origin: center bottom; }
  .hud-wave { padding: 6px 12px; font-size: 12px; letter-spacing: 1px; }
  .hud-bombs, .hud-boost { padding: 6px 12px; }
  .hud-boost-bg { width: 56px; }
  .hud-boss-bar { top: calc(150px + env(safe-area-inset-top)); width: 86vw; }
  #engage-text { top: 40%; }
  .menu-kicker { font-size: 11px; letter-spacing: 4px; }
  .controls-info { font-size: 12px; gap: 6px; margin-top: 16px; }
}
@media (max-height: 500px) {
  .hud-bottom { top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); transform-origin: center bottom; }
  .tc-pause { top: calc(8px + env(safe-area-inset-top)); }
  #lives-display { top: calc(40px + env(safe-area-inset-top)); }
  .tc-zone { height: 80%; }
  .tc-actions { transform: scale(.85); transform-origin: right bottom; }
}

/* ═══ Story: «El Eco del Leviatán» ══════════════════════════════════════════ */

/* ── Comms panel (Lyra / raw sensor feed) ── */
#comms {
  --tone: var(--cyan);
  position: absolute; left: 50%; bottom: 74px; z-index: 68;
  width: min(600px, 88vw);
  display: flex; gap: 14px; align-items: center;
  padding: 9px 16px;
  background: linear-gradient(90deg, rgba(4, 12, 26, .74), rgba(4, 12, 26, .38));
  border-left: 3px solid var(--tone);
  box-shadow: 0 0 24px rgba(0, 0, 0, .5), inset 0 0 30px color-mix(in srgb, var(--tone) 8%, transparent);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
  pointer-events: none;
  opacity: 0; transform: translate(-50%, 14px);
  transition: opacity .25s ease, transform .35s var(--ease-out-expo), border-color .6s;
}
#comms.open { opacity: 1; transform: translate(-50%, 0); }
body:not(.in-game) #comms { display: none; }
#comms[data-mood="tense"]  { --tone: #7fd8ff; }
#comms[data-mood="urgent"] { --tone: var(--amber); }
#comms[data-mood="cold"]   { --tone: #ff3355; }
#comms[data-who="SENSOR"]  { --tone: #c8ffe0; border-left-style: dashed; }
.comms-wave { display: flex; gap: 3px; align-items: center; height: 30px; flex: none; }
.comms-wave i { width: 3px; height: 6px; background: var(--tone); box-shadow: 0 0 8px var(--tone); border-radius: 2px; }
#comms.talking .comms-wave i { animation: commsWave .42s ease-in-out infinite alternate; }
#comms.talking .comms-wave i:nth-child(2) { animation-delay: .08s; }
#comms.talking .comms-wave i:nth-child(3) { animation-delay: .16s; }
#comms.talking .comms-wave i:nth-child(4) { animation-delay: .05s; }
#comms.talking .comms-wave i:nth-child(5) { animation-delay: .12s; }
@keyframes commsWave { from { height: 5px; } to { height: 28px; } }
#comms[data-mood="cold"].talking .comms-wave i { animation-timing-function: steps(2); animation-duration: .2s; }
.comms-body { min-width: 0; text-align: left; }
.comms-name {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 4px;
  color: var(--tone); text-shadow: 0 0 10px var(--tone); margin-bottom: 4px;
}
.comms-text {
  font-family: var(--font-ui); font-size: 17px; font-weight: 600; line-height: 1.35;
  color: #eef8ff; min-height: 1.35em; text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}
#comms[data-mood="cold"][data-who="LYRA"] .comms-text { letter-spacing: 1px; text-transform: uppercase; font-size: 15px; color: #ffd8dc; }
#comms[data-who="SENSOR"] .comms-text {
  font-family: 'Courier New', monospace; font-weight: 400; font-size: 15px; color: #d8ffe8;
  animation: sensorFlicker 1.7s steps(1) infinite;
}
@keyframes sensorFlicker { 0%, 100% { opacity: 1; } 46% { opacity: .55; } 48% { opacity: 1; } 81% { opacity: .7; } 83% { opacity: 1; } }

/* Lyra's mood re-skins the whole HUD: the cockpit itself turns on you. */
body[data-lyra="urgent"] #hud { --cyan: #ffc23a; --cyan-dim: rgba(255, 194, 58, .5); --cyan-faint: rgba(255, 194, 58, .15); }
body[data-lyra="cold"] #hud   { --cyan: #ff4a5e; --cyan-dim: rgba(255, 74, 94, .5); --cyan-faint: rgba(255, 74, 94, .15); filter: saturate(.8); }
body[data-lyra="free"] #hud   { display: none !important; }
body[data-ending="bad"] #hud, body[data-ending="bad"] #comms, body[data-ending="bad"] #lives-display { filter: grayscale(1) brightness(.8); transition: filter 2.5s; }

/* HUD glitch: one bad frame where the cockpit shows something else. */
#game-container.truth-glitch #hud { animation: hudTruth .32s steps(3) both; }
@keyframes hudTruth {
  0%   { transform: translate(-6px, 2px) skewX(-8deg); filter: invert(1) hue-rotate(120deg); opacity: .4; }
  40%  { transform: translate(5px, -3px) skewX(6deg);  filter: invert(1) hue-rotate(200deg); opacity: 1; }
  70%  { transform: translate(-2px, 1px); filter: hue-rotate(60deg); opacity: .6; }
  100% { transform: none; filter: none; opacity: 1; }
}

/* ── Final choice ── */
#choice {
  position: absolute; left: 50%; top: 58%; transform: translateX(-50%); z-index: 72;
  display: flex; flex-direction: column; gap: 12px; width: min(560px, 90vw);
  pointer-events: none;
}
#choice.hidden { display: none; }
.choice-opt {
  display: flex; gap: 14px; align-items: center; padding: 12px 16px;
  font-family: var(--font-ui); font-size: 17px; font-weight: 600; color: #fff; text-align: left;
  background: rgba(20, 4, 8, .82); border: 1px solid #ff3355;
  box-shadow: 0 0 22px rgba(255, 51, 85, .35);
  animation: choiceIn .5s var(--ease-out-expo) both, choicePulse 1s ease-in-out .5s infinite;
}
.choice-opt kbd {
  flex: none; font-family: var(--font-display); font-size: 12px; letter-spacing: 2px;
  padding: 6px 10px; border: 1px solid currentColor; color: #ff8a9a;
}
.choice-defy {
  display: none; background: rgba(4, 20, 16, .82); border: 1px dashed #9fffd8; color: #dffff2;
  box-shadow: 0 0 22px rgba(120, 255, 210, .3);
  animation: choiceLeak .9s steps(6) both;
}
.choice-defy kbd { color: #9fffd8; }
#choice.alt .choice-defy { display: flex; }
@keyframes choiceIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes choicePulse { 50% { box-shadow: 0 0 34px rgba(255, 51, 85, .7); } }
@keyframes choiceLeak {
  0% { opacity: 0; transform: translateX(-14px) skewX(-12deg); filter: hue-rotate(90deg); }
  30% { opacity: .9; transform: translateX(8px) skewX(8deg); }
  45% { opacity: .2; }
  70% { opacity: 1; transform: translateX(-3px); }
  100% { opacity: 1; transform: none; filter: none; }
}

/* ── Briefing ── */
#briefing-screen { background: radial-gradient(ellipse at 50% 45%, rgba(2, 8, 22, .7) 0%, rgba(0, 0, 0, .96) 75%); z-index: 101; }
.briefing-content { max-width: 640px; }
.briefing-lines { text-align: left; margin-bottom: 26px; }
.briefing-lines p {
  font-family: var(--font-ui); font-size: 19px; line-height: 1.5; color: #dcefff; margin: 0 0 12px;
  opacity: 0; animation: fadeUp .7s var(--ease-out-expo) forwards;
}
.briefing-lines p.briefing-head {
  font-family: var(--font-display); font-size: 13px; letter-spacing: 5px; color: var(--amber);
  text-shadow: 0 0 14px var(--amber-dim); margin-bottom: 22px;
}
.briefing-lines p:last-child { color: var(--cyan); font-weight: 700; }

/* ── Endings ── */
.ending-title { font-family: var(--font-display); font-size: clamp(34px, 7vw, 76px); letter-spacing: 6px; margin: 10px 0 26px; }
.ending-lines p {
  font-family: var(--font-ui); font-size: 20px; line-height: 1.5; margin: 0 0 10px;
  opacity: 0; animation: fadeUp 1.4s ease-out forwards;
}
#ending-screen .menu-button, #ending-screen .score-display { opacity: 0; animation: fadeUp 1s ease-out 6.5s forwards; }
#ending-screen.ending-good { background: radial-gradient(ellipse at 50% 60%, rgba(4, 30, 30, .15) 0%, rgba(2, 14, 22, .55) 70%, rgba(0, 6, 12, .8) 100%); }
.ending-good .ending-title {
  background: linear-gradient(120deg, #7dffd0, #fff3b0 45%, #ff9ad8 75%, #8ac8ff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 30px rgba(120, 255, 210, .55));
}
.ending-good .ending-lines p { color: #eafff6; text-shadow: 0 0 14px rgba(120, 255, 210, .5); }
.ending-good .menu-kicker { color: #9fffd8; }
#ending-screen.ending-bad { background: rgba(8, 8, 9, .93); filter: grayscale(1); }
.ending-bad .ending-title { color: #9a9a9a; letter-spacing: 10px; font-size: clamp(24px, 4.6vw, 48px); }
.ending-bad .ending-lines p { color: #7a7a7a; animation-duration: 2.4s; }
.ending-bad .menu-kicker { color: #666; text-shadow: none; }
.ending-bad .menu-button { border-color: #555; color: #888; box-shadow: none; }

/* Epilogue captions */
.ann-caption { top: 70%; }
.ann-caption span {
  font-family: var(--font-ui); font-size: clamp(17px, 2.6vw, 26px); font-weight: 600; letter-spacing: 1px;
  color: #f2fff8; text-shadow: 0 0 18px rgba(120, 255, 210, .7), 0 2px 8px rgba(0, 0, 0, .7);
  animation: captionLife var(--life, 4s) ease-in-out both; display: inline-block; padding: 0 16px;
}
@keyframes captionLife { 0% { opacity: 0; transform: translateY(10px); } 18%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* Phones: the bottom of the screen belongs to the thumbs. */
body.touch #comms { bottom: auto; top: calc(200px + env(safe-area-inset-top)); padding: 8px 12px; gap: 10px; }
body.touch .comms-text { font-size: 14px; }
body.touch #choice { top: 44%; }
@media (max-width: 640px), (max-height: 500px) {
  .comms-text { font-size: 14px; }
  .comms-wave { display: none; }
  .choice-opt { font-size: 14px; padding: 9px 12px; }
  .briefing-lines p { font-size: 15px; margin-bottom: 8px; }
  .ending-lines p { font-size: 16px; }
}
@media (max-height: 500px) {
  body.touch #comms { top: calc(96px + env(safe-area-inset-top)); width: min(440px, 56vw); }
}

/* ═══ Cinema mode: the film takes the camera ═══════════════════════════════ */
#letterbox-top, #letterbox-bottom {
  position: absolute; left: 0; right: 0; height: 12vh; background: #000; z-index: 66;
  pointer-events: none; transition: transform .45s var(--ease-out-expo);
}
#letterbox-top { top: 0; transform: translateY(-101%); }
#letterbox-bottom { bottom: 0; transform: translateY(101%); }
body.cinema #letterbox-top, body.cinema #letterbox-bottom { transform: none; }
#hud, #lives-display, #touch-controls { transition: opacity .3s ease; }
body.cinema #hud, body.cinema #lives-display, body.cinema #touch-controls, body.cinema #engage-text { opacity: 0 !important; }
/* In cinema mode Lyra's panel becomes film subtitles inside the lower bar. */
body.cinema #comms, body.cinema.touch #comms {
  top: auto; bottom: 1.6vh; width: min(900px, 94vw); justify-content: center;
  background: none; border-left: none; box-shadow: none; clip-path: none; padding: 0 12px;
}
body.cinema #comms .comms-wave { display: none; }
body.cinema #comms .comms-body { text-align: center; }
body.cinema #comms .comms-name { font-size: 10px; margin-bottom: 2px; opacity: .85; }
body.cinema #comms .comms-text { font-size: clamp(14px, 2.1vh + .4vw, 20px); text-shadow: 0 0 10px #000, 0 2px 4px #000; }
body.cinema .ann-stage { top: 30%; }
body.cinema .ann-caption { top: auto; bottom: 14vh; }
#menu-screen .menu-button.hidden { display: none; }

/* ── Snow melting on the canopy (Cumbres de la Bruma) ── */
#glass { position: absolute; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; display: none; }
#glass.snowing { display: block; }
body:not(.in-game) #glass, body.cinema #glass { display: none; }
#glass i {
  position: absolute; left: var(--x); top: var(--y); width: var(--s); height: var(--s); border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, .95), rgba(225, 240, 255, .55) 45%, rgba(200, 225, 255, 0) 72%);
  opacity: 0; animation: flakeMelt var(--t) ease-in var(--d) infinite;
}
@keyframes flakeMelt {
  0%   { opacity: 0; transform: scale(.2); filter: blur(0); }
  6%   { opacity: .95; transform: scale(1); }
  45%  { opacity: .8; transform: scale(1.05); filter: blur(.5px); }
  70%  { opacity: .55; transform: translateY(18px) scale(.7, 1.5); filter: blur(1.5px); border-radius: 45% 45% 50% 50%; }
  100% { opacity: 0; transform: translateY(90px) scale(.3, 2.4); filter: blur(2.5px); }
}
/* Opening shots can be skipped with a fresh press of FIRE. */
#letterbox-top::after {
  content: 'FUEGO · saltar'; position: absolute; right: 18px; bottom: 8px; opacity: 0; transition: opacity .4s;
  font-family: var(--font-display); font-size: 10px; letter-spacing: 3px; color: rgba(255, 255, 255, .55);
}
body.cinema.skippable #letterbox-top::after { opacity: 1; }
