{# Finite State theme init — runs in
before paint to avoid flash. Resolves the active theme as follows: - If pdf_mode is True (set by pdf_renderer.py), use the server-rendered theme exactly. Bypasses localStorage / URL / prefers-color-scheme so PDF output stays deterministic. This matters with JS-executing headless browsers (e.g. Playwright) where prefers-color-scheme can match dark in a non-pinned context and yield an unintended dark PDF. - Otherwise, if the server passed an EXPLICIT theme ('light' or 'dark'), honor it as the authoritative initial render. We skip localStorage and prefers-color-scheme so an author who ran ``--theme dark`` gets dark for every viewer regardless of their browser state. The in-page toggle button still writes localStorage for in-session UX, but that storage no longer overrides the next load of an explicit-theme report. - Otherwise (server theme was 'auto'), resolve user preference: 1. localStorage "fs-theme" (user's prior choice) 2. ?theme= URL param (one-off overrides, e.g. for sharing) 3. system preference (prefers-color-scheme: dark) 4. server-rendered fallback (defaults to light when auto) Sets data-theme on ; CSS in _design_system.html keys off this. #} {# Capture whether the caller asked for 'auto' BEFORE collapsing to a concrete light/dark value — the JS needs both signals to honor explicit themes. #} {% set _fs_theme_raw = theme | default('light') %} {% set _fs_theme_wanted_auto = (_fs_theme_raw == 'auto') %} {% set _fs_theme_default = 'light' if _fs_theme_wanted_auto else _fs_theme_raw %}