/* NeoGenesis : LE CASSE-TÊTE DU VILLAGE (casse-tete.html), la feuille du jeu.
   Tout est placé sous .ct-jeu (la section #ctJeu) : rien ici ne touche :root, html, body ni un élément du site.
   Les couleurs viennent des jetons du site (css/style.css), donc des quatre thèmes : clair, sombre, cyber, forêt.
   Les seules couleurs en dur sont l'anneau du focus et les pastilles posées SUR la peinture (blanc et ardoise
   #0b1222, en paire : lisibles sur n'importe quelle partie d'une image, claire ou sombre).
   Néon rationné : une lueur au survol ou au focus seulement. Aucun rouge pour un état de jeu ; --err-text ne sert
   qu'au filet de l'avis « partie impossible à garder » (panne technique). */

.ct-jeu {
  --ct-gap: 2px;          /* l'espace entre deux pièces */
  --ct-pad: 6px;          /* la marge du tapis autour du plateau */
  --ct-rayon: 14px;
  --ct-anneau: #ffffff;   /* focus et pièce prise : anneau blanc... */
  --ct-anneau-2: #0b1222; /* ...doublé d'ardoise, visible sur toute peinture */
  --ct-tapis: var(--bg-3);
  position: relative;
}
.ct-jeu *, .ct-jeu *::before, .ct-jeu *::after { box-sizing: border-box; }
.ct-jeu :focus-visible { outline-width: 3px !important; }
.ct-jeu .ct-charge { padding: 2rem 1rem; color: var(--muted); margin: 0; }
.ct-jeu .ct-h { font-size: 1.25rem; font-weight: 800; margin: 0 0 .3rem; line-height: 1.3; color: var(--text); }
.ct-jeu .ct-ico { display: inline-block; line-height: 1; }

/* ---------- Boutons : principal (accent du thème) et secondaire (contour) ---------- */
.ct-jeu .ct-btn, .ct-jeu .ct-btn2 {
  display: inline-flex; align-items: center; justify-content: center; gap: .1rem;
  min-height: 44px; padding: .55rem 1.15rem; border-radius: 999px;
  font: inherit; font-size: .95rem; line-height: 1.2; text-decoration: none; cursor: pointer;
}
.ct-jeu .ct-btn { background: var(--cyan); color: var(--on-accent); font-weight: 800; border: 1px solid transparent; }
.ct-jeu .ct-btn:hover { filter: brightness(1.08); box-shadow: 0 0 14px rgba(var(--cyan-rgb), .35); }
.ct-jeu .ct-btn2 { background: transparent; color: var(--text); font-weight: 700; border: 1px solid var(--line); }
.ct-jeu .ct-btn2:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(var(--cyan-rgb), .22); }
/* une option allumée : fond de panneau, contour et trait d'accent, et une coche (jamais la couleur seule) */
.ct-jeu .ct-bascule[aria-pressed="true"] { background: var(--panel-2); border-color: var(--cyan); box-shadow: inset 0 -3px 0 var(--cyan); }
.ct-jeu .ct-coche { display: none; }
.ct-jeu .ct-bascule[aria-pressed="true"] .ct-coche {
  display: inline-flex; align-items: center; justify-content: center; margin-left: .45rem;
  width: 1.35em; height: 1.35em; border-radius: 999px; font-size: .8em; font-weight: 800;
  background: var(--cyan); color: var(--on-accent);
}
.ct-jeu .ct-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

