/* --- Quiz Modal Styles --- */
#nm-quiz-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ✅ MODIFIED v7.3.12: Enhanced responsive vh-based modal sizing for all devices */
#nm-quiz-modal-content {
    background: #fff;
    color: #2c3e50;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    /* ✅ v7.3.12: Increased from 85vh for better utilization */
    min-height: 300px;
    /* ✅ v7.3.12: Prevent collapse on very short content */
    height: auto;
    /* ✅ v7.3.12: Allow content to determine height within constraints */
    overflow: hidden;
    /* ✅ Container overflow hidden, scrolling in .nm-quiz-body */
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 2vh auto;
    /* ✅ v7.3.12: Use vh for consistent vertical spacing */
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* ✅ MODIFIED v7.3.10: Fixed overlap with question number - repositioned closer to edge */
#nm-quiz-close-btn {
    position: absolute;
    top: 10px;
    /* Moved up from 15px */
    right: 15px;
    /* Moved closer to edge from 20px */
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    z-index: 10003;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

#nm-quiz-close-btn:hover {
    background: #ef4444;
    color: #fff;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ========================================================================
   ✅ NEW v7.3.3: FLEXBOX STRUCTURAL SECTIONS FOR STICKY HEADER/FOOTER
   ======================================================================== */

/* ✅ MODIFIED v7.3.13: Horizontal flexbox layout for timer | question# | close */
.nm-quiz-header {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 100;
    padding: 15px 65px 15px 20px;
    /* ✅ v7.3.13: Adjusted padding for flexbox layout */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-radius: 8px 8px 0 0;
    flex-shrink: 0;
    border-bottom: 1px solid #e0e0e0;
    flex: 0 0 auto;
    /* Don't grow or shrink */
    display: flex;
    /* ✅ v7.3.13: Flexbox for horizontal layout */
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

/* ✅ MODIFIED v7.3.12: Improved scrollable body with max-height for long content */
.nm-quiz-body {
    flex: 1 1 auto;
    /* Grow to fill available space */
    max-height: calc(90vh - 180px);
    /* ✅ v7.3.12: Deduct header (~100px) + footer (~80px) space */
    overflow-y: auto;
    /* Enable vertical scrolling */
    overflow-x: hidden;
    /* Prevent horizontal scroll */
    padding: 25px 30px;
    -webkit-overflow-scrolling: touch;
    /* Smooth iOS scrolling */
    scrollbar-width: thin;
    /* ✅ v7.3.12: Thinner scrollbar for Firefox */
}

/* Sticky footer section - navigation buttons always visible */
.nm-quiz-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    padding: 15px 25px;
    text-align: center;
    flex: 0 0 auto;
    /* Don't grow or shrink */
    z-index: 100;
}

/* Next/Skip button styling */
.nm-quiz-next-btn {
    background: #2271b1;
    color: #fff;
    border: none;
    padding: 12px 28px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 5px;
    cursor: pointer;
    min-width: 140px;
    transition: background 0.2s ease;
}

.nm-quiz-next-btn:hover {
    background: #135e96;
}

.nm-quiz-next-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ========================================================================
   END NEW STRUCTURAL SECTIONS v7.3.3
   ======================================================================== */

/* --- Pane Management --- */
.nm-quiz-pane {
    display: none;
}

.nm-quiz-pane.active {
    display: block;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- Setup Form Styles --- */
#nm-quiz-setup-pane h2 {
    margin-top: 0;
    margin-bottom: 25px;
}

.nm-form-group {
    margin-bottom: 20px;
    position: relative;
}

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

.nm-form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

#nm-generate-quiz-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    cursor: pointer;
}

#nm-generate-quiz-btn:disabled {
    background: #999;
    cursor: not-allowed;
}

#nm-topic-suggestions {
    position: absolute;
    background: #fff;
    border: 1px solid #ccc;
    border-top: none;
    width: 100%;
    z-index: 10001;
    box-sizing: border-box;
    color: #2c3e50;
}

#nm-topic-suggestions div {
    padding: 10px;
    cursor: pointer;
}

#nm-topic-suggestions div:hover {
    background: #f0f0f0;
}

