/* 
AI Challenge Generator - Safe Isolated CSS
Uses unique namespace and safe z-index range to avoid conflicts
*/

/* Enhanced scroll prevention for all devices */
body.aiChallGen-modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Main container with unique namespace */
.aiChallGen-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    z-index: 3000000; /* Safe z-index above all existing modals */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    overscroll-behavior: contain;
}

.aiChallGen-modal-overlay.aiChallGen-active {
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-8px);
    animation: aiChallGen-fadeIn 0.3s ease-out;
}

.aiChallGen-modal-container {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border-radius: 20px;
    max-width: 95vw;
    max-height: calc(96vh - 2px);
    width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiChallGen-slideIn 0.3s ease-out;
}

/* Browser-specific height fix for all devices */
.aiChallGen-modal-container.browser-mode {
    max-height: calc(90vh - 2px); /* Reduced height for browser UI */
}

/* PWA-specific optimized height for all devices */
.aiChallGen-modal-container.pwa-mode {
    max-height: calc(98vh - 2px); /* Full height for PWA */
}

/* Progress indicator */
.aiChallGen-progress {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 50px;
    background: linear-gradient(135deg, #2d2d2d 0%, #3d3d3d 100%);
    gap: 6px;
}

.aiChallGen-step {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    transition: all 0.3s ease;
}

.aiChallGen-step.active {
    background: linear-gradient(135deg, #8A2BE2 0%, #9A3BF2 50%, #AA4BFF 100%);
    box-shadow: 0 0 8px rgba(138, 43, 226, 0.4);
}

.aiChallGen-step.completed {
    background: linear-gradient(135deg, #00D4AA 0%, #00B894 100%);
}

/* Header with navigation buttons */
.aiChallGen-header {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2d2d2d 0%, #3d3d3d 100%);
}

.aiChallGen-nav-buttons {
    display: contents;
}

.aiChallGen-back-btn {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
}

.aiChallGen-close-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
}

.aiChallGen-back-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.05);
}

.aiChallGen-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.05);
}

.aiChallGen-back-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: translateY(-50%);
}

.aiChallGen-title {
    color: #fff;
    font-size: 24px;
    font-weight: 600;
    margin: 0 10px;
    text-align: center;
    flex: 1;
}

.aiChallGen-description {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    text-align: center;
    margin: 10px 0 0 0;
}

/* Scrollable content area */
.aiChallGen-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    overscroll-behavior: contain;
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
}

.aiChallGen-content::-webkit-scrollbar {
    width: 8px;
}

.aiChallGen-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.aiChallGen-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

/* Card grid layout */
.aiChallGen-cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    max-width: 95%;
    margin: 0 auto;
}

.aiChallGen-card {
    background: linear-gradient(135deg, #3d3d3d 0%, #4d4d4d 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    position: relative;
    overflow: hidden;
}

/* Desktop maintains left alignment, mobile gets center alignment via media query */
@media (min-width: 769px) {
    .aiChallGen-card {
        text-align: left; /* Ensure desktop keeps left alignment */
        align-items: flex-start;
    }
}

.aiChallGen-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border-color: rgba(138, 43, 226, 0.5);
}

