/* Loading overlay - only for race start */
#loadingOverlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 10, 20, 0.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#loadingOverlay.active { display: flex; }

/* Reconnection overlay */
#reconnectOverlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 10, 20, 0.95);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2001;
}
#reconnectOverlay.active { display: flex; }
.loader-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(233, 69, 96, 0.2);
  border-top-color: #e94560;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text {
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
}

/* HUD */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  display: none;
  z-index: 100;
}
#hud.active { display: block; }

.hud-leaderboard {
  position: absolute;
  top: 92px;
  right: 24px;
  width: 230px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  background: rgba(7, 10, 24, 0.72);
  box-shadow: 0 10px 28px rgba(0,0,0,0.28);
  backdrop-filter: blur(8px);
}
.hud-leaderboard-title {
  margin-bottom: 8px;
  color: rgba(255,255,255,0.55);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 1.8px;
  text-transform: uppercase;
}
.hud-leaderboard ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
.hud-leaderboard li {
  display: grid;
  grid-template-columns: 24px 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 27px;
  padding: 2px 6px;
  border-radius: 7px;
  color: rgba(255,255,255,0.82);
  font-size: 0.78rem;
}
.hud-leaderboard li.is-you {
  color: #fff;
  background: rgba(255,204,0,0.18);
  box-shadow: inset 2px 0 #ffcc00;
}
.leaderboard-rank {
  color: #ffcc00;
  font-weight: 900;
  text-align: center;
}
.leaderboard-color {
  width: 8px;
  height: 8px;
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 50%;
}
.leaderboard-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-progress {
  color: rgba(255,255,255,0.52);
  font-size: 0.67rem;
  font-weight: 700;
}

/* Ecrans de partie : sur tactile, la largeur utile est le grand cote de
   l'ecran (hud.css, « Media queries des ecrans de partie »). */
@media (max-width: 700px) and (hover: hover) and (pointer: fine),
  (max-width: 700px) and (max-height: 700px) {
  .hud-leaderboard {
    top: 82px;
    right: 12px;
    width: 180px;
    padding: 8px;
  }
  .hud-leaderboard li { font-size: 0.7rem; }
}

.hud-speed {
  position: absolute;
  bottom: 30px;
  right: 30px;
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
.hud-speed span { font-size: 1rem; color: #ccc; }

.hud-inventory {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 16px;
  background: rgba(7,10,24,0.72);
  backdrop-filter: blur(8px);
  pointer-events: all;
}
.hud-item-slots,
.hud-fire-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.hud-item-slot {
  width: 58px;
  height: 58px;
  padding: 0;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.hud-item-slot:disabled { cursor: default; opacity: 0.35; }
.hud-item-slot.occupied:not(:disabled):hover { transform: translateY(-2px); }
.hud-item-slot.selected {
  border-color: #ffcc00;
  background: rgba(255,204,0,0.16);
  box-shadow: 0 0 14px rgba(255,204,0,0.32);
}
.hud-fire-controls { margin-top: 7px; }
.hud-fire-btn {
  min-width: 78px;
  height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  cursor: pointer;
}
.hud-fire-btn.front { background: linear-gradient(135deg, #168aad, #34b7d8); }
.hud-fire-btn.back { background: linear-gradient(135deg, #d35400, #ff8c42); }
.hud-fire-btn.is-punch.front,
.hud-fire-btn.is-punch.back { background: linear-gradient(135deg, #3a4254, #68748e); }
.hud-fire-btn.is-cooling { opacity: 0.5; }
.hud-fire-btn:disabled { opacity: 0.32; cursor: default; }
.hud-fire-btn:not(:disabled):active { transform: scale(0.96); }

@media (max-width: 700px) and (hover: hover) and (pointer: fine),
  (max-width: 700px) and (max-height: 700px) {
  .hud-inventory { top: 68px; transform: translateX(-50%) scale(0.88); }
}

.hud-countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 30px rgba(233, 69, 96, 0.8);
  display: none;
}

.hud-minimap {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 150px;
  height: 150px;
  background: rgba(0,0,0,0.5);
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.2);
}

/* Rétroviseur : cadre transparent laissant voir le sous-viewport du canvas
   rendu en haut au centre. Dimensions identiques à renderRearviewMirror() :
   260 px au plus, 30 % de la largeur, et 22 % de la hauteur — sans ce
   dernier plafond il couvrait plus du tiers d'un téléphone couché. */
.hud-rearview-frame {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(260px, calc(var(--rumbel-viewport-width, 100vw) * 0.3), calc(var(--rumbel-viewport-height, 100dvh) * 0.22 * 16 / 9));
  aspect-ratio: 16 / 9;
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  box-shadow: 0 2px 14px rgba(0,0,0,0.35), inset 0 0 6px rgba(0,0,0,0.25);
}

.hud-message {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: 700;
  color: #ffcc00;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
  display: none;
}

/* Spectate bar */
#spectateBar {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 10px 24px;
  text-align: center;
  z-index: 900;
  display: none;
  backdrop-filter: blur(8px);
}
#spectateBar.active { display: block; }
.spectate-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: #e94560;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.spectate-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
}
.spectate-hint {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.4);
  margin-top: 4px;
}

/* Volume control */
.hud-volume {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: all;
}
.btn-mute {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-mute:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.5);
}
.btn-mute.muted {
  color: #e94560;
  border-color: rgba(233, 69, 96, 0.5);
}
.volume-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

/* Results */
#results {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 380px;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 500;
  border-left: 2px solid rgba(255,204,0,0.3);
  animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
#results.active { display: flex; }
.results-title {
  font-size: 2rem;
  font-weight: 900;
  color: #ffcc00;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(255,204,0,0.5);
}

.results-round-summary { color: rgba(255,255,255,.76); font-weight:700; margin:-10px 0 12px; text-align:center; }
.results-list {
  /* Colonne flex : le reordonnancement de fin de manche se joue sur
     `order`, sans deplacer les noeuds. Deplacer une ligne relancerait les
     animations de ses enfants (la pastille de gain repartait de zero et
     disparaissait). */
  display: flex;
  flex-direction: column;
  list-style: none;
  width: 320px;
  margin-bottom: 20px;
}
.results-list li {
  padding: 12px 16px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  margin-bottom: 8px;
  color: #fff;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  transition: transform 0.2s;
}
.results-list li:hover {
  transform: scale(1.03);
}
.results-list li:first-child {
  background: rgba(255, 204, 0, 0.15);
  border: 1px solid rgba(255, 204, 0, 0.4);
}

#hud .controls-hint {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.5);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0;
}

.error-msg {
  color: #e94560;
  font-size: 0.9rem;
  margin-top: 10px;
  text-align: center;
  min-height: 20px;
}

.admin-entry {
  position: absolute;
  z-index: 3;
  top: 20px;
  right: 22px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: rgba(255,255,255,0.58);
  background: rgba(255,255,255,0.035);
  font-size: 0.76rem;
  font-weight: 700;
  text-decoration: none;
  transition: 0.2s ease;
}
.admin-entry:hover {
  color: #fff;
  border-color: rgba(53,215,255,0.4);
  background: rgba(53,215,255,0.07);
  transform: translateY(-1px);
}
