:root {
  /* Polices de caractères */
  --font-primary: 'Outfit', sans-serif;
  --font-retro: 'Press Start 2P', cursive;
  
  /* Couleurs de fond et panneaux */
  --color-bg-dark: #0a0a0f;
  --color-bg-panel: rgba(15, 15, 25, 0.75);
  
  /* Couleurs principales du thème et lueurs associées */
  --color-primary: #ff3e3e;
  --color-primary-glow: rgba(255, 62, 62, 0.4);
  --color-secondary: #00f0ff;
  --color-secondary-glow: rgba(0, 240, 255, 0.4);
  
  /* Couleurs spécifiques aux statistiques du HUD */
  --color-health: #ff3b30;
  --color-shield: #007aff;
  --color-ammo: #ffcc00;
  --color-grenade: #34c759;
  
  /* Couleurs de texte */
  --text-light: #f5f5f7;
  --text-muted: #8e8e93;
}

/* Réinitialisation de base pour garantir un rendu uniforme sur tous les navigateurs */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none; /* Empêche la sélection accidentelle de texte en cliquant rapidement */
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden; /* Empêche le défilement pour garder le jeu plein écran */
  background-color: var(--color-bg-dark);
  font-family: var(--font-primary);
  color: var(--text-light);
}

/* Conteneur absolu du Canvas de Three.js : il occupe 100% de la fenêtre en arrière-plan */
#canvas-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1; /* Derrière les interfaces utilisateur (HUD, Menus) */
}

/* ==================== PANNEAUX ET ÉCRANS DE MENU (OVERLAYS) ==================== */
/* Style de base pour les superpositions (Menu Principal, Game Over) qui couvrent tout l'écran */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* Dégradé radial sombre pour concentrer l'attention au centre */
  background: radial-gradient(circle, rgba(10, 10, 15, 0.8) 0%, rgba(5, 5, 8, 0.95) 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10; /* Toujours au-dessus du jeu et du HUD */
  backdrop-filter: blur(10px); /* Effet de flou esthétique moderne sur l'arrière-plan */
  transition: opacity 0.5s ease, visibility 0.5s;
}

/* Classe utilitaire pour cacher les écrans de manière fluide avec transition d'opacité */
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none; /* Désactive les clics sur l'écran caché */
}

/* Style de la boîte de contenu des menus */
.menu-content {
  background: var(--color-bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 40px var(--color-primary-glow);
  border-radius: 20px;
  padding: 40px;
  max-width: 650px;
  width: 90%;
  text-align: center;
  animation: modal-glow 4s infinite alternate; /* Effet de pulsation lumineuse subtile */
}

/* Animation de lueur pulsée autour du panneau du menu */
@keyframes modal-glow {
  0% { box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 62, 62, 0.2); }
  100% { box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 40px rgba(255, 62, 62, 0.5); }
}

.game-logo-img {
  width: 130px;
  height: 130px;
  border-radius: 24px;
  border: 3px solid var(--color-primary);
  box-shadow: 0 0 20px var(--color-primary-glow);
  margin-bottom: 20px;
  object-fit: cover;
}

.game-title {
  font-family: var(--font-retro);
  font-size: 2.2rem;
  color: var(--color-primary);
  text-shadow: 0 0 10px var(--color-primary-glow), 0 0 20px var(--color-primary-glow);
  margin-bottom: 5px;
  letter-spacing: 2px;
}

.game-over-title {
  font-family: var(--font-retro);
  font-size: 2.2rem;
  color: var(--color-primary);
  text-shadow: 0 0 10px var(--color-primary-glow);
  margin-bottom: 15px;
}

.subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 25px;
}

/* Conteneur d'informations sur la carte et les biomes */
.map-info-container {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 20px;
  text-align: left;
}

.map-info-container h3, .controls-info h3 {
  font-family: var(--font-primary);
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: var(--color-secondary);
  margin-bottom: 8px;
}

.map-desc {
  font-size: 0.9rem;
  line-height: 1.4;
  color: #d1d1d6;
}

/* Encadré listant les contrôles et mécaniques de jeu */
.controls-info {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 30px;
  text-align: left;
}

.controls-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
}

/* Représentation visuelle d'une touche de clavier physique */
.key {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
  font-weight: bold;
}

.aim-hint {
  color: var(--color-secondary);
  font-style: italic;
  font-weight: 600;
}

