/* =====================================================
   RESPONSIVE DESIGN ENHANCEMENTS
   Ensures consistent experience across all devices
   ===================================================== */

/* ==================== MOBILE-FIRST BASE ==================== */

/* Prevent horizontal scroll on all devices */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    position: relative;
}

/* Ensure all containers respect viewport width */
.container {
    width: 100%;
    max-width: var(--max-width, 1400px);
    margin: 0 auto;
    padding: 0 1rem;
}

/* Prevent content from being hidden under fixed nav */
main {
    padding-top: 0;
    position: relative;
}

/* Fix for any absolute/fixed positioned elements */
* {
    max-width: 100vw;
}

img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* ==================== NAVIGATION RESPONSIVE ==================== */

/* Mobile menu toggle button */
.nav__toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1001;
}

@media (max-width: 768px) {
    /* Show hamburger menu on mobile */
    .nav__toggle {
        display: block;
    }
    
    /* Hide menu by default on mobile */
    .nav__menu {
        position: fixed;
        top: var(--nav-height, 70px);
        right: -100%;
        width: 280px;
        height: calc(100vh - var(--nav-height, 70px));
        background: rgba(10, 10, 15, 0.98);
        backdrop-filter: blur(20px);
        flex-direction: column;
        align-items: flex-start;
        padding: 2rem;
        gap: 1.5rem;
        transition: right 0.3s ease;
        border-left: 1px solid var(--border-color);
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    }
    
    /* Show menu when active */
    .nav__menu.active {
        right: 0;
    }
    
    /* Full width menu items on mobile */
    .nav__menu li {
        width: 100%;
    }
    
    .nav__menu a {
        width: 100%;
        padding: 0.75rem 1rem;
        display: block;
    }
    
    /* Theme toggle at bottom of mobile menu */
    .theme-toggle {
        margin-left: 0;
        margin-top: 1rem;
    }
}

/* ==================== HERO SECTION RESPONSIVE ==================== */

/* Fix hero content layout and z-index issues */
.hero-content {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
}

.hero-text {
    position: relative;
    z-index: 3;
    flex: 1;
    transition: opacity 0.5s ease;
}

.hero-image {
    position: relative !important;
    z-index: 2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    /* Override base styles that cause positioning issues */
    padding-left: 0 !important;
    left: 0 !important;
    transition: transform 0.3s ease, opacity 0.5s ease !important;
}

.profile-image {
    transition: transform 0.3s ease;
}

/* Desktop: FIXED - image properly centered on right side */
@media (min-width: 1201px) {
    .hero-content {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 6rem !important;
        max-width: 1200px !important;
        margin: 0 auto !important;
        padding: 0 2rem !important;
    }
    
    .hero-text {
        text-align: left !important;
        flex: 1 1 55% !important;
        max-width: 55% !important;
        padding-right: 2rem !important;
    }
    
    .hero-image {
        flex: 0 1 40% !important;
        max-width: 40% !important;
        min-width: auto !important;
        justify-content: center !important;
        align-items: center !important;
        position: relative !important;
        padding: 0 !important;
        margin: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
    }
    
    .hero-image .profile-image {
        width: 100% !important;
        max-width: 420px !important;
        height: auto !important;
        object-fit: cover !important;
        display: block !important;
        position: relative !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 auto !important;
        border-radius: 1rem !important;
    }
}

/* Tablet and medium screens - FIXED stack layout */
@media (min-width: 769px) and (max-width: 1200px) {
    .hero {
        padding: 6rem 0 4rem !important;
    }
    
    .hero-content {
        flex-direction: column-reverse !important;
        gap: 3rem !important;
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        padding: 0 2rem !important;
    }
    
    .hero-image {
        padding: 0 !important;
        padding-left: 0 !important;
        justify-content: center !important;
        flex: 0 0 auto !important;
        min-width: auto !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        max-width: 450px !important;
        position: relative !important;
        margin: 0 auto 2rem auto !important;
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        transform: none !important;
    }
    
    .hero-image .profile-image {
        width: 100% !important;
        max-width: 400px !important;
        height: auto !important;
        object-fit: cover !important;
        display: block !important;
        margin: 0 auto !important;
        position: relative !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        border-radius: 1rem !important;
    }
    
    .hero-text {
        text-align: center !important;
        min-height: auto !important;
        width: 100% !important;
        max-width: 700px !important;
        margin: 0 auto !important;
    }
    
    .cta-buttons {
        justify-content: center !important;
    }
    
    /* Ensure image doesn't overflow or stick to corner */
    .hero-image::before {
        display: none !important;
    }
}

