/*
 * Sautebois — pages où l'on joue (solo, défi du jour) et zone de jeu.
 *
 * Contraintes du réseau :
 *   - #app reste à 800 px hors partie : au-delà, les blocs latéraux fixes
 *     (Infos, Jeux à la une) recouvrent le contenu dès 1280 px. Pendant la
 *     partie ils sont masqués, et la zone de jeu peut s'élargir.
 *   - padding horizontal de #app jamais sous 24 px : le banner partagé sort
 *     du conteneur avec des marges négatives calées sur cette valeur.
 */

* { box-sizing: border-box; }

body.page-sautebois {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, #22381c 0%, #142312 55%, #0b140a 100%);
  color: #ecfccb;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.page-sautebois #app {
  max-width: 800px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

.page-sautebois h1 { font-size: 1.6rem; color: #d9f99d; margin: 8px 0 12px; text-align: center; }
.page-sautebois h2 { font-size: 1.1rem; color: #bef264; margin: 18px 0 8px; }
.page-sautebois a { color: #fde68a; }

.setup-intro {
  color: #d1d5c4;
  line-height: 1.6;
  font-size: 0.95rem;
  text-align: center;
  margin: 0 auto 18px;
  max-width: 62ch;
}
.message-partie { min-height: 1.2em; text-align: center; color: #fcd34d; font-size: 0.92rem; margin: 10px 0; }
.resume-progression { text-align: center; color: #e2e8d0; font-size: 0.92rem; margin: 0 0 14px; }
.lien-defi { text-align: center; margin: 22px 0 6px; }
.monde-titre { text-align: center; }

/* ---- Choix du niveau ----------------------------------------------------- */
.choix-niveaux {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin: 12px 0 10px;
}
.niveau-carte {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 118px;
  padding: 12px 10px;
  border-radius: 14px;
  border: 2px solid #65a30d;
  background: #1f3a14;
  color: #ecfccb;
  font: inherit;
  cursor: pointer;
  text-align: center;
}
.niveau-carte:hover, .niveau-carte:focus-visible { background: #2a4d1b; outline: none; border-color: #bef264; }
.niveau-carte.fini { border-color: #fbbf24; }
.niveau-carte.verrouille { opacity: 0.55; cursor: not-allowed; border-style: dashed; }
.niveau-num { font-size: 1.7rem; font-weight: 800; color: #fde68a; line-height: 1; }
.niveau-nom { font-weight: 700; font-size: 0.95rem; }
.niveau-info, .niveau-glands { font-size: 0.8rem; color: #d1d5c4; }

/* ---- Zone de jeu dans la page --------------------------------------------- */
.zone-jeu { margin: 6px auto 18px; }
.zone-jeu[hidden] { display: none; }
.zone-jeu .sautebois {
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  max-height: calc(100vh - 40px);
}
/* Pendant une partie : la page s'élargit (les blocs latéraux sont masqués). */
body.sb-en-partie .bandeau-infos-wrap,
body.sb-en-partie .bloc-jeux-une-wrap { display: none !important; }
body.sb-en-partie #app { max-width: 1180px; }

/* Téléphone (ou petite fenêtre tactile) : le jeu prend tout l'écran. */
@media (pointer: coarse) and (max-height: 600px), (pointer: coarse) and (max-width: 700px) {
  body.sb-en-partie { overflow: hidden; }
  /* La barre de compte (fixe, en haut à droite) recouvrirait les boutons du
   * jeu et le chrono : on la masque le temps de la partie. */
  body.sb-en-partie .auth-nav { display: none !important; }
  body.sb-en-partie .zone-jeu .sautebois {
    position: fixed;
    inset: 0;
    z-index: 1000;
    aspect-ratio: auto;
    max-height: none;
    border-radius: 0;
  }
}

/* ========================================================================== */
/* Sautebois : zone de jeu, commandes tactiles, écrans de début, pause et fin. */

.sautebois {
  --sb-fond: #1e1423;
  --sb-carte: rgba(30, 20, 35, 0.94);
  --sb-texte: #fff6e6;
  --sb-accent: #ffd86b;
  --sb-bouton: #53b339;
  --sb-bouton-texte: #10240c;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--sb-fond);
  color: var(--sb-texte);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.sautebois canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

/* ---- Barre d'outils ------------------------------------------------------ */
.sb-outils {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 3;
}
.sb-outils button {
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  background: rgba(30, 20, 35, 0.55);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.sb-outils button[hidden] { display: none; }
.sb-outils button.coupee { text-decoration: line-through; opacity: 0.6; }
.sb-outils button:focus-visible { outline: 3px solid var(--sb-accent); outline-offset: 2px; }
.sautebois:not(.partie-lancee) #btn-pause { visibility: hidden; }

/* ---- Commandes tactiles -------------------------------------------------- */
.sb-tactile {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  touch-action: none;
  pointer-events: none;
}
.sautebois.mode-tactile.partie-lancee .sb-tactile { display: block; pointer-events: auto; }

.sb-tactile button {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: clamp(64px, 17vmin, 104px);
  height: clamp(64px, 17vmin, 104px);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.9);
  font-size: clamp(24px, 6vmin, 38px);
  line-height: 1;
  padding: 0;
  pointer-events: none;   /* c'est la zone qui écoute, pas le bouton */
}
.sb-tactile button.appuye { background: rgba(255, 255, 255, 0.4); border-color: #fff; }
.sb-tactile [data-b="gauche"] { left: max(14px, env(safe-area-inset-left)); }
.sb-tactile [data-b="droite"] { left: calc(max(14px, env(safe-area-inset-left)) + clamp(64px, 17vmin, 104px) + 14px); }
.sb-tactile [data-b="saut"] {
  right: max(18px, env(safe-area-inset-right));
  width: clamp(76px, 21vmin, 124px);
  height: clamp(76px, 21vmin, 124px);
}

/* ---- Voiles (début, pause, fin, rotation) -------------------------------- */
.sb-voile {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(20, 12, 24, 0.55);
  touch-action: auto;
}
.sb-voile[hidden] { display: none; }
.sb-carte {
  max-width: 460px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 18px 20px;
  border-radius: 16px;
  background: var(--sb-carte);
  border: 2px solid rgba(255, 216, 107, 0.5);
  text-align: center;
}
.sb-carte h2 { margin: 0 0 8px; font-size: 1.4rem; color: var(--sb-accent); }
.sb-carte p { margin: 6px 0; line-height: 1.45; }
.sb-sous-titre { opacity: 0.85; }
.sb-note { font-size: 0.85rem; opacity: 0.8; }
.sb-commandes { font-size: 0.92rem; opacity: 0.9; }
.sb-commandes kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.1);
  font: inherit;
  font-size: 0.85em;
}
.sautebois.mode-tactile .sb-clavier-seul { display: none; }
.sautebois:not(.mode-tactile) .sb-tactile-seul { display: none; }

.sb-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.sb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 20px;
  border: 0;
  border-radius: 12px;
  background: var(--sb-bouton);
  color: var(--sb-bouton-texte);
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
}
.sb-btn.secondaire { background: rgba(255, 255, 255, 0.14); color: var(--sb-texte); }
.sb-btn:focus-visible { outline: 3px solid var(--sb-accent); outline-offset: 2px; }
.sb-btn[hidden] { display: none; }

.bilan table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.bilan th, .bilan td { padding: 4px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.12); font-size: 0.95rem; }
.bilan td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bilan small { opacity: 0.75; }
.bilan tfoot th, .bilan tfoot td { font-size: 1.15rem; color: var(--sb-accent); border: 0; }
.bilan .morts { font-size: 0.85rem; opacity: 0.8; }
.sb-fin-statut { min-height: 1.3em; font-size: 0.92rem; }
.sb-fin-statut.attente { opacity: 0.8; }
.sb-fin-statut.ok { color: #bef264; }
.sb-fin-statut.erreur { color: #fca5a5; }
.sb-fin-statut a { color: #fde68a; }

.sb-tourner { background: var(--sb-fond); z-index: 5; flex-direction: column; text-align: center; }
.sb-tourner .icone { font-size: 56px; display: block; margin-bottom: 8px; }

/* Petits écrans en paysage : cartes plus compactes pour tenir en hauteur. */
@media (max-height: 420px) {
  .sb-carte { padding: 10px 14px; }
  .sb-carte h2 { font-size: 1.15rem; margin-bottom: 4px; }
  .bilan th, .bilan td { padding: 2px 4px; font-size: 0.85rem; }
  .sb-btn { min-height: 40px; padding: 6px 14px; font-size: 0.92rem; }
  .sb-actions { margin-top: 8px; }
}
