/*
 * Section: "Let it loosen" (the "jl-unwind" group).
 *
 * A soft green field with a title, a small label and a few drifting lines.
 * The text is ordinary blocks; the painted background (a cloudy field, grain
 * and the fades into the page) is added on the front by inc/sections.php.
 *
 * Colours are derived from the theme palette, so the section follows
 * Appearance > Editor > Styles. It stays a deep green with light text in both
 * light and dark mode, and fades into the page colour at the top and bottom.
 */

.jl-unwind.jl-unwind {
	--ju: var(--wp--preset--color--accent-3);
	--ju-light: var(--wp--preset--color--accent-1);
	--ju-ink: var(--wp--preset--color--dark-contrast);
	--ju-pad: 48px;
	--ease-out: cubic-bezier(0.16, 1, 0.3, 1);
	position: relative;
	margin-block: 0;
	/* How far the page colour reaches into the section before the green takes over. */
	--ju-fade-top: clamp(200px, 36vh, 400px);
	--ju-fade-bottom: clamp(130px, 24vh, 260px);
	/* The text starts where the fade has all but finished, so it always sits on green. */
	padding: calc(var(--ju-fade-top) * 0.94) var(--ju-pad) var(--ju-fade-bottom);
	overflow: hidden;
	background: var(--ju);
	color: var(--ju-ink);
	font-family: var(--wp--preset--font-family--dm-sans);
}

/* In dark mode the palette's greens turn pale, so the field is mixed back down to a deep green. */
:root[data-theme="dark"] .jl-unwind.jl-unwind {
	--ju: color-mix(in srgb, var(--wp--preset--color--dark-accent-3) 38%, var(--wp--preset--color--dark-base));
	--ju-light: color-mix(in srgb, var(--wp--preset--color--dark-accent-1) 60%, var(--wp--preset--color--dark-base));
}

.jl-js .jl-unwind.jl-unwind {
	min-height: 125vh;
}

/*
 * WordPress spaces out a Group's children, including the absolutely placed
 * background layers, which pushed them down and left a bare strip of green
 * at the top. Everything inside sets its own spacing instead.
 */
.jl-unwind.jl-unwind > *,
.jl-unwind .jl-unwind__head > *,
.jl-unwind .jl-unwind__lines > * {
	margin-block: 0;
}

/* ---------- Painted background (front only) ---------- */

/*
 * Performance: the cloudy field used to be drawn live with SVG warp and noise
 * filters and three blended layers, which was heavy to scroll. It is now two
 * small images drawn with plain transparency, with no filters or blend modes:
 *
 *   - assets/img/unwind-field.webp  the light and dark variation of the field,
 *                                   as transparent cream and black over the
 *                                   section's own colour
 *   - assets/img/grain.png          a small repeating tile of fine grain
 *
 * Because the images only lighten and darken, the colour itself still comes
 * from the palette (--ju): change Forest in the Styles panel and the section
 * follows, in light and dark mode alike.
 */
.jl-unwind .jl-unwind__bg {
	position: absolute;
	inset: 0;
	overflow: hidden;
	background: url(../img/unwind-field.webp) center / cover no-repeat;
}

.jl-js .jl-unwind .jl-unwind__bg {
	opacity: 0.25;
	transition: opacity 2.4s ease;
}

.jl-js .jl-unwind.is-in .jl-unwind__bg {
	opacity: 1;
}

/* One plain glow drifting slowly across the field keeps it from feeling frozen. */
.jl-unwind .jl-unwind__bg::after {
	content: "";
	position: absolute;
	top: 10%;
	left: 30%;
	width: 70%;
	height: 60%;
	background: radial-gradient(closest-side, color-mix(in srgb, var(--ju-light) 55%, transparent), transparent);
	opacity: 0.5;
	pointer-events: none;
}

.jl-js .jl-unwind .jl-unwind__bg::after {
	will-change: transform;
	animation: jl-unwind-drift 24s ease-in-out infinite alternate paused;
}

.jl-js .jl-unwind.is-live .jl-unwind__bg::after {
	animation-play-state: running;
}

