:root {
  --bg: #020617;
  --panel: #0f172a;
  --panel-2: #1e293b;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --blue: #60a5fa;
  --purple: #a855f7;
  --sky: #0ea5e9;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:disabled {
  cursor: default;
}

/* ---------- Menu ---------- */
.screen-menu,
.screen-over {
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  justify-content: safe center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at center, #0f172a 0%, #000 70%);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.screen-menu {
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 0.75rem max(1.5rem, env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse 55% 40% at 78% 12%, rgba(88, 28, 135, 0.45), transparent 70%),
    radial-gradient(ellipse 42% 36% at 12% 82%, rgba(14, 116, 144, 0.35), transparent 72%),
    radial-gradient(ellipse at 50% 30%, #122044 0%, #070b18 48%, #02040c 100%);
}

.space-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.starfield {
  position: absolute;
  inset: -10%;
  background-repeat: repeat;
}

.starfield-far {
  opacity: 0.45;
  background-image: radial-gradient(1px 1px at 10px 12px, #fff, transparent),
    radial-gradient(1px 1px at 40px 70px, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.5px 1.5px at 90px 30px, #dbeafe, transparent);
  background-size: 140px 110px;
  animation: stars-drift 80s linear infinite;
}

.starfield-near {
  opacity: 0.7;
  background-image: radial-gradient(1.5px 1.5px at 20px 40px, #fff, transparent),
    radial-gradient(2px 2px at 120px 90px, #fde68a, transparent);
  background-size: 220px 180px;
  animation: stars-drift 46s linear infinite;
}

@keyframes stars-drift {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(180px);
  }
}

.planet {
  position: absolute;
  top: 6%;
  right: -70px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, #bfdbfe 0%, #3b82f6 28%, #1e3a8a 62%, #0b1224 100%);
  box-shadow:
    inset -28px -18px 40px rgba(0, 0, 0, 0.45),
    0 0 60px rgba(59, 130, 246, 0.28);
}

.planet::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 46%;
  width: 340px;
  height: 78px;
  transform: translate(-50%, -50%) rotate(-18deg);
  border-radius: 50%;
  border: 10px solid rgba(186, 230, 253, 0.55);
  box-shadow: 0 0 18px rgba(125, 211, 252, 0.35);
}

.moon {
  position: absolute;
  left: 4%;
  bottom: 8%;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #f8fafc, #94a3b8 55%, #475569 100%);
  box-shadow: inset -10px -8px 16px rgba(15, 23, 42, 0.45), 0 0 24px rgba(226, 232, 240, 0.2);
}

.menu-invader {
  position: absolute;
  animation: float-invader 6.5s ease-in-out infinite;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.45));
}

.menu-invader.late {
  animation-delay: -3s;
}

.menu-invader .invader {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.menu-invader .frame-a {
  animation: inv-a 0.7s steps(1, end) infinite;
}

.menu-invader .frame-b {
  animation: inv-b 0.7s steps(1, end) infinite;
}

@keyframes float-invader {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -14px;
  }
}

.menu-shell {
  position: relative;
  z-index: 1;
  width: min(88rem, calc(100% - 1.5rem));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9.5rem;
  align-items: stretch;
  gap: 1.25rem;
}

.card {
  width: 100%;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #334155;
  border-radius: 1rem;
  padding: 1.5rem 1.25rem 1.75rem;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.45);
}

.credits {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  padding: 1rem 0.4rem;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #334155;
  border-radius: 1.25rem;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.45);
}

.author-logo {
  width: 104px;
  height: 104px;
  object-fit: contain;
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.55));
}

.credits-by {
  margin: 0;
  font-weight: 800;
  font-size: 0.82rem;
  line-height: 1.3;
  color: #e2e8f0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.social-links {
  display: grid;
  grid-template-columns: repeat(3, 2.05rem);
  justify-content: center;
  gap: 0.4rem;
  margin: 0.15rem 0 0;
}

