/* =========================================================
   PUISSANCE 4 · design (frontend uniquement)
   Direction artistique : une affiche imprimée en risographie.
   Peu d'encres, posées à plat (corail, jaune, bleu canard, noir, papier),
   des statues et des gravures en noir et blanc, et un grain d'impression
   sur toute la page. Le Puissance 4 devient un jeu de salon, au château.
   ========================================================= */

:root {
  --encre: #1f1b1c;
  --papier: #f0ebe2;
  --corail: #d6524f;
  --jaune: #ffe600;
  --canard: #1789a9;
  --titre: "Avenir Next Condensed", "Arial Narrow", "Helvetica Neue", Impact, sans-serif;
  --manuscrit: "Snell Roundhand", "Savoye LET", "Apple Chancery", "Brush Script MT", cursive;
  --police: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --courbe: cubic-bezier(.2, .8, .2, 1);
  --elan: cubic-bezier(.3, 1.5, .5, 1);
  /* Couleurs de l'écran courant (chaque écran les redéfinit) */
  --fond: var(--corail);
  --texte: var(--papier);
  --vif: var(--jaune);
  --bouton: var(--jaune);
  --sur-bouton: var(--encre);
  --decalage: var(--encre);
}

/* L'encre de chaque joueur */
[data-joueur="X"] { --accent: var(--jaune); --sur-accent: var(--encre); }
[data-joueur="O"] { --accent: var(--corail); --sur-accent: var(--papier); }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  /* Pas de sélection de texte : en cliquant vite sur le plateau, on surlignait l'interface. */
  -webkit-user-select: none; user-select: none;
  background: var(--encre);
  color: var(--papier);
  font-family: var(--police);
  font-size: 17px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; letter-spacing: inherit; }
h1, h2, h3, p { margin: 0; }
img { -webkit-user-drag: none; user-select: none; }

.invisible { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: .05em .45em;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  font: 600 .8em var(--police);
  text-align: center;
}

/* Le grain d'impression, par-dessus tout. Il est fixe, comme sur du papier. */
/* Ses points sont un peu grossis (background-size) pour qu'on le voie encore de loin. */
.grain { position: fixed; inset: 0; z-index: 90; pointer-events: none; background-size: 330px 330px; image-rendering: pixelated; }

/* ---------- Écran de chargement ---------- */
.chargement {
  position: fixed; inset: 0; z-index: 55;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--encre); color: var(--papier);
  transition: clip-path .7s cubic-bezier(.65, 0, .3, 1), visibility 0s .7s;
  clip-path: circle(120% at 50% 50%);
}
/* Il se referme comme une tache d'encre qui se retire. */
.chargement.fini { clip-path: circle(0% at 50% 50%); visibility: hidden; pointer-events: none; }
.chargement .manuscrit { font-size: clamp(1.4rem, 3vw, 2.2rem); margin-right: 3em; }
.chargement-titre { font: italic 800 clamp(2.4rem, 7vw, 4.6rem) var(--titre); text-transform: uppercase; letter-spacing: .03em; line-height: 1; color: var(--jaune); }
.jauge { width: min(260px, 60vw); height: 5px; margin-top: 22px; background: rgba(240, 235, 226, .18); overflow: hidden; }
.jauge i { display: block; height: 100%; background: var(--jaune); transform-origin: 0 50%; scale: 0 1; transition: scale .25s ease-out; }

/* ---------- Plateau et écrans ---------- */

#plateau2d {
  position: fixed; inset: 0; z-index: 0; width: 100%; height: 100%; display: block;
  opacity: 0; pointer-events: none; transition: opacity .35s ease;
}
#plateau2d.visible { opacity: 1; transition: opacity .45s ease; }

#app { position: relative; z-index: 1; height: 100vh; height: 100dvh; overflow: hidden; overflow: clip; }

/* Chaque écran arrive comme une tache d'encre qui s'étale depuis le centre. */
.ecran {
  position: absolute; inset: 0; z-index: 1;
  display: flex;
  padding: 24px;
  overflow: hidden; overflow: clip;   /* « clip » : l'écran ne peut jamais défiler, même par accident */
  background: var(--fond);
  color: var(--texte);
  visibility: hidden;
  transition: visibility 0s .8s;
}
.ecran > * { margin: auto; }
.ecran.actif { z-index: 2; visibility: visible; transition: none; animation: encre .8s cubic-bezier(.65, 0, .3, 1) both; }
@keyframes encre {
  from { clip-path: circle(0% at 50% 58%); }
  to { clip-path: circle(120% at 50% 58%); }
}
/* Vers le jeu : l'écran précédent s'efface tout de suite, la salle grise apparaît derrière. */
body[data-ecran="ecran-jeu"] .ecran:not(.actif) { transition: none; }

