/* ================= GIAO DIỆN GIAO DỊCH NGẦM & CHAT TRẬN ĐẤU (CHUẨN FANTASY PIXEL RPG) ================= */
/* TUYỆT ĐỐI KHÔNG DÙNG OVERFLOW: AUTO / SCROLL Ở BẤT KỲ ĐÂU */

/* 1. Nút trên thanh công cụ và badge */
.trade-toolbar-btn, .chat-toolbar-btn, .pin-toolbar-btn {
  position: relative !important;
}

.pin-toolbar-btn.active {
  background: linear-gradient(180deg, #9333ea, #6b21a8) !important;
  color: #fdf4ff !important;
  border-color: #f5d0fe !important;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.7) !important;
}

.toolbar-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.9);
  animation: tradeBadgePulse 1.8s infinite;
  pointer-events: none;
}

@keyframes tradeBadgePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 6px rgba(239, 68, 68, 0.8); }
  50% { transform: scale(1.15); box-shadow: 0 0 14px rgba(239, 68, 68, 1); }
}

/* 2. Thanh mini bar thu gọn giao dịch (Yêu cầu 2.8) */
.trade-minimized-bar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 92;
  background: linear-gradient(135deg, rgba(17, 32, 51, 0.97), rgba(24, 45, 74, 0.97));
  border: 1.5px solid #f7d286;
  border-radius: 24px;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7), 0 0 12px rgba(247, 210, 134, 0.4);
  backdrop-filter: blur(8px);
  animation: tradeMiniGlow 3s ease-in-out infinite alternate;
}

