/* Import Font Google */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700;900&display=swap');

/* --- GLOBALS --- */
#lsq-wrapper { 
    font-family: 'Montserrat', sans-serif; 
    color: #2c3e50; 
}
.hidden { display: none !important; }
.lsq-btn { 
    padding: 12px 25px; cursor: pointer; border: none; border-radius: 8px; 
    font-weight: 700; transition: all 0.2s ease-in-out; text-transform: uppercase;
    box-shadow: 0 4px #222;
}

/* Button Variants */
.primary-btn { background: #3498db; color: white; box-shadow: 0 4px #2980b9; }
.primary-btn:hover { background: #2980b9; }

.success-btn { background: #2ecc71; color: white; box-shadow: 0 4px #27ae60; }
.success-btn:hover { background: #27ae60; }

.danger-btn { background: #e74c3c; color: white; box-shadow: 0 4px #c0392b; }
.danger-btn:hover { background: #c0392b; }

.secondary-btn { background: #95a5a6; color: white; box-shadow: 0 4px #7f8c8d; }
.secondary-btn:hover { background: #7f8c8d; }

.lsq-btn:active { transform: translateY(2px); box-shadow: 0 2px #222; }

/* --- 1. CONFIG PANEL (Giao diện Quản lý) --- (Giữ nguyên) */
#lsq-config-panel { padding: 30px; background: #f4f6f9; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); }
.section-title { font-size: 2.5rem; font-weight: 900; color: #34495e; text-align: center; margin-bottom: 25px; }

.config-row { display: flex; align-items: center; margin-bottom: 25px; gap: 20px; background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.input-group label { font-weight: 700; margin-right: 8px; color: #34495e; }
.input-group select, .input-group input[type="text"] { padding: 10px; border-radius: 5px; border: 1px solid #ccc; font-size: 1rem; }
.topic-input { flex-grow: 1; }

.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-bottom: 20px; }
.app-card-sub { 
    background: #fff; padding: 20px; border-radius: 10px; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.08); 
    border-top: 5px solid #3498db; 
}
.input-label { font-size: 1.2rem; font-weight: 700; color: #2c3e50; display: block; margin-bottom: 10px; }
.guide-text { font-size: 0.9em; color: #7f8c8d; margin: 5px 0; }
textarea { 
    font-family: monospace; 
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-top: 10px;
    resize: vertical;
}
.full-width { margin-top: 15px; }

.main-action { text-align: center; margin-top: 30px; }
.large-btn { font-size: 1.5rem; padding: 20px 40px; }

/* --- LỊCH SỬ & THÀNH TÍCH --- (Giữ nguyên) */
#lsq-history-panel { border-top: 5px solid #f39c12; margin-top: 30px; }
.subsection-title { color: #f39c12; font-size: 1.8rem; border-bottom: none; }
.topic-tag {
    background: #e0f7fa; color: #00796b; padding: 5px 10px; border-radius: 20px; 
    margin-right: 8px; font-size: 0.9em; font-weight: 600; transition: background 0.2s;
}
.history-entry {
    border: 1px solid #cceeff; background: #ecf0f1; padding: 15px; 
    border-radius: 8px; margin-bottom: 10px; border-left: 5px solid #3498db;
}
.history-entry h4 { margin: 0 0 5px 0; color: #2980b9; font-size: 1.1rem; display: flex; justify-content: space-between; align-items: center;}
.winner-name { color: #e67e22; font-weight: 900; }
.history-details summary { cursor: pointer; font-weight: 700; color: #2c3e50; }
.result-list { list-style: none; padding-left: 10px; font-size: 0.9em; }

/* --- 2. GAME STAGE (FULLSCREEN) --- */
#lsq-game-stage {
    /* Đảm bảo game stage luôn nằm trên mọi thứ */
    position: fixed !important; top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important; 
    z-index: 9999999 !important; /* Tăng cường Z-index */
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #1e3c72 100%) !important;
    color: white; font-weight: 700;
    display: flex; flex-direction: column;
    align-items: center;
}
.game-top-bar {
    width: 100%; padding: 20px 40px; display: flex; justify-content: space-between;
    background: rgba(0,0,0,0.5); box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    font-size: 1.3rem;
    z-index: 10 !important; 
}
.player-status { display: flex; align-items: center; gap: 15px; }
.class-info { color: #f1c40f; }
.topic-info { color: #74b9ff; }
.stage-info { color: #2ecc71; font-weight: 900; }

/* Vòng Quay (Nổi bật) */
.game-stage-content { width: 100%; flex-grow: 1; display: flex; justify-content: center; }
#stage-round-1 { align-items: center; }
.wheel-container { 
    position: relative; 
    margin-top: 50px; 
    text-align: center; 
    display: flex; 
    flex-direction: column;
    align-items: center;
}
#wheel-canvas { 
    box-shadow: 0 0 50px rgba(0,0,0,0.8), 0 0 100px #3498db; 
    border: 10px solid #fff;
    border-radius: 50%;
}
.wheel-arrow {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%) translateY(-10px);
    width: 0; height: 0; border-left: 30px solid transparent; border-right: 30px solid transparent;
    border-top: 50px solid #e74c3c; z-index: 10; filter: drop-shadow(0 0 5px black);
}
.spin-btn {
    /* Sửa lại căn giữa với !important */
    position: absolute !important; top: 50% !important; left: 50% !important; 
    transform: translate(-50%, -50%) !important; 
    width: 120px !important; height: 120px !important; border-radius: 50% !important;
    background: linear-gradient(45deg, #f1c40f, #e67e22) !important; color: #333 !important; font-weight: 900 !important; 
    border: 6px solid #fff !important; box-shadow: 0 0 20px rgba(0,0,0,0.8) !important; font-size: 1.2rem !important;
    
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important; 
    z-index: 15 !important; /* Tăng Z-index cho nút QUAY */
}
.spin-btn.spinning { 
    animation: pulse-shadow 0.5s infinite alternate;
}
@keyframes pulse-shadow {
    from { box-shadow: 0 0 20px rgba(255, 255, 255, 0.5); }
    to { box-shadow: 0 0 40px rgba(255, 255, 255, 1); }
}

.winner-display { margin-top: 30px; font-size: 2.5rem; text-shadow: 2px 2px #000; }
#display-winner { color: #ffd700; font-weight: 900; }
.highlight { animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.1); } }

/* --- 3. MODAL (Chung) --- */
/* Dành cho Quiz Modal (vẫn full screen) và Alert Modal */
.lsq-modal { 
    position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; 
    background: rgba(0,0,0,0.9) !important; 
    z-index: 10000000 !important; /* MAX EMERGENCY Z-index cho Modal */
    display: flex !important; justify-content: center !important; align-items: center !important;
}
.modal-content {
    background: linear-gradient(135deg, #f0f0f5 0%, #ffffff 100%); 
    color: #2c3e50; border-radius: 20px; 
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    padding: 40px; width: 90%; max-width: 800px;
    text-align: center;
    position: relative; 
}

/* NÚT ĐÓNG NỔI (Dùng chung cho Quiz Modal và Alert Modal) */
/* Thêm class .close-modal-btn để dễ dàng bắt sự kiện trong JS */
.lsq-modal .float-close-btn, .leaderboard-dropdown .float-close-btn {
    position: absolute !important;
    top: -15px !important; 
    right: -15px !important; 
    padding: 10px 15px !important;
    font-size: 1.2rem !important;
    background: #e74c3c !important;
    color: white !important;
    border-radius: 50% !important; 
    box-shadow: 0 4px #c0392b !important;
    z-index: 10000001 !important; /* Đảm bảo nút đóng nằm trên Modal */
    cursor: pointer !important;
    line-height: 1 !important; /* Đảm bảo chữ X căn giữa */
    text-align: center !important;
}
.lsq-modal .float-close-btn:hover, .leaderboard-dropdown .float-close-btn:hover { background: #c0392b !important; }

/* Quiz Modal và các phần khác (Giữ nguyên) */
.quiz-title { font-size: 2.2rem; font-weight: 700; color: #2980b9; margin-bottom: 25px; }
.answers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.answer-btn {
    padding: 20px; font-size: 1.3rem; background: #ecf0f1; border: 2px solid #bdc3c7;
    border-radius: 12px; transition: all 0.2s; font-weight: 600;
    white-space: normal; 
    height: auto;
}
.answer-btn:hover:not(:disabled) { background: #d5dbdb; transform: translateY(-3px); box-shadow: 0 5px 10px rgba(0,0,0,0.1); }
.answer-btn.correct { background: #2ecc71 !important; color: white; border-color: #27ae60; box-shadow: 0 5px 15px rgba(46, 204, 113, 0.5); }
.answer-btn.wrong { background: #e74c3c !important; color: white; border-color: #c0392b; box-shadow: 0 5px 15px rgba(231, 76, 60, 0.5); }
.feedback { font-size: 2rem; margin-top: 15px; }

/* Competitive Stage (Giữ nguyên) */
#competitive-stage { padding-top: 100px; flex-direction: column; align-items: center; }
.comp-info-card {
    font-size: 1.8rem; color: #ffd700; background: rgba(0,0,0,0.5);
    padding: 20px 40px; border-radius: 15px; border: 2px solid #ffd700;
    text-align: center; margin-bottom: 30px;
}
.student-list-comp {
    width: 90%; max-width: 600px; background: rgba(255, 255, 255, 0.15); border-radius: 15px;
    list-style: none; padding: 0;
}
.student-list-comp li {
    padding: 15px; border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 1.5rem; display: flex; justify-content: space-between;
}
.student-list-comp li.active {
    background: rgba(255, 255, 255, 0.3); color: #f1c40f; 
    border-left: 8px solid #f1c40f;
}

/* --- LEADERBOARD DROP-DOWN (FIXED UI & SCROLL) --- */
.leaderboard-dropdown {
    position: absolute !important; 
    top: 85px !important; 
    right: 40px !important; 
    z-index: 9999999 !important; /* Z-index cao */
    width: 350px !important; 
    box-shadow: 0 15px 40px rgba(0,0,0,0.5) !important;
    border-radius: 15px !important;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    transform: translateY(-20px);
    opacity: 0;
}

/* Áp dụng display block/none an toàn hơn */
.leaderboard-dropdown.hidden {
    display: block !important; /* Giữ block để transition */
    opacity: 0 !important;
    transform: translateY(-20px) !important;
    pointer-events: none !important; /* Vô hiệu hóa tương tác khi ẩn */
}

.leaderboard-dropdown:not(.hidden) {
    opacity: 1 !important;
    transform: translateY(0) !important;
    pointer-events: auto !important;
}

.leaderboard-box { 
    padding: 20px;
    background: linear-gradient(135deg, #f0f0f5 0%, #ffffff 100%); 
    color: #2c3e50; 
    border-radius: 15px;
    max-width: none; 
    max-height: 80vh !important; /* Đảm bảo chiều cao tối đa */
    position: relative;
    text-align: left; 
    overflow-y: auto !important; /* Kích hoạt thanh cuộn */
}

/* Nút đóng nổi cho Dropdown (sử dụng style chung) */
.leaderboard-dropdown .float-close-btn {
    top: 5px !important; 
    right: 5px !important; 
    padding: 5px 10px !important;
    font-size: 0.8rem !important;
    z-index: 10000002 !important; /* Cao hơn dropdown */
}

/* Style cho thông tin Lớp/Chủ đề (Giữ nguyên) */
.context-info { 
    font-size: 1.1rem;
    font-weight: 600;
    color: #3498db;
    margin-bottom: 15px;
    border-bottom: 2px solid #ccc;
    padding-bottom: 5px;
}
.leaderboard-list-container {
    padding-right: 5px; 
    margin-bottom: 20px;
}
#leaderboard-list { 
    list-style: none; 
    padding: 0; 
}
#leaderboard-list li {
    font-size: 1.2rem;
    padding: 12px 15px; 
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    transition: background 0.2s;
    background-color: #ffffff; 
}
#leaderboard-list li:nth-child(odd) { background-color: #f7f7f7; } 
#leaderboard-list li:hover { background-color: #e8f4f8; }

/* Highlight Top 3 chuyên nghiệp (Giữ nguyên) */
#leaderboard-list li:nth-child(1) { background: linear-gradient(90deg, #ffd700 0%, #fffbe6 5%); color: #e67e22; font-size: 1.3rem; border-color: #f1c40f; font-weight: 900; }
#leaderboard-list li:nth-child(2) { background: linear-gradient(90deg, #bdc3c7 0%, #f3f9f1 5%); color: #2ecc71; font-weight: 800; }
#leaderboard-list li:nth-child(3) { background: linear-gradient(90deg, #95a5a6 0%, #f0f4f9 5%); color: #3498db; font-weight: 800; }

.score-value { font-weight: 900; }