.password-box{
    margin-top:25px;
    background:#1e293b;
    border:2px dashed #3b82f6;
    padding:20px;
    border-radius:12px;
    text-align:center;
}

.password-box h4{
    color:#3b82f6;
    margin-bottom:12px;
}

.password{
    font-size:20px;
    font-weight:bold;
    background:#0f172a;
    padding:12px;
    border-radius:8px;
    letter-spacing:2px;
    cursor:pointer;
    transition:0.3s;
}

.password:hover{
    background:#3b82f6;
    color:white;
}

.copy-msg{
    display:block;
    margin-top:10px;
    font-size:13px;
    color:#94a3b8;
}
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Tahoma, sans-serif;
  background: #0e1014;
  color: #f1f1f1;
  line-height: 1.8;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

.container {
  width: 92%;
  max-width: 1250px;
  margin: 0 auto;
}

/* Topbar */
.topbar {
  background: linear-gradient(135deg, #121722, #1a2233);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 20px 0;
}

.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.logo {
  font-size: 34px;
  font-weight: bold;
  color: #39ff14;
  letter-spacing: 1px;
}

.logo span {
  color: #00bfff;
}

.tagline {
  color: #b6c0d1;
  margin-top: 5px;
  font-size: 14px;
}

.search-box input {
  width: 360px;
  max-width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid #2a3447;
  background: #0f1520;
  color: white;
  outline: none;
}

/* Navbar */
.navbar {
  background: #101723;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.nav-links {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px 0;
}

.nav-links a {
  padding: 10px 14px;
  border-radius: 10px;
  color: #e8edf7;
  transition: 0.25s;
}

.nav-links a:hover {
  background: #1d2a3d;
  color: #39ff14;
}

/* Hero */
.hero {
  padding: 35px 0;
  background: radial-gradient(circle at top left, rgba(0,191,255,0.15), transparent 30%),
              radial-gradient(circle at top right, rgba(57,255,20,0.09), transparent 25%);
}

.hero-content {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
  align-items: center;
}

.hero-text {
  background: #121823;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 28px;
}

.hero-text h1 {
  margin-top: 0;
  font-size: 34px;
  color: #ffffff;
}

.hero-text p {
  color: #c7d0dd;
}

.hero-image img {
  border-radius: 18px;
  height: 100%;
  object-fit: cover;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.hero-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: 2.3fr 1fr;
  gap: 24px;
  margin-top: 30px;
  margin-bottom: 40px;
}

.content section {
  margin-bottom: 35px;
}

.section-title {
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  color: #39ff14;
}

.section-title p {
  margin: 6px 0 0;
  color: #9eabc0;
}

/* Cards */
.post-card,
.widget,
.video-card,
.download-box,
.single-post {
  background: #121823;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.18);
}

.post-card {
  display: flex;
  gap: 18px;
  padding: 16px;
  margin-bottom: 18px;
}

.post-card img {
  width: 220px;
  height: 155px;
  object-fit: cover;
  border-radius: 14px;
}

.post-info {
  flex: 1;
}

.post-info h3 {
  margin-top: 0;
  margin-bottom: 8px;
  color: #ffffff;
}

.post-info p {
  margin: 0 0 12px;
  color: #c5cedb;
}

.meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.meta span {
  background: #0f1520;
  color: #9ddfff;
  border: 1px solid #233049;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.post-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-block;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: bold;
  transition: 0.25s;
}

.btn.small {
  padding: 10px 14px;
  font-size: 14px;
}

.btn.primary {
  background: #00bfff;
  color: #04131a;
}

.btn.primary:hover {
  background: #33ccff;
}

.btn.secondary {
  background: transparent;
  border: 1px solid #2e415f;
  color: #d8e7ff;
}

.btn.secondary:hover {
  background: #192435;
}

.btn.success {
  background: #39ff14;
  color: #081006;
}

.btn.success:hover {
  background: #58ff39;
}

/* Sidebar */
.widget {
  padding: 18px;
  margin-bottom: 18px;
}

.widget h3 {
  margin-top: 0;
  color: #00bfff;
}

.widget ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.widget li {
  margin-bottom: 10px;
}

.widget a {
  color: #d9e5f5;
  transition: 0.2s;
}

.widget a:hover {
  color: #39ff14;
}

/* Video */
.video-card {
  padding: 16px;
}

.video-card video {
  width: 100%;
  border-radius: 14px;
  background: #000;
}

.video-card p {
  margin-bottom: 0;
  color: #cad2df;
}

/* Gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.gallery-grid img {
  border-radius: 16px;
  height: 220px;
  object-fit: cover;
  transition: transform 0.25s;
}

.gallery-grid img:hover {
  transform: scale(1.02);
}

/* Download box */
.download-box {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.download-box a {
  background: #0f1520;
  border: 1px solid #263550;
  padding: 14px 16px;
  border-radius: 12px;
  color: #f2f7ff;
  transition: 0.25s;
}

.download-box a:hover {
  background: #1a2535;
  color: #39ff14;
}

/* Footer */
footer {
  background: #0b0f16;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 32px;
}

.footer-inner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

footer h4 {
  margin-top: 0;
  color: #39ff14;
}

footer ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

footer li {
  margin-bottom: 8px;
}

footer p, footer a {
  color: #c2cede;
}

footer a:hover {
  color: #00bfff;
}

.copyright {
  text-align: center;
  color: #8190a7;
  padding: 18px 0;
  margin-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.05);
}

/* Single Post */
.single-post-page {
  padding: 30px 0 50px;
}

.single-post {
  padding: 22px;
}

.single-cover {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  border-radius: 16px;
  margin-bottom: 20px;
}

.single-post h1 {
  margin-top: 0;
}

.feature-list {
  padding-right: 20px;
}

.download-panel {
  margin-top: 22px;
}

document.addEventListener("DOMContentLoaded", () => {
  const searchInput = document.getElementById("searchInput");
  const searchableItems = document.querySelectorAll(".searchable");

  /*
  جست‌وجوی زنده بین کارت‌های بازی و مطالب
  */
  if (searchInput) {
    searchInput.addEventListener("input", () => {
      const searchText = searchInput.value.trim().toLowerCase();
      let visibleItems = 0;

      searchableItems.forEach((item) => {
        const content = item.textContent.toLowerCase();
        const isMatch = content.includes(searchText);

        item.style.display = isMatch ? "" : "none";

        if (isMatch) {
          visibleItems++;
          item.classList.add("search-result");
        } else {
          item.classList.remove("search-result");
        }
      });

      showSearchMessage(searchText, visibleItems);
    });
  }

  /*
  انیمیشن نمایش کارت‌ها هنگام ورود به صفحه
  */
  const observer = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          entry.target.classList.add("show-card");
          observer.unobserve(entry.target);
        }
      });
    },
    {
      threshold: 0.12
    }
  );

  document.querySelectorAll(".post-card, .video-card").forEach((card) => {
    card.classList.add("hidden-card");
    observer.observe(card);
  });

  /*
  خبرنامه
  */
  const newsletterButton = document.querySelector(".newsletter button");
  const newsletterInput = document.querySelector(".newsletter input");

  if (newsletterButton && newsletterInput) {
    newsletterButton.addEventListener("click", () => {
      const email = newsletterInput.value.trim();

      if (!email) {
        showToast("لطفاً ایمیل خود را وارد کنید.", "error");
        newsletterInput.focus();
        return;
      }

      if (!isValidEmail(email)) {
        showToast("فرمت ایمیل صحیح نیست.", "error");
        newsletterInput.focus();
        return;
      }

      newsletterInput.value = "";
      showToast("عضویت شما با موفقیت انجام شد 🎮", "success");
    });

    newsletterInput.addEventListener("keydown", (event) => {
      if (event.key === "Enter") {
        newsletterButton.click();
      }
    });
  }

  /*
  کپی رمز فایل در post.html
  */
  const passwordElement =
    document.getElementById("filePass") ||
    document.getElementById("password");

  if (passwordElement) {
    passwordElement.addEventListener("click", copyPassword);
    passwordElement.title = "برای کپی کلیک کنید";
  }

  /*
  دکمه بازگشت به بالای صفحه
  */
  const backToTop = document.createElement("button");
  backToTop.className = "back-to-top";
  backToTop.innerHTML = "↑";
  backToTop.setAttribute("aria-label", "بازگشت به بالای صفحه");
  document.body.appendChild(backToTop);

  window.addEventListener("scroll", () => {
    backToTop.classList.toggle("visible", window.scrollY > 400);
  });

  backToTop.addEventListener("click", () => {
    window.scrollTo({
      top: 0,
      behavior: "smooth"
    });
  });

  /*
  اسکرول نرم برای لینک‌های داخلی
  */
  document.querySelectorAll('a[href^="#"]').forEach((link) => {
    link.addEventListener("click", (event) => {
      const targetId = link.getAttribute("href");

      if (targetId === "#") {
        event.preventDefault();
        return;
      }

      const target = document.querySelector(targetId);

      if (target) {
        event.preventDefault();
        target.scrollIntoView({
          behavior: "smooth",
          block: "start"
        });
      }
    });
  });
});


