/* =================================================================== */
/* 1. ĐỊNH NGHĨA BIẾN MÀU SẮC (CHO 2 CHẾ ĐỘ) */
/* =================================================================== */
:root {
    /* Chế độ Sáng (Mặc định) */
    --bg-primary: #f4f7fa;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --border-color: #e0e0e0;
    --accent-primary: #5a67d8;
    --accent-secondary: #4a90e2;
    --correct-color: #28a745;
    --wrong-color: #dc3545;
    --info-bg: #e6f7ff;
    --info-border: #b3e0ff;
    --info-text: #0056b3;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    
    /* Màu mức độ (Mới) */
    --level-easy-bg: #e7f7f0;
    --level-easy-text: #1d7246;
    --level-medium-bg: #fff8e1;
    --level-medium-text: #8a6d3b;
    --level-hard-bg: #fff0f0;
    --level-hard-text: #dc3545;
    --level-vhard-bg: #f3e5f5;
    --level-vhard-text: #6a1b9a;
    --level-default-bg: #f4f4f4;
    --level-default-text: #555;
}

body.dark-mode {
    /* Chế độ Tối (Khi có class .dark-mode) */
    --bg-primary: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --text-primary: #f2f2f2;
    --text-secondary: #aaa;
    --border-color: #3a3a3c;
    --info-bg: #2a3b4c;
    --info-border: #3a4c5e;
    --info-text: #b3e0ff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    
    /* Màu mức độ (Tối) */
    --level-easy-bg: #2a3b2e;
    --level-easy-text: #69c08a;
    --level-medium-bg: #3b3a2a;
    --level-medium-text: #f0e68c;
    --level-hard-bg: #3b2a2a;
    --level-hard-text: #f5c6cb;
    --level-vhard-bg: #3e2753;
    --level-vhard-text: #ce93d8;
    --level-default-bg: #3a3a3c;
    --level-default-text: #aaa;
}

/* =================================================================== */
/* 2. CÀI ĐẶT CHUNG (BODY, FONT) */
/* =================================================================== */
body {
    font-family: 'Lexend', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    padding: 20px;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    width: 100%;
    max-width: 1200px; 
    margin: auto;
    min-height: calc(100vh - 160px); 
}

h1, h2, h3, h4 {
    font-weight: 600;
}

/* =================================================================== */
/* 3. BỘ CHUYỂN ĐỔI CHẾ ĐỘ TỐI/SÁNG (THEME SWITCHER) */
/* =================================================================== */
.theme-switcher-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--text-secondary);
}
.theme-switcher-wrapper .material-icons-outlined {
    font-size: 1.2rem;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.theme-switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--accent-primary);
}
input:checked + .slider:before {
    transform: translateX(20px);
}

/* =================================================================== */
/* 4. BỐ CỤC CHUNG (ĐÃ CHUYỂN SANG 1 CỘT) */
/* =================================================================== */

/* LOGO HEADER */
.page-title {
    text-align: center;
    margin-bottom: 20px;
}
.page-logo {
    display: inline-block;
}
.page-logo img {
    max-height: 45px; 
    width: auto;
    transition: filter 0.3s;
	filter: none;
}
body.dark-mode .page-logo img {
    filter: invert(1); 
}

/* Định nghĩa chung cho các khối nội dung */
.sidebar-block {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 20px;
    transition: background-color 0.3s, border-color 0.3s;
}

/* THÊM KHOẢNG CÁCH GIỮA CÁC KHỐI */
.sidebar-block,
.quiz-game-container,
.comment-section {
    margin-bottom: 30px;
}

/* =================================================================== */
/* 5. KHỐI NỘI DUNG (BÀI HỌC, CÂU HỎI, BÌNH LUẬN) */
/* =================================================================== */

