/* ===============================
   Puzzles – styles spécifiques
   =============================== */

/* Barre commune (css/games.css) aux couleurs du jeu */
.pz-jeu {
  --mg-jeu-largeur: 1204px;
  --mgb-fond: radial-gradient(120% 160% at 0% 0%, rgba(255, 209, 102, 0.22), transparent 55%),
    linear-gradient(120deg, #3b2a1c, #634b30);
  --mgb-accent: #ffd166;
  --mgb-titre: linear-gradient(100deg, #ffffff, #ffd166);
  --mg-fs-fond: #f4f2ee;
  --mg-bulle-fond: #3b2a1c;
}

/* Compteurs : champs du formulaire, affichés comme les valeurs de la barre */
.pz-stat {
  width: 7ch;
  padding: 0;
  border: none;
  background: none;
  color: var(--mgb-valeur);
  font: inherit;
  font-size: 1.35em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -webkit-text-fill-color: var(--mgb-valeur); /* champ désactivé : pas de grisé */
  opacity: 1;
}

.pz-jeu.mg-fs {
  justify-content: center;
}

/* Plein écran : le puzzle, agrandi par pz.js, occupe toute la hauteur restante */
.pz-jeu.mg-fs .table-game {
  margin-bottom: 0;
}

/* Pièce bien placée : badge ✓ vert en bas à droite (taille --pz-badge selon la pièce, pz.js) */
.table-game td {
  position: relative;
}
.table-game td.pz-ok::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  z-index: 2;
  width: var(--pz-badge, 18px);
  height: var(--pz-badge, 18px);
  border-radius: 50%;
  background: #1f9d55
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E")
    center / 72% no-repeat;
  box-shadow: 0 0 0 1.5px #fff, 0 1px 3px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* Pièce sélectionnée (en attente d'échange) : soulevée, contour jaune et ombre portée */
.table-game .pz-piece {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.table-game td.pz-sel {
  z-index: 3;
}
.table-game td.pz-sel .pz-piece {
  z-index: 3;
  transform: scale(1.08);
  box-shadow:
    0 0 0 3px #ffd166,
    0 0 0 5px rgba(59, 42, 28, 0.85),
    0 10px 22px rgba(0, 0, 0, 0.55);
}

/* Glisser-déposer : pièce attrapée (sa case reste vide), copie qui suit le
   pointeur, pièce visée surlignée */
.table-game td {
  touch-action: none; /* au doigt, glisser une pièce ne fait pas défiler la page */
  user-select: none;
  -webkit-user-select: none;
}
.table-game td.pz-prise .pz-piece {
  opacity: 0.25;
}
.table-game td.pz-cible .pz-piece {
  box-shadow: inset 0 0 0 3px #ffd166, inset 0 0 0 9999px rgba(255, 209, 102, 0.25);
}
.pz-fantome {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3000;
  transform-origin: 0 0;
  pointer-events: none;
  box-shadow:
    0 0 0 3px #ffd166,
    0 14px 30px rgba(0, 0, 0, 0.55);
  cursor: grabbing;
}

/* ---------- Écran de sélection ---------- */
.pz-config {
  --pz-accent: #b7791f;
  --pz-texte: #3b2a1c;
  --pz-doux: #7a6a58;
  --pz-bordure: #e6ddd0;
  width: 100%;
  color: var(--pz-texte);
}

/* Réglage de la taille : aperçu du découpage à gauche, curseur à droite */
.pz-reglage {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  align-items: center;
  gap: 28px;
  max-width: 860px;
  margin: 0 auto 26px;
  padding: 22px 26px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 20px rgba(59, 42, 28, 0.1);
  box-sizing: border-box;
}
.pz-apercu {
  display: grid;
  place-items: center;
  height: 240px;
  border-radius: 12px;
  background: #f6f1e9;
}
.pz-apercu-cadre {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}
.pz-apercu-cadre.vide {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: linear-gradient(135deg, #efe7da, #ddd0bd);
}
.pz-apercu img {
  display: block;
  max-width: 100%;
  max-height: 240px;
}
.pz-apercu-vide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1em;
  text-align: center;
  line-height: 1.3;
  color: var(--pz-doux);
  font-weight: 600;
}
.pz-apercu-vide[hidden] {
  display: none;
}
/* Quadrillage du découpage (--n pièces par côté) */
.pz-apercu-grille {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.85) 1.5px, transparent 1.5px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.85) 1.5px, transparent 1.5px);
  background-size: calc(100% / var(--n)) calc(100% / var(--n));
  background-position: -0.75px -0.75px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
}