@keyframes jl-unwind-drift {
	from {
		transform: translate3d(-18%, -8%, 0) scale(0.9);
	}
	to {
		transform: translate3d(14%, 16%, 0) scale(1.15);
	}
}

.jl-unwind .jl-unwind__grain,
.jl-unwind .jl-unwind__fade {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.jl-unwind .jl-unwind__grain {
	background: url(../img/grain.png) 0 0 / 128px 128px repeat;
}

/* Blends into the page colour above and below, in light and dark mode alike. */
/*
 * The fade is long and eased rather than a short straight ramp: it starts as
 * the solid page colour, so there is no seam against the section above, and
 * it eases in and out, so the eye does not catch a line where it begins or ends.
 */
.jl-unwind .jl-unwind__fade--top {
	bottom: auto;
	height: var(--ju-fade-top);
	background: linear-gradient(
		to bottom,
		var(--wp--preset--color--base) 0%,
		var(--wp--preset--color--base) 5%,
		color-mix(in srgb, var(--wp--preset--color--base) 93%, transparent) 16%,
		color-mix(in srgb, var(--wp--preset--color--base) 77%, transparent) 30%,
		color-mix(in srgb, var(--wp--preset--color--base) 55%, transparent) 45%,
		color-mix(in srgb, var(--wp--preset--color--base) 33%, transparent) 60%,
		color-mix(in srgb, var(--wp--preset--color--base) 15%, transparent) 75%,
		color-mix(in srgb, var(--wp--preset--color--base) 4%, transparent) 88%,
		transparent 100%
	);
}

.jl-unwind .jl-unwind__fade--bottom {
	top: auto;
	height: var(--ju-fade-bottom);
	background: linear-gradient(
		to top,
		var(--wp--preset--color--base) 0%,
		var(--wp--preset--color--base) 5%,
		color-mix(in srgb, var(--wp--preset--color--base) 93%, transparent) 16%,
		color-mix(in srgb, var(--wp--preset--color--base) 77%, transparent) 30%,
		color-mix(in srgb, var(--wp--preset--color--base) 55%, transparent) 45%,
		color-mix(in srgb, var(--wp--preset--color--base) 33%, transparent) 60%,
		color-mix(in srgb, var(--wp--preset--color--base) 15%, transparent) 75%,
		color-mix(in srgb, var(--wp--preset--color--base) 4%, transparent) 88%,
		transparent 100%
	);
}

/*
 * Where the section has faded to the page colour, the floating header should
 * read the page, not the green. These strips tell it so (data-header-tone="page").
 */
.jl-unwind .jl-unwind__tone {
	position: absolute;
	right: 0;
	left: 0;
	height: calc(var(--ju-fade-top) * 0.42);
}

.jl-unwind .jl-unwind__tone--top {
	top: 0;
}

.jl-unwind .jl-unwind__tone--bottom {
	bottom: 0;
	height: calc(var(--ju-fade-bottom) * 0.42);
}

/* ---------- Content ---------- */

.jl-unwind .jl-unwind__head,
.jl-unwind .jl-unwind__lines {
	position: relative;
}

/* Own layer for each moving piece of text, so scrolling never redraws the background. */
.jl-js .jl-unwind .jl-unwind__head,
.jl-js .jl-unwind .jl-unwind__lines > p {
	will-change: transform;
}

.jl-unwind .jl-unwind__title {
	color: inherit;
	font-family: var(--wp--preset--font-family--fraunces);
	font-size: clamp(3rem, 4.6vw, 5.5rem);
	font-weight: 400;
	letter-spacing: -0.01em;
	line-height: 1;
}

.jl-unwind .jl-unwind__sub {
	margin: 14px 0 0 8vw;
	font-size: clamp(0.875rem, 1vw, 1.25rem);
	font-weight: 300;
	letter-spacing: 0.32em;
	line-height: 1;
}

.jl-unwind .jl-unwind__lines {
	margin-top: clamp(64px, 18vh, 200px);
}

.jl-unwind .jl-unwind__lines > p {
	max-width: 46vw;
	margin-left: calc(var(--in, 0) * 1vw);
	font-size: clamp(0.8125rem, 0.98vw, 1.1875rem);
	font-weight: 300;
	letter-spacing: 0.17em;
	line-height: 1.85;
	text-shadow:
		0 0 16px color-mix(in srgb, color-mix(in srgb, var(--ju) 55%, #000) 70%, transparent),
		0 1px 3px color-mix(in srgb, color-mix(in srgb, var(--ju) 55%, #000) 55%, transparent);
}

/* Each line sits at its own indent; the pattern repeats every eight lines. */
.jl-unwind .jl-unwind__lines > p:nth-child(8n + 2) { --in: 6; }
.jl-unwind .jl-unwind__lines > p:nth-child(8n + 3) { --in: 36; }
.jl-unwind .jl-unwind__lines > p:nth-child(8n + 4) { --in: 8; }
.jl-unwind .jl-unwind__lines > p:nth-child(8n + 6) { --in: 31; }
.jl-unwind .jl-unwind__lines > p:nth-child(8n + 8) { --in: 9; }

/* ---------- Reveal (front only, once the script is running) ---------- */

.jl-js .jl-unwind .jl-unwind__sub {
	opacity: 0;
	transition: opacity 1.6s ease 0.6s;
}

.jl-js .jl-unwind.is-in .jl-unwind__sub {
	opacity: 1;
}

.jl-unwind .wd {
	display: inline-block;
	opacity: 0;
	transform: translateY(16px);
	transition:
		opacity 1.5s ease var(--d),
		transform 1.5s var(--ease-out) var(--d);
}

/* Only the few words of the title blur into focus; doing that for every word of every line was costly. */
.jl-unwind .jl-unwind__title .wd {
	filter: blur(7px);
	transition:
		opacity 1.5s ease var(--d),
		filter 1.5s ease var(--d),
		transform 1.5s var(--ease-out) var(--d);
}

.jl-unwind.is-in .wd {
	opacity: 1;
	filter: none;
	transform: none;
}

/* ---------- Tablet ---------- */
@media (max-width: 1099px) {
	.jl-unwind.jl-unwind {
		--ju-pad: 40px;
	}

	.jl-js .jl-unwind.jl-unwind {
		min-height: 115vh;
	}

	.jl-unwind .jl-unwind__title {
		font-size: 3.75rem;
	}

	.jl-unwind .jl-unwind__sub {
		margin-left: 9vw;
		font-size: 0.875rem;
	}

	.jl-unwind .jl-unwind__lines {
		margin-top: 16vh;
	}

	.jl-unwind .jl-unwind__lines > p {
		max-width: 70vw;
		margin-left: calc(var(--in, 0) * 0.7vw);
		font-size: 0.9375rem;
	}
}

/* ---------- Mobile: fewer lines, lighter distortion, no drift ---------- */
@media (max-width: 699px) {
	.jl-unwind.jl-unwind {
		--ju-pad: 24px;
		--ju-fade-top: 190px;
		--ju-fade-bottom: 130px;
	}

	.jl-js .jl-unwind.jl-unwind {
		min-height: 100svh;
	}

	.jl-js .jl-unwind .jl-unwind__bg::after {
		animation: none;
	}

	.jl-unwind .jl-unwind__title {
		font-size: 2.75rem;
	}

	.jl-unwind .jl-unwind__sub {
		margin-left: 10vw;
	}

	.jl-unwind .jl-unwind__lines {
		margin-top: 88px;
	}

	.jl-unwind .jl-unwind__lines > p {
		max-width: 100%;
		margin-left: calc(var(--in, 0) * 0.45vw);
		font-size: 0.875rem;
	}

	/* Lines marked "jl-line--hide-sm" are left out on phones. */
	.jl-unwind .jl-line--hide-sm {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.jl-unwind.jl-unwind * {
		transition: none !important;
	}

	.jl-unwind .wd,
	.jl-js .jl-unwind .jl-unwind__sub {
		opacity: 1;
		filter: none;
		transform: none;
	}

	.jl-js .jl-unwind .jl-unwind__bg {
		opacity: 1;
	}

	.jl-js .jl-unwind .jl-unwind__bg::after {
		animation: none;
	}
}
