/* ========== فونت دانا (self-hosted) ========== */
@font-face { font-family: Dana; src: url(/fonts/dana-fanum-light.woff2) format('woff2'); font-weight: 300; font-display: swap; }
@font-face { font-family: Dana; src: url(/fonts/dana-fanum-regular.woff2) format('woff2'); font-weight: 400; font-display: block; }
@font-face { font-family: Dana; src: url(/fonts/dana-fanum-medium.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: Dana; src: url(/fonts/dana-fanum-demibold.woff2) format('woff2'); font-weight: 600; font-display: block; }
@font-face { font-family: Dana; src: url(/fonts/dana-fanum-bold.woff2) format('woff2'); font-weight: 700; font-display: block; }
@font-face { font-family: Dana; src: url(/fonts/dana-fanum-black.woff2) format('woff2'); font-weight: 900; font-display: block; }

:root {
  /* جوهر لاجوردی، کاغذ کاهی، فیروزه، زعفران، انار */
  --ink: oklch(0.27 0.04 245);
  --ink-2: oklch(0.44 0.035 245);
  --ink-3: oklch(0.6 0.025 245);
  --paper: oklch(0.972 0.014 85);
  --paper-2: oklch(0.945 0.022 84);
  --paper-3: oklch(0.905 0.032 82);
  --surface: oklch(0.99 0.006 85);
  --line: oklch(0.87 0.024 80);
  --line-2: oklch(0.8 0.03 78);
  --teal: oklch(0.53 0.1 196);
  --teal-d: oklch(0.43 0.09 200);
  --teal-dd: oklch(0.33 0.07 205);
  --teal-l: oklch(0.93 0.035 195);
  --saffron: oklch(0.8 0.15 78);
  --saffron-d: oklch(0.66 0.14 68);
  --saffron-l: oklch(0.95 0.05 88);
  --pom: oklch(0.55 0.19 25);
  --pom-l: oklch(0.94 0.035 25);
  --ok: oklch(0.58 0.13 155);
  --ok-l: oklch(0.94 0.04 155);
  --on-accent: oklch(0.985 0.008 85);
  --on-gold: oklch(0.26 0.045 60);
  --gold-ink: oklch(0.45 0.1 70);
  --ok-ink: oklch(0.45 0.11 155);
  --toast-bg: oklch(0.27 0.04 245);
  --die-face: oklch(0.975 0.01 85);
  --die-side: oklch(0.86 0.03 82);
  --shade: oklch(0.3 0.05 60);

  --font: Dana, Tahoma, 'Segoe UI', system-ui, sans-serif;
  --fs-xs: 0.75rem; --fs-sm: 0.875rem; --fs-md: 1rem; --fs-lg: 1.3rem; --fs-xl: 1.75rem; --fs-2xl: clamp(2rem, 5vw, 3rem);

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --r-sm: 8px; --r-md: 14px; --r-lg: 22px; --r-pill: 999px;

  --sh-sm: 0 1px 2px oklch(0.3 0.04 60 / 0.1);
  --sh-md: 0 6px 18px -6px oklch(0.3 0.05 60 / 0.22), 0 1px 3px oklch(0.3 0.04 60 / 0.08);
  --sh-lg: 0 24px 50px -18px oklch(0.28 0.05 60 / 0.35);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --z-nav: 20; --z-sheet: 40; --z-overlay: 60; --z-toast: 80; --z-fx: 90;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

/* ========== تم تیره (پیش‌فرض) ========== */
:root[data-theme='dark'] {
  color-scheme: dark;
  --ink: oklch(0.94 0.012 85);
  --ink-2: oklch(0.8 0.018 230);
  --ink-3: oklch(0.64 0.022 235);
  --paper: oklch(0.175 0.02 240);
  --paper-2: oklch(0.225 0.022 238);
  --paper-3: oklch(0.285 0.024 236);
  --surface: oklch(0.205 0.021 239);
  --line: oklch(0.3 0.022 238);
  --line-2: oklch(0.38 0.026 236);
  --teal: oklch(0.56 0.1 197);
  --teal-d: oklch(0.76 0.1 194);
  --teal-dd: oklch(0.36 0.07 204);
  --teal-l: oklch(0.29 0.05 200);
  --saffron: oklch(0.82 0.15 80);
  --saffron-d: oklch(0.64 0.14 68);
  --saffron-l: oklch(0.3 0.06 80);
  --pom: oklch(0.66 0.19 25);
  --pom-l: oklch(0.3 0.08 25);
  --ok: oklch(0.7 0.14 155);
  --ok-l: oklch(0.29 0.06 155);
  --gold-ink: oklch(0.86 0.13 82);
  --ok-ink: oklch(0.8 0.13 155);
  --toast-bg: oklch(0.33 0.035 240);
  --shade: oklch(0.05 0.02 250);
  --sh-sm: 0 1px 2px oklch(0.05 0.02 250 / 0.4);
  --sh-md: 0 8px 22px -8px oklch(0.05 0.02 250 / 0.7), 0 1px 3px oklch(0.05 0.02 250 / 0.4);
  --sh-lg: 0 28px 60px -20px oklch(0.04 0.02 250 / 0.85);
}

:root[data-theme='dark'] .btn.primary:hover { --bg: oklch(0.62 0.1 196); }
:root[data-theme='dark'] .btn:not(.primary):not(.gold):not(.danger):not(.ghost) { box-shadow: 0 2px 0 oklch(0.12 0.02 240); }

/* انتقال نرم بین تم‌ها */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
.theme-fade, .theme-fade *, .theme-fade *::before, .theme-fade *::after { transition: background-color 380ms var(--ease), border-color 380ms var(--ease), color 380ms var(--ease), fill 380ms var(--ease) !important; }
.theme-btn .icon { transition: transform 600ms var(--ease); }
.theme-btn:hover .icon { transform: rotate(-24deg); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: var(--font); font-size: var(--fs-md); line-height: 1.6;
  color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  font-feature-settings: 'ss01';
}
h1, h2, h3 { line-height: 1.25; margin: 0; text-wrap: balance; font-weight: 800; }
p { margin: 0; text-wrap: pretty; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal-d); text-decoration: none; }
img, svg { display: block; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; border-radius: 6px; }

/* ========== دکمه‌ها ========== */
.btn {
  --bg: var(--surface); --fg: var(--ink); --bd: var(--line-2);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-5); border-radius: var(--r-md);
  background: var(--bg); color: var(--fg); border: 1px solid var(--bd);
  font-weight: 600; cursor: pointer; white-space: nowrap; user-select: none;
  transition: transform 120ms var(--ease), background-color 160ms var(--ease), box-shadow 160ms var(--ease);
  box-shadow: 0 2px 0 var(--bd);
}
.btn:hover { background: color-mix(in oklch, var(--bg), var(--ink) 4%); }
.btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--bd); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { --bg: var(--teal); --fg: var(--on-accent); --bd: var(--teal-dd); }
.btn.primary:hover { --bg: var(--teal-d); }
.btn.gold { --bg: var(--saffron); --fg: var(--on-gold); --bd: var(--saffron-d); }
.btn.danger { --bg: var(--pom-l); --fg: var(--pom); --bd: color-mix(in oklch, var(--pom), var(--paper) 55%); }
.btn.ghost { --bg: transparent; --bd: transparent; box-shadow: none; }
.btn.ghost:hover { --bg: var(--paper-2); }
.btn.lg { min-height: 56px; font-size: var(--fs-lg); padding: 0 var(--sp-6); border-radius: var(--r-lg); font-weight: 800; }
.btn.sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.block { width: 100%; }
.btn .spin { width: 18px; height: 18px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon { width: 22px; height: 22px; flex: none; }

/* ========== فرم ========== */
.field { display: grid; gap: 6px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.input {
  width: 100%; min-height: 48px; padding: 0 var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--line-2); background: var(--surface); outline: none;
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
.input:focus { border-color: var(--teal); box-shadow: 0 0 0 4px color-mix(in oklch, var(--teal), transparent 82%); }
.input.err { border-color: var(--pom); }
.field .hint { font-size: var(--fs-xs); color: var(--ink-3); }
.field .error { font-size: var(--fs-xs); color: var(--pom); min-height: 1em; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: 18px 50%, 12px 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-left: 36px; }

.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--paper-2); border-radius: var(--r-md); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; min-height: 40px; padding: 0 var(--sp-4); border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--sh-sm); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: 44px; cursor: pointer; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line-2); position: relative; cursor: pointer; transition: background 160ms var(--ease); flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--die-face); box-shadow: var(--sh-sm); transition: transform 200ms var(--ease); }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(-18px); }