/* Mobile - FIXED LAYOUT - FORCE OVERRIDE ALL BASE STYLES */
@media (max-width: 768px) {
    .hero {
        padding: 7rem 0 4rem !important;
        padding-top: calc(var(--nav-height, 80px) + 2rem) !important;
        overflow: hidden;
        margin-bottom: 0 !important;
        margin-top: 0 !important;
    }
    
    .hero-content {
        flex-direction: column-reverse !important;
        gap: 2.5rem !important;
        padding: 0 1rem !important;
        padding-top: 1rem !important;
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        margin-bottom: 2rem !important;
    }
    
    .hero-text {
        padding: 0 !important;
        margin-bottom: 0 !important;
        width: 100% !important;
        text-align: center !important;
        min-height: auto !important;
    }
    
    .hero-text h1 {
        font-size: 2.5rem !important;
        line-height: 1.2 !important;
        margin-bottom: 1rem !important;
    }
    
    .subtitle {
        font-size: 1.2rem !important;
        margin-bottom: 1rem !important;
    }
    
    .hero-text > p {
        font-size: 1rem !important;
        line-height: 1.6 !important;
        margin-bottom: 1.5rem !important;
    }
    
    /* Mobile image - FORCE CENTER with stronger overrides */
    .hero-image {
        flex: 0 0 auto !important;
        max-width: 100% !important;
        width: 100% !important;
        min-width: auto !important;
        padding: 0 1rem !important;
        padding-left: 1rem !important;
        left: 0 !important;
        right: 0 !important;
        position: relative !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        margin: 0 auto 2rem auto !important;
        transform: none !important;
    }
    
    .hero-image .profile-image {
        max-width: 350px !important;
        width: 100% !important;
        height: auto !important;
        display: block !important;
        margin: 0 auto !important;
        position: relative !important;
        left: 0 !important;
        right: 0 !important;
        object-fit: cover !important;
        border-radius: 1rem !important;
    }
    
    .cta-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        margin-top: 1.5rem !important;
    }
    
    .btn {
        width: 100% !important;
        max-width: 300px !important;
        text-align: center !important;
    }
    
    .hero-image::before {
        display: none !important;
    }
    
    /* Ensure next section (stats) doesn't overlap */
    .hero + section {
        margin-top: 3rem !important;
        padding-top: 3rem !important;
    }
}