@keyframes tradeMiniGlow {
  from { box-shadow: 0 6px 20px #000b, 0 0 8px #f7d2864d; }
  to { box-shadow: 0 6px 20px #000b, 0 0 15px #f7d28675; }
}
.reduced-motion .trade-minimized-bar { animation:none; }

.trade-mini-icon {
  font-size: 18px;
  color: #ffe3a1;
}

.trade-mini-text {
  font-size: 12px;
  font-weight: 700;
  color: #f7d286;
  white-space: nowrap;
}

.trade-mini-btn {
  background: linear-gradient(180deg, #f7d286, #c69c46) !important;
  color: #111e30 !important;
  font-size: 11px !important;
  font-weight: 800 !important;
  padding: 4px 10px !important;
  min-height: 26px !important;
  border-radius: 13px !important;
  border: none !important;
  cursor: pointer !important;
}

/* 3. Popup Giao dịch ngầm độc lập (Đúng mẫu 2 khung đã chốt) */
.trade-standalone-backdrop {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(5, 11, 20, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.trade-standalone-panel {
  position: relative;
  background: linear-gradient(180deg, #132438 0%, #0d1827 100%);
  border: 2px solid #f7d286;
  border-radius: 12px;
  width: min(860px, calc(100vw - 20px));
  max-height: min(calc(100% - 16px), calc(100dvh - 20px));
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.8), 0 0 20px rgba(247, 210, 134, 0.25);
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  gap: 10px;
  overflow: hidden; /* Tuyệt đối không cuộn */
}

/* Header popup */
.trade-standalone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(247, 210, 134, 0.25);
  padding-bottom: 8px;
  flex-shrink: 0;
}

.trade-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.trade-header-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #ffe3a1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.trade-participants-badge {
  background: rgba(247, 210, 134, 0.15);
  border: 1px solid rgba(247, 210, 134, 0.35);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  color: #f3ead7;
  font-weight: 600;
}

.trade-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.trade-header-btn {
  background: #1e3650 !important;
  color: #ffe3a1 !important;
  border: 1px solid rgba(247, 210, 134, 0.35) !important;
  border-radius: 6px !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  padding: 4px 10px !important;
  min-height: 28px !important;
  cursor: pointer !important;
  transition: all 0.15s ease;
}

.trade-header-btn:hover {
  background: #2a4c72 !important;
  border-color: #f7d286 !important;
}

.trade-header-btn.mini {
  background: #172b3e !important;
  color: #9cb1cb !important;
}

/* Dải timer / vòng mặc cả */
.trade-timer-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(12, 23, 37, 0.85);
  border: 1px solid rgba(247, 210, 134, 0.2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  flex-shrink: 0;
}

.trade-round-text {
  font-weight: 800;
  color: #f59e0b;
  letter-spacing: 0.5px;
}

.trade-countdown-text {
  font-weight: 700;
  color: #ffe3a1;
}

/* Thân 2 khung đối xứng: Khung trái Bạn Đưa | Khung phải Bạn Nhận */
.trade-two-frames {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

@media (max-width: 680px) {
  .trade-two-frames {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
}

.trade-frame {
  background: rgba(14, 25, 41, 0.85);
  border: 1.5px solid rgba(247, 210, 134, 0.22);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow: hidden;
}

.trade-frame-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(247, 210, 134, 0.15);
  padding-bottom: 4px;
  flex-shrink: 0;
}

.trade-frame-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #ffe3a1;
}

.trade-frame-cash {
  font-size: 11px;
  color: #9cb1cb;
  font-weight: 600;
}

/* 4 Danh mục thu gọn / mở rộng */
.trade-categories-accordion {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.trade-category-box {
  background: #111f32;
  border: 1px solid rgba(247, 210, 134, 0.14);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.trade-category-box.open {
  border-color: rgba(247, 210, 134, 0.3);
  background: #14253c;
  flex: 1;
  min-height: 0;
}

.trade-cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.15);
  user-select: none;
  flex-shrink: 0;
}

.trade-cat-title {
  font-size: 11px;
  font-weight: 700;
  color: #f3ead7;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cat-icon {
  font-style: normal;
  font-size: 13px;
}

.trade-cat-summary {
  font-size: 10px;
  color: #f7d286;
  font-weight: 600;
}

.trade-cat-toggle {
  background: none !important;
  border: none !important;
  color: #ffe3a1 !important;
  font-size: 10px !important;
  cursor: pointer !important;
  padding: 0 4px !important;
  min-height: auto !important;
}

.trade-cat-body {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-height: 0;
  overflow: hidden; /* Không cuộn */
}

/* Danh mục 1: Tiền (Nhập tự do số nguyên không âm) */
.trade-cash-input-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #bfccdc;
}

.trade-cash-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.trade-cash-input {
  flex: 1;
  background: #0e1927;
  border: 1.5px solid rgba(247, 210, 134, 0.4);
  border-radius: 4px;
  color: #ffe3a1;
  font-size: 14px;
  font-weight: 800;
  padding: 4px 8px;
  text-align: right;
  min-width: 0;
}

.trade-cash-input:focus {
  outline: none;
  border-color: #f7d286;
  box-shadow: 0 0 8px rgba(247, 210, 134, 0.4);
}

.trade-cash-unit {
  font-size: 12px;
  color: #f7d286;
  font-weight: 700;
}

/* Danh sách tài sản & phân trang (Tuyệt đối không cuộn) */
.trade-items-paged-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.trade-item-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #182a40;
  border: 1px solid rgba(247, 210, 134, 0.15);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.trade-item-row:hover {
  background: #203957;
  border-color: rgba(247, 210, 134, 0.4);
}

.trade-item-row.is-selected {
  background: #24446b;
  border-color: #f7d286;
  box-shadow: 0 0 6px rgba(247, 210, 134, 0.25);
}

.trade-item-check {
  width: 14px;
  height: 14px;
  accent-color: #f7d286;
  cursor: pointer;
  flex-shrink: 0;
}

.trade-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.trade-item-name {
  color: #f3ead7;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trade-item-price {
  color: #ffe3a1;
  font-weight: 700;
  font-size: 10px;
  flex-shrink: 0;
}

.trade-paged-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(247, 210, 134, 0.1);
  padding-top: 3px;
  margin-top: auto;
  flex-shrink: 0;
}

.trade-page-btn {
  background: #192e44 !important;
  color: #ffe3a1 !important;
  border: 1px solid rgba(247, 210, 134, 0.25) !important;
  border-radius: 4px !important;
  font-size: 9px !important;
  padding: 2px 6px !important;
  min-height: 20px !important;
  cursor: pointer !important;
}

.trade-page-btn:disabled {
  opacity: 0.35 !important;
  cursor: not-allowed !important;
}

.trade-page-info {
  font-size: 9px;
  color: #bfccdc;
}

.trade-empty-hint {
  font-size: 10px;
  color: #64748b;
  font-style: italic;
  text-align: center;
  padding: 6px 0;
}

/* Bảng tóm tắt giao dịch */
.trade-summary-table {
  background: #0b1522;
  border: 1.5px solid rgba(247, 210, 134, 0.28);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.trade-summary-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trade-summary-col.want {
  text-align: right;
}

.trade-summary-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #f7d286;
}

.trade-sum-row {
  font-size: 12px;
  color: #ffe3a1;
  font-weight: 700;
}

.trade-sum-row-assets {
  font-size: 10px;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trade-summary-divider {
  font-size: 18px;
  font-weight: 900;
  color: #f7d286;
  padding: 0 4px;
}

/* Footer nút bấm */
.trade-standalone-footer {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid rgba(247, 210, 134, 0.2);
  padding-top: 8px;
  flex-shrink: 0;
}

.trade-footer-btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.trade-btn-primary {
  background: linear-gradient(180deg, #f7d286, #c69c46) !important;
  color: #111e30 !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  padding: 6px 16px !important;
  border-radius: 6px !important;
  border: none !important;
  cursor: pointer !important;
  box-shadow: 0 3px 10px rgba(247, 210, 134, 0.3) !important;
}

.trade-btn-secondary {
  background: #1f344d !important;
  color: #f1f5f9 !important;
  border: 1px solid rgba(247, 210, 134, 0.3) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 6px 14px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
}

.trade-btn-danger {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #fca5a5 !important;
  border: 1px solid rgba(239, 68, 68, 0.5) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 6px 14px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
}

/* Modal con Đổi người */
.trade-switch-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 22, 0.92);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.trade-switch-box {
  background: #142438;
  border: 1.5px solid #f7d286;
  border-radius: 10px;
  width: min(480px, 100%);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trade-switch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  color: #ffe3a1;
  font-size: 13px;
}

.trade-switch-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.trade-switch-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1a2f48;
  border: 1px solid rgba(247, 210, 134, 0.2);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  text-align: left;
  color: #f3ead7;
}

.trade-switch-card:hover:not(:disabled) {
  background: #234063;
  border-color: #f7d286;
}

.trade-switch-avatar {
  width: 32px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.trade-switch-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trade-switch-name {
  font-size: 12px;
  font-weight: 700;
  color: #ffe3a1;
}

.trade-switch-stats {
  font-size: 10px;
  color: #bfccdc;
}

.trade-switch-confirm-box {
  background: rgba(220, 38, 38, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  color: #fca5a5;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trade-switch-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* 4. Khung chat trong trận (3.1) - Tuyệt đối không cuộn */
.match-chat-panel {
  position: absolute;
  bottom: 50px;
  right: calc(var(--hud-rail, 160px) + 12px);
  width: 290px;
  background: linear-gradient(180deg, rgba(16, 29, 46, 0.96), rgba(11, 20, 33, 0.96));
  border: 1.5px solid #f7d286;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 85;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(247, 210, 134, 0.2);
  padding-bottom: 4px;
}

.chat-panel-title {
  font-size: 12px;
  font-weight: 800;
  color: #ffe3a1;
}

.chat-close-btn {
  background: none !important;
  border: none !important;
  color: #94a3b8 !important;
  font-size: 14px !important;
  cursor: pointer !important;
  padding: 0 4px !important;
  line-height: 1 !important;
}

.chat-messages-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 140px;
  overflow: hidden; /* Không cuộn */
}

.chat-page-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 110px;
  overflow: hidden;
}

.chat-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
}

.chat-msg-avatar {
  width: 18px;
  height: 24px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.chat-msg-body {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.chat-msg-author {
  font-weight: 700;
  margin-right: 4px;
}

.chat-msg-text {
  color: #f1f5f9;
  word-break: break-word;
}

.chat-pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 3px;
  border-top: 1px solid rgba(247, 210, 134, 0.1);
}

.chat-page-btn {
  background: #17273a !important;
  color: #ffe3a1 !important;
  border: 1px solid rgba(247, 210, 134, 0.25) !important;
  border-radius: 3px !important;
  font-size: 9px !important;
  padding: 1px 6px !important;
  min-height: 20px !important;
  cursor: pointer !important;
}

.chat-page-btn:disabled {
  opacity: 0.3 !important;
  cursor: not-allowed !important;
}

.chat-page-num {
  font-size: 9px;
  color: #94a3b8;
}

.chat-quick-emojis {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  padding: 2px 0;
  border-top: 1px solid rgba(247, 210, 134, 0.12);
}

.chat-emoji-btn {
  background: #16263b !important;
  border: 1px solid rgba(247, 210, 134, 0.18) !important;
  border-radius: 4px !important;
  font-size: 13px !important;
  padding: 2px 5px !important;
  cursor: pointer !important;
  line-height: 1.2 !important;
  transition: transform 0.1s ease;
}

.chat-emoji-btn:hover {
  transform: scale(1.2);
  border-color: #f7d286 !important;
}

.chat-input-row {
  display: flex;
  gap: 4px;
}

#chat-input-text {
  flex: 1;
  background: #0d1724;
  border: 1px solid rgba(247, 210, 134, 0.3);
  border-radius: 4px;
  color: #f1f5f9;
  font-size: 11px;
  padding: 4px 6px;
  min-width: 0;
}

#chat-input-text:focus {
  outline: none;
  border-color: #f7d286;
}

