@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Variable.woff2") format("woff2-variations"), url("fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #F5F3EC;
  --surface: #FFFFFF;
  --surface-2: #FAF8F3;
  --ink: #1D2421;
  --muted: #67706B;
  --line: #E4E0D5;
  --brand: #1F5C3D;
  --brand-ink: #FFFFFF;
  --brand-soft: #E3EEE6;
  --accent: #B8741F;
  --accent-soft: #F6E9D6;
  --good: #2C7A4F;
  --good-soft: #DFF0E5;
  --bad: #B23E2B;
  --bad-soft: #F7E0DA;
  --shadow: 0 1px 2px rgba(29, 36, 33, .06), 0 4px 16px rgba(29, 36, 33, .06);
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1B201D;
    --surface-2: #171B19;
    --ink: #E7ECE9;
    --muted: #9AA49E;
    --line: #2B322E;
    --brand: #6DBF8C;
    --brand-ink: #0F1A13;
    --brand-soft: #1E2D24;
    --accent: #E2A458;
    --accent-soft: #33281A;
    --good: #6DBF8C;
    --good-soft: #1E2D24;
    --bad: #EE8A78;
    --bad-soft: #3A221D;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.75;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

.lat { direction: ltr; unicode-bidi: isolate; font-feature-settings: "ss01"; }

