/* Jeu : la boîte aux sons */

.boite-aux-sons__jeu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--espace-3);
  width: 100%;
}

.boite-aux-sons__series {
  justify-content: center;
}

/* Les sons, sous le jeu */
.boite-aux-sons__changer {
  width: 100%;
  max-width: 40rem;
  margin-top: var(--espace-4);
  padding-top: var(--espace-4);
  border-top: 2px dashed var(--trait);
}

.boite-aux-sons__changer-titre {
  margin: 0 0 var(--espace-2);
  text-align: center;
  font-weight: 700;
  color: var(--encre-2);
}

.boite-aux-sons__age {
  margin-left: 0.4em;
  padding: 0 0.4em;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--encre-2);
  font-size: 0.8rem;
}

.filtre[aria-pressed="true"] .boite-aux-sons__age {
  background: rgba(0, 0, 0, 0.12);
  color: inherit;
}

/* ---------- Le sac : une enveloppe par carte qui reste ---------- */

.boite-aux-sons__sac {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  min-height: 1rem;
  margin-bottom: calc(-1 * var(--espace-3));
}

.boite-aux-sons__sac i {
  position: relative;
  width: 1.3rem;
  height: 0.9rem;
  border-radius: 2px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 2px var(--encre-2);
  overflow: hidden;
}

.boite-aux-sons__sac i::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -0.55rem;
  width: 0.95rem;
  height: 0.95rem;
  border: 2px solid var(--encre-2);
  transform: translateX(-50%) rotate(45deg);
}

/* ---------- Le comptoir et la carte (une carte « par avion ») ---------- */

.boite-aux-sons__comptoir {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 10.5rem;
}

.boite-aux-sons__carte {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: var(--espace-2);
  width: min(100%, 22rem);
  padding: var(--espace-3) var(--espace-4) var(--espace-4);
  border: 9px solid transparent;
  border-radius: 12px;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    repeating-linear-gradient(-45deg, var(--rouge) 0 12px, var(--surface) 12px 18px, var(--bleu) 18px 30px, var(--surface) 30px 36px) border-box;
  color: var(--encre);
  box-shadow: 0 6px 16px var(--ombre);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: box-shadow var(--duree), translate var(--duree);
}

.boite-aux-sons__carte:hover {
  box-shadow: 0 10px 22px var(--ombre);
}

.boite-aux-sons__carte.est-levee {
  translate: 0 -6px;
  /* le code des couleurs : la carte qu'on vient de prendre porte le contour bleu de « ce qu'on vient de choisir » */
  box-shadow: 0 0 0 3px var(--fn-change), 0 12px 24px var(--ombre);
}

.boite-aux-sons__carte.est-tenue {
  z-index: 30;
  cursor: grabbing;
  transition: none;
  box-shadow: 0 18px 30px var(--ombre);
}

.boite-aux-sons__image {
  width: 2.8rem;
  height: 2.8rem;
  font-size: 2.8rem;
  line-height: 1;
  flex-shrink: 0;
}

.boite-aux-sons__image > .icone {
  width: 2.8rem;
  height: 2.8rem;
}

.boite-aux-sons__mot {
  display: inline-flex;
  align-items: baseline;
  max-width: 100%;
  font-weight: 700;
  font-size: clamp(1.9rem, 1.3rem + 3vw, 2.7rem);
  line-height: 1.2;
  white-space: nowrap;
}

/* le trou : toujours la même largeur, pour ne pas dire combien de lettres il cache */
.boite-aux-sons__trou {
  display: inline-block;
  width: 1.5em;
  height: 0.95em;
  margin: 0 0.1em;
  border-radius: 8px;
  border: 3px dashed var(--encre-2);
  background: var(--surface-2);
  transform: translateY(0.1em);
}

.boite-aux-sons__lettres {
  display: inline-block;
  margin: 0;
  padding: 0 0.06em;
  border-radius: 6px;
  background: var(--fn-piege);
  color: var(--fn-piege-texte);
  animation: boite-aux-sons-lettres 420ms cubic-bezier(0.2, 0.9, 0.3, 1.35);
}

