

(function() {
    if (document._impulseUnfoldNewModesBound) return;
    document._impulseUnfoldNewModesBound = true;

    

    
    document.addEventListener('click', function(e) {
        var t = e.target;
        if (!t || !t.closest) return;


        var revealBtn = t.closest('.impulse-acc-reveal-title');
        if (revealBtn) {
            var revealItem = revealBtn.closest('.impulse-acc-reveal-item');
            if (revealItem) {
                var revealAcc = revealItem.closest('.impulse-acc-reveal');
                var wasOpen   = revealItem.classList.contains('open');
                if (revealAcc) {
                    revealAcc.querySelectorAll('.impulse-acc-reveal-item.open')
                        .forEach(function(i) { i.classList.remove('open'); });
                }
                
                if (!wasOpen) revealItem.classList.add('open');
            }
            return;
        }

    }, true);
})();

function _impulseUnfoldInitOnce() {
    if (window._impulseUnfoldLegacyBound) return;
    window._impulseUnfoldLegacyBound = true;
    if (document.querySelector('.impulse-unfold, .impulse-acc-tiles, .impulse-toggle')) {
(function() {
    var ease = 'cubic-bezier(0.4, 0, 0.2, 1)';
    
    document.querySelectorAll('.impulse-unfold-scroll').forEach(function(acc) {
        var cards = Array.prototype.slice.call(acc.querySelectorAll('.impulse-unfold-card'));
        var stage = acc.querySelector('.impulse-unfold-stage');
        var anim = acc.dataset.anim;
        var total = cards.length;
        if (total < 2) return;
        
        var active = 0;
        var transitioning = false;
        var wheelAccum = 0;
        var wheelThreshold = 80;
        
        function measureHeight() {
            var fixedH = parseInt(acc.dataset.height) || 0;
            if (fixedH > 0) {
                stage.style.height = fixedH + 'px';
                cards.forEach(function(c) {
                    c.style.position = 'absolute';
                    c.style.top = '0';
                    c.style.left = '0';
                    c.style.width = '100%';
                    c.style.height = fixedH + 'px';
                    c.style.overflowY = 'hidden';
                });
            } else {
            var maxH = 0;
            cards.forEach(function(c) {
                c.style.position = 'relative';
                c.style.opacity = '1';
                c.style.transform = 'none';
                var h = c.offsetHeight;
                if (h > maxH) maxH = h;
            });
            stage.style.height = maxH + 'px';
            cards.forEach(function(c) {
                c.style.position = 'absolute';
                c.style.top = '0';
                c.style.left = '0';
                c.style.width = '100%';
            });
            }
            positionCards(false);
        }
        
        function positionCards(animate) {
            var dur = animate ? '0.55s' : '0s';
            cards.forEach(function(card, i) {
                var offset = i - active;
                if (offset > total / 2) offset -= total;
                if (offset < -total / 2) offset += total;
                
                card.style.transition = animate ? 'transform ' + dur + ' ' + ease + ', opacity 0.4s ease-in-out, filter 0.4s ease-in-out' : 'none';
                
                if (anim === 'rolodex') {
                    
                    if (offset === 0) {
                        card.style.transform = 'translateY(0) scale(1)';
                        card.style.opacity = '1';
                        card.style.filter = '';
                        card.style.zIndex = total;
                    } else if (offset < 0) {
                        
                        card.style.transform = 'translateY(0) scale(0.55)';
                        card.style.opacity = '0';
                        card.style.filter = 'blur(8px)';
                        card.style.zIndex = 0;
                    } else if (offset <= 2) {
                        var ty = offset * 14;
                        var sd = Math.max(0.75, 1 - offset * 0.12);
                        card.style.transform = 'translateY(' + ty + '%) scale(' + sd + ')';
                        card.style.opacity = Math.max(0, 1 - offset * 0.5).toFixed(2);
                        card.style.filter = 'blur(' + (offset * 3) + 'px)';
                        card.style.zIndex = total - offset;
                    } else {
                        card.style.transform = 'translateY(60%) scale(0.7)';
                        card.style.opacity = '0';
                        card.style.zIndex = 0;
                    }
                } else if (anim === 'depth') {
                    
                    if (offset === 0) {
                        card.style.transform = 'translateX(0) translateY(0) scale(1)';
                        card.style.opacity = '1';
                        card.style.filter = '';
                        card.style.zIndex = total;
                    } else if (offset < 0) {
                        
                        card.style.transform = 'translateX(-100%) scale(0.85)';
                        card.style.opacity = '0';
                        card.style.filter = '';
                        card.style.zIndex = 0;
                    } else {
                        
                        var tx = offset * 18;
                        var ty = offset * 4;
                        var sd = Math.max(0.6, 1 - offset * 0.1);
                        var blur = Math.min(offset * 4, 10);
                        card.style.transform = 'translateX(' + tx + '%) translateY(' + ty + '%) scale(' + sd + ')';
                        card.style.opacity = Math.max(0, 1 - offset * 0.25).toFixed(2);
                        card.style.filter = blur > 0 ? 'blur(' + blur + 'px)' : '';
                        card.style.zIndex = total - offset;
                    }
                }
            });
        }
        
        function goTo(idx) {
            if (idx === active || transitioning) return;
            transitioning = true;
            active = ((idx % total) + total) % total;
            acc.dataset.active = active;
            positionCards(true);
            
            var nums = acc.querySelectorAll('.impulse-acc-stack-num');
            nums.forEach(function(n) {
                var isAct = parseInt(n.dataset.idx) === active;
                n.classList.toggle('active', isAct);
                n.style.opacity = isAct ? '1' : '0.35';
                n.style.fontWeight = isAct ? '600' : '400';
            });
            setTimeout(function() { transitioning = false; }, 550);
        }
        
        
        var prevBtn = acc.querySelector('.impulse-acc-stack-prev');
        var nextBtn = acc.querySelector('.impulse-acc-stack-next');
        if (prevBtn) prevBtn.addEventListener('click', function(e) { e.stopPropagation(); goTo(active - 1); });
        if (nextBtn) nextBtn.addEventListener('click', function(e) { e.stopPropagation(); goTo(active + 1); });
        
        acc.querySelectorAll('.impulse-acc-stack-num').forEach(function(n) {
            n.addEventListener('click', function(e) { e.stopPropagation(); goTo(parseInt(n.dataset.idx)); });
        });
        
        var isHovered = false;
        acc.addEventListener('mouseenter', function() { isHovered = true;  wheelAccum = 0; });
        acc.addEventListener('mouseleave', function() { isHovered = false; wheelAccum = 0; });
        
        acc.addEventListener('wheel', function(e) {
            if (!isHovered) return;
            e.preventDefault();
            e.stopPropagation();
            wheelAccum += e.deltaY;
            if (Math.abs(wheelAccum) >= wheelThreshold) {
                goTo(active + (wheelAccum > 0 ? 1 : -1));
                wheelAccum = 0;
            }
        }, { passive: false });
        
        var touchStartY = 0;
        acc.addEventListener('touchstart', function(e) { touchStartY = e.touches[0].clientY; }, { passive: true });
        acc.addEventListener('touchend', function(e) {
            var dy = touchStartY - e.changedTouches[0].clientY;
            if (Math.abs(dy) > 40) goTo(active + (dy > 0 ? 1 : -1));
        });
        
        measureHeight();
    });
})();

(function() {
    var ease = 'cubic-bezier(0.4, 0, 0.2, 1)';


    
    document.querySelectorAll('.impulse-acc-spotlight').forEach(function(acc) {
        var items = Array.prototype.slice.call(acc.querySelectorAll('.impulse-acc-spot-item'));
        var active = 0;

        
        items.forEach(function(item, i) {
            var body = item.querySelector('.impulse-acc-spot-body');
            if (!body) return;
            body.style.overflow = 'hidden';
            body.style.transition = 'max-height 0.35s ease-in-out, opacity 0.25s ease-in-out';
            if (i === active) {
                body.style.maxHeight = body.scrollHeight + 'px';
                body.style.opacity = '1';
                setTimeout(function() { body.style.maxHeight = 'none'; }, 350);
            } else {
                body.style.maxHeight = '0';
                body.style.opacity = '0';
            }
        });

        function goTo(idx) {
            if (idx === active) return;
            
            acc.style.minHeight = acc.offsetHeight + 'px';
            active = idx;
            items.forEach(function(item, i) {
                var isAct = i === idx;
                var body  = item.querySelector('.impulse-acc-spot-body');
                item.classList.toggle('active', isAct);
                if (!body) return;
                if (isAct) {
                    body.style.display = '';
                    body.style.maxHeight = '0';
                    body.offsetHeight;
                    body.style.maxHeight = body.scrollHeight + 'px';
                    body.style.opacity = '1';
                    setTimeout(function() { if (item.classList.contains('active')) body.style.maxHeight = 'none'; }, 350);
                } else {
                    if (body.style.maxHeight === 'none') body.style.maxHeight = body.scrollHeight + 'px';
                    body.offsetHeight;
                    body.style.maxHeight = '0';
                    body.style.opacity = '0';
                }
            });
            setTimeout(function() { acc.style.minHeight = ''; }, 400);
        }

        items.forEach(function(item, i) {

            var hdr = item.querySelector('.impulse-acc-spot-header');
            if (hdr) {
                hdr.addEventListener('click', function(e) {
                    e.stopPropagation();
                    goTo(i);
                });
            } else {
                item.addEventListener('click', function() { goTo(i); });
            }
        });

        
        var spotWheelAccum = 0;
        acc.addEventListener('wheel', function(e) {
            e.preventDefault();
            e.stopPropagation();
            spotWheelAccum += e.deltaY;
            if (Math.abs(spotWheelAccum) >= 80) {
                var next = active + (spotWheelAccum > 0 ? 1 : -1);
                if (next < 0) next = items.length - 1;
                if (next >= items.length) next = 0;
                goTo(next);
                spotWheelAccum = 0;
            }
        }, { passive: false });
        
        
        var spotTouchY = 0;
        acc.addEventListener('touchstart', function(e) { spotTouchY = e.touches[0].clientY; }, { passive: true });
        acc.addEventListener('touchend', function(e) {
            var dy = spotTouchY - e.changedTouches[0].clientY;
            if (Math.abs(dy) > 40) {
                var next = active + (dy > 0 ? 1 : -1);
                if (next < 0) next = items.length - 1;
                if (next >= items.length) next = 0;
                goTo(next);
            }
        });
    });

    
    document.querySelectorAll('.impulse-acc-tiles').forEach(function(acc) {
        var tiles = Array.prototype.slice.call(acc.querySelectorAll('.impulse-acc-tile'));
        var expandMode = acc.dataset.expand || 'zoom';
        var overlay = acc.querySelector('.impulse-acc-tiles-overlay');
        var expanded = acc.querySelector('.impulse-acc-tile-expanded');
        var expHeader = expanded ? expanded.querySelector('.impulse-acc-tile-expanded-header span') : null;
        var expBody = expanded ? expanded.querySelector('.impulse-acc-tile-expanded-body') : null;
        var expClose = expanded ? expanded.querySelector('.impulse-acc-tile-close') : null;
        var items = [];
        try { items = JSON.parse(acc.dataset.items || '[]'); } catch(e) {}

        function closeZoom() {
            if (overlay) overlay.classList.remove('active');
            if (expanded) expanded.classList.remove('active');
        }
        if (overlay) overlay.addEventListener('click', closeZoom);
        if (expClose) expClose.addEventListener('click', closeZoom);

        tiles.forEach(function(tile, i) {
            tile.addEventListener('click', function(e) {
                if (expandMode === 'zoom') {
                    var item = items[i] || {};
                    if (expHeader) expHeader.textContent = item.title || 'Item';
                    if (expBody) expBody.innerHTML = item.content || '';
                    if (overlay) { overlay.style.display = 'block'; requestAnimationFrame(function() { overlay.classList.add('active'); }); }
                    if (expanded) { expanded.style.display = 'block'; requestAnimationFrame(function() { expanded.classList.add('active'); }); }
                }

                
            });
        });

        
        acc.querySelectorAll('.impulse-acc-tile-close').forEach(function(btn) {
            btn.addEventListener('click', function(e) {
                e.stopPropagation();
                btn.closest('.impulse-acc-tile').classList.remove('slid');
            });
        });
    });


    
    
    if (!document._impulseUnfoldNewModesBound) {
        document._impulseUnfoldNewModesBound = true;
        document.addEventListener('click', function(e) {
            var t = e.target;
            if (!t || !t.closest) return;


            
            
            var revealBtn = t.closest('.impulse-acc-reveal-title');
            if (revealBtn) {
                var revealItem = revealBtn.closest('.impulse-acc-reveal-item');
                if (revealItem) {
                    var body  = revealItem.querySelector('.impulse-acc-reveal-body');
                    var inner = revealItem.querySelector('.impulse-acc-reveal-inner');
                    var nowOpen = !revealItem.classList.contains('open');
                    revealItem.classList.toggle('open', nowOpen);
                    if (body && inner) {
                        if (nowOpen) {
                            
                            body.style.maxHeight = inner.scrollHeight + 'px';
                        } else {
                            body.style.maxHeight = '0px';
                        }
                    }
                }
                return;
            }

        });
    }

})();

function impulseToggleContent(header) {
    var toggle = header.closest('.impulse-toggle');
    var content = toggle.querySelector('.impulse-toggle-content');
    var icon = header.querySelector('.impulse-toggle-icon');
    var isOpen = toggle.classList.contains('open');
    
    if (isOpen) {
        toggle.classList.remove('open');
        if (content) content.style.display = 'none';
        if (icon) icon.style.transform = '';
    } else {
        toggle.classList.add('open');
        if (content) content.style.display = '';
        if (icon) icon.style.transform = 'rotate(180deg)';
    }
}

}
} 
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', _impulseUnfoldInitOnce);
} else {
    _impulseUnfoldInitOnce();
}
document.addEventListener('DOMContentLoaded', function() {
    
    if (document.querySelector('.impulse-map-reveal')) {
    var mapEls = document.querySelectorAll('.impulse-map-reveal');
    if (mapEls.length && 'IntersectionObserver' in window) {
        var mapObs = new IntersectionObserver(function(entries) {
            entries.forEach(function(e) {
                if (e.isIntersecting) {
                    e.target.classList.add('revealed');
                    mapObs.unobserve(e.target);
                }
            });
        }, { threshold: 0.15 });
        mapEls.forEach(function(el) { mapObs.observe(el); });
    } else {
        mapEls.forEach(function(el) { el.classList.add('revealed'); });
    }
    
    }
    
    if (document.querySelector('.impulse-carousel, .impulse-new-slider, .impulse-product-carousel')) {

    
    

    
    function attachCarouselDrag(track, onRelease, onDragMove, onDragStart) {
        var dragging = false, startX = 0, currentX = 0, didDrag = false, rafId = null;
        function getX(e) { return e.touches ? e.touches[0].clientX : e.clientX; }
        function onDown(e) {
            if (e.button !== undefined && e.button !== 0) return;
            dragging = true; didDrag = false;
            startX = currentX = getX(e);
            track.style.cursor = 'grabbing';
            track.style.userSelect = 'none';
            if (onDragStart) onDragStart();
            e.preventDefault();
        }
        function onMove(e) {
            if (!dragging) return;
            currentX = getX(e);
            var delta = currentX - startX;
            if (Math.abs(delta) > 3) didDrag = true;
            if (didDrag && onDragMove) {
                if (rafId) cancelAnimationFrame(rafId);
                var d = delta;
                rafId = requestAnimationFrame(function() { onDragMove(d); rafId = null; });
            }
            e.preventDefault();
        }
        function onUp() {
            if (!dragging) return;
            dragging = false;
            track.style.cursor = 'grab';
            track.style.userSelect = '';
            if (rafId) { cancelAnimationFrame(rafId); rafId = null; }
            var delta = currentX - startX;
            onRelease(delta, didDrag);
            if (didDrag) {
                var blocker = function(ev) {
                    ev.stopPropagation(); ev.preventDefault();
                    track.removeEventListener('click', blocker, true);
                };
                track.addEventListener('click', blocker, true);
            }
        }
        track.style.cursor = 'grab';
        track.addEventListener('mousedown', onDown, { passive: false });
        document.addEventListener('mousemove', onMove, { passive: false });
        document.addEventListener('mouseup', onUp);
        track.addEventListener('touchstart', onDown, { passive: false });
        document.addEventListener('touchmove', onMove, { passive: false });
        document.addEventListener('touchend', onUp);
    }

    document.querySelectorAll('.impulse-product-carousel').forEach(function(carousel) {
        var mode = carousel.dataset.mode || 'slide';
        var track = carousel.querySelector('.impulse-carousel-slides');
        if (!track) return;

        if (mode === 'scroll') {
            var position = 0;
            var isPaused = false;
            var isDragPaused = false;
            var dragStartPos = 0;
            var animId = null;
            var speed = parseFloat(carousel.dataset.scrollSpeed) || 40;
            var origSlides = Array.prototype.slice.call(track.querySelectorAll('.impulse-carousel-slide:not(.impulse-clone)'));
            if (!origSlides.length) return;
            track.style.transform = 'translateX(0)';
            track.style.transition = 'none';
            function getSetWidth() {
                var w = 0;
                origSlides.forEach(function(s) { w += s.offsetWidth + parseInt(carousel.dataset.gap || 0); });
                return w;
            }
            var setWidth = 0;
            function animScroll() {
                if (!isPaused && !isDragPaused) {
                    if (setWidth === 0) setWidth = getSetWidth();
                    if (setWidth > 0) {
                        position -= speed / 60;
                        if (position <= -setWidth) position += setWidth;
                        track.style.transform = 'translateX(' + position + 'px)';
                    }
                }
                animId = requestAnimationFrame(animScroll);
            }
            animId = requestAnimationFrame(animScroll);
            if (carousel.dataset.pause === 'true') {
                carousel.addEventListener('mouseenter', function() { isPaused = true; });
                carousel.addEventListener('mouseleave', function() { isPaused = false; });
            }
            attachCarouselDrag(track,
                function(delta, wasDrag) {
                    if (wasDrag && setWidth > 0) {
                        position = dragStartPos + delta;
                        while (position > 0) position -= setWidth;
                        while (position < -setWidth) position += setWidth;
                    }
                    isDragPaused = false;
                },
                function(delta) {
                    track.style.transition = 'none';
                    track.style.transform = 'translateX(' + (dragStartPos + delta) + 'px)';
                },
                function() {
                    dragStartPos = position;
                    isDragPaused = true;
                }
            );
        } else {

            

            
            

            
            Array.prototype.slice.call(track.querySelectorAll('.impulse-pc-clone'))
                .forEach(function(c) { c.parentNode.removeChild(c); });

            var realSlides = Array.prototype.slice.call(track.querySelectorAll('.impulse-carousel-slide'));
            var realCount  = realSlides.length;
            if (!realCount) return;

            var autoplay         = carousel.dataset.autoplay === 'true';
            var autoplaySpeed    = parseInt(carousel.dataset.speed) || 3000;
            var pauseOnHover     = carousel.dataset.pause === 'true';
            var transitionSpeed  = parseInt(carousel.dataset.transition) || 400;
            var gap              = parseInt(carousel.dataset.gap) || 0;


            
            
            var _initSpv = (function() {
                var w = window.innerWidth;
                var m = parseInt(carousel.dataset.slidesPerViewMobile);
                var t = parseInt(carousel.dataset.slidesPerViewTablet);
                var d = parseInt(carousel.dataset.slidesPerView) || 4;
                if (w <= 767 && m > 0) return m;
                if (w <= 1024 && t > 0) return t;
                return Math.max(1, d);
            })();
            var _bufN = Math.ceil(Math.max(_initSpv, realCount) / realCount) * realCount;

            
            for (var _i = 0; _i < _bufN; _i++) {
                var _hc = realSlides[(_bufN - 1 - _i) % realCount].cloneNode(true);
                _hc.classList.add('impulse-pc-clone');
                _hc.setAttribute('aria-hidden', 'true');
                track.insertBefore(_hc, track.firstChild);
            }
            
            for (var _i = 0; _i < _bufN; _i++) {
                var _tc = realSlides[_i % realCount].cloneNode(true);
                _tc.classList.add('impulse-pc-clone');
                _tc.setAttribute('aria-hidden', 'true');
                track.appendChild(_tc);
            }

            
            var allDom          = Array.prototype.slice.call(track.children);
            var rc              = realCount;
            var _base           = _bufN;     
            var currentPos      = _base;     
            var isAnimating     = false;
            var autoplayTimer   = null;
            var _normaliseTimer = null;

            function getSpv() {
                var w = window.innerWidth;
                var m = parseInt(carousel.dataset.slidesPerViewMobile);
                var t = parseInt(carousel.dataset.slidesPerViewTablet);
                var d = parseInt(carousel.dataset.slidesPerView) || 4;
                if (w <= 767 && m > 0) return m;
                if (w <= 1024 && t > 0) return t;
                return Math.max(1, d);
            }

            var _cachedSW = 0;
            function getSlideW() {
                if (_cachedSW > 0) return _cachedSW;
                var spv = getSpv();
                var cw  = carousel.getBoundingClientRect().width || carousel.offsetWidth;
                if (!cw) return _cachedSW || 0; 
                _cachedSW = Math.floor((cw - gap * (spv - 1)) / spv);
                return _cachedSW;
            }

            function setAllWidths() {
                var spv = getSpv();
                var cw  = carousel.getBoundingClientRect().width || carousel.offsetWidth;
                if (!cw) return; 
                var newSW = Math.floor((cw - gap * (spv - 1)) / spv);
                if (!newSW) return;
                _cachedSW = newSW;
                var swPx = newSW + 'px';
                allDom.forEach(function(s) {
                    s.style.flex     = '0 0 ' + swPx;
                    s.style.maxWidth = swPx;
                    s.style.width    = swPx;
                });
            }

            function positionFor(pos) {
                var sw = getSlideW();
                if (!sw) return null; 
                return -(pos * (sw + gap));
            }

            function moveTo(pos, animate) {
                var px = positionFor(pos);
                if (px === null) return; 
                track.style.transition = animate ? 'transform ' + transitionSpeed + 'ms ease-in-out' : 'none';
                track.style.transform  = 'translateX(' + px + 'px)';
            }

            function normalise() {

                if (currentPos >= _base + rc) {
                    currentPos -= rc;
                    moveTo(currentPos, false);
                } else if (currentPos < _base) {
                    currentPos += rc;
                    moveTo(currentPos, false);
                }
            }

            function stepBy(steps) {
                if (isAnimating) return;
                isAnimating = true;
                currentPos += steps;
                moveTo(currentPos, true);
                clearTimeout(_normaliseTimer);
                _normaliseTimer = setTimeout(function() {
                    normalise();
                    isAnimating = false;
                }, transitionSpeed + 50);
            }

            function startAP() {
                if (autoplay && !autoplayTimer) {
                    autoplayTimer = setInterval(function() { stepBy(1); }, autoplaySpeed);
                }
            }
            function stopAP()    { if (autoplayTimer) { clearInterval(autoplayTimer); autoplayTimer = null; } }
            function restartAP() { stopAP(); startAP(); }


            
            
            requestAnimationFrame(function() {
                requestAnimationFrame(function() {
                    setAllWidths();
                    moveTo(currentPos, false);
                    startAP();
                    if (pauseOnHover) {
                        carousel.addEventListener('mouseenter', stopAP);
                        carousel.addEventListener('mouseleave', startAP);
                    }
                });
            });

            attachCarouselDrag(track,
                function(delta, wasDrag) {
                    if (!wasDrag) { isAnimating = false; restartAP(); return; }
                    var sw    = getSlideW() + gap;
                    var steps = sw > 0 ? -Math.round(delta / sw) : 0;
                    if (steps !== 0) {
                        stepBy(steps);
                    } else {
                        moveTo(currentPos, true);
                        setTimeout(function() { isAnimating = false; }, transitionSpeed + 50);
                    }
                    restartAP();
                },
                function(delta) {
                    var base = positionFor(currentPos);
                    track.style.transition = 'none';
                    track.style.transform  = 'translateX(' + (base + delta) + 'px)';
                },
                function() {

                    clearTimeout(_normaliseTimer);
                    stopAP();
                    isAnimating = false;
                }
            );

            if (typeof ResizeObserver !== 'undefined') {
                var _roTimer = null;
                new ResizeObserver(function() {
                    clearTimeout(_roTimer);
                    _roTimer = setTimeout(function() {
                        setAllWidths();
                        moveTo(currentPos, false);
                    }, 60);
                }).observe(carousel);
            }
        }
    });


    
    function initNewSliders() {
    document.querySelectorAll('.impulse-new-slider').forEach(function(carousel) {
        if (carousel._sliderInit) return;
        carousel._sliderInit = true;

        var track = carousel.querySelector('.impulse-carousel-track');
        var slides = carousel.querySelector('.impulse-carousel-slides');
        var slideItems = carousel.querySelectorAll('.impulse-carousel-slide');
        if (!slides || slideItems.length === 0) return;

        var direction = carousel.dataset.direction || 'right';
        var transitionSpeed = parseInt(carousel.dataset.transition) || 400;
        var isVertical = (direction === 'up' || direction === 'down');
        var autoplay = carousel.dataset.autoplay === 'true';
        var speed = parseInt(carousel.dataset.speed) || 5000;
        var currentIndex = 0;
        var autoplayTimer = null;
        var autoDir = (direction === 'left' || direction === 'up') ? -1 : 1;

        
        function slideSize() {
            return isVertical ? track.offsetHeight : track.offsetWidth;
        }

        function goToSlide(index, instant) {
            var prevIndex = currentIndex;
            if (index < 0) index = slideItems.length - 1;
            if (index >= slideItems.length) index = 0;
            currentIndex = index;
            carousel.dataset.currentSlide = index;
            var offset = index * slideSize();
            
            var isWrap = instant || (prevIndex === slideItems.length - 1 && index === 0) || (prevIndex === 0 && index === slideItems.length - 1);
            if (isWrap) {
                slides.style.transition = 'none';
                slides.style.transform = isVertical ? 'translateY(-' + offset + 'px)' : 'translateX(-' + offset + 'px)';
                slides.offsetHeight;
                slides.style.transition = 'transform ' + transitionSpeed + 'ms ease-in-out';
            } else {
                slides.style.transform = isVertical ? 'translateY(-' + offset + 'px)' : 'translateX(-' + offset + 'px)';
            }
            
            var dotsEl = carousel.querySelector('.impulse-carousel-dots');
            if (dotsEl) {
                dotsEl.querySelectorAll('[data-slide]').forEach(function(d, i) {
                    d.style.background = i === index ? '#1d2327' : 'rgba(255,255,255,0.6)';
                });
            }
            
            if (prevIndex !== index) _sliderAnimLifecycle(slideItems[prevIndex], slideItems[index]);
        }

        function _sliderAnimLifecycle(outEl, inEl) {
            if (typeof activeAnimations === 'undefined') return;
            if (outEl) outEl.querySelectorAll('[id^="section-anim-"]').forEach(function(w) {
                if (activeAnimations[w.id] && activeAnimations[w.id].pause) activeAnimations[w.id].pause();
            });
            if (inEl) inEl.querySelectorAll('[id^="section-anim-"]').forEach(function(w) {
                if (activeAnimations[w.id] && activeAnimations[w.id].start) activeAnimations[w.id].start();
            });
        }

        
        slides.style.transition = 'none';
        goToSlide(0, true);
        slides.offsetHeight; 
        slides.style.transition = 'transform ' + transitionSpeed + 'ms ease-in-out';

        
        var _resizeTimer = null;
        window.addEventListener('resize', function() {
            clearTimeout(_resizeTimer);
            _resizeTimer = setTimeout(function() {
                slides.style.transition = 'none';
                goToSlide(currentIndex, true);
                slides.offsetHeight;
                slides.style.transition = 'transform ' + transitionSpeed + 'ms ease-in-out';
            }, 60);
        });

        
        function restartAutoplay() {
            if (autoplayTimer) { clearInterval(autoplayTimer); autoplayTimer = null; }
            if (autoplay) {
                autoplayTimer = setInterval(function() {
                    goToSlide(currentIndex + autoDir);
                }, speed);
            }
        }
        restartAutoplay();

        
        (function() {
            var dragging = false, startX = 0, startY = 0, didDrag = false;
            slides.addEventListener('mousedown', function(e) { dragging = true; startX = e.clientX; startY = e.clientY; didDrag = false; });
            slides.addEventListener('mousemove', function(e) {
                if (!dragging) return;
                if (Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5) didDrag = true;
            });
            slides.addEventListener('mouseup', function(e) {
                if (!dragging) return;
                dragging = false;
                var dx = isVertical ? (e.clientY - startY) : (e.clientX - startX);
                if (didDrag && Math.abs(dx) >= 50) { goToSlide(currentIndex + (dx < 0 ? 1 : -1)); restartAutoplay(); }
            });
            slides.addEventListener('mouseleave', function() { dragging = false; });
            
            slides.addEventListener('touchstart', function(e) { startX = e.touches[0].clientX; startY = e.touches[0].clientY; didDrag = false; }, { passive: true });
            slides.addEventListener('touchmove', function(e) {
                if (Math.abs(e.touches[0].clientX - startX) > 10 || Math.abs(e.touches[0].clientY - startY) > 10) didDrag = true;
            }, { passive: true });
            slides.addEventListener('touchend', function(e) {
                var dx = isVertical ? (e.changedTouches[0].clientY - startY) : (e.changedTouches[0].clientX - startX);
                if (didDrag && Math.abs(dx) >= 50) { goToSlide(currentIndex + (dx < 0 ? 1 : -1)); restartAutoplay(); }
            });
        })();

        
        var dotsEl = carousel.querySelector('.impulse-carousel-dots');
        if (dotsEl) {
            dotsEl.addEventListener('click', function(e) {
                var btn = e.target.closest('[data-slide]');
                if (btn) { goToSlide(parseInt(btn.dataset.slide)); restartAutoplay(); }
            });
        }
    });
    } 
    window.ImpulseSliderInit = initNewSliders;
    initNewSliders();

    
    document.querySelectorAll('.impulse-carousel:not(.impulse-product-carousel)').forEach(function(carousel) {
        
        if (carousel.classList.contains('impulse-image-carousel')) return;
        if (carousel.classList.contains('impulse-new-slider')) return;
        
        var track = carousel.querySelector('.impulse-carousel-slides');
        var slides = track.querySelectorAll('.impulse-carousel-slide, [style*="flex:0 0"]');
        var dotsContainer = carousel.querySelector('.impulse-carousel-dots');
        var autoplay = carousel.dataset.autoplay === 'true';
        var autoplaySpeed = parseInt(carousel.dataset.speed) || 5000;
        var pauseOnHover = carousel.dataset.pause === 'true';
        var currentIndex = 0;
        var slideCount = slides.length;
        var autoplayTimer = null;
        
        if (slideCount <= 1) return;
        
        
        var w = window.innerWidth;
        var spv = parseInt(carousel.dataset.slidesPerView) || 1;
        if (w <= 768 && carousel.dataset.slidesPerViewMobile) spv = parseInt(carousel.dataset.slidesPerViewMobile);
        else if (w <= 1024 && carousel.dataset.slidesPerViewTablet) spv = parseInt(carousel.dataset.slidesPerViewTablet);
        
        
        var slideWidth = slides[0] ? parseFloat(slides[0].style.flex.split(' ')[2]) : (100 / spv);
        var visibleSlides = Math.round(100 / slideWidth);
        var maxIndex = Math.max(0, slideCount - visibleSlides);
        
        function goToSlide(index) {
            currentIndex = Math.max(0, Math.min(index, maxIndex));
            track.style.transform = 'translateX(-' + (currentIndex * slideWidth) + '%)';
            updateDots();
        }
        
        function updateDots() {
            if (!dotsContainer) return;
            dotsContainer.querySelectorAll('button, span').forEach(function(dot, i) {
                dot.style.background = i === currentIndex ? '#1d2327' : '#ddd';
            });
        }
        
        
        if (dotsContainer && dotsContainer.children.length === 0) {
            for (var i = 0; i <= maxIndex; i++) {
                var dot = document.createElement('button');
                dot.style.cssText = 'width:10px;height:10px;border-radius:50%;border:none;cursor:pointer;background:' + (i === 0 ? '#1d2327' : '#ddd');
                dot.dataset.slide = i;
                dotsContainer.appendChild(dot);
            }
        }
        
        
        attachCarouselDrag(track,
            function(delta) {
                if (Math.abs(delta) >= 50) {
                    goToSlide(currentIndex + (delta < 0 ? 1 : -1));
                } else {
                    track.style.transform = 'translateX(-' + (currentIndex * slideWidth) + '%)';
                }
            },
            function(delta) {
                var base = -(currentIndex * slideWidth);
                track.style.transition = 'none';
                track.style.transform = 'translateX(calc(' + base + '% + ' + delta + 'px))';
            }
        );
        
        if (dotsContainer) {
            dotsContainer.addEventListener('click', function(e) {
                if (e.target.dataset.slide !== undefined) {
                    goToSlide(parseInt(e.target.dataset.slide));
                }
            });
        }
        
        
        function startAutoplay() {
            if (autoplay && !autoplayTimer) {
                autoplayTimer = setInterval(function() {
                    goToSlide(currentIndex >= maxIndex ? 0 : currentIndex + 1);
                }, autoplaySpeed);
            }
        }
        function stopAutoplay() {
            if (autoplayTimer) { clearInterval(autoplayTimer); autoplayTimer = null; }
        }
        if (autoplay) {
            startAutoplay();
            if (pauseOnHover) {
                carousel.addEventListener('mouseenter', stopAutoplay);
                carousel.addEventListener('mouseleave', startAutoplay);
            }
        }
    });
    

    
    
    
    
    var staggerLists = document.querySelectorAll('.impulse-table-stagger');
    if (staggerLists.length > 0 && 'IntersectionObserver' in window) {
        var staggerObs = new IntersectionObserver(function(entries) {
            entries.forEach(function(entry) {
                if (entry.isIntersecting) {
                    entry.target.classList.add('impulse-in-view');
                    staggerObs.unobserve(entry.target);
                }
            });
        }, { threshold: 0.1 });
        staggerLists.forEach(function(el) { staggerObs.observe(el); });
    } else {
        staggerLists.forEach(function(el) { el.classList.add('impulse-in-view'); });
    }
    
    
    (function() {
        var dtEls = document.querySelectorAll('.impulse-display-text[data-dt-entrance], .impulse-display-text[data-dt-scroll]');
        if (!dtEls.length || !('IntersectionObserver' in window)) return;
        
        
        function wrapWords(el) {
            var tag = el.querySelector('h1,h2,h3,h4,h5,h6,p,div');
            if (!tag) return [];
            var text = tag.textContent;
            var words = text.split(/(\s+)/);
            tag.innerHTML = '';
            var spans = [];
            words.forEach(function(w) {
                if (/^\s+$/.test(w)) {
                    tag.appendChild(document.createTextNode(w));
                } else {
                    var s = document.createElement('span');
                    s.className = 'impulse-dt-word';
                    s.style.display = 'inline-block';
                    s.textContent = w;
                    tag.appendChild(s);
                    spans.push(s);
                }
            });
            return spans;
        }
        function wrapChars(el) {
            var tag = el.querySelector('h1,h2,h3,h4,h5,h6,p,div');
            if (!tag) return [];
            var text = tag.textContent;
            tag.innerHTML = '';
            var spans = [];
            for (var i = 0; i < text.length; i++) {
                if (text[i] === ' ') {
                    tag.appendChild(document.createTextNode(' '));
                } else {
                    var s = document.createElement('span');
                    s.className = 'impulse-dt-char';
                    s.style.display = 'inline-block';
                    s.textContent = text[i];
                    tag.appendChild(s);
                    spans.push(s);
                }
            }
            return spans;
        }
        
        
        var dtEntObs = new IntersectionObserver(function(entries) {
            entries.forEach(function(entry) {
                if (!entry.isIntersecting) return;
                var el = entry.target;
                if (el.dataset.dtAnimated) return;
                el.dataset.dtAnimated = '1';
                dtEntObs.unobserve(el);
                
                var entrance = el.dataset.dtEntrance;
                var dur = parseInt(el.dataset.dtDuration) || 800;
                var stagger = parseInt(el.dataset.dtStagger) || 40;
                var tag = el.querySelector('h1,h2,h3,h4,h5,h6,p,div');
                if (!tag) return;
                
                if (entrance === 'fade_up') {
                    tag.style.transition = 'opacity ' + dur + 'ms ease-in-out, transform ' + dur + 'ms ease-in-out';
                    tag.style.opacity = '0';
                    tag.style.transform = 'translateY(30px)';
                    requestAnimationFrame(function() {
                        requestAnimationFrame(function() {
                            tag.style.opacity = '1';
                            tag.style.transform = 'translateY(0)';
                        });
                    });
                } else if (entrance === 'mask_reveal') {
                    el.style.overflow = 'hidden';
                    tag.style.transition = 'transform ' + dur + 'ms cubic-bezier(0.4, 0, 0.2, 1)';
                    tag.style.transform = 'translateY(110%)';
                    requestAnimationFrame(function() {
                        requestAnimationFrame(function() {
                            tag.style.transform = 'translateY(0)';
                        });
                    });
                } else if (entrance === 'blur_in') {
                    tag.style.transition = 'opacity ' + dur + 'ms ease-in-out, filter ' + dur + 'ms ease-in-out';
                    tag.style.opacity = '0';
                    tag.style.filter = 'blur(12px)';
                    requestAnimationFrame(function() {
                        requestAnimationFrame(function() {
                            tag.style.opacity = '1';
                            tag.style.filter = 'blur(0)';
                        });
                    });
                } else if (entrance === 'char_stagger') {
                    var chars = wrapChars(el);
                    chars.forEach(function(c, i) {
                        c.style.opacity = '0';
                        c.style.transform = 'translateY(20px)';
                        c.style.transition = 'opacity ' + (dur * 0.6) + 'ms ease-in-out ' + (i * stagger) + 'ms, transform ' + (dur * 0.6) + 'ms ease-in-out ' + (i * stagger) + 'ms';
                    });
                    requestAnimationFrame(function() {
                        requestAnimationFrame(function() {
                            chars.forEach(function(c) {
                                c.style.opacity = '1';
                                c.style.transform = 'translateY(0)';
                            });
                        });
                    });
                } else if (entrance === 'word_stagger') {
                    var words = wrapWords(el);
                    words.forEach(function(w, i) {
                        w.style.opacity = '0';
                        w.style.transform = 'translateY(20px)';
                        w.style.transition = 'opacity ' + (dur * 0.6) + 'ms ease-in-out ' + (i * stagger) + 'ms, transform ' + (dur * 0.6) + 'ms ease-in-out ' + (i * stagger) + 'ms';
                    });
                    requestAnimationFrame(function() {
                        requestAnimationFrame(function() {
                            words.forEach(function(w) {
                                w.style.opacity = '1';
                                w.style.transform = 'translateY(0)';
                            });
                        });
                    });
                }
            });
        }, { threshold: 0.15 });
        
        dtEls.forEach(function(el) {
            
            if (el.dataset.dtEntrance) {
                var tag = el.querySelector('h1,h2,h3,h4,h5,h6,p,div');
                if (tag) {
                    var ent = el.dataset.dtEntrance;
                    if (ent === 'fade_up') { tag.style.opacity = '0'; tag.style.transform = 'translateY(30px)'; }
                    else if (ent === 'mask_reveal') { el.style.overflow = 'hidden'; tag.style.transform = 'translateY(110%)'; }
                    else if (ent === 'blur_in') { tag.style.opacity = '0'; tag.style.filter = 'blur(12px)'; }
                    else if (ent === 'char_stagger' || ent === 'word_stagger') { tag.style.opacity = '0'; }
                }
                dtEntObs.observe(el);
            }
        });
        
        
        var scrollEls = [];
        dtEls.forEach(function(el) {
            if (!el.dataset.dtScroll || el.dataset.dtScroll === 'none') return;
            var scrollType = el.dataset.dtScroll;
            
            if (scrollType === 'word_reveal') {
                var words = wrapWords(el);
                var fromColor = el.dataset.dtRevealFrom || 'rgba(0,0,0,0.15)';
                var toColor = el.dataset.dtRevealTo || '#1d2327';
                words.forEach(function(w) {
                    w.style.color = fromColor;
                    w.style.transition = 'color 0.3s ease-in-out';
                });
                scrollEls.push({ el: el, type: 'word_reveal', words: words, from: fromColor, to: toColor });
            } else if (scrollType === 'parallax') {
                scrollEls.push({ el: el, type: 'parallax' });
            }
        });
        
        if (scrollEls.length) {
            var ticking = false;
            function onScroll() {
                if (ticking) return;
                ticking = true;
                requestAnimationFrame(function() {
                    ticking = false;
                    var vh = window.innerHeight;
                    scrollEls.forEach(function(item) {
                        var rect = item.el.getBoundingClientRect();
                        
                        var progress = Math.max(0, Math.min(1, 1 - (rect.top / vh)));
                        
                        if (item.type === 'word_reveal') {
                            var total = item.words.length;
                            
                            var adjProgress = Math.max(0, Math.min(1, (progress - 0.2) / 0.6));
                            var revealCount = Math.floor(adjProgress * total);
                            item.words.forEach(function(w, i) {
                                w.style.color = i < revealCount ? item.to : item.from;
                            });
                        } else if (item.type === 'parallax') {
                            var tag = item.el.querySelector('h1,h2,h3,h4,h5,h6,p,div');
                            if (tag) {
                                var offset = (progress - 0.5) * 40;
                                tag.style.transform = 'translateY(' + offset + 'px)';
                            }
                        }
                    });
                });
            }
            window.addEventListener('scroll', onScroll, { passive: true });
            onScroll();
        }
    })();
    
    
    (function() {
        var depthEls = document.querySelectorAll('.impulse-display-text[data-dt-perspective]');
        if (!depthEls.length) return;
        
        depthEls.forEach(function(el) {
            
            if (el.dataset.dt3dMode || el.getAttribute('data-dt-3d-mode')) return;
            
            var tag = el.querySelector('h1,h2,h3,h4,h5,h6,p,div');
            if (!tag) return;
            
            
            var lineEls = Array.prototype.slice.call(tag.querySelectorAll('.impulse-dt-line'));
            if (lineEls.length < 1) return;
            
            var perspVal = parseInt(el.dataset.dtPerspective) || 800;
            var hasMouse = el.dataset.dtMouse === '1';
            var dofVal = el.dataset.dtDof ? parseInt(el.dataset.dtDof) / 100 : 0;
            var chromVal = el.dataset.dtChromatic ? parseInt(el.dataset.dtChromatic) / 100 : 0;
            var hasScatter = el.dataset.dtScatter === '1';
            var hasShadow = el.dataset.dtShadow === '1';
            var hasOrbit = el.dataset.dtOrbit === '1';
            var orbitActive = false;
            var total = lineEls.length;
            
            
            tag.style.perspective = perspVal + 'px';
            tag.style.transformStyle = 'preserve-3d';
            
            
            var maxAbsDepth = 0;
            lineEls.forEach(function(line, i) {
                var z = parseInt(line.dataset.depth) || 0;
                line.dataset.baseZ = z;
                line.dataset.idx = i;
                line.style.transformStyle = 'preserve-3d';
                line.style.willChange = 'transform,filter';
                line.style.transform = 'translateZ(' + z + 'px)';
                if (Math.abs(z) > maxAbsDepth) maxAbsDepth = Math.abs(z);
            });
            

            

            
            function _alphaZero(c) {
                if (!c) return false;
                if (c === 'transparent') return true;
                var m = c.match(/rgba?\([^)]*,\s*([\d.]+)\s*\)/i);
                return !!(m && parseFloat(m[1]) === 0);
            }
            function _fillIsInvisible(line) {
                var fill = line.getAttribute('data-fill') || '';
                if (fill === 'gradient') {
                    return _alphaZero(line.getAttribute('data-grad-1') || '')
                        && _alphaZero(line.getAttribute('data-grad-2') || '');
                }
                return _alphaZero(line.getAttribute('data-color') || '');
            }

            
            function applyShadows(line, absRatio, signedRatio, mx) {
                if (_fillIsInvisible(line)) { line.style.textShadow = ''; return; }
                mx = mx || 0;
                var shadows = [];
                if (chromVal > 0) {
                    var offset = chromVal * 5;
                    var r = ((signedRatio + mx * 0.5) * offset).toFixed(1);
                    var b = ((-signedRatio + mx * 0.5) * offset).toFixed(1);
                    var alpha = (chromVal * 0.4).toFixed(2);
                    shadows.push(r + 'px 0 0 rgba(255,0,50,' + alpha + ')');
                    shadows.push(b + 'px 0 0 rgba(0,80,255,' + alpha + ')');
                }
                if (hasShadow) {
                    var sBlur = (absRatio * 8 + 2).toFixed(0);
                    var sY = (absRatio * 4 + 1).toFixed(0);
                    var sAlpha = (0.15 + absRatio * 0.25).toFixed(2);
                    shadows.push('0 ' + sY + 'px ' + sBlur + 'px rgba(0,0,0,' + sAlpha + ')');
                }
                line.style.textShadow = shadows.length ? shadows.join(',') : '';
            }
            
            
            lineEls.forEach(function(line) {
                var z = parseFloat(line.dataset.baseZ) || 0;
                var absRatio = maxAbsDepth > 0 ? Math.abs(z) / maxAbsDepth : 0;
                var signedRatio = maxAbsDepth > 0 ? z / maxAbsDepth : 0;
                if (dofVal > 0) line.style.filter = 'blur(' + (absRatio * dofVal * 5).toFixed(1) + 'px)';
                if (chromVal > 0 || hasShadow) applyShadows(line, absRatio, signedRatio, 0);
            });
            
            function resetLines() {
                lineEls.forEach(function(line) {
                    var baseZ = parseFloat(line.dataset.baseZ) || 0;
                    var absRatio = maxAbsDepth > 0 ? Math.abs(baseZ) / maxAbsDepth : 0;
                    var signedRatio = maxAbsDepth > 0 ? baseZ / maxAbsDepth : 0;
                    line.style.transition = 'transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), filter 0.4s ease-in-out, text-shadow 0.4s ease-in-out';
                    line.style.transform = 'translateZ(' + baseZ + 'px)';
                    if (dofVal > 0) line.style.filter = 'blur(' + (absRatio * dofVal * 5).toFixed(1) + 'px)';
                    if (chromVal > 0 || hasShadow) applyShadows(line, absRatio, signedRatio, 0);
                });
            }
            
            
            var orbitFrame = null, orbitT = 0;
            function orbitLoop() {
                if (!orbitActive) return;
                orbitT += 0.015;
                lineEls.forEach(function(line, i) {
                    var baseZ = parseFloat(line.dataset.baseZ) || 0;
                    var phase = (i / total) * Math.PI * 2;
                    var r = maxAbsDepth * 0.4;
                    line.style.transition = 'none';
                    line.style.transform = 'translateZ(' + baseZ + 'px) translateX(' + (Math.sin(orbitT + phase) * r * 0.6).toFixed(1) + 'px) translateY(' + (Math.cos(orbitT * 0.7 + phase) * r * 0.25).toFixed(1) + 'px) rotateY(' + (Math.sin(orbitT + phase) * 8).toFixed(1) + 'deg) rotateX(' + (Math.cos(orbitT * 0.5 + phase) * 4).toFixed(1) + 'deg)';
                });
                orbitFrame = requestAnimationFrame(orbitLoop);
            }
            
            
            if (hasMouse || hasOrbit) {
                
                function applyParallax(mx, my) {
                    lineEls.forEach(function(line) {
                        var baseZ = parseFloat(line.dataset.baseZ) || 0;
                        var absRatio = maxAbsDepth > 0 ? Math.abs(baseZ) / maxAbsDepth : 0;
                        var signedRatio = maxAbsDepth > 0 ? baseZ / maxAbsDepth : 0;
                        var tx = mx * 35 * signedRatio;
                        var ty = my * 12 * signedRatio;
                        line.style.transition = 'transform 80ms linear';
                        line.style.transform = 'translateZ(' + baseZ + 'px) translateX(' + tx.toFixed(1) + 'px) translateY(' + ty.toFixed(1) + 'px)';
                        if (dofVal > 0) line.style.filter = 'blur(' + (absRatio * dofVal * 5 * (1 + Math.abs(mx) * 0.8)).toFixed(1) + 'px)';
                        if (chromVal > 0 || hasShadow) applyShadows(line, absRatio, signedRatio, mx);
                    });
                }
                
                
                var scope = el.closest('.impulse-section') || el.closest('.impulse-el[data-type="section"]') || el.parentElement;
                var cachedRect = null;
                scope.addEventListener('mouseenter', function(e) {
                    if (hasMouse) {
                        cachedRect = scope.getBoundingClientRect();
                    } else if (hasOrbit) {
                        orbitActive = true; orbitT = 0; orbitLoop();
                    }
                });
                if (hasMouse) {
                    scope.addEventListener('mousemove', function(e) {
                        if (!cachedRect) cachedRect = scope.getBoundingClientRect();
                        var mx = (e.clientX - cachedRect.left) / cachedRect.width - 0.5;
                        var my = (e.clientY - cachedRect.top) / cachedRect.height - 0.5;
                        applyParallax(mx, my);
                    });
                    
                    
                    var touchActive = false;
                    scope.addEventListener('touchstart', function(e) {
                        touchActive = true;
                        cachedRect = scope.getBoundingClientRect();
                    }, { passive: true });
                    scope.addEventListener('touchmove', function(e) {
                        if (!touchActive || !cachedRect) return;
                        var t = e.touches[0];
                        var mx = (t.clientX - cachedRect.left) / cachedRect.width - 0.5;
                        var my = (t.clientY - cachedRect.top) / cachedRect.height - 0.5;
                        mx = Math.max(-0.5, Math.min(0.5, mx));
                        my = Math.max(-0.5, Math.min(0.5, my));
                        applyParallax(mx, my);
                    }, { passive: true });
                    scope.addEventListener('touchend', function() {
                        touchActive = false;
                        resetLines();
                    }, { passive: true });
                    
                    
                    if ('DeviceOrientationEvent' in window && 'ontouchstart' in window) {
                        var gyroReady = false;
                        
                        if (typeof DeviceOrientationEvent.requestPermission === 'function') {
                            el.addEventListener('touchstart', function gyroPermission() {
                                DeviceOrientationEvent.requestPermission().then(function(state) {
                                    if (state === 'granted') gyroReady = true;
                                }).catch(function(){});
                                el.removeEventListener('touchstart', gyroPermission);
                            }, { once: true });
                        } else {
                            gyroReady = true;
                        }
                        var gyroSmooth = { mx: 0, my: 0 };
                        window.addEventListener('deviceorientation', function(e) {
                            if (!gyroReady || !hasMouse) return;
                            
                            var gx = (e.gamma || 0) / 45; 
                            var gy = ((e.beta || 0) - 45) / 45; 
                            gx = Math.max(-1, Math.min(1, gx)) * 0.5;
                            gy = Math.max(-1, Math.min(1, gy)) * 0.5;
                            
                            gyroSmooth.mx += (gx - gyroSmooth.mx) * 0.12;
                            gyroSmooth.my += (gy - gyroSmooth.my) * 0.12;
                            applyParallax(gyroSmooth.mx, gyroSmooth.my);
                        });
                    }
                }
                scope.addEventListener('mouseleave', function() {
                    if (touchActive) return;
                    cachedRect = null;
                    if (orbitActive) { orbitActive = false; if (orbitFrame) cancelAnimationFrame(orbitFrame); }
                    resetLines();
                });
            }
            
            
            if (hasScatter && 'IntersectionObserver' in window) {
                var seed = 137.508;
                lineEls.forEach(function(line, i) {
                    line.style.opacity = '0';
                    var angle = ((i * seed) % 360) * Math.PI / 180;
                    var dist = 60 + i * 40;
                    line.style.transform = 'translateX(' + (Math.cos(angle) * dist).toFixed(0) + 'px) translateY(' + (Math.sin(angle) * dist * 0.5).toFixed(0) + 'px) translateZ(' + (-(50 + i * 20)).toFixed(0) + 'px) rotateX(' + (Math.sin(i * seed) * 25).toFixed(0) + 'deg) rotateY(' + (Math.cos(i * seed) * 30).toFixed(0) + 'deg)';
                });
                var scObs = new IntersectionObserver(function(entries) {
                    entries.forEach(function(entry) {
                        if (!entry.isIntersecting || el.dataset.dtScattered) return;
                        el.dataset.dtScattered = '1';
                        scObs.unobserve(el);
                        lineEls.forEach(function(line, i) {
                            var baseZ = parseFloat(line.dataset.baseZ) || 0;
                            setTimeout(function() {
                                line.style.transition = 'transform 1.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease-in-out';
                                line.style.opacity = '1';
                                line.style.transform = 'translateZ(' + baseZ + 'px)';
                            }, i * 150);
                        });
                    });
                }, { threshold: 0.1 });
                scObs.observe(el);
            }
            
        });
    })();
    
    
    (function() {
        var ibEls = document.querySelectorAll('.impulse-icon[data-ib-perspective]');
        if (!ibEls.length) return;
        
        ibEls.forEach(function(container) {
            var layers = Array.prototype.slice.call(container.querySelectorAll('.impulse-ib-layer'));
            if (layers.length < 1) return;
            
            var perspVal = parseInt(container.dataset.ibPerspective) || 800;
            var hasMouse = container.dataset.ibMouse === '1';
            var dofVal = container.dataset.ibDof ? parseInt(container.dataset.ibDof) / 100 : 0;
            var chromVal = container.dataset.ibChromatic ? parseInt(container.dataset.ibChromatic) / 100 : 0;
            var hasShadow = container.dataset.ibShadow === '1';
            var hasOrbit = container.dataset.ibOrbit === '1';
            var hasScatter = container.dataset.ibScatter === '1';
            var orbitActive = false;
            var total = layers.length;
            
            container.style.perspective = perspVal + 'px';
            container.style.transformStyle = 'preserve-3d';
            
            var maxAbsDepth = 0;
            layers.forEach(function(layer) {
                var z = parseInt(layer.dataset.depth) || 0;
                layer.dataset.baseZ = z;
                layer.style.transformStyle = 'preserve-3d';
                layer.style.willChange = 'transform,filter';
                layer.style.transform = 'translateZ(' + z + 'px)';
                if (Math.abs(z) > maxAbsDepth) maxAbsDepth = Math.abs(z);
            });
            
            function applyShadows(layer, absRatio, signedRatio, mx) {
                mx = mx || 0;
                var shadows = [];
                var isIcon = layer.classList.contains('impulse-icon-wrap');
                if (chromVal > 0) {
                    var offset = chromVal * 5;
                    var r = ((signedRatio + mx * 0.5) * offset).toFixed(1);
                    var b = ((-signedRatio + mx * 0.5) * offset).toFixed(1);
                    var alpha = (chromVal * 0.4).toFixed(2);
                    if (isIcon) {
                        var filters = [];
                        if (dofVal > 0) filters.push('blur(' + (absRatio * dofVal * 5).toFixed(1) + 'px)');
                        filters.push('drop-shadow(' + r + 'px 0 0 rgba(255,0,50,' + alpha + '))');
                        filters.push('drop-shadow(' + b + 'px 0 0 rgba(0,80,255,' + alpha + '))');
                        if (hasShadow) {
                            var sBlur = (absRatio * 8 + 2).toFixed(0);
                            var sY = (absRatio * 4 + 1).toFixed(0);
                            var sAlpha = (0.15 + absRatio * 0.25).toFixed(2);
                            filters.push('drop-shadow(0 ' + sY + 'px ' + sBlur + 'px rgba(0,0,0,' + sAlpha + '))');
                        }
                        layer.style.filter = filters.join(' ');
                        layer.style.textShadow = '';
                        return;
                    }
                    shadows.push(r + 'px 0 0 rgba(255,0,50,' + alpha + ')');
                    shadows.push(b + 'px 0 0 rgba(0,80,255,' + alpha + ')');
                }
                if (hasShadow) {
                    var sBlur = (absRatio * 8 + 2).toFixed(0);
                    var sY = (absRatio * 4 + 1).toFixed(0);
                    var sAlpha = (0.15 + absRatio * 0.25).toFixed(2);
                    if (isIcon) {
                        layer.style.filter = (dofVal > 0 ? 'blur(' + (absRatio * dofVal * 5).toFixed(1) + 'px) ' : '') + 'drop-shadow(0 ' + sY + 'px ' + sBlur + 'px rgba(0,0,0,' + sAlpha + '))';
                        layer.style.textShadow = '';
                        return;
                    }
                    shadows.push('0 ' + sY + 'px ' + sBlur + 'px rgba(0,0,0,' + sAlpha + ')');
                }
                layer.style.textShadow = shadows.length ? shadows.join(',') : '';
            }
            
            layers.forEach(function(layer) {
                var z = parseFloat(layer.dataset.baseZ) || 0;
                var absRatio = maxAbsDepth > 0 ? Math.abs(z) / maxAbsDepth : 0;
                var signedRatio = maxAbsDepth > 0 ? z / maxAbsDepth : 0;
                if (dofVal > 0 && !chromVal && !hasShadow) {
                    layer.style.filter = 'blur(' + (absRatio * dofVal * 5).toFixed(1) + 'px)';
                }
                if (chromVal > 0 || hasShadow) applyShadows(layer, absRatio, signedRatio, 0);
            });
            
            if (hasScatter) {
                layers.forEach(function(layer, i) {
                    var baseZ = parseFloat(layer.dataset.baseZ) || 0;
                    var angle = (i / total) * Math.PI * 2;
                    var dist = 120 + Math.random() * 80;
                    var sx = Math.cos(angle) * dist;
                    var sy = Math.sin(angle) * dist;
                    var sz = baseZ + (Math.random() - 0.5) * 200;
                    layer.style.transition = 'none';
                    layer.style.opacity = '0';
                    layer.style.transform = 'translateZ(' + sz + 'px) translateX(' + sx.toFixed(0) + 'px) translateY(' + sy.toFixed(0) + 'px) rotate(' + ((Math.random()-0.5)*40).toFixed(0) + 'deg)';
                    setTimeout(function() {
                        layer.style.transition = 'all 0.8s cubic-bezier(0.4, 0, 0.2, 1) ' + (i * 0.12) + 's';
                        layer.style.opacity = '1';
                        layer.style.transform = 'translateZ(' + baseZ + 'px)';
                    }, 50);
                });
            }
            
            function resetLayers() {
                layers.forEach(function(layer) {
                    var baseZ = parseFloat(layer.dataset.baseZ) || 0;
                    var absRatio = maxAbsDepth > 0 ? Math.abs(baseZ) / maxAbsDepth : 0;
                    var signedRatio = maxAbsDepth > 0 ? baseZ / maxAbsDepth : 0;
                    layer.style.transition = 'transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), filter 0.4s ease-in-out, text-shadow 0.4s ease-in-out';
                    layer.style.transform = 'translateZ(' + baseZ + 'px)';
                    if (dofVal > 0 && !chromVal && !hasShadow) {
                        layer.style.filter = 'blur(' + (absRatio * dofVal * 5).toFixed(1) + 'px)';
                    }
                    if (chromVal > 0 || hasShadow) applyShadows(layer, absRatio, signedRatio, 0);
                });
            }
            
            var orbitFrame = null, orbitT = 0;
            function orbitLoop() {
                if (!orbitActive) return;
                orbitT += 0.015;
                layers.forEach(function(layer, i) {
                    var baseZ = parseFloat(layer.dataset.baseZ) || 0;
                    var phase = (i / total) * Math.PI * 2;
                    var r = maxAbsDepth * 0.4;
                    layer.style.transition = 'none';
                    layer.style.transform = 'translateZ(' + baseZ + 'px) translateX(' + (Math.sin(orbitT + phase) * r * 0.6).toFixed(1) + 'px) translateY(' + (Math.cos(orbitT * 0.7 + phase) * r * 0.25).toFixed(1) + 'px) rotateY(' + (Math.sin(orbitT + phase) * 8).toFixed(1) + 'deg) rotateX(' + (Math.cos(orbitT * 0.5 + phase) * 4).toFixed(1) + 'deg)';
                });
                orbitFrame = requestAnimationFrame(orbitLoop);
            }
            
            if (hasMouse || hasOrbit) {
                function applyParallax(mx, my) {
                    layers.forEach(function(layer) {
                        var baseZ = parseFloat(layer.dataset.baseZ) || 0;
                        var absRatio = maxAbsDepth > 0 ? Math.abs(baseZ) / maxAbsDepth : 0;
                        var signedRatio = maxAbsDepth > 0 ? baseZ / maxAbsDepth : 0;
                        var tx = mx * 35 * signedRatio;
                        var ty = my * 12 * signedRatio;
                        var isIcon = layer.classList.contains('impulse-icon-wrap');
                        var tilt = isIcon ? ' rotateY(' + (mx * 12).toFixed(1) + 'deg) rotateX(' + (-my * 8).toFixed(1) + 'deg)' : '';
                        layer.style.transition = 'transform 80ms linear';
                        layer.style.transform = 'translateZ(' + baseZ + 'px) translateX(' + tx.toFixed(1) + 'px) translateY(' + ty.toFixed(1) + 'px)' + tilt;
                        if (dofVal > 0 && !chromVal && !hasShadow) {
                            layer.style.filter = 'blur(' + (absRatio * dofVal * 5 * (1 + Math.abs(mx) * 0.8)).toFixed(1) + 'px)';
                        }
                        if (chromVal > 0 || hasShadow) applyShadows(layer, absRatio, signedRatio, mx);
                    });
                }
                
                var scope = container.closest('.impulse-section') || container.parentElement;
                var cachedRect = null;
                scope.addEventListener('mouseenter', function(e) {
                    if (hasMouse) {
                        cachedRect = scope.getBoundingClientRect();
                    } else if (hasOrbit) {
                        orbitActive = true; orbitT = 0; orbitLoop();
                    }
                });
                if (hasMouse) {
                    scope.addEventListener('mousemove', function(e) {
                        if (!cachedRect) cachedRect = scope.getBoundingClientRect();
                        var mx = (e.clientX - cachedRect.left) / cachedRect.width - 0.5;
                        var my = (e.clientY - cachedRect.top) / cachedRect.height - 0.5;
                        applyParallax(mx, my);
                    });
                    
                    
                    var touchActive = false;
                    scope.addEventListener('touchstart', function(e) {
                        touchActive = true;
                        cachedRect = scope.getBoundingClientRect();
                    }, { passive: true });
                    scope.addEventListener('touchmove', function(e) {
                        if (!touchActive || !cachedRect) return;
                        var t = e.touches[0];
                        var mx = (t.clientX - cachedRect.left) / cachedRect.width - 0.5;
                        var my = (t.clientY - cachedRect.top) / cachedRect.height - 0.5;
                        mx = Math.max(-0.5, Math.min(0.5, mx));
                        my = Math.max(-0.5, Math.min(0.5, my));
                        applyParallax(mx, my);
                    }, { passive: true });
                    scope.addEventListener('touchend', function() {
                        touchActive = false;
                        resetLayers();
                    }, { passive: true });
                    
                    if ('DeviceOrientationEvent' in window && 'ontouchstart' in window) {
                        var gyroReady = false;
                        if (typeof DeviceOrientationEvent.requestPermission === 'function') {
                            container.addEventListener('touchstart', function gyroPermission() {
                                DeviceOrientationEvent.requestPermission().then(function(state) {
                                    if (state === 'granted') gyroReady = true;
                                }).catch(function(){});
                                container.removeEventListener('touchstart', gyroPermission);
                            }, { once: true });
                        } else {
                            gyroReady = true;
                        }
                        var gyroSmooth = { mx: 0, my: 0 };
                        window.addEventListener('deviceorientation', function(e) {
                            if (!gyroReady || !hasMouse) return;
                            var gx = (e.gamma || 0) / 45;
                            var gy = ((e.beta || 0) - 45) / 45;
                            gx = Math.max(-1, Math.min(1, gx)) * 0.5;
                            gy = Math.max(-1, Math.min(1, gy)) * 0.5;
                            gyroSmooth.mx += (gx - gyroSmooth.mx) * 0.12;
                            gyroSmooth.my += (gy - gyroSmooth.my) * 0.12;
                            applyParallax(gyroSmooth.mx, gyroSmooth.my);
                        });
                    }
                }
                scope.addEventListener('mouseleave', function() {
                    if (touchActive) return;
                    cachedRect = null;
                    if (orbitActive) { orbitActive = false; if (orbitFrame) cancelAnimationFrame(orbitFrame); }
                    resetLayers();
                });
            }
        });
    })();
    
    

    var revealEls = document.querySelectorAll('.impulse-reveal');
    if (revealEls.length > 0 && 'IntersectionObserver' in window) {
        var thresholds = [];
        for (var t = 0; t <= 20; t++) thresholds.push(t / 20);
        
        var revealObserver = new IntersectionObserver(function(entries) {
            entries.forEach(function(entry) {
                var el = entry.target;
                var reveal = el.dataset.reveal;
                var intensity = (parseInt(el.dataset.revealIntensity) || 50) / 100;
                var ratio = Math.min(entry.intersectionRatio * 2.5, 1);
                
                if (reveal === 'depth') {
                    var startScale = 1 - (0.08 * intensity);
                    var scale = startScale + (1 - startScale) * ratio;
                    el.style.transform = 'scale(' + scale.toFixed(4) + ')';
                    el.style.opacity = ratio;
                } else if (reveal === 'rise') {
                    var maxShift = 80 * intensity;
                    var shift = maxShift * (1 - ratio);
                    el.style.transform = 'translateY(' + shift.toFixed(1) + 'px)';
                    el.style.opacity = ratio;
                } else if (reveal === 'curtain') {
                    var clipPct = (1 - ratio) * 100;
                    el.style.clipPath = 'inset(' + clipPct.toFixed(1) + '% 0 0 0)';
                } else if (reveal === 'stack') {
                    if (ratio < 1) {
                        el.style.position = 'sticky';
                        el.style.top = '0';
                        el.style.zIndex = '10';
                    } else {
                        el.style.position = '';
                        el.style.top = '';
                        el.style.zIndex = '';
                    }
                }
            });
        }, { threshold: thresholds, rootMargin: '0px 0px -10% 0px' });
        
        revealEls.forEach(function(el) {
            
            if (el.querySelector('.impulse-display-text[data-dt-3d-mode]')) return;
            var reveal = el.dataset.reveal;
            var intensity = (parseInt(el.dataset.revealIntensity) || 50) / 100;
            if (reveal === 'depth') {
                el.style.transform = 'scale(' + (1 - 0.08 * intensity) + ')';
                el.style.opacity = '0';
            } else if (reveal === 'rise') {
                el.style.transform = 'translateY(' + (80 * intensity) + 'px)';
                el.style.opacity = '0';
            } else if (reveal === 'curtain') {
                el.style.clipPath = 'inset(100% 0 0 0)';
            }
            revealObserver.observe(el);
        });
    }
    
    }
    
    if (document.querySelector('.impulse-modal, .impulse-modal-drawer')) {
    
    document.querySelectorAll('.impulse-modal').forEach(function(popup) {
        var trigger = popup.dataset.trigger;
        var scrollPercent = parseInt(popup.dataset.scroll) || 50;
        var delay = parseInt(popup.dataset.delay) || 5;
        var oncePerSession = popup.dataset.once === '1';
        var closeOnOverlay = popup.dataset.closeOverlay !== '0';
        var buttonSelector = popup.dataset.button || '';
        var popupId = popup.id;
        var position = popup.dataset.position || 'center';
        var animation = popup.dataset.animation || 'fade';
        var autoDismiss = popup.dataset.autoDismiss === '1';
        var dismissAfterMs = (parseInt(popup.dataset.dismissAfter) || 4) * 1000;
        var container = popup.querySelector('.impulse-modal-container');
        
        if (oncePerSession && sessionStorage.getItem('popup-' + popupId)) {
            return;
        }
        

        

        var _edgePositions = ['top-center','bottom-center','center-left','center-right'];
        var _isEdge   = _edgePositions.indexOf(position) !== -1;
        var _isCorner = position.indexOf('-') !== -1 && !_isEdge && position !== 'center';

        function getVisibleTransform() {
            if (_isEdge || _isCorner) return 'translate(0,0)';
            return 'translate(-50%,-50%) scale(1)';
        }
        
        var _centrePrefix = (position === 'center') ? 'translate(-50%,-50%) ' : '';
        
        function getHiddenState() {
            if (animation === 'slide') {

                

                if (position === 'center-right')  return { transform: 'translateX(100%)',  filter: '', opacity: 1 };
                if (position === 'center-left')   return { transform: 'translateX(-100%)', filter: '', opacity: 1 };
                if (position === 'bottom-center') return { transform: 'translateY(100%)',  filter: '', opacity: 1 };
                if (position === 'top-center')    return { transform: 'translateY(-100%)', filter: '', opacity: 1 };
                
                return { transform: _centrePrefix + 'scale(0.98)', filter: '', opacity: 0 };
            }
            if (animation === 'depth') {
                
                return { transform: _centrePrefix + 'perspective(1200px) translateZ(-420px)', filter: 'blur(14px)', opacity: 0 };
            }
            if (animation === 'tilt-fall') {
                
                return { transform: _centrePrefix + 'perspective(1200px) rotateZ(-6deg) translateY(-44px)', filter: '', opacity: 0 };
            }
            if (animation === 'glass') {
                
                return { transform: _centrePrefix + 'scale(1.04)', filter: 'blur(20px) saturate(1.3)', opacity: 0 };
            }

            return { transform: _centrePrefix + 'perspective(1200px) translateZ(-120px)', filter: 'blur(4px)', opacity: 0 };
        }
        

        function ensureGlassCss() {
            if (document.getElementById('impulse-modal-glass-css')) return;
            var st = document.createElement('style');
            st.id = 'impulse-modal-glass-css';
            st.textContent = '.impulse-modal-glass{backdrop-filter:blur(18px) saturate(1.4);-webkit-backdrop-filter:blur(18px) saturate(1.4)}';
            document.head.appendChild(st);
        }

        
        var _parallaxHandler = null;
        function attachParallax() {
            if (!container || animation !== 'parallax' || _parallaxHandler) return;
            var tx = 0, ty = 0, cx = 0, cy = 0, raf = null;
            _parallaxHandler = function(e) {
                var rect = container.getBoundingClientRect();
                var nx = ((e.clientX - rect.left) / rect.width  - 0.5) * 2;  
                var ny = ((e.clientY - rect.top)  / rect.height - 0.5) * 2;
                tx = Math.max(-1, Math.min(1, nx));
                ty = Math.max(-1, Math.min(1, ny));
                if (!raf) raf = requestAnimationFrame(function tick(){
                    cx += (tx - cx) * 0.12;
                    cy += (ty - cy) * 0.12;
                    var rx = (-cy * 4).toFixed(2);
                    var ry = ( cx * 4).toFixed(2);
                    container.style.transform = _centrePrefix + 'perspective(1200px) rotateX(' + rx + 'deg) rotateY(' + ry + 'deg)';
                    if (Math.abs(tx-cx) > 0.005 || Math.abs(ty-cy) > 0.005) raf = requestAnimationFrame(tick);
                    else raf = null;
                });
            };
            window.addEventListener('mousemove', _parallaxHandler, { passive: true });
        }
        function detachParallax() {
            if (_parallaxHandler) { window.removeEventListener('mousemove', _parallaxHandler); _parallaxHandler = null; }
        }

        function showPopup() {

            

            if (popup.parentNode !== document.body) {
                popup._originalParent = popup.parentNode;
                popup._originalNextSibling = popup.nextSibling;
                document.body.appendChild(popup);
            }

            

            

            document.body.classList.add('impulse-modal-open');
            popup.style.display = 'block';
            popup.style.opacity = '0';
            if (container) {
                var h = getHiddenState();
                container.style.opacity = String(h.opacity);
                container.style.transform = h.transform;
                container.style.filter = h.filter || '';
                if (animation === 'glass') {
                    ensureGlassCss();
                    container.classList.add('impulse-modal-glass');
                }
            }
            requestAnimationFrame(function() {
                popup.style.transition = 'opacity 0.25s ease-in-out';
                popup.style.opacity = '1';
                if (container) {
                    
                    var curve = animation === 'tilt-fall' ? 'cubic-bezier(0.4, 0, 0.2, 1)' : 'cubic-bezier(0.4, 0, 0.2, 1)';
                    container.style.transition = 'opacity 0.4s ease-in-out, transform 0.45s ' + curve + ', filter 0.4s ease-in-out';
                    container.style.opacity = '1';
                    container.style.transform = getVisibleTransform();
                    container.style.filter = '';
                }
            });
            if (animation === 'parallax') {
                
                setTimeout(attachParallax, 500);
            }

            
            
            setTimeout(function() {
                if (window.impulseLogoAnimatorRunAll) {
                    
                    popup.querySelectorAll('.impulse-logo-animator').forEach(function(a) { a._laInited = false; });
                    window.impulseLogoAnimatorRunAll();
                }
                if (window.Impulse3DText && window.Impulse3DText.init) {
                    popup.querySelectorAll('.impulse-el[data-type="title"]').forEach(function(el) {
                        var id = el.dataset.id;
                        if (id) { try { window.Impulse3DText.init(parseInt(id)); } catch(_e) {} }
                    });
                }
            }, 50);
            if (oncePerSession) {
                sessionStorage.setItem('popup-' + popupId, '1');
            }
            
            if (popup._dismissTimer) { clearTimeout(popup._dismissTimer); popup._dismissTimer = null; }
            if (autoDismiss) {
                popup._dismissTimer = setTimeout(function(){
                    popup._dismissTimer = null;
                    hidePopup();
                }, dismissAfterMs);
            }
        }

        function hidePopup() {
            if (popup._dismissTimer) { clearTimeout(popup._dismissTimer); popup._dismissTimer = null; }
            detachParallax();
            popup.style.transition = 'opacity 0.2s ease-in-out';
            popup.style.opacity = '0';
            if (container) {
                var h2 = getHiddenState();
                container.style.transition = 'opacity 0.2s ease-in-out, transform 0.25s ease-in-out, filter 0.2s ease-in-out';
                container.style.transform = h2.transform;
                container.style.filter = h2.filter || '';
                container.style.opacity = String(h2.opacity);
            }
            setTimeout(function() {
                popup.style.display = 'none';
                popup.style.transition = '';

                

                
                
                if (!document.querySelector('.impulse-modal[style*="display: block"], .impulse-modal[style*="display:block"]')) {
                    document.body.classList.remove('impulse-modal-open');
                }
                if (container) {
                    container.style.transition = '';
                    container.style.filter = '';
                    if (animation === 'glass') container.classList.remove('impulse-modal-glass');
                }

                if (popup._originalParent) {
                    try {
                        popup._originalParent.insertBefore(popup, popup._originalNextSibling || null);
                    } catch (e) {  }
                    popup._originalParent = null;
                    popup._originalNextSibling = null;
                }
            }, 250);
        }
        
        
        var closeBtn = popup.querySelector('.impulse-modal-close');
        if (closeBtn) {
            closeBtn.addEventListener('click', hidePopup);
        }
        
        
        if (closeOnOverlay) {
            popup.addEventListener('click', function(e) {
                if (e.target === popup) hidePopup();
            });
        }
        
        
        document.addEventListener('keydown', function(e) {
            if (e.key === 'Escape' && popup.style.display === 'block') {
                hidePopup();
            }
        });
        
        
        if (trigger === 'timer') {
            setTimeout(showPopup, delay * 1000);
        } else if (trigger === 'scroll') {
            var scrollTriggered = false;
            window.addEventListener('scroll', function() {
                if (scrollTriggered) return;
                var scrolled = (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100;
                if (scrolled >= scrollPercent) {
                    scrollTriggered = true;
                    showPopup();
                }
            });
        } else if (trigger === 'exit') {
            document.addEventListener('mouseout', function(e) {
                if (e.clientY < 10 && popup.style.display !== 'block') {
                    showPopup();
                }
            });
        } else if (trigger === 'click') {
            
            document.querySelectorAll('a[href="#' + popupId + '"], button[data-link="#' + popupId + '"]').forEach(function(triggerEl) {
                triggerEl.addEventListener('click', function(e) {
                    e.preventDefault();
                    showPopup();
                });
            });
            
            document.querySelectorAll('[data-popup-trigger="' + popupId + '"]').forEach(function(triggerEl) {
                triggerEl.addEventListener('click', function(e) {
                    e.preventDefault();
                    showPopup();
                });
            });
            
            if (buttonSelector) {
                try {
                    document.querySelectorAll(buttonSelector).forEach(function(triggerEl) {
                        triggerEl.style.cursor = 'pointer';
                        triggerEl.addEventListener('click', function(e) {
                            e.preventDefault();
                            showPopup();
                        });
                    });
                } catch(err) {}
            }
        }
    });
    
    
    document.querySelectorAll('.impulse-modal-drawer').forEach(function(panel) {
        var ocId = panel.id;
        var position = panel.dataset.position || 'right';
        var overlay = document.querySelector('.impulse-modal-drawer-overlay[data-target="' + ocId + '"]');
        
        function openOC() {
            panel.style.transform = 'translateX(0)';
            if (overlay) {
                overlay.style.display = 'block';
                requestAnimationFrame(function() { overlay.style.opacity = '1'; });
            }
            document.body.style.overflow = 'hidden';
        }
        function closeOC() {
            panel.style.transform = 'translateX(' + (position === 'left' ? '-100%' : '100%') + ')';
            if (overlay) {
                overlay.style.opacity = '0';
                setTimeout(function() { overlay.style.display = 'none'; }, 300);
            }
            document.body.style.overflow = '';
        }
        
        
        var closeBtn = panel.querySelector('.impulse-modal-drawer-close');
        if (closeBtn) closeBtn.addEventListener('click', closeOC);
        
        
        if (overlay && overlay.dataset.close === '1') {
            overlay.addEventListener('click', closeOC);
        }
        
        
        document.addEventListener('keydown', function(e) {
            if (e.key === 'Escape' && panel.style.transform === 'translateX(0)') closeOC();
        });
        
        
        document.querySelectorAll('a[href="#' + ocId + '"], button[data-link="#' + ocId + '"]').forEach(function(triggerEl) {
            triggerEl.addEventListener('click', function(e) {
                e.preventDefault();
                openOC();
            });
        });
    });
    
    
    document.querySelectorAll('.impulse-form').forEach(function(form) {
        form.addEventListener('submit', function(e) {
            e.preventDefault();
            
            var submitBtn = form.querySelector('button[type="submit"]');
            var originalText = submitBtn.textContent;
            var action = form.dataset.action;
            var successMessage = form.dataset.success;
            var redirectUrl = form.dataset.redirect;
            
            
            submitBtn.textContent = 'Sending...';
            submitBtn.disabled = true;
            
            
            var formData = new FormData(form);
            formData.append('action', 'instinctor_submit_form');
            formData.append('nonce', window.ImpulseConfig && ImpulseConfig.nonce || '');
            
            fetch(window.ImpulseConfig && ImpulseConfig.ajaxUrl || '/wp-admin/admin-ajax.php', {
                method: 'POST',
                body: formData
            })
            .then(function(r) { return r.json(); })
            .then(function(data) {
                if (data.success) {
                    if (action === 'redirect' && redirectUrl) {
                        window.location.href = redirectUrl;
                    } else {
                        
                        var successDiv = document.createElement('div');
                        successDiv.style.cssText = 'padding:16px;background:#dcfce7;color:#166534;border-radius:8px;margin-top:16px;text-align:center';
                        successDiv.textContent = successMessage;
                        form.appendChild(successDiv);
                        
                        
                        form.reset();
                        submitBtn.textContent = originalText;
                        submitBtn.disabled = false;
                        
                        setTimeout(function() {
                            successDiv.remove();
                        }, 4000);
                    }
                } else {
                    submitBtn.textContent = 'Error';
                    setTimeout(function() {
                        submitBtn.textContent = originalText;
                        submitBtn.disabled = false;
                    }, 2000);
                }
            })
            .catch(function() {
                submitBtn.textContent = 'Error';
                setTimeout(function() {
                    submitBtn.textContent = originalText;
                    submitBtn.disabled = false;
                }, 2000);
            });
        });
    });
    
    
    document.querySelectorAll('.impulse-newsletter-form').forEach(function(form) {
        form.addEventListener('submit', function(e) {
            e.preventDefault();
            var email = form.querySelector('input[type="email"]').value;
            var btn = form.querySelector('button');
            var originalText = btn.textContent;
            
            btn.textContent = 'Subscribing...';
            btn.disabled = true;
            
            fetch(window.ImpulseConfig && ImpulseConfig.ajaxUrl || '/wp-admin/admin-ajax.php', {
                method: 'POST',
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                body: 'action=instinctor_newsletter_subscribe&email=' + encodeURIComponent(email)
            })
            .then(function(r) { return r.json(); })
            .then(function(data) {
                btn.textContent = data.success ? 'Subscribed!' : 'Error';
                if (data.success) {
                    form.reset();
                }
                setTimeout(function() {
                    btn.textContent = originalText;
                    btn.disabled = false;
                }, 2000);
            })
            .catch(function() {
                btn.textContent = 'Error';
                setTimeout(function() {
                    btn.textContent = originalText;
                    btn.disabled = false;
                }, 2000);
            });
        });
    });
    }
});

