body {
    font-family: sans-serif;
    margin: 0;
    background: #f0f2f5;
}

.header {
    background: #1a73e8;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
}

.container {
    display: flex;
    height: 90vh;
}

.question-pane {
    flex: 3;
    padding: 20px;
    overflow-y: auto;
    background: white;
    margin: 10px;
    border-radius: 8px;
}

.sidebar {
    flex: 1;
    padding: 20px;
    background: #fff;
    margin: 10px;
    border-left: 1px solid #ddd;
}

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

.grid-item {
    padding: 10px;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
}

.grid-item.answered {
    background: #673ab7;
    color: white;
}

.btn-next {
    background: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    cursor: pointer;
}

.btn-icon {
    background: white;
    color: black;
    margin: 10px;
    border: black;
    cursor: pointer;
}

.btn-finish {
    background: white;
    color: black;
    margin: 10px;
    border: black;
    cursor: pointer;

}

.btn-flag {
    background: #dc3545;
    color: white;
    margin-left: 10px;
    padding: 10px 20px;
    border: none;
}

/* Phase 2: Vertical Multi-Image Alignment */
.q-image-block {
    display: block;
    max-width: 100%;
    margin: 0 auto 20px auto;
    /* Vertical spacing */
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

/* Sidebar Color Codes (Phase 2 / 3) */
.grid-item.answered {
    background: #3f51b5;
    color: white;
}

/* Royal Blue */
.grid-item.correct {
    background: #28a745;
    color: white;
}

/* Bright Green */
.grid-item.incorrect {
    background: #dc3545;
    color: white;
}

/* Deep Red */
.grid-item.flagged {
    background: #fbc02d;
    color: black;
    opacity: 0.5;
}

/* Distraction-free container */
.question-pane {
    flex: 3;
    padding: 40px;
    background: #fff;
    border-right: 1px solid #d1d1d1;
}

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --success: #28a745;
    --danger: #dc3545;
    --bg: #f8f9fa;
    --text: #202124;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
}

/* SETUP PAGE */
.setup-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.setup-container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
}

.setup-card {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}

.setup-header h1 {
    margin: 0;
    color: var(--primary);
    font-size: 28px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
}

input,
select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-sizing: border-box;
}

.range-box {
    margin-top: 30px;
    padding: 20px;
    background: #f1f3f4;
    border-radius: 8px;
}

.btn-primary {
    width: 100%;
    margin-top: 30px;
    padding: 15px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

/* EXAM PAGE SIDEBAR FIX */
.sidebar {
    width: 300px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: white;
    border-left: 1px solid #ddd;
    position: sticky;
    top: 0;
}

.sidebar h4 {
    padding: 20px;
    margin: 0;
    border-bottom: 1px solid #eee;
}

/* The fix for "going out of box" */
.grid {
    flex-grow: 1;
    overflow-y: auto;
    /* Adds scrollbar when questions exceed height */
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    align-content: start;
    /* Prevents stretching */
}

.grid-item {
    aspect-ratio: 1/1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-weight: 600;
}

/* RESULT PAGE */
.result-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.result-card {
    background: white;
    width: 90%;
    max-width: 500px;
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.score-badge {
    margin: 20px 0;
}

.final-score {
    font-size: 64px;
    font-weight: 800;
    color: var(--primary);
}

.max-score {
    font-size: 24px;
    color: #777;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    margin: 30px 0;
}

.metric-item {
    padding: 15px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}

.metric-item.correct {
    background: #e6f4ea;
    color: var(--success);
}

.metric-item.wrong {
    background: #fce8e6;
    color: var(--danger);
}

.metric-item.unanswered {
    background: #f1f3f4;
    color: #5f6368;
}

.quote-box {
    font-style: italic;
    color: #555;
    padding: 20px;
    border-left: 4px solid var(--primary);
    background: #f8f9fa;
    margin: 20px 0;
    text-align: left;
}

.result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 30px;
}

.btn-secondary {
    text-decoration: none;
    background: #3c4043;
    color: white;
    padding: 12px 25px;
    border-radius: 6px;
}

/* ADD TO PREVIOUS CSS */

/* Layout Sync */
.main-layout {
    display: flex;
    height: calc(100vh - 65px);
    /* Equalize height with header sub */
    overflow: hidden;
}

.question-pane {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: #fff;
    height: 100%;
    /* Important */
}

/* Sidebar Responsive Grid */
.sidebar {
    width: 320px;
    background: #f8f9fb;
    border-left: 1px solid #d1d9e0;
    transition: 0.3s;
    height: 100%;
}

.sidebar.hidden {
    margin-right: -320px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    /* 6 in one row */
    gap: 6px;
    padding: 15px;
}

.grid-item {
    width: 40px;
    height: 40px;
    font-size: 13px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: white;
}

/* Attractive Options with Highlight */
.opt-label {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    margin: 10px 0;
    border: 2px solid #eee;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.opt-label:hover {
    background: #f0f7ff;
    border-color: var(--primary);
}

.opt-label input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-right: 15px;
}

