/**
 * Reveals: blocks that appear as the reader scrolls to them (divb-hq#358, docs/SPEC-reveals.md §9.1).
 *
 * The classes come from the server (`Mf_Rv_Render`); the saved markup carries none of them.
 * **The start state applies only under `html.mf-rv-on`**, which the script sets after it has
 * shown everything already in the window (§8): without JavaScript, under reduced motion and in
 * print every block is simply there.
 *
 * Kind, strength and step are custom properties, so a block's own classes compute its start
 * state, and a staggering group hands its step to its members by inheritance.
 *
 * Only `opacity`, `transform`, `filter` and `clip-path` move: nothing changes a block's box,
 * so the page never jumps.
 */

.mf-rv-on .mf-rv {
	transition-property: opacity, transform, filter, clip-path;
	transition-duration: var(--mf-rv-dur, 0.8s);
	transition-timing-function: var(--mf-rv-ease, cubic-bezier(0.16, 1, 0.3, 1));
	transition-delay: calc(var(--mf-rv-delay, 0s) + var(--mf-rv-i, 0) * var(--mf-rv-step, 0s));
}

.mf-rv-on .mf-rv:not(.mf-rv-is-in) {
	opacity: var(--mf-rv-o0, 0);
	transform: var(--mf-rv-from, none);
	filter: var(--mf-rv-f0, none);
	clip-path: var(--mf-rv-c0, none);
}

/* The clip kinds end slightly outside the box, so focus rings and overhangs are not cut. */
.mf-rv-on :is(.mf-rv--wipe, .mf-rv--open).mf-rv-is-in {
	clip-path: inset(-1rem);
}

/* A silent reset: back to the start without being seen. */
.mf-rv-on .mf-rv.mf-rv-is-reset,
.mf-rv-on .mf-rv.mf-rv-is-reset .mf-rv-w {
	transition: none;
}

/* The kinds. The distance scales with the strength (--mf-rv-s) and flips with the direction
   the block comes from (--mf-rv-dir, -1 from the top). */
.mf-rv--up {
	--mf-rv-from: translateY(calc(32px * var(--mf-rv-s, 1) * var(--mf-rv-dir, 1)));
}

.mf-rv--side {
	--mf-rv-from: translateX(calc(-40px * var(--mf-rv-s, 1)));
}

.mf-rv--zoom {
	--mf-rv-from: scale(calc(1 - 0.08 * var(--mf-rv-s, 1)));
}

.mf-rv--back {
	--mf-rv-from: scale(calc(1 + 0.08 * var(--mf-rv-s, 1)));
}

.mf-rv--wipe {
	--mf-rv-o0: 1;
	--mf-rv-c0: inset(0 0 100% 0);
	--mf-rv-from: translateY(calc(12px * var(--mf-rv-s, 1) * var(--mf-rv-dir, 1)));
}

.mf-rv--open {
	--mf-rv-o0: 1;
	--mf-rv-c0: inset(0 50% 0 50%);
}

.mf-rv--blur {
	--mf-rv-f0: blur(calc(10px * var(--mf-rv-s, 1)));
}

.mf-rv--tilt {
	--mf-rv-from:
		perspective(900px) rotateX(calc(18deg * var(--mf-rv-s, 1)))
		translateY(calc(16px * var(--mf-rv-s, 1)));
	transform-origin: 50% 0;
}

/* Word by word: the heading stands still, its words slide up one after another (§7). */
.mf-rv--words {
	--mf-rv-o0: 1;
}

.mf-rv-on .mf-rv--words .mf-rv-w {
	display: inline-block;
	transition-property: opacity, transform;
	transition-duration: var(--mf-rv-dur, 0.8s);
	transition-timing-function: var(--mf-rv-ease, cubic-bezier(0.16, 1, 0.3, 1));
	--mf-rv-word: calc(var(--mf-rv-wi, 0) * 0.06s);
	--mf-rv-start: calc(var(--mf-rv-delay, 0s) + var(--mf-rv-i, 0) * var(--mf-rv-step, 0s));
	transition-delay: calc(var(--mf-rv-start) + var(--mf-rv-word));
}

.mf-rv-on .mf-rv--words:not(.mf-rv-is-in) .mf-rv-w {
	opacity: 0;
	transform: translateY(calc(32px * var(--mf-rv-s, 1) * var(--mf-rv-dir, 1)));
}

/* The strengths (D4): distance and duration. *normal* writes no class. */
.mf-rv--soft {
	--mf-rv-s: 0.5;
	--mf-rv-dur: 0.6s;
}

.mf-rv--strong {
	--mf-rv-s: 1.9;
	--mf-rv-dur: 1.05s;
}

/* The swing: a curve that overshoots and settles, independent of the strength. */
.mf-rv--spring {
	--mf-rv-ease: cubic-bezier(0.3, 1.9, 0.5, 1);
}

/* The step of a staggering group, inherited by its members. *mittel* writes no class. */
.mf-rv-seq {
	--mf-rv-step: 0.1s;
}

.mf-rv-seq--short {
	--mf-rv-step: 0.08s;
}

.mf-rv-seq--long {
	--mf-rv-step: 0.2s;
}

/* Reduced motion: everything is there and nothing moves. The script does not arm either. */
@media (prefers-reduced-motion: reduce) {

	.mf-rv-on .mf-rv,
	.mf-rv-on .mf-rv:not(.mf-rv-is-in),
	.mf-rv-on .mf-rv .mf-rv-w {
		opacity: 1;
		transform: none;
		filter: none;
		clip-path: none;
		transition: none;
	}
}

@media print {

	.mf-rv-on .mf-rv:not(.mf-rv-is-in),
	.mf-rv-on .mf-rv:not(.mf-rv-is-in) .mf-rv-w {
		opacity: 1;
		transform: none;
		filter: none;
		clip-path: none;
	}
}
