:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #17223b;
  --muted: #6b7690;
  --line: #e3e8f2;
  --brand: #1f6f8b;
  --brand-2: #2a9d8f;
  --brand-soft: #e6f3f6;
  --ok: #2e9e5b;
  --ok-soft: #e4f6ea;
  --bad: #d64545;
  --bad-soft: #fdeaea;
  --warn: #d98c1f;
  --warn-soft: #fff3df;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(23, 34, 59, 0.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Tajawal', 'Segoe UI', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.3; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* الشريط العلوي */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; gap: 10px;
}
.topbar .brand { font-weight: 800; font-size: 1.15rem; color: var(--brand); display: flex; align-items: center; gap: 8px; }
.topbar .brand img { width: 30px; height: 30px; border-radius: 8px; }
.topbar .actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 0.9rem; }
.icon-btn:active { background: var(--bg); }

.page { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(30px + var(--safe-b)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.tight { padding: 10px 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack > * + * { margin-top: 10px; }

/* الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border: none; border-radius: 12px;
  padding: 11px 18px; font-weight: 700; cursor: pointer; min-height: 44px;
  transition: transform 0.05s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; border-radius: 9px; }
.btn.big { font-size: 1.1rem; padding: 14px 22px; }

/* النماذج */
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 700; margin-bottom: 4px; font-size: 0.95rem; }
.field input:not([type=radio]):not([type=checkbox]), .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fff; min-height: 44px; outline: none;
}
.field input:not([type=radio]):not([type=checkbox]):focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field textarea { min-height: 80px; resize: vertical; }
.field .hint { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 0.95rem; }
.success { background: var(--ok-soft); color: var(--ok); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.info { background: var(--warn-soft); color: #7a4e00; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 0.95rem; }

/* الشارات */
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.gray { background: #eef0f5; color: var(--muted); }

/* صفحة الدخول */
.hero { border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.hero img { width: 100%; max-height: 260px; object-fit: cover; }
.hero .hero-text { padding: 16px; font-size: 1.05rem; text-align: center; }
.hero .placeholder { padding: 40px 16px; text-align: center; font-size: 1.6rem; font-weight: 800; }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.role-btn {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px 10px; text-align: center; cursor: pointer;
}
.role-btn .ic { font-size: 2rem; }
.role-btn .t { font-weight: 800; font-size: 1.1rem; }
.role-btn:active, .role-btn.active { border-color: var(--brand); background: var(--brand-soft); }

/* البنر الإعلاني: 3سم */
.ad-banner { display: block; width: 100%; height: 3cm; border-radius: 12px; overflow: hidden; background: #eef0f5; margin: 12px 0; }
.ad-banner img { width: 100%; height: 100%; object-fit: cover; }

/* أنماط الاختبار */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-btn { position: relative; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 12px 6px; text-align: center; cursor: pointer; }
.mode-btn .t { font-weight: 800; }
.mode-btn .n { color: var(--muted); font-size: 0.8rem; }
.mode-btn.active { border-color: var(--brand); background: var(--brand-soft); }
.mode-btn .q { position: absolute; top: 4px; left: 6px; width: 20px; height: 20px; border-radius: 50%; background: var(--line); font-size: 0.75rem; display: flex; align-items: center; justify-content: center; }
.mode-def { background: var(--warn-soft); border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; margin-top: 8px; }

/* شجرة الفصول */
.chapter { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; overflow: hidden; }
.chapter > .ch-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #fafbfe; cursor: pointer; }
.chapter > .ch-head .title { flex: 1; font-weight: 700; }
.chapter .lessons { padding: 4px 12px 8px 12px; border-top: 1px solid var(--line); }
.lesson-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.lesson-row:last-child { border-bottom: none; }
.lesson-row .title { flex: 1; }
.chk { width: 22px !important; height: 22px; min-height: 0 !important; padding: 0 !important; margin: 0; accent-color: var(--brand); flex-shrink: 0; }
.chev { transition: transform 0.2s; color: var(--muted); }
.chapter.open .chev { transform: rotate(180deg); }
.chapter.open > .ch-head { background: var(--brand-soft); }

/* الأسئلة */
.question { margin-bottom: 12px; }
.question .skill-tag { display: inline-block; background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 3px 10px; font-size: 0.85rem; font-weight: 700; margin-bottom: 8px; }
.question .qtext { font-weight: 700; font-size: 1.05rem; margin-bottom: 10px; }
.opt { display: flex; align-items: center; gap: 10px; border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; background: #fff; }
.opt.active { border-color: var(--brand); background: var(--brand-soft); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt .letter { width: 26px; height: 26px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.opt.active .letter { background: var(--brand); color: #fff; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.progress > div { height: 100%; background: var(--brand-2); transition: width 0.3s; }

/* النتائج */
.score-big { font-size: 2.6rem; font-weight: 900; text-align: center; color: var(--brand); line-height: 1; }
.skill-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.skill-line:last-child { border-bottom: none; }
.skill-line .s { font-weight: 800; min-width: 56px; text-align: center; border-radius: 8px; padding: 2px 8px; }
.skill-line .s.ok { background: var(--ok-soft); color: var(--ok); }
.skill-line .s.bad { background: var(--bad-soft); color: var(--bad); }
.skill-line .s.mid { background: var(--warn-soft); color: var(--warn); }
.lesson-head { font-weight: 800; color: var(--brand); margin: 10px 0 4px; }
.rank-list { counter-reset: r; }
.rank-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.rank-item:last-child { border-bottom: none; }
.rank-item .num { width: 26px; height: 26px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.rank-item .name { flex: 1; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; flex: 1; max-width: 120px; }
.bar > div { height: 100%; background: var(--brand-2); }
.bar.low > div { background: var(--bad); }

/* التبويبات */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tab { flex: 1 1 40%; text-align: center; padding: 8px 6px; border-radius: 9px; cursor: pointer; white-space: nowrap; font-weight: 700; font-size: 0.9rem; color: var(--muted); }
.tab.active { background: var(--brand); color: #fff; }

/* قوائم */
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .body { flex: 1; min-width: 0; }
.list-item a.body { color: inherit; }
.list-item .title { font-weight: 700; }
.list-item .sub { color: var(--muted); font-size: 0.85rem; }
.subject-card { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.subject-card .ic { width: 48px; height: 48px; border-radius: 12px; background: var(--brand-soft); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0; }

/* بانك الأسئلة عند المعلم */
.bank-skill { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.bank-skill .bs-head { font-weight: 800; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.bank-q { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 6px; background: #fff; }
.bank-q.sel { border-color: var(--brand); background: var(--brand-soft); }
.bank-q .body { flex: 1; min-width: 0; }
.bank-q .opts { color: var(--muted); font-size: 0.85rem; }
.bank-q .opts .c { color: var(--ok); font-weight: 700; }
.bank-q .tools { display: flex; flex-direction: column; gap: 4px; }
.bank-q .tools button { font-size: 0.8rem; padding: 3px 8px; min-height: 28px; }

/* الحوار */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }
.modal h3 { margin-bottom: 12px; }
.reason-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.reason-btns .role-btn { padding: 10px; }

.toast { position: fixed; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 100; font-size: 0.95rem; max-width: 90vw; }
.spinner { text-align: center; padding: 30px; color: var(--muted); }
.fab-bar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 calc(6px + var(--safe-b)); }
.install-tip { background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; display: flex; gap: 8px; align-items: center; }
