/* Popup Overlay */
#cpa-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999999;
    display: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Main Popup Container */
#cpa-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    z-index: 1000000;
    display: none;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    animation: cpaPopupSlideIn 0.3s ease-out;
}

/* Popup Content */
.cpa-content {
    position: relative;
    padding: 20px;
    text-align: center;
    overflow: auto;
    max-height: 80vh;
}

/* Close Button */
#cpa-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);
}

#cpa-close:hover {
    background: #ff3838;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.5);
}

#cpa-close:focus {
    outline: 2px solid #ff4757;
    outline-offset: 2px;
}

/* Ad Images */
.cpa-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
    margin: 0 auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.cpa-content img:hover {
    transform: scale(1.02);
}

/* Ad Links */
.cpa-ad-link {
    display: inline-block;
    text-decoration: none;
    transition: all 0.3s ease;
    border-radius: 8px;
    overflow: hidden;
}

.cpa-ad-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

/* HTML Ad Container */
.cpa-html-ad {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

.cpa-html-ad iframe {
    max-width: 100%;
    border-radius: 8px;
}

/* Screen Reader Text */
.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
}

/* Animations */
@keyframes cpaPopupSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes cpaPopupSlideOut {
    from {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    #cpa-popup {
        max-width: 95vw;
        max-height: 85vh;
        margin: 20px;
    }
    
    .cpa-content {
        padding: 15px;
        max-height: 75vh;
    }
    
    #cpa-close {
        top: 5px;
        right: 10px;
        width: 28px;
        height: 28px;
        font-size: 16px;
    }
    
    .cpa-content img {
        max-width: 100%;
        height: auto;
    }
}

@media (max-width: 480px) {
    #cpa-popup {
        max-width: 98vw;
        max-height: 80vh;
        margin: 10px;
        border-radius: 8px;
    }
    
    .cpa-content {
        padding: 12px;
        max-height: 70vh;
    }
    
    #cpa-close {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
}

/* High DPI / Retina Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .cpa-content img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    #cpa-popup {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    #cpa-popup-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .cpa-content {
        color: #e2e8f0;
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    #cpa-popup {
        animation: none;
    }
    
    .cpa-content img,
    .cpa-ad-link,
    #cpa-close {
        transition: none;
    }
    
    .cpa-content img:hover,
    .cpa-ad-link:hover,
    #cpa-close:hover {
        transform: none;
    }
}

/* Focus Styles for Keyboard Navigation */
#cpa-popup:focus-within {
    outline: 2px solid #4299e1;
    outline-offset: 2px;
}

.cpa-ad-link:focus {
    outline: 2px solid #4299e1;
    outline-offset: 2px;
    border-radius: 8px;
}

/* Loading State */
.cpa-content.loading {
    opacity: 0.7;
    pointer-events: none;
}

.cpa-content.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid #e2e8f0;
    border-top: 2px solid #4299e1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Print Styles */
@media print {
    #cpa-popup,
    #cpa-popup-overlay {
        display: none !important;
    }
}