/* ══════════════════════════════════════════════════════════════
   Voice Chat — Dark Theme Styles
   ══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #000000;
    --bg-card: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --text-dim: #636366;
    --accent: #10a37f;
    --accent-hover: #1a7f64;
    --btn-bg: #ffffff;
    --btn-text: #000000;
    --danger: #ff3b30;
    --orb-color-1: #4a9eff;
    --orb-color-2: #6eb5ff;
    --orb-color-3: #93caff;
    --orb-color-4: #b8dfff;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Screen System ────────────────────────────────────────── */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    padding: 20px;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

.screen-content {
    max-width: 400px;
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 60px 0 40px;
}

.screen-content.center {
    align-items: center;
    justify-content: center;
}

/* ── Screen 1: Welcome ────────────────────────────────────── */
.welcome-title {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 36px;
}

.features {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.feature {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.feature-icon {
    font-size: 20px;
    width: 32px;
    flex-shrink: 0;
    text-align: center;
    margin-top: 2px;
}

.feature h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.feature p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.disclaimer {
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
    margin: 24px 0;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: 999px;
    background: var(--btn-bg);
    color: var(--btn-text);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-top: auto;
}

.btn-primary:hover {
    background: #e5e5e5;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    cursor: wait;
    background: #c8c8c8;
    color: #555;
}

/* ── Bootstrap Lazy Loading Overlay ──────────────────────── */
.bootstrap-loading {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.72);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1200;
}

.bootstrap-loading.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.bootstrap-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 18px 24px;
    border-radius: 14px;
    background: rgba(10, 10, 10, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.16);
    min-width: 220px;
}

.bootstrap-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(255, 255, 255, 0.24);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: bootstrapSpin 0.9s linear infinite;
}

.bootstrap-loading-text {
    font-size: 14px;
    color: var(--text-primary);
    text-align: center;
}

@keyframes bootstrapSpin {
    to { transform: rotate(360deg); }
}

/* ── Screen 2: Voice Selection ────────────────────────────── */
.ready-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 48px;
}

.voice-avatar {
    margin-bottom: 24px;
}

.small-orb {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, var(--orb-color-1), var(--orb-color-2), var(--orb-color-3));
    position: relative;
    animation: floatOrb 4s ease-in-out infinite;
}

.orb-inner {
    position: absolute;
    inset: 10%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.3), transparent 60%);
}

@keyframes floatOrb {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.voice-name {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
    text-align: center;
}

.voice-desc {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    text-align: center;
}

.voice-slider {
    display: flex;
    align-items: center;
    width: 100%;
    margin-bottom: 14px;
    gap: 10px;
}

.voice-nav {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.voice-track-wrap {
    flex: 1;
    overflow: hidden;
    border-radius: 14px;
    touch-action: pan-y;
}

.voice-track {
    display: flex;
    gap: 10px;
    transition: transform 0.25s ease;
}

.voice-card {
    min-width: 100%;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.04);
    padding: 12px 14px;
}

.voice-card-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.voice-card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.voice-personality-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 18px;
}

.voice-personality-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.voice-personality-select {
    flex: 1;
    max-width: 190px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 13px;
}

.voice-personality-row.hidden {
    display: none;
}

.provider-picker {
    display: flex;
    gap: 10px;
    margin-bottom: 22px;
}