.social-link {
  width: 2.05rem;
  height: 2.05rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  text-decoration: none;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
}

.social-link svg {
  width: 1.05rem;
  height: 1.05rem;
}

.social-link.instagram {
  color: #e1306c;
}

.social-link.facebook {
  color: #1877f2;
}

.social-link.youtube {
  color: #ff0000;
}

.social-link.web {
  color: #0284c7;
}

.social-link:hover {
  transform: translateY(-2px);
}

.credits-web {
  color: #fde68a;
  font-weight: 800;
  font-size: 0.62rem;
  line-height: 1.3;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.credits-web:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .menu-shell {
    width: min(46rem, 100%);
    grid-template-columns: 1fr;
  }

  .credits {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem 1.25rem;
    padding: 1rem 1.25rem;
  }

  .author-logo {
    width: 120px;
    height: 120px;
  }

  .social-links {
    margin: 0;
  }
}

@media (max-width: 720px) {
  .card {
    padding: 1.1rem 0.9rem 1.25rem;
  }

  .credits-web {
    white-space: normal;
  }

  .planet {
    width: 150px;
    height: 150px;
    right: -48px;
  }

  .planet::after {
    width: 210px;
    height: 48px;
    border-width: 7px;
  }

  .menu-invader {
    opacity: 0.35;
  }
}

@media (min-width: 640px) {
  .card {
    padding: 2rem;
    border-radius: 1.25rem;
  }
}

.menu-header {
  text-align: center;
  margin-bottom: 1.5rem;
  position: relative;
}

.mute-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-weight: 800;
  font-size: 0.8rem;
}

.mute-btn:hover {
  background: #334155;
  color: #fff;
}

.mute-btn.is-muted {
  color: #f87171;
  border-color: #7f1d1d;
}

.over-mute {
  margin-top: 1rem;
}

