/* Custom styles for Taqueria Y Palateria Guerrerense */

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Base font smoothing */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scroll reveal base state — progressive enhancement */
.reveal {
    opacity: 1;
    transform: none;
    transition: opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Only apply hidden state when JS is active and motion is preferred */
@media (prefers-reduced-motion: no-preference) {
    .reveal {
        opacity: 0;
        transform: translateY(24px);
    }
    .reveal.revealed {
        opacity: 1;
        transform: translateY(0);
    }
    .reveal-delay-1 { transition-delay: 0.1s; }
    .reveal-delay-2 { transition-delay: 0.2s; }
    .reveal-delay-3 { transition-delay: 0.3s; }
    .reveal-delay-4 { transition-delay: 0.4s; }
}

/* Navbar scroll state */
.nav-scrolled {
    background: rgba(254, 250, 246, 0.95) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 1px 0 rgba(147, 24, 58, 0.08);
}

/* Mobile menu transitions */
#mobile-menu.menu-open {
    opacity: 1 !important;
    pointer-events: all !important;
}

#mobile-menu.menu-closed {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #fefaf6;
}
::-webkit-scrollbar-thumb {
    background: #d43f66;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #93183a;
}

/* Selection color */
::selection {
    background: #f9d0d9;
    color: #791634;
}

/* Image loading placeholder */
img {
    background-color: #fce7eb;
}

/* Focus styles for accessibility */
a:focus-visible,
button:focus-visible {
    outline: 2px solid #d43f66;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Mobile menu link hover */
.mobile-link {
    position: relative;
}
.mobile-link::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    width: 0;
    height: 2px;
    background: #b52047;
    transition: width 0.3s ease, left 0.3s ease;
}
.mobile-link:hover::after {
    width: 80%;
    left: 10%;
}
</style>

<sm-file path="script.js">
(function () {
    'use strict';

    // ─── Navbar scroll behavior ───────────────────────────────
    const navbar = document.getElementById('navbar');
    let lastScroll = 0;

    function handleNavbar() {
        const currentScroll = window.pageYOffset;
        if (currentScroll > 60) {
            navbar.classList.add('nav-scrolled');
        } else {
            navbar.classList.remove('nav-scrolled');
        }
        lastScroll = currentScroll;
    }

    window.addEventListener('scroll', handleNavbar, { passive: true });
    handleNavbar();

    // ─── Mobile menu ──────────────────────────────────────────
    const menuBtn = document.getElementById('menu-btn');
    const mobileMenu = document.getElementById('mobile-menu');
    const iconOpen = document.getElementById('menu-icon-open');
    const iconClose = document.getElementById('menu-icon-close');
    let menuOpen = false;

    function toggleMenu() {
        menuOpen = !menuOpen;
        menuBtn.setAttribute('aria-expanded', menuOpen);
        
        if (menuOpen) {
            iconOpen.classList.add('hidden');
            iconClose.classList.remove('hidden');
            mobileMenu.classList.remove('menu-closed');
            mobileMenu.classList.add('menu-open');
            document.body.style.overflow = 'hidden';
        } else {
            iconOpen.classList.remove('hidden');
            iconClose.classList.add('hidden');
            mobileMenu.classList.remove('menu-open');
            mobileMenu.classList.add('menu-closed');
            document.body.style.overflow = '';
        }
    }

    menuBtn.addEventListener('click', toggleMenu);

    // Close menu on link click
    document.querySelectorAll('.mobile-link').forEach(function (link) {
        link.addEventListener('click', function () {
            if (menuOpen) toggleMenu();
        });
    });

    // Close menu on Escape
    document.addEventListener('keydown', function (e) {
        if (e.key === 'Escape' && menuOpen) toggleMenu();
    });

    // ─── Scroll reveal (progressive enhancement) ──────────────
    // Only activate when JS runs and user prefers motion
    const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    
    if (!prefersReducedMotion && 'IntersectionObserver' in window) {
        const revealElements = document.querySelectorAll('.reveal');
        
        const revealObserver = new IntersectionObserver(function (entries) {
            entries.forEach(function (entry) {
                if (entry.isIntersecting) {
                    entry.target.classList.add('revealed');
                    revealObserver.unobserve(entry.target);
                }
            });
        }, {
            threshold: 0.1,
            rootMargin: '0px 0px -40px 0px'
        });

        revealElements.forEach(function (el) {
            revealObserver.observe(el);
        });
    }

    // ─── Active nav link highlighting ─────────────────────────
    const sections = document.querySelectorAll('section[id]');
    const navLinks = document.querySelectorAll('nav a[href^="#"]');

    function highlightNav() {
        const scrollPos = window.pageYOffset + 200;
        
        sections.forEach(function (section) {
            const top = section.offsetTop;
            const height = section.offsetHeight;
            const id = section.getAttribute('id');
            
            if (scrollPos >= top && scrollPos < top + height) {
                navLinks.forEach(function (link) {
                    link.classList.remove('text-burgundy-700');
                    if (link.getAttribute('href') === '#' + id) {
                        link.classList.add('text-burgundy-700');
                    }
                });
            }
        });
    }

    window.addEventListener('scroll', highlightNav, { passive: true });
    highlightNav();

})();
</style>
