
document.addEventListener('DOMContentLoaded', function() {
    const music = document.getElementById('background-music');
    const musicToggle = document.getElementById('music-toggle');
    const soundOnIcon = document.getElementById('sound-on-icon');
    const soundOffIcon = document.getElementById('sound-off-icon');

    if (music && musicToggle) {
        // Try to play music by default
        music.play().then(() => {
            // Autoplay started!
            soundOnIcon.style.display = 'inline';
            soundOffIcon.style.display = 'none';
        }).catch(error => {
            // Autoplay was prevented.
            console.log("Autoplay was prevented by the browser.");
            soundOnIcon.style.display = 'none';
            soundOffIcon.style.display = 'inline';
        });

        musicToggle.addEventListener('click', function() {
            if (music.paused) {
                music.play();
                soundOnIcon.style.display = 'inline';
                soundOffIcon.style.display = 'none';
            } else {
                music.pause();
                soundOnIcon.style.display = 'none';
                soundOffIcon.style.display = 'inline';
            }
        });
    }
});
