/* ============================================================================
 * Học Cùng Sơn — beast-fx.css (Đội Animation, Giai đoạn 1 — 2026-11-14)
 * ----------------------------------------------------------------------------
 * Toàn bộ keyframes + class của module beast-fx.js. File MỚI, độc lập —
 * KHÔNG sửa css/app.css. Giai đoạn 2 mới nối vào index.html (sau
 * <link rel="stylesheet" href="css/app.css">).
 *
 * TRUNG THỰC: đây là animation 2D (CSS keyframes + hạt canvas) trên ảnh
 * WebP chibi 3D sẵn có — KHÔNG phải xoay 3D thời gian thực.
 *
 * QUY TẮC Z-INDEX (bắt buộc — xem docs/beast-fx-integration.md):
 * - Lớp hiệu ứng trong trang: tối đa z-index 72.
 * - Thấp hơn: toast #app-toast (z 100), bottom-nav (z 55 — hiệu ứng KHÔNG
 *   phủ lên nav, vì hiệu ứng nằm trong khung nội dung trang), và dialog
 *   #app-modal (top layer của trình duyệt, luôn trên mọi z-index).
 * - Nút 'Bỏ qua' (z 72 trong khung unlock) là phần tử DUY NHẤT được bấm
 *   trong lớp hiệu ứng; mọi lớp hạt/hào quang đều pointer-events:none.
 * - KHÔNG BAO GIỜ dùng .bfx-unlock làm overlay fixed toàn màn hình trong
 *   phòng thi: thanh Thi/Nộp bài là sticky z 6/25 — overlay fixed z 70
 *   sẽ che mất nút Nộp bài. Chuỗi mở khóa chỉ chạy ở Trang 9 / Bộ sưu
 *   tập / sau video / Trang 13 — không có phòng thi ở đó.
 * ========================================================================== */

/* ---- Lớp phủ hạt canvas (burst) — phủ khớp khung thú, không chặn bấm --- */
.bfx-particles {
  position: fixed;
  z-index: 10001; /* trên lớp phủ mở khóa (9999) để hạt chúc mừng thấy được */
  pointer-events: none;
}

/* ---- 1. IDLE: nhấp nhô / bay nhẹ — giữ đúng nhịp mockup + Trang 9 ------
 * bob 2.4s, bay nghiêng ±2° (khớp hcs-petd-idle / hcs-petd-fly trong
 * pets.js — class riêng bfx-* để không đụng hiệu ứng đã có). */
.bfx-idle { animation: bfx-bob 2.4s ease-in-out infinite; }
.bfx-idle-fly { animation: bfx-bob-fly 2.4s ease-in-out infinite; }
@keyframes bfx-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes bfx-bob-fly {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}

/* Tap vào thú: nảy lên một nhịp (0.45s). */
.bfx-hop { animation: bfx-hop .45s ease; }
@keyframes bfx-hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-16px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

