/* --- LAYOUT & GLOBAL --- */
.quiz-layout {
    display: flex;
    width: 100%;
    min-height: 100vh;
    background-color: #f4f4f4;
    font-family: Arial, sans-serif;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 20%;
    background-color: #2c3e50;
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    height: 100vh;
    box-sizing: border-box;
    /* Sticky ensures sidebar stays visible on large screens while scrolling */
    position: sticky;
    top: 0;
    overflow-y: auto; /* Handles vertical overflow on short screens */
}

.sidebar-header {
    margin-bottom: 20px;
    flex-shrink: 0;
}

.sidebar .welcome {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
}

/* Consolidated Sidebar Button */
.sidebar-btn {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    padding: 10px 12px;
    margin: 6px 0;
    background-color: #3f6478;
    color: #ecf0f1;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.05s ease, filter 0.2s ease;
}

.sidebar-btn:hover { filter: brightness(0.95); }
.sidebar-btn:active { transform: translateY(1px); }

/* Button Variants */
.sidebar-btn.alt { background-color: #6c7a89; }
.sidebar-btn.ghost { background-color: #4a6070; }

/* Topics List */
.topics-list {
    flex: 1 1 auto;
    overflow-y: auto;
    margin-bottom: 20px;
    scrollbar-width: thin;
}

.topics-list h3 {
    margin-bottom: 10px;
    font-size: 16px;
    text-transform: uppercase;
    border-bottom: 1px solid #7f8c8d;
    padding-bottom: 5px;
}

.topics-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.topics-list ul li,
.topic-title {
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    display: block;
}

.topics-list ul li:hover,
.topic-title:hover {
    background-color: #34495e;
}

.subtopics {
    display: none;
    margin-top: 5px;
    margin-left: 10px;
    padding-left: 10px;
    font-size: 14px;
}

.subtopics li::before {
    content: '››';
    margin-right: 6px;
    color: #c7ab94;
}

/* Footer / Logout */
.logout-form {
    flex-shrink: 0;
    margin-top: auto;
}

.logout-button {
    background-color: #e74c3c;
    border: none;
    padding: 12px;
    width: 100%;
    color: white;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.logout-button:hover { background-color: #c0392b; }

/* --- MAIN CONTENT --- */
.main-content {
    width: 80%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* Mobile Menu Toggle (Hidden on Desktop) */
#mobile-menu-toggle {
    display: none;
    background-color: #2c3e50;
    color: white;
    padding: 10px 15px;
    border: none;
    text-align: left;
    font-size: 16px;
    cursor: pointer;
    width: 100%;
}

/* Header Buttons */
#quiz-header {
    width: 100%;
    background-color: #3f6478;
    color: #ecf0f1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 40px;
    min-height: 60px;
    box-sizing: border-box;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.header-center {
    display: flex;
    justify-content: center;
    flex: 1;
}

#quiz-header button,
#next-question-button {
    padding: 8px 14px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
    font-size: 14px;
}

#quiz-header button { background-color: #e74c3c; }
#quiz-header button:hover { background-color: #c0392b; }

#next-question-button { background-color: #3498db; margin-left: 10px; }
#next-question-button:hover { background-color: #2980b9; }

#report-problem-button { background-color: #7f8c8d; }
#report-problem-button:hover { background-color: #707b7c; }

/* Quiz Stats */
#quiz-stats span { margin-left: 15px; font-size: 14px; }

/* Question Area */
#quiz-container {
    max-width: 100%;
    padding: 20px;
}

#img-container {
    width: 100%;
    max-width: 300px;
    height: 150px;
    margin: 20px auto;
    display: flex;
    justify-content: center;
    align-items: center;
}
#img-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.question-block h3 { margin-bottom: 20px; font-size: 1.1em; }
.question-block ul { list-style: none; padding: 0; }

/* Option Styling */
.option {
    list-style-type: none;
    cursor: pointer;
    padding: 12px 15px; /* Larger click area */
    margin: 8px 0;
    border: 1px solid #ccc;
    border-radius: 6px;
    background-color: #f9f9f9;
    transition: background-color 0.2s;
    display: block;
}

.option:hover { background-color: #eee; }
.option.correct, .option.correct-flash { background-color: #27ae60; color: white; border-color: #27ae60; font-weight: bold; }
.option.incorrect { background-color: #e74c3c; color: white; border-color: #e74c3c; font-weight: bold; }
.option.disabled { pointer-events: none; opacity: 0.6; }

/* Meta Bar */
.subtopic-meta {
    margin: 12px auto;
    max-width: 900px;
    background: #f7f9fb;
    border: 1px solid #dde4ea;
    color: #2c3e50;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
}
#meta-wrap { min-height: 28px; margin: 8px auto 12px; max-width: 90%; text-align: center; }
.meta-bar.is-hidden { visibility: hidden; pointer-events: none; }

/* --- MODALS --- */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: #ecf0f1;
    padding: 20px 30px;
    border-radius: 8px;
    width: 350px;
    max-width: 90%;
    box-sizing: border-box;
    text-align: center;
    position: relative;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

#contact-modal .modal-content { width: 560px; text-align: left; }
#contact-message { width: 100%; min-height: 150px; margin-top: 10px; resize: vertical; }
.close-button { position: absolute; top: 10px; right: 15px; font-size: 24px; cursor: pointer; }

/* Inputs */
#question-count-input { width: 60px; padding: 5px; margin: 10px 0; text-align: center; }
#start-quiz-button { padding: 8px 16px; background-color: #2ecc71; border: none; border-radius: 4px; color: white; cursor: pointer; }
#start-quiz-button:hover { background-color: #27ae60; }

/* Overlay Message */
.quiz-overlay-message {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.95);
    color: #2c2c54;
    font-size: 20px;
    font-weight: bold;
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: opacity 0.8s ease;
    text-align: center;
}
.quiz-overlay-message.fade-out { opacity: 0; }

/* --- MOBILE OPTIMIZATION (Small Screens) --- */
@media (max-width: 768px) {
    .quiz-layout { flex-direction: column; }

    /* 1. MENU TOGGLE (Always visible on top) */
    #mobile-menu-toggle {
        display: block;
        position: fixed;    /* Fix it to the top of the screen */
        top: 0;
        left: 0;
        width: 100%;
        height: 50px;       /* Exact height to match sidebar padding */
        z-index: 1100;      /* Above the sidebar */
        background-color: #2c3e50;
        color: #fff;
        padding: 0 15px;
        border: none;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        text-align: left;
        font-size: 1rem;
        cursor: pointer;
        line-height: 50px;  /* Vertically center text */
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }

    /* 2. FULL SCREEN SIDEBAR OVERLAY */
    .sidebar {
        display: none;
        position: fixed;    /* Take out of flow, cover everything */
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;      /* Force full screen height */
        padding-top: 50px;  /* Push content down below the Toggle Button */
        background-color: #2c3e50;
        z-index: 1050;      /* Below toggle, above content */
        flex-direction: column;
        box-sizing: border-box;
    }

    .sidebar.active { display: flex; }

    /* Header Area inside Menu */
    .sidebar-header {
        margin-bottom: 10px;
        flex-shrink: 0;
        padding: 10px 15px 0; /* Add side padding */
    }

    /* Compact Welcome Text */
    .sidebar .welcome {
        font-size: 1.1rem;
        margin-bottom: 5px;
        line-height: 1.2;
    }

    /* Compact Sidebar Buttons */
    .sidebar-btn {
        padding: 10px;
        margin: 5px 0;
        font-size: 0.95rem;
    }

    /* 3. SCROLLABLE TOPICS LIST */
    /* This fills all available space between Header and Footer */
    .topics-list {
        flex: 1;            /* Grow to fill empty space */
        overflow-y: auto;   /* Scroll internally if list is huge */
        margin: 5px 15px;   /* Add side margin */
        border: 1px solid rgba(255,255,255,0.1);
        padding: 5px;
        background-color: rgba(0,0,0,0.2); /* Slight darken for contrast */
        border-radius: 4px;
    }

    /* List Items */
    .topics-list h3 { margin: 8px 5px; font-size: 0.9rem; color: #bdc3c7; }

    .topic-title,
    .topics-list ul li {
        padding: 10px;
        margin: 2px 0;
        font-size: 1rem;
    }

    /* 4. FIXED FOOTER (EXIT BUTTON) */
    /* Pushed to the very bottom of the screen */
    .logout-form {
        margin-top: auto;
        flex-shrink: 0;
        padding: 10px 15px 20px; /* Extra bottom padding for phones */
        background-color: #2c3e50; /* Match background */
    }

    .logout-button {
        padding: 12px;
        font-size: 1rem;
        background-color: #e74c3c;
    }

    /* --- CONTENT & QUIZ STYLES (Unchanged) --- */
    .main-content {
        width: 100%;
        padding-top: 50px; /* Push content down so it's not hidden behind the fixed toggle */
    }

    /* Compact Header & Stats (From previous step) */
    #quiz-header {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 5px;
        padding: 5px 10px;
        height: auto;
        background-color: #fff;
        border-bottom: 1px solid #eee;
    }
    .header-left, .header-center, .header-right { display: contents; }

    #quit-quiz-button, #report-problem-button {
        flex: 1 1 45%;
        padding: 6px 5px;
        font-size: 0.8rem;
        margin: 0;
    }
    #show-correct-answer, #next-question-button {
        flex: 1 1 100%;
        padding: 10px 0;
        font-size: 1rem;
        font-weight: bold;
        margin-top: 4px;
    }

    #quiz-stats {
        width: 100%;
        flex: 1 1 100%;
        text-align: center;
        padding: 5px 0 0 0;
        order: 10;
        color: #333 !important;
        font-weight: bold;
        font-size: 0.85rem;
        display: flex;
        justify-content: center;
        gap: 15px;
    }

    /* Meta & Images */
    .subtopic-meta {
        margin: 0;
        padding: 4px 8px;
        font-size: 0.75rem;
        width: 100%;
        background: #f8f9fa;
        border-bottom: 1px solid #eee;
        text-align: center;
        color: #555;
    }

    #img-container {
        width: 100%;
        max-height: 25vh;
        min-height: 0;
        margin: 5px auto;
        display: flex;
        justify-content: center;
        background-color: transparent;
    }
    #img-container img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
        background-color: #fff;
        border-radius: 4px;
    }
    #img-container:empty { display: none; }

    #quiz-container { padding: 10px 15px 80px 15px; }

    .question-block h3 {
        font-size: 1.05rem;
        line-height: 1.3;
        margin: 10px 0 15px 0;
        color: #2c3e50;
    }

    .option {
        padding: 12px;
        font-size: 0.95rem;
        margin: 8px 0;
        background-color: #fff;
    }
}