import { a as colorVar, i as TOKEN_WEIGHTS, n as TOKEN_FONT_SIZES, r as TOKEN_RADII, t as TOKEN_COLORS } from "../tokens-DGlfOSoI.js";
//#region src/theme-engine/contrast-pairs.ts
const SURFACES = [
	"bg",
	"surface",
	"surface-raised"
];
const INTENTS = [
	"success",
	"warning",
	"danger",
	"info"
];
const INTENT_FG = {
	success: "success-fg",
	warning: "warning-fg",
	danger: "danger-fg",
	info: "info-fg"
};
function build() {
	const pairs = [];
	for (const fg of ["fg", "fg-muted"]) for (const bg of SURFACES) pairs.push({
		fg,
		bg,
		level: "text"
	});
	for (const bg of SURFACES) pairs.push({
		fg: "fg-subtle",
		bg,
		level: "ui"
	});
	pairs.push({
		fg: "accent-fg",
		bg: "accent",
		level: "text"
	});
	for (const intent of INTENTS) pairs.push({
		fg: INTENT_FG[intent],
		bg: intent,
		level: "text"
	});
	for (const fg of INTENTS) for (const bg of SURFACES) pairs.push({
		fg,
		bg,
		level: "text"
	});
	for (const bg of SURFACES) pairs.push({
		fg: "border-strong",
		bg,
		level: "ui"
	});
	for (const bg of SURFACES) pairs.push({
		fg: "accent",
		bg,
		level: "ui"
	});
	for (const fg of INTENTS) for (const bg of SURFACES) pairs.push({
		fg,
		bg,
		level: "ui"
	});
	return pairs;
}
/** Frozen declared fg/bg set the design system renders together. validateContrast iterates THIS. */
const CONTRAST_PAIRS = Object.freeze(build());
//#endregion
//#region src/theme-engine/errors.ts
var ThemeValidationError = class extends Error {
	field;
	detail;
	name = "ThemeValidationError";
	code = "THEME_VALIDATION";
	constructor(field, detail) {
		super(`theme validation: ${field} — ${detail}`);
		this.field = field;
		this.detail = detail;
	}
};
var ThemeColorFormatError = class extends Error {
	field;
	detail;
	name = "ThemeColorFormatError";
	code = "THEME_COLOR_FORMAT";
	constructor(field, detail) {
		super(`theme color format: ${field} — expected hex, got ${detail}`);
		this.field = field;
		this.detail = detail;
	}
};
var ThemeResolutionError = class extends Error {
	detail;
	name = "ThemeResolutionError";
	code = "THEME_RESOLUTION";
	constructor(detail) {
		super(`theme resolution: ${detail}`);
		this.detail = detail;
	}
};
var ThemeOverrideError = class extends Error {
	key;
	name = "ThemeOverrideError";
	code = "THEME_OVERRIDE";
	constructor(key) {
		super(`theme override: unknown token key — ${key}`);
		this.key = key;
	}
};
/** Structural guard — matches any THEME_-coded error object. NEVER use `instanceof` across packages. */
function isThemeError(e) {
	return typeof e === "object" && e !== null && "code" in e && typeof e.code === "string" && e.code.startsWith("THEME_");
}
//#endregion
//#region src/theme-engine/keys.ts
const COLOR_TOKEN_KEYS = TOKEN_COLORS;
const SHAPE_TOKEN_KEYS = [
	...TOKEN_RADII.map((r) => `radius-${r}`),
	...TOKEN_FONT_SIZES.map((s) => `font-size-${s}`),
	...TOKEN_WEIGHTS.map((w) => `font-weight-${w}`)
];
//#endregion
//#region src/theme-engine/color.ts
const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
/** Parse `#rgb` / `#rrggbb` (case-insensitive, trimmed) to [r,g,b] 0..255, or null. */
function parseHex(hex) {
	const m = HEX_RE.exec(hex.trim());
	if (!m) return null;
	const h = m[1];
	if (!h) return null;
	if (h.length === 3) return [
		parseInt(h[0] + h[0], 16),
		parseInt(h[1] + h[1], 16),
		parseInt(h[2] + h[2], 16)
	];
	return [
		parseInt(h.slice(0, 2), 16),
		parseInt(h.slice(2, 4), 16),
		parseInt(h.slice(4, 6), 16)
	];
}
/** WCAG-2.x relative luminance (sRGB). white -> 1, black -> 0. */
function relativeLuminance([r, g, b]) {
	const lin = (c) => {
		const s = c / 255;
		return s <= .03928 ? s / 12.92 : Math.pow((s + .055) / 1.055, 2.4);
	};
	return .2126 * lin(r) + .7152 * lin(g) + .0722 * lin(b);
}
/** WCAG-2.x contrast ratio. Order-independent (auto lighter/darker). Range 1..21. */
function contrastRatio(a, b) {
	const la = relativeLuminance(a);
	const lb = relativeLuminance(b);
	const lighter = Math.max(la, lb);
	const darker = Math.min(la, lb);
	return (lighter + .05) / (darker + .05);
}
//#endregion
//#region src/theme-engine/validate.ts
const KEBAB = /^[a-z0-9]+(-[a-z0-9]+)*$/;
const isObj = (v) => typeof v === "object" && v !== null;
const isStr = (v) => typeof v === "string";
const required = (level) => level === "text" ? 4.5 : 3;
function validatePaletteSet(pkg) {
	const errs = [];
	if (!isObj(pkg)) return {
		ok: false,
		error: [new ThemeValidationError("package", "must be an object")]
	};
	if (!isStr(pkg.id) || !KEBAB.test(pkg.id)) errs.push(new ThemeValidationError("id", "missing or not kebab-case"));
	if (!isStr(pkg.name)) errs.push(new ThemeValidationError("name", "missing"));
	const palettes = pkg.palettes;
	if (!Array.isArray(palettes) || palettes.length < 1) errs.push(new ThemeValidationError("palettes", "must be a non-empty array"));
	else {
		const ids = /* @__PURE__ */ new Set();
		palettes.forEach((p, i) => {
			if (!isObj(p)) {
				errs.push(new ThemeValidationError(`palettes[${i}]`, "must be an object"));
				return;
			}
			if (!isStr(p.id) || !KEBAB.test(p.id)) errs.push(new ThemeValidationError(`palettes[${i}].id`, "missing or not kebab-case"));
			else {
				if (ids.has(p.id)) errs.push(new ThemeValidationError(`palettes[${i}].id`, `duplicate: ${p.id}`));
				ids.add(p.id);
			}
			if (!isStr(p.name)) errs.push(new ThemeValidationError(`palettes[${i}].name`, "missing"));
			const colors = p.colors;
			if (!isObj(colors) || !isObj(colors.light) || !isObj(colors.dark)) errs.push(new ThemeValidationError(`palettes[${i}].colors`, "must have light + dark token maps"));
			else for (const mode of ["light", "dark"]) {
				const map = colors[mode];
				for (const key of COLOR_TOKEN_KEYS) {
					const val = map[key];
					if (!isStr(val)) errs.push(new ThemeValidationError(`palettes[${i}].colors.${mode}.${key}`, "missing"));
					else if (!parseHex(val)) errs.push(new ThemeColorFormatError(`palettes[${i}].colors.${mode}.${key}`, val));
				}
			}
		});
		if (isStr(pkg.defaultPaletteId) && !ids.has(pkg.defaultPaletteId)) errs.push(new ThemeValidationError("defaultPaletteId", `does not resolve: ${pkg.defaultPaletteId}`));
	}
	if (!isStr(pkg.defaultPaletteId)) errs.push(new ThemeValidationError("defaultPaletteId", "missing"));
	const shape = pkg.shape;
	if (!isObj(shape) || !isObj(shape.light) || !isObj(shape.dark)) errs.push(new ThemeValidationError("shape", "must have light + dark token maps"));
	else for (const mode of ["light", "dark"]) {
		const map = shape[mode];
		for (const key of SHAPE_TOKEN_KEYS) if (!isStr(map[key])) errs.push(new ThemeValidationError(`shape.${mode}.${key}`, "missing"));
	}
	return errs.length ? {
		ok: false,
		error: errs
	} : {
		ok: true,
		value: pkg
	};
}
/**
* SINGLE-MODE Hard-floor checker — the shared impl + the override-persist seam.
* Accepts any ColorTokens (an EffectiveTokens override result is a superset; extra shape keys ignored).
*/
function validateContrastTokens(colors, pairs = CONTRAST_PAIRS) {
	const failures = [];
	for (const pair of pairs) {
		const need = required(pair.level);
		const fgRgb = parseHex(colors[pair.fg] ?? "");
		const bgRgb = parseHex(colors[pair.bg] ?? "");
		const ratio = fgRgb && bgRgb ? contrastRatio(fgRgb, bgRgb) : 0;
		if (ratio < need) failures.push({
			fg: pair.fg,
			bg: pair.bg,
			ratio,
			required: need
		});
	}
	return {
		pass: failures.length === 0,
		failures
	};
}
function validateContrast(pkg, pairs = CONTRAST_PAIRS) {
	const failures = [];
	for (const palette of pkg.palettes) for (const mode of ["light", "dark"]) {
		const map = palette.colors[mode];
		for (const f of validateContrastTokens(map, pairs).failures) failures.push({
			...f,
			paletteId: palette.id,
			mode
		});
	}
	return {
		pass: failures.length === 0,
		failures
	};
}
//#endregion
//#region src/theme-engine/ramps.ts
const DEFAULT_RAMPS = {
	neutral: {
		light: {
			steps: [
				"#fcfcfd",
				"#f9f9fb",
				"#f0f0f3",
				"#e8e8ec",
				"#e0e1e6",
				"#d9d9e0",
				"#cdced6",
				"#b9bbc6",
				"#8b8d98",
				"#80838d",
				"#60646c",
				"#1c2024"
			],
			alpha: [
				"rgba(0, 0, 85, 0.012)",
				"rgba(0, 0, 85, 0.024)",
				"rgba(0, 0, 51, 0.059)",
				"rgba(0, 0, 45, 0.09)",
				"rgba(0, 9, 50, 0.122)",
				"rgba(0, 0, 47, 0.149)",
				"rgba(0, 6, 46, 0.196)",
				"rgba(0, 8, 48, 0.275)",
				"rgba(0, 5, 29, 0.455)",
				"rgba(0, 7, 27, 0.498)",
				"rgba(0, 7, 20, 0.624)",
				"rgba(0, 5, 9, 0.89)"
			],
			contrast: "#000000"
		},
		dark: {
			steps: [
				"#111113",
				"#18191b",
				"#212225",
				"#272a2d",
				"#2e3135",
				"#363a3f",
				"#43484e",
				"#5a6169",
				"#696e77",
				"#777b84",
				"#afb3ba",
				"#edeef0"
			],
			alpha: [
				"rgba(0, 0, 0, 0)",
				"rgba(216, 244, 246, 0.035)",
				"rgba(221, 234, 248, 0.078)",
				"rgba(211, 237, 248, 0.114)",
				"rgba(217, 237, 254, 0.145)",
				"rgba(214, 235, 253, 0.188)",
				"rgba(217, 237, 255, 0.251)",
				"rgba(217, 237, 255, 0.365)",
				"rgba(223, 235, 253, 0.427)",
				"rgba(229, 237, 253, 0.482)",
				"rgba(240, 245, 254, 0.71)",
				"rgba(252, 253, 255, 0.937)"
			],
			contrast: "#ffffff"
		}
	},
	accent: {
		light: {
			steps: [
				"#fdfdfe",
				"#f7f9ff",
				"#edf2ff",
				"#e1e9ff",
				"#d2deff",
				"#c1d0ff",
				"#abbdf9",
				"#8da4ef",
				"#3e63dd",
				"#3358d4",
				"#3a5bc7",
				"#1f2d5c"
			],
			alpha: [
				"rgba(0, 0, 128, 0.008)",
				"rgba(0, 64, 255, 0.031)",
				"rgba(0, 71, 255, 0.071)",
				"rgba(0, 68, 255, 0.118)",
				"rgba(0, 68, 255, 0.176)",
				"rgba(0, 62, 255, 0.243)",
				"rgba(0, 55, 237, 0.329)",
				"rgba(0, 52, 220, 0.447)",
				"rgba(0, 49, 210, 0.757)",
				"rgba(0, 46, 201, 0.8)",
				"rgba(0, 43, 183, 0.773)",
				"rgba(0, 16, 70, 0.878)"
			],
			contrast: "#ffffff"
		},
		dark: {
			steps: [
				"#11131f",
				"#141726",
				"#15224c",
				"#142d69",
				"#1b367b",
				"#274089",
				"#344c9c",
				"#3e5cbb",
				"#3e63dd",
				"#5472e4",
				"#9eb1ff",
				"#d6e1ff"
			],
			alpha: [
				"rgba(17, 51, 255, 0.059)",
				"rgba(51, 84, 250, 0.09)",
				"rgba(33, 85, 253, 0.251)",
				"rgba(25, 92, 253, 0.373)",
				"rgba(40, 100, 255, 0.447)",
				"rgba(61, 110, 255, 0.506)",
				"rgba(77, 118, 255, 0.584)",
				"rgba(80, 121, 254, 0.718)",
				"rgba(70, 113, 255, 0.859)",
				"rgba(92, 126, 254, 0.89)",
				"rgba(158, 177, 255, 1)",
				"rgba(214, 225, 255, 1)"
			],
			contrast: "#ffffff"
		}
	},
	success: {
		light: {
			steps: [
				"#fbfefc",
				"#f2fcf5",
				"#e3f8e9",
				"#d3f2dd",
				"#c2eacf",
				"#abdebf",
				"#8dcea9",
				"#5bb98b",
				"#30a46c",
				"#2b9a66",
				"#218358",
				"#193b2d"
			],
			alpha: [
				"rgba(0, 192, 64, 0.016)",
				"rgba(0, 197, 59, 0.051)",
				"rgba(0, 192, 55, 0.11)",
				"rgba(0, 180, 58, 0.173)",
				"rgba(0, 168, 55, 0.239)",
				"rgba(0, 155, 61, 0.329)",
				"rgba(0, 146, 63, 0.447)",
				"rgba(0, 146, 75, 0.643)",
				"rgba(0, 143, 74, 0.812)",
				"rgba(0, 134, 71, 0.831)",
				"rgba(0, 113, 63, 0.871)",
				"rgba(0, 38, 22, 0.902)"
			],
			contrast: "#000000"
		},
		dark: {
			steps: [
				"#0e1512",
				"#131b17",
				"#112c20",
				"#123b29",
				"#184933",
				"#20573e",
				"#28684a",
				"#2f7c57",
				"#30a46c",
				"#35b979",
				"#3dd68c",
				"#b1f1cb"
			],
			alpha: [
				"rgba(0, 222, 69, 0.02)",
				"rgba(64, 249, 157, 0.043)",
				"rgba(18, 255, 149, 0.114)",
				"rgba(23, 255, 153, 0.176)",
				"rgba(47, 255, 162, 0.235)",
				"rgba(68, 255, 170, 0.294)",
				"rgba(80, 253, 172, 0.369)",
				"rgba(84, 255, 173, 0.451)",
				"rgba(68, 255, 164, 0.62)",
				"rgba(68, 255, 165, 0.706)",
				"rgba(70, 254, 165, 0.831)",
				"rgba(187, 255, 215, 0.941)"
			],
			contrast: "#000000"
		}
	},
	warning: {
		light: {
			steps: [
				"#fefdfb",
				"#fff9e8",
				"#fff2b5",
				"#ffeb94",
				"#ffe176",
				"#fad373",
				"#edbf63",
				"#e2a336",
				"#ffc53d",
				"#ffba18",
				"#ab6400",
				"#4f3422"
			],
			alpha: [
				"rgba(192, 128, 0, 0.016)",
				"rgba(255, 189, 0, 0.09)",
				"rgba(255, 211, 1, 0.29)",
				"rgba(255, 208, 1, 0.42)",
				"rgba(255, 200, 0, 0.537)",
				"rgba(246, 175, 0, 0.549)",
				"rgba(226, 151, 0, 0.612)",
				"rgba(218, 138, 0, 0.788)",
				"rgba(255, 179, 0, 0.761)",
				"rgba(255, 179, 0, 0.906)",
				"rgba(171, 100, 0, 1)",
				"rgba(52, 21, 0, 0.867)"
			],
			contrast: "#000000"
		},
		dark: {
			steps: [
				"#16120c",
				"#1c1812",
				"#2d1e07",
				"#3e2700",
				"#4c3000",
				"#5b3d06",
				"#704f1a",
				"#8f6424",
				"#ffc53d",
				"#ffd505",
				"#ffca16",
				"#ffe7b3"
			],
			alpha: [
				"rgba(230, 60, 0, 0.024)",
				"rgba(251, 166, 39, 0.047)",
				"rgba(255, 128, 0, 0.118)",
				"rgba(252, 132, 0, 0.192)",
				"rgba(253, 141, 0, 0.251)",
				"rgba(253, 157, 0, 0.314)",
				"rgba(255, 172, 40, 0.4)",
				"rgba(255, 174, 53, 0.529)",
				"rgba(255, 197, 61, 1)",
				"rgba(255, 213, 5, 1)",
				"rgba(255, 202, 22, 1)",
				"rgba(255, 231, 179, 1)"
			],
			contrast: "#000000"
		}
	},
	danger: {
		light: {
			steps: [
				"#fffcfc",
				"#fff7f7",
				"#ffe9ea",
				"#ffdbdc",
				"#ffcdce",
				"#fdbdbe",
				"#f4a9aa",
				"#eb8e90",
				"#e5484d",
				"#dc3e42",
				"#ce2c31",
				"#641723"
			],
			alpha: [
				"rgba(255, 0, 0, 0.012)",
				"rgba(255, 0, 0, 0.031)",
				"rgba(255, 0, 12, 0.086)",
				"rgba(255, 0, 8, 0.141)",
				"rgba(255, 0, 6, 0.196)",
				"rgba(248, 0, 4, 0.259)",
				"rgba(223, 0, 3, 0.337)",
				"rgba(210, 0, 5, 0.443)",
				"rgba(219, 0, 7, 0.718)",
				"rgba(209, 0, 5, 0.757)",
				"rgba(196, 0, 6, 0.827)",
				"rgba(85, 0, 13, 0.91)"
			],
			contrast: "#000000"
		},
		dark: {
			steps: [
				"#191111",
				"#201314",
				"#3c1017",
				"#500f1c",
				"#601623",
				"#72232d",
				"#8b3339",
				"#b54548",
				"#e5484d",
				"#ec5d5e",
				"#ff9592",
				"#ffd1d9"
			],
			alpha: [
				"rgba(244, 18, 18, 0.035)",
				"rgba(242, 47, 62, 0.067)",
				"rgba(251, 12, 50, 0.184)",
				"rgba(254, 10, 59, 0.267)",
				"rgba(255, 32, 71, 0.333)",
				"rgba(255, 62, 86, 0.408)",
				"rgba(255, 84, 95, 0.514)",
				"rgba(255, 93, 97, 0.69)",
				"rgba(254, 78, 84, 0.894)",
				"rgba(255, 100, 101, 0.922)",
				"rgba(255, 149, 146, 1)",
				"rgba(255, 209, 217, 1)"
			],
			contrast: "#000000"
		}
	},
	info: {
		light: {
			steps: [
				"#fbfdff",
				"#f4faff",
				"#e5f5ff",
				"#d5efff",
				"#c2e5ff",
				"#acd8fc",
				"#8ec8f6",
				"#5eb1ef",
				"#0090ff",
				"#0588f0",
				"#0d74ce",
				"#113264"
			],
			alpha: [
				"rgba(0, 128, 255, 0.016)",
				"rgba(0, 140, 255, 0.043)",
				"rgba(0, 157, 255, 0.102)",
				"rgba(0, 158, 255, 0.165)",
				"rgba(0, 147, 255, 0.239)",
				"rgba(0, 136, 246, 0.325)",
				"rgba(0, 131, 235, 0.443)",
				"rgba(0, 132, 230, 0.631)",
				"rgba(0, 144, 255, 1)",
				"rgba(0, 134, 240, 0.98)",
				"rgba(0, 109, 203, 0.949)",
				"rgba(0, 35, 89, 0.933)"
			],
			contrast: "#000000"
		},
		dark: {
			steps: [
				"#0d1520",
				"#111a27",
				"#0c2745",
				"#003465",
				"#004078",
				"#064d8b",
				"#1a5da3",
				"#2270c3",
				"#0090ff",
				"#3b9eff",
				"#70b8ff",
				"#c2e6ff"
			],
			alpha: [
				"rgba(0, 77, 242, 0.067)",
				"rgba(17, 113, 251, 0.094)",
				"rgba(0, 118, 254, 0.22)",
				"rgba(0, 117, 255, 0.353)",
				"rgba(0, 125, 253, 0.435)",
				"rgba(0, 134, 255, 0.514)",
				"rgba(31, 140, 254, 0.616)",
				"rgba(40, 144, 255, 0.749)",
				"rgba(0, 144, 255, 1)",
				"rgba(59, 158, 255, 1)",
				"rgba(112, 184, 255, 1)",
				"rgba(194, 230, 255, 1)"
			],
			contrast: "#000000"
		}
	}
};
function colorsFor(mode) {
	const intentStep = mode === "light" ? 11 : 10;
	const intentContrast = mode === "light" ? "#ffffff" : null;
	return {
		fg: DEFAULT_RAMPS.neutral[mode].steps[11],
		"fg-muted": DEFAULT_RAMPS.neutral[mode].steps[10],
		"fg-subtle": DEFAULT_RAMPS.neutral[mode].steps[9],
		bg: DEFAULT_RAMPS.neutral[mode].steps[0],
		surface: DEFAULT_RAMPS.neutral[mode].steps[1],
		"surface-raised": DEFAULT_RAMPS.neutral[mode].steps[2],
		border: DEFAULT_RAMPS.neutral[mode].steps[5],
		"border-strong": DEFAULT_RAMPS.neutral[mode].steps[9],
		accent: DEFAULT_RAMPS.accent[mode].steps[8],
		"accent-fg": DEFAULT_RAMPS.accent[mode].contrast,
		success: DEFAULT_RAMPS.success[mode].steps[intentStep],
		warning: DEFAULT_RAMPS.warning[mode].steps[intentStep],
		danger: DEFAULT_RAMPS.danger[mode].steps[intentStep],
		info: DEFAULT_RAMPS.info[mode].steps[intentStep],
		"success-fg": intentContrast ?? DEFAULT_RAMPS.success[mode].contrast,
		"warning-fg": intentContrast ?? DEFAULT_RAMPS.warning[mode].contrast,
		"danger-fg": intentContrast ?? DEFAULT_RAMPS.danger[mode].contrast,
		"info-fg": intentContrast ?? DEFAULT_RAMPS.info[mode].contrast
	};
}
colorsFor("light"), colorsFor("dark");
function resolveMode(pref, systemPrefersDark) {
	if (pref === "system") return systemPrefersDark ? "dark" : "light";
	return pref;
}
/** Returns a NEW EffectiveTokens; throws ThemeOverrideError (typed) on an unknown override key. */
function mergeOverrides(base, overrides) {
	if (!overrides) return { ...base };
	for (const key of Object.keys(overrides)) if (!(key in base)) throw new ThemeOverrideError(key);
	return {
		...base,
		...overrides
	};
}
function resolveActiveTheme(args) {
	const { themes, selection, systemPrefersDark } = args;
	const theme = themes.find((t) => t.id === selection.themeId);
	if (!theme) return {
		ok: false,
		error: new ThemeResolutionError(`unknown theme: ${selection.themeId}`)
	};
	const palette = theme.palettes.find((p) => p.id === selection.paletteId);
	if (!palette) return {
		ok: false,
		error: new ThemeResolutionError(`unknown palette: ${selection.paletteId}`)
	};
	const mode = resolveMode(selection.mode, systemPrefersDark);
	const base = {
		...palette.colors[mode],
		...theme.shape[mode]
	};
	try {
		return {
			ok: true,
			value: mergeOverrides(base, selection.overrides)
		};
	} catch (e) {
		if (e instanceof ThemeOverrideError) return {
			ok: false,
			error: e
		};
		if (isThemeError(e)) return {
			ok: false,
			error: e
		};
		throw e;
	}
}
//#endregion
//#region src/theme-engine/css-var.ts
const COLOR_SET = new Set(COLOR_TOKEN_KEYS);
/**
* Map an EffectiveTokens key to its ui-tokens custom-property name.
* color key  -> colorVar(key) = `--mod-color-<key>`
* shape key  -> `--mod-<key>` (already carries radius-/font-size-/font-weight-)
*/
function cssVarFor(key) {
	return COLOR_SET.has(key) ? colorVar(key) : `--mod-${key}`;
}
//#endregion
//#region src/theme-engine/css.ts
const RAMP_KEYS = [
	"neutral",
	"accent",
	"success",
	"warning",
	"danger",
	"info"
];
function decls(colors, shape, mode) {
	const lines = [];
	for (const [k, v] of Object.entries(colors)) lines.push(`  ${cssVarFor(k)}: ${v};`);
	for (const [k, v] of Object.entries(shape)) lines.push(`  ${cssVarFor(k)}: ${v};`);
	for (const rampName of RAMP_KEYS) {
		const ramp = DEFAULT_RAMPS[rampName][mode];
		ramp.steps.forEach((step, index) => lines.push(`  --mod-${rampName}-${index + 1}: ${step};`));
		ramp.alpha.forEach((alpha, index) => lines.push(`  --mod-${rampName}-a${index + 1}: ${alpha};`));
		lines.push(`  --mod-${rampName}-contrast: ${ramp.contrast};`);
	}
	lines.push(`  color-scheme: ${mode};`);
	return lines.join("\n");
}
/** Build-time static CSS for SSR/no-JS first paint. Palette-scoped; group 3 resolves system-mode with no flash. */
function themeToCss(pkg) {
	const blocks = [];
	for (const palette of pkg.palettes) {
		const base = `[data-theme="${pkg.id}"][data-palette="${palette.id}"]`;
		const light = decls(palette.colors.light, pkg.shape.light, "light");
		const dark = decls(palette.colors.dark, pkg.shape.dark, "dark");
		blocks.push(`${base}[data-mode="light"] {\n${light}\n}`);
		blocks.push(`${base}[data-mode="dark"] {\n${dark}\n}`);
		blocks.push(`${base}:not([data-mode]) {\n${light}\n}`);
		blocks.push(`@media (prefers-color-scheme: dark) {\n  ${base}:not([data-mode]) {\n${dark}\n  }\n}`);
	}
	return blocks.join("\n\n");
}
//#endregion
//#region src/theme-engine/apply.ts
/** Apply resolved tokens to an element as inline custom properties + data attributes. Idempotent. */
function applyTheme(el, tokens, themeId, mode) {
	el.dataset.theme = themeId;
	el.dataset.mode = mode;
	el.style.colorScheme = mode;
	for (const [key, value] of Object.entries(tokens)) el.style.setProperty(cssVarFor(key), value);
}
/**
* THE single owner of the `(prefers-color-scheme: dark)` media-query listener.
* Returns an unsubscribe fn. No-ops + returns a noop unsubscribe under SSR (no matchMedia).
*/
function subscribeToSystemMode(cb) {
	if (typeof globalThis.matchMedia !== "function") return () => {};
	const mql = globalThis.matchMedia("(prefers-color-scheme: dark)");
	const handler = (e) => cb(e.matches);
	mql.addEventListener("change", handler);
	return () => mql.removeEventListener("change", handler);
}
//#endregion
export { CONTRAST_PAIRS, ThemeColorFormatError, ThemeOverrideError, ThemeResolutionError, ThemeValidationError, applyTheme, contrastRatio, isThemeError, mergeOverrides, parseHex, relativeLuminance, resolveActiveTheme, resolveMode, subscribeToSystemMode, themeToCss, validateContrast, validateContrastTokens, validatePaletteSet };
