:root {
  --bg-top: #0a1a2f;
  --bg-bottom: #03070f;
  --panel: rgba(8, 18, 36, 0.9);
  --panel-strong: rgba(7, 15, 30, 0.95);
  --card: rgba(11, 21, 40, 0.78);
  --accent: #32d7ff;
  --accent-2: #ffcd45;
  --danger: #ff5d73;
  --text: #e9f6ff;
  --text-dim: #94b9d8;
  --grid: rgba(50, 215, 255, 0.15);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 20% -20%, #173d6b 0%, transparent 60%),
    radial-gradient(800px 500px at 100% 120%, #571941 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.game-shell {
  width: min(100%, 920px);
  background: linear-gradient(180deg, rgba(10, 19, 37, 0.96), rgba(6, 12, 24, 0.92));
  border: 1px solid rgba(50, 215, 255, 0.28);
  border-radius: 24px;
  padding: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(50, 215, 255, 0.06), transparent 36%),
    linear-gradient(300deg, rgba(255, 205, 69, 0.04), transparent 34%);
  pointer-events: none;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

h1 {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.95rem, 2.3vw, 1.22rem);
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: var(--accent-2);
}

.title-credit {
  display: inline-block;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.52em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.88rem;
  font-weight: 500;
}

.stats strong {
  color: var(--accent);
  font-weight: 700;
}

.hp-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hp-bar {
  width: 74px;
  height: 8px;
  border: 1px solid rgba(50, 215, 255, 0.32);
  border-radius: 10px;
  background: rgba(2, 10, 22, 0.85);
  overflow: hidden;
}

.hp-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff5d73 0%, #ffcd45 40%, #64ff8f 100%);
  transition: width 120ms linear;
}

.canvas-wrap {
  margin-top: 16px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(50, 215, 255, 0.18);
  width: 100%;
  aspect-ratio: 800 / 520;
  background: linear-gradient(180deg, rgba(6, 12, 22, 0.92), rgba(4, 8, 16, 0.98));
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, #020408, #040b15 70%);
  background-size: 24px 24px, 24px 24px, 100% 100%;
}

.controls {
  margin-top: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #c3e9ff;
  position: relative;
  z-index: 4;
}

.help-content {
  max-height: 42vh;
  overflow: auto;
}

.touch-controls {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  width: 100%;
}

.rotate-hint {
  display: none;
  margin-top: 6px;
  margin-bottom: 6px;
  border: 1px solid var(--accent-2);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 205, 69, 0.12);
  color: #fff7d6;
  font-size: 0.78rem;
  text-align: center;
}

.bottom-controls {
  margin-top: 6px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-areas: "left shoot right pause quit";
  gap: 10px;
  justify-content: stretch;
  align-items: stretch;
  padding: 0 2px 8px;
  border-bottom: 1px solid rgba(50, 215, 255, 0.12);
}

#leftBtn {
  grid-area: left;
}

#rightBtn {
  grid-area: right;
}

#shootBtn {
  grid-area: shoot;
}

#pauseBtn {
  grid-area: pause;
}

#quitBtn {
  grid-area: quit;
}

.move-zone {
  display: none;
  min-height: 58px;
  border: 1px solid rgba(50, 215, 255, 0.3);
  border-radius: 999px;
  background: rgba(4, 15, 35, 0.92);
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.move-zone::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: rgba(50, 215, 255, 0.45);
}

.move-handle {
  position: absolute;
  top: 8px;
  left: calc(50% - 20px);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid #9ff3ff;
  background: rgba(50, 215, 255, 0.22);
  box-shadow: 0 0 12px rgba(50, 215, 255, 0.35);
  transition: left 70ms linear;
  pointer-events: none;
}

.shoot-main {
  min-height: 46px;
  height: 46px;
  border-color: rgba(255, 205, 69, 0.44);
  background: linear-gradient(180deg, rgba(255, 205, 69, 0.24), rgba(255, 123, 107, 0.14));
  color: #fff7d6;
  border-radius: 12px;
  font-size: 0.78rem;
}

