---
/*
  No-flash theme init. Runs before paint, sets data-theme from stored preference
  or system (ANIMATION_SPEC — the one permitted inline script; CSP-hashed at the
  nginx layer). First visit follows the system; once set, the choice persists.
*/
---

<script is:inline>
  (function () {
    try {
      var t = localStorage.getItem('theme');
      if (t !== 'light' && t !== 'dark') {
        t = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
      }
      document.documentElement.dataset.theme = t;
    } catch (e) {
      document.documentElement.dataset.theme = 'dark';
    }
  })();
</script>
