:root {
  --sky1: #1a0a2e;
  --sky2: #16213e;
  --sky3: #0f3460;
  --ground: #2d5a1b;
  --ground-dark: #1a3a0a;
  --p1-color: #4488ff;
  --p2-color: #ff4444;
  --gold: #ffd700;
  --ui-bg: rgba(10,10,20,0.92);
  --font-pixel: 'Press Start 2P', monospace;
  --font-vt: 'VT323', monospace;
  --block-p1: #4477cc;
  --block-p2: #cc4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--sky1);
  font-family: var(--font-vt);
  overflow: hidden;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* SCREENS */
.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* LOBBY */
#screen-lobby {
  min-height: 100vh;
  position: relative;
  background: linear-gradient(180deg, #1a0a2e 0%, #16213e 50%, #0f3460 100%);
}

.lobby-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.star {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: #fff;
  animation: twinkle var(--d) ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.2; }
  to { opacity: 1; }
}

.lobby-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 16px;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.game-title {
  font-family: var(--font-pixel);
  font-size: clamp(32px, 8vw, 72px);
  color: var(--gold);
  text-shadow:
    4px 4px 0 #a0700a,
    0 0 40px rgba(255,215,0,0.5),
    0 0 80px rgba(255,215,0,0.2);
  letter-spacing: 8px;
  animation: titlePulse 2s ease-in-out infinite alternate;
}

@keyframes titlePulse {
  from { text-shadow: 4px 4px 0 #a0700a, 0 0 20px rgba(255,215,0,0.3); }
  to   { text-shadow: 4px 4px 0 #a0700a, 0 0 60px rgba(255,215,0,0.7), 0 0 100px rgba(255,215,0,0.3); }
}

.title-cannon {
  font-size: 40px;
  animation: cannonBob 1.5s ease-in-out infinite alternate;
}
.left-cannon { animation-delay: 0s; transform-origin: center; }
.right-cannon { animation-delay: 0.5s; transform: scaleX(-1); }
@keyframes cannonBob {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}
.right-cannon { animation: cannonBobR 1.5s ease-in-out infinite alternate 0.5s; }
@keyframes cannonBobR {
  from { transform: scaleX(-1) translateY(0); }
  to { transform: scaleX(-1) translateY(-8px); }
}

.subtitle {
  font-family: var(--font-vt);
  font-size: clamp(16px, 3vw, 24px);
  color: #aaa;
  letter-spacing: 4px;
}

.lobby-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--ui-bg);
  border: 2px solid var(--gold);
  border-radius: 4px;
  padding: 32px 48px;
  box-shadow: 0 0 30px rgba(255,215,0,0.15), inset 0 0 20px rgba(0,0,0,0.5);
}

.btn {
  font-family: var(--font-pixel);
  font-size: 12px;
  padding: 14px 28px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, #ff6b00, #cc4400);
  color: #fff;
  box-shadow: 0 4px 0 #882200, 0 0 20px rgba(255,107,0,0.4);
}
.btn-primary:hover {
  box-shadow: 0 4px 0 #882200, 0 0 30px rgba(255,107,0,0.7);
}

.btn-secondary {
  background: linear-gradient(180deg, #334, #223);
  color: #aaa;
  border: 1px solid #556;
  box-shadow: 0 4px 0 #112;
}
.btn-secondary:hover { color: #fff; }

.waiting-msg {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--gold);
  font-family: var(--font-vt);
  font-size: 20px;
}

.spinner {
  width: 20px; height: 20px;
  border: 3px solid rgba(255,215,0,0.3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.room-code {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: #aaa;
  letter-spacing: 2px;
}
#room-code-val { color: var(--gold); }

.controls-info {
  display: flex;
  gap: 48px;
  background: var(--ui-bg);
  border: 1px solid #334;
  border-radius: 4px;
  padding: 20px 32px;
}

.ctrl-col {
  font-family: var(--font-vt);
  font-size: 18px;
  line-height: 2;
  color: #ccc;
}
.ctrl-col h3 { font-family: var(--font-pixel); font-size: 10px; margin-bottom: 8px; }
.ctrl-col:first-child h3 { color: var(--p1-color); }
.ctrl-col:last-child h3 { color: var(--p2-color); }

kbd {
  background: #334;
  border: 1px solid #556;
  border-bottom: 2px solid #223;
  border-radius: 3px;
  padding: 1px 6px;
  font-family: var(--font-vt);
  font-size: 16px;
  color: #fff;
}

.mobile-note {
  font-family: var(--font-vt);
  font-size: 16px;
  color: #666;
}

.hidden { display: none !important; }

/* HUD */
#hud {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ui-bg);
  border-bottom: 2px solid #334;
  padding: 8px 16px;
  gap: 12px;
}

.hud-player {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.hud-player.right {
  align-items: flex-end;
}

.player-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #ccc;
}

.hp-bar-wrap {
  width: 120px;
  height: 12px;
  background: #222;
  border: 1px solid #444;
  border-radius: 2px;
  overflow: hidden;
}

.hp-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22cc44, #44ff66);
  transition: width 0.3s, background 0.3s;
}

.ammo-display {
  font-family: var(--font-vt);
  font-size: 18px;
  color: var(--gold);
  letter-spacing: 2px;
}

.reload-indicator {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: #ff4444;
  min-height: 12px;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
}

#phase-display {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: #aaa;
  letter-spacing: 1px;
}

#timer-display {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--gold);
}

#score-display {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: #fff;
}

/* CANVAS */
#canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 900px;
}

#gameCanvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

#build-tip {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: var(--gold);
  font-family: var(--font-vt);
  font-size: 16px;
  padding: 6px 16px;
  border-radius: 4px;
  border: 1px solid #444;
  white-space: nowrap;
}

/* MOBILE CONTROLS */
#mobile-controls {
  display: flex;
  justify-content: space-between;
  padding: 8px;
  background: rgba(0,0,0,0.8);
}

.mob-left {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mob-btn {
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 12px 16px;
  background: #223;
  border: 1px solid #446;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.fire-btn {
  background: linear-gradient(180deg, #cc4400, #882200);
  border-color: #ff6600;
  font-size: 11px;
  padding: 20px 24px;
}

.mob-right {
  display: flex;
  align-items: center;
}

/* OVERLAY */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#overlay-box {
  background: var(--ui-bg);
  border: 2px solid var(--gold);
  border-radius: 4px;
  padding: 48px 64px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  box-shadow: 0 0 60px rgba(255,215,0,0.2);
}

#overlay-title {
  font-family: var(--font-pixel);
  font-size: clamp(16px, 4vw, 28px);
  color: var(--gold);
  line-height: 1.5;
}

#overlay-sub {
  font-family: var(--font-vt);
  font-size: 22px;
  color: #aaa;
}

/* Game screen layout */
#screen-game {
  flex-direction: column;
  align-items: center;
  background: #0a0a1a;
  min-height: 100vh;
  justify-content: flex-start;
}

/* Responsive */
@media (max-width: 600px) {
  .controls-info { flex-direction: column; gap: 16px; }
  .lobby-box { padding: 24px; }
  #hud { padding: 6px 8px; }
  .hp-bar-wrap { width: 80px; }
}
