:root{
    --bg-page: #f5f7fb;
    --card-bg: #ffffff;
    --primary: #007bff;
    --primary-dark: #0056b3;
    --muted: #6c757d;
    --success-bg: #e6f7ea;
    --error-bg: #fff0f0;
    --radius: 12px;
    --shadow: 0 6px 20px rgba(18,38,63,0.06);
    --max-width: 820px;
    --gap: 16px;
    --card-padding: 32px;
    --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

/* Reset + page */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    padding: 30px;
    background-color: var(--bg-page);
    font-family: var(--font-sans);
    color: #222;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Card */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    background: var(--card-bg);
    padding: var(--card-padding);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Header */
h1 {
    margin: 0 0 12px 0;
    text-align: center;
    color: var(--primary);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.2px;
}

/* Forms / controls */
.form-label.fw-bold { color: #111; font-weight: 700; }
.mb-3 { margin-bottom: calc(var(--gap) * 0.75); }

/* TestsList wrapper */
#testsList {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 6px 0;
}

/* Pill item */
.test-item {
    --chip-padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: var(--chip-padding);
    border-radius: 999px;
    border: 1px solid rgba(16,24,40,0.06);
    background: #fff;
    cursor: pointer;
    font-weight: 600;
    color: #111827;
    box-shadow: 0 6px 14px rgba(16,24,40,0.03);
    transition: all .12s ease;
    user-select: none;
    min-height: 40px;
    position: relative; /* for absolute input */
}

/* Hidden but accessible checkbox:
   - moved offscreen (left:-9999px) and opacity:0 so input.click() and keyboard focus still work.
   - DO NOT use pointer-events:none or display:none here. */
.test-item input[type="checkbox"] {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: auto;
}

/* Icon (count) */
.test-item .test-icon {
    min-width: 34px;
    height: 26px;
    padding: 0 6px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    background: linear-gradient(180deg, rgba(0,123,255,0.03), rgba(0,123,255,0.01));
    border: 1.5px solid rgba(0,123,255,0.18);
    box-shadow: inset 0 0 3px rgba(0,123,255,0.08);
    pointer-events: none; /* so clicking icon triggers wrapper click */
}

/* Label text */
.test-item .test-label {
    font-size: 0.95rem;
    white-space: nowrap;
    pointer-events: none; /* so clicking text triggers wrapper click */
}

/* optional badge */
.test-item .test-badge {
    margin-left: 8px;
    font-size: 0.78rem;
    padding: 4px 6px;
    border-radius: 999px;
    color: #065f46;
    background: rgba(16,185,129,0.08);
    border: 1px solid rgba(16,185,129,0.06);
}

/* Hover / focus */
.test-item:hover,
.test-item:focus {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(16,24,40,0.06);
    outline: none;
}

/* Checked state */
.test-item.checked {
    background: linear-gradient(180deg, rgba(0,123,255,0.12), rgba(0,123,255,0.06));
    border-color: rgba(0,123,255,0.28);
    color: #013a63;
    box-shadow: 0 12px 30px rgba(0,123,255,0.06);
}
.test-item.checked .test-icon {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
    font-weight: 700;
}

/* Make pill clickable and accessible */
.test-item { cursor: pointer; }
.test-item:active { transform: translateY(-1px); }

/* Start/End inputs */
.row.g-2 .col-md-4 { margin-bottom: 8px; }
input[type="number"].form-control {
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.08);
    padding: 10px 12px;
}

