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

body {
  background: #000;
  color: #fff;
  font-family: 'Rajdhani', sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

#scene-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

canvas {
  display: block;
}

.hidden { display: none !important; }

/* HUD */
#hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* Immersive scanline */
#hud-scanline {
  position: absolute;
  left: 0; width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(0,200,255,0.06), transparent);
  pointer-events: none;
  z-index: 1;
  top: 0;
}

/* Critical HP overlay */
#critical-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255,0,0,0.35) 100%);
  display: none;
  z-index: 8;
  animation: criticalPulse 1s ease infinite alternate;
}

@keyframes criticalPulse {
  from { opacity: 0.2; }
  to { opacity: 0.5; }
}

/* Corner brackets */
.hud-bracket {
  position: absolute;
  width: 30px; height: 30px;
  pointer-events: none;
}
.hud-bracket.top-left {
  top: 8px; left: 8px;
  border-top: 2px solid rgba(0,180,255,0.3);
  border-left: 2px solid rgba(0,180,255,0.3);
}
.hud-bracket.top-right {
  top: 8px; right: 8px;
  border-top: 2px solid rgba(0,180,255,0.3);
  border-right: 2px solid rgba(0,180,255,0.3);
}
.hud-bracket.bottom-left {
  bottom: 50px; left: 8px;
  border-bottom: 2px solid rgba(0,180,255,0.3);
  border-left: 2px solid rgba(0,180,255,0.3);
}
.hud-bracket.bottom-right {
  bottom: 50px; right: 8px;
  border-bottom: 2px solid rgba(0,180,255,0.3);
  border-right: 2px solid rgba(0,180,255,0.3);
}

/* HUD panels */
.hud-panel {
  background: rgba(0, 10, 30, 0.5);
  border: 1px solid rgba(0, 120, 255, 0.15);
  border-radius: 4px;
  padding: 8px 10px;
  backdrop-filter: blur(2px);
}

.hud-panel-header {
  font-family: 'Orbitron', sans-serif;
  font-size: 8px;
  letter-spacing: 3px;
  color: rgba(0, 180, 255, 0.5);
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(0, 100, 200, 0.15);
  padding-bottom: 3px;
}

.hud-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  padding-top: 3px;
}

.hud-stat-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 8px;
  letter-spacing: 2px;
  color: #567;
}

.hud-stat-val {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #8cf;
}

#hud-top-left {
  position: absolute;
  top: 16px; left: 16px;
}

.bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.bar-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  width: 50px;
  color: #8af;
}

.bar-bg {
  width: 140px;
  height: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  transition: width 0.3s ease;
  border-radius: 1px;
}

.bar-fill.health {
  background: linear-gradient(90deg, #f44, #4f4);
  width: 100%;
}

.bar-fill.shield {
  background: linear-gradient(90deg, #2af, #0ff);
  width: 100%;
}

.bar-value {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  min-width: 28px;
  text-align: right;
  color: #cdf;
}

#hud-top-center {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

#wave-indicator {
  font-family: 'Orbitron', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #adf;
  text-shadow: 0 0 12px #08f;
}

#combo-display {
  margin-top: 4px;
}

#combo-text {
  font-family: 'Orbitron', sans-serif;
  font-size: 18px;
  font-weight: 900;
  color: #ff0;
  text-shadow: 0 0 16px #fa0, 0 0 32px #f80;
  animation: comboPulse 0.4s ease infinite alternate;
}

@keyframes comboPulse {
  from { transform: scale(1); }
  to { transform: scale(1.15); }
}

#hud-top-right {
  position: absolute;
  top: 16px; right: 16px;
  text-align: right;
}

#score-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #8af;
}

#score-display {
  font-family: 'Orbitron', sans-serif;
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px #08f;
}

#hud-bottom-left {
  position: absolute;
  bottom: 50px; left: 16px;
}

/* Radar / Minimap */
#hud-bottom-right {
  position: absolute;
  bottom: 50px; right: 16px;
  text-align: center;
}

#radar-canvas {
  border-radius: 50%;
  border: 1px solid rgba(0, 150, 255, 0.3);
  box-shadow: 0 0 15px rgba(0, 100, 255, 0.15), inset 0 0 10px rgba(0, 50, 150, 0.1);
}

.radar-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 8px;
  letter-spacing: 3px;
  color: rgba(0, 180, 255, 0.4);
  margin-top: 4px;
}

/* Threat meter */
#threat-meter {
  margin-top: 8px;
  text-align: right;
}

.threat-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 8px;
  letter-spacing: 2px;
  color: #567;
  margin-bottom: 2px;
}

.threat-bar-bg {
  width: 120px;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-left: auto;
}

.threat-bar-fill {
  height: 100%;
  width: 0%;
  background: #00aaff;
  transition: width 0.5s ease, background 0.5s ease;
  border-radius: 1px;
}

.threat-val {
  font-family: 'Orbitron', sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #00aaff;
  margin-top: 2px;
  transition: color 0.5s ease;
}

