:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #17202b;
  --muted: #5c6878;
  --line: #dde2e9;
  --accent: #0f6b5c;
  --accent-soft: #e2f2ee;
  --accent-text: #ffffff;
  --good: #1d7a3a;
  --good-soft: #e3f4e8;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-ur: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Urdu Typesetting", serif;
  --font-ar: "Amiri", "Traditional Arabic", "Scheherazade New", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161c; --surface: #19212a; --surface-2: #222c37; --text: #e7ecf2; --muted: #9aa7b6;
    --line: #2d3946; --accent: #3fb59d; --accent-soft: #173a34; --accent-text: #08201b;
    --good: #5cc883; --good-soft: #163824; --bad: #ff8a80; --bad-soft: #3d1c1a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161c; --surface: #19212a; --surface-2: #222c37; --text: #e7ecf2; --muted: #9aa7b6;
  --line: #2d3946; --accent: #3fb59d; --accent-soft: #173a34; --accent-text: #08201b;
  --good: #5cc883; --good-soft: #163824; --bad: #ff8a80; --bad-soft: #3d1c1a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
button, input, select { font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.brand h1 { font-size: 18px; margin: 0; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; max-width: 1280px; margin: 0 auto; padding: 20px; }
.filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; align-self: start; position: sticky; top: 88px; max-height: calc(100vh - 108px); overflow: auto; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
select, input[type=search] { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 13px; }
.chip small { color: var(--muted); margin-inline-start: 4px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.on small { color: inherit; opacity: .8; }
.chip .native { font-family: var(--font-ur); font-size: 12px; line-height: 1.6; unicode-bidi: isolate; margin-inline-start: 2px; }

.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--surface); padding: 7px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.toggles label { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.actions { display: grid; gap: 8px; }
.actions button, .ghost { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); padding: 9px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.actions button.ghost, button.ghost { background: transparent; color: var(--accent); }
#themeBtn { width: 40px; height: 40px; padding: 0; font-size: 18px; }

.result-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--muted); }
.score { background: var(--accent-soft); color: var(--accent); padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.q { min-width: 0; overflow-wrap: anywhere; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.q-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; direction: ltr; }
.badge { padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-weight: 600; }
.badge.MCQ { background: #e6eefc; color: #2449a3; }
.badge.SHORT { background: #fdf0dc; color: #8a5300; }
.badge.LONG { background: #f1e6fb; color: #6b2fa0; }
:root[data-theme="dark"] .badge.MCQ, :root[data-theme="dark"] .badge.SHORT, :root[data-theme="dark"] .badge.LONG { background: var(--surface-2); color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.MCQ, :root:not([data-theme="light"]) .badge.SHORT, :root:not([data-theme="light"]) .badge.LONG { background: var(--surface-2); color: var(--text); } }
.marks { margin-inline-start: auto; }
.q-text { font-weight: 600; margin: 0 0 10px; white-space: pre-line; }
.opts { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opt { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; display: flex; gap: 8px; align-items: baseline; }
.opt b { color: var(--muted); }
.practice .opt { cursor: pointer; }
.practice .opt:hover { border-color: var(--accent); }
.opt.right { background: var(--good-soft); border-color: var(--good); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.reveal { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; font-size: 13px; }
.ans { margin-top: 8px; padding: 10px 12px; background: var(--accent-soft); border-radius: 8px; white-space: pre-wrap; }
.ans::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; font-family: var(--font); direction: ltr; text-align: start; }

/* Right-to-left subjects */
.q[dir="rtl"] { text-align: right; }
.q[lang="ur"] .q-text, .q[lang="ur"] .opt, .q[lang="ur"] .ans { font-family: var(--font-ur); line-height: 2.3; font-size: 16px; font-weight: 400; }
.q[lang="ur"] .q-text { font-weight: 600; }
.q[lang="ar"] .q-text, .q[lang="ar"] .opt, .q[lang="ar"] .ans { font-family: var(--font-ar); line-height: 2; font-size: 19px; }
.ans code, .q-text code { font-family: Consolas, monospace; }
.ans.code { font-family: Consolas, "Courier New", monospace; font-size: 13.5px; direction: ltr; text-align: left; }

.empty { color: var(--muted); text-align: center; padding: 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.print-only { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .filters { position: static; max-height: none; }
  .opts { grid-template-columns: 1fr; }
  .top { padding: 12px 16px; }
}

@media print {
  .no-print { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .layout { display: block; padding: 0; }
  .q { border: 0; border-bottom: 1px solid #ccc; border-radius: 0; padding: 8px 0; break-inside: avoid; }
  .badge, .reveal { display: none; }
  .ans { background: none; border-left: 3px solid #999; }
  .paper-head h2 { margin: 0 0 4px; }
  body:not(.with-key) .ans { display: none !important; }
}
