
(function(){
  function unlockScroll(){
    var html=document.documentElement, body=document.body;
    html.style.overflowY='auto'; html.style.height='auto'; html.style.touchAction='auto';
    body.style.overflowY='auto'; body.style.height='auto'; body.style.position='static'; body.style.touchAction='auto';
    body.classList.remove('menu-open','no-scroll','scroll-lock');
    var loader=document.querySelector('.site-loader');
    if(loader){ loader.classList.add('is-hiding'); loader.style.pointerEvents='none'; setTimeout(function(){ if(loader && loader.parentNode){ loader.remove(); } }, 500); }
  }
  function init(){
    unlockScroll(); setTimeout(unlockScroll,300); setTimeout(unlockScroll,1200);
    document.querySelectorAll('.store-slider-copy').forEach(function(el){ el.remove(); });
    document.querySelectorAll('.home-hero-slider').forEach(function(slider){
      if(slider.dataset.criticalSliderReady==='1') return;
      slider.dataset.criticalSliderReady='1';
      var slides=[].slice.call(slider.querySelectorAll('.slide'));
      if(!slides.length) return;
      var i=0; slides.forEach(function(s,idx){ s.classList.toggle('active', idx===0); });
      if(slides.length>1){ setInterval(function(){ slides[i].classList.remove('active'); i=(i+1)%slides.length; slides[i].classList.add('active'); }, 4300); }
    });
    var menuBtn=document.getElementById('menuToggle'), menu=document.getElementById('mobileMenu'), close=document.getElementById('closeMenu');
    if(menuBtn && menu){ menuBtn.onclick=function(e){ e.preventDefault(); e.stopPropagation(); menu.classList.add('show'); document.body.classList.remove('menu-open'); }; }
    if(close && menu){ close.onclick=function(e){ e.preventDefault(); menu.classList.remove('show'); unlockScroll(); }; }
    if(menu){ menu.querySelectorAll('a').forEach(function(a){ a.addEventListener('click',function(){ menu.classList.remove('show'); unlockScroll(); }); }); }
  }
  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',init); else init();
  window.addEventListener('pageshow', unlockScroll);
})();
