/*
 * Entrance animations (ADR 0073), loaded only on public pages that animate something.
 *
 * What enters: the page's sections without an entrance of their own when the site has a default
 * (body .sv-entrances--fade / --fade-up), and anything with its own (.sv-entrance-fade…). It waits
 * hidden until entrance.js sees it come into view (.sv-entered), then CSS fades and moves it in
 * (opacity and the translate property, so an element's own transform on hover stays its own).
 *
 * Safety: nothing is hidden without scripting; if the script is held back (a cache plugin's "delay
 * JavaScript"), everything shows after 2.5s; visitors who ask for less motion see no movement.
 */

.sv-entrances {
	--sv-entrance-duration: 0.7s;
	--sv-entrance-ease: cubic-bezier(0.22, 1, 0.36, 1);
	--sv-entrance-distance: 1rem;
}

.sv-entrances--fast {
	--sv-entrance-duration: 0.45s;
}

.sv-entrances--slow {
	--sv-entrance-duration: 1s;
}

/* The script has started: it shows things as they come into view, the fallback isn't needed. */
.sv-entrances-ready {
	--sv-entrance-fallback: none;
}

/* Visitors who ask their device for less motion: nothing waits hidden, nothing moves. */
@media (prefers-reduced-motion: reduce) {
	.sv-entrances:not(.sv-entrances--always) {
		--sv-entrance-hidden: 1;
		--sv-entrance-shift: 0 0;
		--sv-entrance-fallback: none;
	}
}

/* Where each entrance comes from: sections with the site's default (zero specificity), own choices. */
:where(.sv-entrances--fade-up .sv-page > .sv-section),
.sv-entrance-fade-up {
	--sv-entrance-from: 0 var(--sv-entrance-distance);
}

/* None: shown as it is; a section with None leaves the site's default. */
.sv-entrance-none {
	--sv-entrance-from: 0 0;
}

.sv-entrance-fade {
	--sv-entrance-from: 0 0;
}

.sv-entrance-fade-left {
	--sv-entrance-from: calc(-1.5 * var(--sv-entrance-distance)) 0;
}

.sv-entrance-fade-right {
	--sv-entrance-from: calc(1.5 * var(--sv-entrance-distance)) 0;
}

/* The page's top comes in quickly, so it is never hidden for long. */
:where(.sv-entrances .sv-page > .sv-section:first-child) {
	--sv-entrance-duration: 0.45s;
}

.sv-entrance-speed-fast {
	--sv-entrance-duration: 0.45s;
}

.sv-entrance-speed-normal {
	--sv-entrance-duration: 0.7s;
}

.sv-entrance-speed-slow {
	--sv-entrance-duration: 1s;
}

.sv-entrance-delay-short {
	--sv-entrance-delay: 0.15s;
}

.sv-entrance-delay-medium {
	--sv-entrance-delay: 0.3s;
}

@media (scripting: enabled) {
	.sv-entrances :is(.sv-entrance-fade, .sv-entrance-fade-up, .sv-entrance-fade-left, .sv-entrance-fade-right):not(.sv-entered),
	:is(.sv-entrances--fade, .sv-entrances--fade-up) .sv-page > .sv-section:not(.sv-entrance-none, .sv-entrance-fade, .sv-entrance-fade-up, .sv-entrance-fade-left, .sv-entrance-fade-right, .sv-entered) {
		opacity: var(--sv-entrance-hidden, 0);
		translate: var(--sv-entrance-shift, var(--sv-entrance-from, 0 0));
		animation: var(--sv-entrance-fallback, sv-entrance-fallback 0.01s 2.5s forwards);
	}
}

/* Coming in; the script then hands transitions back to the element (.sv-entrance-done). */
.sv-entered:not(.sv-entrance-done) {
	transition:
		opacity var(--sv-entrance-duration) var(--sv-entrance-ease) var(--sv-entrance-delay, 0s),
		translate var(--sv-entrance-duration) var(--sv-entrance-ease) var(--sv-entrance-delay, 0s);
}

@keyframes sv-entrance-fallback {
	to {
		opacity: 1;
		translate: 0 0;
	}
}

/*
 * Wipe, Zoom in, Word by word (ADR 0116). Wipe: uncovered edge to edge from the start side (a clip; mirrored on
 * right-to-left pages), the element itself doesn't move. Zoom in: it fades in from 94% of its size. Word by word: a
 * heading's words (.sv-word, wrapped by entrance.js) fade up one after another; until they are wrapped the heading
 * waits hidden. The same safety as above: only with scripting, shown after 2.5s anyway, still for reduced motion.
 */
.sv-entrance-wipe {
	--sv-entrance-clip: inset(0 100% 0 0);
}

:where([dir="rtl"]) .sv-entrance-wipe {
	--sv-entrance-clip: inset(0 0 0 100%);
}

.sv-entrance-zoom {
	--sv-entrance-scale: 0.94;
}

@media (prefers-reduced-motion: reduce) {
	.sv-entrances:not(.sv-entrances--always) {
		--sv-entrance-clip: none;
		--sv-entrance-scale: 1;
		--sv-entrance-word: 0 0;
	}
}

@media (scripting: enabled) {
	.sv-entrances .sv-entrance-wipe:not(.sv-entered) {
		clip-path: var(--sv-entrance-clip);
		animation: var(--sv-entrance-fallback, sv-entrance-unclip 0.01s 2.5s forwards);
	}

	.sv-entrances .sv-entrance-zoom:not(.sv-entered) {
		opacity: var(--sv-entrance-hidden, 0);
		scale: var(--sv-entrance-scale);
		animation: var(--sv-entrance-fallback, sv-entrance-unzoom 0.01s 2.5s forwards);
	}

	.sv-entrances .sv-entrance-words:not(.sv-words-ready),
	.sv-entrances .sv-entrance-words:not(.sv-entered) .sv-word {
		opacity: var(--sv-entrance-hidden, 0);
		animation: var(--sv-entrance-fallback, sv-entrance-fallback 0.01s 2.5s forwards);
	}

	.sv-entrances .sv-entrance-words:not(.sv-entered) .sv-word {
		translate: var(--sv-entrance-word, 0 0.4em);
	}
}

.sv-entrance-words .sv-word {
	display: inline-block;
}

.sv-entrance-wipe.sv-entered:not(.sv-entrance-done) {
	clip-path: inset(0);
	transition: clip-path var(--sv-entrance-duration) var(--sv-entrance-ease) var(--sv-entrance-delay, 0s);
}

.sv-entrance-zoom.sv-entered:not(.sv-entrance-done) {
	transition:
		opacity var(--sv-entrance-duration) var(--sv-entrance-ease) var(--sv-entrance-delay, 0s),
		scale var(--sv-entrance-duration) var(--sv-entrance-ease) var(--sv-entrance-delay, 0s);
}

/* Each word a little after the one before (no more than 12 steps, so long headings don't keep visitors waiting). */
.sv-entrance-words.sv-entered:not(.sv-entrance-done) .sv-word {
	transition:
		opacity var(--sv-entrance-duration) var(--sv-entrance-ease) calc(var(--sv-entrance-delay, 0s) + min(var(--sv-word), 12) * 0.07s),
		translate var(--sv-entrance-duration) var(--sv-entrance-ease) calc(var(--sv-entrance-delay, 0s) + min(var(--sv-word), 12) * 0.07s);
}

@keyframes sv-entrance-unclip {
	to {
		clip-path: none;
	}
}

@keyframes sv-entrance-unzoom {
	to {
		opacity: 1;
		scale: 1;
	}
}
