/* Bloxy English — chuyển động: Bloxy có khớp, sân khấu theo chủ đề, hiệu ứng. */

/* ================= Bloxy chuyển động ================= */
.avatar-wrap svg.bloxy { width: 100%; height: 100%; overflow: visible; }
.bloxy * { transform-box: fill-box; }
.b-head { transform-origin: 50% 100%; transition: transform 0.25s; }
.b-body { transform-origin: 50% 100%; }
.b-arm-l, .b-arm-r { transform-origin: 50% 8%; transition: transform 0.25s; }
.b-leg { transform-origin: 50% 0%; }
.b-eyes { transition: transform 0.25s; }
.b-eye { transform-origin: 50% 50%; animation: blink 4.2s infinite; }
.b-mouth { opacity: 0; transform-origin: 50% 50%; }
.b-ear { transform-origin: 50% 50%; transition: opacity 0.2s; }
.avatar-wrap { --lvl: 0; }

/* Đứng chờ: thở nhẹ, chớp mắt */
[data-state="idle"] .bloxy { animation: bob 2.6s ease-in-out infinite; }
/* Đang nói: miệng mở ra khép vào, đầu gật nhẹ, tay khua */
[data-state="talk"] .b-mouth { animation: mouth 0.22s ease-in-out infinite alternate; }
[data-state="talk"] .b-smile { opacity: 0; }
[data-state="talk"] .b-head { animation: nod 0.9s ease-in-out infinite; }
[data-state="talk"] .b-arm-r { animation: gesture 1.4s ease-in-out infinite; }
/* Đang nghe bé: nghiêng đầu, tai sáng và phình theo giọng bé */
[data-state="listen"] .b-head { transform: rotate(-8deg); }
[data-state="listen"] .b-ear { opacity: 0.9; transform: scale(calc(1 + var(--lvl) * 0.9)); }
[data-state="listen"] .bloxy { animation: bob 1.6s ease-in-out infinite; }
/* Đang nghĩ: mắt nhìn lên, bong bóng ? */
[data-state="think"] .b-eyes { transform: translateY(-6px); }
[data-state="think"] .b-head { animation: tilt 1.6s ease-in-out infinite; }
[data-state="think"]::after { content: "?"; position: absolute; right: -6px; top: -12px; font: 800 34px "Baloo 2", sans-serif; color: var(--primary); animation: bob 1s ease-in-out infinite; }
/* Vui sướng: nhảy cẫng */
[data-state="happy"] .bloxy { animation: hop 0.55s ease-in-out infinite; }
[data-state="happy"] .b-arm-l { transform: rotate(150deg); }
[data-state="happy"] .b-arm-r { transform: rotate(-150deg); }
[data-state="happy"] .b-mouth { opacity: 1; }
[data-state="happy"] .b-smile { opacity: 0; }
/* Nhảy theo nhạc */
[data-state="dance"] .bloxy { animation: sway 0.55s ease-in-out infinite alternate; }
[data-state="dance"] .b-arm-l { animation: armup 0.55s ease-in-out infinite alternate; }
[data-state="dance"] .b-arm-r { animation: armup 0.55s ease-in-out infinite alternate-reverse; }
[data-state="dance"] .b-leg-l { animation: kick 0.55s ease-in-out infinite alternate; }
/* Ngã oạch */
[data-state="oops"] .bloxy { animation: fall 1.4s ease-in-out; }
[data-state="oops"] .b-mouth { opacity: 1; }
[data-state="oops"] .b-smile { opacity: 0; }
/* Ngạc nhiên */
[data-state="surprised"] .b-eye { animation: none; transform: scale(1.35); }
[data-state="surprised"] .b-mouth { opacity: 1; transform: scale(0.8, 1.2); }
[data-state="surprised"] .b-smile { opacity: 0; }
[data-state="surprised"] .bloxy { animation: hop 0.5s ease-out 1; }
/* Vẫy tay */
[data-state="wave"] .b-arm-r { animation: wave 0.4s ease-in-out infinite alternate; }
[data-state="wave"] .bloxy { animation: bob 1.2s ease-in-out infinite; }
/* Thì thầm */
[data-state="whisper"] .b-head { transform: rotate(10deg) translateX(4px); }
[data-state="whisper"] .b-arm-r { transform: rotate(-120deg); }
[data-state="whisper"] .b-mouth { animation: mouth 0.35s ease-in-out infinite alternate; }