/* ---------- L'écran de choix ---------- */
.ct-jeu .ct-reprise {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem;
  margin: 0 0 1.3rem; padding: .9rem 1rem;
  background: var(--grad-soft); border: 1px solid var(--line); border-left: 4px solid var(--cyan); border-radius: var(--ct-rayon);
}
.ct-jeu .ct-reprise-t { margin: 0; line-height: 1.5; color: var(--text); }
/* « Aucune partie à reprendre » (lien #reprendre sans partie valide) : dit, et écrit sous le titre */
.ct-jeu .ct-note { margin: 0 0 .6rem; color: var(--text); font-size: .92rem; line-height: 1.5; }
.ct-jeu .ct-form { display: flex; flex-direction: column; gap: 1.2rem; margin-top: .6rem; }
.ct-jeu .ct-champ { border: 0; margin: 0; padding: 0; min-width: 0; }
.ct-jeu .ct-champ legend { font-weight: 800; font-size: 1rem; margin: 0 0 .6rem; padding: 0; color: var(--text); }
.ct-jeu .ct-peintures {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: .7rem;
}
.ct-jeu .ct-peintures li { min-width: 0; }
/* la case à cocher couvre toute la carte, transparente : le toucher et l'exploration au doigt d'un lecteur d'écran
   tombent sur elle ; le dessin est celui de la carte qui la suit */
.ct-jeu .ct-peinture, .ct-jeu .ct-niveau { position: relative; display: block; cursor: pointer; height: 100%; }
.ct-jeu .ct-radio { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.ct-jeu .ct-carte {
  display: flex; flex-direction: column; height: 100%; overflow: hidden;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--ct-rayon);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ct-jeu .ct-carte img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: var(--panel-2); }
.ct-jeu .ct-carte-t { display: block; padding: .55rem .7rem .65rem; font-size: .9rem; font-weight: 700; line-height: 1.35; color: var(--text); }
.ct-jeu .ct-peinture:hover .ct-carte { border-color: rgba(var(--cyan-rgb), .6); }
.ct-jeu .ct-radio:checked + .ct-carte { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan); }
/* la coche est un dessin : son texte de remplacement est vide (« / "" »), sinon elle entre dans le nom de la case
   (« L'église… ✓, coché ») ; la première déclaration reste pour un navigateur qui ne lit pas cette syntaxe */
.ct-jeu .ct-radio:checked + .ct-carte::after {
  content: "✓"; content: "✓" / ""; position: absolute; top: .45rem; right: .45rem;
  display: flex; align-items: center; justify-content: center; width: 1.8rem; height: 1.8rem; border-radius: 999px;
  background: var(--cyan); color: var(--on-accent); font-weight: 800; font-size: 1rem;
  box-shadow: 0 0 0 2px var(--ct-anneau-2);
}
.ct-jeu .ct-radio:focus-visible + .ct-carte, .ct-jeu .ct-radio:focus-visible + .ct-pastille { outline: 3px solid var(--cyan); outline-offset: 3px; }

.ct-jeu .ct-niveaux { display: flex; flex-wrap: wrap; gap: .6rem; }
.ct-jeu .ct-niveau { flex: 1 1 9.5rem; max-width: 15rem; height: auto; }
.ct-jeu .ct-pastille {
  display: flex; flex-direction: column; gap: .1rem; height: 100%; min-height: 44px; padding: .55rem .9rem;
  background: var(--panel); border: 2px solid var(--line); border-radius: 12px; color: var(--text);
  transition: border-color .15s ease;
}
.ct-jeu .ct-pastille strong { font-size: 1rem; }
.ct-jeu .ct-pastille-d { font-size: .84rem; color: var(--muted); }
.ct-jeu .ct-niveau:hover .ct-pastille { border-color: rgba(var(--cyan-rgb), .6); }
.ct-jeu .ct-radio:checked + .ct-pastille { border-color: var(--cyan); background: var(--panel-2); box-shadow: inset 4px 0 0 var(--cyan); }
.ct-jeu .ct-radio:checked + .ct-pastille strong::before { content: "✓ "; content: "✓ " / ""; }