/* Bong bóng thoại khi bấm thú (hiện 2s rồi JS gỡ). */
.bfx-say {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 2px solid #E8EDF3;
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 15px; font-weight: 800; color: #143A6B;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
  animation: bfx-bubble-in .25s ease;
  box-shadow: 0 6px 18px rgba(20,58,107,.15);
}
@keyframes bfx-bubble-in {
  from { opacity: 0; transform: translateX(-50%) translateY(6px) scale(.92); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ---- 2. MỞ KHÓA: khung chuỗi ------------------------------------------ */
.bfx-unlock {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px 20px;
  text-align: center;
  scroll-margin-top: 76px; /* Vòng sửa 6: header cố định 64px + 12px hở — khi
     collection.js cuộn tới khung unlock ở đầu trang, khung không bị kẹt
     dưới header. Chỉ là khoảng cuộn, không đổi layout. */
  /* z-index của khung nằm trong luồng trang (không fixed) nên không che
     thanh dính nào; con cháu dùng z-index nội bộ 1–3, nút Bỏ qua 72. */
}
.bfx-stage { position: relative; min-height: 300px; display: grid; place-items: center; }
.bfx-skip {
  position: absolute;
  top: 0; right: 0;
  z-index: 72;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 99px;
  border: 2px solid #E8EDF3;
  background: #fff;
  color: #143A6B;
  font: inherit;
  font-size: 15px; font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(20,58,107,.12);
}
.bfx-skip:active { transform: scale(.96); }

/* Trứng vẽ bằng CSS (dự phòng khi điểm gọi không truyền opts.eggImg;
   ảnh trứng thật: img/egg-hatching.webp, từ 15/11/2026 — điểm gọi nào
   truyền opts.eggImg thì dùng ảnh đó, xem .bfx-egg-img bên dưới). */
.bfx-egg-wrap { position: relative; z-index: 1; }
.bfx-egg {
  width: 150px; height: 190px;
  margin: 0 auto;
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  background:
    radial-gradient(circle at 35% 30%, #FFF9DB 0%, #FFE9A8 45%, #F5C542 100%);
  border: 3px solid #E8A93D;
  box-shadow: 0 12px 28px rgba(20,58,107,.18), inset 0 -18px 30px rgba(232,169,61,.35);
  position: relative;
  overflow: hidden;
}
.bfx-egg::before { /* đốm trang trí trên vỏ trứng */
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 70% 60%, rgba(255,122,41,.35) 0 12px, transparent 13px),
    radial-gradient(circle at 30% 70%, rgba(26,158,87,.3) 0 9px, transparent 10px),
    radial-gradient(circle at 55% 35%, rgba(29,111,209,.3) 0 8px, transparent 9px);
}
.bfx-egg-crack {
  position: absolute; inset: 0;
  opacity: 0;
  background:
    linear-gradient(115deg, transparent 46%, #8D6E63 47% 49%, transparent 50%),
    linear-gradient(65deg, transparent 52%, #8D6E63 53% 55%, transparent 56%);
}
.bfx-egg-shake { animation: bfx-shake .12s linear infinite; }
@keyframes bfx-shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-4px) rotate(-3deg); }
  75% { transform: translateX(4px) rotate(3deg); }
}
.bfx-egg-crack-on { animation: bfx-crack .3s ease forwards; }
.bfx-egg-crack-on .bfx-egg-crack { opacity: 1; }
@keyframes bfx-crack {
  0% { transform: scale(1); }
  60% { transform: scale(1.06) rotate(-1.5deg); }
  100% { transform: scale(1.02); }
}
.bfx-egg-img { width: 150px; height: 190px; object-fit: contain; }
.bfx-egg-img.bfx-egg-shake { animation: bfx-shake .12s linear infinite; }

/* Lóe sáng lúc trứng vỡ. */
.bfx-flash {
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,.95) 0%, rgba(255,249,219,.55) 45%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}
.bfx-flash-on { animation: bfx-flash .2s ease forwards; }
@keyframes bfx-flash {
  0% { opacity: 0; transform: scale(.6); }
  50% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1.3); }
}