/* Apparition en cascade du contenu de chaque écran */
.r { opacity: 0; }
.ecran.actif .r { animation: revele .8s var(--courbe) both; animation-delay: calc(.4s + var(--i, 0) * 70ms); }
@keyframes revele {
  from { opacity: 0; transform: translateY(26px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Typographie commune ---------- */

.manuscrit {
  font-family: var(--manuscrit);
  font-size: clamp(1.7rem, 4.2vw, 3.1rem);
  font-weight: 400; line-height: 1;
  rotate: -4deg;
}

/* ---------- Boutons : des aplats, avec un décalage d'impression au survol ---------- */

.btn {
  padding: .7em 1.6em;
  border: 0; border-radius: 3px;
  font-family: var(--titre);
  font-size: 1.05rem; font-weight: 800; font-style: italic;
  text-transform: uppercase; letter-spacing: .09em;
  cursor: pointer;
  transition: transform .18s var(--elan), box-shadow .18s var(--elan), background .2s, color .2s;
}
.btn:focus-visible, .choix-avatar:focus-visible, .btn-rond:focus-visible, .format button:focus-visible {
  outline: 3px solid var(--papier); outline-offset: 3px;
}

.btn-principal { background: var(--bouton); color: var(--sur-bouton); box-shadow: 0 0 0 var(--decalage); }
.btn-principal:hover { transform: translate(-4px, -4px); box-shadow: 6px 6px 0 var(--decalage); }
.btn-principal:active { transform: none; box-shadow: 0 0 0 var(--decalage); transition-duration: .05s; }

.btn-fantome { background: none; color: inherit; box-shadow: inset 0 0 0 2px currentColor; }
.btn-fantome:hover { background: var(--texte); color: var(--fond); box-shadow: inset 0 0 0 2px var(--texte); }
.btn-fantome:active { transform: scale(.96); }

.btn-lien { background: none; padding-left: .6em; padding-right: .6em; text-decoration: underline; text-underline-offset: .3em; text-decoration-thickness: 2px; }
.btn-lien:hover { opacity: .65; }

.btn-geant { padding: .75em 2.4em; font-size: 1.35rem; }
.btn-petit { padding: .6em 1.2em; font-size: .9rem; }

.btn-rond {
  position: fixed; top: 18px; right: 18px; z-index: 30;
  width: 42px; height: 42px; padding: 10px;
  border: 0; border-radius: 50%;
  background: var(--encre); color: var(--papier);
  box-shadow: 0 0 0 1.5px rgba(240, 235, 226, .4);
  cursor: pointer;
  transition: transform .2s var(--elan);
}
.btn-rond:hover { transform: scale(1.12) rotate(-8deg); }
.btn-rond svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-son .croix { display: none; }
.btn-son[aria-pressed="false"] .ondes { display: none; }
.btn-son[aria-pressed="false"] .croix { display: inline; }
.btn-aide { right: 70px; padding: 0; font: italic 800 1.25rem var(--titre); }

.long, .court { display: inline; }
.court { display: none; }

.actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.actions-centre { justify-content: center; }

.pastille { display: inline-block; flex: none; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--encre); }

/* Une statue : image détourée, tournée vers l'adversaire. */
.statue, .avatar img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; scale: var(--miroir, 1) 1; }

/* =========================================================
   1. ACCUEIL : un collage, comme une affiche
   ========================================================= */

#ecran-intro { --fond: var(--corail); --texte: var(--papier); --vif: var(--jaune); }

.collage { position: absolute; inset: 0; margin: 0; pointer-events: none; }
.objet {
  position: absolute;
  /* Chaque objet suit un peu la souris, selon sa profondeur (--p). */
  translate: calc(var(--sx, 0) * var(--p) * -46px) calc(var(--sy, 0) * var(--p) * -46px);
  transition: translate .9s var(--courbe);
  opacity: 0; scale: .5;
}
.ecran.actif .objet {
  animation: objet-entre 1.1s var(--elan) both, flotte 7s ease-in-out infinite alternate;
  animation-delay: var(--d, .3s), var(--d, .3s);
}
@keyframes objet-entre { from { opacity: 0; scale: .5; } to { opacity: 1; scale: 1; } }
@keyframes flotte {
  from { transform: rotate(var(--rot, 0deg)) translateY(-7px); }
  to { transform: rotate(calc(var(--rot, 0deg) + 3deg)) translateY(9px); }
}
.objet[data-objet="buste"] {
  left: 50%; top: 47%; height: min(86vh, 96vw); margin: calc(min(86vh, 96vw) / -2) 0 0 calc(min(86vh, 96vw) * -.425);
  --d: .15s;
}
.objet[data-objet="papillon"] { left: 15%; top: -4%; width: 27vmin; --rot: -14deg; --d: .45s; }
.objet[data-objet="sphere"] { right: 12%; top: 3%; width: 15vmin; --d: .55s; }
.objet[data-objet="dodecaedre"] { left: -4%; top: 32%; width: 30vmin; --rot: -8deg; --d: .65s; }
.objet[data-objet="feuille"] { right: -1%; top: 24%; width: 22vmin; --rot: 12deg; --d: .75s; }
.objet[data-objet="fleur"] { left: 6%; bottom: -9%; width: 30vmin; --rot: 6deg; --d: .85s; }
.objet[data-objet="pyramide"] { right: 4%; bottom: -5%; width: 28vmin; --rot: -6deg; --d: .95s; }

.intro-centre { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 44vh; }
.intro-centre .manuscrit { margin: 0 0 -.1em 28%; text-shadow: 2px 2px 0 var(--encre), -1px -1px 0 var(--encre), 2px -1px 0 var(--encre), -1px 2px 0 var(--encre); }

.titre {
  font-family: var(--titre);
  font-size: clamp(3.4rem, 12vw, 9.5rem);
  font-weight: 800; font-style: italic;
  text-transform: uppercase; letter-spacing: .02em; line-height: .92;
  color: var(--vif);
  white-space: nowrap;
}
.titre .lettre { display: inline-block; opacity: 0; }
.ecran.actif .titre .lettre {
  animation: lettre .7s var(--elan) both;
  animation-delay: calc(.75s + var(--i) * 45ms);
}
@keyframes lettre {
  from { opacity: 0; transform: translateY(.5em) rotate(8deg); }
  to { opacity: 1; transform: none; }
}

.sous-titre { margin-top: 14px; padding: .5em 1.1em; background: var(--encre); color: var(--papier); font-size: clamp(.72rem, 1.5vw, .92rem); font-weight: 600; text-transform: uppercase; letter-spacing: .26em; }
#ecran-intro .btn-geant { margin-top: 26px; }

/* =========================================================
   2. PROFIL JOUEUR : la statue à gauche, le nom et le choix à droite
   ========================================================= */

#ecran-joueur[data-joueur="X"] { --fond: var(--jaune); --texte: var(--encre); --vif: var(--encre); --bouton: var(--encre); --sur-bouton: var(--jaune); --decalage: var(--corail); }
#ecran-joueur[data-joueur="O"] { --fond: var(--corail); --texte: var(--papier); --vif: var(--jaune); --bouton: var(--jaune); --sur-bouton: var(--encre); --decalage: var(--encre); }

.profil {
  width: min(1120px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: clamp(20px, 5vw, 70px);
}

.profil-piece { height: min(78vh, 620px); align-self: end; }
/* (Les statues apparaissent par une éclaboussure d'encre, dessinée par script.js.) */
@keyframes statue-monte { from { opacity: 0; translate: 0 70px; } to { opacity: 1; translate: 0 0; } }
@keyframes statue-change { from { opacity: 0; translate: -40px 0; rotate: -5deg; } to { opacity: 1; translate: 0 0; rotate: 0deg; } }

.profil-contenu { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 480px; }
.profil-contenu .manuscrit { margin-bottom: 4px; }
.etape { margin-left: .5em; font: 600 .85rem var(--police); letter-spacing: .2em; text-transform: uppercase; opacity: .7; }

.champ-titre {
  -webkit-user-select: text; user-select: text;
  width: 100%;
  padding: .05em 0 .08em;
  border: 0; border-bottom: 4px solid currentColor;
  border-radius: 0;
  background: none;
  font-family: var(--titre);
  font-size: clamp(2.6rem, 6vw, 4.6rem);
  font-weight: 800; font-style: italic;
  text-transform: uppercase; letter-spacing: .02em; line-height: 1.05;
  color: var(--vif);
  caret-color: currentColor;
  outline: none;
}
.champ-titre::placeholder { color: currentColor; opacity: .32; }

.profil-aide { margin-top: 26px; font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .24em; }

.grille-avatars { display: grid; grid-template-columns: repeat(4, auto); gap: 14px; margin-top: 12px; }

/* Les statues à choisir : des médaillons de papier */
.choix-avatar {
  width: 78px; height: 78px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--papier);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--encre);
  transition: transform .25s var(--elan), box-shadow .2s, opacity .2s;
}
.choix-avatar img { display: block; width: 130%; height: 130%; margin: 4% 0 0 -15%; object-fit: cover; object-position: 50% 0; }
.choix-avatar:hover:not(:disabled) { transform: translateY(-5px) rotate(-4deg); }
.choix-avatar[aria-checked="true"] { transform: scale(1.12); box-shadow: 0 0 0 2px var(--encre), 5px 5px 0 2px var(--encre); }
.choix-avatar:disabled { cursor: not-allowed; opacity: .28; }

