/*
 * Motion layer: entrance reveals, hand-drawn doodles drawing themselves in, and hover play.
 *
 * - Everything is visible by default. Hidden "before" states only apply under `html.hs-motion`,
 *   which an inline head script sets when motion is allowed (see inc/setup.php).
 * - assets/js/motion.js adds `.is-in` to the observed elements as they enter the viewport.
 * - Uses the individual transform properties (scale / rotate / translate) so it composes with
 *   the `transform` each block already sets for its own layout (rotated doodles, zoom vars, etc.).
 * - `:root` prefixes lift hover rules above single-class block rules regardless of load order.
 * - All spatial motion sits inside `prefers-reduced-motion: no-preference`.
 */

/* Parallax lock-in progress (motion.js), smoothed like --hs-p. */
@property --hs-lock {
	syntax: "<number>";
	inherits: true;
	initial-value: 0;
}

/* Scrubbed draw progress: inherited so the pens inside the SVG mask can read it. */
@property --hs-p {
	syntax: "<number>";
	inherits: true;
	initial-value: 0;
}

:root {
	--hs-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
	--hs-ease-pen: cubic-bezier(0.65, 0, 0.35, 1);
	--hs-ease-plop: cubic-bezier(0.34, 1.5, 0.64, 1);
}

@media (prefers-reduced-motion: no-preference) {

	/* =========================================================
	 * 1. Images settle into their frames
	 * ========================================================= */

	.hs-motion :is(
		.hs-hero-intro__media,
		.hs-hero-split__media,
		.hs-hero-photo__media,
		.hs-faq-split__media,
		.hs-framed-image-feature__media,
		.hs-image-cta-banner__media,
		.hs-testimonial-media__media,
		.hs-offering-feature__card-media,
		.hs-product-grid__media,
		.hs-card-slider__card,
		.hs-proof__media,
		.hs-callout__media,
		.hs-product-cards__media,
		.hs-pairs-well-with__media,
		.hs-media-text__media
	) :is(img, video) {
		scale: 1.04;
		opacity: 0;
	}

	.hs-motion .is-in :is(img, video) {
		scale: 1;
		opacity: 1;
		transition:
			scale 1.6s cubic-bezier(0.25, 1, 0.5, 1),
			opacity 0.8s ease-out;
	}

	/* Hover: a slow lean into the photo on cards that are links to more. */
	@media (hover: hover) {
		:root :is(.hs-product-grid__card, .hs-offering-feature__card, .hs-card-slider__card, .hs-product-cards__card, .hs-pairs-well-with__card):hover :is(.hs-product-grid__img, .hs-offering-feature__card-img, .hs-card-slider__image, .hs-product-cards__image, .hs-pairs-well-with__image) {
			scale: 1.06; /* doubled from 1.03 (design review) */
			transition: scale 1.4s var(--hs-ease-out);
		}

		/* "Questions buyers ask": the photo leans in just a little. */
		:root .hs-faq-split__media:hover .hs-faq-split__img {
			scale: 1.03;
			transition: scale 1.4s var(--hs-ease-out);
		}
	}

	:root :is(.hs-product-grid__img, .hs-offering-feature__card-img, .hs-card-slider__image, .hs-product-cards__image, .hs-pairs-well-with__image) {
		transition: scale 1.4s var(--hs-ease-out);
	}

	/* Tilt instead of zoom for the photos flagged in review (motion.js adds .hs-tilt). */
	.hs-motion .hs-tilt {
		transform: perspective(900px) rotateX(var(--hs-tilt-x, 0deg)) rotateY(var(--hs-tilt-y, 0deg));
		transition: transform 0.6s var(--hs-ease-out);
		will-change: transform;
	}

	/* =========================================================
	 * 2. Hand-drawn strokes draw themselves (pattern A)
	 *    Every doodle is a highscope_draw() SVG: a traced centreline per pen, stroked with round
	 *    caps into a mask over the Figma brush. Animating stroke-dashoffset runs a round-tipped pen
	 *    along the line, one pen after another (--a → --b is each pen's share of the whole).
	 *    - Default: drawn once, quickly, when it enters the viewport (motion.js adds .is-in).
	 *    - data-draw="scrub": follows scroll position instead (motion.js writes --hs-p).
	 *    Tunables on the <svg>: --hs-draw-dur (whole doodle), --hs-draw-delay.
	 * ========================================================= */

	.hs-motion .hs-draw .hs-draw__pen {
		stroke-dasharray: 1 2;
		stroke-dashoffset: 1.01;
	}

	.hs-motion .hs-draw.is-in .hs-draw__pen {
		stroke-dashoffset: 0;
		transition: stroke-dashoffset
			calc((var(--b) - var(--a)) * var(--hs-draw-dur, 0.9s))
			var(--hs-draw-ease, cubic-bezier(0.45, 0, 0.55, 1))
			calc(var(--a) * var(--hs-draw-dur, 0.9s) + var(--hs-draw-delay, 0s));
	}

	.hs-motion .hs-draw[data-draw="scrub"] .hs-draw__pen {
		stroke-dashoffset: calc(1.01 - 1.01 * clamp(0, (var(--hs-p) - var(--a)) / (var(--b) - var(--a)), 1));
		transition: none;
	}

	.hs-motion .hs-draw[data-draw="scrub"] {
		transition: --hs-p 0.35s linear;
	}

	/* Short marks are quicker still; long lines a touch longer so the pen speed feels the same. */
	.hs-u__line { --hs-draw-dur: 0.7s; --hs-draw-delay: 0.15s; }
	.hs-hero-split__loop { --hs-draw-dur: 0.6s; --hs-draw-delay: 0.5s; }
	.hs-testimonial-media__sparkle .hs-draw { --hs-draw-dur: 0.6s; }
	.hs-research-stats__emphasis { --hs-draw-dur: 0.5s; --hs-draw-delay: 0.6s; }
	:is(.hs-audience-split__wavy .hs-draw, .hs-events-row__loop) { --hs-draw-dur: 1.3s; }
	.hs-testimonial-centered__scribble .hs-draw { --hs-draw-dur: 1.2s; }

	.hs-included-circles__ring .hs-draw { --hs-draw-dur: 1.4s; }

	/* Doodles also take part in hover play (section 5): keep those transitions. */
	:root :is(
		.hs-research-stats__heart,
		.hs-image-cta-banner__doodle,
		.hs-included-circles__ring,
		.hs-testimonial-media__sparkle
	) {
		transition:
			rotate 1.2s var(--hs-ease-out),
			scale 0.8s var(--hs-ease-out);
	}

	/* Included circles: the ring turns round its label slowly and evenly on hover. */
	:root .hs-included-circles__ring {
		transition: rotate 2.6s cubic-bezier(0.45, 0, 0.25, 1);
	}

	/* Preschool scene: the clouds and birds draw in quickly, one after another, then the
	   clouds drift very slowly and now and then a bird flaps. */
	.hs-scene .hs-draw {
		--hs-draw-delay: calc(0.35s + var(--hs-scene-i, 0) * 0.22s);
	}

	.hs-scene__cloud .hs-draw { --hs-draw-dur: 0.75s; }
	.hs-scene__bird .hs-draw { --hs-draw-dur: 0.35s; }

	.hs-motion .hs-scene__cloud,
	.hs-motion .hs-scene__bird {
		transform-box: fill-box;
		transform-origin: center;
	}

	.hs-motion .hs-scene__cloud {
		animation: hs-cloud-drift 14s ease-in-out calc(2s + var(--hs-scene-i) * -4.5s) infinite alternate;
	}

	.hs-motion .hs-scene__bird {
		animation: hs-bird-flap 7s ease-in-out calc(2.4s + var(--hs-scene-i) * 1.9s) infinite;
	}

	@keyframes hs-cloud-drift {
		from { translate: -7px 0; }
		to { translate: 7px 0; }
	}

	@keyframes hs-bird-flap {
		0%, 86%, 100% { scale: 1 1; }
		89% { scale: 1 0.45; }
		92% { scale: 1 1.05; }
		95% { scale: 1 0.5; }
		98% { scale: 1 1; }
	}

	/* =========================================================
	 * 3. Parallax lock-in (pattern C)
	 *    The coloured panel starts low and pulls up over the photo faster than the photo moves,
	 *    then settles into place and stays there (motion.js eases --hs-lock 0 → 1).
	 * ========================================================= */

	.hs-motion .hs-lockin {
		transition: --hs-lock 0.6s cubic-bezier(0.25, 1, 0.5, 1); /* trails the scroll a little, so it glides */
	}

	.hs-motion .hs-image-cta-banner.hs-lockin .hs-image-cta-banner__card {
		translate: 0 calc((1 - var(--hs-lock)) * min(18vh, 160px));
	}

	.hs-motion .hs-image-cta-banner.hs-lockin .hs-image-cta-banner__img {
		scale: 1.08;
		translate: 0 calc((var(--hs-lock) - 1) * 4%);
	}

	/* "Updated for today's classrooms": same lock-in. The frame rises over the photo while the
	   photo drifts a touch the other way; both stop once the frame has locked in place. */
	.hs-motion .hs-framed-image-feature.hs-lockin .hs-framed-image-feature__panel {
		translate: 0 calc((1 - var(--hs-lock)) * min(18vh, 160px));
	}

	.hs-motion .hs-framed-image-feature.hs-lockin .hs-framed-image-feature__media .hs-framed-image-feature__img {
		scale: 1.08;
		translate: 0 calc((var(--hs-lock) - 1) * 4%);
	}

	/* Handwritten note: a quick scribble, line after line, once the panel has landed. */
	.hs-motion .hs-image-cta-banner__script span {
		-webkit-mask: linear-gradient(90deg, #000 40%, transparent 60%) 100% 0 / 260% 100% no-repeat;
		mask: linear-gradient(90deg, #000 40%, transparent 60%) 100% 0 / 260% 100% no-repeat;
		transition: -webkit-mask-position 0.45s cubic-bezier(0.3, 0, 0.4, 1), mask-position 0.45s cubic-bezier(0.3, 0, 0.4, 1);
	}

	.hs-motion .hs-image-cta-banner__script.is-in span {
		-webkit-mask-position: 0 0;
		mask-position: 0 0;
	}

	.hs-motion .hs-image-cta-banner__script.is-in span {
		transition-delay: 0.35s;
	}

	.hs-motion .hs-image-cta-banner__script.is-in span + span {
		transition-delay: 0.65s;
	}

	/* =========================================================
	 * 4. Progressive plop-in (pattern B)
	 *    Grouped items (cards, steps, products) land one at a time: a small rise and a scale
	 *    that just overshoots. motion.js staggers them with --hs-i (capped) and drops the delays
	 *    once they have landed so hover reacts at once.
	 * ========================================================= */

	.hs-motion :is(
		.hs-research-stats__list,
		.hs-product-grid__list,
		.hs-events-row__list,
		.hs-audience-split__cards,
		.hs-audience-blobs__list,
		.hs-mission-pills__pills,
		.hs-offering-feature__rows,
		.hs-included-circles__circles,
		.hs-products
	) > *,
	.hs-motion :is(.hs-offering-feature__card, .hs-steps-timeline__step) {
		opacity: 0;
		translate: 0 24px;
		scale: 0.94;
	}

	.hs-motion :is(.hs-audience-blobs__list, .hs-mission-pills__pills, .hs-included-circles__circles) > * {
		translate: none;
		scale: 0.8;
	}

	.hs-motion :is(
		.hs-research-stats__list,
		.hs-product-grid__list,
		.hs-events-row__list,
		.hs-audience-split__cards,
		.hs-audience-blobs__list,
		.hs-mission-pills__pills,
		.hs-offering-feature__rows,
		.hs-included-circles__circles,
		.hs-products
	).is-in > *,
	.hs-motion [data-hs-rows] > .is-in,
	.hs-motion :is(.hs-offering-feature__card, .hs-steps-timeline__step).is-in {
		opacity: 1;
		translate: none;
		scale: none;
	}

	:root :is(
		.hs-research-stats__list,
		.hs-product-grid__list,
		.hs-events-row__list,
		.hs-audience-split__cards,
		.hs-audience-blobs__list,
		.hs-mission-pills__pills,
		.hs-offering-feature__rows,
		.hs-included-circles__circles,
		.hs-products
	) > *,
	:root :is(.hs-offering-feature__card, .hs-steps-timeline__step) {
		transition:
			opacity calc(var(--hs-plop-dur, 0.6s) * 0.75) ease-out calc(var(--hs-i, 0) * var(--hs-plop-step, 110ms) + var(--hs-plop-delay, 0ms)),
			translate var(--hs-plop-dur, 0.6s) var(--hs-ease-out) calc(var(--hs-i, 0) * var(--hs-plop-step, 110ms) + var(--hs-plop-delay, 0ms)),
			scale var(--hs-plop-dur, 0.6s) var(--hs-ease-plop) calc(var(--hs-i, 0) * var(--hs-plop-step, 110ms) + var(--hs-plop-delay, 0ms)),
			rotate 0.5s var(--hs-ease-out);
	}

	/* Row lists ("Four parts", "Tested in real classrooms"): each row lands on its own as it
	   scrolls into view, slower and with a wider gap so the sequence is readable. */
	[data-hs-rows] > * {
		--hs-plop-dur: 0.9s;
		--hs-plop-step: 220ms;
	}

	.hs-motion [data-hs-rows] > * {
		translate: 0 40px;
	}

	/* Circles plop just ahead of their rings drawing round them. */
	/* "You're never on your own": slower, wider-spaced plops so each circle is seen landing. */
	.hs-included-circles__circles > * {
		--hs-plop-dur: 0.9s;
		--hs-plop-step: 320ms;
	}

	.hs-included-circles__ring .hs-draw { --hs-draw-delay: calc(var(--hs-i, 0) * 320ms + 300ms); }

	@media (hover: hover) {
		/* =========================================================
		 * 5. Hover play
		 * ========================================================= */

		/* Included circles: the hand-drawn ring spins round its label. */
		:root .hs-included-circles__circle:hover .hs-included-circles__ring {
			rotate: 140deg;
		}

		/* The flourish after the name gives a small lift when you reach the signature. */
		:root .hs-testimonial-media__content:hover .hs-testimonial-media__sparkle {
			rotate: -8deg;
			scale: 1.08;
		}

		/* Research heart leans in. */
		:root .hs-research-stats__intro:hover .hs-research-stats__heart {
			rotate: 8deg;
			scale: 1.04;
		}

		/* Hero loop arrow gives a little flick. */
		:root .hs-hero-split__tagline:hover .hs-hero-split__loop {
			animation: hs-flick 0.7s var(--hs-ease-out);
		}

		@keyframes hs-flick {
			35% { rotate: -14deg; }
			70% { rotate: 6deg; }
		}

		/* CTA banner doodles drift when the card is hovered. */
		:root .hs-image-cta-banner__card:hover .hs-image-cta-banner__doodle {
			rotate: 8deg;
			scale: 1.04;
		}

		/* Arrows travel further, and come back quicker. */
		:root :is(.hs-audience-split__link-arrow, .hs-faq-split__arrow) {
			transition: transform 0.25s ease-in;
		}

		:root :is(.hs-audience-split__link:hover .hs-audience-split__link-arrow, .hs-faq-split__link:hover .hs-faq-split__arrow) {
			transform: translateX(6px);
			transition: transform 0.45s var(--hs-ease-out);
		}

		/* Pills and blobs tilt playfully, alternating direction. */
		:root .hs-mission-pills__pill:hover {
			rotate: -4deg;
		}

		:root .hs-mission-pills__pills > .hs-mission-pills__pill:nth-child(even):hover {
			rotate: 4deg;
		}

		:root .hs-audience-blobs__item:hover {
			rotate: -2.5deg;
		}

		:root .hs-audience-blobs__list > .hs-audience-blobs__item:nth-child(even):hover {
			rotate: 2.5deg;
		}

		/* Buttons: no lift on hover, just a light press on click. */
		:root .hs-btn {
			transition:
				background-color 0.2s ease,
				color 0.2s ease,
				border-color 0.2s ease,
				scale 0.2s var(--hs-ease-out);
		}

		:root .hs-btn:active {
			scale: 0.98;
			transition-duration: 0.08s;
		}
	}
}

/* =========================================================
 * Page transitions (cross-document View Transitions).
 * Same-origin link navigations crossfade: the old page dissolves quickly,
 * the new one rises in a few pixels. The header stays put between pages.
 * Browsers without support simply navigate as before.
 * ========================================================= */

@media (prefers-reduced-motion: no-preference) {
	@view-transition {
		navigation: auto;
	}

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

	::view-transition-old(root) {
		animation: hs-page-out 0.22s ease-in both;
	}

	::view-transition-new(root) {
		animation: hs-page-in 0.5s var(--hs-ease-out) both;
	}

	::view-transition-group(hs-header) {
		animation-duration: 0s;
	}
}

@keyframes hs-page-out {
	to { opacity: 0; }
}

@keyframes hs-page-in {
	from {
		opacity: 0;
		translate: 0 12px;
	}
}
