/* =====================================================
   PREPTEENS MOBILE APP DESIGN — Full Rewrite
   Non-zoomable, fixed header + footer, scrollable content
   ===================================================== */

/* Hide mobile-only elements on desktop */
.mobile-refresh-btn, .mobile-indian-flag, .mobile-only {
    display: none !important;
}

@media screen and (max-width: 768px) {

    /* ============================================
       1. BASE — Lock viewport, app shell layout
       ============================================ */
    html {
        width: 100% !important;
        height: 100% !important;
        overflow: hidden !important;
        touch-action: pan-y !important;
        -webkit-text-size-adjust: 100% !important;
    }

    body {
        width: 100% !important;
        height: 100% !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        background-color: #0d0d0f !important;
        background-image: none !important;
        min-width: 0 !important;
        -webkit-overflow-scrolling: touch !important;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
        /* PERFORMANCE: Better touch response */
        touch-action: manipulation !important;
    }

    /* Lock body when sidebar overlays */
    body.sidebar-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* ============================================
       2. HIDE DESKTOP-ONLY ELEMENTS
       ============================================ */
    .divider-v,
    #difficultyButtons,
    #yearQuestionMap,
    #loginBtn,
    .top-stats,
    .theme-year-wrapper,
    #accountIcon,
    #customTopRow,
    #imgToggle,
    #eyeToggle,
    #adminMediaBtn,
    #openChapters,
    .top-right-actions,
    .question-header,
    #metaInfo,
    .help.note,
    .desktop-only {
        display: none !important;
    }

    /* ============================================
       3. FIXED TOP HEADER — App style
       ============================================ */
    #topControls {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #111113 !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: 0 1px 0 rgba(255,255,255,0.04) !important;
        width: 100% !important;
        /* PERFORMANCE: GPU Layer Lifting & Layout Isolation */
        transform: translateZ(0) !important;
        will-change: transform !important;
        contain: layout !important;
        box-sizing: border-box !important;
        flex-shrink: 0 !important;
    }

    .center-group {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0 !important;
        width: 100% !important;
        padding: 0 !important;
    }

    /* ============================================
       4. TOP ACTION BAR — Settings / Feedback icons
       ============================================ */
    #mobileTopBar {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        padding: 4px 12px !important;
        gap: 0 !important;
        box-sizing: border-box !important;
        visibility: visible !important;
        position: relative !important;
        z-index: 1500 !important;
        pointer-events: auto !important;
        margin: 0 !important;
        border-bottom: 1px solid rgba(255,255,255,0.04) !important;
        height: 52px !important;
    }

    .mobile-only {
        display: flex !important;
    }

    .mtb-left {
        display: flex !important;
        gap: 4px !important;
        flex: 1 !important;
        justify-content: flex-start !important;
    }

    /* Hide bell, center title, tracker, user — not needed */
    .mtb-left .mtb-icon:nth-child(3),
    .mtb-center,
    .mtb-user,
    .mtb-tracker,
    .mtb-right {
        display: none !important;
    }

    .mtb-icon {
        background: rgba(255,255,255,0.04) !important;
        border: 1px solid rgba(255,255,255,0.06) !important;
        border-radius: 10px !important;
        color: #9ca3af !important;
        font-size: 18px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 40px !important;
        height: 40px !important;
        cursor: pointer !important;
        position: relative !important;
        z-index: 1200 !important;
        pointer-events: auto !important;
        transition: background 0.15s !important;
    }

    .mtb-icon:active {
        background: rgba(255,255,255,0.08) !important;
    }

    .mtb-icon svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* ============================================
       5. SEPARATOR LINE + ACCOUNT BUTTON
       ============================================ */
    /* Container for right-side icons in the unified bar */
    .mtb-right-icons {
        display: flex !important;
        gap: 4px !important;
        flex: 1 !important;
        justify-content: flex-end !important;
    }

    /* Remove mobile-mode-row as everything is now in the top bar */
    .mobile-mode-row {
        display: none !important;
    }

    /* Account button — now inline in top bar */
    .mobile-account-btn {
        width: 34px !important;
        height: 34px !important;
        border-radius: 8px !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        background: rgba(255,255,255,0.04) !important;
        color: #9ca3af !important;
        font-size: 14px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
        touch-action: manipulation !important;
        transition: all 0.15s ease !important;
    }

    .mobile-account-btn:active {
        background: rgba(99, 102, 241, 0.15) !important;
        transform: scale(0.92) !important;
    }

    .mobile-refresh-btn {
        width: 34px !important;
        height: 34px !important;
        border-radius: 8px !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        background: rgba(255,255,255,0.04) !important;
        color: #9ca3af !important;
        font-size: 14px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
        touch-action: manipulation !important;
        transition: all 0.15s ease !important;
    }

    .mobile-refresh-btn:active {
        background: rgba(99, 102, 241, 0.15) !important;
        transform: scale(0.92) !important;
    }

    .mobile-indian-flag {
        display: none !important; /* Removed as requested */
    }

    /* ============================================
       6. MODE TOGGLE — PYQ | TEST (centered, elegant)
       ============================================ */
    /* Mobile-specific mode toggle */
    /* Mode Toggle — Aligned with Subject Chips */
    #modeBoxMobile {
        display: flex !important;
        width: auto !important;
        background: transparent !important;
        border: none !important;
        margin: 0 !important;
        gap: 6px !important;
        position: relative !important;
        z-index: 1 !important;
        justify-content: center !important;
    }

    #modeBoxMobile button {
        flex: 1 1 auto !important;
        padding: 6px 14px !important;
        font-family: 'Inter', sans-serif !important;
        font-size: 11px !important;
        font-weight: 500 !important;
        letter-spacing: 0.2px !important;
        text-transform: capitalize !important;
        border: 1px solid rgba(255,255,255,0.08) !important;
        border-radius: 20px !important;
        color: #71717a !important;
        background: transparent !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        white-space: nowrap !important;
    }

    #modeBoxMobile button.active,
    #modeBoxMobile button[aria-selected="true"] {
        background: rgba(99, 102, 241, 0.1) !important;
        color: #a5b4fc !important;
        border-color: rgba(99, 102, 241, 0.35) !important;
        font-weight: 500 !important;
        box-shadow: none !important;
        transform: none !important;
        text-shadow: none !important;
    }

    #modeBoxMobile button:active {
        transform: scale(0.96) !important;
    }

    /* ============================================
       7. SUBJECT CHIPS — Physics / Chemistry / Maths
       ============================================ */
    #subjectBox {
        display: flex !important;
        justify-content: center !important;
        gap: 8px !important;
        padding: 4px 16px 8px 16px !important; /* Reduced from 6px/10px */
        width: 100% !important;
        box-sizing: border-box !important;
        background: transparent !important;
        border: none !important;
    }

    #subjectBox button {
        padding: 7px 20px !important;
        font-size: 13px !important;
        font-weight: 500 !important;
        font-family: 'Inter', sans-serif !important;
        background: transparent !important;
        border: 1px solid rgba(255,255,255,0.08) !important;
        border-radius: 20px !important;
        color: #71717a !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        transition: all 0.2s ease !important;
        letter-spacing: 0.2px !important;
    }

    #subjectBox button.active,
    #subjectBox button[aria-pressed="true"] {
        background: rgba(99, 102, 241, 0.1) !important;
        color: #a5b4fc !important;
        border-color: rgba(99, 102, 241, 0.35) !important;
        font-weight: 600 !important;
    }

    /* ============================================
       7. TOPIC PILLS — Horizontal scroll row
       ============================================ */
    #topicButtons {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 8px !important;
        padding: 2px 16px 8px 16px !important; /* Reduced padding to lift topics up */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        justify-content: flex-start !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        border-bottom: 1px solid rgba(255,255,255,0.04) !important;
        margin: 0 !important;
    }

    #topicButtons::-webkit-scrollbar {
        display: none;
    }

    #topicButtons button {
        flex: 0 0 auto !important;
        padding: 6px 14px !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        background: rgba(255, 255, 255, 0.03) !important;
        border: 1px solid rgba(255, 255, 255, 0.07) !important;
        border-radius: 16px !important;
        color: #71717a !important;
        white-space: nowrap !important;
        transition: all 0.15s ease !important;
    }

    #topicButtons button.selected {
        background: rgba(99, 102, 241, 0.1) !important;
        color: #a5b4fc !important;
        border-color: rgba(99, 102, 241, 0.35) !important;
    }

    /* ============================================
       8. MAIN CONTENT — Scrollable area between header & footer
       ============================================ */
    #mainContent {
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 12px 16px 100px 16px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        -webkit-overflow-scrolling: touch !important;
        /* PERFORMANCE: Layout Isolation & GPU Hint */
        contain: content !important;
        transform: translateZ(0) !important;
        /* Default fallback — JS will override with exact measurement */
        margin-top: 150px !important;
    }

    /* Scrollbar hidden for cleaner app look */
    #mainContent::-webkit-scrollbar {
        display: none;
    }

    /* ============================================
       9. QUESTION AREA — Clean transparent card
       ============================================ */
    #questionArea.card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        box-sizing: border-box !important;
        min-height: auto !important;
        /* PERFORMANCE: GPU Hint for question changes */
        will-change: opacity, transform !important;
    }

    #questionBox {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        overflow: visible !important;
    }

    #questionArea.card.has-content,
    #questionBox {
        align-items: stretch !important;
        justify-content: flex-start !important;
    }

    /* Question wrapper from JS */
    #questionBox .question,
    #questionArea .question {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        height: auto !important;
    }

    /* Empty-state placeholder */
    #questionArea.card .placeholder {
        align-self: center !important;
        text-align: center !important;
        padding: 40px 20px !important;
        color: #4b5563 !important;
        font-size: 14px !important;
    }

    /* ============================================
       10. QUESTION HEADER ROW + MEDIA ICON
       ============================================ */
    .q-header-row {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        margin-bottom: 12px !important;
    }

    .q-header-label {
        font-size: 12px !important;
        font-weight: 600 !important;
        color: #6b7280 !important;
        letter-spacing: 1px !important;
        text-transform: uppercase !important;
        width: 100% !important;
        text-align: left !important;
    }

    .q-media-btn {
        display: none !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 10px !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        background: rgba(255, 255, 255, 0.03) !important;
        color: white !important;
        font-size: 15px !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
    }

    .q-media-btn.has-media {
        display: flex !important;
        border: 1px solid rgba(251, 191, 36, 0.35) !important;
        background: rgba(251, 191, 36, 0.08) !important;
        animation: mediaGlow 2.5s ease-in-out infinite !important;
    }

    @keyframes mediaGlow {
        0%, 100% {
            box-shadow: 0 0 4px rgba(251, 191, 36, 0.2);
            border-color: rgba(251, 191, 36, 0.25);
        }
        50% {
            box-shadow: 0 0 12px rgba(251, 191, 36, 0.5);
            border-color: rgba(251, 191, 36, 0.5);
        }
    }

    /* ============================================
       11. QUESTION TEXT
       ============================================ */
    .q-text {
        font-size: 17px !important;
        font-weight: 400 !important;
        color: #e5e7eb !important;
        line-height: 1.7 !important;
        margin-bottom: 20px !important;
        word-wrap: break-word !important;
        overflow-wrap: anywhere !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        text-align: left !important;
    }

    #questionBox .question-title {
        font-size: 17px !important;
        line-height: 1.7 !important;
        font-weight: 400 !important;
        color: #e5e7eb !important;
        margin-bottom: 20px !important;
        text-align: left !important;
        word-wrap: break-word !important;
    }

    .q-row {
        width: 100% !important;
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    /* KaTeX math horizontal scroll */
    .q-text .katex-display,
    .opt-text .katex-display {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        max-width: 100% !important;
    }

    .q-text .katex,
    .opt-text .katex {
        white-space: normal !important;
        overflow-wrap: anywhere !important;
    }

    #questionBox .katex {
        font-size: 1.1em !important;
    }

    /* ============================================
       12. OPTIONS — Answer cards
       ============================================ */
    .options {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .opt {
        display: flex !important;
        align-items: center !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 14px 16px !important;
        background: #161618 !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        border-radius: 14px !important;
        min-height: 52px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        transition: all 0.15s ease !important;
    }

    .opt:active {
        transform: scale(0.98) !important;
        background: #1e1e21 !important;
    }

    .opt .opt-index {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 30px !important;
        height: 30px !important;
        border: 1.5px solid rgba(59,130,246,0.3) !important;
        color: #60a5fa !important;
        border-radius: 8px !important;
        font-size: 13px !important;
        font-weight: 700 !important;
        margin-right: 14px !important;
        flex-shrink: 0 !important;
        background: rgba(59, 130, 246, 0.06) !important;
    }

    .opt .opt-text {
        flex: 1 !important;
        min-width: 0 !important;
        font-size: 16px !important;
        color: #d1d5db !important;
        font-weight: 400 !important;
        text-align: left !important;
        line-height: 1.5 !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
        white-space: normal !important;
    }

    .opt::after {
        display: none !important;
    }

    /* States */
    .opt.selected {
        border-color: rgba(59,130,246,0.4) !important;
        background: rgba(59, 130, 246, 0.08) !important;
    }

    .opt.correct {
        border-color: rgba(16,185,129,0.5) !important;
        background: rgba(16, 185, 129, 0.08) !important;
    }

    .opt.correct .opt-index {
        border-color: #10b981 !important;
        color: #10b981 !important;
        background: rgba(16, 185, 129, 0.1) !important;
    }

    .opt.wrong {
        border-color: rgba(239,68,68,0.5) !important;
        background: rgba(239, 68, 68, 0.08) !important;
    }

    .opt.wrong .opt-index {
        border-color: #ef4444 !important;
        color: #ef4444 !important;
        background: rgba(239, 68, 68, 0.1) !important;
    }

    /* ============================================
       13. EXPLANATION DOCK — Inline inside mainContent
       ============================================ */
    #explainDock {
        position: relative !important;
        display: none !important;
        width: 100% !important;
        height: auto !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        background: transparent !important;
        border: none !important;
        margin: 20px 0 0 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        transform: none !important;
    }

    #explainDock.open {
        display: block !important;
        z-index: 1 !important;
    }

    #explainDock .explain-dock-header {
        background: rgba(255, 255, 255, 0.03) !important;
        border-radius: 14px 14px 0 0 !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        border-bottom: none !important;
        padding: 12px 16px !important;
    }

    #explainDockContent {
        padding: 20px 16px !important;
        background: #151516 !important;
        border: 1px solid rgba(255, 255, 255, 0.06) !important;
        border-top: none !important;
        border-radius: 0 0 14px 14px !important;
        font-size: 15px !important;
        line-height: 1.7 !important;
        color: #d1d5db !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* ============================================
       14. FIXED BOTTOM FOOTER — Prev / Next
       ============================================ */
    .controls {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: auto !important;
        background: #111113 !important;
        border-top: 1px solid rgba(255,255,255,0.04) !important;
        padding: 12px 16px !important;
        padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 12px !important;
        z-index: 1000 !important;
        box-sizing: border-box !important;
        /* PERFORMANCE: GPU Layer Lifting */
        transform: translate3d(0, 0, 0) !important;
        will-change: transform !important;
    }

    .controls button {
        flex: 1 !important;
        min-width: 0 !important;
        margin: 0 !important;
        height: 50px !important;
        border-radius: 14px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        border: none !important;
        color: white !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        transition: all 0.15s ease !important;
    }

    #prevBtn {
        background: #1e1e21 !important;
        color: #9ca3af !important;
    }

    #prevBtn:active {
        background: #2a2a2e !important;
        transform: scale(0.97) !important;
    }

    #nextBtn {
        background: #3b82f6 !important;
        box-shadow: 0 2px 12px rgba(59,130,246,0.25) !important;
    }

    #nextBtn:active {
        background: #2563eb !important;
        transform: scale(0.97) !important;
    }

    /* ============================================
       15. CHAPTER SIDEBAR — Full-screen overlay
       ============================================ */
    #chaptersSidebar {
        width: 100vw !important;
        max-width: none !important;
        margin: 0 !important;
        border-radius: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        padding: 16px !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        z-index: 9999 !important;
    }

    .chapter-list {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 1 0 !important;
        min-height: 0 !important;
        touch-action: pan-y !important;
    }

    #chaptersSidebar,
    #calendarPanel {
        z-index: 2000 !important;
        position: fixed !important;
        top: 0 !important;
        height: 100vh !important;
        width: 100vw !important;
        max-width: none !important;
        background: #111113 !important;
        border: none !important;
        box-shadow: -8px 0 30px rgba(0, 0, 0, 0.6) !important;
        display: none !important;

        left: 100vw !important;
        right: auto !important;
        transform: translate3d(0,0,0) !important;
        transition: left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
        /* PERFORMANCE: GPU Hint */
        will-change: left !important;
    }

    #chaptersSidebar.open,
    #calendarPanel.open {
        display: flex !important;
        flex-direction: column !important;
        left: 0 !important;
        right: auto !important;
        transform: translateX(0) !important;
    }

    /* ============================================
       16. MEDIA PANEL — Full-screen on mobile
       ============================================ */
    #mediaPanel {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 3000 !important;
        background: rgba(0,0,0,0.95) !important;
        display: none !important; /* Hidden by default */
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
    }

    #mediaPanel.open {
        display: flex !important;
    }

    #mediaPanelInner {
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        overflow: hidden !important;
        touch-action: none !important; /* Critical for pinch-to-zoom */
    }

    #mediaPanelInner img {
        display: block !important;
        max-width: 95% !important;
        max-height: 90% !important;
        object-fit: contain !important;
        /* PERFORMANCE: Smooth loading feel */
        transition: transform 0.1s ease-out, opacity 0.2s ease-in !important;
        decoding: async !important;
    }
    
    /* Global lazy-loaded image smoothness */
    img[loading="lazy"] {
        opacity: 0;
        animation: fadeInLazy 0.3s ease-in forwards;
    }
    @keyframes fadeInLazy {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    /* ============================================
       17. AUTH MODAL — Ensure visible
       ============================================ */
    #authModal {
        z-index: 5000 !important;
    }

    /* ============================================
       18. ZOOM HINT + START CONTROLS — hide
       ============================================ */
    #zoomHint,
    #startLocationControl {
        display: none !important;
    }
}