/* Custom styles for Courtyard At Bay Road */

/* Smooth scroll offset for fixed navbar */
section[id] {
    scroll-margin-top: 80px;
}

/* Reveal animation - progressive enhancement */
@media (prefers-reduced-motion: no-preference) {
    .reveal {
        opacity: 0;
        transform: translateY(24px);
        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);
    }
    .reveal.revealed {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Fallback: ensure content is visible without JS */
.no-js .reveal,
.reveal {
    opacity: 1;
    transform: none;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #fdf6f3;
}
::-webkit-scrollbar-thumb {
    background: #b91d4c;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #971841;
}

/* Focus styles for accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid #b91d4c;
    outline-offset: 2px;
}

/* Input placeholder styling */
input::placeholder,
textarea::placeholder {
    color: #9ca3af;
}

/* Subtle pattern overlay for cream sections */
.bg-cream-50::before,
.bg-cream-100::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle at 1px 1px, rgba(185, 29, 76, 0.03) 1px, transparent 0);
    background-size: 24px 24px;
    pointer-events: none;
}

/* Selection color */
::selection {
    background: #f9cfd9;
    color: #370816;
}
</style>

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

    // Mobile menu toggle
    const mobileToggle = document.getElementById('mobile-toggle');
    const mobileMenu = document.getElementById('mobile-menu');
    const menuIcon = document.getElementById('menu-icon');
    const closeIcon = document.getElementById('close-icon');

    if (mobileToggle) {
        mobileToggle.addEventListener('click', function () {
            const isOpen = !mobileMenu.classList.contains('hidden');
            mobileMenu.classList.toggle('hidden');
            menuIcon.classList.toggle('hidden');
            closeIcon.classList.toggle('hidden');
        });

        // Close mobile menu when a link is clicked
        mobileMenu.querySelectorAll('a').forEach(function (link) {
            link.addEventListener('click', function () {
                mobileMenu.classList.add('hidden');
                menuIcon.classList.remove('hidden');
                closeIcon.classList.add('hidden');
            });
        });
    }

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

    window.addEventListener('scroll', function () {
        const currentScroll = window.pageYOffset;
        if (currentScroll > 50) {
            navbar.classList.add('shadow-sm');
        } else {
            navbar.classList.remove('shadow-sm');
        }
        lastScroll = currentScroll;
    }, { passive: true });

    // Scroll reveal (progressive enhancement)
    if (window.matchMedia('(prefers-reduced-motion: no-preference)').matches) {
        const reveals = document.querySelectorAll('.reveal');

        function checkReveal() {
            const windowHeight = window.innerHeight;
            reveals.forEach(function (el) {
                const elementTop = el.getBoundingClientRect().top;
                if (elementTop < windowHeight - 80) {
                    el.classList.add('revealed');
                }
            });
        }

        window.addEventListener('scroll', checkReveal, { passive: true });
        window.addEventListener('load', checkReveal);
        // Also run immediately in case page is already scrolled
        checkReveal();
    } else {
        // If user prefers reduced motion, make all reveals visible immediately
        document.querySelectorAll('.reveal').forEach(function (el) {
            el.classList.add('revealed');
        });
    }

    // Contact form
    const form = document.getElementById('contact-form');
    const successMsg = document.getElementById('form-success');

    if (form && successMsg) {
        form.addEventListener('submit', function (e) {
            e.preventDefault();
            // Simulate form submission
            const submitBtn = form.querySelector('button[type="submit"]');
            submitBtn.disabled = true;
            submitBtn.textContent = 'Sending...';

            setTimeout(function () {
                form.reset();
                successMsg.classList.remove('hidden');
                submitBtn.disabled = false;
                submitBtn.textContent = 'Send Message';

                // Hide success message after 5 seconds
                setTimeout(function () {
                    successMsg.classList.add('hidden');
                }, 5000);
            }, 800);
        });
    }
})();
</style>
