/* ==========================================================================
   Animations
   - Mobile (1 colonne) : retournement des cartes piloté par le scroll.
       html.flip-css → CSS Scroll-Driven Animations (thread compositeur)
       html.flip-js  → repli JS (js/motion.js) qui écrit --flip-angle / --flip-lift
     La classe est posée par js/motion.js ; sans elle, aucune animation.
   - Desktop : apparition progressive + inclinaison au survol (cards.css).
   - prefers-reduced-motion : tout est désactivé, le contenu reste statique.
   ========================================================================== */

/* --- Retournement mobile (façon jeu de cartes à collectionner) ---------- */
/*
   Progression « cover » : 0 % = le haut de la carte touche le bas de l'écran,
   100 % = le bas de la carte quitte le haut de l'écran.
     0 → 12 %   la carte arrive face cachée, posée
     12 → 18 %  elle se SOULÈVE (vers l'utilisateur, son ombre s'étend)
     18 → 32 %  elle se RETOURNE horizontalement (rotateY 180° → 0°), soulevée
     32 → 38 %  elle se REPOSE, face visible
     38 → 62 %  posée, lisible (elle est entièrement à l'écran)
     62 → 68 %  elle se soulève
     68 → 82 %  elle se retourne (0° → -180°, même sens de rotation)
     82 → 88 %  elle retombe, dos visible
   Chaque phase est adoucie (ease-in-out). Le scroll vers le haut rejoue tout
   à l'envers. Repli JS : rollAt() dans js/motion.js (mêmes paliers, même courbe).
*/
@keyframes card-flip {
  0%, 12%   { transform: translate3d(0, 0, 0) rotateY(180deg); animation-timing-function: ease-in-out; }
  18%       { transform: translate3d(0, var(--lift-y), var(--lift-z)) rotateY(180deg); animation-timing-function: ease-in-out; }
  32%       { transform: translate3d(0, var(--lift-y), var(--lift-z)) rotateY(0deg); animation-timing-function: ease-in-out; }
  38%, 62%  { transform: translate3d(0, 0, 0) rotateY(0deg); animation-timing-function: ease-in-out; }
  68%       { transform: translate3d(0, var(--lift-y), var(--lift-z)) rotateY(0deg); animation-timing-function: ease-in-out; }
  82%       { transform: translate3d(0, var(--lift-y), var(--lift-z)) rotateY(-180deg); animation-timing-function: ease-in-out; }
  88%, 100% { transform: translate3d(0, 0, 0) rotateY(-180deg); }
}

/* Ombre de la carte (portée par ses faces) pendant qu'elle est soulevée. */
@keyframes card-lift-shadow {
  0%, 12%   { opacity: 0; animation-timing-function: ease-in-out; }
  18%, 32%  { opacity: 1; animation-timing-function: ease-in-out; }
  38%, 62%  { opacity: 0; animation-timing-function: ease-in-out; }
  68%, 82%  { opacity: 1; animation-timing-function: ease-in-out; }
  88%, 100% { opacity: 0; }
}

/* Timeline commune : position de chaque carte dans l'écran (retournement + holographie). */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .flip-css .deck__item {
      view-timeline: --card-progress block;
      /* Sans cela, « auto » retrancherait le scroll-padding-top de la page (2rem) :
         la timeline CSS serait décalée par rapport au repli JS. */
      view-timeline-inset: 0;
    }
  }
}

@media (max-width: 39.99rem) and (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .flip-css .card__flipper,
    .flip-css .card__face::after {
      animation: card-flip linear both;
      animation-timeline: --card-progress;
      animation-range: cover 0% cover 100%;
    }

    .flip-css .card__face::after {
      animation-name: card-lift-shadow;
    }
  }

  .flip-js .card__flipper {
    transform: translate3d(0, calc(var(--flip-lift, 0) * var(--lift-y)), calc(var(--flip-lift, 0) * var(--lift-z))) rotateY(var(--flip-angle, 0deg));
    will-change: transform;
  }

  .flip-js .card__face::after {
    opacity: var(--flip-lift, 0);
  }

  /* Accessibilité : une carte qui reçoit le focus clavier est toujours à plat. */
  .flip-css .card:focus-within .card__flipper,
  .flip-js .card:focus-within .card__flipper {
    animation: none;
    transform: none;
  }

  .flip-css .card:focus-within .card__face::after,
  .flip-js .card:focus-within .card__face::after {
    animation: none;
    opacity: 0;
  }

}

