/*
 * Motion presets. Which element uses which preset: assets/motion.json (one map for the whole site).
 * Timing tokens: theme.json custom.motion. Runner: assets/js/motion.js (adds .is-in when an element scrolls in).
 *
 * Everything that hides content is scoped to html.zain-motion, which a head script sets only when the visitor
 * hasn't asked for reduced motion — so no-JS, reduced motion, the editor and scripts/figma-check.py see the page
 * exactly as designed. Each preset sets the start values below; .is-in returns them to normal.
 * Only opacity, translate, scale and filter move — never layout.
 *
 * One family, from the client's first scroll reference (fmrg.studio, its shipped Framer "appear" config, read
 * 2026-11-03): every effect starts when half of the element is in view, plays once.
 *   chars     section headings: each character rises 10px out of a 10px blur, 50ms apart, 0.4s (Framer: spring,
 *             no bounce — approximated by --motion--ease)
 *   text      body copy: rises 10px out of a 2px blur, 0.4s, 300ms after it arrives, blocks 100ms apart (Framer
 *             splits into lines; here each block moves as one — no per-line spans for screen readers to trip on)
 *   scale-in  photos, cards and blocks: fade in from 95%, 0.6s, Framer's tween curve (--motion--ease-scale)
 *   count     a number counts up to its value over 1.4s once its stat has faded in (not in fmrg; restored on
 *             request, Habib 2026-11-03)
 *   art       the element's ::before / ::after art (404) — the scale-in values on its art layers
 */

html.zain-motion [data-zm],
html.zain-motion [data-zm-children] > :not([data-zm]) {
	--zm-delay: calc(var(--zm-wait, 0ms) + var(--zm-i, 0) * var(--wp--custom--motion--step));
	opacity: var(--zm-opacity, 0);
	translate: var(--zm-translate, 0 0);
	scale: var(--zm-scale, 1);
	filter: var(--zm-filter, none);
	transition:
		opacity var(--zm-duration, var(--wp--custom--motion--duration)) var(--zm-ease, var(--wp--custom--motion--ease)) var(--zm-delay),
		translate var(--zm-duration, var(--wp--custom--motion--duration)) var(--zm-ease, var(--wp--custom--motion--ease)) var(--zm-delay),
		scale var(--zm-duration, var(--wp--custom--motion--duration)) var(--zm-ease, var(--wp--custom--motion--ease)) var(--zm-delay),
		filter var(--zm-duration, var(--wp--custom--motion--duration)) var(--zm-ease, var(--wp--custom--motion--ease)) var(--zm-delay),
		transform var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease);
}

html.zain-motion [data-zm].is-in,
html.zain-motion [data-zm-children] > .is-in {
	opacity: 1;
	translate: 0 0;
	scale: 1;
	filter: none;
}

/* Containers that only stagger their children stay put */
html.zain-motion [data-zm-children]:not([data-zm]) {
	opacity: 1;
	translate: none;
	scale: none;
	filter: none;
	transition: none;
}

/* ------------------------------------------------------------------ Presets: start values */

/* text */
[data-zm="text"],
[data-zm-children="text"] > :not([data-zm]) {
	--zm-wait: var(--wp--custom--motion--text-delay);
	--zm-translate: 0 var(--wp--custom--motion--distance);
	--zm-filter: blur(var(--wp--custom--motion--blur-text));
}

/* scale-in */
[data-zm="scale-in"],
[data-zm-children="scale-in"] > :not([data-zm]) {
	--zm-scale: 0.95;
	--zm-duration: var(--wp--custom--motion--duration-scale);
	--zm-ease: var(--wp--custom--motion--ease-scale);
}

/* Elements whose own box doesn't move: their characters, number or art animate instead */
[data-zm="chars"],
[data-zm="count"],
[data-zm="art"] {
	--zm-opacity: 1;
}

/* chars: hidden until motion.js has split it, then each character rises out of a blur */
html.zain-motion [data-zm="chars"]:not(.zain-split) {
	opacity: 0;
}

.zain-word {
	display: inline-block; /* a word never breaks between its characters */
	max-width: 100%; /* a word longer than the line still wraps ("Qualifications" at 320px) */
}

.zain-char {
	display: inline-block;
}

html.zain-motion [data-zm="chars"] .zain-char {
	opacity: 0;
	translate: 0 var(--wp--custom--motion--distance);
	filter: blur(var(--wp--custom--motion--blur-heading));
	transition:
		opacity var(--wp--custom--motion--duration) var(--wp--custom--motion--ease),
		translate var(--wp--custom--motion--duration) var(--wp--custom--motion--ease),
		filter var(--wp--custom--motion--duration) var(--wp--custom--motion--ease);
	transition-delay: calc(var(--zm-delay) + var(--zm-c, 0) * var(--wp--custom--motion--step-char));
}