.logo {
  font-size: clamp(1.9rem, 6vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(90deg, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.mode-toggle {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.mode-toggle-inner {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--panel-2);
  border: 1px solid #334155;
  border-radius: 0.75rem;
  padding: 0.35rem;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1rem;
  border-radius: 0.55rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: #94a3b8;
  transition: 0.15s ease;
}

.mode-btn:hover {
  color: #e2e8f0;
}

.mode-btn.active-hd {
  background: #3b82f6;
  color: #fff;
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}

.mode-btn.active-perf {
  background: #f97316;
  color: #fff;
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.35);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
}

.section-note {
  margin: -0.35rem 0 0.75rem;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
}

.players-rule {
  margin: 0.75rem 0 0;
  color: #86efac;
}

.section {
  margin-bottom: 1.4rem;
}

.mission-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

@media (min-width: 640px) {
  .mission-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
}

@media (min-width: 981px) {
  .mission-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.choice,
.digit-btn,
.player-btn {
  border: 2px solid #334155;
  background: var(--panel-2);
  border-radius: 0.75rem;
  font-weight: 700;
  transition: 0.15s ease;
}

.choice {
  text-align: left;
  padding: 0.7rem 0.85rem;
  font-size: 0.95rem;
  color: #cbd5e1;
}

.choice:hover,
.digit-btn:hover,
.player-btn:hover {
  border-color: #64748b;
}

.choice.active {
  background: rgba(37, 99, 235, 0.2);
  border-color: #3b82f6;
  color: #93c5fd;
}

.row {
  display: flex;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .row {
    gap: 1rem;
  }
}

.digit-btn,
.player-btn {
  flex: 1;
  padding: 0.55rem 0;
  font-size: 1.15rem;
  color: #94a3b8;
}

@media (min-width: 640px) {
  .digit-btn {
    padding: 0.75rem 0;
    font-size: 1.25rem;
  }
  .player-btn {
    padding: 1rem 0;
    font-size: 1.25rem;
  }
}

.digit-btn.active {
  background: rgba(202, 138, 4, 0.18);
  border-color: #eab308;
  color: #facc15;
}

.player-btn.active {
  background: rgba(22, 163, 74, 0.18);
  border-color: #22c55e;
  color: #4ade80;
}

.how-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 2px solid #38bdf8;
  background: rgba(14, 165, 233, 0.12);
  color: #7dd3fc;
  font-size: 1.05rem;
  font-weight: 800;
}

.how-btn:hover {
  background: rgba(14, 165, 233, 0.22);
}

.launch {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 0.9rem 1rem;
  border-radius: 0.75rem;
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(90deg, #2563eb, #9333ea);
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.launch:hover {
  transform: scale(1.02);
  filter: brightness(1.08);
}

@media (min-width: 640px) {
  .launch {
    padding: 1.15rem;
    font-size: 1.5rem;
  }
}

.hint {
  margin-top: 0.9rem;
  text-align: center;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
}

.screen-help {
  height: 100%;
}

.help-shell {
  position: relative;
  z-index: 1;
  width: min(52rem, 100%);
}

.help-card {
  --loop: 9s;
  padding: 1rem 1rem 1.05rem;
}

.help-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.help-top h1 {
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 800;
}

.help-back {
  width: auto;
  margin: 0;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
}

.demo {
  border: 1px solid #334155;
  border-radius: 0.9rem;
  overflow: hidden;
  background: #020617;
}

.demo-field {
  position: relative;
  height: 196px;
  background:
    radial-gradient(circle at 18% 20%, rgba(56, 189, 248, 0.16), transparent 42%),
    linear-gradient(#10182f, #020617 70%);
}

.demo-invader,
.demo-ship,
.demo-missile,
.demo-plus {
  position: absolute;
  left: 68%;
  transform: translateX(-50%);
  animation-duration: var(--loop);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: var(--scrub, 0s);
}

.demo-invader {
  top: 12%;
  width: 58px;
  animation-name: demo-invader;
}

.demo-invader .invader,
.demo-ship .fighter {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.demo-invader .frame-a,
.demo-ship .frame-a {
  animation: inv-a 0.45s steps(1, end) infinite;
}

.demo-invader .frame-b,
.demo-ship .frame-b {
  animation: inv-b 0.45s steps(1, end) infinite;
}

.demo-ship .frame-a,
.demo-ship .frame-b {
  animation-duration: 0.12s;
}

.demo-ship {
  bottom: 4%;
  width: 84px;
  left: 24%;
  animation-name: demo-ship;
}

.demo-missile {
  top: 72%;
  width: 5px;
  height: 18px;
  border-radius: 3px;
  background: linear-gradient(#fff, #38bdf8);
  box-shadow: 0 0 10px #38bdf8;
  opacity: 0;
  animation-name: demo-missile;
}

.demo-plus {
  top: 16%;
  color: #fde047;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 1.35rem;
  font-weight: 800;
  opacity: 0;
  text-shadow: 0 0 12px rgba(253, 224, 71, 0.8);
  animation-name: demo-plus;
}

.demo-console {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.8rem;
  background: #0f172a;
  border-top: 1px solid #334155;
}

.demo-eq {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(1.2rem, 2.6vw, 1.65rem);
  font-weight: 800;
}

.demo-answer {
  display: inline-grid;
  min-width: 1ch;
}

.demo-answer b {
  grid-area: 1 / 1;
  font-weight: 800;
  opacity: 0;
  animation-duration: var(--loop);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: var(--scrub, 0s);
}

.guess-q {
  animation-name: demo-q;
}

.guess-bad {
  color: #fca5a5;
  animation-name: demo-bad;
}

.guess-a {
  color: #86efac;
  animation-name: demo-good;
}

.demo-fire {
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  background: #334155;
  color: #64748b;
  animation: demo-fire var(--loop) linear infinite;
  animation-delay: var(--scrub, 0s);
}

.demo-caption {
  position: relative;
  height: 1.45em;
  margin: 0.55rem 0 0.75rem;
  text-align: center;
  font-weight: 800;
}

.demo-caption span {
  position: absolute;
  inset: 0;
  opacity: 0;
  animation-duration: var(--loop);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: var(--scrub, 0s);
}

.cap-a { animation-name: demo-cap-a; }
.cap-b { animation-name: demo-cap-b; color: #fca5a5; }
.cap-c { animation-name: demo-cap-c; color: #86efac; }
.cap-d { animation-name: demo-cap-d; color: #fde047; }

.help-bits {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

.help-bits li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  min-height: 5.4rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid #334155;
  border-radius: 0.75rem;
  background: rgba(2, 6, 23, 0.55);
}

.help-bits p {
  color: #e2e8f0;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.3;
}

.bit-art {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.7rem;
}

.bit-heart.on {
  color: #fb7185;
}

.bit-heart.fade {
  color: #fb7185;
  animation: heart-lose 2.4s ease-in-out infinite;
}

.bit-keys kbd {
  min-width: 1.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.4rem;
  border: 1px solid #475569;
  background: #1e293b;
  color: #f8fafc;
  font-family: inherit;
  font-weight: 800;
  text-align: center;
}

.bit-race {
  gap: 0.55rem;
}

.race-track {
  flex: 1;
  height: 0.7rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid #334155;
  overflow: hidden;
}

.race-fill {
  display: block;
  height: 100%;
  width: 18%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #fde047);
  animation: race-go 2.8s ease-in-out infinite;
}

.bit-race b {
  color: #fde047;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.95rem;
}

@keyframes demo-ship {
  0%, 14% { left: 24%; }
  30%, 100% { left: 68%; }
}

@keyframes demo-invader {
  0%, 66% { opacity: 1; filter: none; transform: translateX(-50%) scale(1); }
  73% { opacity: 0; filter: brightness(2.5); transform: translateX(-50%) scale(1.4); }
  88%, 100% { opacity: 1; filter: none; transform: translateX(-50%) scale(1); }
}

@keyframes demo-missile {
  0%, 49% { opacity: 0; top: 74%; }
  52% { opacity: 1; top: 68%; }
  66% { opacity: 1; top: 22%; }
  69%, 100% { opacity: 0; top: 16%; }
}

@keyframes demo-plus {
  0%, 66% { opacity: 0; transform: translateX(-50%) translateY(8px) scale(0.8); }
  74% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.15); }
  86% { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(1); }
  100% { opacity: 0; }
}

@keyframes demo-q {
  0%, 17% { opacity: 1; }
  18%, 91% { opacity: 0; }
  92%, 100% { opacity: 1; }
}

@keyframes demo-bad {
  0%, 17% { opacity: 0; }
  18%, 35% { opacity: 1; }
  36%, 100% { opacity: 0; }
}

@keyframes demo-good {
  0%, 35% { opacity: 0; }
  36%, 90% { opacity: 1; }
  92%, 100% { opacity: 0; }
}

@keyframes demo-fire {
  0%, 35% { background: #334155; color: #64748b; box-shadow: none; }
  36%, 72% { background: #22c55e; color: #fff; box-shadow: 0 0 16px rgba(34, 197, 94, 0.65); }
  78%, 100% { background: #334155; color: #64748b; box-shadow: none; }
}

@keyframes demo-cap-a {
  0%, 17% { opacity: 1; }
  18%, 100% { opacity: 0; }
}

@keyframes demo-cap-b {
  0%, 17% { opacity: 0; }
  18%, 35% { opacity: 1; }
  36%, 100% { opacity: 0; }
}

@keyframes demo-cap-c {
  0%, 35% { opacity: 0; }
  36%, 63% { opacity: 1; }
  64%, 100% { opacity: 0; }
}

@keyframes demo-cap-d {
  0%, 63% { opacity: 0; }
  64%, 91% { opacity: 1; }
  92%, 100% { opacity: 0; }
}

@keyframes heart-lose {
  0%, 42% { opacity: 1; color: #fb7185; }
  58%, 88% { opacity: 0.2; color: #334155; }
  100% { opacity: 1; color: #fb7185; }
}

@keyframes race-go {
  0% { width: 16%; }
  72%, 100% { width: 100%; }
}

@media (min-width: 760px) {
  .help-bits {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .demo-invader,
  .demo-ship,
  .demo-missile,
  .demo-plus,
  .demo-answer b,
  .demo-fire,
  .demo-caption span,
  .bit-heart.fade,
  .race-fill {
    animation: none;
  }

  .demo-ship { left: 68%; }
  .demo-missile { opacity: 0; }
  .demo-plus { opacity: 1; transform: translateX(-50%); }
  .guess-q, .guess-bad, .cap-a, .cap-b, .cap-c { opacity: 0; }
  .guess-a, .cap-d { opacity: 1; }
  .demo-fire { background: #22c55e; color: #fff; }
  .race-fill { width: 100%; }
}

/* ---------- Play ---------- */
.play-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #020617;
}

.play-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
}

.match-rule {
  flex: 1;
  margin: 0;
  text-align: center;
  color: #86efac;
  font-size: clamp(0.68rem, 1.5vw, 0.85rem);
  font-weight: 800;
  line-height: 1.25;
}

.ingame-menu {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  z-index: 40;
}

.ingame-menu:hover {
  background: #334155;
  border-color: #64748b;
}

.ingame-menu:active {
  transform: scale(0.97);
}

.play-root {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  background: #020617;
}

.play-root::-webkit-scrollbar {
  height: 6px;
}

.play-root::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 99px;
}

.player-col {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 4px solid #020617;
  min-width: 280px;
}

.player-col:last-child {
  border-right: 0;
}

.players-1 .player-col {
  width: 100%;
  min-width: 100%;
}

.players-2 .player-col {
  width: 50%;
  min-width: 300px;
}

.players-3 .player-col {
  width: 33.333%;
  min-width: 300px;
}

.players-4 .player-col {
  width: 25%;
  min-width: 280px;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
  pointer-events: none;
}

.score {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.2rem 0.7rem;
  backdrop-filter: blur(6px);
}

.score.has-goal {
  font-size: clamp(0.78rem, 1.5vw, 1.05rem);
  letter-spacing: -0.03em;
}

.level-chip {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(0.85rem, 1.6vw, 1.05rem);
  font-weight: 700;
  line-height: 1;
  color: #fde047;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid #854d0e;
  border-radius: 0.4rem;
  padding: 0.28rem 0.5rem;
}

.hearts {
  display: flex;
  gap: 0.2rem;
}

.heart {
  width: 1.35rem;
  height: 1.35rem;
  color: #1e293b;
}

.heart.alive {
  color: #ef4444;
}

.heart.alive.hd {
  filter: drop-shadow(0 0 5px red);
}

.battlefield {
  flex: 5.5 1 0;
  position: relative;
  overflow: hidden;
  border-bottom: 4px solid #334155;
  pointer-events: none;
  background: #000;
}

.battlefield.hd {
  background: radial-gradient(ellipse at top, #1e293b, #0f172a 45%, #000 80%);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.5);
}

.stars {
  position: absolute;
  inset: 0;
  opacity: 0.3;
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PGNpcmNsZSBjeD0iMiIgY3k9IjIiIHI9IjEiIGZpbGw9IiNmZmYiLz48L3N2Zz4=");
  pointer-events: none;
}

.missile {
  position: absolute;
  width: 7px;
  height: 28px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: linear-gradient(to top, #fb923c, #fde047, #fff);
  will-change: top, left;
  box-shadow: 0 0 10px #fde047, 0 0 18px #fb923c;
}

.missile.hd,
.missile.perf {
  background: linear-gradient(to top, #fb923c, #fde047, #fff);
}

.missile::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 70%;
  width: 11px;
  height: 22px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom, rgba(253, 224, 71, 0.7), transparent);
  filter: blur(3px);
  border-radius: 999px;
}

.muzzle {
  position: absolute;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #fde047 40%, rgba(251, 146, 60, 0) 70%);
  box-shadow: 0 0 16px #fde047;
  animation: muzzle-pop 0.2s ease-out forwards;
  z-index: 6;
  pointer-events: none;
}

@keyframes muzzle-pop {
  0% {
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.8);
    opacity: 0;
  }
}

.boom {
  position: absolute;
  width: 8px;
  height: 8px;
  transform: translate(-50%, -50%);
  z-index: 8;
  pointer-events: none;
}

.boom-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #fde047 28%, #fb923c 52%, transparent 70%);
  animation: boom-flash 0.4s ease-out forwards;
}

.boom-pixel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3px 0 0 -3px;
  border-radius: 1px;
  animation: boom-fly 0.45s ease-out forwards;
}

@keyframes boom-flash {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.35);
    opacity: 0;
  }
}

@keyframes boom-fly {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--x), var(--y)) scale(0.2);
    opacity: 0;
  }
}

.enemy {
  position: absolute;
  transform: translate(-50%, -50%);
  will-change: top, left;
}

.enemy.hd {
  filter: drop-shadow(0 0 6px currentColor) drop-shadow(0 0 12px currentColor);
}

.enemy svg.invader {
  width: 56px;
  height: auto;
  overflow: visible;
  display: block;
}

@media (min-width: 640px) {
  .enemy svg.invader {
    width: 68px;
  }
}

.enemy .frame-a {
  animation: inv-a var(--march, 0.7s) steps(1, end) infinite;
}

.enemy .frame-b {
  animation: inv-b var(--march, 0.7s) steps(1, end) infinite;
}

@keyframes inv-a {
  0%,
  49.99% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@keyframes inv-b {
  0%,
  49.99% {
    opacity: 0;
  }
  50%,
  100% {
    opacity: 1;
  }
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(-25%);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

.ship {
  position: absolute;
  bottom: 4%;
  transform: translateX(-50%);
  transition: transform 0.075s linear;
  will-change: left;
  z-index: 4;
}

.ship svg.fighter {
  width: 72px;
  height: auto;
  display: block;
  position: relative;
  z-index: 2;
  overflow: visible;
  image-rendering: pixelated;
}

.ship.moving svg.fighter {
  transform: scale(1.08);
}

@media (min-width: 640px) {
  .ship svg.fighter {
    width: 92px;
  }
}

.ship .frame-a {
  animation: inv-a 0.12s steps(1, end) infinite;
}

.ship .frame-b {
  animation: inv-b 0.12s steps(1, end) infinite;
}

.flame {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 26px;
  background: #f97316;
  filter: blur(7px);
  border-radius: 999px;
  animation: pulse 0.16s ease-in-out infinite;
  opacity: 0.8;
  z-index: 1;
  pointer-events: none;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
    transform: translateX(-50%) scaleY(1.25);
  }
}

.theme-0 {
  color: #60a5fa;
}
.theme-0.hd {
  filter: drop-shadow(0 0 5px rgba(96, 165, 250, 0.75));
}
.theme-1 {
  color: #34d399;
}
.theme-1.hd {
  filter: drop-shadow(0 0 5px rgba(52, 211, 153, 0.75));
}
.theme-2 {
  color: #f472b6;
}
.theme-2.hd {
  filter: drop-shadow(0 0 5px rgba(244, 114, 182, 0.75));
}
.theme-3 {
  color: #fb923c;
}
.theme-3.hd {
  filter: drop-shadow(0 0 5px rgba(251, 146, 60, 0.75));
}

.destroyed {
  position: absolute;
  inset: 0;
  background: rgba(69, 10, 10, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.destroyed.show {
  display: flex;
}

.destroyed span {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #ef4444;
  transform: rotate(-10deg);
  text-shadow: 0 8px 18px rgba(0, 0, 0, 0.6);
}

.level-lock {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(88, 28, 135, 0.45), transparent 55%),
    #05030c;
  box-shadow: inset 0 0 0 4px #fde047, inset 0 0 0 8px #12081c;
  pointer-events: none;
}

.level-lock.show {
  display: flex;
  pointer-events: auto;
}

.level-lock.show::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.09) 0 1px,
    transparent 1px 4px
  );
  animation: scan-drift 0.35s linear infinite;
}

.level-lock.show::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.55) 100%);
}

.level-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.level-lock.show .level-flash {
  animation: level-flash 0.42s steps(2, end) forwards;
}

.level-copy {
  position: relative;
  z-index: 5;
  text-align: center;
  padding: 1rem;
  font-family: "Press Start 2P", "JetBrains Mono", monospace;
}

.level-lock.show .level-copy {
  animation: crt-on 0.4s steps(5, end) both;
}

.level-kicker {
  margin-bottom: 0.85rem;
  color: #67e8f9;
  font-size: clamp(0.55rem, 1.5vw, 0.85rem);
  letter-spacing: 0.12em;
  text-shadow: -2px 0 #ff2bd6, 2px 0 #082f49;
}

.level-num {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 700;
  color: #fde047;
  font-size: clamp(4.2rem, 14vw, 8rem);
  line-height: 1;
  text-shadow:
    -3px 0 #ff2bd6,
    3px 0 #22d3ee,
    6px 6px 0 #3b0764;
}

.level-pace {
  margin-top: 1rem;
  color: #fff;
  font-size: clamp(0.72rem, 2vw, 1.05rem);
  letter-spacing: 0.08em;
  text-shadow: 3px 3px 0 #be123c;
}

.level-lock.show .level-pace {
  animation: pace-blink 0.9s linear infinite;
}

.player-col:has(.level-lock.show) .console {
  pointer-events: none;
}

@keyframes scan-drift {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 0 5px;
  }
}

@keyframes level-flash {
  0% {
    opacity: 0.92;
  }
  45% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

@keyframes crt-on {
  0% {
    transform: scaleY(0.04);
    filter: brightness(2.6);
  }
  55% {
    transform: scaleY(1);
    filter: brightness(1.45);
  }
  100% {
    transform: scaleY(1);
    filter: brightness(1);
  }
}

@keyframes pace-blink {
  0%,
  62% {
    opacity: 1;
  }
  80%,
  100% {
    opacity: 0.25;
  }
}

.console {
  flex: 4.5 1 0;
  background: var(--panel);
  padding: 0.5rem 0.5rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
}

@media (min-width: 640px) {
  .console {
    padding: 1rem;
    gap: 0.75rem;
  }
}

.equation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.8rem;
  border-radius: 0.75rem;
  border: 2px solid #334155;
  background: #020617;
  gap: 0.5rem;
}

.equation.correct {
  border-color: #22c55e;
  background: rgba(5, 46, 22, 0.35);
}

.eq-text {
  font-size: clamp(1.15rem, 2.4vw, 1.85rem);
  font-weight: 800;
  color: #bfdbfe;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eq-input {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(1.3rem, 3vw, 2.1rem);
  font-weight: 700;
  min-width: 4.4rem;
  text-align: right;
  padding: 0.15rem 0.7rem;
  border-radius: 0.5rem;
  color: #fbbf24;
  background: rgba(120, 53, 15, 0.2);
}

.equation.correct .eq-input {
  color: #4ade80;
  background: rgba(20, 83, 45, 0.35);
}

.controls {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  min-height: 0;
}

@media (min-width: 640px) {
  .controls {
    gap: 0.75rem;
  }
}

.move-col {
  width: 22%;
  min-width: 58px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.move-btn,
.num-btn,
.fire-btn {
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  touch-action: none;
  transition: transform 0.08s ease, background 0.12s ease;
}

.move-btn {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid #334155;
  color: #cbd5e1;
}

.move-btn:hover {
  background: #334155;
}

.move-btn:active {
  background: #475569;
}

.pad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.3rem;
  min-width: 0;
}

@media (min-width: 640px) {
  .pad {
    gap: 0.5rem;
  }
}

.num-btn {
  background: var(--panel-2);
  border: 1px solid #334155;
  font-size: clamp(1.05rem, 2.2vw, 1.5rem);
  font-weight: 800;
}

.num-btn:hover {
  background: #334155;
}

.num-btn:active {
  transform: scale(0.95);
  background: #475569;
}

.num-btn.clr {
  background: rgba(127, 29, 29, 0.4);
  border-color: rgba(127, 29, 29, 0.5);
  color: #fca5a5;
  font-size: 0.85rem;
}

.num-btn.del {
  background: rgba(124, 45, 18, 0.4);
  border-color: rgba(154, 52, 18, 0.5);
  color: #fdba74;
  font-size: 0.85rem;
}

.fire-wrap {
  width: 22%;
  min-width: 58px;
  display: flex;
}

.fire-btn {
  width: 100%;
  flex-direction: column;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-size: clamp(0.75rem, 1.6vw, 1.15rem);
  border-bottom: 4px solid #0f172a;
  background: var(--panel-2);
  color: #475569;
  opacity: 0.6;
}

.fire-btn.ready {
  background: #22c55e;
  border-bottom-color: #15803d;
  color: #fff;
  opacity: 1;
  transform: scale(1.05);
}

.fire-btn.ready:hover {
  background: #4ade80;
}

.move-btn svg,
.fire-btn svg {
  pointer-events: none;
}

.fire-btn svg {
  margin-bottom: 0.2rem;
}

.fire-btn.ready svg {
  animation: bounce 1s infinite;
}

/* ---------- Game over ---------- */
.over-card {
  width: min(36rem, 100%);
  background: var(--panel);
  border: 1px solid #334155;
  border-radius: 1.1rem;
  padding: 1.75rem 1.4rem;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.45);
}

