:root {
  color-scheme: dark;
  --bg: #02040d;
  --grid: rgba(110, 140, 255, 0.08);
  --fg: #e8edff;
  --accent: #8ec5ff;
  --danger: #ff7d7d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 25%, #0b1640 0%, var(--bg) 52%, #010206 100%);
  color: var(--fg);
  font-family: "Trebuchet MS", "Arial Narrow", Arial, sans-serif;
  touch-action: manipulation;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.game-shell {
  width: min(96vw, 980px);
  position: relative;
  border: 2px solid rgba(142, 197, 255, 0.35);
  box-shadow: 0 0 40px rgba(42, 113, 255, 0.18);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
}

.hud {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.label {
  color: var(--accent);
  margin-right: 6px;
}

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

.help,
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  background: rgba(1, 4, 10, 0.68);
}

h1,
h2 {
  margin: 0 0 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

p {
  margin: 0;
}

.hint {
  color: var(--accent);
  margin-top: 8px;
}

.menu-btn {
  justify-self: center;
  margin-top: 10px;
  padding: 10px 18px;
  border: 1px solid rgba(142, 197, 255, 0.7);
  color: var(--fg);
  background: rgba(14, 30, 77, 0.7);
  border-radius: 8px;
  font: inherit;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.menu-btn:active {
  transform: scale(0.98);
}

.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(10px + var(--safe-bottom));
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  padding-left: calc(10px + var(--safe-left));
  padding-right: calc(10px + var(--safe-right));
  pointer-events: none;
}

.touch-move {
  display: flex;
  gap: 8px;
}

.touch-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.touch-btn {
  pointer-events: auto;
  width: 74px;
  height: 56px;
  border-radius: 12px;
  border: 1px solid rgba(142, 197, 255, 0.65);
  background: rgba(13, 34, 92, 0.72);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  touch-action: none;
  user-select: none;
}

.touch-btn:active,
.touch-btn.active {
  background: rgba(39, 82, 196, 0.9);
}

.touch-auto {
  width: 88px;
  height: 42px;
  font-size: 0.8rem;
  border-color: rgba(255, 205, 112, 0.8);
  background: rgba(93, 66, 16, 0.72);
}

.touch-fire {
  width: 88px;
  height: 88px;
  border-radius: 999px;
  border-color: rgba(255, 140, 140, 0.95);
  background: rgba(110, 21, 34, 0.7);
}

.hidden {
  display: none;
}

.show-touch .touch-controls {
  display: flex;
}

@media (max-width: 720px) {
  .hud {
    font-size: 0.85rem;
    padding: 8px 10px;
  }

  .touch-btn {
    width: 66px;
    height: 52px;
    font-size: 0.82rem;
  }

  .touch-auto {
    width: 78px;
    height: 38px;
    font-size: 0.74rem;
  }

  .touch-fire {
    width: 80px;
    height: 80px;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  .game-shell {
    width: min(100vw, 980px);
  }

  .hud {
    font-size: 0.76rem;
    padding: 6px 10px;
  }

  .touch-controls {
    bottom: calc(6px + var(--safe-bottom));
    padding-left: calc(6px + var(--safe-left));
    padding-right: calc(6px + var(--safe-right));
    gap: 8px;
  }

  .touch-move {
    gap: 6px;
  }

  .touch-btn {
    width: 58px;
    height: 44px;
    font-size: 0.72rem;
  }

  .touch-auto {
    width: 68px;
    height: 30px;
    font-size: 0.65rem;
  }

  .touch-fire {
    width: 68px;
    height: 68px;
  }
}