.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--pom); color: var(--on-accent); font-size: 0.7rem; font-weight: 700; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; background: var(--paper-2); color: var(--ink-2); }
.chip.ok { background: var(--ok-l); color: var(--ok-ink); }
.chip.pom { background: var(--pom-l); color: var(--pom); }
.chip.gold { background: var(--saffron-l); color: var(--gold-ink); }

.avatar { width: 44px; height: 44px; flex: none; border-radius: 30%; display: grid; place-items: center; font-size: 24px; background: var(--paper-2); border: 1px solid var(--line); position: relative; }
.avatar.lg { width: 96px; height: 96px; font-size: 56px; border-radius: 32px; }
.avatar.sm { width: 34px; height: 34px; font-size: 18px; border-radius: 11px; }
.avatar > img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.avatar:has(> img) { background: var(--paper-3); overflow: visible; }
.avatar[data-online='true']::after { content: ''; position: absolute; bottom: -2px; left: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--surface); }

.skeleton { background: linear-gradient(90deg, var(--paper-2), var(--paper-3), var(--paper-2)); background-size: 200% 100%; animation: sk 1.4s linear infinite; border-radius: var(--r-sm); }
@keyframes sk { to { background-position: -200% 0; } }

/* ========== پوسته برنامه ========== */
.shell { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-nav); display: flex; align-items: center; gap: var(--sp-5);
  padding: var(--sp-3) clamp(var(--sp-4), 4vw, var(--sp-7)); background: color-mix(in oklch, var(--paper), transparent 6%);
  border-bottom: 1px solid var(--line);
}
.brand-group { display: flex; flex-direction: column; gap: 1px; }
.brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: 900; font-size: 1.25rem; color: var(--ink); letter-spacing: -0.01em; }
.brand-mark { width: 34px; height: 34px; }
.powered-by { font-size: 0.66rem; font-weight: 600; color: var(--ink-3); text-decoration: none; direction: ltr; padding-inline-start: 2px; }
.powered-by span { color: #e50914; font-weight: 800; }
.powered-by:hover { color: var(--ink-2); }
.powered-by:hover span { text-decoration: underline; }
@media (max-width: 560px) { .powered-by { display: none; } }

.wonderverse-tag {
  position: fixed; z-index: var(--z-nav); bottom: 14px; inset-inline-end: 14px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em; direction: ltr;
  color: var(--ink-3); background: color-mix(in oklch, var(--surface), transparent 4%);
  border: 1px solid var(--line); padding: 6px 11px; border-radius: 999px;
  text-decoration: none; box-shadow: 0 6px 18px -10px oklch(0.2 0.05 60 / 0.45);
  transition: color 150ms, border-color 150ms;
}
.wonderverse-tag:hover { color: #e50914; border-color: color-mix(in oklch, #e50914, transparent 55%); }
@media (max-width: 820px) { .wonderverse-tag { bottom: calc(var(--nav-h) + var(--safe-b) + 10px); } }
.topnav { display: flex; gap: var(--sp-1); margin-inline-start: var(--sp-5); }
.topnav a { display: flex; align-items: center; gap: var(--sp-2); padding: 8px 14px; border-radius: var(--r-md); color: var(--ink-2); font-weight: 600; position: relative; }
.topnav a:hover { background: var(--paper-2); color: var(--ink); }
.topnav a { isolation: isolate; transition: color 300ms var(--ease), background-color 200ms var(--ease); }
.topnav a[aria-current='page'] { color: var(--teal-d); background: transparent; }
.topnav a[aria-current='page']:hover { background: transparent; }
.nav-pill { position: absolute; inset: 0; z-index: -1; border-radius: var(--r-md); background: var(--teal-l); box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--teal), transparent 78%); pointer-events: none; }
.topnav .nav-pill { view-transition-name: nav-pill; }
.topnav a[aria-current='page'] .icon, .bottomnav a[aria-current='page'] .icon { animation: navIcon 560ms var(--ease) both; }
@keyframes navIcon { 0% { transform: scale(0.6) rotate(-14deg); } 55% { transform: scale(1.18) rotate(4deg); } 100% { transform: none; } }
.topnav .badge { position: absolute; top: 2px; left: 2px; }
.topbar .me { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-3); color: var(--ink); }
.topbar .me .rating { font-weight: 700; font-size: var(--fs-sm); color: var(--ink-2); }
main.page { padding: var(--sp-6) clamp(var(--sp-4), 4vw, var(--sp-7)) calc(var(--sp-7) + var(--nav-h)); max-width: 1200px; width: 100%; margin-inline: auto; }