.profil-contenu .actions { margin-top: 34px; }

/* =========================================================
   3. FACE À FACE : l'écran coupé en deux encres
   ========================================================= */

#ecran-versus {
  background: linear-gradient(100deg, var(--jaune) 0 50%, var(--corail) 50% 100%);
  --texte: var(--encre); --bouton: var(--encre); --sur-bouton: var(--papier); --decalage: var(--papier);
}

.versus-bloc { display: flex; flex-direction: column; align-items: center; gap: clamp(12px, 2.6vh, 26px); text-align: center; width: min(1100px, 100%); }
.versus { display: flex; align-items: flex-end; justify-content: center; gap: clamp(10px, 4vw, 60px); width: 100%; }

.duelliste { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.duelliste[data-joueur="O"] { color: var(--papier); }
.place-piece { height: clamp(150px, 36vh, 380px); width: 100%; }
/* Les statues arrivent chacune de son côté. */
/* (Elles aussi apparaissent par une éclaboussure d'encre.) */
.duelliste[data-joueur="X"] { --cote: -1; }
.duelliste[data-joueur="O"] { --cote: 1; }
@keyframes duel-entre { from { opacity: 0; translate: calc(var(--cote) * 30vw) 0; } to { opacity: 1; translate: 0 0; } }
.versus.choc .statue { animation: duel-choc .5s var(--courbe) both !important; }
@keyframes duel-choc { 0% { translate: 0 0; } 30% { translate: calc(var(--cote) * 22px) -8px; rotate: calc(var(--cote) * 3deg); } 100% { translate: 0 0; rotate: 0deg; } }

.duelliste h3 {
  font-family: var(--titre);
  font-size: clamp(1.6rem, 4.4vw, 3rem); font-weight: 800; font-style: italic;
  text-transform: uppercase; letter-spacing: .03em; line-height: 1;
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.duelliste-role { display: inline-flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .22em; }

/* Le « VS » s'abat entre les deux statues. */
.vs {
  flex: none; align-self: center;
  display: grid; place-items: center;
  width: clamp(64px, 11vmin, 104px); aspect-ratio: 1;
  position: relative;
}
.vs span {
  display: grid; place-items: center; width: 100%; height: 100%;
  border-radius: 50%;
  background: var(--encre); color: var(--papier);
  font: italic 800 clamp(1.5rem, 4.6vmin, 2.6rem) var(--titre); letter-spacing: .04em;
  opacity: 0;
}
.vs::before { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--encre); opacity: 0; }
.ecran.actif .vs span { animation: vs-impact .55s var(--elan) .9s both; }
.ecran.actif .vs::before { animation: vs-onde .9s var(--courbe) 1.05s both; }
@keyframes vs-impact { 0% { opacity: 0; transform: scale(3.6) rotate(-14deg); } 55% { opacity: 1; } 100% { opacity: 1; transform: none; } }
@keyframes vs-onde { 0% { opacity: 1; transform: scale(.6); } 100% { opacity: 0; transform: scale(2.8); } }

/* Choix du format du match */
.format { display: inline-flex; gap: 2px; padding: 4px; border-radius: 4px; background: var(--encre); }
.format button {
  padding: .5em 1.1em; border: 0; border-radius: 2px; background: none;
  font: italic 800 .92rem var(--titre); text-transform: uppercase; letter-spacing: .08em;
  color: var(--papier); white-space: nowrap;
  cursor: pointer; transition: background .2s, color .2s;
}
.format button:hover { color: var(--jaune); }
.format button[aria-checked="true"] { background: var(--papier); color: var(--encre); }
.versus-bloc .actions { flex-direction: column; gap: 6px; }

/* Choix du décor : une étiquette par salle, avec une pastille à sa couleur */
.choix-decor { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.choix-decor button {
  display: inline-flex; align-items: center; gap: .5em;
  padding: .42em .9em .42em .6em; border: 0; border-radius: 3px;
  background: var(--papier); color: var(--encre);
  font: italic 800 .86rem var(--titre); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap;
  box-shadow: inset 0 0 0 2px var(--encre);
  cursor: pointer; transition: transform .2s var(--elan), background .2s, color .2s;
}
.choix-decor button i { width: 1.1em; height: 1.1em; border-radius: 50%; box-shadow: 0 0 0 2px var(--encre); }
.choix-decor button:hover { transform: translateY(-3px) rotate(-2deg); }
.choix-decor button[aria-checked="true"] { background: var(--encre); color: var(--papier); }
.choix-decor button[aria-checked="true"] i { box-shadow: 0 0 0 2px var(--papier); }
.choix-decor button:focus-visible { outline: 3px solid var(--papier); outline-offset: 3px; }

/* =========================================================
   4. JEU : la salle du château (le fond et le plateau sont sur la toile)
   ========================================================= */

#ecran-jeu {
  display: block; padding: 0; background: none; animation: none;
  --fond: var(--canard); --texte: var(--papier); --vif: var(--jaune);
  --bouton: var(--jaune); --sur-bouton: var(--encre); --decalage: var(--encre);
}
#ecran-jeu > * { margin: 0; }

.hud { transition: opacity .7s var(--courbe), translate .7s var(--courbe); }
.hud-cache .hud { opacity: 0; translate: 0 14px; pointer-events: none; }

/* Avant que l'encre ne les touche, la salle et ses statues sont pâles et grises. */
/* (Pas de transparence : sinon on verrait le décor à travers les statues.) */
.carte-joueur { transition: scale .45s var(--courbe); }
/* Le fondu gris -> couleur ne sert que pendant le lancement (classe « eveil »). */
.eveil .carte-joueur, .eveil .decor { transition: filter .8s ease, scale .45s var(--courbe); }
/* Le décor est découpé aux bords de la salle : il ne dépasse jamais de la page. */
#decor { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.endormi, .carte-joueur.endormi { filter: grayscale(1) contrast(.22) brightness(1.32); }

/* Les objets du décor : chacun a une place dans la salle. */
.decor { position: absolute; pointer-events: none; }
.decor { width: calc(var(--taille, 15) * 1vmin); scale: var(--miroir, 1) 1; rotate: var(--rot, 0deg); }
/* Où les poser : toujours dans l'espace entre un joueur et le plateau, jamais au-dessus
   d'une statue (ils sont de la même couleur qu'elle et se confondraient avec). */
.decor[data-place="suspendu-gauche"] { left: max(18%, 258px); top: -4.5vmin; }
.decor[data-place="suspendu-droite"] { right: max(18%, 258px); top: -4.5vmin; }
.decor[data-place="haut-gauche"] { left: max(19%, 266px); top: 5vmin; }
.decor[data-place="haut-droite"] { right: max(21%, 292px); top: 8vmin; }
.decor[data-place="pres-du-bouquet"] { left: max(25%, 340px); top: 24vmin; }
/* Comment ils bougent */
.decor.balance { transform-origin: 50% 0; animation: balance 6s ease-in-out infinite alternate; }   /* un lustre qui se balance à peine */
.decor.balance[data-place="suspendu-droite"] { animation-delay: -3s; }
.decor.flotte { animation: flotte-decor 7s ease-in-out infinite alternate; }
.decor.flotte[data-place="haut-droite"] { animation-delay: -3.5s; }
/* Un papillon : il se promène lentement et, de temps en temps, bat des ailes quelques fois. */
.decor.papillon { animation: battement 9s ease-in-out infinite, promenade 31s ease-in-out infinite; }
.decor.papillon[data-place="pres-du-bouquet"] { animation-duration: 12s, 37s; animation-delay: -5s, -11s; }
@keyframes balance { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }
@keyframes flotte-decor { from { transform: translateY(-6px); } to { transform: translateY(8px); } }
@keyframes battement {
  0%, 58% { transform: scaleX(1); }
  62% { transform: scaleX(.28); }
  66% { transform: scaleX(1); }
  70% { transform: scaleX(.28); }
  74% { transform: scaleX(1); }
  79% { transform: scaleX(.4); }
  85%, 100% { transform: scaleX(1); }
}
@keyframes promenade {
  0%, 100% { translate: 0 0; }
  22% { translate: 3.5vmin -2vmin; }
  47% { translate: 7vmin 1.5vmin; }
  71% { translate: 2vmin 3.5vmin; }
  88% { translate: -1.5vmin 1vmin; }
}
.carte-joueur { z-index: 1; }

/* Le statut : une ligne d'affiche, le nom du joueur dans un bandeau à son encre */
.statut {
  position: absolute; top: 22px; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 170px);
  display: flex; align-items: center; gap: .32em;
  font-family: var(--titre);
  font-size: clamp(1.25rem, 3vw, 2.1rem); font-weight: 800; font-style: italic;
  text-transform: uppercase; letter-spacing: .05em; line-height: 1.1;
  white-space: nowrap;
}
.statut b { padding: .04em .4em; background: var(--accent); color: var(--sur-accent); font-weight: 800; }
.statut.change { animation: statut-change .45s var(--elan); }
@keyframes statut-change { from { opacity: 0; scale: .8; rotate: -3deg; } to { opacity: 1; scale: 1; rotate: 0deg; } }