/* Warnings */
#hud-warnings {
  position: absolute;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.hud-warning {
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 4px 16px;
  border-radius: 3px;
  animation: warningBlink 0.5s ease infinite alternate;
}

#missile-warning {
  color: #ff6600;
  background: rgba(255, 80, 0, 0.12);
  border: 1px solid rgba(255, 100, 0, 0.4);
  text-shadow: 0 0 10px rgba(255, 80, 0, 0.5);
}

#laser-warning {
  color: #ff0044;
  background: rgba(255, 0, 50, 0.12);
  border: 1px solid rgba(255, 0, 50, 0.4);
  text-shadow: 0 0 10px rgba(255, 0, 50, 0.5);
}

@keyframes warningBlink {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

#weapon-display {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.weapon-slot {
  padding: 4px 10px;
  background: rgba(0,100,255,0.1);
  border: 1px solid rgba(0,150,255,0.3);
  border-radius: 4px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.weapon-slot.active {
  border-color: #0af;
  background: rgba(0,170,255,0.2);
  box-shadow: 0 0 12px rgba(0,170,255,0.3);
}

.weapon-icon {
  font-size: 18px;
  color: #0ff;
}

.weapon-name {
  font-family: 'Orbitron', sans-serif;
  font-size: 8px;
  letter-spacing: 1px;
  color: #8cf;
}

.cooldown-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 3px;
  background: #f80;
  width: 0%;
  transition: width 0.1s linear;
}

#weapon-slots {
  display: flex;
  gap: 4px;
}

.slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  color: #68a;
}

.slot.active {
  border-color: #0af;
  color: #0ff;
  background: rgba(0,170,255,0.15);
}

/* Boss HUD */
#boss-hud {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: min(500px, 80vw);
  text-align: center;
}

#boss-name {
  font-family: 'Orbitron', sans-serif;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 4px;
  color: #f44;
  text-shadow: 0 0 20px #f00, 0 0 40px #a00;
  margin-bottom: 6px;
  animation: bossNameGlow 1.5s ease infinite alternate;
}

@keyframes bossNameGlow {
  from { text-shadow: 0 0 20px #f00, 0 0 40px #a00; }
  to { text-shadow: 0 0 30px #f44, 0 0 60px #f00; }
}

.boss-bar-bg {
  width: 100%;
  height: 18px;
  background: rgba(255,0,0,0.1);
  border: 2px solid rgba(255,0,0,0.5);
  border-radius: 3px;
  overflow: hidden;
}

.boss-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #f00, #f60, #f00);
  background-size: 200% 100%;
  animation: bossBarAnim 2s linear infinite;
  transition: width 0.3s ease;
}

@keyframes bossBarAnim {
  from { background-position: 0% 0%; }
  to { background-position: 200% 0%; }
}

/* Damage flash */
#damage-flash {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 9;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(255,0,0,0.5) 100%);
  animation: flashFade 0.3s ease forwards;
}

@keyframes flashFade {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Title Screen */
#title-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

#title-bg-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at 50% 40%, rgba(0,40,120,0.4), transparent 70%),
              linear-gradient(180deg, rgba(0,0,30,0.8), rgba(0,0,0,0.95));
}

#title-content {
  position: relative;
  text-align: center;
  z-index: 1;
}

#game-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(48px, 12vw, 96px);
  font-weight: 900;
  line-height: 0.95;
  color: #fff;
  text-shadow: 0 0 40px #08f, 0 0 80px #04a, 0 2px 0 #024;
  letter-spacing: 8px;
  margin-bottom: 8px;
  animation: titleGlow 3s ease infinite alternate;
}

@keyframes titleGlow {
  from { text-shadow: 0 0 40px #08f, 0 0 80px #04a, 0 2px 0 #024; }
  to { text-shadow: 0 0 60px #0af, 0 0 120px #06f, 0 2px 0 #024; }
}

#title-subtitle {
  font-family: 'Orbitron', sans-serif;
  font-size: 14px;
  letter-spacing: 8px;
  color: #48a;
  margin-bottom: 32px;
}

#highscore-display {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  color: #fa0;
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.title-btn {
  display: block;
  margin: 10px auto;
  padding: 12px 40px;
  font-family: 'Orbitron', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #adf;
  background: rgba(0,100,255,0.08);
  border: 2px solid rgba(0,150,255,0.4);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 240px;
}

.title-btn:hover {
  background: rgba(0,150,255,0.2);
  border-color: #0af;
  color: #fff;
  box-shadow: 0 0 20px rgba(0,170,255,0.3);
}

.title-btn.primary {
  border-color: #0af;
  color: #fff;
  background: rgba(0,150,255,0.15);
  animation: btnPulse 2s ease infinite;
}

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(0,170,255,0.2); }
  50% { box-shadow: 0 0 25px rgba(0,170,255,0.5); }
}

.title-btn.small {
  padding: 8px 30px;
  font-size: 11px;
  min-width: 200px;
}