.safe-zone-hint {
  color: #ff9f0a;
  font-weight: 600;
}

/* ==================== STYLES DES BOUTONS ==================== */
.btn {
  font-family: var(--font-primary);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 1.5px;
  padding: 15px 40px;
  border-radius: 30px;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 5px;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 0 20px var(--color-primary-glow);
}

.btn-primary:hover {
  background: #ff5555;
  box-shadow: 0 0 30px var(--color-primary);
  transform: scale(1.03); /* Léger effet de zoom au survol */
}

.btn-secondary {
  background: transparent;
  color: var(--text-light);
  border: 2px solid var(--text-muted);
}

.btn-secondary:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

/* ==================== STYLES DU HUD (INTERFACE EN JEU) ==================== */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Permet aux clics de traverser le HUD pour viser/tirer dans la scène 3D */
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 25px;
}

#hud.hidden {
  display: none !important;
}

/* Ligne supérieure du HUD (Vague, Timer, Score, Indicateur de Biome) */
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* Boîte de statistiques individuelles du HUD */
.hud-stat-box {
  background: var(--color-bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 20px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  pointer-events: auto; /* Permet d'interagir avec ces éléments si nécessaire */
}

.hud-stat-box .label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 2px;
  margin-bottom: 2px;
}

.hud-stat-box .value {
  font-family: var(--font-retro);
  font-size: 1.2rem;
}

.text-red {
  color: var(--color-primary);
}

.text-cyan {
  color: var(--color-secondary);
}

/* Boîte contenant le compte à rebours de préparation diurne */
#timer-box {
  border-color: var(--color-secondary-glow);
  min-width: 160px;
  transition: opacity 0.3s;
}

#timer-box.hidden {
  opacity: 0;
}

/* Badge indiquant le biome actuel dans lequel évolue le joueur */
.hud-map-badge {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--color-secondary);
  box-shadow: 0 0 10px var(--color-secondary-glow);
  padding: 8px 18px;
  border-radius: 20px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 0.85rem;
}

/* Indicateurs alignés verticalement sur la droite (Cycle Jour/Nuit & Arme active) */
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: absolute;
  top: 100px;
  right: 25px;
  align-items: flex-end;
}

.time-badge, .weapon-badge {
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 1px;
}

/* Styles colorés pour le cycle de temps */
.time-badge.day {
  border-color: #ff9f0a;
  color: #ff9f0a;
  box-shadow: 0 0 10px rgba(255, 159, 10, 0.2);
}

.time-badge.night {
  border-color: #bf5af2;
  color: #bf5af2;
  box-shadow: 0 0 10px rgba(191, 90, 242, 0.2);
}

.weapon-badge {
  border-color: var(--color-ammo);
  color: var(--color-ammo);
}

/* Section inférieure du HUD (Barres d'état à gauche, Armes/compteurs à droite) */
.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

/* Bloc contenant les barres de Vie et de Bouclier */
.hud-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 15px 20px;
  border-radius: 16px;
  width: 320px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

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

.bar-icon {
  font-size: 1.2rem;
  width: 20px;
}

/* Fond de la barre de progression */
.bar-bg {
  flex-grow: 1;
  height: 14px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Remplissage dynamique des barres */
.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1); /* Transition souple des variations de vie/bouclier */
}

