* {
  box-sizing: border-box;
}

:root {
  --bg0: #0e1014;
  --bg1: #1a1f28;
  --panel: #161b22;
  --ink: #e8ecf1;
  --muted: #8b95a5;
  --accent: #e8a838;
  --p1: #e8c84a;
  --p2: #5ecf7a;
  --danger: #e85a4a;
  --steel: #9aa3ad;
  --line: #2a3140;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #2a3344 0%, transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  color: var(--ink);
  font-family: "DIN Alternate", "Avenir Next Condensed", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

#wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.top {
  text-align: center;
}

.top h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  letter-spacing: 0.08em;
  font-weight: 800;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

#stage {
  display: flex;
  gap: 0.85rem;
  align-items: stretch;
  width: 100%;
  justify-content: center;
}

.hud {
  width: 110px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.75rem 0.5rem;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--line);
  border-radius: 4px;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

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

.enemy-icons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  max-height: 220px;
  overflow: hidden;
}

.enemy-icon {
  width: 14px;
  height: 14px;
  background: #c45c4a;
  border: 1px solid #8a3028;
  clip-path: polygon(20% 10%, 80% 10%, 90% 40%, 70% 90%, 30% 90%, 10% 40%);
}

.lives {
  color: var(--danger);
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

.power {
  font-size: 0.75rem;
  color: var(--accent);
}

.score {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.level-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.level-name {
  font-size: 0.72rem;
  color: var(--ink);
  line-height: 1.3;
  opacity: 0.9;
}

.canvas-wrap {
  position: relative;
  line-height: 0;
  border: 3px solid #3a4252;
  box-shadow:
    0 0 0 2px #0a0c10,
    8px 8px 0 rgba(0, 0, 0, 0.35);
  background: #000;
}

#game {
  display: block;
  width: min(624px, calc(100vw - 160px));
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 12, 0.82);
  backdrop-filter: blur(2px);
  z-index: 5;
}

.overlay[hidden],
.overlay.is-hidden {
  display: none !important;
}

.panel {
  width: min(420px, 92%);
  padding: 1.5rem 1.35rem;
  background: var(--panel);
  border: 2px solid var(--line);
  color: var(--ink);
  text-align: center;
}

.panel[hidden] {
  display: none;
}

.panel h2 {
  margin: 0 0 0.6rem;
  font-size: 1.45rem;
  letter-spacing: 0.06em;
}

.panel-desc {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.mode-btns {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.1rem;
}

.btn {
  appearance: none;
  border: 2px solid #e8ecf1;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.7rem 1rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: #1d1c1c;
  color: #1d1c1c;
}

.btn-secondary {
  background: var(--p2);
  border-color: #1d1c1c;
  color: #1d1c1c;
}

.btn-ghost {
  margin-top: 0.45rem;
  border-color: var(--line);
  color: var(--muted);
}

.controls-help {
  text-align: left;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.55;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}

.controls-help p {
  margin: 0.2rem 0;
}

.controls-help strong {
  color: var(--p1);
}

.end-score {
  font-size: 1.1rem;
  margin: 0.5rem 0 1rem;
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: var(--accent);
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  z-index: 6;
  border: 1px solid var(--accent);
  pointer-events: none;
}

.toast[hidden] {
  display: none;
}

.hint {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.hint a {
  color: var(--accent);
}

@media (max-width: 760px) {
  #stage {
    flex-direction: column;
    align-items: center;
  }

  .hud {
    width: 100%;
    max-width: 624px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
  }

  .enemy-icons {
    grid-template-columns: repeat(8, 1fr);
    max-height: none;
  }

  #game {
    width: min(624px, calc(100vw - 2rem));
  }
}

.start-mobile-hint {
  display: none;
  margin: 0 0 0.85rem;
  color: var(--accent);
  font-size: 0.85rem;
}

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: none;
}

#touch-controls.is-active {
  display: block;
}

.tc-stick-zone {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 128px;
  height: 128px;
  pointer-events: auto;
  touch-action: none;
}

.tc-stick-base {
  position: absolute;
  inset: 0;
  border: 3px solid rgba(232, 236, 241, 0.45);
  border-radius: 50%;
  background: rgba(14, 16, 20, 0.45);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.tc-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border: 3px solid #e8c84a;
  border-radius: 50%;
  background: rgba(232, 200, 74, 0.92);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.tc-actions {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 14px;
  pointer-events: auto;
}

.tc-btn {
  width: 72px;
  height: 72px;
  border: 3px solid #e8ecf1;
  border-radius: 50%;
  background: rgba(232, 168, 56, 0.9);
  color: #1d1c1c;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.55);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.tc-btn:active,
.tc-btn.is-pressed {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.55);
  background: rgba(255, 244, 141, 0.95);
}

.tc-fire {
  background: rgba(232, 90, 74, 0.92);
  color: #fff;
  border-color: #1d1c1c;
}

/* Mobile play layout */
body.mobile-play {
  overscroll-behavior: none;
  touch-action: manipulation;
}

body.mobile-play .start-mobile-hint {
  display: block;
}

body.mobile-play .top h1 {
  font-size: 1.15rem;
}

body.mobile-play .subtitle,
body.mobile-play .hint,
body.mobile-play .controls-help {
  display: none;
}

body.mobile-play .hud {
  padding: 0.4rem 0.35rem;
  gap: 0.45rem;
}

body.mobile-play .enemy-icons {
  max-height: 48px;
  overflow: hidden;
}

body.mobile-play.playing #touch-controls.is-active {
  display: block;
}

body.mobile-play.playing .canvas-wrap {
  margin-bottom: 8px;
}

@media (max-width: 760px) and (orientation: landscape) {
  body.mobile-play #wrap {
    padding: 0.35rem 0.5rem 0.5rem;
    gap: 0.35rem;
  }

  body.mobile-play #stage {
    flex-direction: row;
    align-items: center;
  }

  body.mobile-play .hud {
    width: 88px;
    max-width: none;
    flex-direction: column;
    max-height: min(70vh, 520px);
    overflow-y: auto;
  }

  body.mobile-play .enemy-icons {
    grid-template-columns: repeat(2, 1fr);
    max-height: 100px;
  }

  body.mobile-play #game {
    width: min(70vh, calc(100vw - 140px));
  }

  body.mobile-play .top {
    display: none;
  }
}
