/* دکمهٔ نصب PWA */
#installBtn {
  display: none;
}
#installBtn.show {
  display: grid;
}
/* راهنمای iOS */
#iosHint {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(30px) scale(0.9);
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  font-size: var(--f-xs);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.4s var(--ease-ios),
    transform 0.5s var(--ease-spring);
  z-index: 320;
  box-shadow: var(--shadow);
  line-height: 1.7;
  max-width: 90vw;
  text-align: center;
}
#iosHint.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
#iosHint b {
  color: var(--vio);
}
/* ═══ چنج‌لاگ ═══ */
.chlog-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-inline-end: 4px;
}
.chlog-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  background: var(--deep);
}
.chlog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}
.chlog-ver {
  font-weight: 800;
  font-size: var(--f-md);
  color: var(--acc);
  display: inline-flex;
  align-items: baseline; /* baseline، نه center — همه روی یه خط */
  gap: 5px;
  line-height: 1;
}
.chlog-ver-label {
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: 0.1px;
}
.chlog-ver-num {
  font-family: var(--mono);
  font-weight: 800;
  direction: ltr;
  unicode-bidi: isolate; /* مستقل از RTL والد — «1.5» هرگز جابه‌جا نمی‌شه */
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}
.chlog-date {
  font-size: var(--f-2xs);
  color: var(--dim);
  font-family: var(--mono);
}
.chlog-item ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.chlog-item li {
  font-size: var(--f-xs);
  color: var(--mut);
  line-height: 1.7;
  padding-inline-start: 1.1rem;
  position: relative;
}
.chlog-item li::before {
  content: "▸";
  position: absolute;
  inset-inline-start: 0;
  color: var(--vio);
  opacity: 0.7;
}

/* لینک inline تو چنج‌لاگ */
.chlog-link {
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--acc);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 1px dotted
    color-mix(in srgb, var(--acc) 55%, transparent);
  transition:
    color 0.15s var(--ease),
    border-bottom-color 0.15s var(--ease);
}
.chlog-link:hover {
  color: var(--txt);
  border-bottom-color: var(--txt);
}
.chlog-link:active {
  opacity: 0.7;
}
.chlog-current {
  display: inline-block;
  font-size: var(--f-2xs);
  font-weight: 800;
  color: var(--acc);
  background: color-mix(in srgb, var(--acc) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--acc) 40%, transparent);
  padding: 1px 8px;
  border-radius: 999px;
}
/* ═══ نشان آپدیت روی دکمهٔ تنظیمات ═══ */
#settingsBtn.has-update::before {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ros);
  box-shadow: 0 0 0 2px var(--card);
  animation: updPulse 1.8s ease-in-out infinite;
}
@keyframes updPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.7; }
}
/* ══════════════ توکن‌ها ══════════════ */
:root {
  --bg: #070b16;
  --bg2: #0a1122;
  --card: #101a33;
  --card2: #152142;
  --deep: #0b1226;
  --line: rgba(140, 160, 255, 0.14);
  --line2: rgba(140, 160, 255, 0.28);
  --txt: #eaeefb;
  --mut: #a5b0d2;
  --dim: #67739b;
  --vio: #a78bfa;
  --blu: #60a5fa;
  --cyn: #22d3ee;
  --grn: #34d399;
  --amb: #fbbf24;
  --ros: #fb7185;
  --focus: #7c8adb;
  --ink: #0b0f1e;
  --acc: #a78bfa;
  --acc-ink: #0b0f1e;
  --header-bg: rgba(8, 12, 24, 0.68);
  --shadow: 0 14px 40px rgba(2, 5, 18, 0.55);
  --menu-shadow: 0 18px 44px rgba(2, 5, 18, 0.55),
    0 2px 6px rgba(0, 0, 0, 0.2);
  --ease: cubic-bezier(0.22, 0.75, 0.3, 1);
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
  --gap: 16px;
  --header-h: 64px;

  /* ═══ سیستم اندازه ═══
--fs-base مرجع rem است (html{font-size:var(--fs-base)})
پس هر 1rem معادل اندازهٔ پایهٔ انتخاب‌شده کاربر می‌شود */
  --fs-base: 16px;
  --f-2xs: 0.75rem; /* ~12px  — کوچک‌ترین متن مجاز */
  --f-xs: 0.82rem; /* ~13px  — متن ثانویه */
  --f-sm: 0.88rem; /* ~14px  — متن پیش‌فرض بدنهٔ ریز */
  --f-md: 0.94rem; /* ~15px  — متن عادی */
  --f-lg: 1rem; /*  16px  — عنوان کوچک */
  --f-xl: 1.06rem; /* ~17px  — عنوان مودال */
  --f-2xl: 1.25rem; /* ~20px  — عنوان بزرگ */

  /* مونو دوزبانه: لاتین با فونت مونو، فارسی با Vazirmatn.
     ترتیب مهمه — Vazirmatn قبل از monospace عمومی میاد
     تا حروف فارسی به fallback سیستم نرن. */
  --mono:
    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", "Vazirmatn", monospace, system-ui,
    sans-serif;
}
:root[data-theme="light"] {
  --bg: #f3f5fb;
  --bg2: #eaeef8;
  --card: #fff;
  --card2: #eef2fb;
  --deep: #e8edf8;
  --line: rgba(23, 44, 110, 0.13);
  --line2: rgba(23, 44, 110, 0.26);
  --txt: #18203a;
  --mut: #49557c;
  --dim: #7d87ab;
  --vio: #6d28d9;
  --blu: #1d4ed8;
  --cyn: #0e7490;
  --grn: #047857;
  --amb: #b45309;
  --ros: #be123c;
  --acc: #7c3aed;
  --acc-ink: #ffffff;
  --header-bg: rgba(255, 255, 255, 0.74);
  --shadow: 0 12px 32px rgba(90, 110, 170, 0.18);
  --menu-shadow: 0 16px 40px rgba(90, 110, 170, 0.2),
    0 2px 6px rgba(90, 110, 170, 0.1);
  --focus: #4f6bd8;
}

/* ═══ پالت‌های رنگ تأکیدی ═══ */
:root[data-accent="ocean"] {
  --acc: #60a5fa;
  --acc-ink: #0b0f1e;
}
:root[data-accent="forest"] {
  --acc: #34d399;
  --acc-ink: #0b0f1e;
}
:root[data-accent="sunset"] {
  --acc: #fb923c;
  --acc-ink: #0b0f1e;
}
:root[data-accent="galaxy"] {
  --acc: #f472b6;
  --acc-ink: #0b0f1e;
}
:root[data-accent="mono"] {
  --acc: #94a3b8;
  --acc-ink: #0b0f1e;
}

:root[data-accent="mono"] .brand .logo {
  background: var(--acc-ink);
}
:root[data-accent="mono"] .brand .logo svg {
  fill: var(--acc);
}

:root[data-theme="light"][data-accent="ocean"] {
  --acc: #2563eb;
  --acc-ink: #ffffff;
}
:root[data-theme="light"][data-accent="forest"] {
  --acc: #059669;
  --acc-ink: #ffffff;
}
:root[data-theme="light"][data-accent="sunset"] {
  --acc: #ea580c;
  --acc-ink: #ffffff;
}
:root[data-theme="light"][data-accent="galaxy"] {
  --acc: #db2777;
  --acc-ink: #ffffff;
}
:root[data-theme="light"][data-accent="mono"] {
  --acc: #475569;
  --acc-ink: #ffffff;
}

:root[data-fs="small"] {
  --fs-base: 14px;
}
:root[data-fs="large"] {
  --fs-base: 18px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* حذف هالهٔ آبی/سیاه هنگام لمس روی موبایل */
  -webkit-tap-highlight-color: transparent;
}
html {
  scroll-behavior: smooth;
  font-size: var(--fs-base);
  /* غیرفعال‌سازی pull-to-refresh بومی — جایگزین: pull نرم برای sync */
  overscroll-behavior-y: contain;
  /* همیشه جای اسکرول‌بار رزرو می‌شود → باز/بسته شدن پنل‌ها هیچ جابه‌جایی‌ای ایجاد نمی‌کند */
  scrollbar-gutter: stable;
  overflow-y: scroll;
}
body {
  font-family: "Vazirmatn", system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--txt);
  font-size: 1rem;
  line-height: 1.8;
  overflow-x: clip;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
/* قفل اسکرول — فقط overflow: hidden. position: fixed لازم نیست و
   به‌خاطر فریم میانی بین تغییر html و body باعث پرش می‌شد.
   scrollbar-gutter: stable روی html، جای نوار رو همیشه رزرو می‌کنه. */
html.no-scroll,
body.no-scroll {
  overflow: hidden;
}
/* قفل بدنه موقع باز بودن ادیتور روی موبایل —
   چرا فقط ادیتور: iOS وقتی caret رو می‌خواد وسط صفحه بذاره،
   کل layout viewport رو می‌کشه. با position: fixed روی body،
   دیگه چیزی برای کشیدن نیست. تنظیمات و پیش‌نمایش این مشکل رو ندارن. */
body.kb-lock {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(
      900px 500px at 88% -8%,
      rgba(124, 58, 237, 0.15),
      transparent 60%
    ),
    radial-gradient(
      700px 600px at 50% 112%,
      rgba(59, 130, 246, 0.12),
      transparent 60%
    ),
    radial-gradient(
      circle,
      rgba(167, 139, 250, 0.14) 1.1px,
      transparent 1.3px
    );
  background-size: auto, auto, 32px 32px;
}
:root[data-theme="light"] body::before {
  background:
    radial-gradient(
      900px 500px at 88% -8%,
      rgba(124, 58, 237, 0.08),
      transparent 60%
    ),
    radial-gradient(
      700px 600px at 50% 112%,
      rgba(59, 130, 246, 0.06),
      transparent 60%
    ),
    radial-gradient(
      circle,
      rgba(109, 40, 217, 0.1) 1.1px,
      transparent 1.3px
    );
  background-size: auto, auto, 32px 32px;
}

/* ═══ پس‌زمینه‌های انتزاعی ═══ */

/* ── رنگین (mesh) ── */
:root[data-bg="mesh"] body::before {
  background:
    radial-gradient(60% 55% at 18% 12%, rgba(167, 139, 250, 0.22), transparent 72%),
    radial-gradient(55% 50% at 85% 22%, rgba(96, 165, 250, 0.18), transparent 75%),
    radial-gradient(55% 55% at 28% 92%, rgba(52, 211, 153, 0.14), transparent 72%),
    radial-gradient(48% 52% at 92% 88%, rgba(251, 191, 36, 0.12), transparent 72%);
}
:root[data-theme="light"][data-bg="mesh"] body::before {
  background:
    radial-gradient(60% 55% at 18% 12%, rgba(124, 58, 237, 0.1), transparent 72%),
    radial-gradient(55% 50% at 85% 22%, rgba(37, 99, 235, 0.08), transparent 75%),
    radial-gradient(55% 55% at 28% 92%, rgba(5, 150, 105, 0.07), transparent 72%),
    radial-gradient(48% 52% at 92% 88%, rgba(180, 83, 9, 0.06), transparent 72%);
}

/* ── شبکه (grid) ── */
:root[data-bg="grid"] body::before {
  background:
    radial-gradient(700px 420px at 88% -10%, rgba(124, 58, 237, 0.1), transparent 70%),
    linear-gradient(rgba(140, 160, 255, 0.055) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, rgba(140, 160, 255, 0.055) 1px, transparent 1px) 0 0 / 44px 44px;
}
:root[data-theme="light"][data-bg="grid"] body::before {
  background:
    radial-gradient(700px 420px at 88% -10%, rgba(124, 58, 237, 0.05), transparent 70%),
    linear-gradient(rgba(23, 44, 110, 0.06) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, rgba(23, 44, 110, 0.06) 1px, transparent 1px) 0 0 / 44px 44px;
}

/* ── نقطه‌ای (dots) ── */
:root[data-bg="dots"] body::before {
  background:
    radial-gradient(700px 420px at 88% -10%, rgba(124, 58, 237, 0.1), transparent 70%),
    radial-gradient(circle, rgba(167, 139, 250, 0.16) 1.3px, transparent 1.6px) 0 0 / 26px 26px;
}
:root[data-theme="light"][data-bg="dots"] body::before {
  background:
    radial-gradient(700px 420px at 88% -10%, rgba(124, 58, 237, 0.05), transparent 70%),
    radial-gradient(circle, rgba(109, 40, 217, 0.11) 1.3px, transparent 1.6px) 0 0 / 26px 26px;
}

/* ── راه‌راه (stripes) ── */
:root[data-bg="stripes"] body::before {
  background:
    radial-gradient(700px 420px at 88% -10%, rgba(124, 58, 237, 0.09), transparent 70%),
    repeating-linear-gradient(
      135deg,
      rgba(140, 160, 255, 0.045) 0 18px,
      transparent 18px 44px
    );
}
:root[data-theme="light"][data-bg="stripes"] body::before {
  background:
    radial-gradient(700px 420px at 88% -10%, rgba(124, 58, 237, 0.05), transparent 70%),
    repeating-linear-gradient(
      135deg,
      rgba(23, 44, 110, 0.05) 0 18px,
      transparent 18px 44px
    );
}

/* ── ساده (clean) ── */
:root[data-bg="clean"] body::before {
  background: radial-gradient(
    900px 500px at 50% -10%,
    rgba(124, 58, 237, 0.06),
    transparent 70%
  );
}
:root[data-theme="light"][data-bg="clean"] body::before {
  background: radial-gradient(
    900px 500px at 50% -10%,
    rgba(124, 58, 237, 0.04),
    transparent 70%
  );
}

/* body::after (grid overlay) حذف شد برای عملکرد WebView */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: #26335c;
  border-radius: 8px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: #374a82;
}
:root[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #c2cbe3;
}
::selection {
  background: rgba(139, 92, 246, 0.45);
}
button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}

/* غیرفعال‌سازی منوی بومی long-press روی عناصر تعاملی */
.ibtn,
.pin,
.icon-btn,
.etb-toggle,
.etb-close,
.sel-act,
.sel-close,
.qf-part,
.tag-clickable,
.chip {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
code {
  font-family: var(--mono);
  direction: ltr;
  display: inline-block;
  color: var(--cyn);
  font-size: var(--f-xs);
}

/* ══════════════ هدر ══════════════ */
header.top {
  position: sticky;
  top: 0;
  z-index: 60;
  display: grid;
  grid-template-columns:
    minmax(0, 1fr) minmax(0, clamp(340px, 44vw, 620px))
    minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  background: var(--header-bg);
  backdrop-filter: blur(5px) saturate(1.5);
  -webkit-backdrop-filter: blur(5px) saturate(1.5);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  min-height: var(--header-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  justify-self: start;
}
.brand .logo {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 12px;
  background: var(--acc);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--acc) 40%, transparent);
  flex-shrink: 0;
}
.brand .logo svg {
  width: 1.55rem;
  height: 1.55rem;
  fill: var(--acc-ink);
}
.brand h1 {
  font-size: var(--f-md);
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}
.brand small {
  display: block;
  font-size: var(--f-2xs);
  font-weight: 400;
  color: var(--mut);
}

.hend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-self: end;
}
.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--mut);
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s,
    color 0.2s,
    background 0.2s;
  position: relative;
  flex-shrink: 0;
}
.icon-btn svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}
.icon-btn:hover {
  transform: translateY(-1px);
  border-color: var(--focus);
  color: var(--txt);
}
.icon-btn:active {
  transform: scale(0.94);
}

/* ══════════════ سرچ دسکتاپ ══════════════ */
.searchwrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
  max-width: none;
  justify-self: stretch;
}
.searchwrap input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 0.6rem 2.5rem 0.6rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--deep);
  font-size: var(--f-sm);
  outline: none;
  transition:
    border-color 0.22s var(--ease),
    box-shadow 0.22s var(--ease);
}
.searchwrap input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 4px rgba(124, 92, 219, 0.14);
}
.searchwrap .sic {
  position: absolute;
  right: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--dim);
  pointer-events: none;
  width: 1rem;
  height: 1rem;
  display: grid;
  place-items: center;
}
.searchwrap .sic svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

#searchRes {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: min(460px, 72vh);
  overflow-y: auto;
  display: none;
  z-index: 80;
  padding: 6px;
}
#searchRes.show {
  display: block;
  animation: resIn 0.18s var(--ease);
}
@keyframes resIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ══════════════ موبایل: سرچ ══════════════ */
#mSearchBtn {
  display: none;
}
#mSearchBtn .mi {
  display: none;
}
#mSearchBtn .mi svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}
#mSearchBtn .mi-search {
  display: block;
}
#mSearchBtn.on .mi-search {
  display: none;
}
#mSearchBtn.on .mi-close {
  display: block;
}
#mSearchBtn.on {
  border-color: var(--vio);
  color: var(--vio);
}

/* وقتی سرچ موبایل باز است، هدر/فوتر را مات کن
   تا بک‌دراپ تیره از پشت شیشهٔ نیمه‌شفافشان دیده نشود */
