:root {
    --neon-primary: #00f0ff;
    --neon-secondary: #ff00aa;
    --neon-green: #00ff88;
    --bg-dark: #0a0a0f;
    --panel-bg: rgba(10,10,20,0.9);
    --border-color: #2a2a3a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Rajdhani', sans-serif;
    background: linear-gradient(135deg, #0a0a0f, #1a1a2f);
    color: #e0e0e0;
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: background 0.5s;
    overflow: hidden;
}
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(0deg, rgba(0,0,0,0.15) 0px, rgba(0,0,0,0.15) 1px, transparent 1px, transparent 3px);
    pointer-events: none;
    z-index: 999;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}
.login-box {
    background: rgba(10,10,20,0.95);
    border: 1px solid var(--neon-primary);
    border-radius: 15px;
    padding: 40px;
    width: 90%;
    max-width: 350px;
    box-shadow: 0 0 30px rgba(0,240,255,0.3);
    text-align: center;
}
.login-box h1 {
    font-family: 'Orbitron', sans-serif;
    color: var(--neon-primary);
    font-size: 1.8em;
    margin-bottom: 10px;
    text-shadow: 0 0 10px var(--neon-primary);
}
.login-box p { color: #aaa; margin-bottom: 20px; }
.login-box input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    background: rgba(255,255,255,0.05);
    border: 1px solid #444;
    border-radius: 5px;
    color: #fff;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1em;
    outline: none;
    transition: border 0.3s;
}
.login-box input:focus {
    border-color: var(--neon-primary);
    box-shadow: 0 0 10px rgba(0,240,255,0.3);
}
.login-btn {
    background: transparent;
    border: 1px solid var(--neon-primary);
    color: var(--neon-primary);
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    margin-top: 10px;
    transition: all 0.3s;
    width: 100%;
    font-size: 1em;
}
.login-btn:hover {
    background: var(--neon-primary);
    color: #000;
    box-shadow: 0 0 20px var(--neon-primary);
}
.toggle-link { color: #aaa; cursor: pointer; margin-top: 15px; font-size: 0.9em; }
.toggle-link:hover { color: var(--neon-primary); }

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    border: 1px solid #333;
    background: rgba(5,5,15,0.95);
    box-shadow: 0 0 40px rgba(0,240,255,0.2);
    overflow: hidden;
}
.app-header {
    flex-shrink: 0;
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: rgba(10,10,20,0.95);
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
}
.app-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5em;
    font-weight: 900;
    color: var(--neon-primary);
    text-shadow: 0 0 10px var(--neon-primary);
    letter-spacing: 2px;
    pointer-events: none;
}
.app-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}
.profile-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: #111;
    border: 2px solid var(--neon-primary);
    margin-bottom: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(0,240,255,0.4);
    cursor: pointer;
    transition: transform 0.3s;
    position: relative;
}
.profile-circle:hover { transform: scale(1.05); }
.profile-circle img { width: 100%; height: 100%; object-fit: cover; }
.profile-placeholder { font-size: 2.5em; color: #666; }
.profile-name {
    color: var(--neon-primary);
    font-family: 'Orbitron', sans-serif;
    font-size: 1em;
    margin-bottom: 15px;
    letter-spacing: 1px;
}
.profile-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2a;
    border: 1px solid var(--neon-primary);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 100;
    box-shadow: 0 0 20px rgba(0,0,0,0.7);
    min-width: 160px;
}
.profile-menu button {
    background: transparent;
    border: none;
    color: #ccc;
    padding: 10px 14px;
    cursor: pointer;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1em;
    border-radius: 8px;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
}
.profile-menu button:hover {
    background: rgba(0,240,255,0.1);
    color: var(--neon-primary);
}
.settings { width: 100%; margin-top: 10px; }
.settings label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #aaa;
    letter-spacing: 1px;
    font-size: 0.85em;
}
.btn {
    background: transparent;
    border: 1px solid var(--neon-primary);
    color: var(--neon-primary);
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75em;
    font-weight: 700;
    margin: 5px 0;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    width: 100%;
    justify-content: center;
}
.btn:hover {
    background: var(--neon-primary);
    color: #000;
    box-shadow: 0 0 15px var(--neon-primary);
}
.btn-stop { border-color: #ff5555; color: #ff5555; }
.btn-stop:hover { background: #ff5555; color: #000; box-shadow: 0 0 15px #ff5555; }
.btn-secondary { border-color: #888; color: #ccc; }
.btn-secondary:hover { background: #888; color: #000; box-shadow: none; }
.theme-active {
    background: var(--neon-primary);
    color: #000;
    box-shadow: 0 0 15px var(--neon-primary);
    border-color: var(--neon-primary);
}

/* Main Area */
.main-area {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
    min-width: 0;
}
.main-top-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
}
.icon-btn {
    background: transparent;
    border: 1px solid var(--neon-primary);
    color: var(--neon-primary);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover {
    background: var(--neon-primary);
    color: #000;
    box-shadow: 0 0 15px var(--neon-primary);
}
.icon-btn.active {
    background: var(--neon-primary);
    color: #000;
}

/* Video Wrapper */
.video-wrapper {
    position: relative;
    width: min(60vh, 70vw, 800px);
    aspect-ratio: 4 / 3;
    height: auto;
    border-radius: 15px;
    overflow: hidden;
    background: #000;
    border: 3px solid var(--neon-green);
    box-shadow: 0 0 30px rgba(0,255,136,0.4);
    transition: border-radius 0.3s, width 0.3s, height 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.video-wrapper.circle {
    border-radius: 50%;
    width: min(50vh, 350px);
    aspect-ratio: 1 / 1;
}
video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}
.overlay-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}
.posture-arrows {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin: 5px 0;
    font-size: 2em;
    color: var(--neon-primary);
    text-shadow: 0 0 10px var(--neon-primary);
}
.posture-arrow { transition: opacity 0.2s; }
.posture-arrow.inactive { opacity: 0.2; }
.posture-indicator { margin: 5px auto; width: 100%; max-width: 500px; }
.posture-bubble-container {
    width: 220px;
    height: 30px;
    background: #111;
    border-radius: 15px;
    position: relative;
    margin: 5px auto;
    overflow: hidden;
    border: 1px solid #444;
}
.posture-bubble {
    width: 20px;
    height: 20px;
    background: var(--neon-green);
    border-radius: 50%;
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    transition: left 0.3s ease, background 0.3s;
    box-shadow: 0 0 15px var(--neon-green);
}
.posture-text {
    font-weight: 600;
    margin: 5px 0;
    letter-spacing: 1px;
    color: #ccc;
    font-size: 0.9em;
}
#status {
    margin: 5px 0;
    font-weight: 600;
    color: var(--neon-primary);
    letter-spacing: 1px;
    font-size: 0.9em;
}

/* Right Panel */
.right-panel {
    width: 320px;
    padding: 20px;
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}
.right-panel h3 {
    margin-top: 0;
    color: var(--neon-primary);
    font-family: 'Orbitron', sans-serif;
    text-align: center;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(0,240,255,0.5);
}
.result { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.emoji-big { font-size: 3.5em; text-align: center; animation: pulse 1s infinite; filter: drop-shadow(0 0 10px var(--neon-primary)); }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
.bar-chart { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.bar-label { width: 80px; text-align: right; font-weight: 600; font-size: 0.85em; color: #ccc; }
.bar-container { flex: 1; background: #222; border-radius: 20px; height: 18px; overflow: hidden; border: 1px solid #333; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--neon-primary), var(--neon-secondary)); border-radius: 20px; transition: width 0.3s ease; }

/* History Overlay */
.history-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}
.history-box {
    background: #111;
    border: 1px solid var(--neon-primary);
    border-radius: 15px;
    padding: 20px;
    width: 90%;
    max-width: 1200px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 0 40px rgba(0,240,255,0.3);
    position: relative;
}
.history-box h2 {
    text-align: center;
    color: var(--neon-primary);
    font-family: 'Orbitron', sans-serif;
}
.chart-container { margin-top: 20px; height: 300px; width: 100%; }
.close-history {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2em;
    cursor: pointer;
}

/* Startup Overlay */
.startup-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}
.startup-box {
    background: #111;
    border: 1px solid var(--neon-primary);
    border-radius: 15px;
    padding: 30px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 0 40px rgba(0,240,255,0.3);
    position: relative;
    text-align: center;
}
.startup-box h2 { font-family: 'Orbitron', sans-serif; color: var(--neon-primary); margin-bottom: 20px; }
.startup-box ol { color: #ccc; font-size: 1em; }
.close-startup {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2em;
    cursor: pointer;
}

/* Modale Sfida */
.challenge-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    backdrop-filter: blur(5px);
}
.challenge-container {
    display: flex;
    width: 95%;
    height: 95%;
    max-width: 1400px;
    background: #111;
    border: 1px solid var(--neon-primary);
    border-radius: 15px;
    overflow: hidden;
    position: relative;
}
.challenge-video-area {
    flex: 2;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}
.challenge-video-area video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.challenge-info-area {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 15px;
    overflow-y: auto;
    position: relative;
    padding-top: 60px; /* per non sovrapporre con la X */
}
.challenge-timer-score {
    display: flex;
    gap: 20px;
    justify-content: space-between;
    font-size: 1.2em;
    font-weight: bold;
}
.challenge-timer {
    color: var(--neon-primary);
    font-family: 'Orbitron', sans-serif;
    font-size: 2em;
}
.challenge-current-emotion {
    font-size: 5em;
    text-align: center;
    margin: 10px 0;
    color: #fff;
}
.challenge-emotions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: auto;
}
.challenge-emotion-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    border: 1px solid #444;
    border-radius: 10px;
    font-size: 1.8em;
    transition: all 0.3s;
}
.challenge-emotion-item.completed {
    opacity: 0.3;
    filter: grayscale(100%);
}
.challenge-emotion-item span {
    font-size: 0.5em;
    color: #ccc;
    margin-top: 5px;
}
.close-challenge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2em;
    cursor: pointer;
    z-index: 10;
}
.challenge-rules-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5;
    backdrop-filter: blur(5px);
}
.challenge-rules-box {
    background: #111;
    border: 1px solid var(--neon-primary);
    border-radius: 15px;
    padding: 30px;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 0 40px rgba(0,240,255,0.3);
    text-align: center;
}

