* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.mirror-frame {
    width: 100%;
    max-width: 900px;
    aspect-ratio: 16/9;
    background: linear-gradient(145deg, #2d2d2d, #1a1a1a);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
                inset 0 0 50px rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.mirror-frame::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, 
        rgba(255, 255, 255, 0.1) 0%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.1) 100%);
    pointer-events: none;
    z-index: 1;
}

.camera-container {
    width: 100%;
    height: 100%;
    position: relative;
    border-radius: 15px;
    overflow: hidden;
    background: #000;
    transition: filter 0.5s ease;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    filter: brightness(1.1) contrast(1.1);
}

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1);
    z-index: 2;
}

.status-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(10px);
    transition: opacity 0.3s ease;
}

.status-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.status-message {
    text-align: center;
    color: white;
    font-size: 24px;
    font-weight: 600;
}

.status-message p {
    margin-top: 20px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.emotion-display {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    padding: 15px 25px;
    border-radius: 15px;
    display: none;
    align-items: center;
    gap: 15px;
    z-index: 5;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.emotion-display.active {
    display: flex;
    animation: slideIn 0.3s ease;
}

.detection-indicator {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    padding: 10px 15px;
    border-radius: 10px;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 5;
    border: 2px solid rgba(0, 255, 0, 0.3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.detection-indicator.active {
    display: flex;
}

.indicator-dot {
    width: 10px;
    height: 10px;
    background: #2ed573;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

.detection-indicator span {
    color: white;
    font-size: 14px;
    font-weight: 500;
}

/* Маска когда человека нет */
.mask-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 4;
    transition: opacity 0.5s ease;
    /* Важно: маска не должна блокировать видео для обнаружения */
    pointer-events: none; /* Разрешаем события проходить через маску к видео */
}

.mask-overlay > * {
    pointer-events: auto; /* Но сам контент маски может получать события */
}

.mask-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1; /* Убираем из стека когда скрыта */
}

.mask-face {
    font-size: 150px;
    opacity: 0.7;
    animation: maskPulse 3s ease-in-out infinite;
    text-shadow: 0 0 40px rgba(255, 255, 255, 0.6);
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.3));
}

@keyframes maskPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Оверлей изучения лица */
.studying-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 6;
    flex-direction: column;
}

.studying-overlay.active {
    display: flex;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.studying-content {
    text-align: center;
    color: white;
}

.studying-text {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 30px;
    text-shadow: 0 2px 20px rgba(255, 255, 255, 0.3);
    animation: textGlow 2s ease-in-out infinite;
}

@keyframes textGlow {
    0%, 100% {
        text-shadow: 0 2px 20px rgba(255, 255, 255, 0.3);
    }
    50% {
        text-shadow: 0 2px 30px rgba(255, 255, 255, 0.6);
    }
}

.countdown {
    font-size: 120px;
    font-weight: 700;
    color: #ffd700;
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.8);
    animation: countdownPulse 1s ease-in-out;
    line-height: 1;
}

@keyframes countdownPulse {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Оверлей результата */
.result-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 7;
    flex-direction: column;
}

.result-overlay.active {
    display: flex;
    animation: resultAppear 0.8s ease;
}

@keyframes resultAppear {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.result-content {
    text-align: center;
    color: white;
    padding: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    max-width: 600px;
}

.result-icon {
    font-size: 100px;
    margin-bottom: 20px;
    animation: iconBounce 0.6s ease;
}

@keyframes iconBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.result-text {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 15px;
    text-shadow: 0 2px 20px rgba(255, 255, 255, 0.3);
    color: #ffd700;
}

.result-description {
    font-size: 20px;
    opacity: 0.9;
    line-height: 1.6;
    margin-bottom: 20px;
}

.result-timer {
    font-size: 16px;
    opacity: 0.7;
    color: #a4b0be;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes slideIn {
    from {
        transform: translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.emotion-icon {
    font-size: 32px;
    line-height: 1;
}

.emotion-text {
    color: white;
    font-size: 18px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.animation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
    overflow: hidden;
}

.particles {
    width: 100%;
    height: 100%;
    position: relative;
}

.particle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    animation: float 3s ease-in-out infinite;
    will-change: transform, opacity;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.8;
    }
    50% {
        transform: translate(var(--random-x, 0), var(--random-y, -30px)) scale(1.3) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translate(calc(var(--random-x, 0) * 1.5), calc(var(--random-y, -30px) * 1.5)) scale(0.8) rotate(360deg);
        opacity: 0;
    }
}

/* Анимации для разных эмоций */
.emotion-happy .particle {
    background: radial-gradient(circle, #ffd700, #ff6b6b);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
}

.emotion-sad .particle {
    background: radial-gradient(circle, #4a90e2, #2c3e50);
    box-shadow: 0 0 20px rgba(74, 144, 226, 0.8);
}

.emotion-angry .particle {
    background: radial-gradient(circle, #ff4757, #c44569);
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.8);
}

.emotion-surprised .particle {
    background: radial-gradient(circle, #ffa502, #ff6348);
    box-shadow: 0 0 20px rgba(255, 165, 2, 0.8);
}

.emotion-fearful .particle {
    background: radial-gradient(circle, #747d8c, #57606f);
    box-shadow: 0 0 20px rgba(116, 125, 140, 0.8);
}

.emotion-disgusted .particle {
    background: radial-gradient(circle, #2ed573, #1e8449);
    box-shadow: 0 0 20px rgba(46, 213, 115, 0.8);
}

.emotion-neutral .particle {
    background: radial-gradient(circle, #a4b0be, #747d8c);
    box-shadow: 0 0 20px rgba(164, 176, 190, 0.8);
}

/* Эффекты для разных эмоций */
.emotion-happy {
    animation: happyPulse 2s ease-in-out infinite;
}

@keyframes happyPulse {
    0%, 100% {
        filter: brightness(1) saturate(1);
    }
    50% {
        filter: brightness(1.2) saturate(1.3);
    }
}

.emotion-sad {
    animation: sadFade 3s ease-in-out infinite;
}

@keyframes sadFade {
    0%, 100% {
        filter: brightness(0.8) saturate(0.7);
    }
    50% {
        filter: brightness(0.9) saturate(0.8);
    }
}

.emotion-angry {
    animation: angryShake 0.5s ease-in-out infinite;
}

@keyframes angryShake {
    0%, 100% {
        filter: brightness(1.1) saturate(1.5) hue-rotate(0deg);
    }
    25% {
        filter: brightness(1.2) saturate(1.6) hue-rotate(-5deg);
    }
    75% {
        filter: brightness(1.2) saturate(1.6) hue-rotate(5deg);
    }
}

.emotion-surprised {
    animation: surpriseZoom 1s ease-in-out infinite;
}

@keyframes surpriseZoom {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.controls {
    display: flex;
    gap: 15px;
}

.btn {
    padding: 15px 40px;
    font-size: 18px;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Адаптивность */
@media (max-width: 768px) {
    .mirror-frame {
        padding: 10px;
    }
    
    .emotion-display {
        top: 10px;
        right: 10px;
        padding: 10px 15px;
    }
    
    .emotion-icon {
        font-size: 24px;
    }
    
    .emotion-text {
        font-size: 14px;
    }
    
    .status-message {
        font-size: 18px;
    }
}