.trophy {
  width: 5.5rem;
  height: 5.5rem;
  color: #facc15;
  margin: 0 auto 1rem;
}

.over-title {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  margin-bottom: 1.5rem;
}

.over-reason {
  margin: -0.85rem 0 1.35rem;
  color: #fde047;
  font-weight: 800;
}

.rank.is-winner {
  box-shadow: 0 0 0 2px #facc15;
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1.5rem;
}

.rank {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid;
}

.rank-name {
  font-size: 1.1rem;
  font-weight: 800;
}

.rank-score {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 1.3rem;
  color: #fff;
}

.rank.theme-0 {
  background: rgba(30, 58, 138, 0.3);
  border-color: rgba(59, 130, 246, 0.5);
  color: #60a5fa;
}
.rank.theme-1 {
  background: rgba(6, 78, 59, 0.3);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}
.rank.theme-2 {
  background: rgba(131, 24, 67, 0.3);
  border-color: rgba(236, 72, 153, 0.5);
  color: #f472b6;
}
.rank.theme-3 {
  background: rgba(154, 52, 18, 0.3);
  border-color: rgba(249, 115, 22, 0.5);
  color: #fb923c;
}

.over-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .over-actions {
    flex-direction: row;
  }
}

.over-actions button {
  flex: 1;
  padding: 0.95rem 1rem;
  border-radius: 0.75rem;
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
}

.btn-base {
  background: #334155;
}

.btn-base:hover {
  background: #475569;
}

.btn-exit {
  background: #0284c7;
}

.btn-exit:hover {
  background: #0ea5e9;
}
