:root {
    --primary: #FF6B6B;
    --secondary: #4ECDC4;
    --bg-color: #f7f9fc;
    --card-back: #FFE66D;
}

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    padding: 20px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
/* Ngăn kéo thả ảnh (tránh việc kéo ảnh ra tab mới để xem) */
img {
    -webkit-user-drag: none;
}

/* Hiệu ứng bảo mật khi mất tập trung: 
   Nếu học sinh chuyển sang tab khác để xem ảnh đã chụp, 
   màn hình game sẽ bị nhòe đi ngay lập tức */
.blur-security {
    filter: blur(20px);
    transition: filter 0.3s ease;
}
.main-content {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 40px;
    width: 100%;
}

.game-wrapper {
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    max-width: 900px; /* Tăng từ 750px lên 900px để chứa thẻ to */
    text-align: center;
    flex-grow: 1;
    position: relative; /* Thêm cái này để căn chỉnh nút Fullscreen */
}
/* Tuỳ chỉnh giao diện khi khung game ở chế độ Fullscreen */
.game-wrapper:fullscreen {
    max-width: 100vw; /* Chiếm 100% chiều ngang màn hình */
    height: 100vh;    /* Chiếm 100% chiều dọc màn hình */
    border-radius: 0; /* Bỏ bo góc */
    overflow-y: auto; /* Cho phép cuộn nếu màn hình điện thoại/laptop nhỏ */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Căn giữa nội dung theo chiều dọc */
    background-color: var(--bg-color); /* Lấy màu nền của body cho đồng bộ */
}

