:root {
  --bg: #05060f;
  --neon-cyan: #2ff3ff;
  --neon-pink: #ff3df0;
  --neon-purple: #8a5bff;
  --neon-green: #5dff9b;
  --neon-yellow: #ffe75d;
  --hp: #ff4d6d;
  --xp: #2ff3ff;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Rajdhani', sans-serif;
  color: #eaf6ff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

canvas#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-top {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  width: 100%;
  min-height: 42px;
}

/* P1 stats hug the left, P2 stats mirror to the right; timer stays centered. */
.hud-corner { display: flex; align-items: flex-start; gap: 26px; }
.hud-corner.left { justify-self: start; }
.hud-corner.right { justify-self: end; }
.hud-corner.right .hud-stat { align-items: flex-end; }
.hud-corner.right .hud-value { text-shadow: 0 0 12px #ff9f43; }
.hud-corner.right .hud-label { color: #b07a4a; }
.hud-corner.right.downed { opacity: 0.5; filter: grayscale(0.55); }
.hud-center { justify-self: center; display: flex; flex-direction: column; align-items: center; }

.hud-stat {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.hud-label {
  font-size: 12px;
  letter-spacing: 3px;
  color: #6f86a8;
  font-weight: 600;
}

.hud-value {
  font-family: 'Orbitron', sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 12px var(--neon-cyan);
}

.hud-timer {
  font-family: 'Orbitron', sans-serif;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 18px var(--neon-purple), 0 0 4px #fff;
}

/* Adaptive difficulty readout under the timer (see hud.js / world.threat). */
.hud-threat {
  margin-top: 2px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #ff7a8f;
  text-shadow: 0 0 10px rgba(255, 122, 143, .55);
}

/* XP bars row: P1 fills the left half, P2 the right half (each flex:1 in MP). */
.hud-bars { width: 100%; display: flex; gap: 12px; }
.hud-xp1 { flex: 1 1 0; }
.hud-xp2 { flex: 1 1 0; }
.hud-xp2 .bar-fill { background: linear-gradient(90deg, #ff8a3d, #ffb86b); box-shadow: 0 0 14px #ff9f43; }

.bar {
  position: relative;
  width: 100%;
  height: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.6);
}

.bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  border-radius: 10px;
  transition: width 0.18s ease-out;
}

.xp-bar .bar-fill {
  background: linear-gradient(90deg, #1ad7ff, #6df0ff);
  box-shadow: 0 0 14px var(--neon-cyan);
}

.hud-health {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: min(320px, 45vw);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hp-bar { height: 16px; }
.hp-bar .bar-fill {
  background: linear-gradient(90deg, #ff264f, #ff7a8f);
  box-shadow: 0 0 14px var(--hp);
  transition: width 0.12s ease-out;
}

.hp-text {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  color: #ffd7dd;
  text-shadow: 0 0 8px rgba(255,77,109,0.6);
}

/* ---------- Boss bar ---------- */
.boss-bar {
  position: absolute;
  top: 156px;   /* clears the ☰ Menu button (which floats just below the timer) */
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 80vw);
  text-align: center;
  animation: bossIn 0.4s ease;
}
@keyframes bossIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.boss-name {
  font-family: 'Orbitron', sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #fff;
  margin-bottom: 5px;
  text-shadow: 0 0 14px var(--neon-pink);
}
.boss-hp { height: 14px; border: 1px solid rgba(255, 61, 240, 0.4); }
.boss-hp .bar-fill {
  width: 100%;
  background: linear-gradient(90deg, #ff3df0, #ff8df6);
  box-shadow: 0 0 16px var(--neon-pink);
  transition: width 0.15s ease-out;
}

/* ---------- Local co-op / versus (P3) ---------- */
/* Player 2 health mirrors P1's, bottom-right with the warm-orange accent. */
.hud-p2 {
  position: absolute;
  right: 22px;
  bottom: 22px;
  width: min(320px, 45vw);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
}
.hud-p2 .hp-text { text-align: right; color: #ffe2c4; text-shadow: 0 0 8px rgba(255,159,67,0.6); }
.hud-p2.downed { opacity: 0.5; filter: grayscale(0.55); }

/* ---------- Non-blocking level-up dock (per player, bottom of screen) ---------- */
.levelup-dock {
  position: absolute;
  left: 0; right: 0; bottom: 74px;
  display: flex;
  gap: 16px;
  padding: 0 18px;
  justify-content: center;
  align-items: flex-end;
  pointer-events: none;
  z-index: 22;   /* above the pause veil (z20) → stays crisp & clickable while paused */
}
.levelup-dock .ldock { width: 100%; max-width: 760px; }
.levelup-dock.mp { justify-content: space-between; gap: 14px; }
.levelup-dock.mp .ldock { flex: 1 1 0; max-width: calc(50% - 7px); }
.ldock-head {
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  letter-spacing: 2px;
  color: #9fb4d6;
  text-align: center;
  margin-bottom: 8px;
  text-shadow: 0 0 10px currentColor;
}
/* ×N badge: how many level-ups are still queued (deferred picks aren't lost). */
.ldock-n { color: #ffe75d; font-weight: 900; text-shadow: 0 0 10px #ffe75d; }
.ldock-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ldock-card {
  position: relative;
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  padding: 14px 10px 11px;
  border-radius: 14px;
  border: 1px solid rgba(120, 160, 220, 0.3);
  background: linear-gradient(160deg, rgba(20, 26, 56, 0.96), rgba(10, 12, 30, 0.96));
  color: #eaf6ff;
  font-family: 'Rajdhani', sans-serif;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.ldock-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--accent, #2ff3ff), transparent 70%);
  opacity: 0.16;
  pointer-events: none;
}
.ldock-card:hover { transform: translateY(-4px); border-color: var(--accent, #2ff3ff); box-shadow: 0 0 26px -6px var(--accent, #2ff3ff); }
.ldock-card:active { transform: scale(0.97); }
.ldc-key {
  position: absolute;
  top: 7px; left: 7px;
  width: 22px; height: 22px;
  border-radius: 7px;
  background: var(--accent, #2ff3ff);
  color: #05060f;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 12px -2px var(--accent, #2ff3ff);
}
.ldc-ico { font-size: 30px; line-height: 1; margin-top: 2px; filter: drop-shadow(0 0 10px var(--accent, #2ff3ff)); }
.ldc-name { font-family: 'Orbitron', sans-serif; font-weight: 700; font-size: 14px; color: #fff; }
.ldc-sub { font-size: 12px; color: #aebfdc; line-height: 1.25; min-height: 30px; }
.ldc-lvl { font-family: 'Orbitron', sans-serif; font-size: 10px; letter-spacing: 1px; color: var(--accent, #2ff3ff); text-transform: uppercase; }
.ldock-card.evo { border-color: var(--accent, #ffe75d); box-shadow: 0 0 24px -6px var(--accent, #ffe75d); animation: evoPulse 1.6s ease-in-out infinite; }
.ldock-card.evo::before { opacity: 0.3; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  background: radial-gradient(circle at 50% 40%, rgba(11, 14, 34, 0.78), rgba(2, 3, 10, 0.94));
  backdrop-filter: blur(7px);
  z-index: 20;
  animation: fadeIn 0.35s ease;
  /* Scroll when content is taller than the viewport (mobile): margin:auto on the
     inner centers it when it fits and lets it scroll from the top when it doesn't,
     so the close button is always reachable. */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

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

.overlay-inner {
  text-align: center;
  padding: 36px;
  max-width: 540px;
  width: 92%;
  margin: auto;   /* centered when it fits; scrolls from the top when too tall */
}

/* "Close" stays pinned to the bottom of the viewport so you never have to scroll
   the (often tall) card grids down to find it. Sticky → part of the layout when
   the content fits, pinned to the bottom while scrolling when it doesn't. */
/* `.btn.overlay-close` (not just `.overlay-close`) so the centered `margin: auto`
   wins over `.btn { margin: 8px }`, which is later in source at equal specificity
   and would otherwise pin the button to the left. */
.btn.overlay-close {
  position: sticky;
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  display: block;
  width: -moz-fit-content;
  width: fit-content;
  margin: 22px auto 0;
  z-index: 3;
}
.overlay-inner.wide { max-width: 1500px; }
/* The Arsenal is reachable from the game-over panel, which sits later in the DOM
   and would otherwise stack on top of it (equal z-index). Raise it so it opens
   above the "Drift Ended" overlay. */
#shop-screen { z-index: 21; }
/* Trim the start menu's vertical padding so the whole panel is shorter — fits
   mobile / itch.io viewports without scrolling. */
#start-screen .overlay-inner { padding-top: 22px; padding-bottom: 22px; }

.title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(38px, 8vw, 84px);
  letter-spacing: 6px;
  background: linear-gradient(90deg, #2ff3ff, #8a5bff, #ff3df0);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(138, 91, 255, 0.55));
}
.title.small { font-size: clamp(30px, 6vw, 52px); letter-spacing: 8px; }
/* Start-menu title: fixed size on one line (doesn't scale up with the viewport),
   stepping down only on narrow phones so "ASTRAL DRIFT" always stays on one line. */
.title.glitch { font-size: 50px; letter-spacing: 4px; white-space: nowrap; }
@media (max-width: 560px) { .title.glitch { font-size: 32px; letter-spacing: 3px; } }
@media (max-width: 360px) { .title.glitch { font-size: 28px; letter-spacing: 2px; } }
.title.gameover {
  font-size: clamp(30px, 6vw, 56px);   /* a touch smaller than the main title */
  background: linear-gradient(90deg, #ff264f, #ff7a8f, #ffd75d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 38, 79, 0.5));
}

/* Game-over actions: equal-width buttons, each stacked on its own line, centered. */
#gameover-screen .btn {
  display: block;
  width: 340px;
  max-width: 100%;
  margin: 10px auto 0;
  text-align: center;
}

.glitch { position: relative; }

.subtitle {
  margin: 12px 0 20px;
  font-size: 14px;   /* fixed — doesn't grow with the viewport, keeps the menu compact */
  color: #9fb4d6;
  letter-spacing: 1px;
}

.btn {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 17px;
  padding: 16px 38px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  margin: 8px;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
  pointer-events: auto;
}

.btn.primary {
  color: #03121a;
  background: linear-gradient(90deg, #2ff3ff, #6df0ff);
  box-shadow: 0 0 26px rgba(47, 243, 255, 0.55);
}
.btn.primary:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 0 40px rgba(47, 243, 255, 0.85); }

.btn.ghost {
  color: #cfe3ff;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(120, 160, 220, 0.35);
}
.btn.ghost:hover { background: rgba(255,255,255,0.12); transform: translateY(-2px); }

.btn:active { transform: scale(0.97); }

/* Icon + label layout. Each emoji/symbol lives in its own fixed-width box so the
   icon→label gap is identical on every button regardless of glyph width (emoji
   are much wider than text symbols like ⬡/☢/⚙). The icon is a touch larger than
   the label for a more confident, balanced look. */
.btn:has(.btn-ico) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.btn-ico {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9em;
  font-size: 1.4em;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(120, 180, 255, 0.4));
}
.btn-lbl { display: inline-block; }

.controls-hint {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  color: #7e93b6;
  font-size: 15px;
}
.controls-hint b { color: var(--neon-cyan); }
/* Touch devices have no keyboard → drop only the keyboard-specific hint,
   keep the general gameplay tips (weapon/collect) which apply to touch too. */
.is-touch .controls-hint .kbd-only { display: none; }

.menu-meta-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin-top: 10px;
  margin-bottom: 4px;
  min-height: 22px;
}
.menu-meta-row .menu-shards,
.menu-meta-row .best-line {
  margin-top: 0;
}

.best-line {
  margin-top: 12px;
  font-family: 'Orbitron', sans-serif;
  font-size: 15px;
  color: var(--neon-yellow);
  letter-spacing: 2px;
  min-height: 20px;
  text-shadow: 0 0 12px rgba(255, 231, 93, 0.4);
}

/* Version/build stamp — bottom corner of the menu, for bug reports */
.build-stamp {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  letter-spacing: 1px;
  color: #4a5a78;
  pointer-events: none;
  user-select: text;
}

/* First-launch onboarding card */
#intro-screen { z-index: 30; }   /* above the start menu (z20) */
.intro-list {
  list-style: none;
  text-align: left;
  max-width: 440px;
  margin: 24px auto 30px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.intro-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 16px;
  color: #cfe3ff;
  line-height: 1.35;
}
.intro-list .intro-ico { font-size: 24px; width: 30px; text-align: center; flex: none; }
.intro-list b { color: var(--neon-cyan); }

/* ---------- Callsign prompt / text inputs ---------- */
.text-input {
  width: 100%;
  max-width: 360px;
  box-sizing: border-box;
  background: rgba(10, 20, 36, 0.85);
  border: 1px solid rgba(120, 160, 220, 0.35);
  border-radius: 10px;
  color: #eaf4ff;
  font-family: 'Rajdhani', sans-serif;
  font-size: 18px;
  letter-spacing: 0.5px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.text-input::placeholder { color: #5f7799; }
.text-input:focus { border-color: var(--neon-cyan); box-shadow: 0 0 0 2px rgba(47, 243, 255, 0.25); }
.text-input.compact { max-width: 180px; font-size: 15px; padding: 8px 10px; }
.nick-sub { max-width: 420px; margin: 10px auto 18px; color: #cfe3ff; font-size: 15px; line-height: 1.4; }
#nickname-screen .text-input { margin: 0 auto; display: block; text-align: center; }
.nick-actions { display: flex; gap: 12px; justify-content: center; margin: 22px auto 0; flex-wrap: wrap; }
.nick-note { margin-top: 16px; font-size: 12px; color: #6f86a8; }

/* ---------- Level up ---------- */
.levelup-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 900;
  letter-spacing: 5px;
  color: #fff;
  text-shadow: 0 0 24px var(--neon-green);
}
.levelup-sub { margin: 10px 0 28px; color: #9fb4d6; letter-spacing: 2px; font-size: 18px; }

.upgrade-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.upgrade-card {
  position: relative;
  background: linear-gradient(160deg, rgba(20, 26, 56, 0.92), rgba(10, 12, 30, 0.92));
  border: 1px solid rgba(120, 160, 220, 0.25);
  border-radius: 18px;
  padding: 26px 20px;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  overflow: hidden;
  text-align: center;
}
.upgrade-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--accent, #2ff3ff), transparent 70%);
  opacity: 0.16;
  pointer-events: none;
}
.upgrade-card:hover {
  transform: translateY(-6px);
  border-color: var(--accent, #2ff3ff);
  box-shadow: 0 0 34px -4px var(--accent, #2ff3ff);
}

.upgrade-icon {
  font-size: 46px;
  line-height: 1;
  margin-bottom: 14px;
  filter: drop-shadow(0 0 12px var(--accent, #2ff3ff));
}
.upgrade-name {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 1px;
  color: #fff;
  margin-bottom: 8px;
}
.upgrade-desc { font-size: 15.5px; color: #aebfdc; line-height: 1.35; min-height: 44px; }
.upgrade-level {
  margin-top: 14px;
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--accent, #2ff3ff);
  text-transform: uppercase;
}
.upgrade-tag {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 10px;
  letter-spacing: 1.5px;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(0,0,0,0.4);
  color: var(--accent, #2ff3ff);
  border: 1px solid var(--accent, #2ff3ff);
}

/* ---------- Weapon evolution card (P0) ---------- */
.upgrade-card.evo-card {
  border-color: var(--accent, #ffe75d);
  background: linear-gradient(160deg, rgba(46, 38, 14, 0.95), rgba(22, 16, 8, 0.96));
  box-shadow: 0 0 34px -6px var(--accent, #ffe75d);
  animation: evoPulse 1.6s ease-in-out infinite;
}
.upgrade-card.evo-card::before { opacity: 0.32; }
.upgrade-card.evo-card .upgrade-tag { background: var(--accent, #ffe75d); color: #1a1306; border-color: var(--accent, #ffe75d); }
.upgrade-card.evo-card .upgrade-icon { filter: drop-shadow(0 0 16px var(--accent, #ffe75d)); }
@keyframes evoPulse {
  0%, 100% { box-shadow: 0 0 30px -8px var(--accent, #ffe75d); }
  50% { box-shadow: 0 0 42px -2px var(--accent, #ffe75d); }
}
.build-chip.evo { background: rgba(255, 231, 93, 0.08); box-shadow: 0 0 14px -3px var(--accent, #ffe75d); }

/* ---------- Results ---------- */
.results {
  margin: 26px auto 30px;
  max-width: 380px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid rgba(120, 160, 220, 0.15);
  font-size: 18px;
  color: #b8cae6;
}
.result-row b { font-family: 'Orbitron', sans-serif; color: #fff; }
.result-row.highlight { border: none; margin-top: 8px; }
.result-row.highlight span { color: var(--neon-yellow); }
.result-row.highlight b {
  font-size: 30px;
  color: var(--neon-yellow);
  text-shadow: 0 0 16px rgba(255, 231, 93, 0.55);
}
.result-best {
  margin-top: 6px;
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 2px;
  color: var(--neon-green);
  min-height: 22px;
  text-shadow: 0 0 12px rgba(93,255,155,0.4);
}

/* ---------- Meta shards ---------- */
.menu-shards {
  margin-top: 8px;
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 2px;
  color: var(--neon-purple);
  text-shadow: 0 0 12px rgba(138, 91, 255, 0.45);
  min-height: 22px;
}
.result-row.shards span { color: var(--neon-purple); }
.result-row.shards b { color: var(--neon-purple); text-shadow: 0 0 12px rgba(138, 91, 255, 0.5); }

.menu-row { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu-row .btn { margin: 0; width: 360px; max-width: 100%; text-align: center; }
/* Start-menu buttons each lead with an icon → left-align so the icons line up in
   a tidy column and the gap to every label is identical. */
#start-screen .menu-row .btn { justify-content: flex-start; text-align: left; padding-left: 22px; }
#start-btn { width: 360px; max-width: 100%; }

/* ---------- Achievements + stats ---------- */
.ach-count-line {
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 2px;
  color: var(--neon-yellow);
  margin-bottom: 18px;
}
.ach-count-line #ach-count { color: #fff; }
.ach-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.ach-stat {
  background: rgba(20, 26, 56, 0.6);
  border: 1px solid rgba(120, 160, 220, 0.18);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
}
.ach-stat span { display: block; font-size: 12px; color: #8ea4c6; letter-spacing: 1px; }
.ach-stat b { font-family: 'Orbitron', sans-serif; font-size: 18px; color: #fff; }
.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 12px;
  margin-bottom: 24px;
  max-height: 46vh;
  overflow-y: auto;
}
.ach-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(160deg, rgba(20, 26, 56, 0.9), rgba(10, 12, 30, 0.9));
  border: 1px solid rgba(120, 160, 220, 0.22);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
}
.ach-badge.unlocked { border-color: rgba(255, 231, 93, 0.5); box-shadow: 0 0 18px -8px var(--neon-yellow); }
.ach-badge.locked { opacity: 0.5; filter: grayscale(0.6); }
.ach-ico { font-size: 30px; line-height: 1; flex: 0 0 auto; }
.ach-info { flex: 1 1 auto; min-width: 0; }
.ach-name { font-family: 'Orbitron', sans-serif; font-size: 15px; color: #fff; margin-bottom: 2px; }
.ach-d { font-size: 12.5px; color: #aebfdc; line-height: 1.25; }
.ach-unlock { margin-top: 4px; font-size: 12px; color: var(--neon-green); letter-spacing: 0.3px; }
.ach-reward { font-family: 'Orbitron', sans-serif; font-size: 13px; color: var(--neon-purple); flex: 0 0 auto; }

/* new-achievement banner on the game-over screen */
.gameover-ach { margin: 4px 0 18px; min-height: 0; }
.gameover-ach .ga-title { font-family: 'Orbitron', sans-serif; letter-spacing: 2px; color: var(--neon-yellow); font-size: 14px; margin-bottom: 6px; }
.gameover-ach .ga-item { color: #fff; font-size: 15px; line-height: 1.5; }
.gameover-ach .ga-unlock { color: var(--neon-green); font-size: 13px; line-height: 1.4; }

/* ---------- Pilot / mode / location cards (shared visuals; laid out in the
   horizontal loadout strips — see "Pre-run loadout" below) ---------- */
.char-card {
  position: relative;
  background: linear-gradient(160deg, rgba(20, 26, 56, 0.92), rgba(10, 12, 30, 0.92));
  border: 1px solid rgba(120, 160, 220, 0.25);
  border-radius: 18px;
  padding: 24px 18px 20px;
  cursor: pointer;
  pointer-events: auto;
  overflow: hidden;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.char-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--accent, #2ff3ff), transparent 70%);
  opacity: 0.14;
  pointer-events: none;
}
.char-card:hover { transform: translateY(-5px); border-color: var(--accent, #2ff3ff); box-shadow: 0 0 28px -6px var(--accent, #2ff3ff); }
.char-card.selected { border-color: var(--accent, #2ff3ff); box-shadow: 0 0 30px -4px var(--accent, #2ff3ff); }
.char-icon { font-size: 44px; line-height: 1; margin-bottom: 10px; filter: drop-shadow(0 0 12px var(--accent, #2ff3ff)); }
.char-name { font-family: 'Orbitron', sans-serif; font-weight: 700; font-size: 18px; letter-spacing: 1px; color: #fff; margin-bottom: 8px; }
.char-desc { font-size: 14px; color: #aebfdc; line-height: 1.35; min-height: 76px; }
.char-weapon { margin-top: 12px; font-size: 13px; letter-spacing: 1px; color: #9fb4d6; text-transform: uppercase; }
.char-weapon b { color: var(--accent, #2ff3ff); }
.char-card.locked { cursor: not-allowed; filter: grayscale(0.65); opacity: 0.62; }
.char-card.locked:hover { transform: none; border-color: rgba(120, 160, 220, 0.25); box-shadow: none; }
.char-lock { margin-top: 12px; font-size: 12.5px; letter-spacing: 0.5px; color: var(--neon-yellow); }

/* ---------- CODEX (compendium) ---------- */
.codex-tabs {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 2px 0 14px;
}
.codex-tab {
  font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: 0.5px;
  color: #aebfdc; background: rgba(20, 26, 56, 0.7);
  border: 1px solid rgba(120, 160, 220, 0.25); border-radius: 999px;
  padding: 9px 16px; cursor: pointer; pointer-events: auto;
  transition: color 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.12s ease;
}
.codex-tab:hover { color: #eaf6ff; border-color: rgba(47, 243, 255, 0.5); transform: translateY(-1px); }
.codex-tab.active {
  color: #fff; border-color: var(--neon-cyan);
  background: rgba(47, 243, 255, 0.12); box-shadow: 0 0 18px -6px var(--neon-cyan);
}
.codex-count {
  font-size: 13px; letter-spacing: 1px; color: #8ea4c6; margin-bottom: 18px;
}
.codex-count b { color: var(--neon-cyan); font-family: 'Orbitron', sans-serif; }

.codex-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 14px; margin-bottom: 8px;
}
.codex-card {
  position: relative; overflow: hidden; text-align: center;
  background: linear-gradient(160deg, rgba(20, 26, 56, 0.92), rgba(10, 12, 30, 0.92));
  border: 1px solid rgba(120, 160, 220, 0.22); border-radius: 16px;
  padding: 16px 14px 14px; transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.codex-card::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--accent, #2ff3ff), transparent 68%);
  opacity: 0.12; pointer-events: none;
}
.codex-card:hover { transform: translateY(-4px); border-color: var(--accent, #2ff3ff); box-shadow: 0 0 24px -8px var(--accent, #2ff3ff); }
.codex-card.locked { filter: grayscale(0.35); }
.codex-card.locked:hover { transform: translateY(-2px); box-shadow: 0 0 18px -10px var(--accent, #2ff3ff); }

.codex-thumb {
  position: relative; height: 100px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 6px;
}
.codex-thumb canvas { display: block; }
/* Undiscovered foes stay a soft, blurred silhouette — a teasing hint of the shape
   (and its size) without revealing colour, name or stats. */
.codex-thumb.blur canvas { filter: blur(3px) brightness(1.05); opacity: 0.92; }
.codex-emoji { font-size: 46px; line-height: 1; filter: drop-shadow(0 0 12px var(--accent, #2ff3ff)); }
.codex-card.locked .codex-emoji { filter: drop-shadow(0 0 8px rgba(150, 180, 230, 0.4)); opacity: 0.7; }

.codex-name { font-family: 'Orbitron', sans-serif; font-weight: 700; font-size: 14px; letter-spacing: 0.5px; color: #fff; margin-bottom: 6px; }
.codex-name.muted { color: #7e93b6; letter-spacing: 4px; }
.codex-desc { font-size: 12.5px; color: #aebfdc; line-height: 1.3; min-height: 50px; }
.codex-hint { font-size: 12px; letter-spacing: 0.3px; color: var(--neon-yellow); min-height: 50px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.codex-evo { margin-top: 8px; font-size: 11.5px; color: #bda7ff; line-height: 1.3; }
.codex-evo b { color: var(--neon-purple); }
.codex-starts { margin-top: 8px; font-size: 11.5px; letter-spacing: 0.5px; color: #9fb4d6; text-transform: uppercase; }
.codex-starts b { color: var(--accent, #2ff3ff); }

.codex-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.codex-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; color: #cdddf5;
  background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(120, 160, 220, 0.18);
  border-radius: 8px; padding: 3px 7px;
}
.codex-chip .ci { opacity: 0.85; font-size: 11px; }
.codex-chip b { font-family: 'Orbitron', sans-serif; font-weight: 600; color: #fff; font-size: 11px; }
.codex-chip.hp b { color: #ff8aa0; }
.codex-chip.dmg b { color: #ffd23d; }
.codex-chip.good { border-color: rgba(93, 255, 155, 0.3); }
.codex-chip.good b { color: var(--neon-green); }
.codex-chip.bad { border-color: rgba(255, 93, 122, 0.3); }
.codex-chip.bad b { color: #ff6d8a; }

@media (max-width: 560px) {
  .codex-grid { gap: 10px; }
  .codex-tab { font-size: 11px; padding: 7px 12px; }
}

.char-tag {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 10px;
  letter-spacing: 1.5px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--accent, #2ff3ff);
  color: #05060f;
}

/* ---------- Pre-run loadout (mode / pilot / location strips) ----------
   Three stacked sections, each an independent horizontal strip — picked before a
   run from BEGIN THE DRIFT. Sized so all three fit one viewport with no vertical
   scroll; only the strips scroll, sideways. */
.loadout-inner { max-width: 1180px; display: flex; flex-direction: column; }
#loadout-screen .overlay-inner { padding-top: 18px; padding-bottom: 14px; }
/* Compact, tight-margin title so all three rows + actions clear one viewport. */
#loadout-screen .title { font-size: clamp(24px, 4.6vw, 40px); margin: 0 0 14px; }
.loadout-section { margin-bottom: 10px; }
.loadout-label {
  font-family: 'Orbitron', sans-serif; font-size: 13px; letter-spacing: 3px;
  color: #9fb4d6; text-transform: uppercase; text-align: left;
  margin: 0 2px 6px; padding-bottom: 5px;
  border-bottom: 1px solid rgba(120, 160, 220, 0.16);
}
/* Cards in a single non-wrapping row; horizontal scroll only. */
.loadout-strip {
  display: flex; flex-wrap: nowrap; gap: 12px;
  overflow-x: auto; overflow-y: hidden;
  /* Roomy side padding so the edge cards' selected halo isn't clipped by the
     row edges; scroll-padding keeps snap alignment honouring that inset. */
  padding: 6px 16px 10px; scroll-snap-type: x proximity; scroll-padding: 0 16px;
  scrollbar-width: none;            /* Firefox: hide the bar (wheel/drag still scroll) */
}
.loadout-strip::-webkit-scrollbar { display: none; }   /* WebKit: hide the bar + its arrow buttons */
/* Compact card: the .char-card visuals at a fixed strip width. */
.loadout-card {
  flex: 0 0 auto; width: 168px;
  padding: 15px 14px 13px; border-radius: 14px;
  scroll-snap-align: start;
}
/* No vertical hover-lift inside the strip (overflow-y is clipped → would crop).
   Softer glow than the full-size cards so the halo stays inside the row. */
.loadout-card:hover { transform: none; box-shadow: 0 0 16px -7px var(--accent, #2ff3ff); }
.loadout-card.selected { box-shadow: 0 0 18px -6px var(--accent, #2ff3ff); }
.loadout-card .char-icon { font-size: 31px; margin-bottom: 7px; }
.loadout-card .char-name { font-size: 15px; margin-bottom: 5px; }
.loadout-card .char-desc {
  min-height: 0; font-size: 12px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.loadout-card .char-weapon { margin-top: 8px; font-size: 11px; }
.loadout-card .char-lock { margin-top: 8px; font-size: 11px; }
.loadout-card .char-tag { top: 8px; right: 8px; font-size: 11px; padding: 1px 7px; line-height: 1.3; }

/* Pilot row: one strip solo, two side-by-side player columns in 2-player modes. */
.loadout-pilots { display: block; }
.loadout-pilots.split { display: flex; gap: 18px; }
.loadout-pilots.split .loadout-col { flex: 1 1 0; min-width: 0; }
.loadout-col-head {
  font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: 2px;
  color: var(--accent, #2ff3ff); text-align: left; margin: 0 2px 4px;
}
.loadout-actions { display: flex; justify-content: center; gap: 14px; margin-top: 2px; }
.loadout-actions .btn { margin: 0; min-width: 200px; }

@media (max-width: 560px) {
  .loadout-pilots.split { flex-direction: column; gap: 10px; }
  .loadout-card { width: 150px; }
  .loadout-actions { flex-direction: column-reverse; }
  .loadout-actions .btn { width: 100%; min-width: 0; }
}

/* ---------- Shop (permanent upgrades) ---------- */
.shop-balance {
  font-family: 'Orbitron', sans-serif;
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--neon-purple);
  text-shadow: 0 0 16px rgba(138, 91, 255, 0.5);
  margin-bottom: 24px;
}
.shop-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.shop-card {
  position: relative;
  background: linear-gradient(160deg, rgba(20, 26, 56, 0.92), rgba(10, 12, 30, 0.92));
  border: 1px solid rgba(120, 160, 220, 0.25);
  border-radius: 18px;
  padding: 22px 18px 20px;
  overflow: hidden;
  text-align: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.shop-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--accent, #2ff3ff), transparent 70%);
  opacity: 0.14;
  pointer-events: none;
}
.shop-card:hover { border-color: var(--accent, #2ff3ff); box-shadow: 0 0 28px -6px var(--accent, #2ff3ff); }
.shop-card.maxed { opacity: 0.85; }
.shop-icon { font-size: 40px; line-height: 1; margin-bottom: 10px; filter: drop-shadow(0 0 12px var(--accent, #2ff3ff)); }
.shop-name { font-family: 'Orbitron', sans-serif; font-weight: 700; font-size: 17px; letter-spacing: 1px; color: #fff; margin-bottom: 6px; }
.shop-desc { font-size: 14px; color: #aebfdc; line-height: 1.3; min-height: 56px; }
.shop-cur { font-family: 'Orbitron', sans-serif; font-size: 13px; letter-spacing: 0.5px; margin-top: 8px; color: var(--accent, #2ff3ff); }
.shop-cur b { font-weight: 700; }
.shop-cur .shop-cur-next { color: #8a9bc0; font-weight: 400; }
.shop-pips { display: flex; justify-content: center; gap: 6px; margin: 12px 0 14px; }
.shop-pips .pip { width: 14px; height: 6px; border-radius: 3px; background: rgba(150, 170, 210, 0.2); }
.shop-pips .pip.on { background: var(--accent, #2ff3ff); box-shadow: 0 0 8px var(--accent, #2ff3ff); }
.shop-buy {
  font-family: 'Orbitron', sans-serif;
  font-size: 15px;
  letter-spacing: 1px;
  color: #05060f;
  background: var(--accent, #2ff3ff);
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.shop-buy:hover { transform: translateY(-2px); box-shadow: 0 0 22px -2px var(--accent, #2ff3ff); }
.shop-buy:active { transform: scale(0.96); }
.shop-buy.disabled { filter: grayscale(0.7) brightness(0.6); cursor: not-allowed; pointer-events: none; }
.shop-cost.is-max {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--neon-green);
  padding: 9px 0;
}

/* ---------- Touch ---------- */
#touch-layer { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

@media (max-width: 720px) {
  .overlay-inner { padding: 26px 16px; }
  .ach-grid { max-height: none; }   /* page scrolls instead of an inner scroll trap */
  .char-desc { min-height: auto; }
  .shop-desc { min-height: auto; }
  .ach-stats { grid-template-columns: 1fr 1fr; }
  .upgrade-desc { min-height: auto; }
  .hud-timer { font-size: 26px; }
  .hud-value { font-size: 20px; }
  .controls-hint { font-size: 13px; }
  .hud-corner { gap: 14px; }
  .icon-btn { top: 100px; }
  .levelup-dock { bottom: 66px; gap: 8px; padding: 0 10px; }
  .levelup-dock.mp .ldock { max-width: calc(50% - 4px); }
  .ldock-cards { gap: 6px; }
  .ldock-card { padding: 10px 6px 9px; }
  .ldc-ico { font-size: 24px; }
  .ldc-name { font-size: 12px; }
  .ldc-sub { font-size: 11px; min-height: 26px; }
}

/* ---------- Card grids across all menus ----------
   Every menu grid uses `repeat(auto-fill, minmax(min(280px, 100%), 1fr))`, so the
   column count drops automatically as the panel narrows — no fixed breakpoints and
   no horizontal scroll (the `min(…, 100%)` keeps a single column from overflowing on
   phones narrower than 280px). The in-game level-up dock keeps its own layout. */
@media (max-width: 560px) {
  .upgrade-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Top-center menu button (sits below the timer AND the XP bar) ---------- */
.icon-btn {
  position: absolute;
  top: 112px;   /* below the timer + XP bar so it never overlaps the level bar */
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid rgba(120, 160, 220, 0.3);
  background: rgba(10, 14, 34, 0.6);
  color: #fff;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.12s ease, background 0.2s ease;
}
.icon-btn .menu-ico { font-size: 18px; }
.icon-btn .menu-lbl {
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #cfe3ff;
}
.icon-btn:hover { background: rgba(47, 243, 255, 0.18); transform: translateX(-50%) scale(1.08); }

/* ---------- Live FPS counter (top-right, diagnostic) ---------- */
.fps-meter {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 27;
  padding: 3px 8px;
  border-radius: 8px;
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #8affc0;
  background: rgba(5, 8, 18, 0.55);
  border: 1px solid rgba(90, 220, 150, 0.3);
  pointer-events: none;
  white-space: nowrap;
}
.fps-meter.warn { color: #ffd23d; border-color: rgba(255, 210, 61, 0.4); }
.fps-meter.bad { color: #ff5d7a; border-color: rgba(255, 93, 122, 0.45); }

/* ---------- Pause-screen build summary ---------- */
.pause-build { margin: 4px 0 20px; }
.build-title { font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: 3px; color: #6f86a8; margin-bottom: 10px; }
.build-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.build-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 20px; font-size: 13px; color: #dce8ff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--accent, #2ff3ff);
  box-shadow: 0 0 10px -4px var(--accent, #2ff3ff);
}
.build-ico { font-size: 15px; }
.build-lvl { font-family: 'Orbitron', sans-serif; font-size: 11px; color: var(--accent, #2ff3ff); }

/* ---------- Settings panel ---------- */
.settings-panel {
  text-align: left;
  margin: 12px 0 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 6px;
}
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.set-label { font-size: 15px; color: #aebfdc; letter-spacing: 0.5px; }
.seg { display: inline-flex; border: 1px solid rgba(120, 160, 220, 0.25); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.seg-btn { background: transparent; color: #9fb4d6; border: none; padding: 8px 12px; font-family: 'Rajdhani', sans-serif; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg-btn.active { background: linear-gradient(90deg, #2ff3ff, #6df0ff); color: #03121a; }
.set-slider { width: 160px; accent-color: #2ff3ff; }
.set-note { font-size: 12px; color: #6f86a8; margin-top: -4px; }
.set-keyrow { display: flex; flex-direction: column; gap: 8px; }
/* Progress-backup block (save code export/import) */
.save-code { width: 100%; max-width: none; resize: vertical; min-height: 58px; font-size: 12px; line-height: 1.35; word-break: break-all; }
.save-actions { display: flex; gap: 8px; }
.save-actions .seg-btn { border: 1px solid rgba(120, 160, 220, 0.25); border-radius: 10px; }
.set-keys { display: flex; gap: 6px; }   /* one row; buttons share the full width */
.key-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(120, 160, 220, 0.25);
  border-radius: 8px; padding: 6px 4px; color: #9fb4d6; cursor: pointer;
  box-sizing: border-box; flex: 1 1 0; min-width: 0;
}
.key-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-btn b { color: #fff; font-family: 'Orbitron', sans-serif; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-btn.listening { border-color: #2ff3ff; box-shadow: 0 0 12px -3px #2ff3ff; }
