:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 100%);
    --white: #FFFFFF;
    --text: #1F2937;
    --text-light: #6B7280;
    --success: #10B981;
    --error: #EF4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    --card-bg: #FFFFFF;
    --header-bg: rgba(255, 255, 255, 0.98);
    --border-color: #f3f4f6;
    --app-bg: #f9fafb;
    --explain-bg: #f0fdf4;
    --explain-border: #22c55e;
    --explain-text: #166534;

    /* HIỆU ỨNG CHẾ ĐỘ SÁNG */
    --correct-bg: #ECFDF5;
    --correct-text: #065F46;
    --wrong-bg: #FEF2F2;
    --wrong-text: #991B1B;
}

body.dark-mode {
    --bg-gradient: linear-gradient(135deg, #111827 0%, #1f2937 100%);
    --white: #1f2937;
    --text: #f3f4f6;
    --text-light: #9ca3af;
    --card-bg: #1f2937;
    --header-bg: rgba(31, 41, 55, 0.98);
    --border-color: #374151;
    --app-bg: #111827;
    --explain-bg: #064e3b;
    --explain-border: #10b981;
    --explain-text: #a7f3d0;

    /* HIỆU ỨNG CHẾ ĐỘ TỐI */
    --correct-bg: #065f46; 
    --correct-text: #ffffff;
    --wrong-bg: #7f1d1d;
    --wrong-text: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%; max-width: 600px; height: 100%;
    background: var(--card-bg); 
    display: flex; flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-lg);
    overflow-x: hidden;
}

/* --- THÔNG BÁO UPDATE (TO, RÕ, Ở TRÊN CÙNG) --- */
#update-toast {
    position: fixed; 
    top: 20px; 
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: 90%; 
    max-width: 400px;
    background: var(--primary); 
    color: white;
    padding: 16px 20px; 
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 9999; 
    opacity: 0; 
    pointer-events: none;
    transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#update-toast.show { 
    opacity: 1; 
    transform: translateX(-50%) translateY(0); 
    pointer-events: auto; 
}

.toast-content { display: flex; align-items: center; gap: 15px; position: relative; }
.toast-icon { font-size: 28px; }
.toast-text strong { display: block; font-size: 16px; margin-bottom: 2px; }
.toast-text p { font-size: 13px; opacity: 0.9; margin: 0; line-height: 1.4; }

#close-toast {
    background: rgba(255,255,255,0.25); 
    border: none; color: white;
    width: 28px; height: 28px; border-radius: 50%;
    cursor: pointer; font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    position: absolute; right: -10px; top: -10px;
    transition: 0.2s;
}
#close-toast:hover { background: rgba(255,255,255,0.4); }

/* --- NÚT THEME TOGGLE (CỐ ĐỊNH SÁT LỀ PHẢI) --- */
#theme-toggle {
    position: fixed; /* Luôn nổi trên màn hình */
    bottom: 30px; 
    right: 20px; 
    width: 56px; 
    height: 56px; 
    border-radius: 50%; /* Chuyển sang hình tròn để nổi bật */
    background: var(--primary); 
    color: white;
    border: none;
    cursor: pointer; 
    z-index: 999; /* Luôn nằm trên cùng các câu hỏi */
    display: flex; 
    align-items: center; 
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: 0.3s;
}
#theme-toggle:active { transform: scale(0.9); }

/* --- CẤU TRÚC CHUNG --- */
@media (min-width: 600px) {
    .app-container { height: 95vh; margin-top: 2.5vh; border-radius: 24px; }
    #theme-toggle { right: calc(50% - 280px); } /* Cố định cạnh app-container trên PC */
}

.screen { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.hidden { display: none !important; }
.toast-hidden { display: none !important; }

#loading-screen { justify-content: center; align-items: center; padding: 30px; }
.welcome-card { width: 100%; text-align: center; }
.app-title { font-size: 2.2rem; font-weight: 800; margin-bottom: 8px; color: var(--text); }
#status-text { margin-bottom: 40px; color: var(--text-light); }

.toggle-wrapper { display: inline-flex; align-items: center; justify-content: center; margin-bottom: 40px; }
.toggle-switch { position: relative; width: 44px; height: 24px; margin-right: 12px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; border-radius: 34px; transition: .3s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .3s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }
.label-text { font-weight: 600; font-size: 1rem; color: var(--text); }

.mode-buttons { display: flex; flex-direction: column; gap: 16px; width: 100%; }
.btn-start { border: none; padding: 18px; border-radius: 12px; font-size: 1.1rem; font-weight: 600; cursor: pointer; width: 100%; transition: 0.2s; }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4); }
.btn-secondary { background: var(--card-bg); color: var(--text); border: 2px solid var(--border-color); }
.btn-outline { background: transparent; color: var(--text-light); border: 2px solid var(--border-color); }

.sticky-header { background: var(--header-bg); border-bottom: 1px solid var(--border-color); padding: 12px 16px; z-index: 50; }
.header-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; font-size: 0.95rem; color: var(--text); }
.info-item.center { color: var(--primary); font-size: 1.1rem; }
#btn-home-nav { background: var(--border-color); border: none; padding: 8px 16px; border-radius: 8px; font-weight: 600; color: var(--text); cursor: pointer; }

