/* ============================================
   GLOBAL STYLES - IMPROVED UI
============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background 0.6s ease;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow-x: hidden;
    position: relative;
}

/* Animated Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ============================================
   EMOTION-BASED BACKGROUNDS
============================================ */
body.happy {
    background: linear-gradient(135deg, #FFF59D 0%, #FFE082 50%, #FFEB3B 100%);
}

body.sad {
    background: linear-gradient(135deg, #37474F 0%, #546E7A 50%, #607D8B 100%);
}

body.angry {
    background: linear-gradient(135deg, #EF5350 0%, #E53935 50%, #C62828 100%);
    animation: shake 0.5s infinite;
}

body.surprised {
    background: linear-gradient(135deg, #FF6B6B 0%, #4ECDC4 50%, #FFE66D 100%);
    animation: surpriseFlash 0.5s infinite;
}

body.neutral {
    background: linear-gradient(135deg, #90CAF9 0%, #64B5F6 50%, #42A5F5 100%);
}

body.fearful {
    background: linear-gradient(135deg, #9C27B0 0%, #673AB7 50%, #512DA8 100%);
}

body.disgusted {
    background: linear-gradient(135deg, #8BC34A 0%, #689F38 50%, #558B2F 100%);
}

/* ============================================
   ANIMATIONS
============================================ */
@keyframes surpriseFlash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes float {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) rotate(360deg);
        opacity: 0;
    }
}

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

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

/* ============================================
   CONTAINER & LAYOUT - MODERN DESIGN
============================================ */
.container {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    max-width: 1000px;
    width: 95%;
    backdrop-filter: blur(20px);
    animation: fadeIn 0.5s ease;
    position: relative;
    z-index: 1;
    margin-top: 50px; /* Space for auth bar */
}

/* Glass morphism effect */
.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 200px;
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.05) 0%, transparent 100%);
    border-radius: 24px 24px 0 0;
    pointer-events: none;
}

header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
    z-index: 2;
}

h1 {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    font-size: 2.5em;
    font-weight: 800;
    letter-spacing: -0.5px;
    text-shadow: none;
}

.subtitle {
    color: #666;
    font-size: 1.1em;
    font-weight: 400;
    opacity: 0.8;
}

/* ============================================
   VIDEO & CANVAS - ENHANCED DESIGN
============================================ */
.video-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 0 auto 25px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(102, 126, 234, 0.2);
    background: #000;
    transition: all 0.3s ease;
}

.video-container:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 25px 50px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(102, 126, 234, 0.4);
}

/* Decorative border */
.video-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 20px;
    z-index: -1;
    opacity: 0.5;
}

video {
    width: 100%;
    height: auto;
    display: block;
    transform: scaleX(-1);
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform: scaleX(-1);
}

/* ============================================
   CONTROL BUTTONS - MODERN STYLE
============================================ */
.controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

button {
    padding: 14px 32px;
    font-size: 16px;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    box-shadow: 
        0 4px 20px rgba(102, 126, 234, 0.4),
        0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

/* Button ripple effect */
button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:active::before {
    width: 300px;
    height: 300px;
}

#startBtn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#startBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 
        0 8px 30px rgba(102, 126, 234, 0.6),
        0 2px 6px rgba(0, 0, 0, 0.2);
}

#stopBtn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

#stopBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 
        0 8px 30px rgba(245, 87, 108, 0.6),
        0 2px 6px rgba(0, 0, 0, 0.2);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ============================================
   STATUS & EMOTION DISPLAY - ENHANCED
============================================ */
.status {
    text-align: center;
    padding: 18px 25px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: 15px;
    margin-bottom: 25px;
    font-weight: 600;
    color: #333;
    border: 2px solid rgba(102, 126, 234, 0.2);
    backdrop-filter: blur(10px);
}

.loader {
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
    margin: 15px auto 0;
}

.emotion-display {
    text-align: center;
    padding: 35px;
    background: linear-gradient(135deg, rgba(168, 237, 234, 0.3) 0%, rgba(254, 214, 227, 0.3) 100%);
    border-radius: 20px;
    margin-bottom: 25px;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.emotion-display:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.emotion-emoji {
    font-size: 5em;
    margin-bottom: 15px;
    animation: bounce 0.5s ease;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.emotion-text {
    font-size: 1.8em;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.emotion-message {
    font-size: 1.1em;
    color: #555;
    font-weight: 500;
    margin-top: 10px;
    max-width: 500px;
    line-height: 1.6;
}

/* ============================================
   STATISTICS - MODERN CARDS
============================================ */
.stats {
    display: flex;
    justify-content: space-around;
    padding: 20px;
    background: linear-gradient(135deg, rgba(248, 249, 250, 0.8) 0%, rgba(233, 236, 239, 0.8) 100%);
    border-radius: 15px;
    gap: 25px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 25px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.stat-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.stat-label {
    font-size: 0.95em;
    color: #666;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   FLOATING EMOJIS
============================================ */
.floating-emoji {
    position: fixed;
    font-size: 3em;
    animation: float 3s ease-in-out;
    pointer-events: none;
    z-index: 1000;
}

/* ============================================
   RESPONSIVE DESIGN - MOBILE OPTIMIZED
============================================ */
@media (max-width: 768px) {
    body {
        padding-top: 240px;
    }
    
    .container {
        padding: 25px 20px;
        border-radius: 20px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .subtitle {
        font-size: 0.95em;
    }

    .controls {
        flex-direction: column;
    }

    button {
        width: 100%;
        justify-content: center;
        padding: 16px 32px;
        font-size: 15px;
    }

    .emotion-emoji {
        font-size: 4em;
    }
    
    .emotion-text {
        font-size: 1.5em;
    }
    
    .emotion-message {
        font-size: 1em;
    }
    
    .stats {
        flex-direction: column;
        gap: 15px;
    }
    
    .stat-item {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
    }
}