/**
 * Teb Open — Display & motion preference contract (IDEA-022-A, v2.0.09).
 *
 * The pre-paint boot snippet (inc/enqueue.php, wp_head priority 1) reads
 * the persisted user preferences (localStorage `to-prefs`, whitelist
 * validated by theme.js `window.toPrefs`) and applies up to four classes
 * on <html> BEFORE first paint, so switching a preference never flashes:
 *
 *   html.to-motion-off  → all non-essential animation/transition off
 *                         (the explicit, always-on twin of the
 *                         prefers-reduced-motion kill-switch)
 *   html.to-no-glass    → glassmorphism off: every backdrop-filter is
 *                         removed and Surface Floating falls back to its
 *                         opaque matte surface — the full interface stays
 *                         complete and professional without transparency
 *   html.to-contrast    → high-contrast token remap (text, borders,
 *                         scrims, focus ring) — independent from glass
 *   html.to-fs-1..3     → text size steps (+6.25% / +12.5% / +18.75%)
 *
 * The classes are also the machine contract every component relies on:
 * components never implement their own transparency/contrast logic; they
 * consume the semantic tokens this file re-maps.
 *
 * Operating-system settings are honored in parallel (media queries at the
 * bottom): prefers-reduced-motion is already enforced site-wide in
 * base.css; prefers-reduced-transparency mirrors to-no-glass;
 * prefers-contrast mirrors to-contrast; forced-colors gets a minimal
 * CanvasText guard so controls never lose their borders.
 *
 * All values are re-mappings of existing tokens (AGENTS.md: no raw colors
 * outside tokens.css).
 */

/* ---------- Motion off (explicit user choice) ---------- */
html.to-motion-off {
	scroll-behavior: auto;
}

html.to-motion-off *,
html.to-motion-off *::before,
html.to-motion-off *::after {
	animation-duration: 0.01ms !important;
	animation-iteration-count: 1 !important;
	transition-duration: 0.01ms !important;
}

/* ---------- Glass off (transparency reduced) ----------
 * One universal kill for every blur carrier (present and future), then
 * the matte fallback for the shipped Surface Floating consumer (mobile
 * bottom navigation, light + dark). The fallback is an opaque token
 * surface, so the bar remains complete without transparency. */
html.to-no-glass *,
html.to-no-glass *::before,
html.to-no-glass *::after {
	backdrop-filter: none !important;
	-webkit-backdrop-filter: none !important;
}

html.to-no-glass .to-bottomnav {
	background: var(--to-surface);
}

html.to-no-glass .to-bottomnav.to-bottomnav--dark-fallback {
	/* No-op marker: dark styling already derives from [data-theme='dark']
	 * tokens — kept so future glass consumers have a documented pattern. */
	background: var(--to-surface);
}

/* ---------- High contrast (independent capability) ----------
 * Token re-mapping only — every component following the semantic tokens
 * strengthens automatically. Text steps up one notch each; borders take
 * the text ink; scrims darken for panel separation; the focus ring goes
 * full-strength brand. No layout, spacing or geometry changes. */
html.to-contrast {
	--to-text-2: var(--to-text);
	--to-text-3: var(--to-text-2);
	/* border-2 must not reference itself (circular); anchor the stronger
	 * border on the text ink + brand strong, then derive border from it. */
	--to-border-2: color-mix(in srgb, var(--to-text) 34%, var(--to-primary-strong));
	--to-border: color-mix(in srgb, var(--to-text) 22%, var(--to-border-2));
	--to-overlay: color-mix(in srgb, var(--to-on-bright) 68%, transparent);
	--to-overlay-strong: color-mix(in srgb, var(--to-on-bright) 76%, transparent);
	--to-ring: 0 0 0 3px var(--to-primary-strong);
}

html.to-contrast :focus-visible {
	outline-width: 3px;
}

/* ---------- Text size (three steps) ---------- */
html.to-fs-1 {
	font-size: 106.25%;
}

html.to-fs-2 {
	font-size: 112.5%;
}

html.to-fs-3 {
	font-size: 118.75%;
}

/* ---------- Operating-system mirrors ---------- */

/* Reduced transparency (Chromium 118+): same outcome as the manual
 * glass switch — the OS asks, the surface falls back to matte. */
@media (prefers-reduced-transparency: reduce) {
	.to-bottomnav {
		backdrop-filter: none;
		-webkit-backdrop-filter: none;
		background: var(--to-surface);
	}
}

/* More contrast requested at OS level: identical remap to the manual
 * switch (media query cannot inherit the html class). */
@media (prefers-contrast: more) {
	:root {
		--to-text-2: var(--to-text);
		--to-text-3: var(--to-text-2);
		--to-border-2: color-mix(in srgb, var(--to-text) 34%, var(--to-primary-strong));
		--to-border: color-mix(in srgb, var(--to-text) 22%, var(--to-border-2));
		--to-overlay: color-mix(in srgb, var(--to-on-bright) 68%, transparent);
		--to-overlay-strong: color-mix(in srgb, var(--to-on-bright) 76%, transparent);
		--to-ring: 0 0 0 3px var(--to-primary-strong);
	}
}

/* Forced colors (Windows High Contrast): keep structure recognizable —
 * the browser already remaps colors; we only guarantee borders/fills
 * for the surfaces that otherwise paint none. */
@media (forced-colors: active) {
	.to-product-card,
	.to-btn,
	.to-chip,
	.to-bottomnav,
	.to-mega,
	.to-minicart--pop,
	.to-wishpop,
	.to-drawer__panel,
	.to-filterdrawer__panel,
	.to-search__panel,
	.to-lightbox,
	.to-toasts .to-toast,
	input,
	select,
	textarea {
		border: 1px solid CanvasText;
	}

	.to-badge {
		border: 1px solid CanvasText;
	}

	.to-product-card__media,
	.to-header__wave,
	.to-hero__blob,
	.to-hero__bg {
		display: none;
	}
}
