/**
 * Mobile Responsive Fixes
 * Handles all mobile design issues and optimizations
 */

/* ========================================
   BASE MOBILE OPTIMIZATIONS
======================================== */

/* Prevent horizontal scroll */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

* {
    box-sizing: border-box;
}

/* ========================================
   DESKTOP PROTECTION (prevent mobile CSS
   from affecting large screens)
======================================== */

@media (min-width: 769px) {
    /* Restore original navbar padding and layout on desktop */
    .navbar {
        padding: 1.5rem 0 !important;
    }

    .navbar.scrolled {
        padding: 1rem 0 !important;
    }

    /* Ensure navbar container stays flexbox aligned */
    .navbar .container {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    /* Ensure nav-links stay in horizontal row */
    .nav-links {
        display: flex !important;
        align-items: center !important;
        flex-direction: row !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        background: transparent !important;
        padding: 0 !important;
    }

    /* Restore original hero layout on desktop */
    .hero .container {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        align-items: center !important;
        gap: var(--space-4xl) !important;
    }

    .hero-content {
        order: initial !important;
        text-align: left !important;
    }

    .hero-visual {
        order: initial !important;
        max-width: none !important;
        margin: 0 !important;
    }

    /* Restore hero image wrapper size */
    .hero-image-wrapper {
        width: 380px !important;
        height: 380px !important;
    }

    /* Ensure hero image displays correctly */
    .hero-image {
        position: relative !important;
        z-index: 2 !important;
        width: 100% !important;
        height: 100% !important;
        border-radius: 50% !important;
        object-fit: cover !important;
        border: 4px solid var(--bg-primary) !important;
    }

    /* Restore floating card animations */
    .hero-floating-card {
        position: absolute !important;
        animation: float 3s ease-in-out infinite !important;
    }
}

/* ========================================
   MOBILE BREAKPOINTS
======================================== */

@media (max-width: 1200px) {
    .container {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

@media (max-width: 992px) {
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }

    /* Hero Section */
    .hero .container {
        flex-direction: column;
        gap: 3rem;
    }

    .hero-content {
        order: 1;
        text-align: center;
    }

    .hero-visual {
        order: 2;
        max-width: 400px;
        margin: 0 auto;
    }

    .hero h1 {
        font-size: 2.5rem;
        line-height: 1.2;
    }

    .hero-cta {
        justify-content: center;
    }

    /* About Section */
    .about-grid {
        grid-template-columns: 1fr !important;
        gap: 3rem;
    }

    .about-image-container {
        max-width: 400px;
        margin: 0 auto;
    }

    /* Skills Section */
    .skills-categories {
        grid-template-columns: 1fr !important;
    }

    /* Projects Section */
    .projects-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem;
    }

    /* Blog Section */
    .blog-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Typography */
    h1 {
        font-size: 2rem !important;
    }

    h2 {
        font-size: 1.75rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
    }

    /* Navigation */
    .navbar {
        padding: 1rem 0;
    }

    .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: var(--bg-primary, #0a0a0a);
        flex-direction: column;
        align-items: flex-start;
        padding: 5rem 2rem 2rem;
        gap: 1.5rem;
        transition: right 0.3s ease;
        z-index: 999;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    }

    .nav-links.active {
        right: 0;
    }

    .nav-links a {
        width: 100%;
        padding: 0.75rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .hamburger {
        display: flex !important;
        flex-direction: column;
        gap: 4px;
        cursor: pointer;
        z-index: 1000;
    }

    .hamburger span {
        width: 25px;
        height: 3px;
        background: var(--text-primary, #fff);
        transition: all 0.3s ease;
        border-radius: 2px;
    }

    .hamburger.active span:nth-child(1) {
        transform: rotate(45deg) translate(6px, 6px);
    }

    .hamburger.active span:nth-child(2) {
        opacity: 0;
    }

    .hamburger.active span:nth-child(3) {
        transform: rotate(-45deg) translate(6px, -6px);
    }

    .nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.7);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 998;
    }

    .nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Hero Section */
    .hero {
        padding: 6rem 0 4rem;
        min-height: auto;
    }

    .hero h1 {
        font-size: 1.75rem !important;
        margin-bottom: 1rem;
    }

    .hero-description {
        font-size: 0.95rem;
        margin-bottom: 2rem;
    }

    .hero-cta {
        flex-direction: column;
        width: 100%;
    }

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

    .hero-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .hero-stat .number {
        font-size: 2rem;
    }

    .hero-visual {
        max-width: 300px;
    }

    .hero-floating-card {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    .hero-floating-card .icon {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }

    /* Section Headers */
    .section-header {
        text-align: center;
        margin-bottom: 3rem;
    }

    .section-header h2 {
        font-size: 1.75rem !important;
        margin-bottom: 1rem;
    }

    .section-header p {
        font-size: 0.95rem;
    }

    /* About Section */
    .about-info-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .about-counter-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1rem;
    }

    .counter-card {
        padding: 1.5rem 1rem;
    }

    .counter-number {
        font-size: 2rem !important;
    }

    /* Timeline */
    .timeline::before {
        left: 20px;
    }

    .timeline-item {
        padding-left: 50px;
    }

    .timeline-dot {
        left: 13px;
        width: 14px;
        height: 14px;
    }

    .timeline-card {
        padding: 1.25rem;
    }

    .tech-stack {
        gap: 0.5rem;
    }

    .tech-stack span {
        font-size: 0.75rem;
        padding: 0.35rem 0.65rem;
    }

    /* Projects & Blog Grid */
    .projects-grid,
    .blog-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
    }

    .project-card,
    .blog-card {
        max-width: 100%;
    }

    .project-tags,
    .project-tags span {
        font-size: 0.75rem;
    }

    /* Contact Form */
    .contact-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }

    .form-row {
        flex-direction: column;
        gap: 1rem;
    }

    .form-row .form-group {
        width: 100%;
    }

    /* Footer */
    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem;
        text-align: center;
    }

    .footer-column {
        align-items: center;
    }

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

    /* Testimonials */
    .testimonials-slider-container {
        padding: 2rem 1.5rem;
    }

    .testimonial-quote {
        font-size: 0.95rem;
        line-height: 1.6;
    }
}