.progress-bg { height: 6px; background: var(--border-color); border-radius: 10px; overflow: hidden; }
#progress-bar { height: 100%; background: var(--success); width: 0%; transition: width 0.3s ease; }

.quiz-scroll-area { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px; background: var(--app-bg); }
.question-block { background: var(--white); border-radius: 16px; padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); width: 100%; }
.question-text { font-weight: 700; font-size: 1.1rem; margin-bottom: 20px; line-height: 1.5; color: var(--text); word-wrap: break-word; }

.option-item { display: flex; align-items: flex-start; padding: 14px; margin-bottom: 12px; border: 2px solid var(--border-color); border-radius: 12px; cursor: pointer; background: var(--white); transition: 0.2s; }
.option-item input { margin-right: 12px; margin-top: 4px; width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--primary); }
.option-item span { line-height: 1.5; font-size: 1rem; color: var(--text); word-break: break-word; }

/* --- BẮT ĐẦU PHẦN CSS SỬA NÚT ĐÚNG / SAI --- */
.sub-options-row {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.sub-options-row .option-item {
    flex: 1; 
    justify-content: center; 
    align-items: center;
    margin-bottom: 0;
    padding: 12px;
}
/* --- KẾT THÚC PHẦN CSS SỬA --- */

.option-item.correct { background-color: var(--correct-bg) !important; border-color: var(--success) !important; color: var(--correct-text) !important; }
.option-item.wrong { background-color: var(--wrong-bg) !important; border-color: var(--error) !important; color: var(--wrong-text) !important; }
.option-item.correct span, .option-item.wrong span { color: inherit; font-weight: 700; }

.question-block.completed .option-item { pointer-events: none; opacity: 0.6; }
.question-block.completed .option-item.correct { opacity: 1; border-color: var(--success); }
.question-block.completed .option-item.wrong { opacity: 1; }

.explanation-box { margin-top: 12px; padding: 12px 15px; background-color: var(--explain-bg); border-left: 4px solid var(--explain-border); border-radius: 8px; font-size: 14px; color: var(--explain-text); line-height: 1.5; }

#result-screen { justify-content: center; align-items: center; background: var(--card-bg); padding: 20px; }
.result-card { text-align: center; width: 100%; }
.result-title { font-size: 2rem; font-weight: 800; color: var(--text); margin-bottom: 10px; }
.score-box { font-size: 4rem; font-weight: 800; color: var(--primary); margin: 20px 0 40px; }

.qr-container { margin: 25px auto 0; text-align: center; border-top: 1px solid var(--border-color); padding-top: 20px; width: 100%; }
.qr-container p { font-size: 14px; color: var(--text-light); margin-bottom: 15px; font-weight: bold; }
.qr-card-wrapper { display: inline-block; background: #fff; padding: 10px; border-radius: 15px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); line-height: 0; transition: transform 0.2s; }
.qr-card-wrapper:hover { transform: scale(1.05); }
.qr-card-wrapper img { width: 100px; height: auto; border-radius: 8px; display: block; }

/* ==========================================
   CSS CHO MODAL PHÓNG TO QR & THANH TOÁN MOMO
   ========================================== */

/* Lớp phủ mờ nền */
.qr-modal-overlay {
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px); /* Làm mờ cảnh phía sau */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999; /* Đảm bảo nằm trên cùng */
}

/* Khung nội dung bên trong */
.qr-modal-content {
    background: var(--card-bg); /* Tự động đổi màu theo chế độ Sáng/Tối */
    color: var(--text);
    padding: 30px 25px;
    border-radius: 20px;
    position: relative;
    max-width: 90%;
    width: 360px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Ảnh QR phóng to */
#qr-large {
    width: 100%;
    max-width: 280px;
    border-radius: 12px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-sm);
}

/* Dấu X để đóng */
.qr-close {
    position: absolute;
    top: 12px; 
    right: 18px;
    font-size: 30px;
    cursor: pointer;
    color: var(--text-light);
    line-height: 1;
    transition: color 0.2s;
    font-weight: 500;
}
.qr-close:hover { 
    color: var(--error); 
}

/* Khu vực nút bấm */
.qr-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Thiết kế nút bấm chung */
.btn-qr {
    padding: 14px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    cursor: pointer;
}

/* Nút tải xuống */
.btn-qr.download {
    background: var(--app-bg);
    color: var(--text);
    border: 2px solid var(--border-color);
}
.btn-qr.download:hover {
    background: var(--border-color);
}

/* Nút mở ứng dụng Momo */
.btn-qr.open-momo {
    background: #ae2070; /* Màu đặc trưng Momo */
    color: #ffffff;
    border: 2px solid #ae2070;
}
.btn-qr.open-momo:hover {
    background: #8a1959;
    border-color: #8a1959;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(174, 32, 112, 0.4);
}

/* Hiệu ứng Pop-up (Bật ra mượt mà) */
@keyframes zoomIn {
    from { 
        transform: scale(0.85); 
        opacity: 0; 
    }
    to { 
        transform: scale(1); 
        opacity: 1; 
    }
      }
