(function () {
  var nav = document.getElementById('hxNav');
  var toggle = document.getElementById('hxNavToggle');
  var mobile = document.getElementById('hxNavMobile');

  if (nav) {
    var onScroll = function () {
      nav.classList.toggle('hx-nav-scrolled', window.scrollY > 8);
    };
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
  }

  if (toggle && mobile) {
    toggle.addEventListener('click', function () {
      var open = mobile.classList.toggle('hx-open');
      toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
    });
    mobile.querySelectorAll('a').forEach(function (a) {
      a.addEventListener('click', function () {
        mobile.classList.remove('hx-open');
        toggle.setAttribute('aria-expanded', 'false');
      });
    });
  }

  // Pricing page: switching the currency select reloads with ?currency=XXX
  var currencySelect = document.getElementById('hxCurrencySelect');
  if (currencySelect) {
    currencySelect.addEventListener('change', function () {
      var url = new URL(window.location.href);
      url.searchParams.set('currency', currencySelect.value);
      window.location.href = url.toString();
    });
  }
})();
