/* =========================================
   STYLES GLOBAUX & RESET
   ========================================= */
html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #000;
  font-family: system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  width: 100%;
  height: 100%;
  height: 100dvh; /* suit la hauteur réelle sur mobile, barre d'adresse comprise */
}

canvas { display: block; }

/* =========================================
   INTERFACE EN JEU (HUD)
   ========================================= */
.ui-container {
  position: fixed; color: #fff; pointer-events: none; z-index: 10;
  top: calc(15px + env(safe-area-inset-top));
  left: calc(15px + env(safe-area-inset-left));
  max-width: 60vw;
}

#score-display {
  font-size: clamp(20px, 4vw, 28px); font-weight: bold;
  letter-spacing: 0.1em; text-transform: uppercase;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.8); transition: color 0.2s;
}

#timer-display {
  margin-top: 5px; font-size: clamp(16px, 3vw, 20px);
  color: #ffaa00; font-weight: bold; letter-spacing: 2px;
}

#chrono-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #ffffff; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

#level-display {
  margin-top: 5px; font-size: clamp(15px, 3vw, 19px);
  color: #ffdd44; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 220, 60, 0.8);
}

#enemies-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #ff8866; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(255, 120, 80, 0.7);
}

#boss-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #ff88ff; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 100, 255, 0.8);
}

#missile-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #ffcc44; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(255, 170, 50, 0.7);
}

#ammo-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #66ccff; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(80, 180, 255, 0.7);
}

#hits-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #88ff88; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(120, 255, 120, 0.7);
}

/* État du dash d'esquive (touche Espace) : prêt / actif / en recharge */
#throttle-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #88ddff; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(120, 200, 255, 0.7);
}

#dash-display {
  margin-top: 5px; font-size: clamp(14px, 2.8vw, 18px);
  color: #66ffdd; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 8px rgba(100, 255, 220, 0.7);
}

/* Flash rouge plein écran quand le joueur est touché par un kamikaze */
#damage-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 20; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(255,0,0,0) 40%, rgba(200,0,0,0.55) 100%);
}

/* Halo cyan pendant l'invulnérabilité du dash : on voit qu'on est intouchable */
#dash-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 19; opacity: 0;
  transition: opacity 0.08s linear;
  background: radial-gradient(ellipse at center, rgba(0,255,220,0) 45%, rgba(0,230,255,0.45) 100%);
}

/* Aide clavier : titre et rappel souris */
.instructions .kbd-title { color: #66ffdd; letter-spacing: 1px; }
.instructions .mouse-note { display: block; margin-top: 6px; color: #8899aa; font-size: 0.9em; }

/* Bandeau d'information affiché quand la visée libre remplace le curseur capturé */
#aim-notice {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  top: calc(18px + env(safe-area-inset-top));
  max-width: min(90vw, 560px); box-sizing: border-box;
  padding: 10px 16px; border-radius: 8px; text-align: center;
  background: rgba(10, 20, 35, 0.92); border: 1px solid rgba(0, 170, 255, 0.6);
  color: #dbeeff; font-size: clamp(11px, 2.4vw, 14px); line-height: 1.5;
  box-shadow: 0 0 18px rgba(0, 170, 255, 0.25); pointer-events: none;
}
#aim-notice.hidden { display: none; }

.instructions {
  margin-top: 10px; font-size: clamp(11px, 2.5vw, 14px); color: #ccc;
  line-height: 1.5; background: rgba(0, 0, 0, 0.6); padding: 10px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.2);
}

.enemy-text { color: #ff4444; font-weight: bold; }
.civilian-text { color: #44ffaa; font-weight: bold; }

/* Affichage piloté par la classe `touch-mode` posée sur <body> par le JS dès qu'un
   doigt touche l'écran. On n'utilise plus de media query seule : elle classait mal
   les PC portables tactiles, qui doivent voir l'aide clavier/souris. */
.mobile-only, .touch-only { display: none; }
body.touch-mode .desktop-only { display: none; }
body.touch-mode .mobile-only { display: block; }
body.touch-mode .touch-only { display: block; }

/* =========================================
   COMMANDES TACTILES
   ========================================= */
#touch-controls {
  position: fixed; inset: 0; z-index: 14; pointer-events: none;
}

/* Joystick virtuel : il apparaît sous le doigt, à gauche de l'écran */
#joystick {
  position: absolute; width: 132px; height: 132px; margin: -66px 0 0 -66px;
  border-radius: 50%; opacity: 0; transition: opacity 0.15s ease;
  background: radial-gradient(circle, rgba(0,170,255,0.10) 0%, rgba(0,170,255,0.04) 70%, transparent 71%);
  border: 2px solid rgba(0, 200, 255, 0.4);
  box-shadow: 0 0 18px rgba(0, 170, 255, 0.25);
}
#joystick-knob {
  position: absolute; top: 50%; left: 50%; width: 54px; height: 54px;
  margin: 0; border-radius: 50%; transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(120,230,255,0.85) 0%, rgba(0,170,255,0.5) 100%);
  border: 2px solid rgba(200, 245, 255, 0.9);
  box-shadow: 0 0 16px rgba(0, 200, 255, 0.7);
}

