/* ============================================================================
   Exam Codifica Hub - the phone layer.

   Loaded LAST on every page, so these rules land after theme.css and can answer
   it. Everything here is either a phone-only correction or a reservation of
   space that the fixed bars were never given, which is why they sit on top of
   the footer on a small screen.

   Three real causes are addressed, not guessed:
     1. 100vh on a phone is the height of the viewport WITH the browser bars
        hidden, so a min-height:100vh page is taller than what is on screen and
        its last rows end up underneath the fixed bottom bar. dvh is the height
        that is actually visible.
     2. A fixed bar paints over the content unless the content reserves room
        for it - including the home indicator strip on a modern iPhone, which
        is what env(safe-area-inset-bottom) measures.
     3. A phone turned sideways has very little height and plenty of width, so
        the same paddings and the same stacked header waste half of it.
   ========================================================================= */

/* ------------------------------------------------------------- 1 · dynamic height */
.min-h-screen { min-height: 100dvh !important; }
html { height: -webkit-fill-available; }

/* --------------------------------------------------- 2 · room for the fixed bars */
:root {
  --pt-bottombar: 62px;
  --pt-topbar: 56px;
  --pt-safe-b: env(safe-area-inset-bottom, 0px);
  --pt-safe-t: env(safe-area-inset-top, 0px);
  --pt-safe-l: env(safe-area-inset-left, 0px);
  --pt-safe-r: env(safe-area-inset-right, 0px);
}

/* pages that carry the rights bar / footer reserve its height plus the danger
   strip; the pages that opt out with data-no-rights-bar say so themselves */
body { padding-bottom: calc(var(--pt-bottombar) + var(--pt-safe-b)) !important; }
body[data-no-rights-bar="1"] { padding-bottom: var(--pt-safe-b) !important; }

/* the fixed bars themselves never sit inside the danger strip */
.platform-rights-bar,
.platform-footer,
body > footer,
footer.platform-footer {
  padding-bottom: calc(6px + var(--pt-safe-b)) !important;
  padding-left: max(10px, var(--pt-safe-l));
  padding-right: max(10px, var(--pt-safe-r));
}

/* the sticky top bar gets the notch strip, and the page starts below it */
.exam-header,
.sticky-actions,
header.exam-header {
  padding-top: calc(var(--pt-safe-t) + 6px) !important;
  padding-left: max(12px, var(--pt-safe-l));
  padding-right: max(12px, var(--pt-safe-r));
}

/* a last child that would otherwise hide behind the bar */
main > *:last-child,
.container > *:last-child { scroll-margin-bottom: 90px; }

/* ------------------------------------------------------------ 3 · the phone itself */
@media (max-width: 820px) {
  /* iOS zooms the whole page when a field smaller than 16px takes focus */
  input, select, textarea { font-size: 16px !important; }

  /* a table that does not fit scrolls sideways instead of pushing the layout */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  table thead, table tbody { display: table; width: 100%; }

  main, .container, .wrap { padding-left: max(12px, var(--pt-safe-l)) !important;
                            padding-right: max(12px, var(--pt-safe-r)) !important; }

  /* tap targets a thumb can actually hit */
  button, .btn, a.btn, [role="button"] { min-height: 44px; }
  .icon-only-btn { min-width: 44px; min-height: 44px; }

  /* the exam window: the question is the page, everything else steps back */
  #exam .question, .exam-question { font-size: 1.06rem; line-height: 1.9; }
  .exam-modal-overlay, .modal-overlay, .overlay { padding: 0 !important; align-items: flex-end !important; }
  .exam-modal, .modal { max-height: 92dvh; overflow-y: auto; border-radius: 14px 14px 0 0; width: 100%; }
}

/* ------------------------------------------------------------ 4 · held sideways */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --pt-bottombar: 46px; --pt-topbar: 44px; }

  .exam-header, .sticky-actions, header.exam-header {
    padding-top: max(4px, var(--pt-safe-t)) !important;
    padding-bottom: 4px !important;
    font-size: .92rem;
  }
  .exam-header-status { gap: .5rem !important; }

  main, .container, .wrap { padding-top: .6rem !important; padding-bottom: .6rem !important; }

  /* side by side is the whole point of this orientation */
  .grid, .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr 1fr !important; }
  .exam-modal, .modal { max-height: 96dvh; border-radius: 10px; }

  h1 { font-size: 1.25rem !important; }
  h2 { font-size: 1.05rem !important; }
  .mb-8 { margin-bottom: .9rem !important; }
  .p-8 { padding: .9rem !important; }
}