/* Un joueur : sa statue, posée sur sa plaque */
.carte-joueur {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 214px;
  display: flex; flex-direction: column; align-items: stretch;
  /* Le joueur qui attend est en retrait : plus petit, plaque sombre. */
  scale: .9;
}
#carte-X { left: 20px; }
#carte-O { right: 20px; }
.carte-joueur.actif, .carte-joueur.gagnant { scale: 1; }
#carte-X { --cote: -1; }
#carte-O { --cote: 1; }

/* Les statues réagissent. À son tour, le joueur se penche vers le plateau. */
.carte-joueur .avatar { position: relative; transform-origin: 50% 100%; transition: transform .55s var(--elan); }
.carte-joueur.actif .avatar { transform: rotate(calc(var(--cote) * -3.5deg)) translateX(calc(var(--cote) * -7px)); }
.carte-joueur .avatar.sursaut { animation: sursaut .6s var(--courbe); }     /* l'adversaire menace de gagner */
.carte-joueur .avatar.tremble { animation: tremble .45s linear; }          /* colonne pleine */
@keyframes sursaut {
  0% { translate: 0 0; scale: 1; }
  25% { translate: 0 -20px; scale: 1.07 .96; }
  55% { translate: 0 3px; scale: .98 1.03; }
  100% { translate: 0 0; scale: 1; }
}
@keyframes tremble {
  0%, 100% { translate: 0 0; }
  15% { translate: -6px 0; } 30% { translate: 6px 0; } 45% { translate: -5px 0; }
  60% { translate: 4px 0; } 80% { translate: -2px 0; }
}