@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes mouth { from { opacity: 1; transform: scaleY(0.25); } to { opacity: 1; transform: scaleY(1.1); } }
@keyframes nod { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(3deg) translateY(1px); } }
@keyframes gesture { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-35deg); } }
@keyframes tilt { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 30% { transform: translateY(0) scale(1.08, 0.9); } 60% { transform: translateY(-28px) scale(0.95, 1.06); } }
@keyframes sway { from { transform: rotate(-8deg) translateX(-6px); } to { transform: rotate(8deg) translateX(6px); } }
@keyframes armup { from { transform: rotate(20deg); } to { transform: rotate(-160deg); } }
@keyframes kick { from { transform: rotate(0); } to { transform: rotate(-25deg); } }
@keyframes fall { 0% { transform: rotate(0); } 25% { transform: rotate(75deg) translateY(30px); } 70% { transform: rotate(75deg) translateY(30px); } 100% { transform: rotate(0); } }
@keyframes wave { from { transform: rotate(-150deg); } to { transform: rotate(-110deg); } }

/* ================= Sân khấu phiêu lưu ================= */
.scene { position: relative; width: 100%; height: 210px; border-radius: 26px; box-shadow: var(--shadow); overflow: hidden; background: linear-gradient(180deg, #bfe6ff, #e9fbe8); }
.scene .deco { position: absolute; inset: 0; pointer-events: none; }
.scene-bloxy { position: absolute; left: 10px; bottom: 6px; width: 104px; height: 116px; z-index: 2; }
.scene-items { position: absolute; left: 120px; right: 8px; top: 18px; bottom: 18px; display: flex; align-items: center; justify-content: center; gap: 6px; z-index: 2; }
.scene-items .si { width: 74px; height: 74px; display: flex; align-items: center; justify-content: center; font-size: 60px; line-height: 1; animation: popin 0.5s cubic-bezier(.3,1.6,.5,1) backwards, floaty 2.8s ease-in-out infinite 0.5s; }
.scene-items .si img { width: 100%; height: 100%; object-fit: contain; }
.scene-items .si:nth-child(2) { animation-delay: 0.12s, 0.9s; }
.scene-items .si:nth-child(3) { animation-delay: 0.24s, 1.3s; }
.scene.shake { animation: shake 0.45s; }
.env-badge { position: absolute; right: 10px; top: 8px; z-index: 3; background: rgba(255,255,255,0.88); border-radius: 99px; padding: 2px 10px; font-size: 13px; font-weight: 700; color: var(--ink); }
.env-badge:empty { display: none; }

/* Thế giới khối vuông: khối trôi, mây bay */
.scene.t-blocks { background: linear-gradient(180deg, #8fd3ff 0%, #c8ecff 60%, #7ed957 60%, #5cb85c 100%); }
.scene.t-blocks .deco::before { content: ""; position: absolute; width: 60px; height: 22px; border-radius: 12px; background: #fff; top: 22px; left: -70px; box-shadow: 140px 18px 0 -2px #fff, 300px -6px 0 4px #fff; animation: clouds 24s linear infinite; opacity: 0.9; }
.scene.t-blocks .deco::after { content: ""; position: absolute; width: 26px; height: 26px; background: #c28b52; border: 3px solid #7a5230; right: 30px; bottom: 70px; box-shadow: -60px 30px 0 #e8b04a, -150px -20px 0 #a0a0a0; animation: floaty 3s ease-in-out infinite; }
/* Sân khấu nhảy: đèn disco */
.scene.t-dance { background: radial-gradient(circle at 50% 120%, #ff5fa2 0%, #5b2c83 55%, #1b1036 100%); }
.scene.t-dance .deco::before { content: ""; position: absolute; inset: -40%; background: conic-gradient(from 0deg, rgba(255,255,255,0) 0 20deg, rgba(255,230,120,0.35) 20deg 30deg, rgba(255,255,255,0) 30deg 110deg, rgba(120,220,255,0.35) 110deg 120deg, rgba(255,255,255,0) 120deg 220deg, rgba(255,120,200,0.35) 220deg 230deg, rgba(255,255,255,0) 230deg); animation: spin 6s linear infinite; }
.scene.t-dance .deco::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 26px; background: repeating-linear-gradient(90deg, #ff5fa2 0 40px, #3fb7ff 40px 80px, #ffd23f 80px 120px); animation: floorlights 1.2s steps(3) infinite; opacity: 0.8; }
/* Rạp xiếc hài */
.scene.t-funny { background: repeating-linear-gradient(90deg, #ff6b6b 0 34px, #fff3e0 34px 68px); }
.scene.t-funny .deco::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 34px; background: radial-gradient(circle at 17px 0, #ffd23f 16px, transparent 17px) 0 0 / 34px 34px repeat-x; }
.scene.t-funny .deco::after { content: ""; position: absolute; width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,200,0.55), transparent 65%); left: 30%; top: 10%; animation: spot 4s ease-in-out infinite alternate; }
/* Công viên thú cưng */
.scene.t-pets { background: linear-gradient(180deg, #ffe7b8 0%, #cdeeff 45%, #a6e3a1 45%, #7cc576 100%); }
.scene.t-pets .deco::before { content: ""; position: absolute; width: 46px; height: 46px; border-radius: 50%; background: #ffd23f; right: 24px; top: 14px; box-shadow: 0 0 0 10px rgba(255,210,63,0.3); animation: floaty 4s ease-in-out infinite; }
.scene.t-pets .deco::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 30px; background: radial-gradient(circle at 10px 30px, #5cae57 12px, transparent 13px) 0 0 / 24px 30px repeat-x; }

@keyframes popin { from { transform: scale(0) rotate(-20deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes shake { 0%, 100% { transform: translate(0); } 20% { transform: translate(-8px, 3px); } 40% { transform: translate(7px, -3px); } 60% { transform: translate(-5px, 2px); } 80% { transform: translate(4px, -1px); } }
@keyframes clouds { from { transform: translateX(0); } to { transform: translateX(640px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes floorlights { to { background-position: 120px 0; } }
@keyframes spot { from { transform: translateX(-60px); } to { transform: translateX(80px); } }

/* Sao bay vào bộ đếm */
.fly-star { position: fixed; z-index: 30; font-size: 34px; pointer-events: none; }
/* Màn hình LEVEL UP */
.levelup { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(42,31,77,0.55); color: #fff; font: 800 44px "Baloo 2", sans-serif; text-shadow: 0 4px 0 #5b3fe0; animation: pop 0.3s; text-align: center; }
.levelup small { font-size: 22px; font-weight: 600; text-shadow: none; }

/* Nút micro: bóng giọng nói phình theo giọng bé; giữ để nói */
.round-btn.mic { --lvl: 0; touch-action: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.round-btn.mic.listening, .round-btn.mic.holding { animation: none; box-shadow: 0 0 0 calc(6px + var(--lvl) * 30px) rgba(255,45,85,0.25), var(--shadow); transition: box-shadow 0.08s; }
.round-btn.mic.holding { background: #ff2d55; transform: scale(1.08); }
.round-btn.mic.ptt span { font-size: 12px; }
.try-card.now { animation: trypulse 0.5s ease-in-out 2; }
@keyframes trypulse { 50% { transform: scale(1.05); box-shadow: 0 0 0 8px rgba(255,207,74,0.35); } }

/* Chẩn đoán micro (Góc phụ huynh) */
.diag { width: 100%; background: var(--card); border-radius: 16px; padding: 8px; box-shadow: var(--shadow); overflow-x: auto; }
.diag table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: center; }
.diag th { color: var(--muted); font-weight: 600; }
.diag td { border-top: 1px solid #eee8ff; padding: 3px; }
.form input[type=range] { width: 100%; }
.mic-test { width: 100%; height: 18px; background: #e3dcff; border-radius: 99px; overflow: hidden; }
.mic-test .fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--good), #ffd23f, var(--danger)); transition: width 0.08s; }
.credits { font-size: 12px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .scene .deco::before, .scene .deco::after { animation: none; }
}