/* Utility */
.hidden { display: none !important; }

/* Responsive Mobile */
@media (max-width: 768px) {
    body { overflow: auto; }
    .app-body { flex-direction: column; overflow-y: auto; }
    .sidebar { order: 2; width: 100%; border: none; border-top: 1px solid var(--border-color); padding: 10px; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; max-height: 200px; overflow-y: auto; }
    .main-area { order: 1; flex: 0 0 auto; padding: 10px; min-height: auto; }
    .right-panel { order: 3; width: 100%; border: none; border-top: 1px solid var(--border-color); padding: 10px; max-height: 200px; overflow-y: auto; }
    .main-top-controls { gap: 10px; }
    .icon-btn { width: 40px; height: 40px; font-size: 1.2em; }
    .video-wrapper { width: 95vw; aspect-ratio: 4 / 3; max-width: none; }
    .video-wrapper.circle { width: 70vw; aspect-ratio: 1 / 1; max-width: 300px; }
    .btn { padding: 12px; font-size: 0.8em; }
    .settings { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
    .settings label { width: 100%; margin-top: 5px; }
    .settings .btn { width: auto; flex: 1; min-width: 80px; margin: 2px; }
    .profile-circle { width: 70px; height: 70px; }
    .profile-name { margin: 5px 0; }
    .posture-arrows { font-size: 1.5em; gap: 20px; }
    .challenge-container { flex-direction: column; }
    .challenge-video-area { height: 50vh; }
    .challenge-info-area { min-height: 0; flex: 1; overflow-y: auto; padding-top: 40px; }
    .challenge-emotions-grid { grid-template-columns: repeat(3, 1fr); }
    .challenge-current-emotion { font-size: 3em; }
}