.health-color {
  background: linear-gradient(90deg, #ff2d55, #ff3b30);
  box-shadow: 0 0 10px rgba(255, 59, 48, 0.5);
}

.shield-color {
  background: linear-gradient(90deg, #007aff, #00c7fc);
  box-shadow: 0 0 10px rgba(0, 122, 255, 0.5);
}

.bar-val {
  font-family: var(--font-retro);
  font-size: 0.75rem;
  width: 70px;
  text-align: right;
}

/* Compteurs de munitions et de grenades */
.hud-weapons {
  display: flex;
  gap: 15px;
}

.ammo-box, .grenade-box {
  background: var(--color-bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 15px 20px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

.ammo-icon, .grenade-icon {
  font-size: 1.5rem;
  margin-bottom: 5px;
}

.ammo-val, .grenade-val {
  font-family: var(--font-retro);
  font-size: 1rem;
}

.ammo-box {
  border-color: rgba(255, 204, 0, 0.2);
}

.ammo-val {
  color: var(--color-ammo);
}

.grenade-box {
  border-color: rgba(52, 199, 89, 0.2);
  position: relative;
}

.grenade-val {
  color: var(--color-grenade);
}

.btn-key-hint {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ==================== ANNONCES DE VAGUES DE ZOMBIES ==================== */
.wave-alert-overlay {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  animation: alert-in-out 3s forwards;
}

.wave-alert-overlay h2 {
  font-family: var(--font-retro);
  font-size: 3rem;
  color: #fff;
  text-shadow: 0 0 20px var(--color-primary), 0 0 40px var(--color-primary);
  letter-spacing: 5px;
}

/* Animation d'entrée et de sortie grand format pour l'alerte de vague */
@keyframes alert-in-out {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  25% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  75% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* ==================== STATISTIQUES FINALES DE GAME OVER ==================== */
.stats-summary {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 12px;
  padding: 20px;
  margin: 25px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 8px;
}

.stat-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

/* Animation de pulsation générique */
.animate-pulse {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Positionnement explicite du Minimap pour éviter les superpositions */
#minimap {
  position: absolute;
  top: 110px;
  left: 25px;
  border-radius: 50%;
  background: rgba(10, 10, 15, 0.4);
  border: 1px solid rgba(0, 240, 255, 0.25);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  z-index: 6;
}

/* ==================== CONTRÔLES MOBILES ET TACTILES ==================== */
#mobile-controls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 8;
  pointer-events: none; /* Les clics traversent par défaut */
  display: none; /* Masqué par défaut sur ordinateur */
}

/* Affichage uniquement sur appareils tactiles ou écrans < 1024px */
@media (max-width: 1024px), (pointer: coarse) {
  #mobile-controls {
    display: block;
  }
}

/* Force l'affichage si la classe touch-device est active sur body */
body.touch-device #mobile-controls {
  display: block;
}

#joystick-zone {
  position: absolute;
  bottom: 30px;
  left: 30px;
  width: 150px;
  height: 150px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-base {
  width: 120px;
  height: 120px;
  background: rgba(10, 10, 15, 0.4);
  border: 2px solid rgba(0, 240, 255, 0.4);
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.15);
  backdrop-filter: blur(4px);
}

#joystick-knob {
  width: 50px;
  height: 50px;
  background: radial-gradient(circle, #00f0ff 0%, #007aff 100%);
  border: 2px solid #ffffff;
  border-radius: 50%;
  position: absolute;
  box-shadow: 0 0 15px #00f0ff;
  cursor: pointer;
  touch-action: none;
  transform: translate(0px, 0px);
}

#mobile-buttons-zone {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 200px;
  height: 200px;
  pointer-events: none; /* Les clics passent à travers la zone, mais pas les boutons */
}

.mobile-btn {
  position: absolute;
  border-radius: 50%;
  border: 2px solid;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-primary);
  font-weight: 800;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, background-color 0.1s ease, box-shadow 0.1s ease;
}

.mobile-btn:active {
  transform: scale(0.9);
}

.mobile-btn .btn-icon {
  font-size: 1.25rem;
}

.mobile-btn .btn-label {
  font-size: 0.5rem;
  opacity: 0.8;
  margin-top: 1px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Positionnement des boutons */
.shoot-btn {
  width: 76px;
  height: 76px;
  bottom: 15px;
  right: 15px;
  background: rgba(255, 62, 62, 0.25);
  border-color: rgba(255, 62, 62, 0.7);
  box-shadow: 0 0 15px rgba(255, 62, 62, 0.3);
}

.shoot-btn:active {
  background: rgba(255, 62, 62, 0.5);
  border-color: #ff3e3e;
  box-shadow: 0 0 25px rgba(255, 62, 62, 0.6);
}

.shoot-btn .btn-icon {
  font-size: 1.6rem;
}

.dash-btn {
  width: 58px;
  height: 58px;
  bottom: 15px;
  left: 10px;
  background: rgba(0, 240, 255, 0.25);
  border-color: rgba(0, 240, 255, 0.7);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.3);
}

.dash-btn:active {
  background: rgba(0, 240, 255, 0.5);
  border-color: #00f0ff;
  box-shadow: 0 0 25px rgba(0, 240, 255, 0.6);
}