body.msearch-open header.top,
body.msearch-open footer.app-footer {
  background: var(--card);
}

.msearch-back {
  position: fixed;
  inset: 0;
  z-index: 54;
  background: rgba(3, 6, 16, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.42s var(--ease-ios),
    visibility 0s linear 0.42s;
  display: none;
}
.msearch-back.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 0.42s var(--ease-ios),
    visibility 0s;
  /* جایگزین قفل اسکرول: تاچ روی پس‌زمینه هیچ ژستی اجرا نمی‌کند */
  touch-action: none;
  overscroll-behavior: contain;
}

.msearch {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 56;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h) - 16px);
  max-height: calc(100dvh - var(--header-h) - 16px);
  background: linear-gradient(180deg, var(--card), var(--deep));
  border-bottom: 1px solid var(--line2);
  border-radius: 0 0 20px 20px;
  box-shadow: 0 20px 50px rgba(2, 5, 18, 0.6);
  transform: translateY(-24px);
  opacity: 0;
  visibility: hidden;
  transition:
    transform 0.35s var(--ease-ios),
    opacity 0.25s var(--ease-ios),
    visibility 0s linear 0.35s;
  flex-direction: column;
  overflow: hidden;
  display: none;
}
.msearch.open {
  transform: none;
  opacity: 1;
  visibility: visible;
  transition:
    transform 0.4s var(--ease-ios),
    opacity 0.25s var(--ease-ios),
    visibility 0s;
}
.msearch-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.msearch-bar .mb-ic {
  color: var(--dim);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.msearch-bar .mb-ic svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}
.msearch-bar input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--f-lg);
  font-weight: 600;
  padding: 4px 0;
  color: var(--txt);
}
.msearch-bar input::placeholder {
  color: var(--dim);
  font-weight: 500;
}
.msearch-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 12px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ══════════════ آیتم‌های نتایج ══════════════ */
.sp-group-label {
  font-size: var(--f-2xs);
  color: var(--dim);
  font-weight: 800;
  letter-spacing: 0.6px;
  padding: 10px 11px 4px;
  text-transform: uppercase;
}
.sp-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: right;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--txt);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.sp-item:hover,
.sp-item.active {
  background: var(--card2);
}
.sp-item-ic {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 9px;
  flex-shrink: 0;
  background: var(--deep);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--mut);
}
.sp-item-ic svg {
  width: 0.9rem;
  height: 0.9rem;
  display: block;
}
.sp-item.active .sp-item-ic {
  color: var(--vio);
  border-color: rgba(139, 92, 246, 0.4);
}
.sp-item-body {
  flex: 1;
  min-width: 0;
}
.sp-item-title {
  display: block;
  font-size: var(--f-sm);
  font-weight: 600;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-item-title mark {
  background: rgba(251, 191, 36, 0.22);
  color: var(--amb);
  border-radius: 4px;
  padding: 0 2px;
}
.sp-item-sub {
  display: block;
  font-size: var(--f-2xs);
  color: var(--dim);
  line-height: 1.5;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-item-meta {
  font-size: var(--f-2xs);
  color: var(--dim);
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
  flex-shrink: 0;
  font-family: var(--mono);
  unicode-bidi: plaintext;
}
.sp-empty {
  padding: 30px 14px;
  text-align: center;
  color: var(--dim);
  font-size: var(--f-sm);
}

/* ══════════════ چیدمان ══════════════ */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.15rem clamp(12px, 3vw, 32px) 4.5rem;
}

/* ══════════════ فیلتر ══════════════ */
.filters {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}
.chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-width: 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.9rem;
  border-radius: 999px;
  background: var(--card2);
  border: 1px solid var(--line);
  font-size: var(--f-xs);
  color: var(--mut);
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s var(--ease);
  font-family: inherit;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--line2);
  color: var(--txt);
}
.chip:active {
  transform: scale(0.95);
}
.chip.on {
  background: color-mix(in srgb, var(--acc) 15%, transparent);
  color: var(--txt);
  border-color: color-mix(in srgb, var(--acc) 55%, transparent);
}
.chip .cnt {
  font-size: var(--f-2xs);
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(140, 160, 255, 0.1);
  border: 1px solid var(--line);
}
.chip.on .cnt {
  color: var(--acc);
  border-color: color-mix(in srgb, var(--acc) 45%, transparent);
}
.chip .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.b-vio {
  background: var(--vio);
}
.dot.b-blu {
  background: var(--blu);
}
.dot.b-cyn {
  background: var(--cyn);
}
.dot.b-grn {
  background: var(--grn);
}
.dot.b-amb {
  background: var(--amb);
}
.dot.b-ros {
  background: var(--ros);
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
@media (min-width: 761px) {
  .filters {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }
  .chips {
    flex: 1;
  }
  .filter-actions {
    flex-shrink: 0;
  }
}

/* ══════════════ دکمه‌ها ══════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: 11px;
  border: 1px solid var(--line2);
  background: var(--card2);
  font-size: var(--f-sm);
  font-weight: 700;
  cursor: pointer;
  transition: 0.22s var(--ease);
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover {
  transform: translateY(-1px);
  border-color: var(--focus);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.22);
}
.btn:active {
  transform: scale(0.97);
}
.btn.g {
  background: var(--acc);
  color: var(--acc-ink);
  border: none;
  font-weight: 800;
}
.btn.sm {
  padding: 0.4rem 0.8rem;
  font-size: var(--f-xs);
  border-radius: 9px;
}
.btn.dgr {
  border-color: rgba(251, 113, 133, 0.5);
  color: var(--ros);
}

.btn.g.dgr {
  background: #dc2626;
  color: #fff;
  border: none;
}
.btn.g.dgr:hover {
  background: #ef4444;
  box-shadow: 0 8px 20px rgba(220, 38, 38, 0.3);
}

/* ══════════════ Custom Select ══════════════ */
.cselect {
  position: relative;
  display: inline-block;
}
.cselect.full {
  display: block;
  width: 100%;
}
.cselect-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card2);
  font-size: var(--f-xs);
  font-weight: 600;
  color: var(--mut);
  cursor: pointer;
  transition: 0.2s var(--ease);
  font-family: inherit;
}
.cselect.full .cselect-btn {
  width: 100%;
  justify-content: space-between;
  padding: 0.65rem 0.9rem;
  font-size: var(--f-sm);
}
.cselect-btn:hover {
  border-color: var(--line2);
  color: var(--txt);
}
.cselect-btn .cs-ic {
  display: grid;
  place-items: center;
  color: var(--dim);
}
.cselect-btn .cs-ic svg {
  width: 0.85rem;
  height: 0.85rem;
  display: block;
}
.cselect-btn .cs-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}
.cselect-btn .cs-chev {
  display: grid;
  place-items: center;
  color: var(--dim);
  transition: transform 0.2s var(--ease);
}
.cselect-btn .cs-chev svg {
  width: 0.7rem;
  height: 0.7rem;
  display: block;
}
.cselect.open .cselect-btn {
  border-color: var(--focus);
  color: var(--txt);
  box-shadow: 0 0 0 3px rgba(124, 92, 219, 0.12);
}
.cselect.open .cs-chev {
  transform: rotate(180deg);
}
.cselect-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: max(180px, 100%);
  max-height: 260px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 5px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition:
    opacity 0.15s,
    transform 0.15s,
    visibility 0s linear 0.15s;
  z-index: 70;
}
.cselect.open .cselect-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 0.15s,
    transform 0.15s,
    visibility 0s;
}
.cselect-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: right;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--txt);
  font-size: var(--f-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
}
.cselect-item:hover {
  background: var(--card2);
}
.cselect-item .ci-check {
  width: 0.9rem;
  height: 0.9rem;
  flex-shrink: 0;
  color: var(--vio);
  opacity: 0;
  display: grid;
  place-items: center;
}
.cselect-item .ci-check svg {
  width: 0.9rem;
  height: 0.9rem;
  display: block;
}
.cselect-item.on .ci-check {
  opacity: 1;
}
.cselect-item.on {
  color: var(--vio);
}

/* ══════════════ گرید کارت‌ها ══════════════ */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: var(--gap);
}
.grid.filtering {
  animation: gridIn 0.32s var(--ease-ios);
}
@keyframes gridIn {
  from {
    opacity: 0.4;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (max-width: 980px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 620px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: linear-gradient(160deg, var(--card), var(--deep));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.1rem 1.1rem 0.85rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 13rem;
  transition:
    transform 0.45s var(--ease-ios),
    border-color 0.35s var(--ease-ios),
    box-shadow 0.35s var(--ease-ios);
  animation: rise 0.5s var(--ease-ios) both;
  /* مرورگر کارت‌های خارج از viewport رو رندر نمی‌کنه.
     12rem: اندازهٔ تخمینی هر کارت برای layout پایدار.
     content-visibility: auto رفتار پیش‌فرض بافر رو داره (~۵۰٪ viewport).
     با ۱۰۰-۲۰۰ کارت معمولی، این کافیه. */
  content-visibility: auto;
  contain-intrinsic-size: auto 13rem;
}
.card:hover {
  border-color: var(--line2);
  /* transform رو عوض کردیم به box-shadow —
     چون transform روی .card باعث می‌شد containing block برای tooltip
     بشه و تولتیپ pin به‌جای بالای دکمه، داخل کارت ظاهر بشه. */
  box-shadow: 0 20px 48px rgba(2, 5, 18, 0.62);
}
:root[data-theme="light"] .card:hover {
  box-shadow: 0 20px 48px rgba(90, 110, 170, 0.28);
}
.grid.no-anim .card {
  animation: none;
}
/* لیست‌های بزرگ: انیمیشن فقط برای ۱۲ کارت اول، بقیه بدون */
.grid.mass-list .card:nth-child(n + 13) {
  animation: none;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.card.flash {
  animation: flash 1.6s ease;
}
@keyframes flash {
  0% {
    box-shadow:
      0 0 0 3px rgba(251, 191, 36, 0.7),
      var(--shadow);
  }
  100% {
    box-shadow:
      0 0 0 0 transparent,
      var(--shadow);
  }
}

.phead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}
.phead b {
  grid-column: 2;
}
.phead .pcat {
  grid-column: 3;
}

.phead .pin {
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  border: 1px solid var(--line2);
  background: var(--deep);
  color: var(--mut);
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s var(--ease),
    background 0.2s var(--ease),
    color 0.2s var(--ease),
    box-shadow 0.22s var(--ease);
}
.phead .pin svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}
.phead .pin:hover {
  transform: translateY(-2px);
  border-color: var(--focus);
  color: var(--txt);
  background: var(--card2);
}
.phead .pin:active {
  transform: scale(0.94);
}
.phead .pin.on {
  color: var(--amb);
  border-color: rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.12);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.1);
}
.phead .pin.on:hover {
  transform: translateY(-2px);
  border-color: rgba(251, 191, 36, 0.8);
  background: rgba(251, 191, 36, 0.2);
}

.phead b {
  font-size: var(--f-md);
  font-weight: 800;
  line-height: 1.5;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.pcat {
  font-size: var(--f-2xs);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid;
  font-weight: 800;
  flex-shrink: 0;
  align-self: flex-start;
  white-space: nowrap;
}
.b-vio {
  color: var(--vio);
  border-color: rgba(167, 139, 250, 0.4);
  background: rgba(167, 139, 250, 0.1);
}
.b-blu {
  color: var(--blu);
  border-color: rgba(96, 165, 250, 0.4);
  background: rgba(96, 165, 250, 0.1);
}
.b-cyn {
  color: var(--cyn);
  border-color: rgba(34, 211, 238, 0.4);
  background: rgba(34, 211, 238, 0.1);
}
.b-grn {
  color: var(--grn);
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
}
.b-amb {
  color: var(--amb);
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
}
.b-ros {
  color: var(--ros);
  border-color: rgba(251, 113, 133, 0.4);
  background: rgba(251, 113, 133, 0.1);
}

.pdesc {
  color: var(--mut);
  font-size: var(--f-xs);
  line-height: 1.75;
  margin-bottom: 0.6rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ptags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
}
.tag {
  font-size: var(--f-2xs);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  gap: 1px;
  line-height: 1;
}
.tag .th {
  color: var(--vio);
  opacity: 0.55;
  font-weight: 800;
}
.tag .tw {
  line-height: 1;
}
.pfoot {
  margin-top: auto;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  border-top: 1px dashed var(--line);
  padding-top: 0.75rem;
  padding-bottom: 2px;
}
.pfoot .grow {
  flex: 1;
}

.ibtn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card2);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--mut);
  position: relative;
  flex-shrink: 0;
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s,
    background 0.2s,
    color 0.2s;
}
.ibtn:hover {
  transform: translateY(-2px);
  border-color: var(--focus);
  color: var(--txt);
  background: var(--card);
}
.ibtn:active {
  transform: scale(0.94);
}
.ibtn svg {
  width: 1.2rem;
  height: 1.2rem;
  display: block;
}
.ibtn.dgr {
  color: var(--ros);
}
.ibtn.dgr:hover {
  border-color: var(--ros);
  background: rgba(251, 113, 133, 0.08);
}
/* tooltip‌ها از `::after` به یه لایهٔ گلوبال (#gtip) منتقل شدن —
   چون content-visibility روی کارت‌ها، descendants بیرون‌زننده رو
   clip می‌کنه. JS موقعیت‌دهی می‌کنه. */

/* ══════════════ جهت خودکار محتوا ══════════════ */
.phead b,
.pdesc,
.pv-titles b,
.pv-desc,
.sp-item-title,
.sp-item-sub,
.dialog-msg {
  unicode-bidi: plaintext;
  text-align: start;
}

/* ══════════════ حالت خالی ══════════════ */
.empty {
  text-align: center;
  color: var(--dim);
  padding: 60px 20px;
  font-size: var(--f-md);
}
.empty svg {
  width: 3.5rem;
  height: 3.5rem;
  opacity: 0.35;
  margin-bottom: 1rem;
  color: var(--vio);
}
.empty h3 {
  font-size: var(--f-lg);
  font-weight: 700;
  color: var(--mut);
  margin-bottom: 0.5rem;
}
.empty p {
  line-height: 1.8;
  margin-bottom: 1rem;
}
.empty-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  margin-top: 0.75rem;
  border-radius: 11px;
  border: 1px dashed color-mix(in srgb, var(--acc) 45%, transparent);
  background: color-mix(in srgb, var(--acc) 6%, transparent);
  color: color-mix(in srgb, var(--acc) 75%, var(--mut));
  font-family: inherit;
  font-size: var(--f-sm);
  font-weight: 700;
  cursor: pointer;
  transition: 0.18s var(--ease);
}
.empty-cta:hover {
  background: color-mix(in srgb, var(--acc) 12%, transparent);
  border-style: solid;
  color: var(--acc);
}
.empty-cta:active {
  transform: scale(0.97);
}
.empty-cta svg {
  width: 1rem;
  height: 1rem;
  display: block;
  flex-shrink: 0;
}

/* ══════════════ Modal ══════════════ */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(3, 6, 16, 0.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  place-items: safe center;
  padding: 24px 16px;
  overflow-y: auto;
}
.modal-back.open {
  display: grid;
  /* ژست‌های تاچ روی backdrop بلاک می‌شن، ولی خودِ modal-back
     همچنان قابل اسکرول عمودیه (چون overflow-y: auto داره) —
     پس این دو با هم تعارضی ندارن. */
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.modal {
  background: linear-gradient(160deg, var(--card), var(--deep));
  border: 1px solid var(--line2);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 780px;
  padding: 1.4rem;
  animation: rise 0.28s var(--ease) both;
}
.modal h2 {
  font-size: var(--f-xl);
  font-weight: 800;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.modal label {
  display: block;
  font-size: var(--f-xs);
  color: var(--mut);
  margin-bottom: 5px;
  font-weight: 600;
}
.modal .inp,
.modal textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--deep);
  font-size: var(--f-sm);
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.modal .inp:focus,
.modal textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 4px rgba(124, 92, 219, 0.14);
}
.modal textarea {
  resize: vertical;
  line-height: 1.75;
}
.modal textarea.mono {
  font-family: var(--mono);
  direction: ltr;
  text-align: left;
  font-size: var(--f-xs);
  line-height: 1.75;
  unicode-bidi: plaintext;
}
.modal .row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  margin-bottom: 0.75rem;
}
.modal .row.full {
  grid-template-columns: 1fr;
}
.modal .foot {
  display: flex;
  gap: 9px;
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* ══════════════ Editor ══════════════ */
.editor-back {
  padding: 24px 16px;
  align-items: center;
}
.editor-modal {
  max-width: 960px;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 900px);
  height: min(90vh, 900px);
  overflow: visible;
  border-radius: 14px;
}
.editor-modal.meta-hidden .editor-meta {
  display: none;
}

#pTitle.field-error,
#pContent.field-error,
.field-error {
  border-color: var(--ros);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.2);
}