.provider-btn {
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.provider-btn.active {
    background: var(--text-primary);
    color: var(--btn-text);
    border-color: var(--text-primary);
}

.voice-dots {
    display: flex;
    gap: 8px;
    margin-bottom: 28px;
}

.mic-permission-hint {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.45;
    margin: -20px 0 14px;
    min-height: 40px;
    transition: color 0.2s ease;
}

.mic-permission-hint.warn {
    color: #ffb340;
}

.mic-permission-hint.ok {
    color: var(--accent);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: background 0.3s;
}

.dot.active {
    background: var(--text-primary);
}

/* ── Screen 3: Active Chat ────────────────────────────────── */
.chat-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.status-text {
    position: absolute;
    top: 50px;
    font-size: 16px;
    color: var(--text-secondary);
    text-align: center;
    min-height: 24px;
    transition: opacity 0.3s;
}

.model-name {
    position: absolute;
    top: 76px;
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
    min-height: 16px;
}

.session-id {
    position: absolute;
    top: 92px;
    font-size: 10px;
    color: var(--text-dim);
    text-align: center;
    opacity: 0.85;
    min-height: 14px;
    max-width: calc(100% - 32px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.interrupt-mode-indicator {
    position: absolute;
    top: 118px;
    font-size: 11px;
    color: var(--text-dim);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 999px;
    padding: 4px 10px;
    line-height: 1;
    opacity: 1;
    transform: scale(1);
    transition: color 0.18s ease, border-color 0.18s ease, background-color 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}

.interrupt-mode-indicator.listening {
    color: var(--text-secondary);
    border-color: rgba(255, 255, 255, 0.24);
    background: rgba(255, 255, 255, 0.06);
    opacity: 1;
    transform: scale(1);
}

.interrupt-mode-indicator.active {
    color: var(--accent);
    border-color: rgba(16, 163, 127, 0.45);
    background: rgba(16, 163, 127, 0.14);
    opacity: 1;
    transform: scale(1.04);
}

.timeline-log {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 146px;
    height: 110px;
    min-height: 70px;
    max-height: 45vh;
    overflow-y: auto;
    resize: vertical;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(26, 26, 26, 0.88);
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.log-sync-dot {
    position: absolute;
    right: 16px;
    bottom: 130px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    border: 1px solid rgba(255, 255, 255, 0.45);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.log-sync-dot.sending {
    background: var(--accent);
    transform: scale(1.15);
}

.timeline-log .log-row {
    display: block;
    white-space: normal;
    word-break: break-word;
}

.timeline-log .log-time {
    color: var(--text-dim);
    margin-right: 8px;
}

.timeline-log .log-elapsed {
    color: var(--accent);
}

.timeline-log .log-count {
    color: var(--text-dim);
}

.timeline-log::-webkit-scrollbar {
    width: 0;
    height: 0;
    background: transparent;
}

/* ── Voice Orb (4 circles) ────────────────────────────────── */
.orb-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.voice-orb {
    display: flex;
    gap: 12px;
    align-items: center;
}

.orb-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--text-primary);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ── Orb Animation States ─────────────────────────────────── */

/* Idle — static */
.voice-orb.idle .orb-circle {
    animation: none;
    transform: scale(1);
    opacity: 0.6;
}

/* Listening — gentle pulse */
.voice-orb.listening .c1 { animation: listenPulse 1.2s ease-in-out infinite 0s; }
.voice-orb.listening .c2 { animation: listenPulse 1.2s ease-in-out infinite 0.15s; }
.voice-orb.listening .c3 { animation: listenPulse 1.2s ease-in-out infinite 0.3s; }
.voice-orb.listening .c4 { animation: listenPulse 1.2s ease-in-out infinite 0.45s; }

@keyframes listenPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.25); opacity: 1; }
}

/* Thinking — rotating bounce */
.voice-orb.thinking .c1 { animation: thinkBounce 0.8s ease-in-out infinite 0s; }
.voice-orb.thinking .c2 { animation: thinkBounce 0.8s ease-in-out infinite 0.1s; }
.voice-orb.thinking .c3 { animation: thinkBounce 0.8s ease-in-out infinite 0.2s; }
.voice-orb.thinking .c4 { animation: thinkBounce 0.8s ease-in-out infinite 0.3s; }

@keyframes thinkBounce {
    0%, 100% { transform: translateY(0) scale(0.85); opacity: 0.5; }
    50% { transform: translateY(-20px) scale(1.1); opacity: 1; }
}

/* Speaking — expanding wave */
.voice-orb.speaking .c1 { animation: speakWave 0.9s ease-in-out infinite 0s; }
.voice-orb.speaking .c2 { animation: speakWave 0.9s ease-in-out infinite 0.12s; }
.voice-orb.speaking .c3 { animation: speakWave 0.9s ease-in-out infinite 0.24s; }
.voice-orb.speaking .c4 { animation: speakWave 0.9s ease-in-out infinite 0.36s; }

@keyframes speakWave {
    0%, 100% { transform: scaleY(1) scaleX(1); opacity: 0.8; }
    25% { transform: scaleY(1.5) scaleX(0.9); opacity: 1; }
    50% { transform: scaleY(0.7) scaleX(1.15); opacity: 0.9; }
    75% { transform: scaleY(1.3) scaleX(0.95); opacity: 1; }
}

/* ── Transcript ───────────────────────────────────────────── */
.transcript {
    position: absolute;
    top: 146px;
    left: 20px;
    right: 20px;
    text-align: center;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary);
    max-height: 52px;
    overflow: hidden;
    transition: opacity 0.3s;
}

