/*
 * Hidden Edge UK: motion layer.
 * Loaded only while he_motion_on() is true (see functions.php). Calm and slow:
 * transform and opacity only, native scrolling, no layout shift.
 *
 * Nothing is hidden until motion.js has run and put "he-motion-ready" on the
 * html element, so the page is fully visible without the script. The whole file
 * sits inside a no-preference query, so a visitor who asks for reduced motion
 * gets the plain page: no video, no reveals, no parallax, no pinning.
 */

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

	:root {
		--he-ease: cubic-bezier(0.22, 0.8, 0.26, 1);
	}

	@keyframes he-word {
		from {
			transform: translateY(108%);
		}
	}

	@keyframes he-fade-up {
		from {
			opacity: 0;
			transform: translateY(14px);
		}
	}

	@keyframes he-reveal {
		from {
			opacity: 0;
			transform: translateY(24px);
		}
	}

	@keyframes he-draw {
		from {
			transform: scaleX(0);
		}
	}

	@keyframes he-drift {
		from {
			transform: scale(1);
		}
		to {
			transform: scale(1.06);
		}
	}

	@keyframes he-par-band {
		from {
			transform: translateY(0);
		}
		to {
			transform: translateY(5%);
		}
	}

	@keyframes he-par {
		from {
			transform: translateY(-5%);
		}
		to {
			transform: translateY(5%);
		}
	}

	@keyframes he-fill {
		from {
			transform: scaleY(0);
		}
		to {
			transform: scaleY(1);
		}
	}

	/* The wipe edge leans 9.09 degrees, the brand lean: 0.16 of the height, 21.88% of the mark's width. */
	@keyframes he-wipe {
		to {
			clip-path: polygon(0 0, 121.88% 0, 100% 100%, 0 100%);
		}
	}

	/* ---------- Hero: still, loop, entrance ---------- */

	/* Phones, data saver and a loop that is missing: the still drifts in very slowly. */
	html.he-motion-ready .he-hero-still .he-hero__img {
		transform-origin: 50% 55%;
		animation: he-drift 24s ease-in-out infinite alternate;
	}

	/* The visitor pressed Pause motion (kept in localStorage, so the next page starts paused too). Every infinite animation is listed here. */
	html.he-motion-paused.he-motion-ready .he-hero-still .he-hero__img {
		animation-play-state: paused;
	}

	/*
	 * Pause motion (WCAG 2.2.2): the loop and the drifting still run for longer than five seconds, so motion.js
	 * adds this button to the hero, and only when one of them is there. Bottom right, above the scrim. Charcoal
	 * fill with light mono text (about 15:1), leaning like the other buttons; the ring has a dark halo so it
	 * shows on any photo. 44px tall.
	 */
	.he-motion-toggle {
		position: absolute;
		z-index: 2;
		right: calc(max(0px, 50% - 640px) + var(--he-gutter) - 5px);
		bottom: 20px;
		isolation: isolate;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		min-height: 44px;
		padding: 10px 30px;
		border: 0;
		background: transparent;
		color: var(--he-on-dark);
		font-family: var(--he-mono);
		font-weight: 600;
		font-size: 0.8125rem;
		letter-spacing: 0.18em;
		line-height: 1.5;
		text-transform: uppercase;
		cursor: pointer;
	}

	.he-motion-toggle::before {
		content: "";
		position: absolute;
		z-index: -1;
		inset: 0 5px;
		border: 1px solid rgba(242, 240, 239, 0.7);
		border-radius: 2px;
		background: var(--he-ink);
		transform: skewX(-9.09deg);
		transition: background-color 0.15s ease, border-color 0.15s ease;
	}

	.he-motion-toggle:hover::before {
		border-color: var(--he-on-dark);
		background: #2B2B2B;
	}

	.he-motion-toggle:focus-visible {
		outline: none;
	}

	.he-motion-toggle:focus-visible::before {
		outline: 3px solid var(--he-on-dark);
		outline-offset: 3px;
		box-shadow: 0 0 0 9px rgba(26, 26, 26, 0.9);
	}

	/* On a phone the buttons sit at the bottom of the hero; make room under them for the toggle. The still always drifts there. */
	@media (max-width: 767px) {
		body.he-motion.he-page--home .he-hero__in {
			padding-bottom: 84px;
		}
	}

	.he-hero__video {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
		object-fit: cover;
		object-position: center 60%;
		opacity: 0;
		transition: opacity 1.4s ease;
		pointer-events: none;
	}

	.he-hero__video.is-playing {
		opacity: 1;
	}

	/* Each word rises from behind its own mask. Once they have all settled the masks go, so nothing clips the headline's shadow. */
	.he-hero__h1 .he-w {
		display: inline-block;
		clip-path: inset(-0.3em -0.3em -0.06em -0.3em);
	}

	.he-hero__h1 .he-w > span {
		display: inline-block;
		animation: he-word 0.7s var(--he-ease) backwards;
		animation-delay: calc(var(--w, 0) * 60ms + 120ms);
	}

	.he-hero__h1.is-set .he-w {
		clip-path: none;
	}

	.he-hero__sub {
		--o: 1;
	}

	.he-hero .he-actions .he-btn:nth-child(1) {
		--o: 2;
	}

	.he-hero .he-actions .he-btn:nth-child(2) {
		--o: 3;
	}

	/* he-hero-play is set by motion.js only when it ran before the first paint; a headline already on screen is left alone. */
	html.he-hero-play .he-hero .he-label,
	html.he-hero-play .he-hero__sub,
	html.he-hero-play .he-hero .he-actions .he-btn {
		animation: he-fade-up 0.7s var(--he-ease) backwards;
		animation-delay: calc(var(--n, 10) * 60ms + 220ms + var(--o, 0) * 110ms);
	}

	/* ---------- Scroll reveals (once each) ---------- */

	/* No scroll-driven animation: motion.js adds is-in the first time an item comes into view. */
	html.he-motion-ready:not(.he-sd) [data-he-r] {
		opacity: 0;
		transform: translateY(24px);
		transition: opacity 0.8s var(--he-ease), transform 0.8s var(--he-ease);
		transition-delay: calc(var(--i, 0) * 90ms);
	}

	html.he-motion-ready:not(.he-sd) [data-he-r].is-in {
		opacity: 1;
		transform: none;
	}

	html.he-motion-ready:not(.he-sd) [data-he-d][data-he-a]::before {
		transform: scaleX(0);
		transition: transform 1.1s var(--he-ease) 0.15s;
	}

	html.he-motion-ready:not(.he-sd) [data-he-d][data-he-a].is-in::before {
		transform: none;
	}

	/* The thin rule above the home "Five clear steps" list. */
	[data-he-d] {
		position: relative;
	}

	[data-he-d]::before {
		content: "";
		position: absolute;
		top: -8px;
		right: 0;
		left: 0;
		height: 1px;
		background: var(--he-ink);
		transform-origin: left center;
		pointer-events: none;
	}

	@media (min-width: 900px) {
		[data-he-d]::before {
			top: 0;
		}
	}

	@supports (animation-timeline: view()) {

		/* Linked to scroll: the reveal plays as the item rises. is-seen (set by motion.js) ends it for good once it is done. */
		html.he-motion-ready [data-he-r]:not(.is-seen) {
			animation: he-reveal cubic-bezier(0.25, 0.6, 0.3, 1) backwards;
			animation-timeline: view();
			animation-range: entry calc(var(--i, 0) * 16px) entry calc(180px + var(--i, 0) * 16px);
		}

		html.he-motion-ready [data-he-d][data-he-a]:not(.is-seen)::before {
			animation: he-draw cubic-bezier(0.25, 0.6, 0.3, 1) backwards;
			animation-timeline: view();
			animation-range: entry 0px entry 220px;
		}

		/* ---------- Gentle parallax inside the photo frames ---------- */

		/* The band clips with overflow: hidden, which would make it the scroller; the timeline sits on the band itself. */
		html.he-motion-ready .he-band--photo {
			view-timeline: --he-par block;
		}

		html.he-motion-ready .he-band__media img {
			position: absolute;
			top: -7%;
			left: 0;
			width: 100%;
			height: 114%;
			animation: he-par-band linear both;
			animation-timeline: --he-par;
			animation-range: exit 0% exit 100%;
		}

		html.he-motion-ready .he-teaser__media {
			position: relative;
			view-timeline: --he-par block;
		}

		html.he-motion-ready .he-teaser__media img {
			position: absolute;
			top: -7%;
			left: 0;
			width: 100%;
			height: 114%;
			animation: he-par linear both;
			animation-timeline: --he-par;
			animation-range: cover 0% cover 100%;
		}
	}

	/* ---------- Header: solid charcoal once the home page has scrolled ---------- */

	/*
	 * The home header is absolute over the hero. With motion it stays put, and its background is drawn on
	 * a pseudo element: a backdrop filter on the header itself would make it the containing block of the
	 * phone menu, which is position: fixed.
	 */
	html.he-motion-ready body.he-motion.he-page--home .he-header {
		position: fixed;
	}

	html.he-motion-ready body.he-motion.he-page--home .he-header::before {
		content: "";
		position: absolute;
		z-index: -1;
		inset: 0;
		background: rgba(26, 26, 26, 0.94);
		-webkit-backdrop-filter: blur(10px);
		backdrop-filter: blur(10px);
		opacity: 0;
		transition: opacity 0.4s ease;
		pointer-events: none;
	}

	html.he-scrolled.he-motion-ready body.he-motion.he-page--home .he-header::before {
		opacity: 1;
	}

	html.he-motion-ready body.he-motion.admin-bar.he-page--home .he-header {
		top: 32px;
	}

	@media (max-width: 782px) {
		html.he-motion-ready body.he-motion.admin-bar.he-page--home .he-header {
			top: 46px;
		}
	}

	/*
	 * Up to 600px WordPress lets its admin bar scroll away (position absolute), so a fixed header at top: 46px
	 * would leave a 46px gap after scrolling. The page is positioned (.he-page), so the bar and this header
	 * both measure from the top of the page, which already sits below the html margin: the bar takes the first
	 * 46px and the header goes straight under it, absolute, and the two scroll away together.
	 */
	@media (max-width: 600px) {
		html.he-motion-ready body.he-motion.admin-bar.he-page--home .he-header {
			position: absolute;
			top: 46px;
		}
	}

	/* The home header is fixed, so a focused control or an in-page jump must stop below it (WCAG 2.4.11). */
	html.he-motion-ready {
		scroll-padding-top: 6rem;
	}

	.he-sentinel {
		position: absolute;
		top: 40px;
		left: 0;
		width: 1px;
		height: 1px;
		pointer-events: none;
	}

	/* ---------- Closing band: the two-blade mark ---------- */

	.he-cta.has-mark {
		position: relative;
		overflow: hidden;
	}

	.he-cta.has-mark .he-cta__in {
		position: relative;
		z-index: 1;
	}

	/*
	 * Quiet on purpose: a faint mark behind the band. On a phone it bleeds off the right edge behind the
	 * text (the text stays above 6:1); from 900px it sits in the gap between the text and the button.
	 */
	.he-cta__mark {
		position: absolute;
		z-index: 0;
		top: 50%;
		right: -4%;
		height: 86%;
		aspect-ratio: 147.68 / 202;
		transform: translateY(-50%);
		pointer-events: none;
	}

	@media (min-width: 900px) {
		.he-cta__mark {
			right: calc(max(0px, 50% - 640px) + var(--he-gutter) + 250px);
			height: 76%;
		}
	}

	.he-cta__mark svg {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
		clip-path: polygon(0 0, 0 0, -21.88% 100%, 0 100%);
	}

	.he-cta__mark svg:nth-child(-n + 2) {
		opacity: 0.1;
	}

	.he-cta__mark svg:nth-child(3) {
		opacity: 0.6;
	}

	.he-cta__mark path {
		fill: #F2F0EF;
	}

	.he-cta__mark svg:nth-child(3) path {
		fill: #9B3436;
	}

	.he-cta__mark.is-in svg {
		animation: he-wipe 1.2s var(--he-ease) both;
		animation-delay: calc(var(--k, 0) * 420ms);
	}

	/* ---------- How we work: a pinned scene beside the five steps ---------- */

	/*
	 * The layout is reserved from the classes the server puts on the body (he-motion, he-page--how-we-work), so
	 * the grid and the tall steps are in place before motion.js runs; the script then only adds the counter and
	 * rail into the empty first column. The wrapper is also matched by the he-scene-on class the script adds,
	 * which keeps it working in a browser that cannot match :has().
	 */
	@media (min-width: 900px) {

		:is(.he-scene-on, body.he-motion.he-page--how-we-work .he-wrap:has(> .he-steps--big)) {
			--he-sh: min(46vh, 380px);
			display: grid;
			grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
			column-gap: 64px;
			align-items: start;
		}

		:is(.he-scene-on, body.he-motion.he-page--how-we-work .he-wrap:has(> .he-steps--big)) > .he-steps {
			grid-column: 2;
			grid-row: 1;
		}

		:is(.he-scene-on, body.he-motion.he-page--how-we-work .he-wrap:has(> .he-steps--big)) > .he-note {
			grid-column: 2;
			grid-row: 2;
		}

		.he-scene {
			grid-column: 1;
			grid-row: 1;
			position: sticky;
			top: calc(50vh - var(--he-sh) / 2);
			display: flex;
			gap: 28px;
			height: var(--he-sh);
		}

		.he-scene__rail {
			position: relative;
			flex: none;
			width: 2px;
			background: var(--he-rule);
		}

		.he-scene__rail i {
			position: absolute;
			inset: 0;
			background: var(--he-ox);
			transform-origin: top center;
			transform: scaleY(var(--he-p, 0));
			transition: transform 0.7s var(--he-ease);
		}

		.he-scene__count {
			position: relative;
			flex: 1;
			font-family: var(--he-display);
			font-weight: 800;
			font-size: clamp(5.5rem, 12vw, 10rem);
			line-height: 1;
			letter-spacing: -0.02em;
			color: var(--he-ink);
		}

		.he-scene__count span {
			position: absolute;
			top: 50%;
			left: 0;
			opacity: 0;
			transform: translateY(calc(-50% + 28px));
			transition: opacity 0.2s ease, transform 0.7s var(--he-ease);
		}

		/* One after the other: the old numeral is gone (0.2s) before the new one starts, so two are never on screen together. */
		.he-scene__count .is-on {
			opacity: 1;
			transform: translateY(-50%);
			transition-delay: 0.2s;
		}

		.he-scene__count .is-past {
			transform: translateY(calc(-50% - 28px));
		}

		/* The steps are tall enough to scroll through one at a time. The inactive ones soften in colour only. */
		:is(.he-scene-on, body.he-motion.he-page--how-we-work .he-wrap:has(> .he-steps--big)) .he-steps__item {
			min-height: 38vh;
			align-content: center;
		}

		.he-scene-on .he-steps__item h2,
		.he-scene-on .he-steps__item p,
		.he-scene-on .he-steps__item .he-num {
			transition: color 0.5s ease;
		}

		.he-scene-on .he-steps__item:not(.is-active) h2,
		.he-scene-on .he-steps__item:not(.is-active) p,
		.he-scene-on .he-steps__item:not(.is-active) .he-num {
			color: #6B6563;
		}

		html.he-motion-ready .he-scene-on .he-steps__item[data-he-r] {
			animation: none;
			opacity: 1;
			transform: none;
			transition: none;
		}

		@supports (animation-timeline: view()) and (timeline-scope: --a) {
			.he-scene-on {
				timeline-scope: --he-steps;
			}

			.he-scene-on > .he-steps {
				view-timeline: --he-steps block;
			}

			/* From the first step reaching the middle of the screen to the last one leaving it. */
			.he-scene__rail i {
				transition: none;
				animation: he-fill linear both;
				animation-timeline: --he-steps;
				animation-range: cover 50vh cover calc(100% - 50vh);
			}
		}
	}
}

/* Reduced motion switched on while the page is open: the loop must not show. */
@media (prefers-reduced-motion: reduce) {
	.he-hero__video,
	.he-motion-toggle {
		display: none;
	}
}
