:root {
  color-scheme: dark;
  --bg: #070b1d;
  --panel: rgba(14, 20, 49, .78);
  --line: rgba(139, 173, 255, .22);
  --text: #edf4ff;
  --muted: #8d9bbd;
  --cyan: #5de4ff;
  --violet: #8c7cff;
  --gold: #ffc857;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eaf1ff;
  --panel: rgba(255, 255, 255, .84);
  --line: rgba(52, 75, 125, .18);
  --text: #121b38;
  --muted: #566481;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #eaf1ff;
    --panel: rgba(255, 255, 255, .84);
    --line: rgba(52, 75, 125, .18);
    --text: #121b38;
    --muted: #566481;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body {
  min-height: 100svh;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

#app {
  width: min(1300px, 100%);
  height: 100svh;
  margin: auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(12px, 2vw, 28px);
  gap: 12px;
}

#hud,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand h1 {
  margin: 2px 0 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
  letter-spacing: .18em;
  font-weight: 850;
}

.eyebrow {
  margin: 0;
  color: var(--cyan);
  font-size: .65rem;
  letter-spacing: .2em;
  font-weight: 800;
}

.stats {
  display: flex;
  align-items: center;
  gap: clamp(10px, 3vw, 30px);
}

.stats div {
  min-width: 45px;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.stats strong {
  font-size: 1.25rem;
}

.icon-button,
footer button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--muted);
  font-size: .68rem;
  letter-spacing: .08em;
}

#game-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #080b22;
  box-shadow: 0 24px 80px rgba(25, 41, 120, .2);
}

#game,
#game canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(107, 223, 255, .35);
  border-radius: 50%;
  pointer-events: none;
}

#reticle::after {
  content: "";
  position: absolute;
  inset: 10px;
  background: var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--cyan);
}

.modal-card {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: min(430px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: clamp(24px, 5vw, 44px);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 15, 42, .87);
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 90px rgba(0, 0, 0, .36);
}

.modal-card h2 {
  margin: 10px 0;
  font-size: clamp(1.8rem, 6vw, 3rem);
  line-height: 1;
}

.modal-card p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.6;
}

.help {
  margin-bottom: 0;
  font-size: .72rem;
}

.planet-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 24px;
  border: 3px solid var(--cyan);
  border-radius: 50%;
  box-shadow:
    inset -9px -5px 0 rgba(140, 124, 255, .38),
    0 0 30px rgba(93, 228, 255, .35);
}

.primary-button {
  width: 100%;
  min-height: 52px;
  margin-top: 20px;
  border: 0;
  border-radius: 10px;
  color: #071026;
  background: linear-gradient(110deg, var(--cyan), #a8f5ff);
  font-weight: 850;
  letter-spacing: .08em;
  box-shadow: 0 0 25px rgba(93, 228, 255, .28);
}

.hidden {
  display: none;
}

#touch-controls {
  position: absolute;
  z-index: 3;
  inset: auto 18px 18px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
}

.dpad {
  position: relative;
  width: 136px;
  height: 136px;
  pointer-events: auto;
}

.dpad button {
  position: absolute;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(143, 191, 255, .35);
  background: rgba(19, 31, 75, .7);
  border-radius: 9px;
}

.dpad button::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
  transform: rotate(45deg);
  inset: 17px;
}

.dpad button:nth-child(1) {
  left: 45px;
  top: 0;
}

.dpad button:nth-child(2) {
  left: 0;
  top: 45px;
}

.dpad button:nth-child(3) {
  left: 45px;
  top: 90px;
}

.dpad button:nth-child(4) {
  left: 90px;
  top: 45px;
}

.dpad button:nth-child(2)::after {
  transform: rotate(-45deg);
}

.dpad button:nth-child(3)::after {
  transform: rotate(225deg);
}

.dpad button:nth-child(4)::after {
  transform: rotate(135deg);
}

.fire-button {
  pointer-events: auto;
  width: 78px;
  height: 78px;
  border: 2px solid rgba(93, 228, 255, .5);
  border-radius: 50%;
  color: #081027;
  background: var(--cyan);
  font-size: .7rem;
  font-weight: 900;
  box-shadow: 0 0 28px rgba(93, 228, 255, .32);
}

footer {
  color: var(--muted);
  font-size: .62rem;
  letter-spacing: .12em;
}

footer button {
  min-height: 36px;
  padding: 0 8px;
  font-size: .6rem;
}

#toast {
  position: absolute;
  z-index: 4;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--gold);
  font-size: .7rem;
  letter-spacing: .15em;
  pointer-events: none;
  white-space: nowrap;
}

@media (min-width: 700px) {
  #touch-controls {
    opacity: .48;
  }

  #touch-controls:hover {
    opacity: 1;
  }
}

@media (max-width: 560px) {
  #app {
    padding: 10px;
    gap: 8px;
  }

  #hud {
    flex-wrap: wrap;
  }

  .brand {
    order: 1;
  }

  .stats {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .icon-button {
    order: 2;
    margin-left: auto;
  }

  #game-shell {
    border-radius: 16px;
  }

  footer span {
    display: none;
  }

  footer {
    justify-content: flex-end;
  }
}
