:root {
    --bg-dark: #0f1014;
    --panel-bg: rgba(22, 24, 28, 0.75);
    --panel-border: rgba(255, 255, 255, 0.08);
    --accent-primary: #3b82f6;
    --accent-pgm: #ef4444;
    /* Red for Program */
    --accent-pvw: #22c55e;
    /* Green for Preview */
    --text-main: #ffffff;
    --text-dim: #9ca3af;
    --font-ui: 'Inter', sans-serif;
    --font-display: 'Space Grotesk', sans-serif;

    --glass-blur: 16px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);

    --btn-height: 56px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    background-image: radial-gradient(circle at 50% 0%, #1a1d26 0%, var(--bg-dark) 80%);
    color: var(--text-main);
    font-family: var(--font-ui);
    min-height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, handle internally */
}

/* Utilities */
.hidden {
    display: none !important;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 8px;
}

/* Connection Screen */
#connection-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-dark);
    z-index: 1000;
    transition: opacity 0.5s ease;
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.login-box {
    text-align: center;
}

.logo {
    font-family: var(--font-display);
    font-size: 32px;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #fff 0%, #999 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-dim);
    margin-bottom: 32px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.input-group {
    text-align: left;
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    color: var(--text-dim);
    font-size: 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.input-group input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--panel-border);
    color: white;
    padding: 14px;
    border-radius: 12px;
    font-family: var(--font-ui);
    font-size: 16px;
    transition: border-color var(--transition-fast);
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.btn-primary {
    width: 100%;
    background: white;
    color: black;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform 0.1s;
}

.btn-primary:active {
    transform: scale(0.98);
}

.status-msg {
    margin-top: 20px;
    font-size: 13px;
    min-height: 20px;
    color: var(--text-dim);
}

.error {
    color: var(--accent-pgm);
}

/* Dashboard Layout */
#dashboard {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Bar */
.top-bar {
    height: 60px;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-family: var(--font-display);
}

.indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
}

.indicator.connected {
    background: var(--accent-pvw);
    box-shadow: 0 0 10px var(--accent-pvw);
}

.tally-display {
    display: flex;
    gap: 20px;
    flex: 1;
    justify-content: center;
}

.tally-box {
    text-align: center;
}

.tally-box .label {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 700;
    display: block;
}

.tally-box .value {
    font-size: 14px;
    font-weight: 600;
    color: white;
}

.tally-box.program .value {
    color: var(--accent-pgm);
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.tally-box.preview .value {
    color: var(--accent-pvw);
}

.meta-info {
    font-family: monospace;
    color: var(--text-dim);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Main Layout Grid */
.main-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 280px 1fr;
    /* Preview | Trans | Program */
    gap: 1px;
    background: var(--panel-border);
    /* Grid lines */
    overflow: hidden;
}

.panel {
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.panel-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--panel-border);
}

.panel-header h2 {
    font-size: 12px;
    letter-spacing: 1px;
    color: var(--text-dim);
}

.panel-header.sm h3 {
    font-size: 12px;
    color: var(--text-dim);
}

.badge {
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    background: #333;
}

.badge.green {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-pvw);
}

.badge.red {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-pgm);
}

.live-pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

/* Scene Grid */
.scene-grid {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    overflow-y: auto;
}

.scene-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 16px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    height: 100px;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.scene-icon {
    color: var(--text-dim);
}

.scene-name {
    font-weight: 500;
    font-size: 14px;
    line-height: 1.3;
    z-index: 1;
}

.scene-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Active States */
.preview-panel .scene-btn.active {
    border-color: var(--accent-pvw);
    background: rgba(34, 197, 94, 0.1);
    box-shadow: inset 0 0 0 1px var(--accent-pvw);
}

.preview-panel .scene-btn.active .scene-icon {
    color: var(--accent-pvw);
}

.program-panel .scene-btn.active {
    border-color: var(--accent-pgm);
    background: rgba(239, 68, 68, 0.1);
    box-shadow: inset 0 0 0 1px var(--accent-pgm);
}