/* ---------- L'écran de jeu ---------- */
.ct-jeu .ct-entete { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem 1rem; margin: 0 0 .6rem; }
.ct-jeu .ct-entete .ct-h { margin: 0; }
.ct-jeu .ct-taille { margin: 0; color: var(--muted); font-size: .9rem; }
.ct-jeu .ct-outils { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 .7rem; }
.ct-jeu .ct-consigne { margin: 0 0 .8rem; color: var(--muted); font-size: .92rem; line-height: 1.5; max-width: 62rem; }
.ct-jeu .ct-panne {
  margin: 0 0 .8rem; padding: .6rem .85rem; max-width: 62rem;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--err-text); border-radius: 10px;
  color: var(--text); font-size: .9rem; line-height: 1.5;
}
.ct-jeu .ct-aire { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem; }
/* le cadre défile DANS la page si le plateau est plus large que l'écran (8 x 6 sur un petit téléphone) : jamais la page */
.ct-jeu .ct-cadre { flex: 1 1 20rem; min-width: 0; max-width: 100%; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.ct-jeu .ct-plateau {
  /* chaque pièce garde au moins 44 px de côté (cible tactile) */
  --ct-min: calc(var(--ct-cols) * 44px + (var(--ct-cols) - 1) * var(--ct-gap) + 2 * var(--ct-pad) + 2px);
  display: flex; flex-direction: column; gap: var(--ct-gap);
  width: 100%; min-width: var(--ct-min);
  max-width: max(var(--ct-min), min(60rem, calc((100vh - 14rem) * var(--ct-cols) / var(--ct-rows))));
  margin: 0 auto; padding: var(--ct-pad);
  background: var(--ct-tapis); border: 1px solid var(--line); border-radius: var(--ct-rayon);
}
.ct-jeu .ct-rangee { display: grid; grid-template-columns: repeat(var(--ct-cols), minmax(0, 1fr)); gap: var(--ct-gap); }
.ct-jeu .ct-case { display: block; min-width: 0; }
.ct-jeu .ct-piece {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; min-width: 44px; min-height: 44px;
  margin: 0; padding: 0; border: 0; border-radius: 3px; cursor: pointer;
  background-color: var(--panel-2); background-repeat: no-repeat;
  font: inherit; color: transparent;
  transition: transform .15s ease, box-shadow .15s ease;
}
/* la lueur de survol : seulement avec un vrai pointeur (au toucher, :hover reste collé à la dernière pièce touchée
   et la ferait paraître encore prise) */
@media (hover: hover) {
  .ct-jeu .ct-piece:hover { z-index: 1; box-shadow: 0 0 0 2px rgba(var(--cyan-rgb), .9), 0 0 14px rgba(var(--cyan-rgb), .45); }
}
/* le focus : anneau blanc DANS la pièce, doublé d'ardoise (lisible sur une neige claire comme sur une nuit indigo) */
.ct-jeu .ct-piece:focus-visible {
  z-index: 2;
  outline: 3px solid var(--ct-anneau) !important; outline-offset: -3px !important;
  box-shadow: inset 0 0 0 6px var(--ct-anneau-2), 0 0 0 2px var(--ct-anneau-2);
}
/* la pièce prise : plus petite, soulevée, marquée d'un double anneau et d'un signe d'échange (pas la couleur seule) */
.ct-jeu .ct-piece.ct-prise {
  z-index: 3; transform: scale(.88);
  box-shadow: 0 0 0 3px var(--ct-anneau), 0 0 0 6px var(--ct-anneau-2), 0 10px 20px rgba(0, 0, 0, .55);
}
.ct-jeu .ct-piece.ct-prise::before {
  content: "⇄"; position: absolute; top: 3px; left: 3px;
  display: flex; align-items: center; justify-content: center; width: 1.4rem; height: 1.4rem; border-radius: 999px;
  background: var(--ct-anneau-2); color: var(--ct-anneau); font-size: .85rem; font-weight: 800; line-height: 1;
  box-shadow: 0 0 0 2px var(--ct-anneau);
}
/* « Montrer les pièces bien placées » : une coche blanche sur ardoise, et un liseré clair dans la pièce */
.ct-jeu .ct-montrer .ct-piece.ct-ok { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85); }
.ct-jeu .ct-montrer .ct-piece.ct-ok::after {
  content: "✓"; position: absolute; right: 3px; bottom: 3px;
  display: flex; align-items: center; justify-content: center; width: 1.3rem; height: 1.3rem; border-radius: 999px;
  background: var(--ct-anneau-2); color: var(--ct-anneau); font-size: .8rem; font-weight: 800; line-height: 1;
  box-shadow: 0 0 0 2px var(--ct-anneau);
}
@media (hover: hover) {
  .ct-jeu .ct-montrer .ct-piece.ct-ok:hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85), 0 0 0 2px rgba(var(--cyan-rgb), .9), 0 0 14px rgba(var(--cyan-rgb), .45); }
}
/* le focus d'une pièce à sa place garde son anneau d'ardoise : la règle du liseré, plus précise, l'effaçait (revue) */
.ct-jeu .ct-montrer .ct-piece.ct-ok:focus-visible { box-shadow: inset 0 0 0 6px var(--ct-anneau-2), 0 0 0 2px var(--ct-anneau-2); }
.ct-jeu .ct-montrer .ct-piece.ct-ok.ct-prise { box-shadow: 0 0 0 3px var(--ct-anneau), 0 0 0 6px var(--ct-anneau-2), 0 10px 20px rgba(0, 0, 0, .55); }
@keyframes ct-vient { from { opacity: .35; transform: scale(.94); } to { opacity: 1; transform: none; } }
.ct-jeu .ct-piece.ct-vient { animation: ct-vient .32s ease-out; }

