/* Jeu : le détective des pièges */

/* Repli pour les navigateurs sans color-mix() (Safari avant 16.2, vieux iPad) : sous chaque règle qui mélange
   des couleurs, un petit bloc @supports not redonne une couleur simple de base.css (la plus présente du mélange).
   Une ligne de repli écrite juste avant ne suffirait pas : une valeur qui contient var() est jugée trop tard,
   elle devient « unset » (le noir d'un SVG, un fond transparent). */

.detective__choix {
  justify-content: center;
}

/* Les sortes de pièges : une couleur et un trait chacune (les mêmes que dans le mot caché) */
.detective__q--muette { --q: var(--violet); --q-trait: dotted; }
.detective__q--son { --q: var(--rouge); --q-trait: wavy; }
.detective__q--double { --q: var(--vert); --q-trait: double; }
.detective__q--accent { --q: var(--bleu); --q-trait: solid; }

.detective__marque {
  text-decoration-line: underline;
  text-decoration-style: var(--q-trait, solid);
  text-decoration-color: var(--q, var(--accent));
  text-decoration-thickness: 0.1em;
  text-underline-offset: 0.18em;
}

/* ---------- La carte ---------- */

.detective__carte {
  --detective-taille: 3.4rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: var(--espace-4);
  width: 100%;
  max-width: 46rem;
  padding: var(--espace-5) var(--espace-3);
  border-radius: var(--rayon-grand);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 2px var(--trait);
}

.detective__carte > * {
  min-width: 0;
  max-width: 100%;
}

.detective__entete {
  display: grid;
  justify-items: center;
  gap: var(--espace-3);
  width: 100%;
}

.detective__tete {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--espace-4);
  max-width: 34rem;
}

.detective__image {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 50%;
  background: var(--bois);
  box-shadow: inset 0 -4px 0 var(--bois-flanc);
  font-size: 2rem;
}

.detective__image > .icone {
  width: 2.2rem;
  height: 2.2rem;
}

.detective__dire {
  display: flex;
  align-items: center;
  gap: var(--espace-3);
  min-width: 0;
}

.detective__phrase {
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.4;
}

.detective__compte {
  display: flex;
  align-items: center;
  gap: var(--espace-3);
}

.detective__annonce {
  font-family: var(--police-titre);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.detective__indices {
  display: flex;
  gap: 0.35rem;
}

/* un petit rond par piège : vide, puis plein de la couleur du piège */
.detective__indice {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2.5px var(--encre-2);
}

.detective__indice.est-fait {
  background: var(--q);
  box-shadow: none;
  animation: entrer 360ms cubic-bezier(0.2, 0.9, 0.3, 1.5);
}

/* ---------- Le plateau, le mot et la loupe ---------- */

.detective__plateau {
  position: relative;
  width: 100%;
  border-radius: var(--rayon-grand);
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--encre) 10%, transparent) 1px, transparent 1.5px) 0 0 / 14px 14px,
    color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 30%, var(--trait));
  overflow: hidden;
  touch-action: pan-y;
}
@supports not (color: color-mix(in srgb, red 50%, blue)) { .detective__plateau { background: radial-gradient(circle at 1px 1px, transparent 1px, transparent 1.5px) 0 0 / 14px 14px, var(--surface); } }

.detective__dedans {
  display: grid;
  place-items: center;
  min-height: calc(var(--detective-taille) * 1.12 + 6.5rem);
  padding: 3.25rem 1rem;
}

.detective__rangee {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 6px;
}

.detective__lettre {
  --taille: var(--detective-taille);
  min-width: calc(var(--taille) * 0.86);
  padding: 0 0.06em;
  border: 0;
  text-decoration-thickness: 0.09em;
  text-underline-offset: 0.16em;
  transition: box-shadow 160ms, background 160ms, transform 160ms;
}

.detective__lettre.est-repere {
  /* le code des couleurs : le piège sous la loupe, en jaune surligné */
  background: var(--fn-piege);
  color: var(--fn-piege-texte);
  box-shadow: inset 0 -6px 0 var(--bois-flanc), 0 0 0 4px var(--jaune), 0 0 18px 4px color-mix(in srgb, var(--jaune) 70%, transparent);
  transform: translateY(-2px);
}

.detective__lettre.est-enquete {
  /* la lettre qu'on vient de choisir pour l'enquête : le contour bleu du code des couleurs */
  box-shadow: inset 0 -6px 0 var(--bois-flanc), 0 0 0 3px var(--fn-change);
}