.grenade-btn {
  width: 52px;
  height: 52px;
  top: 35px;
  right: 15px;
  background: rgba(52, 199, 89, 0.25);
  border-color: rgba(52, 199, 89, 0.7);
  box-shadow: 0 0 10px rgba(52, 199, 89, 0.3);
}

.grenade-btn:active {
  background: rgba(52, 199, 89, 0.5);
  border-color: #34c759;
  box-shadow: 0 0 20px rgba(52, 199, 89, 0.6);
}

.interact-btn {
  width: 52px;
  height: 52px;
  top: 45px;
  left: 45px;
  background: rgba(255, 204, 0, 0.25);
  border-color: rgba(255, 204, 0, 0.7);
  box-shadow: 0 0 10px rgba(255, 204, 0, 0.3);
}

.interact-btn:active {
  background: rgba(255, 204, 0, 0.5);
  border-color: #ffcc00;
  box-shadow: 0 0 20px rgba(255, 204, 0, 0.6);
}

/* Adaptations responsives et agencements pour terminaux mobiles tactiles */
@media (max-width: 1024px), (pointer: coarse) {
  .hud-bottom {
    position: absolute;
    top: 75px;
    left: 20px;
    right: 20px;
    width: calc(100% - 40px);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
  }
  
  .hud-bars {
    width: 170px !important;
    padding: 8px 12px !important;
  }
  
  .hud-weapons {
    flex-direction: row;
    gap: 8px;
  }
  
  .ammo-box, .grenade-box {
    min-width: 60px !important;
    padding: 6px 10px !important;
    height: 52px;
  }
  
  #minimap {
    top: 195px !important;
    left: 20px !important;
    width: 90px !important;
    height: 90px !important;
  }
  
  .hud-right {
    top: 135px !important;
    right: 20px !important;
    gap: 5px;
  }
}

body.touch-device .hud-bottom {
  position: absolute;
  top: 75px;
  left: 20px;
  right: 20px;
  width: calc(100% - 40px);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

body.touch-device .hud-bars {
  width: 170px !important;
  padding: 8px 12px !important;
}

body.touch-device .hud-weapons {
  flex-direction: row;
  gap: 8px;
}

body.touch-device .ammo-box, body.touch-device .grenade-box {
  min-width: 60px !important;
  padding: 6px 10px !important;
  height: 52px;
}

body.touch-device #minimap {
  top: 195px !important;
  left: 20px !important;
  width: 90px !important;
  height: 90px !important;
}

body.touch-device .hud-right {
  top: 135px !important;
  right: 20px !important;
  gap: 5px;
}

@media (max-width: 768px) {
  #hud {
    padding: 12px;
  }
  
  .hud-stat-box {
    min-width: 80px;
    padding: 4px 8px;
  }
  
  .hud-stat-box .value {
    font-size: 0.85rem;
  }
  
  .hud-stat-box .label {
    font-size: 0.65rem;
  }
  
  .bar-bg {
    height: 8px;
  }
  
  .bar-val {
    width: 35px;
    font-size: 0.6rem;
  }
  
  .ammo-icon, .grenade-icon {
    font-size: 0.95rem;
    margin-bottom: 2px;
  }
  
  .ammo-val, .grenade-val {
    font-size: 0.75rem;
  }
}

/* ==================== BOÎTE D'INTERACTION DU JOUEUR ==================== */
.interaction-prompt {
  position: absolute;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 10, 15, 0.75);
  border: 1px solid var(--color-secondary);
  padding: 10px 18px;
  border-radius: 8px;
  color: #fff;
  font-family: var(--font-retro);
  font-size: 0.65rem;
  text-align: center;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.25), inset 0 0 10px rgba(0, 240, 255, 0.15);
  backdrop-filter: blur(8px);
  pointer-events: none;
  z-index: 100;
  animation: prompt-pulse 1.5s infinite alternate;
  line-height: 1.5;
}

.interaction-prompt.hidden {
  display: none !important;
}

@keyframes prompt-pulse {
  from { box-shadow: 0 0 10px rgba(0, 240, 255, 0.2), inset 0 0 5px rgba(0, 240, 255, 0.1); border-color: rgba(0, 240, 255, 0.6); }
  to { box-shadow: 0 0 20px rgba(0, 240, 255, 0.4), inset 0 0 12px rgba(0, 240, 255, 0.25); border-color: rgba(0, 240, 255, 1); }
}