@keyframes boite-aux-sons-lettres {
  from { transform: translateY(-0.6em) scale(1.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.boite-aux-sons__ecouter {
  position: absolute;
  top: 0.45rem;
  left: 0.5rem;
  color: var(--encre-2);
  opacity: 0.7;
}

/* le tampon de la poste, quand la bonne boîte accepte la carte */
.boite-aux-sons__tampon {
  position: absolute;
  top: 0.3rem;
  right: 0.4rem;
  display: grid;
  place-items: center;
  width: 4.2rem;
  height: 4.2rem;
  border-radius: 50%;
  border: 3px solid var(--bleu);
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 5px var(--bleu);
  color: var(--bleu);
  font-family: var(--police-titre);
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.85;
  transform: rotate(-14deg);
  animation: boite-aux-sons-tampon 300ms cubic-bezier(0.3, 1.4, 0.5, 1);
}

@keyframes boite-aux-sons-tampon {
  from { transform: rotate(-14deg) scale(2.2); opacity: 0; }
  to { transform: rotate(-14deg) scale(1); opacity: 0.85; }
}

.boite-aux-sons__vide {
  display: grid;
  justify-items: center;
  gap: var(--espace-2);
  padding: var(--espace-4);
  color: var(--encre-2);
  font-weight: 700;
  text-align: center;
}

.boite-aux-sons__vide .icone {
  width: 2.8rem;
  height: 2.8rem;
  font-size: 2.8rem;
}

.boite-aux-sons__aide {
  max-width: 34rem;
  min-height: 1.5em;
  color: var(--encre-2);
  font-weight: 700;
  text-align: center;
}

/* ---------- La rue : les boîtes aux lettres ---------- */

.boite-aux-sons__rue {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(0.5rem, 2.5vw, 2rem);
  width: 100%;
  max-width: 44rem;
  padding: 1.6rem var(--espace-2) 0;
  border-bottom: 6px solid var(--trait);
}

.boite-aux-sons__boite {
  position: relative;
  display: grid;
  justify-items: center;
  flex: 1 1 0;
  min-width: 0;
  max-width: 8.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--encre);
  cursor: pointer;
}

.boite-aux-sons__corps {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 0.7rem;
  width: 100%;
  padding: 1.5rem 0.4rem 1rem;
  border-radius: 48% 48% 12px 12px / 34% 34% 12px 12px;
  background: var(--accent);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.18), inset -7px 0 0 rgba(0, 0, 0, 0.07), 0 3px 0 rgba(0, 0, 0, 0.1);
  transition: transform var(--duree), box-shadow var(--duree);
}

.boite-aux-sons__fente {
  width: 64%;
  height: 0.6rem;
  border-radius: 6px;
  background: var(--sur-accent);
  box-shadow: 0 2px 0 rgba(255, 255, 255, 0.35);
}

.boite-aux-sons__plaque {
  min-width: 2.4em;
  padding: 0.1em 0.3em;
  border-radius: 9px;
  background: var(--bois);
  color: var(--bois-encre);
  box-shadow: inset 0 -4px 0 var(--bois-flanc);
  font-weight: 700;
  font-size: clamp(1.45rem, 1.1rem + 1.6vw, 2.1rem);
  line-height: 1.15;
  text-align: center;
}

/* le petit drapeau rouge : il sort de derrière la boîte quand une carte arrive */
.boite-aux-sons__drapeau {
  position: absolute;
  top: -1.2rem;
  right: 20%;
  width: 0.3rem;
  height: 2rem;
  border-radius: 3px;
  background: var(--encre-2);
  opacity: 0;
  transform: translateY(1.4rem);
  transition: transform 360ms cubic-bezier(0.3, 1.6, 0.5, 1), opacity 200ms;
}

.boite-aux-sons__drapeau::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0.3rem;
  width: 1rem;
  height: 0.75rem;
  border-radius: 0 3px 3px 0;
  background: var(--rouge);
}

.boite-aux-sons__pied {
  width: 18%;
  height: 1.3rem;
  background: var(--encre-2);
}

.boite-aux-sons__boite:hover .boite-aux-sons__corps,
.boite-aux-sons__boite.est-survolee .boite-aux-sons__corps {
  transform: translateY(-4px);
}

.boite-aux-sons__boite.est-survolee .boite-aux-sons__corps {
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.18), 0 0 0 5px color-mix(in srgb, var(--encre) 40%, transparent);
}

.boite-aux-sons__boite.est-gavee .boite-aux-sons__corps {
  animation: boite-aux-sons-gloup 420ms ease;
}

.boite-aux-sons__boite.a-du-courrier .boite-aux-sons__drapeau {
  opacity: 1;
  transform: none;
}

@keyframes boite-aux-sons-gloup {
  0%, 100% { transform: none; }
  30% { transform: scale(1.06, 0.92); }
  60% { transform: scale(0.97, 1.04); }
}

