/**
 * MTG Card Modal Styles
 * 
 * Mobile-first responsive modal with glassmorphism and smooth animations.
 * 
 * @package MTG_Engine
 * @version 1.0.0
 */

/* Modal Base */
.mtg-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.mtg-modal--open {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Overlay */
.mtg-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: mtg-modal-fade-in 0.2s ease-out;
}

/* Container */
.mtg-modal__container {
    position: relative;
    max-width: 90vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: mtg-modal-zoom-in 0.25s ease-out;
}

/* Close Button */
.mtg-modal__close {
    position: absolute;
    top: -40px;
    right: -10px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 24px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    z-index: 10;
}

.mtg-modal__close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Content */
.mtg-modal__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Title */
.mtg-modal__title {
    margin: 0;
    padding: 0;
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Image Wrapper */
.mtg-modal__image-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

/* Loader */
.mtg-modal__loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
}

.mtg-modal__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mtg-modal-spin 0.8s linear infinite;
}

/* Image */
.mtg-modal__image {
    max-width: 100%;
    max-height: 70vh;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    transition: transform 0.15s ease-out, opacity 0.15s ease-out;
}

.mtg-modal__image--flipping {
    transform: rotateY(90deg) scale(0.95);
    opacity: 0.5;
}

/* Actions */
.mtg-modal__actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.mtg-modal__flip-btn,
.mtg-modal__download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
}

.mtg-modal__flip-btn {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}

.mtg-modal__flip-btn:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    transform: scale(1.03);
}

.mtg-modal__download-btn {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.mtg-modal__download-btn:hover {
    background: linear-gradient(135deg, #047857, #065f46);
    transform: scale(1.03);
    color: white;
}

.mtg-modal__flip-icon,
.mtg-modal__download-icon {
    font-size: 1rem;
}

/* Cursor for clickable cards */
.mtg-card-modal-trigger {
    cursor: zoom-in;
}

/* Animations */
@keyframes mtg-modal-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes mtg-modal-zoom-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes mtg-modal-spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .mtg-modal__container {
        max-width: 95vw;
        padding: 10px;
    }

    .mtg-modal__close {
        top: -45px;
        right: 0;
        width: 44px;
        height: 44px;
        font-size: 28px;
    }

    .mtg-modal__title {
        font-size: 1.1rem;
        max-width: 80vw;
    }

    .mtg-modal__image {
        max-height: 60vh;
        border-radius: 10px;
    }

    .mtg-modal__actions {
        width: 100%;
        padding: 0 10px;
    }

    .mtg-modal__flip-btn,
    .mtg-modal__download-btn {
        flex: 1;
        justify-content: center;
        padding: 12px 16px;
        min-width: 140px;
    }

    /* Touch hint for DFC on mobile */
    .mtg-modal__image-wrapper::after {
        content: "Swipe to flip";
        position: absolute;
        bottom: -25px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 0.75rem;
        color: rgba(255, 255, 255, 0.5);
        opacity: 0;
        transition: opacity 0.3s;
    }

    .mtg-modal[data-is-dfc="1"] .mtg-modal__image-wrapper::after {
        opacity: 1;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .mtg-modal__image {
        max-height: 55vh;
    }

    .mtg-modal__actions {
        flex-direction: column;
    }

    .mtg-modal__flip-btn,
    .mtg-modal__download-btn {
        width: 100%;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .mtg-modal__container {
        flex-direction: row;
        gap: 20px;
    }

    .mtg-modal__image {
        max-height: 85vh;
        max-width: 50vw;
    }

    .mtg-modal__content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .mtg-modal__title {
        width: 100%;
    }

    .mtg-modal__actions {
        flex-direction: column;
        gap: 8px;
    }
}