/* style.css - Giao diện LMS Hóa THPT (T1 Kaizen) */

:root {
    --primary-color: #0d6efd;
    --bg-light: #f8f9fa;
}

body {
    background-color: var(--bg-light);
    color: #212529;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-width: 320px;
}

/* Giới hạn độ rộng các khối chứa, chống tràn trang khi công thức dài (b) */
.card,
.card-body,
.q-explain,
.q-content {
    min-width: 0;
    max-width: 100%;
}

/* Nội dung câu hỏi chống tràn và cuộn ngang */
.q-content {
    overflow-wrap: anywhere;
    word-break: normal;
    line-height: 1.75;
    font-size: 1.05rem;
}

/* Bảng công thức và dữ liệu hóa học */
.q-content .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.q-content table {
    width: 100%;
    margin-bottom: 1rem;
    border-collapse: collapse;
}

.q-content table th,
.q-content table td {
    border: 1px solid #dee2e6;
    padding: 0.5rem 0.75rem;
    text-align: center;
}

/* Ảnh minh họa không vượt quá khung và có thể phóng to */
.q-content img,
.q-explain img,
img.img-fluid {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.5rem auto;
    cursor: zoom-in;
}

/* Vùng bấm phương án trắc nghiệm trên mobile (tối thiểu 44px) */
.option-label,
.proposition-label {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    background-color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.option-label:hover,
.proposition-label:hover {
    background-color: #f1f3f5;
    border-color: #ced4da;
}

.option-label input[type="radio"],
.proposition-label input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    flex-shrink: 0;
}

/* Ô trả lời ngắn */
.short-answer-input {
    max-width: 300px;
    min-height: 44px;
    font-size: 1.1rem;
}

/* TLN 4 ô, mỗi ô 1 ký tự (D40): 4 x 44px + 3 khoảng 8px = 200px, vừa màn hình 375px */
.tln-boxes {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    max-width: 100%;
}

.tln-box {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-width: 0;
    padding: 0;
    text-align: center;
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background-color: #fff;
    box-sizing: border-box;
}

.tln-box:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* T21: Bàn phím số tự vẽ cho câu TLN 4 ô (cố định đáy màn hình, lưới 4 cột) */
.tln-keypad {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    background-color: #f1f3f5;
    border-top: 1px solid #ced4da;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.tln-keypad-container {
    max-width: 420px;
    margin: 0 auto;
}

.tln-keypad-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.tln-key {
    min-height: 48px;
    height: 48px;
    font-size: 1.35rem;
    font-weight: 600;
    font-family: inherit;
    color: #212529;
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: background-color 0.1s ease, transform 0.05s ease;
    -webkit-tap-highlight-color: transparent;
}

.tln-key:active {
    background-color: #e2e6ea;
    transform: scale(0.97);
}

.tln-key-action {
    background-color: #e9ecef;
    font-size: 1.1rem;
    color: #495057;
}

.tln-key-action:active {
    background-color: #dee2e6;
}

.tln-key-zero {
    grid-column: span 2;
}

.tln-key-next {
    grid-column: span 2;
    font-size: 1rem;
    font-weight: 500;
}

/* MathJax CHTML container chống tràn màn hình mobile 375px (a, b) */
mjx-container {
    max-width: 100% !important;
    /* KHÔNG đặt overflow lên container inline: line-height:0 của MathJax khiến overflow cắt đỉnh glyph (CC_02, H1).
       Cuộn ngang do .q-eq hoặc công thức display đảm nhiệm. */
}

/* D45: công thức inline dài (vd. phương trình nhiều mũi tên) làm tràn trang ngang 390px (đo WebKit: scrollWidth 602).
   Cho inline-block + cuộn ngang trong khung riêng; padding trên/dưới bù line-height:0 của MathJax để không cắt đỉnh chữ C/O (H1). */
.q-content mjx-container:not([display]) {
    display: inline-block;
    overflow-x: auto;
    padding: 0.45em 0 0.3em;
    vertical-align: middle;
    -webkit-overflow-scrolling: touch;
}

