(function() { document.addEventListener('DOMContentLoaded', function() { // Skip-nav link for keyboard/screen reader accessibility var main = document.querySelector('main') || document.querySelector('.main') || document.querySelector('#main'); if (main) { if (!main.id) main.id = 'main-content'; var skipLink = document.createElement('a'); skipLink.href = '#' + main.id; skipLink.className = 'skip-nav'; skipLink.textContent = 'Skip to main content'; skipLink.setAttribute('tabindex', '0'); document.body.insertBefore(skipLink, document.body.firstChild); } // Fix back-to-top buttons without aria-label var btt = document.getElementById('back-to-top'); if (btt && !btt.getAttribute('aria-label')) { btt.setAttribute('aria-label', 'Back to top'); } var sidebar = document.querySelector('.sidebar'); if (!sidebar) return; var body = document.body; var toggle = document.createElement('button'); toggle.className = 'hamburger sidebar-toggle'; toggle.setAttribute('type', 'button'); toggle.setAttribute('aria-label', 'Open navigation'); toggle.setAttribute('aria-expanded', 'false'); toggle.innerHTML = '☰'; body.prepend(toggle); var overlay = document.createElement('div'); overlay.className = 'sidebar-overlay'; body.appendChild(overlay); function setOpen(isOpen) { body.classList.toggle('mobile-drawer-open', isOpen); sidebar.classList.toggle('open', isOpen); overlay.classList.toggle('open', isOpen); toggle.innerHTML = isOpen ? '✕' : '☰'; toggle.setAttribute('aria-label', isOpen ? 'Close navigation' : 'Open navigation'); toggle.setAttribute('aria-expanded', String(isOpen)); } toggle.addEventListener('click', function() { setOpen(!body.classList.contains('mobile-drawer-open')); }); overlay.addEventListener('click', function() { setOpen(false); }); sidebar.querySelectorAll('a').forEach(function(a) { a.addEventListener('click', function() { setOpen(false); }); }); window.addEventListener('resize', function() { if (window.innerWidth > 1080) setOpen(false); }); document.addEventListener('keydown', function(event) { if (event.key === 'Escape') setOpen(false); }); }); })();