/* ============ فونت‌ها (self-hosted) ============ */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/vazirmatn.woff2') format('woff2-variations'), url('/fonts/vazirmatn.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Lalezar';
  src: url('/fonts/lalezar-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFF;
  font-display: swap;
}
@font-face {
  font-family: 'Lalezar';
  src: url('/fonts/lalezar-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF;
  font-display: swap;
}
@font-face {
  font-family: 'JB Mono';
  src: url('/fonts/jbmono-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

/* ============ توکن‌های طراحی ============ */
:root {
  --ink: #1b1e3c;
  --ink-2: #4b5078;
  --ink-3: #8b90b4;
  --bg: #eef1ff;
  --violet: #7c5cff;
  --violet-d: #5a3de0;
  --cyan: #1fb5d6;
  --mango: #ffac2f;
  --pink: #ff5fa2;
  --mint: #16b886;
  --danger: #e5484d;

  --glass: rgba(255, 255, 255, 0.74);
  --glass-strong: rgba(255, 255, 255, 0.84);
  --glass-edge: rgba(255, 255, 255, 0.95);
  --shadow: 0 18px 40px -22px rgba(46, 28, 122, 0.45), 0 2px 6px -2px rgba(46, 28, 122, 0.08);
  --shadow-lg: 0 30px 70px -30px rgba(46, 28, 122, 0.55);

  --r-lg: 26px;
  --r-md: 18px;
  --r-sm: 12px;

  --f-body: 'Vazirmatn', system-ui, Tahoma, sans-serif;
  --f-display: 'Lalezar', 'Vazirmatn', system-ui, sans-serif;
  --f-mono: 'JB Mono', ui-monospace, monospace;

  --ease-jelly: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
[hidden] { display: none !important; }

.num { font-feature-settings: 'tnum'; }
.mono { font-family: var(--f-mono); letter-spacing: 0.02em; }
.display { font-family: var(--f-display); font-weight: 400; letter-spacing: 0; }
.muted { color: var(--ink-2); }
.faint { 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(--violet); outline-offset: 3px; border-radius: 8px; }

/* ============ پس‌زمینه مایع ============ */
/* پس‌زمینه ثابت با گرادیان‌های نرم. عمداً بدون filter: blur و بدون انیمیشن است:
   لکه‌های blurشده‌ی متحرک کل صفحه را در هر فریم دوباره رنگ می‌کردند و روی موبایل لگ می‌انداختند. */
.liquid-bg {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* ارتفاع ثابت (lvh): با جمع/باز شدن نوار آدرس موبایل تغییر اندازه نمی‌دهد و چشمک نمی‌زند */
  height: 100vh;
  height: 100lvh;
  transform: translateZ(0);
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(48vmax 40vmax at 92% -6%, rgba(183, 164, 255, 0.55), transparent 70%),
    radial-gradient(44vmax 40vmax at -8% 96%, rgba(143, 227, 255, 0.5), transparent 70%),
    radial-gradient(30vmax 26vmax at 55% 55%, rgba(255, 210, 138, 0.22), transparent 70%),
    radial-gradient(24vmax 22vmax at 12% 18%, rgba(255, 179, 212, 0.28), transparent 70%),
    var(--bg);
}
.liquid-bg i { display: none; }

/* ============ شیشه ============ */
.glass {
  background: var(--glass);
  border: 1.5px solid var(--glass-edge);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

/* ============ دکمه‌ها ============ */
.btn {
  --btn-bg: var(--violet);
  --btn-fg: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 10px 20px -10px color-mix(in srgb, var(--btn-bg) 80%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.25s var(--ease-jelly), filter 0.2s, box-shadow 0.2s;
}
@media (hover: hover) { .btn:hover { filter: brightness(1.06); transform: translateY(-1px); } }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-ghost { --btn-bg: rgba(255, 255, 255, 0.7); --btn-fg: var(--ink); border: 1.5px solid #fff; box-shadow: 0 6px 16px -10px rgba(46, 28, 122, 0.4); }
.btn-danger { --btn-bg: var(--danger); }
.btn-soft-danger { --btn-bg: #ffe9ea; --btn-fg: #c4262c; box-shadow: none; }
.btn-sm { min-height: 34px; padding: 4px 14px; font-size: 13.5px; }
.btn-icon { width: 38px; min-height: 38px; padding: 0; }

/* ============ فرم ============ */
.field { display: grid; gap: 6px; }
.field > span { font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  border: 1.5px solid rgba(124, 92, 255, 0.18);
  background: rgba(255, 255, 255, 0.85);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.8; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.15); }
.input.ltr { direction: ltr; text-align: left; font-family: var(--f-mono); font-size: 14px; }
.hint { font-size: 12.5px; color: var(--ink-3); }
.form-error { color: var(--danger); font-size: 14px; font-weight: 600; min-height: 1.4em; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 600; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 999px; background: #d9dcef; position: relative; cursor: pointer; transition: background 0.2s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); transition: transform 0.3s var(--ease-jelly); }
.switch input:checked { background: var(--mint); }
.switch input:checked::after { transform: translateX(-18px); }

/* ============ چیپ و برچسب ============ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid #fff;
  color: var(--ink-2);
  white-space: nowrap;
}
.chip-violet { background: #ece6ff; color: #4b2fd0; border-color: transparent; }
.chip-mint { background: #daf7ec; color: #0b6e50; border-color: transparent; }
.chip-gray { background: #eceef6; color: #6b7094; border-color: transparent; }
.chip-pink { background: #ffe3ef; color: #b3195c; border-color: transparent; }
.xp-tag { font-family: var(--f-mono); font-size: 0.72em; letter-spacing: 0.06em; opacity: 0.75; }

/* ============ مدال و آواتار ============ */
.badge { position: relative; flex: none; width: 44px; height: 44px; }
.badge .badge-svg { width: 100%; height: 100%; }
.badge .count {
  position: absolute;
  bottom: -4px;
  left: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  border: 2px solid #fff;
}
.avatar { display: inline-block; vertical-align: middle; flex: none; width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, 0.8); border: 2px solid #fff; box-shadow: 0 6px 14px -8px rgba(46, 28, 122, 0.5); overflow: hidden; }
.avatar .avatar-svg { width: 100%; height: 100%; transform: translateY(4%); }
.avatar.free { background: none; border: 0; box-shadow: none; border-radius: 0; overflow: visible; }
.avatar.free .avatar-svg { transform: none; }
.badge { display: inline-block; }

/* ============ Modal ============ */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(27, 30, 60, 0.42);
  animation: fade-in 0.25s ease both;
}
.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 26px;
  background: var(--glass-strong);
  border: 1.5px solid #fff;
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.45s var(--ease-jelly) both;
  overscroll-behavior: contain;
}
.modal.wide { width: min(760px, 100%); }
.modal-close { position: absolute; top: 14px; left: 14px; }
.modal h2 { font-family: var(--f-display); font-weight: 400; font-size: 28px; margin-bottom: 4px; padding-left: 44px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; flex-wrap: wrap; margin-top: 20px; }
.modal-root.closing { animation: fade-out 0.2s ease both; }
.modal-root.closing .modal { animation: pop-out 0.2s ease both; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(24px) scale(0.92); } }
@keyframes pop-out { to { opacity: 0; transform: scale(0.95); } }

/* ============ Toast ============ */
.toasts { position: fixed; z-index: 90; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 10px; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(27, 30, 60, 0.92);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.5s var(--ease-jelly) both;
}
.toast.error { background: #b4232a; }
.toast .badge { width: 38px; height: 38px; }
.toast .grow { flex: 1; }
.toast .btn { min-height: 32px; padding: 2px 14px; font-size: 13px; --btn-bg: #fff; --btn-fg: var(--ink); }
.toast.leaving { animation: toast-out 0.3s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(30px) scale(0.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px) scale(0.96); } }

/* ============ متفرقه ============ */
.container { width: min(1180px, 100% - 32px); margin-inline: auto; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid rgba(124, 92, 255, 0.2); border-top-color: var(--violet); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-screen { min-height: 70vh; display: grid; place-items: center; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty .display { font-size: 26px; color: var(--ink); margin-bottom: 6px; }
#confetti { position: fixed; inset: 0; z-index: 80; pointer-events: none; }

/* ============ جشن اهدای Trophy ============ */
.celebrate { position: fixed; inset: 0; z-index: 75; display: grid; place-items: center; background: rgba(238, 241, 255, 0.86); animation: fade-in 0.25s ease both; cursor: pointer; overflow: hidden; }
.celebrate.out { animation: fade-out 0.4s ease both; }
.celebrate-rays { position: absolute; width: 900px; height: 900px; background: repeating-conic-gradient(from 0deg, rgba(255, 211, 92, 0.28) 0deg 10deg, transparent 10deg 24deg); border-radius: 50%; mask-image: radial-gradient(circle, #000 20%, transparent 65%); -webkit-mask-image: radial-gradient(circle, #000 20%, transparent 65%); animation: rays 12s linear infinite; }
@keyframes rays { to { transform: rotate(360deg); } }
.celebrate-card { position: relative; text-align: center; padding: 0 20px; }
.celebrate-badge { width: 180px; height: 180px; margin: 0 auto; animation: badge-land 0.9s var(--ease-jelly) both; filter: drop-shadow(0 24px 30px rgba(46, 28, 122, 0.35)); }
.celebrate-badge img { width: 100%; height: 100%; }
@keyframes badge-land { 0% { transform: scale(0) rotate(-200deg); } 70% { transform: scale(1.12) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }
.celebrate-title { font-size: clamp(30px, 6vw, 46px); margin-top: 14px; animation: pop-in 0.6s var(--ease-jelly) 0.25s both; }
.celebrate-sub { font-size: 18px; font-weight: 700; color: var(--ink-2); animation: pop-in 0.6s var(--ease-jelly) 0.35s both; }
.celebrate-xp { display: inline-block; margin-top: 10px; font-size: 40px; color: #fff; background: linear-gradient(135deg, #ffd35c, #ff9f1c); padding: 4px 22px 0; border-radius: 999px; box-shadow: 0 14px 30px -12px rgba(255, 159, 28, 0.8); animation: xp-float 1.1s var(--ease-jelly) 0.45s both; }
@keyframes xp-float { 0% { opacity: 0; transform: translateY(30px) scale(0.6); } 100% { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .liquid-bg i { animation: none; }
}
