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

/* ---------- Tokens ---------- */
:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f0f2f9;
  --text: #1a1f36;
  --muted: #646b86;
  --line: #e3e6f1;
  --primary: #4a43e0;
  --primary-hover: #3c36c4;
  --primary-soft: #eceeff;
  --on-primary: #ffffff;
  --success: #0f7a55;
  --success-soft: #e3f5ec;
  --warn: #a35a00;
  --warn-soft: #fff2dc;
  --danger: #bf2a31;
  --danger-soft: #fdeaea;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(22, 27, 58, .05), 0 10px 28px rgba(22, 27, 58, .07);
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e111f;
    --surface: #171b2f;
    --surface-2: #1f2440;
    --text: #e9ebf6;
    --muted: #a0a7c2;
    --line: #2b3153;
    --primary: #8f91ff;
    --primary-hover: #a7a9ff;
    --primary-soft: #252a52;
    --on-primary: #0f1128;
    --success: #4fd6a1;
    --success-soft: #153a30;
    --warn: #f2b45a;
    --warn-soft: #3b2d12;
    --danger: #ff8a8f;
    --danger-soft: #401a1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.85;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body > main { flex: 1; }
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.5; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.container.narrow { max-width: 760px; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.topbar {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .container { display: flex; align-items: center; gap: 1.25rem; min-height: 64px; }
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 800; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #5b54f0, #8a5cf6); color: #fff;
}
.nav { display: flex; gap: .25rem; margin-inline-start: .5rem; }
.nav a { padding: .35rem .85rem; border-radius: 999px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.userbox { margin-inline-start: auto; display: flex; align-items: center; gap: .75rem; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}
.userinfo { line-height: 1.35; max-width: 180px; }
.userinfo b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.userinfo span { font-size: .75rem; color: var(--muted); }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.link-button:hover { color: var(--danger); }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1.2rem; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-lg { padding: .85rem 1.6rem; font-size: 1.05rem; border-radius: 13px; }
.btn-sm { padding: .3rem .8rem; font-size: .85rem; border-radius: 9px; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }
.btn-google { background: #fff; color: #1f1f1f; border-color: #d4d7e2; }
.btn-google:hover { background: #f6f7fb; }

label { font-weight: 600; font-size: .92rem; }
input[type=text], input[type=email], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .55rem .8rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input[type=checkbox] { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); margin: 0; flex: none; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; cursor: pointer; }
.inline-form { display: inline; margin: 0; }

/* ---------- Cards, chips, alerts ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.card.flat { box-shadow: none; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .1rem .7rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.chip.primary { background: var(--primary-soft); color: var(--primary); }
.chip.success { background: var(--success-soft); color: var(--success); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.alert { padding: .8rem 1.1rem; border-radius: var(--radius-sm); margin: 1rem 0 0; border: 1px solid; font-weight: 500; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert-info, .alert-warning { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.alert-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* ---------- Rendered markdown ---------- */
.prose { overflow-wrap: anywhere; }
.prose > :last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-inline-start: 1.4rem; margin: 0 0 1em; }
.prose ol { list-style-type: persian; }
.prose li { margin: .2rem 0; }
.prose blockquote {
  margin: 1em 0; padding: .8rem 1.1rem; background: var(--surface-2);
  border-inline-start: 4px solid var(--primary); border-radius: 8px; color: var(--text);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: .93rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: .45rem .75rem; text-align: start; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.prose h2, .prose h3, .prose h4 { margin-top: 1.4em; }
.prose code { background: var(--surface-2); padding: .05rem .35rem; border-radius: 5px; font-size: .9em; }
.prose em { color: var(--muted); }

/* ---------- Landing / login ---------- */
.hero { padding: 4.5rem 0 3rem; text-align: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; letter-spacing: -.01em; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 40rem; margin: 0 auto 2rem; }
.hero-glow {
  background:
    radial-gradient(60% 50% at 80% 0%, color-mix(in srgb, #7c6cff 22%, transparent), transparent 70%),
    radial-gradient(50% 40% at 10% 10%, color-mix(in srgb, #3ec1d3 16%, transparent), transparent 70%);
}
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin: 2rem 0; }
.fact { text-align: center; padding: 1.3rem 1rem; }
.fact b { display: block; font-size: 1.9rem; color: var(--primary); line-height: 1.3; }
.fact span { color: var(--muted); font-size: .92rem; }
.login-card { max-width: 440px; margin: 4rem auto; text-align: center; }
.login-card .brand-mark { margin: 0 auto 1rem; width: 52px; height: 52px; border-radius: 15px; }

/* ---------- Dashboard ---------- */
.page { padding: 2.2rem 0 3rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head h1 { margin-bottom: .25rem; }
.status-card { display: grid; grid-template-columns: auto 1fr auto; gap: 1.2rem; align-items: center; }
.status-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.status-icon.success { background: var(--success-soft); color: var(--success); }
.status-icon.warn { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 640px) { .status-card { grid-template-columns: auto 1fr; } .status-card .btn { grid-column: 1 / -1; } }

/* ---------- Exam ---------- */
.exam-bar {
  position: sticky; top: 64px; z-index: 15; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.exam-bar .container { display: flex; align-items: center; gap: 1.2rem; min-height: 58px; }
.progress { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #5b54f0, #8a5cf6); border-radius: 99px; transition: width .3s; }
.timer {
  display: inline-flex; align-items: center; gap: .5rem; padding: .25rem .9rem; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums;
  direction: ltr; min-width: 6.5rem; justify-content: center;
}
.timer.warn { background: var(--warn-soft); color: var(--warn); }
.timer.danger { background: var(--danger-soft); color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.exam-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.5rem; align-items: start; padding: 1.5rem 0 3rem; }
.qnav { position: sticky; top: 140px; display: flex; flex-direction: column; gap: .35rem; padding: .6rem; }
.qnav a {
  display: flex; align-items: center; gap: .65rem; padding: .55rem .7rem; border-radius: 10px;
  color: var(--text); font-weight: 500; font-size: .95rem;
}
.qnav a:hover { background: var(--surface-2); text-decoration: none; }
.qnav a.current { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.qnum {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  border: 2px solid var(--line); font-size: .8rem; font-weight: 700; color: var(--muted);
}
.qnav a.done .qnum { background: var(--success); border-color: var(--success); color: var(--surface); }
.qnav a.current .qnum { border-color: var(--primary); color: var(--primary); }
.qnav a.current.done .qnum { color: var(--surface); background: var(--primary); }
.qnav .submit-link { margin-top: .4rem; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; padding-top: .8rem; color: var(--primary); font-weight: 700; }
.question-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.question-head h2 { margin: 0; flex: 1 1 auto; font-size: 1.45rem; }
.answer-box { margin-top: 1.5rem; }
.answer-box textarea { min-height: 260px; resize: vertical; line-height: 2; font-size: 1.02rem; padding: 1rem 1.1rem; border-radius: 12px; overflow: hidden; }
.answer-meta { display: flex; justify-content: space-between; gap: 1rem; margin-top: .5rem; font-size: .88rem; color: var(--muted); }
.words.over { color: var(--warn); font-weight: 700; }
.save-status { display: inline-flex; align-items: center; gap: .35rem; }
.save-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.save-status[data-state=saving]::before { background: var(--warn); }
.save-status[data-state=error]::before { background: var(--danger); }
.save-status[data-state=error] { color: var(--danger); font-weight: 600; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; }
@media (max-width: 860px) {
  .exam-grid { grid-template-columns: 1fr; }
  .qnav { position: static; flex-direction: row; overflow-x: auto; padding: .4rem; }
  .qnav a { padding: .4rem .55rem; }
  .qnav a .qtitle { display: none; }
  .qnav .submit-link { margin: 0; border: 0; white-space: nowrap; }
  .exam-bar .container { gap: .7rem; }
  .exam-bar .progress { display: none; }
}

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.6rem; max-width: 440px; width: calc(100% - 2rem); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 12, 28, .55); backdrop-filter: blur(2px); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.data th, table.data td { padding: .65rem .85rem; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data thead th { background: var(--surface-2); font-size: .82rem; color: var(--muted); font-weight: 700; position: sticky; top: 0; white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
table.data td.c, table.data th.c { text-align: center; }
.cell-score {
  --v: 0; display: inline-grid; place-items: center; min-width: 2.7rem; padding: .1rem .5rem; border-radius: 8px;
  font-weight: 700; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--success) calc(var(--v) * 1%), var(--surface-2));
  color: var(--text);
}
.cell-score.empty { background: transparent; color: var(--muted); font-weight: 400; }
.core-col { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.identity { display: flex; align-items: center; gap: .7rem; }
.identity .avatar { width: 34px; height: 34px; font-size: .8rem; }
.code { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; direction: ltr; letter-spacing: .06em; font-weight: 700; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.tabs a { padding: .3rem .9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.stats { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ---------- Review cards ---------- */
.answer-card { padding: 0; overflow: hidden; }
.answer-card header { display: flex; align-items: center; gap: .8rem; padding: .9rem 1.2rem; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.answer-text { padding: 1.2rem 1.4rem; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 2; min-height: 4.5rem; }
.answer-text.blank { color: var(--muted); font-style: italic; }
.answer-card footer { padding: .9rem 1.2rem; border-top: 1px solid var(--line); display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.score-form { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; flex: 1; }
.score-input { width: 5.2rem !important; text-align: center; font-weight: 800; font-size: 1.1rem; direction: ltr; padding: .4rem .5rem; }
.chips { display: flex; gap: .25rem; flex-wrap: wrap; }
.chips button { min-width: 2.1rem; padding: .15rem .4rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.chips button:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.chips button.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.note-input { flex: 1 1 260px; min-height: 2.6rem; resize: vertical; font-size: .93rem; }
.others { width: 100%; font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .4rem; }
.rubric { border: 1px dashed color-mix(in srgb, var(--primary) 45%, var(--line)); background: color-mix(in srgb, var(--primary-soft) 40%, var(--surface)); border-radius: var(--radius); padding: .2rem 1.2rem; }
.rubric summary { cursor: pointer; font-weight: 700; padding: .7rem 0; color: var(--primary); }
.rubric[open] summary { border-bottom: 1px solid var(--line); margin-bottom: .8rem; }
.sticky-side { position: sticky; top: 84px; }
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.2rem; }
.flag { display: inline-flex; gap: .3rem; align-items: center; }

/* ---------- Manage ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.2rem; }
.form-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.form-row > .field { flex: 1 1 180px; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.toggle-state { display: flex; align-items: center; gap: .8rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }

@media (max-width: 640px) {
  .topbar .container { gap: .6rem; min-height: 56px; }
  .brand-text, .userinfo { display: none; }
  .nav { margin-inline-start: 0; }
  .container { padding: 0 14px; }
  .exam-bar { top: 56px; }
  .page { padding-top: 1.4rem; }
  .card { padding: 1.1rem; }
}
footer.site { text-align: center; color: var(--muted); font-size: .82rem; padding: 1.5rem 0 2rem; }
@media print { .topbar, .exam-bar, .qnav, .pager, footer.site { display: none; } }
