:root {
    --bg-color: #202124;
    --card-bg: #3c4043;
    --primary: #8ab4f8;
    --danger: #ea4335;
    --text-white: #e8eaed;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Google Sans', Roboto, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-white);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- WELCOME SCREEN --- */
#welcome-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: radial-gradient(circle, #3c4043 0%, #202124 100%);
    z-index: 9999;
}
.welcome-box { text-align: center; max-width: 400px; padding: 20px; }
.logo { font-size: 24px; color: var(--primary); margin-bottom: 20px; font-weight: bold; }
.primary-btn {
    margin-top: 30px; padding: 14px 32px;
    background-color: var(--primary); color: #202124;
    border: none; border-radius: 4px; font-weight: 600; font-size: 16px;
    cursor: pointer; transition: 0.2s;
}
.primary-btn:hover { background-color: #aecbfa; }

/* --- CALL SCREEN LAYOUT --- */
#call-screen {
    display: none; /* Mặc định ẩn */
    flex: 1;
    position: relative;
    flex-direction: column;
    height: 100%;
}

/* Header Bar */
.header-bar {
    position: absolute; top: 0; left: 0; right: 0;
    height: 60px;
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 20px;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}

.room-info { font-size: 14px; font-weight: 500; text-shadow: 0 1px 2px black; }
.divider { margin: 0 10px; opacity: 0.6; }

.participant-badge {
    background: rgba(60, 64, 67, 0.8);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    display: flex; align-items: center; gap: 8px;
}

/* --- VIDEO GRID SYSTEM --- */
#video-grid {
    flex: 1;
    display: grid;
    /* JS sẽ set biến --grid-cols */
    grid-template-columns: repeat(var(--grid-cols, 1), 1fr);
    /* Tự động căn giữa nội dung */
    align-content: center; justify-content: center;
    gap: 15px;
    padding: 20px;
    padding-bottom: 90px; /* Chừa chỗ cho control bar */
    overflow-y: auto;
}

/* THẺ CARD VIDEO */
.video-card {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
    
    /* ÉP HÌNH VUÔNG 1:1 */
    aspect-ratio: 1 / 1; 
    
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

/* XỬ LÝ LỆCH CAM & LẬT CAM */
/* 1. Reset tất cả video về object-fit cover để lấp đầy khung vuông */
.player { width: 100%; height: 100%; }

/* Can thiệp sâu vào thẻ video do Agora tạo ra để không bị méo */
.player video {
    object-fit: cover !important; 
    width: 100% !important;
    height: 100% !important;
}

/* 2. Chỉ lật gương video của CHÍNH MÌNH (Local) */
.video-card.local .player { transform: scaleX(-1); }

/* 3. Video của NGƯỜI KHÁC (Remote) giữ nguyên, không lật */
.video-card.remote .player { transform: none; }


/* Hiệu ứng Hover & Overlay */
.video-card:hover { border-color: #5f6368; }
.overlay {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 10px 15px;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    display: flex; justify-content: space-between; align-items: center;
    opacity: 0; transition: opacity 0.2s;
}
.video-card:hover .overlay { opacity: 1; }
@media (hover: none) { .overlay { opacity: 1; } } /* Mobile luôn hiện */

.user-name { font-size: 13px; font-weight: 500; text-shadow: 0 1px 2px black; }
.pin-btn { 
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; justify-content: center; align-items: center;
    cursor: pointer;
}
.pin-btn:hover { background: rgba(255,255,255,0.4); }

/* --- FOCUS MODE (PINNED) --- */
/* PC Layout */
#video-grid.focused {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    overflow: hidden;
}

#video-grid.focused .video-card.pinned {
    flex: 1;
    height: 100%;
    max-height: calc(100vh - 120px);
    aspect-ratio: auto; /* Bỏ hình vuông để hiển thị full */
    order: 1;
    z-index: 5;
}
/* Khi được ghim, hiển thị trọn vẹn không cắt (contain) */
#video-grid.focused .video-card.pinned .player video { object-fit: contain !important; background: black; }

#video-grid.focused .video-card:not(.pinned) {
    flex: 0 0 220px; /* Cột bên phải 220px */
    aspect-ratio: 1/1;
    order: 2;
    margin-bottom: 10px;
}

/* Mobile Layout */
@media (max-width: 768px) {
    #video-grid.focused { flex-direction: column; overflow-y: hidden; }
    
    #video-grid.focused .video-card.pinned {
        flex: 1; width: 100%;
        max-height: 60vh;
        margin-bottom: 10px;
    }
    
    /* Danh sách trượt ngang bên dưới */
    #video-grid.focused .video-card:not(.pinned) {
        flex: 0 0 110px;
        width: 110px;
        aspect-ratio: 1/1;
        display: inline-block;
        margin-right: 10px;
    }
    
    #video-grid.focused {
        display: block; white-space: nowrap; overflow-x: auto;
    }
    #video-grid.focused .video-card.pinned { display: block; white-space: normal; }
}

/* --- CONTROL BAR --- */
#controls-bar {
    position: absolute; bottom: 25px; left: 50%; transform: translateX(-50%);
    background: #202124;
    padding: 8px 20px;
    border-radius: 50px;
    display: flex; gap: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6);
    z-index: 100;
}
.control-btn {
    width: 48px; height: 48px; border-radius: 50%;
    border: none; font-size: 20px; color: white; cursor: pointer;
    background: #3c4043; transition: 0.2s;
    display: flex; justify-content: center; align-items: center;
}
.control-btn:hover { background: #4b4f52; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.control-btn.inactive { background: var(--danger); }
.control-btn.inactive:hover { background: #d93025; }
.hangup-btn { background: var(--danger); width: 65px; border-radius: 35px; }