/*
 * Footer illustrations
 *
 * Styles and entrance animations for the two decorative footer illustrations:
 * the "Find your way" route and the Illinois map. Both are inline SVG in the
 * footer template part's Custom HTML blocks. The source files and the full
 * markup live in assets/images/footer-illustrations/.
 *
 * Resting state first. Without JavaScript, and for visitors who prefer reduced
 * motion, the illustrations simply render in their final state.
 *
 * assets/js/footer-illustrations.js adds `is-animation-ready` to each
 * `[data-kindling-animate]` illustration, which parks its animations on their
 * first frame, then `is-animating` the first time the illustration scrolls
 * into view, which plays them once. Every animation uses fill-mode `both`, so
 * it rests on its last keyframe, which is identical to the static state.
 *
 * @package Kindling
 */

/* ---------------------------------------------------------------------------
 * Find your way: a route that bleeds in from the page edge.
 * ------------------------------------------------------------------------ */

/*
 * The route starts at the viewport edge, like the design, so it is shifted
 * left by the gutter between the wide layout and the viewport. `left` rather
 * than a negative margin, because constrained layouts own their children's
 * inline margins. The wrapper clips, so the route never causes horizontal
 * scrolling and stops at its column on tablet.
 */
.kindling-footer-route {
	--kindling-route-bleed: var(--wp--custom--layout--main-wide-width-side-spacing);

	position: relative;
	left: calc(-1 * var(--kindling-route-bleed));
	width: calc(100% + var(--kindling-route-bleed));
	overflow: hidden;
}

/*
 * The bleed width comes from the viewport-based layout tokens, which include a
 * classic (non-overlay) scrollbar, so in narrow desktop windows the route can
 * reach a few pixels past the page edge. Clip horizontal overflow on the
 * footer so that never becomes a horizontal scrollbar. `clip` rather than
 * `hidden`, so the footer does not become a scroll container.
 */
.wp-block-template-part:has(.kindling-footer-route) {
	overflow-x: clip;
}

/* Constrained layouts cap children at the content width, which would clip the bleed. */
:is(.is-layout-constrained, .is-layout-flow) > .kindling-footer-route {
	max-width: none;
}

/*
 * Full size (586 x 192) where there is room; scaled so the words fit otherwise.
 * The route is wider than its box by design (the wrapper clips it), so it opts
 * out of the global `svg { max-width: 100% }` reset in style.css.
 */
.kindling-footer-route__svg {
	display: block;
	width: min(586px, 120%);
	max-width: none;
	height: auto;
}

/*
 * Stacked columns: the route runs across the full viewport. It enters from
 * beyond the left edge, so the words start near the content edge at a legible
 * size, and the trail leaves past the right edge.
 */
@media (max-width: 781px) {
	.kindling-footer-route {
		width: calc(100% + 2 * var(--kindling-route-bleed));
	}

	.kindling-footer-route__svg {
		width: 504px;
		margin-left: calc(var(--kindling-route-bleed) - 84px);
	}
}

/*
 * Side-by-side columns: the route is the last item in the footer's tallest
 * column, so it runs through the footer's bottom padding (spacing 70) and the
 * trail leaves off the bottom edge, as in the design.
 */
@media (min-width: 782px) {
	.kindling-footer-route {
		margin-block-end: calc(-1 * var(--wp--preset--spacing--70));
	}
}

.kindling-footer-route__trail {
	stroke: var(--wp--preset--color--theme-18);
}

.kindling-footer-route__dot {
	fill: var(--wp--preset--color--theme-01);
}

.kindling-footer-route__words--find {
	fill: var(--wp--preset--color--theme-04);
}

.kindling-footer-route__words--explore {
	fill: var(--wp--preset--color--theme-14);
}

/* ---------------------------------------------------------------------------
 * Map: Illinois with O'Fallon marked.
 * ------------------------------------------------------------------------ */

.kindling-footer-map {
	position: relative;
	width: fit-content;
	max-width: 100%;
}

.kindling-footer-map__svg {
	display: block;
	max-width: 100%;
	height: auto;
}

.kindling-footer-map__outline {
	stroke: var(--wp--preset--color--theme-14);
}

.kindling-footer-map__marker {
	fill: var(--wp--preset--color--theme-04);
}

/* Only visible while it animates; the resting map has no ring. */
.kindling-footer-map__ripple {
	stroke: var(--wp--preset--color--theme-04);
	opacity: 0;
}

/*
 * Real text, ending just left of the marker and centered on it. Positioned in
 * percentages of the map (marker at 61.5 / 154 across, 190.5 / 277 down), so
 * it stays attached if the map scales.
 */
.kindling-footer-map__label {
	position: absolute;
	top: 68.8%;
	right: 74.4%;
	transform: translateY(-50%);
	color: var(--wp--preset--color--theme-01);
	font-family: var(--wp--custom--font-family--heading);
	font-size: var(--wp--preset--font-size--body-small);
	font-weight: 600;
	line-height: 1;
	white-space: nowrap;
}

