:root {
  --bg-dark: #0d0f14;
  --bg-panel: #161a24;
  --bg-card: #1d2331;
  --border: #2e374b;
  --text-main: #edf2ff;
  --text-muted: #93a1be;
  --accent-gold: #f7c948;
  --accent-red: #ef4444;
  --accent-green: #22c55e;
  --accent-cyan: #38bdf8;
  --p1-color: #fbbf24;
  --p2-color: #4ade80;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", monospace;
  background: radial-gradient(circle at top, #1b2235 0%, #0d0f14 68%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}

.app-shell {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  border-radius: 6px;
}

.brand h1 {
  font-size: 20px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand h1 small {
  font-size: 12px;
  color: var(--accent-gold);
  letter-spacing: 0.14em;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: #283145;
  border-color: #4c5c7c;
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cabinet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 248px;
  gap: 16px;
  align-items: start;
}

.screen-frame {
  background: #232834;
  border: 3px solid #3c465c;
  border-radius: 14px;
  padding: 12px;
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.7), 0 14px 36px rgba(0, 0, 0, 0.48);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #000;
  border: 2px solid #0b0d12;
  border-radius: 6px;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 16, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  gap: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  text-align: center;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.pixel-title {
  font-family: "Courier New", monospace;
  font-size: clamp(36px, 7vw, 54px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #fde047 0%, #f97316 55%, #dc2626 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 #450a0a);
}

.subtitle {
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 0.22em;
  color: var(--text-muted);
}

.hi-score-banner {
  background: rgba(247, 201, 72, 0.12);
  border: 1px solid rgba(247, 201, 72, 0.35);
  color: var(--accent-gold);
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 260px;
}

.menu-btn {
  background: #1c2231;
  color: var(--text-main);
  border: 1px solid #38445f;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.menu-btn:hover {
  border-color: var(--accent-gold);
  background: #242d42;
}

.menu-btn.active {
  background: rgba(247, 201, 72, 0.16);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  box-shadow: 0 0 14px rgba(247, 201, 72, 0.18);
}

.stage-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.stage-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #171c28;
  border: 1px solid #2e374b;
  border-radius: 8px;
  padding: 5px 10px;
}

#stage-label {
  min-width: 145px;
  color: var(--text-main);
  font-weight: 600;
}

.mini-btn {
  background: #263044;
  color: var(--text-main);
  border: none;
  border-radius: 5px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 12px;
}

.mini-btn:hover {
  background: #394865;
}

.start-btn {
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 24px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(234, 88, 12, 0.38);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.start-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

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

.controls-mini {
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 14px;
}

.controls-mini strong {
  color: var(--text-main);
}

/* Stage banner */
#overlay-stage {
  background: #6b7280;
  color: #111827;
}

.stage-banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stage-num {
  font-family: "Courier New", monospace;
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.stage-name {
  font-size: 18px;
  font-weight: 700;
}

/* Pause & Tally */
.pause-box,
.tally-box {
  width: 100%;
  max-width: 320px;
  background: #161b26;
  border: 1px solid #354159;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
}

.pause-box h2,
.tally-box h2 {
  font-size: 22px;
  color: var(--accent-gold);
}

.pause-box p,
.tally-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.tally-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid #2a3347;
  border-bottom: 1px solid #2a3347;
  padding: 10px 0;
  font-size: 13px;
}

.tally-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tally-row .badge-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
}

.tally-total {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.tally-total.highlight {
  color: var(--accent-gold);
  font-size: 16px;
}

/* HUD Panel */
.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hud-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.p1-color {
  color: var(--p1-color);
}

.p2-color {
  color: var(--p2-color);
}

.enemy-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  min-height: 76px;
  align-content: start;
}

.enemy-pip {
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(180deg, #e5e7eb, #9ca3af);
  border: 1px solid #4b5563;
  position: relative;
}

.enemy-pip::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 8px;
  background: #1f2937;
  border-radius: 1px;
}

.enemy-pip.fast {
  background: linear-gradient(180deg, #67e8f9, #0891b2);
}

.enemy-pip.power {
  background: linear-gradient(180deg, #fdba74, #ea580c);
}

.enemy-pip.armor {
  background: linear-gradient(180deg, #86efac, #15803d);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.stat-row span {
  color: var(--text-muted);
}

.stat-row strong {
  font-family: "Courier New", monospace;
  font-size: 15px;
  color: var(--text-main);
}

.hidden {
  display: none !important;
}

.powerup-legend {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.powerup-legend li {
  display: flex;
  align-items: center;
  gap: 7px;
}

.pu-tag {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  font-size: 12px;
  background: #263044;
  color: #fff;
  flex-shrink: 0;
}

.pu-star { background: #ca8a04; }
.pu-helmet { background: #0284c7; }
.pu-shovel { background: #64748b; }
.pu-clock { background: #7c3aed; }
.pu-grenade { background: #dc2626; }
.pu-tank { background: #16a34a; }

/* Touch Controls */
.touch-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 20px;
  user-select: none;
  touch-action: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 4px;
}

.dpad-btn {
  background: #273147;
  color: #fff;
  border: 1px solid #415172;
  border-radius: 10px;
  font-size: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: var(--accent-gold);
  color: #111;
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

.fire-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid #fca5a5;
  background: radial-gradient(circle at 30% 30%, #f87171, #dc2626);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.45);
}

.fire-btn:active,
.fire-btn.pressed {
  transform: scale(0.94);
  filter: brightness(1.15);
}

.footer-tip {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding-bottom: 6px;
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .cabinet {
    grid-template-columns: 1fr;
  }

  .hud-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .legend-card {
    grid-column: 1 / -1;
  }

  .touch-controls {
    display: flex;
  }
}