.editor-titlebar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.8rem;
  background: var(--deep);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  border-radius: 14px 14px 0 0;
}
.editor-titlebar .etb-dots {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.editor-titlebar .etb-dots span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: block;
}
.editor-titlebar .etb-dots span:nth-child(1) {
  background: #ff5f57;
}
.editor-titlebar .etb-dots span:nth-child(2) {
  background: #febc2e;
}
.editor-titlebar .etb-dots span:nth-child(3) {
  background: #28c840;
}
.editor-titlebar .etb-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: var(--f-xs);
  font-weight: 700;
  color: var(--mut);
  justify-content: center;
}
.editor-titlebar .etb-icon {
  display: grid;
  place-items: center;
  color: var(--dim);
}
.editor-titlebar .etb-icon svg {
  width: 0.85rem;
  height: 0.85rem;
  display: block;
}
.editor-titlebar .etb-close {
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--mut);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s var(--ease),
    background 0.2s var(--ease),
    color 0.2s var(--ease);
}
.editor-titlebar .etb-close:hover {
  transform: translateY(-2px);
  border-color: var(--ros);
  color: var(--ros);
  background: var(--card);
}
.editor-titlebar .etb-close:active {
  transform: scale(0.94);
}
.editor-titlebar .etb-close svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.editor-meta {
  display: grid;
  grid-template-columns: minmax(0, 190px) minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 0.65rem 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  overflow: visible;
  animation: metaIn 0.22s var(--ease-ios);
}
/* موبایل: انیمیشن ورود متادیتا رو غیرفعال کن —
   با باز شدن کیبورد قاطی می‌شه و حس lag می‌ده. */
@media (max-width: 760px) {
  .editor-meta {
    animation: none;
  }
}
@keyframes metaIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.editor-meta .em-title {
  grid-column: 1 / -1;
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--deep);
  font-size: var(--f-md);
  font-weight: 700;
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  unicode-bidi: plaintext;
}
.editor-meta .em-title:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(124, 92, 219, 0.14);
}
.editor-meta .em-row {
  display: contents;
}
.editor-meta .em-tags,
.editor-meta .em-desc {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--deep);
  font-size: var(--f-sm);
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.editor-meta .em-tags:focus,
.editor-meta .em-desc:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(124, 92, 219, 0.14);
}

.editor-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  direction: ltr;
  background: #080d1c;
  overflow: hidden;
}
.editor-gutter {
  flex-shrink: 0;
  width: 3.5rem;
  /* padding-top باید با .editor-area یکی باشه — وگرنه شماره‌ها
     از خطوط متن چند پیکسل جابه‌جا می‌شن. */
  padding: 0.85rem 0.6rem 0.85rem 0;
  text-align: right;
  font-family: var(--mono);
  font-weight: 400;
  font-size: var(--f-xs);
  line-height: 1.5rem;
  color: #5d6b98;
  background: rgba(255, 255, 255, 0.015);
  border-right: 1px solid rgba(140, 160, 255, 0.08);
  user-select: none;
  overflow: hidden;
  white-space: pre;
  pointer-events: none;
}
:root[data-theme="light"] .editor-wrap {
  background: #f8fafd;
}
:root[data-theme="light"] .editor-gutter {
  color: #8b95b8;
  background: rgba(23, 44, 110, 0.03);
  border-right-color: rgba(23, 44, 110, 0.08);
}
.editor-area {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1rem;
  border: none;
  background: transparent;
  color: #b9dcff;
  font-family: var(--mono);
  font-weight: 400;
  font-size: var(--f-xs);
  line-height: 1.5rem;
  outline: none;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: none;
  tab-size: 2;
  unicode-bidi: normal;
  text-align: start;
  caret-color: var(--vio);
  -webkit-overflow-scrolling: touch;
}
.editor-area::-webkit-resizer {
  display: none;
  background: transparent;
  border: none;
}
.editor-area::-webkit-scrollbar-corner {
  background: transparent;
}
.pv-body pre::-webkit-scrollbar-corner {
  background: transparent;
}
:root[data-theme="light"] .editor-area {
  color: #1f2a4a;
  caret-color: var(--blu);
}
:root[data-theme="light"] .editor-area::placeholder {
  color: #8b95b8;
  opacity: 0.7;
}
.editor-area::placeholder {
  color: var(--dim);
  opacity: 0.55;
}
.editor-area::selection {
  background: rgba(139, 92, 246, 0.35);
}

.editor-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  background: var(--deep);
  border-top: 1px solid var(--line);
  font-size: var(--f-2xs);
  color: var(--dim);
  flex-shrink: 0;
}
.editor-status > span {
  white-space: nowrap;
}
.editor-status .es-sep {
  opacity: 0.5;
}
.editor-status .es-spacer {
  flex: 1;
}
.editor-status .es-lang {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--mut);
  font-weight: 700;
  font-family: "Vazirmatn", system-ui, sans-serif;
}

.editor-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  padding: 0.8rem 1rem;
  background: var(--card);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  border-radius: 0 0 14px 14px;
}
.editor-actions .btn {
  min-width: 6rem;
}

/* ═══ دکمه‌های نوار عنوان ═══ */
.editor-titlebar .etb-toggle {
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--mut);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  transition: 0.2s var(--ease);
}
.editor-titlebar .etb-toggle:hover {
  border-color: var(--focus);
  color: var(--txt);
  background: var(--card);
}
.editor-titlebar .etb-toggle svg {
  width: 1rem;
  height: 1rem;
  display: block;
}
.editor-titlebar .etb-toggle.on {
  color: var(--vio);
  border-color: rgba(139, 92, 246, 0.45);
  background: linear-gradient(
    135deg,
    rgba(139, 92, 246, 0.14),
    rgba(34, 211, 238, 0.08)
  );
}

/* ═══ ادیتور موبایل ═══ */
@media (max-width: 760px) {
  .editor-back {
    padding: 0;
    overflow: hidden;
    scrollbar-width: none;
    align-items: flex-start;
  }
  .editor-back::-webkit-scrollbar {
    display: none;
  }

  .editor-modal {
    max-width: none;
    max-height: var(--vvh, 100dvh);
    height: var(--vvh, 100dvh);
    border-radius: 0;
    border: none;
  }

  .editor-titlebar,
  .editor-meta,
  .editor-toolbar,
  .editor-status,
  .editor-actions,
  .editor-wrap {
    background: transparent;
  }

  .editor-titlebar {
    padding: 0.55rem 0.75rem;
    border-radius: 0;
  }
  .editor-titlebar .etb-dots {
    display: none;
  }
  .editor-titlebar .etb-title {
    justify-content: flex-start;
    font-size: var(--f-sm);
  }
  .editor-titlebar .etb-close {
    width: 2.15rem;
    height: 2.15rem;
  }

  .editor-meta {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
  }
  .editor-meta .em-title {
    font-size: var(--f-sm);
    padding: 0.6rem 0.75rem;
  }
  .editor-meta .em-tags,
  .editor-meta .em-desc {
    padding: 0.55rem 0.75rem;
    font-size: var(--f-xs);
  }

  .editor-wrap {
    border-radius: 0;
  }

  .editor-gutter {
    display: block;
    width: 2.25rem;
    padding: 0.85rem 0.4rem 0.85rem 0;
    text-align: right;
    font-family: var(--mono);
    /* font-size باید با .editor-area یکی باشه — وگرنه baseline جابه‌جا
       می‌شه و شماره‌های گاتر چند پیکسل از خطوط جدا می‌افتن. */
    font-size: var(--f-xs);
    line-height: 1.4rem;
    color: var(--dim);
    background: transparent;
    border-right: none;
    user-select: none;
    overflow: hidden;
    white-space: pre;
    pointer-events: none;
  }
  :root[data-theme="light"] .editor-gutter {
    color: #8b95b8;
    background: transparent;
    border-right: none;
  }

  .editor-area {
    padding: 0.85rem 0.75rem;
    font-size: var(--f-xs);
    line-height: 1.4rem;
    resize: none !important;
    -webkit-appearance: none;
    appearance: none;
    /* نوار اسکرول رو موبایل مخفی — روی layout موبایل ظاهر می‌شه
       و بین گاتر و متن یه خط عمودی زشت می‌سازه. */
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .editor-area::-webkit-scrollbar {
    width: 0;
    height: 0;
  }

  .editor-status {
    padding: 0.4rem 0.75rem;
    font-size: var(--f-2xs);
    gap: 5px;
    border-top: 1px solid var(--line);
  }
  .editor-status .es-lang {
    font-size: var(--f-2xs);
    padding: 1px 7px;
  }

  .editor-actions {
    padding: 0.65rem 0.75rem
      calc(0.65rem + env(safe-area-inset-bottom, 0px));
    gap: 0.5rem;
    border-radius: 0;
    border-top: 1px solid var(--line);
  }
  .editor-actions .btn {
    flex: 1;
    min-width: 0;
    padding: 0.65rem 0.75rem;
    font-size: var(--f-sm);
  }
}

/* ══════════════ Dialog — Premium ══════════════ */
.dialog-modal {
  max-width: 400px;
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
}
.dialog-accent {
  height: 3px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--acc) 20%,
    var(--acc) 80%,
    transparent
  );
  transition: background 0.22s var(--ease);
}
.dialog-modal.is-danger .dialog-accent {
  background: linear-gradient(
    90deg,
    transparent,
    var(--ros) 20%,
    var(--ros) 80%,
    transparent
  );
}
.dialog-body {
  padding: 1.35rem 1.4rem 1.2rem;
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.6rem;
}
.dialog-ic {
  width: 1.1rem;
  height: 1.1rem;
  color: var(--acc);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.dialog-ic svg {
  width: 100%;
  height: 100%;
  display: block;
}
.dialog-modal.is-danger .dialog-ic {
  color: var(--ros);
}
.dialog-modal.is-help .dialog-ic {
  color: var(--blu);
}
.dialog-modal.is-down .dialog-ic {
  color: var(--grn);
}
.dialog-title {
  font-size: var(--f-xl);
  font-weight: 800;
  letter-spacing: 0.1px;
  line-height: 1.35;
  color: var(--txt);
  min-width: 0;
}

.dialog-msg {
  font-size: var(--f-sm);
  color: var(--mut);
  line-height: 1.85;
  margin-bottom: 1.2rem;
  overflow-wrap: anywhere;
  /* جلوگیری از کلمهٔ تک‌افتاده در خط آخر — مرورگرهای جدید */
  text-wrap: pretty;
}
.dialog-msg b {
  color: var(--txt);
  font-weight: 700;
}
.dialog-msg:empty {
  display: none;
}

.dialog-modal #dialogFieldWrap {
  margin-bottom: 1.2rem;
}

/* فوتر — N دکمه با عرض یکسان، RTL: اولین در راست */
.modal .foot.dialog-foot {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 0.6rem;
  margin-top: 0;
  flex-wrap: nowrap;
}
.modal .foot.dialog-foot .btn {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: var(--f-sm);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* انصراف — ghost */
.dialog-foot #dialogCancel,
.dialog-foot #importCancelBtn,
.dialog-foot #bulkMoveCancelBtn {
  background: transparent;
  border-color: var(--line);
  color: var(--mut);
  font-weight: 700;
}
.dialog-foot #dialogCancel:hover,
.dialog-foot #importCancelBtn:hover,
.dialog-foot #bulkMoveCancelBtn:hover {
  color: var(--txt);
  border-color: var(--line2);
  background: var(--card2);
  box-shadow: none;
}

/* تأیید — پرایمری فیل */
.dialog-foot #dialogOk,
.dialog-foot #importMergeBtn {
  background: var(--acc);
  color: var(--acc-ink);
  border: none;
  font-weight: 800;
}
.dialog-foot #dialogOk:hover,
.dialog-foot #importMergeBtn:hover {
  background: color-mix(in srgb, var(--acc) 88%, #fff);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--acc) 35%, transparent);
}

/* در حالت danger، تأیید به outline قرمز تغییر می‌کند —
   با یه پس‌زمینهٔ خیلی ملایم قرمز تا وزن بصری‌اش با «انصراف» برابر باشه. */
.dialog-modal.is-danger .dialog-foot #dialogOk {
  background: color-mix(in srgb, var(--ros) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--ros) 55%, transparent);
  color: var(--ros);
  font-weight: 800;
}
.dialog-modal.is-danger .dialog-foot #dialogOk:hover {
  background: color-mix(in srgb, var(--ros) 16%, transparent);
  border-color: var(--ros);
  box-shadow: none;
}

/* جایگزین کن — danger outline */
.dialog-foot #importReplaceBtn {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--ros) 55%, transparent);
  color: var(--ros);
  font-weight: 800;
}
.dialog-foot #importReplaceBtn:hover {
  background: color-mix(in srgb, var(--ros) 12%, transparent);
  border-color: var(--ros);
  box-shadow: none;
}

/* ══════════════ Dialog — Premium ══════════════ */

@media (max-width: 480px) {
  .dialog-modal {
    max-width: none;
    width: 100%;
    border-radius: 14px;
  }
  .dialog-body {
    padding: 0.95rem 1rem 0.85rem;
  }
  .dialog-accent {
    height: 2.5px;
  }
  .dialog-head {
    gap: 0.45rem;
    margin-bottom: 0.4rem;
  }
  .dialog-ic {
    width: 1rem;
    height: 1rem;
  }
  .dialog-title {
    font-size: var(--f-md);
    line-height: 1.3;
  }
  .dialog-msg {
    font-size: var(--f-xs);
    line-height: 1.75;
    margin-bottom: 0.9rem;
  }
  .modal .foot.dialog-foot {
    gap: 0.45rem;
  }
  .modal .foot.dialog-foot .btn {
    padding: 0.6rem 0.6rem;
    font-size: var(--f-xs);
    border-radius: 10px;
  }
}

