/**
 * Animated Hero block.
 *
 * Layout works in container query units so the hero scales with its own box
 * rather than the viewport, and every item is positioned with a transform so
 * the drift animation never triggers layout.
 */

.gwi-hero {
	position: relative;
	container-type: size;
	box-sizing: border-box;
	width: 100%;

	/* Proportional to the block's own width, so the editor preview keeps the
	   same shape as the front end no matter how wide the canvas is. */
	aspect-ratio: 100 / var(--gwi-hero-ratio, 41);
	min-height: var(--gwi-hero-min-height, 420px);
	margin-block-start: 0;
	overflow: hidden;
	background-color: #0c3050;
}

/* Intro animations run on the front end only — replaying them on every editor
   preview refresh makes the block hard to work with. */
.gwi-hero--intro {
	animation: gwi-hero-fade-in 1s ease-out both;
}

@keyframes gwi-hero-fade-in {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

.gwi-hero__background {
	position: absolute;
	inset: 0;
	z-index: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}

.gwi-hero__field {
	position: absolute;
	inset: 0;
	z-index: 1;
}

.gwi-hero__item {
	position: absolute;
	top: 0;
	left: 0;
	width: calc(var(--gwi-item-width, 10) * var(--gwi-hero-item-scale, 1) * 1cqw);
	aspect-ratio: 1 / var(--gwi-hero-image-ratio, 1.444);
	will-change: transform;

	/*
	 * Server-rendered position (percentages of the hero box) is the default, so
	 * the scatter is correct before any script runs. The animation loop takes
	 * over by setting --gwi-item-tx / --gwi-item-ty in pixels.
	 */
	transform: translate3d(
		var(--gwi-item-tx, calc(var(--gwi-item-x, 0) * 1cqw)),
		var(--gwi-item-ty, calc(var(--gwi-item-y, 0) * 1cqh)),
		0
	);
}

.gwi-hero__item--layer-0 {
	z-index: 3;
}

.gwi-hero__item--layer-1 {
	z-index: 2;
}

.gwi-hero__item--layer-2 {
	z-index: 1;
}

.gwi-hero__item:hover {
	z-index: 10;
}

.gwi-hero__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	background: transparent;
	opacity: 0.5;
	filter: blur(var(--gwi-item-blur, 0));

	/* Slow settle back to rest; the hover rule below speeds up the way in. */
	transition:
		transform 2.4s ease-out,
		filter 2.4s ease-out,
		opacity 2.4s ease-out;
}

.gwi-hero__item:hover .gwi-hero__image {
	opacity: 1;
	filter: blur(0);
	transform: scale(var(--gwi-item-hover-scale, 1.5));
	transition-duration: 0.3s;
	transition-timing-function: ease;
}

.gwi-hero__content {
	position: absolute;
	inset-block: 0;
	z-index: 100;

	/*
	 * The backdrop and the drifting images stay full bleed; only the headline
	 * is pulled into the global wide column so it lines up with the rest of the
	 * page, falling back to the old 5% inset on narrower screens.
	 */
	inset-inline: max(5%, calc((100% - var(--wp--style--global--wide-size, 1360px)) / 2));

	/* Grid rather than flex so the headline fills the column instead of
	   shrinking to its own content and wrapping early. */
	display: grid;
	align-content: center;
	pointer-events: none;
}

.gwi-hero__title {
	margin: 0;

	/* Same headline measure as before, now capped by the wide column instead
	   of by the full-bleed hero. */
	width: min(100%, 60rem);
	color: #fff;
	font-family: Poppins, sans-serif;
	font-size: clamp(1.5rem, 3.5cqw, 4rem);
	font-weight: 700;
	line-height: 1.2;
	text-align: left;
	text-shadow: 0 0 20px #003050;
	text-wrap: balance;

}

/* Wipe the headline in from the top once the backdrop has faded up. */
.gwi-hero--intro .gwi-hero__title {
	clip-path: inset(0 0 100% 0);
	animation: gwi-hero-reveal 2s ease-out 1s forwards;
}

@keyframes gwi-hero-reveal {
	to {
		clip-path: inset(0 0 0 0);
	}
}

@media (max-width: 781px) {
	/* The hero is held open by its minimum height on phones, so the images need
	   to grow with it or the composition turns into confetti. */
	.gwi-hero {
		--gwi-hero-item-scale: 1.8;
	}

	.gwi-hero__title {
		width: 100%;
	}

	.gwi-hero__title {
		font-size: clamp(1.5rem, 7cqw, 3rem);
	}
}

@media (prefers-reduced-motion: reduce) {
	.gwi-hero--intro,
	.gwi-hero--intro .gwi-hero__title {
		animation: none;
	}

	.gwi-hero--intro .gwi-hero__title {
		clip-path: none;
	}

	.gwi-hero__image {
		transition-duration: 0.15s;
	}
}