.chat-send-btn {
  background: linear-gradient(180deg, #f7d286, #c69c46) !important;
  color: #111e30 !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  padding: 4px 10px !important;
  border-radius: 4px !important;
  border: none !important;
  cursor: pointer !important;
}


/* ================= YÊU CẦU 4: TUYỆT ĐỐI CẤM THANH CUỘN (NO-SCROLL OVERRIDE) ================= */
html, body {
  overflow: hidden !important;
  user-select: none;
}

.app-main, .page, #game, .modalbg, .ranking-content, .portfolio-list, .asset-list {
  overflow: hidden !important;
}

/* Các popup game vừa vặn không cuộn */
.event-popup-panel, .rent-popup-panel, .mode-popup-panel {
  overflow: hidden !important;
  max-height: 96dvh !important;
}

/* Đảm bảo bảng Shop và Portfolio hiển thị dạng lưới phân trang gọn gàng */
.shop-pagination-bar button, .portfolio-pagination-bar button, .ranking-pagination-bar button {
  background: #1b3547 !important;
  color: #ffe3a1 !important;
  border: 1px solid rgba(247, 210, 134, 0.4) !important;
  border-radius: 6px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
}

.shop-pagination-bar button:hover, .portfolio-pagination-bar button:hover, .ranking-pagination-bar button:hover {
  background: #23435a !important;
  border-color: #f7d286 !important;
}

.shop-pagination-bar button:disabled, .portfolio-pagination-bar button:disabled, .ranking-pagination-bar button:disabled {
  opacity: 0.35 !important;
  cursor: not-allowed !important;
}

/* ================= GHIM GỢI Ý LÃNH THỔ (BẢN GHÉP TỪ board-view.css) ================= */
/* 3.2 Ký hiệu Ghim gợi ý lãnh thổ 📍 tím phát sáng, nhấp nháy nhẹ */
.suggest-pin-marker {
  animation: pinDrop 0.35s cubic-bezier(0.18, 1.4, 0.35, 1) both;
}
.pin-halo {
  animation: pinPulseHalo 1.8s ease-in-out infinite;
  transform-origin: 0px -32px;
}
.pin-core-halo {
  animation: pinPulseCore 1.2s ease-in-out infinite alternate;
  transform-origin: 0px -32px;
}
@keyframes pinDrop {
  0% { transform: translateY(-30px); opacity: 0; }
  60% { transform: translateY(2px); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes pinPulseHalo {
  0%, 100% { transform: scale(0.9); opacity: 0.25; }
  50% { transform: scale(1.3); opacity: 0.6; }
}
@keyframes pinPulseCore {
  0% { transform: scale(0.95); opacity: 0.4; }
  100% { transform: scale(1.15); opacity: 0.8; }
}
.board.pin-placement-mode {
  cursor: crosshair !important;
}
.board.pin-placement-mode .iso-tile {
  cursor: crosshair !important;
}

/* ================= 9. PUBLIC LOBBY (SẢNH CÔNG KHAI MỚI) ================= */
.public-lobby-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px 24px;
  box-sizing: border-box;
  overflow: hidden;
}

.pub-lobby-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 14px;
  flex-wrap: wrap;
}

