* { 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; }

/* Khung dọc 9:16, luôn nằm giữa màn hình */
#stage {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(100vw, calc(100dvh * 9 / 16)); aspect-ratio: 9 / 16; overflow: hidden; background: #07041a;
}
#game { width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

#menuBtn {
  position: absolute; top: 1.2%; right: 2%; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255, 255, 255, .12); font-size: 17px; opacity: .55;
}
#menuBtn:hover, #menuBtn:focus-visible { opacity: 1; }

#panel {
  position: absolute; top: 7%; right: 2%; width: min(88%, 310px); max-height: 86%; 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;
}
#panel[hidden] { display: none; }
#panel h3 { margin: 12px 0 6px; font-size: 12px; color: #ffd23f; }
#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); }
.grid button.on { background: #ff3fa8; }
.field { display: block; margin-top: 10px; }
.field input { display: block; width: 100%; margin-top: 4px; }

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; }

#setup {
  position: absolute; inset: 0; display: flex; padding: 5%;
  background: radial-gradient(circle at 50% 30%, rgba(52, 18, 92, .93), rgba(5, 3, 18, .97)); z-index: 6; overflow: auto;
}
#setup[hidden], #tapAudio[hidden] { display: none; }
.card { width: 100%; max-width: 430px; margin: auto; }
.wordmark { display: block; width: min(72%, 300px); margin: 0 auto 10px; }
.card h1 {
  margin: 0; text-align: center; font-size: clamp(38px, 11vw, 60px); font-style: italic; font-weight: 900;
  background: linear-gradient(90deg, #ffd23f, #ff3fa8, #6c7bff); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tag { text-align: center; margin: 4px 0 14px; color: #e5ddff; }
.card ul { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 7px; font-size: 14px; }
.card li { background: rgba(255, 255, 255, .07); padding: 8px 10px; border-radius: 10px; }
.card label { font-weight: 700; font-size: 14px; display: block; margin-bottom: 6px; }
.at { font-weight: 800; font-size: 18px; }
.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); }
.muted { color: #bdb4dc; }
.small { font-size: 12px; text-align: center; margin: 12px 0 0; }
.error { color: #ff8b8b; font-size: 13px; margin: 8px 0 0; }

/* Đăng ký, đăng nhập */
.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 { display: block; margin-bottom: 10px; }
#authForm input { display: block; margin-top: 4px; font-weight: 400; font-size: 16px; }

/* Chọn nhân vật */
#pickGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 46dvh; overflow: auto; padding: 2px; }
#pickGrid button { position: relative; background: rgba(255, 255, 255, .08); border: 2px solid transparent; border-radius: 10px; padding: 4px 2px; font-size: 11px; line-height: 1.2; }
#pickGrid button.on { border-color: #ffd23f; background: rgba(255, 210, 63, .18); }
#pickGrid canvas { display: block; width: 100%; height: auto; }
#pickGrid b { position: absolute; top: 3px; left: 6px; color: #ffd23f; }
#welcomeAvatar { display: block; width: 120px; height: 120px; margin: 0 auto 4px; }

/* Thanh thao tác của người chơi */
#playerBar {
  position: absolute; left: 2%; right: 2%; bottom: 1%; display: flex; align-items: center; gap: 6px; z-index: 3;
}
#playerBar[hidden], #giftMenu[hidden], #toast[hidden], #chatForm[hidden] { display: none; }
#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: 2%; right: 2%; bottom: 8%; 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:active, #giftBtn:active { transform: scale(.88); }
#giftBtn.on { background: #ff3fa8; }
#giftMenu {
  position: absolute; left: 2%; right: 2%; bottom: 8%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px;
  background: rgba(14, 9, 38, .96); border: 1px solid rgba(255, 255, 255, .2); border-radius: 14px; z-index: 3;
}
#giftMenu button { background: rgba(255, 255, 255, .08); border-radius: 10px; padding: 8px 2px; font-size: 12px; line-height: 1.35; }
#giftMenu button span { display: block; font-size: 24px; }
#giftMenu button b { color: #ffd23f; }
#giftMenu button:disabled { opacity: .35; cursor: default; }
#toast {
  position: absolute; left: 50%; bottom: 16%; transform: translateX(-50%); 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: 4;
}
