(() => {
	try {
		const stored = window.localStorage.getItem("claw.theme");
		const mode =
			stored === "light" || stored === "dark" || stored === "system"
				? stored
				: "system";
		const prefersDark = window.matchMedia(
			"(prefers-color-scheme: dark)",
		).matches;
		const shouldUseDark = mode === "dark" || (mode === "system" && prefersDark);
		document.documentElement.classList.toggle("dark", shouldUseDark);
	} catch (_) {}
})();
