/**
 * IMMORTAL NEXUS - MOBILE ENHANCED EXPERIENCE
 * Touch-optimized mystical interface
 */

/* ========================================
   MOBILE VIEWPORT OPTIMIZATIONS
   ======================================== */

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

    /* Prevent iOS zoom on input focus */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Safe area insets for notched devices */
    @supports (padding: max(0px)) {
        body {
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
            padding-bottom: max(0px, env(safe-area-inset-bottom));
        }

        header {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
            padding-top: max(1rem, env(safe-area-inset-top));
        }
    }

    /* ========================================
       PERFORMANCE OPTIMIZATIONS
       ======================================== */

    /* Reduce cosmic background complexity on mobile */
    body::before {
        background-image:
            radial-gradient(2px 2px at 20% 30%, rgba(255, 255, 255, 0.6), transparent),
            radial-gradient(1px 1px at 60% 70%, rgba(255, 255, 255, 0.5), transparent),
            radial-gradient(1px 1px at 80% 10%, rgba(255, 255, 255, 0.4), transparent);
        background-size: 150% 150%, 140% 140%, 160% 160%;
        animation-duration: 180s; /* Slower for performance */
    }

    body::after {
        animation-duration: 90s; /* Slower aurora */
    }

    /* ========================================
       TOUCH-OPTIMIZED INTERACTIONS
       ======================================== */

    /* Minimum touch target size: 44x44px */
    .btn,
    button,
    a.btn,
    .main-nav a {
        min-height: 44px;
        min-width: 44px;
        padding: 1rem 1.5rem;
    }

    /* Icon buttons */
    button[class*="icon"],
    .theme-toggle {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem;
    }

    /* Remove tap highlight */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }

    /* Add custom touch feedback */
    .btn:active,
    button:active,
    a:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    /* ========================================
       MOBILE TYPOGRAPHY
       ======================================== */

    body {
        font-size: 16px;
        line-height: 1.6;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    .hero h1,
    h1.eternal {
        font-size: clamp(2rem, 8vw, 3rem);
        line-height: 1.2;
        margin-bottom: 1rem;
    }

    .hero p {
        font-size: 1.125rem;
        line-height: 1.6;
        margin-bottom: 2rem;
    }

    h2 {
        font-size: 1.75rem;
        line-height: 1.3;
    }

    h3 {
        font-size: 1.5rem;
        line-height: 1.4;
    }

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

    /* Hero section */
    .hero {
        padding: 4rem 1.5rem;
        text-align: center;
    }

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

    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    /* Cards stack on mobile */
    .feature-card,
    .soul-card,
    .debate-arena {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }

    /* Reduce ornate decorations on small screens */
    .feature-card::before,
    .soul-card::before,
    .feature-card::after,
    .soul-card::after {
        font-size: 0.875rem;
        top: 8px;
        left: 8px;
    }

    /* ========================================
       MOBILE NAVIGATION & HEADER
       ======================================== */

    /* Fixed header with safe area insets */
    header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        padding: 1rem 1.5rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        background: linear-gradient(135deg,
            rgba(26, 27, 78, 0.98) 0%,
            rgba(22, 33, 62, 0.98) 100%);
        border-bottom: 1px solid rgba(255, 94, 120, 0.3);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }

    /* Hide desktop main nav on mobile */
    .main-nav {
        display: none !important;
    }

    /* Show mobile nav toggle */
    .mobile-nav-toggle {
        display: flex !important;
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem;
        background: rgba(255, 94, 120, 0.2);
        border: 1px solid rgba(255, 94, 120, 0.4);
        border-radius: 8px;
        color: var(--text);
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .mobile-nav-toggle:hover,
    .mobile-nav-toggle:active {
        background: rgba(255, 94, 120, 0.3);
        box-shadow: 0 0 15px rgba(255, 94, 120, 0.3);
    }

    /* Mobile navigation sidebar */
    .mobile-nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85vw;
        max-width: 320px;
        height: 100vh;
        background: linear-gradient(135deg,
            rgba(26, 13, 51, 0.98) 0%,
            rgba(16, 16, 33, 0.98) 100%);
        border-right: 2px solid rgba(255, 94, 120, 0.4);
        z-index: 1100;
        padding: 1.5rem;
        padding-top: max(1.5rem, env(safe-area-inset-top));
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.5);
    }

    .mobile-nav.active {
        left: 0;
    }

    /* Mobile nav overlay */
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(10, 5, 21, 0.8);
        z-index: 1050;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .mobile-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Mobile nav list */
    .mobile-nav-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .mobile-nav-list li {
        margin-bottom: 0.5rem;
    }

    .mobile-nav-list a {
        display: flex;
        align-items: center;
        gap: 1rem;
        padding: 1rem;
        color: var(--text);
        text-decoration: none;
        border-radius: 8px;
        transition: all 0.3s ease;
        border-left: 3px solid transparent;
    }

    .mobile-nav-list a:hover,
    .mobile-nav-list a:active {
        background: rgba(255, 94, 120, 0.2);
        border-left-color: rgba(255, 94, 120, 0.8);
        transform: translateX(5px);
    }

    .mobile-nav-list a i {
        width: 24px;
        text-align: center;
        color: rgba(255, 94, 120, 0.8);
    }

    /* Prevent scroll when menu open */
    body.mobile-nav-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    /* ========================================
       NOTIFICATION ICON & DROPDOWN
       ======================================== */

    .notification-icon-container {
        position: relative;
        z-index: 100;
    }

    .notification-icon {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 94, 120, 0.2);
        border: 1px solid rgba(255, 94, 120, 0.4);
        border-radius: 8px;
        color: var(--text);
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
    }

    .notification-icon:hover,
    .notification-icon:active {
        background: rgba(255, 94, 120, 0.3);
        box-shadow: 0 0 15px rgba(255, 94, 120, 0.3);
    }

    .notification-badge {
        position: absolute;
        top: -4px;
        right: -4px;
        min-width: 20px;
        height: 20px;
        background: rgba(255, 94, 120, 0.9);
        border: 2px solid rgba(26, 27, 78, 0.98);
        border-radius: 10px;
        font-size: 0.75rem;
        font-weight: bold;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
    }

    /* Notification dropdown on mobile */
    .notifications-dropdown,
    .notification-panel {
        position: fixed !important;
        top: 70px !important;
        right: 1rem !important;
        left: 1rem !important;
        width: auto !important;
        max-width: none !important;
        max-height: calc(100vh - 90px) !important;
        background: linear-gradient(135deg,
            rgba(26, 13, 51, 0.98) 0%,
            rgba(16, 16, 33, 0.98) 100%);
        border: 2px solid rgba(255, 94, 120, 0.4);
        border-radius: 12px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 1050 !important;
    }

    /* ========================================
       USER MENU DROPDOWN
       ======================================== */

    .user-menu {
        position: relative;
        z-index: 100;
    }

    .user-menu-button,
    .user-avatar-button {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem;
        background: rgba(255, 94, 120, 0.2);
        border: 1px solid rgba(255, 94, 120, 0.4);
        border-radius: 8px;
        color: var(--text);
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .user-menu-button:hover,
    .user-menu-button:active,
    .user-avatar-button:hover,
    .user-avatar-button:active {
        background: rgba(255, 94, 120, 0.3);
        box-shadow: 0 0 15px rgba(255, 94, 120, 0.3);
    }

    .user-avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        object-fit: cover;
    }

    /* User dropdown on mobile */
    .user-dropdown,
    .user-menu-dropdown {
        position: fixed !important;
        top: 70px !important;
        right: 1rem !important;
        left: auto !important;
        width: calc(100vw - 2rem) !important;
        max-width: 320px !important;
        background: linear-gradient(135deg,
            rgba(26, 13, 51, 0.98) 0%,
            rgba(16, 16, 33, 0.98) 100%);
        border: 2px solid rgba(255, 94, 120, 0.4);
        border-radius: 12px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
        z-index: 1050 !important;
        overflow: hidden;
    }

    .user-dropdown a,
    .user-menu-dropdown a {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 1rem;
        color: var(--text);
        text-decoration: none;
        transition: all 0.3s ease;
        border-left: 3px solid transparent;
        min-height: 44px;
    }

    .user-dropdown a:hover,
    .user-dropdown a:active,
    .user-menu-dropdown a:hover,
    .user-menu-dropdown a:active {
        background: rgba(255, 94, 120, 0.2);
        border-left-color: rgba(255, 94, 120, 0.8);
    }

    /* ========================================
       MAIN CONTENT SPACING
       ======================================== */

    /* Add top padding to account for fixed header */
    main {
        padding-top: 70px;
    }

    /* ========================================
       HEADER CONTROLS - FIX EMPTY CONTAINERS
       ======================================== */

    .header-controls {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        gap: 0.5rem;
        flex-shrink: 1;
        min-width: 0;
    }

    /* Hide empty notification/user containers when not logged in */
    .notification-icon-container:empty,
    .user-menu:empty,
    #notificationIconContainer:empty,
    #userMenuContainer:empty {
        display: none !important;
    }

    /* Style notification icon when present */
    .notification-icon-container:not(:empty),
    #notificationIconContainer:not(:empty) {
        display: flex;
        align-items: center;
    }

    /* Style user menu when present */
    .user-menu:not(:empty),
    #userMenuContainer:not(:empty) {
        display: flex;
        align-items: center;
        flex-shrink: 1;
        min-width: 0;
        max-width: 120px;
    }

    /* Auth buttons container - show on mobile */
    .header-auth-buttons {
        display: flex;
        flex-shrink: 1;
        min-width: 0;
        gap: 0.3rem;
    }

    /* ========================================
       MOBILE MODALS
       ======================================== */

    .modal,
    [class*="modal"][class*="content"] {
        width: 95vw;
        max-width: 95vw;
        max-height: 90vh;
        margin: 5vh auto;
        border-radius: 12px;
        padding: 1.5rem;
    }

    .modal-header,
    [class*="modal"] header {
        padding: 1rem 1.5rem;
        border-radius: 12px 12px 0 0;
    }

    .modal-body,
    [class*="modal"] .body {
        padding: 1.5rem;
        max-height: calc(90vh - 140px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer,
    [class*="modal"] footer {
        padding: 1rem 1.5rem;
        flex-direction: column;
        gap: 0.75rem;
    }

    .modal-footer button,
    [class*="modal"] footer button {
        width: 100%;
    }

    /* ========================================
       MOBILE FORMS
       ======================================== */

    input,
    textarea,
    select {
        width: 100%;
        padding: 1rem;
        border-radius: 8px;
        font-size: 16px !important; /* Prevent zoom */
    }

    textarea {
        min-height: 120px;
    }

    .form-group,
    [class*="form-group"] {
        margin-bottom: 1.25rem;
    }

    label {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* ========================================
       MOBILE CARDS & LISTS
       ======================================== */

    /* Soul cards grid to single column */
    .souls-grid,
    .feature-grid,
    [class*="grid"] {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    .soul-card {
        padding: 1.25rem;
    }

    /* ========================================
       MOBILE SPACING
       ======================================== */

    section {
        padding: 3rem 1.5rem !important;
    }

    .container {
        padding-left: 1rem;
        padding-right: 1rem;
        max-width: 100%;
    }

    /* ========================================
       MOBILE SCROLLBAR
       ======================================== */

    /* Thinner scrollbar on mobile */
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }

    ::-webkit-scrollbar-thumb {
        border-radius: 4px;
    }

    /* ========================================
       MOBILE TEXT GLOW (Reduced)
       ======================================== */

    /* Reduce glow effects for better mobile performance */
    .eternal-glow,
    .text-immortal-glow,
    h1.eternal {
        text-shadow:
            0 0 8px rgba(255, 94, 120, 0.4),
            0 0 15px rgba(255, 94, 120, 0.2);
    }

    /* ========================================
       MOBILE FOOTER
       ======================================== */

    footer {
        padding: 2rem 1.5rem 1.5rem;
        text-align: center;
    }

    footer nav {
        flex-direction: column;
        gap: 1rem;
    }

    /* ========================================
       LANDSCAPE ORIENTATION
       ======================================== */

    @media (orientation: landscape) and (max-height: 500px) {
        .hero {
            padding: 2rem 1.5rem;
        }

        .hero h1 {
            font-size: 2rem;
        }

        .modal {
            max-height: 85vh;
        }

        header {
            padding: 0.75rem 1.5rem;
        }
    }

    /* ========================================
       PHABLET (375px - 425px)
       ======================================== */

    @media (min-width: 375px) and (max-width: 425px) {
        .feature-card,
        .soul-card {
            padding: 1.25rem;
        }

        .btn {
            font-size: 0.875rem;
            padding: 0.875rem 1.25rem;
        }
    }

    /* ========================================
       SMALL MOBILE (< 375px)
       ======================================== */

    @media (max-width: 374px) {
        body {
            font-size: 14px;
        }

        .hero h1 {
            font-size: 1.75rem;
        }

        .feature-card,
        .soul-card {
            padding: 1rem;
        }

        .btn {
            font-size: 0.8125rem;
            padding: 0.75rem 1rem;
        }

        section {
            padding: 2rem 1rem !important;
        }
    }
}

/* ========================================
   TABLET (768px - 1024px)
   ======================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 90%;
        padding: 0 2rem;
    }

    .souls-grid,
    .feature-grid,
    [class*="grid"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .hero {
        padding: 5rem 2rem;
    }
}

/* ========================================
   PWA OPTIMIZATIONS
   ======================================== */

@media (display-mode: standalone) {
    /* Running as installed PWA */
    header {
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    /* Hide install prompts */
    .install-prompt {
        display: none;
    }

    /* Enhance full-screen experience */
    body {
        background-attachment: fixed;
    }
}

/* ========================================
   HIGH DPI DISPLAYS (RETINA)
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    .feature-card,
    .soul-card,
    .btn,
    input,
    textarea {
        border-width: 0.5px;
    }
}

/* ========================================
   DARK MODE MOBILE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
    [data-theme="dark"] .main-nav.active {
        background: rgba(10, 5, 21, 0.98);
    }

    [data-theme="dark"] .modal {
        background: linear-gradient(135deg,
            rgba(26, 13, 51, 0.98) 0%,
            rgba(16, 16, 33, 0.98) 100%);
    }
}

/* ========================================
   MOBILE ACCESSIBILITY
   ======================================== */

@media (max-width: 768px) {
    /* Larger focus indicators */
    *:focus-visible {
        outline: 3px solid rgba(255, 94, 120, 0.8);
        outline-offset: 2px;
    }

    /* Skip to content link */
    .skip-to-content {
        position: fixed;
        top: -100px;
        left: 10px;
        z-index: 10000;
        padding: 0.75rem 1rem;
        background: rgba(255, 94, 120, 0.9);
        color: white;
        text-decoration: none;
        border-radius: 8px;
        transition: top 0.3s ease;
    }

    .skip-to-content:focus {
        top: 10px;
    }
}

/* ========================================
   MOBILE PRINT STYLES
   ======================================== */

@media print {
    /* Hide decorative elements when printing */
    body::before,
    body::after,
    .mobile-menu-toggle,
    .theme-toggle,
    .floating-theme-toggle {
        display: none !important;
    }

    /* Optimize for printing */
    body {
        background: white !important;
        color: black !important;
    }

    .feature-card,
    .soul-card {
        border: 1px solid #333;
        page-break-inside: avoid;
    }
}
