*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --void: #050814;
  --nebula: #12182e;
  --accent: #6ee7ff;
  --accent-dim: #3d9fab;
  --panel: rgba(12, 18, 38, 0.82);
  --panel-border: rgba(110, 231, 255, 0.25);
  --text: #e8f4ff;
  --muted: #8aa4c8;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  font-family: "Exo 2", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1a2850 0%, var(--void) 55%);
}

.twinkle {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.38;
  animation: twinkle 9s ease-in-out infinite alternate;
  background-image:
    radial-gradient(1px 1px at 65% 40%, rgba(255, 255, 255, 0.85), transparent),
    radial-gradient(1px 1px at 25% 55%, rgba(255, 255, 255, 0.75), transparent),
    radial-gradient(1px 1px at 90% 85%, rgba(255, 255, 255, 0.65), transparent);
  background-size: 100% 100%;
}

@keyframes twinkle {
  from {
    opacity: 0.18;
  }
  to {
    opacity: 0.42;
  }
}

/* Lightweight warp-speed starfield: tiled gradients + transform-only animation */
.starfield {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  contain: strict;
}

.warp-layer {
  position: absolute;
  left: -15%;
  top: -15%;
  width: 130%;
  height: 130%;
  transform: translate3d(0, 0, 0);
  background-repeat: repeat;
  will-change: transform;
}

.warp-deep {
  background-size: 504px 504px;
  opacity: 0.55;
  background-image:
    radial-gradient(1px 1px at 8% 14%, rgba(255, 255, 255, 0.38), transparent),
    radial-gradient(1px 1px at 53% 82%, rgba(190, 220, 255, 0.28), transparent),
    radial-gradient(1px 1px at 91% 37%, rgba(255, 255, 255, 0.32), transparent),
    radial-gradient(1px 1px at 31% 61%, rgba(255, 255, 255, 0.22), transparent),
    radial-gradient(1.5px 1.5px at 72% 19%, rgba(220, 235, 255, 0.26), transparent),
    radial-gradient(1px 1px at 44% 93%, rgba(255, 255, 255, 0.2), transparent);
  animation: warp-loop-a 62s linear infinite;
}

.warp-mid {
  background-size: 336px 336px;
  opacity: 0.72;
  background-image:
    radial-gradient(1px 1px at 17% 28%, rgba(255, 255, 255, 0.52), transparent),
    radial-gradient(1px 1px at 81% 71%, rgba(255, 255, 255, 0.38), transparent),
    radial-gradient(1px 2px at 49% 49%, rgba(200, 230, 255, 0.35), transparent),
    radial-gradient(1px 1px at 66% 12%, rgba(255, 255, 255, 0.42), transparent),
    radial-gradient(1px 1px at 22% 88%, rgba(255, 255, 255, 0.34), transparent),
    radial-gradient(1.5px 1px at 95% 54%, rgba(180, 210, 255, 0.36), transparent);
  animation: warp-loop-b 34s linear infinite;
}

.warp-near {
  background-size: 252px 252px;
  opacity: 0.88;
  background-image:
    radial-gradient(1px 4px at 40% 45%, rgba(230, 248, 255, 0.55), transparent),
    radial-gradient(1px 1px at 12% 76%, rgba(255, 255, 255, 0.65), transparent),
    radial-gradient(1px 3px at 88% 22%, rgba(255, 255, 255, 0.45), transparent),
    radial-gradient(1px 1px at 56% 91%, rgba(200, 225, 255, 0.5), transparent),
    radial-gradient(1px 5px at 73% 38%, rgba(255, 255, 255, 0.35), transparent),
    radial-gradient(1.5px 1px at 29% 17%, rgba(255, 255, 255, 0.58), transparent);
  animation: warp-loop-c 15s linear infinite;
}

@keyframes warp-loop-a {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(0, 504px, 0);
  }
}

@keyframes warp-loop-b {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(0, 336px, 0);
  }
}

@keyframes warp-loop-c {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(0, 252px, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .warp-layer {
    animation: none !important;
  }

  .twinkle {
    animation: none !important;
    opacity: 0.28;
  }
}

.shell {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  max-width: min(52rem, 100%);
  margin: 0 auto;
  padding: 0.45rem 0.65rem 0.55rem;
  min-height: 0;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.hero {
  text-align: center;
  flex-shrink: 0;
}

.hero h1 {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 3.2vmin, 1.55rem);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow:
    0 0 20px rgba(110, 231, 255, 0.45),
    0 0 40px rgba(80, 160, 220, 0.2);
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: clamp(0.68rem, 1.6vmin, 0.82rem);
  color: var(--muted);
  letter-spacing: 0.04em;
}

.game-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  align-self: center;
  width: max-content;
  max-width: 100%;
}

.game-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: clamp(0.4rem, 1.5vmin, 1rem);
}

.game-column {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.game-instructions {
  flex-shrink: 0;
  width: 100%;
  max-width: none;
  padding: 0.4rem 0.35rem 0;
}

.game-sidebar {
  flex: 0 0 auto;
  width: min(210px, 32vw);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  align-self: stretch;
}

.game-sidebar > .panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel {
  width: 100%;
  max-width: none;
  padding: 0.55rem 0.65rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 12px 40px rgba(0, 0, 0, 0.35);
}

.game-sidebar .hud {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  justify-content: center;
}

.game-sidebar .stat {
  flex-direction: row;
  justify-content: space-between;
  align-items: baseline;
  text-align: left;
  gap: 0.5rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: center;
}

.game-sidebar .stat-label {
  font-size: 0.62rem;
}

.stat-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.game-sidebar .stat-value {
  font-size: clamp(0.95rem, 2.6vmin, 1.15rem);
}

.stat-value {
  font-family: "Orbitron", monospace;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent);
}