/*
نمایش پیام جست‌وجو
*/
function showSearchMessage(searchText, count) {
  let message = document.getElementById("searchMessage");

  if (!message) {
    message = document.createElement("div");
    message.id = "searchMessage";
    message.className = "search-message";

    const searchBox = document.querySelector(".search-box");

    if (searchBox) {
      searchBox.appendChild(message);
    }
  }

  if (!searchText) {
    message.textContent = "";
    message.classList.remove("active");
    return;
  }

  message.textContent =
    count > 0
      ? `${count} نتیجه پیدا شد`
      : "نتیجه‌ای پیدا نشد";

  message.classList.add("active");
}


/*
کپی رمز دانلود
*/
async function copyPassword() {
  const passwordElement =
    document.getElementById("filePass") ||
    document.getElementById("password");

  const messageElement =
    document.getElementById("copyMsg") ||
    document.querySelector(".copy-msg");

  if (!passwordElement) return;

  const password = passwordElement.textContent.trim();

  try {
    await navigator.clipboard.writeText(password);

    if (messageElement) {
      messageElement.textContent = "رمز با موفقیت کپی شد ✅";
      messageElement.classList.add("copied");

      setTimeout(() => {
        messageElement.textContent = "برای کپی روی رمز کلیک کنید";
        messageElement.classList.remove("copied");
      }, 2500);
    }

    showToast("رمز فایل کپی شد ✅", "success");
  } catch (error) {
    console.error("Copy failed:", error);
    showToast("کپی رمز انجام نشد؛ رمز را دستی انتخاب کنید.", "error");
  }
}


/*
پیام‌های شناور سایت
*/
function showToast(message, type = "success") {
  let toast = document.getElementById("ivToast");

  if (!toast) {
    toast = document.createElement("div");
    toast.id = "ivToast";
    document.body.appendChild(toast);
  }

  toast.textContent = message;
  toast.className = `iv-toast ${type}`;

  clearTimeout(window.toastTimer);

  window.toastTimer = setTimeout(() => {
    toast.classList.remove("show");
  }, 3000);

  requestAnimationFrame(() => {
    toast.classList.add("show");
  });
}


/*
بررسی ایمیل
*/
function isValidEmail(email) {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
