/* challenge.css — واجهة «تحدي العلوم»: شاشة البداية + شبكة ٤٠ صندوقاً
   ============================================================
   لا تمسّ core.css / game.css — تُحمَّل بعدهما وتضيف أصنافاً خاصة فقط.
   القاعدة: كل هدف لمس ≥64px · تباعد مقروء من آخر الصف · لا تمرير صفحة. */

/* ---------- شاشة البداية ---------- */
.ch-launch {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 2.4vh, 28px);
  padding: clamp(16px, 3vw, 40px);
  text-align: center;
  animation: chIn 0.35s ease both;
}
@keyframes chIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.ch-brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(34px, 6vw, 68px);
  line-height: 1.15;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.ch-brand::after {
  content: '';
  display: block;
  width: 84px;
  height: 6px;
  margin: 12px auto 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #0E7490, #22A5B8);
}
.ch-sub {
  font-size: clamp(16px, 1.7vw, 22px);
  color: #42586B;
  max-width: 46ch;
  margin: 0 auto;
}

.ch-start {
  min-height: 78px;
  padding: 0 clamp(28px, 4vw, 56px);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(22px, 2.6vw, 34px);
  color: #FFFFFF;
  background: linear-gradient(180deg, #0E7490, #0B5E75);
  border: 3px solid #22A5B8;
  border-radius: 18px;
  box-shadow: 0 7px 0 #0A4F62, var(--shadow);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 140ms ease;
}
.ch-start:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 3px 0 #0A4F62; }
.ch-start:disabled { opacity: 0.45; cursor: default; box-shadow: none; transform: none; }

.ch-foot { font-size: clamp(14px, 1.2vw, 17px); color: #6B7F90; }
.ch-error { color: var(--wrong); font-weight: 700; font-size: 18px; }

/* ---------- شريط أدوات الجولة (ثابت أسفل يسار الشاشة · الشريط محجوز في الشبكة) ---------- */
.ch-tools {
  position: fixed;
  inset-inline-end: 14px;
  bottom: 8px;
  z-index: 60;
  display: flex;
  gap: 10px;
  align-items: center;
}
.ch-tools[hidden] { display: none; }
.ch-tool {
  min-height: 52px;
  padding: 0 16px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(15, 36, 51, 0.12);
  cursor: pointer;
}
.ch-tool:active { transform: scale(0.97); }


/* ---------- شبكة ٤٠ صندوقاً (٨ × ٥ على شاشة ١٦:٩) ---------- */
.mode-open-box .grid.grid-n40 {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: clamp(8px, 1vw, 14px);
  align-content: stretch;
  flex: 1 1 auto;
  min-height: 0;
  padding-bottom: 66px; /* يحجز شريط أدوات الجولة — لا يغطي أي صندوق */
}
.mode-open-box .grid.grid-n40 .box {
  min-height: 0;
  height: 100%;
  font-size: clamp(22px, 2.4vw, 40px);
  padding: 0;
}
.mode-open-box .grid.grid-n40 .box.opened,
.mode-open-box .grid.grid-n40 .box.deferred { font-size: clamp(18px, 2vw, 32px); }

@media (max-width: 1100px) {
  .mode-open-box .grid.grid-n40 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .mode-open-box .grid.grid-n40 .box { font-size: clamp(20px, 3.4vw, 34px); }
}
@media (max-width: 640px) {
  .mode-open-box .grid.grid-n40 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-height: 620px) {
  .mode-open-box .grid.grid-n40 { gap: 6px; }
  .ch-brand { font-size: clamp(28px, 4.6vw, 44px); }
}

@media (prefers-reduced-motion: reduce) {
  .ch-launch, .ch-start { animation: none; transition: none; }
}

/* ---------- وضعا اللعب تحت «ابدأ التحدي» ---------- */
.ch-modes {
  display: flex;
  gap: clamp(12px, 1.6vw, 22px);
  flex-wrap: wrap;
  justify-content: center;
}
.ch-mode {
  min-height: 68px;
  padding: 0 clamp(22px, 3vw, 40px);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(19px, 2vw, 26px);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.ch-mode:active { transform: translateY(3px); box-shadow: none; }
.ch-mode.is-free {
  color: #0E7490;
  background: #FFFFFF;
  border: 3px solid #0E7490;
  box-shadow: 0 5px 0 #B7D3DC;
}
.ch-mode.is-team {
  color: #FFFFFF;
  background: linear-gradient(100deg, #C0392B 0%, #C0392B 49%, #1E8449 51%, #1E8449 100%);
  border: 3px solid #FFFFFF;
  box-shadow: 0 5px 0 rgba(15, 36, 51, 0.28), 0 0 0 2px rgba(15, 36, 51, 0.08);
}
.ch-modes-note {
  margin: 0;
  font-size: clamp(13px, 1.1vw, 16px);
  color: #6B7F90;
}

/* ---------- شريط نتيجة الفريقين (أسفل يسار الشاشة — الشريط محجوز في الشبكة) ---------- */
.ch-team {
  position: fixed;
  inset-inline-start: 14px;
  bottom: 8px;
  z-index: 60;
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 3px 10px rgba(15, 36, 51, 0.14);
}
.ch-team[hidden] { display: none; }
.ch-team-chip {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(15px, 1.3vw, 19px);
  color: #FFFFFF;
}
.ch-team-chip.is-red { background: #C0392B; opacity: 0.62; }
.ch-team-chip.is-green { background: #1E8449; opacity: 0.62; }
.ch-team-chip.is-red.is-active { background: #C0392B; opacity: 1; box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.3); }
.ch-team-chip.is-green.is-active { background: #1E8449; opacity: 1; box-shadow: 0 0 0 3px rgba(30, 132, 73, 0.3); }
.ch-team-turn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(14px, 1.2vw, 18px);
  color: var(--text);
}

/* إطار الشاشة الملوّن: لون الفريق صاحب الدور — يُقرأ من آخر الصف */
.ch-turn-frame {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
  box-shadow: inset 0 0 0 7px rgba(192, 57, 43, 0.55);
  transition: box-shadow 200ms ease;
}
.ch-turn-frame.is-red { box-shadow: inset 0 0 0 7px rgba(192, 57, 43, 0.55); }
.ch-turn-frame.is-green { box-shadow: inset 0 0 0 7px rgba(30, 132, 73, 0.55); }
.ch-turn-frame[hidden] { display: none; }

/* ---------- الصندوق المفتوح يُصبغ بلون من أجاب صحيحاً ---------- */
.mode-open-box .grid .box.opened.team-red {
  background: linear-gradient(180deg, #C0392B 0%, #96281B 100%);
  border-color: #F0B4AA;
  color: #FFFFFF;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.22), 0 4px 0 rgba(120, 26, 14, 0.35);
}
.mode-open-box .grid .box.opened.team-green {
  background: linear-gradient(180deg, #1E8449 0%, #14663A 100%);
  border-color: #A8DDBE;
  color: #FFFFFF;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.22), 0 4px 0 rgba(10, 60, 34, 0.35);
}

/* ---------- شاشة الفائز ---------- */
.ch-winner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: clamp(14px, 2vh, 24px) clamp(24px, 4vw, 56px);
  border-radius: 20px;
  border: 4px solid #CBD8E3;
  background: #FFFFFF;
  box-shadow: var(--shadow);
}
.ch-winner.is-red { border-color: #C0392B; background: linear-gradient(180deg, #FBEDEB, #FFFFFF); }
.ch-winner.is-green { border-color: #1E8449; background: linear-gradient(180deg, #EAF6EF, #FFFFFF); }
.ch-winner-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 3.4vw, 46px);
  color: var(--text);
}
.ch-winner.is-red .ch-winner-title { color: #96281B; }
.ch-winner.is-green .ch-winner-title { color: #14663A; }
.ch-winner-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(36px, 5vw, 72px);
  line-height: 1;
  color: var(--text);
  letter-spacing: 2px;
}
.ch-winner-sub { font-size: clamp(14px, 1.3vw, 18px); color: #42586B; }

@media (max-width: 640px) {
  .ch-mode { min-height: 62px; width: 100%; }
  .ch-team { inset-inline-start: 8px; gap: 4px; padding: 5px 6px; }
  .ch-team-chip { min-height: 40px; padding: 0 8px; font-size: 14px; }
  .ch-team-turn { display: none; } /* الدور يُقرأ من إطار الشاشة الملوّن — توفير عرض على الجوال */
}

/* ============================================================================
   وضع الأربع فرق — مدمج هنا (كان ملفاً منفصلاً challenge4.css)
   الأحمر #C0392B · الأخضر #1E8449 · الأصفر #E6B400 · البنفسجي #C2185B
   (البنفسجي كان اسمه «الفوشي» — الاسم تغيّر، قيمة اللون لم تتغيّر)
   ========================================================================== */
.ch-mode.is-team4 {
  color: #FFFFFF;
  background: linear-gradient(100deg,
    #1E8449 0%, #1E8449 24%,
    #C0392B 26%, #C0392B 49%,
    #E6B400 51%, #E6B400 74%,
    #C2185B 76%, #C2185B 100%);
  border: 3px solid #FFFFFF;
  box-shadow: 0 5px 0 rgba(15, 36, 51, 0.28), 0 0 0 2px rgba(15, 36, 51, 0.08);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.38);
}

/* شريط الفرق الأربعة (ثابت أسفل الشاشة — خارج حاوية المحرك) */
.ch-t4 {
  position: fixed;
  inset-inline-start: 14px;
  bottom: 8px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px 10px;
  max-width: calc(100vw - 250px); /* يحجز أزرار الجولة في الطرف الآخر */
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid var(--panel-border);
  border-radius: 22px;
  box-shadow: 0 3px 10px rgba(15, 36, 51, 0.14);
}
.ch-t4[hidden] { display: none; }
.ch-t4-row { display: flex; align-items: stretch; gap: 8px; }
.ch-t4-turn {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(14px, 1.2vw, 18px);
  color: var(--text);
  white-space: nowrap;
}
.ch-t4-chip {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-height: 48px;
  padding: 4px 14px;
  border-radius: 16px;
  border: 3px solid transparent;
  opacity: 0.6;
  transition: opacity 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.ch-t4-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(14px, 1.15vw, 17px);
  line-height: 1.2;
  white-space: nowrap;
}
.ch-t4-nums {
  font-size: clamp(11px, 0.95vw, 14px);
  line-height: 1.25;
  white-space: nowrap;
}

/* ألوان الفرق — الأحمر والأخضر كما هما في وضع الفريقين */
.ch-t4-chip.is-red { background: #C0392B; color: #FFFFFF; }
.ch-t4-chip.is-green { background: #1E8449; color: #FFFFFF; }
.ch-t4-chip.is-yellow { background: linear-gradient(180deg, #F5C43C, #E6B400); color: #3D3100; }
.ch-t4-chip.is-purple { background: #C2185B; color: #FFFFFF; }

/* الفريق صاحب الدور: «· الدور» + حلقة بلون الفريق + رفع الحجم */
.ch-t4-chip.is-active { opacity: 1; transform: translateY(-3px); }
.ch-t4-chip.is-red.is-active { box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.35); }
.ch-t4-chip.is-green.is-active { box-shadow: 0 0 0 4px rgba(30, 132, 73, 0.35); }
.ch-t4-chip.is-yellow.is-active { box-shadow: 0 0 0 4px rgba(230, 180, 0, 0.45); }
.ch-t4-chip.is-purple.is-active { box-shadow: 0 0 0 4px rgba(194, 24, 91, 0.35); }

/* إطار الشاشة الملوّن بلون الفريق صاحب الدور */
.ch-turn-frame.is-yellow { box-shadow: inset 0 0 0 7px rgba(230, 180, 0, 0.65); }
.ch-turn-frame.is-purple { box-shadow: inset 0 0 0 7px rgba(194, 24, 91, 0.55); }

/* مساحة محجوزة أسفل شاشة اللعب حتى لا يغطي الشريط أي صندوق أو زر «متابعة» */
body.t4 .game-screen { padding-bottom: 92px; }
body.t4 .mode-open-box .grid.grid-n40 { padding-bottom: 0; }

/* الصناديق المفتوحة بلون الفريقين الجديدين */
.mode-open-box .grid .box.opened.team-yellow {
  background: linear-gradient(180deg, #F2C200 0%, #D3A600 100%);
  border-color: #FFE9A8;
  color: #3D3100;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.32), 0 4px 0 rgba(150, 118, 0, 0.38);
}
.mode-open-box .grid .box.opened.team-purple {
  background: linear-gradient(180deg, #C2185B 0%, #99124A 100%);
  border-color: #F2A7C4;
  color: #FFFFFF;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.22), 0 4px 0 rgba(122, 15, 60, 0.4);
}

/* شاشة الفائز (٤ فرق) */
.ch-t4-winner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: clamp(14px, 2vh, 24px) clamp(20px, 3vw, 44px);
  border-radius: 20px;
  border: 4px solid #CBD8E3;
  background: #FFFFFF;
  box-shadow: var(--shadow);
}
.ch-t4-winner.is-green { border-color: #1E8449; background: linear-gradient(180deg, #EAF6EF, #FFFFFF); }
.ch-t4-winner.is-red { border-color: #C0392B; background: linear-gradient(180deg, #FBEDEB, #FFFFFF); }
.ch-t4-winner.is-yellow { border-color: #E6B400; background: linear-gradient(180deg, #FFF6DB, #FFFFFF); }
.ch-t4-winner.is-purple { border-color: #C2185B; background: linear-gradient(180deg, #FCE9F1, #FFFFFF); }
.ch-t4-winner.is-draw { border-color: #CBD8E3; }
.ch-t4-final {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: min(520px, 80vw);
}
.ch-t4-final-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  border-radius: 12px;
  border-inline-start: 8px solid #CBD8E3;
  background: #F7FAFC;
}
.ch-t4-final-row.is-green { border-inline-start-color: #1E8449; }
.ch-t4-final-row.is-red { border-inline-start-color: #C0392B; }
.ch-t4-final-row.is-yellow { border-inline-start-color: #E6B400; }
.ch-t4-final-row.is-purple { border-inline-start-color: #C2185B; }
.ch-t4-final-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(15px, 1.4vw, 20px);
  color: var(--text);
}
.ch-t4-final-nums { font-size: clamp(13px, 1.2vw, 17px); color: #42586B; }

/* الجوال: الشريط فوق أزرار الجولة، بصفّين */
@media (max-width: 640px) {
  .ch-t4 {
    inset-inline-start: 8px;
    inset-inline-end: 8px;
    max-width: none;
    bottom: 68px;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 5px 7px;
    border-radius: 18px;
  }
  .ch-t4-turn { display: none; }  /* الدور يُقرأ من الإطار الملوّن + «· الدور» على البطاقة */
  .ch-t4-row { flex-wrap: wrap; gap: 5px; }
  .ch-t4-chip { flex: 1 1 calc(50% - 5px); min-height: 42px; padding: 3px 8px; border-width: 2px; }
  .ch-t4-name { font-size: 13px; }
  .ch-t4-nums { font-size: 11px; }
  .ch-t4-chip.is-active { transform: none; }
  body.t4 .game-screen { padding-bottom: 176px; }
  .ch-t4-final { min-width: 0; }
  .ch-t4-final-row { padding: 5px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .ch-t4-chip { transition: none; }
}