.pub-room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  flex: 1;
  min-height: 0;
  align-content: start;
}

.pub-room-card {
  background: linear-gradient(135deg, rgba(20, 37, 60, 0.95), rgba(12, 22, 38, 0.95));
  border: 1.5px solid rgba(247, 210, 134, 0.4);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.pub-room-card:hover {
  transform: translateY(-2px);
  border-color: #f7d286;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6), 0 0 10px rgba(247, 210, 134, 0.2);
}

.pub-room-code {
  font-family: 'Alviona', monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #ffe3a1;
}

.pub-room-mode {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 600;
}

.pub-room-count {
  font-size: 13px;
  color: #e2e8f0;
  font-weight: 700;
}

.pub-room-status {
  display: inline-block;
  align-self: flex-start;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
}

.pub-room-status.waiting {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.4);
}

.pub-room-status.full {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.4);
}

.pub-room-status.playing {
  background: rgba(147, 51, 234, 0.2);
  color: #c084fc;
  border: 1px solid rgba(192, 132, 252, 0.4);
}

.pub-join-btn {
  margin-top: 4px;
  min-height: 32px !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 4px 14px !important;
  align-self: flex-end;
}

/* ================= 10. POPUP NHẬP MÃ PHÒNG 6 SỐ ================= */
.rcode-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.85);
  backdrop-filter: blur(8px);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.rcode-panel {
  background: linear-gradient(160deg, #162a45, #0c1829);
  border: 2px solid #f7d286;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
  padding: 16px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(247, 210, 134, 0.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  box-sizing: border-box;
}

.rcode-cells {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 6px 0;
  cursor: pointer;
}

.rcode-cell {
  width: 44px;
  height: 52px;
  background: #09121e;
  border: 2px solid rgba(247, 210, 134, 0.35);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Alviona', monospace;
  font-size: 24px;
  font-weight: 800;
  color: #ffe3a1;
  transition: all 0.15s ease;
}

.rcode-cell.active {
  border-color: #f7d286;
  box-shadow: 0 0 10px rgba(247, 210, 134, 0.4);
  background: #0f1d30;
}

.rcode-cell.filled {
  border-color: #f7d286;
  color: #fff;
}

.rcode-error {
  color: #f87171;
  font-size: 11px;
  text-align: center;
  margin: -4px 0 2px;
  font-weight: 600;
}

.rcode-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0;
}

.rcode-key {
  background: linear-gradient(180deg, #1e3656, #14253c) !important;
  border: 1px solid rgba(247, 210, 134, 0.3) !important;
  color: #f1f5f9 !important;
  font-size: 18px !important;
  font-weight: 700 !important;
  border-radius: 8px !important;
  padding: 10px 0 !important;
  min-height: 42px !important;
  cursor: pointer !important;
  transition: all 0.1s ease !important;
}

.rcode-key:active {
  transform: scale(0.95) !important;
  background: #2a4b78 !important;
  border-color: #f7d286 !important;
}

.rcode-key.rcode-clear-all {
  font-size: 11px !important;
  color: #f87171 !important;
}

.rcode-key.rcode-backspace {
  font-size: 18px !important;
  color: #fde047 !important;
}

.rcode-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.rcode-actions button {
  flex: 1;
  min-height: 38px !important;
  font-size: 13px !important;
  font-weight: 700 !important;
}

/* ================= 6. BẢNG LỊCH SỬ GIAO DỊCH RIÊNG (MATCH-HISTORY-PANEL) ================= */
.match-history-panel {
  position: absolute;
  bottom: 50px;
  right: calc(var(--hud-rail, 160px) + 12px);
  width: 320px;
  background: linear-gradient(180deg, rgba(16, 29, 46, 0.98), rgba(11, 20, 33, 0.98));
  border: 1.5px solid #f7d286;
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 85;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.history-page-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 180px;
  overflow: hidden;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(247, 210, 134, 0.15);
  border-radius: 6px;
  padding: 6px 8px;
}

.history-row.invite-top {
  border-color: #f7d286;
  background: rgba(247, 210, 134, 0.08);
}

.history-left {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.history-status-badge {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.history-status-badge.st-pending {
  background: rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  border: 1px solid #fbbf24;
}

.history-status-badge.st-active {
  background: rgba(59, 130, 246, 0.25);
  color: #60a5fa;
  border: 1px solid #60a5fa;
}

.history-status-badge.st-success {
  background: rgba(34, 197, 94, 0.25);
  color: #4ade80;
  border: 1px solid #4ade80;
}

.history-status-badge.st-rejected {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
  border: 1px solid #f87171;
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.history-title {
  font-size: 11px;
  color: #ffe3a1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-terms {
  font-size: 10px;
  color: #cbd5e1;
  line-height: 1.25;
}

.history-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-line .hl-side {
  color: #94a3b8;
  font-weight: 600;
}

.history-time {
  font-size: 9px;
  color: #64748b;
}

.history-open-btn {
  font-size: 10px !important;
  font-weight: 700 !important;
  padding: 3px 8px !important;
  min-height: 24px !important;
  white-space: nowrap !important;
}

.history-empty {
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  padding: 24px 0;
}

/* ================= 3. BONG BÓNG CHAT & EMOJI CẠNH AVATAR ================= */
.chat-bubble {
  position: fixed;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, rgba(20, 36, 58, 0.98), rgba(11, 20, 34, 0.98));
  border: 1.5px solid #f7d286;
  border-radius: 12px;
  padding: 6px 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.75), 0 0 12px rgba(247, 210, 134, 0.3);
  max-width: 220px;
  min-height: 36px;
  pointer-events: none;
  animation: popInBubble 0.25s cubic-bezier(0.18, 1.4, 0.35, 1) both;
}

@keyframes popInBubble {
  0% { opacity: 0; transform: scale(0.65) translateY(10px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.chat-bubble-avatar {
  width: 24px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.chat-bubble-text {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.25;
  word-break: break-word;
  text-shadow: 0 1px 2px #000;
}

.chat-bubble-tail {
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
}

/* ================= 7. HỆ THỐNG BẠN BÈ (MODAL) ================= */
.friends-modal-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.friends-tabs-header {
  display: flex;
  gap: 6px;
  border-bottom: 1.5px solid rgba(247, 210, 134, 0.25);
  padding-bottom: 6px;
}

.friends-tab-btn {
  background: none !important;
  border: 1px solid transparent !important;
  color: #94a3b8 !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  padding: 5px 12px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
}

.friends-tab-btn.active {
  background: rgba(247, 210, 134, 0.15) !important;
  border-color: #f7d286 !important;
  color: #ffe3a1 !important;
}

.friends-tab-page {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
  overflow: hidden;
}

.friend-item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(247, 210, 134, 0.2);
  border-radius: 8px;
  padding: 6px 10px;
}

.friend-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.friend-item-avatar {
  width: 26px;
  height: 34px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.friend-item-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.friend-item-name {
  font-size: 12px;
  font-weight: 700;
  color: #ffe3a1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.friend-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.friend-status-dot.online {
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}

.friend-status-dot.offline {
  background: #64748b;
}

.friend-item-sub {
  font-size: 10px;
  color: #94a3b8;
}

.friend-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.friend-item-actions button {
  font-size: 10px !important;
  padding: 4px 8px !important;
  min-height: 26px !important;
}

.friend-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.friend-search-input {
  flex: 1;
  background: #09121e;
  border: 1px solid rgba(247, 210, 134, 0.35);
  border-radius: 6px;
  color: #fff;
  padding: 6px 10px;
  font-size: 12px;
}

/* ================= 1.5 LAPTOP & COMPACT DESKTOP (MAX-HEIGHT: 800PX) ZERO-SCROLL ================= */
@media (max-height: 800px) and (min-height: 521px) {
  .app-header {
    height: 56px !important;
    padding: 0 3% !important;
  }
  .brand {
    font-size: 15px !important;
  }
  .brand-mark {
    font-size: 32px !important;
  }
  .page.interior-page {
    padding-top: 14px !important;
    padding-bottom: 8px !important;
  }
  .page-heading {
    margin-bottom: 12px !important;
  }
  .page-heading h1 {
    font-size: 24px !important;
    margin: 2px 0 !important;
  }
  .page-heading p {
    font-size: 12px !important;
    line-height: 1.4 !important;
  }
  .balance strong {
    font-size: 22px !important;
  }
  .tabs {
    margin-bottom: 14px !important;
  }
  .tabs button {
    padding: 8px 16px !important;
    font-size: 12px !important;
  }
  .shop-grid {
    gap: 12px !important;
  }
  .shop-card, .dice-skin-card {
    padding: 12px 10px !important;
  }
  .shop-art {
    height: 95px !important;
    min-height: 85px !important;
  }
  .shop-art .dice-skin-face {
    width: 50px !important;
    height: 50px !important;
  }
  .dice-skin-preview {
    transform: scale(0.92);
  }
  .shop-card h3, .dice-skin-card h3 {
    font-size: 16px !important;
    margin: 6px 0 4px !important;
  }
  .shop-card p, .dice-skin-card .shop-item-desc {
    font-size: 11px !important;
    line-height: 1.35 !important;
    min-height: 2.8em !important;
    margin-bottom: 4px !important;
  }
  .shop-card button, .dice-skin-card button {
    padding: 6px 12px !important;
    font-size: 11px !important;
    min-height: 32px !important;
  }
  .page-footnote {
    margin: 8px 0 4px !important;
    font-size: 10px !important;
  }
  .shop-pagination-bar {
    margin-top: 8px !important;
  }
  .shop-pagination-bar button {
    min-height: 30px !important;
    padding: 4px 14px !important;
    font-size: 11px !important;
  }

  /* Collection hero grid on compact desktop */
  .hero-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    gap: 10px !important;
    max-height: 360px !important;
  }
  .hero-card {
    padding: 14px 6px 10px !important;
  }
  .hero-card img {
    height: 90px !important;
  }
  .hero-card h3 {
    font-size: 13px !important;
    margin: 4px 0 !important;
  }
  .hero-card small {
    font-size: 10px !important;
  }
  .collection-footer {
    padding: 8px 0 !important;
    font-size: 11px !important;
  }

  /* Leaderboard on compact desktop */
  .stats-row {
    margin-bottom: 12px !important;
  }
  .stat {
    padding: 10px 14px !important;
  }
  .stat strong {
    font-size: 22px !important;
  }
  .rank-row {
    padding: 8px 4px !important;
    font-size: 12px !important;
  }
}

/* ================= 2. MOBILE LANDSCAPE & COMPACT SCREEN OPTIMIZATION ================= */
@media (max-height: 520px) {
  .page {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }
  .page-heading {
    margin-bottom: 8px !important;
  }
  .page-heading h1 {
    font-size: 20px !important;
    margin: 2px 0 !important;
  }
  .page-heading p {
    display: none !important;
  }
  .balance {
    font-size: 9px !important;
  }
  .balance strong {
    font-size: 18px !important;
  }
  .tabs {
    margin-bottom: 8px !important;
  }
  .tabs button {
    padding: 4px 10px !important;
    font-size: 11px !important;
  }
  .shop-grid {
    gap: 8px !important;
  }
  .shop-card {
    padding: 8px 10px !important;
  }
  .shop-card h3 {
    font-size: 13px !important;
    margin: 4px 0 !important;
  }
  .shop-card p {
    display: none !important;
  }
  .shop-art img {
    height: 48px !important;
  }
  .shop-card button {
    min-height: 28px !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
  }
  .page-footnote {
    display: none !important;
  }
  .hero-card {
    padding: 10px 6px !important;
  }
  .hero-card img {
    height: 52px !important;
  }
  .hero-card h3 {
    font-size: 11px !important;
    margin: 3px 0 !important;
  }
  .hero-card small {
    display: none !important;
  }
  .collection-footer {
    padding: 6px 0 !important;
    font-size: 10px !important;
  }
  .stat {
    padding: 8px 10px !important;
    font-size: 9px !important;
  }
  .stat strong {
    font-size: 18px !important;
  }
  .stats-row {
    margin-bottom: 8px !important;
  }
  .pub-room-card {
    padding: 8px 10px !important;
    gap: 4px !important;
  }
  .pub-room-code {
    font-size: 15px !important;
  }
  .pub-room-count {
    font-size: 11px !important;
  }
  .pub-lobby-actions {
    margin: 6px 0 8px !important;
  }
  .match-chat-panel, .match-history-panel {
    width: 270px !important;
    bottom: 42px !important;
  }
  /* Responsive Home Screen on small height (zero-scroll) */
  .fantasy-home-stage {
    min-height: 0 !important;
    height: 100% !important;
    padding: 4px 14px 2px !important;
    justify-content: space-evenly !important;
  }
  .home-title-area {
    margin: 0 !important;
  }
  .game-crest {
    font-size: 13px !important;
    gap: 8px !important;
    margin-bottom: 0 !important;
  }
  .crest-crown {
    font-size: 18px !important;
  }
  .home-eyebrow {
    font-size: 8px !important;
    letter-spacing: 2px !important;
    margin-bottom: 1px !important;
  }
  .game-main-title {
    font-size: clamp(18px, 4.5vh, 26px) !important;
    letter-spacing: 1px !important;
  }
  .title-sub {
    font-size: 8px !important;
    letter-spacing: 2.5px !important;
    margin-top: 1px !important;
  }
  .home-lead-desc {
    display: none !important;
  }
  .rpg-menu-container {
    width: min(580px, 96%) !important;
    margin: 2px auto !important;
    padding: 6px 12px !important;
    border-radius: 10px !important;
  }
  .rpg-menu-list {
    display: grid !important;
    grid-template-columns: 1fr 1.35fr !important;
    gap: 8px !important;
    align-items: center !important;
  }
  .btn-play-primary {
    height: 42px !important;
    font-size: 13px !important;
    letter-spacing: 1px !important;
    box-shadow: 0 3px 0 #946927, 0 6px 14px rgba(247, 210, 134, 0.35) !important;
  }
  .btn-play-primary .btn-sword {
    font-size: 15px !important;
  }
  .btn-secondary {
    height: 32px !important;
    font-size: 11px !important;
    margin-top: 2px !important;
  }
  .rpg-menu-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4px !important;
  }
  .btn-compact {
    height: 34px !important;
    padding: 2px 4px !important;
    font-size: 9px !important;
    gap: 2px !important;
  }
  .btn-compact .btn-icon {
    font-size: 12px !important;
  }
  .fantasy-home-footer {
    padding: 2px 0 !important;
    min-height: 20px !important;
  }
  .footer-pills {
    display: none !important;
  }
  .footer-links {
    font-size: 9px !important;
    gap: 8px !important;
  }
  .footer-link-btn {
    font-size: 9px !important;
    padding: 2px 4px !important;
  }
  .footer-version {
    font-size: 8px !important;
  }

  /* Responsive Room Code Entry on small height */
  .rcode-panel {
    padding: 8px 12px !important;
    gap: 6px !important;
    max-width: 320px !important;
  }
  .rcode-cells {
    margin: 2px 0 !important;
    gap: 4px !important;
  }
  .rcode-cell {
    width: 32px !important;
    height: 36px !important;
    font-size: 16px !important;
    border-radius: 6px !important;
  }
  .rcode-keypad {
    gap: 3px !important;
    margin: 2px 0 !important;
  }
  .rcode-key {
    min-height: 26px !important;
    height: 26px !important;
    font-size: 13px !important;
    padding: 0 !important;
    border-radius: 5px !important;
  }
  .rcode-actions {
    gap: 6px !important;
  }
  .rcode-actions button {
    min-height: 28px !important;
    height: 28px !important;
    font-size: 11px !important;
  }

  /* Responsive Friends Modal on small height */
  .friends-modal-content {
    gap: 6px !important;
  }
  .friends-tabs-header {
    padding-bottom: 4px !important;
    gap: 4px !important;
  }
  .friends-tab-btn {
    padding: 3px 8px !important;
    font-size: 10px !important;
  }
  .friends-tab-page {
    min-height: 110px !important;
    gap: 4px !important;
  }
  .friend-item-card {
    padding: 3px 6px !important;
    border-radius: 6px !important;
  }
  .friend-item-avatar {
    width: 20px !important;
    height: 26px !important;
  }
  .friend-item-name {
    font-size: 11px !important;
  }
  .friend-item-actions button {
    min-height: 22px !important;
    padding: 1px 6px !important;
    font-size: 9px !important;
  }
  .friend-search-row {
    gap: 6px !important;
    margin-bottom: 4px !important;
  }
  .friend-search-input {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }

  /* Responsive Common Modal on small height */
  #modalbg .modal {
    padding: 10px 14px !important;
    max-height: calc(100% - 12px) !important;
  }
  .modal h2 {
    font-size: 17px !important;
    margin: 3px 0 6px !important;
  }
  .modal-text {
    font-size: 11px !important;
    line-height: 1.35 !important;
  }
  .modal-text p {
    margin: 4px 0 !important;
  }
  .modal-actions {
    margin-top: 8px !important;
    gap: 6px !important;
  }
  .modal-actions button {
    min-height: 28px !important;
    padding: 3px 10px !important;
    font-size: 10px !important;
  }
  .hero-picker {
    gap: 4px !important;
  }
  .hero-picker button {
    padding: 3px !important;
    font-size: 9px !important;
  }
  .hero-picker img {
    width: 40px !important;
    height: 50px !important;
  }

  /* Responsive Mode Select on small height */
  .mode-popup-panel {
    padding: 8px 12px !important;
    max-height: calc(100% - 12px) !important;
  }
  .mode-popup-header {
    margin-bottom: 6px !important;
  }
  .mode-popup-header h2 {
    font-size: 16px !important;
    margin: 2px 0 !important;
  }
  .mode-popup-header p {
    display: none !important;
  }
  .mode-cards-dual {
    gap: 8px !important;
    margin-bottom: 6px !important;
  }
  .mode-dual-card {
    padding: 6px 10px !important;
    border-radius: 8px !important;
  }
  .card-emblem {
    font-size: 22px !important;
    margin-bottom: 4px !important;
  }
  .card-title {
    font-size: 14px !important;
  }
  .card-subtitle {
    font-size: 9px !important;
  }
  .card-desc {
    display: none !important;
  }
  .card-perks {
    gap: 2px !important;
    margin: 4px 0 !important;
    font-size: 8px !important;
  }
  .card-action-hint {
    font-size: 9px !important;
    padding: 2px 6px !important;
  }
  .mode-popup-footer-row button {
    min-height: 26px !important;
    padding: 2px 10px !important;
    font-size: 10px !important;
  }
}

/* ================= YÊU CẦU 3: AI TIẾP QUẢN KHI AFK 60s & NÚT BẬT/TẮT ================= */
.hud-ai-toggle-btn {
  margin-left: auto;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: rgba(27, 54, 54, 0.85);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.hud-ai-toggle-btn.is-ai-on {
  color: #38bdf8;
  border-color: #38bdf8;
  background: rgba(14, 165, 233, 0.25);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}
.hud-ai-toggle-btn.is-ai-off {
  color: #f7d286;
  border-color: rgba(247, 210, 134, 0.4);
  background: rgba(247, 210, 134, 0.1);
}
.ai-toolbar-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(247, 210, 134, 0.4);
  background: rgba(247, 210, 134, 0.12);
  color: #f7d286;
  cursor: pointer;
  white-space: nowrap;
}
.ai-toolbar-btn.active {
  color: #38bdf8;
  border-color: #38bdf8;
  background: rgba(14, 165, 233, 0.25);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}
.player-hud-card.is-ai-controlled {
  border-color: #38bdf8 !important;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4) !important;
  animation: aiPulseGlow 2.5s infinite ease-in-out;
}
@keyframes aiPulseGlow {
  0%, 100% { box-shadow: 0 0 6px rgba(56, 189, 248, 0.3); }
  50% { box-shadow: 0 0 14px rgba(56, 189, 248, 0.7); }
}

/* ================= PANEL LỊCH SỬ GIAO DỊCH (PHÂN TRANG — KHÔNG CUỘN) ================= */
.history-panel-backdrop {
  position: fixed; inset: 0; z-index: 240;
  background: rgba(5, 12, 20, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}
.history-panel {
  width: min(560px, 96vw);
  max-height: min(86dvh, 640px);
  background: linear-gradient(165deg, #0d1f2d 0%, #123043 100%);
  border: 2px solid #f7d286;
  border-radius: 14px;
  box-shadow: 0 0 32px rgba(247, 210, 134, 0.25), 0 12px 40px rgba(0, 0, 0, 0.6);
  display: flex; flex-direction: column;
  padding: 14px 16px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
}
.history-head {
  display: flex; align-items: center; justify-content: space-between;
}
.history-head h2 {
  margin: 0; font-size: 17px; color: #f7d286; letter-spacing: 0.5px;
  text-shadow: 0 0 10px rgba(247, 210, 134, 0.4);
}
.history-tabs { display: flex; gap: 6px; flex-wrap: nowrap; overflow: visible; }
.history-tab {
  flex: 1 1 0; min-width: 0;
  background: rgba(35, 67, 90, 0.6); border: 1px solid #2d5a7a;
  color: #cbd5e1; border-radius: 8px; padding: 6px 4px;
  font-size: 11px; font-weight: bold; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-tab.active {
  background: rgba(247, 210, 134, 0.18); border-color: #f7d286; color: #ffe3a1;
  box-shadow: 0 0 8px rgba(247, 210, 134, 0.35);
}
.history-invites { display: flex; flex-direction: column; gap: 6px; }
.history-invite {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(56, 189, 248, 0.12); border: 1px solid #38bdf8;
  border-radius: 10px; padding: 8px 10px; font-size: 12px;
}
.history-invite-info small { display: block; color: #94a3b8; margin-top: 2px; }
.history-invite-actions { display: flex; gap: 6px; flex-shrink: 0; }
.history-invite-actions .text-button { padding: 5px 10px; font-size: 12px; }
.history-list { display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.history-entry {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  background: rgba(18, 48, 67, 0.75); border: 1px solid #2d5a7a;
  border-radius: 10px; padding: 8px 10px; font-size: 12px;
}
.history-entry-main { display: flex; align-items: center; gap: 6px; min-width: 0; }
.history-entry small { grid-column: 1; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-arrow { color: #f7d286; }
.history-status {
  grid-column: 2; grid-row: 1 / span 2;
  align-self: center; justify-self: end;
  font-size: 10px; font-weight: bold; padding: 3px 8px; border-radius: 999px;
  white-space: nowrap;
}
.history-status.st-pending { background: rgba(56, 189, 248, 0.2); color: #38bdf8; border: 1px solid #38bdf8; }
.history-status.st-trading { background: rgba(247, 210, 134, 0.2); color: #ffe3a1; border: 1px solid #f7d286; }
.history-status.st-rejected { background: rgba(248, 113, 113, 0.18); color: #f87171; border: 1px solid #f87171; }
.history-status.st-success { background: rgba(52, 211, 153, 0.18); color: #34d399; border: 1px solid #34d399; }
.history-empty { text-align: center; color: #94a3b8; font-size: 13px; padding: 26px 0; }
.history-foot {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  color: #ffe3a1; font-weight: bold; font-size: 13px;
}

/* ================= POPUP NHẬP MÃ PHÒNG 6 SỐ ================= */
.rcode-popup {
  position: relative;
  width: min(380px, 92vw);
  background: linear-gradient(165deg, #0d1f2d 0%, #123043 100%);
  border: 2px solid #f7d286; border-radius: 14px;
  box-shadow: 0 0 32px rgba(247, 210, 134, 0.25), 0 12px 40px rgba(0, 0, 0, 0.6);
  padding: 18px 20px 20px; text-align: center; color: #e2e8f0;
}
.rcode-popup h2 { color: #f7d286; font-size: 18px; margin: 4px 0 6px; }
.rcode-hint { font-size: 12px; color: #94a3b8; margin: 0 0 12px; }
.rcode-input {
  width: 100%; box-sizing: border-box;
  background: rgba(5, 12, 20, 0.8); border: 2px solid #2d5a7a; border-radius: 10px;
  color: #ffe3a1; font-size: 26px; letter-spacing: 10px; text-align: center;
  padding: 10px 0 10px 10px; outline: none; font-weight: bold;
}
.rcode-input:focus { border-color: #f7d286; box-shadow: 0 0 12px rgba(247, 210, 134, 0.35); }
.rcode-error { color: #f87171; font-size: 12px; margin: 8px 0 0; }
.rcode-actions { margin-top: 14px; }
.rcode-actions .rpg-menu-btn { width: 100%; }

/* ================= SẢNH CÔNG KHAI (PHÂN TRANG 6 / TRANG) ================= */
.pub-lobby {
  position: relative;
  width: min(520px, 96vw);
  max-height: min(86dvh, 640px);
  background: linear-gradient(165deg, #0d1f2d 0%, #123043 100%);
  border: 2px solid #f7d286; border-radius: 14px;
  box-shadow: 0 0 32px rgba(247, 210, 134, 0.25), 0 12px 40px rgba(0, 0, 0, 0.6);
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 18px 14px; color: #e2e8f0;
}
.pub-lobby h2 { color: #f7d286; font-size: 17px; margin: 2px 0 0; }
.pub-rooms {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  min-height: 150px; align-content: start;
}
.pub-room-card {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  background: rgba(18, 48, 67, 0.85); border: 1px solid #2d5a7a; border-radius: 10px;
  color: #e2e8f0; padding: 9px 10px; font-size: 11px; cursor: pointer;
}
.pub-room-card strong { color: #f7d286; font-size: 13px; }
.pub-room-card span { color: #94a3b8; }
.pub-room-card:hover:not(:disabled) { border-color: #f7d286; box-shadow: 0 0 10px rgba(247, 210, 134, 0.3); }
.pub-room-card.pub-room-full { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }
.pub-empty { grid-column: 1 / -1; text-align: center; color: #94a3b8; padding: 30px 0; font-size: 13px; }
.pub-foot { display: flex; align-items: center; justify-content: center; gap: 12px; color: #ffe3a1; font-weight: bold; font-size: 13px; }

/* Bong bóng chat: dùng lại thiết kế đã duyệt ở mục 3 phía trên (tối + avatar) */

/* ================= ĐIỆN THOẠI NGANG: THU GỌN CHO VỪA MÀN HÌNH, KHÔNG CUỘN ================= */
@media (max-width: 900px) and (orientation: landscape) {
  .history-panel, .pub-lobby { max-height: 92dvh; gap: 6px; padding-top: 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .history-list { min-height: 0; }
  .history-entry { padding: 5px 8px; font-size: 11px; }
  .history-tab { font-size: 10px; padding: 4px 2px; }
  .pub-rooms { grid-template-columns: repeat(3, 1fr); min-height: 0; gap: 6px; }
  .pub-room-card { padding: 6px 8px; font-size: 10px; }
  .rcode-popup { padding: 12px 16px 14px; }
  .rcode-input { font-size: 22px; letter-spacing: 7px; }
}
@media (max-width: 480px) and (orientation: portrait) {
  .pub-rooms { grid-template-columns: repeat(2, 1fr); }
}