if (document.querySelector('.impulse-contact-form, .impulse-login-form, .impulse-register-form, .impulse-newsletter-form')) {
document.addEventListener('submit', function(e) {
    var form = e.target.closest('.impulse-contact-form');
    if (!form) return;
    e.preventDefault();
    var btn = form.querySelector('.impulse-form-submit');
    if (!btn || btn.disabled) return;
    var origText = btn.textContent;
    btn.disabled = true;
    btn.textContent = 'Sending...';
    btn.style.opacity = '0.6';
    var fd = new FormData(form);
    var ajaxUrl = (typeof instinctorFrontend !== 'undefined' && instinctorFrontend.ajaxUrl)
        ? instinctorFrontend.ajaxUrl
        : (window.ajaxurl || '/wp-admin/admin-ajax.php');
    fetch(ajaxUrl, { method: 'POST', body: fd })
        .then(function(r) { return r.json(); })
        .then(function(res) {
            btn.style.opacity = '1';
            if (res.success) {
                var msg = form.dataset.success || 'Thank you! Your message has been sent.';
                form.reset();
                
                var notice = document.createElement('div');
                notice.style.cssText = 'padding:12px 16px;background:#f0fdf4;color:#166534;border:1px solid #bbf7d0;border-radius:6px;font-size:14px;margin-top:8px;transition:opacity 0.5s';
                notice.textContent = msg;
                form.parentNode.insertBefore(notice, form.nextSibling);
                btn.textContent = origText;
                btn.disabled = false;
                setTimeout(function() { notice.style.opacity = '0'; setTimeout(function() { notice.remove(); }, 500); }, 4000);
            } else {
                btn.textContent = res.data && res.data.message ? res.data.message : 'Error. Please try again.';
                setTimeout(function() { btn.textContent = origText; btn.disabled = false; }, 3000);
            }
        })
        .catch(function() {
            btn.style.opacity = '1';
            btn.textContent = 'Error. Please try again.';
            setTimeout(function() { btn.textContent = origText; btn.disabled = false; }, 3000);
        });
});

document.addEventListener('submit', function(e) {
    var form = e.target.closest('.impulse-login-form');
    if (!form) return;
    e.preventDefault();
    var btn = form.querySelector('.impulse-form-submit');
    if (!btn || btn.disabled) return;
    var msgEl = form.querySelector('.impulse-form-message');
    var origText = btn.textContent;
    btn.disabled = true; btn.textContent = 'Signing in...'; btn.style.opacity = '0.6';
    if (msgEl) { msgEl.style.display = 'none'; msgEl.textContent = ''; }
    var fd = new FormData(form);
    fd.append('action', 'instinctor_ajax_login');
    var ajaxUrl = (typeof instinctorFrontend !== 'undefined' && instinctorFrontend.ajaxUrl)
        ? instinctorFrontend.ajaxUrl : (window.ajaxurl || '/wp-admin/admin-ajax.php');
    fetch(ajaxUrl, { method: 'POST', body: fd })
        .then(function(r) { return r.json(); })
        .then(function(res) {
            btn.style.opacity = '1';
            if (res.success) {
                btn.textContent = 'Success!';
                if (msgEl) { msgEl.style.display = 'block'; msgEl.style.background = '#f0fdf4'; msgEl.style.color = '#166534'; msgEl.style.border = '1px solid #bbf7d0'; msgEl.textContent = res.data.message || 'Login successful!'; }
                var redir = form.dataset.redirect || res.data.redirect || '';
                setTimeout(function() { window.location.href = redir || window.location.pathname; }, 800);
            } else {
                if (msgEl) { msgEl.style.display = 'block'; msgEl.style.background = '#fef2f2'; msgEl.style.color = '#991b1b'; msgEl.style.border = '1px solid #fecaca'; msgEl.textContent = res.data && res.data.message ? res.data.message : 'Login failed. Please try again.'; }
                btn.textContent = origText; btn.disabled = false;
            }
        })
        .catch(function() {
            btn.style.opacity = '1'; btn.textContent = origText; btn.disabled = false;
            if (msgEl) { msgEl.style.display = 'block'; msgEl.style.background = '#fef2f2'; msgEl.style.color = '#991b1b'; msgEl.style.border = '1px solid #fecaca'; msgEl.textContent = 'Connection error. Please try again.'; }
        });
});

document.addEventListener('submit', function(e) {
    var form = e.target.closest('.impulse-register-form');
    if (!form) return;
    e.preventDefault();
    var btn = form.querySelector('.impulse-form-submit');
    if (!btn || btn.disabled) return;
    var msgEl = form.querySelector('.impulse-form-message');
    var origText = btn.textContent;
    btn.disabled = true; btn.textContent = 'Creating account...'; btn.style.opacity = '0.6';
    if (msgEl) { msgEl.style.display = 'none'; msgEl.textContent = ''; }
    var fd = new FormData(form);
    fd.append('action', 'instinctor_ajax_register');
    var ajaxUrl = (typeof instinctorFrontend !== 'undefined' && instinctorFrontend.ajaxUrl)
        ? instinctorFrontend.ajaxUrl : (window.ajaxurl || '/wp-admin/admin-ajax.php');
    fetch(ajaxUrl, { method: 'POST', body: fd })
        .then(function(r) { return r.json(); })
        .then(function(res) {
            btn.style.opacity = '1';
            if (res.success) {
                btn.textContent = 'Account created!';
                if (msgEl) { msgEl.style.display = 'block'; msgEl.style.background = '#f0fdf4'; msgEl.style.color = '#166534'; msgEl.style.border = '1px solid #bbf7d0'; msgEl.textContent = res.data.message || 'Account created successfully!'; }
                var redir = form.dataset.redirect || res.data.redirect || '';
                setTimeout(function() { window.location.href = redir || window.location.pathname; }, 1200);
            } else {
                if (msgEl) { msgEl.style.display = 'block'; msgEl.style.background = '#fef2f2'; msgEl.style.color = '#991b1b'; msgEl.style.border = '1px solid #fecaca'; msgEl.textContent = res.data && res.data.message ? res.data.message : 'Registration failed. Please try again.'; }
                btn.textContent = origText; btn.disabled = false;
            }
        })
        .catch(function() {
            btn.style.opacity = '1'; btn.textContent = origText; btn.disabled = false;
            if (msgEl) { msgEl.style.display = 'block'; msgEl.style.background = '#fef2f2'; msgEl.style.color = '#991b1b'; msgEl.style.border = '1px solid #fecaca'; msgEl.textContent = 'Connection error. Please try again.'; }
        });
});

document.addEventListener('click', function(e) {
    var link = e.target.closest('.impulse-lost-password-link');
    if (!link) return;
    e.preventDefault();
    var form = link.closest('.impulse-login-form');
    if (!form) return;
    
    if (form.querySelector('.impulse-forgot-form')) return;
    
    var fields = form.querySelectorAll('input:not([type="hidden"]), button, label, div, a');
    var hidden = [];
    fields.forEach(function(f) { if (f.closest('.impulse-forgot-form')) return; hidden.push(f); f.dataset.wasDisplay = f.style.display; f.style.display = 'none'; });
    var fg = document.createElement('div');
    fg.className = 'impulse-forgot-form';
    fg.style.cssText = 'display:flex;flex-direction:column;gap:12px';
    fg.innerHTML = '<div style="font-size:14px;font-weight:600;color:#1d2327">Reset Password</div>'
        + '<input type="email" name="forgot_email" placeholder="Enter your email address" required style="' + (form.querySelector('input[name="username"]') ? form.querySelector('input[name="username"]').getAttribute('style') : 'width:100%;padding:12px 16px;font-size:14px;border:1px solid #e0e0e0;border-radius:6px;outline:none;box-sizing:border-box') + '">'
        + '<div style="display:flex;gap:8px"><button type="button" class="impulse-forgot-submit impulse-form-submit" style="flex:1;padding:12px;border:none;border-radius:6px;font-size:14px;font-weight:600;cursor:pointer;' + (form.querySelector('.impulse-form-submit') ? 'background:' + getComputedStyle(form.querySelector('.impulse-form-submit')).background + ';color:' + getComputedStyle(form.querySelector('.impulse-form-submit')).color : 'background:#1d2327;color:#fff') + '">Send Reset Link</button>'
        + '<button type="button" class="impulse-forgot-cancel" style="padding:12px 16px;background:transparent;border:1px solid #e0e0e0;border-radius:6px;font-size:14px;cursor:pointer;color:#888">Back</button></div>'
        + '<div class="impulse-forgot-msg" style="display:none;padding:10px 14px;border-radius:6px;font-size:13px;text-align:center"></div>';
    form.appendChild(fg);
    
    fg.querySelector('.impulse-forgot-cancel').addEventListener('click', function() {
        fg.remove();
        hidden.forEach(function(f) { f.style.display = f.dataset.wasDisplay || ''; delete f.dataset.wasDisplay; });
    });
    
    fg.querySelector('.impulse-forgot-submit').addEventListener('click', function() {
        var emailInput = fg.querySelector('input[name="forgot_email"]');
        var email = emailInput.value.trim();
        if (!email) { emailInput.focus(); return; }
        var btn = fg.querySelector('.impulse-forgot-submit');
        var msg = fg.querySelector('.impulse-forgot-msg');
        btn.disabled = true; btn.textContent = 'Sending...';
        var nonce = form.querySelector('input[name="nonce"]');
        var fd = new FormData();
        fd.append('action', 'instinctor_forgot_password');
        fd.append('email', email);
        if (nonce) fd.append('nonce', nonce.value);
        var ajaxUrl = (typeof instinctorFrontend !== 'undefined' && instinctorFrontend.ajaxUrl)
            ? instinctorFrontend.ajaxUrl : (window.ajaxurl || '/wp-admin/admin-ajax.php');
        fetch(ajaxUrl, { method: 'POST', body: fd })
            .then(function(r) { return r.json(); })
            .then(function(res) {
                msg.style.display = 'block';
                if (res.success) {
                    msg.style.background = '#f0fdf4'; msg.style.color = '#166534'; msg.style.border = '1px solid #bbf7d0';
                    msg.textContent = res.data && res.data.message ? res.data.message : 'Check your email for a reset link.';
                    btn.textContent = 'Sent!';
                } else {
                    msg.style.background = '#fef2f2'; msg.style.color = '#991b1b'; msg.style.border = '1px solid #fecaca';
                    msg.textContent = res.data && res.data.message ? res.data.message : 'Could not send reset email.';
                    btn.textContent = 'Send Reset Link'; btn.disabled = false;
                }
            })
            .catch(function() {
                msg.style.display = 'block'; msg.style.background = '#fef2f2'; msg.style.color = '#991b1b'; msg.style.border = '1px solid #fecaca';
                msg.textContent = 'Connection error.';
                btn.textContent = 'Send Reset Link'; btn.disabled = false;
            });
    });
});
}