/* Buttons unified */
.btn {
    border-radius: 10px;
    font-weight: 600;
    padding: 8px 14px;
    transition: transform .08s linear, box-shadow .12s ease;
    border-width: 0;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; border: 0; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline-primary {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid rgba(0,123,255,0.12);
}
.btn-warning { background: #ffc107; color: #111; }
.btn-sm { padding: 6px 10px; }

/* Timer */
.timer {
    font-weight: 700;
    font-size: 1rem;
    color: #0b5ed7;
    background: linear-gradient(90deg, rgba(11,94,215,0.05), rgba(11,94,215,0.02));
    display: inline-block;
    padding: 8px 12px;
    border-radius: 8px;
    float: right;
}

/* Quiz questions */
.question {
    padding: 14px;
    border-radius: 10px;
    border: 1px solid rgba(0,0,0,0.04);
    margin-bottom: 12px;
    background: #fff;
}
.question strong { display: block; margin-bottom: 8px; font-size: 1.04rem; }

/* Options */
.option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    margin: 6px 0;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .08s linear, border-color .08s linear, transform .08s linear;
    user-select: none;
}
.option:hover { background: rgba(0,0,0,0.08); transform: translateY(-1px); }

/* Correct / incorrect */
.correct {
    background: #b7f3c2 !important;   /* Xanh đậm hơn */
    border-color: #27ae60 !important; /* Viền xanh đậm */
}

.incorrect {
    background: #ffc8c8 !important;   /* Đỏ đậm hơn */
    border-color: #e74c3c !important; /* Viền đỏ đậm */
}


/* Score */
#scoreDisplay {
    margin-top: 18px;
    font-weight: 700;
    font-size: 1.25rem;
    text-align: center;
    color: var(--primary-dark);
    padding: 12px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(0,123,255,0.03), rgba(0,123,255,0.01));
    border: 1px solid rgba(0,0,0,0.04);
}

/* Back to top */
#backToTopBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 40px;
    right: 40px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    z-index: 2000;
    border: none;
}

/* Select/Clear buttons (pill style) */
#selectAllBtn, #clearAllBtn {
    background: #ffffff;
    border: 1.5px solid rgba(0, 123, 255, 0.25);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 4px 12px;
    border-radius: 999px;
    transition: all 0.15s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
#selectAllBtn:hover, #clearAllBtn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.25);
}

/* Responsive tweaks */
@media (max-width:900px) {
    :root { --max-width: 720px; --card-padding: 24px; }
    .container { padding: 20px; }
    #backToTopBtn { right: 20px; bottom: 24px; }
}
@media (max-width:600px) {
    :root { --max-width: 100%; --card-padding: 18px; }
    body { padding: 12px; }
    .btn { width: 100%; }
    .row.g-2 { display: block; }
    .col-md-4 { width: 100%; }
    .test-item { padding: 8px 10px; min-height: 36px; font-size: 0.92rem; }
    #testsList { gap: 8px; }
}

/* Utilities */
.hidden { display: none; }
.text-muted { color: var(--muted); }
.small { font-size: 0.88rem; }

/* ========== Enhanced "All questions" button ========== */
#allBtn {
    background: linear-gradient(135deg, var(--primary), #3399ff);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.2px;
    padding: 10px 22px;
    transition: all 0.25s ease;
}

#allBtn:hover {
    background: linear-gradient(135deg, #006ae3, #2f89ff);
    box-shadow: 0 10px 26px rgba(0, 123, 255, 0.45);
    transform: translateY(-2px);
}

#allBtn:active {
    transform: translateY(1px);
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

#allBtn:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.25);
}
/* ===== Sticky Timer ===== */
#timer {
    position: fixed;
    top: 20px;
    right: 40px;
    background: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(255,255,255,0.6));
    backdrop-filter: blur(8px);
    color: var(--primary);
    font-weight: 700;
    font-size: 1rem;
    border-radius: 12px;
    padding: 10px 18px;
    box-shadow: 0 6px 18px rgba(0, 123, 255, 0.15);
    z-index: 2000;
    transition: all 0.3s ease;
}

/* Khi cuộn xuống sâu hơn, cho nó nổi bật hơn tí */
body.scrolled #timer {
    box-shadow: 0 8px 24px rgba(0, 123, 255, 0.25);
    transform: scale(1.03);
}
/* ========== Quiz Button Trio ========== */

/* Common style */
#randomBtn, #allBtn, button.btn-primary {
    border: none;
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 10px 20px;
    transition: all 0.25s ease;
    color: #fff;
    box-shadow: 0 6px 18px rgba(0,0,0,0.15);
}

