/* Theme toggle: Lucide's sun morphing into Lucide's moon. Going dark, the
   rays burst outward and fade one after another, then the core swells on a
   spring into the moon's disc, then a bite circle slides in from the upper
   right. The bite is masked out of the disc and its own stroke, clipped to
   the disc, draws the crescent's inner edge. Going light, the bite leaves,
   the disc shrinks, and the rays fly back in and spring into place. Each
   step clears out before the next arrives, because the rays sit on the
   circle the moon's outline fills. The whole icon tilts as the moon
   arrives. The page changes behind a circle growing from the button
   (theme.js). */
.theme-toggle {
	margin: -8px -8px -8px 0;
}

.theme-icon {
	overflow: visible;
	transition: rotate 700ms cubic-bezier(0.38, 1.21, 0.22, 1);
}

.theme-disc {
	cx: 12px;
	cy: 12px;
	r: 4px;
	transition: r 600ms cubic-bezier(0.38, 1.21, 0.22, 1) 120ms;
}

/* Parked well clear of the sun, the bite takes nothing out of it. Going
   light it leaves first and fast, before the disc starts to shrink, so no
   fragments of its edge are left inside a shrinking disc. */
.theme-bite {
	cx: 30px;
	cy: -6px;
	r: 6px;
	transition: cx 260ms cubic-bezier(0.2, 0, 0, 1), cy 260ms cubic-bezier(0.2, 0, 0, 1);
}

.theme-rays path {
	transform-origin: 12px 12px;
	transition:
		rotate 520ms cubic-bezier(0.42, 1.67, 0.21, 0.9) calc(220ms + var(--i) * 28ms),
		scale 520ms cubic-bezier(0.42, 1.67, 0.21, 0.9) calc(220ms + var(--i) * 28ms),
		opacity 160ms ease calc(220ms + var(--i) * 28ms);
}

html[data-theme="dark"] .theme-icon {
	rotate: -20deg;
}

html[data-theme="dark"] .theme-disc {
	r: 9px;
	transition: r 600ms cubic-bezier(0.38, 1.21, 0.22, 1) 150ms;
}

html[data-theme="dark"] .theme-bite {
	cx: 17px;
	cy: 7px;
	transition: cx 600ms cubic-bezier(0.38, 1.21, 0.22, 1) 300ms, cy 600ms cubic-bezier(0.38, 1.21, 0.22, 1) 300ms;
}

html[data-theme="dark"] .theme-rays path {
	rotate: 45deg;
	scale: 1.4;
	opacity: 0;
	transition:
		rotate 260ms cubic-bezier(0.2, 0, 0, 1) calc(var(--i) * 12ms),
		scale 260ms cubic-bezier(0.2, 0, 0, 1) calc(var(--i) * 12ms),
		opacity 150ms ease calc(var(--i) * 12ms);
}

/* The new theme is revealed through a circle growing from the toggle.
   theme.js sets the circle's centre and final radius just before the
   switch. The keyframes fill backwards, so the very first frame is already
   clipped and the new theme never flashes full screen. The old snapshot
   stays still underneath. html.theme-switching marks the transition as
   the theme's, so other view transitions keep their own animations. */
html.theme-switching::view-transition-old(root) {
	animation: none;
}

html.theme-switching::view-transition-new(root) {
	animation: themeReveal 700ms cubic-bezier(0.2, 0, 0, 1) both;
	mix-blend-mode: normal;
}

@keyframes themeReveal {
	from {
		clip-path: circle(0px at var(--reveal-x) var(--reveal-y));
	}

	to {
		clip-path: circle(var(--reveal-radius) at var(--reveal-x) var(--reveal-y));
	}
}

/* The custom cursor is not given a layer of its own: Gecko sizes such a
   layer once, as the switch starts, so a cursor changing shape during the
   reveal (leaving a menu item, say) was stretched into its old box. It is
   drawn live in the new theme instead, inside the circle, which starts
   where the cursor is. */

@media (prefers-reduced-motion: reduce) {
	.theme-icon,
	.theme-icon * {
		transition: none !important;
	}
}

/* The first frame shows the icon for the theme already applied. */
html.booting .theme-icon,
html.booting .theme-icon * {
	transition: none !important;
}
