/* ============================================================
   mascot.css — «برعي»: روبوت المنصة (رسمه في js/mascot.js)
   الحركة بـ transform/opacity فقط، وتتوقف مع prefers-reduced-motion.
   ============================================================ */

.mascot {
  display: block;
  overflow: visible;
  width: 120px;
  height: 120px;
}

.mascot .rb-float { animation: rb-float 2.6s ease-in-out infinite; }

.mascot .rb-shadow {
  transform-box: fill-box;
  transform-origin: center;
  animation: rb-shadow 2.6s ease-in-out infinite;
}

/* الذراع اليمنى المرفوعة (تلويح / تشجيع / احتفال) */
.mascot .rb-wave {
  transform-box: view-box;
  transform-origin: 106px 114px;
  transform: rotate(-135deg);
  animation: rb-wave 1.1s ease-in-out .35s infinite;
}

/* الذراع اليسرى المرفوعة (احتفال فقط) */
.mascot .rb-wave-l {
  transform-box: view-box;
  transform-origin: 54px 114px;
  transform: rotate(135deg);
  animation: rb-wave-l 1.1s ease-in-out .15s infinite;
}

.mascot .rb-eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: rb-blink 3.6s ease-in-out infinite;
}

.mascot .rb-bulb { animation: rb-bulb 1.6s ease-in-out infinite; }
.mascot .rb-flat { display: none; }

