/**
 * Theme switch button (inc/dark-mode.php, template-parts/components/theme-toggle.php).
 *
 * One compact button with two icons (sun / moon); which one shows comes from the `ahan-dark` class
 * on <html>, so the correct icon is painted before any script runs. Colours are tokens, so the
 * button follows the theme.
 */
.ahan-theme-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 1px solid var(--c-border);
	border-radius: var(--radius-sm);
	background: var(--c-surface);
	color: var(--c-text);
	cursor: pointer;
	transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.ahan-theme-toggle:hover,
.ahan-theme-toggle:focus-visible {
	border-color: var(--c-primary);
	color: var(--c-primary-ink);
}

.ahan-theme-toggle__icon {
	width: 18px;
	height: 18px;
	display: none;
}

html:not(.ahan-dark) .ahan-theme-toggle [data-icon="light"],
html.ahan-dark .ahan-theme-toggle [data-icon="dark"] {
	display: block;
}

@media (max-width: 767px) {
	.ahan-theme-toggle {
		width: 40px;
		height: 40px;
	}
}

/* The palette changes inside a view transition, and its "new" snapshot is taken right after the DOM
   update: with CSS transitions still running, elements would animate twice and the change looks like
   a jump (and the paint cost doubles). theme-toggle.js adds this class for the length of the switch.
   Backdrop blurs are among the costliest things to repaint, and the live layer repaints them every
   frame, so they are dropped for that moment too. */
html.ahan-theme-switching :where(*, *::before, *::after) {
	transition: none !important;
	-webkit-backdrop-filter: none !important;
	backdrop-filter: none !important;
}

/* Circular reveal of the theme change (View Transitions API; the circle's centre and radius are set by
   theme-toggle.js). Browsers without the API switch at once. */
@keyframes ahan-theme-reveal {
	from {
		clip-path: circle(0 at var(--ahan-theme-x, 50%) var(--ahan-theme-y, 50%));
	}

	to {
		clip-path: circle(var(--ahan-theme-r, 150vmax) at var(--ahan-theme-x, 50%) var(--ahan-theme-y, 50%));
	}
}

@media (prefers-reduced-motion: no-preference) {
	::view-transition-old(root),
	::view-transition-new(root) {
		animation: none;
		mix-blend-mode: normal;
	}

	::view-transition-new(root) {
		animation: ahan-theme-reveal 350ms cubic-bezier(0.4, 0, 0.2, 1) both;
	}
}
