* { margin: 0; padding: 0; box-sizing: border-box; }
/* Zones de securite : encoche, coins arrondis, barre d'accueil. La page
   s'etend sous elles (`viewport-fit=cover` dans index.html) ; chaque ecran
   tient ses bords avec ces variables, qui valent 0 partout ailleurs. Une
   seule source, que les feuilles suivantes lisent toutes. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
/* Les boutons plein ecran restent caches tant que le navigateur ne l'offre
   pas (input-controller.js) : `hidden` doit l'emporter sur les `display` des
   boutons dont ils empruntent la classe. */
[data-fullscreen-toggle][hidden] { display: none !important; }
/* Hors francais, la page attend sa traduction avant de s'afficher (i18n.js) :
   sans cela le texte d'origine apparaitrait un instant avant la bonne langue. */
html.i18n-pending body { visibility: hidden; }
html, body {
  width: 100%;
  height: 100%;
  overscroll-behavior: none;
}
body {
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #1a1a2e;
  height: var(--rumbel-viewport-height, 100dvh);
}
#gameCanvas {
  width: var(--rumbel-viewport-width, 100vw);
  height: var(--rumbel-viewport-height, 100dvh);
  display: block;
  touch-action: none;
}

/* ── Rotation automatique ─────────────────────────────────────────────
   Ecran tactile en portrait pendant une partie : la page entiere se couche
   d'un quart de tour (camera-controller.js, `applyScreenRotation`), et le
   joueur n'a plus qu'a tourner son telephone, rotation automatique activee
   ou non. `--rumbel-viewport-*` portent alors la taille de la page, en
   paysage ; `--rumbel-screen-*` celle de l'ecran, tel quel.
   - Les ecrans fixes (HUD, construction, resultats) se placent dans le
     corps tourne : la transformation en fait leur bloc conteneur.
   - Conteneur de taille : `cqw` et `cqh` y mesurent la page couchee, la
     ou `vw` et `vh` mesurent toujours l'ecran debout. Les feuilles des
     ecrans de partie les emploient ; sans conteneur, ils retombent sur
     l'ecran.
   - Les zones de securite tournent avec la page : l'encoche, en haut de
     l'ecran debout, passe sur un cote. */
html[data-screen-rotation] { overflow: hidden; }
html[data-screen-rotation] body {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--rumbel-viewport-width);
  height: var(--rumbel-viewport-height);
  transform-origin: 0 0;
  container-type: size;
}
/* Page couchee vers la droite : son haut longe le bord droit de l'ecran. */
html[data-screen-rotation="cw"] {
  --safe-top: env(safe-area-inset-right, 0px);
  --safe-right: env(safe-area-inset-bottom, 0px);
  --safe-bottom: env(safe-area-inset-left, 0px);
  --safe-left: env(safe-area-inset-top, 0px);
}
html[data-screen-rotation="cw"] body {
  transform: translateX(var(--rumbel-screen-width, 100vw)) rotate(90deg);
}
/* Vers la gauche : son haut longe le bord gauche. */
html[data-screen-rotation="ccw"] {
  --safe-top: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-right, 0px);
  --safe-left: env(safe-area-inset-bottom, 0px);
}
html[data-screen-rotation="ccw"] body {
  transform: translateY(var(--rumbel-screen-height, 100vh)) rotate(-90deg);
}

/* ── Lobby UI ──────────────────────────────────────────────────────────
   L'accueil reprend l'affiche du jeu : elle occupe le fond, un voile la
   calme, et l'interface tient en une colonne de 560 px avec deux hauteurs
   de rangee — 68 px pour le lancement, 48 px pour les chemins rares.
   Rien ne s'empile en meme largeur avec des hauteurs differentes : ce qui
   distingue le bouton du champ, c'est sa couleur, pas quelques pixels. */
#lobby {
  --kk-col: 560px;
  --kk-row: 68px;
  --kk-row-s: 48px;
  --kk-radius: 14px;
  --kk-radius-s: 12px;
  --kk-ink: #16110c;
  --kk-paper: #fffdf7;
  --kk-yellow: #ffc31d;
  --kk-yellow-hi: #ffd84a;
  --kk-yellow-lo: #f79a08;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #0a1426;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  /* Defilement plutot que troncature : sur un ecran court (portable bas de
     gamme, telephone en paysage), `hidden` coupait le bas du bloc et donc
     le bouton Jouer, sans aucun moyen d'y acceder. */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0;
}
#lobby.hidden { display: none; }

/* L'affiche, en `fixed` et non `absolute` : dans un conteneur qui defile,
   elle remonterait avec le contenu. */
