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

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #000;
    font-family: 'Outfit', 'Segoe UI', sans-serif;
}

.container {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Webcam — mirrored */
#webcam {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

/* 2D canvas for hand landmarks — mirrored to match video */
#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
    pointer-events: none;
    z-index: 2;
}

/* Three.js transparent overlay */
#three-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Flash overlay */
#flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease-out;
    z-index: 8;
}

/* Border glow — shifts color based on balance */
#border-glow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 7;
    box-shadow: inset 0 0 60px rgba(255, 50, 50, 0);
    transition: box-shadow 0.3s ease;
}

/* Status */
#status {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Score */
#score {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    z-index: 10;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(57, 255, 20, 0.3);
    display: flex;
    align-items: baseline;
    gap: 6px;
}

#score-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 32px;
    font-weight: 700;
    color: #39FF14;
    text-shadow: 0 0 12px rgba(57, 255, 20, 0.5);
}

#score-label {
    font-size: 14px;
    color: rgba(57, 255, 20, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Challenge info */
#challenge-info {
    position: absolute;
    top: 80px;
    right: 20px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 10px;
    z-index: 10;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: right;
}

#challenge-number {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
}

#challenge-detail {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    color: #60a5fa;
    margin-top: 2px;
}

/* MA Display */
#ma-display {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    z-index: 10;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(251, 191, 36, 0.3);
    text-align: center;
}

#ma-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

#ma-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px;
    font-weight: 700;
    color: #fbbf24;
    text-shadow: 0 0 12px rgba(251, 191, 36, 0.4);
}

/* Balance Meter */
#balance-meter {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    z-index: 10;
    text-align: center;
}

#balance-track {
    width: 100%;
    height: 8px;
    background: linear-gradient(90deg,
        #ef4444 0%,
        #f59e0b 35%,
        #22c55e 50%,
        #f59e0b 65%,
        #ef4444 100%
    );
    border-radius: 4px;
    position: relative;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

#balance-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
    transition: left 0.1s ease-out;
}

#balance-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 6px;
}

/* Instructions */
#instructions {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 24px 36px;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 16px;
    text-align: center;
    z-index: 10;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    max-width: 520px;
    transition: opacity 0.8s ease, transform 0.8s ease;
}

#instructions.fade-out {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

.inst-title {
    font-size: 22px;
    font-weight: 700;
    color: #fbbf24;
    margin-bottom: 12px;
    text-shadow: 0 0 12px rgba(251, 191, 36, 0.3);
}

.inst-body {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.6;
    margin-bottom: 10px;
}

.inst-body strong {
    color: #00FFFF;
}

.inst-hint {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
}

/* Mute button */
#mute-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    transition: background 0.2s;
}

#mute-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Utility */
.hidden {
    display: none !important;
}

/* Score pulse animation */
@keyframes score-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

#score.pulse {
    animation: score-pulse 0.3s ease;
}

/* Loading spinner */
.loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

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

/* Balance celebration flash */
@keyframes celebration-flash {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* Responsive */
@media (max-width: 768px) {
    #status { font-size: 12px; padding: 8px 12px; }
    #score-value { font-size: 24px; }
    #ma-value { font-size: 22px; }
    #instructions { padding: 18px 24px; max-width: 90%; bottom: 60px; }
    .inst-title { font-size: 18px; }
    .inst-body { font-size: 13px; }
    #balance-meter { width: 220px; }
}
