// Sistema de escala de fuentes para accesibilidad
const fontScaleSystem = {
    STORAGE_KEY: 'resistirePref_fontScale',
    MIN_SCALE: 0.8,
    MAX_SCALE: 1.5,
    STEP: 0.1,
    currentScale: 1,

    init() {
        const saved = localStorage.getItem(this.STORAGE_KEY);
        if (saved) {
            const scale = parseFloat(saved);
            if (!isNaN(scale) && scale >= this.MIN_SCALE && scale <= this.MAX_SCALE) {
                this.currentScale = scale;
            }
        }
        this.apply();
        this.updateDisplay();
    },

    apply() {
        document.documentElement.style.setProperty('--font-scale', this.currentScale);
    },

    save() {
        localStorage.setItem(this.STORAGE_KEY, this.currentScale.toString());
    },

    increase() {
        if (this.currentScale < this.MAX_SCALE) {
            this.currentScale = Math.round((this.currentScale + this.STEP) * 10) / 10;
            this.apply();
            this.save();
            this.updateDisplay();
        }
    },

    decrease() {
        if (this.currentScale > this.MIN_SCALE) {
            this.currentScale = Math.round((this.currentScale - this.STEP) * 10) / 10;
            this.apply();
            this.save();
            this.updateDisplay();
        }
    },

    updateDisplay() {
        const el = document.getElementById('font-scale-value');
        if (el) el.textContent = Math.round(this.currentScale * 100) + '%';
    }
};

function increaseFontScale() {
    fontScaleSystem.increase();
}

function decreaseFontScale() {
    fontScaleSystem.decrease();
}
