/* Composants partagés RUN ⇄ BUILD : bouton pause des animations, pastille « Écrire » (mobile),
   grille de preuve « 100 → 10 » et bloc vidéo. Comportement : composants.js. Mode d'emploi : INTEGRATION.md.
   À charger après transformer.css et avant la feuille du thème (le thème peut ainsi surcharger à spécificité égale).

   Variables que chaque thème définit sur :root (repli entre parenthèses, utilisé si la variable manque) :
     --cmp-bg           fond des surfaces posées sur la page : infobulle, repli vidéo (Canvas)
     --cmp-fg           texte principal (CanvasText)
     --cmp-muted        texte secondaire, contraste ≥ 4,5:1 sur le fond (GrayText)
     --cmp-line         filets et contours (gris à 45 %)
     --cmp-surface      fond du bouton pause dans l'en-tête (transparent)
     --cmp-accent       fond de la pastille « Écrire » (CanvasText)
     --cmp-accent-ink   texte de la pastille, contraste ≥ 4,5:1 sur --cmp-accent (Canvas)
     --cmp-alert        points et compteur avant la baisse, contraste ≥ 3:1 sur le fond (#d9482a)
     --cmp-ok           points et compteur après la baisse, contraste ≥ 3:1 sur le fond (#0e7c70)
     --cmp-ghost        points éteints (gris à 30 %)
     --cmp-focus        anneau de focus (currentColor)
     --cmp-radius       coins de la carte vidéo (14px)
     --cmp-shadow       ombre légère de la carte vidéo
     --cmp-font         police de texte (inherit)
     --cmp-display      police du compteur (--cmp-font)
   Réglages facultatifs : --cmp-proof-size (côté de la grille, 13.5rem), --cmp-proof-count-size (taille du
   compteur), --cmp-float-z (plan de la pastille, 45 : au-dessus du contenu, sous l'en-tête des thèmes à 50),
   --cmp-play-bg / --cmp-play-ink (disque et triangle du bouton de lecture, = --cmp-accent / --cmp-accent-ink).
   Jetons typographiques communs (cahier § 1, définis dans transformer.css) : --fs-label, --fs-note, --fs-body-s,
   --fs-role, --measure, avec repli ici s'ils manquent. */

/* Masquage accessible (texte lu par les lecteurs d'écran, invisible à l'écran). */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ------------------------------------------------------------------ */
/* 2.1 Bouton pause des animations                                     */
/* ------------------------------------------------------------------ */

/* Icône seule (44 × 44) : le libellé reste le nom accessible et s'affiche en infobulle au survol ou au focus. */
.motion-toggle {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-sizing: border-box;
  width: 44px;
  min-width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--cmp-line, rgb(128 128 128 / 45%));
  border-radius: 999px;
  background: var(--cmp-surface, transparent);
  color: var(--cmp-muted, GrayText);
  font-family: var(--cmp-font, inherit);
  font-size: var(--fs-label, 0.875rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.2;
  text-transform: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.25s ease, color 0.25s ease;
}

.motion-toggle[hidden] {
  display: none !important;
}

.motion-toggle:hover,
.motion-toggle[data-state="paused"] {
  border-color: var(--cmp-fg, CanvasText);
  color: var(--cmp-fg, CanvasText);
}

.motion-toggle:focus-visible {
  border-radius: 999px;
  outline: 2px solid var(--cmp-focus, currentColor);
  outline-offset: 3px;
}

.motion-toggle__icon {
  position: relative;
  display: block;
  flex: none;
  width: 12px;
  height: 12px;
}

/* Animations en cours : deux barres (pause). */
.motion-toggle__icon::before,
.motion-toggle__icon::after {
  content: "";
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 4px;
  border-radius: 1px;
  background: currentColor;
}

.motion-toggle__icon::before {
  left: 1px;
}

.motion-toggle__icon::after {
  right: 1px;
}

