:root {
  --teal:  #2a9d8f;
  --teal-d:#1f7d72;
  --gold:  #d99b1c;
  --grad:  linear-gradient(120deg, #2a9d8f, #4bbfa8);
  --bg:    #f5f4f2;
  --card:  #ffffff;
  --soft:  #efece6;
  --ink:   #24242c;
  --ink-soft:#6d6d78;
  --line:  #e2ddd4;
  --ok:    #1f8a5a;
  --ok-bg: #e6f5ec;
  --no:    #c0392b;
  --no-bg: #fbeae7;
  --radius:18px;
  --shadow:0 4px 16px rgba(40,30,20,.10);
  --shadow-lg:0 12px 34px rgba(40,30,20,.16);
}
:root[data-theme="dark"] {
  --bg:#14141b; --card:#1f1f2a; --soft:#262633; --ink:#eeeae2; --ink-soft:#a29fab; --line:#3a3a49;
  --gold:#ffd23e; --ok:#4cc38a; --ok-bg:#16342a; --no:#f0736a; --no-bg:#3a1f1e;
  --shadow:0 4px 16px rgba(0,0,0,.35); --shadow-lg:0 12px 34px rgba(0,0,0,.5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#14141b; --card:#1f1f2a; --soft:#262633; --ink:#eeeae2; --ink-soft:#a29fab; --line:#3a3a49;
    --gold:#ffd23e; --ok:#4cc38a; --ok-bg:#16342a; --no:#f0736a; --no-bg:#3a1f1e;
    --shadow:0 4px 16px rgba(0,0,0,.35); --shadow-lg:0 12px 34px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "Tajawal", sans-serif; background: var(--bg); color: var(--ink);
  min-height: 100vh; display: flex; flex-direction: column; line-height: 1.85;
}
b, strong { font-weight: 800; }
.muted { color: var(--ink-soft); font-weight: 500; }
.sm { font-size: .88rem; }
.q-txt, .aya { font-family: "Amiri", "Tajawal", serif; }

/* ── الرأس ── */
.top { background: var(--card); border-bottom: 2px solid var(--line); position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px clamp(12px, 3vw, 28px) 8px; max-width: 1180px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; background: var(--grad); color: #fff;
  display: grid; place-items: center; font: 800 1.5rem "Amiri", serif; flex: none;
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.25; }
.brand-txt b { font-size: 1.3rem; font-weight: 900; }
.brand-txt i { font-style: normal; font-size: .82rem; color: var(--ink-soft); font-weight: 600; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  font: 700 .85rem Tajawal, sans-serif; color: var(--ink); background: var(--soft);
  border: 2px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--teal); color: var(--teal); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 clamp(12px, 3vw, 28px) 10px; max-width: 1180px; margin: 0 auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  font: 800 .98rem Tajawal, sans-serif; color: var(--ink-soft); background: transparent;
  border: 2px solid transparent; border-radius: 999px; padding: 7px 18px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--ink); background: var(--soft); }
.tab.is-on { color: #fff; background: var(--grad); box-shadow: 0 3px 12px rgba(42,157,143,.35); }

/* ── التخطيط ── */
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px clamp(12px, 3vw, 28px) 50px; }
.view { display: none; }
.view.is-on { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.panel h2 { font-size: 1.35rem; font-weight: 900; margin-bottom: 6px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row label { font-weight: 700; font-size: .95rem; }
select, input[type="search"], input[type="text"] {
  font: 700 .98rem Tajawal, sans-serif; color: var(--ink); background: var(--bg);
  border: 2px solid var(--line); border-radius: 12px; padding: 9px 14px; min-height: 42px;
}
select:focus, input:focus { outline: none; border-color: var(--teal); }
.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--teal); }

.btn {
  font: 900 1rem Tajawal, sans-serif; border: none; border-radius: 999px; padding: 10px 26px; min-height: 44px;
  cursor: pointer; background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(42,157,143,.32);
  transition: transform .12s;
}
.btn:active { transform: scale(.97); }
.btn-lg { font-size: 1.1rem; padding: 13px 40px; margin-top: 14px; }
.btn-ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); box-shadow: none; }
.btn-ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn[disabled] { opacity: .5; cursor: default; }

