/* La course des pigeons : couleurs franches, la police du K.F.P. (Nunito), ni lueur ni flou. */
:root {
  --encre: #1b1530;
  --papier: #fffaf0;
  --jaune: #ffd23f;
  --rouge: #e0303a;
  --bleu: #2a7bff;
  --vert: #2fdc8c;
  --gris: #5b6378;
  /* Les zones sûres : celles du téléphone (encoche, barre de geste) et celles de Discord mobile (ses bandeaux). */
  --g: max(env(safe-area-inset-left, 0px), var(--discord-safe-area-inset-left, 0px));
  --d: max(env(safe-area-inset-right, 0px), var(--discord-safe-area-inset-right, 0px));
  --b: max(env(safe-area-inset-bottom, 0px), var(--discord-safe-area-inset-bottom, 0px));
  --h: max(env(safe-area-inset-top, 0px), var(--discord-safe-area-inset-top, 0px));
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd0ff; color: var(--encre); font-family: "Nunito", system-ui, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui button, #ui .zone-joystick, #ui .carte { pointer-events: auto; }

#chargement { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; background: var(--bleu); color: var(--papier); }
#chargement h1 { font-size: clamp(28px, 6vw, 52px); margin: 0 0 8px; font-weight: 900; }
#chargement p { font-size: 18px; margin: 0; font-weight: 700; }
#chargement.erreur { background: var(--rouge); }

/* Le haut de l'écran */
/* La barre du haut : une seule bande, des cases de même hauteur séparées par un trait. */
.barre { position: absolute; top: calc(8px + var(--h)); left: 50%; transform: translateX(-50%); width: min(calc(100% - 20px - var(--g) - var(--d)), 720px); height: 46px; display: flex; align-items: stretch; background: var(--papier); border: 2px solid var(--encre); border-radius: 10px; box-shadow: 0 3px 0 var(--encre); overflow: hidden; }
.case { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 0 12px; border-left: 2px solid var(--encre); min-width: 0; }
.case:first-child { border-left: 0; }
.case.moi { flex: 1 1 0; justify-content: flex-start; }
.case.temps { flex: 0 0 auto; min-width: 72px; }
.case.equipes { flex: 1 1 0; justify-content: flex-end; gap: 12px; }
.valeur { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case.temps .valeur { align-items: center; }
.valeur small, .equipe small { font-size: 11px; font-weight: 800; color: var(--gris); text-transform: uppercase; letter-spacing: 0.04em; }
.valeur b { font-size: 18px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; }
.equipe { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.equipe i { width: 12px; height: 12px; border-radius: 3px; border: 2px solid var(--encre); display: inline-block; }
.equipe.c i { background: var(--bleu); }
.equipe.p i { background: var(--rouge); }
.equipe b { font-size: 18px; font-weight: 900; min-width: 1.2em; text-align: right; }
.equipe .court { display: none; }
.case.son { flex: 0 0 46px; padding: 0; font: inherit; background: transparent; border-top: 0; border-right: 0; border-bottom: 0; color: var(--encre); cursor: pointer; }
.case.son .barre-son { display: none; }
.case.son.coupe .barre-son { display: inline; }
.case.son.coupe .ondes { display: none; }
.case.son.coupe { color: var(--gris); }
.grand { position: absolute; top: 28%; left: 0; right: 0; text-align: center; font-size: clamp(56px, 14vw, 140px); font-weight: 900; color: var(--jaune); -webkit-text-stroke: 4px var(--encre); paint-order: stroke fill; }
.grand.pop { animation: pop 0.5s ease-out; }
@keyframes pop { from { transform: scale(1.5); } to { transform: scale(1); } }
.messages { position: absolute; top: calc(112px + var(--h)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(92vw, 560px); }
.message { background: var(--papier); border: 3px solid var(--encre); border-radius: 10px; padding: 5px 12px; font-weight: 800; font-size: clamp(13px, 2vw, 17px); animation: entre 0.2s ease-out; text-align: center; }
.message.bien { background: var(--vert); }
.message.mal { background: var(--jaune); }
@keyframes entre { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.lien { display: none; position: absolute; bottom: calc(12px + var(--b)); left: 50%; transform: translateX(-50%); background: var(--rouge); color: var(--papier); border: 3px solid var(--encre); border-radius: 10px; padding: 6px 12px; font-weight: 800; }

/* Les cartes : lobby et résultats */
.carte { position: absolute; top: calc(64px + var(--h)); left: 50%; transform: translateX(-50%); width: min(94vw, 720px); max-height: calc(100% - 64px - var(--h) - var(--b)); overflow: auto; background: var(--papier); border: 4px solid var(--encre); border-radius: 14px; padding: 14px 18px; box-shadow: 0 5px 0 var(--encre); display: none; }
.carte h1 { margin: 0 0 6px; font-size: clamp(22px, 4vw, 34px); font-weight: 900; }
.carte h2 { margin: 0 0 6px; font-size: 17px; font-weight: 900; }
.regle { margin: 0 0 10px; font-weight: 700; font-size: 15px; }
.colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.liste { margin: 0; padding-left: 22px; font-weight: 800; font-size: 15px; }
.liste li { margin: 3px 0; }
.liste small { margin-left: 6px; color: var(--gris); font-weight: 700; }
.pigeon { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 3px solid; margin-right: 6px; vertical-align: -2px; }
.boutons { display: flex; gap: 10px; margin: 12px 0 6px; flex-wrap: wrap; }
.bouton { font: inherit; font-weight: 900; font-size: 17px; padding: 10px 16px; border: 3px solid var(--encre); border-radius: 10px; background: var(--papier); color: var(--encre); box-shadow: 0 4px 0 var(--encre); cursor: pointer; }
.bouton.principal { background: var(--jaune); }
.bouton:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--encre); }
.statut { font-weight: 800; margin: 6px 0; }
.aide { color: var(--gris); font-weight: 700; font-size: 14px; margin: 6px 0 0; }

/* Les commandes */
.commandes { display: none; position: absolute; inset: 0; }
.zone { position: absolute; bottom: calc(14px + var(--b)); display: flex; gap: 12px; align-items: flex-end; }
.zone.gauche { left: calc(14px + var(--g)); }
.zone.droite { right: calc(14px + var(--d)); }
.rond { font: inherit; font-weight: 900; font-size: 18px; width: 86px; height: 86px; border-radius: 50%; border: 4px solid var(--encre); background: var(--papier); color: var(--encre); box-shadow: 0 4px 0 var(--encre); display: flex; align-items: center; justify-content: center; touch-action: none; cursor: pointer; }
.rond.petit { width: 68px; height: 68px; font-size: 15px; }
.rond.appuye { transform: translateY(3px); box-shadow: 0 1px 0 var(--encre); background: var(--jaune); }
.rond.objet { background: var(--rouge); color: var(--papier); font-size: 38px; }
.aide-clavier { position: absolute; bottom: calc(10px + var(--b)); left: 50%; transform: translateX(-50%); font-weight: 800; font-size: 13px; background: var(--papier); border: 2px solid var(--encre); border-radius: 8px; padding: 3px 8px; white-space: nowrap; }
.tactile .aide-clavier { display: none; }
#ui:not(.tactile) .conduite .zone.droite .rond:not(.objet) { display: none; }
.rond.derapage { padding: 0; flex-direction: column; }
.rond.derapage svg { display: block; }
.rond.derapage .mot { font-size: 13px; line-height: 1; margin-top: -3px; }
.regime { position: absolute; bottom: calc(120px + var(--b)); left: 50%; transform: translateX(-50%); width: min(60vw, 320px); height: 22px; background: var(--papier); border: 3px solid var(--encre); border-radius: 8px; }
.regime .vert { position: absolute; left: 60%; width: 26%; top: 0; bottom: 0; background: var(--vert); }
.regime .aiguille { position: absolute; top: -6px; bottom: -6px; width: 6px; margin-left: -3px; background: var(--rouge); border: 2px solid var(--encre); z-index: 1; }

.vol > * { z-index: 1; position: absolute; }

/* Le joystick (repris du Vol du jour des abeilles) : la moitié gauche reçoit le pouce, sous le haut de l'écran. */
.zone-joystick { display: none; position: absolute; left: 0; width: 50%; top: calc(96px + var(--h)); bottom: 0; touch-action: none; z-index: 0; }
.joy-base, .joy-bouton, .joy-nom { display: none; position: absolute; left: 0; top: 0; pointer-events: none; will-change: transform; }
.joy-base { width: 144px; height: 144px; border-radius: 50%; background: rgba(27, 21, 48, 0.22); border: 4px solid rgba(255, 255, 255, 0.75); }
.joy-base.tenu { background: rgba(27, 21, 48, 0.35); }
.joy-bouton { width: 60px; height: 60px; border-radius: 50%; background: rgba(255, 210, 63, 0.8); border: 4px solid var(--encre); box-sizing: border-box; }
.joy-bouton.tenu { background: var(--jaune); }
.joy-nom { width: 120px; text-align: center; font-weight: 900; font-size: 14px; color: var(--papier); -webkit-text-stroke: 3px var(--encre); paint-order: stroke fill; }
.sonde-zones { position: absolute; visibility: hidden; pointer-events: none; padding: var(--h) 0 var(--b) 0; }

/* « Tourne ton téléphone » : le conducteur en portrait. */
.carte.tourne { top: 50%; transform: translate(-50%, -50%); width: min(86vw, 360px); text-align: center; }
.tourne p { font-weight: 800; font-size: 17px; margin: 6px 0 12px; }
.tourne-picto { font-size: 54px; line-height: 1; font-weight: 900; }
/* Les karts à suivre, sous la barre : une ligne, le kart suivi en jaune. */
.suivre { top: calc(62px + var(--h)); left: 50%; transform: translateX(-50%); width: min(calc(100% - 20px), 720px); display: flex; align-items: center; gap: 8px; }
.suivre-nom { font-weight: 900; font-size: 13px; color: var(--papier); -webkit-text-stroke: 3px var(--encre); paint-order: stroke fill; white-space: nowrap; }
.cibles { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.cibles::-webkit-scrollbar { display: none; }
.cible { font: inherit; font-weight: 900; font-size: 13px; height: 32px; padding: 0 10px; display: flex; align-items: center; gap: 6px; border: 2px solid var(--encre); border-radius: 8px; background: var(--papier); color: var(--encre); cursor: pointer; white-space: nowrap; box-shadow: 0 2px 0 var(--encre); }
.cible i { width: 12px; height: 12px; border-radius: 3px; border: 2px solid var(--encre); }
.cible.choisie { background: var(--jaune); }

/* Le spectateur : le conducteur arrivé regarde les autres. */
.spectateur { display: none; position: absolute; bottom: calc(48px + var(--b)); left: 50%; transform: translateX(-50%); align-items: center; gap: 10px; background: var(--papier); border: 2px solid var(--encre); border-radius: 10px; padding: 6px 6px 6px 12px; font-weight: 900; box-shadow: 0 3px 0 var(--encre); white-space: nowrap; }
.spectateur .bouton { font-size: 14px; padding: 6px 10px; box-shadow: 0 2px 0 var(--encre); }
.reserve { left: calc(14px + var(--g)); bottom: calc(18px + var(--b)); background: var(--papier); border: 3px solid var(--encre); border-radius: 10px; padding: 5px 10px; font-weight: 900; width: 210px; }
/* Sur téléphone, la réserve monte en haut à gauche : le bas est au joystick et aux boutons. */
.tactile .reserve { top: calc(104px + var(--h)); bottom: auto; width: 170px; }
.reserve .jauge { margin-top: 4px; height: 12px; border: 2px solid var(--encre); border-radius: 6px; overflow: hidden; background: #e9e2cf; }
.reserve .plein { height: 100%; background: var(--vert); }
.rond.fiente, .rond.mega { background: conic-gradient(var(--jaune) var(--pret, 0%), #e9e2cf 0); }
.rond.fiente { width: 104px; height: 104px; font-size: 20px; }
.rond.fiente.pret { background: var(--jaune); }
.rond.mega.pret { background: var(--rouge); color: var(--papier); }

/* Le pare-brise sali et l'essuie-glace */
.pare-brise { display: none; position: absolute; inset: 0; }
.tache { position: absolute; background: #f4f1e6; border: 4px solid #d9d4c0; border-radius: 48% 52% 45% 55% / 55% 45% 55% 45%; }
.tache:nth-child(1) { left: 18%; top: 22%; width: 26vw; height: 20vw; }
.tache:nth-child(2) { left: 46%; top: 30%; width: 22vw; height: 18vw; border-radius: 55% 45% 60% 40%; }
.tache:nth-child(3) { left: 30%; top: 50%; width: 18vw; height: 12vw; }
.tache:nth-child(4) { left: 62%; top: 14%; width: 14vw; height: 12vw; border-radius: 40% 60% 50% 50%; }
.tache:nth-child(5) { left: 8%; top: 52%; width: 12vw; height: 10vw; }
.tache:nth-child(6) { left: 70%; top: 48%; width: 15vw; height: 11vw; }
.tache:nth-child(7) { left: 40%; top: 10%; width: 20vw; height: 14vw; }
.tache:nth-child(8) { left: 2%; top: 18%; width: 16vw; height: 18vw; }
.tache:nth-child(9) { left: 80%; top: 24%; width: 16vw; height: 22vw; }
.balai { position: absolute; left: 50%; bottom: -10vh; width: 8px; height: 120vh; background: var(--encre); transform-origin: 50% 100%; transform: rotate(-80deg); opacity: 0; }
.balai.passe { animation: balai 0.6s ease-in-out; }
@keyframes balai { 0% { opacity: 1; transform: rotate(-80deg); } 50% { transform: rotate(80deg); } 100% { opacity: 1; transform: rotate(-80deg); } }

@media (max-width: 640px) {
  .equipe .long { display: none; }
  .equipe .court { display: inline; }
  .case { padding: 0 8px; gap: 10px; }
  .case.equipes { gap: 8px; }
  .valeur b, .equipe b { font-size: 16px; }
  .case.temps { min-width: 58px; }
}
@media (max-width: 380px) {
  .equipe small { display: none !important; }
}
@media (max-width: 560px), (max-height: 420px) {
  .rond { width: 70px; height: 70px; font-size: 13px; }
  .rond.derapage svg { width: 32px; height: 32px; }
  .rond.fiente { width: 84px; height: 84px; }
  .carte { padding: 10px 12px; }
  .colonnes { gap: 8px; }
  .liste { font-size: 13px; }
  .regle { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { .grand.pop, .message, .balai.passe { animation: none; } }
