:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --gradient: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --radius: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* Animated background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.15) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo .emoji {
    font-size: 2rem;
    filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.5));
}

.logo h1 {
    font-size: 1.875rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-radius: 9999px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
    transition: background 0.3s;
}

.status-dot.active {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
    flex: 1;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Video Section */
.video-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 2px solid var(--surface-light);
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror effect */
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
    pointer-events: none;
}

.video-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    transition: opacity 0.3s;
}

.video-placeholder.hidden {
    opacity: 0;
    pointer-events: none;
}

.placeholder-content {
    text-align: center;
    color: var(--text-muted);
}

.placeholder-content .icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.loading-overlay.active {
    opacity: 1;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--surface-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
}

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

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--surface-light);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-light);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.fps-counter {
    margin-left: auto;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.875rem;
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
}

/* Results Panel */
.results-panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    border: 2px solid var(--surface-light);
    height: fit-content;
    position: sticky;
    top: 2rem;
}

.results-panel h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.no-faces {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    border: 2px dashed var(--surface-light);
    border-radius: 12px;
}

.results-content.hidden {
    display: none;
}

/* Primary Emotion */
.primary-emotion {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--background);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--surface-light);
}

.emotion-icon {
    font-size: 4rem;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.1));
}

.emotion-info {
    flex: 1;
}

.emotion-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    text-transform: capitalize;
}

.confidence-bar {
    position: relative;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: var(--gradient);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.confidence-text {
    position: absolute;
    right: 0;
    top: -20px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary);
}

/* Probabilities */
.probabilities {
    margin-bottom: 1.5rem;
}

.probabilities h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.probabilities-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.prob-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.prob-label {
    width: 80px;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.prob-bar-container {
    flex: 1;
    height: 6px;
    background: var(--background);
    border-radius: 3px;
    overflow: hidden;
}

.prob-bar {
    height: 100%;
    background: var(--surface-light);
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s;
}

.prob-bar.active {
    background: var(--primary);
}

.prob-value {
    width: 45px;
    text-align: right;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: monospace;
}

/* Stats */
.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--surface-light);
}

.stat-item {
    text-align: center;
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    font-family: monospace;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.loading-overlay {
    display: none !important;
}

/* Footer */
.footer {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--surface-light);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

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

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .results-panel {
        position: static;
    }
}