* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  overscroll-behavior: none;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0b101b;
  color: #e2e8f0;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  display: none;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ========================================================================== */
/* SẢNH CHÍNH CHUẨN AAA RTS / ESPORTS (DYNAMIC EMPIRE GLOW & SHOWCASE STAGE)  */
/* ========================================================================== */
#lobby-screen {
  --empire-accent: #00e5ff;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: #060913;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.03) 1px, transparent 1px),
    radial-gradient(ellipse at 50% 0%, rgba(30, 58, 138, 0.42) 0%, #070b14 62%, #04060c 100%);
  background-size: 36px 36px, 36px 36px, 100% 100%;
  justify-content: center;
  align-items: flex-start;
  padding: 16px 22px 28px;
}

.lobby-bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 24% 28%, color-mix(in srgb, var(--empire-accent) 18%, transparent) 0%, transparent 52%),
    radial-gradient(circle at 82% 18%, rgba(250, 204, 21, 0.09) 0%, transparent 45%);
  transition: background 0.35s ease;
  z-index: 0;
}

.lobby-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Thanh Điều Hướng Đỉnh (Top Esports Header) --- */
.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(9, 14, 26, 0.95));
  border: 1px solid rgba(250, 204, 21, 0.28);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  backdrop-filter: blur(12px);
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-crest-wrap {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 35%, rgba(250, 204, 21, 0.28), rgba(15, 23, 42, 0.95));
  border: 1.5px solid rgba(250, 204, 21, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.2);
  flex-shrink: 0;
}

.brand-crest-img {
  width: 36px;
  height: 36px;
}

.brand-kicker {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1.4px;
  color: #fbbf24;
  text-transform: uppercase;
}

.lobby-header h1 {
  font-size: 25px;
  font-weight: 900;
  letter-spacing: 0.8px;
  background: linear-gradient(180deg, #fffbeb 0%, #fde047 55%, #d97706 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.15;
}

.commander-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.commander-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.28);
  padding: 5px 12px 5px 7px;
  border-radius: 11px;
  cursor: text;
  transition: border-color 0.2s ease;
}

.commander-profile:focus-within {
  border-color: var(--empire-accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.commander-profile img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #090d16;
  padding: 2px;
  border: 1px solid var(--empire-accent);
}

.commander-field {
  display: flex;
  flex-direction: column;
}

.commander-field span {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.9px;
  color: #94a3b8;
}

.commander-field input {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: #f8fafc;
  width: 132px;
}

.commander-field input:focus {
  border: none;
  outline: none;
}

.server-pills {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  align-items: center;
}

.status-badge {
  padding: 6px 11px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.status-badge.connecting { background: rgba(120, 53, 15, 0.75); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.35); }
.status-badge.online { background: rgba(20, 83, 45, 0.75); color: #86efac; border: 1px solid rgba(74, 222, 128, 0.35); }
.status-badge.neutral { background: rgba(30, 41, 59, 0.85); color: #cbd5e1; border: 1px solid rgba(71, 85, 105, 0.65); }
.status-badge.action-pill {
  background: rgba(30, 41, 59, 0.92);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.4);
  cursor: pointer;
  transition: all 0.16s ease;
}
.status-badge.action-pill:hover {
  border-color: #fbbf24;
  color: #fde047;
}

input, select {
  background: #0b1220;
  border: 1px solid #334155;
  color: #f8fafc;
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.16s ease;
}

input:focus, select:focus {
  border-color: #fbbf24;
}

/* --- Bố Cục Chính 2 Cột (Trái: Sân Khấu 8 Đế Chế | Phải: Trung Tâm Chế Độ Đấu) --- */
.lobby-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(355px, 1fr);
  gap: 18px;
  align-items: stretch;
}

.lobby-left-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-heading-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 0 2px;
}

.section-title {
  font-size: 13px;
  font-weight: 800;
  color: #fbbf24;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.section-hint {
  font-size: 12px;
  color: #94a3b8;
}

/* --- Lưới 8 Thẻ Đế Chế Tinh Gọn & Sang Trọng --- */
.faction-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.faction-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(165deg, rgba(19, 28, 46, 0.92), rgba(10, 15, 28, 0.95));
  border: 1.5px solid rgba(51, 65, 85, 0.85);
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.faction-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--f-color, #fbbf24);
  opacity: 0.45;
  transition: opacity 0.16s ease, height 0.16s ease;
}

.faction-card:hover {
  transform: translateY(-2px);
  border-color: rgba(148, 163, 184, 0.75);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.38);
}

.faction-card:hover::before {
  opacity: 0.9;
}

