/* ============================================
   MOBILE LAYOUT FIXES
   ============================================ */

@media (max-width: 768px) {
    /* Fix body padding and spacing */
    body {
        padding: 0;
        margin: 0;
    }

    /* Fix sections with better spacing */
    section {
        padding: 3rem 1.5rem !important;
    }

    /* Hero section mobile fixes */
    .hero {
        min-height: 60vh !important;
        padding: 2rem 1rem !important;
    }

    .hero-content {
        padding: 1rem;
    }

        .hero-content h1,
        .glitch {
            font-size: 1.8rem !important;
            line-height: 1.3 !important;
            margin-bottom: 1rem;
            word-wrap: break-word;
        }

    .typing-text {
        font-size: 0.9rem !important;
        line-height: 1.5 !important;
    }

    /* Section headers */
    .section-header h2 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        padding: 0 1rem;
        word-wrap: break-word;
    }

    /* Cards and panels - more breathing room */
    .preview-card,
    .trilogy-card,
    .theme-card,
    .book-card {
        padding: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }

    /* Grid layouts - single column with gaps */
    .preview-grid,
    .trilogy-grid,
    .themes-grid,
    .author-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        padding: 0 1rem;
    }

    /* Buttons - larger tap targets */
    .primary-btn,
    .secondary-btn,
    .card-btn,
    .quiz-btn {
        padding: 1rem 1.5rem !important;
        font-size: 0.9rem !important;
        min-height: 44px; /* iOS recommended tap target */
        width: 100%;
        margin-bottom: 1rem;
    }

    .hero-buttons {
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100%;
    }

        .hero-buttons a {
            width: 100% !important;
            text-align: center;
        }

    /* Navigation - hamburger and sidebar */
    .hamburger {
        top: 1rem !important;
        right: 1rem !important;
        width: 44px !important;
        height: 44px !important;
        z-index: 2001 !important;
    }

    .sidebar {
        width: 85vw !important;
        max-width: 350px !important;
    }

    /* Breadcrumbs - smaller and tucked */
    .breadcrumb-container {
        top: 0.8rem !important;
        left: 0.8rem !important;
        font-size: 0.55rem !important;
        padding: 0.4rem 0.6rem !important;
        max-width: calc(100% - 70px);
        word-wrap: break-word;
    }

    /* Memory Fragment Tracker - move to top to avoid overlap */
    #fragment-progress {
        top: 60px !important; /* Below breadcrumbs */
        right: 10px !important;
        bottom: auto !important;
        font-size: 0.7rem !important;
        padding: 0.5rem 0.7rem !important;
        max-width: 150px !important;
        line-height: 1.2 !important;
    }

        #fragment-progress .progress-bar {
            height: 4px !important;
            margin-top: 0.3rem !important;
        }


    /* User banner - responsive */
    .user-banner {
        top: 3.5rem !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        font-size: 0.65rem !important;
        padding: 0.4rem 0.6rem !important;
        max-width: 90%;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    /* Footer - better spacing */
    footer {
        padding: 2rem 1rem !important;
    }

    .footer-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .footer-links {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Music toggle - full width */
    .music-toggle {
        margin: 2rem auto !important;
        padding: 0 1rem;
    }

    .music-toggle-btn {
        width: 100%;
        padding: 0.8rem !important;
    }

    .volume-control {
        flex-direction: column;
        gap: 0.5rem;
    }

    .volume-slider {
        width: 100% !important;
    }

    /* Quantum Widget - mobile friendly */
    .quantum-widget {
        bottom: 10px !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        min-width: 200px !important;
        max-width: calc(100vw - 40px) !important;
        font-size: 0.7rem !important;
        padding: 0.6rem !important;
    }

        .quantum-widget.minimized {
            width: 120px !important;
            height: 40px !important;
            font-size: 0.65rem !important;
        }

    .quantum-widget-content {
        padding: 0.5rem !important;
    }

    .quantum-id {
        font-size: 0.65rem !important;
        word-break: break-all !important;
    }

  
    /* Quiz page */
    .quiz-section {
        padding: 2rem 1rem !important;
    }

    .answer-option {
        padding: 1rem !important;
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
    }

    .question-text {
        font-size: 1.1rem !important;
        line-height: 1.5 !important;
        padding: 0 0.5rem;
    }

    .result-card {
        padding: 1.5rem !important;
    }

    /* Signal page */
    .visualizer-container {
        height: 200px !important;
    }

    .cipher-text {
        font-size: 0.85rem !important;
        line-height: 1.6 !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }

    .symbol-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 1rem !important;
    }

    .symbol-item {
        font-size: 2rem !important;
        padding: 1rem !important;
    }

    #interpretation-input {
        min-height: 120px !important;
        font-size: 0.9rem !important;
    }

    /* Gallery grid */
    .gallery-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    /* Timeline */
    .timeline-item {
        padding: 1rem !important;
        margin-left: 0 !important;
    }

    /* Character cards */
    .character-card {
        padding: 1.5rem !important;
    }

    /* Intro panels */
    .intro-panel,
    .lore-panel {
        padding: 1.5rem !important;
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }

    /* Splash screen */
    .splash-logo h1 {
        font-size: 1.3rem !important;
        padding: 0 1rem;
    }

    .splash-logo .logo-bracket {
        font-size: 1.8rem !important;
    }

    .splash-enter-btn {
        padding: 0.8rem 1.5rem !important;
        font-size: 0.9rem !important;
    }

    /* Login page */
    .login-card {
        margin: 1rem !important;
        padding: 2rem 1.5rem !important;
    }

    .form-group input,
    .form-group textarea {
        font-size: 1rem !important;
        padding: 0.8rem !important;
    }

    /* Text readability */
    p {
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }

    /* Prevent horizontal scroll */
    * {
        max-width: 100%;
    }

    html, body {
        overflow-x: hidden;
    }

    /* Better touch targets */
    a, button, input[type="checkbox"], input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Fix ash particles on mobile - reduce count */
    .ash-particle {
        display: none;
    }

        /* Show every 3rd particle to reduce clutter */
        .ash-particle:nth-child(3n) {
            display: block;
        }
}

