(() => {
const root = document.documentElement;
let light = false;
// Each page starts at the site's night default. The switch applies to this
// visit, so an old saved light choice cannot override the requested default.
function apply() {
root.dataset.theme = light ? "elpis-light" : "elpis";
const icon = document.querySelector('link[rel~="icon"]');
if (icon) icon.href = `./assets/branding/favicon-amber${light ? "-light" : ""}.svg?v=amber-20261020`;
document.querySelectorAll("[data-theme-src-light]").forEach(image => {
image.src = light ? image.dataset.themeSrcLight : image.dataset.themeSrcDark;
});
document.querySelectorAll("[data-brand-theme]").forEach(button => {
button.innerHTML = light ? `` : ``;
button.setAttribute("aria-label", light ? "Use night theme" : "Use day theme");
button.setAttribute("aria-pressed", String(light));
});
}
apply();
function wire() {
apply();
document.querySelectorAll("[data-brand-theme]").forEach(button => button.addEventListener("click", () => {
light = !light;
apply();
}));
}
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", wire, { once: true });
else wire();
})();