@media (max-width: 480px) {
    /* Extra small devices */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    h1 {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.35rem !important;
    }

    .hero h1 {
        font-size: 1.5rem !important;
    }

    .hero-stats {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .hero-stat {
        padding: 1rem;
    }

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

    .section {
        padding: 3rem 0;
    }

    .about-counter-grid {
        grid-template-columns: 1fr !important;
    }

    .glass-card {
        padding: 1.25rem;
    }

    .project-overlay-btn,
    .blog-read-more {
        font-size: 0.85rem;
    }
}

/* ========================================
   MOBILE TOUCH OPTIMIZATIONS
======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Touch devices */
    .btn,
    a,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch devices */
    .project-overlay {
        opacity: 1;
        background: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.8) 100%);
    }

    .project-overlay-btn {
        transform: none;
    }
}

/* ========================================
   MOBILE IMAGE OPTIMIZATIONS
======================================== */

@media (max-width: 768px) {
    img {
        image-rendering: auto;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    .hero-image,
    .about-image,
    .project-image,
    .blog-image {
        width: 100%;
        height: auto;
        object-fit: cover;
    }

    .project-image {
        max-height: 200px;
    }

    .blog-image {
        max-height: 180px;
    }
}

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

@media (max-width: 768px) {
    /* Reduce animations on mobile */
    .prefers-reduced-motion,
    .prefers-reduced-motion * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    /* Disable parallax on mobile */
    .hero-canvas {
        display: none;
    }

    /* Simplify backgrounds */
    .hero-bg-gradient {
        opacity: 0.5;
    }

    /* Optimize floating cards */
    .hero-floating-card {
        animation: none;
        position: relative;
        transform: none !important;
    }
}

/* ========================================
   ARTICLE / PROSE RESPONSIVE
======================================== */

@media (max-width: 768px) {
    .article-layout {
        max-width: 100%;
    }

    .article-cover {
        height: 200px !important;
    }

    .prose {
        font-size: 0.95rem;
        line-height: 1.8;
    }

    .prose h1 {
        font-size: 1.5rem !important;
    }

    .prose h2 {
        font-size: 1.25rem !important;
    }

    .prose h3 {
        font-size: 1.1rem !important;
    }

    .prose pre {
        font-size: 0.8rem;
        padding: 1rem;
    }

    .prose blockquote {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .prose table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .prose img {
        margin: 1.25rem 0;
    }
}

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

@media (max-width: 896px) and (orientation: landscape) {
    .hero {
        padding: 3rem 0 2rem;
    }

    .hero .container {
        flex-direction: row;
    }

    .hero-content {
        flex: 1;
        text-align: left;
    }

    .hero-visual {
        flex: 0 0 40%;
        max-width: 300px;
    }

    .hero-stats {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ========================================
   SAFE AREA INSETS (for notched devices)
======================================== */

@supports (padding: max(0px)) {
    .navbar,
    .footer,
    .section {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .nav-links {
        padding-top: max(5rem, calc(5rem + env(safe-area-inset-top)));
    }
}

/* ========================================
   MOBILE UTILITY CLASSES
======================================== */

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

.desktop-only {
    display: block !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-hide {
        display: none !important;
    }

    .mobile-full-width {
        width: 100% !important;
    }
}
