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

:root {
    /* White Theme Colors */
    --bg-color: #f4f6f8;
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    /* Accents */
    --accent-emerald: #0d9488;
    --accent-cyan: #06b6d4;
    --accent-crimson: #ef4444;
    --accent-slate: #94a3b8;
}

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

html, body {
    min-height: 100dvh;
    height: auto;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    font-family: 'Outfit', 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(#cbd5e1 1.5px, transparent 1.5px);
    background-size: 24px 24px;
}

/* Custom Glass Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Red Alert Pulsing Glow */
body.drowsy-alert {
    box-shadow: inset 0 0 100px rgba(220, 38, 38, 0.6);
    animation: alertPulse 1s infinite alternate;
}
@keyframes alertPulse {
    from { box-shadow: inset 0 0 50px rgba(220, 38, 38, 0.4); }
    to { box-shadow: inset 0 0 120px rgba(220, 38, 38, 0.85); }
}

/* Floating 3D Spheres / Orbs */
.orb {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    /* Smooth multi-layered radial gradient */
    background: radial-gradient(circle at 35% 35%, #ffffff 0%, #e2e8f0 60%, #cbd5e1 100%);
    box-shadow: 20px 20px 50px rgba(0, 0, 0, 0.08), inset -8px -8px 20px rgba(0, 0, 0, 0.06);
}

.orb-1 { width: 220px; height: 220px; top: -30px; right: -30px; animation: float 8s ease-in-out infinite; }
.orb-2 { width: 170px; height: 170px; bottom: 40px; right: -40px; animation: float 10s ease-in-out infinite 1s; }
.orb-3 { width: 140px; height: 140px; bottom: 60px; left: -30px; animation: float 9s ease-in-out infinite 2s; }
.orb-4 { width: 90px; height: 90px; top: 18%; left: 4%; animation: float 7s ease-in-out infinite 0.5s; }

@keyframes float { 
    0%, 100% { transform: translateY(0px) rotate(0deg); } 
    50% { transform: translateY(-16px) rotate(4deg); } 
}

#app-container {
    height: 100dvh; 
    display: flex; 
    flex-direction: column; 
    justify-content: space-between; 
    align-items: center; 
    padding: 16px 20px; 
    box-sizing: border-box; 
    z-index: 1; 
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* Glassmorphic Capsules */
.capsule {
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    border-radius: 9999px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.06);
}

/* Header */
.app-header {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 90%;
    max-width: 960px;
    padding: 12px 30px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.app-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    letter-spacing: 4px;
    font-size: 26px;
    text-transform: uppercase;
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    position: absolute;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 30px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(16, 185, 129, 0.3);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-slate);
}

.badge-active .status-dot {
    background-color: #10b981;
    animation: pulse-dot 2s infinite;
}

.badge-drowsy .status-dot {
    background-color: var(--accent-crimson);
    animation: pulse-dot-red 1s infinite;
}

.badge-active { color: #10b981; border-color: rgba(16, 185, 129, 0.3); }
.badge-drowsy { color: var(--accent-crimson); border-color: rgba(239, 68, 68, 0.3); }
.badge-paused { color: var(--text-muted); border-color: rgba(148, 163, 184, 0.3); }

@keyframes pulse-dot {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes pulse-dot-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Main Dashboard Grid */
.dashboard-wrapper {
    display: flex;
    width: 92vw;
    max-width: 1200px;
    margin: 20px auto;
    gap: 24px;
    align-items: center;
    justify-content: center;
}

@media (min-width: 1024px) {
    .dashboard-wrapper {
        flex-direction: row;
    }
}

/* Studio Video Card */
.video-wrapper {
    flex: 2;
    aspect-ratio: 16 / 9;
    border-radius: 28px;
    border: 3px solid rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.08);
    overflow: hidden;
    position: relative;
    border-radius: 24px;
    border: 3px solid rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.12);
    transition: box-shadow 0.3s ease;
}

.glow-active {
    box-shadow: 0 25px 50px -12px rgba(16, 185, 129, 0.2), 0 0 30px rgba(16, 185, 129, 0.2);
}

.glow-drowsy {
    box-shadow: 0 25px 50px -12px rgba(239, 68, 68, 0.3), 0 0 40px rgba(239, 68, 68, 0.3);
}

/* Start Overlay */
.start-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 25;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: inherit;
    box-sizing: border-box;
    transition: opacity 0.3s ease;
}

.start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.start-card {
    background: rgba(255, 255, 255, 0.85);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.9);
    max-width: 80%;
}

.start-icon {
    font-size: 3rem;
    color: var(--accent-emerald);
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

.start-card h3 {
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 8px;
    font-size: 1.2rem;
}

.start-card p {
    font-family: 'Inter', sans-serif;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.input_video {
    display: none;
}

.output_canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    transform: scaleX(-1);
    display: block;
    border-radius: inherit;
    z-index: 1;
}

/* Standalone Telemetry Widget */
.telemetry-card {
    flex: 1;
    max-width: 320px;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.08);
}

.telemetry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(203, 213, 225, 0.5);
    padding-bottom: 12px;
}

.telemetry-title {
    font-size: 16px;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: 1px;
    margin: 0;
}

.telemetry-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.telemetry-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Outfit', monospace;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}

.hud-badge-pill {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(16, 185, 129, 0.2);
    border-radius: 12px;
    color: #059669;
    font-family: 'Outfit', monospace;
    font-size: 12px;
    font-weight: 700;
}

.val-success { 
    color: #059669; 
}

