/* === Core Responsive Fixes === */
@media (max-width: 767px) {

    /* Prevent horizontal scrolling */
    html,
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        position: relative;
    }

    /* Main wrapper constraints */
    .wrapper {
        padding-inline: 1rem;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Ensure all content respects viewport boundaries */
    img,
    video,
    iframe {
        max-width: 100%;
        height: auto;
    }

    /* Mobile menu enhancements */
    .mobile-menu {
        z-index: 100;
        padding-top: 5rem;
    }

    .mobile-menu-button {
        z-index: 101;
        background: rgba(107, 75, 255, 0.1);
        border-radius: 50%;
        width: 42px;
        height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-menu-button.active {
        background: var(--clr-primary);
        color: white;
    }
}

/* === Section Spacing === */
@media (max-width: 767px) {
    section {
        padding-block: 4rem;
    }

    .section-title {
        margin-bottom: 2.5rem;
    }

    .portfolio-section {
        padding-top: 4rem;
        padding-bottom: 3rem;
    }

    .portfolio-footer {
        margin-top: 2rem;
    }
}

/* === Content Layout === */
@media (max-width: 767px) {

    /* Fix grid layouts */
    .hero-main-grid,
    .motion-grid-2x2,
    .project-images-grid,
    .contact-grid {
        grid-template-columns: 2fr !important;
        gap: 1.5rem;
    }

    /* Stats grid - 2x2 grid on mobile */
    .stats-grid-modern {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1rem;
        max-width: 100%;
    }

    /* Make stat items more compact */
    .stat-item {
        padding: 1rem;
    }

    .stat-content h4 {
        font-size: 1.5rem;
    }

    .stat-content span {
        font-size: 0.8rem;
    }

    .stat-circle {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    /* Ensure proper stacking order */
    .hero-content-main {
        order: 1;
    }

    .hero-image-container {
        order: 2;
    }

    .hero-stats-showcase {
        order: 3;
    }

    /* Adjustments to maintain proper spacing */
    .hero-actions {
        flex-direction: column;
        gap: 1rem;
    }

    .hero-actions a {
        width: 100%;
        justify-content: center;
    }
}

/* === Modal Fixes === */
@media (max-width: 767px) {

    /* Video Modal Fix */
    .video-modal {
        padding: 0;
        align-items: center;
        justify-content: center;
        overflow-y: auto;
    }

    .video-modal-content {
        width: calc(100% - 2rem) !important;
        max-width: calc(100% - 2rem) !important;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: var(--radius-md);
    }

    .video-modal-header {
        padding: 1rem;
    }

    .video-modal-player {
        height: auto;
    }

    /* Gallery Modal Fix */
    .modal {
        padding: 0;
        overflow-y: auto;
    }

    .modal-content {
        width: calc(100% - 2rem) !important;
        max-width: calc(100% - 2rem) !important;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: var(--radius-md);
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-gallery {
        flex-direction: column;
    }

    .gallery-main {
        width: 100%;
    }

    .modal-image-main {
        width: 100%;
        height: auto;
    }

    .gallery-thumbnails {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        gap: 0.5rem;
        max-height: none;
        width: 100%;
    }

    .gallery-thumbnail {
        width: 80px;
        flex-shrink: 0;
    }

    .modal-footer {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    /* Graphics Grid View Fix */
    .graphics-grid-view {
        padding: 0;
        overflow-y: auto;
    }

    .grid-view-container {
        width: calc(100% - 2rem) !important;
        max-width: calc(100% - 2rem) !important;
        margin: 1rem;
        padding: 1rem;
    }

    .grid-view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 2rem;
    }

    .grid-close-btn {
        position: absolute;
        top: 1rem;
        right: 1rem;
    }

    .project-images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* === Graphics Section Fixes === */
@media (max-width: 767px) {
    .graphics-section {
        padding-block: 4rem;
    }

    .graphics-marquee-container {
        height: auto;
        flex-direction: column;
    }

    .graphics-info-card {
        width: 100%;
        height: auto;
        padding: 2rem 1.5rem;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .graphics-info-card h3 {
        font-size: 1.75rem;
    }

    .graphics-marquee-wrapper {
        height: 480px;
        overflow: hidden;
        mask: none;
        -webkit-mask: none;
    }

    .graphics-card-marquee {
        width: 280px;
        height: 380px;
    }

    .graphics-card-marquee::before {
        display: none;
    }
}

/* === Skills Section Fixes === */
@media (max-width: 767px) {
    .skills-section {
        padding-block: 4rem;
    }

    .skills-marquee-wrapper {
        overflow: hidden;
    }

    .skill-icon-card {
        width: 120px;
    }
}

/* === Misc Element Fixes === */
@media (max-width: 767px) {

    /* Smaller buttons on mobile */
    .btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
    }

    /* Fix background elements */
    .bg-circle {
        opacity: 0.15;
        filter: blur(50px);
    }

    /* Fix header */
    .main-header {
        height: 60px;
    }

    .logo {
        font-size: 1.5rem;
    }
}