.faction-card.selected {
  border-color: var(--f-color, #fbbf24);
  box-shadow:
    0 0 0 1px var(--f-color, #fbbf24),
    0 10px 26px rgba(0, 0, 0, 0.5),
    inset 0 0 28px color-mix(in srgb, var(--f-color, #fbbf24) 16%, transparent);
  background: linear-gradient(160deg, rgba(30, 41, 59, 0.96), rgba(11, 17, 32, 0.98));
}

.faction-card.selected::before {
  opacity: 1;
  height: 4px;
}

.fc-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fc-emblem {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

.fc-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.fc-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.fc-name {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.fc-color-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.fc-arch {
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-ult-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(51, 65, 85, 0.55);
  font-size: 11px;
  color: #cbd5e1;
}

.fc-ult-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-ult-item img {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* --- Sân Khấu Chi Tiết Đế Chế & Xem Quân Cử Động Trực Tiếp --- */
.selected-faction-banner {
  flex: 1;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.94), rgba(9, 13, 24, 0.97));
  border: 1px solid color-mix(in srgb, var(--empire-accent) 48%, #334155);
  border-left: 4px solid var(--empire-accent);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.showcase-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.showcase-identity {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 260px;
}

.banner-nexus-preview {
  width: 78px;
  height: 78px;
  flex-shrink: 0;
  background: radial-gradient(circle at 50% 55%, color-mix(in srgb, var(--empire-accent) 26%, #090d16), #060911);
  border: 1.5px solid color-mix(in srgb, var(--empire-accent) 60%, #334155);
  border-radius: 12px;
  padding: 5px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.showcase-titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.showcase-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.showcase-name-line h2 {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.3px;
}

.empire-color-pill {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 99px;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.showcase-passive {
  font-size: 12.5px;
  color: #cbd5e1;
  line-height: 1.4;
}

.showcase-passive strong {
  color: #fde68a;
}

.showcase-ult-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(250, 204, 21, 0.07);
  border: 1px solid rgba(250, 204, 21, 0.32);
  border-radius: 11px;
  padding: 9px 13px;
  max-width: 340px;
}

.showcase-ult-card img {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 8px;
  background: #090d16;
  padding: 3px;
  border: 1px solid rgba(250, 204, 21, 0.45);
}

.showcase-ult-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.showcase-ult-info small {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #fbbf24;
  text-transform: uppercase;
}

.showcase-ult-info strong {
  font-size: 13px;
  color: #fef08a;
}

.showcase-ult-info span {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.3;
}

/* Sân Khấu 6 Đơn Vị Độc Bản + Ô Xem Tướng Cử Động 60FPS */
.showcase-middle {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(250px, 0.95fr);
  gap: 12px;
  align-items: stretch;
}

.unit-roster-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.unit-showcase-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(19, 28, 46, 0.82);
  border: 1px solid rgba(51, 65, 85, 0.85);
  border-radius: 10px;
  padding: 6px 8px;
  color: #e2e8f0;
  cursor: pointer;
  text-align: left;
  transition: all 0.14s ease;
}

.unit-showcase-btn:hover {
  border-color: #94a3b8;
  background: rgba(30, 41, 59, 0.92);
}

.unit-showcase-btn.active {
  border-color: var(--empire-accent);
  background: color-mix(in srgb, var(--empire-accent) 15%, #0f172a);
  box-shadow: 0 0 12px color-mix(in srgb, var(--empire-accent) 25%, transparent);
}

.unit-showcase-btn img {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 7px;
}

.usb-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.usb-role {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.4px;
}

.usb-name {
  font-size: 12px;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-live-stage {
  display: flex;
  align-items: center;
  gap: 12px;
  background: radial-gradient(circle at 26% 55%, color-mix(in srgb, var(--empire-accent) 22%, #090d16), #080c17);
  border: 1px solid rgba(71, 85, 105, 0.65);
  border-radius: 11px;
  padding: 10px 12px;
}

.live-canvas-pedestal {
  width: 86px;
  height: 86px;
  flex-shrink: 0;
  border-radius: 10px;
  background: rgba(6, 9, 17, 0.85);
  border: 1px solid color-mix(in srgb, var(--empire-accent) 50%, #1e293b);
  display: flex;
  align-items: center;
  justify-content: center;
}

#lobby-unit-anim-canvas {
  width: 82px;
  height: 82px;
  display: block;
}

.live-unit-stats {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.lus-title {
  font-size: 14px;
  font-weight: 800;
  color: #fef08a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lus-sub {
  font-size: 11px;
  color: #94a3b8;
}

.lus-pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-top: 2px;
}

.lus-pill {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(51, 65, 85, 0.75);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
}

/* Dải Kiến Trúc Đặc Trưng Đế Chế */
.showcase-buildings-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(51, 65, 85, 0.55);
  flex-wrap: wrap;
}

.sbb-label {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.sbb-icons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sbb-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(51, 65, 85, 0.75);
  border-radius: 7px;
  padding: 3px 7px 3px 4px;
  font-size: 11px;
  color: #cbd5e1;
}

.sbb-chip img {
  width: 22px;
  height: 22px;
}

/* --- CỘT PHẢI: TRUNG TÂM CHẾ ĐỘ THI ĐẤU (COMMAND DECK) --- */
.lobby-right-deck {
  display: flex;
  flex-direction: column;
}

.deck-card {
  flex: 1;
  background: linear-gradient(180deg, rgba(16, 24, 42, 0.95), rgba(9, 13, 24, 0.98));
  border: 1px solid rgba(250, 204, 21, 0.32);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.52);
}

.arena-deck-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.2px;
  color: #fde047;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(250, 204, 21, 0.2);
}

.arena-live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 10px #4ade80;
}

.rank-banner-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.12), rgba(15, 23, 42, 0.92));
  border: 1px solid rgba(250, 204, 21, 0.36);
  border-radius: 12px;
  padding: 10px 12px;
}

.rank-crest-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(250, 204, 21, 0.35));
}

.rank-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rank-kicker {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fbbf24;
}

.rank-meta strong {
  font-size: 14.5px;
  color: #fffbeb;
}

.rank-meta small {
  font-size: 11.5px;
  color: #cbd5e1;
}

.custom-room-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #94a3b8;
  margin-top: 2px;
}

.custom-room-divider::before,
.custom-room-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(71, 85, 105, 0.55);
}

.btn.cta-launch.searching {
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
  color: #ffffff;
  border-color: #fca5a5;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}
.btn.cta-launch.searching .cta-sub {
  color: rgba(255, 255, 255, 0.85);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  background: #080d18;
  padding: 5px;
  border-radius: 11px;
  border: 1px solid #1e293b;
}

.mode-tab {
  position: relative;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 12.5px;
  font-weight: 800;
  padding: 9px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.mode-tab:hover {
  color: #f1f5f9;
}

.mode-tab.active {
  background: linear-gradient(180deg, #1e293b, #0f172a);
  color: #fde047;
  border: 1px solid rgba(250, 204, 21, 0.42);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.tab-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
  vertical-align: middle;
  margin-left: 3px;
}

.mode-pane {
  display: none;
  flex-direction: column;
  gap: 13px;
  flex: 1;
}

.mode-pane.active {
  display: flex;
}

.pane-desc {
  font-size: 12.5px;
  color: #94a3b8;
  line-height: 1.45;
}

/* Thẻ Đối Đầu Trực Quan (Phe Bạn VS Phe Máy) */
.vs-preview-card {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  background: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.72), rgba(9, 13, 24, 0.95));
  border: 1px solid rgba(71, 85, 105, 0.65);
  border-radius: 12px;
  padding: 12px 10px;
}

.vs-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 3px;
  min-width: 0;
}

.vs-side img {
  width: 46px;
  height: 46px;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.55));
}

.vs-role {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.7px;
  color: #94a3b8;
}

.vs-side strong {
  font-size: 13px;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.vs-badge-center {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #dc2626);
  border: 2px solid #fef08a;
  color: #ffffff;
  font-weight: 900;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.45);
}

.deck-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.deck-field label {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #cbd5e1;
}

.deck-field select {
  width: 100%;
}

/* 3 Thẻ Độ Khó Chiến Thuật */
.diff-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.diff-card {
  background: #0b1220;
  border: 1.5px solid #293548;
  border-radius: 10px;
  padding: 8px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  transition: all 0.15s ease;
}

.diff-card strong {
  font-size: 12px;
  color: #e2e8f0;
}

.diff-card small {
  font-size: 10px;
  color: #94a3b8;
}

.diff-card:hover {
  border-color: #64748b;
}

.diff-card.active {
  background: rgba(234, 179, 8, 0.14);
  border-color: #fbbf24;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.2);
}

.diff-card.active strong {
  color: #fef08a;
}

.btn-row, .join-code-row {
  display: flex;
  gap: 8px;
}

.flex-1 {
  flex: 1;
}

.join-code-row input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Nút Bấm Chuẩn Game (Dùng chung cho cả Sảnh Chính & Chiến Trường) */
.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.985); }
.btn.full { width: 100%; margin-top: auto; }
.btn.primary { background: linear-gradient(90deg, #eab308, #f97316); color: #0f172a; }
.btn.gold { background: linear-gradient(180deg, #fde047, #eab308); color: #0f172a; }
.btn.accent { background: #0284c7; color: #f8fafc; }
.btn.secondary { background: #334155; color: #f1f5f9; }

.btn.cta-launch {
  background: linear-gradient(180deg, #fde047 0%, #f59e0b 52%, #ea580c 100%);
  color: #090d16;
  border: 1px solid #fef08a;
  box-shadow: 0 6px 22px rgba(245, 158, 11, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.btn.cta-launch:hover {
  box-shadow: 0 8px 28px rgba(245, 158, 11, 0.58), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.cta-main {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.6px;
}

.cta-sub {
  font-size: 11px;
  font-weight: 700;
  color: rgba(9, 13, 22, 0.78);
}

.btn.accent-outline {
  background: rgba(14, 165, 233, 0.16);
  border: 1.5px solid #38bdf8;
  color: #e0f2fe;
}

.btn.gold-outline {
  background: linear-gradient(180deg, rgba(250, 204, 21, 0.18), rgba(234, 88, 12, 0.18));
  border: 1.5px solid #fbbf24;
  color: #fef08a;
  padding: 13px 16px;
  font-size: 14px;
}

.waiting-box {
  background: rgba(234, 179, 8, 0.14);
  border: 1px dashed #eab308;
  color: #fef08a;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  text-align: center;
}

.open-rooms-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.mini-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
}
.open-rooms-list {
  min-height: 92px;
  max-height: 150px;
  overflow-y: auto;
  background: #080c17;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
  color: #64748b;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #131c2e;
  border: 1px solid #293548;
  color: #e2e8f0;
  padding: 6px 10px;
  border-radius: 8px;
}
.room-item button {
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: 6px;
  border: none;
  background: #22c55e;
  color: #052e16;
  font-weight: 800;
  cursor: pointer;
}

.deck-rules-footer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(51, 65, 85, 0.6);
  margin-top: auto;
}

.rule-pill {
  background: rgba(11, 18, 32, 0.85);
  border: 1px solid rgba(51, 65, 85, 0.65);
  border-radius: 8px;
  padding: 6px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1px;
  font-size: 10.5px;
}

.rule-pill strong {
  color: #f8fafc;
  font-size: 11px;
}

.rule-pill span {
  color: #94a3b8;
  font-size: 10px;
}

/* ========================================================================== */
/* MÀN HÌNH CHIẾN TRƯỜNG RTS 1V1                                              */
/* ========================================================================== */
#game-screen {
  position: relative;
  flex-direction: column;
  overflow: hidden;
}

.battle-viewport {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

#battle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

#top-hud {
  height: 48px;
  flex-shrink: 0;
  background: rgba(9, 13, 22, 0.96);
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 30;
  gap: 6px;
  white-space: nowrap;
  overflow-x: auto;
  touch-action: pan-x;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

.faction-pill {
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  background: #1e293b;
  border: 1px solid #475569;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.res-box, .pop-box {
  background: #111827;
  border: 1px solid #293548;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pop-box.warn {
  border-color: #eab308;
  color: #fde047;
}
.pop-box.maxed {
  border-color: #ef4444;
  background: rgba(127, 29, 29, 0.45);
  color: #fca5a5;
}

.altar-banner {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(168, 85, 247, 0.45);
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 600;
  color: #e9d5ff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hud-btn {
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #f8fafc;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.hud-btn:hover:not(:disabled) {
  filter: brightness(1.15);
}
.hud-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}
.peace-btn {
  background: linear-gradient(180deg, rgba(6, 95, 70, 0.95), rgba(4, 47, 46, 0.96));
  border-color: #34d399;
  color: #ecfdf5;
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.25);
}
.peace-btn.warn-ending {
  background: linear-gradient(180deg, rgba(146, 64, 14, 0.95), rgba(120, 53, 15, 0.96));
  border-color: #fbbf24;
  color: #fef08a;
}
.peace-btn.esc-tier-1 {
  background: linear-gradient(180deg, rgba(30, 58, 138, 0.94), rgba(15, 23, 42, 0.96));
  border-color: #38bdf8;
  color: #e0f2fe;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.22);
}
.peace-btn.esc-tier-2 {
  background: linear-gradient(180deg, rgba(146, 64, 14, 0.95), rgba(69, 26, 3, 0.96));
  border-color: #f59e0b;
  color: #fef3c7;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.28);
}
.peace-btn.esc-tier-3 {
  background: linear-gradient(180deg, rgba(154, 52, 18, 0.95), rgba(67, 20, 7, 0.96));
  border-color: #f97316;
  color: #ffedd5;
  box-shadow: 0 0 11px rgba(249, 115, 22, 0.32);
}
.peace-btn.esc-tier-4,
.peace-btn.esc-tier-5 {
  background: linear-gradient(180deg, rgba(153, 27, 27, 0.96), rgba(69, 10, 10, 0.98));
  border-color: #facc15;
  color: #fef08a;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.45);
}
.age-btn {
  background: linear-gradient(90deg, #b45309, #eab308);
  color: #090d16;
  border-color: #fde047;
}
.ult-btn {
  background: linear-gradient(90deg, #581c87, #be185d);
  border-color: #f472b6;
}
.hud-btn.danger {
  background: #7f1d1d;
  border-color: #ef4444;
}

.speed-group {
  display: flex;
  gap: 3px;
}
.spd-btn {
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid #334155;
  padding: 4px 7px;
  border-radius: 5px;
  font-size: 11.5px;
  cursor: pointer;
}
.spd-btn.active {
  background: #eab308;
  color: #090d16;
  font-weight: 700;
}

.cursor-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1.5px solid #fbbf24;
  color: #fef08a;
  padding: 6px 10px 6px 14px;
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 700;
  z-index: 32;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 94vw;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

.cursor-banner.hidden {
  display: none !important;
}

.banner-cancel-btn {
  background: #dc2626;
  color: #ffffff;
  border: 1px solid #fca5a5;
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

.toast-feed {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 25;
  pointer-events: none;
  max-width: 420px;
}

.toast-item {
  background: rgba(15, 23, 42, 0.9);
  border-left: 3px solid #fbbf24;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  color: #f1f5f9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

#bottom-dock {
  height: 230px;
  flex-shrink: 0;
  background: rgba(9, 13, 22, 0.97);
  border-top: 1.5px solid #334155;
  display: grid;
  grid-template-columns: 208px 1fr 520px;
  gap: 12px;
  padding: 8px 12px;
  z-index: 30;
}

.minimap-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
  min-width: 0;
}

.minimap-fold-btn {
  display: none;
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid #64748b;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  font-size: 12px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 4;
  padding: 0;
}

#minimap-canvas {
  border: 1.5px solid #475569;
  border-radius: 6px;
  background: #060b13;
  cursor: pointer;
  width: 186px;
  height: 186px;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.minimap-caption {
  font-size: 10.5px;
  color: #94a3b8;
}

.selection-panel {
  background: #0f172a;
  border: 1px solid #293548;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.sel-main-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.sel-portrait-frame {
  width: 68px;
  height: 68px;
  flex-shrink: 0;
  background: radial-gradient(circle, #1e293b 0%, #090d16 100%);
  border: 1.5px solid #fbbf24;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.sel-portrait-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sel-info-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.sel-header {
  font-size: 15px;
  font-weight: 700;
  color: #fef08a;
}

.sel-body {
  font-size: 12.5px;
  color: #cbd5e1;
  line-height: 1.45;
}

/* Thanh Tiến Trình Mua Dân / Mua Quân & Nghiên Cứu Chuẩn Đồ Họa (Không bao giờ đè chữ!) */
.sel-queue {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  margin-top: 3px;
}

.sel-queue.hidden {
  display: none !important;
}

.q-progress-box {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 25px;
  background: #070b14;
  border: 1px solid #475569;
  border-radius: 7px;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.q-progress-box.is-blocked {
  border-color: #ef4444;
  background: rgba(69, 10, 10, 0.72);
}

.q-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(234, 179, 8, 0.52), rgba(34, 197, 94, 0.65));
  border-right: 1.5px solid #4ade80;
  transition: width 0.09s linear;
  pointer-events: none;
}

.q-progress-box.is-blocked .q-progress-fill {
  background: linear-gradient(90deg, rgba(220, 38, 38, 0.55), rgba(249, 115, 22, 0.55));
  border-right-color: #f87171;
}

.q-progress-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
  font-size: 11.5px;
  font-weight: 800;
  pointer-events: none;
}

.q-progress-label {
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.q-progress-box.is-blocked .q-progress-label {
  color: #fecaca;
}

.q-progress-pct {
  color: #fde047;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.q-wait-badge {
  flex-shrink: 0;
  height: 25px;
  padding: 0 7px;
  border-radius: 7px;
  background: rgba(14, 116, 144, 0.35);
  border: 1px solid #38bdf8;
  color: #e0f2fe;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.q-cancel-btn {
  flex-shrink: 0;
  width: 27px;
  height: 25px;
  border-radius: 7px;
  background: rgba(185, 28, 28, 0.88);
  border: 1px solid #fca5a5;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.command-panel {
  background: #0f172a;
  border: 1px solid #293548;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cmd-header {
  font-size: 11.5px;
  font-weight: 700;
  color: #fbbf24;
  letter-spacing: 0.5px;
}

.cmd-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.cmd-btn {
  position: relative;
  overflow: hidden;
  background: #172033;
  border: 1.5px solid #334155;
  border-radius: 8px;
  padding: 5px 7px;
  color: #f1f5f9;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s ease, border-color 0.12s, background 0.12s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.cmd-btn .c-qbadge {
  position: absolute;
  top: 2px;
  right: 3px;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  border-radius: 99px;
  background: #eab308;
  color: #090d16;
  font-size: 9.5px;
  font-weight: 900;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
.cmd-btn .c-qbadge.visible {
  display: inline-flex;
}
.cmd-btn .c-pbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3.5px;
  background: rgba(9, 13, 22, 0.85);
  display: none;
  pointer-events: none;
}
.cmd-btn .c-pbar.visible {
  display: block;
}
.cmd-btn .c-pbar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #facc15, #4ade80);
  transition: width 0.09s linear;
}
.cmd-btn:hover:not(.is-disabled):not(:disabled) {
  border-color: #fbbf24;
  background: #1e293b;
}
.cmd-btn:active:not(.is-disabled):not(:disabled),
.cmd-btn.tap-flash {
  transform: scale(0.96);
  border-color: #4ade80 !important;
  background: rgba(20, 83, 45, 0.85) !important;
}
.cmd-btn:disabled,
.cmd-btn.is-disabled {
  opacity: 0.42;
}
.cmd-btn .c-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  object-fit: contain;
  pointer-events: none;
}
.cmd-btn .c-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
  pointer-events: none;
}
.cmd-btn .c-title {
  font-size: 11px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  gap: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmd-btn .c-cost {
  font-size: 9.8px;
  color: #fcd34d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmd-btn .kbd {
  color: #38bdf8;
  font-weight: 800;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 15, 0.84);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  background: #0f172a;
  border: 2px solid #fbbf24;
  border-radius: 14px;
  padding: 24px 28px;
  width: 530px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.gameover-crest {
  width: 78px;
  height: 78px;
}

.stats-compare {
  width: 100%;
  background: #090d16;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  text-align: left;
  line-height: 1.65;
}

/* ========================================================================== */
/* THANH CÔNG CỤ NGÓN CÁI MOBILE & BỐ CỤC ĐÁP ỨNG (PORTRAIT + LANDSCAPE)       */
/* ========================================================================== */
/* CHỈ khóa touch-action trên 2 canvas vẽ bản đồ — tuyệt đối KHÔNG khóa trên #game-screen để các nút và bảng cuộn cảm ứng nhạy 100%! */
#battle-canvas,
#minimap-canvas {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-screen {
  user-select: none;
  -webkit-user-select: none;
}

.selection-panel {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

#game-screen button,
#lobby-screen button,
.queue-chip {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* Tuyệt đối ẩn toàn bộ nhãn phím tắt bàn phím trên thiết bị cảm ứng & điện thoại */
body.touch-ui .cmd-btn .kbd {
  display: none !important;
}
@media (pointer: coarse), (hover: none), (max-width: 960px) {
  .cmd-btn .kbd {
    display: none !important;
  }
}

/* Khi Minimap nằm gọn trong #battle-viewport (màn hình dọc ĐT) — luôn nằm DƯỚI thanh chỉ số #top-hud 100% không bao giờ đè chữ! */
.minimap-panel.in-viewport {
  position: absolute;
  top: 8px;
  left: max(8px, env(safe-area-inset-left));
  z-index: 24;
  background: rgba(9, 13, 22, 0.88);
  padding: 3px;
  border-radius: 9px;
  border: 1.5px solid #475569;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
}

.minimap-panel.in-viewport .minimap-fold-btn {
  display: inline-flex;
}

.minimap-panel.in-viewport .minimap-caption {
  display: none;
}

.minimap-panel.in-viewport #minimap-canvas {
  width: 88px !important;
  height: 88px !important;
}

.minimap-panel.in-viewport.folded {
  width: 34px;
  height: 34px;
  padding: 0;
}

.minimap-panel.in-viewport.folded #minimap-canvas {
  display: none !important;
}

.minimap-panel.in-viewport.folded .minimap-fold-btn {
  position: static;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  font-size: 16px;
}

.touch-squad-bar {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 26;
}

.m-sbtn {
  width: 52px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  padding: 2px;
}

.m-sbtn:active,
.m-qbtn:active {
  transform: scale(0.94);
}

.m-sbtn .s-badge {
  width: 18px;
  height: 18px;
  border-radius: 99px;
  background: #1e293b;
  border: 1px solid #64748b;
  font-size: 11px;
  font-weight: 900;
  color: #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.m-sbtn.has-units {
  border-color: #38bdf8;
  background: rgba(12, 74, 110, 0.9);
}

.m-sbtn.has-units .s-badge {
  background: #0284c7;
  border-color: #bae6fd;
  color: #ffffff;
}

.m-sbtn span {
  font-size: 15px;
  line-height: 1;
}

.m-sbtn small {
  font-size: 8.8px;
  font-weight: 700;
  color: #cbd5e1;
  line-height: 1;
  white-space: nowrap;
}

.mobile-quick-bar {
  position: absolute;
  right: max(8px, env(safe-area-inset-right));
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 26;
}

.m-qbtn {
  width: 50px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  padding: 2px;
}

.m-qbtn.has-idle {
  border-color: #fbbf24;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.45);
}

.m-qbtn img {
  width: 19px;
  height: 19px;
  pointer-events: none;
}

.m-qbtn span {
  font-size: 15px;
  line-height: 1;
  pointer-events: none;
}

.m-qbtn small {
  font-size: 9px;
  font-weight: 700;
  color: #cbd5e1;
  line-height: 1;
  pointer-events: none;
}

.m-qbtn.active {
  border-color: #4ade80;
  background: rgba(20, 83, 45, 0.92);
  box-shadow: 0 0 12px rgba(74, 222, 128, 0.5);
}

.m-qbtn.active-atk {
  border-color: #f43f5e;
  background: rgba(136, 19, 55, 0.92);
  box-shadow: 0 0 12px rgba(244, 63, 94, 0.55);
}

.mobile-build-confirm {
  position: absolute;
  left: 50%;
  bottom: 58px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(9, 13, 22, 0.96);
  border: 1.5px solid #4ade80;
  padding: 7px 11px;
  border-radius: 99px;
  z-index: 28;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.65);
  max-width: 95vw;
  white-space: nowrap;
}

.mobile-build-confirm .btn {
  padding: 9px 13px;
  font-size: 12.5px;
  min-height: 40px;
}

.mobile-build-confirm .btn.active-multi {
  background: #0284c7;
  color: #ffffff;
  border: 1px solid #7dd3fc;
}

#bottom-dock.dock-collapsed {
  height: 0 !important;
  padding: 0 !important;
  border-top: none !important;
  overflow: hidden !important;
}

/* Tablet & Laptop nhỏ (không bao giờ để minimap 196px tràn sang cột chỉ số!) */
@media (max-width: 1100px) {
  .lobby-main-grid { grid-template-columns: 1fr; }
  .faction-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .showcase-middle { grid-template-columns: 1fr; }
  #bottom-dock { grid-template-columns: 172px 1fr 340px; }
  #bottom-dock #minimap-canvas {
    width: 154px;
    height: 154px;
  }
}

/* Điện thoại Màn Hình Dọc & Ngang Nhỏ (Mobile <= 860px) */
@media (max-width: 860px) {
  #lobby-screen {
    padding: 10px 10px 28px;
  }
  .lobby-header {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 10px;
  }
  .commander-bar {
    justify-content: space-between;
  }
  .lobby-header h1 {
    font-size: 20px;
  }
  .section-hint {
    display: none;
  }
  .faction-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .fc-ult-mini {
    display: none;
  }
  .showcase-ult-card {
    max-width: 100%;
    width: 100%;
  }
  .unit-roster-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  input, select {
    font-size: 16px; /* Ngăn iOS tự động zoom khi chạm ô nhập */
  }

  #top-hud {
    height: auto;
    min-height: 60px;
    flex-wrap: wrap;
    padding: max(4px, env(safe-area-inset-top)) 6px 4px;
    gap: 4px;
  }
  .hud-left, .hud-right {
    gap: 4px;
    flex-wrap: wrap;
  }
  .hud-center,
  .pop-box small {
    display: none;
  }
  .res-box, .pop-box, .faction-pill {
    padding: 3px 6px;
    font-size: 11.5px;
    gap: 4px;
  }
  .hud-icon {
    width: 16px;
    height: 16px;
  }
  .hud-btn {
    padding: 5px 8px;
    font-size: 11.5px;
    min-height: 30px;
  }

  .toast-feed {
    top: 8px;
    left: 104px;
    right: 58px;
    max-width: none;
  }
  .toast-item {
    font-size: 11px;
    padding: 4px 7px;
  }

  #bottom-dock {
    height: 224px;
    grid-template-columns: 1fr;
    grid-template-rows: 70px 1fr;
    gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .selection-panel {
    padding: 6px 8px;
    overflow: hidden;
  }
  .selection-panel.has-queue .sel-body {
    display: none !important;
  }
  .sel-portrait-frame {
    width: 46px;
    height: 46px;
  }
  .sel-header {
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sel-body {
    font-size: 11px;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .command-panel {
    padding: 5px 6px;
    min-height: 0;
  }
  .cmd-header {
    display: none;
  }
  .cmd-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .cmd-btn {
    min-height: 46px;
    padding: 5px 7px;
  }
  .cmd-btn .c-icon {
    width: 29px;
    height: 29px;
  }
  .cmd-btn .c-title {
    font-size: 11.5px;
  }

  .touch-squad-bar {
    left: max(6px, env(safe-area-inset-left));
    bottom: 8px;
    flex-direction: column;
    gap: 5px;
  }
  .m-sbtn {
    width: 48px;
    height: 40px;
  }
  .mobile-quick-bar {
    right: max(6px, env(safe-area-inset-right));
    bottom: 8px;
    flex-direction: column;
    gap: 4px;
  }
  .m-qbtn {
    width: 46px;
    height: 39px;
  }
  .mobile-build-confirm {
    bottom: 12px;
    padding: 6px 9px;
    gap: 6px;
  }
  .cursor-banner {
    top: 8px;
    font-size: 11.5px;
    padding: 5px 8px 5px 11px;
  }
}

/* Điện thoại Xoay Ngang (Mobile Landscape <= 560px chiều cao — Chuẩn Vàng Chơi RTS!) */
@media (max-height: 560px) {
  #top-hud {
    height: 38px;
    min-height: 38px;
    flex-wrap: nowrap;
    padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
    gap: 5px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #top-hud::-webkit-scrollbar {
    display: none;
  }
  .hud-left, .hud-right {
    gap: 4px;
    flex-shrink: 0;
  }
  .hud-center,
  .pop-box small {
    display: none;
  }
  .res-box, .pop-box, .faction-pill {
    padding: 2px 6px;
    font-size: 11px;
    gap: 3px;
  }
  .hud-icon {
    width: 15px;
    height: 15px;
  }
  .hud-btn {
    padding: 4px 8px;
    font-size: 11px;
    gap: 3px;
    min-height: 28px;
  }

  #bottom-dock {
    height: 112px;
    grid-template-columns: 104px minmax(165px, 200px) 1fr;
    grid-template-rows: 1fr;
    gap: 8px;
    padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  #bottom-dock .minimap-panel {
    position: relative;
    background: transparent;
    border: none;
    padding: 0;
  }
  #bottom-dock #minimap-canvas {
    width: 94px !important;
    height: 94px !important;
  }
  .minimap-caption {
    display: none;
  }
  .selection-panel {
    padding: 5px 7px;
    overflow: hidden;
  }
  .selection-panel.has-queue .sel-body {
    display: none !important;
  }
  .sel-portrait-frame {
    width: 42px;
    height: 42px;
  }
  .sel-header {
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sel-body {
    font-size: 10.5px;
    line-height: 1.24;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .command-panel {
    padding: 4px 6px;
    min-height: 0;
  }
  .cmd-header {
    display: none;
  }
  .cmd-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }
  .cmd-btn {
    min-height: 44px;
    padding: 4px 6px;
  }

  .toast-feed {
    top: 6px;
    left: 10px;
    right: auto;
    max-width: 340px;
  }
  .touch-squad-bar {
    flex-direction: row;
    left: max(8px, env(safe-area-inset-left));
    bottom: 8px;
    gap: 5px;
  }
  .m-sbtn {
    width: 46px;
    height: 40px;
  }
  .mobile-quick-bar {
    flex-direction: row;
    right: max(8px, env(safe-area-inset-right));
    bottom: 8px;
    gap: 5px;
  }
  .m-qbtn {
    width: 44px;
    height: 40px;
  }
  .mobile-build-confirm {
    bottom: 54px;
  }
  .cursor-banner {
    top: 6px;
    font-size: 11.5px;
  }
}

