/* Thiết lập cơ bản */
body {
    font-family: Arial, sans-serif;
    background-color: #f0f4f8;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 10px;
}
#app-container {
    width: 100%;
    max-width: 800px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    overflow: visible; 
}
.hidden {
    display: none !important;
}

/* Header & Menu */
#mode-selection { padding: 20px 25px; }

.home-header { 
    display: flex; 
    flex-direction: row; 
    align-items: center; 
    justify-content: flex-start; 
    padding-bottom: 15px; 
    margin-bottom: 15px; 
    border-bottom: 2px solid #0d47a1;
    text-align: left;
}

.app-logo {
    width: 80px;
    height: 80px;
    margin-right: 20px;
    margin-bottom: 0;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}
.app-logo:hover { transform: scale(1.05); }

.header-text {
    display: flex;
    flex-direction: column;
}

.home-header h1 { 
    color: #0d47a1; 
    margin: 0 0 5px 0; 
    font-size: 1.4em; 
    text-transform: uppercase; 
    line-height: 1.2;
}
.home-header p { 
    font-size: 0.95em; 
    color: #555; 
    margin: 0; 
}

.mode-options { margin-top: 15px; display: flex; flex-direction: column; gap: 10px; }
.mode-row { display: flex; gap: 10px; width: 100%; }
.mode-row button { flex: 1; }