/* --- Cartes à venir sur ordinateur et tablette : face cachée + révélation --- */
/*
   Au repos, une carte à venir montre son dos holographique (rotate: y 180deg).
   Survol (souris) ou toucher (tablette) → js/motion.js pose .is-revealed :
   la carte se soulève, se retourne, se repose. À la sortie (.was-revealed),
   même chorégraphie à l'envers. Propriétés individuelles « rotate » et
   « translate » : elles se combinent sans conflit avec « transform » (survol,
   apparition). Durée totale 800 ms ; retournement de 120 à 680 ms, carte soulevée.
*/
@keyframes card-bump-in {
  0%, 100% { translate: 0 0 0; }
  15%, 85% { translate: 0 var(--lift-y) var(--lift-z); }
}

@keyframes card-bump-out {
  0%, 100% { translate: 0 0 0; }
  15%, 85% { translate: 0 var(--lift-y) var(--lift-z); }
}

@keyframes card-bump-shadow-in {
  0%, 100% { opacity: 0; }
  15%, 85% { opacity: 1; }
}

@keyframes card-bump-shadow-out {
  0%, 100% { opacity: 0; }
  15%, 85% { opacity: 1; }
}

@media (min-width: 40rem) {
  .card--coming_soon .card__flipper {
    rotate: y 180deg;
    transition: rotate 560ms var(--ease-in-out) 120ms;
  }

  .card--coming_soon.is-revealed .card__flipper {
    rotate: y 0deg;
  }

  .card--coming_soon.is-revealed .card__flipper {
    animation: card-bump-in 800ms var(--ease-in-out);
  }

  .card--coming_soon.was-revealed .card__flipper {
    animation: card-bump-out 800ms var(--ease-in-out);
  }

  .card--coming_soon.is-revealed .card__face::after {
    animation: card-bump-shadow-in 800ms var(--ease-in-out);
  }

  .card--coming_soon.was-revealed .card__face::after {
    animation: card-bump-shadow-out 800ms var(--ease-in-out);
  }
}

/* --- Holographie du dos des cartes (toutes largeurs) --------------------- */
/*
   Pendant qu'une carte traverse l'écran, la teinte de son calque holographique
   tourne de 0 à --holo-turn (-330°) : bleu brillant → vert → jaune → rouge →
   magenta. Un reflet balaie la carte à l'aller puis au retour.
   Propriétés animées : filter et transform uniquement (compositeur).
   Repli JS (html.flip-js) : js/motion.js écrit --holo-hue et --glare-x.
*/
@keyframes holo-hue {
  from { filter: hue-rotate(0deg) saturate(1.35); }
  to   { filter: hue-rotate(var(--holo-turn)) saturate(1.35); }
}

@keyframes holo-glare {
  0%   { transform: translateX(-160%) rotate(18deg); }
  50%  { transform: translateX(160%) rotate(18deg); }
  100% { transform: translateX(-160%) rotate(18deg); }
}

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .flip-css .card__holo,
    .flip-css .card__glare {
      animation: holo-hue linear both;
      animation-timeline: --card-progress;
      animation-range: cover 0% cover 100%;
    }

    .flip-css .card__glare {
      animation-name: holo-glare;
    }
  }
}

/* --- Apparition progressive (desktop, multi-colonnes) ------------------- */

@keyframes card-reveal {
  from { opacity: 0; transform: translateY(32px) rotate(-1.5deg); }
  to   { opacity: 1; transform: none; }
}

@keyframes card-deal {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

@media (min-width: 40rem) and (prefers-reduced-motion: no-preference) {
  /* Navigateurs récents : la carte se pose au fur et à mesure qu'elle entre à l'écran. */
  @supports (animation-timeline: view()) {
    .deck[data-state="ready"] .card {
      animation: card-reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 80%;
    }
  }

  /* Autres navigateurs : « distribution » des cartes au chargement. */
  @supports not (animation-timeline: view()) {
    .deck[data-state="ready"] .card {
      animation: card-deal var(--dur-slow) var(--ease-out) both;
      animation-delay: calc(min(var(--i, 0), 12) * 45ms);
    }
  }
}

/* --- Mouvement réduit ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .card__flipper {
    transform: none !important;
  }
}