.pz-taille-lib {
  display: block;
  margin: 0 0 12px; /* la feuille du site décale les libellés */
  padding: 0;
  font-weight: 700;
  font-size: 1.05em;
}
.pz-curseur {
  display: flex;
  align-items: center;
  gap: 1em;
}
.pz-curseur input[type="range"] {
  --pct: 5.9%;
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--pz-accent) var(--pct), var(--pz-bordure) var(--pct));
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.pz-curseur input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--pz-accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.pz-curseur input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--pz-accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.pz-curseur output {
  min-width: 4.6em;
  padding: 0.2em 0.5em;
  border-radius: 10px;
  background: #f6f1e9;
  font-family: "Madimi One", sans-serif;
  font-size: 1.5em;
  text-align: center;
  white-space: nowrap;
  color: var(--pz-accent);
}
.pz-taille-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 18px;
  color: var(--pz-doux);
}
.pz-niveau {
  padding: 0.15em 0.75em;
  border-radius: 999px;
  font-size: 0.9em;
  font-weight: 700;
  background: #e3f6ea;
  color: #1f7a45;
}
.pz-niveau[data-niveau="1"] {
  background: #fff3d6;
  color: #9a6400;
}
.pz-niveau[data-niveau="2"] {
  background: #ffe4d1;
  color: #b4470f;
}
.pz-niveau[data-niveau="3"] {
  background: #fde2e2;
  color: #b42323;
}

/* Photos : vignettes en cartes, la photo choisie est cochée */
.pz-photos-titre {
  text-align: center;
  color: var(--pz-texte);
  margin: 0 0 14px;
}
.pz-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.pz-photo {
  position: relative;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 10px rgba(59, 42, 28, 0.12);
  cursor: pointer;
  transition:
    transform 0.15s,
    box-shadow 0.15s,
    border-color 0.15s;
}
/* photo entière (paysage ou portrait), centrée dans une vignette 4:3 */
.pz-photo img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #f6f1e9;
}
.pz-photo:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(59, 42, 28, 0.2);
}
.pz-photo:focus-visible {
  outline: 3px solid var(--pz-accent);
  outline-offset: 2px;
}
.pz-photo[aria-pressed="true"] {
  border-color: var(--pz-accent);
  box-shadow: 0 6px 18px rgba(183, 121, 31, 0.35);
}
.pz-photo[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--pz-accent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E")
    center / 70% no-repeat;
  box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0, 0, 0, 0.4);
}

@media (max-width: 640px) {
  .pz-reglage {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 18px;
  }
  .pz-apercu {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }
  .pz-photos {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

/* Bouton « Commencer le puzzle » aux couleurs de la barre (brun et or) */
.pz-config .pz-commencer {
  margin-left: 0;
  padding: 10px 24px;
  background: linear-gradient(120deg, #3b2a1c, #634b30);
  color: #ffd166;
  box-shadow: 0 10px 22px -12px rgba(59, 42, 28, 0.9);
}
.pz-config .pz-commencer:hover {
  background: linear-gradient(120deg, #4a3624, #7a5c3a);
  color: #ffe09a;
  box-shadow: 0 14px 26px -12px rgba(183, 121, 31, 0.8);
}

/* Plein écran : 6 photos par ligne au plus */
.pz-jeu.mg-fs .pz-photos {
  grid-template-columns: repeat(auto-fill, minmax(max(170px, calc((100% - 5 * 14px) / 6)), 1fr));
}
