/*
 * Billard Extrême — pages de jeu (solo, défi du jour, multijoueur).
 *
 * Tout le CSS des pages de jeu vit ici, jamais en style inline dans le PHP.
 *
 * Deux contraintes de fond :
 *  - le tapis est un canvas dont le rapport est fixe (deux fois plus long que
 *    large) : la mise en page doit le laisser respirer, et surtout ne jamais lui
 *    imposer une hauteur, sinon il se déforme ;
 *  - les commandes doivent rester atteignables au pouce sur mobile, sous le
 *    tapis, sans que la page ait besoin de défiler pendant une partie.
 *
 * Perf : pas de backdrop-filter sur un conteneur permanent, pas de box-shadow
 * animé en boucle. Cf. les pièges relevés sur les jeux précédents.
 */

/* ================= MISE EN PAGE ================= */

/*
 * Le padding horizontal ne descend JAMAIS sous 24 px, y compris sur téléphone.
 *
 * Le banner partagé porte des marges négatives de -28px -24px, qui sont faites
 * pour manger exactement ce padding et venir affleurer les bords du conteneur.
 * Avec moins, il déborde de la page et provoque un défilement horizontal — ce
 * qu'a montré la mesure dans un Chrome en 390 px de large.
 */
#app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

.cache { display: none !important; }

/* ================= ÉCRAN DE RÉGLAGES ================= */

#setup {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(126, 242, 196, 0.22);
  border-radius: 16px;
  padding: 26px 24px 30px;
  margin-bottom: 24px;
}

#setup h1 {
  margin: 0 0 10px;
  font-size: 1.6rem;
  color: var(--color-light);
}

.setup-intro {
  margin: 0 0 22px;
  line-height: 1.7;
  color: #b9d3c8;
}

.setup-bloc { margin-bottom: 22px; }

.setup-bloc h2 {
  font-size: 1.02rem;
  margin: 0 0 10px;
  color: var(--color-accent);
  letter-spacing: 0.02em;
}

.choix-ligne {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.carte-choix {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.03);
  color: #e7f5ef;
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 56px;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}

.carte-choix:hover { border-color: rgba(126, 242, 196, 0.5); transform: translateY(-1px); }
.carte-choix:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.carte-choix.actif {
  border-color: var(--color-light);
  background: color-mix(in srgb, var(--color-mid) 22%, transparent);
}

.choix-nom { display: block; font-weight: 700; margin-bottom: 3px; }
.choix-detail { display: block; font-size: 0.86rem; color: #9db9ae; line-height: 1.5; }

.btn-demarrer {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 16px 20px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-btn1), var(--color-btn2));
  color: #f2fffa;
  font-size: 1.08rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 56px;
}

.btn-demarrer:disabled { opacity: 0.55; cursor: default; }
.btn-demarrer:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

/* ================= LE TAPIS ================= */

#jeu {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(126, 242, 196, 0.2);
  border-radius: 16px;
  padding: 16px;
}

.bandeau-partie {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.94rem;
}

#score-courant { font-weight: 700; color: var(--color-light); }

#restantes { display: flex; flex-wrap: wrap; gap: 14px; }

