/* =========================================
   PHONG CÁCH CHIẾN THẦN (DARK ESPORTS THEME)
   ========================================= */
body {
    background: radial-gradient(circle at center, #1e2029 0%, #000000 100%);
    display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: #E2E8F0;
}

/* Khung chính Glassmorphism */
.game-container {
    background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(20px);
    padding: 20px; border-radius: 20px; border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    display: flex; flex-direction: column; 
    
    /* MỞ RỘNG FULL MÀN HÌNH */
    width: 98vw; 
    max-width: 1600px; 
    height: 96vh; 
    
    overflow: hidden; 
    transition: box-shadow 0.5s, border-color 0.5s;
}

/* HIỆU ỨNG RIÊNG CHO TỪNG SẢNH */
.theme-tapsu { border-top: 3px solid #10B981; box-shadow: 0 0 30px rgba(16, 185, 129, 0.1); }
.theme-chienbinh { border-top: 3px solid #38BDF8; box-shadow: 0 0 30px rgba(56, 189, 248, 0.1); }
.theme-caothu { border-top: 3px solid #EF4444; box-shadow: 0 0 30px rgba(239, 68, 68, 0.15); }

/* Thanh chọn phòng (Tabs) */
.room-tabs { display: flex; gap: 5px; background: rgba(0,0,0,0.4); padding: 5px; border-radius: 12px; margin-bottom: 20px; }
.room-tab {
    flex: 1; padding: 10px; border: none; border-radius: 8px; background: transparent; color: #64748B;
    font-weight: 900; cursor: pointer; transition: all 0.3s; font-size: 13px; text-transform: uppercase;
}
.room-tab.active.room-tapsu { background: rgba(16, 185, 129, 0.2); color: #10B981; border: 1px solid #10B981; }
.room-tab.active.room-chienbinh { background: rgba(56, 189, 248, 0.2); color: #38BDF8; border: 1px solid #38BDF8; }
.room-tab.active.room-caothu { background: rgba(239, 68, 68, 0.2); color: #FCA5A5; border: 1px solid #EF4444; text-shadow: 0 0 5px #EF4444;}

/* Input & Nút bấm */
.epic-input { background: rgba(0,0,0,0.5) !important; color: #fff !important; border: 1px solid #334155 !important; }
.epic-input:focus { border-color: #F59E0B !important; box-shadow: 0 0 10px rgba(245, 158, 11, 0.3); }
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; width: 100%; }
.search-bar .input-field { flex: 1; border-radius: 12px; padding: 10px 15px; outline: none; }
.btn-action { padding: 10px 18px; border-radius: 12px; font-weight: bold; cursor: pointer; border: none; color: white; transition: 0.2s; text-transform: uppercase; font-size: 13px; }
.btn-back { background: transparent; border: 1px solid #475569; color: #94A3B8; }
.btn-leave { background: rgba(239, 68, 68, 0.1); border: 1px solid #EF4444; color: #EF4444; }
.btn-random { background: linear-gradient(45deg, #F59E0B, #D97706); box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4); }
.btn-random:hover { transform: scale(1.05); }

.glow-text { margin: 0; font-size: 18px; font-weight: 900; color: #F8FAFC; text-shadow: 0 0 10px rgba(255,255,255,0.3); }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; }

/* Danh sách người chơi (Smart Grid) */
.player-list { 
    flex: 1; 
    
    /* FIX LỖI KẸT GIAO DIỆN: Bắt buộc có dòng này để Grid tự cắt thanh cuộn */
    min-height: 0; 
    
    overflow-y: auto; 
    display: grid; 
    
    /* Ép hiển thị chính xác 5 cột */
    grid-template-columns: repeat(5, 1fr); 
    
    grid-auto-rows: min-content; 
    gap: 15px; 
    padding-right: 5px; 
    align-content: start; 
}
.player-list::-webkit-scrollbar { width: 4px; }
.player-list::-webkit-scrollbar-thumb { background: #475569; border-radius: 10px; }

/* Thẻ người chơi dạng Dọc (Vuông) */
.player-card { 
    display: flex; flex-direction: column; align-items: center; 
    background: rgba(30, 41, 59, 0.6); padding: 15px 10px; 
    border-radius: 12px; border: 1px solid rgba(255,255,255,0.05); 
    transition: all 0.2s;
}
.player-card:hover { transform: translateY(-3px); background: rgba(51, 65, 85, 0.8); }
.player-card.is-me { border: 1px solid #F59E0B; background: rgba(245, 158, 11, 0.1); }

/* Avatar tự động căn giữa và đẩy to ra */
.avatar { 
    width: 65px; height: 65px; 
    border-radius: 50%; margin-right: 0; margin-bottom: 10px; 
    border: 2px solid #475569; background: #000; 
}

/* Thông tin người chơi */
.player-info { width: 100%; text-align: center; overflow: hidden; }
.player-name { 
    font-weight: 800; font-size: 14px; color: #F8FAFC; 
    margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}
.player-points { font-size: 12px; color: #F59E0B; font-weight: bold; }

/* Khu vực Nút bấm */
.action-col { display: flex; align-items: center; justify-content: center; width: 100%; margin-top: 8px; min-width: unset; }
.status-badge { font-size: 11px; font-weight: bold; background: rgba(255,255,255,0.1); padding: 5px; border-radius: 6px; color: #94A3B8; width: 100%; text-align: center; white-space: nowrap; }
.btn-challenge { background: #8B5CF6; color: white; border: none; padding: 6px 0; width: 100%; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 11px; }
.btn-accept { background: #10B981; color: white; border: none; padding: 6px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; width: 100%;}
.btn-decline { background: rgba(239, 68, 68, 0.2); color: #FCA5A5; border: 1px solid #EF4444; padding: 6px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; width: 100%;}
.invite-msg { display: none; }

/* Thanh tiêu đề VS In-Match */
.vs-board { 
    display: flex; justify-content: space-between; align-items: center; 
    margin: 0 auto 15px auto; 
    background: rgba(0,0,0,0.3); border-radius: 12px; padding: 10px 20px; 
    border: 1px solid #334155; 
    width: 100%; 
    max-width: calc(100vh - 250px); 
}
.player-vs { display: flex; align-items: center; gap: 10px; font-weight: 900; }
.x-side { color: #38BDF8; }
.o-side { color: #EF4444; flex-direction: row-reverse; }
.vs-avatar { width: 35px; height: 35px; border-radius: 50%; border: 2px solid; }
.vs-badge { font-weight: 900; color: #F59E0B; font-size: 18px; font-style: italic; }

/* Bàn cờ được khóa ngàm để luôn nằm gọn trên màn hình */
.board {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    aspect-ratio: 1 / 1;
    overflow: hidden; 
    
    background-color: #334155; 
    gap: 1px; 
    border: 1px solid #334155; 
    
    /* KHÓA KÍCH THƯỚC HIỆU QUẢ NHẤT */
    margin: 0 auto; 
    width: 100%;
    max-width: calc(100vh - 250px); 
    max-height: calc(100vh - 250px);
}

/* Trong phần cấu hình ô cờ */
.cell {
    display: flex; justify-content: center; align-items: center;
    min-width: 0; min-height: 0; width: 100%; height: 100%;
    box-sizing: border-box;
    background-color: #0F172A; 
}
.cell:hover { background-color: #334155; }
.cell.x { color: #38BDF8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.5); }
.cell.o { color: #EF4444; text-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
.cell.win { background-color: rgba(245, 158, 11, 0.3) !important; box-shadow: inset 0 0 15px #F59E0B; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: flex; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(5px); }
.epic-modal { background: #1E293B; border: 1px solid #475569; box-shadow: 0 0 40px rgba(0,0,0,0.9); }