@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;
}

:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #1c2624;
  --muted: #5d6b68;
  --line: #dde4e1;
  --primary: #0f5c5a;
  --primary-ink: #ffffff;
  --primary-soft: #dcefeb;
  --accent: #b5651d;
  --mark: #fff0b3;
  --danger: #b3261e;
  --ok: #1b7a43;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 36, .06), 0 4px 16px rgba(16, 40, 36, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101615;
    --surface: #18201f;
    --surface-2: #1f2a28;
    --text: #e6eeec;
    --muted: #9aaba7;
    --line: #2c3a37;
    --primary: #5cc2b6;
    --primary-ink: #06201d;
    --primary-soft: #1d3a36;
    --accent: #e3a35f;
    --mark: #5a4a12;
    --danger: #f2827a;
    --ok: #6fd39a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.85;
  font-size: 16px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; }
.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px max(16px, calc((100vw - 1040px) / 2));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.brand span { display: flex; flex-direction: column; line-height: 1.4; min-width: 0; }
.brand strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.nav a.active, .nav a:hover { color: var(--primary); background: var(--primary-soft); }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 5;
  display: none; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); text-decoration: none; padding: 2px 10px; min-width: 64px; }
.tabbar svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

@media (max-width: 720px) {
  .nav { display: none; }
  .tabbar { display: flex; }
}
@media (min-width: 721px) {
  body { padding-bottom: 0; }
}

main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 16px 24px; }

/* ---------- common ---------- */
h1, h2, h3 { line-height: 1.5; margin: 0 0 .4em; }
h1 { font-size: clamp(22px, 4.5vw, 30px); }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section { margin-top: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; font-size: 14.5px;
  min-height: 40px;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 12px; font-size: 13px; text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.tag { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 1px 8px; }
.badge { font-size: 12px; border-radius: 6px; padding: 1px 8px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.badge.warn { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

input[type=search], input[type=text], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 10px 14px; font-size: 16px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { min-height: 110px; resize: vertical; line-height: 1.8; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }

/* ---------- hero / search ---------- */
.hero { text-align: center; padding: 18px 0 6px; }
.hero p { color: var(--muted); max-width: 640px; margin: 0 auto 18px; }
.searchbox {
  display: flex; gap: 8px; max-width: 720px; margin: 0 auto; flex-wrap: wrap;
}
.searchbox input { flex: 1 1 260px; font-size: 17px; padding: 12px 16px; border-radius: 14px; }
.searchbox .btn { min-height: 50px; padding: 0 18px; border-radius: 14px; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }

.cat-card { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; }
.cat-card:hover { border-color: var(--primary); }
.cat-card .count { color: var(--primary); font-weight: 700; }

/* ---------- results ---------- */
.result { position: relative; }
.result .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.result .src { font-weight: 700; color: var(--text); text-decoration: none; }
.result .src:hover { color: var(--primary); }
.result blockquote { margin: 6px 0 10px; padding: 0 12px; border-inline-start: 3px solid var(--primary-soft); white-space: pre-line; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

.source-card { display: flex; flex-direction: column; gap: 6px; }
.source-card h3 a { color: var(--text); text-decoration: none; }
.source-card h3 a:hover { color: var(--primary); }
.source-card .summary { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.source-card .actions { margin-top: auto; padding-top: 6px; }

/* ---------- AI answer ---------- */
.answer { font-size: 16.5px; }
.answer p { margin: 0 0 .8em; }
.answer ul, .answer ol { margin: 0 0 .8em; padding-inline-start: 1.4em; }
.cite {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px; margin: 0 2px;
  border-radius: 6px; background: var(--primary-soft); color: var(--primary);
  font-size: 12px; font-weight: 700; text-decoration: none; vertical-align: 2px;
}
.cite:hover { background: var(--primary); color: var(--primary-ink); }
.typing::after { content: '▍'; animation: blink 1s steps(2) infinite; color: var(--primary); }
@keyframes blink { 50% { opacity: 0; } }
.notice { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; font-size: 14px; color: var(--muted); }
.citations li { margin-bottom: 10px; }
.citations { padding-inline-start: 1.2em; }

/* ---------- quiz ---------- */
.option {
  display: block; width: 100%; text-align: start; margin-top: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.option.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); transition: width .3s; }

/* ---------- questions board ---------- */
.qa .answer-box { margin-top: 10px; background: var(--primary-soft); border-radius: 10px; padding: 10px 14px; }
.qa .answer-box strong { color: var(--primary); }

.stars { display: flex; gap: 4px; direction: ltr; justify-content: flex-end; }
.stars button { background: none; border: none; font-size: 28px; cursor: pointer; color: var(--line); padding: 0 2px; }
.stars button.on { color: #e0a800; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-size: 14px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0; font-size: 14px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* admin */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.toast { position: fixed; bottom: 90px; inset-inline: 0; margin: auto; width: fit-content; max-width: 90vw; background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 10px; z-index: 20; }
[hidden] { display: none !important; }

/* admin */
.admin-nav { display: flex; overflow-x: auto; }
@media (max-width: 720px) { .topbar:has(.admin-nav) { flex-wrap: wrap; } .admin-nav { width: 100%; } }
details > summary { cursor: pointer; }
.trl h3 { margin-top: 18px; color: var(--primary); }
@media print {
  .topbar, .tabbar, .footer, .no-print, .toast { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .trl h3 { break-after: avoid; }
}
.hero-course { color: var(--primary) !important; font-weight: 600; margin-bottom: 6px !important; }
@media (max-width: 720px) {
  .src-url, .col-cat { display: none; }
}
