// Dark mode toggle document.addEventListener('DOMContentLoaded', function() { const themeToggle = document.getElementById('theme-toggle'); const themeIcon = document.getElementById('theme-icon'); // Check for saved user preference or use system preference const savedTheme = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'); // Apply the saved theme if (savedTheme === 'dark') { document.documentElement.classList.add('dark'); themeIcon.dataset.feather = 'moon'; } else { document.documentElement.classList.remove('dark'); themeIcon.dataset.feather = 'sun'; } // Toggle theme on button click themeToggle.addEventListener('click', () => { if (document.documentElement.classList.contains('dark')) { document.documentElement.classList.remove('dark'); localStorage.setItem('theme', 'light'); themeIcon.dataset.feather = 'sun'; } else { document.documentElement.classList.add('dark'); localStorage.setItem('theme', 'dark'); themeIcon.dataset.feather = 'moon'; } feather.replace(); }); // Refresh feather icons after theme change feather.replace(); });