:root {
    --bg-color: #0c0c0e;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-hover: rgba(255, 255, 255, 0.2);
    --accent-color: #00f2fe;
    --text-primary: #f5f5f7;
    --text-secondary: #86868b;
    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-stack);
    -webkit-font-smoothing: antialiased;
}

html, body {
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(79, 172, 254, 0.06) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 242, 254, 0.04) 0%, transparent 40%);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

p.subtitle {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Default Mobile Layout (In colonna) */
.main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 480px;
    gap: 14px;
}

.camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4; /* Ottimizzato per la verticalità mobile */
    background: #000;
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Riempie lo spazio senza deformare i tratti del viso */
    transform: scaleX(-1); /* Specchia la camera frontale */
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Assicura che le coordinate combacino perfettamente col video */
    transform: scaleX(-1);
    pointer-events: none;
}

.hud-data-panel {
    width: 100%;
    background: var(--glass-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.data-group {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.015);
    border: 1px solid rgba(255, 255, 255, 0.03);
    padding: 8px 10px;
    border-radius: 10px;
}

.label {
    color: var(--text-secondary);
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.value {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.02em;
    margin-top: 2px;
}

.status-box {
    grid-column: span 2;
    background: rgba(0, 242, 254, 0.025);
    border: 1px solid rgba(0, 242, 254, 0.08);
    padding: 8px 10px;
    text-align: center;
    color: var(--accent-color);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 10px;
}

#status-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(12, 12, 14, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 10;
    text-align: center;
    padding: 20px;
}

.spinner {
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    margin-bottom: 12px;
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.3);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden { display: none !important; }

#start-btn {
    margin-top: 14px;
    padding: 10px 22px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border-hover);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 980px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
}

#start-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Ottimizzazione Desktop (Schermi larghi): Affianca video e pannello dati in orizzontale */
@media (min-width: 900px) {
    .main-wrapper {
        flex-direction: row;
        max-width: 960px;
        align-items: stretch;
        gap: 20px;
    }

    .camera-container {
        width: 560px;
        flex-shrink: 0;
        aspect-ratio: 4/3;
        max-height: none;
    }

    .hud-data-panel {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        gap: 12px;
    }

    .status-box {
        margin-top: auto;
    }
}

#camera-container {
    position: relative;
    width: 100%;
    max-width: 450px;
    aspect-ratio: 3/4;
    background: #000;
    overflow: hidden;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#videoElement {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Specchia la telecamera */
}

#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Si adatta esattamente come il video */
    transform: scaleX(-1); /* Specchia il canvas nella stessa direzione del video per mantenere l'allineamento dei landmark */
    pointer-events: none;
}