/* Buffering layer.
 *
 * The overlay is written by buffer.js before the body parses, but it starts
 * hidden: a warm page never flashes a white sheet. buffer.js adds `is-on`
 * only when the parser is still working after a short delay, and `is-done`
 * once the DOM is usable.
 *
 * Light by default; the script copies the stored theme onto the overlay so a
 * dark session never flashes white.
 */

#hbg-buffer {
	position: fixed;
	inset: 0;
	z-index: 2147483000;
	display: grid;
	place-items: center;
	background: #ffffff;
	color: #16181d;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.24s ease, visibility 0s linear 0.24s;
}

#hbg-buffer.is-on {
	opacity: 1;
	visibility: visible;
	transition: opacity 0.24s ease, visibility 0s;
}

#hbg-buffer[data-theme="dark"] {
	background: #101114;
	color: #f2f2f2;
}

/* The layer sits on <html>, above every themed rule in the bundle, so the
   dismissal is written with !important: nothing in the page cascade gets to
   keep the overlay on screen after the document is usable. */
#hbg-buffer.is-done {
	opacity: 0 !important;
	visibility: hidden !important;
	pointer-events: none !important;
}

.hbg-buffer-inner {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 18px;
}

.hbg-buffer-mark {
	width: 62px;
	height: 62px;
	object-fit: contain;
	animation: hbg-buffer-pulse 1.8s ease-in-out infinite;
}

.hbg-buffer-bar {
	position: relative;
	width: 176px;
	height: 3px;
	overflow: hidden;
	border-radius: 999px;
	background: rgba(101, 113, 255, 0.16);
}

.hbg-buffer-bar span {
	position: absolute;
	inset: 0 auto 0 0;
	width: 8%;
	border-radius: inherit;
	background: linear-gradient(90deg, #7a85ff, #6571ff);
	box-shadow: 0 0 10px rgba(101, 113, 255, 0.55);
	transition: width 0.34s ease;
}

/* The bar moves while the sheet is up, so a slow route reads as work rather
   than a frozen 8% sliver. */
#hbg-buffer.is-on .hbg-buffer-bar span {
	animation: hbg-buffer-run 2.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

#hbg-buffer.is-done .hbg-buffer-bar span {
	width: 100%;
	animation: none;
}

.hbg-buffer-label {
	margin: 0;
	color: currentColor;
	font-family: "Proxima Nova", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
	font-size: 10.5px;
	font-weight: 600;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	opacity: 0.55;
}

@keyframes hbg-buffer-pulse {
	0%,
	100% {
		transform: scale(1);
		opacity: 0.9;
	}
	50% {
		transform: scale(0.94);
		opacity: 1;
	}
}

@keyframes hbg-buffer-run {
	0% {
		width: 8%;
	}
	55% {
		width: 62%;
	}
	100% {
		width: 86%;
	}
}

/* Slim top bar for same-page transitions after the first paint. */
#hbg-progress {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 2147483001;
	height: 2px;
	pointer-events: none;
	background: transparent;
	opacity: 0;
	transition: opacity 0.2s ease;
}

#hbg-progress.is-on {
	opacity: 1;
}

#hbg-progress span {
	display: block;
	height: 100%;
	width: 100%;
	transform: scaleX(0);
	transform-origin: 0 50%;
	background: linear-gradient(90deg, #7a85ff, #6571ff);
	box-shadow: 0 0 8px rgba(101, 113, 255, 0.6);
}

#hbg-progress.is-on span {
	animation: hbg-progress-run 1.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes hbg-progress-run {
	0% {
		transform: scaleX(0);
	}
	60% {
		transform: scaleX(0.7);
	}
	100% {
		transform: scaleX(0.92);
	}
}

@media (prefers-reduced-motion: reduce) {
	.hbg-buffer-mark,
	#hbg-buffer.is-on .hbg-buffer-bar span,
	#hbg-progress.is-on span {
		animation: none;
	}

	#hbg-progress.is-on span {
		transform: scaleX(0.9);
	}
}
