/* Mobile-Specific Optimizations */

/* Performance-first mobile optimizations for smooth scrolling */
@media (max-width: 768px) {
    /* Optimize rendering without breaking transforms */
    body, main, section {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    /* Disable expensive backdrop filters on mobile */
    .card, .project-card, .contact-card, .cv-summary, .cv-details, 
    .timeline-item, .stat-card, .achievement-item {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(15, 20, 30, 0.95) !important;
    }

    /* Simplify header backdrop */
    .site-header {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(10, 15, 25, 0.98) !important;
    }

    /* Disable expensive shadow effects */
    .card, .project-card, .contact-card {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    }

    /* Simplify all animations to improve performance */
    * {
        animation-duration: 0.1s !important; /* Faster for snappier feel */
        transition-duration: 0.1s !important; /* Faster for snappier feel */
    }

    /* Disable complex animations */
    @keyframes fadeInUp,
    @keyframes fadeInDown,
    @keyframes fadeInLeft,
    @keyframes fadeInRight {
        0% { opacity: 0; }
        100% { opacity: 1; }
    }

    /* Remove heavy blur effects */
    .glow-overlay {
        display: none !important;
    }

    /* Reduce background animation opacity for performance */
    .background-animation {
        opacity: 0.5 !important;
    }

    /* Optimize transforms for better performance */
    .project-card:hover,
    .card:hover {
        transform: translateY(-2px) !important;
    }

    /* Disable 3D transforms on mobile (but not on html/body to preserve scrolling) */
    .card, .project-card, .hero, .portrait-frame {
        transform-style: flat !important;
        perspective: none !important;
    }

    /* CRITICAL: Fix text visibility on mobile */
    body {
        text-shadow: none !important;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* Remove excessive text shadows from paragraphs */
    p, h1, h2, h3, h4, h5, h6, span, a, li, label {
        text-shadow: none !important;
    }

    /* Improve text contrast */
    p {
        color: #e0f5eb !important;
    }

    h1, h2, h3, h4, h5, h6 {
        color: #ffffff !important;
    }

    a {
        color: #a0f5c8;
    }

    /* Fix section headings visibility */
    .section-title, .page-title {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    /* Improve card background for better readability */
    .card, .project-card, .contact-card {
        border: 1px solid rgba(124, 92, 255, 0.3) !important;
    }

    /* Fix form input visibility */
    input, textarea, select {
        color: #ffffff !important;
        background: rgba(20, 25, 35, 0.9) !important;
        border: 1px solid rgba(124, 92, 255, 0.4) !important;
    }

    input::placeholder, textarea::placeholder {
        color: rgba(255, 255, 255, 0.5) !important;
    }

    /* Improve button text visibility */
    .btn {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    /* Fix navigation text */
    .main-nav a {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    /* Reduce glow effects that can blur text */
    * {
        filter: none !important;
    }

    /* Keep only essential filters */
    img, svg {
        filter: none;
    }

    .portrait-glow-wrapper::before {
        filter: blur(8px);
        animation: none !important;
    }

    /* Minimum tap target size for mobile */
    a, button, .btn, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Larger tap areas for navigation */
    .main-nav a {
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Improve button spacing */
    .btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    /* Optimize images for mobile */
    img {
        max-width: 100%;
        height: auto;
        image-rendering: -webkit-optimize-contrast;
    }

    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        max-width: 100vw;
        -webkit-overflow-scrolling: touch !important;
        touch-action: auto !important;
        position: relative;
    }

    html {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: auto !important;
    }

    * {
        max-width: 100%;
    }

    /* Better container spacing */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Card improvements */
    .card, .project-card, .contact-card {
        margin-bottom: 1.5rem;
    }

    /* Reduce animations on mobile for performance */
    * {
        animation-duration: 0.1s !important; /* Faster for snappier feel */
        transition-duration: 0.1s !important; /* Faster for snappier feel */
    }

    /* Disable heavy effects */
    .portrait-glow-wrapper::before {
        animation: none;
    }

    /* Optimize backdrop filters */
    .site-header {
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    /* Fix fixed header spacing */
    main {
        padding-top: 72px;
    }

    /* Optimize scroll behavior */
    html {
        scroll-behavior: smooth !important;
    }

    body {
        min-height: 100vh;
    }

    /* Better focus states for accessibility */
    a:focus, button:focus, input:focus, textarea:focus {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }

    /* Improve skill bar visibility */
    .skills-inline {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }

    .skills-inline li {
        width: 100%;
    }

    /* Better social icons spacing */
    .social-icons {
        display: flex;
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Optimize project grids */
    .projects-grid {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
    }

    /* Achievement items */
    .achievement-item {
        flex-direction: column;
        text-align: center;
        padding: 1.25rem;
    }

    /* Stats cards */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Timeline optimization */
    .timeline {
        padding-left: 0;
    }

    .timeline-item::before {
        display: none; /* Hide decorative elements on mobile */
    }

    /* Fix CV section visibility */
    .cv-summary, .cv-details {
        background: rgba(15, 20, 30, 0.85) !important;
        color: #ffffff !important;
    }

    .cv-summary h3, .cv-details h3,
    .cv-summary h4, .cv-details h4 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .cv-summary p, .cv-details p,
    .cv-summary li, .cv-details li {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }

    /* Fix timeline visibility */
    .timeline-item {
        background: rgba(15, 20, 30, 0.85) !important;
    }

    .timeline-item h3, .timeline-item h4 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .timeline-item p, .timeline-item li {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }

    /* Fix project cards */
    .project-card h3, .project-card h4 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .project-card p, .project-card li {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }

    /* Fix stats visibility */
    .stat-card {
        background: rgba(15, 20, 30, 0.85) !important;
    }

    .stat-card h3, .stat-card h4,
    .stat-value {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .stat-label {
        color: #a0f5c8 !important;
        text-shadow: none !important;
    }

    /* Fix contact section */
    .contact-card h3 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .contact-card p, .contact-card a {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }

    /* Fix about section */
    .about-content h3, .about-content h4 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .about-content p, .about-content li {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }

    /* Fix achievement items */
    .achievement-item h3, .achievement-item h4 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .achievement-item p {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }

    /* Fix badge and label visibility */
    .badge, .tag, .label {
        color: #ffffff !important;
        text-shadow: none !important;
        background: rgba(124, 92, 255, 0.3) !important;
    }

    /* Fix live stats section */
    .live-stats h3, .live-stats h4 {
        color: #ffffff !important;
        text-shadow: none !important;
    }

    .live-stats p, .live-stats span {
        color: #e0f5eb !important;
        text-shadow: none !important;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    /* Enhance text visibility even more on very small screens */
    body {
        font-size: 15px !important;
    }

    p {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }

    /* Further reduce spacing */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Compact buttons */
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.95rem;
    }

    /* Stack hero actions */
    .hero-actions {
        flex-direction: column;
        width: 100%;
    }

    .hero-actions .btn {
        width: 100%;
    }

    /* Ensure all headings are visible */
    h1 { font-size: clamp(1.5rem, 7vw, 2rem) !important; }
    h2 { font-size: clamp(1.35rem, 6vw, 1.75rem) !important; }
    h3 { font-size: clamp(1.2rem, 5vw, 1.5rem) !important; }
    h4 { font-size: clamp(1.1rem, 4.5vw, 1.3rem) !important; }
}

/* Landscape mobile optimization */
@media (max-width: 900px) and (orientation: landscape) {
    section {
        padding: 2rem 0;
    }

    .hero {
        padding: 3rem 0 2rem;
    }

    .portrait-frame {
        width: 140px;
        height: 140px;
    }

    /* Disable floating animation on mobile to prevent glitching */
    .portrait-frame img {
        animation: none !important;
        transform: scale(1.05) !important;
    }
}

/* Disable 3D transforms on mobile tablets to prevent glitching */
@media (max-width: 768px) {
    .portrait-frame {
        transform-style: flat !important;
    }

    .portrait-frame:hover {
        transform: scale(1.02) !important;
    }

    .portrait-frame img {
        animation: none !important;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
}

/* Performance optimizations for low-end devices */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }

    .portrait-glow-wrapper::before,
    .site-header::before,
    .project-card::before {
        animation: none !important;
    }
}

/* Dark mode optimizations for mobile */
@media (max-width: 768px) {
    body {
        background: linear-gradient(135deg, #05060a 0%, #0a0d14 100%);
    }

    /* Improve contrast */
    .card, .project-card, .contact-card {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.08);
    }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix iOS viewport height */
    body {
        min-height: -webkit-fill-available;
    }

    /* Prevent zoom on input focus */
    input, select, textarea {
        font-size: 16px !important;
    }

    /* Fix iOS button styling */
    button, .btn {
        -webkit-appearance: none;
        appearance: none;
    }
}

/* Android-specific optimizations */
@media (max-width: 768px) {
    /* Better text rendering */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Optimize scrolling */
    body, html {
        -webkit-overflow-scrolling: touch;
    }

    /* Mobile scrollbar - make it slightly thinner but same vibrant green */
    html::-webkit-scrollbar {
        width: 10px !important; /* Slightly thinner for mobile */
    }

    html::-webkit-scrollbar-track {
        background: transparent !important;
    }

    html::-webkit-scrollbar-thumb {
        background: transparent !important;
        border-radius: 10px !important;
    }

    /* Show custom scrollbar when scrolling on mobile - EXACT MATCH TO DESKTOP */
    html.scrolling::-webkit-scrollbar-track {
        background: linear-gradient(90deg,
            rgba(0, 20, 15, 0.8) 0%,
            rgba(0, 35, 25, 0.9) 50%,
            rgba(0, 20, 15, 0.8) 100%) !important;
        border-radius: 10px !important;
        border: 1px solid rgba(0, 230, 168, 0.2) !important;
        box-shadow: 
            inset 0 0 15px rgba(0, 230, 168, 0.15),
            0 0 10px rgba(0, 0, 0, 0.5) !important;
    }

    html.scrolling::-webkit-scrollbar-thumb {
        background: linear-gradient(180deg, 
            rgba(0, 255, 200, 1) 0%,
            rgba(0, 230, 168, 1) 50%, 
            rgba(0, 200, 140, 1) 100%) !important;
        border-radius: 10px !important;
        border: 2px solid rgba(0, 150, 110, 0.8) !important;
        box-shadow: 
            0 0 20px rgba(0, 255, 200, 0.9),
            0 0 40px rgba(0, 230, 168, 0.7),
            0 0 60px rgba(0, 230, 168, 0.5),
            inset 0 0 10px rgba(255, 255, 255, 0.5),
            inset 0 2px 5px rgba(255, 255, 255, 0.3) !important;
        animation: scrollbar-pulse-mobile 2s ease-in-out infinite !important;
    }

    @keyframes scrollbar-pulse-mobile {
        0%, 100% {
            box-shadow: 
                0 0 20px rgba(0, 255, 200, 0.9),
                0 0 40px rgba(0, 230, 168, 0.7),
                0 0 60px rgba(0, 230, 168, 0.5),
                inset 0 0 10px rgba(255, 255, 255, 0.5),
                inset 0 2px 5px rgba(255, 255, 255, 0.3);
        }
        50% {
            box-shadow: 
                0 0 30px rgba(0, 255, 200, 1),
                0 0 60px rgba(0, 230, 168, 0.9),
                0 0 90px rgba(0, 230, 168, 0.7),
                inset 0 0 15px rgba(255, 255, 255, 0.6),
                inset 0 2px 8px rgba(255, 255, 255, 0.4);
        }
    }
}
