/* ════════════════════════════════════════════════════════════════════════════
   أَرضُ السَّرمد — طَبَقَةُ الجَوّال الاحتِرافيّة
   ────────────────────────────────────────────────────────────────────────────
   مَبادِئُ التَّصميم:
   ١. الأَداءُ أَوَّلاً — لا backdrop-filter، تَحريكٌ بـtransform، تَحميلٌ كَسول
   ٢. سَلامَةُ المسٍ — كلُّ زِرٍّ ≥ ٤٤×٤٤px (مَعيار Apple HIG)
   ٣. تَسَلسُلٌ هَرَميّ — إِجراءٌ واحِدٌ في كلِّ شاشة
   ٤. آمِنٌ من النُّتوءات — safe-area-insets للجَوّالات الحَديثة
   ٥. حَركاتٌ ٦٠ FPS — transform & opacity فَقَط
   ────────────────────────────────────────────────────────────────────────────
   كل القَواعد تَستَخدِم  html.mobile  لتَعلو على CSS الحاسوب
   لا تُؤَثِّرُ على الحاسوب إِطلاقاً
   ════════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────
   ١. الجُذور والمُتَغَيِّرات (Mobile-only)
   ───────────────────────────────────────────────────────────────────────── */
html.mobile {
  --m-topbar-h: 52px;
  --m-bottomsheet-h: 64px;
  --m-bottomsheet-h-expanded: 50dvh;
  --m-touch: 44px;
  --m-radius: 14px;
  --m-radius-sm: 10px;
  --m-pad: 16px;
  --m-pad-sm: 12px;

  --m-shadow: 0 8px 24px rgba(0,0,0,.5);
  --m-shadow-sm: 0 4px 12px rgba(0,0,0,.4);

  --m-bg-overlay: rgba(10, 8, 6, 0.94);
  --m-bg-sheet: rgba(15, 12, 10, 0.98);

  --m-safe-top: env(safe-area-inset-top, 0);
  --m-safe-bottom: env(safe-area-inset-bottom, 0);
  --m-safe-left: env(safe-area-inset-left, 0);
  --m-safe-right: env(safe-area-inset-right, 0);
}

/* ─────────────────────────────────────────────────────────────────────────
   ٢. الأَساسيّات
   ───────────────────────────────────────────────────────────────────────── */
html.mobile,
html.mobile body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
html.mobile body {
  overscroll-behavior-y: contain;
  height: 100dvh;
}

/* قَفلُ التَّمرير عِندَ فَتح فَصلٍ أَو مودال أَو بَحث */
html.mobile body.chapter-open,
html.mobile body.modal-open,
html.mobile body.search-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100dvh;
}

