/* ==========================================================================
   CARexplorer — animations
   Version 1 — 21 novembre 2026. Dépend de ../tokens/tokens.css.

   Principe : seul le symbole de l'IA s'anime longtemps. Tout le reste bouge
   en moins d'un tiers de seconde, avec une seule courbe (--cx-courbe).
   Le dégradé ciel n'existe que lorsque l'IA travaille : au repos le symbole
   est blanc, plat et immobile. Jamais de halo ni de lueur.

   Démonstration : ouvrir demo.html. Spécification : MOTION.md.
   ========================================================================== */

/* ---------- 1. Le symbole : l'étoile en croix, visage de l'IA ---------- */

:root {
  /* La forme du symbole, en masque : il prend la couleur (ou le dégradé) de son fond. */
  --cx-masque-symbole: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath transform='rotate(45 12 12)' d='M12 0C14 6 18 10 24 12C18 14 14 18 12 24C10 18 6 14 0 12C6 10 10 6 12 0Z'/%3E%3C/svg%3E");
}

.cx-symbole {
  display: block;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  background: var(--cx-lune);                 /* repos : blanc, plat, immobile */
  -webkit-mask: var(--cx-masque-symbole) center / contain no-repeat;
  mask: var(--cx-masque-symbole) center / contain no-repeat;
}

/* Écoute : respire pendant que l'on écrit ou que l'on parle (champ actif). */
.cx-symbole--ecoute {
  animation: cx-respire var(--cx-d-respiration) ease-in-out infinite;
}

/* Le dégradé ciel, qui glisse lentement. À combiner avec un état « de travail ». */
.cx-symbole--ciel {
  background: var(--cx-degrade-ciel-symbole);
  background-size: 220% 220%;
  animation: cx-ciel var(--cx-d-degrade) ease-in-out infinite alternate;
}

/* Réflexion : prend le dégradé et tourne par quarts de tour, tant que rien n'est affiché. */
.cx-symbole--reflexion {
  background: var(--cx-degrade-ciel-symbole);
  background-size: 220% 220%;
  animation:
    cx-ciel var(--cx-d-degrade) ease-in-out infinite alternate,
    cx-reflexion var(--cx-d-reflexion) var(--cx-courbe-reflexion) infinite;
}

/* Étape en cours : petit symbole en dégradé qui bat doucement (liste des étapes). */
.cx-symbole--etape {
  background: var(--cx-degrade-ciel-symbole);
  background-size: 220% 220%;
  animation:
    cx-ciel var(--cx-d-degrade) ease-in-out infinite alternate,
    cx-battement 1600ms ease-in-out infinite;
}

/* Trouvaille : un éclat, une seule fois, quand une annonce sort du lot.
   Ajouter la classe au moment voulu ; l'anneau .cx-eclat-anneau se place derrière, centré. */
.cx-symbole--trouvaille {
  background: var(--cx-degrade-ciel-symbole);
  background-size: 220% 220%;
  animation: cx-eclat 1100ms var(--cx-courbe) 1 both;
}
.cx-eclat-anneau {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px #8FC4FF;
  animation: cx-anneau 1100ms var(--cx-courbe) 1 both;
}