/* --- Gameplay Pane Styles --- */
/* ✅ MODIFIED v7.3.13: Progress positioned center with flex order */
.nm-quiz-progress {
    font-size: 18px;
    color: #fff;
    font-weight: 500;
    order: 2;
    /* ✅ v7.3.13: Center position */
    flex: 1 1 auto;
    /* Grow to fill center space */
    text-align: center;
}

/* ✅ MODIFIED v7.3.13: Timer positioned left with flex order */
.nm-quiz-timer {
    margin: 0 auto 10px auto;
    /* ✅ v7.3.3: Centered with bottom margin */
}

/* ✅ MODIFIED v7.3.1: Fluid typography and text wrapping for long questions */
.nm-quiz-question-title {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    /* ✅ NEW v7.3.1: Auto-scaling font size */
    margin: 20px 0;
    text-align: center;
    word-wrap: break-word;
    /* ✅ NEW v7.3.1: Break long words */
    overflow-wrap: break-word;
    /* ✅ NEW v7.3.1: Modern word breaking */
    hyphens: auto;
    /* ✅ NEW v7.3.1: Enable hyphenation */
    line-height: 1.5;
    /* ✅ NEW v7.3.1: Better readability */
}

.nm-quiz-options {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* ✅ MODIFIED v7.3.1: Added word wrapping for long option text */
.nm-quiz-options .quiz-option {
    border: 1px solid #ccc;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    word-wrap: break-word;
    /* ✅ NEW v7.3.1: Break long option text */
    overflow-wrap: break-word;
    /* ✅ NEW v7.3.1: Modern word breaking */
}

.nm-quiz-options .quiz-option:hover {
    background-color: #f0f8ff;
}

.nm-quiz-options .quiz-option.disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.nm-quiz-options .quiz-option.correct {
    background-color: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
    font-weight: bold;
}

.nm-quiz-options .quiz-option.wrong {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
    text-decoration: line-through;
}

/* --- Results Pane Styles --- */
.nm-quiz-results-summary {
    text-align: center;
    margin: 20px 0;
}

.nm-quiz-results-summary p {
    font-size: 18px;
    margin: 0;
}

.nm-final-score {
    font-size: 48px;
    font-weight: bold;
    margin: 10px 0;
}

.nm-final-percentage {
    font-size: 24px;
    color: #555;
}

.nm-quiz-results-actions {
    text-align: center;
    margin-top: 30px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    /* ✅ NEW v7.3.1: Allow buttons to wrap on small screens */
}

.nm-quiz-results-actions button {
    padding: 12px 20px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 5px;
    color: #333;
}

#nm-quiz-share-results-btn {
    border: 1px solid #ccc;
    background: #f0f0f0;
}

#nm-quiz-share-results-btn:hover {
    background: #e0e0e0;
}

.nm-quiz-results-actions .button-primary {
    background: #2271b1;
    border-color: #2271b1;
    color: #fff;
}

.nm-share-container-results {
    margin-top: 20px;
}


/* --- DARK MODE OVERRIDES FOR QUIZ MODAL --- */
body.dark-mode #nm-quiz-modal-content {
    background-color: var(--nm-bg-secondary);
    color: var(--nm-text-primary);
    border: 1px solid var(--nm-border-primary);
}

body.dark-mode #nm-quiz-modal-content .nm-form-group input {
    background-color: var(--nm-bg-tertiary);
    color: var(--nm-text-primary);
    border-color: var(--nm-border-secondary);
}

body.dark-mode #nm-quiz-modal-content .nm-quiz-options .quiz-option {
    border-color: var(--nm-border-secondary);
}

body.dark-mode #nm-quiz-modal-content .nm-quiz-question-title {
    color: var(--nm-text-primary);
}

body.dark-mode #nm-quiz-modal-content .nm-quiz-progress {
    color: var(--nm-text-action);
}

body.dark-mode #nm-quiz-modal-content #nm-quiz-close-btn {
    color: var(--nm-text-action);
}

