/* bar-online — 3D dark neon club */
:root {
  --bg: #07060d;
  --bg-2: #0d0b18;
  --panel: rgba(20, 17, 34, 0.86);
  --panel-2: rgba(28, 24, 46, 0.7);
  --line: rgba(255, 255, 255, 0.09);
  --txt: #e9e6f5;
  --muted: #918da8;
  --pink: #ff2e88;
  --cyan: #35e6ff;
  --violet: #9b5cff;
  --gold: #ffd166;
  --ok: #52e39b;
  --radius: 14px;

  /* 3D depth variables */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5), 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6), 0 8px 16px rgba(0, 0, 0, 0.5);
  --glow-cyan: 0 0 20px rgba(53, 230, 255, 0.4), 0 0 40px rgba(53, 230, 255, 0.2);
  --glow-pink: 0 0 20px rgba(255, 46, 136, 0.4), 0 0 40px rgba(255, 46, 136, 0.2);
  --glow-violet: 0 0 20px rgba(155, 92, 255, 0.4), 0 0 40px rgba(155, 92, 255, 0.2);

  /* JS ghi de theo visualViewport: chieu cao that + chieu cao ban phim ao. */
  --app-h: 100%;
  --kb: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --dock-h: 0px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(155, 92, 255, 0.28), transparent 65%),
    radial-gradient(1000px 600px at 95% 0%, rgba(53, 230, 255, 0.22), transparent 60%),
    radial-gradient(800px 500px at 50% 100%, rgba(255, 46, 136, 0.12), transparent 70%),
    linear-gradient(180deg, #07060d 0%, #0a0813 50%, #0d0b18 100%);
  color: var(--txt);
  font: 14px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
}

.hidden { display: none !important; }

/* ------------------------------- screens ------------------------------- */
.screen { display: none; height: 100%; height: var(--app-h); }
.screen.is-active { display: block; }

/* -------------------------------- lobby -------------------------------- */
.lobby-wrap {
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 48px 24px;
  padding-left: max(24px, var(--safe-l));
  padding-right: max(24px, var(--safe-r));
  padding-bottom: calc(48px + var(--safe-b));
  max-width: 1080px;
  margin: 0 auto;
}

.lobby-head { text-align: center; margin-bottom: 34px; }

.logo {
  font-size: 46px;
  letter-spacing: 6px;
  margin: 0;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 24px rgba(255, 46, 136, 0.7);
}
.logo span { color: var(--cyan); text-shadow: 0 0 24px rgba(53, 230, 255, 0.7); }
.tagline { color: var(--muted); margin: 8px 0 0; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 20px;
}
.lobby-grid > .panel { min-width: 0; }
@media (max-width: 860px) { .lobby-grid { grid-template-columns: 1fr; } }

.panel {
  background: linear-gradient(135deg, rgba(20, 17, 34, 0.92), rgba(28, 24, 46, 0.88));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.2);
  transform-style: preserve-3d;
  position: relative;
}
.panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(155, 92, 255, 0.08) 0%,
    transparent 40%,
    rgba(53, 230, 255, 0.06) 100%);
  pointer-events: none;
}
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 1.4px; margin: 0 0 12px; color: var(--muted); }
.panel h2.mt { margin-top: 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

input[type="text"], input[type="number"], input[type="password"] {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  outline: none;
}
input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(155, 92, 255, 0.18); }

.btn {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--txt);
  border-radius: 9px;
  padding: 9px 14px;
  font: inherit;
  cursor: pointer;
  transition: all .15s ease;
  box-shadow: var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  position: relative;
  transform-style: preserve-3d;
}
.btn:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.08));
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: var(--shadow-sm),
    inset 0 1px 2px rgba(0, 0, 0, 0.3);
}
.btn-primary {
  background: linear-gradient(135deg, #ff2e88 0%, #9b5cff 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-md), var(--glow-pink);
}
.btn-primary:hover {
  box-shadow: var(--shadow-lg), var(--glow-pink);
  filter: brightness(1.15);
}
.btn-block { width: 100%; margin-top: 6px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }
.btn-tip { background: linear-gradient(135deg, #ff9f43, var(--gold)); color: #241a00; border-color: transparent; font-weight: 700; }

.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.error { color: #ff7a90; text-align: center; min-height: 20px; margin-top: 16px; }

.bar-list { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow: auto; }
.bar-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 11px;
  margin-bottom: 9px;
  background: linear-gradient(135deg, rgba(28, 24, 46, 0.85), rgba(20, 17, 34, 0.8));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  transition: all .2s ease;
  transform-style: preserve-3d;
  position: relative;
}
.bar-item::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg,
    rgba(155, 92, 255, 0.05),
    transparent 50%,
    rgba(53, 230, 255, 0.05));
  opacity: 0;
  transition: opacity .2s ease;
}
.bar-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-color: rgba(155, 92, 255, 0.4);
}
.bar-item:hover::before {
  opacity: 1;
}
.bar-item .bi-main { flex: 1; min-width: 0; }
.bar-item .bi-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.bar-item .bi-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-item .bi-hype {
  width: 54px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden;
}
.bar-item .bi-hype i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); }

.tag {
  font-size: 11px; color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  padding: 2px 7px; border-radius: 20px; white-space: nowrap;
}

/* --------------------------------- room -------------------------------- */
/* Trong phong choi, moi thu tru o nhap lieu deu la nut/HUD chu khong phai van
 * ban de doc: chan double-tap-to-zoom (touch-action) va boi den chu khi cham
 * nhanh (user-select) — neu khong iPad se nuot cu cham hoac lam ket dieu khien.
 * touch-action:manipulation van cho cuon, chi bo do tre ~300ms cho cu cham thu hai.
 * Boc trong :where() de do uu tien = 0: cac luat 'touch-action: none' cua san bar
 * va lop cam ung ben duoi van thang, khong bi selector nay de len. */