/* ===== تعبيرات إضافية (transform/opacity فقط) ===== */
.mascot.is-scared .rb-float { animation: rb-shiver .16s linear infinite; }
.mascot.is-shiver .rb-float { animation: rb-shiver .09s linear infinite; }
.mascot .rb-sweat { animation: rb-drip 1.4s ease-in infinite; }
.mascot.is-shock .rb-float { animation: rb-jump 1.2s cubic-bezier(.22, 1, .36, 1) infinite; }
.mascot.is-sad .rb-float { animation: rb-sag 3s ease-in-out infinite; }
.mascot.is-proud .rb-float { animation: rb-puff 2.4s ease-in-out infinite; }
.mascot .rb-think { animation: rb-bulb 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.mascot .rb-gear { transform-box: fill-box; transform-origin: center; animation: rb-spin 3s linear infinite; }
@keyframes rb-shiver { 0%, 100% { transform: translateX(-1.2px); } 50% { transform: translateX(1.2px); } }
@keyframes rb-drip { 0% { transform: translateY(-3px); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(8px); opacity: 0; } }
@keyframes rb-jump { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-14px); } }
@keyframes rb-sag { 0%, 100% { transform: translateY(2px); } 50% { transform: translateY(5px); } }
@keyframes rb-puff { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes rb-spin { to { transform: rotate(360deg); } }
.mascot.rb-spin-once .rb-float { animation: rb-spin-once .9s ease-in-out 1; transform-box: fill-box; transform-origin: center; }
@keyframes rb-spin-once { to { transform: rotate(360deg); } }

/* حرف z للنعاس */
.mascot .rb-z {
  font: 700 15px/1 "Inter", sans-serif;
  animation: rb-z 2.8s ease-in-out infinite;
  opacity: 0;
}
.mascot .rb-z + .rb-z { animation-delay: 1.1s; }

/* الاحتفال: قفزة صغيرة */
.mascot.is-cheer .rb-float { animation: rb-hop .7s cubic-bezier(.22, 1, .36, 1) infinite alternate; }

@keyframes rb-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

@keyframes rb-hop {
  from { transform: translateY(2px); }
  to   { transform: translateY(-9px); }
}

@keyframes rb-shadow {
  0%, 100% { transform: scale(1);   opacity: .22; }
  50%      { transform: scale(.82); opacity: .14; }
}

@keyframes rb-wave {
  0%, 100% { transform: rotate(-120deg); }
  50%      { transform: rotate(-148deg); }
}

@keyframes rb-wave-l {
  0%, 100% { transform: rotate(120deg); }
  50%      { transform: rotate(148deg); }
}

@keyframes rb-blink {
  0%, 44%, 50%, 100% { transform: scaleY(1); }
  47%                { transform: scaleY(.1); }
}

@keyframes rb-bulb {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}

@keyframes rb-z {
  0%   { opacity: 0; transform: translate(0, 4px); }
  35%  { opacity: .8; }
  100% { opacity: 0; transform: translate(6px, -10px); }
}

/* ---------- برعي في ترويسة الرئيسية ---------- */
.home-mascot {
  position: absolute;
  z-index: 1;
  inset-inline-end: 14px;
  bottom: 6px;
  width: 78px;
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.home-mascot .mascot { width: 78px; height: 78px; }

.home-mascot-name {
  display: inline-block;
  margin-top: -6px;
  padding: 1px 10px;
  border-radius: 999px;
  background: #FFFFFF;
  color: #B71F2D;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(23, 25, 29, .10);
}

@media (min-width: 700px) {
  .home-mascot { width: 120px; inset-inline-end: 56px; bottom: 10px; }
  .home-mascot .mascot { width: 120px; height: 120px; }
  .home-mascot-name { font-size: 12.5px; padding: 2px 14px; }
}

/* ---------- حالة فارغة مع برعي ---------- */
.mascot-empty {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: start;
}

.mascot-empty .mascot { flex: 0 0 auto; width: 72px; height: 72px; }
.mascot-empty-text { flex: 1; min-width: 0; }

/* ---------- نتيجة الاختبار ---------- */
.exam-result-icon.has-mascot {
  width: 132px;
  height: 132px;
  background: none;
  border-radius: 0;
  margin-bottom: 8px;
}

.exam-result-icon.has-mascot .mascot { width: 132px; height: 132px; }

/* ---------- قصاصات الاحتفال ---------- */
.cf-layer {
  position: fixed;
  inset: 0;
  z-index: 2200;
  overflow: hidden;
  pointer-events: none;
}

.cf-piece {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: cf-fall var(--d, 2.2s) cubic-bezier(.3, .6, .4, 1) var(--delay, 0s) forwards;
}

@keyframes cf-fall {
  0%   { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  100% { opacity: 0; transform: translate3d(var(--x, 0px), 105vh, 0) rotate(var(--r, 540deg)); }
}

@media (prefers-reduced-motion: reduce) {
  .mascot .rb-float,
  .mascot .rb-shadow,
  .mascot .rb-wave,
  .mascot .rb-wave-l,
  .mascot .rb-eye,
  .mascot .rb-bulb,
  .mascot .rb-z,
  .mascot .rb-sweat,
  .mascot .rb-think,
  .mascot .rb-gear,
  .mascot.is-scared .rb-float,
  .mascot.is-shiver .rb-float,
  .mascot.is-shock .rb-float,
  .mascot.is-sad .rb-float,
  .mascot.is-proud .rb-float,
  .mascot.rb-spin-once .rb-float,
  .mascot.is-cheer .rb-float { animation: none !important; }
  .mascot .rb-z { opacity: .7; }
  .cf-layer { display: none; }
}

/* النصوص تبقى بعيدة عن برعي في الترويسة */
@media (max-width: 700px) {
  .home-welcome-context,
  .home-welcome-stage { max-width: calc(100% - 96px); }
}

/* ============================================================
   الجولة الثالثة: حياة أكثر — حركات «مرة أو مرتين ثم تهدأ» (transform/opacity فقط)
   ============================================================ */

/* نظرة العينين: --gx/--gy بالبكسل (±3) تضبطها ambient.js؛ بدونها تبقى العينان في مكانهما */
.mascot .rb-eyes {
  transform: translate(calc(var(--gx, 0) * 1px), calc(var(--gy, 0) * 1px));
  transition: transform .16s ease-out;
}

/* دخول مرة واحدة ثم يعود الطفو الهادئ */
.mascot.is-welcome .rb-float { animation: rb-hello .7s cubic-bezier(.22, 1, .36, 1) 1, rb-float 2.6s ease-in-out .7s infinite; }
.mascot.is-pop .rb-float     { animation: rb-pop .6s cubic-bezier(.22, 1, .36, 1) 1, rb-float 2.6s ease-in-out .6s infinite; }
.mascot.is-nudge .rb-float   { animation: rb-nudge .7s ease-in-out 2, rb-float 2.6s ease-in-out 1.4s infinite; }
.mascot.is-pump .rb-float    { animation: rb-pump-body .5s ease-out 2, rb-float 2.6s ease-in-out 1s infinite; }
.mascot.is-focus .rb-float   { animation: rb-float 4.2s ease-in-out infinite; }   /* أبطأ وأهدأ */

.mascot .rb-pump {
  transform-box: view-box;
  transform-origin: 106px 114px;
  transform: rotate(-152deg);
  animation: rb-pump .5s ease-out 2;
}
@keyframes rb-pump      { 0% { transform: rotate(-120deg); } 55% { transform: rotate(-168deg); } 100% { transform: rotate(-152deg); } }
@keyframes rb-pump-body { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes rb-hello     { 0% { transform: translateY(6px) scale(.94); } 60% { transform: translateY(-6px) scale(1.03); } 100% { transform: none; } }
@keyframes rb-pop       { 0% { transform: translateY(0) scale(.92); } 40% { transform: translateY(-10px) scale(1.04); } 100% { transform: none; } }
@keyframes rb-nudge     { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-2.5px); } 70% { transform: translateX(2.5px); } }

.mascot .rb-spark { transform-box: fill-box; transform-origin: center; animation: rb-twinkle 1.2s ease-in-out 2; }
.mascot .rb-spark.s2 { animation-delay: .3s; }
.mascot .rb-spark.s3 { animation-delay: .6s; }
@keyframes rb-twinkle { 0%, 100% { transform: scale(.6); opacity: .5; } 50% { transform: scale(1.15); opacity: 1; } }

.mascot .rb-bang  { transform-box: fill-box; transform-origin: center; animation: rb-bang .9s cubic-bezier(.22, 1, .36, 1) 2; }
@keyframes rb-bang { 0% { transform: scale(.5); opacity: 0; } 50% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.mascot .rb-dot { animation: rb-dot 1.2s ease-in-out infinite; }
.mascot .rb-dot.d2 { animation-delay: .2s; }
.mascot .rb-dot.d3 { animation-delay: .4s; }
@keyframes rb-dot { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

.mascot .rb-glow   { animation: rb-bulb 1.6s ease-in-out 3; }
.mascot .rb-trophy { transform-box: fill-box; transform-origin: center bottom; animation: rb-trophy 1s ease-in-out 2; }
@keyframes rb-trophy { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-6deg); } 70% { transform: rotate(6deg); } }

/* تبديل التعبير داخل نفس العنصر: نبضة قصيرة بدل القفزة الفجائية */
.mascot.rb-swap { animation: rb-swap .22s ease-out 1; }
@keyframes rb-swap { 0% { transform: scale(.9); } 100% { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .mascot.is-welcome .rb-float,
  .mascot.is-pop .rb-float,
  .mascot.is-nudge .rb-float,
  .mascot.is-pump .rb-float,
  .mascot.is-focus .rb-float,
  .mascot .rb-pump,
  .mascot .rb-spark,
  .mascot .rb-bang,
  .mascot .rb-dot,
  .mascot .rb-glow,
  .mascot .rb-trophy,
  .mascot.rb-swap { animation: none !important; }
  .mascot .rb-eyes { transform: none !important; transition: none; }
}
