/* =======================================================================
 * MOTION — everything that moves without JS (motion-spec 4 / 9.1) and the
 * hooks for cross-document View Transitions.
 *
 * Rules
 *  - No hidden initial state in a base rule: with no CSS animation support
 *    or no JS, every element is simply visible.
 *  - All time / ease / distance values are tokens (tokens.css, Figma
 *    "Motion" collection). Reduced motion is handled in ONE place: the
 *    tokens collapse in tokens.css, and the whole block below only exists
 *    inside `prefers-reduced-motion: no-preference`.
 *  - Scroll reveals, header panels' children and image settle on scroll are
 *    GSAP (assets/js/core/reveal.js); the opening/closing of panels stays
 *    in components.css (CSS, open = base+settle, close = fast+exit).
 * ===================================================================== */

@media (prefers-reduced-motion: no-preference) {
	@keyframes sf-rise {
		from {
			opacity: 0;
			transform: translateY(var(--sf-distance-md));
		}
	}

	@keyframes sf-rise-sm {
		from {
			opacity: 0;
			transform: translateY(var(--sf-distance-sm));
		}
	}

	@keyframes sf-settle {
		from {
			transform: scale(var(--sf-scale-settle));
		}
	}

	@keyframes sf-fade {
		from {
			opacity: 0;
		}
	}

	/* M1 Hero (home): eyebrow + H1 together, lead after stagger/lg, actions after 2x. */
	.sf-home-hero__eyebrow,
	.sf-home-hero__title {
		animation: sf-rise var(--sf-duration-slower) var(--sf-ease-settle) both;
	}

	.sf-home-hero__lead {
		animation: sf-rise var(--sf-duration-slow) var(--sf-ease-settle) var(--sf-stagger-lg) both;
	}

	.sf-home-hero__actions {
		animation: sf-rise var(--sf-duration-slow) var(--sf-ease-settle) calc(2 * var(--sf-stagger-lg)) both;
	}

	@media (min-width: 64rem) {
		/* the figure media wrapper already clips (home.css) */
		.sf-home-hero__panel .sf-home-figure__img {
			animation: sf-settle var(--sf-duration-slower) var(--sf-ease-settle) both;
		}
	}

	/* M2 Inner page header: breadcrumb + eyebrow + H1 + lead as ONE unit. */
	.sf-page-intro {
		animation: sf-rise-sm var(--sf-duration-slow) var(--sf-ease-settle) both;
	}

	/* M13 Disclosure: content fades in on open; closing is instant. */
	.sf-disclosure[open] > :not(summary) {
		animation: sf-fade var(--sf-duration-base) var(--sf-ease-settle) both;
	}

	/* M5 Cards: image scale + arrow nudge, fine pointers only. Focus never scales. */
	@media (hover: hover) and (pointer: fine) {
		.sf-card__image img,
		.sf-article-card__media img,
		.sf-podcast-row__cover img,
		.sf-book-card__cover img {
			transition: transform var(--sf-duration-slow) var(--sf-ease-settle);
		}

		.sf-card:hover .sf-card__image img,
		.sf-article-card:hover .sf-article-card__media img,
		.sf-podcast-row:hover .sf-podcast-row__cover img,
		.sf-book-card:hover .sf-book-card__cover img {
			transform: scale(var(--sf-scale-hover));
		}

		.sf-text-link .sf-icon,
		.sf-button--text .sf-icon {
			transition: transform var(--sf-duration-fast) var(--sf-ease-standard);
		}

		.sf-text-link:hover .sf-icon--arrow-right,
		.sf-button--text:hover .sf-icon--arrow-right {
			transform: translateX(var(--sf-distance-xs));
		}
	}

	/* M16 Cookie banner: fade only. Dialog: backdrop + panel with @starting-style. */
	.sf-cookie-banner {
		animation: sf-fade var(--sf-duration-fast) var(--sf-ease-standard) both;
	}

	.sf-cookie-dialog {
		opacity: 0;
		transform: translateY(var(--sf-distance-sm));
		transition:
			opacity var(--sf-duration-fast) var(--sf-ease-exit),
			transform var(--sf-duration-fast) var(--sf-ease-exit),
			overlay var(--sf-duration-fast) allow-discrete,
			display var(--sf-duration-fast) allow-discrete;
	}

	.sf-cookie-dialog[open] {
		opacity: 1;
		transform: none;
		transition:
			opacity var(--sf-duration-base) var(--sf-ease-settle),
			transform var(--sf-duration-base) var(--sf-ease-settle),
			overlay var(--sf-duration-base) allow-discrete,
			display var(--sf-duration-base) allow-discrete;
	}

	@starting-style {
		.sf-cookie-dialog[open] {
			opacity: 0;
			transform: translateY(var(--sf-distance-sm));
		}
	}

	.sf-cookie-dialog::backdrop {
		opacity: 0;
		transition:
			opacity var(--sf-duration-fast) var(--sf-ease-exit),
			overlay var(--sf-duration-fast) allow-discrete,
			display var(--sf-duration-fast) allow-discrete;
	}

	.sf-cookie-dialog[open]::backdrop {
		opacity: 1;
		transition:
			opacity var(--sf-duration-base) var(--sf-ease-settle),
			overlay var(--sf-duration-base) allow-discrete,
			display var(--sf-duration-base) allow-discrete;
	}

	@starting-style {
		.sf-cookie-dialog[open]::backdrop {
			opacity: 0;
		}
	}

	/* M12 Embed: the iframe fades over the facade at the same height. */
	.sf-embed__frame {
		animation: sf-fade var(--sf-duration-base) var(--sf-ease-settle) both;
	}

	/* M17 Page transitions (the @view-transition rule itself is printed by
	   PHP in <head>, only outside the purchase flow; see inc/flags.php).
	   Header, top bar and cookie banner keep their own groups so they stay
	   still while the page crossfades. */
	.site-header {
		view-transition-name: sf-header;
	}

	.top-bar {
		view-transition-name: sf-topbar;
	}

	.sf-cookie-banner {
		view-transition-name: sf-consent;
	}

	::view-transition-group(root) {
		animation-duration: var(--sf-duration-base);
		animation-timing-function: var(--sf-ease-standard);
	}

	::view-transition-group(sf-header),
	::view-transition-group(sf-topbar),
	::view-transition-group(sf-consent) {
		animation-duration: 0s;
	}
}

/* No transitions inside the order flow. */
body.sf-no-transitions .site-header,
body.sf-no-transitions .top-bar {
	view-transition-name: none;
}