/* Start Quiz (deep blue) */
button.btn-primary {
    background: linear-gradient(135deg, #007bff, #0056d6);
}
button.btn-primary:hover {
    background: linear-gradient(135deg, #0066e0, #004cc5);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 86, 214, 0.4);
}

/* Quiz Random (vàng tươi nổi bật) */
#randomBtn {
    background: linear-gradient(135deg, #ffb300, #ffc933);
    color: #111;
}
#randomBtn:hover {
    background: linear-gradient(135deg, #ffaa00, #ffcc44);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 179, 0, 0.4);
}

/* All questions (xanh biển sáng) */
#allBtn {
    background: linear-gradient(135deg, #00c6ff, #0072ff);
    color: #fff;
}
#allBtn:hover {
    background: linear-gradient(135deg, #00b4f0, #0066ee);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 114, 255, 0.4);
}

/* Khi bấm */
button:active {
    transform: translateY(1px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* ===================== Fixed Submit + Score ===================== */
.text-start.mt-3 {
    position: fixed;
    top: 70px; /* bên dưới timer */
    right: 40px;
    z-index: 2100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

/* Score box fixed gọn gàng */
#scoreDisplay {
    font-size: 0.95rem;
    font-weight: 600;
    background: rgba(0,123,255,0.08);
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--primary-dark);
    max-width: 230px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.unanswered {
    background: #fff7c2 !important; /* vàng nhạt */
    border-color: #ffe680 !important;
}
#quizForm {
    margin-top: 20px;
}

/* ========== MOBILE RESPONSIVE (≤ 600px) ========== */
@media (max-width: 600px) {

    body {
        padding: 10px;
    }

    .container {
        padding: 14px;
        border-radius: 10px;
        box-shadow: none;
        width: 100%;
    }

    h1 {
        font-size: 1.3rem;
    }

    /* Pills (test selectors) */
    .test-item {
        padding: 6px 10px;
        min-height: 34px;
        font-size: 0.85rem;
        border-radius: 20px;
    }

    .test-item .test-icon {
        min-width: 28px;
        height: 22px;
        font-size: 0.75rem;
    }

    #testsList {
        gap: 6px;
    }

    /* Input boxes: full width */
    .row.g-2 {
        display: block;
    }
    .col-md-4 {
        width: 100%;
        margin-bottom: 10px;
    }

    input.form-control {
        font-size: 0.9rem;
        padding: 8px 10px;
    }

    /* Buttons: full width + stacked */
    .btn,
    #randomBtn,
    #allBtn {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
        margin-bottom: 8px;
        border-radius: 10px;
    }

    /* Timer: đưa về dưới header */
    #timer {
        position: static;
        margin-top: 10px;
        width: 100%;
        text-align: center;
        box-shadow: none;
        font-size: 0.95rem;
    }

    /* Submit + Score => không còn fixed */
    .text-start.mt-3 {
        position: static;
        margin-top: 20px;
        text-align: center;
    }

    #scoreDisplay {
        margin: 12px auto 0 auto;
        font-size: 1rem;
    }

    /* Câu hỏi */
    .question {
        padding: 12px;
        border-radius: 8px;
        font-size: 0.95rem;
    }
    .question strong {
        font-size: 1rem;
    }

    /* Option */
    .option {
        padding: 10px;
        font-size: 0.9rem;
    }

    /* Back to top button */
    #backToTopBtn {
        right: 16px;
        bottom: 20px;
        width: 42px;
        height: 42px;
        background: var(--primary);
    }
    /* Giới hạn nút không tràn */
    #randomBtn,
    #allBtn,
    button.btn-primary {
        width: 100%;
        max-width: 150px;        /* GIỚI HẠN CHUẨN */
        margin: 8px auto;        /* Căn giữa + khoảng cách */
        padding: 10px 14px;      /* Thu nhỏ độ cao */
        font-size: 0.95rem;      /* Nhỏ nhẹ vừa tay */
        border-radius: 10px;
        display: block;
    }
    .quiz-buttons-mobile {
        display: flex;
        gap: 10px;
        justify-content: space-between;
        margin: 10px 0 20px 0;
    }

    .quiz-buttons-mobile .btn {
        flex: 1;
        padding: 12px 6px;
        font-size: 0.78rem;
        border-radius: 10px;
        white-space: nowrap;
    }
    /* Timer không fixed nữa */
    #timer {
        position: static !important;
        display: block;
        width: 100%;
        text-align: center;
        margin: 15px 0;
        padding: 8px 12px;
    }

    /* Bỏ fixed của khối submit */
    .text-start.mt-3 {
        position: static !important;
        width: 100%;
        margin-top: 20px;
        text-align: center;
    }

    /* Nút submit: phóng to lại cho dễ bấm */
    .text-start.mt-3 button {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
        display: block;
        padding: 12px;
        font-size: 1rem;
        border-radius: 10px;
    }

    /* Score cũng về layout bình thường */
    #scoreDisplay {
        margin: 12px auto 0;
        font-size: 0.95rem;
        width: 100%;
        max-width: 300px;
    }
    .quiz-buttons-mobile {
        display: flex;
        gap: 10px;
        justify-content: space-between;
        margin: 10px 0 20px 0;
    }

    .quiz-buttons-mobile .btn,
    .quiz-buttons-mobile #randomBtn,
    .quiz-buttons-mobile #allBtn {
        flex: 1;
        font-size: 0.88rem !important;
        padding: 12px 6px !important;
        border-radius: 12px !important;
        text-align: center;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 48px; /* ép cùng chiều cao */
        white-space: nowrap;
    }
}
.range-row {
    display: flex;
    gap: 16px;
    width: 100%;
}