.detective__lettre.est-resolu {
  background: color-mix(in srgb, var(--q) 28%, var(--bois));
  text-decoration-line: underline;
  text-decoration-style: var(--q-trait);
  text-decoration-color: var(--q);
  box-shadow: inset 0 -6px 0 color-mix(in srgb, var(--q) 45%, var(--bois-flanc)), 0 0 0 3px var(--q);
}
@supports not (color: color-mix(in srgb, red 50%, blue)) { .detective__lettre.est-resolu { background: var(--bois); } }

.detective__loupe {
  position: absolute;
  top: 0;
  left: 0;
  width: 6.4rem;
  height: 6.4rem;
  cursor: grab;
  touch-action: none;
  will-change: transform;
  z-index: 2;
}

.detective__loupe.est-tenue {
  cursor: grabbing;
}

.detective__lentille {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 0 0 6px var(--encre), 0 0 0 9px var(--bois-flanc), 0 8px 18px 6px var(--ombre);
  transition: box-shadow 200ms;
}

/* un reflet sur le verre */
.detective__lentille::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 26%, rgba(255, 255, 255, 0.45), transparent 32%);
  pointer-events: none;
}

.detective__loupe.est-sur-piege .detective__lentille {
  box-shadow: 0 0 0 6px var(--encre), 0 0 0 9px var(--jaune), 0 0 24px 10px color-mix(in srgb, var(--jaune) 60%, transparent);
}

.detective__loupe.est-rien {
  animation: detective-rien 360ms ease;
}

@keyframes detective-rien {
  30% { rotate: -6deg; }
  60% { rotate: 5deg; }
}

.detective__copie {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--encre) 10%, transparent) 1px, transparent 1.5px) 0 0 / 14px 14px,
    color-mix(in srgb, var(--accent) 10%, var(--surface));
}
@supports not (color: color-mix(in srgb, red 50%, blue)) { .detective__copie { background: radial-gradient(circle at 1px 1px, transparent 1px, transparent 1.5px) 0 0 / 14px 14px, var(--surface); } }

.detective__manche {
  position: absolute;
  left: 82%;
  top: 82%;
  width: 1.15rem;
  height: 3.4rem;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--bois-flanc), var(--bois) 45%, var(--bois-flanc));
  box-shadow: 0 0 0 2px var(--encre);
  transform: rotate(-45deg);
  transform-origin: 50% 0;
}

/* Le tampon « Affaire classée » */
.detective__tampon {
  position: absolute;
  right: 0.65rem;
  top: 0.45rem;
  z-index: 3;
  padding: 0.2rem 0.65rem;
  /* le code des couleurs : l'affaire est classée, c'est fait : vert, avec une coche ; plus de rouge (le rouge ferait penser à une erreur) */
  border: 3px solid var(--fn-juste-texte);
  border-radius: 10px;
  color: var(--fn-juste-texte);
  font-family: var(--police-titre);
  font-size: clamp(0.9rem, 0.75rem + 0.6vw, 1.1rem);
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: var(--fn-juste);
  transform: rotate(-6deg) scale(2.2);
  opacity: 0;
  pointer-events: none;
}
.detective__tampon::after {
  content: '\00a0\2713';
}

.detective__plateau.est-classe .detective__tampon {
  opacity: 1;
  transform: rotate(-6deg) scale(1);
  transition: transform 260ms cubic-bezier(0.5, 0, 0.8, 0.4) 200ms, opacity 120ms 200ms;
}

.detective__plateau.est-classe .detective__loupe {
  opacity: 0;
  transition: opacity 200ms;
  pointer-events: none;
}

.detective__plateau.est-classe .detective__rangee {
  gap: 0;
  transition: gap 360ms cubic-bezier(0.22, 1, 0.36, 1);
}
.detective__plateau.est-classe .detective__lettre:first-child:not(:last-child) {
  border-radius: 10px 0 0 10px;
}
.detective__plateau.est-classe .detective__lettre:not(:first-child):not(:last-child) {
  border-radius: 0;
}
.detective__plateau.est-classe .detective__lettre:last-child:not(:first-child) {
  border-radius: 0 10px 10px 0;
}

.detective__message {
  max-width: 32rem;
  min-height: 1.5em;
  font-size: 1.1rem;
  text-align: center;
}

/* ---------- La fiche d'enquête ---------- */

.detective__fiche {
  display: grid;
  gap: var(--espace-4);
  width: 100%;
  max-width: 36rem;
  padding: var(--espace-4);
  border-radius: var(--rayon-grand);
  background: var(--surface);
  box-shadow: 0 6px 16px var(--ombre), inset 0 0 0 2px var(--trait);
  animation: entrer 380ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.detective__fiche-tete {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--espace-3);
  align-items: center;
}

