/* Styles communs des jeux de maths de Sami */

:root {
  --encre: #2a2340;
  --encre-douce: #5f5878;
  --blanc: #ffffff;
  --creme: #fff9ef;
  --jaune: #ffd23f;
  --jaune-fonce: #e0a800;
  --rose: #ff5d8f;
  --bleu: #2bb3f0;
  --vert: #33b06a;
  --vert-fonce: #1f8a4f;
  --vert-clair: #dff6e4;
  --orange: #ff9a1f;
  --orange-fonce: #d97706;
  --orange-clair: #ffeccc;
  --violet: #7656f5;
  --violet-fonce: #4f33c9;
  --violet-clair: #e7e0ff;
  --rouge-auto: #e8463c;
  --bleu-auto: #2b7de9;
  --ombre: rgba(42, 35, 64, 0.16);

  /* Valeurs par défaut, remplacées par chaque thème */
  --theme: var(--violet);
  --theme-fonce: var(--violet-fonce);
  --theme-clair: var(--violet-clair);
  --fond-page: var(--creme);
  --texte-page: var(--encre);
  --fond-scene: rgba(255, 255, 255, 0.6);

  --police: "Arial Rounded MT Bold", "Chalkboard SE", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  --rayon: 24px;
}

body.theme-jungle {
  --theme: var(--vert);
  --theme-fonce: var(--vert-fonce);
  --theme-clair: #bfe8c8;
  --fond-page: linear-gradient(180deg, #e4f8d8 0%, #bfe9a8 100%);
}

body.theme-garage {
  --theme: var(--orange);
  --theme-fonce: var(--orange-fonce);
  --theme-clair: #ffd9a3;
  --fond-page: linear-gradient(180deg, #c6ecff 0%, #eef9ff 70%);
}

body.theme-espace {
  --theme: #9b82ff;
  --theme-fonce: var(--violet-fonce);
  --theme-clair: #cfc2ff;
  --texte-page: #ffffff;
  --fond-scene: rgba(255, 255, 255, 0.08);
  --fond-page:
    radial-gradient(2px 2px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 70% 20%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 80%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 85% 65%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 10% 75%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 50%, #fff 50%, transparent 51%),
    linear-gradient(180deg, #17113d 0%, #2c1d6e 100%);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--police);
  color: var(--texte-page);
  background: var(--fond-page);
  background-color: #fff9ef;
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body.theme-espace { background-color: #17113d; }

/* Décors de fond */
body.theme-jungle::before,
body.theme-jungle::after {
  position: fixed;
  bottom: -18px;
  font-size: 140px;
  opacity: 0.3;
  pointer-events: none;
  z-index: 0;
}
body.theme-jungle::before { content: "🌿"; left: -24px; }
body.theme-jungle::after { content: "🌴"; right: -20px; }

body.theme-garage::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34px;
  background:
    repeating-linear-gradient(90deg, #fff 0 40px, transparent 40px 80px) center / 100% 5px no-repeat,
    #5b5f6b;
  pointer-events: none;
  z-index: 0;
}

button { font-family: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ---------- Structure d'une page de jeu ---------- */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 1100px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 12px 16px 48px;
}

.barre {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bouton-rond {
  flex: none;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: var(--blanc);
  box-shadow: 0 5px 0 var(--ombre);
  font-size: 28px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s;
}
.bouton-rond:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ombre); }

/* Parcours des 8 questions */
.parcours {
  position: relative;
  flex: 1;
  height: 58px;
  min-width: 0;
}
.parcours-piste {
  position: absolute;
  left: 22px;
  right: 22px;
  top: 50%;
  height: 10px;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 5px;
}
.etape {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blanc);
  border: 3px solid var(--theme-clair);
  transition: background 0.3s, transform 0.3s;
}
.etape.faite { background: var(--jaune); border-color: var(--jaune-fonce); transform: scale(1.15); }
.etape.arrivee {
  width: auto;
  height: auto;
  border: none;
  background: none;
  font-size: 26px;
  transform: none;
}
.parcours-jeton {
  position: absolute;
  top: 50%;
  left: calc(22px + (100% - 44px) * var(--p, 0));
  transform: translate(-50%, -62%);
  font-size: 40px;
  line-height: 1;
  transition: left 0.7s cubic-bezier(.4, 1.4, .6, 1);
  pointer-events: none;
}

.miroir { display: inline-block; transform: scaleX(-1); }
.tourne { display: inline-block; transform: rotate(45deg); }
.tourne-gauche { display: inline-block; transform: rotate(-135deg); } /* la fusée pointe vers 0 */

.jeu {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Mascotte et bulle de consigne */
.bulle-zone {
  display: flex;
  align-items: center;
  gap: 14px;
}
.mascotte {
  flex: none;
  font-size: clamp(54px, 9vw, 86px);
  line-height: 1;
  animation: flotter 3s ease-in-out infinite;
}
.mascotte.danse { animation: danse 0.9s ease-in-out; }
.mascotte.pense { animation: pense 0.9s ease-in-out; }

.bulle {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 12px 14px 12px 22px;
  background: var(--blanc);
  color: var(--encre);
  border-radius: var(--rayon);
  box-shadow: 0 6px 0 var(--ombre);
  font-size: clamp(19px, 3vw, 28px);
  line-height: 1.25;
}
.bulle::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  border: 12px solid transparent;
  border-right: 16px solid var(--blanc);
  border-left: 0;
}
.bulle-texte { flex: 1; }
.bulle .bouton-rond {
  width: 52px;
  height: 52px;
  font-size: 24px;
  background: var(--theme-clair);
  box-shadow: 0 4px 0 var(--theme);
}

/* Scène et zone de choix */
.scene {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 280px;
  padding: 20px 16px;
  background: var(--fond-scene);
  border-radius: 28px;
  overflow: hidden;
}

.choix-zone {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(12px, 3vw, 24px);
  min-height: 8px;
}

.choix {
  position: relative;
  border: 4px solid var(--theme-clair);
  border-radius: var(--rayon);
  background: var(--blanc);
  color: var(--encre);
  box-shadow: 0 6px 0 var(--theme-fonce);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.3s, filter 0.3s;
}
.choix:hover { transform: translateY(-2px); }
.choix:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--theme-fonce); }
.choix:focus-visible { outline: 5px solid var(--bleu); outline-offset: 4px; }

.choix.nombre {
  min-width: clamp(84px, 14vw, 116px);
  height: clamp(84px, 14vw, 116px);
  padding: 0 12px;
  font-size: clamp(44px, 8vw, 64px);
  font-weight: bold;
}

.attente .choix { pointer-events: none; }

.choix.faux {
  opacity: 0.35;
  filter: grayscale(1);
  cursor: default;
  animation: secouer 0.45s;
  pointer-events: none;
}
/* Les grands boutons (lignes, cartes) restent lisibles pendant l'aide */
.choix.rangee.faux,
.choix.carte-nombre.faux { opacity: 0.65; filter: grayscale(0.5); }
.choix.bon {
  border-color: var(--vert);
  box-shadow: 0 0 0 7px rgba(51, 176, 106, 0.35), 0 6px 0 var(--vert-fonce);
  animation: rebond 0.55s;
}
.choix.revele {
  border-color: var(--jaune);
  box-shadow: 0 0 0 8px rgba(255, 210, 63, 0.7), 0 6px 0 var(--jaune-fonce);
  animation: pulse 0.9s ease-in-out infinite;
}

/* ---------- Objets, boîtes de 10, piste ---------- */

.objet {
  position: relative;
  display: inline-grid;
  place-items: center;
  font-size: var(--taille-objet, clamp(34px, 6.5vw, 56px));
  line-height: 1.1;
  transition: transform 0.25s, opacity 0.3s, filter 0.3s;
}
.objet.apparait { animation: pop 0.4s backwards; animation-delay: calc(var(--i, 0) * 70ms); }
.objet.compte { transform: scale(1.12); filter: drop-shadow(0 0 8px var(--jaune)); }
.objet.compte::after,
.point.compte::after {
  content: attr(data-num);
  position: absolute;
  top: -10px;
  right: -12px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--jaune);
  color: var(--encre);
  font-size: 17px;
  font-weight: bold;
  box-shadow: 0 2px 0 var(--jaune-fonce);
}
.objet.apparie { opacity: 0.55; }
.objet.seul { animation: halo 1s ease-in-out infinite; }
.objet.partie { opacity: 0.25; filter: grayscale(1); }
/* Le trait est posé sur la case, pour ne pas être pâli avec l'objet parti */
.emplacement:has(> .objet.partie),
.case:has(> .objet.partie) { position: relative; }
.emplacement:has(> .objet.partie)::after,
.case:has(> .objet.partie)::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 5px;
  border-radius: 3px;
  background: var(--encre-douce);
  transform: rotate(-35deg);
}
.theme-espace .emplacement:has(> .objet.partie)::after,
.theme-espace .case:has(> .objet.partie)::after { background: rgba(255, 255, 255, 0.85); }
.objet.clignote { animation: clignote 0.5s ease-in-out 3; }
.objet.cache { visibility: hidden; }

