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

:root {
    --bg: #0b0e14;
    --surface: #131720;
    --surface-2: #1a1f2e;
    --surface-3: #232a3b;
    --border: #2a3042;
    --text: #e8eaed;
    --text-dim: #8b92a5;
    --accent: #4f8cff;
    --accent-glow: rgba(79, 140, 255, 0.25);
    --danger: #ff4f6d;
    --success: #34d399;
    --warning: #fbbf24;
    --orange: #f97316;
    --radius: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

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

/* ── Header ── */
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1.05rem; }
.logo small { color: var(--accent); font-weight: 400; font-size: 0.72rem; margin-left: 4px; }
.logo-icon {
    width: 34px; height: 34px; background: linear-gradient(135deg, var(--accent), #7c3aed);
    border-radius: 9px; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem; color: white;
}
.header-right { display: flex; align-items: center; gap: 14px; }
.connection-status { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-dim); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); transition: background 0.3s; }
.status-dot.connected { background: var(--success); }
.status-dot.connecting { background: var(--warning); animation: pulse-dot 1s infinite; }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── Main ── */
.main-content { display: flex; flex: 1; overflow: hidden; }

/* ── Avatar Section ── */
.avatar-section {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 16px; gap: 14px; min-width: 0;
}
.avatar-container {
    position: relative; width: 100%; max-width: 640px; aspect-ratio: 16/9;
    background: var(--surface); border-radius: var(--radius); overflow: hidden;
    border: 1px solid var(--border); box-shadow: 0 0 40px rgba(0,0,0,0.4);
}
.avatar-container.fullscreen {
    position: fixed; inset: 0; max-width: none; width: 100%; height: 100%;
    aspect-ratio: auto; z-index: 1000; border-radius: 0; border: none;
}
.avatar-placeholder {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 16px; color: var(--text-dim);
}
.pulse-ring {
    position: absolute; width: 120px; height: 120px; border-radius: 50%;
    border: 2px solid var(--accent); opacity: 0.15; animation: pulse-ring 2.5s ease-out infinite;
}
@keyframes pulse-ring { 0%{transform:scale(0.8);opacity:0.3} 100%{transform:scale(1.4);opacity:0} }
.avatar-placeholder p { font-size: 0.85rem; text-align: center; }
#videoPlayer { width: 100%; height: 100%; object-fit: cover; }
.avatar-overlay { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; }
.speaking-indicator {
    display: flex; gap: 3px; align-items: flex-end; height: 24px; padding: 4px 12px;
    background: rgba(0,0,0,0.6); border-radius: 20px; backdrop-filter: blur(8px);
}
.speaking-indicator span { width: 3px; background: var(--accent); border-radius: 2px; animation: speak-bar 0.8s ease-in-out infinite; }
.speaking-indicator span:nth-child(1){height:8px;animation-delay:0s}
.speaking-indicator span:nth-child(2){height:14px;animation-delay:.1s}
.speaking-indicator span:nth-child(3){height:18px;animation-delay:.2s}
.speaking-indicator span:nth-child(4){height:12px;animation-delay:.3s}
.speaking-indicator span:nth-child(5){height:6px;animation-delay:.4s}
@keyframes speak-bar { 0%,100%{transform:scaleY(0.4)} 50%{transform:scaleY(1)} }

/* ── Live transcript overlay ── */
.live-transcript {
    position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.7); color: var(--text-dim); padding: 6px 16px;
    border-radius: 20px; font-size: 0.78rem; max-width: 80%; text-align: center;
    backdrop-filter: blur(8px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Controls ── */
.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; }
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border: none; border-radius: var(--radius); font-family: var(--font);
    font-size: 0.8rem; font-weight: 500; cursor: pointer; transition: all 0.2s; color: white;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--accent); box-shadow: 0 2px 12px var(--accent-glow); }