html.zain-motion [data-zm="chars"].is-in .zain-char {
	opacity: 1;
	translate: 0 0;
	filter: none;
}

/* art: decorative ::before / ::after layers scale in after the content */
html.zain-motion [data-zm="art"]::before,
html.zain-motion [data-zm="art"]::after {
	opacity: 0;
	scale: 0.95;
	transition:
		opacity var(--wp--custom--motion--duration-scale) var(--wp--custom--motion--ease-scale) calc(var(--zm-delay) + var(--wp--custom--motion--text-delay)),
		scale var(--wp--custom--motion--duration-scale) var(--wp--custom--motion--ease-scale) calc(var(--zm-delay) + var(--wp--custom--motion--text-delay));
}

html.zain-motion [data-zm="art"].is-in::before,
html.zain-motion [data-zm="art"].is-in::after {
	opacity: 1;
	scale: 1;
}

/* ------------------------------------------------------------------ Interaction (all visitors; reduced motion
   is shortened to nothing by base.css) */

/* Cards lift a little under the pointer */
@media (hover: hover) {
	.zain-service,
	.zain-qual,
	.zain-focus__card {
		transition: transform var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease);
	}

	.zain-service:hover,
	.zain-qual:hover,
	.zain-focus__card:hover {
		transform: translateY(-6px);
	}
}

/* FAQ answers slide open (browsers without ::details-content just open) */
:root {
	interpolate-size: allow-keywords;
}

/* flow-root keeps the answer's top margin inside the panel: without it the margin escaped and vanished in one frame
   at the end of the close, so the rows below jumped 16px */
html.zain-motion .zain-faq::details-content {
	display: flow-root;
	block-size: 0;
	overflow: clip;
	transition:
		block-size var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease),
		content-visibility var(--wp--custom--motion--duration-fast) allow-discrete;
}

html.zain-motion .zain-faq[open]::details-content {
	block-size: auto;
}

html.zain-motion .zain-faq summary::before {
	transition: background-color 0.2s, rotate var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease);
}

html.zain-motion .zain-faq[open] summary::before {
	rotate: 180deg;
}

/* Booking calendar: the month fades in when the arrows change it */
html.zain-motion .zain-booking__month:not([hidden]) {
	animation: zain-month-in var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease);
}

@keyframes zain-month-in {
	from {
		opacity: 0;
		translate: 0 8px;
	}
}

/* Mobile menu slides down as it opens */
html.zain-motion .zain-menu__dialog[open] {
	transition:
		opacity var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease),
		translate var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease);
}

@starting-style {
	html.zain-motion .zain-menu__dialog[open] {
		opacity: 0;
		translate: 0 -16px;
	}
}

/*
 * Page to page (cross-document view transitions): "Overlap Page Transition" (details.so page-transition-03, in the
 * client's reference list — its preview's shipped CSS, read 2026-11-03). The old page lifts 160px, shrinks to 95% and
 * dims to half; the new one rises from half a screen below, uncovered from its bottom edge (clip 70% → 0); both at
 * once, 1.4s. Chosen over the first reference's blur fade (Habib 2026-11-04): that demo fades a black page into a
 * white one, and between our all-white pages it read as a blank flash; this one moves, so it reads on white. Behind
 * it the hero Book Now's hover green (forest-pale, Habib 2026-11-04), so the shrinking page shows its edges. The header stays put (its own group). Browsers without
 * cross-document view transitions (Firefox) just load the page.
 */
@media (prefers-reduced-motion: no-preference) {
	@view-transition {
		navigation: auto;
	}

	.zain-header {
		view-transition-name: zain-header;
	}

	::view-transition {
		background: var(--wp--custom--color--forest-pale);
	}

	::view-transition-old(root) {
		animation: zain-page-out var(--wp--custom--motion--duration-page) var(--wp--custom--motion--ease-page) both;
	}

	::view-transition-new(root) {
		animation: zain-page-in var(--wp--custom--motion--duration-page) var(--wp--custom--motion--ease-page) both;
	}
}

@keyframes zain-page-out {
	to {
		transform: translateY(calc(-1 * var(--wp--custom--motion--page-lift))) scale(0.95);
		opacity: 0.5;
	}
}

@keyframes zain-page-in {
	from {
		transform: translateY(50vh);
		clip-path: inset(70% 0 0 0);
	}

	to {
		transform: none;
		clip-path: inset(0);
	}
}
