:root {
  --frigo: #3b5fe6;
  --frigo-fonce: #3051d4;
  --craie: #f4f6ff;
  --encre: #1b1b1f;
  --jaune: #ffd23f;
  --rose: #ff6f91;
  --vert: #3ddc97;
  --ombre-magnet: 0 2px 0 #0002, 0 6px 14px #0a175a40;
  --police-mot: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --police-ui: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--police-ui);
  color: var(--craie);
  background:
    radial-gradient(120% 80% at 50% 0%, #4a6cee 0%, var(--frigo) 55%, var(--frigo-fonce) 100%) fixed;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.ecran {
  max-width: 640px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 32px;
}
.ecran.entree > * { animation: apparait .35s ease-out; }
@keyframes apparait { from { opacity: 0; transform: translateY(8px); } }

/* ——— Magnets ——— */
.magnet {
  display: inline-block;
  font-family: var(--police-mot);
  font-weight: 600;
  color: var(--encre);
  background: #fff;
  padding: .15em .55em .2em;
  border-radius: 3px;
  box-shadow: var(--ombre-magnet);
  transform: rotate(var(--angle, 0deg));
  line-height: 1.2;
}
.magnet.jaune { background: var(--jaune); }
.magnet.rose { background: var(--rose); }
.magnet.geant { font-size: clamp(2rem, 10vw, 3.4rem); padding: .2em .6em .25em; }
.magnet.arrive { animation: colle .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes colle {
  0% { transform: translateY(-30px) rotate(calc(var(--angle) * 4)) scale(1.08); opacity: 0; }
  100% { transform: rotate(var(--angle)); opacity: 1; }
}

/* ——— Accueil ——— */
.accueil { padding-top: 4vh; }
.intro {
  background: #ffffff1f; border-radius: 14px; padding: 4px 20px;
  margin: 0 0 1.8em; font-size: 1.02rem;
}
.intro p { margin: .8em 0; }
.accueil a, .fin a { color: var(--jaune); font-weight: 600; overflow-wrap: anywhere; }
.titre-magnets {
  display: flex; flex-wrap: wrap; gap: .3em .35em;
  font-size: clamp(2.6rem, 13vw, 4.4rem);
  margin: 0 0 .7em;
}
.chapo { font-size: 1.2rem; max-width: 30em; margin: 0 0 2em; }
.discret { opacity: .75; margin: 0 0 2em; }

/* ——— Boutons ——— */
.bouton {
  font: inherit; font-weight: 700; font-size: 1.1rem;
  color: var(--encre); background: var(--jaune);
  border: 0; border-radius: 999px;
  min-height: 52px; padding: 0 28px;
  box-shadow: 0 4px 0 #b8901a;
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.bouton:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #b8901a; }
.bouton:disabled { opacity: .45; cursor: not-allowed; }
.lien {
  font: inherit; color: var(--craie); background: none; border: 0;
  text-decoration: underline; text-underline-offset: 3px;
  min-height: 44px; padding: 0 12px; cursor: pointer; opacity: .85;
}
:focus-visible { outline: 3px solid var(--jaune); outline-offset: 3px; }

/* ——— Jeux : en-tête ——— */
.entete-jeu h2 { font-size: 1.6rem; margin: 0 0 .2em; line-height: 1.2; }
.numero-jeu { margin: 0; font-weight: 700; color: var(--jaune); }
.consigne { margin: 0 0 1em; opacity: .9; }
.progression { height: 8px; background: #ffffff2a; border-radius: 99px; overflow: hidden; }
.progression > span { display: block; height: 100%; width: 0; background: var(--jaune); border-radius: inherit; transition: width .3s; }
.compteur { margin: .4em 0 0; font-size: .9rem; opacity: .75; text-align: right; }

/* ——— Jeu 1 ——— */
.scene-mot { min-height: 30vh; max-height: 220px; display: grid; place-items: center; padding: 16px 0; }
.saisie { display: grid; gap: 12px; }
.champ {
  font: 600 1.5rem var(--police-mot);
  width: 100%; min-height: 60px; padding: 0 18px;
  color: var(--encre); background: #fff;
  border: 3px dashed #ffffff00; border-radius: 6px;
  box-shadow: inset 0 2px 6px #0002;
}
.champ::placeholder { color: #9aa0b8; font-style: italic; }
.champ:focus { outline: none; border-color: var(--jaune); }
.actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.secoue { animation: secoue .3s; }
@keyframes secoue { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ——— Divers ——— */
.bandeau {
  position: sticky; top: 0; z-index: 10;
  background: var(--rose); color: var(--encre);
  text-align: center; font-weight: 600; padding: 8px 16px;
}
.erreur { background: #fff; color: var(--encre); padding: 16px; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ——— Jeu 2 ——— */
.colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 8px 0 20px; }
.colonne { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; align-content: start; }
.tuile {
  width: 100%; min-height: 48px; padding: 4px; border: 0; background: none; cursor: pointer;
  font-size: clamp(.95rem, 4.2vw, 1.15rem); text-align: center;
}
.tuile .magnet { display: block; width: 100%; transition: transform .15s, background .2s; overflow-wrap: anywhere; }
.tuile.choisi .magnet { transform: rotate(0) scale(1.06); outline: 3px solid var(--jaune); outline-offset: 2px; }
.tuile.relie .magnet { transform: rotate(0); }

/* ——— Jeu 3 : tri ——— */
.zone { border-radius: 12px; padding: 12px; transition: background .15s, outline-color .15s; }
.reserve {
  display: flex; flex-wrap: wrap; gap: 10px; min-height: 72px;
  background: #ffffff14; margin-bottom: 16px; outline: 2px dashed transparent;
}
.groupes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; margin-bottom: 16px; }
.groupe { background: var(--craie); color: var(--encre); min-height: 110px; outline: 3px dashed transparent; cursor: pointer; }
.zone.cible { outline-color: #ffffff80; }
.groupe.cible { outline-color: var(--jaune); }
.zone.survol { outline-color: var(--jaune); outline-style: solid; background: #fff6d6; }
.reserve.survol { background: #ffffff2a; }
.tete-groupe { display: flex; gap: 8px; align-items: center; margin: 0 0 8px; font-size: 1.1rem; }
.nom-groupe {
  flex: 1; min-width: 0; font: 700 1.05rem var(--police-ui); color: var(--encre);
  border: 0; border-bottom: 2px solid #c9cde0; background: transparent; padding: 6px 2px; border-radius: 0;
}
.nom-groupe:focus { outline: none; border-color: var(--frigo); }
.nom-groupe.manque { border-color: var(--rose); background: #ffe3ea; }
.supprimer { border: 0; background: none; font-size: 1.6rem; line-height: 1; color: #888; min-width: 44px; min-height: 44px; cursor: pointer; }
.contenu { display: flex; flex-wrap: wrap; gap: 8px; }
.vide { margin: 0; opacity: .6; font-size: .95rem; }
.groupe .vide { color: #555; }
.carte {
  border: 0; background: none; padding: 2px; cursor: grab; touch-action: none;
  font-size: 1rem; min-height: 44px; user-select: none; -webkit-user-select: none;
}
.carte .magnet { transition: transform .15s; }
.carte.choisie .magnet { transform: rotate(0) scale(1.06); outline: 3px solid var(--jaune); outline-offset: 2px; }
.groupe .carte.choisie .magnet { outline-color: var(--frigo); }
.carte.en-vol { opacity: .3; }
.fantome { position: fixed; z-index: 50; pointer-events: none; transform: rotate(-3deg) scale(1.05); }
.bouton.secondaire { background: var(--craie); box-shadow: 0 4px 0 #9aa3c8; }
.bouton.secondaire:active { box-shadow: 0 1px 0 #9aa3c8; }

/* ——— Fin ——— */
.fin { padding-top: 10vh; position: relative; z-index: 1; }
.recap { list-style: none; padding: 0; margin: 0 0 1.5em; font-size: 1.15rem; display: grid; gap: .3em; }
.recap strong { color: var(--jaune); font-size: 1.4em; }
.confettis { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confettis i {
  position: absolute; top: -20px; left: var(--x); width: 10px; height: 16px; background: var(--c);
  border-radius: 2px; animation: tombe 2.6s var(--d) ease-in forwards;
}
@keyframes tombe { to { transform: translateY(110vh) rotate(540deg); } }