@keyframes cx-respire { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes cx-ciel { from { background-position: 0% 0%; } to { background-position: 100% 100%; } }
@keyframes cx-reflexion {
  0% { transform: rotate(0) scale(1); }
  50% { transform: rotate(45deg) scale(.82); }
  100% { transform: rotate(90deg) scale(1); }   /* l'étoile a quatre branches : 90° = retour à l'identique, la boucle est invisible */
}
@keyframes cx-battement { 0%, 100% { transform: scale(.9); } 50% { transform: scale(1); } }
@keyframes cx-eclat {
  0% { transform: scale(1) rotate(0); }
  40% { transform: scale(1.35) rotate(90deg); }
  100% { transform: scale(1) rotate(90deg); }
}
@keyframes cx-anneau {
  0% { transform: scale(.5); opacity: 0; }
  25% { opacity: .9; }
  100% { transform: scale(1.9); opacity: 0; }
}

/* ---------- 2. Recherche : de petites étoiles partent du symbole ---------- */
/* <span class="cx-emission"><span class="cx-symbole cx-symbole--etape"></span>
     <i style="--dx: 34px; --dy: -34px"></i><i style="--dx: 34px; --dy: 34px"></i>
     <i style="--dx: -34px; --dy: 34px"></i><i style="--dx: -34px; --dy: -34px"></i></span>
   Quatre étoiles au plus, dans l'axe des branches (les diagonales), décalées de 400 ms. */
.cx-emission {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cx-emission i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  background: var(--cx-degrade-ciel-symbole);
  -webkit-mask: var(--cx-masque-symbole) center / contain no-repeat;
  mask: var(--cx-masque-symbole) center / contain no-repeat;
  animation: cx-emission 1600ms var(--cx-courbe) infinite;
}
.cx-emission i:nth-of-type(2) { animation-delay: 400ms; }
.cx-emission i:nth-of-type(3) { animation-delay: 800ms; }
.cx-emission i:nth-of-type(4) { animation-delay: 1200ms; }
@keyframes cx-emission {
  0% { transform: translate(-50%, -50%) scale(.2); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1); opacity: 0; }
}

/* ---------- 3. Réponse : un trait sort du symbole et devient la première ligne ---------- */
.cx-trait {
  width: 76px;
  height: 3px;
  border-radius: 2px;
  background: var(--cx-degrade-ciel-filet);
  transform-origin: left center;
  animation: cx-trait 700ms var(--cx-courbe) 1 both;
}
@keyframes cx-trait {
  0% { transform: scaleX(0); opacity: 1; }
  70% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}

/* ---------- 4. L'IA au travail ---------- */

/* Texte parcouru par un reflet ciel (« Je parcours 231 322 annonces »). */
.cx-reflet {
  background: linear-gradient(90deg, var(--cx-brume) 0%, var(--cx-brume) 38%, var(--cx-ciel-3) 50%, var(--cx-brume) 62%, var(--cx-brume) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: cx-reflet var(--cx-d-reflet) linear infinite;
}
@keyframes cx-reflet { from { background-position: 110% 0; } to { background-position: -110% 0; } }

/* Filet de progression sous l'étape en cours : 2 px, un trait ciel qui passe. */
.cx-progression {
  position: relative;
  height: 2px;
  border-radius: 1px;
  background: var(--cx-relief);
  overflow: hidden;
}
.cx-progression::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 40%;
  border-radius: 1px;
  background: var(--cx-degrade-ciel-filet);
  animation: cx-progression var(--cx-d-progression) var(--cx-courbe-reflexion) infinite;
}
@keyframes cx-progression { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* Critères compris : chaque pastille arrive à son tour (décalage posé en style : animation-delay). */
.cx-apparait {
  animation: cx-apparait var(--cx-d-critere) var(--cx-courbe) both;
}
@keyframes cx-apparait { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Annonces en cascade : fondu et montée de 8 px, de la première à la dernière. */
.cx-cascade > * {
  animation: cx-cascade var(--cx-d-cascade) var(--cx-courbe) both;
}
.cx-cascade > *:nth-child(2) { animation-delay: calc(var(--cx-d-cascade-decalage) * 1); }
.cx-cascade > *:nth-child(3) { animation-delay: calc(var(--cx-d-cascade-decalage) * 2); }
.cx-cascade > *:nth-child(4) { animation-delay: calc(var(--cx-d-cascade-decalage) * 3); }
.cx-cascade > *:nth-child(5) { animation-delay: calc(var(--cx-d-cascade-decalage) * 4); }
@keyframes cx-cascade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Squelette d'attente : pulsation lente de l'opacité (cartes et lignes en chargement). */
.cx-squelette {
  background: var(--cx-surface-haute);
  border-radius: var(--cx-r-etiquette);
  animation: cx-squelette 1400ms ease-in-out infinite alternate;
}
@keyframes cx-squelette { from { opacity: .55; } to { opacity: 1; } }

/* Texte de la réponse, mot à mot : chaque mot arrive en bleu ciel puis passe au blanc.
   Envelopper chaque mot dans <span class="cx-mot" style="animation-delay: calc(var(--cx-mot) * N)">. */
.cx-mot {
  animation: cx-mot 420ms ease-out both;
}
@keyframes cx-mot {
  0% { opacity: 0; color: var(--cx-ciel-3); }
  30% { opacity: 1; color: var(--cx-ciel-3); }
  100% { opacity: 1; color: inherit; }
}

/* Dictée : barres de niveau en dégradé (hauteurs posées en style). */
.cx-onde {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 32px;
}
.cx-onde i {
  width: 3px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--cx-ciel-3), var(--cx-ciel-1));
  animation: cx-onde 1000ms ease-in-out infinite alternate;
}
@keyframes cx-onde { from { transform: scaleY(.35); } to { transform: scaleY(1); } }