.btn-primary:hover:not(:disabled) { background: #3d7ae8; transform: translateY(-1px); }
.btn-mic {
    width: 44px; height: 44px; padding: 0; justify-content: center;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 50%;
}
.btn-mic:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.btn-mic.active { background: var(--danger); border-color: var(--danger); animation: pulse-mic 1.5s infinite; }
@keyframes pulse-mic { 0%,100%{box-shadow:0 0 0 0 rgba(255,79,109,0.4)} 50%{box-shadow:0 0 0 10px rgba(255,79,109,0)} }
.btn-danger { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: white; }
.btn-icon {
    width: 36px; height: 36px; padding: 0; justify-content: center; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 8px; color: var(--text-dim);
}
.btn-icon:hover:not(:disabled) { background: var(--surface-3); color: var(--text); border-color: var(--accent); }
.btn-icon.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ── Extra controls row ── */
.extra-controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.extra-controls select {
    padding: 6px 10px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-family: var(--font); font-size: 0.75rem; cursor: pointer;
}
.extra-controls select:focus { border-color: var(--accent); outline: none; }
.bg-picker {
    display: flex; gap: 4px; align-items: center;
}
.bg-swatch {
    width: 22px; height: 22px; border-radius: 6px; border: 2px solid transparent;
    cursor: pointer; transition: border-color 0.2s;
}
.bg-swatch:hover, .bg-swatch.active { border-color: var(--accent); }

/* ── Chat Section ── */
.chat-section {
    width: 400px; 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: 12px 16px; border-bottom: 1px solid var(--border);
}
.chat-header h3 { font-size: 0.85rem; font-weight: 600; }
.chat-header-actions { display: flex; gap: 6px; }
.btn-clear, .btn-share-chat {
    background: none; border: none; color: var(--text-dim); cursor: pointer;
    padding: 4px; border-radius: 6px; transition: all 0.2s; display: flex; align-items: center;
}
.btn-clear:hover { color: var(--danger); background: rgba(255,79,109,0.1); }
.btn-share-chat:hover { color: var(--accent); background: var(--accent-glow); }

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

.message {
    max-width: 92%; padding: 10px 14px; border-radius: 14px;
    font-size: 0.82rem; line-height: 1.5; animation: msg-in 0.25s ease-out;
}
@keyframes msg-in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
.system-message { align-self: center; max-width: 100%; background: var(--surface-2); color: var(--text-dim); font-size: 0.78rem; text-align: center; border-radius: 10px; }
.user-message { align-self: flex-end; background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.assistant-message { align-self: flex-start; background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }

/* ── Confidence badge ── */
.confidence-badge {
    display: inline-block; font-size: 0.65rem; padding: 2px 8px; border-radius: 10px;
    margin-top: 6px; font-weight: 500;
}
.confidence-high { background: rgba(52,211,153,0.15); color: var(--success); }
.confidence-medium { background: rgba(251,191,36,0.15); color: var(--warning); }
.confidence-low { background: rgba(255,79,109,0.15); color: var(--danger); }

/* ── Smart link button ── */
.smart-link {
    display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
    padding: 6px 14px; background: var(--accent); color: white; border: none;
    border-radius: 8px; font-size: 0.75rem; font-family: var(--font); cursor: pointer;
    transition: all 0.2s; text-decoration: none;
}
.smart-link:hover { background: #3d7ae8; transform: translateY(-1px); }
.smart-link svg { flex-shrink: 0; }

/* ── Info card ── */
.info-card {
    margin-top: 8px; padding: 10px 14px; background: var(--surface-3); border: 1px solid var(--border);
    border-radius: 10px; font-size: 0.78rem;
}
.info-card-title { font-weight: 600; margin-bottom: 6px; color: var(--accent); font-size: 0.8rem; }
.info-card ul { list-style: none; padding: 0; }
.info-card li { padding: 3px 0; color: var(--text); position: relative; padding-left: 14px; }
.info-card li::before { content: "›"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }

/* ── Suggestions ── */
.suggestions {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; animation: msg-in 0.3s ease-out;
}
.suggestion-btn {
    padding: 6px 12px; background: transparent; border: 1px solid var(--border);
    border-radius: 20px; color: var(--text-dim); font-size: 0.72rem; font-family: var(--font);
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.suggestion-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

/* ── Listening indicator ── */
.listening-indicator {
    display: flex; align-items: center; gap: 8px; padding: 6px 0; color: var(--accent); font-size: 0.75rem;
}
.listening-dots { display: flex; gap: 3px; }
.listening-dots span {
    width: 5px; height: 5px; background: var(--accent); border-radius: 50%;
    animation: listen-bounce 1.2s ease-in-out infinite;
}
.listening-dots span:nth-child(2){animation-delay:.2s}
.listening-dots span:nth-child(3){animation-delay:.4s}
@keyframes listen-bounce { 0%,80%,100%{transform:scale(0.6);opacity:0.4} 40%{transform:scale(1);opacity:1} }

/* ── Chat input ── */
.chat-input-area { padding: 10px 14px; border-top: 1px solid var(--border); }
#chatForm { display: flex; gap: 8px; }
#textInput {
    flex: 1; padding: 9px 12px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-family: var(--font);
    font-size: 0.82rem; outline: none; transition: border-color 0.2s;
}
#textInput:focus { border-color: var(--accent); }
#textInput::placeholder { color: var(--text-dim); }
.btn-send {
    width: 38px; height: 38px; border: none; border-radius: var(--radius); background: var(--accent);
    color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.btn-send:hover:not(:disabled) { background: #3d7ae8; }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Share modal ── */
.share-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 2000;
    display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px);
}
.share-modal-content {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 24px; width: 380px; max-width: 90vw;
}
.share-modal h3 { font-size: 1rem; margin-bottom: 16px; }
.share-options { display: flex; flex-direction: column; gap: 10px; }
.share-option {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 10px; cursor: pointer; transition: all 0.2s;
    color: var(--text); text-decoration: none; font-size: 0.85rem;
}
.share-option:hover { border-color: var(--accent); background: var(--surface-3); }
.share-close {
    margin-top: 16px; width: 100%; padding: 10px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 10px; color: var(--text-dim); font-family: var(--font); font-size: 0.85rem; cursor: pointer;
}
.share-close:hover { background: var(--surface-3); }

/* ── Responsive ── */
@media (max-width: 900px) {
    .main-content { flex-direction: column; }
    .chat-section { width: 100%; height: 45%; border-left: none; border-top: 1px solid var(--border); }
    .avatar-section { padding: 10px; }
    .avatar-container { max-width: 100%; }
    .extra-controls { display: none; }
}
@media (max-width: 500px) {
    .app-header { padding: 8px 12px; }
    .controls { gap: 6px; }
    .btn { padding: 6px 12px; font-size: 0.75rem; }
    .chat-section { height: 50%; }
}
