/*
 * Colour scheme (front end only, enqueued by functions.php). The dark token values are printed inline after this
 * file from settings.custom.dark: they re-point --wp--preset--color--*, --wp--custom--shadow--*, --hero--overlay and
 * --listing--* under both dark selectors and expose every token as --wp--custom--dark--<path>.
 *
 *   auto  (no data-color-scheme)  → follows prefers-color-scheme
 *   html[data-color-scheme=light] → light, whatever the OS says
 *   html[data-color-scheme=dark]  → dark, whatever the OS says
 */
@layer reapit.base, reapit.blocks, reapit.variation;

:root {
	color-scheme: light dark;
}
:root[data-color-scheme="light"] {
	color-scheme: light;
}
:root[data-color-scheme="dark"] {
	color-scheme: dark;
}

/*
 * Editor-applied primary surfaces (bands, the mobile menu overlay, the contrast form theme) lift instead of
 * brighten, and covers stay imagery under a dark overlay: inside them the primary pair is re-pointed to the dark
 * surface tokens, so their primary-contrast text, links and buttons keep their contrast. Badges and buttons
 * elsewhere read the tokens directly and are not affected.
 */
@media (prefers-color-scheme: dark) {
	:root:not([data-color-scheme="light"]) :is(.has-primary-background-color, .wp-block-cover, .reapit-gallery__overlay, .wp-block-reapit-form.is-theme-contrast) {
		--wp--preset--color--primary: var(--wp--custom--dark--surface--primary);
		--wp--preset--color--primary-contrast: var(--wp--custom--dark--surface--primary-contrast);
	}
	/* Light placeholder artwork and photos get a hairline so they do not float on the dark surface. */
	:root:not([data-color-scheme="light"]) :is(.reapit-card__media, .wp-block-post-featured-image img, .wp-block-image img, .wp-block-reapit-entity-image) {
		outline: 1px solid var(--wp--preset--color--border);
		outline-offset: -1px;
	}
}
:root[data-color-scheme="dark"] :is(.has-primary-background-color, .wp-block-cover, .reapit-gallery__overlay, .wp-block-reapit-form.is-theme-contrast) {
	--wp--preset--color--primary: var(--wp--custom--dark--surface--primary);
	--wp--preset--color--primary-contrast: var(--wp--custom--dark--surface--primary-contrast);
}
:root[data-color-scheme="dark"] :is(.reapit-card__media, .wp-block-post-featured-image img, .wp-block-image img, .wp-block-reapit-entity-image) {
	outline: 1px solid var(--wp--preset--color--border);
	outline-offset: -1px;
}

/* ---- toggle: any element with .reapit-color-scheme-toggle; aria-pressed="true" while dark is in effect ---- */
@layer reapit.base {
	.reapit-color-scheme-toggle {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: 0.5em;
		inline-size: 2.75rem;
		block-size: 2.75rem;
		padding: 0;
		border: 1px solid var(--wp--preset--color--border);
		border-radius: 50%;
		background: var(--wp--preset--color--base-2);
		color: var(--wp--preset--color--contrast);
		cursor: pointer;
		transition: background-color var(--wp--custom--transition), color var(--wp--custom--transition);
	}
	.reapit-color-scheme-toggle:hover {
		background: var(--wp--preset--color--base-3);
	}
	.reapit-color-scheme-toggle:focus-visible {
		outline: 2px solid var(--wp--preset--color--accent);
		outline-offset: 2px;
	}
	.reapit-color-scheme-toggle svg {
		inline-size: var(--wp--custom--icon--size, 1.25rem);
		block-size: var(--wp--custom--icon--size, 1.25rem);
		flex: none;
	}
	.reapit-color-scheme-toggle .reapit-color-scheme-toggle__sun,
	.reapit-color-scheme-toggle[aria-pressed="true"] .reapit-color-scheme-toggle__moon {
		display: none;
	}
	.reapit-color-scheme-toggle[aria-pressed="true"] .reapit-color-scheme-toggle__sun {
		display: block;
	}
	.reapit-color-scheme-toggle--floating {
		position: fixed;
		inset-inline-end: var(--wp--preset--spacing--20, 1rem);
		inset-block-end: var(--wp--preset--spacing--20, 1rem);
		z-index: 90;
		box-shadow: 0 2px 10px color-mix(in srgb, var(--wp--preset--color--contrast) 25%, transparent);
	}
	/* A header that places its own toggle (Stone) replaces the floating one, which would cover page controls. */
	body:has(header .reapit-color-scheme-toggle) .reapit-color-scheme-toggle--floating {
		display: none;
	}
	@media (prefers-reduced-motion: reduce) {
		.reapit-color-scheme-toggle {
			transition: none;
		}
	}
	@media print {
		.reapit-color-scheme-toggle--floating {
			display: none;
		}
	}
}
