/* =========================================================
   Lớp giao diện "sảnh game": thanh trên, menu, chuyển mục,
   hộp thoại, màn hình tải, hiệu ứng nút & thẻ.
   ========================================================= */
:root {
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in: cubic-bezier(.5, 0, .75, 0);
  --hud-bg: rgba(13, 10, 36, .82);
  --gold: #f5c86a;
}

/* ===== Nền: tối sâu hơn, có vệt sáng & viền tối quanh màn hình ===== */
body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(109, 40, 217, .22), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(14, 116, 144, .16), transparent 60%),
    linear-gradient(180deg, #0c0a24 0%, #08071a 100%);
}
/* khối màu nền đứng yên: tránh làm mọi lớp mờ (backdrop-filter) phía trên phải vẽ lại mỗi khung hình */
body::before, body::after { opacity: .38; animation: none; will-change: auto; }
html::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .55) 100%);
}

/* ===== Thanh trên (HUD) ===== */
.topbar {
  display: block; padding: 0; background: none; border: 0;
  backdrop-filter: none; -webkit-backdrop-filter: none; /* đặt ở ::before để thanh tab di động vẫn cố định được */
}
.topbar::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(180deg, rgba(16, 12, 44, .94), var(--hud-bg));
  backdrop-filter: blur(18px) saturate(150%); -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(139, 92, 246, .7) 30%, rgba(34, 211, 238, .7) 70%, transparent);
}
.hud-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  max-width: 1240px; margin: 0 auto; padding: 10px clamp(14px, 3vw, 32px) 2px;
}
.brand .logo { position: relative; overflow: hidden; }
.brand .logo::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, .55) 50%, transparent 65%);
  transform: translateX(-120%); animation: logoShine 5s ease-in-out 1.2s infinite;
}
@keyframes logoShine { 0%, 70% { transform: translateX(-120%); } 85%, 100% { transform: translateX(120%); } }

/* ô tiền / cấp */
.stat { position: relative; transition: border-color .3s, box-shadow .3s; }
.stat.money { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; min-width: 92px; justify-content: center; }
.stat.money .coin { display: inline-block; }
.stat.money.bump .coin { animation: coinFlip .6s var(--ease-out); }
.stat.money.bump.up { animation: pillUp .7s var(--ease-out); }
.stat.money.bump.down { animation: pillDown .5s ease; }
@keyframes coinFlip { 50% { transform: rotateY(180deg) scale(1.3); } }
@keyframes pillUp { 30% { border-color: rgba(163, 255, 71, .7); box-shadow: 0 0 22px rgba(163, 255, 71, .45); } }
@keyframes pillDown { 30% { border-color: rgba(255, 83, 112, .7); box-shadow: 0 0 18px rgba(255, 83, 112, .4); } }
.money-delta {
  position: absolute; right: 10px; top: 100%; font: 700 13px var(--display); pointer-events: none; white-space: nowrap;
  animation: deltaFly 1.4s var(--ease-out) forwards;
}
.money-delta.up { color: var(--lime); text-shadow: 0 0 10px rgba(163, 255, 71, .6); }
.money-delta.down { color: var(--red); text-shadow: 0 0 10px rgba(255, 83, 112, .5); }
@keyframes deltaFly { 0% { opacity: 0; transform: translateY(-14px); } 15% { opacity: 1; transform: translateY(2px); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(10px); } }
.stat.level.bump { animation: lvBump .9s var(--ease-out); }
@keyframes lvBump { 25% { transform: scale(1.08); border-color: var(--y); box-shadow: 0 0 26px rgba(255, 210, 63, .5); } }
#xpfill { position: relative; overflow: hidden; }
#xpfill::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .55), transparent); transform: translateX(-100%);
  animation: xpShine 2.8s ease-in-out infinite;
}
@keyframes xpShine { 60%, 100% { transform: translateX(100%); } }

