/*
 * Chasse-Bulles — zone de jeu (remontée, entraînement, défi du jour).
 * Balisage : includes/jeu-html.php. Toutes les classes sont préfixées chb-
 * pour ne jamais croiser celles du socle partagé.
 */

.chb-jeu {
  width: 100%;
  /* La toile est en 3/4 (debout) : sa largeur est bornée par la HAUTEUR
     disponible, sinon le bas du jeu passe sous l'écran. 70 px = la barre
     d'état et ses marges. */
  max-width: min(560px, calc((100vh - 70px - var(--chb-reserve, 0px)) * 3 / 4));
  margin: 0 auto;
  font-family: 'Inter', sans-serif;
  color: #e0f2fe;
}
@supports (height: 100dvh) {
  .chb-jeu { max-width: min(560px, calc((100dvh - 70px - var(--chb-reserve, 0px)) * 3 / 4)); }
}

/* --- Barre d'état ------------------------------------------------------- */
.chb-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 2px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #bae6fd;
}
.chb-hud-droite { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chb-o2 { display: flex; align-items: center; gap: 8px; min-width: 150px; flex: 1 1 150px; max-width: 240px; }
.chb-o2-icone {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #facc15;
  box-shadow: inset -3px -3px 0 rgba(161, 98, 7, 0.45);
  transition: transform 0.2s;
}
.chb-o2.etroit .chb-o2-icone { transform: scale(0.75); }
.chb-o2-barre {
  position: relative;
  flex: 1;
  height: 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.chb-o2-niveau {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: #22d3ee;
  border-radius: 6px;
}
/* Repère des 70 % : en dessous, le poisson passe dans les fentes d'une case. */
.chb-o2-barre::after {
  content: '';
  position: absolute;
  left: 70%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(4, 30, 46, 0.7);
}
.chb-o2.bas .chb-o2-niveau { background: #f87171; }
.chb-o2.bas .chb-o2-texte { color: #fca5a5; }
.chb-o2-texte { min-width: 42px; font-variant-numeric: tabular-nums; text-align: right; }
.chb-hauteur { color: #a5f3fc; font-variant-numeric: tabular-nums; }
.chb-score { color: #fde68a; font-variant-numeric: tabular-nums; }
.chb-outil {
  min-width: 38px;
  min-height: 32px;
  padding: 2px 8px;
  background: none;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  color: #cbd5e1;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.chb-outil:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.4); }
.chb-outil[hidden] { display: none; }
@media (pointer: coarse) {
  .chb-outil { min-width: 44px; min-height: 40px; font-size: 1.1rem; }
  .chb-hud-droite { gap: 6px; }
}

/* --- Toile -------------------------------------------------------------- */
.chb-cadre {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(34, 211, 238, 0.3);
  background: #0d4a6e;
}
#ecran {
  display: block;
  width: 100%;
  height: 100%;
  /* Hors partie, le doigt fait défiler la page : la toile occupe presque tout
     l'écran d'un téléphone. En partie, il pilote le poisson. */
  touch-action: manipulation;
}
.chb-jeu.en-partie #ecran { touch-action: none; }

/* --- Manche tactile ----------------------------------------------------- */
.chb-manche {
  position: absolute;
  display: none;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(165, 243, 252, 0.45);
  pointer-events: none;
  z-index: 5;
  transform: translate(-50%, -50%);
}
.chb-manche.actif { display: block; }
.chb-manche-bouton {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #0891b2;
  border: 2px solid #a5f3fc;
  transform: translate(-50%, -50%);
}

/* --- Croix et bouton de bulle (écrans tactiles) -------------------------
 * La toile, bornée par la hauteur de l'écran, est souvent plus étroite que
 * lui sur un téléphone : les commandes prennent la largeur de l'ÉCRAN,
 * centrées sous la toile, et rétrécissent avec lui (Android de 360 px). */
.chb-commandes {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: min(calc(100vw - 16px), 440px);
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 4px 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.chb-croix { flex: 0 1 auto; }
.chb-croix-rang { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.chb-croix-btn {
  width: clamp(46px, 15vw, 62px);
  height: clamp(44px, 14vw, 58px);
  padding: 0;
  border-radius: 14px;
  border: 1px solid rgba(165, 243, 252, 0.4);
  background: #0b2f42;
  color: #a5f3fc;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chb-croix-btn.actif, .chb-croix-btn:active { background: #0e7490; }
.chb-bouton-bulle {
  width: clamp(80px, 24vw, 104px);
  height: clamp(80px, 24vw, 104px);
  flex: 0 0 auto;
  border-radius: 50%;
  border: 3px solid #e0f2fe;
  background: rgba(186, 230, 253, 0.22);
  color: #f0f9ff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chb-bouton-bulle.actif, .chb-bouton-bulle:active { background: rgba(186, 230, 253, 0.45); }
@media (pointer: coarse) {
  .chb-commandes { display: flex; }
  /* Place pour les commandes sous la toile : 150 px de moins en hauteur. */
  .chb-jeu { max-width: min(560px, calc((100vh - 230px - var(--chb-reserve, 0px)) * 3 / 4)); }
}
@supports (height: 100dvh) {
  @media (pointer: coarse) { .chb-jeu { max-width: min(560px, calc((100dvh - 230px - var(--chb-reserve, 0px)) * 3 / 4)); } }
}
.chb-jeu.mode-tactile .chb-commandes { display: flex; }

/* Téléphone tenu à l'horizontale, comme une manette : la barre d'état en
   colonne et la croix à gauche, la toile sur toute la hauteur au milieu, la
   bulle à droite. En partie, la barre du compte du réseau s'efface (elle
   reprenait 58 px de hauteur sur 412). */
@media (pointer: coarse) and (orientation: landscape) {
  .chb-jeu {
    max-width: none;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto 1fr;
    align-items: center;
    column-gap: 12px;
  }
  .chb-hud { grid-column: 1; grid-row: 1; flex-direction: column; align-items: stretch; align-self: start; gap: 6px; padding: 4px 0; }
  .chb-hud-droite { justify-content: space-between; }
  .chb-o2 { max-width: none; flex: 0 0 auto; }
  .chb-cadre { grid-column: 2; grid-row: 1 / 3; width: calc((100vh - 12px - var(--chb-reserve, 0px)) * 3 / 4); }
  /* Les deux sélecteurs : `.mode-tactile` (posé au premier toucher) remettait
     la croix et la bulle en bloc par-dessus la grille. */
  .chb-commandes, .chb-jeu.mode-tactile .chb-commandes { display: contents; }
  .chb-croix { grid-column: 1; grid-row: 2; justify-self: center; }
  .chb-bouton-bulle { grid-column: 3; grid-row: 1 / 3; justify-self: center; }
  body.chb-en-partie .auth-nav { display: none; }
  body.chb-en-partie { --chb-reserve: 0px !important; }
}
@supports (height: 100dvh) {
  @media (pointer: coarse) and (orientation: landscape) { .chb-cadre { width: calc((100dvh - 12px - var(--chb-reserve, 0px)) * 3 / 4); } }
}

/* La page défile jusqu'au jeu en laissant la place de la barre du compte. */
.chb-jeu { scroll-margin-top: var(--chb-reserve, 0px); }

/* --- Écrans par-dessus la toile ----------------------------------------- */
.chb-voile {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: rgba(3, 22, 34, 0.9);
  overflow: auto;
}
.chb-voile[hidden] { display: none; }
.chb-carte {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 22px;
  text-align: center;
  background: #0b2a3a;
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-radius: 14px;
}
.chb-carte h2 { margin: 0 0 8px; font-size: 1.45rem; font-weight: 800; color: #a5f3fc; }
.chb-carte p { margin: 0 0 6px; color: #cbe7f3; line-height: 1.45; font-size: 0.93rem; }
.chb-carte p.chb-discret { color: #8fb3c4; font-size: 0.84rem; }
.chb-carte kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.06);
}
.chb-aide { list-style: none; margin: 10px 0 10px; padding: 0; text-align: left; }
.chb-aide li { position: relative; padding-left: 26px; margin-bottom: 7px; font-size: 0.86rem; line-height: 1.45; color: #cbe7f3; }
.chb-pastille { position: absolute; left: 2px; top: 3px; width: 15px; height: 15px; border-radius: 50%; }
.chb-pastille.o2 { background: #facc15; }
.chb-pastille.bulle { background: rgba(186, 230, 253, 0.25); border: 2px solid #f472b6; }
.chb-pastille.air { background: rgba(240, 249, 255, 0.4); border: 2px solid #e0f2fe; }
.chb-record strong, .chb-statut strong { color: #fde68a; }
.chb-message { min-height: 1.2em; color: #fcd34d; font-size: 0.85rem; }
.chb-message:empty { display: none; }
.chb-score-final {
  margin: 8px 0 4px !important;
  font-size: 2rem !important;
  font-weight: 900;
  color: #fde68a !important;
  font-variant-numeric: tabular-nums;
}
.chb-score-final small { font-size: 0.9rem; font-weight: 600; color: #8fb3c4; }
.chb-statut { min-height: 1.4em; font-size: 0.92rem !important; }
.chb-statut:empty { display: none; }
.chb-statut.attente { color: #8fb3c4; }
.chb-statut.ok { color: #bbf7d0; }
.chb-statut.erreur { color: #fca5a5; }
.chb-statut a, .chb-lien-compte { color: #a5f3fc; font-weight: 700; }

.chb-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.chb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid #22d3ee;
  border-radius: 10px;
  background: #0891b2;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.chb-btn:hover { background: #0ea5c9; }
.chb-btn:disabled { opacity: 0.5; cursor: wait; }
.chb-btn.secondaire { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.2); color: #e0f2fe; }
.chb-btn.secondaire:hover { background: rgba(255, 255, 255, 0.14); }
.chb-btn[hidden] { display: none; }

.chb-fermer {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: #8fb3c4;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}
.chb-fermer:hover { color: #fff; }
.chb-retour-resultat {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 8;
  transform: translateX(-50%);
}

/* Entraînement, sous le bouton de la remontée */
.chb-entrainement {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.chb-entrainement-titre { font-size: 0.85rem !important; font-weight: 700; color: #a5f3fc !important; }
.chb-entrainement-choix { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; font-size: 0.9rem; }
.chb-entrainement-choix select {
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #072130;
  color: #e0f2fe;
  font-family: inherit;
  font-size: 0.9rem;
}
.chb-case { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; cursor: pointer; }
.chb-case input { width: 18px; height: 18px; }

/* Selon l'appareil : une seule des deux consignes */
.chb-tactile-seul { display: none; }
@media (pointer: coarse) {
  .chb-clavier-seul { display: none; }
  .chb-tactile-seul { display: block; }
}
.chb-jeu.mode-tactile .chb-clavier-seul { display: none; }
.chb-jeu.mode-tactile .chb-tactile-seul { display: block; }

/* Encart « défi du jour » du module partagé, à l'intérieur de la carte de fin */
.chb-carte #cta-defi-du-jour { margin: 8px 0; padding: 10px 12px; }
.chb-carte .cta-ddj-btn { border-radius: 8px; font-weight: 700; }
.chb-carte .partage-score { margin-top: 6px; }
#voile-fin .chb-carte h2 { margin-bottom: 4px; }
#voile-fin .chb-score-final { margin: 2px 0 2px !important; }
#voile-fin .chb-actions { margin-top: 10px; gap: 8px; }

/*
 * Petits écrans et écrans tactiles : les écrans sortent du cadre de la toile
 * et couvrent toute la fenêtre. Ce bloc doit rester APRÈS la règle générale
 * .chb-voile ci-dessus, sinon il est annulé par elle.
 */
@media (max-width: 520px), (pointer: coarse) {
  .chb-voile { position: fixed; z-index: 1000; padding: 12px; }
  .chb-carte { max-width: 380px; max-height: calc(100vh - 24px); padding: 16px; }
  .chb-carte h2 { font-size: 1.25rem; }
  .chb-carte p { font-size: 0.9rem; }
  .chb-score-final { font-size: 1.6rem !important; }
}
@supports (height: 100dvh) {
  @media (max-width: 520px), (pointer: coarse) {
    .chb-carte { max-height: calc(100dvh - 24px); }
  }
}

/* --- Plein écran -------------------------------------------------------- */
.chb-jeu:fullscreen {
  max-width: none;
  width: 100vw;
  height: 100vh;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #031622;
}
.chb-jeu:fullscreen .chb-hud { width: 100%; max-width: calc((100vh - 60px) * 3 / 4); }
.chb-jeu:fullscreen .chb-cadre { width: calc((100vh - 60px) * 3 / 4); }
@media (pointer: coarse) {
  .chb-jeu:fullscreen .chb-cadre { width: min(100%, calc((100vh - 220px) * 3 / 4)); }
}

/* Pendant la partie, les blocs « Infos » et « Jeux à la une » du réseau
   s'effacent ; ils reviennent sur l'écran de fin. */
body.chb-en-partie .bandeau-infos-wrap,
body.chb-en-partie .bloc-jeux-une-wrap { display: none !important; }

/* Badges et points gagnés : posés en bas de l'écran, ils ne recouvrent plus
   le statut ni l'encart du défi de la carte de fin (le module partagé les
   centre au milieu de l'écran). */
.page-chasse-bulles .recomp-toasts {
  top: auto;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
}

/* --- Course fantôme ------------------------------------------------------ */
.chb-course-panneau { margin: 10px 0 4px; text-align: center; }
.chb-course-champ { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 0.9rem; color: #cbe7f3; }
.chb-course-champ input, .chb-course-code input {
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #072130;
  color: #e0f2fe;
  font: inherit;
  font-size: 0.95rem;
}
.chb-course-champ input { width: 11em; }
.chb-course-code { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 12px 0 6px; font-size: 0.88rem; color: #cbe7f3; }
.chb-course-code input { width: 6.5em; text-transform: uppercase; letter-spacing: 0.12em; text-align: center; }
.chb-course-tete { font-weight: 700; }
.chb-course-codesalon { font-size: 1.2rem; letter-spacing: 0.14em; color: #fde68a; }
.chb-course-joueurs { list-style: none; margin: 10px auto; padding: 0; max-width: 280px; text-align: left; }
.chb-course-joueurs li { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 0.92rem; color: #e0f2fe; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.chb-course-pastille { display: inline-block; flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; }
.chb-teinte-0 { background: #f472b6; }
.chb-teinte-1 { background: #4ade80; }
.chb-teinte-2 { background: #fb923c; }
.chb-teinte-3 { background: #a78bfa; }
.chb-course-direct {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 4;
  margin: 0;
  padding: 5px 8px;
  list-style: none;
  border-radius: 8px;
  background: rgba(3, 22, 34, 0.6);
  font-size: 0.72rem;
  line-height: 1.5;
  color: #e0f2fe;
  pointer-events: none;
}
.chb-course-direct[hidden] { display: none; }
.chb-course-direct li { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.chb-course-direct .chb-course-pastille { width: 8px; height: 8px; }
.chb-course-resultats { list-style: none; margin: 8px 0; padding: 0; text-align: left; }
.chb-course-resultats[hidden] { display: none; }
.chb-course-resultats li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 0.9rem; }
.chb-course-resultats li.moi { background: rgba(250, 204, 21, 0.08); }
.chb-course-place { width: 2.2em; font-weight: 800; color: #fde68a; }
.chb-course-nom { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e0f2fe; }
.chb-course-score { color: #8fb3c4; font-size: 0.82rem; white-space: nowrap; }