:where(#screen-room, #screen-room *) {
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
:where(#screen-room input, #screen-room textarea) {
  user-select: text; -webkit-user-select: text;
  -webkit-touch-callout: default;
}

.room-grid {
  height: 100%;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 12px;
  padding: 12px;
  padding-left: max(12px, var(--safe-l));
  padding-right: max(12px, var(--safe-r));
  /* --dock-h da bao gom safe-area cua no roi, nen lay max chu khong cong don */
  padding-bottom: calc(12px + max(var(--dock-h), var(--safe-b)));
}

.side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.side-left {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.drawer-head { display: none; }
.card {
  background: linear-gradient(135deg, rgba(20, 17, 34, 0.92), rgba(28, 24, 46, 0.88));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.2);
  transform-style: preserve-3d;
  position: relative;
}
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(155, 92, 255, 0.06) 0%,
    transparent 40%,
    rgba(53, 230, 255, 0.04) 100%);
  pointer-events: none;
}
.card.grow { flex: 1; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); }

.np-title { font-weight: 600; font-size: 15px; line-height: 1.35; }
.np-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.np-bar { height: 4px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; margin: 10px 0 6px; overflow: hidden; }
#np-progress { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--pink)); }
.np-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }

.host-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.inline-field { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.inline-field input { width: 64px; padding: 4px 6px; }

/* --------------------------------- deck --------------------------------- */
.deck-slots {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.deck-slot {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px; border-radius: 9px;
  background: linear-gradient(135deg, rgba(28, 24, 46, 0.8), rgba(20, 17, 34, 0.75));
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: left; font: inherit; color: var(--txt); cursor: pointer;
  min-height: 52px;
  box-shadow: var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(6px);
  transition: all .2s ease;
  transform-style: preserve-3d;
  position: relative;
}
.deck-slot:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-color: rgba(155, 92, 255, 0.3);
}
.deck-slot.is-empty {
  color: var(--muted);
  border-style: dashed;
  background: linear-gradient(135deg, rgba(28, 24, 46, 0.4), rgba(20, 17, 34, 0.35));
}
.deck-slot.is-me {
  border-color: rgba(53, 230, 255, .55);
  box-shadow: var(--shadow-md), var(--glow-cyan);
}
.deck-slot.is-active {
  background: linear-gradient(135deg, rgba(255, 46, 136, .22), rgba(155, 92, 255, .22));
  border-color: rgba(255, 46, 136, .6);
  box-shadow: var(--shadow-lg), var(--glow-pink);
  animation: deck-pulse 2s ease-in-out infinite;
}
@keyframes deck-pulse {
  0%, 100% { box-shadow: var(--shadow-lg), var(--glow-pink); }
  50% { box-shadow: var(--shadow-xl), 0 0 30px rgba(255, 46, 136, 0.6), 0 0 60px rgba(255, 46, 136, 0.3); }
}
.deck-slot:disabled { cursor: default; opacity: .75; }

.deck-slot .ds-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-slot .ds-sub { font-size: 11px; color: var(--muted); }

/* ------------------------------ vote 🔥 / 💤 ------------------------------ */
.react-row { display: flex; gap: 8px; margin-top: 12px; }
.react-row.hidden { display: none; }
.react-btn {
  flex: 1; padding: 8px; border-radius: 9px; cursor: pointer;
  font: inherit; font-size: 15px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--txt);
}
.react-btn.fire.on {
  background: rgba(255, 46, 136, .22); border-color: rgba(255, 46, 136, .6); font-weight: 700;
}
.react-btn.sleep.on {
  background: rgba(138, 167, 255, .22); border-color: rgba(138, 167, 255, .6); font-weight: 700;
}

/* -------------------------------- crate -------------------------------- */
.crate-list { list-style: none; margin: 0 0 10px; padding: 0; overflow: auto; flex: 1; min-height: 60px; }
.crate-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 9px; background: var(--panel-2);
  border: 1px solid var(--line); margin-bottom: 6px;
}
.crate-item.drag-over { border-color: rgba(53, 230, 255, .6); }
.crate-item .ci-main { flex: 1; min-width: 0; }
.crate-item .ci-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crate-item .ci-sub { font-size: 11px; color: var(--muted); }
.ci-btn {
  background: rgba(53, 230, 255, 0.12); border: 1px solid rgba(53, 230, 255, 0.3);
  color: var(--cyan); border-radius: 8px; padding: 4px 8px; cursor: pointer;
  font: inherit; font-size: 12px; min-width: 30px;
}
.ci-btn:disabled { opacity: .35; cursor: default; }
.ci-del {
  background: rgba(255, 46, 136, 0.12); border: 1px solid rgba(255, 46, 136, 0.35);
  color: var(--pink); border-radius: 8px; padding: 4px 7px; cursor: pointer;
  font: inherit; font-size: 12px;
}

