:root {
  --bg: #f4f6f4; --card: #fff; --ink: #1d2b24; --muted: #5f6f67; --line: #dfe5e1;
  --brand: #0f6b4f; --brand-ink: #fff; --brand-soft: #e3f2ec;
  --ok: #1a8a4a; --ok-soft: #dcf3e4; --bad: #c0392b; --bad-soft: #fbe4e0; --warn: #b9770e; --warn-soft: #fdf0d5;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14201b; --card: #1c2b25; --ink: #e8f0ec; --muted: #9db0a7; --line: #2f4239;
    --brand: #3fb98a; --brand-ink: #08241a; --brand-soft: #1f3a2f;
    --ok: #55d08a; --ok-soft: #1c3b2a; --bad: #ff8574; --bad-soft: #402420; --warn: #f0b95a; --warn-soft: #3b2f17;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.7; font-size: 17px;
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", system-ui, sans-serif;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 16px; }
.wrap.wide { max-width: 1100px; }
h1 { font-size: 1.5rem; margin: .4em 0; }
h2 { font-size: 1.2rem; margin: 1.4em 0 .5em; }
h3 { font-size: 1.05rem; margin: 0 0 .4em; }
.muted { color: var(--muted); font-size: .9em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: 1.1em; height: 1.1em; accent-color: var(--brand); }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block;
  padding: 9px 16px; border-radius: 10px; border: 1.5px solid var(--brand);
  background: var(--brand); color: var(--brand-ink);
}
button.ghost, .btn.ghost { background: transparent; color: var(--brand); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.small { padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.big { padding: 14px 22px; font-size: 1.1rem; width: 100%; }

.err { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-weight: 600; }
.note { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; margin: 10px 0; }
.badge { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .8rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.badge.off { background: var(--line); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- math ---------- */
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.15; margin: 0 .2em; direction: ltr; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 .25em; }
sup { font-size: .7em; line-height: 0; }

/* ---------- student ---------- */
.hero { text-align: center; padding: 18px 0 4px; }
.hero .logo { font-size: 2.4rem; }
.exam-link { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.progress { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 8px; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); transition: width .2s; }
.q { padding: 14px 16px; }
.q-head { display: flex; gap: 12px; align-items: flex-start; }
.q-num { flex: none; min-width: 2.2em; height: 2.2em; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 800; }
.q-text { font-size: 1.15rem; font-weight: 600; flex: 1; }
.q img { max-width: 100%; border-radius: 8px; margin-top: 10px; border: 1px solid var(--line); }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
@media (max-width: 560px) { .opts { grid-template-columns: 1fr; } }
.opt {
  display: flex; gap: 10px; align-items: center; text-align: right; width: 100%;
  background: var(--card); color: var(--ink); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 1.1rem;
}
.opt .l { flex: none; width: 2em; height: 2em; display: grid; place-items: center; border-radius: 50%; background: var(--line); font-weight: 800; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .l { background: var(--brand); color: var(--brand-ink); }
.done { text-align: center; padding: 30px 10px; }
.done .tick { font-size: 3.5rem; }

/* ---------- teacher ---------- */
.nav { background: var(--card); border-bottom: 1px solid var(--line); }
.nav .wrap { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.nav .brand { font-weight: 800; color: var(--brand); margin-inline-end: 10px; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); font-weight: 700; background: var(--bg); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.2; }
.dist { display: grid; grid-template-columns: 2.2em 1fr 7em; gap: 8px; align-items: center; margin: 3px 0; font-size: .95rem; }
.dist .track { height: 18px; background: var(--line); border-radius: 6px; overflow: hidden; }
.dist .track > i { display: block; height: 100%; background: #8aa59a; }
.dist.right .track > i { background: var(--ok); }
.dist.top-wrong .track > i { background: var(--bad); }
.dist.right { font-weight: 700; color: var(--ok); }
.optx { font-size: .9rem; margin-bottom: 2px; }
.chips { display: flex; gap: 3px; flex-wrap: wrap; }
.chip { min-width: 1.9em; text-align: center; padding: 0 4px; border-radius: 6px; font-size: .85rem; font-weight: 700; background: var(--line); color: var(--muted); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.no { background: var(--bad-soft); color: var(--bad); }
.pct { font-weight: 800; }
.pct.hi { color: var(--ok); } .pct.mid { color: var(--warn); } .pct.lo { color: var(--bad); }
.qcard h3 { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.edit-q { border: 2px solid var(--line); }
.edit-opt { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.edit-opt .l { flex: none; width: 1.8em; font-weight: 800; text-align: center; }
.preview { background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; margin-top: 8px; min-height: 2.4em; }
.checks label { display: inline-flex; gap: 6px; align-items: center; margin: 4px 14px 4px 0; font-weight: 500; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 50; font-weight: 600; }
code, .mono { direction: ltr; unicode-bidi: isolate; font-family: Consolas, monospace; background: var(--bg); padding: 1px 6px; border-radius: 6px; }
code { display: inline-block; }
a { color: var(--brand); }

@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .nav, .no-print, button, .toast { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .card, .stat, .tablewrap { border-color: #bbb; break-inside: avoid; }
}
