/* ─── Base & Utilities ─── */
html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow-x: hidden;
}

::selection {
  background: #FBC8B5;
  color: #5E3627;
}

/* ─── Navbar ─── */
#navbar {
  background: rgba(254, 252, 248, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(192, 114, 81, 0.08);
  transition: box-shadow 0.4s ease, background 0.4s ease;
}

#navbar.scrolled {
  background: rgba(254, 252, 248, 0.95);
  box-shadow: 0 4px 30px rgba(192, 114, 81, 0.08);
}

.nav-link {
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: #C07251;
  transition: width 0.3s ease;
  border-radius: 1px;
}

.nav-link:hover::after {
  width: 100%;
}

/* ─── Mobile Menu ─── */
#mobile-menu.open {
  opacity: 1;
  pointer-events: all;
}

.mobile-link {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease, color 0.3s ease;
}

#mobile-menu.open .mobile-link {
  opacity: 1;
  transform: translateY(0);
}

#mobile-menu.open .mobile-link:nth-child(1) { transition-delay: 0.05s; }
#mobile-menu.open .mobile-link:nth-child(2) { transition-delay: 0.1s; }
#mobile-menu.open .mobile-link:nth-child(3) { transition-delay: 0.15s; }
#mobile-menu.open .mobile-link:nth-child(4) { transition-delay: 0.2s; }
#mobile-menu.open .mobile-link:nth-child(5) { transition-delay: 0.25s; }

/* ─── Floating Card Animations ─── */
.card-float-1 { animation: float1 6s ease-in-out infinite; }
.card-float-2 { animation: float2 7s ease-in-out infinite; }
.card-float-3 { animation: float3 5.5s ease-in-out infinite; }
.card-float-4 { animation: float4 6.5s ease-in-out infinite; }

@keyframes float1 {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-12px); }
}

@keyframes float2 {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

@keyframes float3 {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

@keyframes float4 {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}

/* ─── Scroll Reveal ─── */
.reveal {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1), transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .card-float-1, .card-float-2, .card-float-3, .card-float-4 {
    animation: none;
  }
  html { scroll-behavior: auto; }
  .reveal {
    transition: none;
    opacity: 1;
    transform: none;
  }
}

/* ─── FAQ Accordion ─── */
.faq-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1), padding 0.4s ease;
}

.faq-content.open {
  max-height: 200px;
}

.faq-icon {
  transition: transform 0.3s ease;
}

.faq-btn[aria-expanded="true"] .faq-icon {
  transform: rotate(45deg);
}

/* ─── Custom Select Arrow ─── */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239A6D36' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

/* ─── Form Focus Ring ─── */
input:focus, textarea:focus, select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(192, 114, 81, 0.15);
}

/* ─── Smooth image loading ─── */
img {
  opacity: 1;
  transition: opacity 0.4s ease;
}
</style>

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

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

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

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

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

  menuBtn.addEventListener('click', function () {
    menuOpen = !menuOpen;
    if (menuOpen) {
      mobileMenu.classList.add('open');
      menuIconOpen.classList.add('hidden');
      menuIconClose.classList.remove('hidden');
      document.body.style.overflow = 'hidden';
    } else {
      mobileMenu.classList.remove('open');
      menuIconOpen.classList.remove('hidden');
      menuIconClose.classList.add('hidden');
      document.body.style.overflow = '';
    }
  });

  // Close mobile menu on link click
  document.querySelectorAll('.mobile-link').forEach(function (link) {
    link.addEventListener('click', function () {
      menuOpen = false;
      mobileMenu.classList.remove('open');
      menuIconOpen.classList.remove('hidden');
      menuIconClose.classList.add('hidden');
      document.body.style.overflow = '';
    });
  });

  // ─── Scroll reveal (progressive enhancement) ───
  const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  if (!prefersReducedMotion) {
    const revealElements = document.querySelectorAll('.reveal');

    function checkReveal() {
      const windowHeight = window.innerHeight;
      revealElements.forEach(function (el) {
        const elementTop = el.getBoundingClientRect().top;
        const revealPoint = windowHeight * 0.88;
        if (elementTop < revealPoint) {
          el.classList.add('revealed');
        }
      });
    }

    window.addEventListener('scroll', checkReveal, { passive: true });
    // Initial check for elements already in view
    checkReveal();
  } else {
    // If reduced motion is preferred, ensure all reveals are visible
    document.querySelectorAll('.reveal').forEach(function (el) {
      el.classList.add('revealed');
    });
  }

  // ─── FAQ Accordion ───
  document.querySelectorAll('.faq-btn').forEach(function (btn) {
    btn.addEventListener('click', function () {
      const content = this.nextElementSibling;
      const isOpen = this.getAttribute('aria-expanded') === 'true';

      // Close all others
      document.querySelectorAll('.faq-btn').forEach(function (otherBtn) {
        otherBtn.setAttribute('aria-expanded', 'false');
        otherBtn.nextElementSibling.classList.add('hidden');
        otherBtn.nextElementSibling.classList.remove('open');
      });

      // Toggle current
      if (!isOpen) {
        this.setAttribute('aria-expanded', 'true');
        content.classList.remove('hidden');
        content.classList.add('open');
      }
    });
  });

  // ─── Contact Form ───
  const contactForm = document.getElementById('contact-form');
  const formSuccess = document.getElementById('form-success');

  contactForm.addEventListener('submit', function (e) {
    e.preventDefault();

    // Basic validation
    const email = document.getElementById('email');
    const firstName = document.getElementById('first-name');

    if (!firstName.value.trim() || !email.value.trim()) {
      if (!firstName.value.trim()) {
        firstName.classList.add('border-red-300', 'ring-2', 'ring-red-200');
        firstName.addEventListener('input', function () {
          this.classList.remove('border-red-300', 'ring-2', 'ring-red-200');
        }, { once: true });
      }
      if (!email.value.trim()) {
        email.classList.add('border-red-300', 'ring-2', 'ring-red-200');
        email.addEventListener('input', function () {
          this.classList.remove('border-red-300', 'ring-2', 'ring-red-200');
        }, { once: true });
      }
      return;
    }

    // Email format check
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailRegex.test(email.value)) {
      email.classList.add('border-red-300', 'ring-2', 'ring-red-200');
      return;
    }

    // Show success
    contactForm.style.display = 'none';
    formSuccess.classList.remove('hidden');
  });

  // ─── Smooth scroll for anchor links ───
  document.querySelectorAll('a[href^="#"]').forEach(function (anchor) {
    anchor.addEventListener('click', function (e) {
      const targetId = this.getAttribute('href');
      if (targetId === '#') return;
      const target = document.querySelector(targetId);
      if (target) {
        e.preventDefault();
        const navHeight = navbar.offsetHeight;
        const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - navHeight - 20;
        window.scrollTo({
          top: targetPosition,
          behavior: 'smooth'
        });
      }
    });
  });
})();