.request-box { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.request-box .row { display: flex; gap: 6px; }
.request-box .row input[type="number"] { width: 76px; flex: none; }

/* stage */
.stage-wrap { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 10px; }
.stage-top {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, rgba(20, 17, 34, 0.95), rgba(28, 24, 46, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  padding: 10px 14px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  transform-style: preserve-3d;
  position: relative;
}
.stage-top::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg,
    rgba(155, 92, 255, 0.08) 0%,
    transparent 30%,
    transparent 70%,
    rgba(53, 230, 255, 0.06) 100%);
  pointer-events: none;
}
.bar-id { display: flex; align-items: center; gap: 8px; }
.hype { flex: 1; display: flex; align-items: center; gap: 10px; }
.hype-track { flex: 1; height: 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.09); overflow: hidden; box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4); }
#hype-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--violet), var(--pink));
  box-shadow: 0 0 20px rgba(255, 46, 136, 0.8), 0 0 40px rgba(255, 46, 136, 0.4);
  transition: width .25s linear;
  position: relative;
}
#hype-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.3) 0%,
    transparent 20%,
    transparent 80%,
    rgba(255, 255, 255, 0.2) 100%);
}
#hype-label { font-size: 12px; color: var(--muted); width: 84px; text-align: right; }
.wallet { display: flex; align-items: center; gap: 10px; }
.profile-progress {
  display: grid; grid-template-columns: auto 72px;
  gap: 2px 6px; align-items: center; min-width: 142px;
}
.level-badge { color: var(--cyan); font-weight: 800; font-size: 12px; }
.xp-track {
  height: 6px; overflow: hidden; border-radius: 999px;
  background: rgba(255,255,255,.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}
#xp-fill {
  width: 0; min-width: 1px; height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  transition: width .25s linear;
  box-shadow: 0 0 12px rgba(53, 230, 255, 0.6);
  position: relative;
}
#xp-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.4),
    transparent 50%);
}
.xp-label {
  grid-column: 1 / -1; color: var(--muted);
  font-size: 9px; text-align: right;
}
.level-badge.level-up { animation: level-pop .7s ease-out; }
@keyframes level-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.35); color: var(--gold); }
  100% { transform: scale(1); }
}
.coin { color: var(--gold); font-weight: 700; }
#screen-room[data-theme="velvet-gold"] { --pink: #d94b62; --cyan: #ffd166; --violet: #a44255; }
#screen-room[data-theme="cyber-ice"] { --pink: #8aa7ff; --cyan: #56ebff; --violet: #5686ff; }
#screen-room[data-theme="night-rhythm"] { --pink: #ff9520; --cyan: #ffe066; --violet: #c06010; }
.theme-field select { width: 150px; padding: 5px 7px; }

.recap-card {
  position: fixed; bottom: 80px; right: 20px; z-index: 9999;
  background: rgba(14,10,32,0.96); border: 1px solid rgba(255,149,32,0.5);
  border-radius: 12px; padding: 14px 18px; min-width: 200px;
  color: #fff; font-size: 13px; box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  animation: recap-in 0.3s ease, recap-out 0.4s ease 5.6s forwards;
  pointer-events: none;
}
.recap-card h4 {
  margin: 0 0 8px; font-size: 11px; letter-spacing: 1.2px;
  text-transform: uppercase; color: rgba(255,200,80,0.8);
}
.recap-card .recap-title {
  font-size: 12px; color: rgba(255,255,255,0.5); margin-bottom: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px;
}
.recap-card .recap-row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 6px; }
.recap-card .recap-stat { text-align: center; }
.recap-card .recap-stat span { display: block; }
.recap-card .recap-stat .rval { font-size: 18px; font-weight: 700; }
.recap-card .recap-stat .rlbl { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: rgba(255,255,255,0.4); }
.recap-card .rval.perfect { color: #ffe066; }
.recap-card .rval.good { color: #56ebff; }
.recap-card .rval.miss { color: #ff4466; }
.recap-card .recap-footer { margin-top: 8px; font-size: 11px; color: rgba(255,200,80,0.7); border-top: 1px solid rgba(255,255,255,0.08); padding-top: 8px; }
@keyframes recap-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes recap-out { from { opacity: 1; } to { opacity: 0; pointer-events: none; } }
.muted-tag { color: var(--muted); font-size: 11px; }
.pr-level { color: var(--cyan); font-size: 10px; font-weight: 700; }
.mod-btn {
  border-radius: 7px; padding: 3px 6px; font: inherit; font-size: 10px; cursor: pointer;
  background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--txt);
}
.mute-btn { color: var(--cyan); }
.kick-btn { color: var(--pink); border-color: rgba(255,46,136,.35); }
@media (max-width: 900px) {
  .player-row { flex-wrap: wrap; }
  .mod-btn { min-height: 34px; padding: 7px 10px; }
}

.stage-holder {
  position: relative; flex: 1; min-height: 0;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(180deg, #0a0813 0%, #05040a 100%);
  touch-action: none;
  box-shadow: var(--shadow-xl),
    inset 0 0 80px rgba(0, 0, 0, 0.6),
    inset 0 2px 4px rgba(0, 0, 0, 0.8);
  transform-style: preserve-3d;
  position: relative;
}
.stage-holder::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 40%, rgba(155, 92, 255, 0.12), transparent 50%),
    radial-gradient(circle at 70% 60%, rgba(53, 230, 255, 0.08), transparent 50%);
  pointer-events: none;
  z-index: 1;
}
.stage-holder::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(155, 92, 255, 0.06) 0%,
    transparent 20%,
    transparent 80%,
    rgba(53, 230, 255, 0.04) 100%);
  pointer-events: none;
  z-index: 1;
}
#stage { display: block; width: 100%; height: 100%; }
#stage-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
#drop-flash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 20%, rgba(255, 255, 255, .55), transparent 55%);
}
#drop-flash.on { animation: flash .7s ease-out; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
.rhythm-lane {
  position: absolute; right: 16px; top: 16px; /* Chuyển từ bottom sang top */
  width: 92px; height: 240px;
  z-index: 5; overflow: hidden; pointer-events: none;
  border: 1px solid rgba(53,230,255,.4);
  border-radius: 18px;
  background: linear-gradient(180deg,
    rgba(5,4,10,.25),
    rgba(5,4,10,.85));
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-lg),
    inset 0 0 30px rgba(53, 230, 255, 0.15),
    0 0 40px rgba(53, 230, 255, 0.2);
  transition: width .2s, height .2s, opacity .2s;
  transform-style: preserve-3d;
}
.rhythm-lane.compact {
  width: 80px; height: 34px; opacity: .72;
  box-shadow: var(--shadow-md),
    inset 0 0 20px rgba(53, 230, 255, 0.1);
}
.rhythm-notes { position: absolute; inset: 0 16px 28px; }
.rhythm-note {
  position: absolute; left: 50%; top: 0; width: 30px; height: 12px;
  transform: translate(-50%, -50%); border-radius: 999px;
  background: var(--cyan);
  box-shadow: 0 0 18px rgba(53,230,255,.9),
    0 0 30px rgba(53,230,255,.5),
    inset 0 1px 2px rgba(255, 255, 255, 0.3);
}
.rhythm-line {
  position: absolute; left: 12px; right: 12px; bottom: 28px;
  height: 3px;
  background: var(--pink);
  box-shadow: 0 0 16px rgba(255,46,136,.9),
    0 0 30px rgba(255,46,136,.5),
    inset 0 1px 1px rgba(255, 255, 255, 0.3);
}
.rhythm-grade {
  position: absolute; left: 0; right: 0; bottom: 44px;
  text-align: center; font-size: 13px; font-weight: 900;
}
.rhythm-grade[data-grade="perfect"] { color: var(--gold); }
.rhythm-grade[data-grade="good"] { color: var(--cyan); }
.rhythm-grade[data-grade="miss"] { color: var(--pink); }
.rhythm-hint {
  position: absolute; left: 0; right: 0; bottom: 8px;
  text-align: center; font-size: 9px; color: var(--muted);
}
@media (max-width: 900px) {
  .rhythm-lane { bottom: calc(var(--dock-h) + 8px); height: 190px; width: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  .rhythm-lane, .rhythm-note { transition: none; }
}

/* ---- quay bar: menu do uong ----
 * z-index cao hon #touch-layer (6), neu khong lop cam ung nuot het cu cham.
 */
.drink-menu {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  z-index: 7;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 9px 12px; max-width: calc(100% - 24px);
  background: linear-gradient(135deg, rgba(20, 17, 34, .96), rgba(28, 24, 46, .94));
  border: 1px solid rgba(255, 209, 102, .5);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl),
    0 0 30px rgba(255, 209, 102, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
}
.drink-menu::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(255, 209, 102, 0.1) 0%,
    transparent 50%,
    rgba(255, 209, 102, 0.05) 100%);
  pointer-events: none;
}
.dm-head { color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.drink-row { display: flex; gap: 8px; }
.drink-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 76px; padding: 7px 9px;
  background: linear-gradient(135deg, rgba(28, 24, 46, 0.9), rgba(20, 17, 34, 0.85));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: var(--txt); font: inherit; line-height: 1.25; cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  transition: all .2s ease;
  transform-style: preserve-3d;
  position: relative;
}
.drink-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(255, 209, 102, 0.05),
    transparent 50%);
  opacity: 0;
  transition: opacity .2s ease;
}
.drink-btn:hover:not(:disabled) {
  border-color: rgba(255, 209, 102, .7);
  box-shadow: var(--shadow-lg),
    0 0 20px rgba(255, 209, 102, 0.3);
  transform: translateY(-2px);
}
.drink-btn:hover:not(:disabled)::before {
  opacity: 1;
}
.drink-btn:active:not(:disabled) {
  transform: translateY(0);
}
.drink-btn:disabled { opacity: .38; cursor: not-allowed; }
.drink-btn .db-emoji { font-size: 21px; }
.drink-btn .db-name { font-size: 12px; }
.drink-btn .db-cost { font-size: 11px; font-weight: 700; color: var(--gold); }

