# Business Logic Model — theme-foundation (U1) ## Startup 1. `/theme-init.js` (blocking, same origin) reads the stored mode (guarded), falls back to `prefers-color-scheme`, and sets `data-variant="b"` and `data-mode` on ``. 2. `ThemeProvider` initializes its state with the same function (`resolveInitialMode`) so React and the script always agree; it removes the legacy key `slp-software-theme`. 3. `ThemeProvider` subscribes to the `prefers-color-scheme` media query; while `modeSource = 'system'` the mode follows it. ## Mode toggle `toggleMode()`: `mode = (mode === 'light') ? 'dark' : 'light'`, `modeSource = 'user'`, persist (guarded), update ``. ## Variant switch (sequence) ```mermaid sequenceDiagram box rgba(99,179,237,0.4) Browser UI participant U as Visitor participant VT as VariantToggle participant TP as ThemeProvider participant TO as TransitionOverlay end box rgba(154,230,180,0.4) App participant VR as VariantRenderer end U->>VT: click VT->>TP: toggleVariant TP->>TO: start cover TO-->>TP: cover done TP->>VR: set variant, load E chunk if needed VR-->>TP: ready or failed TP->>TP: scroll to top and move focus TP->>TO: reveal TP-->>U: announce result in live region ``` Text alternative: the click asks the theme provider to switch; the overlay covers the page; the renderer loads and swaps the variant; the provider scrolls, moves focus, reveals and announces. ## Time-travel transition (effect) - **cover**: a full-viewport overlay with a pixel-dither pattern (CSS `steps()` animation over a checker mask, accent-coloured) fades in over ~300 ms; pointer events are blocked and `aria-hidden` is set. - **swap**: variant changes, `data-variant` updated, scroll to top, focus to `main`. - **reveal**: the dither clears over ~300 ms. Total about 600 ms plus E chunk load time on first visit. - Reduced motion: none of this renders. ## Error handling - Storage unavailable: mode works for the session only. - E chunk fails to load: stay in B, show the alert, offer retry; the overlay is removed. - Media query unsupported: treat as light.