.project-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    /* Always flex but hidden */
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s;
    will-change: opacity, visibility;
}

.project-modal.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-container {
    background: #0c0c0c;
    width: 90%;
    max-width: 1200px;
    height: 85vh;
    border-radius: 24px;
    border: 1px solid rgba(255, 106, 0, 0.2);
    position: relative;
    overflow: hidden;
    display: flex;
    box-shadow: 0 50px 100px rgba(0, 0, 0, 0.8);
    transform: translateY(20px) scale(0.98);
    transition: transform 0.5s cubic-bezier(0.2, 1, 0.3, 1), opacity 0.5s;
    opacity: 0;
    will-change: transform, opacity;
}

.project-modal.active .modal-container {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--accent-color);
    transform: rotate(90deg);
}

.modal-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    width: 100%;
    height: 100%;
    transition: transform 0.4s ease, opacity 0.4s ease;
    will-change: transform, opacity;
}

/* Navigation Buttons */
.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.05);
    /* Slightly more visible background */
    border: 1px solid rgba(255, 106, 0, 0.4);
    /* Border with accent color */
    border-radius: 50%;
    color: white;
    font-size: 32px;
    cursor: pointer;
    z-index: 2100;
    /* Higher than modal-container */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.modal-nav:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    transform: translateY(-50%) scale(1.15);
    box-shadow: 0 0 30px var(--accent-glow);
}

.modal-nav.prev {
    /* Position exactly on the edge of the 1200px max-width container or screen edge */
    left: calc(50% - 600px - 30px);
}

.modal-nav.next {
    right: calc(50% - 600px - 30px);
}

/* Ensure buttons don't leave the screen on medium displays */
@media (max-width: 1360px) {
    .modal-nav.prev {
        left: 20px;
    }

    .modal-nav.next {
        right: 20px;
    }
}

.nav-arrow {
    margin-top: -4px;
}

@media (max-width: 1100px) {
    .modal-nav {
        width: 50px;
        height: 50px;
        font-size: 28px;
        background: rgba(0, 0, 0, 0.5);
        /* Higher contrast on mobile */
    }

    .modal-nav.prev {
        left: 15px;
    }

    .modal-nav.next {
        right: 15px;
    }
}

.modal-grid.desktop-layout {
    grid-template-columns: 1.7fr 1fr;
}

.modal-media {
    background: #141414;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    overflow: hidden;
    position: relative;
}

/* Video Loader */
.modal-media::after {
    content: '';
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 106, 0, 0.2);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    position: absolute;
    animation: spin 1s linear infinite;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 100;
}

.modal-media.loading::after {
    opacity: 1;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.modal-media video,
.modal-media img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.modal-media.loaded video,
.modal-media.loaded img {
    opacity: 1;
}

.modal-info {
    padding: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
}

.modal-tag {
    color: var(--accent-color);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

.modal-title {
    font-size: 3.5rem;
    font-weight: 400;
    margin-bottom: 8px;
    color: white;
}

.modal-subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.modal-description {
    font-size: 1rem;
    line-height: 1.8;
    color: #aeaeae;
    margin-bottom: 40px;
}

.modal-features {
    list-style: none;
    display: grid;
    gap: 16px;
}

.modal-features li {
    display: flex;
    align-items: center;
    gap: 12px;
    color: white;
    font-size: 0.95rem;
}

.modal-features li::before {
    content: '→';
    color: var(--accent-color);
    font-weight: bold;
}

@media (max-width: 968px) {
    .modal-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow-y: auto;
    }

    .modal-container {
        height: 90vh;
        width: 95%;
    }

    .modal-media {
        padding: 40px 20px 20px 20px;
    }

    .modal-info {
        padding: 30px;
    }

    .modal-title {
        font-size: 2.5rem;
    }
}

/* Carousel Styles */
.carousel-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 12px;
}

.carousel-track {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 0.8s ease-in-out;
}

.carousel-track img {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    background: #141414;
}



.carousel-prev,
.carousel-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    font-size: 1.5rem;
    padding: 10px;
    cursor: pointer;
    z-index: 10;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.carousel-prev:hover,
.carousel-next:hover {
    background: rgba(255, 106, 0, 0.8);
}

.carousel-prev {
    left: 10px;
}

.carousel-next {
    right: 10px;
}

.carousel-dots {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}

.carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s;
}

.carousel-dot.active {
    background: #ff6a00;
    transform: scale(1.2);
}

/* === MODAL MOBILE === */
@media (max-width: 768px) {
    .modal-container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }

    .modal-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: 45vh 1fr;
        overflow-y: auto;
    }

    .modal-media {
        padding: 40px 10px 10px;
        height: 45vh;
    }

    .modal-info {
        padding: 20px;
    }

    .modal-title {
        font-size: 1.8rem;
    }

    .modal-subtitle {
        font-size: 1rem;
        margin-bottom: 16px;
    }

    .modal-description {
        font-size: 0.9rem;
        line-height: 1.6;
        margin-bottom: 20px;
    }

    .modal-features li {
        font-size: 0.85rem;
    }

    .modal-close {
        top: 12px;
        right: 12px;
        width: 44px;
        height: 44px;
        background: rgba(0, 0, 0, 0.6);
        border: 1px solid rgba(255, 255, 255, 0.2);
        font-size: 28px;
    }

    .modal-nav {
        top: 35vh !important;
        transform: translateY(-50%) !important;
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
        background: rgba(0, 0, 0, 0.6) !important;
        border: 1px solid rgba(255, 106, 0, 0.5) !important;
    }

    .modal-nav.prev {
        left: 10px !important;
    }

    .modal-nav.next {
        right: 10px !important;
    }

    .carousel-prev,
    .carousel-next {
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
    }
}