/* Custom styles for Hair by Kelly */

html {
  scroll-behavior: smooth;
}

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

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .hover\:scale-105:hover,
  .hover\:scale-110:hover {
    transform: none;
  }
}

/* Scroll reveal animations - progressive enhancement, only applied via JS */
.reveal {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: no-preference) {
  .reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s ease, transform 0.6s ease;
  }
  .reveal.revealed {
    opacity: 1;
    transform: none;
  }
}

/* Nav scroll state */
.nav-scrolled #nav {
  box-shadow: 0 1px 20px rgba(20, 83, 45, 0.08);
}

/* Service card hover - ensure text contrast */
.group:hover .group-hover\:text-white {
  color: white;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: #fdf9ee;
}
::-webkit-scrollbar-thumb {
  background: #166534;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #14532d;
}

/* Selection color */
::selection {
  background: #166534;
  color: #fefdf8;
}
</style>
<sm-file path="script.js">
(function () {
  'use strict';

  // Mobile menu toggle
  const menuBtn = document.getElementById('menu-btn');
  const mobileMenu = document.getElementById('mobile-menu');
  const menuIcon = document.getElementById('menu-icon');
  let menuOpen = false;

  menuBtn.addEventListener('click', function () {
    menuOpen = !menuOpen;
    mobileMenu.classList.toggle('hidden', !menuOpen);
    if (menuOpen) {
      menuIcon.innerHTML = '<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>';
    } else {
      menuIcon.innerHTML = '<line x1="3" y1="7" x2="21" y2="7"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="17" x2="21" y2="17"/>';
    }
  });

  // Close mobile menu on link click
  document.querySelectorAll('.mobile-link, #mobile-menu a').forEach(function (link) {
    link.addEventListener('click', function () {
      menuOpen = false;
      mobileMenu.classList.add('hidden');
      menuIcon.innerHTML = '<line x1="3" y1="7" x2="21" y2="7"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="17" x2="21" y2="17"/>';
    });
  });

  // Nav scroll effect
  const nav = document.getElementById('nav');
  let lastScroll = 0;

  window.addEventListener('scroll', function () {
    const currentScroll = window.pageYOffset;
    if (currentScroll > 50) {
      nav.style.boxShadow = '0 1px 20px rgba(20, 83, 45, 0.08)';
    } else {
      nav.style.boxShadow = 'none';
    }
    lastScroll = currentScroll;
  }, { passive: true });

  // Scroll reveal (progressive enhancement - only if JS runs and user prefers motion)
  const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  if (!prefersReducedMotion) {
    const revealElements = document.querySelectorAll('section > div > div, .group, .relative');

    function revealOnScroll() {
      const windowHeight = window.innerHeight;
      revealElements.forEach(function (el) {
        const rect = el.getBoundingClientRect();
        if (rect.top < windowHeight - 60) {
          el.classList.add('revealed');
        }
      });
    }

    window.addEventListener('scroll', revealOnScroll, { passive: true });
    revealOnScroll(); // Initial check
  }

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

  if (form && successMsg) {
    form.addEventListener('submit', function (e) {
      e.preventDefault();
      form.style.display = 'none';
      successMsg.classList.remove('hidden');
    });
  }
})();