/* Ô bảng không được bẻ từng ký tự (overflow-wrap:anywhere của .q-content làm cột co về 1 ký tự) */
.q-content table td,
.q-content table th {
    overflow-wrap: normal;
    min-width: 4.5rem;
}

/* Áp dụng biến thể B2 cho Display Math (Unit 4.J) */
mjx-container[display="true"],
mjx-container[jax="SVG"][display="true"] {
    display: block !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    padding-top: 0.45em;
    padding-bottom: 0.3em;
}

/* Dòng liệt kê câu hỏi có nhãn (1), (a)... canh lề flex chống rớt dòng công thức */
.q-item {
    display: flex;
    gap: 0.4rem;
    align-items: flex-start;
}


.q-lab {
    flex: 0 0 auto;
}

/* .q-body KHÔNG có overflow */
.q-body {
    min-width: 0;
    flex: 1 1 auto;
    overflow: visible;
}

/* V4: phương trình độc lập = display math trong khung cuộn ngang riêng */
.q-item-eq {
    align-items: baseline;
}

.q-item + br {
    display: none;
}

.q-eq mjx-container[display="true"] {
    margin: 0.2em 0 !important;
}

.q-eq {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Công thức MathJax rộng / khung cuộn có thể phóng to (Unit 4.G & 4.J) */
.is-wide,
mjx-container.is-wide {
    cursor: zoom-in;
    position: relative;
    outline: none;
}

.is-wide:focus-visible,
mjx-container.is-wide:focus-visible {
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.5);
    border-radius: 4px;
}

.is-wide::after,
mjx-container.is-wide::after {
    content: "🔍";
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.75rem;
    line-height: 1;
    padding: 2px 4px;
    background-color: rgba(0, 0, 0, 0.08);
    border-radius: 3px;
    opacity: 0.7;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.is-wide:hover::after,
mjx-container.is-wide:hover::after {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.18);
}

/* Modal xem phóng to toàn màn hình (Unit 4.G & 4.J) - Phủ toàn màn hình */
.zoom-modal-dialog {
    max-width: 100vw !important;
    width: 100vw !important;
    margin: 0 !important;
}

.zoom-modal-content {
    background-color: rgba(18, 18, 18, 0.96) !important;
    width: 100vw !important;
    min-width: 100vw !important;
    height: 100vh;
}

/* Giao diện khung xem công thức: nền trắng, chữ đen (Unit 4.J) */
.zoom-formula-theme.zoom-modal-content {
    background-color: #ffffff !important;
    color: #000000 !important;
}

.zoom-formula-theme .zoom-close-btn {
    background-color: rgba(0, 0, 0, 0.15);
    filter: invert(1);
}

.zoom-formula-theme .zoom-content-wrapper {
    color: #000000 !important;
}


.zoom-close-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1080;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    opacity: 0.85;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    padding: 10px;
    transition: opacity 0.15s, background-color 0.15s;
}

.zoom-close-btn:hover,
.zoom-close-btn:focus {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.35);
}

.zoom-modal-body {
    overflow: auto;
    touch-action: pan-x pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
    padding: 1.5rem;
    min-height: 100%;
    display: flex;
}

.zoom-content-wrapper {
    margin: auto;
    max-width: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.zoom-controls-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1080;
    background-color: rgba(33, 37, 41, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.zoom-control-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    line-height: 1;
}

.zoom-reset-btn {
    min-height: 44px;
    min-width: 64px;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}



/* Đồng hồ đếm ngược làm bài: dính đầu trang, nền xanh rất nhạt + viền xanh */
.exam-timer {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    margin: -0.5rem -0.75rem 0.75rem;
    background: #e8f1ff;
    color: #0a3d91;
    border: 3px solid #0d6efd;
    border-radius: 0.5rem;
    box-shadow: 0 3px 8px rgba(13, 110, 253, 0.25);
}

.exam-timer-label { font-size: 0.9rem; }

.exam-timer-text {
    font-variant-numeric: tabular-nums;
    font-size: 1.6rem;
    letter-spacing: 0.03em;
}

.exam-timer.is-warning { background: #fff4e5; border-color: #fd7e14; color: #9a4a00; }
.exam-timer.is-danger { background: #fdeaea; border-color: #dc3545; color: #a01c28; }