/* ✅ NEW v7.3.3: Dark mode for structural sections */
body.dark-mode .nm-quiz-header,
body.dark-mode .nm-quiz-footer {
    background-color: var(--nm-bg-secondary);
    border-color: var(--nm-border-primary);
}

body.dark-mode .nm-quiz-timer {
    background-color: var(--nm-bg-secondary);
    color: var(--nm-text-action);
    border-color: var(--nm-text-action);
}

/* ========================================================================
   ✅ NEW v7.3.1: RESPONSIVE BREAKPOINTS FOR MOBILE DEVICES
   ======================================================================== */

/* ✅ MODIFIED v7.3.3: Tablet breakpoint with updated structural padding */
@media (max-width: 768px) {
    #nm-quiz-modal-content {
        width: 95%;
        margin: 15px auto;
    }

    .nm-quiz-header,
    .nm-quiz-footer {
        padding: 15px 20px;
    }

    .nm-quiz-body {
        padding: 20px;
    }

    .nm-quiz-question-title {
        font-size: clamp(0.9rem, 3vw, 1.1rem);
        text-align: left;
        /* ✅ Better readability on mobile */
    }

    .nm-quiz-timer {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .nm-quiz-results-actions {
        flex-direction: column;
    }

    .nm-quiz-results-actions button {
        width: 100%;
    }
}

/* ✅ MODIFIED v7.3.3: Mobile breakpoint with structural padding and touch-friendly sizing */
@media (max-width: 480px) {
    #nm-quiz-modal-content {
        width: 98%;
        margin: 10px auto;
        border-radius: 4px;
    }

    .nm-quiz-header,
    .nm-quiz-footer {
        padding: 12px 15px;
    }

    .nm-quiz-body {
        padding: 15px;
    }

    .nm-quiz-question-title {
        font-size: clamp(0.85rem, 4vw, 1rem);
        margin: 15px 0;
    }

    .nm-quiz-options .quiz-option {
        padding: 12px;
        font-size: 0.9rem;
        min-height: 44px;
        /* ✅ v7.3.3: Touch-friendly tap target */
    }

    .nm-quiz-next-btn {
        padding: 14px 24px;
        width: 100%;
        min-height: 48px;
        /* ✅ v7.3.3: Touch-friendly button */
    }

    .nm-final-score {
        font-size: 36px;
    }

    .nm-final-percentage {
        font-size: 18px;
    }
}

/* ========================================================================
    NEW v7.3.8: BODY SCROLL LOCK AND MOBILE SCROLLING FIX
   ======================================================================== */

/* Lock body scroll when modal is open (prevents page scrolling on mobile) */
body.nm-modal-open {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ✅ MODIFIED v7.3.12: Enhanced mobile scrolling with optimized vh units */
@media (max-width: 768px) {
    #nm-quiz-modal-content {
        max-height: 95vh;
        /* ✅ v7.3.12: Maximize screen usage on tablets/phones */
        width: 95%;
        margin: 1vh auto;
        /* ✅ v7.3.12: Minimal margin for more content space */
    }

    .nm-quiz-body {
        max-height: calc(95vh - 160px);
        /* ✅ v7.3.12: Adjusted for mobile header/footer */
        -webkit-overflow-scrolling: touch;
        /* iOS smooth scroll */
        padding: 20px 18px;
        /* Reduced padding for more space */
    }
}

/* ✅ MODIFIED v7.3.12: Extra small devices optimized for maximum viewport usage */
@media (max-width: 575px) {
    #nm-quiz-modal-content {
        max-height: 97vh;
        /* ✅ v7.3.12: Nearly full height on small phones */
        width: 98%;
        margin: 0.5vh auto;
        /* ✅ v7.3.12: Minimal vertical margin */
        border-radius: 6px;
        /* ✅ v7.3.12: Slightly larger radius */
    }

    .nm-quiz-header,
    .nm-quiz-footer {
        padding: 10px 15px;
        /* ✅ v7.3.12: More compact for small screens */
    }

    .nm-quiz-body {
        max-height: calc(97vh - 140px);
        /* ✅ v7.3.12: Adjusted for compact header/footer */
        padding: 15px 12px;
        /* ✅ v7.3.12: Minimal horizontal padding */
    }
}