/* Khối Thông tin bài học */
.lesson-info h3 {
    margin-top: 0;
    color: var(--accent-primary);
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}
.breadcrumbs {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 15px; 
}
.breadcrumbs a {
    color: var(--accent-secondary);
    text-decoration: none;
}
.breadcrumbs a:hover {
    text-decoration: underline;
}
.lesson-title-h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
    margin: 15px 0 0 0; 
}

/* NÚT CTA CHÍNH (ĐÃ NÂNG CẤP) */
.primary-cta-button {
    background-image: linear-gradient(45deg, var(--accent-primary) 0%, #4a56b1 100%);
    color: white;
    border: none; 
    border-radius: 50px; 
    padding: 14px 24px; 
    font-weight: 600;
    font-family: 'Lexend', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center; 
    gap: 10px;
    margin-top: 20px;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 5px 15px rgba(90, 103, 216, 0.5);
    position: relative;
    overflow: hidden; 
}
.primary-cta-button .material-icons-outlined {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}
.primary-cta-button:hover {
    filter: brightness(1.1);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(90, 103, 216, 0.6);
}
.primary-cta-button:hover .material-icons-outlined {
    transform: translateX(3px) scale(1.05);
}
.primary-cta-button:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(90, 103, 216, 0.5);
    filter: brightness(1); 
}

/* NHÓM NÚT BẤM BÀI HỌC */
.lesson-button-group {
    display: flex;
    flex-wrap: wrap; 
    gap: 10px;
    margin-top: 20px; 
}

/* NÚT CHIA SẺ */
.share-button {
    background-color: transparent;
    border: 2px solid var(--accent-secondary);
    color: var(--accent-secondary);
    border-radius: 25px;
    padding: 8px 15px;
    font-weight: 600;
    font-family: 'Lexend', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 0; 
    transition: all 0.3s ease;
}
.share-button:hover {
    background-color: var(--accent-secondary);
    color: white;
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.3);
}
.share-button .material-icons-outlined {
    font-size: 1.1rem;
}

/* NÚT FLASHCARD */
.secondary-cta-button {
    background-color: var(--accent-secondary);
    border: 2px solid var(--accent-secondary);
    color: white;
    border-radius: 25px;
    padding: 8px 15px;
    font-weight: 600;
    font-family: 'Lexend', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.3);
}
.secondary-cta-button:hover {
    background-color: #3a7bc8;
    border-color: #3a7bc8;
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
    transform: translateY(-1px);
}
.secondary-cta-button .material-icons-outlined {
    font-size: 1.1rem;
}

/* Khối Câu hỏi (Nội dung chính) */
.quiz-game-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 25px;
    transition: background-color 0.3s, border-color 0.3s;
}

/* THẺ MỨC ĐỘ CÂU HỎI */
.question-difficulty-wrapper {
    margin-bottom: 20px; 
    text-align: left;
}
/* ================================== */
/* THẺ MỨC ĐỘ CÂU HỎI (ĐÃ CẬP NHẬT) */
/* ================================== */
.question-difficulty-wrapper {
    margin-bottom: 20px; /* Khoảng cách với câu hỏi bên dưới */
    text-align: left;
}
.question-difficulty-tag {
    display: inline-block;
    padding: 7px 16px; /* <-- Tăng nhẹ padding */
    border-radius: 20px;
    font-size: 0.9rem; /* <-- Tăng nhẹ font size */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s;
    /* THÊM BÓNG ĐỔ NHẸ */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); 
}
/* Màu sắc cho từng mức độ (giữ nguyên) */
.level-nhan-biet {
    background-color: var(--level-easy-bg);
    color: var(--level-easy-text);
}
.level-thong-hieu {
    background-color: var(--level-medium-bg);
    color: var(--level-medium-text);
}
.level-van-dung {
    background-color: var(--level-hard-bg);
    color: var(--level-hard-text);
}
.level-van-dung-cao {
    background-color: var(--level-vhard-bg);
    color: var(--level-vhard-text);
}
.level-default { /* Fallback cho các loại khác */
    background-color: var(--level-default-bg);
    color: var(--level-default-text);
}
/* ================================== */
/* KẾT THÚC CSS MỨC ĐỘ */
/* ================================== */