.boite {
  display: grid;
  grid-template-columns: repeat(5, var(--case, clamp(30px, 5.4vw, 50px)));
  grid-auto-rows: var(--case, clamp(30px, 5.4vw, 50px));
  gap: 4px;
  padding: 6px;
  background: var(--theme-fonce);
  border-radius: 14px;
}
.boite > .case {
  display: grid;
  place-items: center;
  background: var(--blanc);
  border-radius: 8px;
}
.boite .objet { --taille-objet: calc(var(--case, clamp(30px, 5.4vw, 50px)) * 0.72); }
.point {
  position: relative;
  width: 64%;
  height: 64%;
  border-radius: 50%;
  background: var(--theme);
  transition: transform 0.25s;
}
.point.compte { transform: scale(1.15); background: var(--jaune-fonce); }

.boites {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.boite.parking { --case: clamp(40px, 7.5vw, 68px); background: #4c505b; }
.boite.parking > .case { background: #6f7480; border: 2px dashed rgba(255, 255, 255, 0.75); }

.theme-espace .boite { --case: clamp(40px, 7.5vw, 68px); background: rgba(255, 255, 255, 0.18); }
.theme-espace .boite > .case { background: rgba(255, 255, 255, 0.1); border: 2px dashed rgba(255, 255, 255, 0.35); }

/* Piste numérique */
.piste {
  --n: 11;
  position: relative;
  width: 100%;
  max-width: 900px;
  padding-top: 66px;
}
.piste-cases {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
}
.case-p {
  margin: 0 2px;
  padding: 10px 0;
  border-radius: 10px;
  border-bottom: 5px solid var(--theme-clair);
  background: var(--blanc);
  color: var(--encre);
  text-align: center;
  font-size: clamp(16px, 2.8vw, 28px);
  font-weight: bold;
  transition: background 0.3s;
}
.case-p.depart { background: var(--theme-clair); border-bottom-color: var(--theme); }
.case-p.visitee { background: var(--jaune); border-bottom-color: var(--jaune-fonce); }
.piste-jeton {
  position: absolute;
  top: 6px;
  left: calc((var(--pos, 0) + 0.5) / var(--n) * 100%);
  transform: translateX(-50%);
  font-size: clamp(38px, 6vw, 54px);
  line-height: 1;
  transition: left 0.38s ease-in-out;
}
.piste-jeton > span { display: inline-block; }

/* Écriture d'une opération : 4 + 3 = ? */
.egalite {
  display: flex;
  align-items: center;
  gap: 0.28em;
  font-size: clamp(44px, 9vw, 84px);
  font-weight: bold;
  line-height: 1;
}
.egalite .terme-a { color: var(--rouge-auto); }
.egalite .terme-b { color: var(--bleu-auto); }
.theme-espace .egalite .terme-a,
.theme-espace .egalite .terme-b { color: inherit; }
.trou-reponse {
  min-width: 1.25em;
  padding: 0.06em 0.12em;
  border: 4px dashed var(--theme);
  border-radius: 16px;
  color: var(--theme);
  text-align: center;
}
.trou-reponse.rempli {
  border-style: solid;
  background: var(--blanc);
  color: var(--vert-fonce);
  animation: rebond 0.5s;
}

/* Petit bandeau qui écrit l'opération après une réussite */
.tampon {
  min-height: 1.2em;
  font-size: clamp(30px, 6vw, 50px);
  font-weight: bold;
}
.tampon:not(:empty) {
  padding: 4px 20px;
  border-radius: 16px;
  background: var(--blanc);
  color: var(--vert-fonce);
  animation: pop 0.45s;
}

/* ---------- Écrans (choix du niveau, fin de partie) ---------- */

.ecran {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px 56px;
  overflow-y: auto;
  background: var(--fond-page);
  background-color: #fff9ef;
  text-align: center;
}
.theme-espace .ecran { background-color: #17113d; }
.ecran-accueil { position: absolute; top: 14px; left: 16px; }
.ecran-mascotte {
  font-size: clamp(72px, 14vw, 120px);
  line-height: 1;
  animation: flotter 3s ease-in-out infinite;
}
.ecran-titre {
  margin: 0;
  font-size: clamp(30px, 6vw, 52px);
}
.ecran-sous-titre {
  margin: 0;
  font-size: clamp(20px, 3.5vw, 30px);
}
.ecran-sous-titre .bouton-rond { display: inline-grid; vertical-align: middle; margin-left: 8px; width: 48px; height: 48px; font-size: 22px; }

.niveaux {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 920px;
  margin-top: 8px;
}
.carte-niveau {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px 16px;
  border: 4px solid var(--theme-clair);
  border-radius: var(--rayon);
  background: var(--blanc);
  color: var(--encre);
  box-shadow: 0 7px 0 var(--theme-fonce);
  cursor: pointer;
  transition: transform 0.12s;
}
.carte-niveau:hover { transform: translateY(-3px); }
.carte-niveau:active { transform: translateY(4px); }
.carte-niveau:focus-visible { outline: 5px solid var(--bleu); outline-offset: 4px; }
.carte-niveau.verrouille { opacity: 0.55; filter: grayscale(0.7); }
.carte-niveau-num {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--theme);
  color: var(--blanc);
  font-size: 30px;
  font-weight: bold;
}
.carte-niveau.verrouille .carte-niveau-num { background: var(--encre-douce); font-size: 24px; }
.carte-niveau-icone { font-size: 42px; line-height: 1.1; }
.carte-niveau-nom { font-size: 21px; font-weight: bold; }
.carte-niveau-plage { font-size: 16px; color: var(--encre-douce); }

.etoiles { font-size: 28px; letter-spacing: 2px; }
.etoile { color: #d9d4e6; }
.etoile.gagnee { color: var(--jaune); text-shadow: 0 2px 0 var(--jaune-fonce); }

.fin-etoiles { font-size: clamp(64px, 13vw, 100px); letter-spacing: 6px; }
.fin-etoiles .etoile { display: inline-block; }
.fin-etoiles .etoile.gagnee { animation: pop 0.5s backwards; animation-delay: calc(var(--i) * 0.3s + 0.2s); }

.fin-cadeau {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  border-radius: var(--rayon);
  background: var(--blanc);
  color: var(--encre);
  box-shadow: 0 6px 0 var(--ombre);
  font-size: clamp(18px, 3vw, 24px);
  font-weight: bold;
}
.fin-cadeau .autocollant { font-size: 64px; animation: tourbillon 0.9s 1s backwards; }
.fin-debloque {
  padding: 10px 20px;
  border-radius: var(--rayon);
  background: var(--jaune);
  color: var(--encre);
  font-size: clamp(18px, 3vw, 24px);
  font-weight: bold;
  animation: pulse 1.2s ease-in-out 3;
}
.fin-detail { margin: 0; font-size: 16px; opacity: 0.75; }

.boutons-fin {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 8px;
}
.bouton-gros {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 70px;
  padding: 10px 24px;
  border: none;
  border-radius: var(--rayon);
  background: var(--theme);
  color: var(--blanc);
  box-shadow: 0 6px 0 var(--theme-fonce);
  font-size: 24px;
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
}
.bouton-gros.secondaire { background: var(--blanc); color: var(--encre); box-shadow: 0 6px 0 var(--ombre); }
.bouton-gros:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--theme-fonce); }
.bouton-gros .icone { font-size: 32px; }

/* Autocollants (album et fin de partie) */
.autocollant {
  display: inline-grid;
  place-items: center;
  line-height: 1;
  filter: drop-shadow(0 0 0 #fff) drop-shadow(3px 0 0 #fff) drop-shadow(-3px 0 0 #fff) drop-shadow(0 3px 0 #fff) drop-shadow(0 -3px 0 #fff) drop-shadow(0 4px 4px rgba(0, 0, 0, 0.25));
}

/* ---------- Confettis ---------- */

.confettis {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}
.confetti {
  position: absolute;
  top: -24px;
  left: var(--x);
  width: 12px;
  height: 18px;
  border-radius: 3px;
  background: var(--c);
  animation: tomber var(--d) ease-in forwards;
  animation-delay: var(--delai);
}

/* ---------- Animations ---------- */

@keyframes pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes rebond {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.15); }
  70% { transform: scale(0.95); }
}
@keyframes secouer {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(7px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes halo {
  0%, 100% { filter: drop-shadow(0 0 0 transparent); transform: scale(1); }
  50% { filter: drop-shadow(0 0 12px var(--jaune)); transform: scale(1.18); }
}
@keyframes clignote {
  50% { opacity: 0.9; filter: none; }
}
@keyframes flotter {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes danse {
  0%, 100% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-14deg) scale(1.15); }
  40% { transform: rotate(12deg) scale(1.2); }
  60% { transform: rotate(-10deg) scale(1.15) translateY(-12px); }
  80% { transform: rotate(6deg) scale(1.05); }
}
@keyframes pense {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-10deg); }
  60% { transform: rotate(8deg); }
}
@keyframes tourbillon {
  0% { transform: scale(0) rotate(-540deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes tomber {
  to { transform: translate(var(--dx), 112vh) rotate(var(--r)); }
}

/* ---------- Petits écrans ---------- */

@media (max-width: 600px) {
  .app { padding: 10px 12px 44px; gap: 10px; }
  .bouton-rond { width: 50px; height: 50px; font-size: 24px; }
  .parcours-jeton { font-size: 32px; }
  .etape { width: 13px; height: 13px; border-width: 2px; }
  .scene { padding: 16px 10px; min-height: 240px; }
  .bulle { padding-left: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .confettis { display: none; }
}

/* ======================================================================
   Styles propres à chaque jeu
   ====================================================================== */

/* ---------- Comparer : lignes reliées ---------- */
.rangees {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
}
.choix.rangee {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  justify-items: center;
  align-items: center;
  min-height: 96px;
  padding: 12px;
}
.liens {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: 46px;
  padding: 0 16px;
}
.lien {
  width: 6px;
  height: 100%;
  margin: 0 auto;
  border-radius: 3px;
  background: var(--orange);
  transform: scaleY(0);
  transition: transform 0.3s;
}
.lien.visible { transform: scaleY(1); }

/* ---------- Comparer : cartes nombres et crocodile ---------- */
.comparaison {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vw, 40px);
}
.carte-nombre {
  --case: clamp(18px, 4.4vw, 42px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 18px;
  border: 4px solid var(--theme-clair);
  border-radius: var(--rayon);
  background: var(--blanc);
  color: var(--encre);
  box-shadow: 0 6px 0 var(--theme-fonce);
}
.chiffre {
  font-size: clamp(60px, 12vw, 104px);
  font-weight: bold;
  line-height: 1;
}
.cache-points { display: none; }
.montrer-points .cache-points { display: block; animation: pop 0.45s; }
.carte-nombre .boites .boite { --case: clamp(14px, 3.2vw, 30px); }

.trou-signe {
  flex: none;
  display: grid;
  place-items: center;
  width: clamp(84px, 15vw, 132px);
  height: clamp(84px, 15vw, 132px);
  padding: 8px;
  border: 5px dashed var(--theme);
  border-radius: var(--rayon);
  color: var(--theme-fonce);
  font-size: clamp(44px, 8vw, 70px);
  font-weight: bold;
}
.trou-signe.rempli { border-style: solid; background: var(--blanc); }

.choix.signe {
  width: clamp(96px, 16vw, 124px);
  height: clamp(96px, 16vw, 124px);
  padding: 12px;
}
.croc { display: block; width: 100%; height: 100%; }
.croc svg { display: block; width: 100%; height: 100%; overflow: visible; }
.croc-gauche svg { transform: scaleX(-1); }
.machoire-haut, .machoire-bas { transform-origin: 16px 50px; }
.croque .machoire-haut { animation: croc-haut 0.42s ease-in-out 2; }
.croque .machoire-bas { animation: croc-bas 0.42s ease-in-out 2; }
.croque .croc-egal svg { animation: rebond 0.5s 2; }
@keyframes croc-haut { 50% { transform: rotate(17deg); } }
@keyframes croc-bas { 50% { transform: rotate(-17deg); } }

/* ---------- Additionner : le bus ---------- */
.rue {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(12px, 4vw, 40px);
  width: 100%;
  padding-bottom: 26px;
  border-bottom: 10px solid #5b5f6b;
}
.bus {
  position: relative;
  display: flex;
  padding: 16px 54px 38px 18px;
  border-radius: 22px 54px 16px 16px;
  background: #ffc928;
  box-shadow: inset 0 -12px 0 #f0a500, 0 6px 0 var(--ombre);
}
.bus-fenetres { display: flex; gap: 8px; }
.fenetre {
  --taille-objet: clamp(28px, 5.4vw, 46px);
  display: grid;
  place-items: center;
  width: clamp(44px, 8vw, 68px);
  height: clamp(44px, 8vw, 68px);
  border: 3px solid #e09a00;
  border-radius: 12px;
  background: #bfe9ff;
}
.bus-phare {
  position: absolute;
  right: 12px;
  bottom: 30px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff6b0;
  box-shadow: 0 0 14px #fff6b0;
}
.roue {
  position: absolute;
  bottom: -20px;
  width: 42px;
  height: 42px;
  border: 7px solid #8a8a8a;
  border-radius: 50%;
  background: #333;
}
.roue-ar { left: 14%; }
.roue-av { right: 14%; }
.arret { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.panneau { font-size: clamp(44px, 8vw, 64px); line-height: 1; }
.attente-arret {
  --taille-objet: clamp(28px, 5.4vw, 46px);
  display: flex;
  gap: 6px;
  min-height: 52px;
}

/* ---------- Soustraire : fusées et Zig ---------- */
.pas-de-tir {
  display: flex;
  gap: clamp(8px, 2vw, 18px);
  padding: 10px 20px 14px;
  border-bottom: 10px solid rgba(255, 255, 255, 0.35);
}
.emplacement {
  --taille-objet: clamp(48px, 10vw, 92px);
  display: grid;
  place-items: center;
  width: clamp(60px, 12vw, 110px);
  height: clamp(76px, 14vw, 130px);
}
.zig-fusee {
  font-size: clamp(56px, 10vw, 90px);
  line-height: 1;
  animation: flotter 2.4s ease-in-out infinite;
}

/* ---------- Petits écrans ---------- */
@media (max-width: 480px) {
  .comparaison { gap: 8px; }
  .carte-nombre { padding: 10px; }
  .trou-signe { width: 64px; height: 64px; }
  .bus { padding-right: 40px; }
  .bus-fenetres { gap: 4px; }
  .fenetre { width: 40px; height: 40px; }
}

/* ======================================================================
   Accueil
   ====================================================================== */

.accueil {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.accueil-tete {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.accueil-mascottes {
  display: flex;
  gap: 4px;
  font-size: clamp(54px, 10vw, 84px);
  line-height: 1;
}
.accueil-mascottes span { animation: flotter 3s ease-in-out infinite; }
.accueil-mascottes span:nth-child(2) { animation-delay: -1s; }
.accueil-mascottes span:nth-child(3) { animation-delay: -2s; }
.accueil-tete .bulle {
  flex: 0 1 560px;
  border: none;
  font-family: inherit;
  font-weight: bold;
  text-align: left;
  cursor: pointer;
}

.tuiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}
.tuile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 14px 18px;
  border-radius: 30px;
  background: var(--fond-tuile);
  color: var(--blanc);
  box-shadow: 0 8px 0 var(--fonce);
  text-decoration: none;
  transition: transform 0.12s;
}
.tuile:hover { transform: translateY(-4px); }
.tuile:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--fonce); }
.tuile:focus-visible { outline: 5px solid var(--bleu); outline-offset: 5px; }
.tuile-jungle { --fond-tuile: linear-gradient(160deg, #4cc47f, #2a9a5c); --fonce: #1d7444; }
.tuile-garage { --fond-tuile: linear-gradient(160deg, #ffb347, #f08a00); --fonce: #b86200; }
.tuile-espace { --fond-tuile: linear-gradient(160deg, #8d72ff, #4f33c9); --fonce: #33208f; }
.tuile-image { font-size: 76px; line-height: 1; }
.tuile-signe {
  min-width: 60px;
  padding: 2px 18px;
  line-height: 1.3;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.25);
  font-size: 40px;
  font-weight: bold;
}
.tuile-titre { font-size: 32px; font-weight: bold; }
.tuile-sous-titre { font-size: 17px; opacity: 0.92; }
.tuile-niveaux { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
.mini-niveau {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 54px;
  padding: 4px 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--encre);
  font-size: 13px;
}
.mini-niveau .etoiles { font-size: 14px; letter-spacing: 0; }

.album {
  padding: 18px 18px 8px;
  border-radius: 30px;
  background: var(--blanc);
  box-shadow: 0 8px 0 var(--ombre);
}
.album h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 28px;
}
.album-compte {
  padding: 4px 14px;
  border-radius: 14px;
  background: var(--jaune);
  font-size: 18px;
}
.album-ligne {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.album-case {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  background: #f4f1fb;
  font-size: 40px;
  cursor: pointer;
}
.album-case .autocollant { transform: rotate(var(--rot, 0deg)); }
.album-case.vide { cursor: default; }
.album-case.vide .autocollant { filter: brightness(0) opacity(0.12); }
.album-case.saute .autocollant { animation: rebond 0.5s; }

.pied { text-align: center; }
.lien-parents {
  padding: 10px;
  border: none;
  background: none;
  color: var(--encre-douce);
  font-size: 16px;
  text-decoration: underline;
  cursor: pointer;
}

/* Espace parents */
dialog.parents {
  width: calc(100% - 32px);
  max-width: 600px;
  max-height: calc(100dvh - 32px);
  padding: 24px;
  border: none;
  border-radius: 24px;
  background: var(--blanc);
  color: var(--encre);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  font-family: system-ui, -apple-system, sans-serif;
}
dialog.parents::backdrop { background: rgba(42, 35, 64, 0.5); }
.parents h2 { margin: 0 0 14px; font-family: var(--police); }
.parents h3 { margin: 22px 0 8px; font-size: 18px; }
.parents-fermer { position: absolute; top: 14px; right: 14px; margin: 0; }
.parents-fermer .bouton-rond { width: 44px; height: 44px; font-size: 18px; background: #f4f1fb; }
.porte label { font-size: 18px; }
.porte-ligne { display: flex; gap: 10px; margin-top: 10px; }
.porte input {
  width: 120px;
  padding: 8px 12px;
  border: 2px solid #d8d2e8;
  border-radius: 12px;
  font: inherit;
  font-size: 22px;
}
.porte-erreur { color: #b42318; }
.rangee-reglage { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0; font-size: 17px; }
.rangee-reglage input[type="checkbox"] { width: 22px; height: 22px; }
.parents .simple {
  padding: 10px 16px;
  border: 2px solid #d8d2e8;
  border-radius: 14px;
  background: var(--blanc);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.parents .simple:hover { background: #f7f5fc; }
.parents .danger { border-color: #f3b0b0; color: #b42318; }
.parents ul { margin: 0; padding-left: 20px; line-height: 1.5; }
.tableau-progres { width: 100%; border-collapse: collapse; font-size: 15px; }
.tableau-progres th, .tableau-progres td { padding: 6px 4px; border-bottom: 1px solid #eee9f6; text-align: center; }
.tableau-progres th:first-child, .tableau-progres td:first-child { text-align: left; }
.tableau-progres .etoiles { font-size: 16px; letter-spacing: 0; }
.note-voix { color: var(--encre-douce); font-size: 15px; }

/* ======================================================================
   Téléphones (≈ 360–430 px de large), debout puis couché
   ====================================================================== */

/* Tactile : pas de zoom au double-tap, pas de sélection ni de menu à l'appui long */
button, a, .choix, .carte-niveau, .tuile { touch-action: manipulation; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { -webkit-user-select: text; user-select: text; }

/* Sur un écran tactile, l'effet de survol resterait « collé » après le toucher */
@media (hover: none) {
  .choix:hover, .carte-niveau:hover, .tuile:hover { transform: none; }
}

/* Encoche et bords arrondis des iPhone (avec viewport-fit=cover) */
.app, .accueil {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---------- Téléphone debout ---------- */
@media (max-width: 480px) {
  .app { padding: 8px max(10px, env(safe-area-inset-right)) 40px max(10px, env(safe-area-inset-left)); gap: 8px; }
  .barre { gap: 8px; }
  .bouton-rond { width: 46px; height: 46px; font-size: 22px; }
  .mascotte { font-size: 46px; }
  .bulle-zone { gap: 10px; }
  .bulle { min-height: 60px; padding: 8px 8px 8px 14px; font-size: 17px; }
  .bulle .bouton-rond { width: 42px; height: 42px; font-size: 19px; }
  .scene { min-height: 0; padding: 14px 8px; gap: 16px; }

  /* Réponses : 4 boutons tiennent sur une ligne */
  .choix-zone { flex-wrap: nowrap; gap: 10px; }
  .choix.nombre { flex: 0 1 82px; min-width: 62px; height: 82px; padding: 0; font-size: 44px; }
  .choix.signe { width: 94px; height: 94px; }

  /* Comparer : objets et nombres plus grands, il y a la place en hauteur */
  .choix.rangee { min-height: 84px; padding: 10px 6px; --taille-objet: 40px; }
  .liens { height: 40px; padding: 0 10px; }
  .chiffre { font-size: 84px; }
  .carte-nombre { --case: 22px; padding: 10px 8px 12px; }
  .choix.carte-nombre .boite { --case: 22px; }
  .trou-signe { width: 78px; height: 78px; font-size: 46px; }

  /* Additionner et soustraire */
  .egalite { font-size: 52px; }
  .tampon { font-size: 34px; }
  .boite.parking, .theme-espace .boite { --case: 50px; }
  .rue { gap: 10px; }
  .fenetre { width: 38px; height: 38px; --taille-objet: 28px; }
  .attente-arret { flex-wrap: wrap; max-width: 64px; justify-content: center; }
  .pas-de-tir { gap: 6px; padding: 10px 8px 14px; }
  .emplacement { width: 58px; height: 78px; --taille-objet: 50px; }
  .zig-fusee { font-size: 64px; }
  .piste { padding-top: 56px; }
  .piste-jeton { font-size: 40px; }
  .case-p { margin: 0 1px; padding: 10px 0; font-size: 15px; border-radius: 8px; }

  /* Choix du niveau : 2 colonnes de cartes compactes, tout tient sur l'écran */
  .ecran { justify-content: flex-start; gap: 8px; padding: 18px 12px 24px; }
  .ecran-mascotte { font-size: 64px; }
  .ecran-titre { font-size: 27px; }
  .ecran-sous-titre { font-size: 19px; }
  .niveaux { grid-template-columns: 1fr 1fr; gap: 10px; }
  .carte-niveau { gap: 4px; padding: 12px 6px; }
  .carte-niveau-num { width: 40px; height: 40px; font-size: 22px; }
  .carte-niveau-icone { font-size: 32px; }
  .carte-niveau-nom { font-size: 16px; }
  .carte-niveau-plage { font-size: 13px; }
  .carte-niveau .etoiles { font-size: 20px; }

  /* Fin de partie : boutons deux par deux */
  .fin-etoiles { font-size: 64px; }
  .fin-cadeau { gap: 10px; padding: 8px 14px; font-size: 16px; }
  .fin-cadeau .autocollant { font-size: 48px; }
  .fin-debloque { font-size: 17px; }
  .boutons-fin { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 380px; }
  .bouton-gros { justify-content: center; min-height: 60px; padding: 8px 10px; font-size: 19px; }
  .bouton-gros .icone { font-size: 26px; }

  /* Accueil : tuiles en ligne, les 3 jeux visibles dès l'ouverture */
  .accueil { gap: 14px; padding-top: 12px; padding-bottom: 28px; }
  .accueil-tete { gap: 8px; }
  .accueil-mascottes { font-size: 44px; }
  .accueil-tete .bulle { flex-basis: 100%; }
  .tuiles { grid-template-columns: 1fr; gap: 12px; }
  .tuile {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "image titre signe" "image sous-titre signe" "niveaux niveaux niveaux";
    align-items: center;
    gap: 0 12px;
    padding: 12px 14px;
    border-radius: 24px;
    text-align: left;
  }
  .tuile-image { grid-area: image; font-size: 52px; }
  .tuile-titre { grid-area: titre; align-self: end; font-size: 25px; }
  .tuile-sous-titre { grid-area: sous-titre; align-self: start; font-size: 14px; }
  .tuile-signe { grid-area: signe; min-width: 0; padding: 0 10px; font-size: 24px; }
  .tuile-niveaux { grid-area: niveaux; flex-wrap: nowrap; margin-top: 8px; }
  .mini-niveau { flex: 1; min-width: 0; }
  .album { padding: 14px 12px 4px; border-radius: 24px; }
  .album h2 { font-size: 22px; }
  .album-ligne { grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 10px; }
  .album-case { font-size: 28px; border-radius: 12px; }
}

/* ---------- Téléphone couché : les réponses passent dans une colonne à droite ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  body.theme-jungle::before, body.theme-jungle::after { display: none; }
  body.theme-garage::after { height: 12px; background-size: 100% 3px, auto; }
  .app {
    gap: 6px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: 16px;
  }
  .barre { gap: 8px; }
  .bouton-rond { width: 40px; height: 40px; font-size: 19px; box-shadow: 0 3px 0 var(--ombre); }
  .parcours { height: 40px; }
  .parcours-jeton { font-size: 28px; }

  .jeu {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px 12px;
  }
  .bulle-zone { grid-column: 1 / -1; gap: 8px; }
  .mascotte { font-size: 34px; }
  .bulle { min-height: 0; padding: 4px 6px 4px 12px; font-size: 16px; border-radius: 16px; box-shadow: 0 3px 0 var(--ombre); }
  .bulle::before { left: -10px; border-width: 8px; border-right-width: 12px; }
  .bulle .bouton-rond { width: 34px; height: 34px; font-size: 15px; }
  .scene { min-height: 0; padding: 8px; gap: 8px; border-radius: 20px; }

  .choix-zone { flex-direction: column; flex-wrap: nowrap; justify-content: center; gap: 8px; }
  .choix-zone:empty { display: none; }
  .choix-zone:has(> :nth-child(4)) { display: grid; grid-template-columns: repeat(2, auto); align-content: center; }
  .choix.nombre { flex: none; min-width: 64px; width: 64px; height: 64px; padding: 0; font-size: 34px; }
  .choix.signe { width: 70px; height: 70px; padding: 8px; }

  /* Contenu de la scène à l'échelle de la petite hauteur */
  .rangees { max-width: 520px; }
  .choix.rangee { min-height: 64px; padding: 6px; --taille-objet: 34px; }
  .liens { height: 20px; padding: 0 10px; }
  .carte-nombre { gap: 6px; padding: 6px 12px; --case: 20px; }
  .choix.carte-nombre .boite { --case: 20px; }
  .carte-nombre .boites { flex-direction: row; }
  .carte-nombre .boites .boite { --case: 17px; }
  .chiffre { font-size: 48px; }
  .trou-signe { width: 62px; height: 62px; font-size: 38px; border-width: 4px; }
  .egalite { font-size: 38px; }
  .tampon { font-size: 26px; }
  .boite.parking, .theme-espace .boite { --case: 34px; }
  .rue { padding-bottom: 16px; border-bottom-width: 6px; }
  .bus { padding: 10px 40px 24px 12px; }
  .fenetre { width: 40px; height: 40px; --taille-objet: 30px; }
  .roue { bottom: -14px; width: 30px; height: 30px; border-width: 5px; }
  .panneau { font-size: 40px; }
  .pas-de-tir { padding: 4px 12px 8px; border-bottom-width: 6px; }
  .emplacement { width: 56px; height: 64px; --taille-objet: 44px; }
  .zig-fusee { font-size: 40px; }
  .piste { padding-top: 44px; }
  .piste-jeton { font-size: 32px; top: 2px; }
  .case-p { padding: 6px 0; font-size: 16px; }

  /* Choix du niveau et fin de partie sur une seule hauteur d'écran */
  .ecran { justify-content: flex-start; gap: 6px; padding: 10px 16px; }
  .ecran-accueil { top: 10px; }
  .ecran-mascotte { font-size: 44px; }
  .ecran-titre { font-size: 24px; }
  .ecran-sous-titre { font-size: 17px; }
  .ecran-sous-titre .bouton-rond { width: 34px; height: 34px; font-size: 15px; }
  .niveaux { grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 4px; }
  .carte-niveau { gap: 2px; padding: 8px 4px; }
  .carte-niveau-num { width: 34px; height: 34px; font-size: 19px; }
  .carte-niveau-icone { font-size: 26px; }
  .carte-niveau-nom { font-size: 15px; }
  .carte-niveau-plage { font-size: 12px; }
  .carte-niveau .etoiles { font-size: 17px; }
  .fin-etoiles { font-size: 44px; }
  .fin-cadeau { gap: 8px; padding: 4px 12px; font-size: 15px; }
  .fin-cadeau .autocollant { font-size: 36px; }
  .fin-debloque { padding: 4px 14px; font-size: 15px; }
  .fin-detail { font-size: 13px; }
  .boutons-fin { gap: 8px; margin-top: 2px; }
  .bouton-gros { min-height: 48px; padding: 6px 14px; font-size: 17px; }
  .bouton-gros .icone { font-size: 22px; }

  /* Accueil : les 3 tuiles côte à côte */
  .accueil { gap: 10px; padding-top: max(10px, env(safe-area-inset-top)); }
  .accueil-tete { flex-wrap: nowrap; }
  .accueil-mascottes { font-size: 38px; }
  .tuiles { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .tuile { gap: 2px; padding: 10px 8px; border-radius: 22px; }
  .tuile-image { font-size: 40px; }
  .tuile-signe { padding: 0 12px; font-size: 22px; }
  .tuile-titre { font-size: 22px; }
  .tuile-sous-titre { font-size: 13px; }
  .tuile-niveaux { flex-wrap: nowrap; gap: 4px; }
  .mini-niveau { min-width: 0; padding: 2px 4px; font-size: 11px; }
  .album-ligne { grid-template-columns: repeat(12, 1fr); gap: 6px; }
  .album-case { font-size: 28px; }
}

/* Espace parents : vitesse de la voix */
.reglage-vitesse { margin: 14px 0 6px; font-size: 17px; }
.vitesse-ligne { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 22px; }
.vitesse-ligne input[type="range"] { flex: 1; max-width: 320px; height: 32px; accent-color: var(--vert); }
.reglage-vitesse .note-voix { margin: 4px 0 0; }