.buff-badge {
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: var(--gold);
  border: 1px solid rgba(255, 209, 102, .45);
  background: rgba(255, 209, 102, .1);
}

.stage-bottom {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, rgba(20, 17, 34, 0.95), rgba(28, 24, 46, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  padding: 8px 14px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  transform-style: preserve-3d;
  position: relative;
}
.stage-bottom::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg,
    rgba(155, 92, 255, 0.06),
    transparent 50%,
    rgba(53, 230, 255, 0.04));
  pointer-events: none;
}
.stage-bottom { flex: none; flex-wrap: wrap; }
.keys { color: var(--muted); font-size: 12px; flex: 1; min-width: 200px; }
.emoji-row { display: flex; gap: 4px; }
.emoji-btn {
  background: linear-gradient(135deg, rgba(255, 255, 255, .1), rgba(255, 255, 255, .06));
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 8px; cursor: pointer; font-size: 16px; padding: 3px 7px; line-height: 1;
  box-shadow: var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all .15s ease;
  transform-style: preserve-3d;
}
.emoji-btn:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, .18), rgba(255, 255, 255, .12));
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}
.emoji-btn:active {
  transform: translateY(0);
}
.vol { display: flex; align-items: center; gap: 6px; }
.vol input { width: 92px; }

/* players + chat */
.player-list { list-style: none; margin: 0; padding: 0; max-height: 210px; overflow: auto; }
.player-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.player-row .pr-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-row .pr-coin { color: var(--gold); font-size: 12px; }
.crown { color: var(--gold); }
.dancing-tag { color: var(--cyan); font-size: 11px; }

.chat-card { min-height: 200px; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.chat-line { font-size: 13px; word-break: break-word; }
.chat-line .cl-name { font-weight: 600; }
.chat-line.near .cl-scope { color: var(--muted); font-size: 10px; }
.chat-line.all .cl-scope { color: var(--pink); font-size: 10px; }
.chat-line.sys { color: var(--muted); font-style: italic; font-size: 12px; }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.chat-form input { flex: 1; }
.switch { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); cursor: pointer; }