/* Entire label highlights when selected */
.opt-label:has(input:checked) {
    background: #eef5ff;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.1);
}

/* Landing Page Hero */
.landing-nav {
    display: flex;
    justify-content: space-between;
    padding: 20px 10%;
    align-items: center;
}

.hero {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 80px 10%;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 60vh;
    align-items: center;
}

.hero h1 span {
    color: var(--primary);
}

.video-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    padding: 40px 10%;
}

/* Layout Core */
.exam-body {
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent body scroll */
    background-color: #f4f7f9;
}

.exam-header {
    height: 40px;
    background: #1a73e8;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 10;
    -webkit-user-select: none;
    /* Safari */
    -ms-user-select: none;
    /* IE 10 and Edge */
    user-select: none;

    div,
    span {
        cursor: pointer;
    }
}

.exam-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    /* Crucial: ensures children handle their own scroll */
}

/* Question Area */
.question-section {
    flex: 1;
    /* Takes remaining width */
    display: flex;
    flex-direction: column;
    background: white;
}

.question-scroll-area {
    flex: 1;
    overflow-y: scroll;
    padding: 30px 50px;

}

.question-scroll-area::-webkit-scrollbar {
    display: none;
}

.question-scroll-area {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.question-footer {
    height: 70px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 0 50px;
    background: #fff;
}

/* Palette Sidebar */
.palette-sidebar {
    width: 260px;
    /* Slimmer palette */
    background: #f8f9fa;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    transition: 0.3s;
}

.palette-sidebar.hidden {
    display: none;
    /* Completely hidden */
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    /* Exactly 6 per row */
    gap: 5px;
    padding: 10px;
    overflow-y: auto;
}

.palette-btn {
    width: 35px;
    height: 35px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: white;
    font-size: 12px;
    cursor: pointer;
}

/* Options Styling & Alignment */
.opt-label {
    display: flex;
    align-items: center;
    padding: 15px;
    margin: 8px 0;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.opt-label input[type="radio"] {
    width: 18px;
    height: 18px;
    margin-right: 15px;
    accent-color: #1a73e8;
}

.opt-label:hover {
    background: #f8faff;
}

/* Highlight when selected */
.opt-label.selected {
    background: #e8f0fe;
    border-color: #1a73e8;
    font-weight: 600;
}

/* Stats Boxes */
.stats-container {
    padding: 15px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    border-bottom: 1px solid #eee;
}

.stat-item {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.count-box {
    width: 30px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    color: white;
    font-weight: bold;
}


/* Action Buttons */
.btn-primary-action {
    background: #28a745;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 5px;
    font-weight: 600;
    cursor: pointer;
}

.btn-review-action {
    background: purple;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 5px;
    font-weight: 600;
    cursor: pointer;
}

/* Update these rules in your style.css */

/* Practice Mode: Correct */
.palette-btn.correct {
    background-color: #28a745 !important;
    color: white !important;
    border-color: #1e7e34;
}

/* Practice Mode: Incorrect */
.palette-btn.incorrect {
    background-color: #dc3545 !important;
    color: white !important;
    border-color: #bd2130;
}

/* Test Mode: Answered */
.palette-btn.answered {
    background-color: #1a73e8 !important;
    color: white !important;
    border-color: #1557b0;
}

/* Flagged Error */
.palette-btn.marked {
    background-color: purple !important;
    color: white !important;
    border-color: purple;
}

.palette-btn.markedandanswered {
    background: linear-gradient(135deg, purple 50%, #1a73e8 50%) !important;
    color: white !important;
    border-color: purple #1a73e8 #1a73e8 purple !important;
    /* Matches the diagonal split */
}

/* Marked Correct: Purple (top-left) to Green (bottom-right) */
.palette-btn.markedandcorrect {
    background: linear-gradient(135deg, purple 50%, #28a745 50%) !important;
    color: white !important;
    border-color: purple #28a745 #28a745 purple !important;
}

/* Marked Incorrect: Purple (top-left) to Red (bottom-right) */
.palette-btn.markedandincorrect {
    background: linear-gradient(135deg, purple 50%, #dc3545 50%) !important;
    color: white !important;
    border-color: purple #dc3545 #dc3545 purple !important;
}

.count-box.correct {
    background: #28a745;
    color: white;
}

.count-box.incorrect {
    background: #dc3545;
    color: white;
}

.count-box.gray {
    background: #6c757d;
    color: white;
}

.count-box.blue {
    background: #1a73e8;
    color: white;
}

.count-box.purple_answered {
    background: linear-gradient(135deg, purple 50%, #1a73e8 50%) !important;
    color: white;
}

.count-box.purple {
    background: purple;
    color: white;
}

/* Setup Toggle Animation */
.range-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
}

.range-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out, opacity 0.3s;
    opacity: 0;
    background: #f1f3f4;
    border-radius: 8px;
}

.range-content.show {
    max-height: 200px;
    opacity: 1;
    padding: 15px;
    margin-top: 10px;
}

/* Practice Mode Highlights */
.opt-label.correct-glow {
    border: 2px solid #28a745 !important;
    background-color: #e6f4ea !important;
}

.opt-label.wrong-glow {
    border: 2px solid #dc3545 !important;
    background-color: #fce8e6 !important;
}

/* Multi-choice message */
.multi-msg {
    color: #1a73e8;
    font-weight: 600;
    font-size: 0.9em;
    margin-bottom: 10px;
}

/* Switch Toggle UI */
.switch {
    position: relative;
    display: inline-block;
    width: 45px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #1a73e8;
}

input:checked+.slider:before {
    transform: translateX(21px);
}

/* FITB Snippet */
.ans-snippet-box {
    margin-top: 15px;
    border: 2px dashed #28a745;
    padding: 10px;
    border-radius: 8px;
}

/* Multi-choice hint */
.multi-msg {
    color: #1a73e8;
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 0.9em;
}

/* Feedback Glows */
.correct-glow {
    border: 2px solid #28a745 !important;
    background-color: #e6f4ea !important;
    color: #1e7e34 !important;
}

.wrong-glow {
    border: 2px solid #dc3545 !important;
    background-color: #fce8e6 !important;
    color: #a5281b !important;
}

/* Answer Snippet */
.ans-snippet-box {
    margin-top: 15px;
    padding: 10px;
    border: 2px dashed #28a745;
    border-radius: 10px;
    background: #fafffa;
}


/* Fix for Multi-Answer alignment */
.opt-label {
    -webkit-user-select: none;
    /* Safari */
    -ms-user-select: none;
    /* IE 10 and Edge */
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* Keeps checkbox and text together */
    gap: 15px;
    /* Fixed space between box and text */
    padding: 15px 20px;
    margin: 10px 0;
    border: 2px solid #eee;
    border-radius: 8px;
    cursor: pointer;
}

.opt-label input[type="checkbox"],
.opt-label input[type="radio"] {
    margin: 0;
    flex-shrink: 0;
    /* Prevents box from squeezing */
    width: 20px;
    height: 20px;
}

.opt-label span {
    flex-grow: 1;
    /* Text takes remaining space but starts next to checkbox */
    text-align: left;
}

/* --- RESPONSIVE ADJUSTMENTS --- */

@media (max-width: 1024px) {
    .question-scroll-area {
        padding: 20px 30px;
        /* Reduced from 50px */
    }

    .question-footer {
        padding: 0 30px;
    }
}

@media (max-width: 768px) {

    /* Header Adjustments */
    .exam-header {
        padding: 0 10px;
        font-size: 0.9rem;
    }

    .subject-tag {
        display: none;
        /* Hide to save space, or make it very small */
    }

    /* Main Container Logic */
    .exam-container {
        position: relative;
    }

    /* Transform Sidebar into an Overlay */
    .palette-sidebar {
        position: absolute;
        right: 0;
        top: 0;
        height: 100%;
        z-index: 100;
        width: 280px;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
        background: #f8f9fa;
        transform: translateX(0);
        transition: transform 0.3s ease;
    }

    .palette-sidebar.hidden {
        display: flex !important;
        /* Overwrite display:none if used */
        transform: translateX(100%);
        box-shadow: none;
    }

    /* Question Pane expands to full width */
    .question-section {
        width: 100%;
    }

    .question-scroll-area {
        padding: 15px;
    }

    /* Multi-Image Scaling */
    .q-image-block {
        width: 100% !important;
        height: auto !important;
    }

    /* Footer Buttons */
    .question-footer {
        padding: 0px 15px 40px 15px;
        gap: 10px;
        height: auto;
        min-height: 70px;
        flex-wrap: wrap;
        /* Stack buttons if they don't fit */
        justify-content: center;
    }

    .btn-primary-action,
    .btn-review-action,
    .btn-warning-action {
        flex: 1;
        /* Buttons grow to fill width */
        padding: 10px 5px;
        font-size: 13px;
        white-space: nowrap;
    }

    /* Stats Grid inside sidebar */
    .stats-container {
        grid-template-columns: 1fr 1fr;
        /* 2 columns for stats on mobile */
    }
}

@media (max-width: 480px) {
    .brand {
        font-size: 1.1rem;
    }

    .timer-display {
        font-size: 0.8rem;
    }

    .palette-grid {
        grid-template-columns: repeat(5, 1fr);
        /* 5 per row on small phones */
    }
}

@media (max-width: 500px) {
            .brand {
                display: none;
            }
        }
        /* Button text swap for small screens */
        .btn-short-hide .short-text { display: none; }
        .btn-short-show .full-text { display: inline; }
        @media (max-width: 500px) {
            .btn-short-hide .full-text { display: none; }
            .btn-short-hide .short-text { display: inline; }
            .btn-short-show .full-text { display: none; }
            .btn-short-show .short-text { display: inline; }
        }