/* ══════════════ Drawer تنظیمات ══════════════ */
.drawer-back {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(3, 6, 16, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.42s var(--ease-ios),
    visibility 0s linear 0.42s;
}
.drawer-back.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  touch-action: none;
  overscroll-behavior: contain;
  transition:
    opacity 0.42s var(--ease-ios),
    visibility 0s;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 95;
  width: min(440px, 100%);
  background: linear-gradient(160deg, var(--card), var(--deep));
  border-inline-start: 1px solid var(--line2);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.35s var(--ease-ios);
  display: flex;
  flex-direction: column;
}
.drawer.open {
  transform: none;
}
.drawer-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.5rem 1rem;
  min-height: 3.5rem;
  background: var(--deep);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.drawer-head .icon-btn {
  background: transparent;
  border-color: transparent;
}
.drawer-head .icon-btn:hover {
  background: var(--card2);
  border-color: var(--line2);
}
.drawer-head h2 {
  flex: 1;
  font-size: var(--f-lg);
  font-weight: 800;
}
.drawer-body {
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.group {
  margin-bottom: 1.4rem;
}
.group:last-child {
  margin-bottom: 0;
}
.group h4 {
  font-size: var(--f-2xs);
  color: var(--dim);
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.group h4::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.row-pref {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}
.row-pref:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.row-pref:first-of-type {
  padding-top: 0;
}
.row-pref .label {
  flex: 1;
  min-width: 120px;
}
.row-pref .label b {
  display: block;
  font-size: var(--f-sm);
  font-weight: 700;
}
.row-pref .label span {
  font-size: var(--f-2xs);
  color: var(--mut);
  line-height: 1.65;
}

.seg {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  background: var(--deep);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.seg:not(.swatches) button {
  position: relative;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--mut);
  font-size: var(--f-xs);
  font-weight: 700;
  cursor: pointer;
  transition: color 0.22s var(--ease);
  font-family: inherit;
  isolation: isolate;
}
.seg:not(.swatches) button::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--acc, var(--vio));
  opacity: 0;
  transform: scale(0.86);
  transition:
    opacity 0.2s var(--ease),
    transform 0.34s cubic-bezier(0.34, 1.4, 0.5, 1);
  z-index: -1;
  pointer-events: none;
}
.seg:not(.swatches) button:hover {
  color: var(--txt);
}
.seg:not(.swatches) button.on {
  color: var(--acc-ink, var(--ink));
}
.seg:not(.swatches) button.on::before {
  opacity: 1;
  transform: scale(1);
  box-shadow: 0 3px 10px
    color-mix(in srgb, var(--acc, var(--vio)) 35%, transparent);
}
.seg.swatches {
  gap: 10px;
  padding: 0.5rem 0.75rem;
  background: var(--deep);
  border-radius: 12px;
}
.seg.swatches button {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s var(--ease),
    box-shadow 0.25s var(--ease);
}
.seg.swatches button::before {
  content: "";
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background: var(--sw);
  transition: transform 0.2s var(--ease);
}
.seg.swatches button:hover {
  border-color: var(--line2);
  transform: translateY(-1px);
}
.seg.swatches button.on {
  border-color: var(--vio);
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 4px var(--vio);
}
.seg.swatches button.on::before {
  transform: scale(1.06);
}
.sw-default {
  --sw: conic-gradient(
    from 90deg,
    #a78bfa 0 90deg,
    #60a5fa 90deg 180deg,
    #34d399 180deg 270deg,
    #fbbf24 270deg 360deg
  );
}
.sw-ocean {
  --sw: linear-gradient(135deg, #60a5fa, #22d3ee);
}
.sw-forest {
  --sw: linear-gradient(135deg, #34d399, #84cc16);
}
.sw-sunset {
  --sw: linear-gradient(135deg, #fb7185, #fbbf24);
}
.sw-galaxy {
  --sw: linear-gradient(135deg, #c084fc, #f472b6);
}
.sw-mono {
  --sw: linear-gradient(135deg, #e2e8f0, #475569);
}

/* ═══ پیش‌نمایش پس‌زمینه‌ها ═══ */
.bg-default {
  --sw: conic-gradient(
    from 210deg at 65% 35%,
    #a78bfa, #60a5fa, #22d3ee, #34d399, #a78bfa
  );
}
.bg-mesh {
  --sw: linear-gradient(
    135deg,
    #a78bfa 0%,
    #60a5fa 35%,
    #34d399 70%,
    #fbbf24 100%
  );
}
.bg-grid {
  --sw:
    linear-gradient(rgba(167, 139, 250, 0.9) 1px, transparent 1px) 0 0 / 6px
      6px,
    linear-gradient(90deg, rgba(167, 139, 250, 0.9) 1px, transparent 1px) 0
      0 / 6px 6px,
    #0b1226;
}
.bg-dots {
  --sw:
    radial-gradient(circle, #a78bfa 1.2px, transparent 1.6px) 0 0 / 7px 7px,
    #0b1226;
}
.bg-stripes {
  --sw: repeating-linear-gradient(
    45deg,
    #a78bfa 0 4px,
    #0b1226 4px 9px
  );
}
.bg-clean {
  --sw: linear-gradient(180deg, #152142, #0b1226);
}

/* ══════════════ نوار مرتب‌سازی — هم‌جای نوار عادی ══════════════ */
/* دکمه‌های حالت عادی با ابزارهای مرتب‌سازی swap می‌شن،
   بدون تغییر موقعیت در صفحه. */

.cat-reorder-tools {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}
.cat-reorder-tools[hidden] {
  display: none;
}

/* دکمه‌های ↑/↓ — مربع، مینیمال، با border روشن */
.cat-tool-btn {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--deep);
  color: var(--txt);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  flex-shrink: 0;
  transition:
    background 0.15s var(--ease),
    border-color 0.15s var(--ease),
    color 0.15s var(--ease),
    transform 0.12s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.cat-tool-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}
.cat-tool-btn:hover:not(:disabled) {
  border-color: var(--line2);
  background: var(--card2);
  color: var(--acc);
}
.cat-tool-btn:active:not(:disabled) {
  transform: scale(0.94);
  background: color-mix(in srgb, var(--acc) 14%, var(--deep));
}
.cat-tool-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* شمارندهٔ انتخاب — وسط، کمرنگ */
.cat-reorder-count {
  text-align: center;
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: var(--f-xs);
  font-weight: 700;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-reorder-count::before {
  content: "";
}
/* اگه خواستی فقط یه عدد باشه بدون پیشوند */
.cat-reorder-count:not(:empty)::after {
  content: "";
}

/* دکمهٔ پایان — پرایمری، کنار ↓ */
.cat-tool-done {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  height: 2.3rem;
  border: none;
  border-radius: 10px;
  background: var(--acc);
  color: var(--acc-ink);
  font-family: inherit;
  font-size: var(--f-sm);
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    transform 0.12s var(--ease),
    box-shadow 0.2s var(--ease),
    background 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.cat-tool-done:hover {
  background: color-mix(in srgb, var(--acc) 88%, #fff);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--acc) 36%, transparent);
}
.cat-tool-done:active {
  transform: scale(0.96);
}
.cat-tool-done svg {
  width: 0.95rem;
  height: 0.95rem;
  display: block;
}

@media (max-width: 760px) {
  .cat-tool-btn {
    width: 2.1rem;
    height: 2.1rem;
  }
  .cat-tool-btn svg {
    width: 0.95rem;
    height: 0.95rem;
  }
  .cat-tool-done {
    padding: 0.5rem 0.7rem;
    height: 2.1rem;
    font-size: var(--f-xs);
  }
  .cat-tool-done svg {
    width: 0.85rem;
    height: 0.85rem;
  }
  /* تو موبایل باریک، شمارنده فقط عدد نشون بده */
  .cat-reorder-count {
    font-size: var(--f-2xs);
    color: var(--dim);
  }
}

/* روی خیلی باریک، متن «انتخاب» رو حذف کن و فقط عدد بمونه */
@media (max-width: 420px) {
  .cat-reorder-count {
    font-size: 0;
  }
  .cat-reorder-count::before {
    content: attr(data-count);
    font-size: var(--f-sm);
    font-weight: 800;
    color: var(--acc);
  }
}

/* ══════════════ لیست دسته‌ها ══════════════ */
.cat-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  min-height: 2.3rem;
}
.cat-head[hidden] {
  display: none;
}
.cat-head #addCatBtn {
  flex: 1;
}
.cat-head #reorderCatsBtn {
  flex-shrink: 0;
}
/* هر دکمه/ابزاری که تو head هست، اگه [hidden] شد واقعاً غیب شه —
   چون displayهای صریح بالا بر [hidden] غالب می‌شن. */
.cat-head > [hidden],
.cat-head #addCatBtn[hidden],
.cat-head #reorderCatsBtn[hidden],
.cat-head .cat-reorder-tools[hidden] {
  display: none !important;
}
.cat-head #addCatBtn {
  border-style: dashed;
  padding: 0.7rem 0.9rem;
  font-size: var(--f-sm);
  border-radius: 11px;
}
.cat-head #reorderCatsBtn {
  padding: 0.7rem 0.9rem;
  font-size: var(--f-sm);
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.cat-head #reorderCatsBtn svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.cat-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.cat-empty {
  font-size: var(--f-xs);
  color: var(--dim);
  padding: 6px 2px;
}
.cat-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: var(--deep);
  border: 1px solid var(--line);
  transition:
    background 0.18s var(--ease),
    border-color 0.18s var(--ease),
    box-shadow 0.18s var(--ease),
    transform 0.18s var(--ease);
}

/* ── ردیف قابل انتخاب (حالت مرتب‌سازی) ── */
button.cat-item.selectable {
  width: 100%;
  text-align: start;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}
button.cat-item.selectable:hover {
  border-color: var(--line2);
  background: color-mix(in srgb, var(--card2) 40%, var(--deep));
}
button.cat-item.selectable:active {
  transform: scale(0.99);
}
button.cat-item.selectable:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
button.cat-item.selected {
  border-color: color-mix(in srgb, var(--acc) 55%, transparent);
  background: color-mix(in srgb, var(--acc) 12%, var(--deep));
  box-shadow:
    inset 3px 0 0 var(--acc),
    0 4px 14px color-mix(in srgb, var(--acc) 18%, transparent);
}
button.cat-item.selected .cat-check {
  background: var(--acc);
  border-color: var(--acc);
  color: var(--acc-ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 18%, transparent);
}
button.cat-item.selected .cat-check svg {
  opacity: 1;
  transform: scale(1);
}
.cat-item:hover {
  border-color: var(--line2);
}
.cat-item .dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ═══ چک‌باکس ردیف در حالت مرتب‌سازی ═══ */
.cat-check {
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 6px;
  border: 1.5px solid var(--line2);
  background: var(--card);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: transparent;
  transition:
    background 0.2s var(--ease),
    border-color 0.2s var(--ease),
    box-shadow 0.25s var(--ease);
}
.cat-check svg {
  width: 0.75rem;
  height: 0.75rem;
  display: block;
  opacity: 0;
  transform: scale(0.5);
  transition:
    opacity 0.15s var(--ease),
    transform 0.24s var(--ease-spring);
}
.cat-item-name {
  flex: 1;
  font-size: var(--f-sm);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-item-cnt {
  font-size: var(--f-2xs);
  color: var(--dim);
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--card2);
  border: 1px solid var(--line);
}
.cat-item-btn {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--card2);
  cursor: pointer;
  color: var(--mut);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  font-family: inherit;
  transition: 0.15s var(--ease);
}
.cat-item-btn svg {
  width: 0.75rem;
  height: 0.75rem;
  display: block;
}
.cat-item-btn:hover:not(:disabled) {
  color: var(--txt);
  border-color: var(--focus);
}
.cat-item-btn.dgr:hover:not(:disabled) {
  color: var(--ros);
  border-color: var(--ros);
}
.cat-item-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.cat-colors {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}
.cat-colors button {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--c);
  box-shadow: inset 0 0 0 6px var(--card);
  transition: 0.18s var(--ease);
}
.cat-colors button.on {
  box-shadow:
    inset 0 0 0 6px var(--card),
    0 0 0 2px var(--card),
    0 0 0 4px var(--c);
  transform: scale(1.06);
}

/* ══════════════ پنل پیش‌نمایش ══════════════ */
.pv-back {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(3, 6, 16, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.42s var(--ease-ios),
    visibility 0s linear 0.42s;
}
.pv-back.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  /* رو موبایل به‌جای قفل اسکرول، ژست‌های تاچ روی backdrop رو بلاک می‌کنیم
     تا صفحهٔ پشتش نلرزه و هدر sticky جابه‌جا نشه. */
  touch-action: none;
  overscroll-behavior: contain;
  transition:
    opacity 0.42s var(--ease-ios),
    visibility 0s;
}
.pv-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 105;
  width: min(580px, 100%);
  background: linear-gradient(160deg, var(--card), var(--deep));
  border-inline-end: 1px solid var(--line2);
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform 0.4s var(--ease-ios);
  display: flex;
  flex-direction: column;
}
.pv-drawer.open {
  transform: none;
}
.pv-head {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex-shrink: 0;
}
.pv-titles {
  flex: 1;
  min-width: 0;
}
.pv-titles b {
  font-size: var(--f-lg);
  font-weight: 800;
  line-height: 1.5;
  display: block;
  overflow-wrap: anywhere;
}
.pv-meta {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.5rem;
}
.pv-meta .tag {
  font-size: var(--f-2xs);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--dim);
}
.pv-desc {
  padding: 0.75rem 1rem 0;
  color: var(--mut);
  font-size: var(--f-sm);
  line-height: 1.85;
}
.pv-desc:empty {
  display: none;
}
.pv-desc:empty + .var-hint {
  margin-top: 0.75rem;
}
.pv-body {
  flex: 1;
  min-height: 0;
  padding: 0.85rem 1rem;
  display: flex;
  min-width: 0;
}
.pv-wrap {
  flex: 1;
  display: flex;
  direction: ltr;
  background: #080d1c;
  border: 1px solid var(--line);
  border-radius: 12px;
  /* scroll روی خود wrap می‌شینه — گاتر و متن با هم، native */
  overflow: auto;
  overscroll-behavior: contain;
  min-width: 0;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #26335c transparent;
}
:root[data-theme="light"] .pv-wrap {
  scrollbar-color: #c2cbe3 transparent;
  background: #f8fafd;
}
.pv-gutter {
  flex-shrink: 0;
  width: 3.25rem;
  padding: 1rem 0.6rem 1rem 0;
  text-align: right;
  font-family: var(--mono);
  font-weight: 400;
  font-size: var(--f-xs);
  line-height: 1.5rem;
  color: #4a5680;
  background: rgba(255, 255, 255, 0.015);
  border-right: 1px solid rgba(140, 160, 255, 0.08);
  user-select: none;
  overflow: hidden;
  white-space: pre;
  pointer-events: none;
  position: sticky;
  left: 0;
  align-self: flex-start;
}
:root[data-theme="light"] .pv-gutter {
  color: #8b95b8;
  background: rgba(23, 44, 110, 0.03);
  border-right-color: rgba(23, 44, 110, 0.08);
}

.pv-body pre {
  flex: 1;
  min-width: 0;
  padding: 1rem;
  border: none;
  background: transparent;
  font-size: var(--f-xs);
  line-height: 1.5rem;
  color: #b9dcff;
  font-family: var(--mono);
  font-weight: 400;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: none;
  overflow: visible;
  margin: 0;
  unicode-bidi: normal;
  text-align: start;
}
:root[data-theme="light"] .pv-body pre {
  scrollbar-color: #c2cbe3 transparent;
  color: #1f2a4a;
}
.pv-foot {
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  overflow: visible;
}
.pv-foot > * {
  flex-shrink: 0;
}
.pv-foot .spacer {
  flex: 1;
}

/* ── منوی AI ── */
.ai-open-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.ai-open-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 190px;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 5px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition:
    opacity 0.15s var(--ease),
    transform 0.15s var(--ease),
    visibility 0s linear 0.15s;
  z-index: 90;
}
.ai-open-wrap.open .ai-open-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 0.15s var(--ease),
    transform 0.15s var(--ease),
    visibility 0s;
}
.ai-open-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: right;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--txt);
  font-size: var(--f-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
}
.ai-open-item:hover {
  background: var(--card2);
}
.ai-open-item .ai-dot {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--ai-c);
  color: #fff;
  font-family: var(--mono);
  font-weight: 800;
  font-size: var(--f-2xs);
  letter-spacing: -0.4px;
  line-height: 1;
}
.ai-open-item .ai-tag {
  font-size: var(--f-2xs);
  font-weight: 800;
  color: var(--dim);
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
  margin-inline-start: auto;
  flex-shrink: 0;
}
.ai-open-wrap.open #pvOpenInAI {
  border-color: var(--focus);
  color: var(--txt);
  background: var(--card);
  transform: translateY(-2px);
}

/* ══════════════ متغیرها ══════════════ */
.pv-body pre .var {
  color: var(--amb);
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 5px;
  padding: 0 5px;
  font-weight: 700;
}
.var-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--f-xs);
  color: var(--amb);
  padding: 0.5rem 0.75rem;
  margin: 0 1rem 0.5rem;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: 9px;
  line-height: 1.6;
}
.var-hint b {
  font-weight: 800;
}
.var-hint-ic {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
  color: currentColor;
}
.var-hint > span {
  flex: 1;
  min-width: 0;
}
.var-modal-icon {
  color: var(--amb);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.var-modal-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

/* ═══ مودال متغیرها — Deck ═══ */
.var-deck {
  position: relative;
  width: fit-content;
  max-width: 100%;
  justify-self: center;
  transition: transform 0.4s var(--ease-ios);
}
.var-deck.preview-open {
  /* نصف عرض پنل + نصف gap — تا گروه کامل وسط بشینه */
  transform: translateX(194px);
}
.var-modal {
  position: relative;
  z-index: 2;
  width: 620px;
  max-width: 100%;
  padding: 1.3rem 1.3rem 1rem;
}

/* هدر + دکمهٔ toggle */
.var-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.var-head h2 {
  flex: 1;
  margin: 0;
}
.var-preview-toggle {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--mut);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition:
    border-color 0.2s var(--ease),
    background 0.2s var(--ease),
    color 0.2s var(--ease);
}
.var-preview-toggle:hover {
  border-color: var(--line2);
  color: var(--txt);
}
.var-preview-toggle.on {
  color: var(--acc);
  border-color: color-mix(in srgb, var(--acc) 45%, var(--line));
  background: color-mix(in srgb, var(--acc) 12%, transparent);
}
.var-preview-toggle svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

/* کارت پیش‌نمایش — absolute، بیرون از مودال، چسبیده به لبهٔ inline-end */
.var-preview-panel {
  position: absolute;
  inset-inline-start: 100%;
  top: 0;
  bottom: 0;
  width: 380px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--line2);
  background: linear-gradient(160deg, var(--card), var(--deep));
  box-shadow: var(--shadow);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateX(380px);
  transition:
    opacity 0.35s var(--ease-ios),
    transform 0.4s var(--ease-ios);
  margin-inline-start: 8px;
}
.var-deck.preview-open .var-preview-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.var-preview-panel-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid color-mix(in srgb, var(--vio) 18%, var(--line));
  background: color-mix(in srgb, var(--vio) 5%, transparent);
  font-size: var(--f-xs);
  font-weight: 700;
  color: var(--mut);
  flex-shrink: 0;
}
.var-preview-panel-title {
  flex: 1;
  min-width: 0;
}
.var-preview-back {
  display: none;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--mut);
  cursor: pointer;
  place-items: center;
  flex-shrink: 0;
  transition:
    border-color 0.2s var(--ease),
    color 0.2s var(--ease),
    background 0.2s var(--ease),
    transform 0.12s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.var-preview-back:hover {
  border-color: var(--line2);
  color: var(--txt);
  background: var(--card);
}
.var-preview-back:active {
  transform: scale(0.94);
}
.var-preview-back svg {
  width: 1rem;
  height: 1rem;
  display: block;
}
.var-preview-panel .var-preview {
  flex: 1;
  min-height: 0;
  max-height: none;
  border-top: none;
  border-radius: 0;
}
.var-preview-foot {
  display: none;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.var-preview-foot .btn {
  flex: 1;
}

.var-preview-toggle {
  display: grid;
}
/* روی نمایشگرهای باریک، کارت رو باریک‌تر کن که کنار مودال جا شه */
@media (min-width: 760px) and (max-width: 1140px) {
  .var-modal {
    width: 520px;
  }
  .var-preview-panel {
    width: 300px;
    transform: translateX(300px);
  }
  .var-deck.preview-open .var-preview-panel {
    transform: translateX(0);
  }
  .var-deck.preview-open {
    /* (300 + 8) / 2 */
    transform: translateX(154px);
  }
}

/* ── موبایل: overlay داخلی + تب ── */
@media (max-width: 759px) {
  .var-deck {
    position: relative;
    width: auto;
    max-width: none;
    justify-self: stretch;
  }
  .var-deck.preview-open {
    transform: none;
  }
  .var-modal {
    width: 100%;
    max-width: none;
    padding: 1.1rem 1rem 0.9rem;
  }

  /* کارت پیش‌نمایش — لایه‌ای که از پشت میاد داخل */

  .var-preview-panel {
    position: absolute;
    inset: 0;
    margin: 0;
    width: auto;
    max-width: none;
    border-radius: 16px;
    z-index: 5;
    display: flex;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-102%) scale(0.97);
    transform-origin: center center;
    transition:
      opacity 0.28s var(--ease-ios),
      transform 0.5s var(--ease-spring);
    will-change: transform, opacity;
  }
  .var-deck.preview-open .var-preview-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0) scale(1);
  }
  /* هدر و فوتر همیشه نمایش (چون لایه‌ست نه تب) */
  .var-preview-back {
    display: grid;
  }
  .var-preview-foot {
    display: flex;
  }
}