/* ---------- 5. Le ciel de la recherche : points qui scintillent ---------- */
/* Des points de 2 ou 3 px, opacité 0,22 à 0,7, placés hors de la zone de recherche.
   Un sur cinq environ scintille ; durée 3,8 à 7 s et retard négatif posés en style. */
.cx-ciel-etoile {
  position: absolute;
  border-radius: 50%;
  background: var(--cx-brume);
}
.cx-ciel-etoile--scintille {
  animation: cx-scintille 5s ease-in-out infinite alternate;
}
@keyframes cx-scintille { from { opacity: .12; } to { opacity: .85; } }

/* ---------- 6. Le menu ---------- */

/* Le x du logo fait un demi-tour à l'arrivée sur la page, puis au survol.
   Le logo doit être en SVG dans la page, le tracé du x portant la classe .cx-logo-x. */
.cx-logo .cx-logo-x {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform var(--cx-d-logo) var(--cx-courbe);
  animation: cx-logo-x 1200ms var(--cx-courbe) 500ms backwards;
}
.cx-logo:hover .cx-logo-x { transform: rotate(180deg); }
@keyframes cx-logo-x { from { transform: rotate(-180deg); } to { transform: rotate(0); } }

/* La cloche des alertes tinte au survol. */
.cx-cloche svg { transform-origin: 50% 15%; }
.cx-cloche:hover svg { animation: cx-cloche 700ms var(--cx-courbe); }
@keyframes cx-cloche {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-14deg); }
  55% { transform: rotate(10deg); }
  80% { transform: rotate(-4deg); }
}

/* Soulignement d'une entrée de menu : un trait de 2 px qui glisse depuis la gauche.
   Gris au survol, bleu et fixe sur l'entrée active. */
.cx-entree { position: relative; }
.cx-entree::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--cx-gris-repere);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--cx-d-survol) var(--cx-courbe);
}
.cx-entree:hover::after { transform: scaleX(1); }
.cx-entree[aria-current]::after { background: var(--cx-bleu); transform: scaleX(1); }

/* ---------- 7. Mouvement réduit ---------- */
/* Si l'appareil le demande : plus de rotation, d'étoiles ni de boucle. Ce qui apparaît
   le fait par un simple fondu de 150 ms ; le symbole reste en dégradé fixe quand l'IA travaille. */
@media (prefers-reduced-motion: reduce) {
  .cx-symbole,
  .cx-reflet,
  .cx-progression::after,
  .cx-squelette,
  .cx-onde i,
  .cx-ciel-etoile--scintille,
  .cx-logo .cx-logo-x,
  .cx-cloche:hover svg,
  .cx-eclat-anneau,
  .cx-emission i,
  .cx-trait {
    animation: none !important;
  }
  .cx-emission i,
  .cx-eclat-anneau,
  .cx-trait { display: none; }
  .cx-reflet { color: var(--cx-brume); background: none; }
  .cx-apparait,
  .cx-cascade > *,
  .cx-mot {
    animation: cx-fondu var(--cx-d-fondu) linear both !important;
    animation-delay: 0ms !important;
  }
  .cx-entree::after,
  .cx-logo .cx-logo-x { transition: none; }
}
@keyframes cx-fondu { from { opacity: 0; } to { opacity: 1; } }