/* ===== Menu chính: chữ in hoa, vạch sáng trượt theo tab ===== */
.tabs {
  position: relative; display: flex; justify-content: center; gap: 2px;
  max-width: 1240px; margin: 0 auto; padding: 0 clamp(8px, 2vw, 24px);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; isolation: isolate; flex-shrink: 0; display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer;
  color: var(--muted); padding: 12px 18px 15px; font: 700 13px var(--display); letter-spacing: 1.2px; text-transform: uppercase;
  white-space: nowrap; transition: color .25s; -webkit-tap-highlight-color: transparent;
}
.tabs button::before {
  content: ''; position: absolute; inset: 6px 3px 9px; border-radius: 10px; z-index: -1;
  background: rgba(255, 255, 255, .06); opacity: 0; transform: scale(.9); transition: opacity .25s, transform .3s var(--ease-out);
}
.tabs button:hover { color: var(--text); }
.tabs button:hover::before { opacity: 1; transform: none; }
.tabs button i { font-style: normal; font-size: 16px; filter: grayscale(.7) brightness(.8); transition: filter .3s, transform .4s var(--ease-out); }
.tabs button:hover i { filter: none; transform: translateY(-2px); }
.tabs button.active { color: #fff; text-shadow: 0 0 18px rgba(139, 92, 246, .9); }
.tabs button.active i { filter: drop-shadow(0 0 8px rgba(139, 92, 246, .8)); transform: scale(1.15); }
.tabs button:focus-visible { outline: 2px solid var(--c); outline-offset: -4px; border-radius: 10px; }
.tab-ink {
  position: absolute; left: 0; bottom: 0; width: 0; height: 3px; pointer-events: none; border-radius: 3px 3px 0 0;
  background: var(--grad); box-shadow: 0 0 14px rgba(34, 211, 238, .9);
  transition: transform .5s var(--ease-out), width .5s var(--ease-out);
}
.tab-ink::after {
  content: ''; position: absolute; left: 50%; bottom: 3px; width: 130%; height: 30px; transform: translateX(-50%);
  background: radial-gradient(50% 100% at 50% 100%, rgba(139, 92, 246, .38), transparent);
}
.dot { top: 8px; right: 8px; }

/* thông báo nằm dưới thanh trên */
#toasts { top: 118px; }

/* ===== Chuyển mục ===== */
main { position: relative; }
.view { display: none; }
.view.active { display: block; }
.view.v-in > * { animation: vChild .6s var(--ease-out) both; animation-delay: calc(min(var(--i, 0), 6) * 55ms); }
.view.v-in.back > * { --dx: -36px; }
@keyframes vChild { from { opacity: 0; transform: translate3d(var(--dx, 36px), 8px, 0); } }
.view.v-out {
  display: block; position: absolute; top: 14px; left: clamp(12px, 3vw, 28px); right: clamp(12px, 3vw, 28px);
  pointer-events: none; animation: vOut .22s var(--ease-in) both; z-index: 0;
}
.view.v-out.back { --dx: 26px; }
@keyframes vOut { to { opacity: 0; transform: translate3d(var(--dx, -26px), 0, 0); } }

/* ===== Khung & nút ===== */
/* khung: bỏ làm mờ nền (rất tốn GPU khi cuộn), thay bằng nền đặc hơn một chút – nhìn gần như cũ */
.panel {
  backdrop-filter: none; -webkit-backdrop-filter: none;
  background: linear-gradient(180deg, rgba(36, 30, 78, .55), rgba(24, 20, 56, .5));
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.hs-label { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(13, 10, 40, .9); }

/* ánh sáng lướt trên thẻ: chạy bằng transform (GPU lo, không phải vẽ lại thẻ) */
.card-shine { background-size: 100% 100%; background-position: 0 0; transform: translateX(-130%); }
.card.clickable:hover .card-shine { animation: shineT 1s ease forwards; }
.tier-SS .card-shine, .tier-SSS .card-shine { animation: shineT 2.8s linear infinite; }
@keyframes shineT { from { transform: translateX(-130%); } to { transform: translateX(130%); } }
/* viền cầu vồng thẻ SSS: chỉ chạy khi rê chuột / trong hộp thoại (vẽ lại tốn kém khi có nhiều thẻ) */
.tier-SSS.card { animation: none; }
.tier-SSS.card:hover, .modal-box .tier-SSS.card { animation: rainbow 3s linear infinite; }

/* khi hộp thoại / màn trận đấu mở: dừng hiệu ứng lặp phía sau để lớp mờ toàn màn hình không phải tính lại */
body.ov-open main *, body.ov-open .topbar * { animation-play-state: paused !important; }
body.match-open main, body.match-open footer { visibility: hidden; }
.btn { position: relative; overflow: hidden; isolation: isolate; transition: transform .2s var(--ease-out), box-shadow .25s, background .25s, border-color .25s; }
.btn:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
.btn.primary::after {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .35) 50%, transparent 70%);
  transform: translateX(-120%); transition: transform .7s var(--ease-out);
}
.btn.primary:hover:not(:disabled)::after { transform: translateX(120%); }
.ripple {
  position: absolute; border-radius: 50%; pointer-events: none; z-index: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, .45) 0%, rgba(255, 255, 255, .15) 40%, transparent 70%);
  transform: scale(0); animation: ripple .65s var(--ease-out) forwards;
}
@keyframes ripple { to { transform: scale(1); opacity: 0; } }
.acct, .stat.donate-top { position: relative; overflow: hidden; }
.stat.donate-top { cursor: pointer; color: var(--text); font: 600 13px var(--font); }
.stat.donate-top:hover { border-color: rgba(255, 79, 216, .6); box-shadow: 0 0 18px rgba(255, 79, 216, .3); }