/* ------------------------------------------------------------ 5 · full screen button */
.pt-fs-btn {
  position: fixed;
  z-index: 2147483000;                 /* above the app's own overlays */
  /* __FS_SIDE__ ⚠ كان على inset-inline-START وهي اليمين في العربية — وهو الموضع
     الذي تقف فيه القائمة الجانبية (right: 0 · z-index: 900). و z-index الزرّ أكبر
     بمراتب، فهو **يرسم فوق القائمة** ويغطّي طرف صفٍّ فيها (قيست المساحة ٣٣×٣٣ بكسل).
     فصار على اليسار حيث زرّ الوضع أصلًا، **ومرفوعًا فوقه** فلا يتزاحمان — وهما
     اللذان قيل في تعليق سابق إنهما «قيسا فوق بعضهما». */
  inset-inline-start: auto;
  inset-inline-end: max(10px, var(--pt-safe-l));
  bottom: calc(var(--pt-bottombar) + var(--pt-safe-b) + 10px);
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  height: 40px;
  padding: 0 .7rem;
  border: 1px solid rgba(201, 162, 74, .55);
  border-radius: 999px;
  background: rgba(20, 8, 11, .82);
  color: #F6EFE2;
  font: 600 .78rem/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  opacity: .92;
}
/* حلقة التركيز هنا كانت غير مرئية: --pt-safe-l قيمة طول (env(safe-area-inset-left))،
   واستعمالها لونًا يجعل التصريح باطلًا عند الحساب، والاحتياطي لا يُفعَّل عند فساد
   القيمة بل عند غيابها. ويُسقط التصريحُ الفائز تصريحَ outline العام معه. */
