document.addEventListener("DOMContentLoaded", () => {
  const preloader = document.getElementById("preloader");
  const container = document.querySelector(".container");
  setTimeout(() => {
    preloader.style.display = "none";
    container.classList.remove("hidden");
  }, 1500);

  const startBtn = document.getElementById("startBtn");
  const timerEl = document.getElementById("timer");
  const containerHearts = document.querySelector(".hearts-container");

  startBtn.addEventListener("click", () => {
    startBtn.style.display = "none";
    timerEl.classList.remove("hidden");
    startTimer();
    for (let i = 0; i < 30; i++) {
      const heart = document.createElement("div");
      heart.className = "heart";
      heart.style.left = Math.random() * 100 + "%";
      heart.style.top = "100%";
      heart.style.fontSize = Math.random() * 2 + 1 + "rem";
      heart.innerHTML = "💖";
      containerHearts.appendChild(heart);
      setTimeout(() => heart.remove(), 2000);
    }
  });

  function startTimer() {
    const startDate = new Date("2025-01-23T20:52:00");
    setInterval(() => {
      const now = new Date();
      const diff = now - startDate;
      const days = Math.floor(diff / (1000 * 60 * 60 * 24));
      const hours = Math.floor(diff / (1000 * 60 * 60)) % 24;
      const minutes = Math.floor(diff / (1000 * 60)) % 60;
      const seconds = Math.floor(diff / 1000) % 60;
      timerEl.textContent = `Мы вместе: ${days}д ${hours}ч ${minutes}м ${seconds}с`;
    }, 1000);
  }
});

function checkSecret() {
  const input = document.getElementById("secret-input").value.trim();
  const msg = document.getElementById("error-msg");
  if (input === "03.07.2024") {
    document.getElementById("secret-message").classList.remove("hidden");
    msg.textContent = "";
  } else {
    msg.textContent = "Неверная дата 😢";
  }
}