/*
 * Motion states for pages marked up for src/lib/motion.ts. Every hidden start sits under .motion,
 * which the script adds only when the reader has not asked for reduced motion. Transitions sit on the
 * revealed state, so hiding again (design 3's page turns) is instant.
 */
:root {
	--motion-ease: cubic-bezier(0.16, 1, 0.3, 1);
	--motion-snap: cubic-bezier(0.2, 1.4, 0.4, 1);
}
.motion [data-motion] {
	--motion-delay: calc(var(--stagger, 0) * 90ms);
}

/* Lines: every word rises from behind its own mask, and a line's words move together. */
.motion [data-motion="lines"] .mw {
	display: inline-block;
	clip-path: inset(-0.4em -0.3em 0 -0.3em);
	text-decoration: inherit;
}
.motion [data-motion="lines"] .mw__i {
	display: inline-block;
	text-decoration: inherit;
	translate: 0 110%;
}
.motion [data-motion="lines"].is-in .mw {
	/* Once the word is up, the mask opens so descenders are never cut. */
	clip-path: inset(-1em);
	transition: clip-path 0s calc(var(--motion-delay) + var(--line, 0) * 80ms + 0.9s);
}
.motion [data-motion="lines"].is-in .mw__i {
	translate: none;
	transition: translate 0.9s var(--motion-ease) calc(var(--motion-delay) + var(--line, 0) * 80ms);
}

/* Rise: fades up into place. */
.motion [data-motion="rise"] {
	opacity: 0;
	translate: 0 32px;
}
.motion [data-motion="rise"].is-in {
	opacity: 1;
	translate: none;
	transition:
		opacity 0.9s var(--motion-ease) var(--motion-delay),
		translate 0.9s var(--motion-ease) var(--motion-delay);
}

/* Slap: a sticker pressed on, overshooting its size and angle. */
.motion [data-motion="slap"] {
	opacity: 0;
	scale: 1.5;
	rotate: calc(var(--rest-rotate, 0deg) - 12deg);
}
.motion [data-motion="slap"].is-in {
	opacity: 1;
	scale: 1;
	rotate: var(--rest-rotate, 0deg);
	transition:
		opacity 0.25s linear var(--motion-delay),
		scale 0.7s var(--motion-snap) var(--motion-delay),
		rotate 0.7s var(--motion-snap) var(--motion-delay);
}

/* Fade: pictures, slowly, as on The Swaddle. */
.motion [data-motion="fade"] {
	opacity: 0;
}
.motion [data-motion="fade"].is-in {
	opacity: 1;
	transition: opacity 2s var(--motion-ease) var(--motion-delay);
}

/* Curtains: pinned while what follows slides over them. They are measured unpinned (motion.ts). */
.motion [data-stick] {
	position: sticky;
	top: var(--stick, 0px);
}
.motion.motion-measuring [data-stick] {
	position: relative;
	/* Not shifted by the pinning offset either: a tall curtain's --stick is negative, and left in place
	   it would be measured that far above where it sits. */
	top: 0;
}

/* Quick colour changes on hover, wherever a component has not set its own transition. */
.motion :where(a, button) {
	transition:
		color 0.15s,
		background-color 0.15s,
		text-decoration-color 0.15s;
}

/* Printed or saved as PDF: everything shows, in place, whether or not it has been scrolled to. */
@media print {
	.motion [data-motion] {
		opacity: 1 !important;
		translate: none !important;
		scale: none !important;
		rotate: var(--rest-rotate, none) !important;
		transition: none !important;
	}
	.motion [data-motion="lines"] .mw {
		clip-path: none !important;
	}
	.motion [data-motion="lines"] .mw__i {
		translate: none !important;
		transition: none !important;
	}
	.motion [data-stick] {
		position: relative !important;
	}
	.motion [data-parallax] {
		transform: none !important;
	}
}
