/* Room UI - Full Lobby */
#roomUI {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: none;
  z-index: 999;
  overflow-y: auto;
}
#roomUI.active { display: block; }

.room-container {
  /* Trois panneaux cote a cote : 900px les serrait en deux colonnes tres
     hautes, et les boutons de depart tombaient sous la ligne de flottaison. */
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px 20px 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Room top bar */
.room-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.room-code-section {
  display: flex;
  align-items: center;
  gap: 12px;
}
.room-code-label {
  font-size: 0.8rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.room-code {
  font-size: 1.8rem;
  font-weight: 900;
  color: #e94560;
  letter-spacing: 4px;
}
.btn-copy {
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
  color: #ccc;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
.btn-copy:hover { background: rgba(255,255,255,0.15); color: #fff; }
.btn-copy.copied { border-color: #33cc33; color: #33cc33; }

.btn-leave {
  padding: 8px 16px;
  border: 1px solid rgba(233, 69, 96, 0.4);
  border-radius: 6px;
  background: rgba(233, 69, 96, 0.1);
  color: #e94560;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-leave:hover { background: rgba(233, 69, 96, 0.25); }

/* Room main layout */
.room-main {
  display: grid;
  /* Paliers explicites, et non `auto-fit` : celui-ci taillait quatre pistes
     dans 1360px pour trois panneaux, laissant une colonne vide a droite. */
  grid-template-columns: 1fr;
  align-items: start;
  gap: 20px;
  flex: 1;
}
/* Les joueurs prennent moins de place que le kart, et le circuit davantage :
   la liste est une colonne de noms, l'aperçu porte un trace et une fiche. */
@media (min-width: 680px) {
  .room-main { grid-template-columns: minmax(240px, 0.9fr) minmax(280px, 1.1fr); }
}
@media (min-width: 1040px) {
  .room-main { grid-template-columns: minmax(230px, 0.85fr) minmax(270px, 1fr) minmax(300px, 1.15fr); }
}
/* Quatre panneaux de ~280px tiennent des 1200px : c'est la largeur a partir
   de laquelle le salon entier se lit sans defilement. */
@media (min-width: 1200px) {
  .room-main {
    grid-template-columns:
      minmax(210px, 0.8fr) minmax(250px, 0.95fr)
      minmax(260px, 1fr) minmax(280px, 1.05fr);
  }
}

/* Sans le panneau « Choix du circuit », le salon n'a plus que trois
   panneaux : la piste de 1200px laisserait sinon une colonne vide. */
@media (min-width: 1200px) {
  .room-main.room-main-guest {
    grid-template-columns: minmax(230px, 0.85fr) minmax(270px, 1fr) minmax(300px, 1.15fr);
  }
}

.room-panel {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 16px 16px 18px;
}
.panel-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #888;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.player-count {
  background: rgba(233, 69, 96, 0.15);
  color: #e94560;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Player list */
/* Sélecteur de châssis, sous la liste des joueurs */
.kart-select { margin-top: 4px; }
.kart-select-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: rgba(255,255,255,0.45);
  margin-bottom: 10px;
}
.kart-assigned {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid rgba(233, 69, 96, 0.35);
  border-radius: 12px;
  background: rgba(233, 69, 96, 0.07);
}
.kart-assigned-icon { font-size: 1.6rem; line-height: 1; }
.kart-assigned-label {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
}
/* Vitrine du chassis : plateau tournant encadre par deux fleches. */
.kart-stage {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px;
}
.kart-viewport {
  position: relative;
  flex: 1; min-width: 0;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.09);
  background:
    radial-gradient(ellipse at 50% 118%, rgba(233,69,96,0.28), transparent 62%),
    linear-gradient(170deg, rgba(255,255,255,0.07), rgba(255,255,255,0.015));
  overflow: hidden;
}
.kart-viewport canvas { display: block; width: 100%; height: 100%; }
/* Halo au sol : sans lui, le kart flotte dans une boite vide. */
.kart-stage-glow {
  position: absolute; left: 50%; bottom: 12%;
  width: 62%; height: 13%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,0.5), transparent 70%);
  pointer-events: none;
}
.kart-fallback {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}
.kart-fallback[hidden] { display: none; }
.kart-fallback-icon { font-size: 3.2rem; line-height: 1; }

.kart-arrow {
  flex-shrink: 0;
  width: 32px; height: 58px; padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.72);
  font: inherit; font-size: 1.5rem; line-height: 1; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.kart-arrow:hover:not(:disabled) {
  background: rgba(233,69,96,0.2);
  border-color: rgba(233,69,96,0.5);
  color: #fff;
}
.kart-arrow:disabled { opacity: 0.25; cursor: not-allowed; }

.kart-caption {
  display: flex; align-items: baseline; justify-content: center; gap: 9px;
  margin-top: 11px;
}
.kart-name { font-size: 1.05rem; font-weight: 800; color: #fff; letter-spacing: 0.3px; }
.kart-rank {
  font-size: 0.72rem; color: rgba(255,255,255,0.34);
  font-variant-numeric: tabular-nums;
}
/* Reperes de position : ils disent ou l'on est dans le catalogue sans
   ramener la grille de vignettes que la vitrine remplace. */
.kart-dots {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 5px;
  margin-top: 9px;
}
.kart-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
}
.kart-dot.current { background: #e94560; transform: scale(1.5); }
.kart-dot.taken { background: rgba(255,255,255,0.06); }

.color-grid { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.color-choice {
  width: 26px; height: 26px; padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.22);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s;
}
.color-choice:hover:not(:disabled) { transform: scale(1.12); }
.color-choice.selected { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.28); }
.color-choice:disabled { opacity: 0.25; cursor: not-allowed; }
/* Couleur portee par un autre pilote. L'opacite seule se lit comme un defaut
   d'affichage : la barre dit que la case est prise, pas qu'elle est terne. */
.color-choice.taken {
  position: relative;
  opacity: 0.4;
}
.color-choice.taken::after {
  content: '';
  position: absolute;
  left: 50%; top: -3px;
  width: 2px; height: calc(100% + 6px);
  transform: translateX(-50%) rotate(45deg);
  background: rgba(255,255,255,0.75);
  border-radius: 1px;
}

.kart-select-note {
  margin-top: 9px;
  font-size: 0.68rem;
  color: rgba(255,255,255,0.25);
}
.player-kick {
  flex-shrink: 0;
  width: 20px; height: 20px; padding: 0;
  margin-left: 4px;
  border-radius: 5px;
  border: 1px solid rgba(233, 69, 96, 0.3);
  background: rgba(233, 69, 96, 0.1);
  color: rgba(255,255,255,0.5);
  font-size: 0.68rem; line-height: 1; cursor: pointer;
}
.player-kick:hover { background: rgba(233, 69, 96, 0.35); color: #fff; }

/* Ajout de bots, sous la liste des pilotes : le bouton. */
.room-bots {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.room-bots[hidden] { display: none; }
.btn-add-bot {
  flex: 1 1 auto;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px dashed rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.04);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-add-bot:hover:not(:disabled) { background: rgba(255,255,255,0.1); }
.btn-add-bot:disabled { cursor: not-allowed; opacity: 0.5; }
.badge-bot {
  background: rgba(0, 204, 204, 0.15);
  color: #00cccc;
}
.player-kart {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.4);
  flex-shrink: 0;
}

.player-list {
  list-style: none;
}
.player-list li {
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  margin-bottom: 8px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  /* La ligne se replie au lieu de deborder. Chassis, badges et latence
     depassent la colonne des que la fenetre se resserre, et ce qui
     depassait etait dessine par-dessus la carte voisine au lieu d'aller
     a la ligne. Sur un ecran large, tout tient sur une seule ligne et
     cette regle ne se voit pas. */
  flex-wrap: wrap;
  row-gap: 6px;
  border: 1px solid rgba(255,255,255,0.05);
  transition: all 0.2s;
}
.player-list li:hover { background: rgba(255,255,255,0.07); }
.player-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(255,255,255,0.3);
}
.player-name {
  flex: 1 1 auto;
  /* Sans `min-width: 0`, un pseudo long refuse de retrecir et pousse tout
     le reste de la ligne hors de la colonne. Il se coupe donc, au lieu
     d'emporter le kart, les badges et la latence avec lui. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  font-size: 0.95rem;
}
.player-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-host {
  background: rgba(255, 204, 0, 0.15);
  color: #ffcc00;
}
.badge-you {
  background: rgba(51, 204, 51, 0.15);
  color: #33cc33;
}
/* Latence du pilote. Chiffres a chasse fixe et largeur minimale : la
   colonne ne doit pas se decaler a chaque mesure, sinon toute la ligne
   tressaute deux fois par seconde. La couleur double la lecture du chiffre,
   elle ne la remplace pas — le nombre reste lisible sans percevoir la
   teinte. */
.player-ping {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  min-width: 3.4rem;
  text-align: right;
  /* Cale a droite de la ligne : sur une ligne pleine, la latence et la
     pastille « pret » forment une colonne d'etat alignee sur le bord ; quand
     la ligne se replie, elles y restent au lieu de flotter au milieu. */
  margin-left: auto;
  color: rgba(255,255,255,0.35);
  flex-shrink: 0;
}
.player-ping.is-good { color: #33cc33; }
.player-ping.is-fair { color: #ffcc00; }
.player-ping.is-poor { color: #e94560; }
.player-ready {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
}
.player-ready.is-ready {
  background: #33cc33;
  box-shadow: 0 0 6px rgba(51, 204, 51, 0.5);
}
.player-empty {
  padding: 10px 14px;
  border: 1px dashed rgba(255,255,255,0.1);
  border-radius: 10px;
  margin-bottom: 8px;
  color: #444;
  font-size: 0.85rem;
  text-align: center;
}

/* Track Selection */
.track-select {
  margin-bottom: 0;
}
.track-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.track-btn {
  padding: 14px 16px;
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  color: #fff;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}
.track-btn:hover {
  border-color: rgba(233, 69, 96, 0.4);
  background: rgba(233, 69, 96, 0.05);
}
.track-btn.selected {
  border-color: #e94560;
  background: rgba(233, 69, 96, 0.1);
  box-shadow: 0 0 20px rgba(233, 69, 96, 0.15);
}
.track-icon {
  font-size: 2rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  flex-shrink: 0;
}
.track-info {
  flex: 1;
}
.track-name {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 3px;
}
.track-desc {
  font-size: 0.75rem;
  color: #888;
  line-height: 1.3;
}
.track-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  transition: all 0.2s;
}
.track-btn.selected .track-check {
  border-color: #e94560;
  background: #e94560;
  color: #fff;
}
.track-btn.loading {
  pointer-events: none;
  opacity: 0.85;
}
.track-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}
.track-btn.loading .track-progress {
  opacity: 1;
}
.track-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #e94560, #ff6b8a);
  border-radius: 0 0 10px 10px;
  transition: width 0.15s ease-out;
}
.track-progress-text {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 0.65rem;
  color: #e94560;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s;
}
.track-btn.loading .track-progress-text {
  opacity: 1;
}
.track-btn.load-error .track-progress-text {
  opacity: 1;
  color: #ff6b7d;
}
.track-btn {
  position: relative;
  overflow: hidden;
}

/* Bouton « Générer un circuit procédural » */
.track-btn.procedural {
  border-style: dashed;
  border-color: rgba(54, 216, 255, 0.4);
  background: rgba(54, 216, 255, 0.05);
}
.track-btn.procedural:hover {
  border-color: rgba(54, 216, 255, 0.75);
  background: rgba(54, 216, 255, 0.1);
}
.track-btn.procedural .track-icon {
  background: rgba(54, 216, 255, 0.14);
  color: #36d8ff;
}
.track-btn.procedural .track-name {
  color: #36d8ff;
}
.track-btn.procedural.selected {
  border-style: solid;
  border-color: #36d8ff;
  background: rgba(54, 216, 255, 0.12);
  box-shadow: 0 0 20px rgba(54, 216, 255, 0.2);
}
.track-btn.procedural.selected .track-check {
  border-color: #36d8ff;
  background: #36d8ff;
  color: #fff;
}
.track-btn.procedural.loading .track-icon {
  animation: proceduralSpin 0.9s linear infinite;
}
@keyframes proceduralSpin {
  to { transform: rotate(360deg); }
}

/* Force la re-peinture du bouton dans les webviews qui n'affichent pas les
   textContent pendant les évènements réseau continus : une animation de
   GÉOMÉTRIE (padding) force un re-layout + re-paint à chaque frame (les
   animations d'opacité/transform sont des propriétés GPU et ne re-rasterisent
   pas le contenu). */
@keyframes rumbelGeomPulse {
  0% { padding-left: 17px; }
  100% { padding-left: 16px; }
}
.rumbel-geom-pulse {
  animation: rumbelGeomPulse 0.25s ease-out;
}

/* Race settings */
.race-settings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.setting-label {
  font-size: 0.7rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.race-setting-control {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 8px;
  background: rgba(8,15,31,0.78);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
}
.race-setting-control:focus {
  outline: none;
  border-color: #36d8ff;
  box-shadow: 0 0 0 2px rgba(54,216,255,0.14);
}
.race-setting-control:disabled,
.setting-toggle input:disabled + span {
  opacity: 0.52;
  cursor: not-allowed;
}
.setting-toggle { justify-content: flex-end; }
.race-toggle-line {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 8px;
  background: rgba(8,15,31,0.78);
  color: #fff;
  font-size: 0.82rem;
}
.race-toggle-line input { accent-color: #e94560; }
.race-settings-note {
  grid-column: 1 / -1;
  color: rgba(255,255,255,0.4);
  font-size: 0.7rem;
  line-height: 1.35;
}
@media (max-width: 520px) {
  .race-settings { grid-template-columns: 1fr 1fr; }
  .setting-toggle { grid-column: 1 / -1; }
}

/* Room footer */
/* Colle au bas de la fenetre : « Pret » et « Demarrer la course » doivent
   rester cliquables sans avoir a faire defiler le salon. */
.room-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: 14px;
  padding: 10px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  background: linear-gradient(to top, rgba(15, 26, 50, 0.97) 62%, rgba(15, 26, 50, 0));
}
.room-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}
.room-actions .btn-ready {
  flex: 1;
  width: auto;
}
.btn-ready {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  background: linear-gradient(135deg, #33cc33, #228B22);
  color: #fff;
}
.btn-ready:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
  box-shadow: none;
}
.btn-ready:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(51, 204, 51, 0.3);
}
.btn-ready.is-ready {
  background: linear-gradient(135deg, #e94560, #c23152);
}
.btn-ready.is-ready:hover {
  box-shadow: 0 5px 20px rgba(233, 69, 96, 0.3);
}
.btn-start-race {
  background: linear-gradient(135deg, #33cc33, #1e7a1e);
}
.btn-start-race:hover:not(:disabled) {
  box-shadow: 0 5px 20px rgba(51, 204, 51, 0.35);
}
.btn-start-race[hidden] {
  display: none;
}
.btn-start-race:disabled {
  background: linear-gradient(135deg, #5a6072, #3f4553);
  color: rgba(255, 255, 255, 0.45);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.room-map-status {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 22px;
  color: rgba(255,255,255,0.72);
  font-size: 0.84rem;
  line-height: 1.35;
  text-align: center;
}
.room-map-status[hidden] { display: none; }
.room-map-status-copy {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.room-map-status i { margin-top: 2px; }
.room-map-status.is-loading { color: #36d8ff; }
.room-map-status.is-ready { color: #74e39a; }
.room-map-status.is-error {
  padding: 9px 12px;
  border: 1px solid rgba(255,64,88,0.38);
  border-radius: 9px;
  background: rgba(255,64,88,0.10);
  color: #ff93a1;
}
.room-map-progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(54,216,255,0.42);
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.35);
}
.room-map-progress[hidden] { display: none; }
.room-map-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #20bdeb, #75f4ff);
  box-shadow: 0 0 9px rgba(54,216,255,0.65);
  transition: width 180ms ease-out;
}

.controls-hint {
  color: rgba(255,255,255,0.4);
  font-size: 0.8rem;
  text-align: center;
  margin-top: 16px;
}
