window.rolemasterTheme = {
    storageKey: "rolemaster.theme.mode",

    apply(mode) {
        document.documentElement.dataset.theme = mode || "system";
    },

    init(storageKey) {
        if (storageKey) {
            this.storageKey = storageKey;
        }

        let mode = "system";

        try {
            mode = localStorage.getItem(this.storageKey) || "system";
        } catch {
            mode = "system";
        }

        this.apply(mode);
    }
};