/* روی موبایل، فقط مودال متغیرها از بالا شروع شه تا با کیبورد اسکرول بشه */
@media (max-width: 759px) {
  #varModalBack {
    place-items: start center;
    padding: 0.75rem;
    align-content: start;
    overflow-x: hidden;
  }
  #varModalBack .modal {
    margin: 0 0 1rem;
    max-height: none;
  }
  .var-modal {
    padding: 1.1rem 1rem 0.9rem;
  }
}

.var-intro {
  font-size: var(--f-xs);
  color: var(--mut);
  line-height: 1.75;
  padding: 0.6rem 0.85rem;
  background: rgba(251, 191, 36, 0.06);
  border: 1px solid rgba(251, 191, 36, 0.18);
  border-radius: 9px;
  margin-bottom: 1.1rem;
}
.var-intro code {
  color: var(--amb);
  font-weight: 700;
}

.var-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0;
}
.var-form .var-row label {
  display: block;
  margin-bottom: 5px;
}
.var-form .var-row label code {
  font-size: var(--f-xs);
  color: var(--amb);
  font-weight: 700;
}
.var-form .var-row input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--deep);
  font-size: var(--f-sm);
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.var-form .var-row input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 4px rgba(124, 92, 219, 0.14);
}

.var-preview {
  margin: 0;
  border: none;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 0.7rem 0.9rem;
  background: transparent;
  color: var(--txt);
  font-family: var(--mono);
  font-weight: 400;
  font-size: var(--f-xs);
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: none;
  max-height: 220px;
  overflow: auto;
  unicode-bidi: normal;
  text-align: start;
}

/* دکمه‌های انتهایی */
.var-foot {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.55rem;
  margin-top: 1.2rem;
  align-items: stretch;
}
.var-foot .btn {
  padding: 0.7rem 0.9rem;
  font-size: var(--f-sm);
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}
.var-foot .btn svg {
  width: 1rem;
  height: 1rem;
  display: block;
  flex-shrink: 0;
}
.var-foot .var-btn-primary {
  font-weight: 800;
}
.var-foot .var-btn-sec {
  color: var(--mut);
  background: transparent;
  border-color: var(--line);
  font-weight: 700;
}
.var-foot .var-btn-sec:hover {
  color: var(--txt);
  border-color: var(--line2);
  background: var(--card2);
  box-shadow: none;
}
.var-foot .var-btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--mut);
  font-weight: 700;
  padding-inline: 0.75rem;
}
.var-foot .var-btn-ghost:hover {
  color: var(--txt);
  background: var(--card2);
  box-shadow: none;
  border-color: var(--line2);
}

@media (max-width: 520px) {
  .var-foot {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "primary primary"
      "ghost   sec";
    gap: 0.5rem;
  }
  .var-foot .var-btn-primary {
    grid-area: primary;
    order: -1;
    padding: 0.8rem;
    font-size: var(--f-md);
  }
  .var-foot .var-btn-ghost {
    grid-area: ghost;
  }
  .var-foot .var-btn-sec {
    grid-area: sec;
  }
}

/* ══════════════ توست ══════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(30px) scale(0.9);
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 0.65rem 1.1rem;
  font-size: var(--f-sm);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.4s var(--ease-ios),
    transform 0.5s var(--ease-spring);
  z-index: 300;
  box-shadow: var(--shadow);
  max-width: 90vw;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast-ic {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  color: var(--grn);
}
.toast-ic .tc,
.toast-ic .tk,
.toast-ic .tx1,
.toast-ic .tx2 {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.toast-ic .tc {
  stroke-dasharray: 82;
  stroke-dashoffset: 82;
}
.toast-ic .tk {
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
}
.toast-ic .tx1,
.toast-ic .tx2 {
  stroke-dasharray: 16;
  stroke-dashoffset: 16;
  display: none;
}

.toast.show .toast-ic .tc {
  animation: toastDrawCircle 0.5s var(--ease-ios) forwards;
}
.toast.show .toast-ic .tk {
  animation: toastDrawCheck 0.3s var(--ease-ios) 0.4s forwards;
}

@keyframes toastDrawCircle {
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes toastDrawCheck {
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes toastDrawX {
  to {
    stroke-dashoffset: 0;
  }
}

.toast.err .toast-ic {
  color: var(--ros);
}
.toast.err .toast-ic .tk {
  display: none;
}
.toast.err .toast-ic .tx1,
.toast.err .toast-ic .tx2 {
  display: inline;
}

.toast.err.show .toast-ic .tx1 {
  animation: toastDrawX 0.18s var(--ease-ios) 0.4s forwards;
}
.toast.err.show .toast-ic .tx2 {
  animation: toastDrawX 0.18s var(--ease-ios) 0.55s forwards;
}
.toast.warn .toast-ic {
  color: var(--amb);
}

#toastUndo {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(30px) scale(0.9);
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 0.35rem 0.35rem 0.35rem 0.85rem;
  font-size: var(--f-sm);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.4s var(--ease-ios),
    transform 0.5s var(--ease-spring);
  z-index: 305;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  direction: rtl;
}
#toastUndo.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}
#toastUndo .undo-txt {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
  padding-inline-end: 0.1rem;
}
#toastUndo .undo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 10px;
  background: var(--acc);
  color: var(--acc-ink);
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  flex: 0 0 auto;
  transition:
    transform 0.18s var(--ease),
    background 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
#toastUndo .undo-btn svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
  margin: 0;
  flex-shrink: 0;
}
#toastUndo .undo-btn:hover {
  background: color-mix(in srgb, var(--acc) 88%, #fff);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.3);
}
#toastUndo .undo-btn:active {
  transform: scale(0.92);
}
.undo-progress {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(
    to left,
    color-mix(in srgb, var(--acc) 40%, transparent),
    var(--acc)
  );
  transform-origin: right center;
  transform: scaleX(1);
  pointer-events: none;
  opacity: 1;
  border-radius: 0 0 14px 14px;
}
#toastUndo.show .undo-progress {
  animation: undoCountdown var(--undo-dur, 5000ms) linear forwards;
}
#toastUndo.show:hover .undo-progress {
  animation-play-state: paused;
}
@keyframes undoCountdown {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

@media (max-width: 480px) {
  #toastUndo {
    bottom: 20px;
    padding: 0.3rem 0.3rem 0.3rem 0.75rem;
    gap: 0.5rem;
  }
  #toastUndo .undo-txt {
    font-size: var(--f-xs);
  }
  #toastUndo .undo-btn {
    width: 2rem;
    height: 2rem;
  }
  #toastUndo .undo-btn svg {
    width: 1rem;
    height: 1rem;
  }
}
/* ══════════════ تول‌تیپ لمسی (فقط دستگاه‌های بدون hover) ══════════════ */
/* media query لمسی حذف شد — گtip گلوبال، رو هر دستگاهی کار می‌کنه. */

/* ══════════════ انیمیشن‌های لیست دسته‌ها ══════════════ */

/* swap نرم نوار بالا — عادی ↔ مرتب‌سازی */
.cat-head > #addCatBtn,
.cat-head > #reorderCatsBtn,
.cat-head > .cat-reorder-tools {
  animation: catHeadIn 0.28s var(--ease-ios) both;
}
@keyframes catHeadIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ورود stagger ردیف‌ها — فقط بار اول (با .no-anim خاموش می‌شه) */
.cat-list:not(.no-anim) .cat-item {
  animation: catRowIn 0.34s var(--ease-ios) both;
}
.cat-list:not(.no-anim) .cat-item:nth-child(1) { animation-delay: 0ms; }
.cat-list:not(.no-anim) .cat-item:nth-child(2) { animation-delay: 30ms; }
.cat-list:not(.no-anim) .cat-item:nth-child(3) { animation-delay: 60ms; }
.cat-list:not(.no-anim) .cat-item:nth-child(4) { animation-delay: 90ms; }
.cat-list:not(.no-anim) .cat-item:nth-child(5) { animation-delay: 120ms; }
.cat-list:not(.no-anim) .cat-item:nth-child(n+6) { animation-delay: 150ms; }
@keyframes catRowIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* چک‌باکس — پالس spring موقع انتخاب */
.cat-item.selected .cat-check {
  animation: catCheckPop 0.36s var(--ease-spring);
}
@keyframes catCheckPop {
  0%   { transform: scale(0.7); }
  55%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.cat-item.selected .cat-check svg {
  animation: catCheckDraw 0.24s var(--ease-ios) 0.06s both;
}
@keyframes catCheckDraw {
  from {
    opacity: 0;
    transform: scale(0.4) rotate(-12deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

/* پالس ظریف روی ردیف انتخاب‌شده — یه بار، کوتاه */
.cat-item.selected {
  animation: catSelectPulse 0.42s var(--ease-ios);
}
@keyframes catSelectPulse {
  0% {
    box-shadow:
      inset 3px 0 0 var(--acc),
      0 4px 14px color-mix(in srgb, var(--acc) 18%, transparent);
  }
  55% {
    box-shadow:
      inset 3px 0 0 var(--acc),
      0 4px 24px color-mix(in srgb, var(--acc) 36%, transparent);
  }
  100% {
    box-shadow:
      inset 3px 0 0 var(--acc),
      0 4px 14px color-mix(in srgb, var(--acc) 18%, transparent);
  }
}

/* ردیف‌های تازه‌جابه‌جا‌شده — highlight گرم کوتاه */
.cat-item.moved {
  animation: catMovedFlash 0.6s var(--ease-ios);
}

/* خفه کردن انیمیشن‌های تیک موقع re-render (بعد از جابه‌جایی) —
   این کلاس برای دو RAF اضافه می‌شه و بعد برداشته می‌شه. */
.cat-list.no-check-anim .cat-item.selected,
.cat-list.no-check-anim .cat-item.selected .cat-check,
.cat-list.no-check-anim .cat-item.selected .cat-check svg {
  animation: none;
}
@keyframes catMovedFlash {
  0% {
    background: color-mix(in srgb, var(--acc) 26%, var(--deep));
    border-color: color-mix(in srgb, var(--acc) 65%, transparent);
    transform: translateY(-2px);
  }
  55% {
    background: color-mix(in srgb, var(--acc) 18%, var(--deep));
    border-color: color-mix(in srgb, var(--acc) 55%, transparent);
    transform: none;
  }
  100% {
    background: color-mix(in srgb, var(--acc) 12%, var(--deep));
    border-color: color-mix(in srgb, var(--acc) 55%, transparent);
    transform: none;
  }
}

/* ══════════════ Overscroll Containment ══════════════ */
/* هیچ اسکرول داخلی پنل‌ها به بدنهٔ صفحهٔ پشتش نشت نمی‌کنه.
   بدون این، وقتی اسکرول داخلی به انتها می‌رسه، مرورگر موبایل
   نوار آدرس رو باز/بسته می‌کنه و layout می‌لرزه. */
.pv-drawer,
.pv-body,
.pv-wrap,
.pv-body pre,
.drawer,
.drawer-body,
.editor-wrap,
.editor-area,
.editor-meta,
.lib-grid,
.lib-preview-content,
.chlog-list,
.msearch-body,
.var-preview {
  overscroll-behavior: contain;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

html.theme-instant,
html.theme-instant *,
html.theme-instant *::before,
html.theme-instant *::after {
  transition: none !important;
  animation-duration: 0s !important;
}

/* ══════════════ فوتر ══════════════ */
footer.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  padding: 0.55rem 0.9rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
  color: var(--dim);
  font-size: var(--f-2xs);
  line-height: 1.6;
  background: var(--header-bg);
  backdrop-filter: blur(4px) saturate(1.4);
  -webkit-backdrop-filter: blur(4px) saturate(1.4);
  border-top: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  pointer-events: none;
}
footer.app-footer .ft-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0 6px;
}
footer.app-footer .ft-brand {
  color: var(--mut);
  font-weight: 600;
}
footer.app-footer .ft-sep {
  opacity: 0.5;
  margin: 0 2px;
}
footer.app-footer .ft-author {
  color: var(--mut);
  font-weight: 700;
  text-decoration: none;
  transition: color 0.2s var(--ease);
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-family: "Chakra Petch", var(--mono);
  letter-spacing: 0.3px;
  font-size: 0.95em;
}
footer.app-footer .ft-author:hover {
  color: var(--cyn);
  text-shadow:
    0 0 4px color-mix(in srgb, var(--cyn) 60%, transparent),
    0 0 12px color-mix(in srgb, var(--cyn) 30%, transparent);
}
footer.app-footer .ft-ver {
  font-family: var(--mono);
  direction: ltr;
  display: inline-block;
  unicode-bidi: embed;
  color: var(--mut);
  font-weight: 700;
}

/* ══════════════ ریسپانسیو ══════════════ */
@media (max-width: 760px) {
  .searchwrap {
    display: none !important;
  }
  #mSearchBtn {
    display: grid;
  }
  .msearch-back {
    display: block;
  }
  .msearch {
    display: flex;
  }

  header.top {
    display: flex;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
  }
  .brand small {
    display: none;
  }
  .brand h1 {
    font-size: var(--f-sm);
  }
  .hend {
    gap: 0.4rem;
    margin-inline-start: auto;
  }
  .hend .icon-btn {
    width: 2.35rem;
    height: 2.35rem;
  }

  main {
    padding: 0.85rem 0.75rem 4rem;
  }

  /* چیپس‌ها: افقی و اسکرول‌شو */
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .chips::-webkit-scrollbar {
    display: none;
  }
  .chip {
    flex-shrink: 0;
    padding: 0.35rem 0.75rem;
    font-size: var(--f-xs);
  }
  .cselect-btn {
    padding: 0.4rem 0.65rem;
    font-size: var(--f-xs);
  }
  .filter-actions {
    width: 100%;
  }
  .filter-actions .cselect {
    flex: 1;
  }

  /* منوی دراپ‌دان: پهنای ثابت، نه برابر عرض والد */
  .cselect-menu {
    min-width: 200px;
    max-width: min(260px, 82vw);
  }
  .modal-back {
    padding: 1rem 0.65rem;
  }
  /* دیالوگ‌های تکی، باریک‌تر از بقیه مودال‌ها —
     فول‌ویث بودن باعث می‌شه کارت، کمتر شبیه دیالوگ به‌نظر بیاد. */
  .modal-back:has(.dialog-modal) {
    padding: 1.5rem 1.4rem;
  }
  .modal-back:has(.dialog-modal) .dialog-modal {
    width: 100%;
  }
  .modal-back.editor-back {
    padding: 0;
  }
  .modal {
    padding: 1.1rem;
  }
  .modal h2 {
    font-size: var(--f-lg);
  }
  .pv-drawer,
  .drawer {
    width: 100%;
    border-radius: 0;
    border-inline-start: none;
    border-inline-end: none;
  }
  .pref-row.cols-row {
    display: none;
  }

  /* کتابخانه: کارتها تکستونه و بدون اسکرول افقی */
  .lib-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .drawer[data-view="library"] .drawer-body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  /* پیش‌نمایش — گاتر باریک و ارتفاع خط متناسب */
  .pv-body {
    padding: 0.75rem;
  }
  .pv-gutter {
    width: 2.25rem;
    padding: 0.85rem 0.4rem 0.85rem 0;
    /* هم‌اندازه با .pv-body pre — وگرنه baseline یکی نیست */
    font-size: var(--f-xs);
    line-height: 1.4rem;
  }
  .pv-body pre {
    padding: 0.85rem 0.75rem;
    line-height: 1.4rem;
  }

  /* تول‌تیپ‌های نوار بالای ادیتور → زیر دکمه (نه بالای آن)
تا از کادر ادیتور بیرون نزنند و بریده نشوند */
  .etb-close[data-tip]::after,
  .etb-toggle[data-tip]::after {
    top: calc(100% + 8px);
    bottom: auto;
    transform: translateX(-50%) translateY(-4px);
  }
  .etb-close[data-tip]:hover::after,
  .etb-close[data-tip]:focus-visible::after,
  .etb-toggle[data-tip]:hover::after,
  .etb-toggle[data-tip]:focus-visible::after {
    transform: translateX(-50%) translateY(0);
  }
}

/* ═══ Text Engine: Logical Lines + Soft Wrap ═══ */
/* متن اصلی نرم‌پیچیده می‌شود تا اسکرول افقی نداشته باشیم */
/* (base روی .editor-area, .pv-body pre, .var-preview اعمال شده) */
/* گاتر نباید بشکند؛ هر خط منطقی = یک سلول با ارتفاع ثابت */
.editor-gutter,
.pv-gutter {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
  line-height: 1.5rem;
}

@media (max-width: 760px) {
  .editor-gutter,
  .pv-gutter {
    line-height: 1.4rem;
  }
}
/* کاراکتر جای‌گذار برای خطوط خالی */
.gutter-line-empty {
  color: var(--dim);
  opacity: 0.5;
  user-select: none;
  font-weight: bold;
}

/* ═══ Text Direction: RTL/LTR modes ═══ */
.editor-area[dir="rtl"],
.pv-body pre[dir="rtl"],
.var-preview[dir="rtl"] {
  direction: rtl !important;
  text-align: right !important;
}

.editor-area[dir="ltr"],
.pv-body pre[dir="ltr"],
.var-preview[dir="ltr"] {
  direction: ltr !important;
  text-align: left !important;
}

/* ══════════════ Tooltip گلوبال ══════════════ */
/* تو کارت‌ها content-visibility: auto داریم که paint containment
   ایجاد می‌کنه و tooltip‌های بیرون‌زننده (مثل پین) رو clip می‌کنه.
   راه‌حل: یه عنصر سراسری با position: fixed که بیرون همهٔ
   contain contexts باشه و با JS موقعیت‌دهی بشه. */
.gtip {
  position: fixed;
  z-index: 600;
  pointer-events: none;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--card2);
  border: 1px solid var(--line2);
  color: var(--txt);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: var(--f-2xs);
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--menu-shadow);
  opacity: 0;
  transform: translateX(-50%) translateY(4px);
  transition:
    opacity 0.15s var(--ease),
    transform 0.15s var(--ease);
}
.gtip.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.gtip[hidden] {
  display: none;
}