.program-panel .scene-btn.active .scene-icon {
    color: var(--accent-pgm);
}

/* Transitions */
.transition-panel {
    padding: 20px;
    gap: 30px;
    align-items: center;
}

.transition-controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 200px;
}

.btn-trans {
    height: 64px;
    border-radius: 8px;
    border: none;
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
    font-family: var(--font-display);
    letter-spacing: 1px;
    transition: all 0.1s;
}

.btn-cut {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-cut:active {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(2px);
}

.btn-auto {
    background: white;
    color: black;
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.1);
}

.btn-auto:active {
    background: #ddd;
    transform: translateY(2px);
}

.slider-group {
    width: 100%;
    max-width: 200px;
}

.duration-control {
    width: 100%;
    max-width: 200px;
    text-align: center;
}

.duration-control label {
    font-size: 12px;
    color: var(--text-dim);
    display: block;
    margin-bottom: 10px;
}

input[type=range] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    margin-top: -6px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.presets {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.btn-preset {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text-dim);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.btn-preset.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-color: white;
}


/* Audio Mixer */
.audio-mixer-container {
    height: 220px;
    background: var(--bg-dark);
    border-top: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
}

.mixer-scroll {
    flex: 1;
    display: flex;
    overflow-x: auto;
    padding: 20px;
    gap: 16px;
    align-items: stretch;
}

.mixer-scroll::-webkit-scrollbar {
    height: 6px;
}

.mixer-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.channel-strip {
    width: 70px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.fader-track {
    flex: 1;
    width: 30px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    position: relative;
    display: flex;
    justify-content: center;
}

.fader-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--accent-pvw);
    opacity: 0.2;
    border-radius: 15px;
    height: 50%;
    /* Dynamic */
    pointer-events: none;
}

.vol-fader {
    /* Standard Modern Vertical Slider */
    writing-mode: vertical-lr;
    direction: ltr;

    /* Fallbacks / Old defaults */
    -webkit-appearance: slider-vertical;
    appearance: slider-vertical;

    width: 100%;
    height: 100%;
    opacity: 0.8;
    background: transparent;
    cursor: pointer;
}

.channel-info {
    text-align: center;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.vol-val {
    font-size: 10px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.channel-name {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.mute-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mute-btn.muted {
    background: var(--accent-pgm);
    color: black;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}


/* RESPONSIVE DESIGN */
@media (max-width: 768px) {
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        /* Program, Controls, Preview */
        overflow-y: auto;
        display: block;
        /* Stack blocks */
    }

    #dashboard {
        height: auto;
        min-height: 100vh;
    }

    .panel-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-dark);
    }

    /* Mobile Order: Program first, then Transition, then Preview */
    .program-panel {
        order: 1;
        border-bottom: 5px solid var(--bg-dark);
    }

    .transition-panel {
        order: 2;
        padding: 10px;
        border-bottom: 5px solid var(--bg-dark);
    }

    .preview-panel {
        order: 3;
    }

    .transition-panel {
        flex-direction: row;
        justify-content: space-between;
    }

    .transition-controls {
        flex-direction: row;
        width: auto;
        max-width: none;
        flex: 1;
    }

    .btn-trans {
        height: 48px;
        flex: 1;
        font-size: 14px;
    }

    .duration-control {
        display: none;
    }

    /* Hide slider on mobile to save space, or make small */

    .scene-grid {
        grid-template-columns: repeat(3, 1fr);
        /* 3 columns on mobile */
    }

    .scene-btn {
        height: 80px;
        padding: 10px;
    }

    .scene-name {
        font-size: 12px;
    }

    .audio-mixer-container {
        position: sticky;
        bottom: 0;
        z-index: 20;
        height: 140px;
    }

    .channel-strip {
        width: 50px;
        padding: 6px;
    }

    .top-bar {
        position: sticky;
        top: 0;
        z-index: 50;
    }
}