/* ── الإحصاءات ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.7rem; font-weight: 900; color: var(--teal); line-height: 1.3; }
.stat span { font-size: .86rem; color: var(--ink-soft); font-weight: 700; }
.bar { height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--grad); border-radius: 999px; }

/* ── البحث ── */
.searchbar { margin-bottom: 14px; }
.searchbar input { width: 100%; }
.results { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 16px; max-height: 420px; overflow-y: auto; }
.res { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 10px; }
.res:last-child { border-bottom: none; }
.res:hover { background: var(--soft); }
.res b { color: var(--teal); font-size: .82rem; display: block; }
.mark { background: rgba(217,155,28,.28); border-radius: 4px; padding: 0 2px; }

/* ── قائمة الأبواب + المتن ── */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.chlist { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); position: sticky; top: 118px; max-height: calc(100vh - 140px); overflow-y: auto; }
@media (max-width: 860px) { .chlist { position: static; max-height: none; } }
.chitem { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: right; background: transparent; border: 2px solid transparent; border-radius: 12px; padding: 9px 11px; cursor: pointer; font: 700 .95rem Tajawal, sans-serif; color: var(--ink); }
.chitem:hover { background: var(--soft); }
.chitem.is-on { background: var(--soft); border-color: var(--teal); }
.chitem .n { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--soft); color: var(--ink-soft); display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.chitem.is-on .n, .chitem.done .n { background: var(--teal); color: #fff; }
.chitem.done .n::after { content: "✓"; }
.chitem.done .n span { display: none; }

.chbody { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: clamp(16px, 3vw, 30px); box-shadow: var(--shadow); }
.chbody h1 { font-size: clamp(1.4rem, 3.4vw, 1.95rem); font-weight: 900; line-height: 1.5; }
.chbody .lead { color: var(--ink-soft); font-weight: 600; margin: 4px 0 20px; border-bottom: 2px solid var(--line); padding-bottom: 14px; }
.sec { margin-bottom: 26px; }
.sec h3 { font-size: 1.14rem; font-weight: 900; color: var(--teal); margin-bottom: 8px; padding-right: 12px; border-right: 4px solid var(--teal); }
.sec p { margin-bottom: 6px; }
.note { background: var(--soft); border-right: 4px solid var(--gold); border-radius: 10px; padding: 10px 14px; margin-top: 10px; font-weight: 600; }
.note::before { content: "تنبيه — "; font-weight: 900; color: var(--gold); }
.exs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ex { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 5px 12px; font-family: "Amiri", serif; font-size: 1.08rem; }

.tblwrap { overflow-x: auto; margin-top: 10px; border: 2px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 460px; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); font-size: .94rem; vertical-align: top; }
th { background: var(--soft); font-weight: 900; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--soft); }

.chfoot { display: flex; gap: 10px; flex-wrap: wrap; border-top: 2px solid var(--line); padding-top: 16px; margin-top: 8px; }

/* ── البطاقات ── */
.flash { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: clamp(20px, 5vw, 44px); text-align: center; min-height: 230px; display: grid; place-content: center; gap: 14px; }
.flash .f { font-size: clamp(1.25rem, 4vw, 1.7rem); font-weight: 900; }
.flash .b { font-size: 1.08rem; color: var(--ink); font-weight: 600; border-top: 2px dashed var(--line); padding-top: 16px; }
.flash .tag { font-size: .8rem; color: var(--ink-soft); font-weight: 800; }
.fbar { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.prog-txt { text-align: center; font-weight: 800; color: var(--ink-soft); margin-top: 12px; }

/* ── الاختبار ── */
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 12px; }
.mode { text-align: right; background: var(--soft); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; font-family: Tajawal, sans-serif; color: var(--ink); }
.mode b { display: block; font-size: 1.02rem; font-weight: 900; }
.mode span { font-size: .84rem; color: var(--ink-soft); font-weight: 600; }
.mode.is-on { border-color: var(--teal); background: var(--card); box-shadow: 0 0 0 3px rgba(42,157,143,.14); }
.mode.is-on b::after { content: " ✓"; color: var(--teal); }

.qhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.qcount { font-weight: 800; color: var(--ink-soft); }
.timer { font-weight: 900; background: var(--soft); border: 2px solid var(--line); border-radius: 999px; padding: 4px 16px; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--no); border-color: var(--no); }
.qcard { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: clamp(16px, 3vw, 28px); box-shadow: var(--shadow); }
.qtag { font-size: .8rem; font-weight: 800; color: var(--teal); background: var(--soft); border-radius: 999px; padding: 3px 12px; display: inline-block; margin-bottom: 10px; }
.qtxt { font-size: clamp(1.1rem, 3vw, 1.32rem); font-weight: 800; line-height: 1.85; margin-bottom: 16px; }
.opts { display: grid; gap: 9px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: right; width: 100%;
  background: var(--soft); border: 2px solid var(--line); border-radius: 14px; padding: 11px 15px;
  cursor: pointer; font: 700 1rem Tajawal, sans-serif; color: var(--ink);
}
.opt:hover:not([disabled]) { border-color: var(--teal); }
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: .85rem; font-weight: 900; }
.opt.picked { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(42,157,143,.14); }
.opt.good { border-color: var(--ok); background: var(--ok-bg); }
.opt.good .k { background: var(--ok); color: #fff; border-color: var(--ok); }
.opt.good .k::after { content: "✓"; }
.opt.bad { border-color: var(--no); background: var(--no-bg); }
.opt.bad .k { background: var(--no); color: #fff; border-color: var(--no); }
.opt.bad .k::after { content: "✗"; }
.opt.good .k b, .opt.bad .k b { display: none; }
.fb { margin-top: 14px; border-radius: 12px; padding: 11px 15px; font-weight: 700; border: 2px solid var(--line); }
.fb.good { border-color: var(--ok); background: var(--ok-bg); }
.fb.bad { border-color: var(--no); background: var(--no-bg); }
.fb b { display: block; margin-bottom: 3px; }
.qnav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }

.score { text-align: center; padding: 26px 20px; }
.score .pct { font-size: clamp(2.6rem, 10vw, 4.2rem); font-weight: 900; color: var(--teal); line-height: 1.15; }
.score .verdict { font-size: 1.2rem; font-weight: 900; margin-bottom: 6px; }
.score .verdict.pass { color: var(--ok); }
.score .verdict.fail { color: var(--no); }
.brk { display: grid; gap: 8px; margin-top: 18px; text-align: right; }
.brkrow { display: grid; grid-template-columns: 1fr 90px 46px; gap: 10px; align-items: center; font-weight: 700; font-size: .93rem; }
.brkrow .bar { margin: 0; }
.rev { margin-top: 20px; display: grid; gap: 10px; }
.revq { background: var(--soft); border: 2px solid var(--line); border-right: 4px solid var(--no); border-radius: 12px; padding: 11px 15px; text-align: right; }
.revq .qq { font-weight: 800; }
.revq .aa { color: var(--ok); font-weight: 700; font-size: .93rem; }
.revq .ee { color: var(--ink-soft); font-size: .89rem; font-weight: 500; }

/* ── الشفوي ── */
.olist { display: grid; gap: 10px; }
.oitem { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.oitem.known { border-right: 5px solid var(--ok); }
.oitem.review { border-right: 5px solid var(--gold); }
.oq { font-weight: 800; font-size: 1.05rem; }
.oa { display: none; margin-top: 10px; padding-top: 10px; border-top: 2px dashed var(--line); font-weight: 600; }
.oitem.open .oa { display: block; }
.obar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip { font: 800 .85rem Tajawal, sans-serif; border: 2px solid var(--line); background: var(--soft); color: var(--ink); border-radius: 999px; padding: 5px 14px; cursor: pointer; }
.chip:hover { border-color: var(--teal); }
.chip.on-ok { border-color: var(--ok); color: var(--ok); }
.chip.on-no { border-color: var(--gold); color: var(--gold); }

/* ── أخطائي ── */
.errch { margin-bottom: 16px; }
.errch h3 { font-size: 1.05rem; font-weight: 900; color: var(--teal); margin-bottom: 8px; }

.empty { text-align: center; color: var(--ink-soft); font-weight: 700; padding: 34px 16px; }

.foot { border-top: 2px solid var(--line); background: var(--card); padding: 18px clamp(12px, 3vw, 28px); text-align: center; color: var(--ink-soft); }
.foot p { max-width: 780px; margin: 0 auto; font-size: .92rem; }
.foot .sm { margin-top: 6px; font-size: .82rem; }

@media print { .top, .foot, .chfoot { display: none; } .split { grid-template-columns: 1fr; } }
