// Southern Roots Landscaping — mobile nav toggle
document.addEventListener('DOMContentLoaded', function () {
  var hamburger = document.getElementById('hamburger');
  var nav = document.getElementById('main-nav');

  if (!hamburger || !nav) return;

  function closeNav() {
    nav.classList.remove('is-open');
    hamburger.classList.remove('is-active');
    hamburger.setAttribute('aria-expanded', 'false');
  }

  function toggleNav() {
    var isOpen = nav.classList.toggle('is-open');
    hamburger.classList.toggle('is-active', isOpen);
    hamburger.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
  }

  hamburger.addEventListener('click', toggleNav);

  // Close the menu after a nav link is tapped
  nav.querySelectorAll('a').forEach(function (link) {
    link.addEventListener('click', closeNav);
  });

  // Close the menu if window is resized back up to desktop width
  window.addEventListener('resize', function () {
    if (window.innerWidth > 900) closeNav();
  });
});