/* Boutons d'action, en bas à droite, sous le pouce droit */
#touch-buttons {
  position: absolute; display: flex; align-items: flex-end; gap: 14px;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.touch-btn {
  pointer-events: auto; -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-size: 26px; padding: 0;
  touch-action: none; transition: transform 0.08s ease, filter 0.08s ease;
}
.touch-btn:active { transform: scale(0.9); filter: brightness(1.5); }
.touch-btn.fire {
  width: 92px; height: 92px; font-size: 36px;
  background: rgba(255, 60, 40, 0.28); border: 2px solid rgba(255, 120, 80, 0.85);
  box-shadow: 0 0 20px rgba(255, 80, 40, 0.4);
}
.touch-btn.mega {
  width: 66px; height: 66px;
  background: rgba(255, 150, 20, 0.28); border: 2px solid rgba(255, 190, 70, 0.85);
}
.touch-btn.dash {
  width: 66px; height: 66px;
  background: rgba(0, 220, 200, 0.22); border: 2px solid rgba(100, 255, 220, 0.85);
}

/* Écrans étroits ou peu hauts : HUD compacté pour ne pas manger la zone de jeu */
@media (max-width: 620px), (max-height: 480px) {
  .ui-container { top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); }
  #score-display { font-size: 18px; }
  #timer-display, #chrono-display, #level-display, #enemies-display, #boss-display,
  #missile-display, #ammo-display, #hits-display, #throttle-display, #dash-display {
    font-size: 12px; margin-top: 2px;
  }
  .instructions { font-size: 10px; padding: 6px; line-height: 1.35; margin-top: 6px; }
}

/* =========================================
   VISEUR CENTRAL
   ========================================= */
.crosshair {
  position: fixed; top: 50%; left: 50%; width: 24px; height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.4); border-radius: 50%;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 10;
}
.crosshair::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 4px; height: 4px; background: white; border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* =========================================
   RADAR — emplacement des ennemis autour du joueur
   ========================================= */
#radar-container {
  position: fixed; z-index: 10; pointer-events: none;
  right: calc(16px + env(safe-area-inset-right));
  top: calc(15px + env(safe-area-inset-top));
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#radar-label {
  font-size: 11px; letter-spacing: 3px; color: #66ffdd; font-weight: bold;
  text-shadow: 0 0 6px rgba(100, 255, 220, 0.7);
}
#radar {
  position: relative; width: 116px; height: 116px; border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 45, 25, 0.55) 0%, rgba(0, 15, 10, 0.8) 100%);
  border: 2px solid rgba(68, 255, 170, 0.5);
  box-shadow: 0 0 16px rgba(0, 255, 140, 0.25), inset 0 0 20px rgba(0, 255, 140, 0.08);
  overflow: hidden;
}
#radar::before, #radar::after {
  content: ''; position: absolute; background: rgba(102, 255, 221, 0.18);
}
#radar::before { left: 50%; top: 0; width: 1px; height: 100%; }
#radar::after { top: 50%; left: 0; height: 1px; width: 100%; }
#radar-player {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  margin: -6px 0 0 -6px;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 11px solid #66ffdd;
  filter: drop-shadow(0 0 3px rgba(102, 255, 221, 0.9));
}
#radar-blips { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.radar-blip {
  position: absolute; left: 0; top: 0; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px;
  border-radius: 50%; background: #ff4444; box-shadow: 0 0 6px rgba(255, 60, 60, 0.9);
}
.radar-blip-boss {
  width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px;
  background: #ff66ff; box-shadow: 0 0 9px rgba(255, 100, 255, 0.9);
}
.radar-blip-far { opacity: 0.5; }