.be-camp { display: inline-flex; align-items: center; gap: 6px; color: #cfe6dc; }
.be-camp b { color: #fff; }

.be-pastille {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #6b7b74;
  box-shadow: inset 1px -1px 2px rgba(0, 0, 0, 0.5), inset -2px 2px 3px rgba(255, 255, 255, 0.3);
}

.be-groupe-rouge  .be-pastille { background: #e23b3b; }
.be-groupe-jaune  .be-pastille { background: #f2c53d; }
.be-groupe-pleine .be-pastille { background: #e23b3b; }
.be-groupe-rayee  .be-pastille { background: linear-gradient(#f4f4ee 0 30%, #e8853a 30% 70%, #f4f4ee 70% 100%); }

.be-compteur { color: var(--color-light); font-weight: 700; }

.tapis-zone {
  display: flex;
  justify-content: center;
  /* Le canvas se dimensionne tout seul d'après la largeur du parent : ne rien
     lui imposer ici, ni hauteur ni ratio. */
}

#tapis {
  display: block;
  border-radius: 10px;
  touch-action: none;      /* sinon un glissement de visée fait défiler la page */
  cursor: crosshair;
  max-width: 100%;
}

/* ================= COMMANDES ================= */

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px 16px;
  margin-top: 12px;
}

#consigne {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 20px;
  font-size: 0.92rem;
  color: #9db9ae;
}

#tour {
  grid-column: 1 / -1;
  margin: 0;
  font-weight: 700;
  color: #e7f5ef;
}

/* Pastille d'effet : la blanche vue de face. */
.effet-pad {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffffff 0%, #e8e8e0 45%, #b9b9ad 100%);
  border: 2px solid rgba(126, 242, 196, 0.45);
  cursor: pointer;
  touch-action: none;
  flex: 0 0 auto;
}

.effet-pad::before,
.effet-pad::after {
  content: '';
  position: absolute;
  background: rgba(0, 0, 0, 0.16);
}
.effet-pad::before { left: 50%; top: 8%; bottom: 8%; width: 1px; }
.effet-pad::after  { top: 50%; left: 8%; right: 8%; height: 1px; }

.effet-point {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 15px;
  height: 15px;
  margin: -7.5px 0 0 -7.5px;
  border-radius: 50%;
  background: #ff5d8f;
  border: 2px solid #fff;
  pointer-events: none;
}

.effet-legende { font-size: 0.8rem; color: #9db9ae; text-align: center; margin-top: 4px; }

.bloc-puissance { min-width: 0; }

.bloc-puissance label {
  display: block;
  font-size: 0.86rem;
  color: #9db9ae;
  margin-bottom: 4px;
}

#puissance {
  width: 100%;
  accent-color: var(--color-light);
  height: 30px;
}

.jauge-fond {
  height: 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  margin-top: 4px;
}

.jauge-fond span {
  display: block;
  height: 100%;
  width: 45%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--color-mid), var(--color-accent));
}

.btn-tirer {
  padding: 16px 26px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-accent), #c93b68);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  min-height: 56px;
  min-width: 120px;
}

.btn-tirer:disabled { opacity: 0.4; cursor: default; }
.btn-tirer:focus-visible { outline: 2px solid var(--color-light); outline-offset: 2px; }

/* ================= ANNONCE DE POCHE ================= */

.choix-poche {
  grid-column: 1 / -1;
  border: 1px solid rgba(255, 93, 143, 0.45);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255, 93, 143, 0.08);
}

.choix-poche p { margin: 0 0 8px; font-size: 0.9rem; color: #ffd6e3; }

.poches-grille {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 340px;
}

.poches-grille button {
  padding: 10px 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: #ffe7ef;
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  min-height: 46px;
}

.poches-grille button.choisie {
  border-color: var(--color-accent);
  background: rgba(255, 93, 143, 0.28);
  font-weight: 700;
}

/* ================= MESSAGES ================= */

#message {
  margin-top: 12px;
  min-height: 22px;
  font-size: 0.96rem;
  color: var(--color-light);
}

#message.erreur { color: #ff9ab5; }

.barre-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.btn-secondaire {
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9px;
  background: transparent;
  color: #cfe6dc;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-secondaire:hover { border-color: var(--color-light); color: #fff; }

/* ================= DÉCISION (noire à la casse) ================= */

.decision {
  grid-column: 1 / -1;
  border: 1px solid rgba(126, 242, 196, 0.5);
  border-radius: 12px;
  padding: 14px 16px;
  background: rgba(20, 184, 138, 0.12);
}

.decision p { margin: 0 0 10px; line-height: 1.6; }
.decision .decision-boutons { display: flex; flex-wrap: wrap; gap: 10px; }

.decision button {
  padding: 12px 18px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--color-btn1), var(--color-btn2));
  color: #f2fffa;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}