.lobby-poster {
  position: fixed; inset: 0; z-index: 0;
  background: url('/assets/branding/kapy-kart-poster.jpg') center top / cover no-repeat;
  filter: blur(2px) saturate(1.06) brightness(0.94);
  pointer-events: none;
}
/* Voile : pose sur la poussiere de l'affiche, le texte clair devenait
   illisible des que le kart passait dessous. */
#lobby::after {
  content: '';
  position: fixed; inset: 0; z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 54% 44% at 50% 64%, rgba(6,12,26,0.74), transparent 76%),
    linear-gradient(180deg, rgba(6,12,26,0.44) 0%, rgba(6,12,26,0.16) 26%, rgba(6,12,26,0.78) 100%);
}

.lobby-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 1.8vh, 20px);
  width: 100%;
  padding: 0 20px;
  /* `auto` en marge verticale centre le bloc quand il tient, et laisse le
     defilement prendre le relais quand il ne tient plus. */
  margin: auto 0;
}
.lobby-col { width: min(var(--kk-col), 100%); }

/* Le logo de l'affiche. Le nom du jeu vit dans l'attribut `alt` : c'est lui
   que liront les lecteurs d'ecran et les moteurs. */
.lobby-brand { display: grid; place-items: center; }
.lobby-logo {
  display: block;
  width: min(520px, 74vw);
  filter: drop-shadow(0 14px 26px rgba(0,0,0,0.45));
}
.lobby-subtitle {
  max-width: 48ch;
  text-align: center;
  color: #eaf4ff;
  font-size: 0.96rem;
  font-weight: 600;
  text-shadow: 0 2px 10px rgba(4,10,22,0.8);
}

/* Rangee de lancement : le pseudo et JOUER cote a cote, meme hauteur,
   memes coins, meme contour noir — deux pieces du meme objet. */
.lobby-box { width: min(var(--kk-col), 100%); }
.lobby-launch { display: flex; gap: 10px; height: var(--kk-row); }
.lobby-identity { position: relative; flex: 1; min-width: 0; margin: 0; max-width: none; }
.lobby-identity .input-icon { left: 18px; opacity: 0.55; font-size: 1.05rem; }
#lobby .btn-play {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 208px; height: 100%; flex: none;
  margin: 0; padding: 0 16px;
  border: 3px solid var(--kk-ink);
  border-radius: var(--kk-radius);
  background: linear-gradient(180deg, var(--kk-yellow-hi), var(--kk-yellow) 45%, var(--kk-yellow-lo));
  color: #2b1c00;
  font-family: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  font-size: 1.75rem; font-weight: 900; font-style: italic; letter-spacing: 0.08em;
  text-shadow: 0 1px 0 rgba(255,255,255,0.45);
  box-shadow: 0 6px 0 var(--kk-ink), 0 14px 26px rgba(22,17,12,0.3);
  transition: transform 0.12s, box-shadow 0.18s, filter 0.18s;
}
#lobby .btn-play:hover:not([disabled]) {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--kk-ink), 0 20px 34px rgba(22,17,12,0.34);
}
#lobby .btn-play:active:not([disabled]) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--kk-ink);
}
/* Desactive tant que le pilote n'est pas nomme. A peine grise, il se
   confondait avec le bouton actif sur ce fond deja chaud. */
#lobby .btn-play[disabled] {
  cursor: not-allowed;
  filter: grayscale(0.75) brightness(0.86);
  opacity: 0.8;
  box-shadow: 0 4px 0 rgba(22,17,12,0.6);
}
#lobby .btn-play i { font-size: 1.15rem; font-style: normal; }

.lobby-hint {
  text-align: center;
  color: rgba(234,244,255,0.82);
  font-size: 0.76rem; font-weight: 600;
  text-shadow: 0 2px 8px rgba(4,10,22,0.8);
  min-height: 18px;
}
.lobby-hint kbd {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 5px; margin: 0 3px;
  border: 2px solid var(--kk-ink); border-radius: 5px;
  background: #ffe9a8; color: #2b2118;
  font: 700 0.68rem/1 'Segoe UI', sans-serif;
}

/* Les chemins rares n'apparaissent qu'une fois le pilote nomme : avant, ils
   proposent des detours vers une partie qu'on ne peut de toute facon pas
   rejoindre sans nom. `visibility` et pas seulement `opacity`, pour qu'ils
   sortent aussi de l'ordre de tabulation. */