.game-sidebar .game-over {
  font-size: 0.72rem;
  padding: 0.25rem 0.35rem;
  line-height: 1.25;
}

.game-over {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.82rem;
  color: #ffb4b4;
  padding: 0.35rem;
  border-radius: 8px;
  background: rgba(180, 60, 80, 0.15);
  border: 1px solid rgba(255, 120, 140, 0.35);
}

.game-over.hidden {
  display: none;
}

.status-flash {
  font-size: 0.68rem;
  line-height: 1.25;
  color: #ffc68a;
  padding: 0.28rem 0.35rem;
  border-radius: 8px;
  background: rgba(140, 90, 40, 0.25);
  border: 1px solid rgba(255, 190, 120, 0.35);
  text-align: center;
}

.status-flash.hidden {
  display: none;
}

.lives-indicator {
  color: #ffb8c8;
  text-shadow: 0 0 10px rgba(255, 120, 160, 0.35);
}

/* Frame: no downward offset shadow (that read as a bottom gradient). Canvas CSS
   size is set in JS to whole pixels and a height divisible by 20 rows to avoid
   blurry banding when the bitmap is scaled. */
.play-wrap {
  position: relative;
  flex: 0 1 auto;
  align-self: center;
  border-radius: 14px;
  padding: 3px;
  overflow: hidden;
  background: #080f24;
  border: 1px solid rgba(110, 231, 255, 0.45);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.45) inset,
    0 0 28px rgba(80, 150, 220, 0.22);
  max-height: min(640px, calc(100dvh - 5.5rem));
}

#game {
  display: block;
  border-radius: 11px;
  background: #050814;
  box-shadow: inset 0 0 0 1px rgba(110, 231, 255, 0.22);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.panel-heading {
  margin: 0 0 0.35rem;
  font-family: "Orbitron", sans-serif;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.rewards-caption {
  margin: 0;
  font-size: clamp(0.56rem, 1.25vmin, 0.66rem);
  color: var(--muted);
  line-height: 1.4;
}

.rewards-caption strong {
  color: var(--text);
}

.rewards-panel .badge-grid {
  flex: 1 1 0;
  min-height: 56px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
  margin-top: 0.35rem;
  padding-right: 2px;
}

.planet-badge {
  position: relative;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--pb-hi), var(--pb-lo) 62%, #050814);
  box-shadow: 0 0 6px rgba(110, 231, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.planet-badge-ring::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(240, 220, 160, 0.45);
  transform: scaleX(1.35) rotate(-28deg);
  pointer-events: none;
}

.badge-more {
  align-self: center;
  font-family: "Orbitron", sans-serif;
  font-size: 0.58rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.highscore-badge-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(110, 231, 255, 0.15);
  flex-shrink: 0;
}

.trophy-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  border: 1px solid rgba(110, 231, 255, 0.28);
  background: rgba(0, 0, 0, 0.35);
}

.trophy-badge::before {
  content: "★";
  color: rgba(255, 255, 255, 0.35);
}

.trophy-badge.locked {
  opacity: 0.45;
  filter: grayscale(1);
}

.trophy-badge.earned {
  opacity: 1;
  filter: none;
  border-color: rgba(255, 210, 130, 0.65);
  box-shadow: 0 0 14px rgba(255, 200, 100, 0.35);
  background: radial-gradient(circle at 35% 28%, #ffecc8, #c99830 62%, #4a3010);
}

.trophy-badge.earned::before {
  color: #fffef8;
  text-shadow: 0 0 8px rgba(255, 240, 200, 0.9);
}

.trophy-caption {
  font-size: clamp(0.58rem, 1.25vmin, 0.68rem);
  color: var(--muted);
  line-height: 1.3;
}

.trophy-caption small {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.68em;
  color: var(--accent-dim);
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.game-sidebar .controls-panel {
  gap: 0.4rem;
  justify-content: center;
}

.difficulty-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.difficulty-select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: clamp(0.78rem, 1.9vmin, 0.88rem);
  color: var(--text);
  background: rgba(8, 14, 28, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
}

.difficulty-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: clamp(0.75rem, 1.8vmin, 0.82rem);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.sound-row input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  font-family: "Orbitron", sans-serif;
  font-size: clamp(0.62rem, 1.5vmin, 0.7rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(30, 44, 72, 0.9);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: rgba(45, 62, 98, 0.95);
  border-color: rgba(110, 231, 255, 0.4);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(165deg, rgba(110, 231, 255, 0.25), rgba(40, 90, 140, 0.45));
  border-color: rgba(110, 231, 255, 0.55);
  color: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(165deg, rgba(110, 231, 255, 0.38), rgba(50, 110, 170, 0.55));
}

.hint {
  margin: 0;
  font-size: clamp(0.62rem, 1.45vmin, 0.72rem);
  color: var(--muted);
  line-height: 1.35;
  text-align: center;
}

@media (max-width: 520px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .game-column {
    width: 100%;
    align-items: center;
  }

  .game-sidebar {
    align-self: center;
    width: min(320px, 100%);
    flex-direction: column;
    max-height: none;
  }

  .game-sidebar > .panel {
    flex: 1 1 auto;
    min-height: min(140px, 28vh);
  }

  .game-sidebar .hud {
    flex: 1 1 auto;
  }

  .play-wrap {
    max-height: min(640px, calc(100dvh - 14rem));
  }
}