/* STYLE CHO NÚT FULLSCREEN */
.fullscreen-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background-color: #f1f2f6;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
}
.fullscreen-btn:hover { background-color: #e0e0e0; transform: scale(1.1); }

.game-header h2 { color: var(--primary); margin-top: 0; }

.stats {
    display: flex;
    justify-content: space-around;
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 20px;
    background: #f1f2f6;
    padding: 10px;
    border-radius: 10px;
}

/* KHUNG GAME CHÍNH */
.game-board {
    display: grid;
    gap: 12px; /* Tăng khoảng cách giữa các thẻ một chút */
    perspective: 1000px; 
    justify-content: center;
}

.card {
    width: 100px;  /* Tăng lên 100px */
    height: 100px; /* Tăng lên 100px */
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.card.flipped { transform: rotateY(180deg); }

.card-face {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    /* font-size: 55px;  <-- XÓA DÒNG NÀY (Không dùng text nữa) */
    border-radius: 15px; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    overflow: hidden; /* Đảm bảo hình ảnh không lòi ra ngoài viền bo góc */
}

.card-front { background-color: var(--secondary); color: white; }
.card-front::after { content: "?"; font-size: 60px;} 
.card-back { 
    background-color: #fff; /* Đổi nền mặt sau thành màu trắng để nổi bật hình ảnh */
    transform: rotateY(180deg); 
}
/* THÊM MỚI ĐOẠN NÀY DƯỚI .card-back */
.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Tự động cắt/zoom ảnh cho vừa khít hình vuông */
    display: block;
    pointer-events: none; /* Tránh click nhầm vào ảnh sinh ra lỗi JS */
}
/* BẢNG XẾP HẠNG (THIẾT KẾ LẠI) */
.leaderboard-container {
    background: white;
    padding: 30px 25px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 500px; /* Nới rộng kích thước để chứa tên dài */
    margin: 0 auto; /* Căn giữa màn hình */
}
.leaderboard-container h2 { color: #FFA502; text-align: center; margin-top:0; font-size: 24px;}

ul { list-style: none; padding: 0; margin: 0;}
li {
    background: #f1f2f6;
    margin: 12px 0;
    padding: 12px 15px;
    border-radius: 12px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px; /* Khoảng cách giữa tên và điểm */
}

/* Xử lý hiển thị Tên dài */
li span:first-child {
    flex: 1; /* Chiếm hết khoảng trống còn lại */
    text-align: left;
    word-break: break-word; /* Bắt buộc xuống dòng nếu tên dính liền quá dài */
    line-height: 1.4;
}

/* Xử lý hiển thị Điểm số */
li span:last-child {
    white-space: nowrap; /* Điểm số không bao giờ bị rớt dòng */
    background: #fff;
    padding: 5px 10px;
    border-radius: 8px;
    color: #27ae60;
    font-size: 16px;
}
/* [THÊM MỚI] Style cho nút Thi Lại */
#btnPlayAgain {
    display: block;
    width: 100%;
    margin-top: 25px;
    padding: 15px;
    font-size: 20px;
    font-weight: 900;
    color: white;
    background-color: #4ECDC4;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 5px 15px rgba(78, 205, 196, 0.4);
    text-transform: uppercase;
}
#btnPlayAgain:hover {
    background-color: #45b7af;
    transform: translateY(-2px);
}
#btnPlayAgain:active {
    transform: translateY(2px);
    box-shadow: 0 2px 5px rgba(78, 205, 196, 0.4);
}
/* Màu huy chương */
li:nth-child(1) { background: #FFD700; color: #b8860b; transform: scale(1.05); box-shadow: 0 4px 10px rgba(255, 215, 0, 0.3);}
li:nth-child(1) span:last-child { color: #b8860b; }
li:nth-child(2) { background: #E0E0E0; color: #696969; }
li:nth-child(3) { background: #cd7f32; color: white; }
li:nth-child(3) span:last-child { color: #cd7f32; }

/* LOBBY (MÀN HÌNH CHỜ) */
.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(-45deg, #FF9A9E, #FECFEF, #84fab0, #8fd3f4);
    background-size: 400% 400%;
    animation: gradientBG 10s ease infinite;
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
    visibility: hidden; opacity: 0; transition: 0.4s ease-in-out;
}
.overlay.active { visibility: visible; opacity: 1; }

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.lobby-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 40px 30px; 
    border-radius: 25px;
    text-align: center; 
    max-width: 450px; 
    width: 90%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2), 0 0 0 10px rgba(255,255,255,0.4);
    transform: scale(0.8);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.overlay.active .lobby-box { transform: scale(1); }

.lobby-box h1 {
    font-size: 34px; font-weight: 900; margin-top: 0; margin-bottom: 20px;
    background: linear-gradient(to right, #FF416C, #FF4B2B);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    text-transform: uppercase; letter-spacing: 2px;
}

.level-btn-group { display: flex; gap: 15px; margin-top: 20px; justify-content: center; }
.level-btn-group button {
    flex: 1; padding: 15px 5px; font-size: 18px; font-weight: 900;
    border: none; border-radius: 15px; cursor: pointer; color: white;
    transition: 0.2s; text-transform: uppercase;
}
.btn-th { background-color: #FF9F43; box-shadow: 0 6px 0px #CC6600; }
.btn-th:hover { background-color: #FF8812; transform: translateY(-2px); box-shadow: 0 8px 0px #CC6600; }
.btn-th:active { transform: translateY(4px); box-shadow: 0 2px 0px #CC6600; }

.btn-thcs { background-color: #00A8FF; box-shadow: 0 6px 0px #0077B3; }
.btn-thcs:hover { background-color: #008DE6; transform: translateY(-2px); box-shadow: 0 8px 0px #0077B3; }
.btn-thcs:active { transform: translateY(4px); box-shadow: 0 2px 0px #0077B3; }

.waiting-msg { 
    color: #e84118; font-size: 20px; font-weight: 900; margin: 25px 0;
    animation: pulseText 1s infinite alternate; 
}
@keyframes pulseText { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(1.05); opacity: 1; text-shadow: 0 0 10px rgba(232, 65, 24, 0.4);} }

.lobby-box input {
    width: 100%; padding: 18px; margin: 20px 0; font-size: 20px; font-weight: bold; color: #2f3542;
    border: 3px solid #ced6e0; border-radius: 15px; box-sizing: border-box; font-family: inherit; text-align: center;
    transition: 0.3s;
}
.lobby-box input:focus { outline: none; border-color: #1dd1a1; box-shadow: 0 0 15px rgba(29, 209, 161, 0.4); }

#btnReady {
    width: 100%; padding: 18px; font-size: 24px; font-weight: 900; letter-spacing: 1px;
    border: none; border-radius: 15px; cursor: pointer; color: white;
    background-color: #1dd1a1; box-shadow: 0 6px 0 #10ac84; transition: 0.2s; text-transform: uppercase;
}
#btnReady:hover { background-color: #1ee2ad; transform: translateY(-2px); box-shadow: 0 8px 0 #10ac84; }
#btnReady:active { transform: translateY(4px); box-shadow: 0 2px 0 #10ac84; }
/* Tinh chỉnh khoảng cách cho FontAwesome Icon trong các nút */
.level-btn-group button i {
    margin-right: 8px; /* Tạo khoảng trống giữa icon và chữ */
    font-size: 20px;   /* Cho icon to lên một chút */
}

.fullscreen-btn i {
    font-size: 22px; /* Kích thước chuẩn cho nút phóng to */
}
/* =========================================
   HIỆU ỨNG PHÁO HOA CSS (COMBO x5)
   ========================================= */
.firework-particle {
    position: fixed;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    pointer-events: none; /* Không cản trở click chuột của người chơi */
    z-index: 9999;
    animation: explode 1.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    box-shadow: 0 0 8px currentColor; /* Tạo hiệu ứng phát sáng nhẹ */
}

@keyframes explode {
    0% { 
        transform: translate(0, 0) scale(1); 
        opacity: 1; 
    }
    100% { 
        transform: translate(var(--tx), var(--ty)) scale(0); 
        opacity: 0; 
    }
}