/* toast */
#toast-stack {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none;
}
.toast {
  background: linear-gradient(135deg, rgba(20, 17, 34, .98), rgba(28, 24, 46, .96));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: 3px solid var(--violet);
  padding: 9px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow-xl),
    0 0 30px rgba(155, 92, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  animation: toastin .25s ease-out;
  transform-style: preserve-3d;
  position: relative;
}
.toast::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(155, 92, 255, 0.08),
    transparent 50%);
  pointer-events: none;
}
.toast.gold { border-left-color: var(--gold); box-shadow: var(--shadow-xl), 0 0 30px rgba(255, 209, 102, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1); }
.toast.pink { border-left-color: var(--pink); box-shadow: var(--shadow-xl), 0 0 30px rgba(255, 46, 136, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1); }
.toast.bad { border-left-color: #ff7a90; box-shadow: var(--shadow-xl), 0 0 30px rgba(255, 122, 144, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1); }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } }

/* youtube cage: chi can tieng */
#yt-cage {
  position: fixed; width: 1px; height: 1px; bottom: 0; left: 0;
  overflow: hidden; opacity: .01; pointer-events: none;
}
/*
 * Khi bi chan tu phat: phong iframe ra toan man hinh de cu cham roi THANG
 * vao youtube.com.
 *
 * DA KIEM CHUNG TREN IPAD THAT (2026-08-09): goi player.unMute()/playVideo()
 * tu MOT handler click tren trang cha — dung postMessage API, dung ca trong
 * cung mot lan goi dong bo — VAN KHONG mo duoc tieng. WebKit khong coi hanh
 * dong nay la user activation cho iframe cross-origin, du la cach "chuan"
 * theo tai lieu YouTube. Nut bam duoc (thay doi UI) nhung khong co tieng, roi
 * gate lai hien vi checkBlocked() do dung: van chua he phat.
 *
 * Vi vay CA gate (ke ca hop/nut) deu phai pointer-events:none — cu cham PHAI
 * roi thang xuong iframe that su, khong duoc chan lai o bat ky lop nao cua
 * trang cha. Sau khi iframe nhan duoc cu cham that (thoa dieu kien WebKit),
 * vong dong bo nen (reconcile(), chay moi 2.5s, xem audio.js) se goi lai
 * playVideo() va lan nay se thanh cong; onStateChange bat PLAYING roi tu
 * goi hideGate() — khong can unlock() lam viec nay.
 */
body.audio-blocked #yt-cage {
  width: 100%; height: 100%; inset: 0; bottom: auto; left: auto;
  opacity: .15; pointer-events: auto; z-index: 79;
  /* Tang opacity len 0.15 thay vi 0.01: mobile Safari co the ignore touch
   * tren element qua trong suot. 0.15 du de nhan touch nhung van nhin qua duoc. */
}
body.audio-blocked #yt-cage iframe { width: 100%; height: 100%; border: 0; }

.gate {
  position: fixed; inset: 0; z-index: 80;
  background: radial-gradient(circle at 50% 50%,
    rgba(4, 3, 10, .88),
    rgba(7, 6, 13, .94));
  backdrop-filter: blur(16px);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
}

/* Button invisible đã bị XÓA vì nó chặn click không cho xuống iframe.
 * Theo thiết kế đúng: click phải rơi trực tiếp vào iframe để WebKit unlock audio.
 * Giữ rule này để tránh ai đó thêm lại button sau này. */
.gate-unlock-btn {
  display: none !important;  /* KHÔNG BAO GIỜ hiển thị - nó phá hoại thiết kế */
}

.gate-box {
  background: linear-gradient(135deg, rgba(20, 17, 34, 0.96), rgba(28, 24, 46, 0.94));
  border: 1px solid rgba(155, 92, 255, 0.4);
  border-radius: var(--radius);
  padding: 26px 30px;
  text-align: center;
  max-width: 380px;
  pointer-events: none;
  box-shadow: var(--shadow-xl),
    0 0 60px rgba(155, 92, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  transform-style: preserve-3d;
  position: relative;
}
.gate-box::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(155, 92, 255, 0.1) 0%,
    transparent 50%,
    rgba(53, 230, 255, 0.08) 100%);
  pointer-events: none;
}
.gate-box h2 { margin: 0 0 8px; font-size: 18px; pointer-events: none; }
.gate-box p { color: var(--muted); margin: 0 0 16px; pointer-events: none; }
.gate-hint {
  display: inline-block; padding: 10px 18px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(155, 92, 255, .25), rgba(155, 92, 255, .15));
  border: 1px solid rgba(155, 92, 255, .6);
  font-weight: 600;
  animation: gatepulse 1.6s ease-in-out infinite;
  pointer-events: none;
  box-shadow: 0 0 30px rgba(155, 92, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
@keyframes gatepulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 30px rgba(155, 92, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1); }
  50% { opacity: .55; box-shadow: 0 0 50px rgba(155, 92, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15); }
}

/* ======================================================================== */
/* CAM UNG — joystick + nut hanh dong, phu len san bar.                     */
/* Bat/tat bang JS (body.is-touch), khong phu thuoc be ngang man hinh:      */
/* iPad landscape rong 1180px van la man hinh cham.                          */
/* ======================================================================== */
#touch-layer {
  position: absolute; inset: 0; z-index: 6;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  pointer-events: none; /* Cho phép click xuyên qua layer, chỉ các button và joystick có pointer-events */
}

#touch-layer > * {
  pointer-events: auto; /* Chỉ các phần tử con (button, joystick) nhận sự kiện */
}

.stick {
  position: absolute;
  left: calc(20px + var(--safe-l)); bottom: 20px;
  width: 132px; height: 132px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%,
    rgba(155, 92, 255, .22),
    rgba(20, 17, 34, .85),
    rgba(10, 8, 18, .7));
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: var(--shadow-lg),
    inset 0 0 30px rgba(155, 92, 255, 0.15),
    0 0 40px rgba(155, 92, 255, 0.2);
  opacity: .42;
  transition: opacity .18s ease;
  transform-style: preserve-3d;
}
.stick.active {
  opacity: .92;
  transition: none;
  box-shadow: var(--shadow-xl),
    inset 0 0 40px rgba(155, 92, 255, 0.25),
    0 0 60px rgba(155, 92, 255, 0.4);
}
.stick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: linear-gradient(135deg, rgba(255, 46, 136, .95), rgba(155, 92, 255, .95));
  border: 1px solid rgba(255, 255, 255, .4);
  box-shadow: var(--shadow-lg),
    0 0 20px rgba(255, 46, 136, 0.5),
    inset 0 2px 4px rgba(255, 255, 255, 0.2),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3);
  transform-style: preserve-3d;
}

.touch-actions {
  position: absolute;
  right: calc(16px + var(--safe-r)); bottom: 18px;
  display: flex; align-items: flex-end; gap: 10px;
}

/* Hiển thị touch-actions cả trên desktop, chỉ ẩn joystick */
body:not(.is-touch) .stick {
  display: none;
}

