/* ============================================================
   منوی سه‌خط، پروفایل گرد و بهینه‌سازی موبایل
   ============================================================ */

/* ---------- دکمه سه‌خط ---------- */
.menu-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: border-color .3s ease;
}
.menu-btn:hover { border-color: var(--accent); }

.menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--fg);
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), opacity .25s ease;
}

.menu-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- هدر ---------- */
.topbar .brand { flex: 1; }
.auth { margin-inline-start: auto; }

/* ---------- پشت‌زمینه منو ---------- */
.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}
.menu-backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- خود منو (از سمت راست باز می‌شود) ---------- */
.site-menu {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 30;
  width: min(86vw, 320px);
  display: flex;
  flex-direction: column;
  padding: 18px 18px calc(28px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card);
  border-inline-start: 1px solid var(--line);
  box-shadow: -20px 0 40px -20px rgba(0, 0, 0, .45);
  transform: translateX(105%);
  transition: transform .4s cubic-bezier(.2, .8, .2, 1);
}
.site-menu.open { transform: none; }

body.menu-open { overflow: hidden; }

.menu-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.menu-head strong { font-size: 1.05rem; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
}

.menu-section-title {
  margin: 14px 0 6px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.menu-list a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--fg);
  transition: background .25s ease, color .25s ease;
}
.menu-list a:hover { background: var(--soft); color: var(--accent); }

/* ورود آیتم‌های منو با تأخیر پشت سر هم */
.site-menu.open .menu-list li {
  animation: rise .5s cubic-bezier(.2, .8, .2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 40ms + 120ms);
}

.menu-sep {
  height: 1px;
  margin: 14px 0;
  background: var(--line);
}

.menu-auth { display: flex; gap: 10px; }
.menu-auth a {
  flex: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.menu-logout button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: #e5484d;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- پروفایل گرد ---------- */
.avatar-link {
  display: inline-flex;
  border-radius: 50%;
  transition: transform .25s ease;
}
.avatar-link:hover { transform: scale(1.06); }

.avatar {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  object-fit: cover;
  color: #fff;
  font-weight: 900;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 3px var(--line);
}

.av-p1 { background: linear-gradient(135deg, #ff6a88, #ff99ac); }
.av-p2 { background: linear-gradient(135deg, #6d4aff, #a58bff); }
.av-p3 { background: linear-gradient(135deg, #2ec4b6, #5ee7ff); }
.av-p4 { background: linear-gradient(135deg, #ffb703, #fb8500); }
.av-p5 { background: linear-gradient(135deg, #06d6a0, #118ab2); }
.av-p6 { background: linear-gradient(135deg, #e0488f, #7b2cbf); }

/* ---------- صفحه حساب کاربری ---------- */
.account { max-width: 640px; margin: 0 auto; }

.account-head {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 16px 0 8px;
}
.account-head strong { font-size: 1.2rem; }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin: 12px 0 8px;
}
.preset-grid form { margin: 0; }

.preset-btn {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 50%;
  color: #fff;
  font: inherit;
  font-weight: 900;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform .25s ease, box-shadow .25s ease;
}
.preset-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 10px 20px -10px var(--accent);
}

.small { font-size: .85rem; }
.reset-form { margin-top: 16px; }

/* ---------- محدود کردن عناصر فقط روی موبایل ---------- */
.hide-sm { display: inline; }

/* ============================================================
   موبایل
   ============================================================ */
@media (max-width: 640px) {
  body { font-size: 15px; }

  .topbar {
    flex-wrap: nowrap;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }
  .topbar .brand { font-size: 1.05rem; }
  .auth { gap: 8px; }
  .hide-sm { display: none; }

  .menu-btn { width: 42px; height: 42px; }
  .theme-toggle { width: 40px; height: 40px; }

  .container { padding: 18px 14px calc(56px + env(safe-area-inset-bottom)); }

  .hero { padding: 18px 0 10px; }
  .hero h1 { font-size: 1.7rem; }
  .hero p { font-size: .92rem; }

  .search { flex-direction: row; max-width: none; margin-top: 16px; }
  .search .btn { flex-shrink: 0; }

  .section-title { margin: 28px 0 14px; }

  /* دو کارت کنار هم برای جا دادن محتوای بیشتر */
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .card { border-radius: 14px; }
  .card img, .cover-empty { aspect-ratio: 4 / 3; font-size: .85rem; }
  .card-body { padding: 10px 11px 12px; }
  .card h3 {
    font-size: .92rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .meta { gap: 8px; font-size: .74rem; }
  .tag { font-size: .68rem; padding: 0 8px; }

  /* اندازه مناسب انگشت */
  .btn, .like, .preset-btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-small { min-height: 38px; }
  .toolbar button { min-width: 42px; min-height: 38px; }
  .actions-row .btn { flex: 1 1 auto; }

  /* فیلدها با فونت ۱۶ پیکسلی تا iOS زوم نکند */
  input, select, textarea { font-size: 16px; padding: 12px 14px; }
  label { font-size: .9rem; }

  .auth-card { margin: 16px auto; }
  .submit { margin-top: 8px; }
  .submit, .article, .account { padding: 0; }
  .comments { margin-top: 26px; padding-top: 18px; }

  .article-head h1 { font-size: 1.45rem; line-height: 1.6; }
  .article .cover { border-radius: 12px; margin: 14px 0; }
  .prose { font-size: 1rem; line-height: 1.95; overflow-wrap: anywhere; }
  .prose img { max-width: 100%; height: auto; }
  .prose code { white-space: pre-wrap; }

  .list li { padding: 12px; }
  .preset-grid { grid-template-columns: repeat(3, 1fr); }

  .footer { font-size: .74rem; padding: 16px; }

  /* انیمیشن پس‌زمینه روی موبایل خاموش تا باتری و سرعت حفظ شود */
  body::before { animation: none; }
}

/* روی گوشی‌های لمسی، هاور که گیر نکند */
@media (hover: none) {
  .card:hover,
  .card:hover img,
  .btn:hover,
  .like:hover,
  .list li:hover,
  .avatar-link:hover,
  .preset-btn:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .site-menu, .menu-backdrop { transition: none; }
}