(function() {
    function setupEntranceReveal() {
        var animatedEls = document.querySelectorAll('.impulse-animated');
        if (!animatedEls.length) return;
        var ioFallback = function() {
            var stillHidden = document.querySelectorAll('.impulse-animated:not(.impulse-visible)');
            for (var i = 0; i < stillHidden.length; i++) {
                var el = stillHidden[i];
                var r = el.getBoundingClientRect();
                if (r.width > 0 && r.height > 0 && r.top < window.innerHeight * 1.1 && r.bottom > 0) {
                    el.classList.add('impulse-visible');
                }
            }
        };

        

        

        
        function _pinVisible(e) {
            if (!e.target || !e.target.classList) return;
            if (!e.target.classList.contains('impulse-animated')) return;
            
            if (e.target !== e.currentTarget) {}
            try { e.target.style.opacity = '1'; } catch (_e) {}
        }
        if ('IntersectionObserver' in window) {
            var observer = new IntersectionObserver(function(entries) {
                entries.forEach(function(entry) {
                    if (entry.isIntersecting) {
                        entry.target.classList.add('impulse-visible');

                        
                        entry.target.addEventListener('animationend', _pinVisible, { once: true });
                        observer.unobserve(entry.target);
                    }
                });
            }, { threshold: 0.1 });
            animatedEls.forEach(function(el) { observer.observe(el); });
        }

        
        animatedEls.forEach(function(el) {
            el.addEventListener('animationend', _pinVisible, { once: true });
        });
        requestAnimationFrame(ioFallback);
        setTimeout(ioFallback, 100);
        setTimeout(ioFallback, 500);
        setTimeout(ioFallback, 1500);
        setTimeout(function() {
            document.querySelectorAll('.impulse-animated:not(.impulse-visible)').forEach(function(el) {
                el.classList.add('impulse-visible');
            });
        }, 2000);
        var _q = false;
        window.addEventListener('scroll', function() {
            if (_q) return; _q = true;
            requestAnimationFrame(function() { _q = false; ioFallback(); });
        }, { passive: true });
    }
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', setupEntranceReveal);
    } else {
        setupEntranceReveal();
    }
})();