/* Victoire : le perdant se décolore. Le vainqueur, lui, quitte sa plaque pour aller danser. */
.carte-joueur.perdant { filter: grayscale(1) contrast(.24) brightness(1.3); scale: .86; transition: filter 1.1s ease, scale .6s var(--courbe); }

/* ---------- La danse du vainqueur ----------
   Une toile par-dessus la salle où script.js dessine la vidéo de la statue (détourée, avec le grain). */
.danseur {
  position: fixed; z-index: 44; pointer-events: none;
  transform-origin: 50% 100%;
  animation: se-dresse .45s var(--elan) both;
  transition: opacity .3s;
}
@keyframes se-dresse { from { scale: .55; opacity: 0; } }
.danseur.salut { opacity: 0; }
.carte-joueur.gagnant .avatar { transform: none; }

/* La salle est passée à l'encre du vainqueur : on garde tout lisible dessus. */
#ecran-jeu { transition: color .6s ease; }
#ecran-jeu[data-gagnant="X"] { --texte: var(--encre); --fond: var(--jaune); }
#ecran-jeu[data-gagnant="O"] { --texte: var(--papier); --fond: var(--corail); }
#ecran-jeu[data-gagnant] .statut b { background: var(--encre); color: var(--accent); }
#ecran-jeu[data-gagnant] .carte-joueur.gagnant .plaque { background: var(--encre); color: var(--accent); box-shadow: 6px 6px 0 var(--papier); }
#ecran-jeu[data-gagnant] .coup { box-shadow: 0 0 0 1.5px var(--encre); }
.carte-joueur .avatar { height: clamp(150px, 40vh, 340px); }

