/* 🧊 Cubi – linh vật hướng dẫn của CubeX (mascot.js + cubi-lines.js). Nhỏ, ở mép dưới bên trái, không che nút; đang chơi thì tự ẩn. */
.cubi { position: fixed; left: 0; top: 0; z-index: 44; width: 60px; height: 66px; padding: 0; border: 0; background: none; cursor: pointer;
  transition: opacity .3s; will-change: transform; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.cubi:focus-visible { outline: 3px solid var(--accent, #5b3df5); outline-offset: 2px; border-radius: 12px; }
.cubi .cbi { width: 100%; height: 100%; transition: transform .2s; transform-origin: 50% 90%; }
.cubi.left .cbi { transform: scaleX(-1); }
.cubi svg { display: block; width: 100%; height: 100%; overflow: visible; }
.cubi[hidden], .cubi-bub[hidden], .cubi-mini[hidden] { display: none !important; }

/* các phần của hình */
.cubi .cb-body { transform-box: view-box; transform-origin: 32px 66px; animation: cbBreathe 3.2s ease-in-out infinite; }
.cubi .cb-sh { transform-box: fill-box; transform-origin: center; }
.cubi .cb-leg { transform-box: fill-box; transform-origin: 50% 0; }
.cubi .cb-a1 { transform-box: view-box; transform-origin: 8px 41px; transition: transform .3s; }
.cubi .cb-a2 { transform-box: view-box; transform-origin: 57px 41px; transition: transform .35s cubic-bezier(.3, 1.4, .5, 1); }
.cubi .cb-pup { transform: translate(var(--lx, 0px), var(--ly, 0px)); transition: transform .18s; }
.cubi .cb-eyes { transform-box: fill-box; transform-origin: center; animation: cbBlink 4.6s infinite; }
.cubi .cb-happy, .cubi .cb-sleepy, .cubi .cb-mo-open, .cubi .cb-zz { opacity: 0; }
.cubi .cb-zz { font: 800 11px/1 system-ui, sans-serif; fill: #5b3df5; }
@keyframes cbBreathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.015, .975); } }
@keyframes cbBlink { 0%, 93%, 100% { transform: scaleY(1); } 95.5% { transform: scaleY(.08); } }

/* đi bộ: bước chân thật – chân thay nhau nhấc, người nhún + nghiêng, tay đánh ngược chân */
.cubi.walk .cb-body { animation: cbWalkBody .44s ease-in-out infinite; }
.cubi.walk .cb-l1 { animation: cbStep .44s ease-in-out infinite; }
.cubi.walk .cb-l2 { animation: cbStep .44s ease-in-out -.22s infinite; }
.cubi.walk .cb-a1 { animation: cbSwing .44s ease-in-out infinite; }
.cubi.walk .cb-a2 { animation: cbSwing .44s ease-in-out -.22s infinite; }
.cubi.walk .cb-sh { animation: cbShadow .22s ease-in-out infinite alternate; }
@keyframes cbWalkBody { 0%, 50%, 100% { transform: translateY(0) rotate(2deg) scale(1.02, .97); } 25%, 75% { transform: translateY(-3.5px) rotate(4deg) scale(.98, 1.03); } }
@keyframes cbStep { 0%, 100% { transform: translate(0, 0) rotate(0); } 25% { transform: translate(3px, -4px) rotate(-12deg); } 50% { transform: translate(0, 0) rotate(0); } 75% { transform: translate(-2px, 0) rotate(8deg); } }
@keyframes cbSwing { 0%, 100% { transform: rotate(-18deg); } 50% { transform: rotate(18deg); } }
@keyframes cbShadow { to { transform: scaleX(.85); opacity: .7; } }

/* nói: miệng mấp máy */
.cubi.talk .cb-mo-open { animation: cbTalk .26s steps(1) infinite; }
.cubi.talk .cb-mo { animation: cbTalk2 .26s steps(1) infinite; }
@keyframes cbTalk { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes cbTalk2 { 0% { opacity: 0; } 50% { opacity: 1; } }
/* chỉ tay về phía nút (góc --pa do mascot.js tính) */
.cubi.point .cb-a2 { transform: rotate(var(--pa, -100deg)); animation: none; }
.cubi.point .cb-hand { animation: cbWiggle .7s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes cbWiggle { 50% { transform: scale(1.25); } }
/* vẫy tay */
.cubi.wave .cb-a2 { animation: cbWave .45s ease-in-out 4; }
@keyframes cbWave { 0%, 100% { transform: rotate(-120deg); } 50% { transform: rotate(-160deg); } }
/* vui: mắt cười ^ ^ + nhảy lên */
.cubi.happy .cb-eyes, .cubi.sleep .cb-eyes { opacity: 0; }
.cubi.happy .cb-happy { opacity: 1; }
.cubi.hop .cb-body { animation: cbHop .5s cubic-bezier(.3, .7, .4, 1) 2; }
@keyframes cbHop { 0%, 100% { transform: translateY(0) scale(1, 1); } 15% { transform: translateY(0) scale(1.1, .88); } 45% { transform: translateY(-12px) scale(.94, 1.08); } 80% { transform: translateY(0) scale(1.06, .94); } }
/* bị chọc: xoay vòng */
.cubi.spin .cbi { animation: cbSpin .7s ease-in-out; }
@keyframes cbSpin { 50% { transform: rotate(180deg) scale(.9); } 100% { transform: rotate(360deg); } }
/* ngủ */
.cubi.sleep .cb-sleepy, .cubi.sleep .cb-zz { opacity: 1; }
.cubi.sleep .cb-zz { animation: cbZz 1.6s ease-in-out infinite; }
@keyframes cbZz { 0% { transform: translate(0, 0); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(6px, -12px); opacity: 0; } }
/* nhìn quanh, vươn vai */
.cubi.stretch .cb-body { animation: cbStretch 1.2s ease-in-out; }
.cubi.stretch .cb-a1 { transform: rotate(150deg); } .cubi.stretch .cb-a2 { transform: rotate(-150deg); }
@keyframes cbStretch { 40%, 60% { transform: scale(.96, 1.08); } }
/* biến mất / hiện ra (đi xa hoặc qua trang mới – không bay ngang màn hình) */
.cubi.poof-out .cbi { animation: cbOut .26s ease-in forwards; }
.cubi.poof-in .cbi { animation: cbIn .42s cubic-bezier(.3, 1.6, .5, 1); }
.cubi.left.poof-out .cbi { animation-name: cbOutL; } .cubi.left.poof-in .cbi { animation-name: cbInL; }
@keyframes cbOut { to { transform: scale(.1, 1.3) translateY(10px); opacity: 0; } }
@keyframes cbOutL { to { transform: scaleX(-.1) scaleY(1.3) translateY(10px); opacity: 0; } }
@keyframes cbIn { 0% { transform: scale(.2); opacity: 0; } 60% { transform: scale(1.15, .9); opacity: 1; } 100% { transform: scale(1); } }
@keyframes cbInL { 0% { transform: scaleX(-.2) scaleY(.2); opacity: 0; } 60% { transform: scaleX(-1.15) scaleY(.9); opacity: 1; } 100% { transform: scaleX(-1); } }
.cubi-spark { position: fixed; z-index: 44; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; pointer-events: none; animation: cbSpark .55s ease-out forwards; }
@keyframes cbSpark { to { transform: translate(var(--sx), var(--sy)) scale(.2); opacity: 0; } }
/* đang cuộn trang → mờ đi cho khỏi vướng */
.cubi.duck { opacity: .3; }
.cubi:hover { opacity: 1; }

/* bong bóng trò chuyện (có đuôi chỉ về Cubi) */
.cubi-bub { position: fixed; left: 0; top: 0; z-index: 47; width: max-content; max-width: min(290px, calc(100vw - 24px)); min-width: 150px; padding: 10px 13px; border-radius: 18px;
  background: var(--panel, #fff); color: var(--text, #1d1b2c); border: 2px solid var(--accent, #5b3df5); box-shadow: 0 10px 28px rgba(0, 0, 0, .2); font-size: .95rem; line-height: 1.45;
  animation: cbBubIn .22s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes cbBubIn { from { transform: scale(.7); opacity: 0; } }
.cubi-bub::after { content: ''; position: absolute; width: 14px; height: 14px; background: inherit; border: inherit; border-width: 0 2px 2px 0; }
.cubi-bub.t-none::after { display: none; }
.cubi-bub.t-down::after { left: calc(var(--tx, 50%) - 8px); bottom: -9px; transform: rotate(45deg); }
.cubi-bub.t-up::after { left: calc(var(--tx, 50%) - 8px); top: -9px; transform: rotate(-135deg); }
.cubi-bub.t-left::after { top: calc(var(--ty, 50%) - 8px); left: -9px; transform: rotate(135deg); }
.cubi-bub.t-right::after { top: calc(var(--ty, 50%) - 8px); right: -9px; transform: rotate(-45deg); }
.cubi-bub .cbb-h { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: .78rem; font-weight: 800; color: var(--muted, #777); }
.cubi-bub .cbb-h span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cubi-bub .cbb-h small { margin-left: auto; font-weight: 700; white-space: nowrap; }
.cubi-bub .cbb-x { flex: none; width: 28px; height: 28px; min-height: 0; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--muted, #777); font-size: .95rem; cursor: pointer; }
.cubi-bub .cbb-x:hover { background: var(--surface, #f2f0ff); }
.cubi-bub .cbb-t { margin: 0; min-height: 1.45em; }
.cubi-bub .cbb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cubi-bub .cbb-t i { font-style: normal; opacity: 0; }
.cubi-bub .cbb-bar { height: 3px; margin: 8px 0 0; border-radius: 3px; background: var(--border, #e3e0f2); overflow: hidden; }
.cubi-bub .cbb-bar b { display: block; height: 100%; width: 0; background: var(--accent, #5b3df5); }
.cubi-bub.paused .cbb-bar b { background: #f4a300; }
.cubi-bub .cbb-pause { margin: 4px 0 0; font-size: .78rem; color: #b97800; font-weight: 700; }
.cubi-bub .cbb-list { display: grid; gap: 6px; margin-top: 8px; width: min(266px, calc(100vw - 52px)); max-height: min(50vh, 340px); overflow: auto; }
.cubi-bub .cbb-list button { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 8px 10px; border-radius: 10px; text-align: left;
  border: 1px solid var(--border, #ddd); background: var(--surface, #f6f5ff); color: inherit; font: inherit; font-size: .9rem; cursor: pointer; }
.cubi-bub .cbb-list button:hover { border-color: var(--accent, #5b3df5); }
.cubi-bub .cbb-list button.here { border-color: var(--accent, #5b3df5); font-weight: 700; }
.cubi-bub .cbb-nav { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.cubi-bub .cbb-nav button { min-height: 38px; padding: 0 14px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; border: 1px solid var(--border, #ddd); background: var(--surface, #f6f5ff); color: inherit; }
.cubi-bub .cbb-nav button.go { background: var(--accent, #5b3df5); border-color: var(--accent, #5b3df5); color: #fff; }

/* ô đang được chỉ: viền vàng nhấp nháy (không che, không làm tối màn hình) */
.cubi-hl { outline: 3px solid #ffb703 !important; outline-offset: 3px; animation: cubiHl 1.1s ease-in-out infinite; }
@keyframes cubiHl { 50% { outline-color: rgba(255, 183, 3, .25); } }

/* nút ✕ tắt Cubi (góc trên-phải Cubi; máy tính: rê chuột vào Cubi · điện thoại: khi mở menu Cubi) */
.cubi-x { position: fixed; left: 0; top: 0; z-index: 46; width: 24px; height: 24px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--panel, #fff);
  background: #1d1b2c; color: #fff; font-size: 12px; font-weight: 800; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
.cubi-x:hover { background: #e5484d; }
.cubi-x[hidden] { display: none !important; }
@media (pointer: coarse) { .cubi-x { width: 30px; height: 30px; font-size: 14px; } }
.cubi-bub .cbb-off { margin-top: 6px; text-align: center; }
.cubi-bub .cbb-off button { min-height: 32px; padding: 4px 6px; border: 0; background: none; color: var(--muted, #777); font: inherit; font-size: .82rem; text-decoration: underline; cursor: pointer; }

/* nút nhỏ gọi Cubi lại khi đã ẩn */
.cubi-mini { position: fixed; left: max(8px, env(safe-area-inset-left)); bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 44; width: 34px; height: 34px; padding: 0;
  border-radius: 50%; border: 1px solid var(--border, #ddd); background: var(--panel, #fff); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); font-size: 1.05rem; cursor: pointer; opacity: .75; }
.cubi-mini:hover { opacity: 1; }
@media (max-width: 600px) {
  .cubi { width: 50px; height: 55px; }
  .cubi-mini { bottom: calc(var(--nav-h, 64px) + 10px + env(safe-area-inset-bottom)); }
}
/* đang chơi (bấm giờ, đấu, chơi khối lớn…): Cubi biến mất hẳn */
body.timing .cubi, body.play-mode .cubi, body.bigplay-mode .cubi, body.duel-playing .cubi, body.dy-playing .cubi,
body.timing .cubi-bub, body.play-mode .cubi-bub, body.bigplay-mode .cubi-bub, body.duel-playing .cubi-bub, body.dy-playing .cubi-bub,
body.timing .cubi-x, body.play-mode .cubi-x, body.bigplay-mode .cubi-x, body.duel-playing .cubi-x, body.dy-playing .cubi-x,
body.timing .cubi-mini, body.play-mode .cubi-mini, body.bigplay-mode .cubi-mini, body.duel-playing .cubi-mini, body.dy-playing .cubi-mini { display: none !important; }
@media (max-width: 760px) { body.tr-solving .cubi, body.tr-solving .cubi-bub, body.tr-solving .cubi-mini { display: none !important; } }
/* 🎵 Cubi hát (26/11): mắt cười, miệng mở theo nhịp, chữ hát nhỏ trên đầu + nốt nhạc bay lên – KHÔNG bắt chuột (bấm xuyên qua), nằm dưới Cubi */
.cubi.sing .cb-eyes { opacity: 0; }
.cubi.sing .cb-happy { opacity: 1; }
.cubi.sing .cb-mo-open { animation: cbTalk .6s steps(1) infinite; }
.cubi.sing .cb-mo { animation: cbTalk2 .6s steps(1) infinite; }
.cubi-sing { position: fixed; left: 0; top: 0; z-index: 43; pointer-events: none; white-space: nowrap; padding: 3px 10px; border-radius: 12px;
  background: var(--panel, #fff); color: var(--text, #1d1b2c); border: 1px solid var(--border, #e3e0f0); box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
  font: 700 .78rem/1.3 system-ui, sans-serif; opacity: .88; animation: cbSingIn .3s ease-out; }
.cubi-sing[hidden] { display: none !important; }
@keyframes cbSingIn { from { opacity: 0; transform: translateY(6px); } }
.cubi-note { position: fixed; z-index: 42; pointer-events: none; font: 800 16px/1 system-ui, sans-serif; font-style: normal; text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  animation: cbNote 1.6s ease-out forwards; }
@keyframes cbNote { 0% { transform: translate(0, 0) scale(.6); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(var(--nx, 0px), -44px) rotate(14deg) scale(1.1); opacity: 0; } }
body.timing .cubi-sing, body.play-mode .cubi-sing, body.bigplay-mode .cubi-sing, body.duel-playing .cubi-sing, body.dy-playing .cubi-sing,
body.timing .cubi-note, body.play-mode .cubi-note, body.bigplay-mode .cubi-note, body.duel-playing .cubi-note, body.dy-playing .cubi-note { display: none !important; }
@media (prefers-reduced-motion: reduce) { .cubi *, .cubi .cbi, .cubi-bub { animation: none !important; } .cubi-hl { animation: none; } }