(function() {
    function _impulseB64Decode(s) {
        if (!s) return '';
        try { return decodeURIComponent(escape(atob(s))); } catch (e) { return s; }
    }
    function _impulseB64Encode(s) {
        try { return btoa(unescape(encodeURIComponent(s || ''))); } catch (e) { return ''; }
    }
    function _impulseDeviceForWidth(w) {
        if (w <= 767)  return 'mobile';
        if (w <= 1024) return 'tablet';
        return 'desktop';
    }
    function _impulseApplyResponsiveText() {
        var w = window.innerWidth || document.documentElement.clientWidth || 1280;
        var dev = _impulseDeviceForWidth(w);
        document.querySelectorAll('[data-content-tablet],[data-content-mobile]').forEach(function(el) {
            
            if (!el.hasAttribute('data-content-desktop')) {
                el.setAttribute('data-content-desktop', _impulseB64Encode(el.innerHTML || ''));
            }
            var encDesk = el.getAttribute('data-content-desktop') || '';
            var encTab  = el.getAttribute('data-content-tablet') || '';
            var encMob  = el.getAttribute('data-content-mobile') || '';

            

            
            var pickEnc;
            if (dev === 'tablet') {
                pickEnc = encTab || encDesk || encMob;
            } else if (dev === 'mobile') {
                pickEnc = encMob || encTab || encDesk;
            } else {
                pickEnc = encDesk || encTab || encMob;
            }

            if (el._impLastEnc === pickEnc) return;
            el._impLastEnc = pickEnc;
            el.innerHTML = _impulseB64Decode(pickEnc);
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', _impulseApplyResponsiveText);
    } else {
        _impulseApplyResponsiveText();
    }
    var _impRespRsz = null;
    window.addEventListener('resize', function() {
        if (_impRespRsz) clearTimeout(_impRespRsz);
        _impRespRsz = setTimeout(_impulseApplyResponsiveText, 120);
    });
})();
