/* --- Global Variables for Theming --- */
:root {
    --mpp-bg-color: rgba(255, 255, 255, 0.65);
    --mpp-border-radius: 24px;
    --mpp-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
    --mpp-accent-color: #0071e3;
    --mpp-text-color: #1d1d1f;
}

@supports (backdrop-filter: blur(20px)) {
    :root {
        --mpp-bg-color: rgba(255, 255, 255, 0.65);
    }
}

/* --- Preview Button Style --- */
#mpp-open-modal-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: #f5f5f7;
    color: var(--mpp-text-color);
    border: none;
    padding: 10px 18px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    margin-left: 10px !important; /* To add space from add-to-cart */
}
#mpp-open-modal-button:hover {
    transform: scale(1.05);
    background-color: #e8e8ea;
}
/* Add an icon (You can use a real SVG here) */
#mpp-open-modal-button::before {
    content: '✨'; /* Example: Sparkle Icon */
    font-size: 16px;
}


/* --- Modal General Style --- */
.mpp-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    -webkit-animation: fadeIn 0.3s;
    animation: fadeIn 0.3s;
    overflow: hidden;
}

.mpp-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 520px;
    background: var(--mpp-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--mpp-border-radius);
    box-shadow: var(--mpp-shadow);
    padding: 32px;
    box-sizing: border-box;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.mpp-close-button {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 30px;
    height: 30px;
    background: rgba(0,0,0,0.1);
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    line-height: 30px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.mpp-close-button:hover {
    background: rgba(0,0,0,0.2);
}

/* --- Upload State --- */
.mpp-state { display: none; }
.mpp-state.active { display: block; }

#mpp-upload-state h2 {
    font-size: 24px;
    color: var(--mpp-text-color);
    margin: 0 0 24px 0;
}

.mpp-upload-area {
    background: rgba(0,0,0,0.05);
    border: 2px dashed rgba(0,0,0,0.1);
    border-radius: 18px;
    padding: 40px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}
.mpp-upload-area.dragover {
    transform: scale(1.03);
    border-color: var(--mpp-accent-color);
    background: rgba(0, 113, 227, 0.1);
}
.mpp-upload-area p {
    margin: 10px 0 0 0;
    color: #6e6e73;
}
.mpp-upload-area .upload-icon {
    font-size: 48px;
    color: var(--mpp-accent-color);
}
#mpp-image-upload { display: none; }

/* --- Loading State --- */
.mpp-loader-container {
    padding: 40px 0;
}
.mpp-loader {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(0,0,0,0.1);
    border-top-color: var(--mpp-accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}
.mpp-status-text {
    font-size: 18px;
    color: var(--mpp-text-color);
}


/* --- Result State --- */
.mpp-result-image-wrapper {
    width: 100%;
    border-radius: 18px;
    overflow: hidden;
    margin-bottom: 24px;
    background: #f5f5f7;
    position: relative; /* For before/after slider */
}
#mpp-result-image {
    display: block;
    width: 100%;
    height: auto;
}

.mpp-action-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
}
.mpp-action-bar button {
    background: rgba(0,0,0,0.08);
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}
.mpp-action-bar button:hover {
    background: rgba(0,0,0,0.12);
}
.mpp-action-bar button.primary {
    background-color: var(--mpp-accent-color);
    color: #fff;
}
.mpp-action-bar button.primary:hover {
    background-color: #0077ed;
}

/* --- Mobile (iOS Style Bottom Sheet) --- */
@media (max-width: 600px) {
    .mpp-modal-content {
        width: 100%;
        max-width: none;
        top: auto;
        bottom: 0;
        left: 0;
        transform: translate(0, 0);
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    }
    .mpp-modal.closing .mpp-modal-content {
        animation: slideDown 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    }
}


/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes slideUp { 
    from { transform: translateY(100%); } 
    to { transform: translateY(0); } 
}
@keyframes slideDown { 
    from { transform: translateY(0); } 
    to { transform: translateY(100%); } 
}

/* --- The "Magic" Preview Button Design V2 (Refined & Optimized) --- */

/* 1. Base Structure and 3D Effect */
#mpp-open-modal-button {
    all: unset;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    margin-left: 12px !important;
    border-radius: 50px;
    cursor: pointer;
    position: relative;
    font-family: 'Vazirmatn', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    background: linear-gradient(145deg, #8e44ad, #6c3483);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-top-color: rgba(255, 255, 255, 0.3);
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.2),
        0 1px 3px rgba(0, 0, 0, 0.1),
        inset 0 1px 1px rgba(255, 255, 255, 0.4);
    
    /* Optimized transition for smoother performance */
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Prevents flickering/jittering on some browsers */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* 2. The Pulsing Glow Effect (Unchanged) */
#mpp-open-modal-button::after {
    content: '';
    position: absolute;
    top: -4px; 
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50px;
    background: linear-gradient(145deg, #a569bd, #8e44ad);
    z-index: -1;
    filter: blur(15px);
    opacity: 0.7;
    animation: softPulse 2.5s infinite ease-in-out;
}

/* 3. Icon (Animation Removed) */
#mpp-open-modal-button::before {
    content: '✨';
    font-size: 20px;
    display: inline-block;
}

/* 4. Refined Interaction States */

/* Hover State */
#mpp-open-modal-button:hover {
    transform: translateY(-3px) scale(1.02); /* A bit more lift and scale for a premium feel */
    box-shadow: 
        0 8px 15px rgba(0, 0, 0, 0.25), /* Stronger shadow when lifted */
        0 3px 6px rgba(0, 0, 0, 0.15),
        inset 0 1px 1px rgba(255, 255, 255, 0.4);
}

/* Active/Click State - The core of the improvement */
#mpp-open-modal-button:active {
    transform: translateY(1px) scale(0.98); /* Pushes down and slightly shrinks */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2), /* Reduced outer shadow */
        inset 0 2px 4px rgba(0, 0, 0, 0.4); /* Stronger inner shadow for pressed effect */
    transition-duration: 0.05s; /* Make the press action feel instant */
}


/* 5. Mobile Optimization (Unchanged) */
@media (max-width: 768px) {
    #mpp-open-modal-button {
        width: 100%;
        padding: 16px 24px;
        margin-top: 15px;
        margin-left: 0 !important;
        font-size: 18px;
    }
}

/* 6. Keyframes (iconSpin removed) */
@keyframes softPulse {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0.7;
    }
}