/*
 * Temple Oublié — pages où l'on joue (solo, entraînement, 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-temple {
  margin: 0;
  background: #120a04;
  color: #fde7c4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.page-temple #app {
  max-width: 800px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}
/* La barre de compte est fixée en haut à droite : sous 1100 px elle recouvrait le titre. */
@media (max-width: 1100px) {
  .page-temple #app { padding-top: 72px; }
}

.page-temple h1 { font-size: 1.6rem; color: #ffcc33; margin: 8px 0 12px; text-align: center; }
.page-temple h2 { font-size: 1.1rem; color: #fdba74; margin: 18px 0 8px; }
.page-temple a { color: #ffd166; }

.setup-intro {
  color: #e7d3b4;
  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: #eadbc4; font-size: 0.92rem; margin: 0 0 14px; }
.lien-defi { text-align: center; margin: 22px 0 6px; }
.monde-titre { text-align: center; margin: 22px 0 4px; }
.monde-note { text-align: center; font-size: 0.88rem; color: #8fd4ff; margin: 0 0 6px; }

/* Étoiles d'un niveau (sortie, butin, sans mourir dans le temps) */
.etoiles { display: inline-flex; gap: 2px; font-size: 1.05rem; line-height: 1; }
.etoiles.petites { font-size: 0.9rem; vertical-align: -1px; }
.etoiles .on { color: #ffcc33; }
.etoiles .off { color: rgba(255, 255, 255, 0.22); }
.legende-etoiles { text-align: center; font-size: 0.82rem; color: #d6c2a3; margin: 14px auto 0; max-width: 60ch; }
.fin-etoiles { font-size: 1.4rem; margin: 6px 0; }
.fin-etoiles .etoiles { font-size: 1.6rem; gap: 6px; }
.fin-serie { color: #fcd34d; font-size: 0.92rem; }

/* Temps par salle (écran de fin) */
.temps-salles { text-align: left; margin: 8px 0; font-size: 0.88rem; }
.temps-salles summary { cursor: pointer; color: #ffd166; }
.temps-salles table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.temps-salles th, .temps-salles td { padding: 3px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); font-variant-numeric: tabular-nums; }
.temps-salles strong { color: #bef264; }

/* Temple sans fin */
.panneau-sans-fin { max-width: 62ch; margin: 10px auto; text-align: center; line-height: 1.55; }
.panneau-sans-fin[hidden] { display: none; }
.record-sans-fin { color: #ffcc33; font-weight: 700; min-height: 1.2em; }
.to-debut-statut { min-height: 1.2em; font-size: 0.9rem; margin: 8px 0 0; }
.to-debut-statut.erreur { color: #fca5a5; }

/* ---- Choix du niveau et du mode ------------------------------------------- */
.choix-mode { display: flex; justify-content: center; gap: 8px; margin: 0 0 14px; flex-wrap: wrap; }
.choix-mode button {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 2px solid #9a3412;
  background: #2a1606;
  color: #fde7c4;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.choix-mode button[aria-pressed="true"] { background: #ffcc33; border-color: #ffcc33; color: #2a1606; }
.choix-mode button:focus-visible { outline: 3px solid #ffcc33; outline-offset: 2px; }
.mode-explication { text-align: center; font-size: 0.88rem; color: #d6c2a3; margin: -4px 0 12px; min-height: 1.2em; }

.choix-niveaux[hidden] { display: none; }
.choix-grille {
  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 #9a3412;
  background: #2a1606;
  color: #fde7c4;
  font: inherit;
  cursor: pointer;
  text-align: center;
}
.niveau-carte:hover, .niveau-carte:focus-visible { background: #3b2008; outline: none; border-color: #ffcc33; }
.niveau-carte.fini { border-color: #ffcc33; }
.niveau-carte.verrouille { opacity: 0.55; cursor: not-allowed; border-style: dashed; }
.niveau-num { font-size: 1.7rem; font-weight: 800; color: #ffcc33; line-height: 1; }
.niveau-nom { font-weight: 700; font-size: 0.95rem; }
.niveau-info, .niveau-idoles { font-size: 0.8rem; color: #d6c2a3; }

/* ---- Zone de jeu dans la page --------------------------------------------- */
/* La zone se cale SOUS la barre de compte (fixée en haut à droite, ~62 px) :
 * sinon elle recouvrait les boutons Son, Plein écran et Arrêt en 1366 × 768. */
.zone-jeu { margin: 6px auto 18px; scroll-margin-top: 72px; }
.zone-jeu[hidden] { display: none; }
.zone-jeu .temple {
  height: auto;
  aspect-ratio: 40 / 27;
  border-radius: 12px;
  max-height: calc(100vh - 84px);
  margin: 0 auto;
}
/* Pendant une partie : la page s'élargit (les blocs latéraux sont masqués). */
body.to-en-partie .bandeau-infos-wrap,
body.to-en-partie .bloc-jeux-une-wrap { display: none !important; }
body.to-en-partie #app { max-width: 1180px; }

/* Écran tactile (téléphone, tablette) : pendant la partie, le jeu prend tout
 * l'écran, la barre de compte s'efface. Une rotation ne coupe plus rien. */
@media (pointer: coarse) {
  body.to-en-partie { overflow: hidden; }
  body.to-en-partie .auth-nav { display: none !important; }
  body.to-en-partie .zone-jeu .temple {
    position: fixed;
    inset: 0;
    z-index: 1000;
    aspect-ratio: auto;
    max-height: none;
    border-radius: 0;
  }
}
/* Même chose dès que le jeu a reçu un premier toucher (écran tactile non annoncé). */
body.to-ecran-tactile.to-en-partie { overflow: hidden; }
body.to-ecran-tactile.to-en-partie .auth-nav { display: none !important; }
body.to-ecran-tactile.to-en-partie .zone-jeu .temple { position: fixed; inset: 0; z-index: 1000; aspect-ratio: auto; max-height: none; border-radius: 0; }

/* ========================================================================== */
/* La zone de jeu : canvas, commandes tactiles, écrans de début, arrêt et fin. */

.temple {
  --to-fond: #000000;
  --to-carte: #1c1004;
  --to-texte: #fde7c4;
  --to-accent: #ffcc33;
  --to-bouton: #ff8000;
  --to-bouton-texte: #1c0a00;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--to-fond);
  color: var(--to-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;
}

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

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

/* ---- Commandes tactiles -------------------------------------------------- */
.to-tactile {
  --t: clamp(48px, 13vmin, 78px);
  --m: max(10px, env(safe-area-inset-bottom));
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  touch-action: none;
  pointer-events: none;
}
.temple.mode-tactile.partie-lancee .to-tactile { display: block; pointer-events: auto; }

.to-tactile button {
  position: absolute;
  width: var(--t);
  height: var(--t);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.92);
  font-size: calc(var(--t) * 0.42);
  line-height: 1;
  padding: 0;
  pointer-events: none;   /* c'est la zone qui écoute, pas le bouton */
}
.to-tactile button.appuye { background: rgba(255, 255, 255, 0.4); border-color: #fff; }
/* croix de direction, à gauche */
.to-tactile [data-b="gauche"] { left: max(10px, env(safe-area-inset-left)); bottom: calc(var(--m) + var(--t) * 0.6); }
.to-tactile [data-b="droite"] { left: calc(max(10px, env(safe-area-inset-left)) + var(--t) * 2); bottom: calc(var(--m) + var(--t) * 0.6); }
.to-tactile [data-b="haut"] { left: calc(max(10px, env(safe-area-inset-left)) + var(--t)); bottom: calc(var(--m) + var(--t) * 1.2); }
.to-tactile [data-b="bas"] { left: calc(max(10px, env(safe-area-inset-left)) + var(--t)); bottom: var(--m); }
/* actions, à droite */
.to-tactile [data-b="saut"] {
  right: max(12px, env(safe-area-inset-right));
  bottom: var(--m);
  width: calc(var(--t) * 1.2);
  height: calc(var(--t) * 1.2);
}
.to-tactile [data-b="tir"] { right: calc(max(12px, env(safe-area-inset-right)) + var(--t) * 1.35); bottom: var(--m); }
.to-tactile [data-b="caillou"] { right: calc(max(12px, env(safe-area-inset-right)) + var(--t) * 0.1); bottom: calc(var(--m) + var(--t) * 1.35); }
.to-tactile [data-b="dynamite"] { right: calc(max(12px, env(safe-area-inset-right)) + var(--t) * 1.35); bottom: calc(var(--m) + var(--t) * 1.15); }

/* Portrait : le jeu est calé en haut (rendu.js), les commandes occupent le bas
 * de l'écran sans rien cacher ; les outils passent entre les deux pavés. */
.temple.portrait .to-tactile { --t: clamp(56px, 17vw, 96px); --m: max(18px, env(safe-area-inset-bottom)); }
.temple.portrait .to-outils {
  top: auto;
  right: 50%;
  transform: translateX(50%);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + clamp(56px, 17vw, 96px) * 2.6);
}

/* ---- Voiles (début, arrêt/pause, fin, rotation) ------------------------- */
.to-voile {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.55);
  touch-action: auto;
}
.to-voile[hidden] { display: none; }
.to-carte {
  max-width: 480px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 18px 20px;
  border-radius: 14px;
  background: var(--to-carte);
  border: 2px solid #9a3412;
  text-align: center;
}
.to-carte h2 { margin: 0 0 8px; font-size: 1.4rem; color: var(--to-accent); }
.to-carte p { margin: 6px 0; line-height: 1.45; }
.to-sous-titre { opacity: 0.88; }
.to-note { font-size: 0.88rem; opacity: 0.85; }
.to-commandes { font-size: 0.9rem; opacity: 0.92; }
ul.to-commandes { list-style: none; padding: 0; margin: 8px 0; line-height: 1.9; }
.to-commandes kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 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;
}
.temple.mode-tactile .to-clavier-seul { display: none; }
.temple:not(.mode-tactile) .to-tactile-seul { display: none; }

.to-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.to-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 20px;
  border: 0;
  border-radius: 10px;
  background: var(--to-bouton);
  color: var(--to-bouton-texte);
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
}
.to-btn.secondaire { background: rgba(255, 255, 255, 0.14); color: var(--to-texte); }
.to-btn:focus-visible { outline: 3px solid var(--to-accent); outline-offset: 2px; }
.to-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.93rem; }
.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(--to-accent); border: 0; }
.bilan .morts { font-size: 0.85rem; opacity: 0.8; }
.to-fin-statut { min-height: 1.3em; font-size: 0.92rem; }
.to-fin-statut.attente { opacity: 0.8; }
.to-fin-statut.ok { color: #bef264; }
.to-fin-statut.erreur { color: #fca5a5; }
.to-fin-statut a { color: #ffd166; }

.to-tourner { background: var(--to-fond); z-index: 5; flex-direction: column; text-align: center; }
.to-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) {
  .to-carte { padding: 10px 14px; }
  .to-carte h2 { font-size: 1.15rem; margin-bottom: 4px; }
  .bilan th, .bilan td { padding: 2px 4px; font-size: 0.85rem; }
  .to-btn { min-height: 40px; padding: 6px 14px; font-size: 0.92rem; }
  .to-actions { margin-top: 8px; }
}
