* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #fff; }
/* Trên điện thoại: chạm nhanh không làm zoom trang, giữ lâu không bôi đen chữ. */
html, body, #stage, #stage * { touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#stage input { -webkit-user-select: text; user-select: text; }

/* Toàn màn hình: màn dọc lẫn màn ngang đều dùng hết khung hình */
#stage { position: fixed; inset: 0; overflow: hidden; background: #05030f; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
[hidden] { display: none !important; }

.glass { background: rgba(8, 4, 24, .62); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); border: 1px solid rgba(255, 255, 255, .12); border-radius: 10px; }
.gold { color: #ffd23f; }

/* ---------- HUD trên cùng ---------- */
#hud { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; padding: 6px 8px 0; pointer-events: none; display: flex; flex-direction: column; gap: 4px; z-index: 2; }
#hudTop { display: flex; align-items: center; gap: 8px; padding-right: 44px; min-height: 30px; }
#brand {
  font-style: italic; font-weight: 900; font-size: clamp(18px, 5.4vw, 26px); letter-spacing: .3px; white-space: nowrap;
  background: linear-gradient(90deg, #ffd23f, #ff3fa8, #7f8cff); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .9));
}
#meStatus { margin-left: auto; font-size: 12px; font-weight: 700; color: #4dff88; text-shadow: 0 1px 3px #000; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#guestStrip { display: flex; justify-content: center; gap: 2px; min-height: 66px; padding: 3px 2px; background: rgba(8, 4, 24, .55); border-radius: 10px; transition: opacity .25s; }
.guest { position: relative; flex: 0 1 62px; min-width: 0; text-align: center; font-size: 10px; font-weight: 700; line-height: 1.15; }
.guest img { display: block; width: 44px; height: 44px; object-fit: cover; object-position: 50% 12%; border-radius: 50%; margin: 0 auto 1px; border: 1.5px solid rgba(255, 255, 255, .35); background: #2a1650; }
.guest b { position: absolute; top: -1px; right: 2px; font-size: 10.5px; font-weight: 900; color: #cfc8e8; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; }
.guest b.has { color: #ffd23f; }
.guest span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-shadow: 0 1px 2px #000; }
.guest.me span { color: #7dffb0; }
.guest.me img { border-color: #7dffb0; }
#heatBar { position: relative; height: 22px; background: rgba(8, 4, 24, .8); border-radius: 11px; overflow: hidden; }
#heatFill { position: absolute; left: 2px; top: 2px; bottom: 2px; border-radius: 9px; width: 0; background: linear-gradient(90deg, #5a5cff 0, #ff3fa8 45%, #ff8a1f 80%, #ffe14d 100%); background-size: calc(100vw - 20px) 100%; }
#heatLabel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; text-shadow: 0 1px 2px #000, 0 0 3px #000; white-space: nowrap; overflow: hidden; }
#hudRow { display: flex; justify-content: space-between; gap: 6px; }
#topBox, #statBox { padding: 5px 8px; width: 148px; font-size: 11px; font-weight: 700; line-height: 1.45; }
#topBox b { display: block; color: #ffd23f; font-weight: 800; font-size: 10.5px; }
#topList { list-style: none; margin: 0; padding: 0; }
#topList li { display: flex; gap: 4px; justify-content: space-between; white-space: nowrap; }
#topList li span:first-child { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#topList li em { font-style: normal; color: #ffd23f; }
#statBox { font-size: 11.5px; }

/* Màn ngang: bảng xếp hạng và thống kê dạt hai bên */
@media (min-aspect-ratio: 1/1) {
  #hud { padding: 8px 14px 0; }
  #hudTop { position: absolute; left: 14px; top: 8px; padding: 0; }
  #meStatus { position: absolute; left: 0; top: 30px; max-width: 200px; }
  #guestStrip { margin: 0 auto; max-width: min(64vw, 780px); width: 100%; }
  #heatBar { margin: 0 auto; width: min(64vw, 780px); }
  #heatFill { background-size: min(64vw, 780px) 100%; }
  #hudRow { position: absolute; left: 14px; right: 14px; top: 62px; }
  #topBox, #statBox { width: 170px; font-size: 12px; }
}

/* Điện thoại xoay ngang: mọi thứ gọn lại để nhường chỗ cho sàn nhảy */
@media (min-aspect-ratio: 1/1) and (max-height: 500px) {
  #brand { font-size: 17px; }
  #hudTop { top: 4px; left: 10px; }
  #meStatus { top: 24px; font-size: 11px; max-width: 130px; }
  #hud { padding-top: 4px; }
  #guestStrip { min-height: 46px; max-width: 58vw; padding: 1px; }
  .guest { font-size: 9px; }
  .guest img { width: 30px; height: 30px; }
  #heatBar { height: 18px; width: 58vw; }
  #heatLabel { font-size: 10.5px; }
  #hudRow { top: 44px; left: 10px; right: 10px; }
  #topBox, #statBox { width: 128px; font-size: 10px; padding: 3px 6px; line-height: 1.32; }
  #topBox b { font-size: 9.5px; }
  #statBox { margin-top: 26px; }
  #topBox { margin-top: 0; }
  #hint { display: none; }
  #commentBtn { height: 38px; font-size: 14px; }
  #coinBadge { padding: 7px 10px; font-size: 13px; }
  #heartBtn { width: 44px; height: 44px; font-size: 20px; }
  #giftBtn { width: 38px; height: 38px; font-size: 17px; }
  #playerBar { width: min(70%, 480px); bottom: 5px; }
}

#hint {
  position: absolute; left: 50%; bottom: calc(66px + env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0; padding: 5px 14px; max-width: 94%;
  background: rgba(8, 4, 24, .66); border-radius: 12px; color: #ffe27a; font-weight: 800; font-size: clamp(12px, 3.5vw, 14.5px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 2px #000; pointer-events: none; z-index: 2;
}

#banner {
  position: absolute; left: 50%; top: 64%; min-width: 260px; max-width: 94%; padding: 11px 22px; text-align: center; pointer-events: none;
  background: rgba(10, 5, 28, .88); border: 3px solid var(--c, #ffd23f); border-radius: 16px; box-shadow: 0 0 34px color-mix(in srgb, var(--c, #ffd23f) 45%, transparent); z-index: 3;
  transform: translate(-50%, -50%) scale(0); transition: transform .22s cubic-bezier(.2, 1.3, .4, 1);
}
#banner.show { transform: translate(-50%, -50%) scale(1); }
#banner strong { display: block; color: var(--c, #ffd23f); font-weight: 900; font-size: clamp(18px, 5.6vw, 25px); line-height: 1.2; text-shadow: 0 2px 3px #000; }
#banner span { display: block; margin-top: 3px; font-weight: 800; font-size: clamp(13px, 4vw, 16px); }

#fireVignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 55%, rgba(255, 120, 0, 0) 38%, rgba(255, 70, 0, .34) 100%); animation: firePulse .35s ease-in-out infinite alternate; z-index: 1; }
@keyframes firePulse { from { opacity: .75; } to { opacity: 1; } }

#menuBtn {
  position: absolute; top: calc(6px + env(safe-area-inset-top)); right: 8px; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255, 255, 255, .14); font-size: 17px; opacity: .7; z-index: 4;
}
#menuBtn:hover, #menuBtn:focus-visible { opacity: 1; }

/* Nút ✕ nhỏ cạnh nhân vật của mình khi đang ở bục nhảy, ghế VIP hoặc bàn DJ */
#stepDownBtn {
  position: absolute; transform: translate(-50%, -50%); min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px;
  background: #ff3f5f; border: 1.5px solid #fff; font-size: 13px; font-weight: 800; line-height: 1; white-space: nowrap; z-index: 3;
}
#stepDownBtn::before { content: ""; position: absolute; inset: -8px; }
#stepDownBtn.armed { background: #ffd23f; color: #1b1030; }

#panel {
  position: absolute; top: calc(48px + env(safe-area-inset-top)); right: 8px; width: min(88%, 310px); max-height: 80%; overflow: auto;
  background: rgba(14, 9, 38, .96); border: 1px solid rgba(255, 255, 255, .18); border-radius: 14px; padding: 12px; font-size: 13px; z-index: 5;
}
#closePanel { background: none; font-size: 16px; padding: 2px 6px; }
.row { display: flex; align-items: center; gap: 6px; }
.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid button { background: rgba(255, 255, 255, .1); padding: 9px 4px; border-radius: 9px; }
.grid button:hover { background: rgba(255, 255, 255, .2); }

input {
  font: inherit; color: #fff; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 9px; padding: 9px 10px; width: 100%; min-width: 0;
}
input:focus { outline: 2px solid #ff3fa8; }

/* ---------- Màn đăng ký, chọn nhân vật ---------- */
#setup {
  position: absolute; inset: 0; display: flex; padding: 5%; z-index: 6; overflow: auto;
  background: radial-gradient(circle at 50% 30%, rgba(40, 14, 76, .72), rgba(5, 3, 18, .9));
}
.card { width: 100%; max-width: 430px; margin: auto; }
.wordmark { display: block; width: min(52%, 220px); margin: 0 auto 8px; }
.card h1 {
  margin: 0; text-align: center; font-size: clamp(32px, 9.5vw, 52px); font-style: italic; font-weight: 900; line-height: 1.05;
  background: linear-gradient(90deg, #ffd23f, #ff3fa8, #6c7bff); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tag { text-align: center; margin: 6px 0 12px; color: #e5ddff; }
.card label { font-weight: 700; font-size: 14px; display: block; margin-bottom: 6px; }
.primary:disabled { opacity: .45; cursor: default; }
.primary, .ghost { width: 100%; padding: 13px; border-radius: 12px; font-weight: 800; font-size: 16px; margin-top: 10px; }
.primary { background: linear-gradient(90deg, #ff3fa8, #ff8a1f); }
.ghost { background: rgba(255, 255, 255, .12); }
.split { display: flex; gap: 8px; }
.muted { color: #bdb4dc; }
.small { font-size: 12px; text-align: center; margin: 12px 0 0; }
.error { color: #ff8b8b; font-size: 13px; margin: 8px 0 0; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: rgba(255, 255, 255, .08); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.tabs button { background: none; padding: 9px; border-radius: 9px; font-weight: 700; }
.tabs button.on { background: #ff3fa8; }
#authForm label, #codeForm label { display: block; margin-bottom: 10px; }
#authForm input, #codeForm input { display: block; margin-top: 4px; font-weight: 400; font-size: 16px; }

/* Khi chọn nhân vật: club 3D và nhân vật xem trước nằm ở nửa trống của màn hình */
#setup.stageView { background: linear-gradient(180deg, rgba(5, 3, 18, 0) 34%, rgba(5, 3, 18, .55) 52%, rgba(5, 3, 18, .94) 72%); padding: 0 12px calc(12px + env(safe-area-inset-bottom)); align-items: flex-end; }
#setup.stageView .card { margin: 0 auto; max-width: 520px; }
#setup.stageView .wordmark, #setup.stageView h1 { display: none; }
#setup.stageView .tag { font-weight: 700; text-shadow: 0 1px 3px #000; }
@media (min-aspect-ratio: 1/1) {
  #setup.stageView { background: linear-gradient(90deg, rgba(5, 3, 18, 0) 34%, rgba(5, 3, 18, .55) 50%, rgba(5, 3, 18, .94) 66%); justify-content: flex-end; align-items: center; padding: 16px 28px; }
  #setup.stageView .card { margin: 0; width: min(46vw, 520px); }
}

#pickGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 38dvh; overflow: auto; padding: 2px; }
@media (min-aspect-ratio: 1/1) { #pickGrid { max-height: 62dvh; } }
#pickGrid button { position: relative; background: rgba(255, 255, 255, .08); border: 2px solid transparent; border-radius: 10px; padding: 3px 2px 4px; font-size: 11px; line-height: 1.2; min-width: 0; }
#pickGrid button.on { border-color: #ffd23f; background: rgba(255, 210, 63, .18); }
#pickGrid img, #pickGrid .ph { display: block; width: 100%; aspect-ratio: 150 / 186; border-radius: 7px; object-fit: cover; background: #2a1650; margin-bottom: 2px; }
#pickGrid b { position: absolute; top: 4px; left: 6px; color: #ffd23f; text-shadow: 0 1px 2px #000; }

/* ---------- Thanh thao tác ---------- */
#playerBar {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(96%, 560px); bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 6px; z-index: 3;
}
#coinBadge {
  flex: none; padding: 9px 11px; border-radius: 20px; background: rgba(8, 4, 24, .88); border: 1px solid #ffd23f;
  color: #ffd23f; font-weight: 800; font-size: 14px;
}
#commentBtn {
  flex: 1; min-width: 0; height: 42px; border-radius: 21px; background: rgba(8, 4, 24, .88); border: 1px solid rgba(255, 255, 255, .3);
  font-weight: 700; font-size: 15px; white-space: nowrap;
}
#commentBtn:hover, #commentBtn[aria-expanded="true"] { background: #ff3fa8; border-color: #ff3fa8; }
#chatForm {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(96%, 560px); bottom: calc(68px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 6px; padding: 8px;
  background: rgba(14, 9, 38, .96); border: 1px solid rgba(255, 255, 255, .2); border-radius: 14px; z-index: 3;
}
#chatInput { flex: 1; width: auto; border-radius: 20px; font-size: 16px; padding: 8px 14px; }
#chatSend { flex: none; height: 38px; padding: 0 16px; border-radius: 19px; background: #ff3fa8; font-weight: 800; }
#chatCancel { flex: none; width: 38px; height: 38px; border-radius: 50%; background: rgba(255, 255, 255, .12); }
#heartBtn, #giftBtn { flex: none; width: 42px; height: 42px; border-radius: 50%; background: rgba(8, 4, 24, .88); border: 1px solid rgba(255, 255, 255, .3); font-size: 19px; }
#heartBtn { width: 52px; height: 52px; font-size: 24px; touch-action: none; }
#heartBtn.holding { background: #ff3fa8; border-color: #ff3fa8; transform: scale(1.14); }
#giftBtn:active { transform: scale(.88); }
#giftBtn.on { background: #ff3fa8; }
#giftMenu {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(96%, 560px); bottom: calc(68px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; padding: 6px;
  background: rgba(14, 9, 38, .96); border: 1px solid rgba(255, 255, 255, .2); border-radius: 14px; z-index: 3;
}
#giftMenu button { display: flex; flex-direction: column; align-items: center; text-align: center; background: rgba(255, 255, 255, .08); border-radius: 10px; padding: 7px 1px; font-size: 10.5px; line-height: 1.25; }
#giftMenu button span { font-size: 22px; line-height: 1.2; }
#giftMenu button b { color: #ffd23f; margin-top: auto; padding-top: 2px; }
#giftMenu button:disabled { opacity: .35; cursor: default; }
#giftMenu #birthdayBtn { display: block; grid-column: 1 / -1; padding: 11px 6px; font-size: 14px; font-weight: 800; background: linear-gradient(90deg, #ff3fa8, #ff8a1f); }
#giftMenu #birthdayBtn.armed { background: #ffd23f; color: #1b1030; }
#toast {
  position: absolute; left: 50%; bottom: 33%; transform: translateX(-50%); width: max-content; max-width: 90%; margin: 0; padding: 9px 14px; border-radius: 12px;
  background: rgba(8, 4, 24, .94); border: 1px solid #ff8b8b; font-size: 13px; text-align: center; z-index: 7;
}
#toast.good { border-color: #ffd23f; }

/* ---------- Nhạc YouTube của DJ: khung nằm dưới canvas, canvas trong suốt đúng chỗ màn video ---------- */
#tube { position: absolute; left: 0; top: 0; width: 640px; height: 360px; transform-origin: 0 0; pointer-events: none; z-index: 0; background: #000; }
#tube iframe { width: 640px; height: 360px; border: 0; display: block; }
#gl { z-index: 1; }
#overlay { z-index: 2; }
#tubeTap { position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 118px); transform: translateX(-50%); z-index: 40; background: #ffd23f; color: #1b1030; font-weight: 800; border-radius: 999px; padding: 9px 16px; box-shadow: 0 4px 18px rgba(0, 0, 0, .5); }

/* ---------- Tạo nhân vật: giới tính và nghề ---------- */
.lbl { display: block; font-size: 12.5px; font-weight: 800; margin: 2px 0 5px; text-shadow: 0 1px 3px #000; }
.pickRow { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.pickRow .lbl { margin: 0; }
.seg { display: inline-flex; gap: 6px; }
.seg button { background: rgba(255, 255, 255, .1); border: 2px solid transparent; border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: 13px; }
.seg button.on { border-color: #ffd23f; background: rgba(255, 210, 63, .18); }
#roleGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 7px; }
#roleGrid button { text-align: left; background: rgba(20, 12, 40, .78); border: 2px solid rgba(255, 255, 255, .12); border-radius: 10px; padding: 6px 6px 5px; font-size: 10.5px; line-height: 1.28; min-width: 0; color: #e8e2f5; }
#roleGrid button b { display: block; font-size: 13px; color: #fff; margin-bottom: 2px; }
#roleGrid button small { display: block; color: #b9aed1; margin-top: 3px; font-size: 10px; }
#roleGrid button.on { border-color: #ffd23f; background: rgba(60, 40, 10, .85); }
@media (max-width: 420px) { #roleGrid { grid-template-columns: 1fr 1fr; } }
#roleGrid button p { display: none; }
#roleNote { margin: 0 0 8px; font-size: 12.5px; line-height: 1.4; color: #efe8ff; background: rgba(20, 12, 40, .72); border-radius: 10px; padding: 7px 9px; }
#pickGrid:empty { display: none; }

/* ---------- Nút và bảng theo nghề trên sàn ---------- */
#roleBtn { flex: none; height: 42px; padding: 0 12px; border-radius: 21px; background: linear-gradient(180deg, #ffe27a, #e9a91c); color: #2a1600; font-weight: 800; font-size: 14px; white-space: nowrap; border: 0; }
#roleBtn.on { background: #ff3fa8; color: #fff; }
/* Màn hẹp: nút bình luận chỉ còn biểu tượng để đủ chỗ cho nút nghề */
@media (max-width: 440px) { #commentBtn { font-size: 0; flex: none; width: 46px; } #commentBtn::before { content: '💬'; font-size: 19px; } #playerBar { justify-content: center; } }
#roleMenu { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(66px + env(safe-area-inset-bottom)); width: min(94%, 460px); max-height: 52dvh; overflow: auto; z-index: 30; background: rgba(14, 8, 32, .94); border: 1px solid rgba(255, 255, 255, .14); border-radius: 14px; padding: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .55); }
#roleMenu h3 { margin: 0 0 6px; font-size: 14px; }
#roleMenu p { margin: 4px 0 8px; font-size: 12px; color: #c9bfe0; }
.who { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.who:first-of-type { border-top: 0; }
.who .nm { flex: 1; min-width: 0; font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who button { background: rgba(255, 255, 255, .1); border-radius: 9px; padding: 6px 8px; font-size: 12px; font-weight: 700; }
.who button.gold { background: linear-gradient(180deg, #ffe27a, #e9a91c); color: #2a1600; }
.who button:disabled { opacity: .4; }
.musicForm { display: flex; gap: 6px; margin-top: 6px; }
.musicForm input { flex: 1; min-width: 0; }
.wide { width: 100%; margin-top: 6px; }
#inviteCard { position: absolute; left: 50%; transform: translateX(-50%); top: 38%; z-index: 45; width: min(90%, 360px); background: rgba(20, 10, 40, .96); border: 2px solid #ffd23f; border-radius: 16px; padding: 14px; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .6); }
#inviteCard p { margin: 0 0 10px; font-weight: 700; }
#inviteCard .row { display: flex; gap: 8px; justify-content: center; }