.bottomnav { display: none; }
@media (max-width: 820px) {
  .topnav, .topbar .me .rating { display: none; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; inset-inline: 0; bottom: 0; z-index: var(--z-nav);
    height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px -18px oklch(0.3 0.05 60 / 0.35);
  }
  .bottomnav a { display: grid; place-items: center; align-content: center; gap: 2px; color: var(--ink-3); font-size: 0.72rem; font-weight: 600; position: relative; }
  .bottomnav a[aria-current='page'] { color: var(--teal-d); }
  .bottomnav a[aria-current='page'] .icon { stroke-width: 2.4; }
  .bottomnav a { isolation: isolate; }
  .bottomnav .nav-pill { inset: 7px auto auto 50%; width: 58px; height: 30px; translate: -50% 0; border-radius: var(--r-pill); view-transition-name: nav-pill-b; }
  .bottomnav .badge { position: absolute; top: 6px; left: calc(50% - 22px); }
  main.page { padding-top: var(--sp-5); }
}

/* ========== توست ========== */
#toasts { position: fixed; top: var(--sp-4); inset-inline: 0; margin-inline: auto; width: min(420px, calc(100% - 24px)); display: grid; gap: var(--sp-2); z-index: var(--z-toast); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--toast-bg); color: var(--on-accent); border-radius: var(--r-md); box-shadow: var(--sh-lg);
  animation: toastIn 360ms var(--ease);
}
.toast.err { background: var(--pom); }
.toast.ok { background: var(--teal-dd); }
.toast .t-body { flex: 1; font-size: var(--fs-sm); line-height: 1.5; }
.toast .btn { min-height: 34px; padding: 0 12px; font-size: var(--fs-sm); }
.toast.out { animation: toastOut 220ms var(--ease-in) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-16px) scale(0.97); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: var(--z-fx); }