/* Extra small devices */
@media (max-width: 480px) {
    .glitch,
    .hero-content h1 {
        font-size: 1.5rem !important;
    }

    .section-header h2 {
        font-size: 1.2rem !important;
    }

    .breadcrumb-container {
        font-size: 0.5rem !important;
        padding: 0.3rem 0.5rem !important;
    }

    .sidebar {
        width: 100vw !important;
        max-width: 100vw !important;
    }

    .symbol-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* WIDGET LAYOUT SYSTEM - prevent overlap */
    @media (max-width: 768px) {
        /* Stack widgets vertically on small screens */
        .quantum-widget,
        #fragment-progress,
        .user-banner,
        .breadcrumb-container {
            position: fixed;
            z-index: 100;
        }

        /* Priority order (top to bottom):
       1. Breadcrumbs (top-left)
       2. Fragment Tracker (top-right)  
       3. User Banner (top-left, below breadcrumbs)
       4. Quantum Widget (bottom-center)
    */

        /* Ensure no horizontal scroll from widgets */
        .quantum-widget,
        #fragment-progress,
        .user-banner {
            max-width: calc(100vw - 20px) !important;
            overflow: hidden !important;
            text-overflow: ellipsis !important;
        }

        /* Hide widgets when sidebar is open to reduce clutter */
        body.sidebar-open .quantum-widget,
        body.sidebar-open #fragment-progress,
        body.sidebar-open .user-banner {
            opacity: 0.3 !important;
            pointer-events: none !important;
        }
    }

}

/* Audio Player - compact mobile version */
@media (max-width: 768px) {
    .audio-player-container {
        bottom: 60px !important; /* Above quantum widget */
        left: 10px !important;
        right: 10px !important;
        max-width: calc(100vw - 20px) !important;
        font-size: 0.7rem !important;
    }

        .audio-player-container.minimized {
            width: 100px !important;
            height: 35px !important;
        }

    .audio-controls button {
        padding: 0.4rem !important;
        font-size: 0.8rem !important;
    }

    .volume-slider {
        width: 60px !important;
    }
}