const STORAGE_KEY = "montech_theme"; /** The initial class is applied by the inline boot script in `nuxt.config.ts` before first paint. */ export function useTheme() { const isDark = useState("theme-dark", () => false); function sync() { isDark.value = document.documentElement.classList.contains("dark"); } function toggle() { isDark.value = !isDark.value; document.documentElement.classList.toggle("dark", isDark.value); try { localStorage.setItem(STORAGE_KEY, isDark.value ? "dark" : "light"); } catch { /* storage unavailable (private mode) */ } } return { isDark, sync, toggle }; }