
(function(){
  function qs(sel, root=document){ return root.querySelector(sel); }
  function qsa(sel, root=document){ return Array.from(root.querySelectorAll(sel)); }
  function inject(){
    const page = document.body.dataset.page || 'index.html';
    const h = document.getElementById('site-header');
    const f = document.getElementById('site-footer');
    if(h && window.ROKN_RENDER_HEADER) h.innerHTML = window.ROKN_RENDER_HEADER(page);
    if(f && window.ROKN_RENDER_FOOTER) f.innerHTML = window.ROKN_RENDER_FOOTER(page);

    const toggle = document.getElementById('navToggle');
    const nav = document.getElementById('mainNav');
    if(toggle && nav){
      toggle.addEventListener('click', ()=>{
        nav.classList.toggle('open');
        toggle.setAttribute('aria-expanded', String(nav.classList.contains('open')));
      });
    }
    const trigger = qs('.services-trigger');
    const group = qs('.nav-services-group');
    if(trigger && group){ trigger.addEventListener('click', ()=> group.classList.toggle('open')); }
  }
  function reveal(){
    const els = qsa('.reveal');
    if(!('IntersectionObserver' in window) || !els.length){ els.forEach(el=>el.classList.add('in-view')); return; }
    const io = new IntersectionObserver(entries=>{ entries.forEach(e=>{ if(e.isIntersecting) e.target.classList.add('in-view'); }); }, {threshold:0.12});
    els.forEach(el=>io.observe(el));
  }
  function heroMotion(){
    const hero = qs('.hero-scene');
    if(!hero) return;
    const rings = qsa('.hero-orb', hero);
    let t = 0;
    function frame(){
      t += 0.01;
      rings.forEach((orb,i)=>{
        const x = Math.sin(t + i) * (10 + i * 2);
        const y = Math.cos(t * 1.2 + i) * (6 + i * 2);
        orb.style.transform = `translate3d(${x}px, ${y}px, 0)`;
      });
      requestAnimationFrame(frame);
    }
    frame();
  }
  function counters(){
    qsa('[data-count]').forEach(el=>{
      const target = parseInt(el.dataset.count || '0', 10);
      let cur = 0; const step = Math.max(1, Math.ceil(target / 60));
      function tick(){ cur += step; if(cur >= target){ el.textContent = target; return; } el.textContent = cur; requestAnimationFrame(tick); }
      tick();
    });
  }
  document.addEventListener('DOMContentLoaded', ()=>{ inject(); reveal(); heroMotion(); counters(); });
})();
document.querySelectorAll('.service-links-list a').forEach(link => {
  if (window.location.pathname.includes(link.getAttribute('href'))) {
    link.classList.add('active');
  }
});