/**
 * Bricksify: Scroll Highlight.
 *
 * Loads only with the companion plugin, together with scroll-highlight.js.
 * Every rule targets markup or classes the script creates, so an element
 * carrying `bxc-scroll-highlight` without the plugin is simply normal text.
 */

.bxc-scroll-highlight .bxhl__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* SplitType's markup in the reference: words and letters are inline blocks,
   so a word never breaks between its letters. An underline (links) does not
   reach into inline blocks by itself, so they take it over. */
.bxc-scroll-highlight .bxhl__vis,
.bxc-scroll-highlight .bxhl__word,
.bxc-scroll-highlight .bxhl__char {
	text-decoration: inherit;
}

.bxc-scroll-highlight .bxhl__word {
	display: inline-block;
	white-space: nowrap;
}

.bxc-scroll-highlight .bxhl__char {
	display: inline-block;
}

/* Line highlight: words wait at the dimmed opacity, a lit line fades up
   with the reference's `transition: all .6s ease-in-out`. */
.bxc-scroll-highlight.bxhl--lines .bxhl__word {
	opacity: var(--bxhl-dim, 0.2);
	transition: opacity var(--bxhl-fade, 0.6s) ease-in-out;
}

.bxc-scroll-highlight.bxhl--lines .bxhl__word.is-lit {
	opacity: 1;
}

/* Letter fill: the script tweens each letter; this is the state before. */
.bxc-scroll-highlight.bxhl--letters .bxhl__char {
	opacity: var(--bxhl-dim, 0.2);
}

/*
 * Wipe: the reference covers each line with a layer of the background
 * colour at 0.65. Here each word is masked instead: covered parts show at
 * --bxhl-dim (0.35 = the same look on a plain background, and right on any
 * other). The padding, cancelled by the negative margin so nothing moves,
 * lets the mask reach glyphs that stick out of a tight line height.
 * --bxhl-x is where the edge crosses the word, set by the script.
 */
.bxc-scroll-highlight.bxhl--wipe .bxhl__word {
	padding: 0.25em 0.15em;
	margin: -0.25em -0.15em;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
}

.bxc-scroll-highlight.bxhl--ltr .bxhl__word {
	-webkit-mask-image: linear-gradient(90deg, #000 var(--bxhl-x, -99999px), rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, -99999px));
	mask-image: linear-gradient(90deg, #000 var(--bxhl-x, -99999px), rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, -99999px));
}

.bxc-scroll-highlight.bxhl--rtl .bxhl__word {
	-webkit-mask-image: linear-gradient(90deg, rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, 99999px), #000 var(--bxhl-x, 99999px));
	mask-image: linear-gradient(90deg, rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, 99999px), #000 var(--bxhl-x, 99999px));
}

.bxc-scroll-highlight.bxhl--btt .bxhl__word {
	-webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, 99999px), #000 var(--bxhl-x, 99999px));
	mask-image: linear-gradient(180deg, rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, 99999px), #000 var(--bxhl-x, 99999px));
}

.bxc-scroll-highlight.bxhl--ttb .bxhl__word {
	-webkit-mask-image: linear-gradient(180deg, #000 var(--bxhl-x, -99999px), rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, -99999px));
	mask-image: linear-gradient(180deg, #000 var(--bxhl-x, -99999px), rgba(0, 0, 0, var(--bxhl-dim, 0.35)) var(--bxhl-x, -99999px));
}

/*
 * Word boxes: each word waits invisible, shows
 * as a solid rounded box (80% of its height, 105% of its width, centred),
 * then the box fades while the word appears. --bxhl-a (word) and --bxhl-b
 * (box) are written by the script from the scroll.
 *   --bxhl-box     box colour       (the text colour)
 *   --bxhl-radius  box corners      (16px, the reference's rounded-2xl)
 *   --bxhl-accent  accent words     (text and box)
 */
.bxc-scroll-highlight.bxhl--box .bxhl__word {
	position: relative;
	opacity: var(--bxhl-a, 0);
}

.bxc-scroll-highlight.bxhl--box .bxhl__word::before {
	content: "";
	position: absolute;
	left: 50%;
	top: 50%;
	width: 105%;
	height: 80%;
	transform: translate(-50%, -50%);
	border-radius: var(--bxhl-radius, 16px);
	background-color: var(--bxhl-box, currentColor);
	opacity: var(--bxhl-b, 1);
	pointer-events: none;
}

.bxc-scroll-highlight.bxhl--box .bxhl__in {
	position: relative;
	opacity: calc(1 - var(--bxhl-b, 1));
	text-decoration: inherit;
}

.bxc-scroll-highlight.bxhl--box .bxhl__word.is-accent {
	color: var(--bxhl-accent, #3456f5);
}

.bxc-scroll-highlight.bxhl--box .bxhl__word.is-accent::before {
	background-color: var(--bxhl-accent, #3456f5);
}

/*
 * Pinned boxes: the script wraps the element in a track (--bxhl-pin screen
 * heights) holding a sticky stage one screen tall, the text centred in it.
 * lvh: the stage must not resize while a phone's toolbar slides away.
 */
.bxhl-pin {
	position: relative;
	width: 100%;
	align-self: stretch;
	height: calc(var(--bxhl-pin, 4) * 100vh);
	height: calc(var(--bxhl-pin, 4) * 100lvh);
}

.bxhl-pin__stage {
	position: sticky;
	top: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	width: 100%;
	height: 100vh;
	height: 100lvh;
}

/*
 * Before the script runs, the text is hidden so it cannot flash at full
 * strength and then dim. `bx-js` is printed in <head> by the companion only
 * on pages that use the effect, so a visitor without JavaScript always sees
 * the text. If the script never arrives, the failsafe shows it after 3s.
 */
html.bx-js body.bricks-is-frontend .bxc-scroll-highlight:not(.is-ready) {
	visibility: hidden;
	animation: bxhl-failsafe 0s 3s forwards;
}

@keyframes bxhl-failsafe {
	to {
		visibility: visible;
	}
}

@media (prefers-reduced-motion: reduce) {
	html.bx-js body.bricks-is-frontend .bxc-scroll-highlight:not(.is-ready) {
		visibility: visible;
		animation: none;
	}
}

/*
 * The visual copy stays an inline run of words. Bricks styles every span inside
 * a Text Link as inline-flex (`.brxe-text-link span`), which drops the spaces
 * between the word boxes of a multi-word link.
 */
.bxc-scroll-highlight .bxhl__vis {
	display: inline;
}