.question-content {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.6;
    margin-bottom: 30px;
    text-align: left;
}
.question-content p {
    margin: 0;
}

/* CĂN CHỈNH HÌNH ẢNH (CÔNG THỨC DẠNG ẢNH) */
.question-content p img,
.answer-option h6 img,
.answer-option p img,
.answer-option img { 
    display: inline;
    vertical-align: -0.3em;   
    width: auto;
    margin: 0 3px;
}

/* ================================== */
/* BỔ SUNG: XỬ LÝ ẢNH BASE64 (MỚI) */
/* ================================== */
.answer-option .imd img,
.explanation-box .imd img {
    max-width: 100%; /* Đảm bảo ảnh không tràn khỏi ô */
    height: auto;    /* Giữ đúng tỷ lệ */
    vertical-align: middle; /* Căn giữa với text (ví dụ: "A. ") */
    margin-left: 5px;
}
/* ================================== */
/* KẾT THÚC BỔ SUNG */
/* ================================== */

.answer-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}
@media (min-width: 600px) {
    .answer-grid {
        grid-template-columns: 1fr 1fr;
    }
}
.answer-option {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}
.answer-option .material-icons-outlined {
    color: var(--text-secondary);
    transition: color 0.3s;
}
.answer-option:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-secondary);
    color: var(--accent-primary);
}
.answer-option:hover .material-icons-outlined {
    color: var(--accent-primary);
}
.answer-option.correct {
    border-color: var(--correct-color);
    background-color: #f0fff4;
    color: var(--correct-color);
    font-weight: 600;
}
.answer-option.wrong {
    border-color: var(--wrong-color);
    background-color: #fff0f0;
    color: var(--wrong-color);
    font-weight: 600;
}
body.dark-mode .answer-option.correct {
    background-color: #2a3b2e;
}
body.dark-mode .answer-option.wrong {
    background-color: #3b2a2a;
}
.answer-option.correct .material-icons-outlined { color: var(--correct-color); }
.answer-option.wrong .material-icons-outlined { color: var(--wrong-color); }
.answer-option h6, .answer-option p {
    margin: 0;
    font-size: 1rem;
    font-weight: 500; 
}

.explanation-box {
    background: var(--info-bg);
    border: 1px solid var(--info-border);
    color: var(--info-text);
    border-radius: 8px;
    padding: 20px;
    margin-top: 30px;
    transition: all 0.3s;
    /* Cho phép text-align từ CSDL */
    text-align: left; 
}
.explanation-box h4 {
    color: var(--info-text);
    margin: 0 0 10px 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
}
.explanation-box p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
}
/* Cập nhật cho khối giải thích */
.explanation-box > div {
    font-size: 0.95rem;
    line-height: 1.6;
}
.explanation-box > div p {
    margin-top: 10px; /* Thêm khoảng cách giữa các đoạn P trong giải thích */
}
.explanation-box > div p:first-child {
    margin-top: 0;
}


