/* Tapio — نظام تصميم خفيف، جوال أولاً، بدون أي مكتبات خارجية */

/**
 * سِمَتان اثنتان فقط:
 *  - الافتراضية (فاتحة): خلفية بيضاء نقية — الإعداد والتصفّح والإحصاءات.
 *  - .stage (داكنة #12102E): الجلسة المباشرة — يُضاف الصنف على <html> فتنقلب
 *    كل الألوان دفعة واحدة. كل لون هنا رمز (token) فلا يُكتب لون مباشرة في
 *    القواعد أدناه، وإلا انكسرت إحدى السِمَتين.
 */
:root {
  color-scheme: light;
  --bg: #faf9f6;
  --bg-2: #f2f0ec;
  --surface: #ffffff;
  --surface-2: #f2f0ec;
  /* سطح الزرّ الثانويّ: درجةٌ أقوى من الأسطح الخافتة عمداً — لأن
     `--brand-soft` قريبٌ منها، فزرٌّ بلونها داخل لوحةٍ ملوّنة يختفي */
  --btn-soft: #e8e5e0;
  --border: #e2e0dc;
  --text: #221b5b;
  --muted: #6e6a8f;
  /*
   * بنفسجيّ المعلّم وتركوازيّ الطالب من ألوان الشعار. التركوازي هنا أغمق
   * درجةً من لون العلامة (‎#00a3a3‎): في هذه الصفحات يحمل نصّاً أبيض ويُستعمل
   * نصّاً بذاته، وكلاهما يسقط تحت العتبة بلون العلامة الصريح (3.10:1).
   * القيمتان الآن 4.62:1 و 5.16:1 مع الأبيض.
   */
  --brand: #785ce0;
  --brand-2: #017a7a;
  --on-brand: #ffffff;
  --ok: #128a4d;
  --warn: #a45c00;
  --bad: #cc2f2f;
  --ok-soft: rgba(18, 138, 77, 0.1);
  --bad-soft: rgba(204, 47, 47, 0.09);
  --warn-soft: rgba(164, 92, 0, 0.1);
  --brand-soft: rgba(122, 95, 224, 0.09);
  --scrim: rgba(255, 255, 255, 0.86);
  /* مقبض المفاتيح والمقاييس + مسار المفتاح المطفأ — يحتاجان تبايناً في السِمَتين */
  --knob: #ffffff;
  --track: #d6d3ce;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 45, 0.06), 0 6px 18px rgba(20, 22, 45, 0.06);
  --tap: 48px;
}