/* En pause : un triangle (relancer). */
.motion-toggle[data-state="paused"] .motion-toggle__icon::before {
  top: 0;
  bottom: 0;
  left: 2px;
  width: 10px;
  border-radius: 0;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.motion-toggle[data-state="paused"] .motion-toggle__icon::after {
  display: none;
}

.motion-toggle__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Infobulle : au survol (souris) ou au focus clavier ; survolable (pont invisible), Échap la referme (composants.js). */
@media (hover: hover) {
  .motion-toggle:is(:hover, :focus-visible):not([data-hint="off"]) .motion-toggle__label {
    top: calc(100% + 10px);
    right: 0;
    z-index: 1;
    width: auto;
    height: auto;
    padding: 6px 10px;
    overflow: visible;
    clip-path: none;
    border-radius: 6px;
    background: var(--cmp-fg, CanvasText);
    color: var(--cmp-bg, Canvas);
    /* Une phrase, pas une étiquette : 16 px comme les notes. */
    font-size: var(--fs-note, 1rem);
    font-family: var(--cmp-font, system-ui, sans-serif);
    letter-spacing: 0;
    text-transform: none;
    line-height: 1.3;
    pointer-events: auto;
  }

  .motion-toggle:is(:hover, :focus-visible):not([data-hint="off"]) .motion-toggle__label::before {
    content: "";
    position: absolute;
    right: 0;
    bottom: 100%;
    left: 0;
    height: 12px;
  }
}

/* Écran large : le libellé s'affiche en toutes lettres à côté de l'icône. */
@media (min-width: 1600px) {
  .motion-toggle {
    width: auto;
    padding: 0 16px 0 14px;
  }

  /* Même spécificité que l'infobulle ci-dessus (et placée après) : au survol, le libellé reste à plat. */
  .motion-toggle .motion-toggle__label,
  .motion-toggle:is(:hover, :focus-visible):not([data-hint="off"]) .motion-toggle__label {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    overflow: visible;
    clip-path: none;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    pointer-events: none;
  }

  .motion-toggle:is(:hover, :focus-visible):not([data-hint="off"]) .motion-toggle__label::before {
    content: none;
  }
}

/* ------------------------------------------------------------------ */
/* 2.2 Pastille « Écrire » (sous 900 px)                               */
/* ------------------------------------------------------------------ */

.float-contact {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: var(--cmp-float-z, 45);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  min-height: 48px;
  padding: 0 20px 0 18px;
  border-radius: 999px;
  background: var(--cmp-accent, CanvasText);
  color: var(--cmp-accent-ink, Canvas);
  font-family: var(--cmp-font, inherit);
  font-size: var(--fs-body-s, 1rem);
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 14px 34px -14px rgb(0 0 0 / 55%), 0 2px 6px rgb(0 0 0 / 18%);
  /* Repliée : invisible et hors d'atteinte (ni clic ni focus), même si l'attribut hidden manquait. */
  visibility: hidden;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
  -webkit-tap-highlight-color: transparent;
}

/* Enveloppe dessinée par un masque (aucun glyphe lu par les lecteurs d'écran). */
.float-contact::before {
  content: "";
  flex: none;
  width: 18px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Crect x='1' y='1' width='22' height='16' rx='2' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='m2 2.5 10 7.5 10-7.5' fill='none' stroke='%23000' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Crect x='1' y='1' width='22' height='16' rx='2' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='m2 2.5 10 7.5 10-7.5' fill='none' stroke='%23000' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.float-contact.is-visible {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition-delay: 0s;
}

.float-contact[hidden] {
  display: none !important;
}

.float-contact:focus-visible {
  border-radius: 999px;
  outline: 2px solid var(--cmp-focus, currentColor);
  outline-offset: 3px;
}

/* Jamais à partir de 900 px, même si le script se trompe. */
@media (min-width: 900px) {
  .float-contact {
    display: none !important;
  }
}

/* ------------------------------------------------------------------ */
/* 2.3 Grille de preuve « 100 → 10 »                                   */
/* ------------------------------------------------------------------ */

.proof-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.75rem;
}

/* Sans JavaScript : l'état final dessiné en CSS (90 points éteints, 10 points menthe sur la dernière rangée). */
.proof-grid:not(.is-built)::before {
  content: "";
  display: block;
  flex: none;
  width: var(--cmp-proof-size, 13.5rem);
  max-width: 100%;
  aspect-ratio: 1;
  background:
    radial-gradient(circle closest-side, var(--cmp-ok, #0e7c70) 62%, transparent 66%) 0 100% / 10% 10% repeat-x,
    radial-gradient(circle closest-side, var(--cmp-ghost, rgb(128 128 128 / 30%)) 30%, transparent 34%) 0 0 / 10% 10%;
}

.proof-grid__dots {
  display: grid;
  flex: none;
  grid-template-columns: repeat(var(--proof-cols, 10), minmax(0, 1fr));
  width: var(--cmp-proof-size, 13.5rem);
  max-width: 100%;
}

/* Diamètre : 64 % de la case (marges en % de la largeur de la case). */
.proof-grid__dot {
  display: block;
  aspect-ratio: 1;
  margin: 18%;
  border-radius: 50%;
  background: var(--cmp-ok, #0e7c70);
  transition: background-color 0.45s ease var(--proof-delay, 0ms), transform 0.3s ease, opacity 0.3s ease;
}

.proof-grid[data-proof-state="armed"] .proof-grid__dot,
.proof-grid[data-proof-state="playing"] .proof-grid__dot {
  background: var(--cmp-alert, #d9482a);
}

.proof-grid .proof-grid__dots > .proof-grid__dot.is-off {
  background: var(--cmp-ghost, rgb(128 128 128 / 30%));
  transform: scale(0.5);
  transition-delay: 0ms;
}

.proof-grid__count {
  display: inline-block;
  min-width: 2ch;
  color: var(--cmp-ok, #0e7c70);
  font-family: var(--cmp-display, var(--cmp-font, inherit));
  font-size: var(--cmp-proof-count-size, clamp(3.5rem, 2.4rem + 5vw, 7.5rem));
  font-weight: 650;
  letter-spacing: -0.04em;
  line-height: 0.9;
  transition: color 0.45s ease;
}

/* Chiffres à chasse fixe pendant le décompte seulement (pas de sautillement), chiffres proportionnels au repos. */
.proof-grid[data-proof-state="armed"] .proof-grid__count,
.proof-grid[data-proof-state="playing"] .proof-grid__count {
  color: var(--cmp-alert, #d9482a);
  font-variant-numeric: tabular-nums;
}

.proof-grid.is-instant .proof-grid__dot,
.proof-grid.is-instant .proof-grid__count {
  transition: none !important;
}

/* ------------------------------------------------------------------ */
/* 2.4 Bloc vidéo                                                      */
/* ------------------------------------------------------------------ */

.video-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.875rem;
  min-width: 0;
  margin: 0;
}

/* La vidéo et son bouton de lecture partagent la première case : le bouton se pose au centre de l'image. */
.video-card > video,
.video-card > .video-card__play {
  grid-area: 1 / 1;
}

.video-card video {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  border: 1px solid var(--cmp-line, rgb(128 128 128 / 45%));
  border-radius: var(--cmp-radius, 14px);
  background: #000;
  box-shadow: var(--cmp-shadow, 0 18px 40px -24px rgb(0 0 0 / 45%));
}

/* Rayon redonné au focus : BUILD arrondit tout :focus-visible à 4 px, après cette feuille. */
.video-card video:focus-visible {
  border-radius: var(--cmp-radius, 14px);
  outline: 2px solid var(--cmp-focus, currentColor);
  outline-offset: 3px;
}

/* Grand bouton de lecture (créé par composants.js, absent sans JavaScript) : toute l'image est cliquable,
   un disque au centre porte le triangle. */
.video-card__play {
  z-index: 1;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--cmp-radius, 14px);
  background: transparent;
  color: var(--cmp-play-ink, var(--cmp-accent-ink, Canvas));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.video-card__play::before,
.video-card__play::after {
  content: "";
  grid-area: 1 / 1;
}

.video-card__play::before {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--cmp-play-bg, var(--cmp-accent, CanvasText));
  box-shadow: 0 0 0 1px rgb(0 0 0 / 22%), 0 18px 40px -12px rgb(0 0 0 / 60%);
  transition: box-shadow 0.2s ease;
}

.video-card__play::after {
  width: 26px;
  height: 30px;
  margin-left: 6px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.video-card__play:hover::before {
  box-shadow: 0 0 0 6px rgb(255 255 255 / 30%), 0 18px 40px -12px rgb(0 0 0 / 60%);
}

.video-card__play:focus-visible {
  border-radius: var(--cmp-radius, 14px);
  outline: 3px solid var(--cmp-focus, currentColor);
  outline-offset: 3px;
}

.video-card__play[hidden] {
  display: none !important;
}

@media (max-width: 520px) {
  .video-card__play::before {
    width: 64px;
    height: 64px;
  }

  .video-card__play::after {
    width: 20px;
    height: 23px;
    margin-left: 5px;
  }
}

.video-card video::cue {
  font-family: "Geist", system-ui, sans-serif;
  /* Taille du navigateur (5 % de la hauteur de l'image), mais jamais sous 14 px sur une vidéo étroite. */
  font-size: max(0.875rem, 100%);
  line-height: 1.3;
}

.video-card figcaption {
  display: grid;
  gap: 0.25rem;
  max-width: var(--measure, 52ch);
  color: var(--cmp-muted, GrayText);
  font-family: var(--cmp-font, inherit);
  font-size: var(--fs-note, 1rem);
  line-height: 1.5;
}

.video-card__title {
  color: var(--cmp-fg, CanvasText);
  font-size: var(--fs-role, 1.125rem);
  font-weight: 600;
  line-height: 1.3;
}

.video-card__fallback {
  margin: 0;
  font-family: var(--cmp-font, inherit);
  font-size: var(--fs-body-s, 1rem);
}

.video-card__fallback a {
  color: var(--cmp-fg, CanvasText);
}

/* ------------------------------------------------------------------ */
/* Mouvement réduit, pause, impression, couleurs forcées               */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .motion-toggle,
  .video-card__play::before,
  .float-contact,
  .proof-grid__dot,
  .proof-grid__count {
    transition: none !important;
  }

  .float-contact {
    transform: none;
  }
}

:root[data-motion="paused"] .float-contact {
  transform: none;
  transition: none;
}

@media print {
  .motion-toggle,
  .float-contact {
    display: none !important;
  }
}

@media (forced-colors: active) {
  .motion-toggle__icon {
    forced-color-adjust: none;
    color: ButtonText;
  }

  .float-contact::before {
    forced-color-adjust: none;
    background: LinkText;
  }

  .video-card__play::before {
    border: 2px solid ButtonText;
  }

  .video-card__play::after {
    forced-color-adjust: none;
    background: ButtonText;
  }

  /* Les points gardent leurs couleurs : sans elles, la grille ne dit plus rien. */
  .proof-grid__dots,
  .proof-grid:not(.is-built)::before {
    forced-color-adjust: none;
  }
}
