    (function() {
        if (window.paintopsCompareWired) return;
        window.paintopsCompareWired = true;

        var overlay = document.querySelector('.pp-compare-modal-overlay');
        if (!overlay) return;

        var beforeImg = overlay.querySelector('.pp-compare-before');
        var afterImg = overlay.querySelector('.pp-compare-after');
        var divider = overlay.querySelector('.pp-compare-divider');
        var slider = overlay.querySelector('.pp-compare-slider');
        var closeBtn = overlay.querySelector('.pp-compare-close');

        function applySlider() {
            var v = parseInt(slider.value, 10);
            afterImg.style.clipPath = 'inset(0 ' + (100 - v) + '% 0 0)';
            divider.style.left = v + '%';
        }

        document.addEventListener('click', function(e) {
            var trigger = e.target.closest ? e.target.closest('.pp-view-compare-btn') : null;
            if (!trigger) return;
            e.preventDefault();

            beforeImg.src = trigger.getAttribute('data-before-url');
            afterImg.src = trigger.getAttribute('data-after-url');
            slider.value = 50;
            applySlider();
            overlay.style.display = 'block';
        });

        if (slider) {
            slider.addEventListener('input', applySlider);
        }

        if (closeBtn) {
            closeBtn.addEventListener('click', function() {
                overlay.style.display = 'none';
            });
        }
    })();
