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

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(180deg, #000 0%, #0f0f23 50%, #1a1a3e 100%);
  font-family: 'Courier New', monospace;
}

#game-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Stars ── */
.star {
  position: absolute;
  width: 2px; height: 2px;
  background: white;
  border-radius: 50%;
  animation: twinkle 2s infinite;
}
@keyframes twinkle {
  0%,100% { opacity: 0.3; }
  50%      { opacity: 1; }
}

/* ── Menu Screen ── */
#menu-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 300;
  background: linear-gradient(180deg, #000 0%, #0f0f23 60%, #1a1a3e 100%);
}
#menu-screen.hidden { display: none !important; }

.menu-title {
  font-size: clamp(2.2rem, 6vw, 4rem);
  color: #60a5fa;
  text-shadow: 0 0 20px #3b82f6, 0 0 40px #1d4ed8;
  letter-spacing: 6px;
  animation: titlePulse 2s ease-in-out infinite;
}
@keyframes titlePulse {
  0%,100% { text-shadow: 0 0 20px #3b82f6, 0 0 40px #1d4ed8; }
  50%     { text-shadow: 0 0 40px #60a5fa, 0 0 80px #3b82f6; }
}
.menu-sub {
  color: #6b7280;
  letter-spacing: 3px;
  font-size: 0.85rem;
  margin-top: -8px;
  margin-bottom: 8px;
}

#start-btn, #music-toggle-btn, #restart-btn, #menu-btn {
  background: transparent;
  border: 2px solid;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  transition: all 0.2s;
  letter-spacing: 2px;
}
#start-btn {
  border-color: #3b82f6;
  color: #93c5fd;
  padding: 14px 48px;
  font-size: 1.2rem;
}
#start-btn:hover { background: #3b82f6; color: white; box-shadow: 0 0 20px #3b82f6; }

#music-toggle-btn {
  border-color: #4b5563;
  color: #9ca3af;
  padding: 10px 28px;
  font-size: 0.9rem;
}
#music-toggle-btn:hover { border-color: #8b5cf6; color: #c4b5fd; }
#music-toggle-btn.music-off { border-color: #374151; color: #6b7280; }

.menu-controls {
  display: flex;
  gap: 24px;
  color: #4b5563;
  font-size: 0.78rem;
  margin-top: 8px;
  letter-spacing: 1px;
}

/* ── Ship ── */
#ship {
  position: absolute;
  width: 50px; height: 50px;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
  clip-path: polygon(50% 0%, 0% 100%, 50% 85%, 100% 100%);
  filter: drop-shadow(0 0 10px #3b82f6);
  z-index: 10;
  display: none;
}
#ship.active { display: block; }
#ship::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  background: #60a5fa;
  border-radius: 50%;
  bottom: -5px; left: 50%;
  transform: translateX(-50%);
  filter: blur(5px);
  animation: engineGlow 0.3s infinite;
}
@keyframes engineGlow {
  0%,100% { opacity:0.5; transform: translateX(-50%) scale(1); }
  50%      { opacity:1;   transform: translateX(-50%) scale(1.3); }
}
#ship.powerup-rapid {
  filter: drop-shadow(0 0 20px #fbbf24) drop-shadow(0 0 30px #f59e0b);
}
#ship.powerup-spread {
  filter: drop-shadow(0 0 20px #10b981) drop-shadow(0 0 30px #059669);
}
#ship.powerup-shield {
  filter: drop-shadow(0 0 20px #8b5cf6) drop-shadow(0 0 30px #a78bfa);
}