/* =========================================
   GYROSCOPE — cap de départ et inclinaison
   ========================================= */
#gyro-display {
  position: fixed; z-index: 10; pointer-events: none;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
/* Sur mobile/tactile, le bas de l'écran est occupé par le joystick (gauche) et les
   boutons d'action (droite) : le gyroscope se place donc sous le radar plutôt qu'en bas,
   pour ne plus jamais se retrouver caché derrière les boutons tactiles. */
body.touch-mode #gyro-display {
  bottom: auto; left: auto; transform: none;
  top: calc(160px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
}
#gyro-dial {
  position: relative; width: 88px; height: 88px; border-radius: 50%;
  border: 2px solid rgba(102, 255, 221, 0.5);
  box-shadow: 0 0 14px rgba(0, 255, 180, 0.25);
  overflow: hidden; background: #061a12;
}
#gyro-horizon {
  position: absolute; left: -25%; top: 50%; width: 150%; height: 300%;
  background: linear-gradient(to bottom,
    rgba(60, 140, 255, 0.4) 0%, rgba(60, 140, 255, 0.4) 50%,
    rgba(120, 75, 35, 0.4) 50%, rgba(120, 75, 35, 0.4) 100%);
  transform: translateY(-50%);
}
#gyro-center-mark {
  position: absolute; left: 50%; top: 50%; width: 12px; height: 12px;
  margin: -6px 0 0 -6px; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}
#gyro-needle-wrap { position: absolute; inset: 0; }
#gyro-home-needle {
  position: absolute; left: 50%; top: 6px; width: 0; height: 0; margin-left: -6px;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 13px solid #ffaa33;
  filter: drop-shadow(0 0 4px rgba(255, 170, 50, 0.9));
}
#gyro-label {
  font-size: 12px; color: #66ffdd; font-weight: bold; letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(100, 255, 220, 0.7);
  background: rgba(0, 0, 0, 0.4); padding: 2px 9px; border-radius: 4px;
}

/* Radar/gyroscope compactés sur petits écrans, comme le reste du HUD */
@media (max-width: 620px), (max-height: 480px) {
  #radar-container { top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); }
  #radar { width: 88px; height: 88px; }
  #gyro-dial { width: 68px; height: 68px; }
  #gyro-display { bottom: calc(10px + env(safe-area-inset-bottom)); }
  body.touch-mode #gyro-display {
    bottom: auto; top: calc(120px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
  }
}

/* =========================================
   MENUS (MODALS)
   ========================================= */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85); display: flex; flex-direction: column;
  justify-content: center; align-items: center; z-index: 100; color: white;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none !important; }

.modal-content {
  background: rgba(15, 15, 25, 0.95); padding: clamp(20px, 5vw, 40px);
  border: 2px solid #00aaff; border-radius: 12px; text-align: center;
  width: 90%; max-width: 450px; box-sizing: border-box;
  box-shadow: 0 0 20px rgba(0, 170, 255, 0.3); max-height: 95vh;
  display: flex; flex-direction: column;
}
.modal-content h1 {
  margin-top: 0; color: #00aaff; text-transform: uppercase;
  letter-spacing: 2px; text-shadow: 0 0 10px rgba(0,170,255,0.5);
  font-size: clamp(24px, 5vw, 32px);
}

.pause-content { background: transparent; border: none; box-shadow: none; }
.form-group { margin: 15px 0; text-align: left; }
.form-group label { display: block; margin-bottom: 8px; color: #ccc; font-weight: bold; font-size: 14px;}
.form-group input {
  width: 100%; padding: 12px; box-sizing: border-box; background: #000;
  border: 1px solid #00aaff; color: #fff; border-radius: 4px; font-size: 16px;
}
.form-group input:focus { outline: none; box-shadow: 0 0 8px #00aaff; }

.action-btn {
  background: #00aaff; color: #000; font-weight: bold; padding: 15px;
  border: none; border-radius: 4px; cursor: pointer; text-transform: uppercase;
  font-size: 16px; transition: all 0.2s; width: 100%; letter-spacing: 1px;
}
.action-btn:active { transform: scale(0.98); }

.table-wrapper { overflow-y: auto; max-height: 30vh; margin-top: 10px; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.leaderboard-table th, .leaderboard-table td { padding: 8px; border-bottom: 1px solid #333; text-align: left; }
.leaderboard-table th { color: #00aaff; border-bottom: 2px solid #00aaff; position: sticky; top: 0; background: #111; }
