document.addEventListener('DOMContentLoaded', function () {
  var timeline = document.querySelector('ol.timeline');
  if (!timeline) return;

  // Progressive enhancement: activates CSS hidden state
  timeline.classList.add('js-lazy-timeline');

  var items = Array.prototype.slice.call(
    timeline.querySelectorAll('.timeline-item')
  );

  function reveal(item) {
    item.classList.add('is-visible');
  }

  var observer = new IntersectionObserver(
    function (entries) {
      entries.forEach(function (entry) {
        if (entry.isIntersecting) {
          reveal(entry.target);
          observer.unobserve(entry.target);
        }
      });
    },
    {
      rootMargin: '-80px 0px 0px 0px',
      threshold: 0.12,
    }
  );

  items.forEach(function (item) {
    observer.observe(item);
  });
});