/* ── TTS Buffer Visualization ─────────────────────────────── */
.tts-buffer-panel {
    position: absolute;
    top: 208px;
    left: 16px;
    right: 16px;
    max-height: 140px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 8px 10px;
    display: none; /* shown via JS when active */
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.tts-buffer-panel.active {
    display: flex;
}

.tts-buffer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tts-buffer-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
    font-weight: 600;
}

.tts-buffer-stats {
    font-size: 10px;
    color: var(--text-dim);
    font-family: monospace;
}

.tts-buffer-incoming {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.35);
    font-style: italic;
    min-height: 0;
    word-break: break-word;
    line-height: 1.4;
    transition: opacity 0.2s;
}

.tts-buffer-incoming:empty {
    display: none;
}

.tts-buffer-segments {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 72px;
    overflow-y: auto;
    scrollbar-width: none;
}

.tts-buf-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.4;
    word-break: break-word;
    transition: background 0.3s, border-color 0.3s, opacity 0.4s;
    border: 1px solid transparent;
}

.tts-buf-item .buf-indicator {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background 0.3s, box-shadow 0.3s;
}

.tts-buf-item .buf-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tts-buf-item .buf-status {
    flex-shrink: 0;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    opacity: 0.7;
}

/* Buffer item states */
.tts-buf-item.waiting {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

.tts-buf-item.waiting .buf-indicator {
    background: rgba(255, 255, 255, 0.3);
}

.tts-buf-item.waiting .buf-status {
    color: var(--text-dim);
}

.tts-buf-item.speaking {
    background: rgba(99, 179, 237, 0.12);
    border-color: rgba(99, 179, 237, 0.35);
    color: var(--text-primary);
}

.tts-buf-item.speaking .buf-indicator {
    background: #63b3ed;
    box-shadow: 0 0 6px rgba(99, 179, 237, 0.6);
    animation: bufPulse 1s ease-in-out infinite;
}

.tts-buf-item.speaking .buf-status {
    color: #63b3ed;
}

.tts-buf-item.done {
    background: rgba(72, 187, 120, 0.08);
    border-color: rgba(72, 187, 120, 0.2);
    color: var(--text-dim);
    opacity: 0.6;
}

.tts-buf-item.done .buf-indicator {
    background: #48bb78;
}

.tts-buf-item.done .buf-status {
    color: #48bb78;
}

@keyframes bufPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.7; }
}

/* ── Chat Controls ────────────────────────────────────────── */
.chat-controls {
    position: absolute;
    bottom: 40px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.btn-mic {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: var(--text-primary);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.3s;
}

.btn-mic:hover {
    background: #e0e0e0;
}

.btn-mic:active {
    transform: scale(0.92);
}

.btn-mic.active {
    background: var(--danger);
    color: white;
    box-shadow: 0 0 0 6px rgba(255, 59, 48, 0.25);
}

.btn-close {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-close:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.4);
}

/* ── Mic Permission Toast ─────────────────────────────────── */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
    .welcome-title { font-size: 26px; }
    .orb-circle { width: 40px; height: 40px; }
    .voice-orb { gap: 8px; }
}

@media (min-width: 768px) {
    .orb-circle { width: 56px; height: 56px; }
    .voice-orb { gap: 16px; }
}
