:root {
  --night: #0b1230;
  --panel: rgba(20, 28, 70, 0.78);
  --panel-solid: #161f4d;
  --line: rgba(160, 220, 255, 0.16);
  --text: #eef4ff;
  --muted: #a7b3d9;
  --ghost: #7dfcff;
  --gold: #ffcf4a;
  --gold-deep: #e09a12;
  --green: #5df59a;
  --danger: #ff4d6d;
  --radius: 16px;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); }
body { -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

#stage, #stage canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, rgba(4, 6, 20, 0.65) 100%); }
#flash { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(circle, rgba(255, 40, 70, 0) 30%, rgba(255, 30, 60, 0.55)); opacity: 0; transition: opacity 0.6s; }
#flash.on { opacity: 1; transition: opacity 0.05s; }

/* ---------- nhãn trong thế giới ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.wl { position: absolute; left: 0; top: 0; will-change: transform; white-space: nowrap; }
.hp { width: 64px; height: 7px; border-radius: 6px; background: rgba(5, 8, 25, 0.75); border: 1px solid rgba(255, 255, 255, 0.25); overflow: hidden; }
.hp i { display: block; height: 100%; width: 100%; background: var(--green); transition: width 0.15s; }
.hp.ghost { width: 92px; height: 8px; }
.hp.ghost i { background: linear-gradient(90deg, #7dfcff, #c8a8ff); }
.ghost-label { text-align: center; }
.gname { font-size: 12px; font-weight: 800; color: #dffbff; text-shadow: 0 0 8px rgba(125, 252, 255, 0.9), 0 1px 2px #000; margin-bottom: 3px; }
.name-label { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: rgba(10, 14, 40, 0.7); border: 1px solid var(--line); }
.name-label:empty { display: none; }
.name-label.me { background: var(--gold); color: #3a2300; border-color: transparent; box-shadow: 0 0 14px rgba(255, 207, 74, 0.6); }
.name-label.dead { background: rgba(120, 10, 30, 0.8); color: #ffd0d8; text-decoration: line-through; }
.floater { position: absolute; left: 0; top: 0; font-weight: 800; font-size: 14px; color: var(--gold); text-shadow: 0 1px 3px #000, 0 0 8px rgba(255, 207, 74, 0.7); }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; right: 0; top: 0; display: none; justify-content: space-between; align-items: flex-start; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 16px 0; pointer-events: none; }
body.playing #hud { display: flex; }
#hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 6px; }
.gold { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 10px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); font-weight: 800; font-size: 20px; }
.gold .ic { width: 24px; height: 24px; }
.gold small { font-size: 12px; font-weight: 600; color: var(--green); }
.alive { font-size: 12px; color: var(--muted); padding-left: 12px; }
.hud-center { position: absolute; left: 50%; transform: translateX(-50%); top: max(12px, env(safe-area-inset-top)); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.phase { padding: 7px 16px; border-radius: 99px; font-weight: 700; font-size: 14px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); }
.phase.calm { color: #dffbff; }
.phase.hunt { color: #ffd6dd; border-color: rgba(255, 77, 109, 0.4); }
#hud-ghost { min-width: 240px; }
#hud-ghost-lvl { font-size: 12px; font-weight: 700; color: #dffbff; text-shadow: 0 0 8px rgba(125, 252, 255, 0.8); margin-bottom: 4px; }
.gbar { height: 10px; border-radius: 99px; background: rgba(5, 8, 25, 0.75); border: 1px solid rgba(125, 252, 255, 0.35); overflow: hidden; }
.gbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7dfcff, #c8a8ff); box-shadow: 0 0 12px #7dfcff; transition: width 0.15s; }
.hud-right { display: flex; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: rgba(125, 252, 255, 0.5); }
body.muted #btn-mute .wave { opacity: 0.15; }

/* ---------- bảng xây dựng ---------- */
#panel { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translate(-50%, 130%); width: min(640px, calc(100% - 24px)); padding: 16px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(16px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); transition: transform 0.28s cubic-bezier(.2, .9, .3, 1.2); }
#panel.open { transform: translate(-50%, 0); }
#panel .close { position: absolute; right: 10px; top: 10px; width: 32px; height: 32px; border-radius: 10px; border: 0; background: rgba(255, 255, 255, 0.06); display: grid; place-items: center; }
#panel .close svg { width: 16px; height: 16px; }
.ph { display: flex; align-items: center; gap: 12px; padding-right: 40px; }
.ph h3 { margin: 0; font-size: 17px; }
.ph p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.pic { width: 48px; height: 48px; flex: none; border-radius: 12px; background: rgba(255, 255, 255, 0.06); display: grid; place-items: center; }
.pic svg { width: 40px; height: 40px; }
.acts { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.act { flex: 1 1 180px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 12px; border: 0; font-weight: 700; background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #2e1a00; box-shadow: 0 4px 0 #8a5a06; }
.act:active { transform: translateY(2px); box-shadow: 0 2px 0 #8a5a06; }
.act.ghost { background: rgba(255, 255, 255, 0.08); color: var(--text); box-shadow: none; }
.act.off { filter: grayscale(0.8) brightness(0.65); cursor: not-allowed; }
.cost { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; }
.cost .ic { width: 16px; height: 16px; }
.maxed { flex: 1; text-align: center; padding: 12px; border-radius: 12px; background: rgba(93, 245, 154, 0.12); color: var(--green); font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.card.off, .cards .off { opacity: 0.5; cursor: not-allowed; }
.cards .card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 12px 8px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); }
.cards .card:not(.off):hover { border-color: var(--gold); background: rgba(255, 207, 74, 0.08); }
.cards strong { font-size: 13px; }
.cards small { font-size: 11px; color: var(--muted); line-height: 1.3; min-height: 28px; }
.cards .cost { color: var(--gold); margin-top: 2px; }

/* ---------- thông báo ---------- */
#toasts { position: fixed; left: 50%; top: 110px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: calc(100% - 32px); }
.toast { padding: 9px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); animation: tin 0.3s ease-out, tout 0.4s ease-in 2.8s forwards; text-align: center; max-width: 520px; }
.toast.ok { border-color: rgba(93, 245, 154, 0.5); color: #c9ffe0; }
.toast.warn { border-color: rgba(255, 207, 74, 0.5); color: #ffe9b0; }
.toast.danger { border-color: rgba(255, 77, 109, 0.7); color: #fff; background: rgba(120, 12, 36, 0.85); }
@keyframes tin { from { opacity: 0; transform: translateY(-10px) scale(0.96); } }
@keyframes tout { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- màn hình phủ ---------- */
.overlay { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px 16px; overflow-y: auto; }
#menu { background: linear-gradient(180deg, rgba(11, 18, 48, 0.2), rgba(11, 18, 48, 0.75)); }
body.playing #menu { display: none; }
.modal { background: rgba(6, 10, 30, 0.6); backdrop-filter: blur(6px); z-index: 5; }
.brand { text-align: center; }
.logo { width: 84px; height: 84px; margin: 0 auto 6px; filter: drop-shadow(0 0 22px rgba(125, 252, 255, 0.7)); animation: float 3.2s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }
.brand h1 { margin: 0; font-size: clamp(48px, 11vw, 92px); font-weight: 900; letter-spacing: 0.02em; line-height: 1; color: #eaffff; text-shadow: 0 0 18px rgba(125, 252, 255, 0.85), 0 0 50px rgba(125, 252, 255, 0.45), 0 4px 0 #1b2a6b; animation: flicker 6s infinite; }
@keyframes flicker { 0%, 92%, 100% { opacity: 1; } 93% { opacity: 0.4; } 94% { opacity: 1; } 96% { opacity: 0.6; } }
.tag { margin: 12px auto 0; max-width: 440px; color: #c8d4f5; font-size: 15px; line-height: 1.5; }
.card { width: min(400px, 100%); padding: 22px; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(18px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); }
.card.wide { width: min(560px, 100%); }
.card.center { text-align: center; }
.card h2 { margin: 0 0 14px; font-size: 24px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); margin-bottom: 16px; }
.tab { border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tab.on { background: rgba(255, 255, 255, 0.1); color: var(--text); }
form label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
form input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(5, 9, 30, 0.6); color: var(--text); outline: none; user-select: text; -webkit-user-select: text; }
form input:focus { border-color: var(--ghost); box-shadow: 0 0 0 3px rgba(125, 252, 255, 0.15); }
.err { min-height: 18px; color: #ff9cb0; font-size: 13px; margin: -4px 0 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); font-weight: 700; }
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn.primary { width: 100%; border: 0; background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #2e1a00; box-shadow: 0 5px 0 #8a5a06, 0 10px 30px rgba(255, 180, 40, 0.3); }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #8a5a06; }
.btn.primary:disabled { filter: grayscale(0.6); }
.btn.big { padding: 16px; font-size: 19px; }
.btn.big svg { width: 20px; height: 20px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
#google-btn { display: flex; justify-content: center; min-height: 44px; }
.me { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(135deg, #7dfcff, #8a55c7); background-size: cover; background-position: center; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #0b1230; flex: none; }
.me-name { font-weight: 800; font-size: 17px; }
.me-stats { color: var(--muted); font-size: 13px; }
.link { margin-left: auto; border: 0; background: none; color: var(--muted); font-size: 13px; text-decoration: underline; }
.steps { padding-left: 20px; margin: 0 0 12px; line-height: 1.55; color: #d6def7; }
.steps li { margin-bottom: 8px; }
.steps b { color: var(--text); }
.keys { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.board-list { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; margin-bottom: 16px; }
.brow { display: grid; grid-template-columns: 34px 36px 1fr auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.brow .rank { font-weight: 900; text-align: center; color: var(--muted); }
.brow:nth-child(1) .rank { color: var(--gold); }
.brow:nth-child(2) .rank { color: #d9e2f2; }
.brow:nth-child(3) .rank { color: #e0a070; }
.brow .avatar { width: 36px; height: 36px; font-size: 14px; }
.brow .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .nm small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.brow .sc { font-weight: 800; color: var(--gold); }
.empty { text-align: center; color: var(--muted); padding: 20px; }
.result-icon { width: 96px; height: 96px; margin: 0 auto 6px; }
.sub { color: var(--muted); margin: -6px 0 16px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats div { padding: 12px 8px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); }
.stats small { display: block; color: var(--muted); font-size: 12px; }
.stats b { font-size: 22px; }
#result .row .btn.primary { width: auto; }
#loading { background: var(--night); z-index: 10; transition: opacity 0.5s; }
#loading p { color: var(--muted); }
#loading.gone { opacity: 0; pointer-events: none; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 3px solid rgba(125, 252, 255, 0.15); border-top-color: var(--ghost); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sảnh: phòng chơi nhóm ---------- */
#menu { justify-content: flex-start; }
#menu > .brand { margin-top: auto; }
#menu > .card:last-child { margin-bottom: auto; }
.back { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 16px; display: inline-flex; align-items: center; gap: 4px; padding: 8px 14px 8px 8px; border-radius: 99px; background: rgba(10, 14, 40, 0.55); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 700; font-size: 14px; }
.back svg { width: 18px; height: 18px; }
.back:hover { background: rgba(255, 255, 255, 0.1); }
#lobby .row:first-of-type { margin-top: 0; }
#lobby .row .btn.big { width: 100%; font-size: 16px; padding: 14px 10px; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
.join input { margin: 0; text-transform: uppercase; letter-spacing: 0.18em; font-weight: 800; text-align: center; }
.join input::placeholder { letter-spacing: normal; font-weight: 500; text-transform: none; }
#lobby-err { margin: 6px 0 0; min-height: 0; }
.rooms-head { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 0 8px; font-weight: 800; font-size: 14px; }
.rooms-head small { color: var(--green); font-weight: 600; font-size: 12px; }
.room-list { display: flex; flex-direction: column; gap: 6px; max-height: 190px; overflow-y: auto; }
.room-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid transparent; text-align: left; width: 100%; color: inherit; }
.room-item:hover:not(:disabled) { border-color: var(--gold); background: rgba(255, 207, 74, 0.08); }
.room-item:disabled { opacity: 0.55; cursor: default; }
.room-item b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item small { color: var(--muted); font-size: 12px; }
.room-item .cnt { font-weight: 800; font-size: 13px; padding: 4px 10px; border-radius: 99px; background: rgba(125, 252, 255, 0.12); color: var(--ghost); }
.room-item .cnt.busy { background: rgba(255, 77, 109, 0.15); color: #ffb3c1; }
.room-list .empty { padding: 12px; font-size: 13px; }

#roomcard { width: min(460px, 100%); }
.room-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.room-name { font-weight: 800; font-size: 18px; }
.room-code { color: var(--muted); font-size: 13px; }
.room-code b { color: var(--gold); letter-spacing: 0.18em; font-size: 16px; }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 11px; flex: none; }
.members { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.member { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); min-width: 0; }
.member .avatar { width: 30px; height: 30px; font-size: 13px; }
.member span { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.member em { font-style: normal; font-size: 11px; font-weight: 800; color: #3a2300; background: var(--gold); padding: 1px 7px; border-radius: 99px; }
.member .kick { border: 0; background: none; color: var(--muted); padding: 0 2px; font-size: 16px; line-height: 1; }
.member .kick:hover { color: var(--danger); }
.member.empty-slot { background: none; border: 1px dashed var(--line); color: var(--muted); font-size: 12px; justify-content: center; min-height: 44px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.check input { width: 16px; height: 16px; accent-color: var(--gold); }
.chat { border-radius: 14px; background: rgba(0, 0, 0, 0.22); padding: 8px; margin-bottom: 14px; }
.chat-log { height: 110px; overflow-y: auto; font-size: 13px; line-height: 1.45; padding: 2px 4px 6px; user-select: text; -webkit-user-select: text; }
.chat-log p { margin: 0 0 2px; }
.chat-log b { color: var(--ghost); }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.chat-form input { margin: 0; padding: 9px 12px; }
.wait { text-align: center; color: var(--muted); padding: 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); }
.link.center { display: block; margin: 12px auto 0; }
.name-label.ally { background: rgba(125, 252, 255, 0.22); border-color: rgba(125, 252, 255, 0.6); color: #e6fdff; }
.ingame-chat { position: fixed; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: min(360px, calc(100% - 32px)); z-index: 4; }
.ingame-chat input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--ghost); background: rgba(5, 9, 30, 0.85); color: var(--text); outline: none; }
.toast.chat { border-color: rgba(125, 252, 255, 0.4); font-weight: 600; }
.toast.chat b { color: var(--ghost); }
.webgl-help { max-width: 460px; text-align: center; line-height: 1.6; color: #d6def7; }
.webgl-help b { color: var(--gold); }
.webgl-help code { padding: 1px 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); }
.webgl-help a { color: var(--ghost); }

@media (max-width: 640px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .hud-center { top: 86px; }
  #hud-ghost { min-width: 180px; }
  .gold { font-size: 17px; }
  #toasts { top: 170px; }
  .toast { font-size: 13px; }
  .back { position: static; align-self: flex-start; }
}
/* đang ở phòng chờ: thu gọn tiêu đề cho vừa màn hình */
#menu.compact .tag, #menu.compact .logo { display: none; }
#menu.compact .brand h1 { font-size: clamp(36px, 7vw, 52px); }
#menu.compact { gap: 14px; }
