/* General App Layout */
#gplx-app { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: #333; }
.gplx-container { display: flex; gap: 20px; flex-wrap: wrap; }
.gplx-main-panel { flex: 3; min-width: 300px; border: 1px solid #ddd; padding: 20px; border-radius: 5px; background: #fff; }
.gplx-side-panel { flex: 1; min-width: 250px; border: 1px solid #ddd; padding: 20px; border-radius: 5px; background: #fff; }

/* Loading and Error */
.gplx-loading, .gplx-error { text-align: center; padding: 40px; font-size: 1.2em; }
.gplx-error { color: #dc3232; }

/* Question Display */
.gplx-question-header { font-size: 1.2em; font-weight: bold; margin-bottom: 20px; color: #0073aa; }
.gplx-question-content { margin-bottom: 15px; }
.gplx-question-image {
    max-width: 100%;
    height: auto;
    margin-bottom: 15px;
    border: 1px solid #eee;
    display: block;      /* THÊM DÒNG NÀY */
    margin-left: auto;   /* THÊM DÒNG NÀY */
    margin-right: auto;  /* THÊM DÒNG NÀY */
}

/* Answer Options */
.gplx-answers { list-style: none; padding: 0; margin: 0; }
.gplx-answer { padding: 15px; border: 1px solid #ccc; border-radius: 4px; margin-bottom: 10px; cursor: pointer; transition: all 0.2s ease-in-out; }
.gplx-answer:hover { background: #f0f6fc; }
.gplx-answer.selected { border-color: #0073aa; background-color: #f0f6fc; font-weight: bold; }
.gplx-answer.correct { background-color: #d4edda; border-color: #c3e6cb; }
.gplx-answer.wrong { background-color: #f8d7da; border-color: #f5c6cb; }
.gplx-explanation { margin-top: 15px; padding: 10px; background: #f1f1f1; border-left: 4px solid #0073aa; }

/* Navigation */
.gplx-navigation { display: flex; justify-content: space-between; margin-top: 20px; }
.gplx-btn { background-color: #0073aa; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 1em; }
.gplx-btn:disabled { background-color: #a0a5aa; cursor: not-allowed; }

/* Side Panel - Question Grid & Timer */
.gplx-question-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 5px; margin-bottom: 20px; }
.gplx-grid-item { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border: 1px solid #ccc; border-radius: 50%; cursor: pointer; }
.gplx-grid-item.answered { background: #e0e0e0; }
.gplx-grid-item.current { border-color: #0073aa; font-weight: bold; }

.gplx-finish-btn { width: 100%; background-color: #28a745; }

/* Result Screen */
.gplx-results { text-align: center; }
.gplx-result-status { font-size: 2em; font-weight: bold; margin-bottom: 20px; }
.gplx-result-status.passed { color: #28a745; }
.gplx-result-status.failed { color: #dc3232; }
.gplx-result-details { margin-bottom: 20px; }

/* Thêm các đoạn này vào cuối file style.css */

/* --- Cải tiến cho Bảng câu hỏi (Grid) --- */
.gplx-grid-item.current {
    background-color: #ffeb3b; /* Màu vàng cho câu hiện tại */
    border-color: #fbc02d;
    font-weight: bold;
}
/* Trạng thái sau khi nộp bài */
.gplx-grid-item.correct-grid {
    background-color: #4caf50; /* Màu xanh lá */
    color: white;
    border-color: #388e3c;
}
.gplx-grid-item.wrong-grid {
    background-color: #f44336; /* Màu đỏ */
    color: white;
    border-color: #d32f2f;
}


/* --- CSS cho Hộp hướng dẫn bàn phím --- */
.gplx-key-hint {
    text-align: center;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #f9f9f9;
    margin: 20px 0;
    font-size: 0.9em;
}
.gplx-key-hint .key-icon {
    display: inline-block;
    padding: 2px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background-color: #fff;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    font-family: monospace;
}

/* THÊM ĐOẠN NÀY VÀO CUỐI FILE */

/* --- Style cho thanh thời gian nằm ngang --- */
.gplx-timer-bar {
    width: 100%;
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: var(--gplx-timer, #333);
    color: #fff;
    text-align: center;
    font-size: 1.2em;
    box-sizing: border-box; /* Quan trọng để padding không làm vỡ layout */
}

/* THÊM ĐOẠN NÀY VÀO CUỐI FILE */

/* --- Style cho Câu hỏi Điểm liệt --- */
.gplx-critical-marker {
    color: #f44336;
    font-weight: bold;
    font-size: 1.2em;
    margin-right: 5px;
}
.gplx-critical-notice {
    color: #f44336;
    font-weight: bold;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
    text-align: center;
}
/* THÊM ĐOẠN NÀY VÀO CUỐI FILE */

/* --- Style cho dấu * của câu liệt trên Grid --- */
.gplx-grid-item {
    position: relative; /* Bắt buộc để định vị phần tử con bên trong */
}

.grid-critical-marker {
    position: absolute;
    top: 2px;      /* Đẩy xuống một chút */
    right: 5px;    /* Đẩy sang phải một chút */
    font-size: 1em; /* Giảm kích thước một chút cho cân đối */
    font-weight: bold;
    color: var(--gplx-grid-wrong, #f44336);
    text-shadow: 0 0 2px white;
}

/* THÊM TOÀN BỘ ĐOẠN NÀY VÀO CUỐI FILE */

/* --- CSS cho Màn hình Chọn Đề thi (Modal) --- */
.gplx-selection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.gplx-selection-modal {
    background: #fff;
    padding: 25px 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.gplx-selection-modal h3 {
    margin-top: 0;
    font-size: 1.5em;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.gplx-form-group {
    margin-bottom: 20px;
}

.gplx-form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.gplx-form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
}

.gplx-selection-actions {
    margin-top: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gplx-btn-secondary {
    background-color: #f0ad4e;
    color: #fff;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    text-decoration: none;
    text-align: center;
}

.gplx-btn-secondary:hover {
    background-color: #ec971f;
}

/* --- CSS cho các Nút hành động bên cạnh Grid --- */
.gplx-side-actions {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.gplx-side-actions .gplx-btn,
.gplx-side-actions .gplx-btn-secondary {
    width: 100%;
}

/* THÊM TOÀN BỘ ĐOẠN NÀY VÀO CUỐI FILE */

/* --- CSS cho Modal Nhiệm vụ --- */
.gplx-task-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    padding: 15px;
    box-sizing: border-box;
}

.gplx-task-modal-content {
    background: #fff;
    padding: 20px 25px;
    border-radius: 8px;
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.gplx-task-modal-close {
    position: absolute;
    top: 10px; right: 15px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
}

.gplx-task-modal-plea {
    text-align: center;
    font-size: 1.1em;
    margin-top: 0;
    margin-bottom: 20px;
}

.gplx-task-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 50px 0;
    font-size: 1.2em;
}

.gplx-spinner {
    width: 24px; height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--gplx-primary, #0073aa);
    border-radius: 50%;
    animation: gplx-spin 1s linear infinite;
    margin-right: 15px;
}

@keyframes gplx-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.gplx-task-step { margin-bottom: 15px; }
.gplx-task-step img { max-width: 100%; height: auto; border: 1px solid #ddd; margin-top: 10px; }

.gplx-task-keyword-wrapper {
    display: flex;
    margin-top: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}
#gplx-task-keyword {
    flex-grow: 1;
    border: none;
    padding: 10px;
    font-weight: bold;
    background-color: #f5f5f5;
}
#gplx-task-copy-btn {
    border: none;
    background-color: #eee;
    padding: 0 15px;
    cursor: pointer;
}

.gplx-task-modal-footer { margin-top: 20px; padding-top: 20px; border-top: 1px solid #eee; }
#gplx-task-password-input {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    margin-bottom: 10px;
}
#gplx-task-error-message {
    color: #dc3232;
    font-weight: bold;
    min-height: 20px;
    text-align: center;
}

.gplx-task-actions {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* THÊM TOÀN BỘ ĐOẠN NÀY VÀO CUỐI FILE */

/* --- Tối ưu Bảng câu hỏi (Grid) --- */
.gplx-side-panel {
    flex: 1; /* Giữ lại flex-basis từ code cũ */
    min-width: 250px;
    border: 1px solid #ddd;
    padding: 20px;
    border-radius: 5px;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-self: flex-start; /* DÒNG MỚI QUAN TRỌNG */
}
.gplx-question-grid {
    max-height: calc(60vh - 200px); /* Điều chỉnh lại một chút cho phù hợp */
    overflow-y: auto;
    padding-right: 6px;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); /* Giảm kích thước tối thiểu */
    gap: 8px;
    margin-bottom: 20px;
}
.gplx-grid-item {
    width: 32px; /* Giảm kích thước */
    height: 32px; /* Giảm kích thước */
    font-size: 0.9em; /* Giảm cỡ chữ một chút */
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    border-radius: 50%;
    cursor: pointer;
    position: relative; 
}
.grid-critical-marker {
    top: -2px;
    right: 8px;
    font-size: 12px;
}

/* --- Thanh chọn Chương --- */
.gplx-chapter-filter {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 15px;
    background-color: #fffff; /* Nền tối */
    margin-bottom: 20px;
}
.gplx-chapter-filter .gplx-btn-chapter {
    padding: 8px 16px;
    background-color: #0073aa;
    color: #e2e8f0;
    border-radius: 9999px; /* Bo tròn */
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}
/* Hover cho các nút chưa active */
.gplx-btn-chapter:not(.active):hover {
    background-color: #005a87; /* Một màu xanh đậm hơn để hover */
    color: #fff;
}
.gplx-btn-chapter.active {
    background-color: #facc15 !important; /* Màu vàng cố định */
    color: #1e293b !important;       /* Chữ màu tối để dễ đọc */
    border-color: #facc15 !important;
    font-weight: bold;
}
.gplx-chapter-btn.critical {
    color: #ef4444; /* Màu đỏ */
    border-color: #4b5563;
}
.gplx-chapter-btn.critical.active {
    background-color: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
}

/* --- Ghi chú / Legend --- */
.gplx-legend {
    text-align: center;
    margin-bottom: 20px;
    padding: 10px;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    font-size: 0.9em;
}
.gplx-legend strong {
    font-weight: bold;
}
.gplx-legend .correct-text { color: #16a34a; }
.gplx-legend .wrong-text { color: #dc2626; }

/* THÊM ĐOẠN NÀY VÀO CUỐI FILE */

/* --- Style cho Tiêu đề Chương trong Main Panel --- */
.gplx-current-chapter-title {
    padding: 10px 15px;
    margin-bottom: 25px;
    color: #fff;
    border-radius: 5px;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
}

/* THÊM ĐOẠN NÀY VÀO CUỐI FILE */

/* --- Style cho dòng ghi chú mới trên bảng câu hỏi --- */
.gplx-grid-legend {
    font-size: 0.85em; /* Cỡ chữ nhỏ hơn một chút */
    color: #555;
    margin-bottom: 15px; /* Tạo khoảng cách với lưới câu hỏi */
    text-align: center;
    line-height: 1.5;
}

.gplx-grid-legend .legend-color-correct {
    font-weight: bold;
    color: var(--gplx-grid-correct, #4caf50); /* Dùng màu đã cấu hình */
}

.gplx-grid-legend .legend-color-wrong {
    font-weight: bold;
    color: var(--gplx-grid-wrong, #f44336); /* Dùng màu đã cấu hình */
}

/* THÊM ĐOẠN NÀY VÀO FILE style.css */

/* --- Style cho Tiêu đề "Danh sách câu hỏi" --- */
.gplx-side-panel h3 {
    margin-top: 0;
    margin-bottom: 15px; /* Tạo khoảng cách với lưới câu hỏi */
    padding-bottom: 10px; /* Tạo khoảng cách với đường gạch chân */
    font-size: 1.3em;
    font-weight: 700;
    color: #333;
    text-align: center;
    border-bottom: 1px solid #eee; /* Thêm đường gạch chân mờ để phân tách */
}

/* THÊM ĐOẠN MỚI NÀY VÀO SAU */
.gplx-grid-legend .legend-color-critical {
    font-weight: bold;
    color: var(--gplx-grid-wrong, #f44336); /* Dùng chung màu đỏ với câu sai */
}

/*
==========================================================================
    TỐI ƯU GIAO DIỆN CHO THIẾT BỊ DI ĐỘNG (MOBILE OPTIMIZATION)
==========================================================================
*/

@media screen and (max-width: 768px) {

    /* --- 1. BỐ CỤC CHUNG --- */
    .gplx-container {
        flex-direction: column; /* Xếp chồng 2 cột lên nhau */
        gap: 15px;
    }

    .gplx-main-panel,
    .gplx-side-panel {
        flex: 1 1 auto; /* Reset flex để chúng chiếm toàn bộ chiều rộng */
        min-width: 100%;
        padding: 15px;
    }

    /* --- 2. THANH LỌC CHƯƠNG --- */
    .gplx-chapter-filter {
        flex-wrap: nowrap; /* Ngăn các nút xuống dòng */
        overflow-x: auto; /* Cho phép cuộn ngang */
        justify-content: flex-start; /* Căn lề từ bên trái */
        padding: 10px;
        /* Thêm hiệu ứng thanh cuộn ẩn cho trải nghiệm mượt hơn */
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }
    .gplx-chapter-filter::-webkit-scrollbar {
        display: none; /* Chrome, Safari and Opera */
    }
    .gplx-btn-chapter {
        flex-shrink: 0; /* Ngăn các nút bị co lại */
        padding: 6px 14px;
        font-size: 0.9em;
    }

    /* --- 3. CỘT BÊN (SIDE PANEL) & LƯỚI CÂU HỎI --- */
    .gplx-side-panel {
        order: 2; /* Đẩy cột bên xuống dưới cột câu hỏi */
    }
    .gplx-question-grid {
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); /* Giảm kích thước ô */
        gap: 8px; /* Giảm khoảng cách */
        max-height: 250px; /* Giới hạn chiều cao và cho phép cuộn */
    }
    .gplx-grid-item {
        width: 36px;
        height: 36px;
        font-size: 0.9em;
    }

    /* --- 4. CỘT CHÍNH (MAIN PANEL) & NỘI DUNG CÂU HỎI --- */
    .gplx-main-panel {
        order: 1; /* Đẩy cột câu hỏi lên trên */
    }
    .gplx-question-header {
        font-size: 1.1em;
        margin-bottom: 15px;
    }
    .gplx-question-content,
    .gplx-answer {
        font-size: 15px; /* Giảm cỡ chữ một chút cho dễ đọc */
    }
    .gplx-answer {
        padding: 12px;
    }

    /* --- 5. NÚT ĐIỀU HƯỚNG --- */
    .gplx-navigation {
        margin-top: 15px;
    }
    .gplx-btn {
        padding: 8px 15px;
        font-size: 0.95em;
    }
    .gplx-key-hint {
        display: none;
    }
    
    /* --- 6. MÀN HÌNH KẾT QUẢ --- */
    .gplx-result-status {
        font-size: 1.5em;
    }
    
    .gplx-explanation {
        font-size: 14px;
    }
    
    .gplx-current-chapter-title {
        font-size: 0.9em;
}

.gplx-side-panel h3 {
    font-size: 1em;
}

}

@media screen and (max-width: 480px) {
    /* Tinh chỉnh thêm cho màn hình rất nhỏ */
    .gplx-question-content,
    .gplx-answer {
        font-size: 14px;
    }
    .gplx-question-grid {
        grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    }
    .gplx-grid-item {
        width: 32px;
        height: 32px;
    }
}