.plaque {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 12px 10px 10px;
  background: var(--encre); color: var(--papier);
  box-shadow: inset 0 0 0 1.5px rgba(240, 235, 226, .3);
  text-align: center;
  transition: background .3s, color .3s, box-shadow .3s var(--elan);
}
.carte-joueur.actif .plaque, .carte-joueur.gagnant .plaque { background: var(--accent); color: var(--sur-accent); box-shadow: 6px 6px 0 var(--encre); }
.carte-nom {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: italic 800 1.5rem var(--titre); text-transform: uppercase; letter-spacing: .04em; line-height: 1;
}
.carte-score { display: flex; justify-content: center; align-items: center; gap: 6px; min-height: 1.2em; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; }
/* Un point par manche à gagner */
.point { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 0 0 2px currentColor; }
.point.plein { background: currentColor; animation: point-gagne .6s var(--elan); }
@keyframes point-gagne { from { transform: scale(2.4); opacity: 0; } to { transform: none; opacity: 1; } }
.carte-temps { font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .12em; opacity: .75; }
.carte-tour {
  position: absolute; left: 50%; bottom: 100%; translate: -50% 12%; z-index: 1;
  width: max-content;
  padding: .12em .6em .2em;
  background: var(--encre);
  font: 400 1.5rem var(--manuscrit); color: var(--papier);
  rotate: -4deg;
  opacity: 0; scale: .7;
  transition: opacity .3s, scale .35s var(--elan);
}
.carte-joueur.actif .carte-tour { opacity: 1; scale: 1; }

