// ========================================
// HEADER - Efeito ao rolar a página
// ========================================

const header = document.getElementById('siteHeader');

if (header) {
  window.addEventListener('scroll', () => {
    header.classList.toggle('scrolled', window.scrollY > 40);
  });
}


// ========================================
// MENU MOBILE / BURGER
// ========================================

const burger = document.getElementById('burgerBtn');
const mobileMenu = document.getElementById('mobileMenu');
const closeMenu = document.getElementById('closeMenu');

if (burger && mobileMenu) {

  // Abrir menu
  burger.addEventListener('click', () => {
    mobileMenu.classList.add('open');
  });

  // Fechar pelo X
  if (closeMenu) {
    closeMenu.addEventListener('click', () => {
      mobileMenu.classList.remove('open');
    });
  }

  // Fechar ao clicar em algum link
  mobileMenu.querySelectorAll('a').forEach(link => {
    link.addEventListener('click', () => {
      mobileMenu.classList.remove('open');
    });
  });
}


// ========================================
// SCROLL REVEAL
// ========================================

const revealEls = document.querySelectorAll('.reveal, .reveal-scale');

if (revealEls.length > 0) {

  const io = new IntersectionObserver((entries) => {

    entries.forEach(entry => {

      if (entry.isIntersecting) {

        entry.target.classList.add('in');

        io.unobserve(entry.target);
      }

    });

  }, {
    threshold: 0.15
  });

  revealEls.forEach(element => {
    io.observe(element);
  });
}

// CARDS DOS PROFESSORES

document.querySelectorAll('.prof-card').forEach(card => {

  const img = card.querySelector('img');
  const title = card.querySelector('h1');
  const info = card.querySelector('.prof-card-info');
  const hint = card.querySelector('.prof-hint');

  // Verifica se todos os elementos existem
  if (!img || !title || !info || !hint) {
    return;
  }

  // Mouse entrando no card
  card.addEventListener('mouseenter', () => {

    img.style.transform = 'translateY(-100%)';
    img.style.opacity = '0';

    title.style.transform = 'translateY(-100%)';
    title.style.opacity = '0';

    hint.style.transform = 'translateY(-100%)';
    hint.style.opacity = '0';

    info.style.transform = 'translateY(0)';
    info.style.opacity = '1';
    info.style.background = 'var(--gold)';
  });


  // Mouse saindo do card
  card.addEventListener('mouseleave', () => {

    img.style.transform = 'translateY(0)';
    img.style.opacity = '1';

    title.style.transform = 'translateY(0)';
    title.style.opacity = '1';

    hint.style.transform = 'translateY(0)';
    hint.style.opacity = '1';

    info.style.transform = 'translateY(100%)';
    info.style.opacity = '0';
  });

});


// FAQ

document.querySelectorAll('.faq-item').forEach(item => {

  const question = item.querySelector('.faq-q');
  const answer = item.querySelector('.faq-a');

  if (!question || !answer) {
    return;
  }


  // FAQ que começa aberto
  if (item.classList.contains('open')) {
    answer.style.maxHeight = answer.scrollHeight + 'px';
  }


  question.addEventListener('click', () => {

    const isOpen = item.classList.contains('open');


    // Fecha todos
    document.querySelectorAll('.faq-item').forEach(other => {

      other.classList.remove('open');

      const otherAnswer = other.querySelector('.faq-a');

      if (otherAnswer) {
        otherAnswer.style.maxHeight = '0';
      }

    });


    // Abre o clicado
    if (!isOpen) {

      item.classList.add('open');

      answer.style.maxHeight = answer.scrollHeight + 'px';

    }

  });

});