// Shared theme bootstrap used by the main page (app.jsx) and by the standalone
// legal pages (privacy.html, terms.html, refund.html). Exposes globals on
// `window` because the project loads files via plain <script> tags, not ES
// modules.

window.THEME_STORAGE_KEY = "flik:theme";

window.getInitialTheme = function getInitialTheme() {
  try {
    const stored = localStorage.getItem(window.THEME_STORAGE_KEY);
    if (stored === "light" || stored === "dark") return stored;
  } catch (_) {}
  if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
    return "dark";
  }
  return "light";
};
