/* ============================================================ Branson Consulting — main.js ============================================================ */ (function () { 'use strict'; /* ── Sticky nav shadow ── */ const nav = document.querySelector('.site-nav'); if (nav) { window.addEventListener('scroll', () => { nav.classList.toggle('scrolled', window.scrollY > 10); }, { passive: true }); } /* ── Scroll reveal with per-sibling stagger ── */ const revealEls = document.querySelectorAll('.reveal'); if ('IntersectionObserver' in window && revealEls.length) { const io = new IntersectionObserver((entries) => { entries.forEach((e) => { if (e.isIntersecting) { e.target.classList.add('in'); io.unobserve(e.target); } }); }, { threshold: 0.07, rootMargin: '0px 0px -20px 0px' }); revealEls.forEach((el) => { const siblings = el.parentElement ? [...el.parentElement.querySelectorAll(':scope > .reveal')] : []; const idx = siblings.indexOf(el); if (idx > 0) el.style.transitionDelay = `${idx * 80}ms`; io.observe(el); }); } else { revealEls.forEach((el) => el.classList.add('in')); } /* ── Active nav ── */ const anchors = document.querySelectorAll('[id]'); const navLinks = document.querySelectorAll('.nav-links a[href^="#"]'); function syncNav() { let current = ''; anchors.forEach((s) => { if (s.getBoundingClientRect().top < window.innerHeight * 0.45) current = s.id; }); navLinks.forEach((a) => { a.classList.toggle('active', a.getAttribute('href') === `#${current}`); }); } window.addEventListener('scroll', syncNav, { passive: true }); syncNav(); /* ── Smooth scroll ── */ document.querySelectorAll('a[href^="#"]').forEach((a) => { a.addEventListener('click', (e) => { const target = document.querySelector(a.getAttribute('href')); if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth' }); } }); }); })();