/* إِيقافُ التَّأثيرات الثَّقيلة عالَمياً */
html.mobile *,
html.mobile *::before,
html.mobile *::after {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
html.mobile .opener-bg,
html.mobile .cinema-grain,
html.mobile .cinema-vignette,
html.mobile .cinema-overlay {
  animation: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٣. الشاشةُ الافتِتاحيّة (Opener)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .opener {
  padding: 24px 18px;
  padding-top: calc(24px + var(--m-safe-top));
  padding-bottom: calc(24px + var(--m-safe-bottom));
  align-items: center;
}
html.mobile .opener-frame {
  max-width: 100%;
  width: 100%;
  padding: 28px 22px;
  border-radius: var(--m-radius);
}
html.mobile .opener-eyebrow {
  font-size: 10px;
  letter-spacing: .25em;
  margin-bottom: 16px;
}
html.mobile .opener-title {
  font-size: clamp(40px, 11vw, 64px);
  line-height: 1.05;
  margin-bottom: 8px;
}
html.mobile .opener-sub {
  font-size: 15px;
  margin-bottom: 22px;
}
html.mobile .opener-legend {
  font-size: 12.5px;
  line-height: 2;
  padding: 14px 16px;
  margin-bottom: 26px;
}
html.mobile .opener-actions {
  flex-direction: column;
  gap: 12px;
  width: 100%;
}
html.mobile .opener-btn {
  width: 100%;
  min-height: var(--m-touch);
  padding: 13px 18px;
  font-size: 13px;
  justify-content: center;
}
html.mobile .opener-meta {
  font-size: 10.5px;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 22px;
}
html.mobile-sm .opener-title { font-size: 38px; }
html.mobile-sm .opener-legend { font-size: 11.5px; padding: 12px 14px; }

/* ═══════════════════════════════════════════════════════════════════════
   ٤. الشَّريطُ العَلويّ (Topbar) — تَصميمٌ مُتَوازِن
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .topbar {
  height: var(--m-topbar-h);
  min-height: var(--m-topbar-h);
  padding: 0;
  padding-top: var(--m-safe-top);
  height: calc(var(--m-topbar-h) + var(--m-safe-top));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: stretch;
  background: rgba(10, 8, 6, 0.95);
  border-bottom: 1px solid rgba(212, 168, 67, 0.2);
}

/* العَلامة التِّجاريّة */
html.mobile .topbar-brand {
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 100%;
  border-left: 1px solid rgba(212, 168, 67, 0.15);
}
html.mobile .brand-mark {
  width: 32px;
  height: 32px;
  font-size: 17px;
  flex-shrink: 0;
}
html.mobile .brand-text { display: none; }

/* قائمة التَّنَقُّل — أَفُقيّة قابِلة للتَّمرير */
html.mobile .topbar-nav {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
  gap: 0;
  padding: 6px 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  display: flex;
  align-items: center;
  scroll-padding-inline: 12px;
  scroll-snap-type: x proximity;
}
html.mobile .topbar-nav::-webkit-scrollbar { display: none; }

html.mobile .nav-btn {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 56px;
  height: 38px;
  padding: 4px 10px;
  border-radius: 8px;
  scroll-snap-align: start;
  background: transparent;
  border: 1px solid transparent;
  color: var(--paper);
  transition: background-color 0.2s, border-color 0.2s;
}
html.mobile .nav-btn.active {
  background: rgba(212, 168, 67, 0.18);
  border-color: rgba(212, 168, 67, 0.35);
}
html.mobile .nav-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
html.mobile .nav-btn span {
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

/* الأَزرار الجانِبيّة (بَحث، ملء شاشة) */
html.mobile .topbar-controls {
  padding: 0 10px;
  gap: 4px;
  display: flex;
  align-items: center;
  height: 100%;
  border-right: 1px solid rgba(212, 168, 67, 0.15);
}
html.mobile .ctrl-btn {
  width: 36px;
  height: 36px;
  font-size: 14px;
  border-radius: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٥. الجَوُّ السينمائيّ (Cinema Mode) — تَصميمٌ نَظيف
   ═══════════════════════════════════════════════════════════════════════ */

/* الفيديو يَملأُ الشاشة كاملةً */
html.mobile .cinema-stage,
html.mobile .cinema-frames {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 1;
}
html.mobile .cinema-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
html.mobile .cinema-frame video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
}
html.mobile .cinema-overlay,
html.mobile .cinema-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* إِخفاءُ العَناصِر السينمائيّة المُكَرَّرة (مَكانها في اللَّوحة السُّفليّة) */
html.mobile body[data-mode="cinema"] .chapter-hud,
html.mobile body[data-mode="cinema"] .scene-info,
html.mobile body[data-mode="cinema"] .scene-quote,
html.mobile body[data-mode="cinema"] .scene-bar {
  display: none !important;
}

/* ─────────────────────────────────────────────────────────────────────
   بوب أَب الكَيانات في الجَوّ السينمائيّ
   ────────────────────────────────────────────────────────────────────
   البِنية الفِعليّة (من v3.js):
     <div class="entity-popup">
       <video|div class="popup-media">      (الصورة/الفيديو)
       <div class="popup-body">
         <div class="popup-tag">             (مَخفيّ على الجَوّال)
         <h3 class="popup-name">             (اسم الكَيان)
         <div class="popup-sub">             (وَصف فَرعيّ)
         <p class="popup-desc">              (الوَصف، حتى ١٦٠ حَرف)
         <div class="popup-info">            (مَخفيّ على الجَوّال)
         <div class="popup-cta">             (مَخفيّ على الجَوّال)
       </div>
     </div>
   ──────────────────────────────────────────────────────────────────── */

html.mobile body[data-mode="cinema"] .entity-popup {
  display: flex !important;
  position: fixed !important;
  /* فَوق اللَّوحة السُّفليّة المَطويّة بـ ٨ بكسل */
  bottom: calc(var(--m-bottomsheet-h) + var(--m-safe-bottom) + 8px) !important;
  right: 12px !important;
  left: 12px !important;
  top: auto !important;
  /* ارتِفاع مَحدود صَريح — مُسَتَحيل يُغَطّي الشاشة */
  height: 120px !important;
  max-height: 120px !important;
  min-height: 120px !important;
  max-width: none !important;
  width: auto !important;
  flex-direction: row !important;
  align-items: stretch !important;
  gap: 12px !important;
  padding: 10px !important;
  overflow: hidden !important;
  background: rgba(10, 8, 6, 0.96) !important;
  border: 1px solid var(--gold) !important;
  border-radius: var(--m-radius) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
  z-index: 60 !important;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s, transform 0.4s;
  pointer-events: none;
  box-sizing: border-box !important;
}
html.mobile body[data-mode="cinema"] .entity-popup.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ① الوَسائط (popup-media): فيديو، صورة، أَو فارِغ — حَجم ثابِت ١٠٠×١٠٠ */
html.mobile body[data-mode="cinema"] .entity-popup .popup-media,
html.mobile body[data-mode="cinema"] .entity-popup video.popup-media,
html.mobile body[data-mode="cinema"] .entity-popup div.popup-media {
  width: 100px !important;
  height: 100px !important;
  flex-shrink: 0 !important;
  border-radius: var(--m-radius-sm) !important;
  border: 1px solid rgba(212, 168, 67, 0.4) !important;
  background-size: cover !important;
  background-position: center !important;
  background-color: var(--night-mid) !important;
  overflow: hidden !important;
}
html.mobile body[data-mode="cinema"] .entity-popup video.popup-media {
  object-fit: cover !important;
  object-position: center !important;
}
html.mobile body[data-mode="cinema"] .entity-popup .popup-media-empty {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-family: var(--serif) !important;
  font-size: 32px !important;
  color: var(--gold-light) !important;
}

/* ② الجِسم النَّصّيّ (popup-body): يَأخُذ المُتَبَقّي */
html.mobile body[data-mode="cinema"] .entity-popup .popup-body {
  flex: 1 !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  gap: 3px !important;
  overflow: hidden !important;
  padding: 0 !important;
}

/* ③ الاسم — سَطر واحِد */
html.mobile body[data-mode="cinema"] .entity-popup .popup-name {
  font-size: 15px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  color: var(--paper) !important;
  margin: 0 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  font-family: var(--serif) !important;
}

/* ④ الوَصف الفَرعيّ — سَطر واحِد */
html.mobile body[data-mode="cinema"] .entity-popup .popup-sub {
  font-size: 11px !important;
  line-height: 1.3 !important;
  color: var(--gold-light) !important;
  font-style: italic !important;
  margin: 0 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

/* ⑤ الوَصف الكامِل — سَطران بحدٍّ أَقصى */
html.mobile body[data-mode="cinema"] .entity-popup .popup-desc {
  font-size: 11.5px !important;
  line-height: 1.45 !important;
  color: var(--paper-deep) !important;
  margin: 2px 0 0 !important;
  -webkit-line-clamp: 2 !important;
  line-clamp: 2 !important;
  display: -webkit-box !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
}

/* ⑥ إِخفاء العَناصِر الزَّائدة على الجَوّال (لتَوفير المِساحة) */
html.mobile body[data-mode="cinema"] .entity-popup .popup-tag,
html.mobile body[data-mode="cinema"] .entity-popup .popup-info,
html.mobile body[data-mode="cinema"] .entity-popup .popup-cta {
  display: none !important;
}

/* بَدَلاً عَنها: لَوحةٌ سُفليّة (Bottom Sheet) واحِدة مُوَحَّدة */
html.mobile body[data-mode="cinema"]::before {
  content: '';
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.85) 100%);
  pointer-events: none;
  z-index: 5;
}

/* لَوحةُ المَعلومات السُّفليّة الجَديدة (تُحقَن بـJS) */
html.mobile .m-bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--m-bg-sheet);
  border-top: 1px solid rgba(212, 168, 67, 0.25);
  border-radius: 18px 18px 0 0;
  z-index: 50;
  padding: 8px var(--m-pad) calc(8px + var(--m-safe-bottom));
  transition: transform 0.35s cubic-bezier(.4, 0, .2, 1);
  box-shadow: 0 -8px 28px rgba(0,0,0,0.4);
  max-height: var(--m-bottomsheet-h-expanded);
  overflow: hidden;
}

html.mobile .m-bottom-sheet-handle {
  width: 40px;
  height: 4px;
  background: rgba(212, 168, 67, 0.5);
  border-radius: 2px;
  margin: 0 auto 10px;
  cursor: pointer;
}

html.mobile .m-bottom-sheet-collapsed {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px 8px;
  cursor: pointer;
  min-height: 44px;
}
html.mobile .m-bs-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--blood), var(--gold-deep));
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--paper);
  font-size: 14px;
  border: 1px solid rgba(212, 168, 67, 0.5);
}
html.mobile .m-bs-text {
  flex: 1;
  min-width: 0;
}
html.mobile .m-bs-eyebrow {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--gold-light);
  text-transform: uppercase;
  margin-bottom: 1px;
}
html.mobile .m-bs-title {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 700;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
html.mobile .m-bs-toggle {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-light);
  font-size: 14px;
  background: transparent;
  border: none;
  transition: transform 0.3s;
}
html.mobile .m-bottom-sheet.expanded .m-bs-toggle {
  transform: rotate(180deg);
}