/* Khối Bình luận (Nội dung chính) */
.comment-section {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 25px;
    transition: background-color 0.3s, border-color 0.3s;
}
.comment-section h2 {
    color: var(--text-primary);
    text-align: left;
    margin-top: 0;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.comment-section h2 .material-icons-outlined {
    color: var(--accent-secondary);
}

.comment-form { 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    margin-bottom: 30px; 
}
.comment-form input, .comment-form textarea { 
    width: 100%; 
    padding: 12px 15px; 
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 8px; 
    font-family: var(--font-main); 
    font-size: 1rem; 
    box-sizing: border-box; 
    transition: all 0.3s;
}
.comment-form input:focus, .comment-form textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.2);
}
.comment-form textarea { 
    min-height: 100px; 
    resize: vertical; 
}
.submit-comment-btn { 
    background: var(--accent-secondary); 
    color: white; 
    padding: 10px 20px; 
    border: none; 
    border-radius: 25px; 
    font-size: 1rem; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.3s ease; 
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.3);
    align-self: flex-start; 
    display: inline-flex; 
    align-items: center; 
    gap: 8px; 
}
.submit-comment-btn:hover { 
    background: #3a7bc8; 
    transform: translateY(-2px);
}
.comment-list { 
    list-style: none; 
    padding: 0; 
    margin: 0; 
    display: flex; 
    flex-direction: column; 
    gap: 20px; 
}
.comment-item { 
    display: flex; 
    gap: 15px; 
    background: var(--bg-primary);
    padding: 15px; 
    border-radius: 8px; 
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}
.comment-avatar { 
    width: 40px; 
    height: 40px; 
    border-radius: 50%; 
    background: var(--accent-primary); 
    color: white; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: 600; 
    font-size: 1.2rem; 
    flex-shrink: 0; 
}
.comment-content { 
    flex-grow: 1; 
}
.comment-author { 
    font-weight: 600; 
    color: var(--text-primary); 
    margin: 0 0 5px 0; 
}
.comment-text { 
    font-size: 0.95rem; 
    line-height: 1.6; 
    color: var(--text-secondary); 
    margin: 0; 
}
.comment-date { 
    font-size: 0.8rem; 
    color: var(--text-secondary); 
    margin-top: 8px; 
}

/* =================================================================== */
/* 6. MODAL (CHUNG) */
/* =================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-dark);
    text-align: center;
    width: 90%;
    max-width: 400px;
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s ease;
    position: relative;
}
.modal-overlay.show .modal-content {
    transform: scale(1);
    opacity: 1;
}

.modal-close-icon {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.modal-close-icon:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

/* MODAL FLASHCARD */
.flashcard-modal-icon {
    font-size: 3rem;
    color: var(--accent-primary);
    margin-bottom: 10px;
}
.flashcard-modal-icon .material-icons-outlined {
    font-size: 3rem; 
}
#flashcard-modal-content h3 {
    margin-top: 0;
    color: var(--text-primary);
}
#flashcard-modal-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 25px;
}
.flashcard-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}
.modal-cancel-btn {
    background-color: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 50px;
    padding: 12px 24px;
    font-weight: 600;
    font-family: 'Lexend', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}
.modal-cancel-btn:hover {
    background-color: var(--bg-primary);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}


/* MODAL CHIA SẺ */
#share-modal-content h3 {
    margin-top: 0;
    color: var(--text-primary);
}
#share-modal-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 20px;
}
.share-options {
    display: flex;
    justify-content: center;
    gap: 10px; 
    margin-bottom: 25px;
    flex-wrap: wrap; 
}
.social-share-btn {
    text-decoration: none;
    font-weight: 500;
    padding: 10px 15px; 
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 0.9rem; 
}
.social-share-btn.facebook {
    background-color: #1877f2;
    color: white;
}
.social-share-btn.facebook:hover {
    background-color: #166fe5;
}
.social-share-btn.twitter {
    background-color: #1da1f2;
    color: white;
}
.social-share-btn.twitter:hover {
    background-color: #1a91da;
}
.social-share-btn.zalo {
    background-color: #0068ff;
    color: white;
}
.social-share-btn.zalo:hover {
    background-color: #005ae0;
}

.copy-link-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#share-url {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    font-size: 0.9rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 8px;
    text-align: center;
}
.copy-link-btn {
    background-color: var(--accent-secondary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}
.copy-link-btn:hover {
    background-color: #3a7bc8;
}
.copy-link-btn.copied {
    background-color: var(--correct-color);
}
/* Nền cho ảnh công thức trong phần giải thích */
.explanation-box img {
    background-color: var(--info-bg);
}
/* =================================================================== */
/* 7. FOOTER */
/* =================================================================== */
footer {
    text-align: center;
    padding: 25px 20px;
    margin-top: 30px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    transition: all 0.3s;
}
footer p {
    margin: 5px 0;
}