body:not(.is-touch) .touch-actions {
  display: flex;
  flex-direction: row; /* Xếp ngang */
  gap: 12px;
  right: 20px;
  bottom: 20px; /* Nằm dưới cùng, ngang với emoji row */
  left: auto;
}

/* Ẩn nút tray trên desktop vì không cần thiết */
body:not(.is-touch) #tb-tray {
  display: none;
}
.touch-btn {
  width: 62px; height: 62px; border-radius: 50%;
  background: linear-gradient(135deg, rgba(28, 24, 46, .85), rgba(20, 17, 34, .8));
  border: 1px solid rgba(255, 255, 255, .2);
  color: var(--txt);
  font-size: 25px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(12px);
  touch-action: none;
  box-shadow: var(--shadow-lg),
    inset 0 1px 2px rgba(255, 255, 255, 0.1);
  transition: all .15s ease;
  transform-style: preserve-3d;
}
.touch-btn:active { transform: scale(.93); }
.touch-btn.on {
  background: linear-gradient(135deg, rgba(53, 230, 255, .4), rgba(155, 92, 255, .4));
  border-color: rgba(53, 230, 255, .7);
  box-shadow: var(--shadow-xl), var(--glow-cyan);
}
.tb-beat {
  width: 78px; height: 78px; font-size: 31px;
  border-color: rgba(255, 209, 102, .5);
  box-shadow: var(--shadow-lg),
    0 0 25px rgba(255, 209, 102, 0.3),
    inset 0 1px 2px rgba(255, 255, 255, 0.1);
}
.tb-small { width: 46px; height: 46px; font-size: 19px; }

/* Khay emoji/am luong chi la popover khi .stage-bottom bi thu thanh popover */
#tb-tray { display: none; }
body.is-stack #tb-tray { display: flex; }
/* May cham thi khong co ban phim de ma nhac phim */
body.is-touch .keys { display: none; }

/* ======================================================================== */
/* DOCK + DRAWER — chi song khi man hinh hep (JS bat body.is-compact).      */
/* ======================================================================== */
#dock { display: none; }
#drawer-scrim { display: none; }

body.is-compact #dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
  display: flex; gap: 4px; justify-content: center;
  background: linear-gradient(180deg, rgba(11, 9, 20, .98), rgba(7, 6, 13, .96));
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding: 5px max(6px, var(--safe-l)) calc(5px + var(--safe-b)) max(6px, var(--safe-r));
  backdrop-filter: blur(16px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform-style: preserve-3d;
}
.dock-btn {
  flex: 1 1 0; max-width: 200px; min-height: 46px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: none; border: 0; border-radius: 10px;
  color: var(--muted); font: inherit; font-size: 19px; line-height: 1.1;
  cursor: pointer;
  transition: all .15s ease;
}
.dock-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}
.dock-btn span { font-size: 10px; letter-spacing: .3px; }
.dock-btn.active {
  color: var(--cyan);
  background: linear-gradient(135deg, rgba(53, 230, 255, .15), rgba(53, 230, 255, .08));
  box-shadow: inset 0 0 20px rgba(53, 230, 255, 0.2);
}
.dock-btn.hidden { display: none !important; }

/* Nut vote noi len dock: chi can khi cot nhac bi cat khoi layout (stack). */
.dock-react { display: none; }
body.is-stack .dock-react { display: flex; }
body.is-stack .dock-react span { font-size: 11px; font-weight: 700; }
.dock-react.on { color: var(--pink); background: rgba(255, 46, 136, .12); }
.dock-react.hidden { display: none !important; }

body.is-compact #drawer-scrim {
  display: block;
  position: fixed; inset: 0; z-index: 45;
  background: rgba(3, 2, 8, .58);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
body.is-compact #drawer-scrim.on { opacity: 1; pointer-events: auto; }

body.is-compact .side.is-drawer {
  position: fixed; z-index: 50;
  left: 0; right: 0;
  /* Ngoi tren dock; khi ban phim ao mo thi ngoi tren ban phim (--kb lon hon). */
  bottom: max(var(--kb), var(--dock-h));
  height: min(72%, 620px);
  padding: 0 max(12px, var(--safe-l)) 12px max(12px, var(--safe-r));
  background: linear-gradient(180deg, rgba(13, 11, 24, .98), rgba(11, 9, 20, .96));
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, .6),
    0 -8px 32px rgba(155, 92, 255, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  transform: translateY(105%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform-style: preserve-3d;
}
body.is-compact .side.is-drawer.open { transform: none; }
body.is-compact .side.is-drawer .drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 2px 10px;
  font-size: 13px;
}
/* thanh keo nho cho biet day la sheet keo len */
body.is-compact .side.is-drawer .drawer-head::before {
  content: ''; position: absolute; left: 50%; top: 6px; transform: translateX(-50%);
  width: 38px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .22);
}
/* Tablet nam ngang: sheet keo tu duoi len chiem het man hinh la phi cho.
 * Doi thanh panel truot tu canh phai vao. */
body.is-compact:not(.is-stack) .side.is-drawer {
  top: 0; left: auto; right: 0;
  width: min(360px, 42%);
  height: auto;
  border: 0; border-left: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px 0 0 18px;
  box-shadow: -18px 0 50px rgba(0, 0, 0, .6),
    -8px 0 32px rgba(155, 92, 255, 0.15),
    inset 1px 0 0 rgba(255, 255, 255, 0.08);
  background: linear-gradient(90deg, rgba(13, 11, 24, .98), rgba(11, 9, 20, .96));
  transform: translateX(105%);
  padding-top: 0;
}
/* Cung do "manh" voi rule truot tu duoi len nen phai lap lai trang thai mo. */
body.is-compact:not(.is-stack) .side.is-drawer.open { transform: none; }
body.is-compact:not(.is-stack) .side.is-drawer .drawer-head::before { content: none; }

.drawer-close {
  background: none; border: 0; color: var(--muted);
  font-size: 17px; line-height: 1; padding: 8px 10px; cursor: pointer;
  min-width: 40px; min-height: 40px;
}

