/* Aurélie et Aurél' — animations d'apparition au défilement.
   Chargée sur le site public uniquement (pas dans l'éditeur), voir functions.php.

   Principes :
   - rien ne bouge si l'appareil demande moins d'animations ;
   - le contenu reste visible par défaut : un navigateur qui ne gère pas
     animation-timeline affiche la page statique ;
   - le premier écran (#haut) n'est jamais animé, pour ne pas retarder l'affichage ;
   - chaque élément est opaque dès qu'il est entièrement entré à l'écran ;
   - propriétés individuelles translate / scale, pour ne pas écraser
     les rotations des photos (transform). */

@media (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		/* Déclenchement : l'animation ne commence qu'une fois l'élément remonté
		   de cette part de la hauteur d'écran au-dessus du bas de la fenêtre */
		.entry-content { --aea-retard: 20%; }

		@keyframes aea-apparition {
			from { opacity: 0; translate: 0 14px; }
		}
		@keyframes aea-photo {
			from { opacity: 0; translate: 0 16px; }
		}
		@keyframes aea-pastille {
			from { scale: 0.94; }
		}

		/* 1. Titres et chapôs des sections (hors titres posés dans une carte) */
		.entry-content > section[id]:not(#haut) :is(h2, h2 + p):not(.is-style-carte *, .is-style-urgence *),
		/* 2. Cartes, encadrés, étapes et questions */
		.entry-content > section[id]:not(#haut) .is-layout-grid > *,
		.entry-content > section[id]:not(#haut) .wp-block-column > :is(.is-style-carte, .is-style-urgence),
		.entry-content > section[id]:not(#haut) .is-nowrap.has-background,
		.entry-content > section[id]:not(#haut) .is-style-liste-pointilles > *,
		.entry-content > section[id]:not(#haut) .wp-block-details {
			animation: aea-apparition linear both;
			animation-timeline: view(block 0 var(--aea-retard));
			animation-range: entry 0% entry 75%;
		}

		/* Textes et blocs peu hauts : la plage « entry » dépend de la hauteur de
		   l'élément (≈ 30px pour un titre, apparition trop brève). On cale la durée
		   sur la fenêtre : 18 % de la plage « cover » ≈ 120px de défilement. */
		.entry-content > section[id]:not(#haut) :is(h2, h2 + p):not(.is-style-carte *, .is-style-urgence *),
		.entry-content > section[id]:not(#haut) .is-nowrap.has-background,
		.entry-content > section[id]:not(#haut) .is-style-liste-pointilles > *,
		.entry-content > section[id]:not(#haut) .wp-block-details {
			animation-range: cover 0% cover 18%;
		}

		/* 3. Pastilles et pictos : léger grossissement */
		.entry-content > section[id]:not(#haut) .is-style-pastille {
			animation: aea-pastille linear both;
			animation-timeline: view(block 0 var(--aea-retard));
			animation-range: entry 20% entry 100%;
		}

		/* 4. Photos hors premier écran (la rotation reste sur l'img) */
		.entry-content > section[id]:not(#haut) :is(.is-style-polaroid, .is-style-polaroid-ombre) {
			animation: aea-photo linear both;
			animation-timeline: view(block 0 var(--aea-retard));
			animation-range: entry 0% entry 80%;
		}

		/* Cascade dans les grilles, sur grand écran : la 2e et la 3e carte
		   d'une rangée suivent avec un léger décalage */
		@media (min-width: 782px) {
			.entry-content > section[id]:not(#haut) .is-layout-grid > :nth-child(3n+2) {
				animation-range: entry 10% entry 85%;
			}
			.entry-content > section[id]:not(#haut) .is-layout-grid > :nth-child(3n+3) {
				animation-range: entry 20% entry 95%;
			}
		}
	}

	/* 5. Questions fréquentes : la réponse apparaît et disparaît en fondu,
	   avec une légère descente. Navigateurs sans ::details-content :
	   ouverture instantanée, comme avant. */
	@supports selector(::details-content) {
		.wp-block-details::details-content {
			opacity: 0;
			translate: 0 -8px;
			transition:
				opacity 0.45s ease-out,
				translate 0.45s ease-out,
				content-visibility 0.45s allow-discrete;
		}
		.wp-block-details[open]::details-content {
			opacity: 1;
			translate: 0 0;
		}
	}

	/* Et la hauteur se déplie / se replie, là où interpolate-size est géré
	   (sinon la hauteur change d'un coup, le fondu reste) */
	@supports (interpolate-size: allow-keywords) and selector(::details-content) {
		.wp-block-details {
			interpolate-size: allow-keywords;
		}
		.wp-block-details::details-content {
			block-size: 0;
			overflow: hidden;
			transition:
				block-size 0.45s ease-out,
				opacity 0.45s ease-out,
				translate 0.45s ease-out,
				content-visibility 0.45s allow-discrete;
		}
		.wp-block-details[open]::details-content {
			block-size: auto;
		}
	}
}
