(function () { var toggle = document.getElementById('darkModeToggle'); var saved = null; try { saved = localStorage.getItem('dark_mode'); } catch (error) { /* Storage may be unavailable. */ } function applyTheme(enabled) { document.body.classList.toggle('dark-mode', enabled); toggle.setAttribute('aria-pressed', String(enabled)); toggle.setAttribute('aria-label', enabled ? 'Switch to light mode' : 'Switch to dark mode'); } applyTheme(saved === 'true' || (saved === null && window.matchMedia('(prefers-color-scheme: dark)').matches)); toggle.addEventListener('click', function () { var enabled = !document.body.classList.contains('dark-mode'); applyTheme(enabled); try { localStorage.setItem('dark_mode', String(enabled)); } catch (error) { /* Theme works without storage. */ } }); }()); // Standard language dropdown, matching the main website header. (function () { var menu = document.querySelector('.lang-more'); var button = document.querySelector('.lang-more-btn'); if (!menu || !button) return; function closeLanguages() { menu.classList.remove('open'); button.setAttribute('aria-expanded', 'false'); } button.addEventListener('click', function (event) { event.preventDefault(); event.stopPropagation(); var open = menu.classList.toggle('open'); button.setAttribute('aria-expanded', String(open)); }); document.addEventListener('click', function (event) { if (!menu.contains(event.target)) closeLanguages(); }); document.addEventListener('keydown', function (event) { if (event.key === 'Escape') closeLanguages(); }); document.getElementById('navToggle').addEventListener('click', closeLanguages); }());