// Runs blocking in <head>, before the first paint.
//
// app.js is a deferred module, so anything it does happens after the browser
// has already drawn the page - which is why the theme toggle used to flash the
// wrong option on load, and why a manually chosen theme would show a frame of
// the OS one first. This has to stay a classic script with no defer/async, and
// it has to stay small enough that blocking on it is free.
//
// Absent attribute means "follow the OS", so the only work here is restoring a
// manual choice. Everything else - the pressed styling, the toggle handlers -
// is CSS and app.js respectively.
(function () {
  try {
    var theme = localStorage.getItem("tarakan:theme")
    if (theme === "light" || theme === "dark") {
      document.documentElement.setAttribute("data-theme", theme)
    }
  } catch (_error) {
    // Private mode or blocked storage: fall through to the OS preference.
  }
})()