/* Shield ring around ship */
#shield-ring {
  position: absolute;
  width: 70px; height: 70px;
  border: 3px solid #a78bfa;
  border-radius: 50%;
  z-index: 9;
  box-shadow: 0 0 12px #8b5cf6, inset 0 0 12px rgba(139,92,246,0.3);
  animation: shieldSpin 2s linear infinite;
  pointer-events: none;
}
@keyframes shieldSpin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ── Bullets ── */
.bullet {
  position: absolute;
  width: 4px; height: 16px;
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
  border-radius: 2px;
  box-shadow: 0 0 10px #fbbf24, 0 0 20px #f59e0b;
  animation: bulletMove 0.9s linear forwards;
}
.bullet.spread-l { animation: bulletMoveL 0.9s linear forwards; }
.bullet.spread-r { animation: bulletMoveR 0.9s linear forwards; }
@keyframes bulletMove  { to { transform: translateY(-110vh); } }
@keyframes bulletMoveL { to { transform: translateY(-110vh) translateX(-80px); } }
@keyframes bulletMoveR { to { transform: translateY(-110vh) translateX(80px); } }

/* Enemy bullet */
.enemy-bullet {
  position: absolute;
  width: 6px; height: 6px;
  background: #f97316;
  border-radius: 50%;
  box-shadow: 0 0 8px #f97316;
  animation: enemyBulletMove 1.5s linear forwards;
  z-index: 5;
}
@keyframes enemyBulletMove { to { transform: translateY(120vh); } }

