/* Pre-paint theme boot (issue #180). Must stay a plain classic script in a * separate file: the prod CSP (nginx.conf, script-src 'self') forbids inline * scripts, and executing during parsing — before the deferred module * bundle — is what prevents a white flash for dark users. Reads the same * JSON-encoded localStorage keys as src/theme/theme.ts; keep them in sync. */ (function () { var theme = 'light'; try { var raw = window.localStorage.getItem('ui.theme.mode'); var mode = raw === null ? 'system' : JSON.parse(raw); var dark = mode === 'dark' || (mode !== 'light' && window.matchMedia('(prefers-color-scheme: dark)').matches); if (dark) theme = 'dark'; } catch { /* Broken storage/JSON: default to light. */ } document.documentElement.dataset.theme = theme; document.documentElement.style.colorScheme = theme; try { /* Hook for the accent-theming stage (ADR 0018): a pre-derived stylesheet * cached under ui.theme.css is injected before first paint so custom * accents do not flash either. Unset until that stage ships. */ var css = window.localStorage.getItem('ui.theme.css'); if (css) { var style = document.createElement('style'); style.id = 'user-theme'; style.textContent = JSON.parse(css); document.head.appendChild(style); } } catch { /* Optional enhancement only. */ } })();