.aiChallGen-card.aiChallGen-selected {
    border-color: #8A2BE2;
    background: linear-gradient(135deg, #4d2d4d 0%, #6d4d6d 100%);
    box-shadow: 0 0 20px rgba(138, 43, 226, 0.3);
}

.aiChallGen-card-emoji {
    font-size: 32px;
    margin-right: 8px;
    display: inline;
    line-height: 1;
}

.aiChallGen-card-content {
    flex: 1;
}

.aiChallGen-card-title {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 0;
}

.aiChallGen-card-description {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    line-height: 1.4;
}

/* Footer with action buttons */
.aiChallGen-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(135deg, #2d2d2d 0%, #3d3d3d 100%);
}

.aiChallGen-footer-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.aiChallGen-primary-btn, .aiChallGen-secondary-btn {
    padding: 15px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.aiChallGen-primary-btn {
    background: linear-gradient(135deg, #8A2BE2 0%, #9A3BF2 100%);
    color: #fff;
}

.aiChallGen-primary-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #9A3BF2 0%, #AA4BFF 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(138, 43, 226, 0.4);
}

.aiChallGen-primary-btn.aiChallGen-primary-btn:disabled {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    cursor: not-allowed;
    transform: none;
}

.aiChallGen-primary-btn.aiChallGen-selected-state {
    background: linear-gradient(135deg, #8A2BE2 0%, #9A3BF2 100%);
}

.aiChallGen-primary-btn.aiChallGen-selected-state:hover {
    background: linear-gradient(135deg, #9A3BF2 0%, #AA4BFF 100%);
}

.aiChallGen-secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.aiChallGen-secondary-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.aiChallGen-secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Loading state */
.aiChallGen-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: rgba(255, 255, 255, 0.7);
}

.aiChallGen-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid #8A2BE2;
    border-radius: 50%;
    animation: aiChallGen-spin 1s linear infinite;
    margin-right: 15px;
}

/* Error state */
.aiChallGen-error {
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    border-radius: 10px;
    padding: 15px;
    color: #ff4757;
    text-align: center;
    margin: 10px 0;
}

/* Animations */
@keyframes aiChallGen-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes aiChallGen-slideIn {
    from { 
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to { 
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

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

/* Mobile responsiveness */
@media (max-width: 768px) {
    .aiChallGen-modal-container {
        width: calc(100vw - 8px); /* Enhanced to use 98%+ of screen */
        max-width: calc(100vw - 8px); /* Override the 95vw constraint */
        max-height: calc(85vh - 2px); /* Conservative height for mobile browser */
    }
    
    /* PWA gets full height */
    .aiChallGen-modal-container.pwa-mode {
        max-height: calc(98vh - 2px); /* Full height for PWA */
    }
    
    /* Browser gets conservative height to avoid cutoff */
    .aiChallGen-modal-container.browser-mode {
        max-height: calc(80vh - 2px); /* Safe height for browser with address bar */
    }
}
    
    .aiChallGen-cards-grid {
        grid-template-columns: 1fr;
        max-width: 100%; /* Use full available width within modal */
        margin: 0;
    }
    
    .aiChallGen-header {
        padding: 12px 20px; /* Consistent with desktop, optimized for mobile */
    }
    
    .aiChallGen-title {
        font-size: 20px;
        margin: 0 8px; /* Enhanced margins for better text spacing */
    }
    
    .aiChallGen-content {
        padding: 15px;
        /* Let flexbox handle height - removed fixed calculations that break footer visibility */
    }
    
    /* Streamlined footer for mobile */
    .aiChallGen-footer {
        padding: 12px 15px; /* Reduced from 20px to 12px - saves 16px total height */
    }
    
    .aiChallGen-footer-buttons {
        gap: 8px; /* Reduced from 10px to 8px - saves 2px */
    }
    
    /* Enhanced card content centering for mobile */
    .aiChallGen-card {
        text-align: center; /* Center all card content */
        align-items: center; /* Center flex items vertically */
        padding: 20px; /* Equal padding for visual balance */
    }
    
    .aiChallGen-card-content {
        display: flex;
        flex-direction: column;
        align-items: center; /* Center content horizontally */
        text-align: center; /* Center text */
        gap: 8px; /* Equal spacing between elements */
    }
    
    /* Specific centering for steps without card-content wrapper */
    .aiChallGen-card[data-theme] {
        flex-direction: column; /* Stack content vertically */
        justify-content: center; /* Center content vertically */
        text-align: center; /* Center text horizontally */
    }
    
    .aiChallGen-card[data-idea-title] {
        flex-direction: column; /* Stack content vertically */  
        justify-content: center; /* Center content vertically */
        text-align: center; /* Center text horizontally */
    }
    
    /* Ensure title and description are centered in steps 3 & 4 */
    .aiChallGen-card[data-theme] .aiChallGen-card-title,
    .aiChallGen-card[data-idea-title] .aiChallGen-card-title {
        text-align: center;
        margin-bottom: 12px; /* Consistent spacing */
    }
    
    .aiChallGen-card[data-idea-title] .aiChallGen-card-description {
        text-align: center;
        margin-top: 0; /* Remove default top margin */
    }
}

/* Clean AI Help Button - Simple & Effective with just enough specificity */
button.ai-help-btn {
    background: linear-gradient(135deg, #ff00cc, #333399, #00ccff);
    color: white;
    border: none;
    padding: 16px 24px;
    border-radius: 16px;
    font-size: 16px;
    cursor: pointer;
    width: 100%;
    margin: 10px 0 20px 0;
    transition: all 0.3s ease;
    display: block;
    text-align: center;
}

.ai-help-btn:hover,
.ai-help-btn:focus,
.ai-help-btn:active {
    background: linear-gradient(135deg, #ff1adb, #4747a3, #1adbff);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 0, 204, 0.4);
}

.aiChallGen-trigger-description {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    text-align: center;
    margin-top: 8px;
    margin-bottom: 25px;
}