/* ==========================================================================
   RESET & BASE
   ========================================================================== */
   * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #041022;
    font-family: 'Segoe UI', sans-serif;
    overflow-x: hidden;
}

.pvp-screen {
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, #06142b, #041022);
    color: white;
}

/* ==========================================================================
   HEADER SECTION
   ========================================================================== */
.pvp-header {
    height: 70px; /* Giảm nhẹ chiều cao từ 90px xuống cho thoáng màn hình */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.match-title {
    font-size: 28px; /* Thu nhỏ từ 40px tránh chiếm diện tích dọc */
    font-weight: 700;
}

.back-btn {
    position: absolute;
    left: 24px;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    font-size: 22px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: translateX(-2px);
}

/* ==========================================================================
   LAYOUT MAIN & RESPONSIVE FLEXBOX
   ========================================================================== */
.pvp-main {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 10px 16px 30px;
}

.side-column {
    width: 100%;
    max-width: 540px; /* Giới hạn bằng thớt cờ trên mobile */
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.board-zone {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    width: 100%;
}

/* Ép bàn cờ to tối đa theo vùng chứa nhưng không vượt giới hạn đẹp */
.chess-board-area, 
.board-zone canvas { 
    width: 100% !important;   
    max-width: 560px; /* Tăng nhẹ kích thước tối đa giúp bàn cờ nhìn to rõ hơn */
    height: auto;
    border-radius: 20px;
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   PLAYER CARD & AVATAR SVG TIMER
   ========================================================================== */
.player-card {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 10px 14px; /* Thu gọn padding để thẻ mỏng, ôm sát gọn gàng */
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(16px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    gap: 10px;
}

.player-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.player-left > div:last-child {
    min-width: 0;
    flex: 1;
}

/* Khung bọc viền SVG bao quanh Avatar */
.avatar-container {
    position: relative;
    width: 52px; /* Thu nhỏ từ 64px giúp tổng thể thẻ thanh thoát */
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    z-index: 2;
}

/* Vòng tròn SVG đếm ngược nước đi */
.timer-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    z-index: 1;
}

.timer-circle {
    fill: none;
    stroke: #2ecc71; 
    stroke-width: 2.5px; /* Giảm độ dày một chút cho tinh tế */
    stroke-linecap: round;
    stroke-dasharray: 175.93; 
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.timer-circle.timer-danger {
    stroke: #e74c3c; 
    filter: drop-shadow(0 0 3px rgba(231, 76, 60, 0.6));
}

/* Cấu hình hiển thị Tên tránh rớt hàng */
.player-name {
    font-size: 15px; /* Hạ cỡ chữ xuống để khít hàng ngang */
    font-weight: 700;
    white-space: nowrap;      
    overflow: hidden;         
    text-overflow: ellipsis;  
    max-width: 120px;         
}

.elo-tag {
    color: #ffd700;
    font-size: 0.9em;
    font-weight: bold;
    margin-left: 4px;
}

.player-role {
    margin-top: 1px;
    opacity: 0.5;
    font-size: 12px;
}

/* Đồng hồ tổng của trận đấu (Thu nhỏ cỡ chữ siêu bự cũ) */
.player-time {
    font-size: 22px; /* Thu nhỏ từ 34px xuống 22px để cân bằng với thẻ tên */
    font-weight: 700;
    font-family: monospace;
    font-variant-numeric: tabular-nums;
    background: rgba(0, 0, 0, 0.25);
    padding: 4px 10px;
    border-radius: 8px;
    color: #a0aec0;
    transition: 0.3s;
    flex-shrink: 0;
}

/* Hộp thời gian sáng lên khi tới lượt */
.player-time.active-turn {
    background: #27ae60;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(39, 174, 96, 0.3);
}

/* ==========================================================================
   BUTTONS INTERACTION
   ========================================================================== */
.action-row {
    width: 100%;
    display: flex;
    gap: 10px;
}

.action-btn {
    flex: 1;
    height: 44px; /* Giảm chiều cao từ 54px xuống cho thanh mảnh */
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: 0.2s ease;
}

.action-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
}

.draw-btn { background: #2563eb; }
.resign-btn { background: #dc2626; }

/* ==========================================================================
   DESKTOP RESPONSIVE MODE (Màn hình rộng từ 900px trở lên)
   ========================================================================== */
/* ==========================================================================
   DESKTOP RESPONSIVE MODE (Màn hình rộng từ 900px trở lên)
   ========================================================================== */
   @media (min-width: 900px) {
    .pvp-main {
        flex-direction: row;
        align-items: flex-start; /* 🔥 Đổi từ center thành flex-start để đẩy 2 khung lên đỉnh */
        justify-content: center;
        gap: 24px;
        padding-top: 20px;
    }

    .side-column {
        width: 260px; /* Giữ nguyên độ rộng gọn gàng cho 2 cột bên */
    }

    .board-zone {
        flex: 1; 
        max-width: 560px;
    }
}

/* ==========================================================================
   CSS GAME OVER POPUP (Đảm bảo nổi lên trên tất cả mọi thứ)
   ========================================================================== */
/* Lớp phủ mờ phủ kín toàn màn hình */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(4, 16, 34, 0.85); /* Màu tối mờ */
    backdrop-filter: blur(8px);       /* Làm nhòe bàn cờ phía sau */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999; /* Số cực to để đè bẹp thẻ Canvas và Layout */
    animation: fadeInPopup 0.3s ease forwards;
}

/* Hộp thoại thông tin ở giữa */
.game-over-modal {
    background: #0b1e36;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 28px;
    width: 90%;
    max-width: 380px;
    padding: 32px 24px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    animation: scaleUpPopup 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-icon {
    font-size: 56px;
    margin-bottom: 12px;
}

.game-over-modal h2 {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 8px;
    color: #ffffff;
}

.modal-reason {
    font-size: 14px;
    color: #a0aec0;
    margin-bottom: 24px;
}

/* Khung bọc điểm số Elo */
.elo-result-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 26px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.elo-row {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
}

/* Màu chữ đại diện cho việc cộng trừ điểm */
.text-win { color: #2ecc71 !important; font-weight: bold; }
.text-lose { color: #e74c3c !important; font-weight: bold; }

/* Nút xác nhận thoát */
.confirm-leave-btn {
    width: 100%;
    height: 48px;
    background: linear-gradient(90deg, #2563eb, #1d4ed8);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.confirm-leave-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

/* Hiệu ứng chuyển động mượt mà */
@keyframes fadeInPopup {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleUpPopup {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ========================================================
   🔥 TRỌN BỘ CSS POPUP CONFIRM DÙNG CHUNG CHO PVP LAYOUT
   ======================================================== */

/* 1. Lớp nền mờ bao phủ toàn màn hình */
.match-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.65); /* Nền đen mờ nhẹ */
    backdrop-filter: blur(4px); /* Làm nhòe bàn cờ phía sau cực nghệ */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999; /* Đảm bảo luôn đè lên trên Canvas và Sidebar */
}

/* 2. Khung nội dung chính của Popup */
.match-popup-content {
    background: linear-gradient(145deg, #1e1e24, #141418); /* Đổ màu tối huyền bí */
    border: 2px solid #3e3e4a; /* Viền mờ phân cách */
    border-radius: 16px;
    padding: 28px 32px;
    width: 380px;
    max-width: 90%;
    text-align: center;
    color: #ffffff;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 
                0 0 20px rgba(255, 255, 255, 0.05) inset;
    
    /* Hiệu ứng xuất hiện mượt mà trượt nhẹ từ trên xuống */
    animation: popupSlideDown 0.25s ease-out forwards;
}

/* 3. Định dạng Tiêu đề (Chứa Icon động từ cha truyền qua) */
.match-popup-content h2 {
    font-size: 22px;
    font-weight: 800;
    margin-top: 0;
    margin-bottom: 12px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px; /* Khoảng cách giữa icon và chữ */
}

/* 4. Định dạng dòng chữ mô tả/cảnh báo */
.match-popup-content p {
    font-size: 15px;
    line-height: 1.5;
    color: #b3b3b3; /* Chữ màu xám nhẹ dễ đọc, không bị chói */
    margin-bottom: 28px;
}

/* 5. Cụm bọc 2 nút bấm dàn hàng ngang */
.popup-button-group {
    display: flex;
    justify-content: space-between;
    gap: 16px; /* Khoảng cách giữa 2 nút */
}

/* 6. Base Style chung cho cả 2 nút */
.btn-confirm-ok, 
.btn-confirm-cancel {
    flex: 1; /* Hai nút dài bằng nhau tự động */
    padding: 12px 0;
    font-size: 15px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

/* 7. Nút XÁC NHẬN - Style màu Đỏ/Cam nguy hiểm mạnh mẽ */
.btn-confirm-ok {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.btn-confirm-ok:hover {
    transform: translateY(-2px); /* Nhấc nhẹ lên khi di chuột */
    background: linear-gradient(135deg, #ff5e4d, #d63031);
    box-shadow: 0 6px 16px rgba(231, 76, 60, 0.4);
}

.btn-confirm-ok:active {
    transform: translateY(0); /* Lún xuống khi click */
}

/* 8. Nút HỦY BỎ - Style màu xám lịch sự ẩn mình */
.btn-confirm-cancel {
    background-color: #2c2c35;
    color: #a0a0a5;
    border: 1px solid #444452;
}

.btn-confirm-cancel:hover {
    background-color: #383844;
    color: #ffffff;
    border-color: #555566;
}

/* ========================================================
   🎬 KEYFRAMES ANIMATION (Hiệu ứng trượt)
   ======================================================== */
@keyframes popupSlideDown {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}