/* مُحتَوى اللَّوحة الكامِل (يَظهَر عِند التَّوسيع) */
html.mobile .m-bottom-sheet-content {
  display: none;
  padding: 8px 4px 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(var(--m-bottomsheet-h-expanded) - 80px);
}
html.mobile .m-bottom-sheet.expanded .m-bottom-sheet-content {
  display: block;
}

html.mobile .m-bs-section {
  margin-bottom: 14px;
}
html.mobile .m-bs-section:last-child { margin-bottom: 0; }
html.mobile .m-bs-section-title {
  font-family: var(--ui);
  font-size: 10px;
  letter-spacing: 0.25em;
  color: var(--gold-light);
  text-transform: uppercase;
  margin-bottom: 8px;
}
html.mobile .m-bs-desc {
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.7;
  color: var(--paper-deep);
  margin: 0;
}
html.mobile .m-bs-loc {
  font-family: var(--body);
  font-size: 11.5px;
  color: var(--gold-light);
  margin-top: 6px;
  font-style: italic;
}
html.mobile .m-bs-quote {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  line-height: 1.75;
  color: var(--paper);
  padding: 10px 14px;
  border-right: 2px solid var(--gold);
  background: rgba(212, 168, 67, 0.08);
  border-radius: 0 6px 6px 0;
  margin: 0 0 6px;
}
html.mobile .m-bs-quote-attr {
  font-family: var(--ui);
  font-size: 10px;
  color: var(--gold-light);
  letter-spacing: 0.15em;
  display: block;
  margin-top: 4px;
}

/* مُتَنَقِّل المَشاهد داخل اللَّوحة */
html.mobile .m-bs-scenes {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}
html.mobile .m-bs-scenes::-webkit-scrollbar { display: none; }
html.mobile .m-bs-scene-chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(212, 168, 67, 0.1);
  border: 1px solid rgba(212, 168, 67, 0.25);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: 0.1em;
  white-space: nowrap;
}
html.mobile .m-bs-scene-chip.active {
  background: var(--gold);
  color: var(--ink);
  border-color: var(--gold);
}