/* ===== Thẻ: nghiêng 3D & vệt sáng theo chuột ===== */
@media (hover: hover) and (pointer: fine) {
  .card.clickable { transition: transform .45s var(--ease-out), box-shadow .3s; }
  .card.clickable:hover {
    transform: perspective(800px) translateY(-6px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(1.04);
  }
  .card.clickable.tilting { transition: transform .1s linear, box-shadow .3s; will-change: transform; }
  .card.clickable::after {
    content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 3;
    background: radial-gradient(circle at var(--mx, 50%) var(--my, 0%), rgba(255, 255, 255, .24), transparent 48%);
    opacity: 0; transition: opacity .3s;
  }
  .card.clickable:hover::after { opacity: 1; }
}

/* ===== Hộp thoại: mở bật lên, đóng mờ dần ===== */
.overlay { animation: ovIn .28s ease both; }
.overlay.swap { animation: none; }
@keyframes ovIn { from { opacity: 0; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); } }
.modal-box { animation: mbIn .45s var(--ease-out) both; }
@keyframes mbIn { from { opacity: 0; transform: translateY(26px) scale(.94); } }
.overlay.ghost { pointer-events: none; z-index: 49; animation: ovOut .24s ease both; }
.overlay.ghost .modal-box { animation: mbOut .24s var(--ease-in) both; }
@keyframes ovOut { to { opacity: 0; } }
@keyframes mbOut { to { opacity: 0; transform: translateY(14px) scale(.96); } }

/* thông báo */
.toast { animation: toastIn .45s var(--ease-out); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-18px) scale(.9); } }