/* ================= OVERLAY DE FIN ================= */

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 12, 10, 0.82);
  z-index: 60;
}

.overlay.visible { display: flex; }

.overlay-carte {
  width: min(460px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  border: 1px solid rgba(126, 242, 196, 0.35);
  border-radius: 16px;
  padding: 26px 24px;
  background: linear-gradient(165deg, #123f34 0%, #0a1f1b 100%);
  text-align: center;
}

.overlay-carte h2 { margin: 0 0 6px; font-size: 1.5rem; color: var(--color-light); }
.overlay-sous { margin: 0 0 16px; color: #b9d3c8; }

.stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.95rem;
}

.stat:last-child { border-bottom: 0; }
.stat-libelle { color: #9db9ae; }
.stat-valeur { font-weight: 700; color: #fff; }

.validation {
  margin: 14px 0 4px;
  font-size: 0.86rem;
  color: #9db9ae;
  line-height: 1.5;
}

.validation.ok { color: var(--color-light); }
.validation.ko { color: #ff9ab5; }

.overlay-boutons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.overlay-boutons .btn-cta {
  padding: 14px 22px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--color-btn1), var(--color-btn2));
  color: #f2fffa;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

/* ================= MULTIJOUEUR ================= */

.joueurs-liste {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.joueur-puce {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.86rem;
  color: #cfe6dc;
}

/* Les deux camps se distinguent par une pastille de couleur, pas par la seule
   position dans la liste : à quatre, l'ordre de passage alterne les équipes. */
.joueur-puce::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #7ef2c4;
}

.joueur-puce.camp-1::before { background: #ff5d8f; }
.joueur-puce.actif { border-color: var(--color-light); background: rgba(126, 242, 196, 0.16); color: #fff; }
.joueur-puce.absent { opacity: 0.55; font-style: italic; }
.joueur-puce.vide { opacity: 0.45; font-style: italic; }
.joueur-puce.vide::before { background: transparent; border: 1px dashed rgba(255, 255, 255, 0.4); }

.chrono {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #9db9ae;
  min-width: 44px;
  text-align: right;
}

.chrono.urgent { color: var(--color-accent); }

.salon-prive {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.rejoindre-code {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.rejoindre-code label {
  display: block;
  width: 100%;
  font-size: 0.86rem;
  color: #9db9ae;
  margin-bottom: 4px;
}

#champ-code {
  width: 110px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-align: center;
  min-height: 48px;
}

.code-partage {
  margin: 16px 0;
  padding: 14px 18px;
  border: 1px dashed rgba(126, 242, 196, 0.5);
  border-radius: 12px;
  text-align: center;
}

.code-partage p { margin: 0 0 6px; color: #9db9ae; font-size: 0.9rem; }

.code-valeur {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--color-light);
  margin: 0 !important;
}

#attente { text-align: center; }
#attente .joueurs-liste { justify-content: center; margin: 14px 0; }

/* ================= MOBILE ================= */

@media (max-width: 720px) {
  /* Le padding horizontal reste à 24 px : voir la note en tête de fichier. */
  #app { padding: 20px 24px 30px; }
  #jeu { padding: 12px 10px; }
  .hud { grid-template-columns: auto 1fr; gap: 12px; }
  .btn-tirer { grid-column: 1 / -1; width: 100%; }
  .effet-pad { width: 62px; height: 62px; }
  .poches-grille { max-width: none; }
}

/*
 * Pendant une partie, les blocs latéraux fixes (bandeau Infos et Jeux à la une)
 * recouvriraient le tapis sur les écrans juste assez larges pour les afficher.
 * On les masque le temps du jeu, et ils reviennent à la fin.
 */
body.billard-en-jeu .bandeau-infos-wrap,
body.billard-en-jeu .bloc-jeux-une-wrap {
  display: none !important;
}
