:root {
  color-scheme: dark;
  --ink: #f2f7ec;
  --muted: #a9b9ad;
  --line: rgba(242, 247, 236, 0.18);
  --panel: rgba(8, 18, 18, 0.78);
  --danger: #ff4d5f;
  --reward: #76f7a3;
  --warn: #ffd166;
  --cyan: #61d8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 25% 14%, rgba(118, 247, 163, 0.16), transparent 28%),
    radial-gradient(circle at 78% 18%, rgba(255, 77, 95, 0.16), transparent 26%),
    linear-gradient(180deg, #091111 0%, #040707 56%, #070b09 100%);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.radio-return {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 10;
  display: inline-grid;
  place-items: center;
  min-width: 74px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255, 209, 102, 0.46);
  border-radius: 6px;
  background: rgba(5, 8, 8, 0.82);
  color: var(--warn);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
}

.radio-return:hover,
.radio-return:focus-visible {
  outline: 2px solid rgba(97, 216, 255, 0.7);
  outline-offset: 2px;
  border-color: rgba(255, 209, 102, 0.82);
  background: rgba(55, 31, 6, 0.9);
}

#gameShell {
  position: relative;
  width: min(calc(100vw - 24px), 960px, calc((100vh - 70px) * 8 / 7));
  aspect-ratio: 8 / 7;
  max-height: calc(100vh - 70px);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #050808;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
}

.hud {
  position: absolute;
  inset: calc(max(12px, env(safe-area-inset-top)) + 58px) max(12px, env(safe-area-inset-right)) auto max(12px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  font-size: clamp(11px, 1.6vw, 15px);
  line-height: 1;
  text-transform: uppercase;
}

.weapon-hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  width: min(760px, calc(100% - 28px));
  min-height: 0;
  padding: 5px 6px;
  transform: translateX(-50%);
  border: 1px solid rgba(97, 216, 255, 0.36);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(8, 18, 18, 0.86), rgba(8, 18, 18, 0.56));
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}

.weapon-copy,
.weapon-meter,
.weapon-note {
  display: none;
}

.weapon-hud.ready,
.weapon-hud.firing {
  border-color: rgba(255, 209, 102, 0.92);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(55, 31, 6, 0.9), rgba(8, 18, 18, 0.72)),
    repeating-linear-gradient(90deg, rgba(255, 209, 102, 0.12) 0 6px, transparent 6px 18px);
  box-shadow: 0 0 22px rgba(255, 209, 102, 0.18), inset 0 0 0 1px rgba(255, 209, 102, 0.22);
}

.weapon-hud.firing {
  border-color: rgba(118, 247, 163, 0.96);
  background:
    linear-gradient(180deg, rgba(6, 55, 34, 0.92), rgba(8, 18, 18, 0.72)),
    repeating-linear-gradient(90deg, rgba(118, 247, 163, 0.14) 0 8px, transparent 8px 20px);
  box-shadow: 0 0 30px rgba(118, 247, 163, 0.22), inset 0 0 0 1px rgba(118, 247, 163, 0.26);
}

.weapon-copy {
  display: grid;
  grid-template-columns: minmax(74px, auto) minmax(110px, 1fr) minmax(44px, auto);
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.weapon-status,
.weapon-key,
.weapon-note {
  font-size: clamp(8px, 1.15vw, 11px);
  font-weight: 900;
  line-height: 1;
}

.weapon-status {
  color: var(--cyan);
  text-align: left;
}

.weapon-hud.ready .weapon-status,
.weapon-hud.firing .weapon-status {
  color: var(--warn);
}

.weapon-copy strong {
  overflow: visible;
  color: var(--reward);
  font-size: clamp(12px, 1.55vw, 16px);
  line-height: 1.04;
  white-space: normal;
}

.weapon-hud.ready .weapon-copy strong,
.weapon-hud.firing .weapon-copy strong {
  color: var(--warn);
}

.weapon-key {
  justify-self: end;
  min-width: 44px;
  padding: 3px 5px;
  border: 1px solid rgba(118, 247, 163, 0.45);
  border-radius: 4px;
  color: var(--reward);
  background: rgba(4, 8, 8, 0.68);
}

.weapon-hud.ready .weapon-key,
.weapon-hud.firing .weapon-key {
  border-color: rgba(255, 209, 102, 0.76);
  color: #161006;
  background: var(--warn);
}

.weapon-meter {
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(242, 247, 236, 0.12);
}

.weapon-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--reward), var(--cyan), var(--warn));
  transition: width 140ms ease-out;
}

