/* ===== الأساسيات ===== */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  /* المسافات الآمنة على الآيفون: النوتش/الجزيرة أعلى، ومؤشر الهوم أسفل،
     والحواف الجانبية في الوضع الأفقي. تبقى القيم الافتراضية على الحاسوب. */
  padding:
    max(24px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: #f6f7f9;
  color: #1f2430;
  font-family: "Segoe UI", "Tahoma", "Arial", sans-serif;
  font-size: 17px;
  line-height: 1.7;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-text-size-adjust: 100%; /* يمنع تكبير النص تلقائياً على iOS */
}

/* ===== البطاقة ===== */
.quiz-card {
  width: 100%;
  max-width: 720px;
  background: #ffffff;
  border: 1px solid #e4e7ec;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 18px rgba(16, 24, 40, 0.06);
}

/* ===== العدّاد ===== */
.counter {
  display: block;
  text-align: center;
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 14px;
}

/* ===== مستطيل السؤال ===== */
.question-box {
  background: #ffffff;
  border: 1px solid #e0e3e9;
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 18px;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.8;
}

/* ملاحظة: لا يُعرض أي رقم داخلي للسؤال — العدّاد أعلاه هو الرقم الوحيد. */

/* ===== الإجابات ===== */
.answers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: right;
  background: #f2f3f5;
  border: 2px solid #e2e5ea;
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.answer:hover:not(:disabled) {
  background: #e9ebef;
  border-color: #cdd2da;
}

.answer:focus-visible {
  outline: 3px solid #9ec5ff;
  outline-offset: 2px;
}

.answer:disabled {
  cursor: default;
}

.answer .letter {
  flex: 0 0 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid #d7dbe2;
  border-radius: 8px;
  font-weight: 700;
  font-size: 16px;
}

.answer .text {
  flex: 1 1 auto;
  min-width: 0;            /* يسمح بالالتفاف داخل flex */
  overflow-wrap: anywhere; /* لا تخرج الكلمات الطويلة عن الشاشة الضيقة */
}

.answer .mark {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

/* حالة الاختيار قبل التحقق */
.answer.selected {
  background: #eaf2fd;
  border-color: #4a90e2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.18);
}

/* حالة صحيحة */
.answer.correct {
  background: #d9f2e0;
  border-color: #34a853;
  box-shadow: none;
}

.answer.correct .letter {
  border-color: #9bd9ae;
}

.answer.correct .mark {
  display: flex;
  background: #2e9e4f;
}

/* حالة خاطئة */
.answer.wrong {
  background: #fadbdb;
  border-color: #d93a3a;
  box-shadow: none;
}

.answer.wrong .letter {
  border-color: #eaa3a3;
}

.answer.wrong .mark {
  display: flex;
  background: #cf3b3b;
}

/* ===== رسالة التنبيه ===== */
.message {
  min-height: 22px;
  margin-top: 12px;
  font-size: 15px;
  color: #b3541e;
  text-align: center;
}

.message:empty {
  margin-top: 0;
  min-height: 0;
}

/* ===== شريط التنقل ===== */
.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.nav button {
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  padding: 11px 18px;
  cursor: pointer;
  border: 1px solid transparent;
}

/*
 * أزرار التنقل (السابق / التالي / تقدم) — أخضر ممتلئ بنص أبيض.
 * مقصود أن يختلف بوضوح عن أخضر الإجابة الصحيحة (#d9f2e0 خلفية فاتحة بنص داكن)،
 * فهذا زر ممتلئ داكن والآخر لوحة فاتحة.
 */
.nav .side {
  flex: 0 0 auto;
  min-width: 104px;
  background: #2f9e4f;
  border-color: #268744;
  color: #ffffff;
}

.nav .side:hover:not(:disabled) {
  background: #268744;
  border-color: #1f7038;
}

.nav .side:active:not(:disabled) {
  background: #1f7038;
  border-color: #17572a;
}

.nav .side:focus-visible {
  outline: 3px solid #a7dfbb;
  outline-offset: 2px;
}

/* معطّل: رمادي هادئ — لا أخضر لامع ولا تأثير تحويم */
.nav .side:disabled {
  background: #eceef1;
  border-color: #dfe2e7;
  color: #8d949f;
  opacity: 1; /* بدل التلاشي العام حتى يبقى النص مقروءاً */
  cursor: not-allowed;
}

.nav .check {
  flex: 1 1 auto;
  background: #58a6e8;
  border-color: #4795d8;
  color: #ffffff;
}

.nav .check:hover:not(:disabled) {
  background: #4795d8;
}

.nav button:focus-visible {
  outline: 3px solid #9ec5ff;
  outline-offset: 2px;
}

.nav button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ===== شريط المراجعة ===== */
.review-bar {
  margin-top: 10px;
}

.review-bar .secondary,
#resultsView .secondary {
  width: 100%;
  font: inherit;
  font-weight: 700;
  background: #eef0f3;
  border: 1px solid #dcdfe5;
  border-radius: 10px;
  padding: 11px 18px;
  color: #3a4152;
  cursor: pointer;
}

.review-bar .secondary:hover,
#resultsView .secondary:hover {
  background: #e2e5ea;
}

.review-bar .secondary:focus-visible,
#resultsView .secondary:focus-visible {
  outline: 3px solid #9ec5ff;
  outline-offset: 2px;
}

#resultsView .secondary {
  margin-top: 10px;
}

/* ===== شاشة النتيجة ===== */
#resultsView {
  text-align: center;
  padding: 6px 4px 2px;
}

.results-title {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 700;
  color: #1f2430;
}

.score {
  /* اتجاه لاتيني حتى تظهر الصيغة "8 / 10" بترتيبها الصحيح */
  direction: ltr;
  margin: 0 0 14px;
  font-size: 40px;
  font-weight: 700;
  line-height: 1.2;
  color: #2f6fb5;
}

.results-line {
  margin: 0 0 8px;
  font-size: 16px;
  color: #3a4152;
}

.results-muted {
  color: #6b7280;
  font-size: 15px;
}

#resultsView .primary {
  width: 100%;
  margin-top: 14px;
  font: inherit;
  font-weight: 700;
  background: #58a6e8;
  border: 1px solid #4795d8;
  border-radius: 10px;
  padding: 12px 18px;
  color: #ffffff;
  cursor: pointer;
}

#resultsView .primary:hover {
  background: #4795d8;
}

#resultsView .primary:focus-visible {
  outline: 3px solid #9ec5ff;
  outline-offset: 2px;
}

/* ===== الشاشات الصغيرة ===== */
@media (max-width: 520px) {
  body {
    padding:
      max(14px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    font-size: 16px;
    align-items: flex-start;
  }

  .quiz-card {
    padding: 16px;
  }

  .question-box {
    font-size: 17px;
    padding: 14px;
  }

  .nav {
    flex-wrap: wrap;
  }

  .nav .check {
    order: 3;
    flex: 1 0 100%;
  }

  .nav .side {
    flex: 1 1 0;
    min-width: 0;
  }
}

/* ===== الشاشات القصيرة / الوضع الأفقي على الهاتف ===== */
@media (max-height: 520px) and (orientation: landscape) {
  body {
    align-items: flex-start;
    padding:
      max(10px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .quiz-card {
    padding: 14px 16px;
  }

  .answers {
    gap: 8px;
  }

  .answer {
    padding: 9px 12px;
  }

  .question-box {
    margin-bottom: 12px;
    padding: 12px 14px;
  }
}