.lobby-links {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  margin-top: 4px;
  opacity: 0; visibility: hidden; transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.34s cubic-bezier(0.2,0.9,0.25,1), visibility 0.34s;
}
#lobby.is-ready .lobby-links { opacity: 1; visibility: visible; transform: none; }
.lobby-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--kk-row-s); padding: 0 10px;
  border: 3px solid var(--kk-ink);
  border-radius: var(--kk-radius-s);
  background: var(--kk-paper);
  color: #2b2118;
  font: inherit; font-size: 0.84rem; font-weight: 700;
  text-decoration: none; cursor: pointer;
  box-shadow: 0 4px 0 rgba(22,17,12,0.4);
  transition: background 0.16s, transform 0.12s;
}
.lobby-link:hover { background: #ffe9a8; color: #2b2118; transform: translateY(-1px); }
.lobby-link i { color: #e2660d; }
/* Les pastilles se separent d'elles-memes : le point du milieu ferait un
   troisieme objet entre deux boutons deja detaches. */
.lobby-link-sep { display: none; }
/* Le classement a sa place dans le podium du coin ; ce bouton n'est la que
   pour les ecrans trop etroits pour l'accueillir. */
.lobby-link--ladder { display: none; }

.lobby-code {
  display: flex; gap: 10px; align-items: stretch;
  height: var(--kk-row-s);
  margin-top: 10px;
}
.lobby-code[hidden] { display: none; }
.lobby-code .input-group { flex: 1; margin: 0; }
#lobby .lobby-code .btn {
  width: auto; height: 100%; margin: 0; padding: 0 20px;
  border: 3px solid var(--kk-ink); border-radius: var(--kk-radius-s);
  background: var(--kk-paper); color: #2b2118;
  font-size: 0.84rem; font-weight: 800; white-space: nowrap;
  box-shadow: 0 4px 0 rgba(22,17,12,0.4);
}
#lobby .lobby-code .btn:hover { background: #ffe9a8; transform: none; }

/* Podium du coin. Il tient lieu de bouton « Classement » : il montre
   l'enjeu au lieu de le nommer, et le clic ouvre le classement complet. */
.lobby-ladder {
  position: fixed; z-index: 3; top: 18px; left: 18px;
  display: grid; gap: 5px;
  width: 244px; padding: 11px 12px 12px;
  border: 3px solid var(--kk-ink); border-radius: var(--kk-radius-s);
  background: var(--kk-paper); color: #2b2118;
  text-align: left; cursor: pointer;
  box-shadow: 0 5px 0 rgba(22,17,12,0.45), 0 14px 26px rgba(4,10,22,0.35);
  transition: transform 0.12s, box-shadow 0.18s;
}
.lobby-ladder[hidden] { display: none; }
.lobby-ladder:hover { transform: translateY(-2px); box-shadow: 0 7px 0 rgba(22,17,12,0.45), 0 18px 32px rgba(4,10,22,0.4); }
.lobby-ladder:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(22,17,12,0.45); }
.lobby-ladder-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 2px;
  font-family: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  font-size: 1.05rem; font-weight: 900; font-style: italic;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.lobby-ladder-head i { color: #e2a10d; }
.lobby-ladder-rows { display: grid; gap: 0; }
.lobby-ladder-row {
  display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 9px;
  padding: 4px 0; border-top: 1px solid rgba(22,17,12,0.12);
  font-size: 0.84rem; font-weight: 700;
}
/* Or, argent, bronze : la place se lit a la couleur avant le chiffre, et le
   contour noir les tient sur n'importe quel fond. */
.lobby-medal {
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--kk-ink);
  font: 900 0.78rem/1 'Segoe UI', sans-serif; color: #2b2118;
}
.lobby-medal.gold { background: linear-gradient(180deg, #ffe066, #f0a500); }
.lobby-medal.silver { background: linear-gradient(180deg, #f2f5f8, #b9c4cf); }
.lobby-medal.bronze { background: linear-gradient(180deg, #e3a06a, #b26a2f); }
.lobby-ladder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-ladder-score { font-weight: 800; font-size: 0.78rem; color: rgba(43,33,24,0.62); }
/* Marche encore libre : la place existe, elle attend son pilote. Le
   contraste tombe assez pour ne pas se confondre avec un resultat. */
.lobby-ladder-row.is-empty { color: rgba(43,33,24,0.42); font-style: italic; }
.lobby-ladder-row.is-empty .lobby-medal { opacity: 0.4; }
.lobby-ladder-row.is-empty .lobby-ladder-score { color: rgba(43,33,24,0.34); }
/* Classement encore vide : une phrase, pas trois marches desertes. */
.lobby-ladder-note {
  padding: 6px 0 2px; border-top: 1px solid rgba(22,17,12,0.12);
  font-size: 0.8rem; font-weight: 600; line-height: 1.35;
  color: rgba(43,33,24,0.55);
}

/* Le nombre de pilotes en ligne n'est pas une action : il passe en coin, la
   ou on le consulte sans qu'il dispute l'attention au bouton. */
.lobby-status {
  position: fixed; z-index: 3; right: 18px; bottom: 18px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border: 3px solid var(--kk-ink); border-radius: 999px;
  background: var(--kk-paper); color: #2b2118;
  font-size: 0.8rem; font-weight: 700;
  box-shadow: 0 3px 0 rgba(22,17,12,0.35);
}
/* Vide — annuaire injoignable, ou personne en ligne — il ne doit pas
   laisser une pastille blanche dans le coin. */
.lobby-status:empty { display: none; }
.lobby-status .live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #17a35c; margin: 0;
}

.lobby-footer {
  text-align: center;
  max-width: 56ch;
  color: rgba(234,244,255,0.72);
  font-size: 0.76rem;
  text-shadow: 0 2px 8px rgba(4,10,22,0.8);
}
.lobby-footer-link {
  border: 0; padding: 0; background: none; cursor: pointer;
  font: inherit; font-weight: 800; color: #ffd84a;
  text-decoration: underline; text-underline-offset: 3px;
}
.lobby-footer-link:hover { color: #fff; }
#lobby .error-msg {
  color: #ffb4b4; font-weight: 700;
  text-shadow: 0 2px 8px rgba(4,10,22,0.9);
}

/* La barre du coin superieur droit, en pieces d'affiche : contour noir,
   papier creme, relief. Administration n'a pas a etre le plus gros bouton
   de la moitie haute, elle passe en icone seule. */
.lobby-topbar {
  position: fixed; z-index: 3; top: 18px; right: 18px;
  display: flex; gap: 8px; align-items: center;
}
#lobby .settings-trigger-btn,
#lobby .admin-entry {
  position: static;
  display: grid; place-items: center;
  width: 42px; height: 42px; padding: 0;
  border: 3px solid var(--kk-ink); border-radius: var(--kk-radius-s);
  background: var(--kk-paper); color: #2b2118;
  font-size: 1rem;
  box-shadow: 0 4px 0 rgba(22,17,12,0.4);
  transition: background 0.16s, transform 0.12s;
}
/* Le bouton de langue porte le code courant a cote du globe : il est un peu
   plus large que ses voisins, qui n'ont qu'une icone. */
#lobby .settings-trigger-btn.lang-trigger {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: auto; min-width: 42px; padding: 0 10px;
}
#lobby .lang-trigger-code {
  font-size: 0.82rem; font-weight: 800; letter-spacing: 0.04em; line-height: 1;
}
#lobby .admin-entry { opacity: 0.72; }
#lobby .admin-entry span { display: none; }
#lobby .settings-trigger-btn:hover,
#lobby .admin-entry:hover {
  background: #ffe9a8; color: #2b2118; opacity: 1;
  transform: translateY(-1px);
}

/* ── Mouvement ─────────────────────────────────────────────────────────
   Trois usages, rien d'autre : faire entrer l'ecran, signaler qu'un etat a
   change, et donner un souffle lent au logo. Tout est court (0,3–0,6 s). */
@keyframes kkIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes kkInLeft { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
@keyframes kkInRight { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes kkPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(23,163,92,0.5); } 50% { box-shadow: 0 0 0 7px rgba(23,163,92,0); } }
@keyframes kkPop { 40% { transform: scale(1.035); } }

/* Entree en cascade, dans l'ordre de lecture : l'oeil suit au lieu de
   recevoir l'ecran d'un bloc. Moins de 0,5 s de retard cumule. */
#lobby:not(.hidden) .lobby-brand { animation: kkIn 0.55s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby:not(.hidden) .lobby-subtitle { animation: kkIn 0.55s 0.07s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby:not(.hidden) .lobby-launch { animation: kkIn 0.55s 0.14s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby:not(.hidden) .lobby-hint { animation: kkIn 0.5s 0.2s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby:not(.hidden) .lobby-footer { animation: kkIn 0.5s 0.3s ease-out both; }
#lobby:not(.hidden) .lobby-topbar { animation: kkIn 0.45s 0.36s ease-out both; }
#lobby:not(.hidden) .lobby-ladder { animation: kkInLeft 0.5s 0.3s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby:not(.hidden) .lobby-status { animation: kkInRight 0.5s 0.38s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby:not(.hidden) .lobby-ladder-row { animation: kkIn 0.4s both; }
#lobby:not(.hidden) .lobby-ladder-row:nth-child(1) { animation-delay: 0.42s; }
#lobby:not(.hidden) .lobby-ladder-row:nth-child(2) { animation-delay: 0.5s; }
#lobby:not(.hidden) .lobby-ladder-row:nth-child(3) { animation-delay: 0.58s; }
#lobby:not(.hidden) .lobby-logo { animation: kkIn 0.55s cubic-bezier(0.2,0.9,0.25,1) both; }
.lobby-status .live-dot { animation: kkPulse 2.6s ease-in-out infinite; }
#lobby.is-ready .lobby-link:nth-child(1) { animation: kkIn 0.38s 0.02s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby.is-ready .lobby-link:nth-child(2) { animation: kkIn 0.38s 0.09s cubic-bezier(0.2,0.9,0.25,1) both; }
#lobby.is-ready .lobby-link:nth-child(3) { animation: kkIn 0.38s 0.16s cubic-bezier(0.2,0.9,0.25,1) both; }
/* Le bouton vient de s'activer : une impulsion breve, une seule fois. */
#lobby .btn-play.just-enabled { animation: kkPop 0.36s cubic-bezier(0.2,1.5,0.4,1); }

/* Ecran court (portable 1366x768 et en dessous) : la colonne reste
   entiere, seules les rangees et la typo se resserrent. */
@media (max-height: 820px) {
  #lobby { --kk-row: 60px; --kk-row-s: 44px; }
  #lobby .btn-play { width: 190px; font-size: 1.55rem; }
  .lobby-logo { width: min(420px, 62vw); }
  .lobby-subtitle { font-size: 0.88rem; }
  .lobby-footer { display: none; }
}
/* Ecran etroit : le podium du coin n'a plus la place, le bouton
   « Classement » de la rangee reprend son role, et la pastille d'etat
   rentre dans le flux plutot que de couvrir le contenu. */
@media (max-width: 900px) {
  .lobby-ladder { display: none !important; }
  .lobby-link--ladder { display: inline-flex; }
  .lobby-links { grid-template-columns: repeat(2, 1fr); }
  .lobby-link--ladder { grid-column: span 2; }
}
@media (max-width: 640px) {
  #lobby { padding-top: 76px; justify-content: flex-start; }
  /* Portrait : en `cover`, l'affiche entiere tient dans la hauteur et son
     propre lettrage revient en bas de l ecran, sous celui du logo. On
     zoome pour le sortir du cadre. */
  .lobby-poster { background-size: auto 150%; }
  .lobby-content { margin: 0; }
  .lobby-launch { height: auto; flex-direction: column; }
  /* En colonne, `flex: 1` (base 0) laissait la rangee se replier sur la
     hauteur du contenu : le champ du pseudo s'ecrasait. */
  .lobby-identity, #lobby .btn-play { flex: none; width: 100%; height: var(--kk-row); }
  .lobby-status { position: static; margin-top: 4px; }
}
/* Reglage systeme « moins d'animations » : tout est coupe. Le devoilement
   des chemins rares reste — c'est une regle d'interface, pas une
   animation : la rangee apparait simplement d'un coup. */
@media (prefers-reduced-motion: reduce) {
  #lobby *, #lobby *::before, #lobby *::after { animation: none !important; transition: none !important; }
  .lobby-links { transform: none; }
}

/* Apercu du circuit selectionne. */
/* Une seule colonne : le panneau du salon est etroit par nature (il partage
   la largeur avec la liste des joueurs), et deux colonnes y tronquaient le
   nom du circuit en ecrasant les chiffres. */
.track-preview { margin-top: 4px; }
.track-preview[hidden] { display: none; }
.track-preview-map {
  position: relative;
  aspect-ratio: 16 / 9;
  margin-bottom: 13px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.07);
  background: radial-gradient(ellipse at 50% 40%, rgba(54,216,255,0.09), rgba(0,0,0,0.28));
  overflow: hidden;
}
.track-preview-map canvas { display: block; width: 100%; height: 100%; }
.track-preview-map canvas[hidden] { display: none; }
.track-preview-wait {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center; padding: 10px;
  font-size: 0.72rem; color: rgba(255,255,255,0.4);
}
.track-preview-wait[hidden] { display: none; }
.track-preview-info { min-width: 0; display: flex; flex-direction: column; }
.track-preview-name {
  font-size: 1.02rem; font-weight: 800; color: #fff;
  line-height: 1.25;
}
.track-preview-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.track-tag {
  padding: 2px 9px; border-radius: 20px;
  font-size: 0.66rem; letter-spacing: 0.5px;
  border: 1px solid rgba(255,255,255,0.16); color: rgba(255,255,255,0.62);
}
.track-tag.generated { border-color: rgba(124,179,255,0.45); color: #9ec5ff; }
.track-tag.liked { border-color: rgba(61,220,132,0.4); color: #6ee7a0; }
/* Chiffres du circuit : longueur, virages, boites. */
.track-preview-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px; margin: 12px 0 0;
}
.track-preview-stats div { min-width: 0; }
.track-preview-stats dt {
  font-size: 0.6rem; letter-spacing: 0.8px; text-transform: uppercase;
  color: rgba(255,255,255,0.3);
}
.track-preview-stats dd {
  margin: 1px 0 0; font-size: 0.92rem; font-weight: 700;
  color: rgba(255,255,255,0.85); font-variant-numeric: tabular-nums;
}
.btn-regenerate {
  margin-top: 13px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid rgba(124,179,255,0.4);
  background: rgba(124,179,255,0.14);
  color: #bcd8ff;
  font: inherit; font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.btn-regenerate:hover:not(:disabled) { background: rgba(124,179,255,0.28); color: #fff; }
.btn-regenerate:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-regenerate[hidden] { display: none; }
.track-preview-hint {
  margin-top: 7px;
  font-size: 0.7rem; color: rgba(255,255,255,0.32);
}
/* Salon ouvert au public : interrupteur cote hote. */
.room-visibility {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.6);
}
.room-visibility[hidden] { display: none; }

/* Parties en cours : ecran plein, meme rang que #lobby et #roomUI. */
#roomsPage {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: none;
  z-index: 1001;
  overflow-y: auto;
  overflow-x: hidden;
}
#roomsPage.active { display: block; }
.rooms-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.rooms-topbar {
  display: flex; align-items: flex-start; gap: 14px;
  margin-bottom: 22px;
}
.rooms-heading { flex: 1; min-width: 0; }
.rooms-title { margin: 0; font-size: 1.7rem; font-weight: 900; letter-spacing: -0.5px; }
.rooms-lede { margin: 4px 0 0; color: rgba(255,255,255,0.45); font-size: 0.86rem; }
.btn-back, .btn-refresh {
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.75);
  border-radius: 9px; padding: 9px 14px;
  font: inherit; font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.btn-refresh { padding: 9px 13px; font-size: 1rem; line-height: 1; }
.btn-back:hover, .btn-refresh:hover { background: rgba(255,255,255,0.13); color: #fff; }
.btn-refresh.spinning { animation: roomsSpin 0.6s linear; }
@keyframes roomsSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.rooms-list { display: flex; flex-direction: column; gap: 10px; }
.rooms-row {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px;
  border-radius: 13px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  transition: border-color 0.15s, background 0.15s;
}
.rooms-row:hover { border-color: rgba(255,255,255,0.18); background: rgba(255,255,255,0.06); }
.rooms-row-main { flex: 1; min-width: 0; }
.rooms-row-name {
  font-size: 1.05rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rooms-row-meta {
  font-size: 0.78rem; color: rgba(255,255,255,0.45);
  margin-top: 3px;
  display: flex; flex-wrap: wrap; gap: 4px 10px;
}
.rooms-count {
  flex-shrink: 0; text-align: center;
  font-variant-numeric: tabular-nums;
}
.rooms-count-value { font-size: 1.05rem; font-weight: 700; color: rgba(255,255,255,0.85); }
.rooms-count-label {
  display: block; font-size: 0.62rem; letter-spacing: 0.8px;
  text-transform: uppercase; color: rgba(255,255,255,0.32);
}
.rooms-join {
  flex-shrink: 0;
  padding: 10px 20px; border-radius: 9px;
  border: 1px solid rgba(233, 69, 96, 0.45);
  background: rgba(233, 69, 96, 0.18);
  color: #ff9db0; font: inherit; font-size: 0.88rem; font-weight: 700;
  cursor: pointer;
}
.rooms-join:hover:not(:disabled) { background: rgba(233, 69, 96, 0.34); color: #fff; }
.rooms-join:disabled { opacity: 0.35; cursor: not-allowed; }
.rooms-tag {
  display: inline-block; margin-left: 8px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.62rem; letter-spacing: 0.7px; text-transform: uppercase;
  border: 1px solid rgba(255,255,255,0.16); color: rgba(255,255,255,0.55);
  vertical-align: middle;
}
.rooms-tag.racing { border-color: rgba(255,171,64,0.4); color: #ffab40; }
.rooms-empty {
  padding: 52px 20px; text-align: center;
  border: 1px dashed rgba(255,255,255,0.12); border-radius: 13px;
}
.rooms-empty-title { font-size: 1rem; color: rgba(255,255,255,0.6); margin-bottom: 5px; }
.rooms-empty-note { font-size: 0.84rem; color: rgba(255,255,255,0.34); }
.rooms-foot {
  margin-top: auto; padding-top: 26px;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
}
.rooms-foot .btn { width: 100%; max-width: 300px; }
.rooms-foot-note {
  font-size: 0.74rem; color: rgba(255,255,255,0.32);
  text-align: center; max-width: 46ch;
}
@media (max-width: 560px) {
  .rooms-container { padding: 20px 14px 32px; }
  /* Le titre est pris en tenaille entre Retour et Rafraichir : il descend
     sous eux plutot que de se casser en trois lignes. */
  .rooms-topbar { flex-wrap: wrap; gap: 10px; }
  .rooms-heading { flex-basis: 100%; order: 3; }
  .rooms-title { font-size: 1.4rem; }
  .rooms-row { flex-wrap: wrap; gap: 10px; }
  .rooms-row-main { flex-basis: 100%; }
  .rooms-join { flex: 1; }
}

/* Classement general : meme ecran plein que #roomsPage, dont il reprend le
   cadre (.rooms-container, .rooms-topbar, .btn-back) pour que les deux
   pages secondaires se ressemblent. */
#leaderboardPage {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: none;
  z-index: 1001;
  overflow-y: auto;
  overflow-x: hidden;
}
#leaderboardPage.active { display: block; }
.leaderboard-tabs {
  display: flex; gap: 6px;
  padding: 5px;
  margin-bottom: 18px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
}
.leaderboard-tab {
  flex: 1;
  padding: 10px 8px;
  border: none; border-radius: 9px;
  background: transparent;
  color: rgba(255,255,255,0.55);
  font: inherit; font-size: 0.85rem; font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.leaderboard-tab:hover { color: #fff; }
.leaderboard-tab.active {
  background: rgba(233, 69, 96, 0.22);
  color: #ff9db0;
  box-shadow: inset 0 0 0 1px rgba(233, 69, 96, 0.35);
}

.leaderboard-list { display: flex; flex-direction: column; gap: 8px; }
.leaderboard-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 16px;
  border-radius: 13px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
}
/* Le podium se lit avant d'etre lu : les trois premieres lignes portent
   leur metal, le reste du tableau reste neutre. */
.leaderboard-row.podium-1 { border-color: rgba(255,215,0,0.38); background: rgba(255,215,0,0.09); }
.leaderboard-row.podium-2 { border-color: rgba(200,210,225,0.32); background: rgba(200,210,225,0.07); }
.leaderboard-row.podium-3 { border-color: rgba(205,127,50,0.32); background: rgba(205,127,50,0.08); }
.leaderboard-row.is-you { box-shadow: inset 0 0 0 1px rgba(76, 201, 240, 0.55); }
.leaderboard-rank {
  flex-shrink: 0;
  width: 38px; text-align: center;
  font-size: 1.15rem; font-weight: 800;
  color: rgba(255,255,255,0.5);
  font-variant-numeric: tabular-nums;
}
.leaderboard-row-main { flex: 1; min-width: 0; }
.leaderboard-name {
  font-size: 1.02rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.leaderboard-you-tag {
  display: inline-block; margin-left: 8px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.6rem; letter-spacing: 0.7px; text-transform: uppercase;
  border: 1px solid rgba(76, 201, 240, 0.5); color: #7fd8f5;
  vertical-align: middle;
}
.leaderboard-meta {
  margin-top: 3px;
  font-size: 0.76rem; color: rgba(255,255,255,0.45);
}
.leaderboard-wins {
  flex-shrink: 0; text-align: right;
  font-variant-numeric: tabular-nums;
}
.leaderboard-wins-value { font-size: 1.35rem; font-weight: 800; color: #fff; line-height: 1.1; }
.leaderboard-wins-label {
  display: block; font-size: 0.62rem; letter-spacing: 0.8px;
  text-transform: uppercase; color: rgba(255,255,255,0.32);
}
.leaderboard-empty {
  padding: 52px 20px; text-align: center;
  border: 1px dashed rgba(255,255,255,0.12); border-radius: 13px;
}
.leaderboard-empty-title { font-size: 1rem; color: rgba(255,255,255,0.6); margin-bottom: 5px; }
.leaderboard-empty-note { font-size: 0.84rem; color: rgba(255,255,255,0.34); }
.leaderboard-self { margin-top: 16px; }
.leaderboard-self[hidden] { display: none; }
.leaderboard-self-label {
  font-size: 0.66rem; letter-spacing: 0.9px; text-transform: uppercase;
  color: rgba(255,255,255,0.32); margin-bottom: 6px;
}
@media (max-width: 560px) {
  .leaderboard-tab { font-size: 0.78rem; padding: 9px 4px; }
  .leaderboard-row { gap: 10px; padding: 12px 13px; }
  .leaderboard-rank { width: 28px; font-size: 1rem; }
  .leaderboard-meta { font-size: 0.72rem; }
  .leaderboard-wins-value { font-size: 1.15rem; }
}

/* Comment jouer */
.howto-overlay {
  position: fixed; inset: 0;
  /* Au-dessus de #lobby (1000) et de #roomUI (999) : le panneau s'ouvre
     depuis les deux. `display:flex` battant l'attribut `hidden`, la regle
     [hidden] ci-dessous est ce qui le referme vraiment. */
  z-index: 2100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(8, 10, 20, 0.82);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.howto-panel {
  position: relative;
  width: min(860px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 30px 30px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(160deg, rgba(30, 34, 60, 0.98), rgba(18, 20, 38, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  /* La page ne fixe aucune couleur de texte : sans celle-ci, les titres du
     panneau sortaient en noir sur ce fond nuit. */
  color: #fff;
}
.howto-overlay[hidden] { display: none; }
.howto-close {
  position: absolute; top: 14px; right: 16px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #fff; font-size: 0.95rem; cursor: pointer;
}
.howto-close:hover { background: rgba(255, 255, 255, 0.14); }
.howto-title { margin: 0 0 6px; font-size: 1.55rem; letter-spacing: 0.5px; }
.howto-lede { margin: 0 0 20px; color: rgba(255, 255, 255, 0.68); font-size: 0.95rem; }
.howto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.howto-card {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.04);
}
.howto-card-title { font-weight: 700; margin-bottom: 6px; font-size: 0.98rem; }
.howto-card p { margin: 0; font-size: 0.9rem; line-height: 1.5; color: rgba(255, 255, 255, 0.74); }
.howto-card kbd {
  display: inline-block;
  min-width: 20px; padding: 1px 6px; margin: 0 1px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.1);
  font: inherit; font-size: 0.82rem; font-weight: 700; color: #fff;
}
.howto-tier { font-weight: 700; }
.howto-tier.t1 { color: #6ec1ff; }
.howto-tier.t2 { color: #ffab40; }
.howto-tier.t3 { color: #c58bff; }
/* Telephone : le panneau prend la largeur, et la croix la taille du doigt. */
@media (max-width: 560px) {
  .howto-overlay { padding: 12px; }
  .howto-panel { padding: 22px 18px 20px; }
  .howto-title { padding-right: 44px; }
}
@media (pointer: coarse), (hover: none) {
  .howto-close { top: 10px; right: 10px; width: 44px; height: 44px; }
}


.input-group {
  position: relative;
  margin-bottom: 14px;
}
.input-group .input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  opacity: 0.5;
  pointer-events: none;
}
/* Champs de l'accueil : papier creme, contour noir epais, meme relief que
   les boutons — ils appartiennent au meme jeu de pieces. */
.lobby-box input {
  width: 100%; height: 100%;
  padding: 0 18px 0 48px;
  border: 3px solid #16110c;
  border-radius: var(--kk-radius);
  background: #fffdf7;
  color: #2b2118;
  font-size: 1.02rem;
  font-weight: 600;
  outline: none;
  box-shadow: 0 4px 0 rgba(22,17,12,0.4);
  transition: background 0.18s, box-shadow 0.18s;
}
.lobby-box input:focus {
  background: #fff;
  box-shadow: 0 4px 0 rgba(22,17,12,0.4), 0 0 0 4px rgba(255,195,29,0.55);
}
.lobby-box input::placeholder { color: rgba(43,33,24,0.45); font-weight: 600; }
.lobby-code input { border-radius: var(--kk-radius-s); font-size: 0.92rem; }

.btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s;
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}
.btn-primary {
  background: linear-gradient(135deg, #e94560, #c23152);
  color: #fff;
  box-shadow: 0 4px 15px rgba(233, 69, 96, 0.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(233, 69, 96, 0.45);
}
.btn-primary:active {
  transform: translateY(0);
}
.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

/* Telephone en paysage : le formulaire d'abord. Le logo rapetisse au lieu de
   sortir de l'ecran, la pastille d'etat rentre dans le flux pour ne plus couvrir
   les liens. */
html[data-short-viewport] #lobby { justify-content: flex-start; padding: max(8px, var(--safe-top)) 0 8px; }
html[data-short-viewport] .lobby-content { margin: 0; gap: 8px; }
/* Cale a gauche de la colonne : au centre, il passait sous les icones du coin. */
html[data-short-viewport] .lobby-brand { width: min(var(--kk-col), 100%); place-items: center start; }
html[data-short-viewport] .lobby-logo { width: min(200px, 28vw); }
html[data-short-viewport] .lobby-subtitle,
html[data-short-viewport] .lobby-hint:empty { display: none; }
html[data-short-viewport] .lobby-status { position: static; margin-top: 2px; }
