:root {
    --bg-dark: #0a0b10;
    --bg-panel: #14161f;
    --accent-primary: #00f2ff;
    /* Neon Cyan */
    --accent-secondary: #7000ff;
    /* Neon Purple */
    --text-main: #e8eaed;
    --text-muted: #9aa0a6;
    --border-color: #2a2d3a;
    --success: #00ff9d;
    --warning: #ffbd2e;
    --danger: #ff0055;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Layout Grid --- */
.cockpit-wrapper {
    display: grid;
    grid-template-columns: 350px 1fr;
    /* Sidebar | Main Content */
    height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header h2 {
    margin: 0;
    color: var(--text-main);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 6px;
    margin-bottom: 32px;
    font-weight: 400;
    letter-spacing: 0.2px;
}

.toolbox h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-top: 24px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    font-weight: 600;
}

/* --- Tool Cards --- */
.tool-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 16px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.tool-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(0, 242, 255, 0.3);
}

.tool-card.active-card {
    border-color: var(--accent-primary);
    background: rgba(0, 242, 255, 0.05);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.15);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.9375rem;
}

.card-header span {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-body {
    margin-top: 10px;
    transition: opacity 0.3s;
}

.disabled-body {
    opacity: 0.3;
    pointer-events: none;
}

.info-text {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

/* --- Form Elements --- */
input[type="text"],
textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: 6px;
    margin-top: 6px;
    margin-bottom: 12px;
    box-sizing: border-box;
    font-family: 'Inter', monospace;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

input[type="text"]:focus,
textarea:focus {
    border-color: var(--accent-primary);
    outline: none;
    background: rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 0 3px rgba(0, 242, 255, 0.1);
}

label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
}

/* --- Toggle Switch --- */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2a2d3a;
    transition: .3s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* --- Action Buttons --- */
.control-group {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.action-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    color: white;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-family: 'Inter', sans-serif;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.action-btn:hover:not(:disabled)::before {
    width: 300px;
    height: 300px;
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
    box-shadow: 0 4px 12px rgba(0, 242, 255, 0.2);
}

.primary-btn:hover:not(:disabled) {
    box-shadow: 0 6px 16px rgba(0, 242, 255, 0.3);
    transform: translateY(-1px);
}

.primary-btn:disabled {
    background: #2a2d3a;
    cursor: not-allowed;
    opacity: 0.5;
    box-shadow: none;
}

.secondary-btn {
    background: #2a2d3a;
    border: 1px solid var(--border-color);
}

.secondary-btn:hover:not(:disabled) {
    background: #3a3d4a;
    border-color: var(--text-muted);
    transform: translateY(-1px);
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.status-text {
    margin-top: 12px;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* --- Main Stage --- */
.main-stage {
    display: flex;
    flex-direction: column;
    background: #000;
    position: relative;
}

.video-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

#video-stream {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    z-index: 1;
}

#canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    /* pointer-events: none;  <-- Removed to allow Konva interactivity */
}

#caption-overlay {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 22, 31, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px 25px;
    border-radius: 12px;
    color: var(--text-main);
    font-size: 1rem;
    text-align: center;
    max-width: 80%;
    z-index: 20;
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

#caption-overlay.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

#placeholder-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, #1a1d29 0%, #000 100%);
    z-index: 0;
}

.loader-content {
    text-align: center;
    color: var(--text-muted);
}

/* --- Log Panel --- */
.log-panel {
    height: 150px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.log-header {
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: bold;
}

.log-content {
    flex: 1;
    padding: 10px 20px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--accent-primary);
}

.status-indicator {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
}

.status-ready {
    background: #333;
    color: #aaa;
}

.status-live {
    background: rgba(0, 255, 157, 0.2);
    color: var(--success);
    border: 1px solid var(--success);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 242, 255, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(0, 242, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 242, 255, 0);
    }
}

.pulse-animation {
    animation: pulse 2s infinite;
}

input[type="file"] {
    display: none;
}