/*
 * "How it works" scroll progress line (bpsy-core, loaded only on pages whose Bricks data has data-bpsy-timeline).
 * The old site used GSAP ScrollTrigger (scrub): each step's fill line scales 0 -> 1 while the step's centre moves from 80 % of
 * the viewport height up by the step's own height; the step's icon turns brand-coloured at the start.
 * Here: CSS scroll-driven animation; timeline.js covers browsers without it.
 * Markup hooks (page.html): data-bpsy-timeline (list), data-bpsy-step (each row), data-bpsy-tl-fill (fill line).
 */

/* Base: the fill starts empty (the grey track line stays visible). */
[data-bpsy-tl-fill] {
	transform-origin: 50% 0;
	transform: scaleY(0);
}

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

/* Animations beat the per-element Bricks ID rule that sets the icon colour, so no !important is needed. */
@keyframes bpsy-tl-icon {
	from { color: var(--hcl-neutral-9); fill: var(--hcl-neutral-9); }
	to { color: var(--hcl-brand-9); fill: var(--hcl-brand-9); }
}

@supports (animation-timeline: view()) and (view-timeline-inset: 0% 20%) {
	/* Bottom inset 20 %: "entry 0 %" = the step's top edge at 80 % of the viewport, and entry
	   percentages are fractions of the step's own height. Centre at 80 % = entry 50 %; one step
	   height later = entry 150 % (GSAP: start "center bottom-=20%", end "+= step height"). */
	[data-bpsy-step] {
		view-timeline: --bpsy-step block;
		view-timeline-inset: 0% 20%;
	}

	[data-bpsy-tl-fill],
	[data-bpsy-step] > :first-child .brxe-icon {
		animation-duration: auto;
		animation-fill-mode: both;
		animation-timeline: --bpsy-step;
		animation-range: entry 50% entry 150%;
	}

	[data-bpsy-tl-fill] {
		animation-name: bpsy-tl-fill;
		animation-timing-function: linear;
	}

	[data-bpsy-step] > :first-child .brxe-icon {
		animation-name: bpsy-tl-icon;
		animation-timing-function: steps(1, jump-start);
	}
}

/* Reduced motion: no scrubbing; each line appears whole when its step is reached. */
@media (prefers-reduced-motion: reduce) {
	[data-bpsy-tl-fill] {
		animation-timing-function: steps(1, jump-start);
	}
}

/* JS fallback (timeline.js adds .bpsy-tl-js on <html> only when the CSS above is unsupported). */
.bpsy-tl-js [data-bpsy-tl-fill] {
	transform: scaleY(var(--bpsy-tl-p, 0));
}

.bpsy-tl-js [data-bpsy-step].is-active > :first-child .brxe-icon {
	animation: bpsy-tl-icon 0s steps(1, jump-start) both;
}
