@font-face {
  font-family: 'AradVF';
  src: url('fonts/AradVF.ttf') format('truetype');
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --sidebar-bg: #161b2e;
  --sidebar-text: #b7bfd9;
  --sidebar-active: #2563eb;
  --card-bg: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --text: #1e2233;
  --muted: #7a839c;
  --border: #e7eaf3;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(22, 27, 46, 0.06);
}

body {
  font-family: 'AradVF', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app { display: flex; height: 100vh; }

/* ===== سایدبار ===== */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; padding: 0 6px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #1e40af);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 15px;
}
.brand-title { font-size: 15px; font-weight: 700; color: #fff; }
.brand-sub { font-size: 11px; color: #8891ad; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 10px;
  background: transparent; border: none; color: var(--sidebar-text);
  font-size: 14px; text-align: right; cursor: pointer;
  transition: background .15s, color .15s;
  font-family: inherit;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.level-badge {
  font-size: 12px; text-align: center; padding: 8px;
  border-radius: 8px; background: rgba(59,130,246,0.15); color: #93c5fd;
}

/* ===== محتوا ===== */
.content { flex: 1; padding: 30px 36px; overflow-y: auto; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 22px; }
.page-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

.btn {
  padding: 10px 20px; border-radius: 10px; border: none;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: transform .1s, opacity .15s;
}
.btn:hover { opacity: 0.92; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #eef1f8; color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== داشبورد ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-box {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat-box .stat-value { font-size: 24px; font-weight: 800; color: var(--primary); }
.stat-box .stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.cta-card { display: flex; align-items: center; justify-content: space-between; background: linear-gradient(135deg, #eef4ff, #f7faff); }
.cta-text h3 { font-size: 15px; margin-bottom: 4px; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.action-card { cursor: pointer; text-align: center; transition: transform .15s, box-shadow .15s; }
.action-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(22,27,46,0.1); }
.action-icon { font-size: 26px; margin-bottom: 8px; }
.action-title { font-weight: 700; margin-bottom: 2px; font-size: 14px; }

/* ===== فیلترها ===== */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filters select {
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border);
  font-family: inherit; font-size: 13px; background: #fff; color: var(--text);
}

/* ===== فلش‌کارت ===== */
.flash-progress { text-align: center; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.flashcard { max-width: 480px; margin: 0 auto 22px; height: 260px; perspective: 1200px; cursor: pointer; }
.flashcard-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .5s; transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
  border-radius: 18px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.flashcard-front { background: linear-gradient(135deg, #ffffff, #f3f6ff); }
.flashcard-back { background: linear-gradient(135deg, #2563eb, #1e40af); color: #fff; transform: rotateY(180deg); }
.flash-english { font-size: 30px; font-weight: 800; color: var(--text); direction: ltr; }
.flash-hint { margin-top: 12px; }
.flash-persian { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.flash-phonetic { font-size: 14px; opacity: .85; direction: rtl; }

.flash-actions { display: flex; justify-content: center; gap: 14px; }
.flash-actions .btn { min-width: 150px; font-size: 14px; padding: 12px 20px; }

/* ===== کوییز ===== */
.quiz-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.progress-bar { flex: 1; height: 8px; background: #eef1f8; border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; transition: width .3s; }
.quiz-progress span { font-size: 12px; color: var(--muted); white-space: nowrap; }

.quiz-word { font-size: 30px; font-weight: 800; text-align: center; margin: 10px 0 4px; direction: ltr; }
.quiz-phonetic { text-align: center; margin-bottom: 20px; }

.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 560px; margin: 0 auto; }
.quiz-option {
  padding: 16px; border-radius: 12px; border: 1.5px solid var(--border);
  background: #fafbff; cursor: pointer; font-size: 14.5px; text-align: center;
  transition: border-color .15s, background .15s;
  font-family: inherit;
}
.quiz-option:hover { border-color: var(--primary); background: #eef4ff; }
.quiz-option.correct { border-color: var(--success); background: #ecfdf3; color: #166534; font-weight: 700; }
.quiz-option.wrong { border-color: var(--danger); background: #fef2f2; color: #991b1b; font-weight: 700; }
.quiz-option.disabled { pointer-events: none; }

.quiz-result-actions { display: flex; gap: 12px; margin-top: 14px; }

/* ===== پیشرفت ===== */
.bars-chart { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bar { width: 60%; background: linear-gradient(180deg, #3b82f6, #1d4ed8); border-radius: 6px 6px 0 0; min-height: 3px; }
.bar-day-label { font-size: 10px; color: var(--muted); }

.category-list { display: flex; flex-direction: column; gap: 12px; }
.category-row { display: flex; align-items: center; gap: 12px; }
.category-name { width: 110px; font-size: 13px; flex-shrink: 0; }
.category-bar-bg { flex: 1; height: 10px; background: #eef1f8; border-radius: 6px; overflow: hidden; }
.category-bar-fill { height: 100%; background: var(--primary); border-radius: 6px; }
.category-count { font-size: 12px; color: var(--muted); width: 55px; text-align: left; flex-shrink: 0; }

/* ===== فصل‌های کوییز ===== */
.chapter-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.chapter-card {
  background: var(--card-bg); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); cursor: pointer; position: relative;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.chapter-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(22,27,46,0.1); border-color: var(--primary); }
.chapter-card.locked { opacity: 0.55; cursor: not-allowed; }
.chapter-card.locked:hover { transform: none; box-shadow: var(--shadow); border-color: var(--border); }
.chapter-card.completed { border-color: var(--success); }
.chapter-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chapter-level-tag {
  font-size: 10.5px; padding: 3px 9px; border-radius: 20px; font-weight: 700;
  background: #eef4ff; color: var(--primary);
}
.chapter-level-tag.l2 { background: #fff3e0; color: #c2680a; }
.chapter-level-tag.l3 { background: #fdeaea; color: #b91c1c; }
.chapter-check { font-size: 16px; }
.chapter-name { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.chapter-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.chapter-bar-bg { height: 7px; background: #eef1f8; border-radius: 6px; overflow: hidden; }
.chapter-bar-fill { height: 100%; background: var(--primary); border-radius: 6px; }
.chapter-lock-icon { position: absolute; top: 14px; left: 16px; font-size: 14px; }
.chapter-title { font-weight: 700; font-size: 15px; margin-bottom: 14px; color: var(--primary); }

/* ===== نتیجه تعیین سطح ===== */
.placement-result-card { text-align: center; max-width: 560px; margin: 0 auto; }
.result-emoji { font-size: 42px; margin-bottom: 6px; }
.level-meter { margin: 22px 0; }
.level-meter-track { height: 12px; background: #eef1f8; border-radius: 8px; overflow: hidden; position: relative; }
.level-meter-fill { height: 100%; background: linear-gradient(90deg, #60a5fa, #2563eb); border-radius: 8px; transition: width .6s ease; }
.level-meter-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.placement-breakdown { display: flex; justify-content: center; gap: 20px; margin-bottom: 10px; }
.breakdown-item { text-align: center; }
.breakdown-value { font-size: 18px; font-weight: 800; color: var(--primary); }
.breakdown-label { font-size: 11px; color: var(--muted); }

.hidden { display: none !important; }

/* ===================== نسخه وب / موبایل ===================== */
html { -webkit-text-size-adjust: 100%; }
html { height: 100%; min-height: -webkit-fill-available; background: var(--bg); }
body { height: 100%; min-height: -webkit-fill-available; background: var(--sidebar-bg); -webkit-tap-highlight-color: transparent; }
@media (min-width: 821px) { body { background: var(--bg); } }
/* ثابت روی کل صفحه (شامل ناحیه امن آیفون) تا نوار سفید پایین نیاد */
.app { position: fixed; top: 0; right: 0; bottom: 0; left: 0; height: auto; }
.content { -webkit-overflow-scrolling: touch; }

.speak-btn {
  border: none; background: rgba(37, 99, 235, 0.1); color: var(--primary);
  width: 44px; height: 44px; border-radius: 50%; font-size: 18px; cursor: pointer;
  margin-top: 10px; font-family: inherit;
}
.speak-btn:active { transform: scale(0.94); }
.speak-row { text-align: center; margin-bottom: 14px; }
.speak-row .speak-btn { margin-top: 0; }
.backup-note { margin: 6px 0 14px; line-height: 1.8; }
#page-progress .quiz-result-actions { flex-wrap: wrap; }

@media (max-width: 820px) {
  html { background: var(--sidebar-bg); }
  .content { background: var(--bg); }
  .app { flex-direction: column-reverse; }

  /* سایدبار تبدیل می‌شه به نوار پایین */
  .sidebar {
    width: 100%; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255,255,255,0.08);
  }
  .brand, .sidebar-footer { display: none; }
  .nav { flex-direction: row; gap: 2px; justify-content: space-between; }
  .nav-item {
    flex: 1; flex-direction: column; gap: 3px; padding: 7px 2px;
    font-size: 11px; text-align: center; min-width: 0; white-space: nowrap;
  }
  .nav-icon { font-size: 19px; width: auto; }

  .content {
    padding: calc(18px + env(safe-area-inset-top)) 16px 24px;
  }
  .page-header h1 { font-size: 20px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-box { padding: 14px; }
  .cta-card { flex-direction: column; align-items: stretch; gap: 14px; }
  .quick-actions { grid-template-columns: 1fr; }
  .chapter-list { grid-template-columns: 1fr 1fr; gap: 10px; }
  .chapter-card { padding: 14px; }

  .flashcard { height: 240px; }
  .flash-actions { gap: 10px; }
  .flash-actions .btn { min-width: 0; flex: 1; padding: 14px 10px; }
  .filters select, .filters .btn { flex: 1 1 40%; min-height: 44px; font-size: 16px; }

  .quiz-options { grid-template-columns: 1fr; }
  .quiz-option { padding: 15px; min-height: 52px; }
  .quiz-result-actions { flex-wrap: wrap; }
  .quiz-result-actions .btn { flex: 1 1 40%; min-height: 44px; }
  .btn { min-height: 44px; }

  .category-name { width: 84px; font-size: 12px; }
}


/* حالت Home Screen آیفون: منو کامل به پایین صفحه بچسبه */
@media (max-width: 820px) {
  html.standalone .sidebar { padding-bottom: 4px; }
  html.standalone .nav-item { padding-top: 9px; padding-bottom: 9px; }
}

/* ===================== پروفایل و خوش‌آمدگویی ===================== */
.text-input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1.5px solid var(--border);
  font-family: inherit; font-size: 16px; background: #fff; color: var(--text); outline: none;
}
.text-input:focus { border-color: var(--primary); }
.name-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.name-row .text-input { flex: 1 1 180px; width: auto; }

.profile-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile-avatar {
  width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #3b82f6, #1e40af); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800;
}
.profile-info { flex: 1; min-width: 140px; }
.profile-name { font-size: 20px; font-weight: 800; margin-bottom: 2px; word-break: break-word; }
.profile-level-chip {
  display: inline-block; margin-top: 8px; padding: 3px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 700; background: #eef4ff; color: var(--primary);
}
.level-steps { display: flex; gap: 8px; margin-bottom: 10px; }
.level-step {
  flex: 1; text-align: center; padding: 10px 4px; border-radius: 10px; font-size: 13px;
  background: #eef1f8; color: var(--muted); font-weight: 600;
}
.level-step.reached { background: #dbe8ff; color: var(--primary); }
.level-step.current { background: var(--primary); color: #fff; }

.welcome-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000;
  background: rgba(22, 27, 46, 0.78); display: flex; align-items: center; justify-content: center;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}
.welcome-card {
  background: #fff; border-radius: 18px; padding: 28px 24px; width: 100%; max-width: 380px;
  text-align: center; display: flex; flex-direction: column; gap: 14px;
}
.welcome-emoji { font-size: 44px; }
.welcome-card h2 { font-size: 18px; }
.welcome-card .btn { width: 100%; min-height: 46px; }

@media (max-width: 420px) {
  .chapter-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