/* Thú hiện ra: scale + fade. */
.bfx-beast { position: relative; z-index: 1; }
.bfx-beast img {
  height: 260px; max-width: 92%;
  object-fit: contain;
  position: relative; z-index: 2;
}
.bfx-beast-ph {
  width: 180px; height: 180px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 72px; font-weight: 900; color: #fff;
  position: relative; z-index: 2;
}
.bfx-beast-in { animation: bfx-pop-in .5s ease both; }
@keyframes bfx-pop-in {
  from { opacity: 0; transform: scale(.6) translateY(16px); }
  60% { opacity: 1; transform: scale(1.06) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Hào quang sức mạnh: pulse quanh thú (màu đặt inline theo hệ). */
.bfx-aura {
  position: absolute;
  inset: -30px;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}
.bfx-aura-on { animation: bfx-aura-pulse 1.2s ease-in-out infinite; }
@keyframes bfx-aura-pulse {
  0%, 100% { opacity: .45; transform: scale(1); }
  50% { opacity: .9; transform: scale(1.08); }
}

/* Banner tên thú + 'Đã thu phục!' */
.bfx-banner { margin-top: 6px; position: relative; z-index: 2; }
.bfx-banner-in { animation: bfx-banner-in .4s ease both; }
@keyframes bfx-banner-in {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.bfx-banner-name { font-size: 26px; font-weight: 900; color: #143A6B; }
.bfx-banner-title { font-size: 20px; font-weight: 900; color: #1A9E57; margin-top: 2px; }
.bfx-banner-sub { font-size: 15px; font-weight: 700; color: #5B6B82; margin-top: 2px; }
.bfx-rewards { margin-top: 10px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: 36px; }
.bfx-fly-star, .bfx-fly-xp {
  display: inline-block;
  font-size: 22px; font-weight: 900;
  animation: bfx-fly-up .8s ease both;
}
.bfx-fly-star { color: #FFC107; text-shadow: 0 2px 6px rgba(255,193,7,.5); }
.bfx-fly-star:nth-child(2) { animation-delay: .12s; }
.bfx-fly-star:nth-child(3) { animation-delay: .24s; }
.bfx-fly-star:nth-child(4) { animation-delay: .36s; }
.bfx-fly-star:nth-child(5) { animation-delay: .48s; }
.bfx-fly-xp {
  font-size: 18px; color: #1A9E57;
  background: #E6F7ED;
  border: 2px solid #1A9E57;
  border-radius: 99px;
  padding: 2px 12px;
  animation-delay: .3s;
}
@keyframes bfx-fly-up {
  from { opacity: 0; transform: translateY(18px) scale(.6); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- 3. PHÔ DIỄN SỨC MẠNH -------------------------------------------- */
/* Glow quanh thú lúc phô diễn (màu --bfx-glow đặt inline theo hệ). */
.bfx-glow-on {
  filter: drop-shadow(0 0 14px var(--bfx-glow, #FFC107)) drop-shadow(0 0 34px var(--bfx-glow, #FFC107));
  transition: filter .25s ease;
}
/* Bóng Tối: rung NHẸ khung thú ~2px — CHỈ khung thú, KHÔNG rung màn hình. */
.bfx-shake-soft { animation: bfx-shake-soft .18s linear infinite; }
@keyframes bfx-shake-soft {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-2px, 1px); }
  75% { transform: translate(2px, -1px); }
}
/* Điện: chớp sáng khung thú (nhấp nháy nhẹ, không chớp toàn màn hình). */
.bfx-bolt-flash { animation: bfx-bolt-flash .16s steps(2) infinite; }
@keyframes bfx-bolt-flash {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.7) saturate(1.4); }
}
/* Thẻ tên kỹ năng hiện khi phô diễn. */
.bfx-skill {
  position: absolute;
  left: 50%; bottom: 8px;
  transform: translateX(-50%);
  z-index: 3;
  background: #fff;
  border: 3px solid #FFC107;
  border-radius: 16px;
  padding: 10px 16px;
  text-align: center;
  max-width: calc(100% - 24px);
  pointer-events: none;
  box-shadow: 0 10px 26px rgba(20,58,107,.2);
  animation: bfx-banner-in .3s ease both;
}
.bfx-skill-name { font-size: 18px; font-weight: 900; color: #143A6B; }
.bfx-skill-desc { font-size: 14px; font-weight: 700; color: #5B6B82; margin-top: 2px; }

/* ---- Tôn trọng prefers-reduced-motion: tắt hết chuyển động của module -- */
@media (prefers-reduced-motion: reduce) {
  .bfx-idle, .bfx-idle-fly, .bfx-hop,
  .bfx-egg-shake, .bfx-egg-crack-on,
  .bfx-flash-on, .bfx-beast-in, .bfx-aura-on,
  .bfx-banner-in, .bfx-fly-star, .bfx-fly-xp,
  .bfx-shake-soft, .bfx-bolt-flash, .bfx-bubble-in {
    animation: none !important;
  }
  .bfx-aura-on { opacity: .6; }
  .bfx-beast-in, .bfx-banner-in { opacity: 1; }
}