.bottom-controls button {
  width: 100%;
  min-height: 44px;
  height: 44px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.help-panel {
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  background: rgba(5, 12, 24, 0.72);
  overflow: hidden;
  position: relative;
  z-index: 5;
}

.help-toggle {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  font-size: 0.86rem;
  font-weight: 700;
  color: #d6f5ff;
  background: rgba(50, 215, 255, 0.08);
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.help-toggle:hover {
  background: rgba(50, 215, 255, 0.16);
}

.help-toggle[aria-expanded="true"] {
  color: #fff7d6;
}

.help-content {
  padding: 14px;
}

.help-content p {
  margin: 0;
}

.difficulty-switch {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.audio-controls {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.audio-controls label {
  font-size: 0.8rem;
  color: #d6f5ff;
}

.audio-controls input[type="range"] {
  width: 140px;
}

.audio-preset {
  font-size: 0.78rem;
  padding: 7px 9px;
}

.audio-preset.active {
  border-color: var(--accent-2);
  background: rgba(255, 205, 69, 0.22);
  color: #fff7d6;
}

.powerup-legend {
  margin-top: 10px;
}

.powerup-legend p {
  margin: 0 0 6px;
}

.legend-items {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #07121d;
}

.legend-heal {
  background: #64ff8f;
}

.legend-rapid {
  background: #32d7ff;
}

.legend-shield {
  background: #ffcd45;
}

.legend-blaster {
  background: #ff7b6b;
}

.mode-choice {
  font-size: 0.8rem;
  padding: 8px 12px;
}

.mode-choice.active {
  border-color: var(--accent-2);
  background: rgba(255, 205, 69, 0.22);
  color: #fff7d6;
}

.leaderboard-wrap {
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.leaderboard-wrap p {
  margin: 0 0 8px;
}

.leaderboard {
  margin: 0;
  padding-left: 20px;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #d6f5ff;
}

.leaderboard li {
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
}

button {
  border: 1px solid rgba(50, 215, 255, 0.26);
  background: linear-gradient(180deg, rgba(15, 28, 51, 0.95), rgba(8, 16, 30, 0.96));
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 700;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(50, 215, 255, 0.58);
  outline: none;
}

button:active {
  transform: translateY(1px) scale(0.98);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: auto;
  background: rgba(3, 8, 16, 0.72);
  backdrop-filter: blur(6px);
  text-align: center;
  padding: 18px;
  z-index: 3;
  overflow: auto;
}

.overlay.upgrade-focus {
  z-index: 9;
  background: rgba(0, 0, 0, 0.58);
}

.overlay.upgrade-focus p {
  border-color: #ffcd45;
  box-shadow: 0 0 18px rgba(255, 205, 69, 0.35);
  animation: none;
}

.overlay p {
  background: rgba(6, 14, 26, 0.92);
  border: 1px solid rgba(50, 215, 255, 0.24);
  border-radius: 16px;
  padding: 16px 18px;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.6rem, 2.2vw, 0.78rem);
  line-height: 1.6;
  color: var(--accent-2);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.3);
  animation: blink 1.35s infinite steps(1);
  max-width: min(92vw, 720px);
}

.overlay.hidden {
  display: none;
}

.upgrade-panel {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.overlay.upgrade-focus .upgrade-panel {
  gap: 12px;
}

.menu-panel {
  margin-top: 4px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.menu-panel button {
  min-width: 220px;
  background: linear-gradient(180deg, rgba(255, 205, 69, 0.22), rgba(255, 123, 107, 0.14));
  border-color: rgba(255, 205, 69, 0.44);
}

#quitBtn {
  border-color: rgba(255, 93, 115, 0.42);
  background: linear-gradient(180deg, rgba(255, 93, 115, 0.22), rgba(120, 18, 42, 0.22));
}

.scores-panel {
  margin-top: 12px;
  min-width: min(92vw, 420px);
  border: 1px solid rgba(50, 215, 255, 0.2);
  border-radius: 18px;
  background: rgba(6, 14, 26, 0.95);
  padding: 16px;
}

.pseudo-panel {
  margin-top: 12px;
  min-width: min(92vw, 360px);
  border: 1px solid rgba(255, 205, 69, 0.34);
  border-radius: 18px;
  background: rgba(6, 14, 26, 0.96);
  padding: 16px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
}

#pseudoInput {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 10px;
  background: rgba(4, 15, 35, 0.9);
  color: #d6f5ff;
  border: 1px solid rgba(50, 215, 255, 0.2);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  font-size: 0.82rem;
}

#pseudoInput:focus {
  outline: 1px solid var(--accent-2);
  border-color: var(--accent-2);
}

.pseudo-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.pseudo-actions button {
  min-width: 140px;
}

.scores-title {
  margin: 0 0 8px;
  font-family: "Press Start 2P", monospace;
  font-size: 0.68rem;
  color: #ffcd45;
  animation: none !important;
  border: 0 !important;
  background: transparent !important;
  padding: 0 !important;
}

.scores-panel .leaderboard {
  max-height: 36vh;
  overflow: auto;
  margin-bottom: 10px;
}

#scoresCloseBtn {
  min-width: 180px;
}

.upgrade-choice {
  min-width: 180px;
  font-size: 0.78rem;
  padding: 12px 10px;
  background: linear-gradient(180deg, rgba(50, 215, 255, 0.2), rgba(11, 30, 55, 0.9));
}

.upgrade-choice:hover {
  background: rgba(255, 205, 69, 0.2);
  border-color: var(--accent-2);
}

.overlay.upgrade-focus .upgrade-choice {
  border-color: #ffcd45;
  background: rgba(255, 205, 69, 0.2);
}

.hidden-element {
  display: none;
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.75;
  }
}