.detective__fiche-lettres {
  display: inline-grid;
  place-items: center;
  min-width: 2.8rem;
  height: 2.8rem;
  padding: 0 0.5rem;
  border-radius: 10px;
  background: var(--bois);
  color: var(--bois-encre);
  box-shadow: inset 0 -4px 0 var(--bois-flanc);
  font-weight: 700;
  font-size: 1.5rem;
}

.detective__fiche-deja {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--q, var(--encre-2));
}

.detective__fiche-titre {
  font-size: 1.2rem;
  font-weight: 700;
}

.detective__etiquettes {
  display: grid;
  gap: var(--espace-2);
}

/* les étiquettes : des fiches à bord perforé, comme dans un dossier d'enquête */
.detective__etiquette {
  display: flex;
  align-items: center;
  gap: var(--espace-3);
  min-height: 3.2rem;
  padding: 0.6rem 1rem 0.6rem 2.4rem;
  border: 0;
  border-radius: 12px;
  background:
    radial-gradient(circle at 1.05rem 50%, var(--surface) 0.42rem, transparent 0.47rem),
    color-mix(in srgb, var(--q, var(--accent)) 14%, var(--surface-2));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--q, var(--accent)) 45%, var(--trait)), inset 0 -4px 0 color-mix(in srgb, var(--q, var(--accent)) 30%, var(--trait));
  color: var(--encre);
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  transition: transform var(--duree), opacity var(--duree);
}
@supports not (color: color-mix(in srgb, red 50%, blue)) { .detective__etiquette { background: radial-gradient(circle at 1.05rem 50%, var(--surface) 0.42rem, transparent 0.47rem), var(--surface-2); } }

.detective__etiquette:hover {
  transform: translateX(3px);
}

.detective__etiquette.est-ecarte {
  opacity: 0.38;
  cursor: default;
  transform: none;
}

/* ---------- Les pièges trouvés ---------- */

.detective__trouvailles {
  display: grid;
  gap: var(--espace-2);
  width: 100%;
  max-width: 36rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detective__trouvailles:empty {
  display: none;
}

.detective__trouvaille {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--espace-3);
  align-items: center;
  padding: var(--espace-2) var(--espace-3);
  border-radius: var(--rayon);
  background: var(--surface);
  box-shadow: inset 4px 0 0 var(--q);
  font-size: 1.02rem;
  line-height: 1.4;
  animation: entrer 420ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.detective__truc {
  display: grid;
  justify-items: center;
  width: 100%;
}

/* ---------- Le carnet du détective ---------- */

.detective__carnet {
  display: grid;
  gap: var(--espace-3);
  width: 100%;
  max-width: 46rem;
  padding: var(--espace-5);
  border-radius: var(--rayon-grand);
  background:
    repeating-linear-gradient(180deg, transparent 0 1.9rem, color-mix(in srgb, var(--bleu) 18%, transparent) 1.9rem 2rem),
    var(--surface-2);
  box-shadow: inset 6px 0 0 color-mix(in srgb, var(--rouge) 55%, transparent);
}
@supports not (color: color-mix(in srgb, red 50%, blue)) { .detective__carnet { background: repeating-linear-gradient(180deg, transparent 0 1.9rem, transparent 1.9rem 2rem), var(--surface-2); } }

.detective__carnet-tete {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--espace-2);
}

.detective__carnet-titre {
  font-family: var(--police-titre);
  font-weight: 400;
  font-size: 1.2rem;
}

.detective__legende {
  display: flex;
  flex-wrap: wrap;
  gap: var(--espace-2) var(--espace-4);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.92rem;
  color: var(--encre-2);
}

.detective__legende li {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
}

.detective__legende .detective__marque {
  font-weight: 700;
  color: var(--encre);
}

.detective__pages {
  display: flex;
  flex-wrap: wrap;
  gap: var(--espace-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.detective__page.est-neuve {
  animation: detective-neuve 900ms cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

@keyframes detective-neuve {
  0% { transform: translateY(-40px) scale(1.6); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

.detective__page-bouton {
  min-height: 2.75rem;
  padding: 0.25rem 0.8rem;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--trait);
  font-size: 1.2rem;
  font-weight: 700;
}

.detective__dessine .detective__marque {
  text-decoration-thickness: 3px;
}

.detective__glyphe-piege {
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22), 0 0 0 3px var(--jaune);
}

@media (max-width: 520px) {
  .detective__tete {
    flex-direction: column;
    gap: var(--espace-2);
    text-align: center;
  }

  .detective__image {
    width: 2.6rem;
    height: 2.6rem;
    font-size: 1.9rem;
  }

  .detective__loupe {
    width: 5.4rem;
    height: 5.4rem;
  }

  .detective__dedans {
    padding: 2.8rem 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .detective__plateau.est-classe .detective__tampon {
    transition: none;
  }
}
