/* ============================================
   Magic Mirror - Face Swap
   Premium UI Design System
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --bg-glass: rgba(255, 255, 255, 0.06);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.4);

    --text-primary: #f0f0f5;
    --text-secondary: #8b8b9e;
    --text-muted: #5a5a6e;

    --accent-primary: #6366f1;
    --accent-primary-light: #818cf8;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, #6366f1, #a855f7, #ec4899);
    --accent-gradient-subtle: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.15));

    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Animated background */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(168, 85, 247, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(236, 72, 153, 0.04) 0%, transparent 50%);
    animation: bgFloat 20s ease-in-out infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes bgFloat {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(2%, -2%) rotate(1deg); }
    66% { transform: translate(-1%, 1%) rotate(-0.5deg); }
}

/* ===== Layout ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.8s ease-out;
}

.header__logo {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.header__icon {
    width: 48px;
    height: 48px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow-glow);
}

.header__title {
    font-size: 2.5rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.header__subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 400;
    max-width: 500px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ===== Main Grid ===== */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: var(--transition-normal);
    animation: fadeInUp 0.6s ease-out both;
}

.card:nth-child(1) { animation-delay: 0.1s; }
.card:nth-child(2) { animation-delay: 0.2s; }

.card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.card__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.card__badge {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.card__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card__label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ===== Image Preview ===== */
.image-preview {
    width: 100%;
    aspect-ratio: 3/4;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: var(--transition-normal);
}

.image-preview--active {
    border-style: solid;
    border-color: var(--accent-primary);
}

.image-preview img,
.image-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview__placeholder {
    text-align: center;
    padding: 2rem;
}

.image-preview__placeholder-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.image-preview__placeholder-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

[hidden] {
    display: none !important;
}

/* ===== Camera Controls ===== */
.capture-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.btn {
    flex: 1;
    padding: 0.85rem 1.25rem;
    border: none;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: var(--transition-fast);
}

.btn:hover::after {
    opacity: 1;
}

.btn:active {
    transform: scale(0.97);
}

.btn--primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

.btn--primary:hover {
    box-shadow: 0 6px 30px rgba(99, 102, 241, 0.45);
    transform: translateY(-1px);
}

.btn--secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.btn--secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glow);
}

.btn--danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn--danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn--large {
    padding: 1.1rem 2rem;
    font-size: 1.05rem;
    border-radius: var(--radius-lg);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn:disabled::after {
    display: none;
}

/* ===== Action Bar ===== */
.action-bar {
    display: flex;
    justify-content: center;
    animation: fadeInUp 0.6s ease-out 0.3s both;
}

.action-bar .btn {
    min-width: 280px;
}

/* ===== Result Section ===== */
.result-section {
    margin-top: 2.5rem;
    animation: fadeInUp 0.6s ease-out;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 2rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    text-align: center;
}

.result-card__title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-image-container {
    max-width: 500px;
    margin: 0 auto 1.5rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 2px solid rgba(99, 102, 241, 0.3);
}

.result-image-container img {
    width: 100%;
    display: block;
}

.result-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.loading-content {
    text-align: center;
    padding: 3rem;
}

.loading-spinner {
    width: 64px;
    height: 64px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1.5rem;
}

.loading-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.loading-subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideInRight 0.4s ease-out;
    min-width: 300px;
    max-width: 420px;
}

.toast--error {
    border-color: rgba(239, 68, 68, 0.3);
}

.toast--success {
    border-color: rgba(34, 197, 94, 0.3);
}

.toast__icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.toast__message {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.4;
}

/* ===== Hidden File Input ===== */
.file-input-hidden {
    display: none;
}

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

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 1.25rem 1rem 3rem;
    }

    .header__title {
        font-size: 1.8rem;
    }

    .header__subtitle {
        font-size: 0.95rem;
    }

    .main-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .image-preview {
        aspect-ratio: 1/1;
    }

    .card {
        padding: 1.25rem;
    }

    .capture-controls {
        flex-direction: column;
    }

    .action-bar .btn {
        min-width: 100%;
    }

    .result-actions {
        flex-direction: column;
    }
}

/* ===== Camera Mirror Effect ===== */
#cameraVideo {
    transform: scaleX(-1);
}

/* ===== Drag & Drop State ===== */
.image-preview--dragover {
    border-color: var(--accent-primary) !important;
    background: rgba(99, 102, 241, 0.05);
}

.image-preview--dragover .image-preview__placeholder-icon {
    animation: pulse 0.6s ease-in-out infinite;
}
