// Shared reveal-on-scroll utility. Used by both index and team pages.
window.initReveals = function initReveals() {
  const selectors = [
    '.s-head',
    '.problem-row',
    '.arch-grid',
    '.arch-col',
    '.stat-block .stat',
    '.tract-stats',
    '.tract-stats .cell',
    '.tract-grid > .card',
    '.cmu',
    '.team-row',
    '.advisor-row',
    '.price-card',
    '.price-foot',
    '.cta-tile',
    '.cta h2',
    '.cta .lede',
    '.cta .contact-row',
    '.module-row > div',
    '.module-vis',
    '.thesis h2',
    '.tracts-cta',
  ];
  const sel = selectors.join(',');
  const els = document.querySelectorAll(sel);
  els.forEach((el) => {
    el.classList.add('reveal');
    const parent = el.parentElement;
    if (parent) {
      const siblings = Array.from(parent.children).filter((c) => c.matches && c.matches(sel));
      const idx = siblings.indexOf(el);
      if (idx > 0) {
        el.style.setProperty('--reveal-delay', `${Math.min(idx, 4) * 75}ms`);
      }
    }
  });
  const obs = new IntersectionObserver(
    (entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          obs.unobserve(e.target);
        }
      });
    },
    { threshold: 0.08, rootMargin: '0px 0px -40px 0px' }
  );
  els.forEach((el) => obs.observe(el));
  return obs;
};
