/* Modal Styles - Using same color scheme */
:root {
    --primary: #00d4aa;
    --primary-dark: #00b894;
    --text: #2d3436;
    --text-light: #636e72;
    --bg: #ffffff;
    --bg-alt: #f8f9fa;
    --border: #dfe6e9;
    --shadow: rgba(0, 0, 0, 0.1);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow-y: auto;
    /* Safe area for iPhone */
    padding-top: max(2rem, env(safe-area-inset-top));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-container {
    position: relative;
    background: var(--bg);
    border-radius: 20px;
    max-width: 1200px;
    width: 100%;
    max-height: calc(90vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-content {
    overflow-y: auto;
    padding: 2rem;
    flex: 1;
}

.modal-page-content {
    width: 100%;
}

.modal-error {
    text-align: center;
    padding: 3rem;
}

.modal-error p {
    color: var(--text-light);
    margin-bottom: 2rem;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 1rem;
    }

    .modal-container {
        max-height: 95vh;
        border-radius: 16px;
    }

    .modal-content {
        padding: 1.5rem;
    }

    .modal-close {
        top: 0.75rem;
        right: 0.75rem;
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 0;
    }

    .modal-container {
        max-height: 100vh;
        border-radius: 0;
        height: 100vh;
    }

    .modal-content {
        padding: 1rem;
        padding-top: 3rem;
    }
}

/* Scrollbar for modal */
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: var(--bg-alt);
}

.modal-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Style content inside modal */
.modal-page-content {
    width: 100%;
}

.modal-page-content .webcode-page {
    padding: 0;
}

.modal-page-content .webcode-header {
    margin-bottom: 2rem;
}

/* Ensure games work in modal */
.modal-page-content canvas {
    max-width: 100%;
    height: auto;
}

.modal-page-content iframe {
    width: 100%;
    min-height: 500px;
}

/* Iframe wrapper for external URLs */
.modal-iframe-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.modal-iframe-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-iframe-url-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.modal-iframe-icon {
    font-size: 0.875rem;
    flex-shrink: 0;
}

.modal-iframe-url {
    font-size: 0.875rem;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-iframe-controls {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.modal-iframe-new-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.modal-iframe-new-tab:hover {
    background: var(--border);
    color: var(--primary);
}

.modal-iframe {
    width: 100%;
    flex: 1;
    border: none;
    background: var(--bg);
    min-height: 500px;
}

.modal-iframe-fallback {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

/* External URL content (fallback) */
.modal-external-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 2rem;
    min-height: 400px;
    width: 100%;
}

.modal-external-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.8;
}

.modal-external-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 1rem;
}

.modal-external-description {
    font-size: 1.125rem;
    color: var(--text-light);
    line-height: 1.7;
    max-width: 600px;
    margin-bottom: 2.5rem;
}

.modal-external-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 2rem;
}

.modal-external-url {
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    width: 100%;
    max-width: 600px;
}

.modal-external-url small {
    color: var(--text-light);
    font-size: 0.875rem;
    word-break: break-all;
}

/* Button styles for modal */
.modal-external-content .btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
}

.modal-external-content .btn-primary {
    background: var(--primary);
    color: white;
}

.modal-external-content .btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 212, 170, 0.3);
}

.modal-external-content .btn-secondary {
    background: transparent;
    color: var(--text);
    border: 2px solid var(--border);
}

.modal-external-content .btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.modal-external-content .btn-large {
    padding: 1rem 2.5rem;
    font-size: 1.125rem;
}

@media (max-width: 768px) {
    .modal-iframe-header {
        padding: 0.5rem 0.75rem;
    }
    
    .modal-iframe-url {
        font-size: 0.75rem;
    }
    
    .modal-iframe-new-tab {
        width: 28px;
        height: 28px;
    }
    
    .modal-iframe {
        min-height: 400px;
    }
    
    .modal-external-content {
        padding: 2rem 1.5rem;
        min-height: 300px;
    }
    
    .modal-external-icon {
        font-size: 3rem;
        margin-bottom: 1rem;
    }
    
    .modal-external-title {
        font-size: 1.5rem;
    }
    
    .modal-external-description {
        font-size: 1rem;
        margin-bottom: 2rem;
    }
    
    .modal-external-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .modal-external-actions .btn {
        width: 100%;
    }
}
