@font-face{font-family:"Vazirmatn FD";font-style:normal;font-weight:400;font-display:swap;src:url(/static/fonts/Vazirmatn-FD-Regular.35740bc0.woff2) format("woff2")}
@font-face{font-family:"Vazirmatn FD";font-style:normal;font-weight:500;font-display:swap;src:url(/static/fonts/Vazirmatn-FD-Medium.cfecf151.woff2) format("woff2")}
@font-face{font-family:"Vazirmatn FD";font-style:normal;font-weight:700;font-display:swap;src:url(/static/fonts/Vazirmatn-FD-Bold.59df46af.woff2) format("woff2")}
@font-face{font-family:"Vazirmatn";font-style:normal;font-weight:400;font-display:swap;src:url(/static/fonts/Vazirmatn-Regular.e3821013.woff2) format("woff2")}
@font-face{font-family:"Vazirmatn";font-style:normal;font-weight:700;font-display:swap;src:url(/static/fonts/Vazirmatn-Bold.836fae7d.woff2) format("woff2")}
/* ---------- tokens ---------- */
:root {
  --brand: #d4a409;
  --brand-ink: #8a6a05;
  --olive: #7e6c1f;
  --grey: #c3c6ca;
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ed;
  --text: #1c1b19;
  --muted: #6b6862;
  --border: #e6e2db;
  --shadow: 0 1px 2px rgb(28 27 25 / 6%), 0 4px 16px rgb(28 27 25 / 4%);
  --warn: #b4522e;
  --good: #3f7d58;
  --dot-s: 45%;
  --dot-l: 45%;
  --radius: 10px;
  --sidebar-w: 300px;
  --topbar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --brand: #e8bc3a;
    --brand-ink: #e8bc3a;
    --olive: #b8a44e;
    --grey: #4a4f57;
    --bg: #15171a;
    --surface: #1d2025;
    --surface-2: #23272e;
    --text: #e9e7e2;
    --muted: #9a978f;
    --border: #2c313a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 20%);
    --warn: #e08a63;
    --good: #6fb98c;
    --dot-s: 40%;
    --dot-l: 58%;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --brand: #e8bc3a;
  --brand-ink: #e8bc3a;
  --olive: #b8a44e;
  --grey: #4a4f57;
  --bg: #15171a;
  --surface: #1d2025;
  --surface-2: #23272e;
  --text: #e9e7e2;
  --muted: #9a978f;
  --border: #2c313a;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 20%);
  --warn: #e08a63;
  --good: #6fb98c;
  --dot-s: 40%;
  --dot-l: 58%;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn FD', Vazirmatn, Tahoma, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.95;
  letter-spacing: 0; /* letter-spacing breaks Arabic-script joining */
  -webkit-text-size-adjust: 100%;
}
img { max-width: 100%; height: auto; }
a { color: var(--brand-ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* Latin terms keep Latin digits and disable the Farsi-Digits substitution. */
.en, code, kbd, samp, .math {
  font-family: Vazirmatn, system-ui, sans-serif;
  direction: ltr;
  unicode-bidi: isolate;
}
code, kbd, samp { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
code {
  background: var(--surface-2);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.skip {
  position: absolute; inset-inline-start: -9999px; top: 8px; z-index: 100;
  background: var(--surface); padding: 8px 16px; border-radius: var(--radius);
}
.skip:focus { inset-inline-start: 16px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand img { border-radius: 8px; }
.search { position: relative; margin-inline-start: auto; flex: 1 1 340px; max-width: 380px; }
.search input {
  width: 100%; height: 38px; padding: 0 14px;
  font: inherit; font-size: 0.95rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.search input::placeholder { color: var(--muted); }
.search-results {
  position: absolute; inset-inline: 0; top: calc(100% + 8px);
  max-height: 60vh; overflow-y: auto; z-index: 50;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
}
.search-results a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); text-decoration: none; }
.search-results a:hover, .search-results a.is-active { background: var(--surface-2); }
.search-results b { display: block; font-size: 0.95rem; }
.search-results span { display: block; font-size: 0.8rem; color: var(--muted); }
.search-empty { padding: 12px; color: var(--muted); font-size: 0.9rem; }

.theme-toggle, .hamburger {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; cursor: pointer; color: var(--text);
}
.theme-toggle::before { content: '☾'; font-size: 1.1rem; }
:root[data-theme='dark'] .theme-toggle::before { content: '☀'; }
.hamburger { display: none; }
.hamburger span, .hamburger span::before, .hamburger span::after {
  display: block; width: 16px; height: 2px; background: currentColor; border-radius: 2px;
}
.hamburger span { position: relative; }
.hamburger span::before, .hamburger span::after { content: ''; position: absolute; }
.hamburger span::before { top: -5px; }
.hamburger span::after { top: 5px; }

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 32px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 24px 0 48px;
}
.sidebar-heading { margin: 0 0 12px; font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.nav-list, .nav-topics { list-style: none; margin: 0; padding: 0; }
.nav-chapter-link {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 0.92rem; font-weight: 500;
}
.nav-chapter-link:hover { background: var(--surface-2); }
.nav-chapter-link[aria-current] { background: var(--surface-2); font-weight: 700; }
.nav-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: hsl(var(--ch-hue, 45) var(--dot-s) var(--dot-l)); }
.nav-chapter-title { flex: 1; }
.nav-weight { font-size: 0.72rem; color: var(--muted); }
.nav-topics { margin: 2px 0 10px; padding-inline-start: 18px; border-inline-start: 2px solid var(--border); }
.nav-topics a {
  display: block; padding: 5px 10px; border-radius: 6px;
  color: var(--muted); text-decoration: none; font-size: 0.88rem;
}
.nav-topics a:hover { background: var(--surface-2); color: var(--text); }
.nav-topics a[aria-current] { color: var(--brand-ink); font-weight: 700; background: var(--surface-2); }
.nav-topics a.is-read::after, .topic-cards li.is-read b::after { content: ' ✓'; color: var(--brand); }

/* ---------- main ---------- */
.main { padding: 24px 0 64px; min-width: 0; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 16px; padding: 0; font-size: 0.83rem; color: var(--muted); }
.crumbs li + li::before { content: '›'; margin-inline-end: 6px; color: var(--grey); }
.crumbs a { color: var(--muted); }

.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head h1 { flex: 1; }
.prose { max-width: 74ch; }
.prose h1 { font-size: 2rem; line-height: 1.5; margin: 0 0 16px; }
.prose h2 { font-size: 1.4rem; line-height: 1.6; margin: 40px 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.prose h3 { font-size: 1.12rem; margin: 28px 0 8px; }
.prose p { margin: 0 0 16px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-inline-start: 24px; }
.prose li { margin-bottom: 6px; }
.prose .lead { font-size: 1.08rem; color: var(--muted); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }
blockquote { margin: 0 0 16px; padding: 4px 16px; border-inline-start: 3px solid var(--grey); color: var(--muted); }

.read-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; font: inherit; font-size: 0.85rem;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.read-mark { width: 16px; height: 16px; border: 2px solid var(--grey); border-radius: 50%; }
.read-toggle[aria-pressed='true'] { color: var(--brand-ink); border-color: var(--brand); }
.read-toggle[aria-pressed='true'] .read-mark { background: var(--brand); border-color: var(--brand); }

/* ---------- callouts ---------- */
.callout {
  margin: 0 0 20px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-inline-start: 4px solid var(--grey);
  border-radius: var(--radius);
}
.callout > :last-child { margin-bottom: 0; }
.callout-title { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 6px; color: var(--muted); }
.callout.def { border-inline-start-color: var(--brand); }
.callout.def .callout-title { color: var(--brand-ink); }
.callout.key { border-inline-start-color: var(--olive); background: var(--surface-2); }
.callout.key .callout-title { color: var(--olive); }
.callout.contrast { border-inline-start-color: var(--warn); }
.callout.contrast .callout-title { color: var(--warn); }
.callout.example { border-inline-start-color: var(--good); }
.callout.example .callout-title { color: var(--good); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 9px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- math ---------- */
/* Formulas are plain HTML from build/tex.py, laid out here — no KaTeX. */
.math {
  font-family: "Times New Roman", Times, serif;
  font-size: 1.15rem; line-height: 1.4;
  white-space: nowrap;
}
.math i { font-family: inherit; }
.math-display {
  display: block; text-align: center;
  margin: 0; padding: 16px 8px;
  overflow-x: auto; overflow-y: hidden;
}
.math-inline { font-size: 1.05em; }

.math .upr { font-style: normal; }
.math sub, .math sup { font-size: 0.72em; line-height: 0; }
.math .scripts {
  display: inline-flex; flex-direction: column;
  vertical-align: -0.35em; line-height: 1;
}
.math .scripts sup, .math .scripts sub { vertical-align: baseline; line-height: 1.1; }

.math .frac {
  display: inline-flex; flex-direction: column; align-items: center;
  vertical-align: -0.55em; margin: 0 0.15em; font-size: 0.95em;
}
.math .frac .num { padding: 0 0.35em 0.12em; }
.math .frac .den { padding: 0.12em 0.35em 0; border-top: 1px solid currentColor; }

.math .bigop {
  display: inline-flex; flex-direction: column; align-items: center;
  vertical-align: -0.5em; margin: 0 0.2em;
}
.math .bigop .op { font-size: 1.5em; line-height: 1; }
.math .bigop .lim { font-size: 0.6em; line-height: 1.2; }
.formula {
  margin: 0 0 20px; padding: 4px 0 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.formula figcaption { padding: 4px 16px 12px; font-size: 0.83rem; color: var(--muted); }
.formula figcaption > :last-child { margin-bottom: 0; }

/* ---------- glossary / vocab ---------- */
.vocab { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 4px; }
.vocab li { display: flex; gap: 10px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 0.92rem; }
.vocab .fa { font-weight: 500; }
.vocab .en { color: var(--muted); font-size: 0.88rem; }

/* ---------- cards ---------- */
.chapter-cards ul, .topic-cards ul, .related ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.chapter-cards ul { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.chapter-cards a, .topic-cards a {
  display: block; height: 100%; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; color: var(--text);
}
.chapter-cards a { border-top: 3px solid hsl(var(--ch-hue, 45) var(--dot-s) var(--dot-l)); }
.chapter-cards a:hover, .topic-cards a:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.chapter-cards b, .topic-cards b { display: block; margin-bottom: 4px; }
.chapter-cards span, .topic-cards span { display: block; font-size: 0.85rem; color: var(--muted); line-height: 1.7; }
.chapter-cards .weight {
  display: inline-block; margin-bottom: 6px; padding: 1px 8px;
  font-size: 0.72rem; color: var(--brand-ink);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.related ul { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.related a { display: block; padding: 10px 14px; background: var(--surface-2); border-radius: var(--radius); text-decoration: none; font-size: 0.9rem; }

.chapter-progress { font-size: 0.85rem; color: var(--muted); }

/* ---------- pager ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 74ch; margin-top: 48px; }
.pager a {
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; color: var(--text);
}
.pager a:hover { border-color: var(--brand); }
.pager span { display: block; font-size: 0.75rem; color: var(--muted); }
.pager b { font-size: 0.92rem; }
.pager-next { text-align: end; }

/* ---------- footer ---------- */
.footer { border-top: 1px solid var(--border); padding: 24px 16px 40px; text-align: center; color: var(--muted); font-size: 0.85rem; }
.footer p { margin: 0 0 4px; }
.footer-note { font-size: 0.78rem; }

/* ---------- responsive ---------- */
.backdrop { position: fixed; inset: 0; z-index: 45; background: rgb(0 0 0 / 40%); }
@media (max-width: 900px) {
  .hamburger { display: grid; }
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .sidebar {
    position: fixed; z-index: 46; top: 0; inset-inline-end: 0;
    width: min(320px, 86vw); height: 100vh;
    padding: 20px; background: var(--surface);
    border-inline-start: 1px solid var(--border);
    transform: translateX(100%); transition: transform 0.2s ease;
  }
  [dir='rtl'] .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: none !important; }
  .search { flex-basis: 120px; }
  .brand span { display: none; }
  .pager { grid-template-columns: 1fr; }
}
@media (min-width: 901px) { .backdrop { display: none !important; } }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .sidebar { transition: none; } }

/* ---------- print ---------- */
@media print {
  .topbar, .sidebar, .pager, .backdrop, .read-toggle, .footer-note, .crumbs { display: none !important; }
  .shell { display: block; max-width: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; line-height: 1.6; }
  .prose { max-width: none; }
  .callout, .table-wrap, .formula { break-inside: avoid; border: 1px solid #999; }
  .prose h2 { break-after: avoid; }
}