/* ── Enemy: Basic (red, fast) ── */
.enemy {
  position: absolute;
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #ef4444 0%, #991b1b 100%);
  clip-path: polygon(50% 100%, 0% 0%, 50% 15%, 100% 0%);
  filter: drop-shadow(0 0 8px #ef4444);
  animation: enemyMove 3s linear forwards;
  z-index: 6;
}
@keyframes enemyMove { to { transform: translateY(120vh); } }

/* ── Enemy: Zigzagger (green, weaves) ── */
.enemy-zigzag {
  position: absolute;
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #10b981 0%, #065f46 100%);
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
  filter: drop-shadow(0 0 8px #10b981);
  animation: zigzagMove 2.5s linear forwards;
  z-index: 6;
}
@keyframes zigzagMove {
  0%   { transform: translateY(0)      translateX(0); }
  20%  { transform: translateY(20vh)   translateX(60px); }
  40%  { transform: translateY(40vh)   translateX(-60px); }
  60%  { transform: translateY(60vh)   translateX(60px); }
  80%  { transform: translateY(80vh)   translateX(-60px); }
  100% { transform: translateY(120vh)  translateX(0); }
}

/* ── Enemy: Bomber (orange, large, slow) ── */
.enemy-bomber {
  position: absolute;
  width: 58px; height: 52px;
  background: radial-gradient(circle at 40% 40%, #fb923c, #9a3412);
  clip-path: polygon(50% 100%, 10% 70%, 0% 20%, 30% 0%, 70% 0%, 100% 20%, 90% 70%);
  filter: drop-shadow(0 0 12px #f97316);
  animation: bomberMove 5s linear forwards;
  z-index: 6;
}
@keyframes bomberMove { to { transform: translateY(120vh); } }

/* Generic small HP bar (basic & zigzag) */
.enemy-hp-wrap {
  position: absolute;
  top: -7px; left: 50%;
  transform: translateX(-50%);
  width: 34px; height: 4px;
  background: #1f2937;
  border-radius: 2px;
  overflow: hidden;
  pointer-events: none;
}
.enemy-hp-fill {
  height: 100%;
  width: 100%;
  background: #22c55e;
  border-radius: 2px;
  transition: width 0.1s;
}
.enemy-bomber .enemy-hp-wrap { width: 50px; }
.enemy-bomber .enemy-hp-fill { background: #f97316; }

/* Death animation */
.enemy.hit      { animation: explodeBasic  0.45s ease-out forwards; }
.enemy-zigzag.hit { animation: explodeZigzag 0.45s ease-out forwards; }
.enemy-bomber.hit { animation: explodeBomber 0.55s ease-out forwards; }

@keyframes explodeBasic {
  0%   { transform: scale(1)   rotate(0deg);   opacity: 1;   filter: brightness(1); }
  25%  { transform: scale(2.2) rotate(30deg);  opacity: 0.9; filter: brightness(4); }
  60%  { transform: scale(1.5) rotate(80deg);  opacity: 0.5; filter: brightness(2); }
  100% { transform: scale(0)   rotate(140deg); opacity: 0; }
}
@keyframes explodeZigzag {
  0%   { transform: scale(1)   rotate(0deg);    opacity: 1;   filter: brightness(1); }
  25%  { transform: scale(2.4) rotate(-50deg);  opacity: 0.9; filter: brightness(5); }
  60%  { transform: scale(1.6) rotate(-110deg); opacity: 0.4; filter: brightness(3); }
  100% { transform: scale(0)   rotate(-200deg); opacity: 0; }
}
@keyframes explodeBomber {
  0%   { transform: scale(1)   rotate(0deg);  opacity: 1;   filter: brightness(1); }
  20%  { transform: scale(3.0) rotate(20deg); opacity: 1;   filter: brightness(6); }
  55%  { transform: scale(2.0) rotate(50deg); opacity: 0.6; filter: brightness(3); }
  100% { transform: scale(0)   rotate(90deg); opacity: 0; }
}

/* ── Explosions ── */
.explosion {
  position: absolute;
  width: 60px; height: 60px;
  background: radial-gradient(circle, #fbbf24 0%, #f59e0b 50%, transparent 70%);
  border-radius: 50%;
  animation: explosionAnim 0.5s ease-out forwards;
  pointer-events: none;
  z-index: 7;
}
.explosion.big {
  width: 100px; height: 100px;
}
@keyframes explosionAnim {
  0%   { transform: scale(0); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

/* ── Powerup drops ── */
.powerup-drop {
  position: absolute;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  border: 2px solid rgba(255,255,255,0.4);
  animation: dropFall 9s linear forwards, dropPulse 0.6s ease-in-out infinite;
  z-index: 8;
  cursor: default;
}
.powerup-drop.rapid  { background: rgba(251,191,36,0.25); box-shadow: 0 0 12px #fbbf24; border-color: #fbbf24; }
.powerup-drop.spread { background: rgba(16,185,129,0.25); box-shadow: 0 0 12px #10b981; border-color: #10b981; }
.powerup-drop.shield { background: rgba(139,92,246,0.25); box-shadow: 0 0 12px #8b5cf6; border-color: #8b5cf6; }
.powerup-drop.nuke   { background: rgba(239,68,68,0.25);  box-shadow: 0 0 12px #ef4444; border-color: #ef4444; }
/* dropFall uses transform; dropPulse uses filter to avoid conflict */
@keyframes dropFall  { to { transform: translateY(120vh); } }
@keyframes dropPulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.7); } }

/* ── Nuke flash ── */
#nuke-flash {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.1s;
}
#nuke-flash.boom { opacity: 0.85; }

/* ── HUD ── */
#hud {
  position: absolute;
  top: 20px; left: 20px;
  color: white;
  font-size: 18px;
  z-index: 100;
  text-shadow: 0 0 10px rgba(59,130,246,0.8);
  display: none;
}
#hud.active { display: block; }
#score, #health, #high-score-hud, #game-timer { margin-bottom: 8px; }
#high-score-hud { color: #fbbf24; font-size: 14px; }
#game-timer     { color: #a3e635; font-size: 14px; letter-spacing: 1px; }

#powerup-indicator {
  position: absolute;
  top: 20px; right: 20px;
  padding: 10px 20px;
  border-radius: 6px;
  color: white;
  font-size: 14px;
  display: none;
  z-index: 100;
  animation: pulse 0.5s infinite;
}
#powerup-indicator.show { display: block; }
#powerup-indicator.rapid  { background: rgba(251,191,36,0.9); color: #000; }
#powerup-indicator.spread { background: rgba(16,185,129,0.9); }
#powerup-indicator.shield { background: rgba(139,92,246,0.9); }

@keyframes pulse {
  0%,100% { opacity:1; transform: scale(1); }
  50%      { opacity:0.8; transform: scale(1.04); }
}

/* ── Game Over ── */
#game-over {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.92);
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  color: white;
  display: none;
  z-index: 200;
  border: 2px solid #8b5cf6;
  box-shadow: 0 0 40px rgba(139,92,246,0.5);
  min-width: 280px;
}
#game-over.show { display: block; animation: fadeIn 0.5s; }
@keyframes fadeIn {
  from { opacity:0; transform: translate(-50%,-50%) scale(0.8); }
  to   { opacity:1; transform: translate(-50%,-50%) scale(1); }
}
#game-over h1  { font-size: 2.8rem; margin-bottom: 16px; color: #ef4444; }
#final-score   { font-size: 1.8rem; margin-bottom: 8px; color: #fbbf24; }
#high-score-display { font-size: 1rem; color: #a78bfa; margin-bottom: 24px; }
#restart-btn, #menu-btn {
  padding: 13px 32px;
  font-size: 1rem;
  margin: 6px;
}
#restart-btn { border-color: #3b82f6; color: #93c5fd; }
#restart-btn:hover { background: #3b82f6; color: white; box-shadow: 0 0 20px #3b82f6; }
#menu-btn { border-color: #4b5563; color: #9ca3af; }
#menu-btn:hover { border-color: #8b5cf6; color: #c4b5fd; }

/* ── Laser bar ── */
#laser-bar-wrap {
  position: absolute;
  top: 20px; right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
#laser-bar-label {
  color: #60a5fa;
  font-size: 10px;
  letter-spacing: 2px;
  text-shadow: 0 0 8px #3b82f6;
}
#laser-bar-track {
  width: 14px; height: 130px;
  background: rgba(255,255,255,0.07);
  border: 1px solid #1d4ed8;
  border-radius: 7px;
  overflow: hidden;
  position: relative;
}
#laser-bar-fill {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%; height: 0%;
  background: linear-gradient(to top, #1d4ed8, #60a5fa);
  border-radius: 7px;
  transition: height 0.12s ease-out;
}
#laser-bar-hint {
  color: #374151;
  font-size: 11px;
  letter-spacing: 1px;
}
/* Ready state — bar is full */
#laser-bar-wrap.ready #laser-bar-fill {
  background: linear-gradient(to top, #3b82f6, #bfdbfe);
  animation: laserReady 0.5s ease-in-out infinite;
}
#laser-bar-wrap.ready #laser-bar-hint {
  color: #93c5fd;
  animation: pulse 0.5s infinite;
}
#laser-bar-wrap.active #laser-bar-fill {
  background: linear-gradient(to top, #06b6d4, #e0f2fe);
}
@keyframes laserReady {
  0%,100% { box-shadow: inset 0 0 6px #3b82f6; }
  50%      { box-shadow: inset 0 0 18px #93c5fd; }
}

/* ── Laser beam ── */
#laser-beam {
  position: absolute;
  width: 8px;
  top: 0; bottom: 130px;
  pointer-events: none;
  z-index: 15;
  background: linear-gradient(to bottom, transparent 0%, #93c5fd 30%, #60a5fa 70%, #3b82f6 100%);
  box-shadow: 0 0 12px #60a5fa, 0 0 28px #3b82f6, 0 0 50px rgba(59,130,246,0.4);
  border-radius: 4px;
  animation: beamFlicker 0.07s ease-in-out infinite;
}
@keyframes beamFlicker {
  0%,100% { opacity: 1;    width: 8px; }
  50%     { opacity: 0.88; width: 10px; }
}

@media (max-width: 768px) {
  #ship { width:40px; height:40px; bottom:60px; }
  .enemy { width:35px; height:35px; }
  .enemy-zigzag { width:30px; height:30px; }
  .enemy-bomber { width:48px; height:44px; }
  #hud { font-size:15px; }
}