/* ===== Tên đội & hộp thoại đổi tên ===== */
.tn-box { min-width: 0; }
#team-name.tn-name {
  display: flex; align-items: center; gap: 10px; max-width: 100%; padding: 4px 12px 4px 0; cursor: pointer;
  background: none; border: 0; border-radius: 10px; box-shadow: none; color: var(--text); text-align: left;
}
.tn-name b { font: 700 22px var(--display); letter-spacing: .5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tn-name i { font-style: normal; font-size: 14px; opacity: .5; transition: opacity .2s, transform .3s var(--ease-out); }
.tn-name:hover i { opacity: 1; transform: rotate(-12deg) scale(1.15); }
.tn-name:hover b { color: #c4b5fd; }
.tn-name:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
.tn-hint { display: block; color: var(--muted); font-size: 11px; }
.rn-field { position: relative; margin: 12px 0 6px; }
.rn-field input {
  width: 100%; padding: 13px 64px 13px 14px; border-radius: 12px; outline: none; font: 600 17px var(--font); color: var(--text);
  background: rgba(0, 0, 0, .3); border: 1px solid var(--stroke2); transition: border-color .2s, box-shadow .2s;
}
.rn-field input:focus { border-color: var(--c); box-shadow: 0 0 0 3px rgba(34, 211, 238, .2); }
.rn-field span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); }
.rn-msg { min-height: 22px; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.rn-msg.good { color: var(--lime); }
.rn-msg.bad { color: var(--red); }
.rn-msg.wait { color: var(--muted); }
.name-rules { margin-top: 12px; background: rgba(255, 255, 255, .04); border: 1px solid var(--stroke); border-radius: 12px; padding: 10px 14px; font-size: 13px; }
.name-rules summary { cursor: pointer; font-weight: 700; }
.name-rules ol { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 4px; color: var(--muted); }
@media (max-width: 640px) { .tn-name b { font-size: 18px; } }

/* ===== Màn hình tải ===== */
#splash {
  position: fixed; inset: 0; z-index: 300; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: radial-gradient(900px 600px at 50% 40%, #1d1550, #08071a 70%);
  transition: opacity .6s ease, visibility .6s;
}
#splash.sp-out { opacity: 0; visibility: hidden; }
#splash.sp-out .sp-logo, #splash.sp-out .sp-title { transform: scale(1.12); transition: transform .6s var(--ease-out); }
.sp-glow {
  position: absolute; width: 420px; height: 420px; border-radius: 50%; filter: blur(70px); opacity: .55;
  background: conic-gradient(from 0deg, #8b5cf6, #22d3ee, #ff4fd8, #8b5cf6); animation: spin 6s linear infinite;
}
.sp-logo {
  position: relative; width: 96px; height: 96px; border-radius: 28px; display: grid; place-items: center; font-size: 52px;
  background: var(--grad-hot); box-shadow: 0 16px 50px rgba(139, 92, 246, .6), inset 0 1px 0 rgba(255, 255, 255, .4);
  animation: spLogo .9s var(--ease-out) both;
}
@keyframes spLogo { from { opacity: 0; transform: scale(.5) rotate(-12deg); } }
.sp-title {
  position: relative; margin-top: 18px; font: 700 clamp(26px, 6vw, 40px) var(--display); letter-spacing: 4px;
  background: linear-gradient(90deg, #fff, #c4b5fd 55%, #67e8f9); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: spUp .8s var(--ease-out) .15s both;
}
.sp-sub { position: relative; color: var(--muted); letter-spacing: 6px; text-transform: uppercase; font: 600 12px var(--display); animation: spUp .8s var(--ease-out) .25s both; }
@keyframes spUp { from { opacity: 0; transform: translateY(14px); } }
.sp-bar { position: relative; width: min(260px, 70vw); height: 4px; margin-top: 26px; border-radius: 99px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.sp-bar i { position: absolute; inset: 0; width: 100%; border-radius: inherit; background: var(--grad); box-shadow: 0 0 12px var(--c); transform-origin: left; animation: spLoad 1.4s var(--ease-out) both; }
@keyframes spLoad { from { transform: scaleX(0); } 60% { transform: scaleX(.8); } to { transform: scaleX(1); } }
.sp-tip { position: relative; margin-top: 10px; color: var(--muted); font-size: 12px; animation: spUp .8s var(--ease-out) .35s both; }

/* nhãn tab: bản ngắn cho điện thoại */
.lbl-short { display: none; }
@media (max-width: 640px) { .tabs .lbl-long { display: none; } .tabs .lbl-short { display: inline; } }

/* ===== Không cho chữ trên thanh trên xuống dòng ===== */
.brand b, .stat, .stat.donate-top, .acct { white-space: nowrap; }
.brand > div { min-width: 0; }
.brand small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { flex-shrink: 0; }

/* ===== Laptop nhỏ / máy tính bảng ===== */
@media (max-width: 1180px) {
  .brand small, #xptext { display: none; }
  .tabs button { padding: 12px 13px 15px; letter-spacing: .6px; }
}
@media (max-width: 1000px) {
  /* thanh trên gọn lại */
  .brand b { font-size: 17px; letter-spacing: 1px; }
  .brand .logo { width: 38px; height: 38px; font-size: 20px; border-radius: 12px; }
  .xpbar { width: 64px; }
  .stat { padding: 6px 11px; }
  .stat.donate-top span, .acct .acct-name, .acct .acct-sync { display: none; }
  .acct { padding: 3px; }
  /* menu: biểu tượng trên, chữ dưới, chia đều chiều ngang */
  .tabs { justify-content: space-between; padding: 0 8px; overflow: hidden; }
  .tabs button {
    flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 8px 2px 11px;
    font: 600 11px var(--font); letter-spacing: 0; text-transform: none;
  }
  .tabs button span:not(.dot):not(.dot-num) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .tabs button i { font-size: 18px; }
  .tabs button::before { inset: 3px 2px 6px; }
  #toasts { top: 112px; }
  /* bản đồ: nhãn khu vực nằm dưới chấm, bỏ dòng phụ để không đè nhau */
  .hs { gap: 3px; flex-direction: column; }
  .hs-dot { width: 34px; height: 34px; font-size: 15px; }
  .hs-label { padding: 2px 7px; border-radius: 8px; text-align: center; }
  .hs-label b { font-size: 11px; }
  .hs-label small { display: none; }
  .hs.intl .hs-dot { width: 44px; height: 44px; font-size: 20px; }
}

/* ===== Di động: menu dưới đáy như ứng dụng game ===== */
@media (max-width: 640px) {
  .hud-row { padding: 8px 12px; }
  body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-width: none; margin: 0; gap: 0; overflow: visible;
    justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: rgba(13, 10, 36, .94); border-top: 1px solid var(--stroke);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
  }
  .tabs button {
    flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 7px 2px;
    font: 600 9.5px var(--font); letter-spacing: 0; text-transform: none;
  }
  .tabs button span:not(.dot):not(.dot-num) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .tabs button i { font-size: 20px; }
  .tabs button::before { inset: 2px; border-radius: 14px; }
  .tabs button.active::before { opacity: 1; transform: none; background: linear-gradient(180deg, rgba(139, 92, 246, .3), rgba(34, 211, 238, .08)); }
  .tabs button.active i { transform: translateY(-1px) scale(1.12); }
  .tab-ink { top: 0; bottom: auto; border-radius: 0 0 3px 3px; }
  .tab-ink::after { bottom: auto; top: 3px; background: radial-gradient(50% 100% at 50% 0%, rgba(139, 92, 246, .38), transparent); }
  .dot { top: 4px; right: calc(50% - 18px); }
  .hs-dot { width: 28px; height: 28px; font-size: 13px; }
  .hs-label { padding: 1px 6px; }
  .hs-label b { font-size: 9px; }
  .hs.intl .hs-dot { width: 38px; height: 38px; font-size: 18px; }
  #toasts { top: 66px; }
  .view.v-out { top: 16px; }
}

@media (max-width: 420px) {
  .hs-dot { width: 24px; height: 24px; font-size: 11px; border-width: 1.5px; }
  .hs-step { width: 13px; height: 13px; font-size: 7px; top: -4px; right: -4px; }
  .hs-label { padding: 0 4px; }
  .hs-label b { font-size: 8px; letter-spacing: 0; }
  .hs.intl .hs-dot { width: 32px; height: 32px; font-size: 15px; }
}

/* ===== Nút âm thanh ===== */
.sfx-btn { cursor: pointer; font-size: 16px; padding: 6px 10px; color: var(--text); font-family: var(--font); }
.sfx-btn.off { opacity: .55; }

/* ===== Cài đặt âm thanh ===== */
.au-row { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--stroke); }
.au-txt { flex: 1; min-width: 0; }
.au-txt b { display: block; font-size: 15px; }
.au-txt small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.au-txt input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--v); }
.au-sw { position: relative; flex-shrink: 0; width: 46px; height: 26px; margin-top: 2px; cursor: pointer; }
.au-sw input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.au-sw i { position: absolute; inset: 0; border-radius: 99px; background: rgba(255,255,255,.14); transition: background .2s; pointer-events: none; }
.au-sw i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.au-sw input:checked + i { background: var(--grad); }
.au-sw input:checked + i::after { transform: translateX(20px); }
#au-test { margin: 12px 0 4px; }
.au-help { margin-top: 10px; line-height: 1.5; }

