{# FOUC-prevention: resolve theme preference and apply data-theme to before any stylesheet loads. Reads localStorage first (client cache), then falls back to the server-rendered ProfileSettings.theme, then to 'system'. The matchMedia listener re-applies when the OS preference flips while the page is open AND the user has 'system' selected. `_ps_global` is reused by the topbar `_ps` set below so the route only hits the DB once per render. #} {% set _ps_global = profile_switcher_data() %} {% set _resolved_theme = _ps_global.profile.theme if _ps_global.show_switcher else 'system' %} {# palette.js must run BEFORE alpine.min.js so window.paletteOverlay is defined by the time Alpine's first init pass evaluates the overlay's x-data attribute. Defer scripts execute in document order. #}