@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@500;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Unified Design Tokens (Pastel Zen Dark Default & Crisp Light) ── */
:root, [data-theme="oled"] {
    --bg: #15161a;
    --surface: #1b1c22;
    --card: #21222a;
    --border: #2e303d;
    --border-hover: #3e4152;
    --text: #e6e8ee;
    --text-muted: #8e93a6;
    --accent: #6ea390;
    --accent-hover: #7eb3a0;
    --accent-muted: rgba(110, 163, 144, 0.16);
    --wave-bar: #6ea390;
    --wave-osc: #cfd4e2;
    --live-dot: #6ea390;
    --err-dot: #ba6b78;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-head: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
    --bg: #ffffff;
    --surface: #f4f4f7;
    --card: #ffffff;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-muted: rgba(37, 99, 235, 0.1);
    --wave-bar: #2563eb;
    --wave-osc: #0f172a;
    --live-dot: #10b981;
    --err-dot: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* ── Container Layouts ── */
.app-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

/* ── Header Bar ── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.brand-title {
    font-family: var(--font-head);
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.01em;
}

.brand-subtitle {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Theme Toggle Button */
.btn-theme-toggle {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-theme-toggle:hover {
    border-color: var(--border-hover);
    color: var(--accent);
}

/* Live Status Badge */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
}

.live-indicator.active {
    color: var(--text);
    border-color: var(--live-dot);
}

.live-dot-pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--text-muted);
    transition: background-color 0.3s;
}

.live-indicator.active .live-dot-pulse {
    background-color: var(--live-dot);
}

/* ── Main Canvas & Spectrogram ── */
.visualizer-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 240px;
}

.visualizer-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

/* View Switcher Buttons */
.view-switch-group {
    display: inline-flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.btn-view-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.btn-view-toggle:hover {
    color: var(--text);
}

.btn-view-toggle.active {
    background: var(--card);
    color: var(--accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Media Container */
.media-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 520px;
    min-height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    overflow: hidden;
    background: #000000;
}

/* Stream Video */
.stream-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    margin: 0 auto;
    display: none;
    border-radius: 10px;
    background: #000000;
}

/* Mode 1: Spectrum only */
.media-container[data-view="spectrum"] .stream-video {
    display: none;
}
.media-container[data-view="spectrum"] .canvas-wrapper {
    display: flex;
}

/* Mode 2: Video only (Centered) */
.media-container[data-view="video"] .stream-video {
    display: block;
    margin: 0 auto;
}
.media-container[data-view="video"] .canvas-wrapper {
    display: none;
}

.canvas-wrapper {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
}

canvas.spectrum-canvas {
    width: 100%;
    flex: 1;
    min-height: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: block;
    box-sizing: border-box;
}

canvas.osc-canvas {
    width: 100%;
    height: 55px;
    flex-shrink: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: block;
    box-sizing: border-box;
}

/* ── Controls Toolbar ── */
.controls-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.btn-play-large {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #000000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.btn-play-large:hover {
    transform: scale(1.04);
    background: var(--accent-hover);
}

.btn-play-large.playing {
    background: var(--err-dot);
    color: #ffffff;
}

.btn-play-large.connecting {
    opacity: 0.85;
    animation: btnPulse 1s infinite alternate ease-in-out;
}

@keyframes btnPulse {
    from { transform: scale(1); filter: brightness(1); }
    to { transform: scale(0.94); filter: brightness(1.25); }
}

.btn-play-large svg {
    width: 22px;
    height: 22px;
}

.controls-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 180px;
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-text {
    color: var(--text-muted);
}

.btn-chat-badge {
    all: unset;
    box-sizing: border-box;
    background: var(--accent-muted);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    font-family: var(--font);
}

.btn-chat-badge:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.proto-selector {
    display: flex;
    gap: 4px;
    background: var(--bg);
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.proto-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.proto-btn.active {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
}

.volume-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.vol-slider {
    flex: 1;
    -webkit-appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    cursor: pointer;
}

.vol-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* ── Buttons & Inputs ── */
.btn-icon {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
    position: relative;
}

.btn-icon:hover {
    border-color: var(--border-hover);
}

.badge-counter {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent);
    color: #000;
    font-size: 0.6rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Chat Drawer ── */
.chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    transform: translateX(100%);
    width: 360px;
    max-width: 100vw;
    height: 100%;
    height: 100dvh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.5);
    box-sizing: border-box;
    overflow: hidden;
}

.chat-drawer.open {
    transform: translateX(0);
}

.chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.chat-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.btn-chat-back {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    font-family: var(--font);
    white-space: nowrap;
}

.btn-chat-back:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.btn-chat-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    font-family: var(--font);
    white-space: nowrap;
}

.btn-chat-close:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: var(--card);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg-item {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.4;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chat-msg-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-msg-user {
    font-weight: 600;
    color: var(--accent);
}

.chat-input-bar {
    padding: 12px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--surface);
    box-sizing: border-box;
}

.chat-username-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.chat-username-label {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    font-family: var(--font);
}

.chat-username-input {
    flex: 1;
    min-width: 0;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    width: 100%;
    align-items: center;
    box-sizing: border-box;
}

.input-field {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 0.82rem;
    outline: none;
    box-sizing: border-box;
}

.chat-input-bar > .input-field {
    width: 100%;
}

.chat-input-row .input-field {
    flex: 1;
    min-width: 0;
    width: 0;
}

.input-field:focus {
    border-color: var(--accent);
}

.btn-send {
    background: var(--accent);
    border: none;
    color: #000;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
    box-sizing: border-box;
    transition: opacity 0.2s;
}

.btn-send:active {
    opacity: 0.8;
}

/* ── Footer Quote ── */
footer.app-footer {
    text-align: center;
    padding: 12px;
    font-size: 0.68rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

@media (max-width: 600px) {
    .app-container {
        padding: 10px;
        gap: 12px;
    }
    .chat-drawer {
        width: 100vw;
        max-width: 100vw;
        border-left: none;
    }
    .status-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

/* ── PIN Code Auth Overlay ── */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 16, 20, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    animation: authFadeIn 0.3s ease-out;
}

@keyframes authFadeIn {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-icon {
    font-size: 2.2rem;
    margin-bottom: 8px;
}

.auth-title {
    font-family: var(--font-head);
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.01em;
}

.auth-subtitle {
    font-size: 0.82rem;
    color: var(--accent);
    margin-bottom: 16px;
    font-weight: 500;
}

.auth-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-input {
    text-align: center;
    font-size: 1.2rem;
    letter-spacing: 0.2em;
    font-family: var(--font-mono);
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
}

.auth-btn {
    padding: 12px 20px;
    font-size: 0.9rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.auth-btn:active {
    transform: scale(0.98);
}

.auth-error {
    margin-top: 14px;
    font-size: 0.8rem;
    color: var(--err-dot);
    background: rgba(186, 107, 120, 0.12);
    border: 1px solid rgba(186, 107, 120, 0.3);
    padding: 8px 12px;
    border-radius: 8px;
}

