/*
 * Automatic dark mode.
 * Follows the visitor's device setting (prefers-color-scheme). Every block
 * colour in the theme comes from the palette variables, so swapping them
 * here re-colours the whole site.
 */

:root { color-scheme: light dark; }

@media (prefers-color-scheme: dark) {
	html:root {
		--wp--preset--color--base: #1A1917;
		--wp--preset--color--base-2: #24221F;
		--wp--preset--color--contrast: #F2EEE4;
		--wp--preset--color--contrast-2: #B5AFA3;
		--wp--preset--color--accent: #A9B97E;
		--wp--preset--color--accent-2: #C2D09A;
		--wp--preset--color--accent-soft: #2E3322;
		--wp--preset--color--border: #3A3732;
		--wp--preset--shadow--soft: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
	}

	/* Palette utility classes carry hard-coded values in WP core; re-point them. */
	.has-base-background-color { background-color: var(--wp--preset--color--base) !important; }
	.has-base-2-background-color { background-color: var(--wp--preset--color--base-2) !important; }
	.has-contrast-background-color { background-color: var(--wp--preset--color--contrast) !important; }
	.has-accent-background-color { background-color: var(--wp--preset--color--accent) !important; }
	.has-accent-soft-background-color { background-color: var(--wp--preset--color--accent-soft) !important; }
	.has-base-color { color: var(--wp--preset--color--base) !important; }
	.has-contrast-color { color: var(--wp--preset--color--contrast) !important; }
	.has-contrast-2-color { color: var(--wp--preset--color--contrast-2) !important; }
	.has-accent-color { color: var(--wp--preset--color--accent) !important; }

	/* ---- Legacy content guard ----
	   Old pages hard-code light backgrounds and black text inline.
	   Neutralise them so text stays readable on the dark page. */
	.wp-block-post-content [style*="background-color: #f"],
	.wp-block-post-content [style*="background-color:#f"],
	.wp-block-post-content [style*="background-color: #F"],
	.wp-block-post-content [style*="background-color:#F"],
	.wp-block-post-content [style*="background-color: rgb(2"],
	.wp-block-post-content [style*="background: #f"],
	.wp-block-post-content [style*="background:#f"],
	.wp-block-post-content [style*="background-color: white"] {
		background-color: transparent !important;
	}
	.wp-block-post-content [style*="color: #000"],
	.wp-block-post-content [style*="color:#000"],
	.wp-block-post-content [style*="color: #333"],
	.wp-block-post-content [style*="color:#333"],
	.wp-block-post-content [style*="color: rgb(0, 0, 0)"],
	.wp-block-post-content [style*="color: black"] {
		color: inherit !important;
	}
	.wp-block-post-content font[color] { color: inherit; }

	/* Transparent diagrams and flowcharts: give them a light backing
	   so black lines don't disappear. Opaque photos are unaffected. */
	.wp-block-post-content img:not(.ws-no-backing) {
		background-color: #FAF8F3;
	}

	/* Embedded documents / PDFs / third-party widgets keep their own light look */
	.wp-block-post-content iframe { background-color: #FAF8F3; border-radius: 6px; }

	/* Header glass effect on dark */
	.ws-header { background: color-mix(in srgb, var(--wp--preset--color--base) 85%, transparent); }
}

/* Light/dark image pairs (see style.css) */
@media (prefers-color-scheme: dark) {
	.ws-light-only { display: none !important; }
	.ws-dark-only { display: revert !important; }
	figure.ws-dark-only, .wp-block-image.ws-dark-only, .wp-block-cover.ws-dark-only { display: block !important; }
	.wp-block-post-content img.ws-dark-only, .ws-dark-only img { background-color: transparent; }
}

/* Hero artwork: charcoal version */
@media (prefers-color-scheme: dark) {
	.ws-hero { background-image: url(../images/hero-side-dark-800.jpg); }
}
@media (prefers-color-scheme: dark) and (min-width: 900px) {
	.ws-hero { background-image: url(../images/hero-side-dark.jpg); }
}
