/* Giao diện tông ấm kiểu game bắn súng hoạt hình: khung gỗ, viền vàng, nền giấy kem */
:root {
  --wood-1: #c4732a;
  --wood-2: #8a4513;
  --wood-3: #5a2a0a;
  --cream: #fff6e2;
  --cream-2: #ffe6b5;
  --gold-1: #fff1a8;
  --gold-2: #ffc93c;
  --gold-3: #e08a00;
  --orange: #ff8a00;
  --ink: #4a2410;
  --ink-2: #8a5a35;
  --blue: #3b82f6;
  --red: #ef4444;
  --green: #31c24d;
  --font: 'Baloo 2', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
button { touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(180deg, #4fb6f7 0%, #a9e0ff 55%, #d9f3ff 100%);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input { font-family: inherit; font-size: inherit; color: inherit; }
[hidden] { display: none !important; }
.hidden { display: none !important; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 .35em; border-radius: 6px; color: var(--ink);
  background: linear-gradient(#fff, #f3dcb0); border: 1px solid #c49a63; border-bottom-width: 3px;
  font: 700 .85em/1.5 var(--font); text-align: center;
}

/* Nền trời có mây + đồi (sảnh, phòng chờ) */
.sky-bg { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.cloud {
  position: absolute; width: 180px; height: 54px; background: #fff; border-radius: 60px; opacity: .9;
  animation: drift 60s linear infinite;
}
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; left: 26px; top: -40px; }
.cloud::after { width: 64px; height: 64px; left: 90px; top: -28px; }
.c1 { top: 12%; left: -200px; }
.c2 { top: 30%; left: -200px; animation-delay: -22s; transform: scale(.7); }
.c3 { top: 6%; left: -200px; animation-delay: -42s; transform: scale(1.2); }
@keyframes drift { to { left: calc(100% + 220px); } }
.hills {
  position: absolute; left: -10%; right: -10%; bottom: -60px; height: 220px;
  background:
    radial-gradient(ellipse 40% 100% at 20% 100%, #5fcf47 60%, transparent 61%),
    radial-gradient(ellipse 45% 90% at 75% 100%, #4cb83a 60%, transparent 61%),
    radial-gradient(ellipse 30% 70% at 50% 100%, #7ddf5c 60%, transparent 61%);
}

/* ─────────── Màn hình ─────────── */
.screen { display: none; position: fixed; inset: 0; }
.screen { height: 100dvh; }
#rotate-hint { display: none; }
#btn-chat { display: none; }
.screen.active { display: flex; }
#screen-lobby { padding: 16px; overflow-y: auto; }
#screen-room { flex-direction: column; overflow-y: auto; }
#screen-game { flex-direction: column; background: #140a28; }

/* Khung gỗ + nền kem */
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--cream), var(--cream-2));
  border: 5px solid var(--wood-2);
  border-radius: 20px;
  box-shadow: inset 0 0 0 2px var(--gold-2), inset 0 4px 12px rgba(255, 255, 255, .7), 0 8px 0 var(--wood-3), 0 14px 30px rgba(60, 25, 0, .35);
  padding: 18px;
}
.ribbon {
  display: inline-block; margin: 0 0 8px; padding: 2px 18px; border-radius: 10px; font-weight: 800; font-size: 16px;
  color: #fff; background: linear-gradient(180deg, #ff9d2e, #e06a00); border: 2px solid var(--wood-3);
  text-shadow: 0 2px 0 var(--wood-3); box-shadow: 0 3px 0 var(--wood-3);
}
.panel > .ribbon:first-child { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); white-space: nowrap; }
.ribbon.small { font-size: 13px; padding: 0 12px; }
h3 { margin: 14px 0 8px; font-size: 17px; color: var(--wood-2); }
.note { margin: -4px 0 8px; color: var(--ink-2); font-size: 13px; }

/* ─────────── Nút ─────────── */
.btn {
  border: 2px solid #0d3f7a; border-radius: 14px; padding: 8px 16px; cursor: pointer; font-weight: 800; color: #fff;
  background: linear-gradient(180deg, #7fd0ff, #2b8ae6 55%, #1c6cc4);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .55), 0 4px 0 #0d3f7a;
  text-shadow: 0 1px 0 #0d3f7a, 0 0 2px #0d3f7a; transition: transform .08s, filter .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08) saturate(1.1); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .55), 0 1px 0 #0d3f7a; }
.btn:disabled { filter: grayscale(.85) brightness(.95); opacity: .7; cursor: not-allowed; }
.btn.primary {
  border-color: #7a3500; background: linear-gradient(180deg, #ffe680, #ffb21a 50%, #ff8a00);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), 0 4px 0 #7a3500; text-shadow: 0 1px 0 #7a3500, 0 0 3px #7a3500;
}
.btn.primary:active:not(:disabled) { box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), 0 1px 0 #7a3500; }
.btn.primary.on {
  border-color: #145c22; background: linear-gradient(180deg, #b8f5a0, #4fd65f 50%, #22a63a);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), 0 4px 0 #145c22; text-shadow: 0 1px 0 #145c22, 0 0 3px #145c22;
}
.btn.ghost {
  color: var(--ink); text-shadow: none; border-color: var(--wood-2);
  background: linear-gradient(180deg, #fffaf0, #f3d9a8); box-shadow: inset 0 2px 0 #fff, 0 3px 0 var(--wood-2);
}
.btn.small { padding: 4px 12px; font-size: 13px; border-radius: 10px; }
.btn.big { font-size: 22px; padding: 10px 24px; letter-spacing: 1px; }

input {
  background: #fffdf6; border: 2px solid #d3a86c; border-radius: 12px; padding: 9px 12px; outline: none; color: var(--ink);
  box-shadow: inset 0 2px 4px rgba(120, 70, 20, .15);
}
input:focus { border-color: var(--orange); }

/* ─────────── Sảnh ─────────── */
.lobby { width: min(800px, 100%); margin: auto; position: relative; z-index: 1; }
.logo {
  margin: 0; text-align: center; font-size: 72px; line-height: .95; font-weight: 800; letter-spacing: 3px;
  color: #ffd84a; -webkit-text-stroke: 3px #7a3500; paint-order: stroke fill;
  text-shadow: 0 5px 0 #7a3500, 0 10px 20px rgba(80, 30, 0, .4);
}
.logo span { display: block; font-size: .45em; color: #fff; -webkit-text-stroke: 2px #1c6cc4; text-shadow: 0 3px 0 #1c6cc4; letter-spacing: 10px; }
.lobby .panel { margin-top: 30px; padding-top: 26px; }
.btn.play { display: block; width: 100%; margin-top: 6px; }
#play-note { margin-top: 8px; }
.wr-sub { justify-self: start; margin: 8px 0 0; }
.tagline { text-align: center; color: var(--ink-2); margin: 0 0 12px; font-weight: 600; }
.field { display: grid; gap: 4px; font-weight: 700; margin-bottom: 12px; }
/* Sảnh: tạo phòng / vào phòng */
#screen-hall { padding: 16px; overflow-y: auto; }
.hall-me {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; margin-bottom: 14px; padding: 6px 12px;
  border-radius: 14px; background: linear-gradient(180deg, #fff6c8, #ffe39a); border: 2px solid #f0b94a;
}
#hall-avatar { width: 64px; height: 80px; object-fit: contain; }
.hall-info b { display: block; font-size: 18px; color: var(--wood-2); }
.hall-info small { color: var(--ink-2); font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#code-input { min-width: 0; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }
h3 small { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 320px; overflow-y: auto; }
.room-list li {
  display: grid; grid-template-columns: 70px 1fr 50px 80px auto; align-items: center; gap: 8px;
  background: #fffdf6; border: 2px solid #ecc993; border-radius: 12px; padding: 5px 10px;
}
.room-list li.empty { display: block; color: var(--ink-2); text-align: center; padding: 12px; }
.room-list .code { font-weight: 800; letter-spacing: 2px; color: var(--orange); }
.room-list .host { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 700; }
.room-list .st { color: var(--green); font-size: 13px; font-weight: 700; }
.room-list .st.playing { color: var(--ink-2); }
.howto { margin-top: 14px; color: var(--ink-2); }
.howto summary { cursor: pointer; font-weight: 800; color: var(--wood-2); }
.howto ul { padding-left: 18px; margin: 8px 0 0; display: grid; gap: 4px; }

/* ─────────── Phòng chờ ─────────── */
.room-header {
  position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; background: linear-gradient(180deg, var(--wood-1), var(--wood-2));
  border-bottom: 4px solid var(--wood-3); box-shadow: inset 0 -2px 0 var(--gold-2), 0 4px 12px rgba(0, 0, 0, .25); color: #fff;
}
.room-title { font-size: 20px; font-weight: 700; text-shadow: 0 2px 0 var(--wood-3); }
.room-title b { color: var(--gold-2); letter-spacing: 3px; font-size: 28px; }
.pill { background: rgba(0, 0, 0, .25); border-radius: 99px; padding: 2px 10px; font-size: 14px; margin-left: 6px; }
.hdr-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.room-body {
  position: relative; z-index: 1; display: grid; grid-template-columns: 1fr 320px; grid-template-areas: 'arena side';
  gap: 26px 18px; padding: 26px 18px 18px; align-items: start;
}
.arena { grid-area: arena; display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.side { grid-area: side; display: grid; gap: 14px; }
.team-side { text-align: center; display: grid; gap: 8px; justify-items: center; }
.side-title {
  font-weight: 800; font-size: 18px; color: #fff; background: var(--c); border-radius: 10px; padding: 0 16px;
  border: 2px solid rgba(0, 0, 0, .35); text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.slots { display: grid; grid-template-columns: repeat(2, minmax(0, 150px)); gap: 10px; justify-content: center; width: 100%; }
.slot {
  position: relative; width: 100%; height: 190px; border-radius: 16px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 85%, rgba(255, 255, 255, .9), transparent 60%), linear-gradient(180deg, #bfe8ff, #fff6e2);
  border: 3px solid var(--c); box-shadow: 0 4px 0 rgba(0, 0, 0, .2);
}
.slot.me { box-shadow: 0 0 0 3px var(--gold-2), 0 4px 0 rgba(0, 0, 0, .2); }
.slot canvas { position: absolute; left: 0; top: 0; width: 150px; height: 150px; }
.slot .pedestal { position: absolute; left: 25px; right: 25px; bottom: 44px; height: 14px; border-radius: 50%; background: radial-gradient(#d39a54, #8a4513); }
.slot .plate {
  position: absolute; left: 6px; right: 6px; bottom: 6px; background: linear-gradient(180deg, var(--wood-1), var(--wood-2));
  border-radius: 10px; color: #fff; padding: 2px 6px; text-shadow: 0 1px 0 var(--wood-3);
}
.slot .plate b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .plate small { display: block; font-size: 11px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .tags { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.slot .x {
  position: absolute; top: 4px; right: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #7a1010;
  background: #ff5a4a; color: #fff; font-weight: 800; cursor: pointer; line-height: 1;
}
.slot.empty {
  display: grid; place-items: center; color: var(--ink-2); font-weight: 800; border-style: dashed; cursor: default;
  background: rgba(255, 255, 255, .5);
}
.slot.empty.can-add { cursor: pointer; }
.slot.empty.can-add:hover { background: rgba(255, 255, 255, .85); }
.tag { font-size: 11px; border-radius: 6px; padding: 0 6px; font-weight: 800; color: #fff; border: 1px solid rgba(0, 0, 0, .25); }
.tag.host { background: var(--orange); }
.tag.bot { background: #7a8699; }
.tag.ready { background: var(--green); }
.tag.wait { background: #b59a7a; }
.vs {
  font-size: 54px; font-weight: 800; color: #ffd84a; -webkit-text-stroke: 3px #7a3500; paint-order: stroke fill;
  text-shadow: 0 4px 0 #7a3500;
}

.grid { display: grid; gap: 10px; margin-bottom: 14px; }
.grid.chars { grid-template-columns: repeat(4, 1fr); }
.grid.weapons { grid-template-columns: repeat(3, 1fr); }
.card {
  display: grid; justify-items: center; gap: 2px; text-align: center; cursor: pointer; color: var(--ink);
  background: linear-gradient(180deg, #fffdf6, #fbe6c0); border: 3px solid #e2b97a; border-radius: 16px; padding: 8px;
  transition: transform .1s, border-color .15s, box-shadow .15s; box-shadow: 0 3px 0 #c49a63;
}
.card:hover { transform: translateY(-3px); border-color: var(--orange); }
.card.selected { border-color: var(--orange); background: linear-gradient(180deg, #fff6c8, #ffd77a); box-shadow: 0 0 0 3px var(--gold-2), 0 0 18px rgba(255, 170, 0, .6); }
.card b { font-size: 16px; color: var(--wood-2); }
.card small { color: var(--ink-2); font-size: 12px; line-height: 1.3; }
.char-card canvas { width: 96px; height: 96px; }
.weapon-card { justify-items: stretch; }
.weapon-card canvas { width: 130px; height: 56px; justify-self: center; }
.stats { display: grid; gap: 1px; margin-top: 4px; font-size: 12px; text-align: left; }
.stats label { display: flex; justify-content: space-between; color: var(--ink-2); }
.stats label span { color: var(--ink); font-weight: 800; }
.meter { height: 7px; background: #ecd3a5; border-radius: 99px; overflow: hidden; margin-bottom: 3px; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--orange), #ffd84a); border-radius: 99px; }

.map-pick { display: grid; gap: 6px; }
.map-preview {
  position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; border: 3px solid var(--wood-2);
  background: linear-gradient(180deg, #8fd3ff, #d9f3ff); display: grid; place-items: center;
}
.map-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.map-preview img[hidden] + span { font-size: 40px; }
.map-preview span {
  position: absolute; left: 6px; bottom: 6px; background: rgba(60, 25, 5, .8); color: #fff; font-weight: 800;
  font-size: 12px; border-radius: 8px; padding: 0 8px;
}
.map-ctrl { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; }
.map-ctrl select {
  min-width: 0; background: #fffdf6; border: 2px solid #d3a86c; border-radius: 10px; padding: 4px 8px;
  font: 700 13px var(--font); color: var(--ink);
}
/* Tủ đồ */
.wardrobe { display: grid; grid-template-columns: 220px 1fr; gap: 14px; margin-bottom: 14px; align-items: start; }
.wr-preview {
  display: grid; gap: 8px; justify-items: center; padding: 8px; border-radius: 16px; border: 3px solid #e2b97a;
  background: radial-gradient(ellipse at 50% 88%, rgba(255, 255, 255, .95), transparent 55%), linear-gradient(180deg, #bfe8ff, #fff6e2);
}
.wr-preview img { width: 200px; height: 250px; object-fit: contain; }
.wr-slots { display: grid; gap: 6px; }
.wr-row { display: grid; grid-template-columns: 70px auto 1fr auto auto; gap: 6px; align-items: center; }
.wr-row:first-child { grid-template-columns: 70px 1fr; }
.wr-label { font-weight: 800; color: var(--wood-2); }
.wr-sex { display: flex; gap: 6px; }
.wr-sex .on { background: linear-gradient(180deg, #ffe680, #ffb21a 50%, #ff8a00); border-color: #7a3500; color: #fff; text-shadow: 0 1px 0 #7a3500; }
.wr-item {
  display: flex; align-items: center; gap: 8px; min-width: 0; height: 44px; padding: 2px 8px; border-radius: 10px;
  background: #fffdf6; border: 2px solid #ecc993;
}
.wr-item img { width: 38px; height: 38px; object-fit: contain; }
.wr-kind {
  grid-column: 1 / -1; margin: 2px 0 0 76px; padding: 6px 10px; border-radius: 10px; font-size: 13px;
  background: linear-gradient(180deg, #fff6c8, #ffe39a); border: 2px solid #f0b94a; color: var(--ink);
}
.wr-kind b { color: var(--wood-2); }
.wr-catalog { min-width: 0; display: grid; grid-template-rows: 1fr auto auto; gap: 8px; }
.wr-tabs { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.wr-tabs .btn.small { padding: 3px 5px; }
.wr-tabs .on { background: linear-gradient(#ffe680, #ffb21a); border-color: #b86a00; }
.wr-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: repeat(3, 1fr); gap: 6px; }
.wr-choice, .wr-equip {
  min-width: 0; cursor: pointer; font-family: inherit; color: var(--ink-2);
  display: grid; justify-items: center; align-content: center; gap: 1px;
  border: 2px solid #d9b77f; border-radius: 10px; background: linear-gradient(#fffdf7, #f3dfb8); padding: 3px;
}
.wr-choice { min-height: 66px; }
.wr-choice img { width: 48px; height: 48px; object-fit: contain; }
.wr-choice small, .wr-equip small { font-size: 10px; line-height: 1.1; }
.wr-choice:hover, .wr-equip:hover { border-color: var(--orange); background: #fff5cd; }
.wr-choice.selected, .wr-equip.selected { border-color: #f0a000; box-shadow: inset 0 0 0 2px #ffe375; background: #fff1b0; }
.wr-choice > span { font-size: 28px; line-height: 48px; }
.wr-equipped { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 100%; }
.wr-equip img { width: 28px; height: 28px; object-fit: contain; }
.wr-equip > span { line-height: 28px; }
.wr-pages { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; }
.wr-preview { grid-template-rows: auto auto auto auto; }
.wr-catalog .wr-kind { margin: 0; }
@media (max-width: 640px) {
  .wr-tabs { grid-template-columns: repeat(3, 1fr); }
  .wr-pages { flex-wrap: wrap; }
}
.wr-item small { font-weight: 700; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot img.show { position: absolute; left: 50%; top: -6px; width: 148px; height: 185px; object-fit: contain; transform: translateX(-50%); }
.slot img.show.flip { transform: translateX(-50%) scaleX(-1); }
@media (max-width: 640px) { .wardrobe { grid-template-columns: 1fr; } }
.actions { display: grid; gap: 10px; }
.hint { margin: 0; color: var(--ink-2); font-size: 13px; text-align: center; font-weight: 600; }
.chat { display: grid; gap: 6px; }
.chat-log {
  height: 230px; overflow-y: auto; background: #fffdf6; border: 2px solid #ecc993; border-radius: 12px; padding: 8px;
  font-size: 14px; display: flex; flex-direction: column; gap: 2px;
}

/* ─────────── Trận đấu ─────────── */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#canvas:active { cursor: grabbing; }

#me-card { position: absolute; top: 8px; left: 8px; display: flex; align-items: center; gap: 4px; pointer-events: none; }
.avatar-ring {
  width: 92px; height: 92px; border-radius: 50%; padding: 5px; flex: none;
  background: conic-gradient(from 200deg, #fff1a8, #ffb21a, #e06a00, #ffb21a, #fff1a8);
  box-shadow: 0 0 0 3px #7a3500, 0 4px 10px rgba(0, 0, 0, .35);
}
.avatar-ring img { width: 100%; height: 100%; border-radius: 50%; display: block; border: 3px solid var(--c, #3b82f6); background: #fff; }
#me-card.dead img { filter: grayscale(1); }
.me-info { display: grid; gap: 3px; margin-left: -14px; padding-left: 18px; }
.plate {
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2)); color: #fff; font-weight: 800; padding: 0 12px 0 16px;
  border-radius: 0 10px 10px 0; border: 2px solid var(--wood-3); text-shadow: 0 1px 0 var(--wood-3); white-space: nowrap;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}
.bar { position: relative; height: 16px; width: 170px; background: #3a1a06; border: 2px solid var(--wood-3); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; transition: width .3s; }
.bar.hp i { background: linear-gradient(180deg, #ff9b8a, #e5322a 60%, #b01d18); }
.bar span { position: absolute; inset: 0; font-size: 11px; font-weight: 800; color: #fff; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000; }

#hud-top {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: flex-start; pointer-events: none;
}
/* ảnh hai đội hai bên + thanh máu */
.team-row { display: flex; gap: 6px; padding-top: 6px; }
.tp { position: relative; width: 50px; }
.tp img {
  width: 50px; height: 50px; display: block; border-radius: 8px; background: #2a3550;
  border: 2px solid #c9d4ea; box-shadow: 0 0 0 1px #1a2236, 0 2px 4px rgba(0, 0, 0, .45);
}
.tp .tp-badge {
  position: absolute; top: -6px; left: -6px; width: 20px; height: 22px;
  background: linear-gradient(180deg, #ffe680, #f0a71c 60%, #b86a00);
  clip-path: polygon(50% 0, 100% 18%, 100% 60%, 50% 100%, 0 60%, 0 18%);
  display: grid; place-items: center; font: 800 10px var(--font); color: #7a2600;
}
.tp .hpb { display: block; height: 6px; margin-top: 3px; border-radius: 3px; background: #4b4f5c; overflow: hidden; border: 1px solid #1a1a22; }
.tp .hpb s { display: block; height: 100%; background: linear-gradient(180deg, #ff7468, #d81f18); }
.tp.cur img { border-color: #ffd23f; box-shadow: 0 0 0 2px #7a3500, 0 0 14px #ffd23f; }
.tp.dead { filter: grayscale(1); opacity: .5; }
/* lực gió */
.wind-box { display: grid; justify-items: center; gap: 1px; min-width: 150px; }
.wind-title { font: 800 15px var(--font); color: #fff; -webkit-text-stroke: 3px #1b2240; paint-order: stroke fill; }
.wind-pill {
  position: relative; width: 132px; height: 30px; border-radius: 99px;
  background: linear-gradient(180deg, #2c3550, #141a2c); border: 2px solid #8794b3;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .4);
}
.wind-shape {
  position: absolute; inset: 3px 6px; transition: transform .25s;
  background: linear-gradient(180deg, #f4f7ff, #b7c3dd);
  clip-path: polygon(0 16%, 68% 16%, 68% 0, 100% 50%, 68% 100%, 68% 84%, 0 84%);
}
.wind-shape.left { transform: scaleX(-1); }
.wind-shape.left + #wind-value { inset: 0 6px 0 34%; }
.wind-shape.calm { opacity: .25; }
#wind-value {
  position: absolute; inset: 0 34% 0 6px; display: grid; place-items: center; transition: inset .25s;
  font: italic 800 17px var(--font); letter-spacing: 1px; color: #1b2240;
}
.wind-prev {
  margin-top: 2px; padding: 0 10px; border-radius: 6px; background: rgba(15, 20, 40, .65);
  font: 700 11px var(--font); color: #ffe14d; white-space: nowrap;
}
.wind-prev i { font-style: normal; color: #7ff0ff; display: inline-block; }
.wind-prev i.left { transform: scaleX(-1); }
.wind-prev b { color: #fff; }
/* đồng hồ to + PASS */
#timer-box {
  position: absolute; top: 102px; left: 50%; transform: translateX(-50%);
  display: grid; justify-items: center; gap: 2px;
}
#turn-timer {
  font: 800 64px/0.95 var(--font); min-height: 60px; pointer-events: none;
  background: linear-gradient(180deg, #fff3a8 10%, #ffbe2e 50%, #f07a00 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 3px #5a2400; paint-order: stroke fill; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .5));
}
#turn-timer.warn { animation: pulse .5s infinite alternate; }
.pass-btn {
  pointer-events: auto; cursor: pointer; min-width: 92px; padding: 3px 18px; border-radius: 8px;
  font: 800 18px var(--font); letter-spacing: 1px; color: #fff; text-shadow: 0 1px 2px #000;
  background: linear-gradient(180deg, #5d6272, #2b2f3a); border: 2px solid #9aa0b0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 6px rgba(0, 0, 0, .45);
}
.pass-btn:hover:not(:disabled) { filter: brightness(1.15); }
.pass-btn:disabled { opacity: .45; cursor: default; }
@keyframes pulse { to { transform: scale(1.12); } }

#minimap-box {
  position: absolute; top: 8px; right: 8px; width: 216px; border-radius: 12px; overflow: hidden;
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2)); border: 3px solid var(--wood-3);
  box-shadow: inset 0 0 0 1px var(--gold-2), 0 4px 10px rgba(0, 0, 0, .35);
}
.frame-title { color: #fff; font-weight: 800; font-size: 12px; padding: 1px 8px; text-shadow: 0 1px 0 var(--wood-3); }
#minimap { display: block; width: 100%; aspect-ratio: 2 / 1; background: rgba(0, 0, 0, .2); cursor: pointer; touch-action: none; border-top: 2px solid var(--wood-3); }

#banner {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) scale(.6); opacity: 0; pointer-events: none;
  font-size: 54px; font-weight: 800; white-space: nowrap; letter-spacing: 2px;
  color: #ffe14d; -webkit-text-stroke: 3px #7a3500; paint-order: stroke fill; text-shadow: 0 5px 0 #7a3500, 0 0 30px rgba(255, 200, 0, .6);
}
#banner.show { animation: banner 1.6s ease-out forwards; }
#banner.pow {
  font-size: 66px; color: #ff6a1a; -webkit-text-stroke: 3px #5a0a00;
  text-shadow: 0 5px 0 #5a0a00, 0 0 24px rgba(255, 90, 0, .9), 0 0 48px rgba(255, 200, 0, .7);
}
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

#toast {
  position: absolute; top: 200px; left: 50%; transform: translate(-50%, -10px); opacity: 0;
  background: rgba(60, 25, 5, .82); color: #fff; border: 2px solid var(--gold-2); border-radius: 12px; padding: 4px 16px;
  font-weight: 700; pointer-events: none; transition: opacity .25s, transform .25s; text-align: center; max-width: 90%;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#game-chat { position: absolute; left: 10px; bottom: 10px; width: min(340px, 60%); display: grid; gap: 4px; }
#game-chat-log { display: grid; gap: 2px; font-size: 14px; color: #fff; }
#game-chat-log div { background: rgba(40, 18, 4, .6); border-radius: 8px; padding: 2px 8px; transition: opacity 1s; }
#game-chat-log div.fade { opacity: 0; }
#game-chat-input { opacity: 0; transition: opacity .2s; padding: 5px 10px; }
#game-chat-input:focus { opacity: 1; }

#touch { display: none; position: absolute; right: 12px; bottom: 12px; gap: 14px; align-items: center; }
.dpad { display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 40px); }
.dpad button, #touch .fire {
  border: 2px solid var(--wood-3); color: #fff; font-weight: 800; touch-action: none; user-select: none; cursor: pointer;
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2)); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35);
}
.dpad button { border-radius: 10px; }
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }
#touch .fire {
  width: 88px; height: 88px; border-radius: 50%; font-size: 22px; border: 4px solid #7a3500;
  background: radial-gradient(circle at 50% 35%, #ffe680, #ff8a00 60%, #d65a00); text-shadow: 0 2px 0 #7a3500;
  box-shadow: 0 0 0 3px var(--gold-2), 0 6px 0 #7a3500;
}
@media (pointer: coarse) { #touch { display: flex; } #game-chat { display: none; } }

#over {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(30, 10, 0, .55); backdrop-filter: blur(2px); padding: 16px;
}
.over-card { width: min(600px, 100%); text-align: center; animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
#over-title { margin: 0; font-size: 56px; font-weight: 800; letter-spacing: 2px; -webkit-text-stroke: 3px #7a3500; paint-order: stroke fill; }
#over-title.win { color: #ffe14d; text-shadow: 0 5px 0 #7a3500; }
#over-title.lose { color: #d8dde6; -webkit-text-stroke-color: #3b4252; text-shadow: 0 5px 0 #3b4252; }
#over-sub { color: var(--ink-2); margin: 0 0 12px; font-weight: 700; }
#over-stats { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 14px; }
#over-stats th { color: var(--ink-2); font-weight: 700; text-align: left; padding: 4px 6px; border-bottom: 2px solid #e2b97a; }
#over-stats td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #f0d6a8; font-weight: 600; }
#over-stats tr.me td { color: var(--orange); }
.mini-av { width: 34px; height: 34px; border-radius: 8px; border: 2px solid; display: block; }
.mvp { background: var(--orange); color: #fff; border-radius: 6px; padding: 0 6px; font-size: 11px; font-weight: 800; }

/* ─────────── Thanh điều khiển dưới (gỗ) ─────────── */
#hud-bottom {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 16px; align-items: center;
  padding: 6px 14px; color: #fff;
  background: repeating-linear-gradient(90deg, rgba(0, 0, 0, .05) 0 3px, transparent 3px 40px), linear-gradient(180deg, #d0843a, var(--wood-2) 60%, var(--wood-3));
  border-top: 4px solid var(--gold-2); box-shadow: 0 -2px 0 var(--wood-3); transition: box-shadow .2s;
}
#hud-bottom.active { box-shadow: 0 -2px 0 var(--wood-3), 0 -8px 24px rgba(255, 200, 0, .45); }
.dial-box { width: 116px; height: 116px; margin: -26px 0 -4px; }
#angle-dial { width: 116px; height: 116px; display: block; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .4)); }
.label { font-size: 13px; font-weight: 800; color: var(--gold-1); text-shadow: 0 1px 0 var(--wood-3); }
.power-head { display: flex; align-items: baseline; gap: 8px; text-shadow: 0 1px 0 var(--wood-3); }
.power-head b { font-size: 18px; }
.power-head .sub { margin-left: auto; font-size: 12px; color: var(--gold-1); }
/* tóm tắt phát bắn theo đạo đã chọn */
#shot-plan { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 800; color: #ffd23f; }
#power-bar {
  position: relative; height: 26px; border-radius: 10px; background: #2b1203; border: 3px solid var(--wood-3);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .6), 0 0 0 1px var(--gold-2);
}
#power-bar::before {
  content: ''; position: absolute; inset: 0; border-radius: 7px; pointer-events: none; z-index: 2;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(255, 255, 255, .35) calc(10% - 2px) 10%);
}
#power-fill {
  display: block; height: 100%; width: 100%; border-radius: 7px; clip-path: inset(0 100% 0 0);
  background: linear-gradient(180deg, rgba(255, 255, 255, .45), transparent 45%), linear-gradient(90deg, #ffe14d, #ff9d00 50%, #ff3b1f);
}
#power-last {
  display: none; position: absolute; top: -8px; bottom: -8px; width: 4px; margin-left: -2px;
  background: #fff35a; box-shadow: 0 0 8px #ffe14d; z-index: 3; border-radius: 2px;
}
#power-last::before {
  content: ''; position: absolute; top: -6px; left: -5px; border: 7px solid transparent; border-top-color: #fff35a; border-bottom: 0;
}
.ruler { position: relative; height: 14px; font-size: 10px; font-weight: 800; color: var(--gold-1); text-shadow: 0 1px 0 var(--wood-3); }
.ruler span { position: absolute; transform: translateX(-50%); }
.bar.stamina { width: 100%; height: 11px; }
.bar.stamina i { background: linear-gradient(180deg, #b5f4ff, #22b8d6); }
.bar.stamina span { font-size: 9px; }
.bar.stamina { height: 13px; }
.item-count {
  position: absolute; left: 3px; bottom: 13px; font-size: 11px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px #000;
}
.item-cost {
  position: absolute; right: 3px; top: 1px; font-size: 10px; font-weight: 800; color: #9ff3ff; text-shadow: 0 1px 2px #000;
}
.item.poor .item-count {
  position: absolute; left: 3px; bottom: 13px; font-size: 11px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px #000;
}
.item-cost { color: #ff8a7a; }

.hud-items { display: flex; gap: 6px; }
.item {
  position: relative; width: 60px; height: 60px; border-radius: 12px; cursor: pointer; padding: 2px; color: #fff;
  background: radial-gradient(circle at 50% 30%, #3866b8, #13295c); border: 3px solid var(--gold-3);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25), 0 3px 0 var(--wood-3); display: grid; place-items: center;
}
.item:hover:not(:disabled) { border-color: #ffe14d; }
.item:disabled { filter: grayscale(.9) brightness(.75); cursor: default; }
.item.used { filter: none; border-color: #ffe14d; background: radial-gradient(circle at 50% 30%, #ffcf4d, #b86a00); box-shadow: 0 0 14px #ffd23f, 0 3px 0 var(--wood-3); }
.item-icon { font-size: 22px; line-height: 1; font-weight: 800; color: #ffe14d; text-shadow: 0 2px 0 #3a1a00; }
.item-key { position: absolute; top: 1px; left: 5px; font-size: 10px; font-weight: 800; color: #fff; }
.item-name { font-size: 9px; line-height: 1; white-space: nowrap; font-weight: 700; }
.item-cd {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: #fff; text-shadow: 0 2px 4px #000; pointer-events: none;
}
.side-btns { display: grid; gap: 6px; }

#notice {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0; z-index: 50; color: #fff;
  background: #b3261e; border: 2px solid #ffb4ab; border-radius: 12px; padding: 8px 16px; font-weight: 700;
  transition: opacity .25s, transform .25s; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
#notice.show { opacity: 1; transform: translate(-50%, 0); }
#conn-status { position: fixed; top: 10px; right: 10px; z-index: 60; background: #1c6cc4; color: #fff; border-radius: 10px; padding: 4px 12px; font-size: 13px; }
#conn-status.bad { background: #b3261e; }

/* ─────────── Màn hình nhỏ ─────────── */
@media (max-width: 1100px) {
  .room-body { grid-template-columns: 1fr; grid-template-areas: 'arena' 'side'; }
  .grid.weapons { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  #hud-bottom { grid-template-columns: auto 1fr; gap: 8px 12px; }
  .hud-items { grid-column: 1 / -1; justify-content: center; }
  .side-btns { grid-column: 1 / -1; grid-auto-flow: column; justify-content: center; }
  .item { width: 52px; height: 52px; }
  #minimap-box { width: 150px; }
  .tp, .tp img { width: 38px; } .tp img { height: 38px; }
  .wind-box { min-width: 120px; } .wind-pill { width: 110px; }
}
@media (max-width: 640px) {
  .logo { font-size: 52px; }
  .row { grid-template-columns: 1fr; }
  .room-list li { grid-template-columns: 60px 1fr 44px auto; }
  .room-list .st { display: none; }
  .grid.chars { grid-template-columns: repeat(2, 1fr); }
  .grid.weapons { grid-template-columns: 1fr; }
  .arena { grid-template-columns: 1fr; }
  .vs { font-size: 36px; text-align: center; }
  .room-header { flex-wrap: wrap; padding: 10px 16px; }
  .room-body { padding: 26px 16px 16px; }
  .avatar-ring { width: 64px; height: 64px; }
  .bar { width: 110px; }
  #hud-top { top: 80px; }
  #timer-box { top: 172px; }
  #toast { top: 262px; }
  #banner { font-size: 38px; }
  #minimap-box { width: 120px; }
  .dial-box, #angle-dial { width: 92px; height: 92px; }
}

/* Máy tính ngang: phòng chờ vừa cửa sổ, chỉ phần tin nhắn cuộn. */
@media (min-width: 900px) and (min-height: 500px) and (orientation: landscape) {
  /* Tạo nhân vật: tên ở đầu, tủ đồ hai cột, nút tiếp tục luôn hiện. */
  #screen-lobby { padding: 10px 18px 16px; overflow: hidden; }
  #screen-lobby > .lobby { width: min(1000px, 100%); margin: auto; max-height: 100%; }
  #screen-lobby .logo { font-size: 36px; line-height: 1; letter-spacing: 2px; }
  #screen-lobby .logo span { display: inline; font-size: 22px; margin-left: 12px; letter-spacing: 5px; }
  #screen-lobby .creator { margin-top: 18px; padding: 16px 16px 10px; }
  #screen-lobby .creator > .ribbon { font-size: 14px; padding: 0 14px; top: -14px; }
  #screen-lobby .tagline { font-size: 12px; margin: 0 0 6px; }
  #screen-lobby .field { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px; margin-bottom: 5px; }
  #screen-lobby .field input { min-width: 0; padding: 4px 10px; }
  #screen-lobby #char-note { font-size: 11px; margin: 0 0 6px; }
  #screen-lobby .wardrobe { grid-template-columns: 210px minmax(0, 1fr); gap: 14px; margin-bottom: 6px; }
  #screen-lobby .wr-preview { height: 100%; grid-template-rows: minmax(0, 1fr) auto; padding: 6px; gap: 4px; }
  #screen-lobby .wr-preview img { width: 190px; height: 230px; max-height: 100%; }
  #screen-lobby .wr-slots { gap: 4px; }
  #screen-lobby .wr-row { grid-template-columns: 60px auto minmax(0, 1fr) auto auto; gap: 5px; }
  #screen-lobby .wr-row:first-child { grid-template-columns: 60px 1fr; }
  #screen-lobby .wr-label { font-size: 13px; }
  #screen-lobby .wr-sub { display: none; }
  #screen-lobby .wr-item { height: 32px; padding: 0 6px; }
  #screen-lobby .wr-item img { width: 28px; height: 28px; }
  #screen-lobby .wr-slots .btn.small { padding: 1px 10px; }
  #screen-lobby .wr-kind { margin: 1px 0 0; padding: 4px 8px; font-size: 12px; line-height: 1.3; }
  #screen-lobby .btn.play { margin: 0; padding: 4px 16px; font-size: 19px; }
  #screen-lobby #play-note { margin: 4px 80px 0 0; text-align: left; font-size: 11px; }
  #screen-lobby .howto { position: absolute; right: 16px; bottom: 8px; margin: 0; font-size: 12px; }
  #screen-lobby .howto[open] {
    z-index: 3; left: 16px; bottom: 8px; padding: 10px 14px;
    background: var(--cream); border: 2px solid var(--wood-2); border-radius: 12px;
    max-height: calc(100% - 24px); overflow-y: auto; box-shadow: 0 4px 20px #5a2a0a55;
  }
  #screen-lobby #classic-pick { max-height: 40vh; overflow-y: auto; }
  #screen-room { overflow: hidden; }
  #screen-room .room-header { flex: 0 0 auto; padding: 6px 14px; gap: 10px; }
  #screen-room .room-header .btn { padding: 4px 12px; font-size: 13px; }
  #screen-room .room-title { display: flex; align-items: center; gap: 6px; font-size: 17px; white-space: nowrap; }
  #screen-room .room-title b { font-size: 24px; }
  #screen-room .pill { margin: 0; font-size: 12px; }
  #screen-room .hdr-btns { flex-wrap: nowrap; }
  #screen-room .room-body {
    flex: 1; min-height: 0; grid-template-columns: minmax(0, 1fr) clamp(250px, 25vw, 320px);
    grid-template-areas: 'arena side'; align-items: stretch; gap: 14px; padding: 14px 14px 18px;
  }
  #screen-room .panel { min-height: 0; min-width: 0; padding: 12px; }
  #screen-room .arena { gap: 10px; }
  #screen-room .team-side { min-height: 0; height: 100%; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; }
  #screen-room .slots {
    min-height: 0; height: 100%; max-height: 440px; align-self: center;
    grid-template-columns: repeat(2, minmax(0, 170px)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 10px;
  }
  #screen-room .slot { height: 100%; min-height: 0; }
  #screen-room .slot img.show { top: 0; width: 100%; height: calc(100% - 32px); }
  #screen-room .slot canvas { left: 50%; transform: translateX(-50%); width: auto; height: calc(100% - 32px); max-width: 100%; object-fit: contain; }
  #screen-room .slot .plate { left: 4px; right: 4px; bottom: 4px; padding: 1px 4px; }
  #screen-room .slot .plate b { font-size: 13px; }
  #screen-room .slot .plate small { font-size: 10px; }
  #screen-room .side-title { font-size: 16px; }
  #screen-room .vs { font-size: 36px; }
  #screen-room .side { grid-template-rows: auto auto minmax(0, 1fr); gap: 10px; }
  #screen-room .map-preview { aspect-ratio: auto; height: clamp(75px, 18vh, 150px); }
  #screen-room .map-preview img[hidden] + span { font-size: 22px; }
  #screen-room .map-preview span { max-width: calc(100% - 12px); }
  #screen-room .actions { gap: 6px; }
  #screen-room .actions .btn.big { font-size: 19px; padding: 6px 12px; }
  #screen-room .hint { font-size: 12px; line-height: 1.3; }
  #screen-room .chat { min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; }
  #screen-room .chat .ribbon { margin: 0; }
  #screen-room .chat-log { height: auto; min-height: 0; overflow-wrap: anywhere; }
  #screen-room .chat input { min-width: 0; padding: 5px 9px; font-size: 13px; }
}

@media (min-width: 900px) and (min-height: 500px) and (max-height: 650px) and (orientation: landscape) {
  #screen-lobby .logo { font-size: 30px; }
  #screen-lobby .creator { margin-top: 15px; padding-top: 12px; }
  #screen-lobby .wr-slots { gap: 3px; }
  #screen-lobby .wr-item { height: 27px; }
  #screen-lobby .wr-item img { width: 23px; height: 23px; }
  #screen-lobby .wr-slots .btn.small { padding: 0 8px; font-size: 12px; }
  #screen-lobby .wr-preview img { height: 195px; }
  #screen-lobby .tagline { margin-bottom: 3px; }
}

/* Phòng thay đồ: 18 món mỗi trang, ô đang mặc nằm dưới nhân vật. */
@media (min-width: 900px) and (min-height: 500px) and (orientation: landscape) {
  #screen-lobby .wardrobe { grid-template-columns: 210px minmax(0, 1fr); }
  #screen-lobby .wr-preview { grid-template-rows: auto minmax(0, 1fr) auto auto; height: auto; }
  #screen-lobby .wr-preview > img { height: 180px; width: 180px; object-fit: contain; justify-self: center; }
  #screen-lobby .wr-equipped img { width: 28px; height: 28px; }
  #screen-lobby .wr-catalog { grid-template-rows: minmax(0, 1fr) auto auto; gap: 6px; }
  #screen-lobby .wr-choice { min-height: 64px; }
  #screen-lobby .wr-choice img { width: 45px; height: 45px; }
  #screen-lobby .wr-tabs .btn.small { padding: 2px 5px; }
  #screen-lobby .wr-pages .btn.small { padding: 2px 7px; font-size: 12px; }
}
@media (min-width: 900px) and (min-height: 500px) and (max-height: 650px) and (orientation: landscape) {
  #screen-lobby .wr-preview > img { height: 130px; }
  #screen-lobby .wr-choice { min-height: 48px; padding: 2px; }
  #screen-lobby .wr-choice img { width: 33px; height: 33px; }
  #screen-lobby .wr-equip img { width: 22px; height: 22px; }
  #screen-lobby .wr-equipped { gap: 3px; }
}

/* Điện thoại: ưu tiên nút dễ chạm và không để nội dung tràn ngang. */
@media (max-width: 899px) {
  #screen-lobby, #screen-hall { padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  #screen-lobby .logo, #screen-hall .logo { font-size: 36px; }
  #screen-lobby .logo span, #screen-hall .logo span { display: inline; font-size: 20px; margin-left: 8px; letter-spacing: 4px; }
  .lobby .panel { padding: 20px 10px 12px; margin-top: 24px; }
  .wardrobe { grid-template-columns: 170px minmax(0, 1fr); gap: 8px; }
  .wr-preview { padding: 5px; gap: 5px; }
  .wr-preview > img { width: 150px; height: 175px; object-fit: contain; }
  .wr-tabs { grid-template-columns: repeat(3, 1fr); }
  .wr-tabs .btn { min-height: 36px; }
  .wr-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .wr-choice { min-height: 55px; }
  .wr-choice img { width: 36px; height: 36px; }
  .wr-pages { flex-wrap: wrap; }
  .wr-pages button { min-height: 36px; }
  .hall-me { grid-template-columns: auto minmax(0, 1fr); gap: 6px; }
  .hall-me .btn { grid-column: 1 / -1; }
  .room-list li { padding: 5px; gap: 4px; grid-template-columns: 56px minmax(0, 1fr) 38px auto; }
  .room-list .st { display: none; }
  .room-list .btn { min-height: 38px; }
  .room-header { flex-wrap: wrap; padding: 8px; gap: 8px; }
  .room-header .btn { padding: 6px 8px; font-size: 12px; }
  .room-title { font-size: 15px; }
  .room-title b { font-size: 21px; }
  .room-title .pill { font-size: 11px; }
  .room-body { grid-template-columns: 1fr; grid-template-areas: 'arena' 'side'; padding: 14px 10px 20px; gap: 16px; }
  .room-body .panel { padding: 10px; }
  .arena { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 6px; }
  .team-side { min-width: 0; gap: 6px; }
  .side-title { font-size: 14px; padding: 0 8px; }
  .slots { gap: 6px; }
  .slot { height: 135px; border-width: 2px; border-radius: 10px; }
  .slot img.show { width: 100%; height: 110px; top: 0; }
  .slot canvas { width: 100%; height: 110px; object-fit: contain; }
  .slot .plate { left: 2px; right: 2px; bottom: 2px; padding: 1px; }
  .slot .plate b { font-size: 11px; }
  .slot .plate small { font-size: 9px; }
  .slot.empty { font-size: 11px; }
  .slot .tags { top: 2px; left: 2px; }
  .slot .tag { font-size: 9px; padding: 0 3px; }
  .slot .x { width: 28px; height: 28px; right: 1px; top: 1px; }
  .team-side > .btn { font-size: 10px; padding: 5px; min-height: 36px; }
  .vs { font-size: 23px; }
  .side { gap: 10px; }
  .map-preview { max-height: 120px; aspect-ratio: auto; height: 120px; }
  .map-preview img[hidden] + span { font-size: 20px; }
  .chat-log { height: 110px; }
}
@media (max-width: 540px) {
  .wardrobe { grid-template-columns: 1fr; }
  .wr-preview { grid-template-columns: 1fr 1fr; align-items: center; }
  .wr-preview > img { grid-column: 1; grid-row: 1 / 4; justify-self: center; }
  .wr-preview .wr-sex, .wr-preview .wr-equipped, .wr-preview > button { grid-column: 2; }
  .wr-preview .wr-sex { justify-content: center; }
  .wr-preview > button { font-size: 11px; padding: 5px; }
  .wr-catalog .wr-kind { font-size: 12px; }
}

/* Trận trên thiết bị cảm ứng: xoay ngang trước khi thao tác. */
@media (pointer: coarse) {
  #screen-game { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  #btn-chat { display: block; }
  #game-chat.open { display: grid; z-index: 8; left: 160px; bottom: 8px; max-height: 65%; padding: 6px; background: #251607e8; border-radius: 10px; }
  #game-chat.open #game-chat-input { opacity: 1; min-width: 0; }
  #game-chat-log { max-height: 100px; overflow-y: auto; }
  #touch { left: 12px; right: 14px; justify-content: space-between; pointer-events: none; }
  #touch button { pointer-events: auto; }
}
@media (pointer: coarse) and (orientation: portrait) and (max-width: 999px) {
  #rotate-hint { position: absolute; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; text-align: center; color: #fff5d5; background: #2a1609f5; }
  #rotate-hint b { font-size: 24px; }
  .rotate-icon { font-size: 72px; color: var(--gold-2); }
}
@media (max-height: 500px) and (orientation: landscape) {
  #screen-game #hud-bottom { grid-template-columns: 66px minmax(110px, 1fr) auto auto; gap: 8px; padding: 3px 8px; min-height: 74px; }
  #screen-game .dial-box, #screen-game #angle-dial { width: 66px; height: 66px; margin: 0; }
  #screen-game .hud-items { grid-column: auto; gap: 4px; }
  #screen-game .item { width: 42px; height: 48px; }
  #screen-game .item-name { font-size: 8px; }
  #screen-game .side-btns { grid-column: auto; grid-auto-flow: row; gap: 3px; }
  #screen-game .side-btns .btn { padding: 2px 6px; font-size: 10px; min-height: 26px; }
  #screen-game .power-head { gap: 4px; }
  #screen-game .power-head .sub { font-size: 9px; }
  #screen-game #shot-plan { display: none; }
  #screen-game #power-bar { height: 19px; }
  #screen-game .ruler { height: 12px; }
  #screen-game #hud-top { top: 4px; gap: 8px; }
  #screen-game .team-row { gap: 3px; }
  #screen-game .tp, #screen-game .tp img { width: 28px; }
  #screen-game .tp img { height: 28px; }
  #screen-game .tp .tp-badge { width: 14px; height: 15px; font-size: 8px; left: -3px; top: -3px; }
  #screen-game .wind-box { min-width: 90px; }
  #screen-game .wind-title { font-size: 11px; }
  #screen-game .wind-pill { width: 85px; height: 22px; }
  #screen-game #wind-value { font-size: 12px; }
  #screen-game .wind-prev { font-size: 8px; }
  #screen-game #timer-box { top: 66px; }
  #screen-game #turn-timer { font-size: 34px; min-height: 32px; }
  #screen-game .pass-btn { font-size: 12px; padding: 2px 8px; }
  #screen-game #me-card { top: 6px; left: 6px; gap: 4px; }
  #screen-game .avatar-ring { width: 38px; height: 38px; }
  #screen-game .bar { width: 86px; }
  #screen-game #me-name { font-size: 11px; }
  #screen-game #minimap-box { width: 90px; top: 4px; right: 4px; }
  #screen-game .frame-title { font-size: 8px; }
  #screen-game #toast { top: 112px; font-size: 11px; padding: 2px 8px; }
  #screen-game #banner { font-size: 28px; }
  .dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 32px); }
  #touch .fire { width: 66px; height: 66px; font-size: 18px; }
  #over { overflow-y: auto; align-items: flex-start; padding: 8px; }
  .over-card { padding: 10px; }
  #over-title { font-size: 30px; }
  #over-stats { font-size: 11px; margin-bottom: 6px; }
}
@media (max-height: 500px) and (min-width: 600px) and (orientation: landscape) {
  #screen-lobby .wardrobe { grid-template-columns: 160px minmax(0, 1fr); }
  #screen-lobby .wr-preview { display: grid; grid-template-columns: 1fr; }
  #screen-lobby .wr-preview > img { width: 110px; height: 100px; justify-self: center; }
  #screen-lobby .wr-grid { gap: 3px; }
  #screen-lobby .wr-choice { min-height: 40px; }
  #screen-lobby .wr-choice img { width: 28px; height: 28px; }
  #screen-lobby .wr-equipped img { width: 20px; height: 20px; }
  #screen-lobby .wr-catalog { gap: 4px; }
  #screen-lobby .wr-tabs { grid-template-columns: repeat(6, 1fr); }
  #screen-lobby .tagline { display: none; }
  #screen-room .room-body { grid-template-columns: minmax(0, 1fr) 230px; grid-template-areas: 'arena side'; }
}

/* Map kín màn hình, HUD nổi trong suốt; chỗ trống vẫn kéo camera được. */
#screen-game #hud-bottom {
  position: absolute; z-index: 10;
  left: env(safe-area-inset-left); right: env(safe-area-inset-right); bottom: env(safe-area-inset-bottom);
  background: linear-gradient(180deg, rgba(12, 18, 27, 0), rgba(12, 18, 27, .55) 28%, rgba(12, 18, 27, .8));
  border-top: 0; box-shadow: none; pointer-events: none;
}
#screen-game #hud-bottom.active { box-shadow: none; }
#screen-game #hud-bottom button { pointer-events: auto; }
#screen-game #hud-bottom .power-box { min-width: 0; }
#screen-game #game-chat { bottom: calc(var(--hud-height, 110px) + 12px); }
#screen-game #touch { bottom: calc(var(--hud-height, 110px) + 12px); }
#screen-game #over { z-index: 20; }
@media (pointer: coarse) {
  #screen-game #game-chat.open { bottom: calc(var(--hud-height, 110px) + 8px); }
}

/* Tên và nút đi tiếp cùng hàng, dành thêm một hàng cho tủ đồ. */
.creator-entry { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
#screen-lobby .creator-entry .field { display: flex; align-items: center; gap: 10px; margin: 0; min-width: 0; }
#screen-lobby .creator-entry input { width: 240px; min-width: 0; }
#screen-lobby .creator-entry .btn.play { width: auto; margin: 0; flex: 0 0 auto; font-size: 17px; padding: 5px 20px; }
.wr-grid { grid-template-rows: repeat(4, 1fr); }
@media (max-width: 540px) {
  .creator-entry { gap: 8px; }
  #screen-lobby .creator-entry .field { flex: 1; display: grid; gap: 2px; font-size: 12px; }
  #screen-lobby .creator-entry input { width: 100%; }
  #screen-lobby .creator-entry .btn.play { font-size: 13px; padding: 7px 10px; align-self: end; margin-bottom: 3px; }
}

/* Tủ trang bị nâu đồng: nhân vật giữa sáu ô đồ, túi bên phải. */
#screen-lobby .creator {
  background: linear-gradient(135deg, #79512c, #392718 70%); border-color: #3c2513;
  box-shadow: inset 0 0 0 2px #f5d68b, inset 0 0 0 6px #a57b40, 0 7px 0 #25170b, 0 12px 26px #28170766;
  padding: 14px 16px 16px; color: #ffe7b3;
}
#screen-lobby .creator > .ribbon {
  top: -6px; left: 12px; right: 12px; transform: none; text-align: center; padding: 2px 12px;
  border-radius: 8px; font-size: 20px; background: linear-gradient(#e8be70, #a56828 48%, #714113 52%, #b87b34);
  border: 2px solid #39200e; box-shadow: inset 0 0 0 2px #f9d58a, 0 3px 0 #2b180a;
}
#screen-lobby .creator-entry { margin: 6px 0 10px; }
#screen-lobby .creator-entry input { background: #f9ebc9; border-color: #a8793c; }
#screen-lobby .wardrobe { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin: 0; }
#screen-lobby .wr-preview {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  min-height: 380px; padding: 10px; border: 3px solid #b98b4d; border-radius: 9px;
  background: radial-gradient(ellipse at 50% 55%, #fff1c8 0%, #dbc397 48%, #ae8656 100%);
  box-shadow: inset 0 0 0 2px #ffe3a2, 0 0 0 2px #2c1c0e;
}
#screen-lobby .wr-preview > img {
  position: absolute; left: 50%; top: 44px; transform: translateX(-50%); width: calc(100% - 135px);
  height: calc(100% - 94px); max-height: none; object-fit: contain; pointer-events: none;
}
#screen-lobby .wr-preview .wr-sex { position: relative; z-index: 1; }
#screen-lobby .wr-preview > button { z-index: 1; margin-top: auto; }
#screen-lobby .wr-equipped {
  position: absolute; inset: 55px 10px 52px; display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px;
  grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 8px; width: auto; pointer-events: none;
}
#screen-lobby .wr-equip { pointer-events: auto; grid-column: 1; }
#screen-lobby .wr-equip:nth-child(1), #screen-lobby .wr-equip:nth-child(4) { grid-row: 1; }
#screen-lobby .wr-equip:nth-child(2), #screen-lobby .wr-equip:nth-child(5) { grid-row: 2; }
#screen-lobby .wr-equip:nth-child(3), #screen-lobby .wr-equip:nth-child(6) { grid-row: 3; }
#screen-lobby .wr-equip:nth-child(n+4) { grid-column: 3; }
#screen-lobby .wr-catalog { min-height: 0; grid-template-rows: minmax(0, 1fr) auto auto; gap: 8px; padding: 10px; border: 3px solid #ad8147; border-radius: 9px; background: #c7a473; box-shadow: inset 0 0 0 2px #f8dca3, 0 0 0 2px #2c1c0e; }
#screen-lobby .wr-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); gap: 7px; }
#screen-lobby .wr-choice, #screen-lobby .wr-equip {
  min-height: 0; padding: 4px; border-radius: 4px; border: 3px solid #ecd5a1; color: #ffe8ae;
  background: radial-gradient(ellipse at center, #7e512b, #352216 80%); box-shadow: 0 0 0 1px #63401e, inset 0 0 0 1px #ac8454;
}
#screen-lobby .wr-choice img { width: 100%; height: 100%; max-width: 68px; max-height: 68px; object-fit: contain; min-height: 0; }
#screen-lobby .wr-equipped img { width: 44px; height: 44px; object-fit: contain; }
#screen-lobby .wr-equip small { font-size: 10px; color: #ffe8ae; }
#screen-lobby .wr-choice.selected, #screen-lobby .wr-equip.selected { border-color: #ffdf54; box-shadow: 0 0 0 1px #8c480d, inset 0 0 8px #ffcf4577, 0 0 9px #ffcd49; background: radial-gradient(#b37a25, #503315); }
#screen-lobby .wr-choice:hover, #screen-lobby .wr-equip:hover { border-color: #ffe36f; }
#screen-lobby .wr-pages { color: #442b13; font-weight: 800; }
#screen-lobby .wr-kind { background: #392719; color: #efd7a7; border-color: #9b723d; margin: 0; font-size: 11px; }
#screen-lobby .wr-kind b { color: #ffdf76; }
@media (min-width: 900px) and (min-height: 500px) and (orientation: landscape) {
  #screen-lobby .creator { padding: 14px 16px 16px; }
  #screen-lobby .wardrobe { height: clamp(300px, calc(100dvh - 190px), 490px); }
  #screen-lobby .wr-preview { min-height: 0; }
}
@media (max-height: 500px) and (min-width: 600px) and (orientation: landscape) {
  #screen-lobby .creator { padding: 10px; }
  #screen-lobby .wardrobe { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: 265px; }
  #screen-lobby .wr-preview { min-height: 0; }
  #screen-lobby .wr-preview > img { width: calc(100% - 112px); height: calc(100% - 75px); top: 36px; }
  #screen-lobby .wr-equipped { grid-template-columns: 48px minmax(0, 1fr) 48px; inset: 42px 6px 42px; gap: 4px; }
  #screen-lobby .wr-equipped img { width: 28px; height: 28px; }
  #screen-lobby .wr-choice img { max-height: 42px; }
  #screen-lobby .wr-grid { gap: 4px; }
}
@media (max-width: 599px) {
  #screen-lobby .wardrobe { grid-template-columns: 1fr; }
  #screen-lobby .wr-preview { min-height: 330px; }
  #screen-lobby .wr-catalog { min-height: 360px; }
}
#screen-lobby .wardrobe { align-items: stretch; }
#screen-lobby .wr-preview { align-self: stretch; height: 100%; }

/* Máy tính: thông tin súng nằm cạnh nút Tiếp tục, phía trên túi đồ. */
@media (min-width: 900px) and (min-height: 500px) and (orientation: landscape) {
  #screen-lobby .creator-entry { min-height: 44px; }
  #screen-lobby .creator-entry input { width: clamp(180px, calc(100vw - 844px), 240px); }
  #screen-lobby .wr-kind {
    position: absolute; top: 18px; left: 52%; right: 16px;
    padding: 5px 8px; line-height: 1.3;
  }
  #screen-lobby .wr-catalog { grid-template-rows: minmax(0, 1fr) auto; }
}

/* Đồng bộ các màn theo khung đồng của tủ trang bị. */
:root {
  --bronze-panel: linear-gradient(135deg, #79512c, #392718 70%);
  --bronze-shadow: inset 0 0 0 2px #f5d68b, inset 0 0 0 6px #a57b40, 0 7px 0 #25170b, 0 12px 26px #28170766;
  --bronze-inset: inset 0 0 0 2px #ffe3a2, 0 0 0 2px #2c1c0e;
}
#screen-hall .logo { font-size: 36px; line-height: 1; letter-spacing: 2px; }
#screen-hall .logo span { display: inline; font-size: 22px; margin-left: 12px; letter-spacing: 5px; }
#screen-hall .lobby { width: min(1000px, 100%); }
#screen-hall .hall, #screen-room .panel {
  background: var(--bronze-panel); color: #ffe7b3; border-color: #3c2513; border-radius: 16px;
  box-shadow: var(--bronze-shadow);
}
#screen-hall .hall { padding: 20px; margin-top: 20px; }
#screen-hall .hall > .ribbon { position: static; transform: none; display: block; text-align: center; margin: 0 0 14px; }
#screen-hall .ribbon, #screen-room .ribbon, #screen-game .frame-title {
  background: linear-gradient(#e8be70, #a56828 48%, #714113 52%, #b87b34);
  color: #fff0c8; border-color: #39200e; text-shadow: 0 2px 1px #39200e;
  box-shadow: inset 0 0 0 1px #f9d58a; border-radius: 6px;
}
#screen-hall .hall-me {
  background: radial-gradient(ellipse at 35% 30%, #dbc397, #ae8656); border: 3px solid #b98b4d;
  box-shadow: var(--bronze-inset); color: #392719; border-radius: 8px;
}
#screen-hall .hall-info b { color: #392719; }
#screen-hall .hall-info small { color: #593a1d; }
#screen-hall h3, #screen-hall h3 small { color: #ffe3a2; }
#screen-hall .room-list { min-height: 90px; padding: 7px; background: #2f2015; border: 2px solid #b98b4d; border-radius: 8px; }
#screen-hall .room-list li { background: linear-gradient(#67472c, #44301f); border-color: #9f7845; color: #ffe7b3; border-radius: 6px; }
#screen-hall .room-list li.empty { color: #dfc79c; display: grid; place-items: center; }
#screen-hall .room-list .code { color: #ffda70; }
#screen-hall .room-list .st { color: #a7ed94; }
#screen-hall .room-list .st.playing { color: #ebc787; }
#screen-hall input, #screen-room input, #screen-room select { background: #f9ebc9; border-color: #a8793c; color: #4a2c12; }
#screen-room .room-header {
  background: linear-gradient(#a5743c, #654121 55%, #392719); border-color: #33200f;
  box-shadow: inset 0 -2px #e5c185, 0 3px 8px #28170766;
}
#screen-room .slot {
  background: radial-gradient(ellipse at 50% 50%, #e7d2ac, #b08a59); border-radius: 6px;
  box-shadow: inset 0 0 0 1px #f8dca3, 0 3px #2c1c0e;
}
#screen-room .slot.empty { background: radial-gradient(#705033, #3d2b1c); color: #dec69b; }
#screen-room .slot.empty.can-add:hover { background: #80603b; color: #fff0be; }
#screen-room .slot.me { box-shadow: 0 0 0 2px #ffda59, inset 0 0 8px #ffda5977; }
#screen-room .slot .plate { background: linear-gradient(#7d552d, #392719); border: 1px solid #c49a60; border-radius: 5px; color: #fff0c8; }
#screen-room .side-title { border-radius: 5px; border-color: #e5c185; }
#screen-room .hint { color: #ebd1a2; }
#screen-room .map-preview { border-color: #c29b61; border-radius: 6px; box-shadow: 0 0 0 1px #2c1c0e; }
#screen-room .chat-log { background: #302116; color: #ffe7b3; border-color: #ac8454; border-radius: 6px; }
#screen-room .map-preview span { background: #302116d9; color: #ffe7b3; }
#screen-lobby .btn.ghost, #screen-hall .btn.ghost, #screen-room .btn.ghost, #screen-game .btn.ghost {
  background: linear-gradient(#f6dfad, #bf975e); border-color: #69441e; border-radius: 7px;
  box-shadow: inset 0 1px #fff0c7, 0 3px #3b250f; color: #442b13;
}
#screen-lobby .btn.primary, #screen-hall .btn.primary, #screen-room .btn.primary { border-radius: 9px; }
#screen-game #minimap-box { background: var(--bronze-panel); border-color: #ad8147; border-radius: 6px; box-shadow: inset 0 0 0 1px #f8dca3, 0 3px 8px #28170766; }
#screen-game .over-card { background: var(--bronze-panel); border-color: #3c2513; box-shadow: var(--bronze-shadow); color: #ffe7b3; }
#screen-game #over-sub, #screen-game #over-stats th { color: #e2c28f; }
#screen-game .dpad button { background: linear-gradient(#ad7c40, #63401e); border-color: #d8b479; border-radius: 7px; }
@media (max-width: 899px) {
  #screen-hall .hall { padding: 14px; }
  #screen-hall .logo span { font-size: 20px; }
}

/* Sảnh: nhân vật bên trái, phòng và thao tác bên phải. */
#screen-hall .hall { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; }
#screen-hall .hall > .ribbon { grid-column: 1 / -1; margin-bottom: 0; }
#screen-hall .hall-me {
  margin: 0; padding: 14px; display: grid; grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) auto auto; justify-items: center; gap: 12px; text-align: center;
}
#screen-hall #hall-avatar { width: 100%; height: 280px; object-fit: contain; }
#screen-hall .hall-info { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
#screen-hall .hall-info b { font-size: 22px; }
#screen-hall .hall-me .btn { grid-column: auto; }
#screen-hall .hall-rooms { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; }
#screen-hall .hall-rooms h3 { margin: 0; }
#screen-hall .room-list { max-height: none; align-content: start; overflow-y: auto; }
#screen-hall .room-list li { min-height: 48px; }
#screen-hall .room-list li.empty { min-height: 100%; }
#screen-hall .hall-rooms .row { margin: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); }
#screen-hall .join { min-width: 0; }
@media (min-width: 900px) and (min-height: 500px) and (orientation: landscape) {
  #screen-hall .hall { height: clamp(350px, calc(100dvh - 120px), 600px); grid-template-rows: auto minmax(0, 1fr); }
  #screen-hall #hall-avatar { height: 100%; max-height: 360px; min-height: 0; }
}
@media (max-width: 899px) {
  #screen-hall .hall { grid-template-columns: 190px minmax(0, 1fr); gap: 10px; }
  #screen-hall #hall-avatar { height: 210px; }
  #screen-hall .hall-rooms .row { grid-template-columns: 1fr; }
  #screen-hall .room-list { max-height: 320px; }
}
@media (max-width: 599px) {
  #screen-hall .hall { grid-template-columns: 1fr; }
  #screen-hall .hall-me { grid-template-columns: 100px minmax(0, 1fr); grid-template-rows: auto auto; text-align: left; padding: 8px; gap: 8px; }
  #screen-hall #hall-avatar { grid-row: 1 / 3; width: 100px; height: 125px; }
  #screen-hall .hall-info { justify-self: start; }
  #screen-hall .hall-me .btn { grid-column: 2; justify-self: start; }
  #screen-hall .hall-rooms { grid-template-rows: auto minmax(100px, 1fr) auto; }
}

/* Vào phòng qua danh sách, cụm dưới chỉ còn nút tạo phòng. */
#screen-hall .hall-rooms .row { grid-template-columns: 1fr; }

/* Tạo phòng ngay trong sảnh, mật khẩu để trống là phòng mở. */
#screen-hall .hall-rooms .row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
#screen-hall .hall-rooms .row input { min-width: 0; width: 100%; padding: 7px 9px; font-size: 13px; }
#screen-hall .room-list li { grid-template-columns: minmax(0, 1fr) 42px 76px auto; }
#screen-hall .room-list li.empty { display: block; text-align: center; padding: 20px 12px; min-height: 70px; }
#screen-hall .join-password { grid-column: 1 / -1; min-width: 0; width: 100%; padding: 4px 8px; font-size: 12px; }
#screen-room .room-title { min-width: 0; }
#screen-room #room-code { font-size: 20px; letter-spacing: 0; overflow-wrap: anywhere; }
@media (max-width: 899px) {
  #screen-hall .hall-rooms .row { grid-template-columns: 1fr; }
  #screen-hall .room-list li { grid-template-columns: minmax(0, 1fr) 38px auto; }
}

.room-host-name { display: block; margin-top: 4px; font-size: 12px; font-weight: normal; opacity: .8; }

/* Phòng chờ ngang trên điện thoại: chia theo chiều cao thực, không dùng ô 190px. */
#room-chat-toggle { display: none; }
@media (orientation: landscape) and (max-height: 600px), (orientation: landscape) and (pointer: coarse) {
  #screen-room { overflow: hidden; padding: 0; }
  #screen-room .room-header { flex: 0 0 auto; min-height: 40px; padding: 3px 8px; gap: 6px; }
  #screen-room .room-header .btn { font-size: 12px; padding: 3px 8px; min-height: 32px; }
  #screen-room .room-title { min-width: 0; font-size: 14px; }
  #screen-room #room-code { font-size: 17px; }
  #screen-room .hdr-btns { flex-wrap: nowrap; }
  #screen-room .room-body {
    flex: 1; min-height: 0; min-width: 0; width: 100%;
    grid-template-columns: minmax(0, 1fr) clamp(180px, 27vw, 260px);
    grid-template-areas: 'arena side'; align-items: stretch;
    padding: 8px max(8px, env(safe-area-inset-right)) 12px max(8px, env(safe-area-inset-left)); gap: 8px;
  }
  #screen-room .panel { min-width: 0; min-height: 0; padding: 7px; border-width: 3px; border-radius: 12px; }
  #screen-room .arena { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 7px; }
  #screen-room .team-side { height: 100%; min-height: 0; min-width: 0; grid-template-rows: auto minmax(0, 1fr) auto; gap: 4px; }
  #screen-room .side-title { font-size: 13px; padding: 0 8px; }
  #screen-room .vs { font-size: 24px; }
  #screen-room .slots { height: 100%; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 5px; }
  #screen-room .slot { height: 100%; min-height: 0; border-width: 2px; border-radius: 8px; font-size: 11px; }
  #screen-room .slot img.show, #screen-room .slot canvas { top: 0; left: 50%; width: 100%; max-width: 100%; height: calc(100% - 26px); object-fit: contain; transform: translateX(-50%); }
  #screen-room .slot img.show.flip { transform: translateX(-50%) scaleX(-1); }
  #screen-room .slot .plate { bottom: 2px; left: 2px; right: 2px; padding: 0 2px; }
  #screen-room .slot .plate b { font-size: 11px; line-height: 1.2; }
  #screen-room .slot .plate small { font-size: 9px; line-height: 1.2; }
  #screen-room .slot .tags { top: 2px; left: 2px; }
  #screen-room .tag { font-size: 8px; padding: 0 3px; }
  #screen-room .slot .x { width: 24px; height: 24px; top: 2px; right: 2px; }
  #screen-room .team-side > .btn { font-size: 10px; padding: 2px 5px; min-height: 28px; max-width: 100%; }
  #screen-room .side { grid-template-rows: minmax(0, 1fr) auto auto; gap: 6px; }
  #screen-room .map-pick { min-width: 0; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; gap: 4px; }
  #screen-room .map-preview { min-width: 0; min-height: 0; width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }
  #screen-room .map-preview img { min-width: 0; min-height: 0; }
  #screen-room .map-preview span { max-width: calc(100% - 12px); font-size: 11px; }
  #screen-room .map-preview img[hidden] + span { font-size: 16px; }
  #screen-room .map-ctrl { min-width: 0; grid-template-columns: 30px minmax(0, 1fr) 30px; gap: 3px; }
  #screen-room .map-ctrl .btn, #screen-room .map-ctrl select { font-size: 11px; padding: 2px 4px; min-height: 30px; }
  #screen-room .actions { gap: 0; }
  #screen-room .actions .btn.big { font-size: 17px; padding: 4px 8px; min-height: 38px; }
  #screen-room .hint { display: none; }
  #screen-room #room-chat-toggle { display: block; font-size: 12px; padding: 2px 8px; min-height: 30px; }
  #screen-room .chat { display: none; }
  #screen-room.chat-open .chat { display: grid; position: absolute; z-index: 5; right: calc(27vw + 18px); top: 8px; bottom: 12px; width: min(300px, 48vw); padding: 8px; background: #302116f5; border: 2px solid #c49a60; border-radius: 10px; grid-template-rows: auto minmax(0, 1fr) auto; }
  #screen-room .chat-log { min-height: 0; height: auto; overflow-y: auto; overflow-wrap: anywhere; }
  #screen-room .chat input { min-width: 0; width: 100%; font-size: 14px; padding: 4px; }
  #screen-room .chat .ribbon { margin: 0; }
}

/* Sảnh trên máy ngang thấp: danh sách cuộn riêng, hàng tạo phòng luôn hiện. */
@media (orientation: landscape) and (max-height: 600px), (orientation: landscape) and (pointer: coarse) {
  #screen-hall { overflow: hidden; padding: 6px max(8px, env(safe-area-inset-right)) 12px max(8px, env(safe-area-inset-left)); }
  #screen-hall > .lobby { width: min(1100px, 100%); height: 100%; min-height: 0; margin: 0 auto; display: flex; flex-direction: column; }
  #screen-hall .logo { display: none; }
  #screen-hall .hall { flex: 1; height: auto; min-height: 0; margin: 0; padding: 8px; border-width: 3px; border-radius: 12px; grid-template-columns: clamp(140px, 24vw, 230px) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 6px 10px; }
  #screen-hall .hall > .ribbon { padding: 0 8px; font-size: 16px; line-height: 26px; min-height: 26px; }
  #screen-hall .hall-me { min-width: 0; min-height: 0; padding: 6px; margin: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto; gap: 4px; }
  #screen-hall #hall-avatar { grid-row: auto; width: 100%; height: 100%; max-height: none; min-height: 0; }
  #screen-hall .hall-info { justify-self: center; }
  #screen-hall .hall-info b { font-size: 17px; line-height: 1.2; }
  #screen-hall .hall-info small { font-size: 11px; }
  #screen-hall .hall-me .btn { grid-column: auto; justify-self: center; padding: 3px 8px; font-size: 11px; min-height: 30px; }
  #screen-hall .hall-rooms { min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; gap: 5px; }
  #screen-hall .hall-rooms h3 { font-size: 15px; line-height: 24px; }
  #screen-hall .room-list { min-height: 0; max-height: none; padding: 5px; }
  #screen-hall .room-list li { grid-template-columns: minmax(0, 1fr) 32px auto; min-height: 48px; padding: 4px 6px; gap: 5px; font-size: 13px; }
  #screen-hall .room-host-name { margin-top: 1px; font-size: 11px; }
  #screen-hall .room-list .st { display: none; }
  #screen-hall .room-list .btn { min-height: 32px; padding: 3px 10px; font-size: 12px; }
  #screen-hall .hall-rooms .row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 5px; }
  #screen-hall .hall-rooms .row input { min-height: 34px; padding: 4px 6px; font-size: 12px; }
  #screen-hall #btn-create { min-height: 34px; padding: 4px 8px; font-size: 12px; }
}

/* Bật toàn màn hình ngay từ bước đầu, chừa chỗ để không che tủ đồ. */
#screen-lobby #creator-fullscreen { position: fixed; top: max(6px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); z-index: 10; min-height: 32px; padding: 3px 10px; font-size: 12px; }
#screen-lobby { padding-top: max(44px, calc(env(safe-area-inset-top) + 38px)); }

/* Tủ đồ ngang co theo màn hình, kể cả khi vào toàn màn hình. */
@media (orientation: landscape) and (max-height: 600px), (orientation: landscape) and (pointer: coarse) {
  #screen-lobby { overflow: hidden; padding: 4px max(8px, env(safe-area-inset-right)) 12px max(8px, env(safe-area-inset-left)); }
  #screen-lobby > .lobby { width: min(1100px, 100%); height: 100%; min-height: 0; max-height: 100%; margin: 0 auto; display: flex; flex-direction: column; }
  #screen-lobby .logo { flex: 0 0 34px; margin: 0; padding: 0 120px 0 0; font-size: 23px; line-height: 34px; text-align: center; }
  #screen-lobby .logo span { display: inline; font-size: 14px; letter-spacing: 3px; margin-left: 6px; }
  #screen-lobby .creator { flex: 1; min-height: 0; margin: 4px 0 0; padding: 7px; border-width: 3px; border-radius: 12px; display: flex; flex-direction: column; }
  #screen-lobby .creator-entry { flex: 0 0 auto; min-height: 0; margin: 0 0 6px; gap: 8px; }
  #screen-lobby .creator-entry .field { display: flex; flex: 0 1 auto; font-size: 12px; gap: 6px; white-space: nowrap; }
  #screen-lobby .creator-entry input { width: clamp(120px, 24vw, 240px); padding: 3px 8px; height: 32px; font-size: 14px; }
  #screen-lobby .creator-entry .btn.play { align-self: center; min-height: 32px; margin: 0; padding: 3px 12px; font-size: 14px; }
  #screen-lobby .wardrobe { flex: 1; height: auto; min-height: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  #screen-lobby .wr-preview { display: flex; min-height: 0; height: 100%; padding: 4px; }
  #screen-lobby .wr-preview .wr-sex { gap: 4px; }
  #screen-lobby .wr-preview .wr-sex .btn, #screen-lobby .wr-preview > button { min-height: 28px; font-size: 11px; padding: 2px 9px; }
  #screen-lobby .wr-preview > img { width: calc(100% - 104px); height: calc(100% - 62px); top: 30px; }
  #screen-lobby .wr-equipped { inset: 33px 5px 36px; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 3px; }
  #screen-lobby .wr-equipped img { width: 26px; height: 26px; max-height: 65%; }
  #screen-lobby .wr-equip { padding: 1px; border-width: 2px; }
  #screen-lobby .wr-equip small { font-size: 8px; line-height: 1; }
  #screen-lobby .wr-catalog { min-height: 0; height: 100%; padding: 5px; gap: 3px; grid-template-rows: minmax(0, 1fr) auto auto; }
  #screen-lobby .wr-grid { min-height: 0; gap: 3px; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); }
  #screen-lobby .wr-choice { min-height: 0; padding: 1px; border-width: 2px; overflow: hidden; }
  #screen-lobby .wr-choice img { min-height: 0; width: 100%; height: 100%; max-width: 48px; max-height: 100%; object-fit: contain; }
  #screen-lobby .wr-pages { min-height: 28px; flex-wrap: nowrap; font-size: 10px; gap: 4px; }
  #screen-lobby .wr-pages .btn { min-height: 28px; padding: 0 7px; font-size: 12px; }
  #screen-lobby .wr-kind { position: static; padding: 2px 5px; font-size: 9px; line-height: 1.2; }
}

/* Hàng đầu chia đôi theo hai khung nhân vật và túi đồ. */
@media (min-width: 600px) and (orientation: landscape) {
  #screen-lobby .creator-entry { width: calc(50% - 7px); min-height: 44px; gap: 8px; }
  #screen-lobby .creator-entry .field { flex: 1; min-width: 0; gap: 6px; font-size: 12px; white-space: nowrap; }
  #screen-lobby .creator-entry input { flex: 1; width: 0; min-width: 0; padding-left: 8px; padding-right: 8px; }
  #screen-lobby .creator-entry .btn.play { flex: 0 0 auto; font-size: 14px; padding: 4px 10px; }
  #screen-lobby .wr-kind { position: absolute; top: 26px; left: calc(50% + 7px); right: 16px; padding: 4px 7px; font-size: 10px; line-height: 1.3; }
  #screen-lobby .wr-catalog { grid-template-rows: minmax(0, 1fr) auto; }
}
@media (orientation: landscape) and (max-height: 600px), (orientation: landscape) and (pointer: coarse) {
  #screen-lobby .creator-entry { width: calc(50% - 4px); min-height: 38px; gap: 5px; }
  #screen-lobby .creator-entry .field { flex: 1; min-width: 0; font-size: 10px; gap: 4px; }
  #screen-lobby .creator-entry input { flex: 1; width: 0; min-width: 0; padding: 3px 5px; font-size: 12px; }
  #screen-lobby .creator-entry .btn.play { font-size: 11px; padding: 3px 6px; }
  #screen-lobby .wr-kind { position: absolute; top: 13px; left: calc(50% + 4px); right: 7px; padding: 3px 5px; font-size: 9px; line-height: 1.25; }
  #screen-lobby .wr-catalog { grid-template-rows: minmax(0, 1fr) auto; }
}

/* HUD kính tối, viền kim loại; bản đồ kín màn hình. */
#screen-game { --hud-glass: linear-gradient(145deg, #26313dda, #0b111bce); }
#screen-game #me-card { top: 12px; left: max(12px, env(safe-area-inset-left)); gap: 0; }
#screen-game .avatar-ring { width: 66px; height: 66px; padding: 3px; box-shadow: 0 0 0 1px #654924, 0 3px 12px #0008; }
#screen-game .avatar-ring img { background: #273344; border-width: 1px; }
#screen-game #me-name { background: var(--hud-glass); border: 1px solid #d1ae66; font-size: 14px; padding: 2px 12px; border-radius: 5px; }
#screen-game .bar { border: 1px solid #e3c17b99; background: #090c14c9; }
#screen-game #hud-top { top: 10px; gap: 12px; }
#screen-game .team-row { gap: 5px; }
#screen-game .tp, #screen-game .tp img { width: 38px; }
#screen-game .tp img { height: 38px; border-radius: 5px; border-color: #d6bc83; }
#screen-game .tp .tp-badge { width: 15px; height: 17px; font-size: 9px; }
#screen-game .wind-title { font-size: 12px; }
#screen-game .wind-box { min-width: 112px; }
#screen-game .wind-pill { width: 112px; height: 30px; border-radius: 7px; border-color: #bdcce6; background: linear-gradient(#475b88dd, #162039e8); }
#screen-game .wind-prev { font-size: 10px; background: #10182bbf; }
#screen-game #timer-box { top: 90px; gap: 4px; }
#screen-game #turn-timer { font-size: 58px; min-height: 54px; }
#screen-game .pass-btn { border: 1px solid #f4cf80; border-radius: 20px; min-width: 100px; padding: 2px 15px; font-size: 15px; background: linear-gradient(#e8a43e, #87451c); }
#screen-game #minimap-box { top: 10px; right: max(10px, env(safe-area-inset-right)); width: 176px; border: 1px solid #e3c17b; border-radius: 7px; background: var(--hud-glass); box-shadow: 0 3px 10px #0006; }
#screen-game #map-name { background: transparent; padding: 2px 30px 2px 8px; font-size: 11px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#screen-game #btn-game-exit { position: absolute; z-index: 2; right: 0; top: 0; width: 28px; height: 24px; padding: 0; border: 1px solid #ffd791; border-radius: 3px; background: linear-gradient(#ed7153, #9a211b); color: white; font: 800 23px/20px var(--font); cursor: pointer; }
#screen-game #minimap { border: 0; border-top: 1px solid #e3c17b88; }
#screen-game #hud-bottom { grid-template-columns: 90px minmax(0, 1fr) 92px; grid-template-rows: auto auto; gap: 5px 18px; align-items: end; padding: 8px max(18px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); background: linear-gradient(transparent, #09101b77 45%, #090e19cc); }
#screen-game .dial-box { grid-column: 1; grid-row: 1 / 3; width: 90px; height: 90px; margin: 0; align-self: end; }
#screen-game #angle-dial { width: 90px; height: 90px; }
#screen-game .hud-items { grid-column: 2; grid-row: 1; justify-content: center; gap: 8px; }
#screen-game .item { width: 62px; height: 62px; border-radius: 7px; border: 1px solid #e4d1a3; padding: 4px; background: linear-gradient(140deg, #6682a7aa, #121b2be8 65%); box-shadow: inset 0 0 0 2px #ffffff29, 0 3px 8px #0006; }
#screen-game .item-icon { font-size: 27px; color: #fff2b4; text-shadow: 0 2px 3px #000; }
#screen-game .item-name { font-size: 9px; }
#screen-game .item-key { top: 3px; left: 4px; font-size: 9px; opacity: .7; }
#screen-game .item-cost { top: 3px; right: 4px; font-size: 9px; color: #c5edff; }
#screen-game .item.used { border-color: #ffe681; background: linear-gradient(140deg, #d7a935c9, #704719de); box-shadow: inset 0 0 0 2px #ffe88866, 0 0 12px #ffd15499; }
#screen-game .item:disabled { opacity: .6; }
#screen-game .power-box { grid-column: 2; grid-row: 2; min-width: 0; }
#screen-game #power-bar { height: 19px; border: 1px solid #e4d1a3; border-radius: 5px; background: #070d19b8; box-shadow: inset 0 2px 5px #000a; }
#screen-game .ruler { height: 15px; color: #fff3d1; }
#screen-game .battle-vitals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#screen-game .battle-vitals .bar { width: 100%; height: 16px; }
#screen-game .battle-vitals span { font-size: 10px; }
#screen-game .bar.stamina i { background: linear-gradient(#d8ff76, #5eae16 55%, #2b7610); }
#screen-game .side-btns { grid-column: 3; grid-row: 1 / 3; display: grid; gap: 5px; }
#screen-game .side-btns .btn { min-height: 30px; padding: 3px 6px; font-size: 10px; border: 1px solid #c8b990; border-radius: 5px; color: #f9e9c7; background: var(--hud-glass); box-shadow: inset 0 1px 0 #ffffff30; }
#screen-game #btn-chat { display: block; }
#screen-game #touch { display: none; }
#screen-game #banner { font-style: italic; font-size: clamp(28px, 5vw, 64px); }
@media (hover: none) and (pointer: coarse) {
  #screen-game #touch { display: flex; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); bottom: calc(var(--hud-height, 100px) + 12px); justify-content: space-between; pointer-events: none; }
  #screen-game #touch button { pointer-events: auto; }
  #screen-game .dpad { grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 32px); padding: 4px; border: 1px solid #c3d5eb88; border-radius: 50%; background: radial-gradient(#51657d77, #0d172680); box-shadow: inset 0 0 12px #ffffff20; }
  #screen-game .dpad button { color: #cdefff; border: 1px solid #a6c6e2; border-radius: 7px; background: linear-gradient(#526c8ecc, #14263edb); }
  #screen-game #touch .fire { width: 72px; height: 72px; font-size: 21px; border-width: 2px; align-self: center; }
}
@media (max-width: 1000px), (max-height: 550px) {
  #screen-game #hud-top { gap: 5px; }
  #screen-game #me-card { top: 6px; left: 6px; }
  #screen-game .avatar-ring { width: 40px; height: 40px; }
  #screen-game #me-name { font-size: 10px; padding: 0 5px; max-width: 95px; }
  #screen-game .me-info .bar { width: 86px; height: 12px; }
  #screen-game .me-info .bar span { font-size: 8px; }
  #screen-game .tp, #screen-game .tp img { width: 25px; }
  #screen-game .tp img { height: 25px; }
  #screen-game .team-row { gap: 3px; }
  #screen-game .wind-box { min-width: 85px; }
  #screen-game .wind-pill { width: 85px; height: 24px; }
  #screen-game .wind-title { font-size: 10px; }
  #screen-game .wind-prev { font-size: 8px; }
  #screen-game #timer-box { top: 67px; }
  #screen-game #turn-timer { font-size: 38px; min-height: 35px; }
  #screen-game .pass-btn { min-width: 75px; font-size: 12px; padding: 1px 10px; }
  #screen-game #minimap-box { top: 6px; right: 6px; width: 108px; }
  #screen-game #map-name { font-size: 8px; line-height: 20px; }
  #screen-game #hud-bottom { grid-template-columns: 58px minmax(0, 1fr) 65px; gap: 3px 9px; padding: 5px 9px 6px; }
  #screen-game .dial-box, #screen-game #angle-dial { width: 58px; height: 58px; }
  #screen-game .hud-items { gap: 5px; }
  #screen-game .item { width: 43px; height: 43px; padding: 2px; }
  #screen-game .item-icon { font-size: 21px; }
  #screen-game .item-name { font-size: 7px; }
  #screen-game .item-key, #screen-game .item-cost { font-size: 7px; }
  #screen-game .item-count { font-size: 9px; bottom: 10px; }
  #screen-game .side-btns .btn { min-height: 25px; font-size: 8px; padding: 2px 3px; }
  #screen-game .power-head b { font-size: 12px; }
  #screen-game .power-head .sub { font-size: 9px; }
  #screen-game #power-bar { height: 14px; }
  #screen-game .ruler { height: 12px; font-size: 8px; }
  #screen-game .battle-vitals { gap: 6px; }
  #screen-game .battle-vitals .bar { height: 12px; }
  #screen-game .battle-vitals span { font-size: 8px; }
}

/* Cụm điều khiển gọn ở đáy, chừa hai góc cho tay cầm cảm ứng. */
#screen-game .side-btns { display: none; }
#screen-game #hud-bottom {
  left: 50%; right: auto; width: min(850px, calc(100% - 32px)); transform: translateX(-50%);
  grid-template-columns: 76px minmax(0, 1fr); gap: 4px 12px;
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
}
#screen-game .dial-box, #screen-game #angle-dial { width: 76px; height: 76px; }
#screen-game .hud-items { gap: 6px; }
#screen-game .item { width: 52px; height: 52px; border-radius: 9px; }
#screen-game .item-icon { font-size: 24px; }
#screen-game .power-head .sub { font-size: 10px; }
@media (max-width: 1000px), (max-height: 550px) {
  #screen-game #hud-bottom { width: min(670px, calc(100% - 24px)); grid-template-columns: 52px minmax(0, 1fr); gap: 3px 8px; padding: 4px 8px max(6px, env(safe-area-inset-bottom)); }
  #screen-game .dial-box, #screen-game #angle-dial { width: 52px; height: 52px; }
  #screen-game .item { width: 40px; height: 40px; }
  #screen-game .item-icon { font-size: 19px; }
}
@media (hover: none) and (pointer: coarse) {
  #screen-game #hud-bottom { width: min(760px, calc(100% - 260px)); padding: 5px 6px max(8px, env(safe-area-inset-bottom)); grid-template-columns: minmax(0, 1fr); }
  #screen-game .dial-box { display: none; }
  #screen-game .hud-items, #screen-game .power-box { grid-column: 1; }
  #screen-game #touch { bottom: max(12px, env(safe-area-inset-bottom)); left: max(14px, env(safe-area-inset-left)); right: max(14px, env(safe-area-inset-right)); align-items: end; }
  #screen-game .dpad {
    position: relative; width: 112px; height: 112px; padding: 4px;
    grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px);
    border: 1px solid #d8e8ff66; border-radius: 50%;
    background: radial-gradient(circle, #26374b88 20%, #12203288 65%, #9fbad733 68%, #101d2a66 72%);
    box-shadow: inset 0 1px 3px #ffffff55, inset 0 -2px 6px #0006, 0 3px 10px #0003;
  }
  #screen-game .dpad::after { content: ''; position: absolute; width: 22px; height: 22px; left: 44px; top: 44px; border-radius: 50%; border: 1px solid #c4d9ef66; background: radial-gradient(#91adc177, #22344688); pointer-events: none; }
  #screen-game .dpad button { font-size: 16px; border: 1px solid #bbd5ef99; border-radius: 11px; background: linear-gradient(145deg, #748ca5b3, #233950d9); color: #eefaff; text-shadow: 0 1px 3px #10263b; box-shadow: inset 0 1px 1px #ffffff66, 0 2px 3px #0004; }
  #screen-game .dpad button:active { background: linear-gradient(#4b9bce, #246397); box-shadow: inset 0 2px 4px #0005, 0 0 9px #8cdaff88; }
  #screen-game #touch .fire {
    width: 92px; height: 92px; align-self: end; margin: 0 2px 8px 0;
    border: 2px solid #ffe9a3; font-size: 23px; letter-spacing: 1px; color: #fff9e1;
    background: radial-gradient(circle at 38% 27%, #ffeeb0, #ffc044 30%, #ed8c13 65%, #a84c08);
    box-shadow: inset 0 0 0 4px #9c4c1666, inset 0 3px 4px #fff8c399, 0 0 0 3px #51351bb3, 0 5px 12px #0006;
    text-shadow: 0 2px 2px #8c420b;
  }
  #screen-game #touch .fire:active { filter: brightness(1.12); box-shadow: inset 0 3px 8px #99460899, 0 0 0 3px #51351bb3, 0 0 14px #ffd26988; }
}

/* Máy tính dùng thước lực rộng và đồng hồ góc lớn, nhìn xuyên bản đồ. */
@media (hover: hover) and (pointer: fine) {
  #screen-game #hud-bottom {
    left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    width: auto; transform: none; grid-template-columns: clamp(110px, 10vw, 164px) minmax(0, 1fr);
    padding: 8px 8px max(10px, env(safe-area-inset-bottom)); gap: 5px 16px;
    background: transparent; border-radius: 0;
  }
  #screen-game .dial-box, #screen-game #angle-dial { width: clamp(110px, 10vw, 164px); height: clamp(110px, 10vw, 164px); }
  #screen-game .dial-box { background: transparent; }
  #screen-game #angle-dial { filter: drop-shadow(0 2px 3px #0007); }
  #screen-game .hud-items { justify-content: flex-start; padding-left: 4px; }
  #screen-game #power-bar { height: 32px; border: 1px solid #f5e3b9cc; background: #12203026; border-radius: 3px; box-shadow: inset 0 0 0 2px #ffffff15, 0 1px 4px #0005; }
  #screen-game #power-bar::before { border-radius: 2px; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), #fff8 calc(10% - 1px) 10%); }
  #screen-game .power-head { gap: 8px; }
  #screen-game .power-head .label, #screen-game .power-head b { font-size: 20px; }
  #screen-game .power-head .sub { font-size: 13px; }
  #screen-game .ruler { height: 19px; font-size: 12px; color: #fff5d3; text-shadow: 0 1px 3px #000, 0 0 3px #000; }
  #screen-game .battle-vitals .bar { height: 18px; }
  #screen-game .battle-vitals span { font-size: 11px; }
}

/* Đồng hồ góc gộp vào tay điều khiển; thanh lực kính trong như máy tính. */
#touch-angle-dial, #touch-angle-value { display: none; }
@media (hover: none) and (pointer: coarse) {
  #screen-game #hud-bottom { background: transparent; }
  #screen-game #power-bar { height: 22px; border: 1px solid #f5e3b9cc; background: #12203026; border-radius: 3px; box-shadow: inset 0 0 0 2px #ffffff15, 0 1px 4px #0005; }
  #screen-game #power-bar::before { border-radius: 2px; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), #fff8 calc(10% - 1px) 10%); }
  #screen-game .ruler { color: #fff5d3; text-shadow: 0 1px 3px #000, 0 0 3px #000; }
  #screen-game .dpad { width: 140px; height: 140px; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); background: radial-gradient(circle, #22384c22, #12203244); }
  #screen-game .dpad::after { display: none; }
  #screen-game .dpad button { position: relative; z-index: 2; width: 36px; height: 36px; align-self: center; justify-self: center; }
  #screen-game #touch-angle-dial { display: block; position: absolute; left: 34px; top: 34px; width: 72px; height: 72px; pointer-events: none; }
  #screen-game #touch-angle-value { display: block; position: absolute; left: 50%; top: 50%; transform: translate(-50%, 6px); color: #fff0a1; font-size: 17px; font-weight: 800; line-height: 1; text-shadow: 0 1px 3px #000, 0 0 3px #000; pointer-events: none; }
  #screen-game #hud-bottom { width: min(760px, calc(100% - 310px)); }
}

/* Máy tính: góc bên trái, thước lực gọn ở giữa, đạo cụ bên phải. */
@media (hover: hover) and (pointer: fine) {
  #screen-game #hud-bottom {
    grid-template-columns: clamp(110px, 10vw, 150px) minmax(0, 1fr) auto;
    grid-template-rows: auto; gap: 14px; align-items: end; background: transparent;
  }
  #screen-game .dial-box { grid-column: 1; grid-row: 1; }
  #screen-game .dial-box, #screen-game #angle-dial { width: clamp(110px, 10vw, 150px); height: clamp(110px, 10vw, 150px); }
  #screen-game .power-box { grid-column: 2; grid-row: 1; padding-bottom: 2px; }
  #screen-game .hud-items { grid-column: 3; grid-row: 1; justify-content: flex-end; align-self: end; padding: 0 0 2px; gap: 6px; }
  #screen-game .item { width: clamp(42px, 4vw, 60px); height: clamp(48px, 4.5vw, 66px); }
  #screen-game #power-bar { height: 26px; background: linear-gradient(#111b27e6, #080e17e6); border: 1px solid #dfd3b3; box-shadow: inset 0 2px 5px #0009, 0 0 0 2px #17202b99; }
  #screen-game .power-head .label, #screen-game .power-head b { font-size: 17px; }
  #screen-game .ruler { height: 17px; font-size: 10px; }
  #screen-game .battle-vitals .bar { height: 16px; }
}

/* Thước lực kim loại: 100 nấc nhỏ, vạch chục dài và lực tích màu đỏ. */
#screen-game #power-bar {
  background: linear-gradient(180deg, #d7d9d9 0%, #969da2 32%, #42494e 34%, #20262b 75%, #343a3f 100%);
  border: 1px solid #e9e6d9; border-radius: 2px;
  box-shadow: inset 0 0 0 2px #10161a, 0 0 0 1px #545b60, 0 2px 4px #0008;
}
#screen-game #power-bar::before {
  border-radius: 0;
  background:
    repeating-linear-gradient(90deg, #101419e6 0 1px, transparent 1px 1%) left top / 100% 35% no-repeat,
    repeating-linear-gradient(90deg, #080c10 0 1px, transparent 1px 5%) left top / 100% 52% no-repeat,
    repeating-linear-gradient(90deg, #05080c 0 2px, transparent 2px 10%) left top / 100% 72% no-repeat;
}
#screen-game #power-fill {
  border-radius: 0;
  background: linear-gradient(180deg, #ffb7a980, #e2362a88 35%, #a80c09c9 75%, #ff5540);
  box-shadow: inset 0 -2px 0 #ff8a66, inset 0 0 0 1px #ef5b4699;
}
@media (hover: hover) and (pointer: fine) {
  #screen-game #power-bar { height: 30px; }
}

/* Thước lực tương phản cao: số ở trên, nấc sáng và kim đỏ tại lực hiện tại. */
#screen-game .power-box { display: grid; grid-template-rows: auto 16px auto auto; row-gap: 2px; }
#screen-game .power-head { grid-row: 1; }
#screen-game #power-ruler { grid-row: 2; height: 16px; font-size: 12px; line-height: 16px; color: #fff; font-weight: 800; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 0 0 3px #000; }
#screen-game #power-bar {
  grid-row: 3; height: 30px;
  border: 2px solid #d9d8d1; border-radius: 2px;
  background: linear-gradient(#d4d6d5 0 30%, #50565b 30% 34%, #151b22 34% 88%, #3a4147 88%);
  box-shadow: 0 0 0 1px #11171e, inset 0 0 0 1px #030609, 0 1px 4px #0009;
}
#screen-game #power-bar::before {
  inset: 0; z-index: 2;
  background:
    repeating-linear-gradient(90deg, #1a1d20 0 1px, transparent 1px 1%) 0 0 / 100% 36% no-repeat,
    repeating-linear-gradient(90deg, #111518 0 1px, transparent 1px 5%) 0 0 / 100% 52% no-repeat,
    repeating-linear-gradient(90deg, #070b0e 0 2px, transparent 2px 10%) 0 0 / 100% 70% no-repeat;
}
#screen-game #power-fill {
  height: 66%; position: absolute; left: 0; right: 0; bottom: 0; z-index: 1;
  background: linear-gradient(#ff6c48, #e52a16 35%, #a80b07 72%, #ff4024);
  box-shadow: inset 0 1px 0 #ffb393, inset 0 -2px 0 #ff623c;
}
#screen-game #power-needle { position: absolute; z-index: 4; top: -1px; bottom: 0; left: 0; width: 1px; background: #ff4e30; box-shadow: 0 0 3px #000; pointer-events: none; }
#screen-game #power-needle::before { content: ''; position: absolute; left: -7px; top: -10px; width: 15px; height: 10px; clip-path: polygon(0 0, 100% 0, 50% 100%); background: linear-gradient(#ffb7a3, #ef2c20 45%, #ab100c); filter: drop-shadow(0 1px 1px #000); }
#screen-game .battle-vitals { grid-row: 4; margin-top: 4px; }
@media (hover: none) and (pointer: coarse) {
  #screen-game .power-box { grid-template-rows: auto 13px auto auto; }
  #screen-game #power-ruler { height: 13px; font-size: 9px; line-height: 13px; }
  #screen-game #power-bar { height: 24px; }
}

/* Thước lực dịu màu, vạch mảnh; phía dưới chỉ giữ thể lực toàn chiều dài. */
#screen-game .power-box { grid-template-rows: auto auto 16px auto; }
#screen-game #power-bar {
  grid-row: 2;
  background: linear-gradient(#c2c5c8 0%, #a8adb2 31%, #737a83 33%, #505965 90%, #747c84 100%);
  border-color: #c5c7ca;
}
#screen-game #power-bar::before {
  background:
    repeating-linear-gradient(90deg, #252d36a6 0 .65px, transparent .65px 1%) 0 0 / 100% 34% no-repeat,
    repeating-linear-gradient(90deg, #202a34b3 0 .75px, transparent .75px 5%) 0 0 / 100% 46% no-repeat,
    repeating-linear-gradient(90deg, #18232ccc 0 1px, transparent 1px 10%) 0 0 / 100% 62% no-repeat;
}
#screen-game #power-fill { background: linear-gradient(#ffd18c, #efa159 40%, #de704c 78%, #ee9b63); box-shadow: inset 0 1px 0 #ffe3b3, inset 0 -1px 0 #f8af7f; }
#screen-game #power-ruler { grid-row: 3; }
#screen-game .battle-vitals { grid-template-columns: minmax(0, 1fr); margin-top: 1px; }
#screen-game .battle-vitals .hp { display: none; }
@media (hover: none) and (pointer: coarse) {
  #screen-game .power-box { grid-template-rows: auto auto 13px auto; }
}

/* Mốc căn lực kéo độc lập; nền thước nhẹ để không lấn bản đồ. */
#screen-game #power-bar { pointer-events: auto; touch-action: none; cursor: ew-resize; user-select: none; background: linear-gradient(#c2c5c855 0%, #a8adb244 31%, #737a8333 33%, #28334255 100%); border-color: #d0d4d88c; box-shadow: inset 0 0 0 1px #17212b66, 0 1px 3px #0005; }
#screen-game #power-fill { opacity: .72; }
#screen-game #power-bar::before { opacity: .65; }
#screen-game #power-needle { cursor: ew-resize; }
#screen-game #power-needle::after { content: ''; position: absolute; inset: -12px -12px -5px; }
#screen-game #power-guide-value { display: none; position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%); background: #15202de6; border: 1px solid #dbbc80; border-radius: 4px; padding: 1px 5px; color: #fff0bc; font-size: 11px; line-height: 1.3; }
#screen-game #power-bar.guiding #power-guide-value { display: block; }

/* Màu lực phủ kín lòng thước, vạch chia vẫn vẽ phía trên. */
#screen-game #power-fill { height: 100%; top: 0; bottom: 0; }

/* Đạo cụ: biểu tượng vector, màu riêng và phản hồi khi server xác nhận. */
#screen-game .item { --item-accent: #82d6ff; border: 1px solid #91abc5; border-radius: 12px; background: radial-gradient(ellipse at 50% 0, #49647c, #182938 68%); box-shadow: inset 0 1px 1px #ffffff66, inset 0 -2px 4px #0007, 0 3px 6px #0005; transition: transform .15s, border-color .15s; overflow: hidden; }
#screen-game .item[data-item="triple"] { --item-accent: #cbb6ff; }
#screen-game .item[data-item="power"] { --item-accent: #ffbc56; }
#screen-game .item[data-item="heal"] { --item-accent: #74edaf; }
#screen-game .item[data-item="teleport"] { --item-accent: #65e7ff; }
#screen-game .item[data-item="stealth"] { --item-accent: #c2a2ff; }
#screen-game .item .item-icon { color: var(--item-accent); width: 56%; height: 56%; display: grid; place-items: center; filter: drop-shadow(0 1px 3px #0008); }
#screen-game .item-icon svg { width: 100%; height: 100%; }
#screen-game .item:active:not(:disabled) { transform: translateY(2px) scale(.94); }
#screen-game .item.used { border-color: var(--item-accent); box-shadow: inset 0 0 12px #ffffff20, 0 0 7px var(--item-accent); }
#screen-game .item.activated { animation: item-activate .55s ease-out; }
#screen-game .item .item-cost { color: #d7e7f3; }
@keyframes item-activate { 0% { transform: scale(.9); } 40% { transform: translateY(-3px) scale(1.08); box-shadow: 0 0 18px var(--item-accent); } 100% { transform: none; } }
@media (max-width: 950px) { #screen-game .hud-items { gap: 4px; } }

/* Tách đạo cụ đạn bên phải, đạo cụ chức năng giữ dưới cùng. */
#screen-game #ammo-items { position: absolute; z-index: 8; top: 48%; right: max(14px, env(safe-area-inset-right)); transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; padding: 0; pointer-events: none; }
#screen-game #ammo-items .item { pointer-events: auto; width: clamp(46px, 4.5vw, 64px); height: clamp(52px, 5vw, 70px); }
#screen-game .item[data-item="teleport"] .item-icon { filter: drop-shadow(0 0 3px #c2ecff88); }
#screen-game .item[data-item="stealth"] .item-icon { filter: drop-shadow(0 0 4px #46d5ffbb); }
@media (hover: none) and (pointer: coarse) {
  #screen-game #ammo-items { top: 43%; right: max(9px, env(safe-area-inset-right)); gap: 6px; }
  #screen-game #ammo-items .item { width: 43px; height: 46px; }
}
@media (max-height: 450px) {
  #screen-game #ammo-items { gap: 4px; }
  #screen-game #ammo-items .item { width: 39px; height: 40px; }
}

/* Đạo cụ chức năng gọn ở cuối hàng lực, thay dòng Lần trước. */
#screen-game .power-head .sub { display: none; }
#screen-game .power-head { align-items: center; min-width: 0; }
#screen-game #items { position: static; display: flex; flex-direction: row; flex: 0 0 auto; margin-left: auto; padding: 0; gap: 4px; align-self: center; }
#screen-game #items .item { width: 40px; height: 40px; border-radius: 8px; padding: 2px; }
#screen-game #items .item-name { font-size: 8px; }
#screen-game #items .item-key, #screen-game #items .item-cost { font-size: 8px; }
@media (hover: none) and (pointer: coarse), (max-height: 550px) {
  #screen-game #items .item { width: 34px; height: 34px; }
  #screen-game #items .item-name { font-size: 7px; }
}

#screen-game #shot-plan { display: none; }

/* Chat cảm ứng luôn hiện dưới tên và máu; chừa vùng bản đồ để thao tác. */
.game-chat-compose { display: flex; gap: 4px; min-width: 0; }
.game-chat-compose input { min-width: 0; flex: 1; }
#game-chat-send { display: none; }
@media (hover: none) and (pointer: coarse) {
  #screen-game #game-chat, #screen-game #game-chat.open {
    display: grid; position: absolute; z-index: 12;
    left: max(10px, env(safe-area-inset-left)); top: var(--chat-top, 70px); bottom: auto;
    width: min(260px, 32vw); max-height: none; padding: 0; gap: 5px;
    background: transparent; border-radius: 0; pointer-events: none;
  }
  #screen-game #game-chat-log { max-height: min(110px, 22dvh); overflow-y: auto; font-size: 11px; gap: 3px; pointer-events: auto; scrollbar-width: thin; }
  #screen-game #game-chat-log:empty { display: none; }
  #screen-game #game-chat-log div { padding: 3px 6px; border-radius: 5px; background: #12202c88; overflow-wrap: anywhere; text-shadow: 0 1px 2px #000; }
  #screen-game #game-chat-log div.fade { opacity: .7; }
  #screen-game .game-chat-compose { pointer-events: auto; }
  #screen-game #game-chat-input { opacity: 1; width: 100%; height: 30px; padding: 3px 7px; font-size: 16px; color: #f1f7ff; background: #142535a6; border: 1px solid #adc9e766; border-radius: 7px; }
  #screen-game #game-chat-input::placeholder { color: #d4dfeb; font-size: 11px; }
  #screen-game #game-chat-send { display: block; width: 30px; height: 30px; padding: 0; color: #d8f1ff; border: 1px solid #adc9e788; border-radius: 7px; background: #244b6fb3; }
}

/* Thu gọn trò chuyện và biểu cảm trên đầu nhân vật. */
.game-social-bar { display: flex; gap: 5px; pointer-events: auto; }
.game-social-bar button { padding: 3px 8px; min-height: 28px; border: 1px solid #adc9e777; border-radius: 7px; color: #eff8ff; background: #193247b3; font: 700 11px var(--font); cursor: pointer; }
#game-emote-toggle { font-size: 18px; line-height: 1; }
#game-emote-picker:not([hidden]) { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; width: 180px; max-width: 100%; padding: 6px; background: #172b40ed; border: 1px solid #a1c3e088; border-radius: 10px; pointer-events: auto; }
#game-emote-picker button { border: 0; border-radius: 6px; background: #ffffff12; font-size: 23px; min-height: 34px; cursor: pointer; padding: 2px; }
#game-emote-picker button:active { background: #82c9ff66; transform: scale(.9); }
#screen-game #game-chat.collapsed #game-chat-log, #screen-game #game-chat.collapsed .game-chat-compose { display: none; }
#screen-game #game-chat.collapsed { width: auto; }

/* Máy tính: lịch sử chat ở trên, điều khiển ở dưới, cuộn để xem tin cũ. */
@media (hover: hover) and (pointer: fine) {
  #screen-game #game-chat, #screen-game #game-chat.open {
    display: flex; flex-direction: column; justify-content: flex-end; gap: 5px;
    top: auto; left: 12px; bottom: calc(var(--hud-height, 110px) + 12px);
    width: min(340px, 34vw); height: auto; max-height: none; padding: 0;
    background: transparent; z-index: 12; pointer-events: none;
  }
  #screen-game #game-chat-log {
    order: 1; display: flex; flex-direction: column; flex: 0 1 auto;
    max-height: min(220px, 30dvh); min-height: 0; gap: 3px;
    overflow-y: auto; overflow-x: hidden; scrollbar-width: thin;
    scrollbar-color: #aac9e2 #182e4277; pointer-events: auto;
  }
  #screen-game #game-chat-log:empty { display: none; }
  #screen-game #game-chat-log div { flex: 0 0 auto; overflow-wrap: anywhere; }
  #screen-game #game-chat-log div.fade { opacity: 1; }
  #screen-game #game-emote-picker { order: 2; }
  #screen-game .game-social-bar { order: 3; }
  #screen-game .game-chat-compose { order: 4; pointer-events: auto; }
  #screen-game #game-chat-input { opacity: 1; color: #f1f7ff; background: #142535b3; border: 1px solid #adc9e766; border-radius: 7px; }
  #screen-game #game-chat-input::placeholder { color: #c8d8e8; }
  #screen-game #game-chat-send { display: block; width: 32px; border: 1px solid #adc9e777; border-radius: 7px; color: #eaf7ff; background: #244b6fb3; cursor: pointer; }
}