.range-row .range-col {
    flex: 1;
}

.range-row input.form-control {
    width: 100%;
    padding: 10px 12px;
}

.range-row label {
    font-size: 0.9rem;
    margin-bottom: 6px;
    display: block;
    font-weight: 600;
}
/* Auto shrink label if too long */
.range-row label {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    /* Tự thu nhỏ từ 14px xuống thấp nhất 10px nếu thiếu chỗ */
    font-size: clamp(10px, 1.2vw, 14px);
}
/* ===== TIMER + SCORE MINI WRAPPER ===== */
.timer-score-wrapper {
    position: fixed;
    top: 20px;
    right: 40px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

/* Score mini cạnh timer */
.score-mini {
    background: rgba(0,123,255,0.12);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 0.9rem;
    padding: 6px 12px;
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.1);
    min-width: 80px;
    text-align: center;
}


/* ==== MOBILE FIX ==== */
@media (max-width: 600px) {
    .timer-score-wrapper {
        position: static !important;
        width: 100%;
        margin-bottom: 10px;
        align-items: center;
    }

    .score-mini {
        font-size: 0.85rem;
        width: auto;
        padding: 6px 10px;
    }
}
/* Hidden in desktop */
.score-mini {
    display: none;
}

/* Show in mobile only */
@media (max-width: 600px) {
    .score-mini {
        display: block;
        background: rgba(0,123,255,0.12);
        color: var(--primary-dark);
        font-weight: 700;
        font-size: 0.95rem;
        padding: 8px 12px;
        border-radius: 10px;
        text-align: center;
        margin-bottom: 10px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    }
}
/* ========== EXTRA SCORE DISPLAY UNDER TIMER (MOBILE ONLY) ========== */
@media (max-width: 600px) {

    /* Container để chứa bản clone */
    #timer {
        position: relative;
    }

    /* Clone scoreDisplay hiển thị dưới timer */
    #timer::after {
        content: attr(data-score);     /* lấy nội dung từ scoreDisplay */
        display: block;
        margin-top: 8px;
        padding: 6px 12px;
        font-size: 0.95rem;
        font-weight: 700;
        text-align: center;
        border-radius: 10px;
        background: rgba(0,123,255,0.12);
        color: var(--primary-dark);
    }
    /* Hide score clone if timer has no data-score */
    @media (max-width: 600px) {
        #timer:not([data-score])::after {
            content: none !important;
            display: none !important;
        }
    }
}
@media (max-width: 600px) {
    #timer {
        display: inline-block;
        color: #005ecb;
        padding: 10px 18px;
        font-size: 1rem;
        font-weight: 700;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3);
        margin: 0 auto 10px auto;
        text-align: center;
    }

    /* Bản score clone dưới timer */
    #timer::after {
        background: rgba(0, 102, 255, 0.10);
        padding: 8px 12px;
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        font-size: 0.85rem;
        margin-top: 10px;
    }
}
#scoreDisplay:empty {
    display: none !important;
}
#timer:empty {
    display: none !important;
}
/* Highlight khi chọn nhưng CHƯA submit */
.option:not(.correct):not(.incorrect):has(input[type="radio"]:checked) {
    background: rgba(0, 0, 0, 0.08) !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
}