.mode-options button { 
    padding: 15px;
    font-size: 1.05em; 
    border: 2px solid #0d47a1; 
    background-color: #e3f2fd; 
    color: #0d47a1; 
    border-radius: 8px; 
    cursor: pointer; 
    text-align: center; 
    display: flex; flex-direction: column; justify-content: space-between; 
}
.mode-options button:hover { background-color: #bbdefb; }
.mode-options button strong { display: block; margin-bottom: 4px; text-transform: uppercase; }
.mode-options button span { font-size: 0.85em; color: #1976d2; }

.toggle-topics-btn { background-color: #e8eaf6 !important; border-style: dashed !important; color: #3f51b5 !important; }
.toggle-topics-btn:hover { background-color: #c5cae9 !important; }

/* Menu Chủ đề 3 Cột */
.topic-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); 
    gap: 6px;
    margin-top: 5px;
    padding: 8px;
    background-color: #fafafa;
    border: 1px solid #ddd;
    border-radius: 8px;
    animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.topic-btn { padding: 8px 10px; font-size: 0.9em; border: 1px solid #90caf9; background-color: white; color: #1565c0; border-radius: 5px; cursor: pointer; text-align: left; transition: all 0.2s; display: flex; flex-direction: column; gap: 2px; }
.topic-btn:hover { background-color: #1976d2; color: white; border-color: #1976d2; }
.topic-header { display: flex; align-items: flex-start; gap: 4px; font-weight: bold; line-height: 1.1; }
.topic-number { background-color: #e3f2fd; color: #1565c0; padding: 1px 3px; border-radius: 3px; font-size: 0.8em; flex-shrink: 0; }
.topic-info { font-size: 0.8em; color: #666; display: flex; justify-content: space-between; width: 100%; margin-top: 2px; }
.topic-btn:hover .topic-number, .topic-btn:hover .topic-info { color: #e3f2fd; background-color: transparent; }

.mode-group-title { font-size: 1.1em; font-weight: bold; color: #555; margin-top: 15px; margin-bottom: 0; text-align: left; border-bottom: 1px solid #eee; padding-bottom: 3px; }
.mode-options .mode-group-title:first-of-type { margin-top: 0; }

/* Bảng quy định điểm */
.exam-rules { margin-top: 15px; padding: 10px; background-color: #f9f9f9; border-radius: 8px; text-align: center; font-size: 0.85em; color: #444; }
.exam-rules p { font-weight: bold; margin-bottom: 8px; margin-top: 0; }
.rules-table { width: auto; min-width: 300px; margin: 10px auto; border-collapse: collapse; background-color: white; font-size: 1em; }
.rules-table th, .rules-table td { border: 1px solid #ddd; padding: 5px; text-align: center; }
.rules-table th { background-color: #e3f2fd; color: #0d47a1; font-weight: bold; }
.rules-table tr:nth-child(even) { background-color: #f2f2f2; }
.rules-table .failed-row { color: #c62828; font-weight: bold; }

/* Footer */
footer { 
    margin-top: 15px; 
    padding-top: 15px; 
    border-top: 1px solid #eee; 
    font-size: 0.85em; 
    position: relative; 
    display: flex;
    justify-content: flex-end; 
    align-items: center;
    min-height: 100px; 
}
.footer-branding {
    position: absolute;
    left: 0; right: 0; top: 50%;
    transform: translateY(-50%); 
    text-align: center;
    width: 100%;
    z-index: 0;
    display: flex; flex-direction: column; gap: 5px;
    padding-right: 160px; padding-left: 20px; box-sizing: border-box;
}
.footer-slogan { font-style: normal; font-weight: normal; color: #1565c0; margin: 0; }
.footer-email { font-size: 0.9em; color: #757575; font-style: italic; margin-top: 15px; }
.donation-container {
    display: flex; flex-direction: column; align-items: flex-end; text-align: right; gap: 5px;
    position: relative; z-index: 1; background-color: rgba(255, 255, 255, 0.9); padding-left: 10px;
}
.donation-text { font-size: 0.95em; color: #0d47a1; font-weight: bold; white-space: nowrap; }
.qr-code-img { width: 80px; height: auto; border: 1px solid #ddd; border-radius: 4px; padding: 2px; background: white; }

/* Quiz Styles */
#quiz-container { padding: 20px; }
#quiz-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #ddd; font-size: 1em; gap: 10px; }
#back-to-menu-btn { background-color: #f5f5f5; color: #555; border: 1px solid #ddd; padding: 6px 10px; font-size: 0.9em; font-weight: bold; border-radius: 5px; cursor: pointer; }
#quiz-mode-title { font-weight: bold; color: #0d47a1; flex-grow: 1; text-align: center; text-transform: uppercase; }
#timer-container { color: #d32f2f; font-weight: bold; white-space: nowrap; }
#header-submit-btn { background-color: #2e7d32; color: white; border: none; padding: 6px 12px; font-size: 0.9em; font-weight: bold; border-radius: 5px; cursor: pointer; }

/* Ma trận câu hỏi (Đã thu nhỏ kích thước) */
#question-matrix {
    display: grid;
    /* Mỗi ô tối thiểu 30px (nhỏ hơn trước) để xếp được nhiều hơn */
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 5px; /* Giảm khoảng cách cho gọn */
    justify-content: start;
    
    margin-top: 20px;
    padding-top: 15px;
    padding-right: 5px; 
    border-top: 1px solid #eee;
    
    max-height: 250px; 
    overflow-y: auto;  
    scrollbar-width: thin;
}

#question-matrix::-webkit-scrollbar { width: 6px; }
#question-matrix::-webkit-scrollbar-thumb { background-color: #ccc; border-radius: 3px; }
#question-matrix::-webkit-scrollbar-track { background-color: #f1f1f1; }

.matrix-box { 
    width: 100%; 
    height: 28px; /* Giảm chiều cao xuống 28px */
    display: flex; 
    justify-content: center; 
    align-items: center; 
    font-size: 0.85em; /* Giảm font một chút cho vừa ô nhỏ */
    font-weight: bold; 
    border: 1px solid #ccc; 
    border-radius: 4px; 
    background-color: #f5f5f5; 
    color: #555; 
    cursor: pointer; 
    transition: all 0.2s; 
}
.matrix-box:hover { background-color: #e0e0e0; border-color: #999; }
.matrix-box.answered { background-color: #e3f2fd; border-color: #1976d2; color: #0d47a1; }
.matrix-box.current { border-color: #d32f2f; color: #d32f2f; font-weight: 800; background-color: #fff; box-shadow: 0 0 3px rgba(211, 47, 47, 0.5); }

/* Settings */
#quiz-settings { 
    margin-top: 20px; 
    padding-top: 15px; 
    border-top: 1px solid #eee; 
    display: flex;
    flex-wrap: wrap; 
    justify-content: center; 
    gap: 20px; 
    color: #333;
    font-size: 0.9em; 
}
.setting-item { display: flex; align-items: center; cursor: pointer; }
#quiz-settings label { margin-left: 5px; cursor: pointer; }

#question-text { font-size: 1.05em; font-weight: bold; margin-bottom: 20px; line-height: 1.4; }

/* Options 2x2 */
#options-container { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.option-btn { width: 100%; padding: 8px 10px; font-size: 0.95em; text-align: left; background-color: #f5f5f5; border: 2px solid #ddd; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; height: 100%; }
.option-btn:hover { background-color: #e0e0e0; border-color: #1976d2; }
.option-radio { width: 14px; height: 14px; border: 1.5px solid #555; border-radius: 50%; background-color: #fff; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.option-label { line-height: 1.3; }
.option-label strong { color: #0d47a1; }
.option-btn.selected { background-color: #bbdefb; border-color: #0d47a1; }
.option-btn.selected .option-radio { border-color: #0d47a1; }
.option-btn.selected .option-radio::after { content: ''; width: 7px; height: 7px; background-color: #0d47a1; border-radius: 50%; }
.option-btn.correct { background-color: #c8e6c9; border-color: #2e7d32; color: #2e7d32; }
.option-btn.correct .option-radio { border-color: #2e7d32; background-color: #2e7d32; }
.option-btn.correct .option-radio::after { content: '✔'; color: white; font-size: 9px; font-weight: bold; }
.option-btn.incorrect { background-color: #ffcdd2; border-color: #c62828; color: #c62828; }
.option-btn.incorrect .option-radio { border-color: #c62828; background-color: #c62828; }
.option-btn.incorrect .option-radio::after { content: '×'; color: white; font-size: 11px; font-weight: bold; }

#feedback-container { margin-top: 20px; padding: 15px; background-color: #fffde7; border: 1px solid #fbc02d; border-radius: 8px; }
#feedback-text, .review-item .feedback-container { margin-top: 5px; font-size: 0.9em; line-height: 1.5; white-space: pre-wrap; }
#navigation-container { margin-top: 15px; display: flex; }
#navigation-container button { padding: 10px 20px; font-size: 0.95em; font-weight: bold; border: none; border-radius: 5px; cursor: pointer; }
#prev-btn { background-color: #eee; color: #555; }
#next-btn { background-color: #1976d2; color: white; margin-left: auto; }

/* Kết quả */
#results-container { padding: 25px; }
.results-layout { display: flex; justify-content: space-between; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin-top: 15px; }
.results-details { flex-basis: 60%; display: flex; flex-direction: column; gap: 10px; }
.detail-item { display: flex; justify-content: space-between; font-size: 1em; }
.results-score { flex-basis: 35%; text-align: center; border-left: 2px solid #eee; padding-left: 15px; }
.score-value { font-size: 3.5em; font-weight: bold; color: #0d47a1; }

.results-navigation, .review-footer-nav { margin-top: 20px; text-align: center; }
.results-navigation button, .review-footer-nav button { padding: 10px 20px; margin: 5px; border: none; border-radius: 5px; font-weight: bold; cursor: pointer; }
#restart-btn, #restart-btn-bottom { background-color: #1976d2; color: white; }
#review-btn, #scroll-to-top-btn { background-color: #fbc02d; color: #333; }
#back-to-menu-btn-results, #back-to-menu-btn-bottom { background-color: #757575; color: white; }

/* Review Items */
#review-section { margin-top: 25px; text-align: left; }
.review-item { padding: 12px; margin-bottom: 10px; border-radius: 8px; border: 1px solid #ddd; scroll-margin-top: 160px; }
.review-item p { margin-bottom: 6px; margin-top: 0; font-size: 0.95em; }
.review-item.review-correct { background-color: #f1f8e9; }
.review-item.review-incorrect { background-color: #fff3f3; }
.review-item.review-unanswered { background-color: #fff3f3; border-color: #c62828; }

.review-options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.review-answer { padding: 5px 8px; border-radius: 5px; border: 1px solid #ddd; background-color: #fff; display: flex; align-items: center; gap: 6px; font-size: 0.9em; }
.review-answer.correct { background-color: #c8e6c9; border-color: #2e7d32; color: #2e7d32; }
.review-answer.user-wrong { background-color: #ffcdd2; border-color: #c62828; color: #c62828; text-decoration: line-through; }
.review-explanation-hr { border: none; border-top: 1px dashed #ccc; margin-top: 8px; margin-bottom: 8px; }

/* Sticky Header */
#review-sticky-header {
    position: sticky; top: 0; z-index: 1000; background-color: #ffffff;
    border-bottom: 2px solid #0d47a1; padding: 8px 0; margin-bottom: 15px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.review-header-title { font-weight: bold; text-align: center; margin-bottom: 5px; color: #0d47a1; font-size: 0.85em; }
#review-filters { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.filter-btn { padding: 4px 10px; border: 1px solid #ddd; background-color: #fff; border-radius: 15px; cursor: pointer; font-size: 0.8em; font-weight: bold; }
.filter-btn.active { background-color: #e3f2fd; border-color: #1976d2; color: #0d47a1; }

#review-matrix {
    display: grid; 
    /* Đồng bộ kích thước với ma trận chính */
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); 
    gap: 5px; 
    justify-content: start; 
    
    max-height: 35vh; 
    overflow-y: auto; 
    padding: 0 5px;
    scrollbar-width: thin;
}
.review-box { height: 28px; display: flex; justify-content: center; align-items: center; font-size: 0.85em; font-weight: bold; border: 1px solid #ccc; border-radius: 3px; cursor: pointer; }
.review-box.correct { background-color: #c8e6c9; border-color: #2e7d32; color: #2e7d32; }
.review-box.incorrect { background-color: #ffcdd2; border-color: #c62828; color: #c62828; }
.review-box.unanswered { background-color: #f5f5f5; border-color: #c62828; color: #c62828; }

.toggle-explanation-btn { background-color: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; padding: 5px 10px; border-radius: 5px; cursor: pointer; font-size: 0.85em; font-weight: bold; margin-top: 5px; width: 100%; text-align: left; }
.toggle-explanation-btn:hover { background-color: #bbdefb; }

/* --- PHẦN THÊM MỚI CHO DASHBOARD (Plugin) --- */
.auth-btn {
    padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer;
    font-size: 13px; color: white; background-color: #4285F4; margin-left: 5px;
}
.auth-btn:hover { opacity: 0.9; }
.dashboard-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 10000;
    display: flex; justify-content: center; align-items: center;
}
.dashboard-content {
    background: white; padding: 20px; border-radius: 8px; width: 90%; max-width: 500px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
#scoreTable td, #scoreTable th { text-align: center; font-size: 14px; color: #333; }

/* Responsive */
@media (max-width: 700px) {
    body { padding: 10px; }
    #mode-selection, #quiz-container, #results-container { padding: 10px; }
    
    .home-header { flex-direction: column; text-align: center; }
    .app-logo { margin-right: 0; margin-bottom: 10px; }
    
    .mode-row { flex-direction: column; gap: 10px; }
    .mode-row button { width: 100%; }
    
    .topic-grid { grid-template-columns: repeat(2, 1fr); }
    
    #quiz-header { flex-wrap: wrap; gap: 10px; }
    #quiz-mode-title { order: -1; flex-basis: 100%; }
    
    /* Mobile: Giảm thêm chút nữa cho vừa màn hình nhỏ */
    #question-matrix, #review-matrix {
        grid-template-columns: repeat(auto-fill, minmax(28px, 1fr)); 
    }
    
    .matrix-box, .review-box { height: 28px; font-size: 0.8em; }
    #options-container, .review-options-grid { gap: 8px; }
    .results-layout { flex-direction: column; gap: 20px; }
    .results-score { border-left: none; border-top: 2px solid #eee; padding-top: 20px; }
    .score-value { font-size: 3.5em; }
    .results-navigation button, .review-footer-nav button { width: 100%; margin: 5px 0; }
    
    .rules-table { font-size: 0.85em; }
    .rules-table th, .rules-table td { padding: 5px; }
    
    /* Footer mobile */
    footer { flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding-bottom: 20px; }
    .footer-branding { position: static; transform: none; width: auto; padding: 0; }
    .donation-container { align-items: center; text-align: center; padding-left: 0; }

    @media (max-width: 400px) { 
        #options-container, .review-options-grid { grid-template-columns: 1fr; } 
        .topic-grid { grid-template-columns: 1fr; }
    }
}