/*
 * Dark mode. The theme's whole palette (body background/text, every card, border and accent) is already painted
 * through var(--wp--preset--color--*), so redefining those custom properties on html[data-theme="dark"] re-themes
 * the entire site in one place — no page stylesheet needs its own dark-mode rules.
 *
 * The exception is the handful of components that are deliberately dark in light mode too (the ink-background
 * hero/CTA/footer sections, code blocks, active-state chips, fallback cover art): their ink/ivory pairing must
 * stay the original, fixed values in both modes, so each is restored below, scoped to its own selector. Custom
 * properties inherit, so restoring tokens on an ancestor (e.g. .has-ink-background-color) is enough for every
 * descendant rule that also reads them.
 *
 * The toggle itself (assets/js/dark-mode-toggle.js) sets/clears data-theme="dark" on <html> and persists the
 * choice to localStorage; a blocking inline script in functions.php applies it before first paint.
 */

html[data-theme="dark"] {
	color-scheme: dark;
	--wp--preset--color--ivory: #17181c;
	--wp--preset--color--white: #1f2126;
	--wp--preset--color--ink: #f3efe4;
	--wp--preset--color--stone: #b7b9bd;
	--wp--preset--color--line: #34373d;
	--wp--preset--color--brass-dark: #c9a75c;
}

/* ---------------------------------------------------------------- Always-dark sections and components */

html[data-theme="dark"] :is(
	.has-ink-background-color,
	.home .ayh-header,
	.ayh-view-switch__btn[aria-pressed="true"],
	.ayh-post-card__image,
	.ayh-pager .page-numbers.current,
	.ayh-prose pre,
	.ayh-prose code,
	.ayh-work__list > .wp-block-post,
	.ayh-en-work__image,
	.ayh-service:hover,
	.ayh-service:focus-within,
	.ayh-products__image,
	.ayh-filters__list a[aria-current="page"],
	.ayh-card__image,
	.ayh-case__cover,
	.ayh-product__cover,
	.ayh-intake__status,
	.ayh-field .ayh-check:has(input:checked)
) {
	--wp--preset--color--ivory: #f6f2e9;
	--wp--preset--color--white: #ffffff;
	--wp--preset--color--ink: #16181d;
	--wp--preset--color--stone: #3b3d42;
	--wp--preset--color--line: #ddd6c6;
}

/* The hero's bottom "cut" bridges into the ordinary page surface below it, so — unlike the rest of the hero —
 * it must follow the page's ivory token, not the fixed one restored above. */

html[data-theme="dark"] :is(.ayh-page-hero, .ayh-hero)::after {
	--wp--preset--color--ivory: #17181c;
}

/* ---------------------------------------------------------------- Core block styles with hardcoded colors
 * The "stripes" table style (wp-includes/css: .is-style-stripes) paints its own odd-row background as a flat
 * #f0f0f0, outside our preset tokens entirely, so it stays pale (and its ink text unreadable) in dark mode. */

html[data-theme="dark"] .wp-block-table.is-style-stripes tbody tr:nth-child(odd) {
	background-color: var(--wp--preset--color--white);
}

/* The logo and the client marks are drawn for a light page; invert them for a dark one. */

html[data-theme="dark"] .ayh-logo__color {
	display: none !important;
}

html[data-theme="dark"] .ayh-logo__ink {
	display: block !important;
}

html[data-theme="dark"] .ayh-client__logo {
	filter: grayscale(1) contrast(1.2) invert(1);
}

/* The header's "شروع همکاری" button is ink-on-ivory by design (inner pages, light mode): with ink flipped to a
 * light text colour that would turn it into a stray pale pill, so it takes the brass treatment the home page's
 * own (always-dark) header already uses instead. */

html[data-theme="dark"] body:not(.home) .ayh-header {
	--ayh-cta-bg: var(--wp--preset--color--brass);
	--ayh-cta-fg: var(--wp--preset--color--ink);
	--ayh-cta-bg-hover: var(--wp--preset--color--brass-dark);
}
