/*
================================================================
PREMIUM MOBILE EXAM UI - V2.7 (FINAL UI POLISH)
================================================================
*/

@media (max-width: 992px) { /* Tablet and Mobile styles */
    
    .question-nav-col { display: none !important; }

    body.mock-test-active { background-color: #f0f2f5;}
    .test-layout { display: block !important; padding: 0 !important; margin: 0 !important; }
    .question-main-col { width: 100% !important; }

    /* --- Fixed Mobile Header --- */
    .mock-test-mobile-header { display: flex !important; align-items: center; justify-content: space-between; position: fixed; top: 0; left: 0; right: 0; height: 56px; background: #ffffff; border-bottom: 1px solid var(--border-color-light); padding: 0 16px; z-index: 10000; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
    #timer-display { display: flex; align-items: center; gap: 8px; font-size: 1em; font-weight: 700; color: var(--headline-color); background: none; border: none; padding: 0; margin: 0; }
    #timer-display svg { stroke: var(--headline-color); }
    #mobile-nav-toggle { display: flex !important; flex-direction: column; justify-content: center; align-items: center; width: 40px; height: 40px; background: transparent; border: none; cursor: pointer; padding: 0; z-index: 10001; }
    #mobile-nav-toggle span { display: block; width: 22px; height: 2.5px; background: var(--headline-color); border-radius: 3px; transition: all 0.3s ease-in-out; }
    #mobile-nav-toggle span:not(:last-child) { margin-bottom: 5px; }
    body.nav-open #mobile-nav-toggle span:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
    body.nav-open #mobile-nav-toggle span:nth-child(2) { opacity: 0; }
    body.nav-open #mobile-nav-toggle span:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

    /* --- Palette Drawer & Overlay (Modified for Scrolling Body) --- */
    .mobile-palette-drawer {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: 0;
        width: 85vw;
        max-width: 320px;
        height: 100%;
        background: #ffffff;
        box-shadow: -4px 0 15px rgba(0,0,0,0.1);
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out;
        z-index: 9999;
        padding: 0; /* Remove padding from main container */
        overflow: hidden; /* Prevent this container from scrolling */
    }
    
    /* Fixed Header of the drawer */
    .mobile-palette-drawer .nav-header {
        flex-shrink: 0; /* Prevent header from shrinking */
        padding: 15px 16px;
        padding-top: 70px; /* Space for the main mobile header */
        border-bottom: 1px solid var(--border-color-light);
    }

    body.nav-open .mobile-palette-drawer { transform: translateX(0); }

    /* This code is now "smart". It will fit as many columns as possible without horizontal scrolling. */
    .mobile-palette-drawer .question-palette {
        grid-template-columns: repeat(auto-fill, minmax(45px, 1fr)) !important;
        gap: 8px;
        flex-grow: 1; /* Allow this area to fill available space */
        overflow-y: auto; /* Make ONLY this area scrollable vertically */
        overflow-x: hidden; /* Explicitly hide horizontal scroll */
        padding: 16px;
    }
    
    /* Fixed footer elements of the drawer */
    .mobile-palette-drawer .palette-legend,
    .mobile-palette-drawer .nav-footer {
        flex-shrink: 0;
        padding: 15px 16px;
        border-top: 1px solid var(--border-color-light);
    }
    
    /* Prevents a double border when both legend and footer are present */
    .mobile-palette-drawer .palette-legend + .nav-footer {
        border-top: none;
        padding-top: 0;
    }

    .nav-overlay { display: block; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; z-index: 9998; }
    body.nav-open .nav-overlay { opacity: 1; visibility: visible; }

    /* --- Question Card & Options --- */
    .question-card { padding: 16px; min-height: calc(100vh - 56px - 72px); background-color: transparent; border: none; box-shadow: none; }
    .question-card .question-header { background-color: #ffffff; padding: 16px; margin: -16px -16px 20px -16px; border-bottom: 1px solid var(--border-color-light); box-shadow: 0 2px 4px rgba(0,0,0,0.04); }
    .question-header h4, .question-header p { overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; }
    .option-label { background-color: #ffffff; border: 2px solid var(--border-color-light); border-radius: 12px; padding: 15px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); align-items: flex-start; }
    .option-label span:not(.custom-radio) { flex-grow: 1; min-width: 0; overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; }
    .option-label input[type="radio"] { display: none; }
    .custom-radio { width: 22px; height: 22px; border: 2px solid #ccc; border-radius: 50%; margin-right: 15px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; margin-top: 3px; }
    .custom-radio::before { content: ''; width: 10px; height: 10px; background-color: white; border-radius: 50%; transform: scale(0); transition: all 0.2s ease; }
    .option-label input[type="radio"]:checked + .custom-radio { background-color: var(--button-color); border-color: var(--button-color); }
    .option-label input[type="radio"]:checked + .custom-radio::before { transform: scale(1); }
    .option-label:has(input:checked) { border-color: var(--button-color); background-color: #fffaf0; box-shadow: 0 4px 10px rgba(255, 140, 0, 0.15); }
	    /* Add left border for marked card only on mobile */
    .question-card.marked-card {
        border-left: 4px solid var(--review-color);
        padding-left: 15px;
    }
    
    /* --- Footer Bar --- */
    .question-footer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 999; margin-top: 0; height: 72px; padding: 12px !important; background: #ffffff; border-top: 1px solid var(--border-color-light); box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08); }
    
    /* =================== FINAL FIX: THIS IS THE KEY CHANGE FOR THE BUTTON =================== */
    .question-footer .btn { 
        padding: 12px 5px !important; 
        line-height: 1.2; 
        text-align: center; 
        display: flex; 
        align-items: center; 
        justify-content: center; 
        border-radius: 12px !important; 
        font-size: 0.85em !important; 
        font-weight: 700 !important; 
        min-height: 48px !important; 
        border: none !important; 
    }
    /* ======================================================================================= */

    .btn.btn-primary { background-color: var(--button-color) !important; color: white !important; }
    .btn.btn-warning { background-color: #f0f2f5 !important; color: var(--headline-color) !important; }
    .btn.btn-secondary { background-color: transparent !important; color: #6c757d !important; }
    #mock-test-form .question-footer { display: grid !important; grid-template-columns: 1fr 1fr 1.5fr; gap: 10px; }

    /* --- Specific Page Fixes --- */
    .review-summary-stats { grid-template-columns: 1fr !important; gap: 15px !important; }
    .mobile-palette-drawer .palette-legend ul { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 5px; justify-items: start; }
    .mobile-palette-drawer .palette-legend li { font-size: 0.9em; }
    .analysis-page-container .question-card { padding-bottom: 90px; }
    .analysis-page-container .analysis-footer { display: flex !important; justify-content: center !important; align-items: center; gap: 15px; }
    .analysis-page-container .analysis-footer .btn { flex: 1; max-width: 150px; }
    .analysis-header .analysis-title { font-weight: 700; font-size: 1.1em; color: var(--headline-color); }

    /*
    ================================================================
    PREMIUM START PAGE - MOBILE VIEW FINE-TUNING
    ================================================================
    */
    body.mock-test-active .start-page-wrapper {
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding: 20px 15px !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        min-height: calc(100vh - 56px); /* Fill screen height */
        display: flex;
        flex-direction: column;
    }

    .start-page-header { margin-bottom: 25px; }

    /* ================== THIS IS THE FIX ================== */
    .test-info-cards {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important; /* Force 3 columns on a single line */
        gap: 10px !important; /* Reduce the gap to fit them comfortably */
        margin-bottom: 25px;
    }
    /* ======================================================= */

    .info-card { padding: 15px; }
    .info-card .value { font-size: 1.4em; }

    .test-instructions { flex-grow: 1; }
    .start-page-wrapper .test-instructions ul {
        list-style-type: '✔' !important;
        list-style-position: outside !important;
        padding-left: 20px !important;
        margin-left: 0 !important;
    }
    .start-page-wrapper .test-instructions li {
        padding-left: 12px !important;
        margin-bottom: 15px !important;
    }

    .start-page-wrapper + .start-test-footer,
    body.mock-test-active > .start-test-footer {
        position: static !important;
        margin-top: 20px;
        box-shadow: none !important;
        background: transparent !important;
        backdrop-filter: none !important;
    }

    #start-test-button { padding: 12px 35px !important; font-size: 1.1em !important; }
}