/* ===== Mở gói: từng thẻ một ===== */
.po { text-align: center; }
.po-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.po-head b { font: 700 18px var(--display); }
.po-step { font-size: 13px; color: var(--muted); font-weight: 600; }
.po-stage {
  --tc: #ffffff; position: relative; height: 340px; display: grid; place-items: center; overflow: hidden; border-radius: 20px; cursor: pointer;
  background: radial-gradient(circle at 50% 50%, #1d1650, #07051a 72%); border: 1px solid var(--stroke); user-select: none; -webkit-user-select: none;
}
.po-rays {
  position: absolute; inset: -50%; opacity: 0; transition: opacity .45s;
  background: repeating-conic-gradient(color-mix(in srgb, var(--tc) 26%, transparent) 0 7deg, transparent 7deg 18deg);
  animation: spin 10s linear infinite;
}
.po-glow {
  position: absolute; width: 300px; height: 300px; border-radius: 50%; opacity: 0; transform: scale(.3);
  background: radial-gradient(circle, color-mix(in srgb, var(--tc) 80%, transparent) 0%, color-mix(in srgb, var(--tc) 30%, transparent) 40%, transparent 68%);
  transition: opacity .35s, transform .6s cubic-bezier(.2, 1.3, .4, 1);
}
.po-stage.lit .po-rays { opacity: 1; }
.po-stage.lit .po-glow { opacity: 1; transform: scale(1.2); }
.po-stage.lit .flip-back { border-color: var(--tc); box-shadow: 0 0 26px var(--tc), 0 0 70px color-mix(in srgb, var(--tc) 60%, transparent); }
.po-stage.lit .flip-back b { color: var(--tc); }
.po-stage.sss .po-rays, .po-stage.sss .po-glow, .po-stage.sss .flip-back { animation: spin 10s linear infinite, hue 1.6s linear infinite; }
.po-stage.sss .po-glow, .po-stage.sss .flip-back { animation: hue 1.6s linear infinite; }
.po-stage.big { animation: poShake .55s; }
@keyframes poShake { 15%, 55% { transform: translate(-5px, 2px); } 35%, 75% { transform: translate(5px, -2px); } }
.po-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 4; }
.po-stage.flash .po-flash { animation: poFlash .55s ease-out; }
@keyframes poFlash { 0% { opacity: .8; } 100% { opacity: 0; } }

