:root {
    --bg:        #0b0b0f;
    --surface:   #13131a;
    --surface-2: #1c1c27;
    --surface-3: #252535;
    --border:    rgba(255,255,255,0.07);
    --border-2:  rgba(255,255,255,0.12);
    --text:      #f1f1f3;
    --text-2:    #9090a8;
    --text-3:    #5a5a72;
    --accent:    #6366f1;
    --accent-2:  #818cf8;
    --green:     #22c55e;
    --red:       #ef4444;
    --yellow:    #f59e0b;
    --chat-w:    300px;
    --header-h:  54px;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ═══════════════════ APP SHELL ═══════════════════ */

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

/* ═══════════════════ HEADER ═══════════════════ */

.header {
    height: var(--header-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(239,68,68,0.15);
    border: 1px solid rgba(239,68,68,0.4);
    color: #f87171;
    padding: 3px 10px 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
}

.live-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
    animation: pulse-dot 1.8s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .5; transform: scale(.75); }
}

.device-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-2);
    letter-spacing: -.01em;
}

/* Header center stats */
.header-center {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    white-space: nowrap;
}
.stat-chip .chip-icon {
    font-size: 10px;
    opacity: .5;
}

.stat-sep {
    width: 1px; height: 16px;
    background: var(--border-2);
}

/* Header right */
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.viewer-chip {
    font-size: 12px;
    color: var(--text-3);
    min-width: 60px;
    text-align: right;
}

.motion-chip {
    background: rgba(239,68,68,.15);
    border: 1px solid rgba(239,68,68,.4);
    color: #f87171;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 6px;
    animation: flash-motion .9s infinite alternate;
}
@keyframes flash-motion { from{opacity:.6} to{opacity:1} }

.hdr-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    color: var(--text-2);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: all .15s;
    white-space: nowrap;
}
.hdr-btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }

.hdr-btn--icon {
    width: 34px; height: 34px;
    padding: 0;
    justify-content: center;
}
.hdr-btn.active {
    background: rgba(99,102,241,.15);
    border-color: rgba(99,102,241,.4);
    color: var(--accent-2);
}

/* ═══════════════════ MAIN ═══════════════════ */

.main {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

/* ═══════════════════ VIDEO SECTION ═══════════════════ */

.video-section {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #000;
}

.video-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

.video-wrap img, #snapCanvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.snap-badge {
    position: absolute;
    top: 10px; right: 10px;
    background: rgba(0,0,0,.6);
    border: 1px solid rgba(255,255,255,.15);
    color: rgba(255,255,255,.6);
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 6px;
    backdrop-filter: blur(8px);
    pointer-events: none;
    z-index: 5;
}

.err-banner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15,15,20,.9);
    border: 1px solid rgba(239,68,68,.35);
    color: #f87171;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 13.5px;
    font-weight: 500;
    backdrop-filter: blur(12px);
}

/* ═══════════════════ PAUSED OVERLAY ═══════════════════ */

.paused-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #000;
    color: rgba(255,255,255,.35);
    font-size: 14px;
    font-weight: 500;
    z-index: 99999;
}

/* ═══════════════════ CHAT PANEL ═══════════════════ */

.chat-panel {
    width: var(--chat-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--border);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--header-h);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
}
.chat-title svg { color: var(--text-3); }

.chat-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-2);
    cursor: pointer;
    transition: all .15s;
}
.chat-close:hover { background: var(--surface-3); color: var(--text); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-3);
    font-size: 13px;
    margin-top: 32px;
    text-align: center;
}

.chat-msg { display: flex; flex-direction: column; gap: 4px; }
.chat-msg .msg-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-2);
    letter-spacing: .01em;
}
.chat-msg .msg-text {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    border-top-left-radius: 3px;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    word-break: break-word;
}

.chat-footer {
    border-top: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.chat-name {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    color: var(--text);
    font-size: 12.5px;
    padding: 7px 11px;
    outline: none;
    font-family: 'Inter', sans-serif;
    transition: border-color .15s;
}
.chat-name:focus { border-color: rgba(99,102,241,.5); }
.chat-name::placeholder { color: var(--text-3); }

.chat-row {
    display: flex;
    gap: 6px;
}

.chat-text {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    padding: 8px 11px;
    outline: none;
    font-family: 'Inter', sans-serif;
    transition: border-color .15s;
}
.chat-text:focus { border-color: rgba(99,102,241,.5); }
.chat-text::placeholder { color: var(--text-3); }

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity .15s, transform .1s;
}
.send-btn:hover { opacity: .9; }
.send-btn:active { transform: scale(.95); }

/* ═══════════════════ TOAST ═══════════════════ */

.toast {
    position: fixed;
    bottom: 20px; left: 50%;
    transform: translateX(-50%) translateY(60px);
    background: var(--surface-3);
    border: 1px solid var(--border-2);
    color: var(--text);
    padding: 9px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    transition: transform .22s cubic-bezier(.34,1.56,.64,1);
    z-index: 999;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ═══════════════════ MOBILE ═══════════════════ */

@media (max-width: 640px) {
    .header-center { display: none; }
    .hdr-btn span { display: none; }
    .hdr-btn { padding: 0; width: 34px; height: 34px; justify-content: center; }

    .chat-panel {
        width: 100%;
        position: fixed;
        inset: 0;
        z-index: 200;
        border-left: none;
    }

}

@media (max-width: 900px) {
    .hdr-btn span { display: none; }
    .hdr-btn:not(.hdr-btn--icon) { padding: 0; width: 34px; height: 34px; justify-content: center; }
}