html.stage,
html.dark {
  color-scheme: dark;
  --bg: #171240;
  --bg-2: #1f1852;
  --surface: #1f1852;
  --surface-2: #322a6e;
  --btn-soft: #322a6e;
  --border: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --muted: #a29dc6;
  --brand: #8f78e8;
  --brand-2: #00c2c2;
  --on-brand: #171240;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --ok-soft: rgba(52, 211, 153, 0.16);
  --bad-soft: rgba(251, 113, 133, 0.16);
  --warn-soft: rgba(251, 191, 36, 0.16);
  --brand-soft: rgba(143, 120, 232, 0.18);
  --scrim: rgba(23, 18, 64, 0.86);
  --knob: #ffffff;
  --track: rgba(255, 255, 255, 0.2);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  /* مسطّح تماماً في السِمَتين — لا تدرّجات ولا زخارف */
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, 'Noto Naskh Arabic', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

img,
svg {
  max-width: 100%;
}

.wrap {
  width: min(1100px, 100%);
  margin-inline: auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.wrap.narrow {
  width: min(540px, 100%);
}

/* ------------------------------------------------------------------ عناصر */

.brand {
  display: flex;
  align-items: center;
  min-height: 40px;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.3px;
}

/**
 * الشعار الكامل (يحوي الكلمة) — ملفان: ملوّن للخلفية البيضاء وأبيض للجلسة
 * الداكنة. التبديل بالـ CSS لا بالـ JS فيقع فوراً مع تغيّر السِمة بلا وميض.
 * استبدال الملفين وحدهما يحدّث كل الصفحات.
 */
/* الشعار مركّب رأسياً (رمز فوق الكلمة) بنسبة ~1.56:1، فيحتاج ارتفاعاً أكبر
   من شعار أفقي حتى تبقى الكلمة مقروءة */
.brand .logo {
  height: 42px;
  width: auto;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
}

/* الترويسة الكبيرة في الصفحة الرئيسية */
.brand.hero .logo {
  height: clamp(78px, 22vw, 104px);
}

.brand .dark-only {
  display: none;
}

html.stage .brand .light-only,
html.dark .brand .light-only {
  display: none;
}

html.stage .brand .dark-only,
html.dark .brand .dark-only {
  display: block;
}

/* الأيقونة المصغّرة — في شاشتَي الطالب والعرض حيث يظهر عنوان النشاط بجانبها */
.brand .dot {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--scrim);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

/*
 * أزرار الشريط العلوي. كانت تخلط شكلين وارتفاعين (icon-btn مربّع ٤٠px مع
 * btn.sm بيضوي ٣٨px) فتتكسّر على الجوال في ثلاثة صفوف غير متساوية. هنا
 * نوحّد الارتفاع والاستدارة، ونجعل الالتفاف مرتّباً محاذياً لجهة البداية.
 */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.topbar-actions > * {
  flex: 0 0 auto;
}

/*
 * جهة بداية القراءة من الشريط: روابط التنقّل وحدها (الرئيسية وما بعدها).
 * تنكمش قبل أن تنكمش جهة النهاية، فالهوية والمبدّلان أثبت من رابطٍ ثانوي.
 * لا `overflow: hidden` هنا: القوائم المنسدلة من هذه الجهة يبتلعها القصّ.
 */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-start;
  min-width: 0;
}

.topbar-nav > * {
  flex: 0 0 auto;
}

.topbar-actions .btn.sm,
.topbar-actions .icon-btn,
.topbar-actions .badge {
  min-height: 40px;
  height: 40px;
  border-radius: 999px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.topbar-actions .icon-btn {
  width: 40px;
  min-width: 40px;
  padding: 0;
}

/* اسم المعلّم قد يطول فيدفع بقية الأزرار إلى سطر جديد */
.topbar-actions .who {
  max-width: 11ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

/*
 * لا زرَّ في الشريط يلتفّ نصُّه: «EN» كان يصير «E» فوق «N» حين يضيق الشريط
 * بشارة الرمز وشارة البثّ على الجوال. والزرّ إمّا يظهر كاملاً أو يُخفى.
 */
.topbar .btn,
.topbar .icon-btn,
.topbar .badge {
  white-space: nowrap;
  flex-shrink: 0;
}

/*
 * شاشةُ الجلسة على الجوال: رمزُ الدخول وحالةُ البثّ أهمّ من الشعار واسم
 * المعلّم — فحين تظهر شارةُ الرمز على شاشةٍ ضيّقة يُخفى الاثنان بدل أن
 * يُعتصر الاسم إلى ثلاث نقاط ويُسحق الشعار إلى صفر.
 */
@media (max-width: 520px) {
  .topbar:has(#codeBadge:not(.hidden)) .brand,
  .topbar:has(#codeBadge:not(.hidden)) .tp-who__name {
    display: none;
  }
}

.topbar .logo {
  height: 30px;
  width: auto;
}

/*
 * عنوان النشاط قد يكون جملة كاملة. على شاشة الطالب كان يلتفّ ثلاثة أسطر
 * فيبتلع ثلث الشاشة في كل سؤال — والطالب لا يقرأ العنوان، يقرأ السؤال.
 * سطر واحد بحذفٍ في آخره، والعنوان كاملاً في التلميح.
 */
/* أساس صفري: العنوان يأخذ ما يفضل عن الأزرار لا العكس، وإلا دفَعها — وهو
   نصّ طويل — إلى سطر ثانٍ يبتلع ثلث شاشة الجوال. */
.topbar .brand {
  min-width: 0;
  flex: 1 1 0;
}

.topbar-actions {
  flex: 0 1 auto;
}

.title-line {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

@media (max-width: 720px) {
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }
  .topbar-actions {
    gap: 5px;
  }
  .topbar-actions .btn.sm,
  .topbar-actions .icon-btn,
  .topbar-actions .badge {
    min-height: 40px;
    height: 40px;
    padding: 0 10px;
    font-size: 0.78rem;
  }
  .topbar-actions .icon-btn {
    width: 40px;
    min-width: 40px;
    padding: 0;
  }
  /* على الجوال تكفي الأيقونة: النصّ يبقى في العنوان والقارئ الصوتي */
  .topbar-actions .label-wide {
    display: none;
  }
  .topbar-actions .who {
    max-width: 7ch;
  }
  .topbar .logo {
    height: 26px;
  }
}

/* الهواتف الضيقة: نشدّ المقاسات قليلاً كي يبقى الشريط سطراً واحداً */
@media (max-width: 430px) {
  .topbar {
    padding: 8px 10px;
    gap: 6px;
  }
  .topbar-actions {
    gap: 4px;
  }
  .topbar-actions .btn.sm,
  .topbar-actions .icon-btn,
  .topbar-actions .badge {
    min-height: 40px;
    height: 40px;
    padding: 0 8px;
    font-size: 0.75rem;
  }
  .topbar-actions .icon-btn {
    width: 40px;
    min-width: 40px;
    padding: 0;
  }
  .topbar-actions .who {
    max-width: 6ch;
  }
  .topbar .logo {
    height: 22px;
  }
}

/* ------------------------------------------------------- تذييل الموقع */

.site-footer {
  /* يُركَّب في body لا داخل .wrap (لأن لوحة المدرب تعيد رسم .wrap كلياً)،
     فنعطيه العرض والحشوة نفسها كي يبقى محاذياً للمحتوى فوقه */
  width: min(1100px, 100%);
  margin: 28px auto 20px;
  padding: 18px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.9;
  display: grid;
  gap: 6px;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  /* هدف لمسٍ محترم لروابط صغيرة الخطّ — حشوة لا تكبير خطّ */
  display: inline-block;
  padding: 10px 4px;
  margin: -6px 0;
}

.site-footer a:hover {
  color: var(--text);
}

.site-footer-by {
  font-weight: 600;
}

.site-footer-actions:empty {
  display: none;
}

.site-footer .install-btn {
  margin-bottom: 6px;
}

/* ------------------------------------------------- مراجعة بعد النشاط */

.review-card .review-answer {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.ok-text {
  color: var(--ok, #128a4d);
}

/* ------------------------------------------------------ المكتبة العامة */

.publish-form {
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.publish-form label {
  display: grid;
  gap: 4px;
}

/* ------------------------------------------------------ فيديو السؤال */

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.video-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* --------------------------------------------------- شريحة المحتوى */

.slide-body {
  margin: 0;
  line-height: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.slide-body.big {
  font-size: clamp(1.1rem, 2.4vw, 1.9rem);
  line-height: 1.9;
}

.slide-stage {
  text-align: center;
}

/* ------------------------------------------- رتّب وطابِق (شاشة الطالب) */

.order-list {
  display: grid;
  gap: 8px;
}

.order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 52px;
  cursor: pointer;
}

.order-item.on {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface-2));
}

.order-item .rank {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.order-item.on .rank {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/*
 * «طابِق»: كل طرفٍ بطاقةٌ بعرض الشاشة — الطرف في سطر، وما اختاره الطالب
 * تحته بنصّه كاملاً — ونقرتُها تفتح تحتها قائمة الأطراف المقابلة. لا
 * `<select>`: القائمة الأصلية المغلقة على الجوال تقصّ التعريف إلى كلمتين.
 */
.match-list {
  display: grid;
  gap: 10px;
}

.match-block {
  display: grid;
  gap: 6px;
}

.match-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'term caret'
    'value caret';
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  text-align: start;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 56px;
  cursor: pointer;
}

.match-term {
  grid-area: term;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.match-value {
  grid-area: value;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.match-item.has-value {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface-2));
}

.match-item.has-value .match-value {
  color: var(--text);
}

.match-item.is-open {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.match-caret {
  grid-area: caret;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.15s ease-out;
}

.match-item.is-open .match-caret {
  transform: rotate(180deg);
}

.match-menu {
  display: grid;
  gap: 6px;
  margin-inline-start: 12px;
  padding: 4px 0 4px;
  padding-inline-start: 10px;
  border-inline-start: 2px solid var(--brand);
}

.match-choice {
  display: grid;
  justify-items: start;
  gap: 4px;
  width: 100%;
  text-align: start;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: var(--tap);
  cursor: pointer;
}

.match-choice .grow {
  overflow-wrap: anywhere;
}

.match-choice.is-mine {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/*
 * جوابٌ استُعمل مع طرفٍ آخر: **لا يُبهَت**. الإبهات يقول «ممنوع»، والجواب
 * الواحد قد يصلح لأكثر من طرف عمداً — والشارة وحدها تكفي خبراً.
 */
.match-choice.is-used .match-tag {
  opacity: 0.9;
}

.match-tag {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

/* كشف «طابِق» و«رتّب»: كل سطرٍ بعلامته — ✓ أو ✕ أو رقم موضعه */
.reveal-list {
  display: grid;
  gap: 8px;
}

.reveal-pair {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.reveal-pair .grow {
  overflow-wrap: anywhere;
}

.reveal-pair.is-ok {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
  background: var(--ok-soft);
}

.reveal-pair.is-bad {
  border-color: color-mix(in srgb, var(--bad) 45%, var(--border));
  background: var(--bad-soft);
}

.reveal-mark {
  flex: 0 0 26px;
  height: 26px;
  margin-top: 2px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
}

.reveal-pair.is-ok .reveal-mark {
  color: var(--ok);
  border-color: var(--ok);
}

.reveal-pair.is-bad .reveal-mark {
  color: var(--bad);
  border-color: var(--bad);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card {
  margin-top: 14px;
}

.stack {
  display: grid;
  gap: 12px;
}

/**
 * عنصرُ الشبكة حدُّه الأدنى `auto` أي عرضُ محتواه الأدنى — فسطرٌ واحد لا
 * يُكسر (رابطٌ طويل مثلاً) يوسّع العمود كلّه، ويوسّع البطاقة، وتنزاح الصفحة
 * أفقياً على الجوال. الصفر يسمح للعمود أن يلتزم عرض حاويته، ويترك التمرير
 * لمن طلبه لنفسه (`.link-box`, `.chart-card`).
 */
.stack > * {
  min-width: 0;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

h1 {
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  margin: 0 0 6px;
  line-height: 1.25;
}

h2 {
  font-size: 1.15rem;
  margin: 0 0 10px;
}

h3 {
  font-size: 1rem;
  margin: 0 0 8px;
}

p {
  margin: 0 0 10px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

.hidden {
  display: none !important;
}

/**
 * سمة `hidden` أضعف تخصيصاً من أي صنف يضبط `display` — و`display: grid` على
 * `.stack` كان يُظهر لوحاتٍ نبنيها مخفيّة. القاعدة الافتراضية في المتصفح لا
 * تكفي هنا، فنجعل السمة قاطعة كما هو متوقّع منها.
 */
[hidden] {
  display: none !important;
}

/*
 * حلقة تركيز واحدة لكل ما يُنقر أو يُكتب فيه. من يتنقّل بلوحة المفاتيح — وهو
 * حال قارئ الشاشة وحال المعلّم الذي يدير جلسته من الكيبورد — كان يفقد موضعه
 * تماماً. و`:focus-visible` لا `:focus` كي لا تظهر الحلقة لمن ينقر بالفأرة.
 */
:where(a, button, [role='button'], input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* حركة أقلّ لمن طلبها من نظامه — قرارُ راحةٍ لا تفضيلَ ذوق */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

::selection {
  background: var(--brand-soft);
  color: var(--text);
}

/* الشريط العلوي ملتصق، فقفزةُ رابطٍ داخلي (فهرس الدليل) كانت تُخفي العنوان تحته */
[id] {
  scroll-margin-top: 84px;
}

/* ------------------------------------------------------------------ أزرار */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  /* كثير من الأزرار وسوم <a> — بلا هذا يظهر خط سفلي من المتصفح */
  text-decoration: none;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  /* زرّ «بانتظار المشاركين» كان يبدو جاهزاً للضغط: الشفافية وحدها لا تكفي
     على زرّ ملوّن، فنُذهب لونه أيضاً حتى يُقرأ «ليس الآن» بلا تجربة. */
  opacity: 0.5;
  filter: saturate(0.25);
  cursor: not-allowed;
}

.btn:disabled:active {
  transform: none;
}

/* مسطّحة تماماً: لون واحد صريح لكل زر، بلا تدرّجات ولا ظلال */
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.btn.accent {
  background: var(--brand-2);
  border-color: var(--brand-2);
  color: var(--on-brand);
}

/*
 * كل زرٍّ ممتلئ، ولا زرَّ إطارٌ فارغ.
 *
 * كان الثانويّ والخطِر شفّافَين بإطارٍ وحده — يُقرآن على الأرضية الداكنة
 * كحدودٍ مرسومة لا كأزرارٍ تُضغط، وعلى الجوال يفوتهما الإصبع لأنهما لا
 * يبدوان هدفاً. والتراتب محفوظ باللون لا بالفراغ: العلامة للأهمّ، وسطحٌ
 * أفتح للثانويّ، وأحمرٌ صريح للخطِر.
 */
.btn.ghost {
  background: var(--btn-soft);
  color: var(--text);
}

.btn.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: var(--on-brand);
}

/*
 * «إنهاء للجميع» ليس حذفاً. لو لبس الأحمر ظنّه المعلّم تدميراً فتردّد أمام
 * صفٍّ ينتظر، ولو لبس لون «التالي» ضغطه سهواً في منتصف الاختبار. لونٌ ثالث
 * صريح — أخضرُ «تمّ» — يفصل الفعلين بلا شرح.
 */
.btn.finish {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--on-brand);
}

.btn.block {
  width: 100%;
}

.btn.sm {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 999px;
}

.icon-btn {
  min-height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-grid;
  place-items: center;
}

/* ------------------------------------------------------------------ حقول */

label {
  font-weight: 600;
  font-size: 0.92rem;
  display: block;
  margin-bottom: 6px;
}

input,
textarea,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: var(--tap);
  outline: none;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

/**
 * الخانة والدائرة ليستا حقلَي نصّ. القاعدة العامة أعلاه كانت تمطّهما إلى
 * مربّعٍ فارغ بعرض السطر وارتفاع ٤٨ بكسل — يظهر كصندوقٍ غامض وسط الشاشة
 * منفصلٍ عن نصّه، كما حدث في خانة «اسمح بأسئلة تحتاج تصحيحاً يدوياً».
 */
input[type='checkbox'],
input[type='radio'] {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  min-height: 0;
  padding: 0;
  margin: 2px 0 0;
  accent-color: var(--brand);
  cursor: pointer;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  margin-bottom: 0;
  cursor: pointer;
}

.switch input {
  width: 46px;
  height: 26px;
  min-height: 0;
  flex: 0 0 auto;
  appearance: none;
  background: var(--track);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  padding: 0;
}

.switch input::after {
  content: '';
  position: absolute;
  inset-inline-start: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--knob);
  transition: inset-inline-start 0.15s ease;
}

.switch input:checked {
  background: var(--brand);
}

.switch input:checked::after {
  inset-inline-start: 23px;
}

/* ------------------------------------------------------------------ شارات */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.badge.bad {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}

.badge.live::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

/* ------------------------------------------------------------------ أفاتار */

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: #1b2445;
  display: grid;
  place-items: center;
}

.avatar.lg {
  width: 108px;
  height: 108px;
}

.avatar.sm {
  width: 30px;
  height: 30px;
}

/* ------------------------------------------------------------------ شبكات */

.grid {
  display: grid;
  gap: 12px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.stat .v {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat .k {
  color: var(--muted);
  font-size: 0.8rem;
}

/* -------------------------------------------------------------- الخيارات */

.options {
  display: grid;
  gap: 10px;
}

/*
 * أزرار الإجابة تملأ ما تبقى من الشاشة بدل أن تتكوّم في أعلاها ويبقى نصفها
 * السفلي فارغاً. هدفٌ أكبر = ضغطة أدقّ وأسرع، وهي اللحظة الوحيدة التي
 * يتنافس فيها الصفّ على الثواني. مقيّدة بشاشة طويلة كي لا تنضغط القصيرة.
 */
@media (min-height: 620px) {
  .options.fill {
    display: flex;
    flex-direction: column;
    min-height: min(54vh, 480px);
  }
  .options.fill .opt {
    flex: 1 1 0;
  }
}

.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: start;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 62px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.08s ease, border-color 0.15s ease;
}

.opt:active {
  transform: scale(0.985);
}

.opt .tag {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex: 0 0 auto;
  color: #0b1020;
}

.opt.c0 .tag {
  background: #f472b6;
}
.opt.c1 .tag {
  background: #60a5fa;
}
.opt.c2 .tag {
  background: #fbbf24;
}
.opt.c3 .tag {
  background: #34d399;
}
.opt.c4 .tag {
  background: #a78bfa;
}
.opt.c5 .tag {
  background: #fb923c;
}
.opt.c6 .tag {
  background: #22d3ee;
}
.opt.c7 .tag {
  background: #f87171;
}

.opt.selected {
  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.dim {
  opacity: 0.55;
}

.opt .bar {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  background: rgba(124, 92, 255, 0.25);
  z-index: 0;
  transition: width 0.5s ease;
}

.opt > * {
  position: relative;
  z-index: 1;
}

.opt .count {
  margin-inline-start: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ------------------------------------------- الانتقال التلقائي بعد الإجابة */

/**
 * شريط الانتقال عند الطالب في الوضع الحرّ.
 *
 * ملتصقٌ بأسفل الشاشة لا في أعلى الصفحة: الطالب يقرأ نتيجته ثم شرحها ثم
 * إجابات زملائه، وأي زرٍّ في الأعلى يغيب عن نظره عند أول تمرير. و‏`z-index`
 * أعلى من قصاصات الاحتفال (٩٠) لأنها كانت تتساقط فوقه فتُبهت لونه في
 * اللحظة نفسها التي يُفترض أن يكون فيها أوضح ما في الشاشة.
 */
.nextbar {
  position: sticky;
  bottom: 0;
  z-index: 95;
  display: grid;
  gap: 6px;
  margin: 14px -16px 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--scrim);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.nextbar .btn {
  min-height: 54px;
  font-size: 1.05rem;
}

.autonext {
  display: grid;
  gap: 6px;
  margin: -4px 0 6px;
  text-align: center;
}

/* داخل الشريط الملتصق: العدّاد سطرٌ رفيع فوق الزرّ لا كتلةٌ منفصلة */
.nextbar .autonext {
  margin: 0;
  gap: 4px;
}

.autonext-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

/* شريط يتقلّص: يرى الطالب متى ينتقل فلا يفاجئه الانتقال */
.autonext-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--brand);
  transform-origin: inline-start;
  animation: autonext-shrink linear forwards;
}

@keyframes autonext-shrink {
  to {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .autonext-bar {
    display: none;
  }
}

/* ------------------------------------------------- الألعاب التفاعلية */

/*
 * قوائم التصفية داخل صفّ: الحقول عرضها ١٠٠٪ افتراضياً فتتكدّس كل واحدة في
 * سطر. هنا نجعلها تتقاسم السطر وتلتفّ عند الضيق فقط.
 */
.filters select {
  width: auto;
  min-width: 9rem;
  flex: 0 1 auto;
}

.game-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  /* صفوفٌ متساوية الارتفاع: عنوانٌ طويل في بطاقة لا يجعل جارتها أقصر */
  grid-auto-rows: 1fr;
}

/**
 * `.card + .card` تضيف هامشاً علويّاً للإيقاع الرأسي في العمود الواحد —
 * وداخل الشبكة كانت تدفع كل بطاقةٍ بعد الأولى فتقصّ ارتفاعها ١٤ بكسل،
 * فيتعرّج الصفّ رغم تساوي الصفوف.
 */
.game-grid > .card + .card {
  margin-top: 0;
}

.game-card,
.teacher-card {
  text-decoration: none;
  color: inherit;
  min-width: 0;
  align-content: start;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

/* وصفٌ مسهب لا يمطّ البطاقة — سطران ثم حذف */
.game-card .muted.small {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-card:hover,
.teacher-card:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
}

/* الصورة المصغّرة — نسبة ثابتة فلا يقفز التخطيط قبل وصولها */
.game-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: calc(var(--radius) - 4px);
  overflow: hidden;
  background: var(--surface-2);
}

/**
 * كل المصغّرات بمقاسٍ واحد على العرض مهما اختلفت الصور المرفوعة: الصندوق
 * بنسبةٍ ثابتة، والصورة تملؤه قصّاً لا تشويهاً. والرفع نفسه يوحّدها أصلاً
 * إلى ٦٤٠×٣٦٠ في جهاز المعلّم، فهذه الطبقة الثانية لا الأولى.
 */
.game-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.game-thumb.sm {
  width: 96px;
  flex: 0 0 96px;
}

.game-thumb.big {
  max-height: 300px;
  margin-bottom: 12px;
}

/* بديلٌ للألعاب التي رُفعت قبل أن تصير الصورة مطلوبة */
.game-thumb.blank {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--accent, #f59e0b) 100%);
}

.game-thumb.blank span {
  font-size: 2.2rem;
  font-weight: 800;
  color: #fff;
}

/* مسرح اللعبة: نسبة ثابتة كي لا يقفز التخطيط قبل تحميلها */
.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 320px;
  max-height: 78vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}

/**
 * وضع اللعب: اللعبة تملأ الشاشة. الإطار باقٍ لأنه هو العزل، لكنه يختفي
 * كإطار — لا شريط ولا هوامش ولا تمرير — فيتصرّف في الجوال كتطبيق.
 * نستعمل dvh لا vh: شريط متصفّح الجوال يتحرّك، وvh يقصّ أسفل اللعبة.
 */
.game-stage.immersive {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-height: none;
  min-height: 0;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  z-index: 80;
  background: #000;
}

body.playing {
  overflow: hidden;
}

body.playing .topbar,
body.playing .footer {
  display: none;
}

.game-hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  inset-inline-end: max(8px, env(safe-area-inset-right));
  display: flex;
  gap: 6px;
  z-index: 2;
}

.hud-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 0;
  font-size: 1.05rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  color: #fff;
  background: rgba(17, 17, 17, 0.55);
  backdrop-filter: blur(6px);
}

.hud-btn:hover {
  background: rgba(17, 17, 17, 0.8);
}

/**
 * خلفية الإطار بيضاء في السِمَتين عمداً: اللعبة محتوى طرفٍ ثالث كُتب على
 * افتراض خلفيةٍ فاتحة، وقلبُها إلى الداكن يُخفي نصوصها السوداء.
 */
.game-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.big-cta {
  font-size: 1.15rem;
  padding: 14px;
}

/* صورة البروفايل في لوحة المعلّم */
.profile-face {
  width: 96px;
  height: 96px;
  flex: 0 0 96px;
  border-radius: 999px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  font-size: 2.2rem;
  font-weight: 800;
}

.profile-face img,
.teacher-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.teacher-head .teacher-face {
  margin: 0;
  width: 84px;
  height: 84px;
  flex: 0 0 84px;
}

/* بطاقة المعلّم في الدليل */
.teacher-face {
  width: 72px;
  height: 72px;
  margin: 4px auto 2px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  font-size: 1.8rem;
  font-weight: 800;
  overflow: hidden;
}

/* شريط مراحل المعالج: الإعدادات ← الأسئلة ← المراجعة */
.wizbar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.wizstep {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}

.wizstep .num {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.78rem;
}

.wizstep.on {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--text);
}

.wizstep.on .num {
  background: var(--brand);
  color: var(--on-brand);
}

/* صفّ المراجعة: سؤالٌ في سطر، يُنقر فيُفتح للتعديل */
.review-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: start;
}

.review-row:hover {
  border-color: var(--brand);
}

/* سؤالٌ بلا نص — لا يصحّ أن يمرّ إلى الإطلاق دون أن يُرى */
.review-row.warn {
  border-color: color-mix(in srgb, var(--warn) 55%, var(--border));
  background: var(--warn-soft);
}

.review-row .n {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* شريط خطوات المعالج: رقمٌ لكل سؤال يُنقر للقفز إليه */
.qsteps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.qstep {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* سؤالٌ كُتب نصّه — كي يرى المعلّم ما بقي فارغاً بنظرة */
.qstep.done {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
  color: var(--ok);
}

.qstep.on {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--on-brand);
}

/* شرائح اختيار متعدّد — الصفوف في نموذج رفع اللعبة */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font: inherit;
  font-size: 0.85rem;
  padding: 5px 11px;
  /* شريحةُ الاسم في كشف الصفّ هي زرُّ الدخول نفسه للطالب: ٤٤px لا ٣٠ */
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.chip.on {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--text);
  font-weight: 600;
}

.cover-preview img {
  width: 100%;
  max-width: 320px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid var(--border);
  display: block;
}

/**
 * رابطٌ يُنسخ: يمرّر نفسه ولا يكسر الصفحة.
 * `min-width: 0` ليس زينة: عنصرُ فليكس لا يصغر دون عرض محتواه الأدنى مهما
 * وضعتَ له `overflow-x: auto` — فكان الرابط الطويل يمدّ الصفّ ويمدّ الصفحة.
 */
.link-box {
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  /* الرابط رمزٌ لاتيني لا نصٌّ عربي: في سياق RTL كان `https://` يُقذف إلى
     آخره فيُقرأ «://localhost…» — وهو رابطٌ لا يُصدَّق أنه صحيح وإن نُسخ
     صحيحاً. (DESIGN.md §4: ما لا يُمرآ يُلفّ في LTR صراحةً.) */
  direction: ltr;
  text-align: left;
  font-size: 0.8rem;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.star {
  font: inherit;
  font-size: 1.9rem;
  line-height: 1;
  background: none;
  border: 0;
  padding: 2px 4px;
  /* خمس نجومٍ متلاصقة على الجوال: كل واحدةٍ هدفُ إبهامٍ كامل لا حرفاً بحجمه */
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  color: var(--border);
}

.star.on {
  color: #f5b700;
}

.star:disabled {
  cursor: default;
}

/* ---------------------------------------------------- بطاقة علامة الطالب */

.mark-card {
  border: 2px solid var(--brand);
  background: var(--brand-soft);
}

/* `.stack` شبكةٌ تمدّ أبناءها، والشارة تبدو شريطاً فارغاً حين تُمدّ */
.mark-card > .badge {
  justify-self: center;
  width: auto;
}

/* الرقم هو رسالة البطاقة كلها، فيأخذ حجماً لا يُنازَع عليه */
.mark-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.mark-value strong {
  font-size: clamp(2.8rem, 14vw, 4rem);
  font-weight: 800;
}

.mark-value .of {
  font-size: clamp(1.2rem, 6vw, 1.6rem);
  font-weight: 700;
  color: var(--muted);
}

.mark-card .progress {
  width: 100%;
}

/* ------------------------------------------------- نتائج الاستطلاع للمدرب */

.poll-panel {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
}

.poll-bars {
  display: grid;
  gap: 6px;
}

.poll-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  font-weight: 600;
}

/* العمود لا يُلوَّن كاملاً: النسبة تُقرأ من طول التعبئة لا من لون البطاقة */
.poll-bar .fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 0;
  opacity: 0.22;
  transition: width 0.45s ease;
}

.poll-bar > *:not(.fill) {
  position: relative;
  z-index: 1;
}

.poll-bar .pct {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.poll-bar .n {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.poll-bar.lead {
  border-color: var(--brand);
}

.poll-bar.lead .pct {
  color: var(--brand);
}

.poll-bar.c0 .fill { background: #f472b6; }
.poll-bar.c1 .fill { background: #60a5fa; }
.poll-bar.c2 .fill { background: #fbbf24; }
.poll-bar.c3 .fill { background: #34d399; }
.poll-bar.c4 .fill { background: #a78bfa; }
.poll-bar.c5 .fill { background: #fb923c; }
.poll-bar.c6 .fill { background: #22d3ee; }
.poll-bar.c7 .fill { background: #f87171; }

.poll-who {
  display: grid;
  gap: 4px;
  padding: 8px 0;
  border-top: 1px dashed var(--border);
}

/* --------------------------------------------------------------- المؤقّت */

.timer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer .num {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 2.2ch;
  text-align: center;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  flex: 1 1 auto;
}

.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  transition: width 0.25s linear;
}

.progress.thin {
  height: 6px;
}

/* ------------------------------------------------------------- الجداول */

.table-wrap {
  /* بلا هذين يتمدّد الصندوق مع جدوله فتتّسع الصفحة كلّها بدل أن يُمرَّر هو */
  min-width: 0;
  max-width: 100%;
  /* خلايا الجدول اللاصقة تُقاس من أقرب سلفٍ متموضع: بلا هذا تُحسب خارج الصندوق
     فتتّسع الصفحة كلّها أفقياً على الجوال */
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 520px;
}

th,
td {
  padding: 10px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  position: sticky;
  top: 0;
  background: var(--bg-2);
}

/* تخطيط متناوب: العين تتبع الصفّ الصحيح في جدول من ثلاثين طالباً بلا مسطرة */
tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

tbody tr:hover {
  background: var(--surface-2);
}

/* أرقام بعرض ثابت: الأعمدة الرقمية تصطفّ فتُقارَن بنظرة لا بقراءة */
td {
  font-variant-numeric: tabular-nums;
}

/* آخر عمود بلا خطّ سفلي زائد تحت آخر صفّ */
tbody tr:last-child td {
  border-bottom: 0;
}

.dots {
  display: inline-flex;
  gap: 3px;
}

.dots i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--surface-2);
  display: inline-block;
}

.dots i.ok {
  background: var(--ok);
}
.dots i.bad {
  background: var(--bad);
}
.dots i.neutral {
  background: var(--brand-2);
}

/* ------------------------------------------------------- قائمة المشاركين */

.people {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
  animation: pop 0.25s ease;
}

.chip.answered {
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(34, 197, 94, 0.12);
}

.chip.off {
  opacity: 0.45;
}

@keyframes pop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
}

/* -------------------------------------------------------- سحابة الكلمات */

/* شاشة العرض المنفصلة (بروجكتر) — نص أكبر يُرى من بعيد */
body.screen-body {
  font-size: 20px;
}

body.screen-body .wrap {
  width: min(1400px, 96%);
}

body.screen-body .qr {
  width: 340px;
  height: 340px;
}

body.screen-body .bigcode {
  font-size: clamp(3rem, 14vw, 6rem);
}

body.screen-body .big-q {
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  text-align: center;
}

body.screen-body .people {
  justify-content: center;
}

@media (min-width: 900px) {
  body.screen-body .card {
    padding: 24px;
  }
}

/* زر «متابعة عبر جوجل» */
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.google-btn svg {
  flex: 0 0 auto;
  background: #fff;
  border-radius: 4px;
  padding: 2px;
}

/* بطاقة النتيجة القابلة للمشاركة */
.share-card-img {
  width: 100%;
  max-width: 320px;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: pop 0.35s ease;
}

/* مقياس السحب — خط أفقي بمؤشر يُسحب */
.slider-card {
  text-align: center;
}

.slider-value {
  font-size: 2.6rem;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transition: transform 0.15s ease;
}

input[type='range'].slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

input[type='range'].slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  box-shadow: inset 0 0 0 1px var(--border);
}

input[type='range'].slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 30px;
  height: 30px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--knob);
  border: 4px solid var(--brand);
  box-shadow: var(--shadow);
}

input[type='range'].slider::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
}

input[type='range'].slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--knob);
  border: 4px solid var(--brand);
  box-shadow: var(--shadow);
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 8px;
}

.slider-ticks span {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
  min-width: 1.4em;
  transition: color 0.15s ease, transform 0.15s ease;
}

.slider-ticks span.on {
  color: var(--text);
  transform: scale(1.3);
}

.cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}

.cloud span {
  font-weight: 800;
  line-height: 1.2;
  animation: pop 0.3s ease;
}

/*
 * ألوان سحابة الكلمات لكل سِمة. كانت سبعة ألوان ثابتة في الجافاسكربت اختيرت
 * للخلفية الداكنة، فتصير على الفاتحة (‎#FAF9F7‎) بتباين ١.٦ — كلماتٌ لا تُرى.
 * السبعة نفسها هنا للداكن، ودرجاتٌ أعمق منها للفاتح.
 */
.cloud .c0 { color: #b8236f; }
.cloud .c1 { color: #1d5fc4; }
.cloud .c2 { color: #9a5b00; }
.cloud .c3 { color: #0f7a4f; }
.cloud .c4 { color: #6c3df4; }
.cloud .c5 { color: #b7491a; }
.cloud .c6 { color: #0b7f96; }

html.dark .cloud .c0 { color: #f472b6; }
html.dark .cloud .c1 { color: #60a5fa; }
html.dark .cloud .c2 { color: #fbbf24; }
html.dark .cloud .c3 { color: #34d399; }
html.dark .cloud .c4 { color: #a78bfa; }
html.dark .cloud .c5 { color: #fb923c; }
html.dark .cloud .c6 { color: #22d3ee; }

.quotes {
  display: grid;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
}

.quote {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  animation: pop 0.25s ease;
}

/* ------------------------------------------------------------- الترتيب */

.board {
  display: grid;
  gap: 8px;
}

.board .item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.board .item.me {
  border-color: var(--brand);
  background: rgba(124, 92, 255, 0.2);
}

.board .rank {
  font-weight: 800;
  width: 2ch;
  text-align: center;
  color: var(--muted);
}

.board .item:nth-child(1) .rank {
  color: #fbbf24;
}
.board .item:nth-child(2) .rank {
  color: #cbd5e1;
}
.board .item:nth-child(3) .rank {
  color: #f0a675;
}

.board .score {
  margin-inline-start: auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------- QR ورمز */

.joinbox {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  align-items: center;
}

@media (min-width: 640px) {
  .joinbox {
    grid-template-columns: auto 1fr;
  }
}

.qr {
  background: #fff;
  padding: 10px;
  border-radius: var(--radius);
  width: 210px;
  height: 210px;
  margin-inline: auto;
  display: grid;
  place-items: center;
}

.qr svg {
  width: 100%;
  height: 100%;
  display: block;
}

.bigcode {
  font-size: clamp(2.4rem, 12vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  direction: ltr;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ------------------------------------------------------------ محرر الأسئلة */

.qitem {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.qitem + .qitem {
  margin-top: 10px;
}

.qhead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-2);
  cursor: pointer;
}

.qhead .n {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--brand);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex: 0 0 auto;
}

.qhead .t {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.qbody {
  padding: 12px;
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--border);
}

.opt-edit {
  display: flex;
  gap: 8px;
  align-items: center;
}

.opt-edit .mark {
  min-height: 44px;
  min-width: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 1.05rem;
  cursor: pointer;
}

.opt-edit .mark.on {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.types {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
}

.type-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  gap: 4px;
  justify-items: center;
  min-height: 64px;
}

.type-btn .em {
  font-size: 1.2rem;
}

.type-btn.on {
  border-color: var(--brand);
  background: rgba(124, 92, 255, 0.22);
}

/* ------------------------------------------------------------- التبويبات */

.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  overflow-x: auto;
  /*
   * صفٌّ يُمرَّر لا يُقصّ: ما يخفيه الحدّ يُقال بتلاشٍ في طرفه لا بقطعٍ حادّ
   * يبدو عطلاً، والتمرير يتوقّف على زرٍّ كامل لا نصفه. وشريط التمرير مخفيّ —
   * الأزرار نفسها تقول إن هنا ما يُمرَّر.
   */
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 18px, #000 calc(100% - 18px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 18px, #000 calc(100% - 18px), transparent);
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs button {
  scroll-snap-align: start;
}

.tabs button {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 42px;
}

.tabs button.on {
  background: var(--brand);
  color: var(--on-brand);
}

@media (max-width: 430px) {
  .tabs button {
    padding: 9px 8px;
    font-size: 0.85rem;
  }
}

/* ------------------------------------------------------------ شريط سفلي */

.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--scrim);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.actionbar .btn {
  flex: 1 1 auto;
  /* سطرٌ واحد لكل زرّ: على جوالٍ بعرض 360 كانت أربعة أزرار تنضغط فيلتفّ نصّ
     كلٍّ منها سطرين داخل دائرة. الآن يلتفّ الشريط نفسه إلى صفّين إن لزم */
  white-space: nowrap;
}

.actionbar {
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- تنبيه */

/**
 * الإشعار خلفيّته داكنة **دائماً** في السِمَتين، فلونُ نصّه لا يصحّ أن يأتي
 * من رمز `--text`: في السِمَة الفاتحة هو أسودُ تقريباً، فيصير النص غير مقروء
 * على الكحلي. لونٌ فاتح صريح هو الجواب ما دامت الخلفية صريحةً داكنة.
 */
.toast {
  position: fixed;
  inset-inline: 12px;
  /* في الأعلى لا الأسفل: أسفل الشاشة مكانُ الفعل الأساسي (شريط الإطلاق وخيارات
     الإجابة)، وإشعارٌ يغطّيه ثوانيَ يحجب ما جاء المستخدم ليضغطه */
  top: calc(12px + env(safe-area-inset-top));
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100% - 24px);
  background: #1f1852;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 100;
  animation: pop 0.2s ease;
  font-weight: 600;
  text-align: center;
}

.toast.bad {
  background: #4a1d24;
  border-color: rgba(239, 68, 68, 0.5);
}

.toast.ok {
  background: #12341f;
  border-color: rgba(34, 197, 94, 0.5);
}

/* والعلّة نفسها كانت هنا: نصٌّ أصفر فاتح على خلفية عنبرية شاحبة في السِمَة
   الفاتحة. الرمز `--warn` داكنٌ في الفاتحة وفاتحٌ في الداكنة، فيصحّ فيهما. */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--warn);
  font-size: 0.9rem;
}


/* حاوية زرّ السِمَة — بعض الصفحات تضعه في <span> مجرّد */
#langRow,
#themeRow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* --------------------------------------------------------- كشف الأسماء */

.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/**
 * بلاطات أقسام اللوحة: صفٌّ لكل قسم على الجوّال، وشبكةٌ على الشاشة الأوسع.
 * كلٌّ منها رابطٌ كامل الارتفاع — الهدفُ اللمسيّ هو البطاقة لا كلمةٌ فيها.
 */
.tp-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tp-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.tp-tile:hover {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
}

.tp-tile__em {
  font-size: 1.5rem;
  line-height: 1;
}

.tp-tile__body {
  display: grid;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.tp-tile__note {
  color: var(--muted);
  font-size: 0.78rem;
  /* سطرٌ واحد لا يكسر ارتفاع البلاطات فتتفاوت في الشبكة */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tp-tile__meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

/* --------------------------------------------------------- سجلّ الطلاب */

/* الرمز الشخصي: أرقامٌ لاتينية متباعدة تُقرأ من بعيد، وتُنسخ بنقرة */
.chip.pin {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2em;
  font-weight: 700;
  color: var(--text);
  min-height: 36px;
  padding-inline: 10px;
}

/* اتجاه آخر النتائج: أعمدة صغيرة بلون النسبة — الأقدم في بداية القراءة */
.trend {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 28px;
  direction: ltr;
}

.trend i {
  display: block;
  width: 7px;
  border-radius: 2px;
  background: var(--muted);
}

.trend i.ok {
  background: var(--ok);
}

.trend i.warn {
  background: var(--warn);
}

.trend i.bad {
  background: var(--bad);
}

/* الصفّ في جدول السجل زرٌّ إلى ملفّ الطالب: يُبرَز عند المرور */
.rec-table tbody tr:hover td {
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}

/* ------------------------------------------------------------ المواعيد */

/*
 * شبكةُ الأوقات — أزرارٌ كما في Calendly.
 *
 * وشبكةٌ تملأ نفسها بحسب العرض لا عمودان ثابتان: المعلّم يفتح أوقاته من
 * حاسوبه فيرى يومه كلّه في نظرة، والطالب يختار من جوّاله فيرى عمودين
 * مريحين — والقاعدة واحدة لا نسختان.
 */
.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.slot {
  display: grid;
  gap: 2px;
  justify-items: center;
  /* هدفُ لمسٍ كامل (DESIGN.md): الوقت يُضغط من الجوّال لا من فأرة */
  min-height: 52px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.slot:hover:not(:disabled) {
  border-color: var(--brand);
}

.slot.on {
  border-color: var(--brand);
  background: var(--brand-soft);
  font-weight: 700;
}

/* وقتٌ مفتوحٌ سلفاً: يُرى ولا يُضغط — حذفُه من قائمة «مواعيدي» لا من هنا */
.slot:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ✕ داخل رقاقة الموعد: حذفٌ في مكانه بلا صفٍّ ثانٍ من الأزرار */
.chip__x {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 2px;
  margin-inline-start: 4px;
}

.chip__x:hover {
  color: var(--bad);
}

/* يومٌ فيه اختيارٌ لم يُحفظ بعد: نقطةٌ تقول «هنا شيء» بلا أن تُشبه المختار */
.chip.has::after {
  content: '•';
  color: var(--brand);
  font-weight: 700;
  margin-inline-start: 4px;
}

/* عيّنةُ درسٍ: رابطٌ خارجيّ يُقرأ سطراً كاملاً لا كلمةً في جملة */
.sample-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}

.sample-link:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* صفّ العيّنة في البروفايل: عنوانٌ ثم رابط، ويتراصّان على الجوّال */
.sample-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 6px;
  margin-block-end: 6px;
}

/* نموذجُ الحجز في صفحته الواسعة: حقلان في السطر حيث يتّسع */
.book-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

@media (max-width: 560px) {
  .sample-row {
    grid-template-columns: 1fr;
  }
}

/* وجهُ المعلّم في صفحته العامّة */
.tp-face {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--brand-soft);
}

.tp-face--empty {
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--brand);
}

/* ------------------------------------------------------------ الواجبات */

/*
 * كشفُ من يُكلَّف: صناديقُ أسماء داخل صندوقٍ يُمرَّر.
 *
 * فصلُ ستّين طالباً لو انسدل بطوله دفع زرَّ «كلّف» إلى ما تحت الشاشة، فيبدو
 * النموذج بلا زرّ. وسقفُه أربعون بالمئة من الشاشة: يُرى منه صفوفٌ تكفي
 * للتعرّف على ما فيه، وما زاد يُمرَّر داخله.
 */
.roster-pick {
  display: grid;
  gap: 2px;
  max-height: min(40dvh, 320px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
}

.roster-pick__row {
  display: flex;
  align-items: center;
  gap: 8px;
  /* هدفُ لمسٍ كامل: الاسم كلّه يُبدّل الصندوق، لا مربّعٌ صغير وحده */
  min-height: 40px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin: 0;
}

.roster-pick__row:hover {
  background: var(--brand-soft);
}

.roster-pick__row input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
}

/* ------------------------------------------------- دليل الخطوات الأولى */

.guide-steps {
  display: grid;
  gap: 2px;
}

.guide-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

/* الخطوة الجارية وحدها ملوّنة: أربعُ بطاقاتٍ متساوية لا تقول «ابدأ من هنا» */
.guide-step.now {
  background: var(--brand-soft);
}

.guide-step.done .gs-n {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--on-brand);
}

.guide-step.done > .stack strong {
  text-decoration: line-through;
  opacity: 0.6;
}

.gs-n {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  margin-top: 1px;
}

.guide-step.now .gs-n {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

/* ------------------------------------------------------------- شاشة كبيرة */

.big-q {
  font-size: clamp(1.35rem, 4.5vw, 2.2rem);
  font-weight: 800;
  line-height: 1.35;
  margin: 0 0 4px;
}

.feedback {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 24px 12px;
  text-align: center;
  animation: pop 0.3s ease;
}

.feedback .em {
  font-size: 3.4rem;
  line-height: 1;
}

.feedback .msg {
  font-size: 1.3rem;
  font-weight: 800;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
  margin: 12px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 24px 12px;
}

/* ------------------------------------------------------------- المؤثرات */

.fx-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

.fx-emoji {
  position: fixed;
  bottom: 8%;
  z-index: 85;
  pointer-events: none;
  animation: floatUp 2.6s ease-out forwards;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}

@keyframes floatUp {
  0% {
    transform: translateY(0) scale(0.6);
    opacity: 0;
  }
  15% {
    transform: translateY(-30px) scale(1.15);
    opacity: 1;
  }
  100% {
    transform: translateY(-58vh) scale(1) rotate(12deg);
    opacity: 0;
  }
}

.fx-countdown {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-content: center;
  gap: 8px;
  justify-items: center;
  background: var(--scrim);
  backdrop-filter: blur(6px);
}

.fx-countdown .n {
  font-size: clamp(5rem, 26vw, 11rem);
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.fx-countdown .n.pop {
  animation: countPop 0.45s ease-out;
}

.fx-countdown .l {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.08em;
}

@keyframes countPop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  55% {
    transform: scale(1.18);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

/* --------------------------------------------------------- التفاعلات */

.reactions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.react {
  font-size: 1.5rem;
  line-height: 1;
  min-height: 52px;
  min-width: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.react:active {
  transform: scale(0.88);
}

.react.bump {
  animation: countPop 0.35s ease-out;
}

/* ------------------------------------------------------- منصة التتويج */

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  padding-top: 8px;
}

.podium .pod {
  flex: 1 1 0;
  max-width: 150px;
  display: grid;
  justify-items: center;
  gap: 6px;
}

.podium .who {
  display: grid;
  justify-items: center;
  gap: 2px;
  text-align: center;
}

.podium .nm {
  font-weight: 800;
  font-size: 0.9rem;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium .sc {
  font-weight: 800;
  color: var(--brand-2);
  font-variant-numeric: tabular-nums;
}

.podium .block {
  width: 100%;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, var(--brand), rgba(124, 92, 255, 0.25));
  display: grid;
  place-items: center;
  animation: rise 0.6s ease-out;
  transform-origin: bottom;
}

.podium .medal {
  font-size: 1.8rem;
}

@keyframes rise {
  from {
    transform: scaleY(0.05);
  }
}

/* ------------------------------------------------------ تفاصيل أخرى */

.timer .num.hot {
  color: #fca5a5;
  animation: pulse 1s infinite;
}

.badge.streak {
  background: rgba(251, 146, 60, 0.18);
  border-color: rgba(251, 146, 60, 0.45);
  color: #fed7aa;
}

.toast.long {
  border-radius: 14px;
  line-height: 1.7;
  text-align: start;
}

/* ------------------------------------- كشف الإجابة الصحيحة وشرحها */

.card.reveal {
  border-color: var(--ok);
  background: var(--ok-soft);
  animation: pop 0.3s ease;
}

/* ------------------------------------------------------------- الأوسمة */

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.award {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 12px 14px;
  min-width: 104px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(251, 191, 36, 0.18), rgba(124, 92, 255, 0.14));
  border: 1px solid rgba(251, 191, 36, 0.35);
  animation: pop 0.35s ease;
}

.award .em {
  font-size: 1.9rem;
  line-height: 1;
}

.award .lbl {
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.award.sm {
  flex-direction: row;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  min-width: 0;
  border-radius: 999px;
}

.award.sm .em {
  font-size: 1rem;
}

.award.sm .lbl {
  font-size: 0.75rem;
}

.link {
  color: var(--brand-2);
  text-decoration: none;
  font-weight: 700;
}

.link:hover {
  text-decoration: underline;
}

/* ------------------------------------------------ محادثة «صمّم بالذكاء الاصطناعي» */

.chat-thread {
  display: grid;
  gap: 10px;
  max-height: min(52vh, 460px);
  overflow-y: auto;
  padding: 4px;
}

.bubble {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  max-width: 92%;
}

.bubble.me {
  justify-self: start;
  background: var(--brand-soft);
  border-color: transparent;
}

.bubble.ai {
  justify-self: end;
}

.bubble .who {
  font-size: 12px;
  color: var(--muted);
}

.bubble .body {
  white-space: pre-wrap;
  line-height: 1.65;
}

/**
 * ردُّ النموذج بعد ترجمة رموزه إلى تنسيق.
 *
 * `pre-wrap` يبقى: الأسطر داخل الفقرة الواحدة يكتبها النموذج متعمّداً.
 * لكنّ الكتل تصير عُقَداً حقيقية، فتُضبط هوامشها هنا كي لا تتباعد الفقاعة
 * بفراغٍ مزدوج — فراغِ الوسم وفراغِ السطر الذي وُلد منه.
 */
.bubble .body.rich > :first-child {
  margin-block-start: 0;
}

.bubble .body.rich > :last-child {
  margin-block-end: 0;
}

.bubble .body.rich p,
.bubble .body.rich ul,
.bubble .body.rich ol,
.bubble .body.rich blockquote,
.bubble .body.rich pre {
  margin-block: 8px;
}

.bubble .body.rich .md-h {
  font-weight: 700;
  margin-block: 10px 4px;
}

.bubble .body.rich ul,
.bubble .body.rich ol {
  /* الحشو في الجهة المنطقية: النقاط تسبق النصّ يميناً في العربية */
  padding-inline-start: 20px;
  display: grid;
  gap: 4px;
}

.bubble .body.rich li {
  /* عناصر القائمة سطورٌ يلفّها العرض لا نصٌّ محفوظ الأسطر */
  white-space: normal;
}

.bubble .body.rich code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  /* الشيفرة رموزٌ لاتينية دائماً، فاتجاهها من اليسار */
  direction: ltr;
  unicode-bidi: isolate;
}

.bubble .body.rich pre {
  margin-block: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}

.bubble .body.rich pre code {
  padding: 0;
  border: 0;
  background: none;
  white-space: pre;
}

.bubble .body.rich blockquote {
  margin-inline: 0;
  padding-inline-start: 10px;
  border-inline-start: 3px solid var(--brand);
  color: var(--muted);
}

.bubble .body.rich hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: 10px;
}

.bubble .body.rich a {
  color: var(--brand);
  overflow-wrap: anywhere;
}

.chat-compose {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-compose .btn {
  white-space: nowrap;
  flex: 0 0 auto;
  min-height: 52px;
  height: 52px;
}

/* على الجوال يأخذ الصندوق العرض كاملاً وينزل الزر تحته */
@media (max-width: 560px) {
  .chat-compose {
    flex-direction: column;
    align-items: stretch;
  }
}

/* مادّة الدرس المرفقة: زرٌّ وشرائح أسماء الملفّات فوق خانة الكتابة */
.attach {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.attach-list:empty {
  display: none;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 22ch;
}

.attach-sent {
  margin-top: 4px;
  word-break: break-word;
}

.chat-input {
  flex: 1 1 auto;
  min-height: 52px;
  resize: vertical;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.chat-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.q-preview {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.stack.tight {
  gap: 6px;
}

.note {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.note.warn {
  background: var(--warn-soft);
}

.spinner.sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
  margin: 0;
}

/* ------------------------------------------------ صورة السؤال والتصحيح اليدوي */

.badge.warn {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

/* صورة السؤال: تملأ العرض بلا أن تطغى على النص، وبارتفاع محدود على الشاشات الكبيرة */
.q-image {
  display: block;
  width: 100%;
  max-height: 42vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-2);
}

body.screen-body .q-image {
  max-height: 34vh;
}

.img-edit {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.img-edit img {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.grade-row {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* ما ينتظر التصحيح يُبرز بحافة ملوّنة كي يعرف المدرب أين توقّف */
.grade-row.pending {
  border-inline-start: 4px solid var(--warn);
  background: var(--warn-soft);
}

.grade-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.7;
}

/* ------------------------------------------------ أكمل الفراغ */

/* الجملة تُقرأ كسطر متصل والحقول جزء منها لا صناديق منفصلة */
.blank-line {
  font-size: 1.15rem;
  line-height: 2.4;
  font-weight: 700;
}

.blank-input {
  display: inline-block;
  width: clamp(90px, 28%, 190px);
  margin: 0 4px;
  padding: 4px 10px;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 0;
  border-bottom: 3px solid var(--brand);
  border-radius: 8px 8px 0 0;
  text-align: center;
}

.blank-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  background: var(--brand-soft);
}

/* إجابة الطالب أمام الإجابة المتوقعة في لوحة التصحيح */
.grade-expected {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* ------------------------------------------------ تحليل النتائج (رسوم) */

.chart-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.chart-stat {
  display: grid;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.chart-stat strong {
  font-size: 1.5rem;
  font-weight: 800;
}

.chart-stat span {
  font-size: 12px;
  color: var(--muted);
}

.chart-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: stretch;
  margin-bottom: 12px;
}

/**
 * البطاقة تجرّ جدولها ولا تجرّ الصفحة.
 *
 * `.chart-table` عرضها ١٠٠٪ لكنّ ذلك حدٌّ أدنى لا أقصى: تخطيط الجدول التلقائي
 * لا يضغط الخلية دون عرض أطول كلمة فيها، فخمسةُ أعمدة عربية تحتاج ~٥٢٠ بكسل
 * على شاشة ٣٩٠ — فكانت تمتدّ ويمتدّ معها المستند كلّه، فتنزاح كل الصفحة
 * أفقياً ويختفي نصفها. الآن يفيض الجدول داخل بطاقته وحدها.
 */
.chart-card {
  flex: 1 1 260px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 12px;
  overflow-x: auto;
}

.chart-card.grow {
  flex: 3 1 320px;
}

.chart-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.chart-donut {
  display: block;
  width: 100%;
  max-width: 180px;
  margin: 0 auto;
  color: var(--text);
}

.chart-bars {
  display: grid;
  gap: 8px;
}

.chart-bar {
  display: grid;
  grid-template-columns: minmax(90px, 34%) 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.chart-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.chart-track {
  display: block;
  height: 14px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.chart-track i {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.chart-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-highlights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

/* كل بطاقة تُبرز سؤالاً واحداً بلون حالته */
.chart-highlight {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  border-inline-start: 4px solid var(--brand);
}

.chart-highlight.bad { border-inline-start-color: var(--bad); }
.chart-highlight.ok { border-inline-start-color: var(--ok); }
.chart-highlight.warn { border-inline-start-color: var(--warn); }

.chart-highlight .t {
  font-size: 12px;
  color: var(--muted);
}

.chart-highlight .v {
  font-size: 12px;
  color: var(--muted);
}

.chart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.chart-table th,
.chart-table td {
  border-bottom: 1px solid var(--border);
  padding: 7px 8px;
  text-align: start;
}

/* على الجوال نضيّق الحشو والخطّ أولاً — فالتمرير آخر الحلول لا أوّلها */
@media (max-width: 560px) {
  .chart-table {
    font-size: 12px;
  }

  .chart-table th,
  .chart-table td {
    padding: 6px 5px;
  }
}

.rec-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rec {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-inline-start: 4px solid var(--brand);
  line-height: 1.7;
}

.rec.ok { border-inline-start-color: var(--ok); background: var(--ok-soft); }
.rec.warn { border-inline-start-color: var(--warn); background: var(--warn-soft); }
.rec.bad { border-inline-start-color: var(--bad); background: var(--bad-soft); }

/* ------------------------------------------------ جدولة الاختبار ومدته */

.countdown-big {
  font-size: 2rem;
  font-weight: 800;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

/* شريط رفيع فوق السؤال: كم بقي من زمن الاختبار كاملاً */
.deadline-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  font-weight: 700;
}

.deadline-bar strong {
  font-variant-numeric: tabular-nums;
}

.schedule-card {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
}

/* ترحيب باسم المعلّم أعلى صفحاته */
.welcome {
  display: grid;
  gap: 2px;
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--brand-soft);
  border: 1px solid var(--border);
}

/* شاشة الاختيار: بطاقتان كبيرتان لا ثالث لهما */
.start-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* البطاقة كلّها رابط: الهدف أكبر من زرّ، فلا يخطئه إصبعٌ على الجوال */
.start-card {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  padding: 26px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
}

.start-card:hover,
.start-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--brand);
}

.start-card.ai {
  background: var(--brand-soft);
  border-color: var(--brand);
}

.start-emoji {
  font-size: 2.8rem;
  line-height: 1;
}

.start-name {
  font-size: 1.15rem;
}

/* الزرّ داخل البطاقة زينةٌ بصرية: البطاقة نفسها هي الرابط */
.start-card .btn {
  margin-top: 6px;
  pointer-events: none;
}

/* طرق استخدام المساعد الذكي — ثلاث بطاقات متجاورة تشرح ما يمكن كتابته */
.ai-ways {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.ai-way {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}

/* مدخل البروفايل في الشريط العلوي — صورة المعلّم إن رفعها */
.profile-btn {
  overflow: hidden;
  padding: 0;
}

.profile-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* رسم التسجيلات اليومية في لوحة المالك */
.signup-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  /* المدى ثلاثون يوماً: على الجوال يُمرَّر أفقياً بدل أن تُسحق الأعمدة */
  overflow-x: auto;
}

.sc-col {
  flex: 1 0 8px;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.sc-bar {
  width: 100%;
  border-radius: 3px 3px 0 0;
  background: var(--brand);
  transition: height 0.2s ease;
}

/* يومٌ بلا تسجيل: خيطٌ باهت يقول «مررنا بهذا اليوم» لا فراغ يُقرأ كانقطاع */
.sc-bar.zero {
  background: var(--border);
}

/* تهنئة الحساب الجديد بمنحته — أول ما يراه بعد أول تسجيل دخول */
.welcome-pop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
}

/* نافذةٌ لا مهرب منها: سؤال البلد مطلوب، فالأرضية أعتم ولا تُغلق بالنقر */
.welcome-pop.locked {
  background: color-mix(in srgb, var(--scrim) 85%, black);
}

.welcome-card {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--brand);
  background: var(--surface);
  box-shadow: 0 18px 50px rgb(0 0 0 / 28%);
}

/* بطاقةُ النسخ اليدويّ: آخر ما يبقى حين يمنع المتصفّح الحافظة.
   الرابط فيها حقلٌ حقيقي محدَّدٌ كاملاً — لا فقاعةٌ تختفي قبل أن يُلمس. */
.copy-pop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
}

.copy-card {
  width: min(420px, 100%);
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 18px 50px rgb(0 0 0 / 28%);
}

.copy-card input.link-box {
  width: 100%;
  font-size: 0.95rem;
  padding: 10px 12px;
}

/* منحة التسجيل — تُرى قبل السعر لا بعده */
.trial {
  gap: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--brand-soft);
  border: 1px solid var(--brand);
}

.trial h2 {
  font-size: 1.1rem;
}

.trial p {
  font-size: 0.92rem;
}

/* ------------------------------------------------------------- الباقات */

.plans {
  display: grid;
  gap: 12px;
  /* بطاقتان جنباً إلى جنب على الحاسوب، وواحدةٌ تحت الأخرى على الجوال:
     المقارنة تحتاج أن تُرى معاً حين يتّسع العرض، ولا تُضغط حين يضيق */
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/*
 * ثلاث بطاقات: العتبة أضيق كي تُرى الثلاث معاً على حاسوبٍ عاديّ.
 *
 * وبعتبة ٢٦٠px كانت الثالثة تنزل وحدها في سطرٍ ثانٍ على شاشةٍ متوسّطة، فتبدو
 * ملحقةً بالباقتين لا ثالثةً لهما — والمقارنة بين ثلاثٍ لا تصحّ إن لم تُرَ
 * الثلاث في نظرةٍ واحدة.
 */
.plans--three {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.plan {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

/* الباقة المدفوعة تُبرَز بإطار العلامة لا بلونٍ صارخ */
.plan.best {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand) inset;
}

.plan-price {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.plan-price strong {
  font-size: 2rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.plan-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
}

.plan-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
}

.plan-list .mark {
  font-weight: 800;
  color: var(--ok);
}

.plan-list li.off .mark {
  color: var(--muted);
}

/* جدول المقارنة: أسماء الميزات جملٌ لا أرقام، فلا يُمنع لفّها كبقية الجداول */
.plans-table {
  min-width: 520px;
}

.plans-table th:first-child,
.plans-table td:first-child {
  min-width: 170px;
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface);
}

.plans-table th,
.plans-table td {
  white-space: normal;
}

.plans-table .plan-cell {
  text-align: center;
  width: 1%;
  white-space: nowrap;
}

/*
 * صفُّ المشاركة: أزرارٌ صغيرة تلتفّ، ولا تُشدّ إلى عرضٍ واحد.
 * أسماء المنصّات تختلف طولاً (𝕏 حرفٌ و«تيليجرام» ثمانية)، ومساواتها بالقوّة
 * تترك فراغاً في الصغير وتقصّ الكبير.
 */
.share-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.share-row .btn {
  flex: 0 0 auto;
}

/* --------------------------------------------------- صفحة الدفع المحلّي */

.pay-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.pay-head__badge {
  font-size: 1.6rem;
  line-height: 1;
}

/* خطوةٌ مرقّمة: الرقم دائرةٌ ثابتة العرض كي تصطفّ الخطوات تحت بعضها */
.pay-step {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
}

.pay-step__no {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 99px;
  background: var(--brand-soft);
  border: 1px solid var(--brand);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/*
 * رقم المحفظة: يُقرأ ليُكتب في تطبيقٍ آخر، فهو أكبر ما في الصفحة بعد العنوان،
 * وبخطٍّ أحاديّ العرض كي لا يلتبس ٠ بحرفٍ ولا ٦ بـ٨. و`dir: ltr` عليه في
 * الترميز لأنه رقم هاتفٍ لا نصّ عربي.
 */
.pay-wallet {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--brand);
  background: var(--brand-soft);
}

.pay-wallet__no {
  flex: 1;
  min-width: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

/* نصّ للقارئ الصوتي وحده: العلامة ✅/✖ تُرى، ومعناها يُقرأ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/*
 * ترقيم القوائم يتبع لغة الصفحة. كان الدليل يخلط النظامين في شاشةٍ واحدة:
 * عناوينه بأرقام عربية-هندية (١. ٢. ٣.) وقوائمه المرقّمة بلاتينية (1. 2. 3.)
 * لأنها ترقيم المتصفّح الافتراضي. أرقام الواجهة الحيّة (المؤقّت، النقاط،
 * العدّاد) تبقى لاتينية كما ينصّ DESIGN.md §4 — هذه للنثر وحده.
 */
html[dir='rtl'] ol {
  list-style-type: arabic-indic;
}

/*
 * أيقونة «؟» وفقاعتها — بيت النصوص الإرشادية بدل فقراتٍ دائمة فوق كل شاشة.
 * النقطة صغيرة بصرياً (22px) داخل هدف ضغطٍ 40px، والهامش السالب يعيد ما
 * أضافه الهدف كي لا ينتفخ سطر العنوان.
 */
.hintdot {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
}

.hintdot__btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
  margin: -9px;
  padding: 0;
  border: 0;
  background: none;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  border-radius: 999px;
}

.hintdot__dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface);
}

.hintdot__btn:hover .hintdot__dot,
.hintdot__btn:focus-visible .hintdot__dot,
.hintdot__btn[aria-expanded='true'] .hintdot__dot {
  color: var(--brand);
  border-color: var(--brand);
}

.hintdot__pop {
  /* ثابتة لا مطلقة: المطلقة توسّع المستند خارج حافته فينزاح المحتوى كلّه
     أفقياً على الجوال — الإحداثيات تُحسب في hintDot نفسه */
  position: fixed;
  z-index: 60;
  min-width: 200px;
  max-width: min(300px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.7;
  text-align: start;
  white-space: pre-line;
}

.hintdot__pop[hidden] {
  display: none;
}

/*
 * قطعة القراءة في الشاشات القديمة (إجابة مفتوحة، أكمل الفراغ، سحابة كلمات)
 * وفي شاشة العرض. الصندوق يمرّر نصّه ويبقى ما تحته ظاهراً.
 */
.passage {
  max-height: 40vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--brand);
  background: var(--bg-2);
  white-space: pre-wrap;
  line-height: 1.7;
}

.passage.big {
  max-height: 46vh;
  font-size: 1.15rem;
}

/**
 * فعلان متساويان في صفٍّ واحد (إنشاء نشاط · إنشاء لعبة).
 *
 * `auto-fit` مع حدٍّ أدنى لا عمودان ثابتان: على هاتفٍ بعرض 320px يصير
 * العمودان زرّين فوق بعضهما بدل نصَّين مقصوصين — والزرّ الذي لا يُقرأ اسمه
 * ليس زرّاً.
 */
.btn-duo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.btn-duo .btn {
  width: 100%;
}

/* ------------------------------------------- منشئ الألعاب التفاعلية */

/**
 * نجاحٌ يُقرأ لا يُخمَّن. `.note.warn` كانت وحدها، فكان رابط اللعبة المنشورة
 * يظهر في صندوقٍ رماديّ لا يقول إن شيئاً نجح.
 */
.note.ok {
  background: var(--ok-soft);
}

/* سطرٌ تحت الحقل يشرح حدّه — أصغر من `small` لأنه ملحقٌ لا نصّ */
.tiny {
  font-size: 0.72rem;
  line-height: 1.5;
}

/**
 * شبكة إعدادات المنشئ: عمودان على الجوال ثم تتّسع.
 * `auto-fill` مع حدٍّ أدنى يجعلها تتنفّس بلا استعلامات وسائط لكل مقاس.
 */
.knob-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.knob input {
  /* رقمٌ يُقرأ من اليسار كبقية أرقام المنصّة، وهدفُ لمسٍ يسع إصبعاً */
  direction: ltr;
  text-align: center;
  min-height: 44px;
  font-variant-numeric: tabular-nums;
}

/**
 * مفاتيح الميزات: صفٌّ لكل ميزة، خانةٌ ثم اسمٌ ثم سطرُ شرح.
 * عمودٌ واحد على الجوال ثم عمودان — الشرح سطرٌ كامل لا يُقصّ.
 */
.switch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: nowrap;
  /* هدفُ لمسٍ يسع إصبع معلّمٍ على الجوال، والخانة وحدها لا تكفي */
  min-height: 44px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

.switch-row input {
  margin-block-start: 3px;
  flex: 0 0 auto;
}

/* ميزةٌ مطفأة: الصفّ يبهت فيُقرأ حالُه قبل أن تُقرأ خانته */
.switch-row:has(input:not(:checked)) {
  opacity: 0.62;
}

/* بطاقةٌ تُطوى: العنوان وحده ظاهر حتى يطلب المعلّم التفاصيل */
details.card > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

details.card > summary::-webkit-details-marker {
  display: none;
}

details.card > summary::after {
  content: '▾';
  color: var(--muted);
  margin-inline-start: auto;
  transition: transform 0.15s ease-out;
}

details.card[open] > summary::after {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  details.card > summary::after {
    transition: none;
  }
}

/**
 * شريط «نسختك قديمة»: أسفل الشاشة، فوق كل شيء، ولا يحجب فعلاً — رسالةٌ
 * وزرّ. ويظهر مرّةً واحدة حين يختلف إصدار الصفحة عن إصدار الخادم.
 */
.stale-bar {
  position: fixed;
  inset-inline: 12px;
  bottom: 12px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.85rem;
}

/* رقم النسخة في التذييل: صغيرٌ لا يزاحم، ولاتينيّ الاتجاه */
.site-footer-version {
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

/**
 * جدولان يصيران بطاقاتٍ على الجوّال: لوحة المالك، ومتابعة الواجب.
 *
 * ستّة أعمدة في شاشةٍ بعرض ٣٩٠px تعني أن «بريميوم ١٢ يوماً» يقع بجوار أزرار
 * التمديد فلا يُقرأ أيّهما، والمالك يمرّر يميناً ويساراً ليجمع صفّاً واحداً.
 * ومثله متابعة الواجب: «من سلّم ومن لم يسلّم» سؤالٌ يُسأل من الجوّال غالباً،
 * وجوابُه لا يجوز أن يكون خلف تمريرٍ أفقيّ. فتصير كل خليةٍ سطراً معنوناً
 * باسم عمودها، واسمُ الطالب ترويسةَ بطاقته.
 */
/*
 * صفُّ إحصاءِ المعلّم — يُدرَج تحت صفّه حين يُفتح ويُنزع حين يُطوى.
 *
 * ولا قاعدةَ إخفاءٍ له هنا عمداً: ظهورُه لا يجوز أن يعتمد على نمطٍ قد تكون
 * في متصفّح المالك نسخةٌ قديمةٌ منه. ما في الشجرة يُرى، وما ليس فيها لا يُرى.
 */
.adm-table tr.adm-stats > td {
  padding: 10px;
  background: var(--surface-2);
}

@media (max-width: 720px) {
  .adm-table,
  .hw-table {
    min-width: 0;
  }

  .adm-table thead,
  .hw-table thead {
    display: none;
  }

  .adm-table,
  .adm-table tbody,
  .adm-table tr,
  .adm-table td,
  .hw-table,
  .hw-table tbody,
  .hw-table tr,
  .hw-table td {
    display: block;
    width: 100%;
  }

  .adm-table tr,
  .hw-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--surface);
  }

  .adm-table tr:hover,
  .adm-table tbody tr:nth-child(even),
  .hw-table tr:hover td,
  .hw-table tbody tr:nth-child(even) {
    background: var(--surface);
  }

  .adm-table td,
  .hw-table td {
    border: 0;
    padding: 4px 0;
    white-space: normal;
  }

  /* عنوانُ العمود فوق قيمته — عدا الاسم فهو ترويسة البطاقة */
  .adm-table td[data-label]::before,
  .hw-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    margin-bottom: 2px;
  }

  .adm-table td:first-child,
  .hw-table td:first-child {
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 4px;
  }
}

/*
 * وبطاقةُ الواجب أضيق من بطاقة المالك: أربعةُ سطورٍ لكل طالبٍ تجعل صفّاً من
 * ثلاثين تمريراً لا ينتهي، والسؤال المطروح («من لم يسلّم؟») يُقرأ من الشارات
 * وحدها. فيبقى الاسم سطراً، وينساب ما بعده في سطرٍ واحد — بلا عنوانٍ لما
 * يقول نفسه (شارةُ الحالة والنسبة)، وبعنوانٍ ملاصقٍ لما لا يقوله (الوقت
 * والمجموعة).
 */
@media (max-width: 720px) {
  .hw-table td {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    padding-inline-end: 12px;
  }

  .hw-table td[data-label]::before {
    display: inline;
    margin: 0;
  }

  .hw-table td:first-child {
    display: block;
    width: 100%;
  }
}

/* --------------------------------------------------- تقرير تحليل الفصل */
/*
 * ورقةٌ تُطبع: على الشاشة بطاقاتٌ كسائر المنصّة، وعلى الورق تُنزع الأزرار
 * والشريط والظلال وتُفرض ألوانُ الضوء — السمة الداكنة ليست للورق.
 */
.report {
  display: grid;
  gap: 12px;
}

.report h1 {
  margin: 0;
  font-size: 1.5rem;
}

.report h2 {
  font-size: 1.05rem;
}

.report .headline {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.6;
}

.report-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.report-cols:empty {
  display: none;
}

.report ul,
.report ol {
  margin: 0;
  padding-inline-start: 20px;
  line-height: 1.8;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.report-table th,
.report-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: start;
  line-height: 1.6;
  /* الملاحظة والخطوة نصّان يلتفّان — جدولٌ يمرّر أفقياً يُقصّ على الورق */
  white-space: normal;
}

.report-table td:nth-child(6),
.report-table td:nth-child(7) {
  min-width: 180px;
}

.report-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}

.report .trend {
  direction: ltr;
  text-align: end;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/*
 * وعلى الجوّال يصير كل طالبٍ بطاقةً — جدولُ سبعة أعمدة لا يُقرأ بعرض ٣٩٠px.
 * و`screen` شرطٌ لازم: ورقةُ A4 عرضها ٧٠٣px فتقع تحت الحدّ، فكان الجدولُ
 * ينطوي بطاقاتٍ في الطباعة — كلُّ سطرٍ ثلاثةُ أضعاف طوله، والورقةُ ورقتان.
 */
@media screen and (max-width: 720px) {
  .report-table thead {
    display: none;
  }

  .report-table,
  .report-table tbody,
  .report-table tr,
  .report-table td {
    display: block;
    width: 100%;
  }

  .report-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--surface);
  }

  .report-table td {
    border: 0;
    padding: 4px 0;
  }

  .report-table td:empty {
    display: none;
  }

  .report .trend {
    text-align: start;
  }

  .report-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    margin-bottom: 2px;
  }

  .report-table td:first-child {
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 4px;
  }
}

.report-foot {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.7;
  margin: 0;
}

@media print {
  html,
  html.dark,
  html.stage {
    --bg: #fff;
    --bg-2: #fff;
    --surface: #fff;
    --surface-2: #f4f4f4;
    --border: #cfcfcf;
    --text: #111;
    --muted: #555;
    color-scheme: light;
  }

  body.report-page {
    background: #fff;
    color: #111;
  }

  body.report-page .topbar,
  body.report-page .no-print,
  body.report-page .toast {
    display: none !important;
  }

  body.report-page .wrap {
    width: 100%;
    max-width: none;
    padding: 0;
    margin: 0;
  }

  body.report-page .table-wrap {
    overflow: visible;
  }

  body.report-page .card,
  body.report-page .stat {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #cfcfcf;
  }

  body.report-page .badge {
    border: 1px solid #999;
  }

  body.report-page a {
    color: inherit;
    text-decoration: none;
  }

  @page {
    margin: 12mm;
  }
}

/* --------------------------------------------------- دليل المعلّمين */
.td-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.td-filters input[type='search'] {
  grid-column: 1 / -1;
}

.td-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: start;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.td-card:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
}

.td-card .tp-face {
  width: 56px;
  height: 56px;
  font-size: 1.4rem;
}

.td-card .bio {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------------------------ بطاقة الطالب لوليّ الأمر */
.cd-note {
  min-height: 68px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.9;
  outline-offset: 2px;
}

/* نائبٌ عن النصّ في حقلٍ محرَّر: `placeholder` لا تعمل على contenteditable */
.cd-note:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.cd-sign {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 6px;
}

.cd-line {
  border-bottom: 1px solid var(--border);
  height: 26px;
}

@media print {
  body.report-page .cd-note {
    border-color: #cfcfcf;
    min-height: 44px;
  }

  body.report-page .cd-line {
    height: 22px;
  }

  body.report-page .stats {
    gap: 8px;
  }

  body.report-page .report-table th,
  body.report-page .report-table td {
    padding: 5px 6px;
  }

  body.report-page .cd-sign {
    gap: 10px;
    margin-top: 2px;
  }

  /* حقلٌ فارغ يُطبع فراغاً لا كلمةَ إرشادٍ في ورقةٍ تذهب إلى البيت */
  body.report-page .cd-note:empty::before {
    content: '';
  }
}

/*
 * على الورق يُشدّ الإيقاع: البطاقة تُسلَّم لوليّ الأمر ورقةً واحدة، وسطرٌ
 * فائضٌ إلى صفحةٍ ثانية يجعلها ورقتين — إحداهما شبه فارغة.
 */
@media print {
  body.report-page .report {
    gap: 6px;
  }

  body.report-page .card {
    padding: 8px 12px;
  }

  body.report-page .stat {
    padding: 8px 10px;
  }

  body.report-page .stat .v {
    font-size: 1.3rem;
  }

  body.report-page .report h1 {
    font-size: 1.25rem;
  }

  body.report-page .report h2 {
    font-size: 0.98rem;
  }
}

/* ------------------------------------------------------- دليل المعلّم */
/*
 * عنوانُ الجزء بين البطاقات: الدليل مرجعٌ طويل، فيحتاج القارئ فاصلاً يقول
 * «انتقلتَ من بابٍ إلى باب» — لا بطاقةً أخرى تشبه ما قبلها.
 */
.help-part {
  margin: 22px 0 2px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
  font-size: 1.05rem;
  color: var(--muted);
  letter-spacing: 0.2px;
}