@media (max-width: 640px) {
  body {
    padding: 8px;
  }

  .game-shell {
    padding: 10px;
    border-radius: 16px;
  }

  .hud {
    justify-content: center;
  }

  h1 {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stats span {
    font-size: 0.72rem;
    justify-content: center;
  }

  .controls {
    font-size: 0.82rem;
  }

  .bottom-controls {
    grid-template-columns: 1.35fr 0.65fr;
    grid-template-areas:
      "move shoot"
      "pause quit";
  }

  .desktop-move {
    display: none;
  }

  .move-zone {
    display: block;
    grid-area: move;
  }

  .bottom-controls button {
    min-height: 52px;
    height: 52px;
    font-size: 0.8rem;
  }

  .shoot-main {
    min-height: 62px;
    height: 62px;
    font-size: 0.9rem;
    border-radius: 999px;
  }

  .move-zone {
    min-height: 62px;
  }

  .move-handle {
    top: 9px;
    width: 42px;
    height: 42px;
    left: calc(50% - 21px);
  }

  .help-content {
    max-height: 34vh;
  }

  .upgrade-choice {
    min-width: 150px;
    font-size: 0.5rem;
  }

  .menu-panel {
    width: 100%;
  }

  .menu-panel button {
    min-width: 0;
    width: 100%;
  }

  .scores-panel {
    min-width: 0;
    width: 100%;
    padding: 10px;
  }

  .leaderboard {
    font-size: 0.72rem;
    line-height: 1.55;
  }

  .help-panel summary {
    font-size: 0.76rem;
  }

  .help-toggle {
    font-size: 0.76rem;
  }
}

@media (max-width: 420px) {
  .stats {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .hp-bar {
    width: 96px;
  }

  .overlay p {
    padding: 10px;
    line-height: 1.45;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  .rotate-hint {
    display: block;
  }
}

@media (max-width: 900px) {
  html,
  body {
    width: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  .game-shell {
    width: 100%;
    max-width: none;
    min-height: calc(100dvh - 12px);
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding: 4px;
  }

  .game-shell {
    min-height: 100dvh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 6px;
    border-radius: 8px;
  }

  .hud {
    gap: 6px;
  }

  h1 {
    font-size: 0.72rem;
  }

  .stats {
    gap: 8px;
  }

  .stats span {
    font-size: 0.56rem;
    padding: 6px 8px;
  }

  .canvas-wrap {
    margin-top: 0;
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
  }

  canvas {
    height: 100%;
  }

  .controls {
    margin-top: 0;
  }

  .help-panel,
  .rotate-hint {
    display: none !important;
  }

  .bottom-controls {
    margin-top: 0;
  }
}
