:root {
  --blue: #1f6bff; --blue-d: #1645b8; --navy: #0d1f5c; --sky: #4fc3ff; --yellow: #ffd23f; --pink: #ff5fa2;
  --panel: linear-gradient(180deg, rgba(42, 112, 255, .92), rgba(22, 60, 180, .92));
  --panel-b: #9fd2ff; --text: #fff; --muted: #cfe3ff; --danger: #ff4d5e; --ok: #3fdc7a;
  --font: "Nunito", "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
}
* { box-sizing: border-box; touch-action: manipulation; } /* chạm đúp không phóng to (iOS Safari bỏ qua user-scalable=no); các vùng cần kéo tự đặt none / pan-x ở dưới */
html, body { margin: 0; height: 100%; overflow: hidden; background: #0a1440; color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; user-select: none;
  -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; overscroll-behavior: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; touch-action: none; }
#fade { position: fixed; inset: 0; background: #0a1440; pointer-events: none; opacity: 0; transition: opacity .35s; z-index: 50; }
#fade.on { opacity: 1; }
.screen { position: fixed; inset: 0; z-index: 2; display: none; flex-direction: column; padding: 14px; padding-top: max(14px, env(safe-area-inset-top));
  padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); padding-bottom: max(14px, env(safe-area-inset-bottom));
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.screen.active { display: flex; }
#scr-game { overflow: hidden; touch-action: none; }
#hud-players { touch-action: pan-x pan-y; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 8px; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); letter-spacing: .3px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; }
.row.center { justify-content: center; }
button, select, input { font-family: inherit; font-size: 14px; }
button {
  background: linear-gradient(180deg, #ffffff, #d7ecff); color: #123a9c; border: 0; border-radius: 12px; padding: 8px 14px;
  font-weight: 800; cursor: pointer; box-shadow: 0 3px 0 #6f9fe0, 0 4px 10px rgba(0, 0, 0, .25); transition: transform .08s, filter .15s;
}
@media (hover: hover) { button:hover { filter: brightness(1.07); transform: translateY(-1px); } }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #6f9fe0; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.primary { background: linear-gradient(180deg, #ffe169, #ffb21f); color: #6b3400; box-shadow: 0 3px 0 #c9790a, 0 4px 12px rgba(0, 0, 0, .3); }
button.danger { background: linear-gradient(180deg, #ff8090, #e8364c); color: #fff; box-shadow: 0 3px 0 #a3192b; }
button.big { font-size: 17px; padding: 12px 18px; border-radius: 16px; }
button.on { background: linear-gradient(180deg, #8bff9f, #2fc95b); color: #064d1b; box-shadow: 0 3px 0 #1b8a3a; }
select, input:not([type]), input[type=text], input[type=password] {
  background: #fff; color: #0d2a7a; border: 2px solid #9fd2ff; border-radius: 10px; padding: 6px 9px; font-weight: 700; outline: none; min-width: 0;
}
input:focus-visible, select:focus-visible { border-color: var(--yellow); }
input:disabled { opacity: .7; cursor: not-allowed; }
/* tài khoản */
.account { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.account #acc-status { flex: 1 1 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button { flex: 1; }
#auth-form .row button { flex: 1; }
.auth-err { color: #fff; background: rgba(232, 54, 76, .55); border: 1px solid #ff8090; padding: 6px 10px; border-radius: 10px; font-weight: 700; }
input[type=range] { accent-color: var(--yellow); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--yellow); vertical-align: middle; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: 13px; margin: 6px 0; }
.field:has(input[type=checkbox]) { flex-direction: row; align-items: center; gap: 8px; }
.panel {
  background: var(--panel); border: 3px solid var(--panel-b); border-radius: 20px; padding: 14px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), 0 10px 30px rgba(0, 0, 40, .45); backdrop-filter: blur(4px);
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head h3 { margin: 0; }
.pill { background: rgba(0, 20, 80, .55); border: 2px solid rgba(160, 210, 255, .6); padding: 4px 12px; border-radius: 99px; font-weight: 800; font-size: 13px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.topbar h2 { margin: 0; }

/* ---------- logo / màn hình chính ---------- */
.logo { text-align: center; font-weight: 900; font-size: clamp(46px, 8vw, 92px); line-height: .95; margin: 8px 0 6px; transform: rotate(-3deg); filter: drop-shadow(0 6px 0 #0b2a8a) drop-shadow(0 10px 16px rgba(0, 0, 0, .5)); }
.logo span { display: inline-block; -webkit-text-stroke: 6px #0d2f9e; paint-order: stroke fill; margin: 0 6px; animation: bob 2.4s ease-in-out infinite; }
.logo .l1 { color: #5fd0ff; }
.logo .l2 { color: #ffe14d; animation-delay: .25s; }
.logo .l3 { color: #ff6fae; font-size: .7em; animation-delay: .5s; }
@keyframes bob { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-8px) } }
.title-wrap { flex: 1; display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; padding-bottom: 8px; flex-wrap: wrap; }
.profile { width: 330px; max-width: 100%; }
.char-pick { display: flex; align-items: center; gap: 8px; }
.char-pick .arrow { padding: 18px 10px; }
.char-card { flex: 1; text-align: center; }
.char-card img { width: 140px; height: 140px; display: block; margin: 0 auto; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .35)); }
#char-name { font-weight: 900; font-size: 22px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 12px; text-align: left; margin-top: 6px; }
.bar { height: 8px; border-radius: 6px; background: rgba(0, 0, 0, .3); overflow: hidden; align-self: center; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffe14d, #ff9f1a); }
.colors { display: flex; gap: 6px; justify-content: center; margin: 10px 0 4px; }
.colors span { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff; cursor: pointer; box-shadow: 0 2px 4px rgba(0, 0, 0, .4); }
.colors span.sel { outline: 3px solid var(--yellow); transform: scale(1.15); }
.menu { display: flex; flex-direction: column; gap: 10px; width: 340px; max-width: 100%; }
.menu .row button { flex: 1; }
.foot { text-align: center; }

/* ---------- sảnh ---------- */
.browser-wrap, .room-wrap, .board-wrap { flex: 1; display: flex; gap: 14px; min-height: 0; flex-wrap: wrap; }
.rooms { flex: 2; min-width: 300px; display: flex; flex-direction: column; }
#room-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; min-height: 120px; }
.room-item { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, .14); border-radius: 14px; padding: 10px 12px; cursor: pointer; border: 2px solid transparent; }
@media (hover: hover) { .room-item:hover { border-color: var(--yellow); } }
.room-item:active { border-color: var(--yellow); }
.room-item b { font-size: 16px; }
.join-info { flex: 1; min-width: 260px; text-align: center; }
#qr svg { width: 190px; height: 190px; background: #fff; border-radius: 14px; padding: 6px; }
#lan-urls div { font-weight: 900; font-size: 18px; background: rgba(0, 0, 0, .25); border-radius: 10px; padding: 6px; margin: 6px 0; user-select: text; }
.empty { text-align: center; padding: 30px; color: var(--muted); }

/* ---------- phòng ---------- */
.slots-panel { flex: 2; min-width: 320px; overflow: auto; }
.side { flex: 1; min-width: 280px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.slot { background: rgba(255, 255, 255, .13); border-radius: 16px; padding: 8px; text-align: center; position: relative; min-height: 172px; border: 3px solid transparent; }
.slot.me { border-color: var(--yellow); }
.slot.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); border: 3px dashed rgba(255, 255, 255, .25); }
.slot img { width: 92px; height: 92px; }
.slot .nm { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .tag { position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 900; padding: 2px 6px; border-radius: 8px; background: rgba(0, 0, 0, .35); }
.slot .rdy { position: absolute; top: 6px; right: 6px; font-size: 11px; font-weight: 900; padding: 2px 6px; border-radius: 8px; background: var(--ok); color: #053; }
.slot .x { position: absolute; bottom: 6px; right: 6px; padding: 2px 7px; font-size: 12px; border-radius: 8px; }
.slot .team { margin-top: 4px; font-size: 12px; padding: 3px 8px; border-radius: 8px; }
.slot .mini { display: flex; gap: 3px; justify-content: center; margin-top: 4px; flex-wrap: wrap; }
.slot .mini button { padding: 2px 6px; font-size: 11px; border-radius: 7px; }
.settings-panel .row { margin-top: 10px; }
.settings-panel .row button { flex: 1; }
#map-preview canvas { width: 100%; border-radius: 10px; image-rendering: pixelated; border: 2px solid rgba(255, 255, 255, .4); }
.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 140px; }
#chat-log { flex: 1; overflow: auto; font-size: 13px; margin-bottom: 6px; user-select: text; }
#chat-log .sys { color: #ffe9a3; font-style: italic; }
#chat-log b { color: #bfe6ff; }

/* ---------- HUD ---------- */
#scr-game { padding: 0; pointer-events: none; }
#scr-game > * { pointer-events: auto; }
.hud-side {
  position: absolute; right: 10px; top: 10px; bottom: 10px; width: 228px; background: var(--panel); border: 3px solid var(--panel-b); border-radius: 18px;
  padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 30px rgba(0, 0, 40, .45);
}
.hud-map { font-weight: 900; text-align: center; font-size: 14px; background: rgba(0, 0, 0, .25); border-radius: 10px; padding: 4px; }
.hud-timer { display: flex; justify-content: space-between; align-items: center; background: #0b1f66; border-radius: 12px; padding: 6px 10px; border: 2px solid #5aa8ff; }
.hud-timer span { font-size: 12px; font-weight: 900; color: #ffd23f; }
.hud-timer b { font-size: 24px; font-variant-numeric: tabular-nums; }
.hud-timer.hot b { color: #ff5d6c; animation: blink .5s infinite; }
@keyframes blink { 50% { opacity: .45 } }
.hud-score { display: none; text-align: center; font-size: 26px; font-weight: 900; }
.hud-score.show { display: block; }
#hud-players { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 5px; }
.hp { display: flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .15); border-radius: 12px; padding: 4px 6px; border-left: 6px solid #fff; }
.hp img { width: 38px; height: 38px; }
.hp .info { flex: 1; min-width: 0; }
.hp .n { font-weight: 900; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp .s { font-size: 11px; color: var(--muted); }
.hp.trapped { background: rgba(80, 180, 255, .4); animation: blink .6s infinite; }
.hp.dead { opacity: .4; filter: grayscale(1); }
.hp.me { box-shadow: inset 0 0 0 2px var(--yellow); }
.hp .k { font-weight: 900; font-size: 13px; }
.hud-items { background: rgba(0, 0, 0, .22); border-radius: 12px; padding: 6px; }
.hud-items-title { font-weight: 900; font-size: 12px; color: #ffd23f; text-align: center; }
.loc { display: grid; grid-template-columns: 26px 1fr; gap: 4px; align-items: center; margin-top: 4px; }
.loc .who { font-weight: 900; font-size: 12px; background: #fff; color: #1645b8; border-radius: 6px; text-align: center; }
.loc .st { font-size: 12.5px; display: flex; gap: 6px; flex-wrap: wrap; }
.loc .sl { display: flex; gap: 4px; grid-column: 2; }
.loc .sl span { width: 30px; height: 30px; border-radius: 8px; background: rgba(255, 255, 255, .18); display: flex; align-items: center; justify-content: center; font-size: 18px; border: 2px solid rgba(255, 255, 255, .3); }
.loc .ab { grid-column: 2; font-size: 15px; letter-spacing: 2px; min-height: 18px; }
#hud-menu { margin-top: auto; }
#hud-center { position: absolute; left: 0; right: 240px; top: 38%; text-align: center; font-size: clamp(40px, 8vw, 96px); font-weight: 900; pointer-events: none;
  -webkit-text-stroke: 5px #0d2f9e; paint-order: stroke fill; color: #ffe14d; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, .35)); }
#hud-center.pop { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.2); opacity: 0 } to { transform: scale(1); opacity: 1 } }
#hud-banner { position: absolute; left: 0; right: 240px; top: 14px; text-align: center; pointer-events: none; }
#hud-banner span { display: inline-block; background: rgba(10, 30, 110, .75); border: 2px solid #8fc8ff; padding: 6px 16px; border-radius: 99px; font-weight: 900; }
#hud-feed { position: absolute; left: 12px; top: 12px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; max-width: 40vw; }
#hud-feed div { background: rgba(10, 30, 110, .7); border-radius: 10px; padding: 4px 10px; font-size: 13px; font-weight: 800; animation: feed 5s forwards; }
@keyframes feed { 0% { opacity: 0; transform: translateX(-20px) } 8% { opacity: 1; transform: none } 85% { opacity: 1 } 100% { opacity: 0 } }
#spectate { position: absolute; bottom: 16px; left: 50%; transform: translateX(calc(-50% - 120px)); display: none; }
#spectate.show { display: block; }
.touch { display: none; }
body.touch-on .touch { display: block; }
body.touch-on .kbd-hint { display: none; }
.stick { position: absolute; left: 24px; bottom: 24px; width: 150px; height: 150px; border-radius: 50%; background: rgba(255, 255, 255, .15); border: 3px solid rgba(255, 255, 255, .4); touch-action: none; }
.stick .knob { position: absolute; left: 45px; top: 45px; width: 60px; height: 60px; border-radius: 50%; background: rgba(255, 255, 255, .7); }
.t-btn { position: absolute; border-radius: 50%; font-size: 34px; padding: 0; touch-action: none; }
.t-btn.bomb { right: 260px; bottom: 40px; width: 96px; height: 96px; background: radial-gradient(circle at 35% 30%, #9fe0ff, #1f6bff); }
.t-btn.item { right: 370px; bottom: 30px; width: 64px; height: 64px; font-size: 26px; }
.t-btn.emote { right: 260px; bottom: 150px; width: 54px; height: 54px; font-size: 24px; }
.t-btn.item.empty { opacity: .6; }
.t-btn.held { transform: scale(.92); filter: brightness(.9); }
.touch-hint { display: none; }
body.touch-on .touch-hint { display: revert; }
body.touch-on .mouse-hint { display: none; }
.t-btn.item[data-next]::after { content: attr(data-next); position: absolute; right: -4px; top: -4px; width: 26px; height: 26px; line-height: 26px; font-size: 15px; border-radius: 50%;
  background: #fff; border: 2px solid var(--yellow); box-shadow: 0 2px 4px rgba(0, 0, 0, .4); }
.t-btn { -webkit-touch-callout: none; }
.emote-wheel { position: absolute; left: 50%; top: 50%; transform: translate(calc(-50% - 120px), -50%); display: none; gap: 8px; flex-wrap: wrap; width: 260px; justify-content: center; }
.emote-wheel.show { display: flex; }
.emote-wheel button { font-size: 30px; width: 56px; height: 56px; padding: 0; border-radius: 50%; }
.replay-bar { position: absolute; left: 12px; right: 252px; bottom: 12px; display: flex; gap: 8px; align-items: center; background: var(--panel); border: 3px solid var(--panel-b); border-radius: 16px; padding: 8px; }
.replay-bar input[type=range] { flex: 1; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(5, 10, 40, .55); display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal > .panel { width: 420px; max-width: 100%; max-height: 92vh; max-height: 92dvh; overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 8px; }
.modal h2 { text-align: center; }
.results-panel { width: 760px !important; }
#res-title { text-align: center; font-size: 46px; color: #ffe14d; -webkit-text-stroke: 3px #0d2f9e; paint-order: stroke fill; }
#res-sub { text-align: center; }
#res-table { width: 100%; border-collapse: separate; border-spacing: 0 4px; font-size: 14px; }
#res-table th { font-size: 12px; color: var(--muted); }
#res-table td { background: rgba(255, 255, 255, .13); padding: 4px 6px; text-align: center; }
#res-table td:first-child { border-radius: 10px 0 0 10px; font-weight: 900; font-size: 18px; }
#res-table td:last-child { border-radius: 0 10px 10px 0; }
#res-table tr.win td { background: rgba(255, 210, 63, .35); }
#res-table img { width: 40px; height: 40px; vertical-align: middle; }
#res-table .nm { text-align: left; font-weight: 900; }
#res-ach { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ach { background: rgba(255, 210, 63, .25); border: 2px solid var(--yellow); border-radius: 12px; padding: 6px 10px; font-weight: 800; font-size: 13px; animation: pop .6s; }
.ach.locked { background: rgba(0, 0, 0, .2); border-color: rgba(255, 255, 255, .2); color: var(--muted); filter: grayscale(1); }
.help { width: 820px !important; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.keys { width: 100%; font-size: 13px; border-collapse: collapse; }
.keys td, .keys th { padding: 3px 6px; border-bottom: 1px solid rgba(255, 255, 255, .15); }
.help-items { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 13px; }
.help-items div span { display: inline-block; width: 24px; }

/* ---------- editor / board ---------- */
.editor-wrap { flex: 1; display: flex; gap: 12px; min-height: 0; flex-wrap: wrap; }
.palette { width: 210px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-content: start; overflow: auto; }
.palette button { font-size: 12px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.palette button.sel { outline: 3px solid var(--yellow); }
.palette button i { width: 26px; height: 26px; border-radius: 6px; display: block; }
.ed-canvas-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 300px; }
#ed-canvas { max-width: 100%; max-height: calc(100vh - 160px); max-height: calc(100dvh - 160px); border-radius: 12px; background: #000; cursor: crosshair; touch-action: none; }
.ed-actions { width: 200px; display: flex; flex-direction: column; gap: 8px; }
.board-wrap .panel { flex: 1; min-width: 300px; overflow: auto; }
#bd-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#bd-table td, #bd-table th { padding: 6px; border-bottom: 1px solid rgba(255, 255, 255, .15); text-align: center; }
#bd-table td:nth-child(2) { text-align: left; font-weight: 900; }
#bd-ach { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#bd-ach .ach { animation: none; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: #0d1f5c; border: 2px solid var(--yellow); border-radius: 12px; padding: 8px 16px; font-weight: 800; animation: feed 3.6s forwards; }
#loading { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: #0a1440; font-weight: 900; transition: opacity .4s; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 6px solid #2a5bd8; border-top-color: #ffd23f; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

@media (max-width: 820px) {
  .slots { grid-template-columns: repeat(2, 1fr); }
  .help-grid { grid-template-columns: 1fr; }
}

/* Trong trận có 3 kiểu bố cục (game.js dùng cùng điều kiện TOP_BAR_MQ để biết có chừa chỗ cho thanh bên không):
   1) thanh bên rộng (mặc định, máy tính / máy tính bảng nằm ngang cao);
   2) thanh bên gọn: màn hình thấp (điện thoại nằm ngang, kể cả khi rộng <= 820px);
   3) thanh trên: điện thoại/máy tính bảng đứng, hoặc cửa sổ rất hẹp. Khối 3 phải đứng SAU khối 2 để ghi đè. */
@media (max-height: 520px) and (min-width: 560px) {
  .hud-side { width: 170px; top: 6px; bottom: 6px; right: max(6px, env(safe-area-inset-right)); padding: 6px; gap: 5px; }
  .hud-items, .hud-map { display: none; }
  .hp img { width: 26px; height: 26px; }
  .hud-timer b { font-size: 18px; }
  #hud-center, #hud-banner { right: calc(180px + env(safe-area-inset-right)); }
  .t-btn.bomb { right: calc(190px + env(safe-area-inset-right)); bottom: 20px; width: 84px; height: 84px; }
  .t-btn.item { right: calc(286px + env(safe-area-inset-right)); bottom: 16px; }
  .t-btn.emote { right: calc(190px + env(safe-area-inset-right)); bottom: 116px; }
  .stick { left: max(14px, env(safe-area-inset-left)); bottom: 14px; width: 130px; height: 130px; }
  .stick .knob { left: 35px; top: 35px; }
  .replay-bar { right: calc(190px + env(safe-area-inset-right)); flex-wrap: wrap; }
  .emote-wheel { transform: translate(calc(-50% - 90px), -50%); }
  #spectate { transform: translateX(calc(-50% - 90px)); bottom: auto; top: 10px; }
}
@media (orientation: portrait) and (max-width: 820px), (max-width: 559px) {
  .hud-side { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; bottom: auto; width: auto; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 6px; gap: 6px; }
  .hud-timer { flex: 1 1 auto; order: 1; padding: 3px 10px; }
  .hud-timer b { font-size: 20px; }
  .hud-score { order: 1; }
  #hud-menu { margin: 0; flex: 0 0 auto; order: 2; }
  #hud-players { flex-direction: row; flex: 1 1 100%; order: 3; overflow-x: auto; overflow-y: hidden; }
  .hp { min-width: 104px; padding: 2px 5px; gap: 4px; }
  .hp img { width: 26px; height: 26px; }
  .hp .s { font-size: 10.5px; }
  .hud-items, .hud-map { display: none; }
  #hud-center, #hud-banner { right: 0; }
  #hud-feed { top: 118px; max-width: 70vw; }
  .stick { left: max(24px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom)); }
  .t-btn.bomb { right: max(24px, env(safe-area-inset-right)); bottom: max(40px, calc(16px + env(safe-area-inset-bottom))); width: 96px; height: 96px; }
  .t-btn.item { right: 134px; bottom: max(30px, calc(16px + env(safe-area-inset-bottom))); width: 64px; height: 64px; }
  .t-btn.emote { right: max(24px, env(safe-area-inset-right)); bottom: 150px; }
  .replay-bar { right: 12px; flex-wrap: wrap; }
  .emote-wheel { transform: translate(-50%, -50%); }
  #spectate { transform: translateX(-50%); bottom: auto; top: 140px; }
}

/* ---------- màn hình nhỏ / cảm ứng: các màn hình không phải trận được cuộn dọc ---------- */
@media (max-width: 820px), (max-height: 520px) {
  .screen:not(#scr-game) > * { flex-shrink: 0; }
  .title-wrap, .browser-wrap, .room-wrap, .board-wrap, .editor-wrap { flex: 0 0 auto; }
  .title-wrap { justify-content: center; align-items: center; }
  .profile, .menu { width: 100%; max-width: 420px; }
  .rooms, .slots-panel, .side, .join-info { min-width: 0; flex: 1 1 100%; }
  #room-list { overflow: visible; }
  .board-wrap .panel { min-width: 0; flex: 1 1 100%; }
  .ed-canvas-wrap { min-width: 0; flex: 1 1 100%; }
  .palette { width: 100%; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); overflow: visible; }
  .ed-actions { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .ed-actions > button { flex: 1 1 40%; }
  .topbar input, .topbar select { flex: 1 1 120px; }
  .chat-panel { min-height: 180px; }
  .results-panel { padding: 10px; }
  #res-table { font-size: 12px; }
  #res-table img { width: 28px; height: 28px; }
}
@media (max-height: 520px) {
  .logo { font-size: clamp(34px, 7vw, 56px); margin: 0 0 4px; }
  .char-card img { width: 84px; height: 84px; }
  .stats { display: none; }
  .modal { align-items: flex-start; }
}
@media (pointer: coarse) {
  button, select, input { font-size: 16px; } /* >=16px để iOS không tự phóng to khi chạm vào ô nhập */
  button { min-height: 40px; }
  .field { font-size: 14px; }
  button.big { min-height: 48px; }
  .small { font-size: 13px; }
}