/* ======================================================================== */
/* TABLET NGANG (901–1180): cot nhac o lai, cot chat thanh drawer.          */
/* ======================================================================== */
@media (max-width: 1180px) {
  .room-grid { grid-template-columns: 260px minmax(0, 1fr); }
  .stage-top { gap: 10px; flex-wrap: wrap; }
  #hype-label { width: auto; }
}

/* ======================================================================== */
/* DIEN THOAI + TABLET DOC (<= 900): mot cot, ca hai ben deu la drawer.     */
/* ======================================================================== */
@media (max-width: 900px) {
  .room-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
    padding-left: max(8px, var(--safe-l));
    padding-right: max(8px, var(--safe-r));
    padding-top: calc(8px + var(--safe-t));
    padding-bottom: calc(8px + max(var(--dock-h), var(--safe-b)));
  }

  .stage-top { padding: 7px 10px; gap: 8px; font-size: 13px; }
  .stage-top .bar-id strong { font-size: 13px; }
  .hype { min-width: 120px; }
  #hype-label { font-size: 11px; }
  .wallet #btn-leave { display: none; }        /* da co nut Roi bar o dock */

  /* thanh emoji + am luong thanh popover noi tren san, bat bang nut 🎛 */
  .stage-bottom {
    position: absolute; right: 12px; bottom: 104px; z-index: 8;
    display: none; flex-direction: column; align-items: stretch; gap: 10px;
    width: 208px; padding: 12px;
  }
  .stage-bottom.open { display: flex; }
  .keys { display: none; }
  .emoji-row { flex-wrap: wrap; justify-content: center; gap: 6px; }
  .emoji-btn { font-size: 22px; padding: 7px 10px; min-width: 44px; min-height: 42px; }
  .vol { justify-content: space-between; }
  .vol input { flex: 1; width: auto; height: 26px; }

  /* nut/o nhap du to de cham; 16px de iOS khong tu zoom khi focus input */
  .btn { min-height: 42px; padding: 10px 14px; }
  .btn-sm { min-height: 38px; padding: 8px 12px; font-size: 13px; }
  input[type="text"], input[type="number"], input[type="password"] {
    font-size: 16px; padding: 11px 12px;
  }
  .inline-field input { width: 74px; }
  .ci-btn, .ci-del { min-width: 42px; min-height: 38px; font-size: 13px; }
  .switch { font-size: 12px; }
  .switch input { width: 18px; height: 18px; }

  .card { padding: 12px; }
  .player-list { max-height: 34vh; }
  .chat-card { min-height: 0; }

  /* lobby gon lai */
  .lobby-wrap { padding-top: calc(24px + var(--safe-t)); padding-bottom: calc(24px + var(--safe-b)); }
  .logo { font-size: 34px; letter-spacing: 4px; }
  .lobby-head { margin-bottom: 22px; }
  .panel { padding: 16px; }
  .bar-list { max-height: none; }
  .bar-item { flex-wrap: wrap; }
  .bar-item .bi-main { flex: 1 1 100%; }
}

/* Man hinh rat thap khi xoay ngang (dien thoai landscape): thu nho phan tren */
@media (max-height: 480px) and (max-width: 1180px) {
  .stage-top { padding: 5px 10px; }
  .stick { width: 108px; height: 108px; bottom: 12px; }
  .stick-knob { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
  .touch-btn { width: 52px; height: 52px; font-size: 21px; }
  .tb-beat { width: 64px; height: 64px; font-size: 26px; }
  .tb-small { width: 40px; height: 40px; font-size: 16px; }
  body.is-compact .side.is-drawer { height: 92%; }
}

/* Khong co hover that (may cham): bo hieu ung hover de khong bi "dinh" */
@media (hover: none) {
  .btn:hover { background: rgba(255, 255, 255, 0.07); }
  .btn-primary:hover { filter: none; }
  .emoji-btn:hover { background: rgba(255, 255, 255, .07); }
}

/* ---------------- Man tao nhan vat ---------------- */
.creator {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 50%,
    rgba(5, 4, 10, 0.94),
    rgba(7, 6, 13, 0.98));
  backdrop-filter: blur(12px);
  padding: 16px;
}
.creator.hidden { display: none; }

.creator-box {
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(135deg, rgba(18, 12, 31, 0.98), rgba(20, 17, 34, 0.96));
  border: 1px solid rgba(155, 92, 255, 0.4);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-xl),
    0 0 60px rgba(155, 92, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  transform-style: preserve-3d;
  position: relative;
}
.creator-box::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(155, 92, 255, 0.12) 0%,
    transparent 50%,
    rgba(53, 230, 255, 0.08) 100%);
  pointer-events: none;
}
.creator-title { margin: 0 0 4px; font-size: 20px; }
.creator-sub { margin: 0 0 14px; font-size: 13px; color: rgba(233, 230, 245, 0.6); }

#creator-canvas {
  background: linear-gradient(180deg, #120a20, #08060f);
  border-radius: 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-lg),
    inset 0 0 40px rgba(0, 0, 0, 0.6),
    inset 0 2px 4px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(155, 92, 255, 0.2);
}

.creator-slots { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.creator-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
  border-radius: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.creator-slot-name { font-size: 13px; color: rgba(233, 230, 245, 0.75); }
.creator-slot-value { flex: 1; font-size: 13px; text-align: center; }
.creator-arrow {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #e9e6f5;
  cursor: pointer;
  font-size: 15px;
  padding: 4px 12px;
  box-shadow: var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all .15s ease;
}
.creator-arrow:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.1));
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.creator-actions { display: flex; gap: 10px; }
.creator-actions .btn { flex: 1; }

/* ---------------- Shop / tu do ---------------- */
/* Shop LUON la drawer, ke ca tren desktop: no khong duoc chiem mot cot co
 * dinh trong luoi va khong duoc che san nhay. Khi man hinh hep thi cac rule
 * `body.is-compact .side.is-drawer` co do uu tien cao hon se lo phan truot,
 * nen khoi duoi day chi ta phien ban desktop. */
