(function () {
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;

  function attachGlitch(el) {
    function glitch() {
      el.classList.add('is-glitching');
      setTimeout(function () { el.classList.remove('is-glitching'); }, 500);
      setTimeout(glitch, 4000 + Math.random() * 7000);
    }
    setTimeout(glitch, 3500);
  }

  document.querySelectorAll('.hero-name, .section-title').forEach(attachGlitch);
})();