@media (max-width: 480px) {
    /* Extra small mobile - optimized */
    .hero {
        padding: 4rem 0 3rem !important;
    }
    
    .hero-content {
        gap: 2rem !important;
        padding: 0 1rem !important;
        margin-bottom: 1.5rem !important;
    }
    
    .hero-text {
        margin-bottom: 0 !important;
    }
    
    .hero-text h1 {
        font-size: 2rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.75rem !important;
    }
    
    .subtitle {
        font-size: 1.1rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    .hero-text > p {
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
        margin-bottom: 1.25rem !important;
    }
    
    .cta-buttons {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.875rem !important;
        margin-top: 1.25rem !important;
    }
    
    .btn {
        width: 100% !important;
        max-width: 280px !important;
        padding: 0.875rem 1.5rem !important;
        font-size: 0.95rem !important;
    }
    
    /* Image sizing for small screens */
    .hero-image {
        max-width: 100% !important;
        padding: 0 0.5rem !important;
        margin: 0 auto 1.5rem auto !important;
        display: flex !important;
        justify-content: center !important;
        transform: none !important;
    }
    
    .profile-image {
        margin: 0 auto !important;
    }
}

/* ==================== SECTIONS RESPONSIVE ==================== */

@media (max-width: 1024px) {
    section {
        padding: 3rem 0;
    }
}

@media (max-width: 768px) {
    section {
        padding: 2.5rem 0;
    }
    
    .section-header h2 {
        font-size: 2rem;
    }
    
    .section-subtitle {
        font-size: 1rem;
    }
}

/* ==================== ABOUT SECTION RESPONSIVE ==================== */

@media (max-width: 968px) {
    .about-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .about-image {
        order: -1; /* Image first on mobile */
        max-width: 500px;
        margin: 0 auto;
    }
}

/* ==================== STATS SECTION RESPONSIVE ==================== */

/* Ensure stats section has proper spacing and doesn't overlap */
.stats-grid {
    position: relative;
    z-index: 1;
    margin-top: 0;
}

@media (max-width: 968px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
        padding: 0 1rem;
    }
    
    /* Add space between hero and stats on mobile */
    section:has(.stats-grid) {
        margin-top: 2rem !important;
        padding: 3rem 0 !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0 1rem;
    }
    
    .stat-card {
        padding: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    .stat-number {
        font-size: 2.5rem;
    }
    
    /* Ensure proper spacing */
    section:has(.stats-grid) {
        margin-top: 1.5rem !important;
        padding: 2rem 0 !important;
    }
}

/* ==================== PROJECTS GRID RESPONSIVE ==================== */

@media (max-width: 1200px) {
    .project-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
}

@media (max-width: 768px) {
    .project-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* ==================== SKILLS GRID RESPONSIVE ==================== */

@media (max-width: 768px) {
    .skills-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 0.75rem;
    }
    
    .skill-item {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .skills-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==================== CONTACT FORM RESPONSIVE ==================== */

@media (max-width: 768px) {
    .contact__form {
        padding: 2rem 1.5rem;
    }
    
    .form-group {
        margin-bottom: 1.25rem;
    }
}

/* ==================== PROJECT DETAIL PAGES RESPONSIVE ==================== */

.project-hero {
    padding: 8rem 0 5rem;
}

@media (max-width: 968px) {
    .project-hero {
        padding: 6rem 0 3rem;
    }
    
    .project-hero h1 {
        font-size: 2.5rem;
    }
    
    .project-meta {
        flex-wrap: wrap;
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    .project-hero {
        padding: 5rem 0 2.5rem;
    }
    
    .project-hero h1 {
        font-size: 2rem;
    }
    
    .project-hero .section-subtitle {
        font-size: 1rem;
    }
}

/* Feature cards responsive */
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .features-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .feature-card {
        padding: 1.25rem;
    }
}

/* ==================== BUTTONS RESPONSIVE ==================== */

@media (max-width: 480px) {
    .project-links {
        flex-direction: column;
    }
    
    .project-links .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ==================== IMAGES RESPONSIVE ==================== */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

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

/* ==================== PROJECT CARD ICONS FIX ==================== */

/* Make icons in project cards large and properly displayed */
.project-card .project-image {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.project-card .project-image i {
    font-size: 4rem;
    color: rgba(0, 0, 0, 0.15);
}

/* Adjust for smaller screens */
@media (max-width: 768px) {
    .project-card .project-image {
        min-height: 180px;
        padding: 1.5rem;
    }
    
    .project-card .project-image i {
        font-size: 3.5rem;
    }
}

@media (max-width: 480px) {
    .project-card .project-image {
        min-height: 150px;
        padding: 1rem;
    }
    
    .project-card .project-image i {
        font-size: 3rem;
    }
}

/* ==================== TYPOGRAPHY RESPONSIVE ==================== */

@media (max-width: 768px) {
    h1 {
        font-size: 2.5rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 2rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.5rem;
    }
    
    h4 {
        font-size: 1.25rem;
    }
    
    p, li {
        font-size: 1rem;
        line-height: 1.6;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.75rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
}

/* ==================== FOOTER RESPONSIVE ==================== */

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

@media (max-width: 768px) {
    .footer {
        padding: 1.5rem 1rem;
        font-size: 0.9rem;
    }
}

/* ==================== TOUCH DEVICES ==================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets for mobile */
    .btn,
    .nav__menu a,
    .project-card,
    .skill-item {
        min-height: 44px; /* Apple's recommended minimum touch target */
        min-width: 44px;
    }
    
    /* Disable hover effects on touch devices */
    .project-card:hover::before {
        opacity: 0;
    }
    
    /* Show active state instead */
    .project-card:active {
        transform: scale(0.98);
    }
    
    .btn:active {
        transform: scale(0.95);
    }
}

/* ==================== LANDSCAPE MOBILE ==================== */

@media (max-width: 968px) and (orientation: landscape) {
    .hero {
        padding: 4rem 0 3rem;
    }
    
    .hero-content {
        flex-direction: row;
        align-items: center;
    }
    
    .hero-image {
        max-width: 40%;
    }
    
    .hero-text {
        text-align: left;
    }
}

/* ==================== TABLET SPECIFIC ==================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 0 2rem;
    }
    
    .project-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

@media print {
    .nav,
    .theme-toggle,
    .cta-buttons,
    .particles-bg,
    .page-transition,
    .loading-overlay {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    a {
        text-decoration: underline;
    }
    
    .hero,
    section {
        page-break-inside: avoid;
    }
}

/* ==================== ACCESSIBILITY IMPROVEMENTS ==================== */

/* Focus visible for keyboard navigation */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Skip to content link for accessibility */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--accent-primary);
    color: white;
    padding: 1rem 2rem;
    z-index: 10000;
    text-decoration: none;
    font-weight: bold;
}

.skip-to-content:focus {
    top: 0;
}

/* ==================== ULTRA-WIDE SCREENS ==================== */

@media (min-width: 1920px) {
    .container {
        max-width: 1600px;
    }
    
    .hero-content {
        gap: 6rem;
    }
}

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

/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode optimizations for OLED screens */
@media (prefers-color-scheme: dark) {
    body[data-theme="dark"] {
        background: #000;
    }
}

/* ==================== FINAL MOBILE FIX - HIGHEST PRIORITY ==================== */
/* Ensures hero image is centered on ALL mobile devices */

@media screen and (max-width: 768px) {
    /* Ensure hero section has proper spacing from nav */
    .hero {
        min-height: auto !important;
        padding-top: calc(var(--nav-height, 80px) + 3rem) !important;
    }
    
    /* Force override all hero image positioning on mobile */
    .hero .hero-content .hero-image {
        flex: none !important;
        max-width: 100% !important;
        min-width: 0 !important;
        width: 100% !important;
        padding: 0 1rem !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        padding-top: 1.5rem !important;
        margin: 1rem auto 2rem !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        position: relative !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        transform: none !important;
    }
    
    /* Force center the actual image */
    .hero .hero-content .hero-image .profile-image {
        max-width: 350px !important;
        width: 100% !important;
        margin: 0 auto !important;
        display: block !important;
        left: 0 !important;
        right: 0 !important;
        position: relative !important;
    }
    
    /* Remove decorative background on mobile */
    .hero .hero-content .hero-image::before {
        display: none !important;
        opacity: 0 !important;
    }
}

@media screen and (max-width: 480px) {
    /* Extra small screens */
    .hero {
        padding-top: calc(var(--nav-height, 80px) + 2.5rem) !important;
    }
    
    .hero .hero-content .hero-image {
        padding: 0 0.5rem !important;
        padding-top: 1.5rem !important;
        margin-top: 1rem !important;
    }
    
    .hero .hero-content .hero-image .profile-image {
        max-width: 300px !important;
    }
}

/* iOS-specific fixes for iPhone Safari */
@supports (-webkit-touch-callout: none) {
    /* iPhone-specific padding to account for nav bar */
    @media screen and (max-width: 768px) {
        .hero {
            padding-top: calc(var(--nav-height, 80px) + 3.5rem) !important;
            padding-top: calc(env(safe-area-inset-top) + var(--nav-height, 80px) + 2rem) !important;
        }
        
        .hero-content {
            padding-top: 2rem !important;
        }
        
        .hero .hero-content .hero-image {
            margin-top: 1.5rem !important;
            padding-top: 2rem !important;
        }
    }
}