.po-card { position: relative; z-index: 2; width: 170px; aspect-ratio: 3 / 4.3; }
.po-card .flip { width: 100%; cursor: inherit; }
.po-card .flip:not(.flipped):hover .flip-inner { transform: none; }
.po-card .flip-inner { transition: transform .75s cubic-bezier(.3, 1.4, .5, 1); }
.po-card.enter { animation: poEnter .75s cubic-bezier(.2, 1.25, .4, 1) both; }
@keyframes poEnter { from { transform: translateY(90px) scale(.5) rotate(-8deg); opacity: 0; } }
.po-card.pulse .flip-back { animation: poPulse .24s ease-out; }
@keyframes poPulse { 0% { filter: brightness(2.6); transform: scale(1.07); box-shadow: 0 0 46px #fff; } 100% { filter: none; transform: none; } }
.po-stage.lit .po-card:not(:has(.flipped)) { animation: poHover 1.2s ease-in-out infinite; }
@keyframes poHover { 50% { transform: translateY(-6px) scale(1.02); } }
.po-pack {
  position: absolute; inset: 0; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 2px solid var(--pc); box-shadow: 0 0 34px color-mix(in srgb, var(--pc) 55%, transparent);
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--pc) 45%, transparent), transparent 70%), repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 8px, transparent 8px 16px), #15112f;
}
.po-pack span { font-size: 66px; filter: drop-shadow(0 6px 18px color-mix(in srgb, var(--pc) 70%, transparent)); }
.po-pack b { font: 700 15px var(--display); color: color-mix(in srgb, var(--pc) 75%, white); letter-spacing: 1px; }
.po-card.shake { animation: poRattle 1.35s ease-in both; }
.po-card.idle { animation: poIdle 2.2s ease-in-out infinite; }
@keyframes poIdle { 50% { transform: translateY(-8px) rotate(-1.5deg); } }
@keyframes poRattle {
  0% { transform: scale(.9); } 20% { transform: scale(1) rotate(-2deg); } 30% { transform: rotate(3deg); } 40% { transform: rotate(-4deg); }
  50% { transform: rotate(5deg) scale(1.03); } 60% { transform: rotate(-6deg) scale(1.05); } 70% { transform: rotate(6deg) scale(1.07); }
  80% { transform: rotate(-5deg) scale(1.1); filter: brightness(1.4); } 100% { transform: scale(1.18); filter: brightness(2.2); }
}
.po-burst { position: absolute; left: 50%; top: 50%; z-index: 3; pointer-events: none; }
.po-burst i {
  position: absolute; width: 7px; height: 7px; margin: -3.5px; border-radius: 50%; background: var(--tc); box-shadow: 0 0 10px var(--tc), 0 0 2px #fff;
  animation: poBurst .95s var(--d) cubic-bezier(.1, .7, .3, 1) both;
}
@keyframes poBurst { 0% { opacity: 1; transform: rotate(var(--a)) translateY(-40px) scale(1.2); } 100% { opacity: 0; transform: rotate(var(--a)) translateY(calc(-1 * var(--r))) scale(.3); } }
.po-stage.sss .po-burst i { animation: poBurst .95s var(--d) cubic-bezier(.1, .7, .3, 1) both, hue .8s linear infinite; }
.po-tap { position: absolute; bottom: 10px; left: 0; right: 0; z-index: 3; font-size: 12px; color: rgba(255,255,255,.55); pointer-events: none; animation: ping 1.6s infinite; }

