/*** Bagel rain — bagels drop in and pile up along the bottom of the home page ***/

.bagel-rain {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	overflow: hidden;
	pointer-events: none;
	/* Negative, so the bagels sit behind the text of the page they fall on.
	   .page-content below establishes the stacking context that contains them,
	   which keeps them above the page background but under everything else. */
	z-index: -1;
}

/* Keep the page itself above the falling bagels. */
.site-header, .page-content, .site-footer {
	position: relative;
	z-index: 1;
}

.bagel {
	position: absolute;
	left: var(--x);
	bottom: var(--rest);
	width: var(--size);
	margin-left: calc(var(--size) / -2);
	animation: bagel-drop 2.5s var(--delay) both;
}

.bagel img {
	display: block;
	width: 100%;
	height: auto;
	transform: rotate(var(--spin-end));
	animation: bagel-spin 2.5s var(--delay) both;
}

/* Fall, land, squash, bounce, then shrink away. Percentages of translateY are
   relative to the bagel's own height, so every size bounces proportionally. */
@keyframes bagel-drop {
	0% {
		transform: translate(var(--sway), -105vh) scale(1, 1);
		opacity: 1;
		animation-timing-function: cubic-bezier(0.45, 0, 0.85, 0.4);
	}
	44% {
		transform: translate(0, 0) scale(1, 1);
		animation-timing-function: ease-out;
	}
	48% {
		transform: translate(0, 0) scale(1.18, 0.82);
		animation-timing-function: ease-out;
	}
	58% {
		transform: translate(0, -26%) scale(0.94, 1.06);
		animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.4);
	}
	66% {
		transform: translate(0, 0) scale(1.1, 0.9);
		animation-timing-function: ease-out;
	}
	72% {
		transform: translate(0, -8%) scale(0.97, 1.03);
		animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.4);
	}
	77% {
		transform: translate(0, 0) scale(1.05, 0.95);
		animation-timing-function: ease-out;
	}
	80% {
		transform: translate(0, 0) scale(1, 1);
		opacity: 1;
		animation-timing-function: ease-in;
	}
	100% {
		transform: translate(0, 0) scale(0.6, 0.6);
		opacity: 0;
	}
}

/* Spin on the way down, then wobble to a stop. */
@keyframes bagel-spin {
	0% {
		transform: rotate(var(--spin-start));
		animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1);
	}
	44% {
		transform: rotate(var(--spin-end));
		animation-timing-function: ease-out;
	}
	58% {
		transform: rotate(calc(var(--spin-end) + 5deg));
		animation-timing-function: ease-in-out;
	}
	70% {
		transform: rotate(calc(var(--spin-end) - 2deg));
		animation-timing-function: ease-in-out;
	}
	100% {
		transform: rotate(var(--spin-end));
	}
}

/* Narrow screens: fewer, smaller bagels. */
@media screen and (max-width: 700px) {
	.bagel {
		width: calc(var(--size) * 0.7);
		margin-left: calc(var(--size) * -0.35);
	}
	.bagel:nth-child(2n) {
		display: none;
	}
}

/* Respect a reduced-motion preference: no drop, no bagels. */
@media (prefers-reduced-motion: reduce) {
	.bagel-rain {
		display: none;
	}
}