.view-enter { animation: viewIn 420ms var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } }

/* ========== جابه‌جایی بین صفحه‌ها (خانه، دوستان، رتبه‌ها، پروفایل) ========== */
/* جهت: fwd = رفتن به آیتم بعدی منو (سمت چپ در راست‌به‌چپ)؛ صفحه‌ی تازه از چپ می‌آید و قبلی به راست می‌رود */
:root { --vt-dir: 0; }
:root[data-nav-dir='fwd'] { --vt-dir: -1; }
:root[data-nav-dir='back'] { --vt-dir: 1; }
.topbar { view-transition-name: topbar; }
.bottomnav { view-transition-name: bottomnav; }
/* نکته: صفحه دیگر view-transition-name ندارد. قبلاً کل صفحه به‌صورت یک عکس (snapshot) گرفته می‌شد و
   با scale و blur جابه‌جا می‌شد؛ هم‌زمان اندازه‌ی گروه بین دو صفحه با ارتفاع متفاوت کش می‌آمد و محتوایی که
   بعداً لود می‌شد عکس را دفرمه می‌کرد ← متن و تصویرها تار/کش‌آمده/پرشی دیده می‌شدند تا انیمیشن تمام شود.
   حالا View Transition فقط برای سُر خوردن «قرص» منو است و خود صفحه روی DOM زنده، فقط با opacity و
   translate (بدون blur/scale) انیمیت می‌شود؛ پس متن‌ها از فریم اول تیز هستند. */
::view-transition-group(root) { animation-duration: 300ms; }
::view-transition-group(nav-pill), ::view-transition-group(nav-pill-b) { animation-duration: 520ms; animation-timing-function: cubic-bezier(0.2, 1, 0.3, 1); }
::view-transition-old(nav-pill), ::view-transition-new(nav-pill), ::view-transition-old(nav-pill-b), ::view-transition-new(nav-pill-b) { animation: none; height: 100%; }
@keyframes pageIn { from { opacity: 0; transform: translate3d(calc(var(--vt-dir) * 40px), calc((1 - var(--vt-dir) * var(--vt-dir)) * 12px), 0); } }
/* محتوای صفحه‌ی تازه پله‌پله بالا می‌آید */
main.page[data-dir] > * > * { animation: riseIn 520ms cubic-bezier(0.16, 1, 0.3, 1) both; }
main.page[data-dir] > * > *:nth-child(2) { animation-delay: 50ms; }
main.page[data-dir] > * > *:nth-child(3) { animation-delay: 90ms; }
main.page[data-dir] > * > *:nth-child(4) { animation-delay: 130ms; }
main.page[data-dir] > * > *:nth-child(n+5) { animation-delay: 160ms; }
@keyframes riseIn { from { opacity: 0; transform: translate3d(0, 12px, 0); } }
main.page[data-dir] { animation: pageIn 420ms cubic-bezier(0.16, 1, 0.3, 1) both; }
main.page[data-dir='fwd'] { --vt-dir: -1; }
main.page[data-dir='back'] { --vt-dir: 1; }
main.page[data-dir='none'] { --vt-dir: 0; }
/* تصویر آواتارها بعد از لود شدن نرم ظاهر می‌شود، نه با پرش */
.av-img { transition: opacity 200ms var(--ease); }
.av-img:not(.ready) { opacity: 0; }

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