// Navigation functionality
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
const navItems = document.querySelectorAll('.nav-item');
const navBrand = document.querySelector('.nav-brand');
const backButtons = document.querySelectorAll('.back-button');
const pageSections = document.querySelectorAll('.page-section');

// Hamburger menu toggle
hamburger.addEventListener('click', () => {
    hamburger.classList.toggle('active');
    navMenu.classList.toggle('active');
});

// Function to show specific page
function showPage(pageId) {

    // Close mobile menu if open
    hamburger.classList.remove('active');
    navMenu.classList.remove('active');
}

// Brand (logo) click handler for home page
navBrand.addEventListener('click', (e) => {
    const pageId = navBrand.getAttribute('data-page');
    showPage(pageId);
});

// Navigation item click handlers
navItems.forEach(item => {
    item.addEventListener('click', (e) => {
        const pageId = item.getAttribute('data-page');
        showPage(pageId);
    });
});

// Back button click handlers
backButtons.forEach(button => {
    button.addEventListener('click', (e) => {
        const pageId = button.getAttribute('data-page');
        showPage(pageId);
    });
});

// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
    // Don't close menu if clicking inside an iframe or its container
    if (e.target.closest('.episodes-embed-container') || 
        e.target.tagName === 'IFRAME' ||
        hamburger.contains(e.target) || 
        navMenu.contains(e.target)) {
        return;
    }
    hamburger.classList.remove('active');
    navMenu.classList.remove('active');
});