.pt-fs-btn:hover { opacity: 1; }
.pt-fs-btn:focus-visible { opacity: 1; outline: 2px solid var(--primary, #c8283a); outline-offset: 2px; }
.pt-fs-btn svg { width: 16px; height: 16px; }
.pt-fs-btn .lbl { white-space: nowrap; }

/* while the window is genuinely full screen there is no bar to clear.
   __FS_STACK__ ⚠ **ولا يُنسى الرفع هنا أيضًا**: القاعدة العامة رُفعت ٦٦ بكسل،
   وهذه القاعدة الخاصة **تغلبها** — فقيس الزرّ في ملء الشاشة عند ١١.٦٧ بكسل
   وتراكب مع زرّ الوضع. **ورفعُ قيمة في القاعدة العامة لا يكفي إذا كان للعنصر
   حالة خاصة تغلبها.** فيُثبَّت الترتيب في كل الحالات. */
:fullscreen .pt-fs-btn, :-webkit-full-screen .pt-fs-btn { bottom: calc(10px + var(--pt-safe-b)); }

/* a phone held sideways has no room for the label */
@media (orientation: landscape) and (max-height: 540px) {
  .pt-fs-btn .lbl { display: none; }
  .pt-fs-btn { bottom: calc(var(--pt-bottombar) + var(--pt-safe-b) + 6px); }
}

@media print { .pt-fs-btn { display: none !important; } }

/* ============================================================================
   شريط الحقوق على الجوال — عطلان مقيسان، لا مُفترَضان
   ============================================================================
   قِيس على ٣٧٥ بكسل داخل outcomes.html:

     barRect.h = 54   bodyPadBottom = 36   ⟶ نقص ١٨ بكسل من المحتوى المحجوب
     overlaps  = platform-rights-text ~ codifica-brand → 98×13 بكسل
     brandPosition = absolute

   ▸ الأوّل: «Exam Codifica Hub» مُعرَّف في theme.css بـ`position: absolute; left: 50%` متمركزًا
     فوق الشريط كله. وعلى الشاشات العريضة لا يضرّ: نصّ الحقوق يُحاذى يمينًا وسطر الشكر
     يسارًا، والوسط فارغ. أمّا قاعدة الجوال في offline.css فتُوسّط النصّين — فيمتدّ النصّ
     تحت العلامة المتمركزة ويتقاطعان. فتُخرج العلامة من الطيّ إلى صفّها الأوّل.
   ▸ والثاني: الشريط مثبَّت أسفل الشاشة، والمحجوز للجسم ٢٫٢٥rem = ٣٦ بكسل، وارتفاعه عند
     الجوال ٥٤ بكسل — فتختفي آخر ١٨ بكسل من المحتوى تحته بلا أثر ظاهر.

   وكلاهما شاشة الجوال وحدها، فالتعديل محصور في مدى ≤ ٦٤٠ بكسل ولا يمسّ سطح المكتب.

   ⚠ ودقّة في القياس لازمة هنا: مستطيل **العنصر** يتراكب على سطح المكتب أيضًا (٤١×١٣ مقيسة،
   لأن نصّ الحقوق يأخذ نصف الشريط ونصّ الشكر نصفه، فيغطّي الوسط وهما فارغاه في المحاذاة).
   والذي يجب قياسه مستطيل **النصّ** لا العنصر — يُقاس بـRange على عقدة النصّ. وبذلك:
       سطح المكتب: تراكب النصّ ‎(none)‎ — والوسط فارغ فعلًا، والعلامة تتمركز فيه.
       الجوال:      تراكب العنصر ٩٨×١٣ والنصّ متمركز تحته — وهو التراكب المرئي فعلًا.
   فلو حُكم بالمستطيل وحده لَعُدّ سطح المكتب معطوبًا وهو سليم، أو لَعُدّ الجوال سليمًا وهو معطوب.
   ============================================================================ */
@media (max-width: 640px) {
  /* ⚠ قِيس بعد أوّل محاولة: إخراج العلامة إلى صفّها أزال التراكب **لكنه** رفع الشريط
     من ٥٤ إلى ٧٢ بكسل، فبقي نقص ٨ بكسل في المساحة المحجوزة — أي أن علاج العطل الأوّل
     أنتج عطلًا ثانيًا. والقياس هو ما أظهر ذلك، لا النظر.
     وعلى ٣٧٥ بكسل لا يوجد مجال للعلامة: نصّ الحقوق متمركز بعرض الشريط كله، وسطر الشكر
     تحته، فلا مكان لجانب. وإبقاؤها يعني صفًّا ثالثًا يأكل ١٨ بكسل من ارتفاع الشاشة.
     والاسم غير مفقود عند إخفائها: سطر الحقوق نفسه يبدأ بـ«© Exam Codifica Hub».
     فتُخفى هنا وتبقى في سطح المكتب كعلامة زخرفية متمركزة. */
  .codifica-brand { display: none !important; }
  /* ٤rem = ٦٤ بكسل مقابل شريط من صفّين ارتفاعه ٥٤ ⟶ ١٠ بكسل هامش للأمان */
  body.has-rights-bar { padding-bottom: 4rem !important; }
}


/* ── أهداف اللمس على الجوّال ──────────────────────────────────────────────
   WCAG 2.5.8 (AA) يطلب ٢٤×٢٤ بكسل CSS. ولم يُغيَّر صندوق أي عنصر ولا تخطيطه:
   توسيع **منطقة الإصابة** بطبقة شفّافة فوقه — فلا يتزحزح شيء، ولا يتقاطع هدفان.
   (وأزرار القشرة الأيقونية لم تُوسَّع عمدًا: المسافة المقيسة بينها ٤ بكسل، فأي
   توسيع يتقاطع فيسرق اللاحقُ لمسةَ السابق — وذلك أسوأ من هدف صغير.) */
.credit-wa, .back-link, .guide-narration summary, label[for="rememberUsername"] { position: relative; }
.credit-wa::after { content: ''; position: absolute; inset: -3px; }
.back-link::after, label[for="rememberUsername"]::after {
    content: ''; position: absolute; inset: -1px;
}
/* أمّا summary فتوسيعه بطبقة زائفة لا يكفي: العنصر التالي يُرسم فوقه في ترتيب
   الرسم فتقع النقرة على التالي لا على العنوان (قِيس: نجح عند 375 وسقط عند 360
   في صفحتين). فيُوسَّع صندوقه نفسه — ارتفاعه 22 والمطلوب 24. */
.guide-narration summary { min-height: 24px; }
