/* theme.js — Restores theme and text size from localStorage before first paint.
   Loaded synchronously (no defer/async) to prevent flash of wrong appearance.
   DOM interaction (button wiring) is handled by settings.js (deferred).
*/
(function () {
    var TEXT_SIZES = [20, 23, 26];

    /* Theme */
    var storedTheme = localStorage.getItem('theme');
    if (storedTheme === 'dark' || storedTheme === 'light') {
        document.documentElement.setAttribute('data-theme', storedTheme);
    }

    /* Text size */
    var storedSize = parseInt(localStorage.getItem('text-size'), 10);
    if (!isNaN(storedSize) && storedSize >= 0 && storedSize < TEXT_SIZES.length) {
        document.documentElement.style.setProperty('--text-size', TEXT_SIZES[storedSize] + 'px');
    }

    /* Focus mode */
    if (localStorage.getItem('focus-mode')) {
        document.documentElement.setAttribute('data-focus-mode', '');
    }

    /* Reduce motion */
    if (localStorage.getItem('reduce-motion')) {
        document.documentElement.setAttribute('data-reduce-motion', '');
    }
})();