.bas {
  position: absolute; left: 0; right: 0; bottom: 20px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.barre { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 0 12px; }

/* Historique : une pastille par coup, à l'encre du joueur, avec le numéro de colonne */
.coups {
  display: flex; align-items: center; gap: 5px;
  max-width: min(92vw, 560px); height: 32px; margin: 0; padding: 0 16px;
  list-style: none; overflow-x: auto; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
}
.coups::-webkit-scrollbar { display: none; }
.coups > :first-child { margin-left: auto; }
.coups > :last-child { margin-right: auto; }
.coups-vide { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .2em; white-space: nowrap; opacity: .85; }
.coup {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--sur-accent);
  font: 800 .74rem var(--titre); line-height: 1;
  transition: opacity .3s, transform .3s var(--elan);
}
.coup.dernier { box-shadow: 0 0 0 2px var(--encre); animation: coup-entre .4s var(--elan); }
.coup.attente { opacity: .25; transform: scale(.78); }
@keyframes coup-entre { from { transform: scale(0); } to { transform: none; } }

/* =========================================================
   Fenêtres, message, erreur
   ========================================================= */

.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 20px;
  background: rgba(31, 27, 28, .72);
  opacity: 0; visibility: hidden;
  transition: opacity .35s, visibility 0s .35s;
}
.modal.ouvert { opacity: 1; visibility: visible; transition-delay: 0s; }