/* l'image à reconstituer : même recadrage que le plateau (object-fit: cover, au format du plateau) */
.ct-jeu .ct-modele {
  flex: 0 1 20rem; min-width: min(100%, 14rem); margin: 0; padding: .6rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--ct-rayon);
}
.ct-jeu .ct-modele-img { display: block; width: 100%; height: auto; object-fit: cover; border-radius: 8px; background: var(--panel-2); }
.ct-jeu .ct-modele figcaption { margin: .45rem .1rem 0; font-size: .86rem; color: var(--muted); }
.ct-jeu .ct-bilan { margin: .8rem 0 0; color: var(--text); font-size: .92rem; }

/* ---------- La fin : la peinture entière, son titre, une phrase ---------- */
.ct-jeu .ct-fin { display: flex; flex-direction: column; gap: .9rem; }
.ct-jeu .ct-fin-fig {
  margin: 0; max-width: 60rem; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--ct-rayon);
}
.ct-jeu .ct-fin-fig img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; background: var(--panel-2); animation: ct-apparait .8s ease-out; }
.ct-jeu .ct-fin-fig figcaption { display: flex; flex-direction: column; gap: .35rem; padding: .9rem 1.1rem 1.1rem; }
.ct-jeu .ct-fin-titre { font-size: 1.1rem; color: var(--text); }
.ct-jeu .ct-fin-phrase { color: var(--muted); line-height: 1.6; font-style: italic; }
@keyframes ct-apparait { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Petit écran : le plateau prend toute la largeur (8 x 6 tient alors dans 375 px) ---------- */
@media (max-width: 560px) {
  .ct-jeu { --ct-gap: 1px; --ct-pad: 3px; }
  .ct-jeu .ct-cadre { margin-inline: -1rem; max-width: none; }
  .ct-jeu .ct-plateau { border-radius: 0; border-inline: 0; }
  /* les quatre options sur deux colonnes : le plateau reste près du haut de l'écran */
  .ct-jeu .ct-outils { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
  .ct-jeu .ct-outils .ct-btn2 { padding: .45rem .6rem; border-radius: 14px; font-size: .86rem; text-align: center; }
  .ct-jeu .ct-modele { flex-basis: 100%; }
}

/* ---------- Mouvement réduit et « Connexion tranquille » : aucune animation ni transition ---------- */
:root[data-calm="1"] .ct-jeu *, :root[data-calm="1"] .ct-jeu *::before, :root[data-calm="1"] .ct-jeu *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .ct-jeu *, .ct-jeu *::before, .ct-jeu *::after { animation: none !important; transition: none !important; }
}
