/* ========================================
   Back-to-top button: a little hanger that swings,
   with a ring that fills as you scroll down the page.
======================================== */
.to-top {
	--to-top-size: 52px;
	position: fixed;
	right: calc(1rem + env(safe-area-inset-right, 0px));
	bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
	z-index: 900;
	display: flex;
	align-items: center;
	justify-content: flex-start;
	height: var(--to-top-size);
	min-width: var(--to-top-size);
	padding: 0;
	background: var(--ink);
	color: var(--paper);
	border: 0;
	border-radius: calc(var(--to-top-size) / 2);
	cursor: pointer;
	box-shadow: 0 10px 24px -8px rgba(26, 26, 26, 0.55);
	-webkit-tap-highlight-color: transparent;
	opacity: 0;
	transform: translateY(24px) scale(0.8);
	pointer-events: none;
	transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}

.to-top[hidden] {
	display: none;
}

.to-top.is-visible {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

.to-top:hover {
	background: var(--coral);
}

.to-top:focus-visible {
	outline: 2px solid var(--coral);
	outline-offset: 3px;
}

/* Progress ring around the button */
.to-top-ring {
	position: absolute;
	top: 0;
	left: 0;
	width: var(--to-top-size);
	height: var(--to-top-size);
	transform: rotate(-90deg);
	pointer-events: none;
}

.to-top-ring circle {
	fill: none;
	stroke-width: 2.5;
}

.to-top-track {
	stroke: rgba(250, 248, 245, 0.18);
}

.to-top-progress {
	stroke: var(--coral);
	stroke-linecap: round;
	stroke-dasharray: 157.08;
	stroke-dashoffset: calc(157.08 - (157.08 * var(--to-top-progress, 0)));
}

.to-top:hover .to-top-progress {
	stroke: var(--paper);
}

/* The hanger itself, swinging from its hook */
.to-top-swing {
	display: flex;
	flex-shrink: 0;
	width: 26px;
	height: 26px;
	margin: 0 calc((var(--to-top-size) - 26px) / 2);
	transform-origin: 50% 20%;
}

.to-top-hanger {
	width: 100%;
	height: 100%;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.to-top-arrow {
	stroke: var(--coral);
	stroke-width: 2.2;
}

.to-top:hover .to-top-arrow {
	stroke: var(--paper);
}

.to-top.is-visible .to-top-swing {
	animation: to-top-swing 1.4s ease-out 0.15s 1;
}

.to-top.is-launching .to-top-swing {
	animation: to-top-swing-hard 0.6s ease-in-out 1;
}

.to-top.is-launching {
	transform: translateY(-14px) scale(1);
}

@keyframes to-top-swing {
	0% { transform: rotate(0deg); }
	18% { transform: rotate(16deg); }
	38% { transform: rotate(-11deg); }
	58% { transform: rotate(7deg); }
	78% { transform: rotate(-3deg); }
	100% { transform: rotate(0deg); }
}

@keyframes to-top-swing-hard {
	0% { transform: rotate(0deg); }
	25% { transform: rotate(-24deg); }
	55% { transform: rotate(18deg); }
	100% { transform: rotate(0deg); }
}

/* Label slides out on desktop hover / keyboard focus */
.to-top-label {
	max-width: 0;
	overflow: hidden;
	white-space: nowrap;
	font-family: var(--mono);
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	transition: max-width 0.3s ease, padding 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
	.to-top:hover .to-top-label,
	.to-top:focus-visible .to-top-label {
		max-width: 9.5rem;
		padding-left: 0.3rem;
		padding-right: 1.25rem;
	}
}

@media (max-width: 480px) {
	.to-top {
		--to-top-size: 48px;
		right: calc(0.75rem + env(safe-area-inset-right, 0px));
		bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
	}
}

@media (prefers-reduced-motion: reduce) {
	.to-top,
	.to-top-label {
		transition: opacity 0.2s ease;
	}

	.to-top.is-visible .to-top-swing,
	.to-top.is-launching .to-top-swing {
		animation: none;
	}

	.to-top.is-launching {
		transform: none;
	}
}