/* ---------------------------------------------------------------------------
 * Entrance animations.
 * ------------------------------------------------------------------------ */

@media (prefers-reduced-motion: no-preference) {
	.is-animation-ready {
		--kindling-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
		--kindling-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
		--kindling-ease-settle: cubic-bezier(0.34, 1.4, 0.64, 1);
	}

	.is-animation-ready :is(.kindling-footer-route__reveal, .kindling-footer-map__outline) {
		stroke-dasharray: 1 1;
	}

	.is-animation-ready :is(.kindling-footer-route__dot, .kindling-footer-route__glyph, .kindling-footer-map__ripple, .kindling-footer-map__marker) {
		transform-box: fill-box;
		transform-origin: center;
	}

	/*
	 * Parked on the first frame until the illustration is in view. This rule
	 * outranks the per-element `animation` shorthands below, which would
	 * otherwise reset the play state to running.
	 */
	.is-animation-ready:not(.is-animating) :is(
			.kindling-footer-route__reveal,
			.kindling-footer-route__dot,
			.kindling-footer-route__glyph,
			.kindling-footer-map__outline,
			.kindling-footer-map__marker,
			.kindling-footer-map__ripple,
			.kindling-footer-map__label
		) {
		animation-play-state: paused;
	}

	/*
	 * Route, about 2.6s: the trail walks in from the page edge and lands on the
	 * first dot, the gold words step in one letter after another along their
	 * curve like footprints, a second dot, the teal words, and the trail
	 * carries on off the footer.
	 *
	 * The trails are revealed through masks that follow their own geometry, so
	 * the dashes keep their 4/4 pattern. The words are one path per glyph and
	 * animate only opacity and transform, staggered by each glyph's `--i`, which
	 * keeps the reveal smooth.
	 */
	.is-animation-ready .kindling-footer-route__trail--start {
		mask: url(#kindling-route-reveal-start);
	}

	.is-animation-ready .kindling-footer-route__trail--end {
		mask: url(#kindling-route-reveal-end);
	}

	.is-animation-ready .kindling-footer-route__reveal--start {
		animation: kindling-draw 0.7s var(--kindling-ease-out) 0.1s both;
	}

	.is-animation-ready .kindling-footer-route__dot--find {
		animation: kindling-pop 0.35s var(--kindling-ease-settle) 0.65s both;
	}

	.is-animation-ready .kindling-footer-route__words--find {
		--kindling-glyph-start: 0.72s;
	}

	.is-animation-ready .kindling-footer-route__dot--explore {
		animation: kindling-pop 0.35s var(--kindling-ease-settle) 1.3s both;
	}

	.is-animation-ready .kindling-footer-route__words--explore {
		--kindling-glyph-start: 1.36s;
	}

	.is-animation-ready .kindling-footer-route__glyph {
		animation: kindling-glyph 0.4s var(--kindling-ease-out)
			calc(var(--kindling-glyph-start) + var(--i) * 18ms) both;
	}

	.is-animation-ready .kindling-footer-route__reveal--end {
		animation: kindling-draw 0.8s var(--kindling-ease-in-out) 1.75s both;
	}

	/*
	 * Map, about 3.2s: Illinois traces itself, the marker drops onto O'Fallon
	 * and settles, a ring ripples out twice as the "found it" moment, and the
	 * name slides out from the marker. It starts a beat after the route, so the
	 * two sequences read as one when they enter together.
	 */
	.is-animation-ready .kindling-footer-map__outline {
		animation: kindling-draw 1.6s var(--kindling-ease-in-out) 0.3s both;
	}

	.is-animation-ready .kindling-footer-map__marker {
		animation: kindling-drop 0.6s var(--kindling-ease-out) 1.6s both;
	}

	.is-animation-ready .kindling-footer-map__ripple {
		/* forwards, not both: the ring stays invisible while it waits. */
		animation: kindling-ripple 1.2s var(--kindling-ease-out) 2s 2 forwards;
	}

	.is-animation-ready .kindling-footer-map__label {
		animation: kindling-label 0.5s var(--kindling-ease-out) 2.05s both;
	}
}

@keyframes kindling-draw {
	from {
		stroke-dashoffset: 1;
	}

	to {
		stroke-dashoffset: 0;
	}
}

@keyframes kindling-pop {
	from {
		transform: scale(0);
	}

	to {
		transform: scale(1);
	}
}

@keyframes kindling-glyph {
	from {
		opacity: 0;
		transform: translateY(4px) scale(0.85);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

@keyframes kindling-drop {
	0% {
		opacity: 0;
		transform: translateY(-18px);
	}

	60% {
		opacity: 1;
		transform: translateY(1.5px);
	}

	100% {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes kindling-ripple {
	from {
		opacity: 0.8;
		transform: scale(1);
	}

	to {
		opacity: 0;
		transform: scale(3.4);
	}
}

@keyframes kindling-label {
	from {
		opacity: 0;
		transform: translate(8px, -50%);
	}

	to {
		opacity: 1;
		transform: translate(0, -50%);
	}
}
