/* ════════════════════════════════════════════════════════════════
   «النجاة من الشلال» — falls.js

   الإعداد بألوان النظام وخطّه، والمسرح لوحةٌ داكنة هادئة تحت مشهد
   النهر حتى يُقرأ السؤال على البروجكتر من آخر الفصل.
   ⚠ ألوان المسرح خاصّة باللعبة ولا تتبع المظهر الفاتح أو الداكن.
   ════════════════════════════════════════════════════════════════ */

/* ─── الإعداد ─────────────────────────────────────────────────── */
/* العنوان في شريطٍ فوق المعاينة، والمعاينة قواربُ الفصل نفسه بأسماء طلابه */
.fl-hero {
  position: relative; overflow: hidden; isolation: isolate;
  border-radius: 22px; margin-bottom: var(--s4); background: #0b2f3a;
}
.fl-hero-txt {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 14px clamp(14px, 3vw, 28px);
  color: #fff; background: linear-gradient(90deg, #0e7490, #0b4f63 60%, #0b2f3a);
}
.fl-hero h2 { margin: 0; font-size: clamp(26px, 3.6vw, 44px); font-weight: 900; line-height: 1.2; }
.fl-hero p { margin: 0; flex: 1 1 260px; font-weight: 700; font-size: var(--fs-sm); color: #cfeaf0; }
.fl-hero-tag {
  display: inline-flex; gap: 6px; align-items: center; padding: 3px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .14); font-size: var(--fs-xs); font-weight: 800;
}
.fl-hero-tag svg { width: 15px; height: 15px; }
.fl-hero-cv {
  display: block; width: 100%; aspect-ratio: 1920 / 840; max-height: 330px;
  object-fit: cover; object-position: 50% 62%;
}

.fl-card { margin-bottom: var(--s3); }
.fl-card-h { display: flex; align-items: center; gap: 8px; margin: 0 0 var(--s3); }
.fl-card-h .tiny { font-weight: 600; }
.fl-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s3); align-items: end; }
.fl-grid .field { margin: 0; }
.fl-who-h { flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s2); }
.fl-who-h .fl-card-h { margin: 0; }