/* Overlay screens */
.overlay-bg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,10,0.85);
  backdrop-filter: blur(4px);
}

.overlay-content {
  position: relative;
  z-index: 1;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
  padding: 30px;
}

.overlay-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 6px;
  text-align: center;
  margin-bottom: 20px;
  color: #fff;
  text-shadow: 0 0 30px #08f;
}

#loadout-screen, #howto-screen, #gameover-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}

#upgrade-points-display {
  text-align: center;
  margin-bottom: 16px;
}

.points-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  color: #8af;
}

#points-value {
  font-family: 'Orbitron', sans-serif;
  font-size: 24px;
  font-weight: 900;
  color: #fa0;
  text-shadow: 0 0 15px #f80;
  margin-left: 8px;
}

.loadout-section {
  margin-bottom: 16px;
}

.loadout-section h3 {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  letter-spacing: 3px;
  color: #68a;
  margin-bottom: 8px;
}

.card-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.weapon-card {
  width: 150px;
  padding: 12px;
  background: rgba(0,50,120,0.15);
  border: 1px solid rgba(0,100,255,0.2);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  pointer-events: all;
}

.weapon-card:hover {
  border-color: #08f;
  background: rgba(0,80,180,0.2);
}

.weapon-card.selected {
  border-color: #0ff;
  background: rgba(0,150,255,0.2);
  box-shadow: 0 0 15px rgba(0,200,255,0.3);
}

.weapon-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.card-icon {
  font-size: 28px;
  margin-bottom: 4px;
}

.card-name {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #adf;
  margin-bottom: 4px;
}

.card-desc {
  font-size: 11px;
  color: #68a;
  margin-bottom: 6px;
  line-height: 1.3;
}

.stat-bar-mini {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
  font-size: 9px;
  color: #579;
}

.stat-bar-mini .stat-fill-bg {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}

.stat-bar-mini .stat-fill {
  height: 100%;
  background: #0af;
  border-radius: 2px;
}

.card-cost {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  color: #fa0;
  margin-top: 4px;
}

/* How to play */
.howto-body {
  text-align: center;
  margin-bottom: 20px;
}

.control-row {
  margin: 8px 0;
  font-size: 15px;
  color: #8af;
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(0,100,255,0.15);
  border: 1px solid rgba(0,150,255,0.4);
  border-radius: 3px;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  color: #0ff;
  margin: 0 2px;
}

.howto-body p {
  margin-top: 16px;
  color: #68a;
  font-size: 13px;
}

/* Game Over */
#gameover-title {
  color: #f44;
  text-shadow: 0 0 30px #f00;
}

#gameover-title.victory {
  color: #0f0;
  text-shadow: 0 0 30px #0f0;
}

#final-score-display {
  text-align: center;
  font-family: 'Orbitron', sans-serif;
  font-size: 36px;
  font-weight: 900;
  color: #fa0;
  text-shadow: 0 0 20px #f80;
  margin-bottom: 16px;
}

#score-breakdown {
  text-align: center;
  font-size: 14px;
  color: #68a;
  margin-bottom: 20px;
  line-height: 1.8;
}

/* Wave Announce */
#wave-announce {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  pointer-events: none;
}

#wave-announce-text {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(32px, 8vw, 64px);
  font-weight: 900;
  letter-spacing: 6px;
  color: #fff;
  text-shadow: 0 0 40px #08f, 0 0 80px #04a;
  animation: waveAnnounce 2.5s ease forwards;
}

@keyframes waveAnnounce {
  0% { opacity: 0; transform: scale(0.5); }
  20% { opacity: 1; transform: scale(1.1); }
  40% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.2) translateY(-20px); }
}

/* Touch Controls */
#touch-controls {
  position: fixed;
  bottom: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 15;
  pointer-events: none;
}

#touch-move-zone {
  position: absolute;
  bottom: 0; left: 0;
  width: 50%; height: 100%;
  pointer-events: all;
}

.touch-btn {
  position: absolute;
  pointer-events: all;
  width: 70px; height: 70px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #0ff;
  background: rgba(0,150,255,0.15);
  border: 2px solid rgba(0,200,255,0.4);
}

#touch-fire-btn {
  right: 20px;
  bottom: 80px;
}

#touch-secondary-btn {
  right: 100px;
  bottom: 40px;
  width: 55px; height: 55px;
  font-size: 9px;
  border-color: rgba(255,150,0,0.5);
  color: #fa0;
  background: rgba(255,120,0,0.1);
}

.mobile-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .mobile-only { display: block; }
}

/* Footer */
#game-footer {
  position: fixed;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 11px;
}

#game-footer a {
  color: #345;
  text-decoration: none;
  font-family: 'Rajdhani', sans-serif;
}

#game-footer a:hover {
  color: #08f;
}

/* Scrollbar */
.overlay-content::-webkit-scrollbar { width: 4px; }
.overlay-content::-webkit-scrollbar-track { background: transparent; }
.overlay-content::-webkit-scrollbar-thumb { background: #08f; border-radius: 2px; }