/* ══════════════ حالت انتخاب چندگانه ══════════════ */
body.selmode .card {
  cursor: pointer;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}
body.selmode .card:hover {
  transform: none;
}
body.selmode .card::after {
  content: "";
  position: absolute;
  top: 0.7rem;
  inset-inline-end: 0.7rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 2px solid var(--line2);
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition:
    background 0.22s var(--ease),
    border-color 0.22s var(--ease),
    transform 0.22s var(--ease-spring);
  z-index: 3;
  pointer-events: none;
}
body.selmode .card.selected {
  border-color: var(--acc);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--acc) 45%, transparent),
    var(--shadow);
}
body.selmode .card.selected::after {
  background-color: var(--acc);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-size: 65%;
  background-position: center;
  background-repeat: no-repeat;
  border-color: var(--acc);
  transform: scale(1.05);
}
body.selmode .card .pfoot,
body.selmode .card .phead .pin {
  pointer-events: none;
  opacity: 0.35;
}

/* نوار عملیات گروهی */
.sel-bar {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(24px) scale(0.95);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.4rem 0.35rem 0.55rem;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line2);
  box-shadow: var(--shadow);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.28s var(--ease-ios),
    transform 0.4s var(--ease-spring);
  max-width: calc(100vw - 20px);
}
.sel-bar.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}
.sel-info {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  font-size: var(--f-xs);
  font-weight: 700;
  color: var(--mut);
  padding-inline-start: 0.35rem;
  padding-inline-end: 0.7rem;
  border-inline-end: 1px solid var(--line);
  white-space: nowrap;
  flex-shrink: 0;
}
.sel-info b {
  color: var(--acc);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: var(--f-lg);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.sel-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.sel-act,
.sel-close {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 2.15rem;
  padding: 0 0.7rem;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--mut);
  font-family: inherit;
  font-size: var(--f-xs);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  transition:
    background 0.16s var(--ease),
    color 0.16s var(--ease),
    transform 0.12s var(--ease);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.sel-act .sel-ico,
.sel-close .sel-ico {
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.sel-act svg,
.sel-close svg {
  width: 1rem;
  height: 1rem;
  display: block;
}
.sel-act:hover,
.sel-close:hover {
  background: var(--card2);
  color: var(--txt);
}
.sel-act:active,
.sel-close:active {
  transform: scale(0.96);
}
.sel-act.dgr {
  color: var(--ros);
}
.sel-act.dgr:hover {
  background: rgba(251, 113, 133, 0.12);
}
.sel-act[disabled] {
  opacity: 0.3;
  pointer-events: none;
}
.sel-close {
  margin-inline-start: 0;
  padding-inline-start: 1rem;
  position: relative;
  /* لبهٔ سمت خط جداکننده صاف، بقیه گرد */
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}
.sel-close::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
  pointer-events: none;
}
.sel-close:hover {
  color: var(--ros);
  background: rgba(251, 113, 133, 0.1);
}

/* تول‌تیپ نوار انتخاب (فقط دسکتاپ) */
@media (hover: hover) {
  .sel-act[data-tip]::after,
  .sel-close[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--card2);
    border: 1px solid var(--line2);
    color: var(--txt);
    font-size: var(--f-2xs);
    font-weight: 700;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 7px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition:
      opacity 0.15s,
      transform 0.15s;
    z-index: 5;
  }
  .sel-act[data-tip]:hover::after,
  .sel-close[data-tip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (max-width: 760px) {
  .sel-bar {
    left: 50%;
    right: auto;
    width: max-content;
    max-width: calc(100vw - 20px);
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%) translateY(calc(100% + 24px));
    border-radius: 14px;
    padding: 0.35rem 0.35rem 0.35rem 0.35rem;
    gap: 0.35rem;
  }
  .sel-bar.show {
    transform: translateX(-50%) translateY(0);
  }
  .sel-info {
    padding-inline-start: 0.35rem;
    padding-inline-end: 0.55rem;
  }
  .sel-info b {
    font-size: var(--f-lg);
  }
  .sel-actions {
    gap: 0.1rem;
  }
  /* موبایل: فقط آیکون، بدون متن */
  .sel-act,
  .sel-close {
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    justify-content: center;
    gap: 0;
  }
  .sel-act .sel-lbl,
  .sel-close .sel-lbl {
    display: none;
  }
  .sel-act svg,
  .sel-close svg {
    width: 1.15rem;
    height: 1.15rem;
  }
  .sel-close {
    width: 2.4rem;
    padding-inline-start: 0;
    margin-inline-start: 0.35rem;
    border-start-start-radius: 0;
    border-end-start-radius: 0;
  }
}

/* دستهٔ انتقال گروهی (به‌شکل دکمه) */
button.cat-item {
  font-family: inherit;
  color: inherit;
  font-size: inherit;
  cursor: pointer;
  width: 100%;
  text-align: start;
}
button.cat-item:hover {
  border-color: var(--focus);
}

/* ══════════════ FAB مشترک (همه‌جا) ══════════════ */
.quick-fab {
  position: fixed;
  left: 24px;
  bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  background: var(--card);
  border: 1.5px solid var(--line2);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  transition:
    transform 0.3s var(--ease-spring),
    opacity 0.25s var(--ease),
    border-color 0.2s var(--ease);
}
.quick-fab:hover {
  border-color: var(--focus);
}
.quick-fab .qf-part {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.62rem 0.9rem;
  border: none;
  background: transparent;
  color: var(--txt);
  font-family: inherit;
  font-weight: 800;
  font-size: var(--f-sm);
  cursor: pointer;
  transition: background 0.16s var(--ease);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  min-height: 2.55rem;
}
.quick-fab .qf-part[data-qf="add"] {
  color: var(--acc);
}
.quick-fab .qf-part[data-qf="select"] {
  color: var(--vio);
}
.quick-fab .qf-part:hover {
  background: var(--card2);
}
.quick-fab .qf-part:active {
  background: color-mix(in srgb, var(--acc) 14%, transparent);
}
.quick-fab .qf-part svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
  flex-shrink: 0;
}
.quick-fab .qf-sep {
  width: 1px;
  align-self: stretch;
  background: var(--line2);
}
body.selmode .quick-fab {
  display: none;
}

@media (max-width: 760px) {
  .quick-fab {
    left: 20px;
    bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    border-radius: 14px;
  }
  .quick-fab .qf-part {
    padding: 0.75rem 1rem;
    min-height: 2.9rem;
    font-size: var(--f-sm);
    gap: 0.5rem;
  }
  .quick-fab .qf-part svg {
    width: 1.1rem;
    height: 1.1rem;
  }
}

@media (max-width: 480px) {
  .quick-fab .qf-part span {
    display: none;
  }
  .quick-fab .qf-part {
    padding: 0.75rem 0.9rem;
    gap: 0;
  }
}

/* ══════════════ کانتکست منو (دسکتاپ) ══════════════ */
.ctx-menu {
  position: fixed;
  z-index: 500;
  min-width: 220px;
  max-width: 280px;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 12px;
  box-shadow: var(--menu-shadow);
  padding: 5px;
  font-size: var(--f-sm);
  animation: ctxIn 0.14s var(--ease-ios);
}
.ctx-menu[hidden] {
  display: none;
}
@keyframes ctxIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-2px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.ctx-menu button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: start;
  padding: 0.5rem 0.7rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--txt);
  font-family: inherit;
  font-size: var(--f-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s var(--ease);
  white-space: nowrap;
}
.ctx-menu button:hover,
.ctx-menu button:focus-visible {
  background: var(--card2);
  outline: none;
}
.ctx-menu button svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: var(--mut);
  display: block;
}
.ctx-menu button.ctx-dgr {
  color: var(--ros);
}
.ctx-menu button.ctx-dgr svg {
  color: var(--ros);
}
.ctx-menu button.ctx-dgr:hover {
  background: rgba(251, 113, 133, 0.12);
}
.ctx-menu .ctx-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--line);
}
.ctx-menu .ctx-hint {
  margin-inline-start: auto;
  font-size: var(--f-2xs);
  color: var(--dim);
  font-weight: 700;
  font-family: var(--mono);
}

/* ── ساب‌منو ── */
.ctx-sub {
  position: relative;
}
.ctx-sub > button .ctx-chev {
  width: 0.75rem;
  height: 0.75rem;
  margin-inline-start: auto;
  color: var(--dim);
  transform: rotate(180deg); /* ← اشاره به چپ، هم‌راستا با محل باز شدن */
}
.ctx-submenu {
  position: absolute;
  top: -5px;
  right: calc(100% + 4px);
  min-width: 190px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 12px;
  box-shadow: var(--menu-shadow);
  padding: 5px;
  opacity: 0;
  visibility: hidden;
  transform: translateX(4px);
  transition:
    opacity 0.14s var(--ease-ios),
    transform 0.14s var(--ease-ios),
    visibility 0s linear 0.14s;
  pointer-events: none;
}
.ctx-sub:hover > .ctx-submenu,
.ctx-sub:focus-within > .ctx-submenu,
.ctx-sub.open > .ctx-submenu {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
  transition:
    opacity 0.14s var(--ease-ios),
    transform 0.14s var(--ease-ios),
    visibility 0s;
}
.ctx-submenu .ai-dot {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--ai-c);
  color: #fff;
  font-family: var(--mono);
  font-weight: 800;
  font-size: var(--f-2xs);
  letter-spacing: -0.4px;
  line-height: 1;
}

/* ══════════════ جهت مرتب‌سازی ══════════════ */
.sort-dir {
  display: grid;
  place-items: center;
  align-self: stretch;
  padding: 0 0.7rem;
  min-width: 2.2rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--mut);
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  transition:
    border-color 0.2s var(--ease),
    background 0.2s var(--ease),
    color 0.2s var(--ease);
}
.sort-dir:hover {
  border-color: var(--line2);
  color: var(--txt);
}
.sort-dir:active {
  background: var(--deep);
}
.sort-dir svg {
  width: 1rem;
  height: 1rem;
  display: block;
  transition: transform 0.32s var(--ease-spring);
}
.sort-dir.desc svg {
  transform: rotate(180deg);
}
@media (max-width: 760px) {
  .sort-dir {
    min-width: 2rem;
    padding: 0 0.55rem;
  }
  .sort-dir svg {
    width: 0.9rem;
    height: 0.9rem;
  }
}

/* ══════════════ تنظیمات: drill-down ══════════════ */
.drawer-head h2 {
  font-size: var(--f-xl);
  font-weight: 800;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.3px;
  max-width: calc(100% - 8.5rem);
}

.drawer-head .icon-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2.5rem;
  height: 2.5rem;
}
.drawer-head .icon-btn svg {
  width: 1.1rem;
  height: 1.1rem;
}
/* X روی لبهٔ چپ (end در RTL) */
#closeDrawer {
  inset-inline-end: 0.85rem;
}
/* فلش برگشت روی لبهٔ راست (start در RTL) */
.st-back {
  display: none;
  inset-inline-start: 0.85rem;
}
/* موبایل: هر viewی که home نیست، back می‌گیره — چون home یه صفحهٔ واقعیه.
   دسکتاپ: back فقط برای زیرشاخه‌های عمیق (data-can-back) — home سایدباره. */
@media (max-width: 899px) {
  .drawer[data-view]:not([data-view="home"]) .st-back {
    display: grid;
  }

  /* کتابخانه: بدنه flex، فقط گرید اسکرول */
  .drawer[data-view="library"] .drawer-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .drawer[data-view="library"] .st-view[data-view="library"]:not([hidden]) {
    flex: 1;
    min-height: 0;
  }
}

.st-view[hidden] {
  display: none;
}

/* ═══ انیمیشن ورود به شاخه‌های منو ═══
   forward (RTL): محتوای جدید از چپ وارد می‌شه، به راست سُر می‌خوره.
   back: از راست وارد می‌شه. */
.st-view.view-in-fwd {
  animation: stViewFwd 0.26s var(--ease-ios) both;
}
.st-view.view-in-back {
  animation: stViewBack 0.26s var(--ease-ios) both;
}
@keyframes stViewFwd {
  from {
    opacity: 0;
    transform: translateX(-18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes stViewBack {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
/* کاربری که animation رو قطع کرده، فقط محتوا رو بدون حرکت ببینه */
@media (prefers-reduced-motion: reduce) {
  .st-view.view-in-fwd,
  .st-view.view-in-back,
  .cat-head > #addCatBtn,
  .cat-head > #reorderCatsBtn,
  .cat-head > .cat-reorder-tools,
  .cat-list .cat-item,
  .cat-item.selected,
  .cat-item.selected .cat-check,
  .cat-item.selected .cat-check svg,
  .cat-item.moved {
    animation: none;
  }
  .cat-list.no-check-anim .cat-item,
  .cat-list.no-check-anim .cat-item.selected {
    animation: none;
  }
}

/* ── لیست ردیف‌ها (خانه) ── */
.st-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.st-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: linear-gradient(
    160deg,
    var(--card2),
    color-mix(in srgb, var(--deep) 92%, var(--card2))
  );
  border: 1px solid var(--line);
  color: var(--txt);
  font-family: inherit;
  cursor: pointer;
  text-align: start;
  transition:
    transform 0.15s var(--ease),
    border-color 0.18s var(--ease),
    background 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}
.st-row::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--acc) 6%, transparent)
  );
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  pointer-events: none;
}
.st-row:hover {
  border-color: var(--line2);
}
.st-row:hover::before {
  opacity: 1;
}
.st-row:active {
  transform: scale(0.985);
}

/* آیکون رنگی per-row */
.st-icon {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--st-c, var(--acc));
  color: var(--st-ink, var(--acc-ink));
  flex-shrink: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 14px color-mix(in srgb, var(--st-c, var(--acc)) 28%, transparent);
}
.st-icon svg {
  width: 1.2rem;
  height: 1.2rem;
  display: block;
}