.fl-seg {
  display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.fl-seg button {
  display: inline-flex; gap: 6px; align-items: center; padding: 8px 14px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-muted); font: inherit; font-weight: 800; cursor: pointer;
}
.fl-seg button.on { background: var(--brand-500); color: #fff; }
.fl-seg svg { width: 17px; height: 17px; }
.fl-hint { margin: 0 0 var(--s3); }

.fl-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s3); }
.fl-group {
  padding: 10px; border-radius: 16px; border: 2px solid var(--border); background: var(--surface);
  opacity: .62; transition: opacity .15s, border-color .15s, box-shadow .15s;
}
.fl-group.on { opacity: 1; border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.fl-group-h {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px; border: 0;
  background: none; color: var(--ink); font: inherit; text-align: start; cursor: pointer;
}
div.fl-group-h { cursor: default; }
.fl-group-h b { flex: 1; min-width: 0; }
.fl-check { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; background: var(--c); color: #fff; flex: 0 0 auto; }
.fl-check svg { width: 14px; height: 14px; }
.fl-group:not(.on) .fl-check { background: var(--surface-2); border: 2px solid var(--border-strong); }
.fl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fl-chip {
  padding: 4px 11px; border-radius: 999px; border: 1.5px solid var(--border-strong);
  background: var(--surface-2); color: var(--ink); font: inherit; font-size: var(--fs-sm); font-weight: 700; cursor: pointer;
}
.fl-chip.is-out { opacity: .45; text-decoration: line-through; border-style: dashed; }
.fl-chip.is-on { background: var(--c); border-color: var(--c); color: #fff; }
.fl-roster { margin-top: 0; }
.fl-auto { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 var(--s3); }
.fl-auto .select { width: auto; min-width: 80px; }
.fl-auto .label { margin: 0; }
.fl-note {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; margin-bottom: var(--s3);
  border-radius: 12px; background: color-mix(in srgb, #2f6fb2 10%, var(--surface)); color: var(--ink); font-size: var(--fs-sm);
}
.fl-note svg { flex: 0 0 auto; margin-top: 3px; }
.fl-rules { margin: 0; padding-inline-start: 20px; display: grid; gap: 6px; line-height: 1.75; }
.fl-go { display: flex; flex-wrap: wrap; gap: var(--s3); justify-content: center; margin: var(--s4) 0; }
.fl-go .btn { min-width: 260px; justify-content: center; }
.fl-go #flTry { min-width: 160px; }
.fl-trial {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 4px 8px; border-radius: 999px;
  background: rgba(217, 162, 31, .92); color: #1d1500; font-weight: 700; font-size: 12px; white-space: nowrap;
}
.fl-trial svg { width: 14px; height: 14px; }

/* ─── المسرح ──────────────────────────────────────────────────── */
.fl-stage {
  --fl-panel: #0c2530; --fl-line: rgba(255, 255, 255, .12); --fl-dim: #a7c0c6; --fl-gold: #ffd65a;
  position: relative; overflow: hidden; border-radius: 18px; background: #071a22; color: #eaf4f6;
  /* الشاشة كلّها: شريط السؤال أعلى، والمشهد يملأ الباقي، والترتيب شريطٌ رفيع أسفل */
  display: flex; flex-direction: column; height: calc(100dvh - 16px); min-height: 520px;
}
.fl-stage:fullscreen { height: 100vh; border-radius: 0; }
.fl-scene { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; background: #06141b; }
.fl-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

/* ─── شريط السؤال أعلى المشهد ─────────────────────────────────── */
/* السؤال والخيارات فوق خلفية الشلال مباشرةً بلا لوحةٍ خلفها (طلب المستخدم
   ٢٠٢٦-١١-١٨)، والمشهد يمتدّ تحتها إلى أعلى الشاشة. الظلّ يبقي النصّ مقروءًا. */
.fl-top {
  position: absolute; top: 0; inset-inline: 0; z-index: 5;
  height: clamp(206px, 27vh, 250px); display: flex; gap: 10px; align-items: stretch; padding: 10px 12px;
  background: none; border: 0; pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .9), 0 0 2px rgba(0, 0, 0, .95);
}
.fl-top > * { pointer-events: auto; }
.fl-top .fl-ask { overflow: visible; }
.fl-top .fl-ask-body p { font-size: clamp(20px, 2vw, 32px); font-weight: 900; }
.fl-top .fl-qn, .fl-top .fl-ask .btn-ghost { color: #e3f1f4; }
.fl-top .fl-clock { background: rgba(4, 16, 22, .45); border-radius: 50%; }
.fl-side { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.fl-intro {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin: auto;
  font-size: clamp(22px, 2.4vw, 38px); animation: fl-drop .45s cubic-bezier(.2, 1.4, .4, 1);
}
.fl-intro span { color: var(--fl-dim); font-weight: 700; }
.fl-intro b { font-weight: 900; color: #fff; border-bottom: 4px solid var(--c); padding-bottom: 2px; }
.fl-intro em { display: inline-flex; gap: 6px; align-items: center; font-style: normal; font-weight: 800; font-size: .7em; color: var(--fl-gold); }
.fl-intro em svg { width: 1em; height: 1em; }

/* رسالة الإجابة: تحلّ محلّ رأس السؤال بالارتفاع نفسه */
.fl-msg {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 12px;
  flex: 0 0 auto; min-height: 50px; padding: 6px 16px; border-radius: 14px; color: #fff; text-align: center;
  animation: fl-msg .5s cubic-bezier(.2, 1.4, .4, 1) both;
}
.fl-msg svg { width: 28px; height: 28px; flex: 0 0 auto; }
.fl-msg b { font-size: clamp(18px, 1.9vw, 30px); font-weight: 900; }
.fl-msg span { font-size: clamp(15px, 1.4vw, 22px); font-weight: 800; opacity: .95; }
.fl-msg.is-ok { background: linear-gradient(135deg, #1f8a4c, #2fb565); }
.fl-msg.is-bad { background: linear-gradient(135deg, #b02a20, #dd4a33); }
.fl-msg.is-win { background: linear-gradient(135deg, #d4a017, #f0c040); color: #3b2400; }
.fl-msg.is-big { margin: auto 0; min-height: 90px; }
@keyframes fl-msg { from { transform: scale(.85); opacity: 0; } }
.fl-stage.is-paused .fl-canvas { filter: saturate(.55) brightness(.8); }

.fl-turn {
  position: absolute; top: 12px; left: 50%; translate: -50% 0; z-index: 2;
  display: flex; align-items: center; gap: 10px; padding: 7px 18px; border-radius: 999px; white-space: nowrap;
  background: rgba(7, 26, 34, .84); border: 2px solid var(--c); box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  font-size: clamp(14px, 1.5vw, 22px);
}
.fl-turn span { color: var(--fl-dim); font-weight: 700; }
.fl-turn b { font-weight: 900; color: #fff; }
.fl-turn em { display: inline-flex; gap: 5px; align-items: center; font-style: normal; font-weight: 800; font-size: .85em; color: var(--fl-gold); }
.fl-turn em svg { width: 1em; height: 1em; }
.fl-turn[hidden] { display: none; }
.fl-turn.on { animation: fl-drop .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes fl-drop { from { transform: translateY(-30px); opacity: 0; } }

.fl-tools { display: grid; grid-template-columns: repeat(2, 40px); gap: 6px; justify-content: center; }
.fl-ibtn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .25); background: rgba(7, 26, 34, .72); color: #fff;
}
.fl-ibtn svg { width: 20px; height: 20px; }
.fl-ibtn:hover { background: rgba(7, 26, 34, .94); }
.fl-ibtn-x { background: rgba(160, 30, 25, .82); }

.fl-overlay { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.fl-overlay > * { pointer-events: auto; }
.fl-count {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none !important;
  font-size: clamp(70px, 12vw, 180px); font-weight: 900; color: #fff;
  text-shadow: 0 6px 0 rgba(0, 0, 0, .35), 0 0 40px rgba(0, 0, 0, .4); animation: fl-pop .72s ease both;
}
.fl-count.is-go { color: var(--fl-gold); font-size: clamp(50px, 8vw, 120px); }
@keyframes fl-pop { from { transform: scale(1.6); opacity: 0; } 30% { transform: scale(1); opacity: 1; } to { opacity: 0; } }
.fl-paused, .fl-quit, .fl-podium {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 14, 20, .55); backdrop-filter: blur(3px);
}
.fl-box {
  max-width: 460px; padding: 22px 26px; border-radius: 20px; text-align: center; color: #fff;
  background: #0f2e3a; border: 1px solid rgba(255, 255, 255, .18); box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.fl-box h3 { margin: 0 0 8px; font-size: clamp(20px, 2vw, 30px); }
.fl-box p { margin: 0 0 14px; color: var(--fl-dim); }
.fl-box-wide { width: 100%; max-width: min(880px, 96%); max-height: 100%; overflow: auto; }
.fl-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.fl-btn {
  display: inline-flex; gap: 8px; align-items: center; padding: 10px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .3); background: rgba(255, 255, 255, .08); color: #fff; font: inherit; font-weight: 800;
}
.fl-btn svg { width: 18px; height: 18px; }
.fl-btn-go { background: #2e9b57; border-color: #2e9b57; }
.fl-btn-danger { background: #b8322a; border-color: #b8322a; }

/* منصّة التتويج */
.fl-podium .fl-box { padding: 16px 20px; }
.fl-podium .fl-box h3 { margin-bottom: 2px; }
.fl-stands { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 10px; max-width: 520px; margin: 2px auto 10px; }
.fl-stand { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.fl-stand b { font-size: clamp(14px, 1.4vw, 20px); overflow-wrap: anywhere; }
.fl-stand > .num { color: var(--fl-gold); font-weight: 800; }
.fl-step {
  display: grid; place-items: center; width: 100%; border-radius: 12px 12px 4px 4px;
  background: linear-gradient(180deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
}
.fl-stand-1 .fl-step { height: clamp(56px, 9vh, 104px); } .fl-stand-2 .fl-step { height: clamp(40px, 6.5vh, 74px); } .fl-stand-3 .fl-step { height: clamp(28px, 4.6vh, 52px); }
.fl-step i { font-style: normal; font-size: clamp(22px, 3vh, 34px); font-weight: 900; color: #fff; }
.fl-crown { color: var(--fl-gold); } .fl-crown svg { width: 30px; height: 30px; }
.fl-tie { color: var(--fl-gold) !important; font-weight: 800; }
.fl-none { font-weight: 800; color: #fff !important; }
.fl-dec { font-size: .7em; color: var(--fl-gold); font-weight: 700; }
.fl-final { list-style: none; margin: 0 0 10px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 5px 8px; text-align: start; }
.fl-final li {
  display: grid; grid-template-columns: 24px 1fr auto auto auto; gap: 8px; align-items: center;
  padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, .06); border-inline-start: 5px solid var(--c);
  font-size: var(--fs-sm);
}
.fl-final li > span:nth-child(3) { color: var(--fl-dim); font-size: var(--fs-sm); }
.fl-final li.is-fell, .fl-final li.is-broken, .fl-final li.is-lost { opacity: .7; }
.fl-save { font-size: var(--fs-sm); color: #bfe3c9 !important; }

/* ─── الترتيب: شريطٌ رفيع أسفل المشهد ─────────────────────────── */
.fl-rank {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 7px 12px;
  background: var(--fl-panel); border-top: 1px solid var(--fl-line); overflow-x: auto;
}
.fl-rank-h { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; color: var(--fl-dim); font-size: var(--fs-sm); }
.fl-rank-h b { display: inline-flex; gap: 6px; align-items: center; color: #fff; }
.fl-rank-h svg { width: 16px; height: 16px; }
.fl-rank ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.fl-rank li {
  flex: 1 1 190px; max-width: 320px;
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto auto auto; gap: 7px; align-items: center;
  padding: 4px 8px; border-radius: 10px; background: rgba(255, 255, 255, .05); font-size: var(--fs-sm);
  border-inline-start: 4px solid var(--c);
}
.fl-rank li.is-turn { background: color-mix(in srgb, #ffd65a 18%, transparent); outline: 1.5px solid var(--fl-gold); }
.fl-rank li.is-safe { background: rgba(46, 155, 87, .24); }
.fl-rank li.is-fell, .fl-rank li.is-broken, .fl-rank li.is-lost { opacity: .55; }
.fl-r-n { color: var(--fl-dim); font-weight: 800; }
.fl-r-name { display: flex; flex-direction: column; min-width: 0; font-weight: 800; line-height: 1.3; }
.fl-r-name b { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fl-r-name small { color: var(--fl-dim); font-weight: 600; font-size: .78em; }
.fl-r-ok { color: #7ee2a0; font-weight: 800; }
.fl-r-bad { color: #ff9c8f; font-weight: 800; }
.fl-r-t { min-width: 54px; text-align: end; color: var(--fl-gold); font-weight: 800; }

.fl-ask {
  flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto;
}
.fl-ask-head { min-height: 50px; }
.fl-ask .fl-choices { margin-top: auto; }
.fl-wait { margin: auto; color: var(--fl-dim); font-weight: 800; font-size: var(--fs-lg); }
.fl-ask-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.fl-who { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-lg); }
.fl-who i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); }
.fl-lead { display: inline-flex; gap: 5px; align-items: center; color: var(--fl-gold); font-size: var(--fs-sm); }
.fl-lead svg { width: 15px; height: 15px; }
.fl-qn { color: var(--fl-dim); font-size: var(--fs-sm); }
.fl-ask .spacer { flex: 1; }
.fl-ask .btn-ghost { color: var(--fl-dim); }
.fl-clock { --p: 1; position: relative; display: grid; place-items: center; width: 54px; height: 54px; flex: 0 0 auto; }
.fl-clock svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.fl-clock circle { fill: none; stroke: rgba(255, 255, 255, .14); stroke-width: 4; }
.fl-clock .fl-clock-v { stroke: #3fbf6a; stroke-linecap: round; stroke-dasharray: calc(var(--p) * 100) 100; }
.fl-clock.is-low .fl-clock-v { stroke: #ef5a23; }
.fl-clock b { font-size: 18px; font-weight: 900; }
.fl-clock.is-low b { color: #ff9c8f; animation: fl-beat 1s ease infinite; }
@keyframes fl-beat { 50% { transform: scale(1.18); } }
.fl-ask-body { display: flex; gap: 12px; align-items: center; }
.fl-ask-body p { margin: 0; color: #fff; font-size: clamp(18px, 1.8vw, 28px); font-weight: 800; line-height: 1.45; }
.fl-ask-body p.is-long { font-size: clamp(16px, 1.45vw, 23px); line-height: 1.35; }
/* الخيارات في صفٍّ واحد حتى لا يأكل الشريط من المشهد */
.fl-choices { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .fl-choices:not(.is-tf) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.fl-choice {
  display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 7px 12px; border-radius: 14px;
  border: 2px solid color-mix(in srgb, var(--cc) 75%, #fff); background: color-mix(in srgb, var(--cc) 42%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  color: #fff; font: inherit; font-size: clamp(16px, 1.5vw, 23px); font-weight: 800; text-align: start; cursor: pointer;
  transition: transform .12s, background .12s;
}
.fl-choice:hover:not(:disabled) { transform: translateY(-2px); background: color-mix(in srgb, var(--cc) 62%, transparent); }
.fl-choice i {
  display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 10px;
  background: var(--cc); font-style: normal; font-weight: 900;
}
.fl-choice span { flex: 1; min-width: 0; }
.fl-choice:disabled { cursor: default; opacity: .5; }
.fl-choice.is-right { opacity: 1; border-color: #3fbf6a; background: rgba(46, 155, 87, .55); box-shadow: 0 0 0 3px rgba(63, 191, 106, .45); }
.fl-choice.is-wrong { opacity: 1; border-color: #ef5a23; background: rgba(190, 40, 30, .55); }
.fl-verdict { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 8px 12px; border-radius: 12px; font-weight: 800; }
.fl-verdict svg { width: 18px; height: 18px; }
.fl-verdict.is-ok { background: rgba(46, 155, 87, .3); color: #bff0cf; }
.fl-verdict.is-bad { background: rgba(190, 40, 30, .3); color: #ffd0c9; }
