:root {
    --beat-purple: #B47BF8;
    --beat-cyan: #4DD0E1;
    --beat-pink: #FF4ECD;
    --beat-yellow: #FFD93D;
    --beat-dark: #0A0E27;
    --beat-darker: #050714;
    --beat-card: #141938;
    --beat-card-light: #1E2547;
    --text-primary: #FFFFFF;
    --text-secondary: #A0AEC0;
    --text-muted: #718096;
    --success: #48BB78;
    --warning: #ECC94B;
    --danger: #F56565;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--beat-darker);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* Header */
.header {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(180, 123, 248, 0.3);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.logo-text {
    font-weight: 700;
    font-size: 1em;
    background: linear-gradient(90deg, var(--beat-purple), var(--beat-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-text span {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.85em;
    -webkit-text-fill-color: var(--text-secondary);
}

.user-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-badge {
    background: var(--beat-card);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.8em;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.75em;
}

/* Main Layout */
.app-container {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
}

/* Video */
.video-container {
    position: relative;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    width: 100%;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: linear-gradient(135deg, #050714 0%, #141938 100%);
}

.video-overlay-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.5);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8em;
}

.robot-name {
    background: rgba(0, 0, 0, 0.5);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8em;
    font-weight: 500;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
}

.status-indicator.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-indicator.connecting {
    background: var(--warning);
    animation: blink 0.8s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.video-overlay-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
}

.video-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Beat Pulse Overlay */
.beat-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80px;
    height: 80px;
    margin: -40px 0 0 -40px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--beat-pink) 0%, transparent 70%);
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.beat-pulse.flash {
    animation: beat-flash 0.3s ease-out;
}

@keyframes beat-flash {
    0% { opacity: 0; transform: scale(0.5); }
    30% { opacity: 0.9; transform: scale(2.5); }
    100% { opacity: 0; transform: scale(4); }
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(90deg, var(--beat-purple), var(--beat-pink));
    color: white;
}

.btn-secondary { background: rgba(255, 255, 255, 0.15); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-mute {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-mute.muted { background: var(--danger); }
.btn-mute svg { width: 16px; height: 16px; }

/* Audio Source Section */
.audio-section {
    background: var(--beat-card);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.source-tabs {
    display: flex;
    gap: 8px;
}

.source-tab {
    flex: 1;
    padding: 10px;
    background: var(--beat-darker);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85em;
    text-align: center;
    transition: all 0.2s;
}

.source-tab.active {
    border-color: var(--beat-purple);
    color: var(--beat-purple);
    background: rgba(180, 123, 248, 0.08);
}

.source-tab:hover { background: var(--beat-card-light); }

.source-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.file-drop {
    padding: 24px;
    border: 2px dashed var(--beat-card-light);
    border-radius: 8px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
}

.file-drop:hover, .file-drop.dragover {
    border-color: var(--beat-purple);
    color: var(--beat-purple);
    background: rgba(180, 123, 248, 0.05);
}

.file-drop input { display: none; }

.audio-player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.audio-player audio {
    flex: 1;
    height: 36px;
}

.dance-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-dance {
    flex: 1;
    padding: 12px;
    background: linear-gradient(90deg, var(--beat-purple), var(--beat-pink));
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-dance:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-dance.active {
    background: var(--danger);
}

/* Visualizer */
.visualizer {
    background: var(--beat-card);
    border-radius: 12px;
    padding: 16px;
}

.visualizer-header {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--beat-purple);
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bpm-display {
    font-family: monospace;
    color: var(--beat-cyan);
    font-size: 0.9em;
}

canvas.viz-canvas {
    width: 100%;
    height: 100px;
    background: var(--beat-darker);
    border-radius: 8px;
    display: block;
}

/* Sensitivity slider */
.slider-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 12px;
}

.slider-label {
    font-size: 0.8em;
    color: var(--text-secondary);
    min-width: 90px;
}

.slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    background: var(--beat-darker);
    border-radius: 4px;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--beat-purple);
    border-radius: 50%;
    cursor: pointer;
}

.slider-value {
    font-family: monospace;
    font-size: 0.8em;
    color: var(--beat-cyan);
    min-width: 40px;
    text-align: right;
}

/* Robot Selector */
.panel {
    background: var(--beat-card);
    border-radius: 12px;
    overflow: hidden;
}

.panel-header {
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    font-size: 0.85em;
    color: var(--beat-purple);
}

.panel-content { padding: 12px; }

.robot-list { display: flex; flex-direction: column; gap: 8px; }

.robot-card {
    padding: 10px 14px;
    background: var(--beat-darker);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}

.robot-card:hover { background: var(--beat-card-light); }
.robot-card.selected { border-color: var(--beat-purple); }
.robot-card .name { font-weight: 600; font-size: 0.9em; }
.robot-card .id { font-size: 0.75em; color: var(--text-muted); font-family: monospace; }

/* Login */
.login-view {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--beat-card);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    max-width: 380px;
}

.login-logo {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    border-radius: 12px;
}

.login-card h2 {
    background: linear-gradient(90deg, var(--beat-purple), var(--beat-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    font-size: 1.6em;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.9em;
    line-height: 1.5;
}

.btn-hf {
    background: #FFD21E;
    color: #000;
    border: none;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Desktop layout */
@media (min-width: 900px) {
    .app-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        max-width: 1200px;
        gap: 12px;
    }
    .video-container {
        grid-column: 1;
        grid-row: 1 / 3;
    }
    #robotSelector { grid-column: 1; }
    .audio-section { grid-column: 2; grid-row: 1; }
    .visualizer { grid-column: 2; grid-row: 2; }
}