.val-danger { 
    color: #dc2626; 
    text-shadow: 0 0 8px rgba(220,38,38,0.2); 
}

/* Interventions & Loaders */
#intervention-container {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#intervention-container.hidden {
    display: none;
}

#intervention-video {
    width: 90%;
    max-height: 90%;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(239, 68, 68, 0.3);
}

#fallback-alert {
    text-align: center;
    color: var(--accent-crimson);
    font-weight: 900;
}

#fallback-alert h1 {
    font-size: clamp(14px, 2vw, 22px);
    font-weight: 900;
    color: #dc2626;
    margin-top: 4px;
    word-break: break-word;
    letter-spacing: -0.02em;
    animation: pulse-text 1s infinite alternate;
}

#loading-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100;
    background-color: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Inter', sans-serif;
}

#loading-screen.hidden {
    display: none;
}

.loader {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(13, 148, 136, 0.2);
    border-top: 3px solid var(--accent-emerald);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

/* Control Panel */
.controls-panel {
    display: flex;
    flex-direction: row;
    width: auto;
    border-radius: 9999px;
    padding: 8px 20px;
    gap: 12px;
    justify-content: center;
    align-items: center;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 10px 30px -5px rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.control-btn {
    width: auto;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 10px 20px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn:hover {
    transform: translateY(-2px);
}

.control-btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #0d9488);
    color: white;
    border: none;
    box-shadow: 0 6px 20px rgba(13, 148, 136, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 8px 25px rgba(13, 148, 136, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.85);
    color: #334155;
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
    background: #ffffff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

/* Single-Line Footer */
.app-footer {
    position: relative; 
    z-index: 10;
    margin-bottom: 8px; 
    display: flex; 
    flex-direction: row; 
    align-items: center; 
    justify-content: center; 
    gap: 16px; 
    white-space: nowrap;
    flex-shrink: 0;
}

.credit-text {
    font-size: 12px; 
    color: #64748b; 
    font-weight: 600; 
    line-height: 1.4;
    font-family: 'Inter', sans-serif;
}

.social-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.social-pill {
    width: 32px; 
    height: 32px; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    padding: 0;
    color: var(--accent-emerald);
    text-decoration: none;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.social-pill:hover {
    transform: translateY(-2px);
    color: #0f766e;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 15px rgba(13, 148, 136, 0.15);
}

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

@keyframes pulse-text {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.05); opacity: 1; }
}

/* Mobile & Tablet Responsive Layout */
@media (max-width: 1023px) {
    .dashboard-wrapper {
        flex-direction: column;
        width: 90vw;
        gap: 16px;
        margin: 10px auto;
    }
    
    .video-wrapper {
        width: 100%;
        aspect-ratio: 16 / 9;
        border-radius: 20px;
    }
    
    .telemetry-card {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        padding: 16px 20px;
        border-radius: 20px;
    }

    #app-container {
        padding: 10px;
    }
    
    .app-header {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        padding: 10px 16px !important;
        width: 90vw !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 10px auto !important;
        position: relative !important;
    }

    .app-title {
        font-size: 18px !important;
        letter-spacing: 2px !important;
        margin: 0 !important;
        padding: 0 !important;
        text-align: center !important;
        width: auto !important;
        font-weight: 800;
        color: #0f172a;
    }
    
    .badge {
        position: static !important;
        transform: none !important;
        top: auto !important;
        right: auto !important;
        left: auto !important;
        font-size: 10px !important;
        padding: 4px 12px !important;
        letter-spacing: 0.5px !important;
        display: inline-block !important;
        margin-top: 2px !important;
    }
    
    .orb-1, .orb-4 { display: none; }
    
    .start-card {
        width: 85%;
        max-width: 280px;
        padding: 14px 18px;
        box-sizing: border-box;
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(16px);
        border: 1.5px solid rgba(255, 255, 255, 0.95);
        border-radius: 18px;
        text-align: center;
        box-shadow: 0 15px 30px rgba(0,0,0,0.2);
    }
    
    .start-icon {
        font-size: 26px;
        margin-bottom: 8px;
    }
    
    .start-card h3 {
        font-size: 13px;
        font-weight: 800;
        margin: 0 0 4px 0;
        line-height: 1.3;
        color: #0f172a;
    }
    
    .start-card p {
        font-size: 10.5px;
        color: #64748b;
        margin: 0;
        font-weight: 500;
    }
    
    .output_canvas {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }
    
    .controls-panel {
        display: flex;
        flex-direction: column;
        width: 88vw;
        max-width: 340px;
        height: auto;
        min-height: unset;
        margin: 20px auto 16px;
        padding: 16px;
        box-sizing: border-box;
        background: rgba(255, 255, 255, 0.75);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border: 1.5px solid rgba(255, 255, 255, 0.9);
        border-radius: 24px;
        box-shadow: 0 10px 30px -5px rgba(0,0,0,0.08);
        gap: 10px;
        align-items: center;
        justify-content: center;
    }
    
    .control-btn {
        width: 100%;
        box-sizing: border-box;
        padding: 12px 16px;
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.5px;
        border-radius: 14px;
        text-align: center;
        justify-content: center;
        margin: 0;
    }
    
    .app-footer {
        display: flex; 
        flex-direction: column; 
        align-items: center; 
        gap: 8px; 
        width: 90vw; 
        margin: 0 auto 24px; 
        text-align: center;
    }
    
    .divider {
        display: none;
    }
    
    .social-links {
        margin-top: 4px;
    }
}