.po-tray { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 6px; min-height: 52px; }
.po-slot { width: 46px; height: 46px; border-radius: 50%; border: 2px dashed var(--stroke2); display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.po-mini { position: relative; width: 46px; height: 46px; animation: pop .35s cubic-bezier(.2, 1.3, .4, 1); }
.po-av { position: absolute; inset: 0; border-radius: 50%; overflow: hidden; background: #15112f; box-shadow: 0 0 0 2px var(--tcol), 0 0 14px var(--tcol); }
.po-av > * { width: 100%; height: 100%; display: block; object-fit: cover; }
.po-mini b { position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); font: 700 9px/1.4 var(--display); padding: 0 5px; border-radius: 6px; background: var(--tcol); color: #0b0920; white-space: nowrap; }

.po-sum { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 6px 0 4px; }
.po-sc { width: 140px; animation: poEnter .45s cubic-bezier(.2, 1.25, .4, 1) both; animation-delay: calc(var(--i) * 80ms); }
@media (max-width: 640px) {
  .po-stage { height: 300px; }
  .po-card { width: 150px; }
  .po-sum { gap: 8px; }
  .po-sc { width: calc(33.33% - 6px); }
}
@media (prefers-reduced-motion: reduce) { .po-stage.big, .po-card.shake { animation: none; } }

/* ===== Nâng cấp: nhịp chậm ≈5 giây (khớp với âm thanh trong upgrade.js) ===== */
.ua-main { animation-duration: 5.2s; }
.ua-mat { animation-duration: 2.6s; }

/* ===== Nâng cấp: chớp sáng mỗi nhát đập ===== */
.ua-hit { position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0; background: radial-gradient(circle at 50% 42%, rgba(255,255,255,.9), rgba(255, 210, 63, .35) 30%, transparent 62%); }
.upg-anim.hit .ua-hit { animation: uaHit .32s ease-out; }
.upg-anim.hit .ua-cards { animation: uaKnock .32s ease-out; }
@keyframes uaHit { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes uaKnock { 0% { transform: scale(.94) translateY(3px); } 60% { transform: scale(1.03); } 100% { transform: none; } }

/* ===== Nâng cấp: thanh chọn các cấp + của cùng một thẻ ===== */
.ug-levels { margin: 14px 0 0; padding: 12px 14px; border-radius: 16px; background: rgba(255,255,255,.04); border: 1px solid var(--stroke); }
.ug-levels > span i { font-style: normal; opacity: .8; }
.ug-levels > div { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ugl {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; padding: 6px 10px; cursor: pointer;
  border-radius: 12px; background: rgba(0,0,0,.25); border: 1px solid var(--stroke2); color: var(--text); font-family: var(--font);
}
.ugl b { font: 700 15px var(--display); color: var(--text); }
.ugl b[class*="lv-"] { color: var(--lc); }
.ugl small { font-size: 11px; color: var(--muted); }
.ugl.ok { border-color: rgba(163, 255, 71, .55); }
.ugl.ok small { color: var(--lime); }
.cd-levels { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.cd-levels .ugl { min-width: 54px; padding: 4px 8px; }
.ugl.cur { background: linear-gradient(180deg, rgba(139, 92, 246, .35), rgba(34, 211, 238, .12)); border-color: var(--c); }

/* ===== Điện thoại: gọn, nhiều thẻ trên một màn hình, dễ chạm ===== */
button, .btn, .card, .slot, select, label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.scoreboard { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.sb-team { min-width: 0; }
.match-box { overflow-x: hidden; }

@media (max-width: 640px) {
  /* iOS phóng to trang khi ô nhập dưới 16px */
  select, input[type=text], input[type=email], input[type=password], textarea { font-size: 16px; }

  /* đầu trang đội hình: tên + vòng sức mạnh nằm cùng hàng */
  .team-hero .panel-head { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
  .team-hero .team-name { gap: 10px; min-width: 0; flex: 1; }
  .team-hero .tn-box { min-width: 0; }
  .team-hero .my-logo { width: 34px; height: 40px; }
  .team-name label { font-size: 10px; margin-bottom: 2px; }
  #team-name.tn-name { width: auto; max-width: 100%; gap: 4px; padding: 2px 4px; margin-left: -4px; }
  #team-name.tn-name b { font-size: 15px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #team-name.tn-name i { font-size: 12px; }
  .tn-hint { font-size: 10px; line-height: 1.25; }
  .power-ring { width: 92px; height: 92px; }
  .power-ring > div { width: 78px; height: 78px; padding: 0 6px; }
  .power-ring small { font-size: 8px; letter-spacing: .5px; }
  .power-ring b { font-size: 26px; }
  .power-ring span { font-size: 8px; line-height: 1.2; max-width: 70px; }

  /* đội hình: 3 thẻ trên, 2 thẻ dưới ở giữa */
  .lineup { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 8px; }
  .lineup .slot { grid-column: span 2; min-width: 0; }
  .lineup .slot:nth-child(4) { grid-column: 2 / 4; }
  .lineup .slot:nth-child(5) { grid-column: 4 / 6; }
  .slot-label { font-size: 9.5px; letter-spacing: .2px; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* lưới thẻ: 3 cột */
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .center-grid { grid-template-columns: repeat(3, minmax(0, 112px)); }

  /* bộ lọc bộ sưu tập */
  .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 8px; }
  .filters select { width: 100%; min-width: 0; padding-left: 10px; padding-right: 6px; }
  .filters .check { font-size: 13px; line-height: 1.2; }
  .filters .btn { grid-column: 1 / -1; white-space: nowrap; }
  .tier-legend { flex-wrap: nowrap; overflow-x: auto; margin: 8px -16px; padding: 0 16px 4px; scrollbar-width: none; scroll-snap-type: x proximity; }
  .tier-legend::-webkit-scrollbar { display: none; }
  .tl { flex-shrink: 0; white-space: nowrap; scroll-snap-align: start; }

  /* cửa hàng: 2 gói một hàng */
  .packs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .pack { padding: 14px 10px; gap: 4px; }
  .pack-icon { font-size: 36px; }
  .pack h4 { font-size: 15px; }
  .pack .muted { font-size: 12px; }
  .odds { margin: 6px 0 10px; }
  .odd { grid-template-columns: 24px minmax(0, 1fr) 34px; gap: 5px; font-size: 11px; margin: 4px 0; }
  .pack .btn { padding-left: 6px; padding-right: 6px; font-size: 13px; white-space: nowrap; }

  /* nâng cấp: thẻ không quá to */
  .upg-stage .card { max-width: 150px; margin: 0 auto; }

  /* hộp thoại: kiểu bảng trượt từ đáy */
  .overlay#modal { align-items: flex-end; padding: 0; }
  #modal .modal-box { width: 100%; max-height: 90dvh; border-radius: 22px 22px 0 0; padding: 20px 16px calc(18px + env(safe-area-inset-bottom)); }

  /* trận đấu: toàn màn hình */
  #match.overlay { padding: 0; }
  .match-box { max-height: 100dvh; height: 100dvh; border-radius: 0; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); gap: 8px; border: 0; }
  .m-head b#m-title { font-size: 15px; }
  .m-series { padding: 3px 10px; font-size: 12px; }
  .scoreboard { gap: 6px; padding: 8px; }
  .sb-name { font-size: 12.5px; gap: 5px; line-height: 1.15; overflow-wrap: anywhere; }
  .sb-name > :not(.sb-logo) { min-width: 0; overflow-wrap: anywhere; }
  .sb-logo { width: 20px; height: 24px; }
  .sb-sub { font-size: 10.5px; }
  .sb-kills { font-size: 24px; gap: 8px; }
  .sb-clock { font-size: 12px; padding: 2px 7px; }
  .gd { font-size: 11px; }
  .m-body { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .map-wrap { max-width: min(100%, 52dvh); }
  .kda { padding: 4px 6px; border-radius: 14px; }
  .kda-row { grid-template-columns: 24px minmax(0, 1fr) auto; gap: 5px; padding: 4px 0; font-size: 12px; }
  .kda-row .kav, .kda-row .ro-av { width: 24px; height: 24px; }
  .kdv { font-size: 12px; }
  .kda-row.dead::after { right: 40px; font-size: 10px; }
  .kf { font-size: 10.5px; padding: 2px 7px; }
  .m-ctrl .btn { padding: 7px 10px; }
  .commentary { height: 140px; font-size: 13px; }
}
@media (max-width: 860px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 400px) {
  .pc-id { padding: 10px; gap: 8px; }
  .pc-id code { font-size: 20px; letter-spacing: 2px; }
  .net { flex-wrap: wrap; }
  .tabs button { font-size: 8.5px; }
}
@media (max-width: 340px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .packs { grid-template-columns: 1fr; }
}

/* ===== Người dùng chọn giảm chuyển động ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
