:root {
  /* Deep space: black-navy void, neon-teal hull glow, violet gravity wells. */
  --bg: #03060f;
  --bg-2: #0a1430;
  --panel: rgba(8, 14, 30, 0.94);
  --ink: #e7eeff;
  --muted: #8693b5;
  --accent: #46f0d0;     /* neon teal — ship / HUD */
  --accent-2: #9b6bff;   /* violet — gravity wells */
  --warn: #ff6b8a;       /* hull-breach pink */
  --line: rgba(180, 200, 255, 0.10);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 14px;
}

/* Ads */
.ad-rail { display: flex; justify-content: center; align-items: center; min-height: 90px; }
.ad-slot { width: 100%; max-width: 728px; }
.ad-placeholder {
  width: 100%; max-width: 728px; min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: 12px;
  color: var(--muted); font-size: 12px; letter-spacing: 0.18em;
  text-transform: uppercase; background: rgba(255, 255, 255, 0.02);
}
.ad-rail.ad-live .ad-placeholder { display: none; }
.ad-rail:not(.ad-live) .ad-slot { display: none !important; }

/* Stage */
.stage { max-width: 1040px; width: 100%; margin: 0 auto; }
.game-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 5;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, #0c1838 0%, #060b1c 55%, #03060f 100%);
  cursor: crosshair;
  touch-action: none;
}

/* HUD — kept clear of the top-right controls; shrinks on narrow screens. */
.hud {
  position: absolute;
  top: 14px; left: 16px; right: 110px;
  display: flex; gap: 18px; align-items: center;
  pointer-events: none;
  font-size: 13px; letter-spacing: 0.1em;
  color: var(--muted);
}
.hud b { color: var(--ink); font-size: 18px; margin-left: 5px; font-variant-numeric: tabular-nums; }
.hud-lives { display: flex; align-items: center; gap: 6px; }
.hud-lives .ships { display: inline-flex; gap: 4px; }
.hud-lives .ship-pip {
  width: 11px; height: 13px; display: inline-block;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 100%, 50% 78%, 0 100%);
  filter: drop-shadow(0 0 4px rgba(70, 240, 208, 0.7));
}
@media (max-width: 620px) {
  .hud { gap: 10px; right: 96px; font-size: 11px; letter-spacing: 0.04em; }
  .hud b { font-size: 14px; margin-left: 3px; }
}

/* Tractor-beam energy meter — thin bar along the BOTTOM of the arena. */
.beam {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: min(520px, 78%); pointer-events: none; z-index: 2;
}
.beam .beam-label {
  font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--muted); text-align: center; margin-bottom: 4px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.beam .beam-bar {
  height: 7px; border-radius: 5px; overflow: hidden;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
}
.beam .beam-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.08s linear;
}
.beam.is-overheat .beam-fill { background: linear-gradient(90deg, var(--warn), #ffb05a); }
.beam.is-overheat .beam-label { color: var(--warn); }
/* lift the beam meter clear of the on-screen pads on touch devices */
body.is-touch .beam { bottom: 84px; width: min(420px, 64%); }

.controls {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: flex; gap: 8px; align-items: center;
}
.ctrl-btn {
  height: 38px; border-radius: 19px;
  border: 1px solid var(--line); background: rgba(12, 22, 48, 0.7);
  color: var(--ink); font-size: 14px; font-weight: 700; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; text-decoration: none;
  backdrop-filter: blur(4px);
  transition: filter 0.15s ease, transform 0.06s ease;
}
.ctrl-btn:hover { filter: brightness(1.25); }
.ctrl-btn:active { transform: scale(0.94); }
.back-btn { padding: 0 14px; }
.mute-btn { width: 38px; border-radius: 50%; font-size: 16px; }
.mute-btn.is-muted { opacity: 0.6; }

/* Touch controls — only shown on coarse-pointer / touch devices (body.is-touch). */
.touch-controls { display: none; }
body.is-touch .touch-controls {
  display: flex; justify-content: space-between; align-items: flex-end;
  position: absolute; inset: auto 0 0 0; z-index: 4;
  padding: 0 14px 14px; pointer-events: none;
}
.touch-controls.hidden { display: none !important; }
.tc-cluster { display: flex; gap: 10px; pointer-events: auto; }
.tc-btn {
  width: 58px; height: 58px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(12, 22, 48, 0.55);
  color: var(--ink); font-size: 22px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); user-select: none; touch-action: none;
}
.tc-btn.is-down { background: rgba(70, 240, 208, 0.28); border-color: var(--accent); }
.tc-btn--fire { width: 70px; height: 70px; font-size: 24px; }
.tc-btn--fire.is-down { background: rgba(255, 107, 138, 0.3); border-color: var(--warn); }
.tc-btn--tractor.is-down { background: rgba(155, 107, 255, 0.32); border-color: var(--accent-2); }

/* Overlay */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 7, 18, 0.62); backdrop-filter: blur(3px);
  transition: opacity 0.2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.panel {
  width: min(470px, 88%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 26px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.logo {
  margin: 0 0 10px; font-size: clamp(30px, 5.4vw, 46px); font-weight: 800;
  letter-spacing: 0.10em;
  text-shadow: 0 0 22px rgba(70, 240, 208, 0.45);
}
.logo span { color: var(--accent); }
.msg { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 20px; }
.msg b { color: var(--ink); }
.kbd {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin: 0 1px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.04); color: var(--ink);
  font: 600 12px/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
}
.result { margin-bottom: 16px; }
.big-score { font-size: 56px; font-weight: 800; color: var(--accent); line-height: 1; text-shadow: 0 0 24px rgba(70, 240, 208, 0.4); }
.result-line { color: var(--muted); font-size: 14px; margin-top: 6px; }
.btn {
  border: none; border-radius: 12px; padding: 13px 18px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
}
.btn--primary:hover { filter: brightness(1.06); }
.hint { margin-top: 12px; color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

.btn--ghost { background: rgba(255, 255, 255, 0.08); color: var(--ink); white-space: nowrap; }
.name-row { display: flex; gap: 8px; margin-bottom: 16px; }
#name-input {
  flex: 1; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); padding: 10px 12px; font-size: 15px; outline: none;
}
#name-input:focus { border-color: var(--accent); }

/* Leaderboard */
.leaderboard {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.leaderboard h2 {
  margin: 0 0 12px; font-size: 16px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
#leaderboard-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
#leaderboard-list li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
#leaderboard-list li:last-child { border-bottom: none; }
#leaderboard-list li:not(.lb-empty)::before {
  counter-increment: rank; content: counter(rank);
  width: 26px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.lb-name { flex: 1; margin: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--muted); justify-content: center !important; }
li.is-you { color: var(--accent); }