/* ── top bar ─────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 800; letter-spacing: -.2px; }
.stats { display: flex; gap: 6px; font-size: 13px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 700; white-space: nowrap;
}
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 12px;
  font-size: 20px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:active { background: var(--brand-soft); }

/* ── main / layout ───────────────────────────────────── */
main {
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom));
  outline: none;
}
body.no-tabs main { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.note {
  border-radius: 12px; padding: 10px 14px; font-size: 14px;
  background: var(--accent-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.note.info { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 25%, transparent); }

/* ── buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 700; text-decoration: none; color: var(--ink);
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

/* ── home ────────────────────────────────────────────── */
.hero {
  background: var(--brand); color: var(--brand-ink);
  border-radius: 20px; padding: 18px; display: flex; gap: 14px; align-items: center;
}
.hero b { font-size: 28px; display: block; line-height: 1.2; }
.hero .btn { background: var(--brand-ink); color: var(--brand); border: 0; min-height: 44px; }
.units { display: grid; gap: 10px; }
.unit {
  display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.unit .emoji {
  width: 48px; height: 48px; border-radius: 14px; background: var(--brand-soft);
  display: grid; place-items: center; font-size: 24px; flex: none;
}
.unit h3 { margin: 0; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; width: 0; transition: width .3s ease; }
.done-mark { color: var(--good); font-weight: 800; font-size: 13px; }

/* ── word card ───────────────────────────────────────── */
.word {
  text-align: center; padding: 28px 18px 20px;
}
.word .big { font-size: 40px; font-weight: 800; line-height: 1.3; margin: 4px 0; }
.word .pron { font-size: 18px; color: var(--muted); }
.word .mean { font-size: 22px; font-weight: 700; margin-top: 14px; }
.chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.chip {
  font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.chip.warn { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.ok { background: var(--good-soft); color: var(--good); border-color: transparent; }
.dots { display: flex; gap: 5px; justify-content: center; margin: 14px 0 2px; flex-wrap: wrap; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--brand); width: 18px; border-radius: 99px; }

/* ── quiz ────────────────────────────────────────────── */
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.qhead .bar { flex: 1; margin: 0; height: 8px; }
.prompt { text-align: center; padding: 22px 16px; }
.prompt .ask { color: var(--muted); font-size: 14px; }
.prompt .big { font-size: 34px; font-weight: 800; margin-top: 6px; line-height: 1.35; }
.opts { display: grid; gap: 10px; margin-top: 14px; }
.opt {
  min-height: 56px; padding: 10px 16px; text-align: start; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.opt small { font-weight: 400; color: var(--muted); font-size: 13px; }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt[disabled] { cursor: default; }
.feedback { margin-top: 12px; font-weight: 700; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.score { font-size: 56px; font-weight: 800; line-height: 1.1; color: var(--brand); }

/* ── flashcard ───────────────────────────────────────── */
.flash { min-height: 260px; display: flex; flex-direction: column; justify-content: center; cursor: pointer; }
.flash .hint { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* ── dictionary ──────────────────────────────────────── */
.search {
  width: 100%; min-height: 50px; padding: 10px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
.search:focus, .field input:focus, .field select:focus, .composer textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.li {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-decoration: none; color: inherit;
  border-bottom: 1px solid var(--line);
}
.li:last-child { border-bottom: 0; }
.li .lat { font-weight: 800; font-size: 18px; min-width: 88px; text-align: left; }
.li .meta { flex: 1; min-width: 0; }
.li .meta div:first-child { font-weight: 700; }

/* ── forms ───────────────────────────────────────────── */
.field { display: block; }
.field > span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2);
}
.field input.ltr { direction: ltr; text-align: left; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; border: 1px solid var(--line); }
.seg label { text-align: center; padding: 8px 6px; border-radius: 10px; cursor: pointer; font-weight: 700; font-size: 14px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--surface); box-shadow: var(--shadow); color: var(--brand); }
details summary { cursor: pointer; font-weight: 700; font-size: 14px; color: var(--muted); }

/* ── AI chat ─────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; line-height: 1.8; word-wrap: break-word; }
.msg.user { align-self: flex-start; background: var(--brand); color: var(--brand-ink); border-end-start-radius: 4px; }
.msg.assistant { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-end-end-radius: 4px; }
.msg.error { align-self: stretch; max-width: none; background: var(--bad-soft); color: var(--bad); }
.msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0; padding-inline-start: 20px; }
.msg code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; direction: ltr; unicode-bidi: isolate; }
.typing { color: var(--muted); font-size: 14px; }
.composer {
  position: fixed; inset-inline: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 10px 16px;
}
.composer form { max-width: 560px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 140px; padding: 11px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
}
.composer .btn { min-height: 48px; padding: 10px 16px; }
.ai-page main, main.ai-page { padding-bottom: calc(var(--tabs-h) + 96px + env(safe-area-inset-bottom)); }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; }
.suggest button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }

/* ── bottom tabs ─────────────────────────────────────── */
.tabs {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 700; color: var(--muted); text-decoration: none;
}
.tabs a span { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs a.active { color: var(--brand); }
.tabs a.active span { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 6px; inset-inline-start: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
body.no-tabs .tabs { display: none; }

/* ── sheet + toast ───────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 85dvh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  animation: up .2s ease;
}
.sheet-head { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--surface); padding-top: 8px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 480px; margin: 0 auto; background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: 14px; text-align: center; font-weight: 700;
}
.noscript { padding: 24px; text-align: center; }

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

/* ══ v2: مسیر درس، تمرین‌های جمله، هدف روزانه ══════════════════════ */
.goal { display: flex; align-items: center; gap: 14px; }
.goal .ring {
  --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0);
}
.goal .ring b { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 13px; }
.unit-sec { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 14px; box-shadow: var(--shadow); }
.unit-sec.locked { opacity: .6; }
.unit-head { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.path { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.node {
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; font-weight: 800; font-size: 18px;
  background: var(--line); color: var(--muted); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12);
}
.node.done { background: var(--brand); color: var(--brand-ink); }
.node.current { background: var(--accent); color: #fff; animation: pulse 1.6s ease-in-out infinite; }
.node.locked { cursor: not-allowed; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent), inset 0 -4px 0 rgba(0,0,0,.12); } 50% { box-shadow: 0 0 0 8px transparent, inset 0 -4px 0 rgba(0,0,0,.12); } }

/* lesson runner */
.lesson-top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.lesson-top .bar { flex: 1; height: 12px; margin: 0; }
.lesson-top .bar > i { background: var(--good); }
.ex-title { font-size: 20px; font-weight: 800; margin: 0 0 14px; }
.tag-new { display: inline-block; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 12px; padding: 2px 10px; border-radius: 99px; }
.src { display: flex; gap: 10px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); margin-bottom: 14px; }
.src .big { font-size: 26px; font-weight: 800; }
.answer-area { min-height: 64px; border-bottom: 2px solid var(--line); border-top: 2px solid var(--line); padding: 8px 0; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.answer-area.ltr, .bank.ltr { direction: ltr; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.tile {
  min-height: 46px; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  font-weight: 700; font-size: 17px; cursor: pointer; box-shadow: inset 0 -3px 0 var(--line);
}
.tile.used { visibility: hidden; }
.blank-line { font-size: 26px; font-weight: 800; text-align: center; padding: 18px 8px; }
.blank-line .gap { display: inline-block; min-width: 72px; border-bottom: 3px solid var(--accent); margin: 0 6px; }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match-grid .col { display: grid; gap: 10px; align-content: start; }
.mbtn { min-height: 54px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; font-size: 16px; cursor: pointer; padding: 6px; }
.mbtn.sel { border-color: var(--brand); background: var(--brand-soft); }
.mbtn.ok { border-color: var(--good); background: var(--good-soft); opacity: .45; pointer-events: none; }
.mbtn.no { border-color: var(--bad); background: var(--bad-soft); }
.type-in { width: 100%; min-height: 96px; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-size: 18px; resize: none; }
.type-in:focus { outline: none; border-color: var(--brand); }
.check-wrap { position: fixed; inset-inline: 0; bottom: 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); z-index: 7; }
.check-wrap > div { max-width: 560px; margin: 0 auto; }
.fbar { position: fixed; inset-inline: 0; bottom: 0; z-index: 8; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease; }
.fbar > div { max-width: 560px; margin: 0 auto; }
.fbar.good { background: var(--good-soft); color: var(--good); }
.fbar.bad { background: var(--bad-soft); color: var(--bad); }
.fbar h3 { font-size: 18px; margin: 0 0 4px; }
.fbar p { color: var(--ink); margin: 0 0 12px; }
.fbar.good .btn.primary { background: var(--good); border-color: var(--good); color: var(--surface); }
.fbar.bad .btn.primary { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.fbar .btn:not(.primary) { background: var(--surface); color: var(--ink); }
body.lesson main { padding-bottom: 180px; }
.strength { display: inline-flex; gap: 3px; vertical-align: middle; }
.strength i { width: 6px; height: 14px; border-radius: 2px; background: var(--line); }
.strength i.on { background: var(--brand); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.result-stats .card { padding: 12px; text-align: center; }
.result-stats b { display: block; font-size: 22px; color: var(--brand); }
.tip-body h3 { margin-top: 10px; }

/* ══ v3: تالشی با خط فارسی ═══════════════════════════════════════════ */
.tal { font-weight: 800; }
.li .tal { font-size: 19px; min-width: 92px; }
.li .meta .lat { font-size: 13px; font-weight: 400; min-width: 0; text-align: inherit; }
.lat-hint { direction: ltr; unicode-bidi: isolate; color: var(--muted); font-size: 15px; margin-top: 2px; }
.src .lat-hint { font-size: 14px; margin: 0; }
.word .big .tal, .src .big .tal { font-weight: 800; }
.mbtn.tal, .opt.tal, .tile.tal { font-size: 19px; }
.learn-li { cursor: default; }
.learn-li .icon-btn { font-size: 18px; flex: none; }
