/**
 * Page loader: only shown when a page is slow (see ueno_child_loader_script()).
 * The homepage bird in black; its spiral is drawn over and over for as long as
 * the page takes: drawn from the mouth to the centre (1.6 s), held as the
 * finished drawing (0.6 s), faded out (0.4 s), and again. The loader fades out
 * whenever the page is ready, at any point in a round.
 */
.site-loader {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.85);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.show-loader .site-loader {
	opacity: 1;
	visibility: visible;
	transition: opacity 0.2s ease;
}

.site-loader__drawing {
	display: block;
	width: auto;
	height: min(40vh, 300px);
	aspect-ratio: 440 / 600;
	overflow: visible;
}

/* The mask: a thick line along the spiral's centre, drawn from the mouth. */
.site-loader__line {
	fill: none;
	stroke: #fff;
	stroke-width: 16;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 1 1;
	stroke-dashoffset: 1;
}

/*
 * One round = 2.6 s: draw 0–61.5% (1.6 s), hold 61.5–84.6% (0.6 s), fade
 * 84.6–100% (0.4 s), repeated while the loader shows. During the hold the
 * unmasked spiral takes over in one step (no overlap, which would darken the
 * soft edges), so the held frame is exactly the drawing.
 */
.site-loader__spiral-full {
	opacity: 0;
}

.show-loader .site-loader__line {
	animation: site-loader-draw 2.6s infinite;
}

.show-loader .site-loader__spiral {
	animation: site-loader-masked 2.6s infinite;
}

.show-loader .site-loader__spiral-full {
	animation: site-loader-full 2.6s infinite;
}

@keyframes site-loader-draw {
	0% {
		stroke-dashoffset: 1;
		animation-timing-function: cubic-bezier(0.45, 0.05, 0.4, 1);
	}
	61.5%,
	100% {
		stroke-dashoffset: 0;
	}
}

/* The masked spiral: visible while drawing, hidden from the swap on. */
@keyframes site-loader-masked {
	0%,
	61.5% {
		opacity: 1;
	}
	61.6%,
	100% {
		opacity: 0;
	}
}

/* The full spiral: takes over at the swap, holds, then fades out. */
@keyframes site-loader-full {
	0%,
	61.5% {
		opacity: 0;
	}
	61.6%,
	84.6% {
		opacity: 1;
	}
	100% {
		opacity: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.show-loader .site-loader__line,
	.show-loader .site-loader__spiral,
	.show-loader .site-loader__spiral-full {
		animation: none;
	}

	.site-loader__spiral {
		opacity: 0;
	}

	.site-loader__spiral-full {
		opacity: 1;
	}
}