/* au deuxième essai manqué, la bonne boîte s'agite */
.boite-aux-sons__boite.est-indiquee .boite-aux-sons__corps {
  animation: boite-aux-sons-appel 900ms ease-in-out infinite;
  /* la boîte qui appelle : un cadre d'encre, plus de vert (le vert dit « c'est juste » dans le code des couleurs) */
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.18), 0 0 0 5px var(--encre);
}

@keyframes boite-aux-sons-appel {
  0%, 100% { transform: none; }
  25% { transform: rotate(-4deg); }
  75% { transform: rotate(4deg); }
}

/* ---------- Le message ---------- */

.boite-aux-sons__message {
  display: grid;
  justify-items: center;
  gap: var(--espace-2);
  max-width: 36rem;
  min-height: 3.2em;
  font-size: 1.1rem;
  text-align: center;
}

.boite-aux-sons__phrase {
  font-size: 1.15rem;
}

.boite-aux-sons__colore b {
  padding: 0 0.08em;
  border-radius: 5px;
  /* le code des couleurs : les lettres du son qu'on cherche, en jaune surligné */
  background: var(--fn-piege);
  color: var(--fn-piege-texte);
}

.boite-aux-sons__colore--grand {
  font-weight: 700;
  font-size: 1.5rem;
}

.boite-aux-sons__ecriture {
  font-size: 1.3rem;
}

.boite-aux-sons__raison {
  font-weight: 700;
}

/* ---------- Le tri : ce que chaque boîte a reçu ---------- */

.boite-aux-sons__tri {
  display: grid;
  gap: var(--espace-2);
  width: 100%;
  max-width: 40rem;
  padding: var(--espace-4);
  border-radius: var(--rayon-grand);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 2px var(--trait);
  transition: box-shadow 400ms;
}

.boite-aux-sons__tri.est-fini {
  /* le code des couleurs : la tournée est finie, vert pâle et une coche dans le coin */
  position: relative;
  background: var(--fn-juste);
  color: var(--fn-juste-texte);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.boite-aux-sons__tri.est-fini .boite-aux-sons__tri-titre {
  color: var(--fn-juste-texte);
}

.boite-aux-sons__tri.est-fini::after {
  content: '\2713';
  position: absolute;
  top: var(--espace-2);
  right: var(--espace-3);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--fn-juste-texte);
}

.boite-aux-sons__tri-titre {
  font-family: var(--police-titre);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--encre-2);
}

.boite-aux-sons__ligne {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr);
  align-items: center;
  gap: var(--espace-3);
}

.boite-aux-sons__etiquette {
  display: grid;
  place-items: center;
  min-height: 2.4rem;
  border-radius: 8px;
  background: var(--bois);
  color: var(--bois-encre);
  box-shadow: inset 0 -3px 0 var(--bois-flanc);
  font-weight: 700;
  font-size: 1.25rem;
}

.boite-aux-sons__puces {
  display: flex;
  flex-wrap: wrap;
  gap: var(--espace-2);
  min-width: 0;
}

.boite-aux-sons__puce {
  padding: 0.15rem 0.6rem;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--trait);
  font-weight: 700;
  font-size: 1.15rem;
}

.boite-aux-sons__puce.est-neuve {
  animation: boite-aux-sons-puce 500ms cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

@keyframes boite-aux-sons-puce {
  from { transform: translateY(-10px) scale(0.6); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.boite-aux-sons__rien {
  width: 3rem;
  height: 0;
  border-top: 3px dotted var(--trait);
}

.boite-aux-sons__truc {
  display: grid;
  justify-items: center;
  width: 100%;
}

@media (max-width: 520px) {
  .boite-aux-sons__carte {
    padding: var(--espace-3) var(--espace-3) var(--espace-4);
  }

  .boite-aux-sons__corps {
    padding-top: 1.2rem;
    gap: 0.55rem;
  }

  .boite-aux-sons__tampon {
    width: 3.4rem;
    height: 3.4rem;
    font-size: 0.95rem;
  }

  .boite-aux-sons__tri {
    padding: var(--espace-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .boite-aux-sons__boite.est-indiquee .boite-aux-sons__corps {
    animation: none;
  }
}

/* Repli pour les iPad restés en iOS 15, qui ne connaissent pas color-mix (règle 12 du CLAUDE.md, 22/10/2026) */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .boite-aux-sons__boite.est-survolee .boite-aux-sons__corps { box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.18), 0 0 0 5px var(--encre-2); }
}

/* « Encore » et « Pause / Continuer » rangés sous les boîtes, centrés dans l'axe */
.boite-aux-sons__actions {
  min-height: 2.8rem;
}