.modal-boite {
  --fond: var(--papier); --texte: var(--encre); --bouton: var(--encre); --sur-bouton: var(--papier); --decalage: var(--corail);
  width: min(100%, 560px);
  padding: clamp(24px, 4.5vw, 40px);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
  background: var(--papier); color: var(--encre);
  box-shadow: 12px 12px 0 var(--accent, var(--jaune));
  transform: scale(.85) rotate(-3deg);
  transition: transform .5s var(--elan);
}
.modal.ouvert .modal-boite { transform: none; }
.modal-boite h2 {
  font: italic 800 clamp(2rem, 6vw, 3.2rem) var(--titre);
  text-transform: uppercase; letter-spacing: .02em; line-height: 1; overflow-wrap: anywhere;
}
.modal-boite .manuscrit { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.fin-avatars { display: flex; justify-content: center; gap: 18px; margin: 2px 0 -4px; }
.fin-avatars .avatar { width: 170px; height: 190px; }
.modal.ouvert .fin-avatars .avatar { animation: avatar-gagnant .7s var(--elan) .12s both; }
@keyframes avatar-gagnant { from { transform: translateY(50px) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.fin-texte { font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .2em; }
.modal-boite .actions { margin-top: 16px; }
/* Match gagné : la fenêtre passe à l'encre du vainqueur. */
.modal-boite.match { background: var(--accent); color: var(--sur-accent); box-shadow: 12px 12px 0 var(--encre); --fond: var(--accent); --texte: var(--sur-accent); }
.modal-boite.match .fin-avatars .avatar { width: 210px; height: 230px; }
.modal-boite.match[data-joueur="O"] { --bouton: var(--jaune); --sur-bouton: var(--encre); --decalage: var(--encre); }

/* Règles et raccourcis */
.aide { width: min(100%, 520px); align-items: stretch; gap: 16px; text-align: left; --accent: var(--canard); }
.aide h2, .aide .manuscrit { text-align: center; }
.aide .manuscrit { margin-bottom: -6px; }
.aide-regles { margin: 0; padding-left: 1.2em; display: grid; gap: 8px; }
.aide-touches { margin: 0; display: grid; gap: 8px; padding: 14px 16px; border: 2px solid var(--encre); }
.aide-touches div { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.aide-touches dt { white-space: nowrap; }
.aide-touches dd { margin: 0; font-size: .92rem; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: 104px; z-index: 50;
  padding: .6em 1.3em;
  background: var(--papier); color: var(--encre);
  font: italic 800 1rem var(--titre); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap;
  box-shadow: 5px 5px 0 var(--encre);
  opacity: 0; transform: translate(-50%, 16px) rotate(-2deg);
  transition: opacity .3s, transform .4s var(--elan);
  pointer-events: none;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0) rotate(-2deg); }

.erreur-serveur {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  padding: 12px 120px 12px 20px;
  background: var(--papier); border-bottom: 3px solid var(--encre);
  color: var(--encre); text-align: center; font-size: .95rem; font-weight: 600;
  display: none;
}
.erreur-serveur.visible { display: block; }

#confettis { position: fixed; inset: 0; z-index: 45; width: 100%; height: 100%; pointer-events: none; }

/* =========================================================
   Petits écrans
   ========================================================= */

@media (max-width: 880px) {
  .intro-centre { margin-top: 40vh; }
  .objet[data-objet="buste"] { top: 40%; }

  .profil { grid-template-columns: 1fr; gap: 6px; }
  .profil-piece { height: 30vh; }
  .profil-contenu { align-items: center; text-align: center; margin: 0 auto; }
  .champ-titre { text-align: center; }
  .profil-aide { margin-top: 14px; }
  .choix-avatar { width: 62px; height: 62px; }
  .profil-contenu .actions { margin-top: 20px; justify-content: center; }

  .place-piece { height: 30vh; }
  .format button { padding: .5em .7em; font-size: .8rem; }
  .choix-decor button { font-size: .74rem; padding: .4em .7em .4em .5em; }

  .decor { display: none; }
  .statut { top: 152px; max-width: calc(100% - 28px); font-size: 1.15rem; }
  .carte-joueur {
    top: 64px; transform: none;
    width: calc(50% - 20px);
    flex-direction: row; align-items: stretch;
  }
  #carte-X { left: 14px; }
  #carte-O { right: 14px; flex-direction: row-reverse; }
  .carte-joueur .avatar { flex: none; width: 58px; height: 74px; overflow: hidden; background: var(--papier); }
  .carte-joueur .avatar img { width: 150%; height: 150%; margin-left: -25%; object-fit: cover; object-position: 50% 0; }
  .plaque { flex: 1; min-width: 0; padding: 8px 6px; gap: 3px; justify-content: center; }
  .carte-joueur.actif .plaque { box-shadow: 4px 4px 0 var(--encre); }
  .carte-nom { font-size: 1.05rem; }
  .carte-tour { display: none; }

  .carte-joueur.actif .avatar { transform: none; }
  .btn-petit { padding: .55em .8em; font-size: .8rem; }
  .bas { bottom: 22px; gap: 8px; }
  .barre { gap: 8px; }
  .long { display: none; }
  .court { display: inline; }
  .fin-avatars .avatar { width: 130px; height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