/* رنگ اختصاصی هر ردیف */
.st-row[data-nav="appearance"] .st-icon {
  --st-c: var(--vio);
  --st-ink: #0b0f1e;
}
.st-row[data-nav="color"] .st-icon {
  --st-c: var(--acc);
  --st-ink: var(--acc-ink);
}
.st-row[data-nav="sound"] .st-icon {
  --st-c: var(--cyn);
  --st-ink: #0b0f1e;
}
.st-row[data-nav="categories"] .st-icon {
  --st-c: var(--amb);
  --st-ink: #0b0f1e;
}
.st-row[data-nav="data"] .st-icon {
  --st-c: var(--grn);
  --st-ink: #0b0f1e;
}
.st-row[data-nav="about"] .st-icon {
  --st-c: var(--mut);
  --st-ink: var(--deep);
}
:root[data-theme="light"] .st-row[data-nav="appearance"] .st-icon,
:root[data-theme="light"] .st-row[data-nav="sound"] .st-icon,
:root[data-theme="light"] .st-row[data-nav="categories"] .st-icon,
:root[data-theme="light"] .st-row[data-nav="data"] .st-icon {
  --st-ink: #ffffff;
}

.st-label {
  font-size: var(--f-md);
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.1px;
}
.st-val {
  font-size: var(--f-xs);
  color: var(--mut);
  font-weight: 600;
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
  min-width: 3.2rem;
  text-align: center;
}
.st-val:empty {
  visibility: hidden;
}

.st-chev {
  color: var(--dim);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.15s var(--ease), color 0.15s var(--ease);
}
.st-chev svg {
  width: 1rem;
  height: 1rem;
  display: block;
}
.st-row:hover .st-chev {
  color: var(--txt);
  transform: translateX(-2px);
}

/* ── بج آپدیت ── */
.st-update-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0.95rem;
  margin-bottom: 1rem;
  border-radius: 14px;
  background: linear-gradient(
    160deg,
    color-mix(in srgb, var(--ros) 14%, var(--card)),
    color-mix(in srgb, var(--ros) 5%, var(--deep))
  );
  border: 1px solid color-mix(in srgb, var(--ros) 40%, var(--line));
  position: relative;
  overflow: hidden;
}
.st-update-banner::after {
  content: "";
  position: absolute;
  inset-inline-end: -20px;
  top: -20px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--ros) 30%, transparent),
    transparent 70%
  );
  pointer-events: none;
}
.st-update-banner[hidden] {
  display: none;
}
.st-update-info {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}
.st-update-info b {
  display: block;
  font-size: var(--f-sm);
  font-weight: 800;
  color: var(--ros);
  margin-bottom: 2px;
}
.st-update-info span {
  font-size: var(--f-2xs);
  color: var(--mut);
  line-height: 1.5;
}

/* ── صفحه‌های فرعی ── */
.st-section {
  margin-bottom: 1.5rem;
}
.st-section:last-child {
  margin-bottom: 0;
}
.st-section-title {
  font-size: var(--f-2xs);
  color: var(--dim);
  font-weight: 800;
  letter-spacing: 0.6px;
  margin-bottom: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-transform: uppercase;
}
.st-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to left, var(--line), transparent);
}
.st-section-title.st-danger {
  color: var(--ros);
  opacity: 0.85;
}
.st-section .row-pref {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}
.st-section .row-pref:first-child {
  padding-top: 0.2rem;
}
.st-section .row-pref:last-child {
  border-bottom: none;
  padding-bottom: 0.2rem;
}
.st-section .row-pref .label b {
  font-size: var(--f-md);
}
.st-section .row-pref .label span {
  font-size: var(--f-xs);
}

/* ═══ تنظیمات ظاهر — flat list ═══ */
.pref-row {
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--line);
}
.pref-row:first-child {
  padding-top: 0.3rem;
}
.pref-row:last-child {
  border-bottom: none;
  padding-bottom: 0.3rem;
}

.pref-head {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}
.pref-ico {
  width: 1.05rem;
  height: 1.05rem;
  color: var(--mut);
  flex-shrink: 0;
  margin-top: 0.28rem;
}
.pref-ico svg {
  width: 100%;
  height: 100%;
  display: block;
}
.pref-titles {
  flex: 1;
  min-width: 0;
}
.pref-titles b {
  display: block;
  font-size: var(--f-sm);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.1px;
}
.pref-titles span {
  display: block;
  font-size: var(--f-xs);
  color: var(--mut);
  line-height: 1.6;
  margin-top: 2px;
}

/* Segmented control — پر و برابر */
.pref-row .seg {
  width: 100%;
}
.pref-row .seg:not(.swatches) button {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  font-size: var(--f-sm);
}
.pref-row .seg.swatches {
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
}
.pref-row .seg.swatches button {
  width: 2.4rem;
  height: 2.4rem;
}
.pref-row .seg.swatches button::before {
  width: 1.75rem;
  height: 1.75rem;
}

/* دکمهٔ افزودن دسته تو تنظیمات */
.st-view[data-view="categories"] #addCatBtn {
  padding: 0.75rem;
  font-size: var(--f-sm);
  border-radius: 12px;
  border-style: dashed;
}

/* ═══ صفحهٔ درباره ═══ */
.about-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  gap: 0.6rem;
}
.about-logo {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--vio), var(--acc));
  color: var(--acc-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 14px 36px color-mix(in srgb, var(--acc) 42%, transparent);
  margin-bottom: 0.4rem;
}
.about-logo svg {
  width: 2.7rem;
  height: 2.7rem;
}
.about-name {
  font-size: var(--f-2xl);
  font-weight: 800;
  letter-spacing: 0.3px;
  line-height: 1.2;
  margin: 0;
  font-family: "Chakra Petch", var(--mono);
  color: var(--txt);
}
.about-tag {
  font-size: var(--f-xs);
  color: var(--mut);
  line-height: 1.8;
  max-width: 22rem;
  margin: 0.1rem 0 0.4rem;
}
.about-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.about-chip {
  font-size: var(--f-2xs);
  font-weight: 700;
  color: var(--mut);
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
}
.about-desc {
  font-size: var(--f-xs);
  color: var(--mut);
  line-height: 1.9;
  max-width: 26rem;
  margin: 0.9rem 0 0.6rem;
}
.about-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.4rem 0 0.6rem;
}
.about-chlog-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.05rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--deep);
  color: var(--mut);
  font-family: inherit;
  font-size: var(--f-xs);
  font-weight: 700;
  cursor: pointer;
  transition: 0.18s var(--ease);
  margin: 0;
}
.about-chlog-btn svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.about-chlog-btn:hover {
  color: var(--txt);
  border-color: var(--line2);
  background: var(--card2);
}
.about-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  width: min(100%, 20rem);
  justify-content: center;
  font-size: var(--f-xs);
}
.about-ver {
  color: var(--mut);
  font-weight: 600;
}
.about-ver b {
  color: var(--txt);
  font-family: var(--mono);
  font-weight: 800;
  direction: ltr;
  unicode-bidi: embed;
  display: inline-block;
}
.about-dot {
  color: var(--dim);
}
.about-author {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--cyn);
  font-weight: 700;
  font-family: "Chakra Petch", var(--mono);
  letter-spacing: 0.3px;
  font-size: var(--f-sm);
  padding: 4px 10px;
  border-radius: 8px;
  transition: background 0.18s var(--ease);
  direction: ltr;
  unicode-bidi: isolate;
}
.about-author svg {
  width: 1rem;
  height: 1rem;
  display: block;
}
.about-author:hover {
  background: color-mix(in srgb, var(--cyn) 12%, transparent);
}

/* ══════════════ راهنما ══════════════ */
.help-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  padding: 0.2rem 0 1rem;
}
.help-sec h3 {
  font-size: var(--f-md);
  font-weight: 800;
  color: var(--txt);
  margin-bottom: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.help-sec h3::before {
  content: "";
  width: 3px;
  height: 1em;
  border-radius: 999px;
  background: var(--acc);
  flex-shrink: 0;
}
.help-sec p {
  font-size: var(--f-sm);
  color: var(--mut);
  line-height: 1.9;
  margin: 0;
}
.help-sec p code {
  color: var(--amb);
  font-weight: 700;
  background: color-mix(in srgb, var(--amb) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--amb) 25%, transparent);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.92em;
}
.help-sec p b {
  color: var(--txt);
  font-weight: 700;
}
.help-keys {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.help-keys li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: var(--f-sm);
  color: var(--mut);
  line-height: 1.6;
}
.help-keys li span {
  flex: 1;
}
.help-keys kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.7rem;
  padding: 0 0.5rem;
  font-family: var(--mono);
  font-size: var(--f-2xs);
  font-weight: 700;
  color: var(--txt);
  background: var(--deep);
  border: 1px solid var(--line2);
  border-bottom-width: 2px;
  border-radius: 6px;
  line-height: 1;
}

/* ══════════════ سطل آشغال ══════════════ */
.st-row[data-nav="trash"] .st-icon {
  --st-c: var(--ros);
  --st-ink: #ffffff;
}

.trash-head {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.trash-head[hidden] {
  display: none;
}
.trash-head .btn {
  flex: 1;
  min-width: 0;
}

.trash-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.trash-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--deep);
  transition: border-color 0.18s var(--ease);
}
.trash-item:hover {
  border-color: var(--line2);
}
.trash-item-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.trash-item-head b {
  flex: 1;
  min-width: 0;
  font-size: var(--f-sm);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trash-item-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--f-2xs);
  color: var(--dim);
}
.trash-item-sep {
  opacity: 0.5;
}
.trash-item-ttl {
  color: var(--amb);
  font-weight: 700;
}
.trash-item-acts {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.15rem;
}
.trash-item-acts .btn {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  font-size: var(--f-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.trash-item-acts .btn svg {
  width: 0.9rem;
  height: 0.9rem;
  flex-shrink: 0;
}

.trash-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 0.5rem;
  color: var(--dim);
}
.trash-empty svg {
  width: 3rem;
  height: 3rem;
  opacity: 0.35;
  color: var(--ros);
  margin-bottom: 0.5rem;
}
.trash-empty p {
  font-size: var(--f-md);
  font-weight: 700;
  color: var(--mut);
}
.trash-empty span {
  font-size: var(--f-xs);
  line-height: 1.7;
}

/* ═══ صفحهٔ کتابخانه ═══ */
/* این ویو کل ارتفاع در دسترس رو می‌گیره، فقط گرید اسکرول می‌شه */
.st-view[data-view="library"]:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  gap: 0.75rem;
}
.lib-intro {
  font-size: var(--f-xs);
  color: var(--mut);
  line-height: 1.85;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
}
.lib-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.55rem;
  margin-bottom: 0;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-block: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line2) transparent;
  overscroll-behavior: contain;
  /* refocus: کندتر، نرم‌تر — حس «برگشتن به فوکوس» */
  transition:
    opacity 0.22s var(--ease-ios),
    filter 0.22s var(--ease-ios);
}
.lib-grid.swapping {
  opacity: 0.35;
  /* defocus: blur + کمی desaturate — محتوا هنوز دیده می‌شه ولی حل شده */
  filter: blur(6px) saturate(0.7);
  /* خروج تندتره، چون swap بعدش اتفاق می‌افته */
  transition:
    opacity 0.14s var(--ease-ios),
    filter 0.14s var(--ease-ios);
}
@media (max-width: 760px) {
  /* موبایل: blur سبک‌تر — WebView اندروید از blur سنگین لگ می‌گیره */
  .lib-grid.swapping {
    filter: blur(4px) saturate(0.75);
  }
}
@media (prefers-reduced-motion: reduce) {
  .lib-grid,
  .lib-grid.swapping {
    transition: opacity 0.1s linear;
    filter: none;
  }
}
.lib-grid::-webkit-scrollbar {
  width: 6px;
}
.lib-grid::-webkit-scrollbar-track {
  background: transparent;
}
.lib-grid::-webkit-scrollbar-thumb {
  background: var(--line2);
  border-radius: 999px;
}
@media (min-width: 900px) {
  .lib-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
.lib-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--deep);
  cursor: pointer;
  transition: border-color 0.15s var(--ease);
  text-align: start;
  font-family: inherit;
  color: inherit;
  min-width: 0;
  contain: layout paint style;
}
.lib-card:hover {
  border-color: var(--line2);
}
.lib-card:active {
  border-color: var(--acc);
}
.lib-card-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.lib-card-cat {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--f-2xs);
  font-weight: 700;
  color: var(--mut);
  flex-shrink: 0;
}
.lib-card-cat .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}
.lib-card-b {
  flex: 1;
  min-width: 0;
  font-size: var(--f-sm);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-card-added {
  font-size: var(--f-2xs);
  font-weight: 800;
  color: var(--grn);
  background: color-mix(in srgb, var(--grn) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--grn) 40%, transparent);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
.lib-card-desc {
  font-size: var(--f-2xs);
  color: var(--mut);
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.lib-card-tags .tag {
  font-size: var(--f-2xs);
  padding: 2px 8px;
}
.lib-card-foot {
  display: flex;
  gap: 0.4rem;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--line);
  min-width: 0;
}
.lib-card-hint {
  font-size: var(--f-2xs);
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.lib-card-foot .btn {
  padding: 0.35rem 0.75rem;
  font-size: var(--f-2xs);
  border-radius: 8px;
  min-height: 1.9rem;
  font-weight: 800;
}
.lib-card-foot .btn[disabled] {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.lib-actions {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0;
  flex-shrink: 0;
  min-width: 0;
}
#libAddAll {
  flex: 1;
  padding: 0.65rem;
  font-size: var(--f-sm);
  border-radius: 11px;
  border-style: dashed;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0;
}
.lib-icon-btn {
  width: 2.6rem;
  min-height: 2.6rem;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--deep);
  color: var(--mut);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-family: inherit;
  transition:
    border-color 0.18s var(--ease),
    background 0.18s var(--ease),
    color 0.18s var(--ease),
    transform 0.12s var(--ease);
}
.lib-icon-btn:hover {
  color: var(--txt);
  border-color: var(--line2);
  background: var(--card2);
}
.lib-icon-btn:active {
  transform: scale(0.94);
}
.lib-icon-btn svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}
.lib-icon-btn[hidden] {
  display: none;
}
.lib-icon-btn.spin svg {
  animation: libRefreshSpin 0.55s var(--ease-ios);
}
@keyframes libRefreshSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ══════════════ PSwitch — سوئیچ بین N گزینه ══════════════
   یه ردیف از گزینه‌ها، اسلایدر --acc بینشون می‌چرخه.
   تعداد گزینه‌ها مهم نیست — flex:1 روی هر گزینه، پهنای مساوی می‌ده.
   موقعیت اسلایدر با JS از روی getBoundingClientRect محاسبه می‌شه. */
.pswitch {
  position: relative;
  display: flex;
  gap: 0.4rem;
  padding: 0.4rem;
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 14px;
  isolation: isolate;
}

.pswitch-slide {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  height: calc(100% - 0.8rem);
  width: 0;
  border-radius: 11px;
  background: var(--acc);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, #fff 22%, transparent),
    0 4px 14px color-mix(in srgb, var(--acc) 34%, transparent);
  transition:
    transform 0.44s cubic-bezier(0.34, 1.4, 0.5, 1),
    width 0.44s cubic-bezier(0.34, 1.4, 0.5, 1),
    opacity 0.2s var(--ease);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}
.pswitch.ready .pswitch-slide {
  opacity: 1;
}

.pswitch-opt {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.9rem 0.6rem;
  border: none;
  background: transparent;
  border-radius: 11px;
  cursor: pointer;
  font-family: inherit;
  color: var(--mut);
  text-align: center;
  transition: transform 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.pswitch-opt:active {
  transform: scale(0.97);
}
.pswitch-opt:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.pswitch-opt .pswitch-ico {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--acc) 10%, transparent);
  color: var(--acc);
  flex-shrink: 0;
  transition:
    background 0.3s var(--ease),
    color 0.3s var(--ease),
    transform 0.3s var(--ease-spring);
}
.pswitch-opt .pswitch-ico svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.pswitch-opt b {
  font-size: var(--f-sm);
  font-weight: 800;
  line-height: 1.3;
  color: var(--txt);
  transition: color 0.3s var(--ease);
}
.pswitch-opt > span:last-child {
  font-size: var(--f-2xs);
  line-height: 1.5;
  color: var(--dim);
  transition: color 0.3s var(--ease);
}

.pswitch-opt.on {
  color: var(--acc-ink);
}
.pswitch-opt.on .pswitch-ico {
  background: color-mix(in srgb, var(--acc-ink) 18%, transparent);
  color: var(--acc-ink);
  transform: scale(1.06);
}
.pswitch-opt.on b {
  color: var(--acc-ink);
}
.pswitch-opt.on > span:last-child {
  color: color-mix(in srgb, var(--acc-ink) 78%, transparent);
}

/* حالت فشرده — بدون آیکون و توضیح، فقط متن، مناسب برای ۳ یا ۴ گزینه */
.pswitch.compact .pswitch-opt {
  flex-direction: row;
  padding: 0.55rem 0.7rem;
  gap: 0.4rem;
}
.pswitch.compact .pswitch-ico {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 7px;
}
.pswitch.compact .pswitch-ico svg {
  width: 0.8rem;
  height: 0.8rem;
}
.pswitch.compact .pswitch-opt b {
  font-size: var(--f-xs);
}
.pswitch.compact .pswitch-opt > span:last-child {
  display: none;
}