.weapon-hud.ready .weapon-meter span,
.weapon-hud.firing .weapon-meter span {
  background: linear-gradient(90deg, var(--warn), #ff4d5f);
}

.weapon-rack {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.weapon-slot {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 24px;
  grid-template-rows: auto 4px;
  align-items: center;
  gap: 3px 5px;
  min-width: 0;
  padding: 4px 5px;
  border: 1px solid rgba(97, 216, 255, 0.22);
  border-radius: 5px;
  background: rgba(4, 8, 8, 0.54);
}

.weapon-slot.ready {
  border-color: rgba(255, 209, 102, 0.72);
  background: rgba(55, 31, 6, 0.58);
}

.weapon-slot.fired {
  border-color: rgba(118, 247, 163, 0.92);
  background: rgba(6, 55, 34, 0.68);
  box-shadow: 0 0 14px rgba(118, 247, 163, 0.16);
}

.weapon-slot.locked {
  opacity: 0.62;
}

.weapon-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  position: relative;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(118, 247, 163, 0.5);
  border-radius: 50%;
  color: var(--reward);
  background: rgba(118, 247, 163, 0.1);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

.weapon-icon::before,
.weapon-icon::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
}

.weapon-icon-cover::before {
  inset: 5px 6px 4px;
  border: 2px solid currentColor;
  border-top-width: 3px;
  border-radius: 8px 8px 10px 10px;
  clip-path: polygon(0 0, 100% 0, 88% 68%, 50% 100%, 12% 68%);
}

.weapon-icon-cover::after {
  inset: 8px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.weapon-icon-swarm::before {
  top: 4px;
  left: 8px;
  width: 0;
  height: 0;
  border-right: 4px solid transparent;
  border-bottom: 9px solid currentColor;
  border-left: 4px solid transparent;
  filter:
    drop-shadow(-6px 7px 0 currentColor)
    drop-shadow(6px 7px 0 currentColor);
}

.weapon-icon-swarm::after {
  right: 4px;
  bottom: 4px;
  left: 4px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.55;
}

.weapon-icon-bomb::before {
  right: 5px;
  bottom: 4px;
  left: 5px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.weapon-icon-bomb::after {
  top: 4px;
  right: 5px;
  width: 8px;
  height: 7px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(28deg);
}

.weapon-icon-sweep::before {
  top: 5px;
  right: 4px;
  left: 4px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 5px 0 currentColor, 0 10px 0 currentColor;
}

.weapon-icon-sweep::after {
  top: 4px;
  left: 6px;
  width: 11px;
  height: 14px;
  border-right: 2px solid currentColor;
  transform: skewX(-18deg);
  opacity: 0.55;
}

.weapon-slot.ready .weapon-icon,
.weapon-slot.fired .weapon-icon {
  border-color: rgba(255, 209, 102, 0.78);
  color: #161006;
  background: var(--warn);
}

.weapon-slot-copy {
  min-width: 0;
  text-align: left;
}

.weapon-slot-copy strong {
  overflow: hidden;
  color: rgba(242, 247, 236, 0.9);
  font-size: 8px;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weapon-slot-key {
  justify-self: end;
  min-width: 20px;
  padding: 2px 4px;
  border: 1px solid rgba(118, 247, 163, 0.35);
  border-radius: 3px;
  color: rgba(242, 247, 236, 0.72);
  background: rgba(4, 8, 8, 0.56);
  font-size: 7px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.weapon-slot.ready .weapon-slot-key,
.weapon-slot.fired .weapon-slot-key {
  border-color: rgba(255, 209, 102, 0.72);
  color: #161006;
  background: var(--warn);
}

.weapon-slot-meter {
  grid-column: 2 / 4;
  overflow: hidden;
  height: 4px;
  border-radius: 999px;
  background: rgba(242, 247, 236, 0.12);
}

.weapon-slot-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--reward), var(--cyan));
  transition: width 140ms ease-out;
}

.weapon-slot.ready .weapon-slot-meter span,
.weapon-slot.fired .weapon-slot-meter span {
  background: linear-gradient(90deg, var(--warn), #ff4d5f);
}

.weapon-hud .weapon-copy,
.weapon-hud .weapon-meter,
.weapon-hud .weapon-note {
  display: none;
}

.hud-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(8, 18, 18, 0.84), rgba(8, 18, 18, 0.48));
}

.hud-cluster.right {
  justify-content: flex-end;
}

.sound-button {
  min-width: 42px;
  min-height: 28px;
  padding: 0 7px;
  border-color: rgba(97, 216, 255, 0.55);
  color: var(--ink);
  background: rgba(97, 216, 255, 0.14);
  font-size: 11px;
  pointer-events: auto;
}

.sound-button.muted {
  border-color: rgba(255, 77, 95, 0.55);
  color: rgba(242, 247, 236, 0.72);
  background: rgba(255, 77, 95, 0.16);
}

.hud-cluster.effects {
  color: var(--warn);
}

.hud strong {
  display: inline-block;
  min-width: 4ch;
  color: var(--reward);
  text-align: right;
}

.ticker-chip {
  padding: 4px 6px;
  border-radius: 4px;
  color: #06100c;
  background: var(--reward);
  font-weight: 800;
}

.banner {
  position: absolute;
  top: 22%;
  left: 50%;
  width: min(420px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 6px;
  background: rgba(10, 12, 9, 0.78);
  color: var(--warn);
  text-align: center;
  text-transform: uppercase;
  font-size: clamp(13px, 2.2vw, 22px);
  font-weight: 900;
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(1, 5, 4, 0.58), rgba(1, 5, 4, 0.9));
  text-align: center;
}

.scoreboard {
  width: min(420px, calc(100vw - 72px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-radius: 6px;
  background: rgba(8, 18, 18, 0.74);
}

.scoreboard-title,
.initials-entry label {
  color: var(--warn);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.score-list {
  display: grid;
  gap: 4px;
  min-height: 96px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.score-list li {
  display: grid;
  grid-template-columns: 3ch 5ch 1fr 7ch;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: clamp(10px, 1.6vw, 13px);
  line-height: 1;
  text-align: left;
  text-transform: uppercase;
}

.score-list .score-rank {
  color: var(--muted);
}

.score-list .score-name {
  color: var(--reward);
  font-weight: 900;
}

.score-list .score-level {
  color: var(--cyan);
  text-align: center;
}

.score-list .score-value {
  color: var(--warn);
  text-align: right;
}

.score-list .empty-score {
  grid-template-columns: 1fr;
  color: var(--muted);
  text-align: center;
}

.initials-entry {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.initials-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.initials-entry input {
  width: 86px;
  height: 44px;
  border: 1px solid rgba(118, 247, 163, 0.62);
  border-radius: 6px;
  color: var(--reward);
  background: rgba(5, 8, 8, 0.92);
  font: 900 24px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-align: center;
  text-transform: uppercase;
}

.initials-entry input:focus-visible {
  outline: 2px solid rgba(97, 216, 255, 0.7);
  outline-offset: 2px;
}

.ship-select {
  display: grid;
  grid-template-columns: repeat(4, minmax(104px, 1fr));
  gap: 7px;
  width: min(620px, calc(100vw - 72px));
  margin: 0;
  padding: 8px 8px 9px;
  border: 1px solid rgba(97, 216, 255, 0.34);
  border-radius: 6px;
  background: rgba(8, 18, 18, 0.62);
}

.ship-select legend {
  padding: 0 6px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.ship-card {
  position: relative;
  display: grid;
  grid-template-rows: 48px auto auto;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  padding: 7px 5px 6px;
  border: 1px solid rgba(242, 247, 236, 0.16);
  border-radius: 4px;
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
}

.ship-card:has(input:checked) {
  border-color: rgba(118, 247, 163, 0.86);
  background: rgba(118, 247, 163, 0.1);
  box-shadow: inset 0 0 0 1px rgba(118, 247, 163, 0.28), 0 0 16px rgba(118, 247, 163, 0.12);
}

.ship-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ship-card img {
  width: 68px;
  height: 48px;
  object-fit: contain;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.48));
}

.ship-name {
  color: var(--reward);
  font-size: clamp(10px, 1.35vw, 12px);
  line-height: 1;
}

.ship-tags {
  max-width: 12ch;
  color: var(--muted);
  font-size: clamp(7px, 1.05vw, 9px);
  line-height: 1.15;
  text-align: center;
}

.ship-select input {
  accent-color: var(--reward);
}

.level-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(1, 5, 4, 0.55), rgba(1, 5, 4, 0.9)),
    repeating-linear-gradient(0deg, rgba(118, 247, 163, 0.06) 0 2px, transparent 2px 9px);
  text-align: center;
}

.level-overlay.bonus {
  background:
    linear-gradient(180deg, rgba(14, 10, 2, 0.44), rgba(1, 5, 4, 0.92)),
    repeating-linear-gradient(90deg, rgba(255, 209, 102, 0.08) 0 4px, transparent 4px 16px);
}

.level-overlay.prize {
  background:
    linear-gradient(180deg, rgba(5, 16, 10, 0.5), rgba(1, 5, 4, 0.92)),
    repeating-linear-gradient(45deg, rgba(118, 247, 163, 0.08) 0 5px, transparent 5px 18px);
}

.level-overlay.boss {
  background:
    linear-gradient(180deg, rgba(22, 5, 7, 0.5), rgba(1, 5, 4, 0.92)),
    repeating-linear-gradient(0deg, rgba(255, 77, 95, 0.09) 0 4px, transparent 4px 15px);
}

.level-kicker {
  color: var(--warn);
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
}

.level-overlay h2 {
  max-width: min(760px, 100%);
  color: var(--ink);
  font-size: clamp(34px, 7vw, 70px);
  line-height: 0.96;
}

.level-prize {
  min-width: min(420px, 100%);
  padding: 10px 14px;
  border: 1px solid rgba(118, 247, 163, 0.54);
  border-radius: 6px;
  color: var(--reward);
  background: rgba(8, 18, 18, 0.74);
  font-size: clamp(13px, 2vw, 18px);
  font-weight: 900;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

.mark {
  color: var(--reward);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(34px, 8vw, 76px);
  line-height: 0.95;
  text-transform: uppercase;
}

h2 {
  font-size: clamp(30px, 6vw, 58px);
  line-height: 1;
  text-transform: uppercase;
}

p {
  max-width: 520px;
  color: var(--muted);
  font-size: clamp(13px, 2vw, 18px);
  line-height: 1.45;
}

button {
  min-width: 150px;
  min-height: 44px;
  border: 1px solid rgba(118, 247, 163, 0.62);
  border-radius: 6px;
  color: #07100d;
  background: var(--reward);
  font: 900 14px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-transform: uppercase;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  outline: 2px solid rgba(97, 216, 255, 0.7);
  outline-offset: 2px;
}

button.secondary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.controls {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  display: none;
  grid-template-columns: 58px minmax(78px, 116px) minmax(74px, 108px) 58px;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  pointer-events: none;
}

.controls button {
  min-width: 0;
  width: 58px;
  height: 54px;
  pointer-events: auto;
  color: var(--ink);
  background: rgba(8, 18, 18, 0.78);
  backdrop-filter: blur(8px);
}

.controls .fire-button {
  width: 100%;
  color: #120909;
  background: var(--warn);
}

.controls .cover-button {
  width: 100%;
  color: #06100c;
  background: var(--reward);
}

.help {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  max-width: min(100vw - 24px, 960px);
  color: rgba(242, 247, 236, 0.68);
  font-size: 12px;
}

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  body {
    display: block;
  }

  .controls {
    display: grid;
  }

  .help {
    display: none;
  }

  #gameShell {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
    border-right: 0;
    border-left: 0;
  }

  .hud {
    top: calc(max(10px, env(safe-area-inset-top)) + 92px);
    flex-wrap: wrap;
    align-items: flex-start;
    font-size: 11px;
  }

  .weapon-hud {
    top: max(8px, env(safe-area-inset-top));
    width: min(430px, calc(100% - 16px));
    padding: 5px 7px;
  }

  .weapon-copy {
    grid-template-columns: minmax(62px, auto) minmax(98px, 1fr) minmax(44px, auto);
    gap: 5px;
  }

  .weapon-copy strong {
    font-size: 13px;
  }

  .weapon-rack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  .weapon-slot {
    grid-template-columns: 20px minmax(0, 1fr) 22px;
    padding: 3px 4px;
  }

  .weapon-icon {
    width: 20px;
    height: 20px;
  }

  .weapon-slot-copy strong {
    font-size: 8px;
  }

  .weapon-slot-key {
    font-size: 7px;
  }

  .weapon-status,
  .weapon-key,
  .weapon-note {
    font-size: 8px;
  }

  .hud .effects {
    order: 3;
    width: min(100%, 360px);
  }

  .hud-cluster {
    padding: 7px 8px;
    gap: 6px;
  }

  .sound-button {
    min-width: 38px;
    min-height: 26px;
    font-size: 10px;
  }

  .ship-select {
    grid-template-columns: repeat(2, minmax(104px, 1fr));
    width: min(360px, calc(100vw - 36px));
  }

  .ship-card {
    grid-template-rows: 38px auto auto;
  }

  .ship-card img {
    width: 58px;
    height: 38px;
  }

  .banner {
    top: 22%;
  }
}