/* أَزرارُ المَوسيقى */
html.mobile .m-bs-music {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid rgba(212, 168, 67, 0.15);
  margin-top: 6px;
}
html.mobile .m-bs-music-info {
  flex: 1;
  min-width: 0;
}
html.mobile .m-bs-music-label {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--gold-light);
  text-transform: uppercase;
  margin-bottom: 1px;
}
html.mobile .m-bs-music-title {
  font-family: var(--serif);
  font-size: 12px;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html.mobile .m-bs-music-controls {
  display: flex;
  gap: 4px;
}
html.mobile .m-bs-music-btn {
  width: var(--m-touch);
  height: var(--m-touch);
  background: rgba(212, 168, 67, 0.12);
  border: 1px solid rgba(212, 168, 67, 0.3);
  border-radius: 50%;
  color: var(--paper);
  font-size: 13px;
}

/* إِخفاءُ مُشَغِّل المَوسيقى الأَصليّ على الجَوّال — تَمَّ دَمجُه باللَّوحة */
html.mobile .music-player {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٦. وَضعُ الفُصول (Chapter Open) — Slide-up Drawer
   ═══════════════════════════════════════════════════════════════════════ */

/* إِخفاء كل العَناصِر السينمائيّة في وَضع الفُصول */
html.mobile body.chapter-open .chapter-hud,
html.mobile body.chapter-open .scene-info,
html.mobile body.chapter-open .scene-quote,
html.mobile body.chapter-open .entity-popup,
html.mobile body.chapter-open .scene-bar,
html.mobile body.chapter-open .m-bottom-sheet {
  display: none !important;
}

/* حاوِيَة الفَصل */
html.mobile .content-host {
  position: fixed;
  inset: calc(var(--m-topbar-h) + var(--m-safe-top)) 0 0;
  background: var(--paper);
  z-index: 80;
  overflow: hidden;
}
html.mobile .content-host.open {
  animation: m-slide-up 0.35s cubic-bezier(.4, 0, .2, 1);
}
@keyframes m-slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

html.mobile .chapter-host {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px calc(80px + var(--m-safe-bottom));
  max-width: 100%;
}

/* رَأسُ الفَصل */
html.mobile .chapter-head {
  position: relative;
  flex-direction: column;
  gap: 6px;
  padding: 18px 16px;
  text-align: center;
  margin-bottom: 22px;
  border-radius: var(--m-radius);
  overflow: hidden;
}
html.mobile .chapter-roman {
  font-size: 28px;
  opacity: 0.4;
  order: -1;
}
html.mobile .chapter-eyebrow {
  font-size: 10px;
  letter-spacing: 0.3em;
  margin-bottom: 4px;
}
html.mobile .chapter-title {
  font-size: clamp(24px, 6.5vw, 34px);
  line-height: 1.15;
  margin-bottom: 4px;
}
html.mobile .chapter-sub {
  font-size: 12px;
  line-height: 1.5;
}
html.mobile .chapter-intro {
  font-size: 13px;
  line-height: 2;
  padding: 16px 18px;
  margin-bottom: 24px;
  border-radius: var(--m-radius);
}
html.mobile .section-hero-bg {
  aspect-ratio: 16/10;
  border-radius: var(--m-radius);
}

/* زِرّ "عُد للأَجواء" — أَيقونة دائريّة في أَسفَل اليَسار */
html.mobile body.chapter-open .back-to-cinema {
  display: flex !important;
  position: fixed;
  top: auto;
  bottom: calc(16px + var(--m-safe-bottom));
  left: 16px;
  right: auto;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
  align-items: center;
  z-index: 95;
  background: linear-gradient(135deg, rgba(122, 31, 24, 0.95), rgba(20, 12, 8, 0.95));
  box-shadow: 0 8px 24px rgba(0,0,0,0.5), 0 0 18px rgba(212, 168, 67, 0.3);
  border: 1px solid var(--gold);
}
html.mobile body.chapter-open .back-to-cinema span:not(.btc-icon) { display: none; }
html.mobile body.chapter-open .back-to-cinema .btc-icon {
  width: auto;
  height: auto;
  background: transparent;
  font-size: 18px;
  color: var(--paper);
}

/* ═══════════════════════════════════════════════════════════════════════
   ٧. مُرَشِّحُ الفِئات (Category chips)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .cat-filter {
  overflow-x: auto;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 4px 0;
  margin-bottom: 22px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 16px;
}
html.mobile .cat-filter::-webkit-scrollbar { display: none; }
html.mobile .cat-chip {
  flex-shrink: 0;
  font-size: 12px;
  padding: 9px 16px;
  letter-spacing: 0.05em;
  scroll-snap-align: start;
  min-height: 36px;
  border-radius: 20px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٨. شَبَكةُ البِطاقات (Card Grid)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .card-grid {
  grid-template-columns: 1fr !important;
  gap: 14px;
}

html.mobile .card {
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border-radius: var(--m-radius);
  background: var(--paper);
  box-shadow: 0 4px 14px rgba(40, 28, 12, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}
html.mobile .card:active {
  transform: scale(0.98);
}
html.mobile .card-media {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 16/10;
  position: relative;
  overflow: hidden;
}
html.mobile .card-media-video,
html.mobile .card-media img,
html.mobile .card-media > video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  object-position: center;
  display: block;
}
html.mobile .card-media-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 50%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
}
html.mobile .card-text {
  padding: 14px 16px 16px;
}
html.mobile .card-name {
  font-size: 19px;
  line-height: 1.2;
  margin-bottom: 4px;
}
html.mobile .card-sub {
  font-size: 12px;
  line-height: 1.4;
  margin-bottom: 8px;
}
html.mobile .card-desc {
  font-size: 12.5px;
  line-height: 1.7;
  -webkit-line-clamp: 3;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٩. المودال (Entity Modal) — Full-screen Sheet
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .modal-bg {
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
  background: rgba(0, 0, 0, 0.92);
}

html.mobile .modal-card {
  width: 100vw !important;
  height: 100dvh !important;
  max-width: 100vw !important;
  max-height: 100dvh !important;
  border-radius: 0;
  margin: 0;
  display: flex !important;
  flex-direction: column !important;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
  overflow: hidden;
  background: var(--paper);
}

/* أَزرارُ التَّحَكُّم — ثابِتة في الأَعلى */
html.mobile .modal-close {
  position: fixed;
  top: calc(12px + var(--m-safe-top));
  left: 12px;
  width: 44px;
  height: 44px;
  font-size: 24px;
  z-index: 220;
  background: rgba(10, 8, 6, 0.85);
  color: var(--paper);
  border-radius: 50%;
  border: 1px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
}

html.mobile .modal-edit-btn {
  position: fixed;
  top: calc(12px + var(--m-safe-top));
  right: 12px;
  width: 44px;
  height: 44px;
  z-index: 220;
  background: rgba(212, 168, 67, 0.95);
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* جانِبُ العَلاقات — مَخفيّ على الجَوّال */
html.mobile .modal-conn-side {
  display: none !important;
}

/* المُحتَوى الرَّئيسيّ */
html.mobile .modal-main {
  width: 100%;
  height: 100%;
  padding: calc(64px + var(--m-safe-top)) 18px calc(28px + var(--m-safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

/* البَطل (الصورة/الفيديو) */
html.mobile .modal-hero {
  width: 100%;
  aspect-ratio: 4/3 !important;
  max-height: 42vh;
  margin: 0 0 20px;
  border-radius: var(--m-radius);
  overflow: hidden;
  position: relative;
}
html.mobile .modal-hero img,
html.mobile .modal-hero video,
html.mobile video.modal-hero,
html.mobile .modal-hero-vid {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  display: block;
}

/* النُّصوص */
html.mobile .modal-eyebrow {
  font-size: 10px;
  letter-spacing: 0.3em;
  margin-bottom: 6px;
  color: var(--gold-deep);
}
html.mobile .modal-name {
  font-size: 26px;
  line-height: 1.15;
  margin-bottom: 6px;
}
html.mobile .modal-sub {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
  color: var(--gold-deep);
  font-style: italic;
}
html.mobile .modal-desc {
  font-size: 14px;
  line-height: 2;
  margin-bottom: 20px;
}

/* جَدول المَعلومات */
html.mobile .modal-info {
  padding: 14px 16px;
  margin-bottom: 18px;
  border-radius: var(--m-radius-sm);
  background: rgba(212, 168, 67, 0.08);
  border: 1px solid rgba(212, 168, 67, 0.2);
}
html.mobile .modal-info-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px dotted rgba(40, 28, 12, 0.1);
}
html.mobile .modal-info-row:first-child { padding-top: 0; }
html.mobile .modal-info-row:last-child { padding-bottom: 0; border-bottom: none; }
html.mobile .modal-info-key {
  font-size: 11.5px;
  flex-shrink: 0;
  font-weight: 700;
  color: var(--gold-deep);
  letter-spacing: 0.05em;
  min-width: 90px;
}
html.mobile .modal-info-val {
  font-size: 12.5px;
  text-align: left;
  line-height: 1.5;
  color: var(--ink);
}

/* الصِّفات */
html.mobile .modal-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
html.mobile .modal-trait {
  font-size: 11px;
  padding: 5px 11px;
  border-radius: 14px;
}

/* الاقتِباس */
html.mobile .modal-quote {
  padding: 14px 16px;
  margin: 18px 0;
  font-size: 14px;
  line-height: 2;
  border-radius: 8px;
}
html.mobile .modal-quote-attr {
  font-size: 11px;
  margin-top: 6px;
  display: block;
}

/* لَوحة التَّعديل */
html.mobile .modal-edit-panel {
  padding: 18px;
  border-radius: var(--m-radius);
  margin: 18px 0;
}
html.mobile .modal-edit-panel h4 {
  font-size: 15px;
  margin-bottom: 14px;
}
html.mobile .modal-edit-panel label {
  font-size: 11px;
  margin-bottom: 4px;
  display: block;
}
html.mobile .modal-edit-panel input,
html.mobile .modal-edit-panel textarea {
  font-size: 14px;
  padding: 10px 12px;
  width: 100%;
  margin-bottom: 12px;
}
html.mobile .modal-edit-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
html.mobile .modal-edit-actions button {
  width: 100%;
  padding: 12px;
  min-height: var(--m-touch);
  font-size: 13px;
}

/* العَلاقات داخِل المُحتَوى الرَّئيسيّ */
html.mobile .modal-main .modal-connections {
  margin-top: 24px;
  padding: 16px;
  background: rgba(212, 168, 67, 0.06);
  border-radius: var(--m-radius);
  border: 1px solid rgba(212, 168, 67, 0.15);
}
html.mobile .modal-main .modal-conn-heading {
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--gold-deep);
  margin-bottom: 10px;
}
html.mobile .modal-main .modal-conn-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
html.mobile .modal-main .modal-conn-item {
  font-size: 12px;
  padding: 8px 14px;
  background: var(--paper);
  border: 1px solid rgba(212, 168, 67, 0.3);
  border-radius: 18px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٠. شَجَرَةُ العائلة (Family Tree)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .family-tree {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px -16px;
  padding: 0 16px;
}
html.mobile .family-tree-svg,
html.mobile .family-tree svg {
  min-width: 600px;
  display: block;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١١. البَحثُ الشامِل (Search overlay)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .search-overlay {
  padding: 0;
  align-items: stretch;
  background: rgba(0, 0, 0, 0.92);
}
html.mobile .search-card {
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  border-radius: 0;
  padding: calc(16px + var(--m-safe-top)) 16px 16px;
  display: flex;
  flex-direction: column;
}
html.mobile .search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}
html.mobile .search-row input {
  font-size: 16px; /* مَنع zoom على iOS */
  padding: 12px 14px;
  flex: 1;
  border-radius: var(--m-radius-sm);
  min-height: var(--m-touch);
}
html.mobile .search-close {
  width: 44px;
  height: 44px;
  font-size: 24px;
  flex-shrink: 0;
  border-radius: 50%;
}
html.mobile .search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
html.mobile .search-result {
  padding: 14px;
  font-size: 13.5px;
  border-radius: var(--m-radius-sm);
  margin-bottom: 8px;
  min-height: 56px;
  display: flex;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٢. لايت بوكس الصُّوَر (Image Lightbox)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .lightbox {
  padding: calc(16px + var(--m-safe-top)) 14px calc(16px + var(--m-safe-bottom));
}
html.mobile .lightbox img {
  max-width: 100%;
  max-height: 80dvh;
  border-radius: var(--m-radius-sm);
}
html.mobile .lightbox-caption {
  font-size: 12.5px;
  padding: 10px 16px;
  margin-top: 12px;
  text-align: center;
}
html.mobile .lightbox-close {
  top: calc(14px + var(--m-safe-top));
  right: 14px;
  width: 44px;
  height: 44px;
  font-size: 24px;
  border-radius: 50%;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٣. الخَطُّ الزَّمَنيّ (Timeline)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .timeline-host {
  padding: 0;
  margin: 0;
  position: relative;
}
html.mobile .timeline-host::before {
  right: 14px;
  width: 2px;
}
html.mobile .timeline-event {
  padding: 14px 16px;
  margin-right: 30px;
  margin-bottom: 16px;
  border-radius: var(--m-radius);
  position: relative;
}
html.mobile .timeline-event::before {
  right: -22px;
  top: 18px;
  width: 14px;
  height: 14px;
  border-width: 3px;
}
html.mobile .timeline-year {
  font-size: 12px;
  padding: 4px 12px;
  margin-bottom: 8px;
  display: inline-block;
}
html.mobile .timeline-title {
  font-size: 17px;
  margin-bottom: 6px;
  line-height: 1.3;
}
html.mobile .timeline-desc {
  font-size: 12.5px;
  line-height: 1.75;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٤. المَسافات (Distances Atlas)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .distances-host {
  display: block !important;
  grid-template-columns: none !important;
}
html.mobile .distances-list {
  position: static;
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  margin-bottom: 18px;
  border-radius: var(--m-radius);
  background: rgba(212, 168, 67, 0.05);
  border: 1px solid rgba(212, 168, 67, 0.15);
}
html.mobile .dist-item {
  padding: 10px 14px;
  font-size: 12.5px;
  border-radius: 8px;
  min-height: 40px;
}
html.mobile .dist-content {
  padding: 0;
}
html.mobile .atlas-page-img,
html.mobile .dist-content img {
  width: 100% !important;
  border-radius: var(--m-radius);
  margin-bottom: 12px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٥. الأَلسنة (Languages)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .lang-search {
  padding: 14px;
  margin-bottom: 18px;
  border-radius: var(--m-radius);
  position: static !important; /* مَنعُ التَّمرير المُلاصِق */
}
html.mobile .lang-search input {
  font-size: 16px; /* مَنع zoom iOS */
  padding: 10px 0;
}
html.mobile .lang-search-stat { font-size: 11px; }
html.mobile .lang-result-group {
  padding: 14px;
  margin-bottom: 10px;
  border-radius: var(--m-radius-sm);
}
html.mobile .lang-result-row {
  flex-direction: row;
  gap: 8px;
  padding: 8px 0;
  font-size: 12.5px;
  flex-wrap: wrap;
}

html.mobile .lang-jump {
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}
html.mobile .lang-jump-btn {
  width: 100%;
  text-align: center;
  font-size: 12px;
  padding: 11px 14px;
  min-height: var(--m-touch);
}

html.mobile .tongue-block {
  padding: 18px 14px;
  border-radius: var(--m-radius);
  margin-bottom: 24px;
}
html.mobile .tongue-header {
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 16px;
}
html.mobile .tongue-glyph {
  width: 54px;
  height: 54px;
  font-size: 26px;
}
html.mobile .tongue-h { font-size: 24px; line-height: 1.2; }
html.mobile .tongue-tagline { font-size: 13px; }
html.mobile .tongue-traits { font-size: 12.5px; line-height: 1.75; }
html.mobile .tongue-flip-all {
  font-size: 11px;
  padding: 10px 16px;
  align-self: stretch;
  text-align: center;
  min-height: 40px;
}

html.mobile .vocab-section-title {
  font-size: 14px;
  margin: 20px 0 12px;
}
html.mobile .vocab-grid {
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 10px;
}

html.mobile .vocab-topic {
  padding: 14px;
  margin-bottom: 18px;
  border-radius: var(--m-radius-sm);
}
html.mobile .vocab-topic-title {
  font-size: 14px;
  margin-bottom: 12px;
}
html.mobile .vocab-topic-icon {
  width: 30px;
  height: 30px;
  font-size: 15px;
}
html.mobile .vocab-topic-count {
  font-size: 10px;
  padding: 2px 9px;
}

/* بِطاقات قَلب — دَقيقة على الجَوّال */
html.mobile .flashcard {
  height: 90px;
  perspective: 1000px;
}
html.mobile .flashcard-face {
  padding: 10px;
  border-radius: var(--m-radius-sm);
}
html.mobile .flashcard .vocab-ar {
  font-size: 15px !important;
  font-weight: 700;
  line-height: 1.2;
}
html.mobile .flashcard .vocab-trans {
  font-size: 14px !important;
  line-height: 1.2;
}
html.mobile .flashcard-back .vocab-latin {
  font-size: 9.5px;
  letter-spacing: 0.05em;
}
html.mobile .flashcard-back .vocab-star {
  font-size: 9px;
  padding: 1px 6px;
}
html.mobile .flashcard-hint { font-size: 8.5px; }

/* أَمثلة */
html.mobile .examples-host { gap: 10px; }
html.mobile .example-card {
  padding: 14px 16px;
  border-radius: var(--m-radius-sm);
}
html.mobile .example-trans { font-size: 13.5px; line-height: 1.85; }
html.mobile .example-ar { font-size: 11.5px; }

/* جَدول حَجَر الرَّشيد */
html.mobile .rosetta-block {
  padding: 14px;
  border-radius: var(--m-radius);
}
html.mobile .rosetta-title {
  font-size: 16px;
  margin-bottom: 10px;
}
html.mobile .rosetta-table {
  font-size: 11.5px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
  border-radius: 8px;
}
html.mobile .rosetta-table th,
html.mobile .rosetta-table td {
  padding: 8px 10px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٦. النارفوند (Narfund Codex)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .narfund-codex {
  display: block !important;
  grid-template-columns: none !important;
}
html.mobile .codex-pages-list {
  position: static;
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  border-radius: var(--m-radius);
  margin-bottom: 18px;
  background: rgba(212, 168, 67, 0.05);
  border: 1px solid rgba(212, 168, 67, 0.15);
}
html.mobile .codex-page-btn {
  padding: 10px 14px;
  font-size: 12.5px;
  gap: 8px;
  min-height: 40px;
}
html.mobile .codex-page-num {
  font-size: 11px;
  min-width: 26px;
}
html.mobile .codex-content {
  padding: 18px;
  border-radius: var(--m-radius);
}
html.mobile .codex-content img {
  width: 100%;
  border-radius: var(--m-radius-sm);
  margin-bottom: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٧. الشَّعارات (Crests)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .crest-group {
  margin-bottom: 28px;
}
html.mobile .crest-group-title {
  font-size: 17px;
  margin-bottom: 16px;
  padding-bottom: 12px;
}
html.mobile .crest-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
html.mobile .crest-card {
  padding: 14px 12px;
  border-radius: var(--m-radius);
}
html.mobile .crest-frame {
  aspect-ratio: 1;
  margin-bottom: 12px;
}
html.mobile .crest-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
html.mobile .crest-name {
  font-size: 13.5px;
  margin-bottom: 3px;
  line-height: 1.2;
}
html.mobile .crest-sub {
  font-size: 10.5px;
  margin-bottom: 8px;
  line-height: 1.3;
}
html.mobile .crest-note {
  font-size: 11.5px;
  line-height: 1.65;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٨. رِحلةُ الرفقة (Journey)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .js-trail {
  position: fixed;
  top: auto;
  bottom: calc(76px + var(--m-safe-bottom));
  right: 50%;
  transform: translateX(50%);
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  max-width: calc(100vw - 100px);
  max-height: none;
  padding: 8px 12px;
  border-radius: 28px;
  scrollbar-width: none;
  background: rgba(10, 8, 6, 0.92);
  border: 1px solid rgba(212, 168, 67, 0.3);
  z-index: 90;
}
html.mobile .js-trail::-webkit-scrollbar { display: none; }
html.mobile .js-trail-dot {
  width: 32px;
  height: 32px;
  font-size: 11px;
  flex-shrink: 0;
}
html.mobile .js-trail-dot-label { display: none; }

html.mobile .js-scenes {
  margin-bottom: 90px;
}
html.mobile .js-scene {
  min-height: 75dvh;
  margin-bottom: 22px;
  border-radius: var(--m-radius);
}
html.mobile .js-scene-frame {
  padding: 22px 16px 26px;
}
html.mobile .js-scene-header {
  margin-bottom: 8px;
}
html.mobile .js-scene-num,
html.mobile .js-scene-eyebrow {
  font-size: 10px;
  padding: 5px 12px;
  letter-spacing: 0.2em;
}
html.mobile .js-scene-title-block {
  margin-top: 10px;
}
html.mobile .js-scene-title {
  font-size: clamp(24px, 7.5vw, 36px);
  line-height: 1.1;
}
html.mobile .js-scene-subtitle {
  font-size: 13px;
}

/* الكَيانات الطّافية مَخفيّة */
html.mobile .js-chips { display: none !important; }

html.mobile .js-scene-quote {
  padding: 16px 18px;
  margin: 16px auto 12px;
  border-radius: 8px;
}
html.mobile .js-quote-text {
  font-size: 13.5px;
  line-height: 1.95;
}
html.mobile .js-quote-attr { font-size: 10.5px; }

html.mobile .js-scene-card {
  padding: 16px;
  margin: 0 auto;
  border-radius: var(--m-radius);
}
html.mobile .js-scene-desc {
  font-size: 13.5px;
  line-height: 1.95;
  margin-bottom: 12px;
}
html.mobile .js-scene-cta {
  font-size: 11px;
  padding: 11px 18px;
  letter-spacing: 0.15em;
  min-height: var(--m-touch);
}

html.mobile .js-scene-next {
  font-size: 11px;
  padding: 11px 20px;
  letter-spacing: 0.1em;
  margin: 16px auto 0;
  min-height: var(--m-touch);
}
html.mobile .js-next-arrow { font-size: 16px; }

html.mobile .js-hotspot {
  width: 40px;
  height: 40px;
}
html.mobile .js-hotspot-icon {
  width: 26px;
  height: 26px;
  font-size: 13px;
}

html.mobile .js-reveal-panel {
  width: 92%;
  padding: 14px;
  flex-direction: row;
  gap: 12px;
  border-radius: var(--m-radius);
}
html.mobile .js-reveal-img {
  width: 90px;
  flex-shrink: 0;
  border-radius: var(--m-radius-sm);
}
html.mobile .js-reveal-body {
  padding-top: 28px;
}
html.mobile .js-reveal-name { font-size: 17px; }
html.mobile .js-reveal-label {
  font-size: 9.5px;
  letter-spacing: 0.25em;
}
html.mobile .js-reveal-sub { font-size: 11.5px; }
html.mobile .js-reveal-open {
  font-size: 10px;
  padding: 8px 14px;
  letter-spacing: 0.15em;
  min-height: 36px;
}
html.mobile .js-reveal-close {
  width: 30px;
  height: 30px;
  font-size: 18px;
  top: 8px;
  left: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ١٩. الخَرائط (Maps)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .maps-cinematic {
  aspect-ratio: 4/3;
  border-radius: var(--m-radius);
  margin-bottom: 26px;
}
html.mobile .maps-cinematic-text {
  right: 16px;
  left: 16px;
  bottom: 16px;
}
html.mobile .maps-cinematic-eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.3em;
  margin-bottom: 6px;
}
html.mobile .maps-cinematic-title {
  font-size: 24px;
  margin-bottom: 6px;
}
html.mobile .maps-cinematic-sub {
  font-size: 12px;
  line-height: 1.7;
}

html.mobile .maps-grid {
  grid-template-columns: 1fr;
  gap: 18px;
}
html.mobile .map-card {
  border-radius: var(--m-radius);
}
html.mobile .map-card-frame {
  aspect-ratio: 4/3;
}
html.mobile .map-card-img {
  object-fit: contain;
  background: linear-gradient(135deg, #2a1810, #4a2818);
}
html.mobile .map-card-overlay {
  top: 10px;
  left: 10px;
  gap: 8px;
}
html.mobile .map-card-zoom,
html.mobile .map-card-download {
  width: 40px;
  height: 40px;
  font-size: 16px;
}
html.mobile .map-card-text {
  padding: 16px;
}
html.mobile .map-card-title {
  font-size: 19px;
  margin-bottom: 3px;
}
html.mobile .map-card-sub {
  font-size: 12px;
  margin-bottom: 8px;
}
html.mobile .map-card-meta {
  margin: 8px 0 12px;
  font-size: 11.5px;
  flex-wrap: wrap;
}
html.mobile .map-card-artist {
  font-size: 10.5px;
  padding: 4px 10px;
}
html.mobile .map-card-era {
  font-size: 10.5px;
}
html.mobile .map-card-scroll {
  font-size: 12.5px;
  line-height: 1.95;
  padding: 12px 14px;
}

/* لايت بوكس الخَرائط */
html.mobile .map-lightbox {
  padding: calc(60px + var(--m-safe-top)) 10px calc(14px + var(--m-safe-bottom));
}
html.mobile .map-lightbox-close {
  top: calc(14px + var(--m-safe-top));
  left: 14px;
  width: 44px;
  height: 44px;
  font-size: 24px;
  border-radius: 50%;
}
html.mobile .map-lightbox-title {
  font-size: 16px;
  margin-bottom: 10px;
}
html.mobile .map-lightbox-img,
html.mobile .map-lightbox-frame {
  max-height: calc(100dvh - 110px);
  border-radius: var(--m-radius);
  background: linear-gradient(135deg, #2a1810, #4a2818);
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٠. المَلحمة (Epic — Books)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .epic-shelf {
  display: flex !important;
  flex-direction: column;
  grid-template-columns: none !important;
  gap: 32px;
  margin-bottom: 90px;
}
html.mobile .epic-book {
  display: block !important;
  grid-template-columns: none !important;
}
html.mobile .book-cover {
  aspect-ratio: 2/3;
  max-width: 230px;
  margin: 0 auto 20px;
}
html.mobile .book-cover-overlay {
  padding: 30px 20px;
}
html.mobile .book-roman {
  font-size: 9.5px;
  margin-bottom: 8px;
}
html.mobile .book-saga {
  font-size: 12.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
}
html.mobile .book-title {
  font-size: 24px;
  line-height: 1.15;
}

html.mobile .book-meta {
  padding: 0 4px;
}
html.mobile .book-status {
  font-size: 10.5px;
  padding: 4px 12px;
  margin-bottom: 12px;
  display: inline-block;
}
html.mobile .book-saga-line {
  font-size: 11.5px;
  border-right: 2px solid var(--gold);
  padding-right: 10px;
  margin-bottom: 6px;
}
html.mobile .book-name {
  font-size: 23px;
  margin-bottom: 6px;
  line-height: 1.2;
}
html.mobile .book-sub {
  font-size: 13px;
  margin-bottom: 4px;
}
html.mobile .book-pages {
  font-size: 11.5px;
  margin-bottom: 14px;
}
html.mobile .book-pitch {
  font-size: 13.5px;
  line-height: 1.95;
  margin-bottom: 14px;
}
html.mobile .book-arc {
  font-size: 12.5px;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
}
html.mobile .book-quote {
  font-size: 13.5px;
  padding: 12px 16px;
  line-height: 1.85;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢١. الأَجواءُ السينمائيّة (Cinema browser)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .scenes-grid {
  grid-template-columns: 1fr;
  gap: 14px;
}
html.mobile .scene-card {
  padding: 16px;
  border-radius: var(--m-radius);
  min-height: 64px;
}
html.mobile .scene-card-title {
  font-size: 17px;
  margin-bottom: 4px;
}
html.mobile .scene-card-sub {
  font-size: 12.5px;
  margin-bottom: 8px;
}
html.mobile .scene-card-meta { font-size: 10.5px; }

html.mobile .video-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
html.mobile .video-thumb {
  border-radius: var(--m-radius-sm);
  overflow: hidden;
}
html.mobile .video-thumb video {
  aspect-ratio: 16/10;
  width: 100%;
  height: auto;
}
html.mobile .video-thumb-name {
  font-size: 10.5px;
  padding: 8px 10px;
  line-height: 1.3;
}

html.mobile .album-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
html.mobile .album-tile {
  border-radius: var(--m-radius-sm);
  overflow: hidden;
}
html.mobile .album-tile img {
  aspect-ratio: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٢. هامِشُ الكاتب (Notes)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .notes-host {
  display: block !important;
  grid-template-columns: none !important;
}
html.mobile .notes-list {
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  margin-bottom: 18px;
}
html.mobile .notes-add-btn {
  width: 100%;
  padding: 13px;
  font-size: 13px;
  margin-bottom: 14px;
  min-height: var(--m-touch);
}
html.mobile .notes-meta {
  padding: 18px;
  border-radius: var(--m-radius);
}
html.mobile .notes-meta input,
html.mobile .notes-meta textarea {
  font-size: 16px; /* مَنع zoom iOS */
  padding: 11px 14px;
  width: 100%;
  margin-bottom: 12px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٣. شارةُ الأَدمن
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .admin-badge {
  bottom: calc(80px + var(--m-safe-bottom));
  right: 14px;
  font-size: 9.5px;
  padding: 5px 12px;
  letter-spacing: 0.2em;
}
html.mobile body.chapter-open .admin-badge {
  bottom: calc(20px + var(--m-safe-bottom));
  right: 80px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٤. حدّادو أَفالون / مَمالك النارفوند ضِمن الشَّعارات
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .smiths-grid {
  grid-template-columns: 1fr !important;
  gap: 16px;
}
html.mobile .narfund-realms {
  grid-template-columns: 1fr;
  gap: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٥. نَموذجُ تَفعيل المُدير
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile .admin-only {
  /* لا يُؤَثِّر — تَبقى قَواعِد الإِخفاء كَما هي */
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٦. تَوازُنُ الفَيديو في البِطاقات (لمَنع تَقَلُّب صُوَر)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile video {
  background: #1a1410;
}
html.mobile img {
  background: rgba(40, 28, 12, 0.05);
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٧. إِخفاءُ السَّكرول بار في عَناصِر التَّمرير الأُفُقيّ
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile [data-mobile-hscroll]::-webkit-scrollbar { display: none; }
html.mobile [data-mobile-hscroll] { scrollbar-width: none; }

/* ═══════════════════════════════════════════════════════════════════════
   ٢٨. وَضعُ الشاشة الأَفُقيّ (Landscape) على الجَوّال
   ═══════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) and (orientation: landscape) {
  html.mobile .opener-frame {
    max-height: 90dvh;
    overflow-y: auto;
    padding: 18px 22px;
  }
  html.mobile .opener-title { font-size: 38px; margin-bottom: 4px; }
  html.mobile .opener-sub { font-size: 13px; margin-bottom: 12px; }
  html.mobile .opener-legend { font-size: 11.5px; padding: 10px 14px; margin-bottom: 14px; }
  html.mobile .opener-actions { flex-direction: row; }
  html.mobile .opener-btn { padding: 10px 16px; }

  html.mobile .modal-hero {
    max-height: 50dvh;
    aspect-ratio: 16/9 !important;
  }

  html.mobile .js-scene { min-height: 100dvh; }
}

/* ═══════════════════════════════════════════════════════════════════════
   ٢٩. شاشاتٌ صَغيرةٌ جدّاً (≤ ٣٨٠px)
   ═══════════════════════════════════════════════════════════════════════ */
html.mobile-sm .opener-title { font-size: 36px; }
html.mobile-sm .nav-btn { min-width: 50px; padding: 4px 8px; }
html.mobile-sm .nav-btn span { font-size: 8.5px; }
html.mobile-sm .modal-name { font-size: 22px; }
html.mobile-sm .modal-desc { font-size: 13px; }
html.mobile-sm .vocab-grid { grid-template-columns: 1fr !important; }
html.mobile-sm .crest-grid,
html.mobile-sm .album-grid,
html.mobile-sm .video-grid {
  grid-template-columns: 1fr;
}
html.mobile-sm .chapter-title { font-size: 22px; }
html.mobile-sm .js-scene-title { font-size: 22px; }
html.mobile-sm .map-card-title { font-size: 17px; }
html.mobile-sm .timeline-title { font-size: 15px; }

/* ════════════════════════════════════════════════════════════════════════
   ٣٠. تَحسينُ الأَداء الشامِل — مُكافحةُ اللاج بدون حَذف عَناصِر
   ════════════════════════════════════════════════════════════════════════
   تَقنيّاتٌ مُتَقَدِّمة:
   • content-visibility: auto  → المُتَصَفِّح يَتَخَطّى رَسم العَناصِر خارج الشاشة
   • contain: layout paint    → يَحصُر إعادة الرَّسم داخل العَنصُر فَقَط
   • will-change: transform    → فَقَط للعَناصِر النَّشِطة
   • -webkit-transform: translateZ(0) → طَبَقة GPU مُنفَصِلة
   ════════════════════════════════════════════════════════════════════════ */

/* ─── أ. تَخَطِّي رَسم العَناصِر خارِج الشاشة ─── */
/* مُلاحَظة: لا نُطَبِّقها على البِطاقات التي تَحوي فيديو (تُؤَخِّر تَحميله) */
html.mobile .crest-card,
html.mobile .timeline-event,
html.mobile .vocab-topic,
html.mobile .codex-content,
html.mobile .example-card,
html.mobile .crest-group,
html.mobile .lang-result-group,
html.mobile .flashcard {
  content-visibility: auto;
  contain-intrinsic-size: auto 280px;
}

/* أَحجامٌ مُتَوَقَّعة للحِفاظ على مَكان التَّمرير */
html.mobile .timeline-event { contain-intrinsic-size: auto 140px; }
html.mobile .flashcard { contain-intrinsic-size: auto 84px; }
html.mobile .crest-card { contain-intrinsic-size: auto 220px; }

/* ─── ب. حَصرُ تَأثير إِعادة الرَّسم (Repaint Containment) ─── */
html.mobile .card,
html.mobile .map-card,
html.mobile .crest-card,
html.mobile .modal-card,
html.mobile .opener-frame,
html.mobile .js-scene,
html.mobile .epic-book {
  contain: layout paint;
}

/* ─── ج. طَبَقة GPU للفيديو السينمائيّ النَّشِط فَقَط ─── */
html.mobile .cinema-frame.active {
  will-change: opacity;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}
/* لا display:none للإِطارات غَير النَّشِطة — تَأثير التَّلاشي يَحتاجها */
html.mobile .cinema-frame:not(.active) {
  will-change: auto;
}

/* ─── د. تَخفيفُ الظِّلال على الجَوّال ─── */
html.mobile .card { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
html.mobile .card:active { box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
html.mobile .map-card,
html.mobile .crest-card { box-shadow: 0 2px 6px rgba(40,28,12,0.1); }
html.mobile .modal-card { box-shadow: none; }

/* ─── هـ. تَعطيلُ تَحريكات غَير ضَروريّة ─── */
html.mobile .cinema-overlay,
html.mobile .opener-bg,
html.mobile .cinema-grain,
html.mobile .cinema-vignette {
  animation: none !important;
  transition: none !important;
}

/* تَخفيفُ تَحريك الانتِقال بَين المَشاهد السينمائيّة */
html.mobile .cinema-frame {
  transition: opacity 0.6s ease !important;
  animation: none !important;
}
html.mobile .cinema-frame.transition-pan,
html.mobile .cinema-frame.transition-zoom-in,
html.mobile .cinema-frame.transition-zoom-out,
html.mobile .cinema-frame.transition-drift-r,
html.mobile .cinema-frame.transition-drift-l {
  transform: none !important;
  animation: none !important;
}

/* ─── و. تَنعيمُ التَّمرير ─── */
html.mobile .chapter-host,
html.mobile .modal-main,
html.mobile .search-results,
html.mobile .codex-pages-list,
html.mobile .distances-list,
html.mobile .notes-list,
html.mobile .m-bottom-sheet-content {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ─── ز. تَأخيرُ الرَّسم للعَناصِر ذات الأَولويّة المُنخَفِضة ─── */
html.mobile .album-grid img,
html.mobile .video-grid video,
html.mobile .crest-img {
  content-visibility: auto;
  contain-intrinsic-size: auto 200px;
}

/* ─── ح. الفيديو في البِطاقات — يَستَخدِم poster + preload فَقَط عِند الحاجة ─── */
html.mobile video {
  background-color: #1a1410;
  background-size: cover;
  background-position: center;
}

/* ─── ط. تَخفيفُ التَّمرير الأُفُقيّ في القائمة العَلويّة ─── */
html.mobile .topbar-nav {
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
}

/* ─── ي. تَحسينُ الإِطارات بَعد فَتح/إِغلاق الفُصول ─── */
html.mobile .content-host {
  contain: layout paint;
}
html.mobile .modal-bg {
  contain: layout paint;
}

/* ─── ك. الصُّوَر — تَحسينُ تَحميلها ─── */
html.mobile img {
  image-rendering: auto;
}
html.mobile .card-media-still,
html.mobile .crest-img,
html.mobile .map-card-img {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* ─── ل. تَجنُّبُ إِعادة الرَّسم عِند التَّمرير ─── */
html.mobile .topbar,
html.mobile .m-bottom-sheet,
html.mobile body.chapter-open .back-to-cinema {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform;
}

/* ─── م. تَقليلُ تأثير backdrop خارج الجَوّال (مَوجود بالفِعل لكن للتَّأكيد) ─── */
html.mobile .topbar,
html.mobile .m-bottom-sheet,
html.mobile .chapter-hud,
html.mobile .scene-info,
html.mobile .entity-popup,
html.mobile .music-player,
html.mobile .modal-bg,
html.mobile .search-overlay,
html.mobile .lightbox {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* ─── ن. تَحسينُ التَّحريكات — استَخدِم transform و opacity فَقَط ─── */
html.mobile * {
  /* لا تَستَخدِم transition على خَصائص ثَقيلة */
}
html.mobile .modal-bg,
html.mobile .search-overlay,
html.mobile .lightbox,
html.mobile .map-lightbox {
  transition: opacity 0.3s ease !important;
}

/* ─── س. عَدَمُ تَخصيص will-change لكل شَيء (سَيَستَهلِك ذاكِرة) ─── */
html.mobile *:not(.cinema-frame.active):not(.topbar):not(.m-bottom-sheet) {
  will-change: auto;
}
