/* ==========================================================================
   KHẢO THÍ VIỆT - BEELIO MASCOT SYSTEM (CHÚ ONG VÀNG CHĂM CHỈ 3D)
   Quy chuẩn giao diện hoạt họa linh vật chuyển động theo từng mốc bài học
   ========================================================================== */

/* 1. KHUNG CHỨA LINH VẬT ĐỘNG TRÊN BẢN ĐỒ */
.beelio-mascot-entity,
.g4-mascot-container {
  position: absolute;
  pointer-events: none; /* Tránh che chắn các nút bài học xung quanh */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  z-index: 25;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  /* Chuyển động lượn bay mượt mà theo gia tốc tự nhiên */
  transition: top 0.85s cubic-bezier(0.34, 1.35, 0.64, 1),
              left 0.85s cubic-bezier(0.34, 1.35, 0.64, 1),
              transform 0.4s ease;
  transform-origin: center bottom;
  transform: translate(-50%, -78%);
  width: 140px;
  height: auto;
  min-height: 120px;
}

/* 2. BÓNG TRÒN DƯỚI ĐẤT THEO DÕI LINH VẬT (DYNAMIC SHADOW) */
.mascot-ground-shadow {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 12px;
  background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.28) 0%, rgba(15, 23, 42, 0) 75%);
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.85s ease, opacity 0.85s ease;
  z-index: 1;
}

/* 3. BỌC HÌNH ẢNH 3D VÀ HIỆU ỨNG NỔI (FLOAT) */
.mascot-bee-avatar-3d,
.mascot-bee-avatar {
  position: relative;
  width: 92px;
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: auto; /* Cho phép bé bấm trực tiếp vào chú ong để nhào lộn vui vẻ */
  cursor: pointer;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.16));
  animation: beelioBeeFloat 2.8s infinite ease-in-out;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mascot-bee-avatar-3d img,
.mascot-bee-avatar img,
.bee-mascot-render-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
  transform: scaleX(-1); /* Mặc định quay mặt và chỉ tay về bên phải theo hướng tiến của con đường */
  transition: transform 0.25s ease;
}

/* 4. CÁC TRẠNG THÁI HOẠT HỌA CỦA CHÚ ONG (MASCOT STATES) */

/* 4.1. Trạng thái nghỉ & bồng bềnh (Idle Hovering) */
@keyframes beelioBeeFloat {
  0% {
    transform: translateY(0px) rotate(0deg);
  }
  30% {
    transform: translateY(-8px) rotate(-2deg);
  }
  70% {
    transform: translateY(-3px) rotate(2.5deg);
  }
  100% {
    transform: translateY(0px) rotate(0deg);
  }
}

/* 4.2. Trạng thái đang bay chuyển mốc (Flight in progress) */
.beelio-mascot-entity.is-flying .mascot-bee-avatar-3d,
.g4-mascot-container.is-flying .mascot-bee-avatar {
  animation: beelioBeeFlightFlutter 0.18s infinite alternate ease-in-out !important;
  filter: drop-shadow(0 10px 18px rgba(245, 158, 11, 0.45));
}

.beelio-mascot-entity.is-flying .mascot-ground-shadow,
.g4-mascot-container.is-flying .mascot-ground-shadow {
  transform: translateX(-50%) scale(0.65);
  opacity: 0.18;
}

@keyframes beelioBeeFlightFlutter {
  0% {
    transform: translateY(-12px) scaleY(0.96) rotate(-5deg);
  }
  100% {
    transform: translateY(-8px) scaleY(1.04) rotate(-3deg);
  }
}

/* 4.3. Bay hoặc hướng sang trái (Trở lại hướng nguyên bản của ảnh là nhìn sang trái) */
.beelio-mascot-entity.fly-left .mascot-bee-avatar-3d img,
.g4-mascot-container.fly-left .mascot-bee-avatar img {
  transform: scaleX(1);
}

