:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2f3d;
    --text: #f5f5f7;
    --muted: #9aa3b2;
    --accent: #10a37f;
    --accent-dim: rgba(16, 163, 127, 0.15);
    --danger: #ef4444;
    --warning: #f59e0b;
    --speaking: #6366f1;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
}

.demo-page {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.demo-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(15, 17, 23, 0.95);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.demo-header a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.875rem;
}

.demo-header a:hover {
    color: var(--text);
}

.demo-title {
    font-size: 1rem;
    font-weight: 600;
}

.demo-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .demo-main {
        grid-template-columns: 1.1fr 0.9fr;
        align-items: start;
        padding: 24px;
    }
}

.video-panel,
.control-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

.video-wrap {
    position: relative;
    aspect-ratio: 4 / 3;
    background: #000;
}

#camera-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scaleX(-1);
}

.video-overlay {
    position: absolute;
    inset: auto 12px 12px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.vision-badge {
    font-size: 0.75rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    padding: 6px 10px;
    border-radius: 999px;
    backdrop-filter: blur(4px);
}

.status-bar {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
}

.status-dot.online { background: var(--accent); }
.status-dot.listening {
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
    animation: pulse 1.5s infinite;
}
.status-dot.processing { background: var(--warning); }
.status-dot.speaking { background: var(--speaking); }
.status-dot.error { background: var(--danger); }
.status-dot.connecting { background: var(--warning); animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

#status-text {
    font-size: 0.9rem;
    color: var(--text);
}

.subtitle-panel {
    padding: 12px;
    min-height: 200px;
    max-height: 340px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    display: flex;
    width: 100%;
}

.chat-msg.user { justify-content: flex-end; }
.chat-msg.ai { justify-content: flex-start; }
.chat-msg.system { justify-content: center; }

.chat-bubble {
    max-width: 88%;
    padding: 9px 12px;
    border-radius: 14px;
    line-height: 1.45;
    font-size: 0.88rem;
    word-break: break-word;
}

.chat-msg.user .chat-bubble {
    background: rgba(37, 99, 235, 0.85);
    color: #eff6ff;
    border-bottom-right-radius: 4px;
}

.chat-msg.ai .chat-bubble {
    background: rgba(16, 163, 127, 0.18);
    color: var(--text);
    border: 1px solid rgba(16, 163, 127, 0.25);
    border-bottom-left-radius: 4px;
}

.chat-msg.system .chat-bubble {
    max-width: 100%;
    padding: 4px 8px;
    background: transparent;
    color: var(--muted);
    font-size: 0.76rem;
    text-align: center;
}

.chat-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    opacity: 0.75;
    margin-bottom: 3px;
}

.mode-panel {
    margin: 0 12px 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
}

.mode-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mode-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    flex-shrink: 0;
}

.aec-badge {
    font-size: 0.68rem;
    color: var(--muted);
    flex-shrink: 0;
}

.aec-badge.ok { color: #6ee7b7; }
.aec-badge.warn { color: #fcd34d; }

.mode-switch {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.mode-option {
    min-height: 0;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 600;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.mode-option.active {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-dim);
}

.mode-option:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.mode-hint {
    margin: 6px 0 0;
    font-size: 0.72rem;
    line-height: 1.35;
    color: var(--muted);
}

.controls {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
    flex: 1;
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn:not(:disabled):active {
    transform: scale(0.98);
}

.error-box {
    margin: 0 16px 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fecaca;
    font-size: 0.875rem;
}

.hint {
    padding: 0 16px 16px;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.5;
}

#capture-canvas {
    display: none;
}