/* ========================================================================== */
/* HỘP THOẠI XÁC NHẬN THOÁT TRẬN / PHỤC HỒI TRẬN KHI ẤN LOAD TRANG           */
/* ========================================================================== */
.confirm-leave-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(5, 9, 18, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.confirm-leave-box {
  max-width: 440px;
  width: 100%;
  border: 1.5px solid rgba(250, 204, 21, 0.52);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.72);
  text-align: center;
  padding: 22px 20px 20px;
}

.confirm-leave-icon {
  font-size: 38px;
  line-height: 1;
  margin-bottom: 8px;
}

.confirm-leave-box h2 {
  font-size: 20px;
  font-weight: 900;
  color: #fde047;
  margin-bottom: 8px;
}

.confirm-leave-box p {
  font-size: 14px;
  line-height: 1.45;
  color: #e2e8f0;
  margin-bottom: 18px;
}

.confirm-leave-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.confirm-stay-btn {
  flex: 1 1 175px;
  min-height: 46px;
  font-size: 14px;
  font-weight: 800;
  touch-action: manipulation;
}

.confirm-exit-btn {
  flex: 1 1 145px;
  min-height: 46px;
  font-size: 14px;
  font-weight: 800;
  background: linear-gradient(180deg, #dc2626, #991b1b);
  color: #fff;
  border: 1px solid #f87171;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.confirm-exit-btn:hover {
  filter: brightness(1.1);
}

