/* ═══════════════════════════════════════════════════
   AOS — Animate On Scroll (custom lightweight build)
   Elements with data-aos="fade-up/fade-left/fade-right
   /fade-down/zoom-in/flip-up" animate on scroll
═══════════════════════════════════════════════════ */
(function(){
'use strict';

function runAOS(){
  var els = document.querySelectorAll('[data-aos]');
  if(!els.length) return;

  var obs = new IntersectionObserver(function(entries){
    entries.forEach(function(entry){
      if(!entry.isIntersecting) return;
      var el = entry.target;
      var delay = parseInt(el.getAttribute('data-aos-delay') || 0);
      setTimeout(function(){ el.classList.add('aos-animate'); }, delay);
      obs.unobserve(el);
    });
  },{
    threshold: 0.07,
    rootMargin: '0px 0px -36px 0px'
  });

  els.forEach(function(el){ obs.observe(el); });
}

// Also keep the old .anim observer running
function runOldAnim(){
  var els = document.querySelectorAll('.anim,.anim-l,.anim-r,.anim-s,.anim-blur,.blur-reveal,.section-line,.line-reveal-wrap');
  if(!els.length) return;
  var obs = new IntersectionObserver(function(entries){
    entries.forEach(function(e){
      if(!e.isIntersecting) return;
      var el = e.target;
      var d = parseFloat(el.dataset.delay||0)*1000;
      setTimeout(function(){ el.classList.add('show','in','aos-animate'); }, d);
      obs.unobserve(el);
    });
  },{threshold:0.08, rootMargin:'0px 0px -40px 0px'});
  els.forEach(function(el){ obs.observe(el); });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded', function(){ runAOS(); runOldAnim(); });
} else {
  runAOS(); runOldAnim();
}
})();