/* 4.4. Trạng thái tiếp đất nhún nhảy vui sướng (Landing Bounce) */
.beelio-mascot-entity.is-landing .mascot-bee-avatar-3d,
.g4-mascot-container.is-landing .mascot-bee-avatar {
  animation: beelioBeeLandBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

@keyframes beelioBeeLandBounce {
  0% {
    transform: translateY(-14px) scale(0.9, 1.15);
  }
  45% {
    transform: translateY(4px) scale(1.18, 0.85);
  }
  75% {
    transform: translateY(-4px) scale(0.96, 1.04);
  }
  100% {
    transform: translateY(0) scale(1, 1);
  }
}

/* 4.5. Nhào lộn vui vẻ khi bé chạm vào chú ong (Barrel Roll / Cheer Tap) */
.beelio-mascot-entity.is-spinning .mascot-bee-avatar-3d,
.g4-mascot-container.is-spinning .mascot-bee-avatar {
  animation: beelioBeeBarrelRoll 0.75s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
}

@keyframes beelioBeeBarrelRoll {
  0% {
    transform: scale(1) rotate(0deg);
  }
  30% {
    transform: scale(1.25) translateY(-14px) rotate(120deg);
  }
  70% {
    transform: scale(1.15) translateY(-8px) rotate(260deg);
  }
  100% {
    transform: scale(1) translateY(0) rotate(360deg);
  }
}

/* 5. BÓNG THOẠI BẬT LÊN (SPEECH BUBBLE — GỌN GÀNG, KHÔNG BAO GIỜ CHE NÚT BÀI HỌC) */
.beelio-mascot-entity .mascot-speech-bubble,
.mascot-speech-bubble {
  position: relative;
  background: rgba(255, 255, 255, 0.97);
  border: 1.8px solid var(--beelio-gold, #F6B91A);
  border-radius: 14px;
  padding: 4px 10px;
  font-family: var(--beelio-game-font, 'Nunito', sans-serif);
  font-size: 11px;
  font-weight: 800;
  color: var(--beelio-ink, #24324A);
  white-space: normal !important;
  flex-shrink: 0;
  height: auto;
  width: max-content;
  max-width: 142px;
  line-height: 1.28;
  box-shadow: 0 4px 12px rgba(36, 50, 74, 0.14);
  margin-bottom: 4px;
  z-index: 5;
  pointer-events: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  transform-origin: center bottom;
  animation: beelioSpeechPopIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Đuôi bóng thoại chỉ xuống đầu chú ong */
.mascot-speech-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #FFFFFF;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.04));
}

.mascot-speech-bubble::before {
  content: '';
  position: absolute;
  top: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: #CBD5E1;
  z-index: -1;
}

.mascot-speech-bubble.bubble-hidden {
  opacity: 0;
  transform: scale(0.6) translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Điều chỉnh vị trí linh vật ở chặng 1 / sát mép trái sang thảm cỏ thoáng để KHÔNG che Nút bài 3 */
.beelio-mascot-entity[data-stage-avoid-node3="1"],
.g4-mascot-container[data-stage-avoid-node3="1"] {
  transform: translate(-88%, -62%) !important;
}

.beelio-mascot-entity.edge-left .mascot-speech-bubble {
  transform: translateX(8px);
}
.beelio-mascot-entity.edge-left .mascot-speech-bubble::after,
.beelio-mascot-entity.edge-left .mascot-speech-bubble::before {
  left: 36%;
}
.beelio-mascot-entity.edge-right .mascot-speech-bubble {
  transform: translateX(-14px);
}
.beelio-mascot-entity.edge-right .mascot-speech-bubble::after,
.beelio-mascot-entity.edge-right .mascot-speech-bubble::before {
  left: 64%;
}

@keyframes beelioSpeechPopIn {
  0% {
    opacity: 0;
    transform: scale(0.6) translateY(8px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Tia sáng / tia hào hứng bên cạnh bóng thoại */
.bubble-spark-icon {
  display: inline-block;
  color: #F59E0B;
  font-size: 14px;
  animation: sparkPulse 1.2s infinite alternate ease-in-out;
}

@keyframes sparkPulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.2); opacity: 1; }
}

/* 6. HẠT PHẤN HOA / VỆT SÁNG BAY (SPARKLE TRAIL EMITTER) */
.bee-sparkle-trail {
  position: absolute;
  pointer-events: none;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  overflow: visible;
  z-index: 20;
}

.bee-particle {
  position: absolute;
  pointer-events: none;
  width: 7px;
  height: 7px;
  background: radial-gradient(circle, #FDE047 30%, #F59E0B 80%, transparent 100%);
  border-radius: 50%;
  opacity: 0.9;
  filter: drop-shadow(0 0 4px #F59E0B);
  animation: beeParticleFade 0.65s forwards ease-out;
}

@keyframes beeParticleFade {
  0% {
    transform: scale(1.2) translate(0, 0);
    opacity: 1;
  }
  100% {
    transform: scale(0.2) translate(var(--tx, -15px), var(--ty, 18px));
    opacity: 0;
  }
}

/* 7. HIỆU ỨNG HOVER KHI RÊ CHUỘT LÊN CHÚ ONG */
.beelio-mascot-entity:hover .mascot-bee-avatar-3d,
.g4-mascot-container:hover .mascot-bee-avatar {
  transform: translateY(-6px) scale(1.08);
  filter: drop-shadow(0 10px 20px rgba(245, 158, 11, 0.4));
}

.beelio-mascot-entity:active .mascot-bee-avatar-3d,
.g4-mascot-container:active .mascot-bee-avatar {
  transform: translateY(2px) scale(0.96);
}

/* 8. QUY CHUẨN TƯƠNG THÍCH MÀN HÌNH NHỎ (MOBILE RESPONSIVE) */
@media (max-width: 640px) {
  .beelio-mascot-entity,
  .g4-mascot-container {
    width: auto !important;
    min-width: 80px;
    height: auto !important;
    min-height: unset !important;
    transform: translate(-50%, -78%) !important;
  }
  
  .mascot-bee-avatar-3d,
  .mascot-bee-avatar {
    width: 66px !important;
    height: 66px !important;
  }
  
  .mascot-speech-bubble {
    font-size: 11px !important;
    padding: 4px 8px !important;
    max-width: 145px !important;
    margin-bottom: 4px !important;
    line-height: 1.3 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
  }

  .beelio-mascot-entity.edge-left .mascot-speech-bubble {
    transform: translateX(10px) !important;
  }
  .beelio-mascot-entity.edge-left .mascot-speech-bubble::after,
  .beelio-mascot-entity.edge-left .mascot-speech-bubble::before {
    left: 34% !important;
  }
  .beelio-mascot-entity.edge-right .mascot-speech-bubble {
    transform: translateX(-12px) !important;
  }
  .beelio-mascot-entity.edge-right .mascot-speech-bubble::after,
  .beelio-mascot-entity.edge-right .mascot-speech-bubble::before {
    left: 66% !important;
  }
}