.side-shop { display: none; }
.side-shop.is-drawer { display: flex; }

body:not(.is-compact) .side-shop.is-drawer {
  position: fixed;
  z-index: 50;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  width: min(340px, 92vw);
  padding: 0 14px 14px;
  background: linear-gradient(90deg, rgba(13, 11, 24, .98), rgba(11, 9, 20, .96));
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px 0 0 18px;
  box-shadow: -18px 0 50px rgba(0, 0, 0, 0.6),
    -8px 0 32px rgba(155, 92, 255, 0.15),
    inset 1px 0 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  transform: translateX(105%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  overflow: hidden;
  transform-style: preserve-3d;
}
body:not(.is-compact) .side-shop.is-drawer.open { transform: none; }
/* Scrim von chi song o che do compact; shop mo duoc tren desktop nen no
 * cung can lop toi de bam ra ngoai la dong. */
body:not(.is-compact) #drawer-scrim.on {
  display: block;
  position: fixed; inset: 0; z-index: 45;
  background: rgba(3, 2, 8, .48);
  opacity: 1; pointer-events: auto;
}
body:not(.is-compact) .side-shop.is-drawer .drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px 10px;
  font-size: 13px;
}

/* Cai nut o thanh vi tien chi can khi dock chua hien (dock da co nut 👕). */
body.is-compact #btn-wardrobe { display: none; }

.shop-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.shop-slot-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(233, 230, 245, 0.5);
  margin: 12px 0 6px;
}
.shop-slot-title:first-child { margin-top: 0; }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 8px;
}

.shop-item {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 6px 4px;
  cursor: pointer;
  text-align: center;
  color: inherit;
  font: inherit;
  box-shadow: var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: all .2s ease;
  transform-style: preserve-3d;
  position: relative;
}
.shop-item::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(155, 92, 255, 0.05),
    transparent 50%);
  opacity: 0;
  transition: opacity .2s ease;
}
.shop-item:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06));
  box-shadow: var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}
.shop-item:hover::before {
  opacity: 1;
}
.shop-item.equipped {
  border-color: #35e6ff;
  box-shadow: var(--shadow-md), var(--glow-cyan);
}
.shop-item.locked { opacity: 0.55; }

.shop-item canvas { display: block; margin: 0 auto 4px; }
.shop-item-name { display: block; font-size: 11px; color: rgba(233, 230, 245, 0.85); }
.shop-item-cost { display: block; font-size: 11px; color: #ffd166; }
.shop-item-owned { display: block; font-size: 11px; color: rgba(233, 230, 245, 0.5); }

/* Missions Panel */
#missions-panel {
  position: fixed;
  right: 20px;
  top: 80px;
  width: 320px;
  max-height: 500px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

#missions-list {
  padding: 16px;
  overflow-y: auto;
  max-height: 420px;
}

.mission-card {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(71, 85, 105, 0.5);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  transition: all 0.2s ease;
}

.mission-card:hover {
  border-color: rgba(56, 189, 248, 0.6);
  transform: translateY(-2px);
}

.mission-card.completed {
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.5);
}

.mission-label {
  font-size: 14px;
  font-weight: 600;
  color: #f8fafc;
  margin-bottom: 8px;
}

.mission-progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.mission-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #22d3ee);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.mission-card.completed .mission-progress-fill {
  background: linear-gradient(90deg, #22c55e, #10b981);
}

.mission-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.mission-count {
  color: #94a3b8;
  font-weight: 500;
}

.mission-reward {
  color: #fbbf24;
  font-weight: 600;
}

.mission-check {
  font-size: 16px;
}

.mission-toast {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(34, 197, 94, 0.95);
  color: white;
  padding: 16px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  z-index: 10000;
  animation: slideDown 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mission-toast.fade-out {
  animation: fadeUp 0.5s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes fadeUp {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
}

@media (max-width: 768px) {
  #missions-panel {
    position: fixed;
    right: 10px;
    left: 10px;
    width: auto;
    top: 70px;
  }
}


/* ============================ ma khoi phuc ============================ */
.recovery { margin: -4px 0 12px; font-size: 12px; }
.recovery summary { cursor: pointer; color: var(--muted); user-select: none; }
.recovery summary:hover { color: var(--txt); }
.recovery .hint { margin: 6px 0 8px; }
.recovery-row { display: flex; gap: 6px; margin-bottom: 6px; }
.recovery-row input { flex: 1; }
#recovery-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ============================ bang xep hang ============================ */
.leaderboard { margin-top: 18px; }
.leaderboard h2 { display: flex; align-items: center; gap: 8px; }
.lb-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.lb-tab.is-active { border-color: var(--violet); box-shadow: 0 0 0 2px rgba(155, 92, 255, 0.3); }
.lb-list { list-style: none; margin: 10px 0 0; padding: 0; }
.lb-list li { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.lb-list li:last-child { border-bottom: 0; }
.lb-rank { width: 28px; text-align: center; }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-value { color: var(--gold); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--muted); justify-content: center; }
.streak-badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: rgba(255, 159, 67, 0.16); color: #ffb86b; white-space: nowrap; }

/* ============================ battle / ban be / tang do ============================ */
.battle-banner { margin: 0 0 8px; padding: 7px 10px; border-radius: 9px; font-size: 12px;
  background: linear-gradient(135deg, rgba(255, 46, 136, 0.22), rgba(155, 92, 255, 0.22));
  border: 1px solid rgba(255, 46, 136, 0.45); }
.battle-banner small { color: var(--muted); }
.friends { margin-top: 18px; }
.friends .lb-list li { gap: 8px; }
.dm-gift { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.dm-gift select { flex: 1; background: rgba(0, 0, 0, 0.4); color: var(--txt); border: 1px solid var(--line); border-radius: 7px; padding: 4px; }
#staff-controls select { background: rgba(0, 0, 0, 0.4); color: var(--txt); border: 1px solid var(--line); border-radius: 7px; padding: 3px; }
