/* public/css/quiz-styles.css */

/* Base Styles */
body {
    font-size: 16px; /* Font size cơ bản cho body */
    line-height: 1.6;
    color: #333;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.wpqib-quiz-container {
    max-width: 750px; /* Giảm chiều rộng tổng thể */
    margin: 25px auto;
    padding: 25px; /* Giảm padding một chút */
    border: 1px solid #e0e0e0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); /* Shadow tinh tế hơn */
    background-color: #ffffff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border-radius: 10px;
    color: #333;
}

.wpqib-quiz-title {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 35px;
    font-size: 1.8em; /* Giảm kích thước font */
    font-weight: 700;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

/* Question Styles */
.wpqib-question-wrapper {
    margin-bottom: 30px;
    padding-bottom: 25px;
    border-bottom: 1.5px dashed #fe0c0c;
}

.wpqib-question-wrapper:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.wpqib-question-text {
    font-size: 1em; /* Giảm kích thước font */
    font-weight: 700;
    margin-bottom: 18px;
    margin-top: 18px;
    color: #34495e;
    line-height: 1.5;
}

.wpqib-question-image {
    text-align: center; /* Căn giữa ảnh */
}
.wpqib-question-image img {
    max-width: 100%;
    height: auto;
    margin: 15px auto; /* Căn giữa ảnh và giảm margin top/bottom */
    display: block;
    border: 1px solid #f0f0f0;
    padding: 8px;
    box-sizing: border-box;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.wpqib-options-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.wpqib-option-item {
    margin-bottom: 12px;
}

.wpqib-option-item label {
    display: flex;
    align-items: center; /* Quay lại căn giữa để đẹp hơn cho các đáp án ngắn */
    padding: 12px 18px;
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    cursor: pointer;
    background-color: #fcfcfc;
    transition: all 0.25s ease-in-out;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.wpqib-option-item label:hover {
    background-color: #e6f7ff;
    border-color: #8acaff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

.wpqib-option-item input[type="radio"] {
    margin-right: 15px;
    margin-top: 0; /* Xóa khoảng đệm thừa để căn giữa hoàn hảo */
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    accent-color: #007bff;
}

.wpqib-option-item label .option-text {
    flex-grow: 1;
    font-size: 1.5em;
    line-height: 1.2; /* Giảm khoảng cách dòng để chữ gọn hơn */
    text-align: justify;
    padding-top: 8px; /* QUAN TRỌNG: Đẩy chữ xuống 4px để ngang hàng với nút radio */
}

/* Selected, Correct, Incorrect Styles */
.wpqib-option-item input[type="radio"]:checked + label {
    background-color: #d1efff;
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

.wpqib-option-item.correct label {
    background-color: #e6ffe6;
    border-color: #28a745;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.2);
    position: relative;
    padding-right: 40px;
}
.wpqib-option-item.correct label::after {
    content: " \2713";
    color: #28a745;
    margin-left: auto;
    font-size: 1.4em;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

.wpqib-option-item.incorrect label {
    background-color: #ffe6e6;
    border-color: #dc3545;
    color: #6a6a6a;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.2);
    position: relative;
    padding-right: 40px;
}
.wpqib-option-item.incorrect label::after {
    content: " \2717";
    color: #dc3545;
    margin-left: auto;
    font-size: 1.4em;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

.wpqib-explanation {
    margin-top: 20px;
    padding: 15px 20px;
    background-color: #f8f9fa;
    border-left: 5px solid #007bff;
    font-size: 0.95em; /* Giảm font size */
    color: #495057;
    border-radius: 0 6px 6px 0;
    line-height: 1.6;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Submit Area */
.wpqib-quiz-submit-area {
    text-align: center;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px dashed #e9ecef;
}

.wpqib-quiz-submit-area button,
.wpqib-results-actions button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 12px 30px;
    margin: 0 10px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.8em; /* Giảm font size */
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    min-width: 180px; /* Giảm min-width */
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.wpqib-quiz-submit-area button:hover,
.wpqib-results-actions button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
}
.wpqib-results-actions button.wpqib-review-btn {
    background-color: #28a745;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}
.wpqib-results-actions button.wpqib-review-btn:hover {
    background-color: #218838;
    box-shadow: 0 6px 16px rgba(40, 167, 69, 0.4);
}
.wpqib-results-actions button.wpqib-restart-btn {
    background-color: #6c757d;
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}
.wpqib-results-actions button.wpqib-restart-btn:hover {
    background-color: #5a6268;
    box-shadow: 0 6px 16px rgba(108, 117, 125, 0.4);
}


/* Results Summary */
.wpqib-quiz-results-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 35px; /* Giảm margin */
    padding: 30px;
    background-color: #eaf7ff;
    border: 1px solid #8acaff;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.2);
}

.wpqib-results-header {
    width: 100%;
    text-align: center;
    margin-bottom: 25px;
}

.wpqib-results-header h3 {
    color: #0056b3;
    font-size: 1.8em; /* Giảm font size */
    margin-bottom: 20px;
    font-weight: 700;
}

.wpqib-score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px; /* Giảm khoảng cách */
    margin-bottom: 25px;
}

.wpqib-chart-container {
    position: relative;
    width: 150px; /* Kích thước canvas nhỏ hơn */
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wpqib-chart-container canvas {
    max-width: 100%;
    max-height: 100%;
}

.wpqib-score-text-overlay {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #333;
    font-weight: bold;
    font-size: 1.1em;
    line-height: 1.2;
}
.wpqib-score-percentage {
    font-size: 1.8em; /* Giảm font size */
    color: #007bff;
}
.wpqib-score-fraction {
    font-size: 1em;
    color: #555;
}


.wpqib-score-details {
    text-align: left;
    font-size: 1.05em; /* Giảm font size */
    line-height: 1.8;
}

.wpqib-score-details p {
    margin: 0;
    padding: 5px 0;
    color: #495057;
}
.wpqib-score-details span {
    font-weight: 600;
    color: #007bff;
}
.wpqib-score-details .wpqib-incorrect-score {
    color: #dc3545;
}
.wpqib-score-details .wpqib-score {
    color: #28a745;
}

.wpqib-results-actions {
    margin-top: 25px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
}


.wpqib-loading {
    text-align: center;
    font-style: italic;
    color: #666;
    padding: 20px;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .wpqib-score-display {
        flex-direction: row;
        justify-content: center;
        align-items: center;
    }
}

@media (max-width: 600px) {
    .wpqib-quiz-container {
        padding: 15px;
        margin: 10px auto; /* Thêm auto để căn giữa container */
    }
    .wpqib-quiz-title {
        font-size: 1.4em; /* Tăng nhẹ để dễ đọc hơn */
        margin-bottom: 25px;
    }
    .wpqib-question-text {
        font-size: 0.9em; /* Giữ nguyên 1em là đủ đọc */
        margin-bottom: 15px;
    }
    .wpqib-option-item label {
        padding: 12px 15px; /* Tăng padding dọc, giảm padding ngang */
    }
.wpqib-option-item input[type="radio"] {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    margin-top: 0; /* Reset về 0 */
}
.wpqib-option-item label .option-text {
    font-size: 1.15em;
    text-align: left;
    padding-top: 8px; /* QUAN TRỌNG: Đẩy chữ xuống 2px trên mobile */
}
    .wpqib-question-wrapper {
        margin-bottom: 25px;
        padding-bottom: 20px;
        border-bottom: 1px dashed #fe0c0c;
    }

    /* Tối ưu các nút bấm */
    .wpqib-quiz-submit-area button,
    .wpqib-results-actions button,
    .wpqib-final-actions .wpqib-restart-btn,
    .wpqib-final-actions .wpqib-next-quiz-btn {
        padding: 12px 25px; /* Tăng padding để nút to và dễ nhấn hơn */
        font-size: 0.8em;
        min-width: 150px; /* Tăng nhẹ min-width */
        margin: 5px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }

    /* Tối ưu khu vực kết quả */
    .wpqib-results-header h3 {
        font-size: 1.5em;
        margin-bottom: 15px;
    }
    .wpqib-score-display {
        flex-direction: column;
        gap: 20px;
    }
    .wpqib-chart-container {
        width: 130px; /* Tăng nhẹ kích thước biểu đồ */
        height: 130px;
    }
    .wpqib-score-percentage {
        font-size: 1.6em;
    }
    .wpqib-score-fraction {
        font-size: 1em;
    }
    .wpqib-score-details {
        font-size: 1em;
        text-align: center; /* Căn giữa text chi tiết điểm trên mobile */
    }
    .wpqib-explanation {
        margin-top: 15px;
        padding: 12px 18px;
        font-size: 0.9em;
    }
    
}

/* MỚI: CSS cho Spinner và trạng thái Loading của nút (Đã tối ưu) */
.wpqib-quiz-container button .wpqib-spinner,
.wpqib-quiz-container a.wpqib-next-quiz-btn .wpqib-spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: wpqib-spin 1s ease-in-out infinite;
    -webkit-animation: wpqib-spin 1s ease-in-out infinite;
    margin-right: 8px;
    vertical-align: middle;
}

/* Áp dụng trạng thái loading cho tất cả các nút có liên quan */
.wpqib-quiz-container button.loading,
.wpqib-quiz-container a.wpqib-next-quiz-btn.loading {
    cursor: not-allowed;
    opacity: 0.8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wpqib-quiz-container button.loading .wpqib-spinner,
.wpqib-quiz-container a.wpqib-next-quiz-btn.loading .wpqib-spinner {
    display: inline-block;
}

@keyframes wpqib-spin {
    to { -webkit-transform: rotate(360deg); }
}
@-webkit-keyframes wpqib-spin {
    to { -webkit-transform: rotate(360deg); }
}

/* [MỚI] CSS cho khu vực hành động cuối cùng */
.wpqib-final-actions {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: center;
    gap: 15px; /* Khoảng cách giữa các nút */
}

.wpqib-final-actions .wpqib-restart-btn,
.wpqib-final-actions .wpqib-next-quiz-btn {
    /* Kế thừa style từ các nút có sẵn */
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 12px 30px;
    margin: 0;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    min-width: 150px;
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
    text-decoration: none; /* Dành cho thẻ <a> */
    display: inline-block;
    text-align: center;
}
.wpqib-final-actions .wpqib-restart-btn:hover,
.wpqib-final-actions .wpqib-next-quiz-btn:hover {
    background-color: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(108, 117, 125, 0.4);
}

.wpqib-final-actions .wpqib-next-quiz-btn {
    background-color: #007bff; /* Màu khác cho nút "Tiếp theo" */
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}
.wpqib-final-actions .wpqib-next-quiz-btn:hover {
    background-color: #0056b3;
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
}
/*
==================================================
==>> [MỚI] TỐI ƯU HÓA HIỂN THỊ MATHJAX <<==
==================================================
*/

/* 
 * Lớp 1: Lớp an toàn - Thêm thanh cuộn ngang cho các container
 * Điều này đảm bảo layout không bao giờ bị vỡ nếu công thức quá lớn.
*/
.wpqib-question-text,
.wpqib-option-item .option-text,
.wpqib-explanation {
    overflow-x: auto; /* Thêm thanh cuộn ngang khi cần */
    -webkit-overflow-scrolling: touch; /* Giúp cuộn mượt hơn trên iOS */
    padding-bottom: 8px; /* Tạo khoảng trống nhỏ cho thanh cuộn */
    scrollbar-width: thin; /* Làm thanh cuộn mỏng hơn trên Firefox */
    scrollbar-color: #aaa #f1f1f1; /* Tùy chỉnh màu thanh cuộn Firefox */
}
/* Tùy chỉnh thanh cuộn cho các trình duyệt Webkit (Chrome, Safari) */
.wpqib-question-text::-webkit-scrollbar,
.wpqib-option-item .option-text::-webkit-scrollbar,
.wpqib-explanation::-webkit-scrollbar {
    height: 6px; /* Chiều cao của thanh cuộn ngang */
}
.wpqib-question-text::-webkit-scrollbar-track,
.wpqib-option-item .option-text::-webkit-scrollbar-track,
.wpqib-explanation::-webkit-scrollbar-track {
    background: #f1f1f1;
}
.wpqib-question-text::-webkit-scrollbar-thumb,
.wpqib-option-item .option-text::-webkit-scrollbar-thumb,
.wpqib-explanation::-webkit-scrollbar-thumb {
    background: #aaa;
    border-radius: 3px;
}
.wpqib-question-text::-webkit-scrollbar-thumb:hover,
.wpqib-option-item .option-text::-webkit-scrollbar-thumb:hover,
.wpqib-explanation::-webkit-scrollbar-thumb:hover {
    background: #888;
}


/* 
 * Lớp 2: Lớp tối ưu - Cố gắng làm cho công thức tự co lại
 * Dành cho MathJax v3 (phiên bản phổ biến hiện nay).
*/
mjx-container {
    max-width: 100%; /* Giới hạn chiều rộng tối đa của container MathJax */
    text-align: left !important; /* Đảm bảo công thức luôn căn trái trong container của nó */
}

/* 
 * Cụ thể hơn cho các công thức hiển thị dạng khối (display math)
 * để chúng có thể xuống dòng hoặc co giãn tốt hơn.
*/
mjx-container[display="true"] {
    display: block;
    width: 100%;
    box-sizing: border-box;
}