@media (max-width: 480px) {
  .pswitch-opt {
    padding: 0.75rem 0.4rem;
    gap: 0.4rem;
  }
  .pswitch-opt .pswitch-ico {
    width: 1.7rem;
    height: 1.7rem;
  }
  .pswitch-opt b {
    font-size: var(--f-xs);
  }
  .pswitch-opt > span:last-child {
    font-size: 0.7rem;
  }
}

/* ═══ تنظیمات کتابخانه ═══ */
#libSettingsModal {
  max-width: 400px;
}

/* seg داخل دیالوگ — کمی جمع‌تر از صفحهٔ تنظیمات */
#libSettingsModal .seg {
  margin-bottom: 0;
}
#libSettingsModal .seg:not(.swatches) button {
  padding: 0.6rem 0.85rem;
  font-size: var(--f-sm);
}

/* lib-mode-hint حذف شد — توضیح هر گزینه تو خود duo هست. */

/* دکمهٔ بستن تو dialog-foot تک‌ستونه — فول‌عرض */
#libSettingsModal .dialog-foot {
  grid-auto-flow: row;
  grid-auto-columns: 1fr;
  margin-top: 0;
}
#libSettingsModal .dialog-foot .btn {
  padding: 0.75rem 0.9rem;
}
#libAddAll svg {
  width: 1rem;
  height: 1rem;
}
#libAddAll:hover {
  border-style: solid;
}

/* ── مودال پیش‌نمایش ── */
.lib-preview-modal {
  max-width: 680px;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: min(85vh, 780px);
}
.lib-preview-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1.15rem 1.3rem 0.9rem;
  flex-shrink: 0;
}
.lib-preview-titles {
  flex: 1;
  min-width: 0;
}
.lib-preview-titles h2 {
  margin: 0 0 0.5rem;
  font-size: var(--f-xl);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.1px;
}
.lib-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}
.lib-preview-meta .tag {
  font-size: var(--f-2xs);
  padding: 3px 9px;
}

/* نوار آمار متن */
.lib-preview-stats {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  padding: 0.7rem 1.3rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--deep) 65%, transparent);
  flex-shrink: 0;
  font-size: var(--f-2xs);
}
.lps-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  color: var(--dim);
  font-weight: 600;
}
.lps-item b {
  color: var(--mut);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-weight: 300;
  font-size: var(--f-sm);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.lib-preview-content {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 1.15rem 1.3rem;
  background: transparent;
  font-family: var(--mono);
  font-weight: 400;
  font-size: var(--f-xs);
  line-height: 1.85;
  color: var(--txt);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
  unicode-bidi: plaintext;
  text-align: start;
  scrollbar-width: thin;
  scrollbar-color: var(--line2) transparent;
}
.lib-preview-content::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.lib-preview-content::-webkit-scrollbar-track {
  background: transparent;
}
.lib-preview-content::-webkit-scrollbar-thumb {
  background: var(--line2);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.lib-preview-content::-webkit-scrollbar-thumb:hover {
  background: var(--mut);
  background-clip: padding-box;
}
.lib-preview-modal .foot {
  padding: 0.9rem 1.3rem;
  border-top: 1px solid var(--line);
  margin-top: 0;
  flex-shrink: 0;
}
.lib-preview-modal .foot .btn {
  flex: 1;
}

/* موبایل: آمار جمع‌تر و اسکرول‌شو */
@media (max-width: 760px) {
  .lib-preview-head {
    padding: 1rem 1rem 0.75rem;
  }
  .lib-preview-titles h2 {
    font-size: var(--f-lg);
  }
  .lib-preview-stats {
    gap: 0.9rem;
    padding: 0.6rem 1rem;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .lib-preview-stats::-webkit-scrollbar {
    display: none;
  }
  .lps-item {
    flex-shrink: 0;
  }
  .lib-preview-content {
    padding: 1rem;
    line-height: 1.75;
  }
  .lib-preview-modal .foot {
    padding: 0.75rem 1rem;
  }
}

/* ── درباره ── */
.st-about {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem 1.5rem;
}
.st-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}
.st-brand-logo {
  width: 4rem;
  height: 4rem;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--vio), var(--acc));
  color: var(--acc-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 12px 32px color-mix(in srgb, var(--acc) 40%, transparent);
}
.st-brand-logo svg {
  width: 2.5rem;
  height: 2.5rem;
}
.st-brand b {
  font-size: var(--f-xl);
  font-weight: 800;
  letter-spacing: 0.3px;
}
.st-brand span {
  font-size: var(--f-xs);
  color: var(--mut);
  font-family: var(--mono);
  direction: ltr;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
}
.st-author {
  margin-top: 1.25rem;
  text-decoration: none;
  padding: 0.55rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--deep);
  transition: 0.18s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.st-author:hover {
  border-color: var(--cyn);
  background: var(--card2);
}
.st-author .ft-author {
  font-family: "Chakra Petch", var(--mono);
  font-weight: 700;
  color: var(--cyn);
  letter-spacing: 0.4px;
  font-size: var(--f-sm);
}

/* ══════════════ تنظیمات: دسکتاپ دو ستونه (≥900px) ══════════════ */
/* ═══ اسکرول‌بار تم‌پذیر برای پنل تنظیمات ═══ */
.drawer-body,
.st-view {
  scrollbar-width: thin;
  scrollbar-color: var(--line2) transparent;
}
.drawer-body::-webkit-scrollbar,
.st-view::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.drawer-body::-webkit-scrollbar-track,
.st-view::-webkit-scrollbar-track {
  background: transparent;
}
.drawer-body::-webkit-scrollbar-thumb,
.st-view::-webkit-scrollbar-thumb {
  background: var(--line2);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.drawer-body::-webkit-scrollbar-thumb:hover,
.st-view::-webkit-scrollbar-thumb:hover {
  background: var(--mut);
  background-clip: padding-box;
}

@media (min-width: 900px) {
  /* دراور → مودال وسط‌چین */
  .drawer {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    width: min(840px, calc(100vw - 48px));
    height: min(640px, calc(100vh - 48px));
    transform: translate(-50%, -50%) scale(0.96);
    border-radius: 18px;
    border: 1px solid var(--line2);
    border-inline-start: 1px solid var(--line2);
    opacity: 0;
    pointer-events: none;
    transition:
      opacity 0.2s var(--ease-ios),
      transform 0.28s var(--ease-spring);
    overflow: hidden;
  }
  .drawer.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
  }

  /* هدر */
  /* هدر دسکتاپ: از absolute خلاص شو، از flex استفاده کن */
  .drawer-head {
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    min-height: 0;
    background: var(--deep);
  }
  .drawer-head .icon-btn {
    position: static;
    transform: none;
    width: 2.25rem;
    height: 2.25rem;
  }
  .drawer-head h2 {
    flex: 1;
    text-align: start;
    max-width: none;
    font-size: var(--f-xl);
    letter-spacing: 0.2px;
  }

  /* دسکتاپ: back فقط برای viewهایی که والد منطقی دارن */
  .drawer[data-can-back="1"] .st-back {
    display: grid;
    margin-inline-start: -0.4rem; /* نزدیک‌تر به لبه — حس breadcrumb */
  }

  /* بدنه → گرید دو ستونه */
  .drawer-body {
    display: grid;
    grid-template-columns: 220px 1fr;
    padding: 0;
    overflow: hidden;
    gap: 0;
    background: var(--card);
  }

  /* ستون ناوبری (home) */
  .drawer-body .st-view[data-view="home"] {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    border-inline-end: 1px solid var(--line);
    background: var(--deep);
    overflow-y: auto;
    padding: 0.6rem;
    height: 100%;
    scrollbar-width: thin;
  }

  /* ستون محتوا */
  .drawer-body .st-view:not([data-view="home"]) {
    grid-column: 2;
    grid-row: 1;
    overflow-y: auto;
    padding: 1.3rem 1.5rem;
    height: 100%;
    scrollbar-width: thin;
    background: var(--card);
  }

  /* لیست ناوبری */
  .st-list {
    gap: 0.15rem;
  }
  .st-row {
    grid-template-columns: auto 1fr;
    gap: 0.7rem;
    padding: 0.55rem 0.7rem;
    background: transparent;
    border-color: transparent;
    border-radius: 10px;
    box-shadow: none;
  }
  .st-row::before {
    display: none;
  }
  .st-row:hover {
    background: var(--card2);
    border-color: transparent;
  }
  .st-row:active {
    transform: none;
  }
  .st-row.active {
    background: color-mix(in srgb, var(--acc) 16%, transparent);
    border-color: color-mix(in srgb, var(--acc) 38%, transparent);
  }
  .st-row.active .st-icon {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.14),
      0 4px 14px color-mix(in srgb, var(--st-c, var(--acc)) 42%, transparent);
  }
  .st-row .st-val,
  .st-row .st-chev {
    display: none;
  }
  .st-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 9px;
    box-shadow: none;
  }
  .st-icon svg {
    width: 1rem;
    height: 1rem;
  }
  .st-label {
    font-size: var(--f-sm);
    font-weight: 700;
  }

  /* کتابخانه: خودش اسکرول نکنه — گرید اسکرول شه */
  .drawer-body .st-view[data-view="library"] {
    overflow: hidden;
  }

  /* صفحهٔ درباره: وسط‌چین عمودی */
  .drawer-body .st-view[data-view="about"] {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .st-about {
    padding: 1rem;
    min-height: auto;
    width: 100%;
  }

  /* بنر آپدیت */
  .st-update-banner {
    margin-bottom: 0.5rem;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }
  .st-update-banner .btn {
    width: 100%;
  }
  .st-update-info b {
    font-size: var(--f-xs);
  }
  .st-update-info span {
    font-size: var(--f-2xs);
  }

  /* سکشن‌های محتوا: کمی جمع‌تر */
  .drawer-body .st-section {
    margin-bottom: 1.2rem;
  }
  .drawer-body .st-section .row-pref {
    padding: 0.8rem 0;
  }
}

/* ══════════════ فیکس باگ‌های تنظیمات ══════════════ */

/* ۱) [hidden] باید همیشه برنده باشه — حتی روی viewهایی که display صریح دارن */
.drawer .st-view[hidden],
.drawer-body .st-view[hidden] {
  display: none !important;
}

/* ۲) دکمه‌های داخل سکشن‌های تنظیمات — پولیش ظاهری */
.st-section .row-pref .btn {
  flex-shrink: 0;
  flex-grow: 0;
  padding: 0.5rem 0.95rem;
  font-size: var(--f-xs);
  border-radius: 10px;
  min-height: 2.2rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  transition:
    background 0.18s var(--ease),
    border-color 0.18s var(--ease),
    color 0.18s var(--ease),
    transform 0.12s var(--ease);
}
.st-section .row-pref .btn:not(.g):not(.dgr) {
  background: var(--card2);
  border: 1px solid var(--line2);
  color: var(--txt);
}
.st-section .row-pref .btn:not(.g):not(.dgr):hover {
  background: var(--card);
  border-color: var(--focus);
}
.st-section .row-pref .btn:hover {
  transform: translateY(-1px);
  box-shadow: none;
}
.st-section .row-pref .btn:active {
  transform: scale(0.96);
}
.st-section .row-pref .btn.dgr {
  background: transparent;
  border: 1px solid rgba(251, 113, 133, 0.55);
  color: var(--ros);
}
.st-section .row-pref .btn.dgr:hover {
  background: rgba(251, 113, 133, 0.1);
  border-color: var(--ros);
}

/* ۳) تو دسکتاپ، .st-row فعال نباید پس‌زمینه سکشن رو از دست بده */
@media (min-width: 900px) {
  .drawer-body .st-view[data-view="about"] {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ══════════════ صفحهٔ صدا: اسلایدر شدت ══════════════ */
.st-slider-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.15rem 0;
}
.st-slider {
  flex: 1;
  min-width: 0;
  height: 6px;
  border-radius: 999px;
  cursor: pointer;
  accent-color: var(--acc);
  background: transparent;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.st-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
}
.st-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--acc);
  border: 3px solid var(--card);
  margin-top: -8px;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--acc) 45%, transparent);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.st-slider:hover::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 3px 14px color-mix(in srgb, var(--acc) 60%, transparent);
}
.st-slider:active::-webkit-slider-thumb {
  transform: scale(1.05);
}
.st-slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--deep);
  border: 1px solid var(--line);
}
.st-slider::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--acc);
}
.st-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--acc);
  border: 3px solid var(--card);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--acc) 45%, transparent);
}
.st-slider:focus-visible {
  outline: none;
}
.st-slider:focus-visible::-webkit-slider-thumb {
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent),
    0 2px 10px color-mix(in srgb, var(--acc) 45%, transparent);
}

/* عدد درصد — فونت درست، بدون mono */
.st-slider-val {
  min-width: 3.6rem;
  text-align: center;
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: var(--f-md);
  font-weight: 800;
  color: var(--acc);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  direction: rtl;
}

.st-slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: var(--f-2xs);
  color: var(--dim);
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0 3px;
}

/* دکمهٔ پیش‌نمایش */
#soundTestBtn {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border-style: dashed;
  font-size: var(--f-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
#soundTestBtn svg {
  width: 1rem;
  height: 1rem;
}
#soundTestBtn:hover {
  border-style: solid;
}

/* انیمیشن ظاهر شدن بخش‌های وابسته به sound-on */
.st-view[data-view="sound"] .st-section[data-when="sound-on"] {
  animation: stSlideIn 0.25s var(--ease-ios);
}
@keyframes stSlideIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ══════════════ انتخاب تم صوتی (گرید) ══════════════ */
.seg.st-seg-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 5px;
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg.st-seg-grid button {
  width: 100%;
  padding: 0.55rem 0.3rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--mut);
  font-size: var(--f-xs);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition:
    color 0.18s var(--ease),
    background 0.18s var(--ease);
  position: relative;
  overflow: hidden;
}
.seg.st-seg-grid button:hover {
  color: var(--txt);
  background: var(--card2);
}
.seg.st-seg-grid button.on {
  color: var(--acc-ink);
  background: var(--acc);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--acc) 35%, transparent);
}

/* ══════════════ کتابخانه: حالت‌های بارگذاری ══════════════ */
.lib-loading,
.lib-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--dim);
  font-size: var(--f-sm);
  grid-column: 1 / -1;
}
.lib-loading::after {
  content: "";
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-inline-start: 0.5rem;
  border: 2px solid var(--line2);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: libSpin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes libSpin {
  to {
    transform: rotate(360deg);
  }
}

/* ══════════════ آیکون عنوان مودال ══════════════ */
.modal-h-ic {
  display: inline-grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 9px;
  background: color-mix(in srgb, var(--acc) 16%, transparent);
  color: var(--acc);
  flex-shrink: 0;
}
.modal-h-ic svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}
/* آیکون هشدار قرمز (برای دیالوگ‌های خطرناک) */
.modal-h-ic.is-warn {
  background: color-mix(in srgb, var(--ros) 16%, transparent);
  color: var(--ros);
}
/* آیکون کمک/سؤال */
.modal-h-ic.is-help {
  background: color-mix(in srgb, var(--blu) 16%, transparent);
  color: var(--blu);
}
/* آیکون ورودی (download) */
.modal-h-ic.is-down {
  background: color-mix(in srgb, var(--grn) 16%, transparent);
  color: var(--grn);
}

/* آیکون داخل .btn */
.btn > svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  display: block;
}

@media (max-width: 759px) {
  .var-deck {
    position: relative;
    width: auto;
    max-width: none;
    justify-self: stretch;
  }
}

@media (max-width: 759px) {
  /* آیکون چشمِ هدر در موبایل — گوشهٔ چپ، سایز بزرگ‌تر */
  .var-head .var-preview-toggle {
    display: grid;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 12px;
  }

  /* پنل = overlay تمام‌صفحه از پایین (به‌جای side-card که اسکرول افقی می‌داد) */
  .var-deck .var-preview-panel {
    position: fixed;
    inset: 0;
    margin: 0;
    width: 100%;
    max-width: none;
    border-radius: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transform: translateX(-100%);
    transition:
      opacity 0.25s var(--ease-ios),
      transform 0.4s var(--ease-ios),
      visibility 0s linear 0.4s;
  }
  .var-deck.preview-open .var-preview-panel {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transform: translateX(0);
    transition:
      opacity 0.25s var(--ease-ios),
      transform 0.4s var(--ease-ios),
      visibility 0s linear 0s;
  }
 .var-deck .var-preview-panel-head {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    flex-shrink: 0;
    background: var(--deep);
    border-bottom: 1px solid var(--line);
  }
  .var-deck .var-preview-panel-title {
    flex: 1;
    font-size: var(--f-md);
    color: var(--txt);
    font-weight: 800;
  }
  .var-deck .var-preview-back {
    display: grid;
    order: -1;
  }
  .var-deck .var-preview {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .var-deck .var-preview-foot {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0.9rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }
  .var-deck .var-preview-foot .btn { flex: 1; }
}

