/* CSS Variables */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a26;
    --accent-primary: #7c3aed;
    --accent-secondary: #a78bfa;
    --accent-glow: rgba(124, 58, 237, 0.4);
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(124, 58, 237, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(167, 139, 250, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(124, 58, 237, 0.05) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

/* Avatar Container */
#avatar-container {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#avatar {
    width: 100%;
    height: 100%;
}

#avatar canvas {
    width: 100% !important;
    height: 100% !important;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    z-index: 10;
}

#loading.hidden {
    display: none;
}

/* Status Indicator */
#status-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}

#status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-secondary);
    padding: 10px 20px;
    border-radius: 100px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-lg);
}

#status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 12px var(--success);
    animation: pulse-glow 2s ease-in-out infinite;
}

#status-dot.listening {
    background: var(--accent-primary);
    box-shadow: 0 0 12px var(--accent-primary);
    animation: pulse-glow-fast 0.8s ease-in-out infinite;
}

#status-dot.thinking {
    background: var(--warning);
    box-shadow: 0 0 12px var(--warning);
    animation: pulse-glow 1s ease-in-out infinite;
}

#status-dot.speaking {
    background: var(--accent-secondary);
    box-shadow: 0 0 12px var(--accent-secondary);
    animation: pulse-glow-fast 0.5s ease-in-out infinite;
}

#status-dot.error {
    background: var(--danger);
    box-shadow: 0 0 12px var(--danger);
    animation: none;
}

#status-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

@keyframes pulse-glow-fast {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

/* Subtitles */
#subtitles {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(90vw, 700px);
    text-align: center;
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--text-primary);
    background: rgba(10, 10, 15, 0.85);
    padding: 16px 28px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
    z-index: 90;
}

#subtitles.visible {
    opacity: 1;
    visibility: visible;
}

/* Debug Sidebar (toggle with 'D' key) */
#debug-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 340px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    backdrop-filter: blur(12px);
}

#debug-sidebar.sidebar-visible {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.sidebar-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 4px 8px;
    border-radius: 4px;
}

.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.section-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

/* Status in Sidebar */
#debug-sidebar .status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 12px;
}

#debug-sidebar .status.disconnected {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

#debug-sidebar .status.connected {
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
}

#debug-sidebar .status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse-glow 2s ease-in-out infinite;
}

#debug-sidebar .status.disconnected .status-dot {
    background: var(--danger);
}

#debug-sidebar .status.connected .status-dot {
    background: var(--success);
}

/* Button Row */
.button-row {
    display: flex;
    gap: 8px;
}

#debug-sidebar button {
    flex: 1;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

#debug-sidebar button:hover:not(:disabled) {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

#debug-sidebar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#debug-sidebar button:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-small {
    flex: none !important;
    padding: 6px 12px !important;
    font-size: 0.7rem !important;
}

/* Event Log */
.event-log-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0;
}

.event-log {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 8px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.7rem;
    margin-bottom: 16px;
}

.event-log::-webkit-scrollbar {
    width: 6px;
}

.event-log::-webkit-scrollbar-track {
    background: transparent;
}

.event-log::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.event-log::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.log-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 2px;
    cursor: default;
}

.log-entry:hover {
    background: var(--bg-tertiary);
}

.log-entry.log-sent {
    border-left: 2px solid var(--accent-primary);
}

.log-entry.log-received {
    border-left: 2px solid var(--success);
}

.log-entry.log-info {
    border-left: 2px solid var(--text-muted);
}

.log-entry.log-error {
    border-left: 2px solid var(--danger);
}

.log-time {
    color: var(--text-muted);
    font-size: 0.65rem;
    min-width: 55px;
}

.log-arrow {
    font-weight: bold;
    width: 12px;
    text-align: center;
}

.log-entry.log-sent .log-arrow {
    color: var(--accent-primary);
}

.log-entry.log-received .log-arrow {
    color: var(--success);
}

.log-entry.log-info .log-arrow,
.log-entry.log-error .log-arrow {
    color: var(--text-muted);
}

.log-name {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* Expand indicator */
.log-expand {
    color: var(--text-muted);
    font-size: 0.6rem;
    transition: transform 0.2s ease;
    opacity: 0;
}

.log-entry.has-data {
    cursor: pointer;
}

.log-entry.has-data:hover .log-expand {
    opacity: 1;
}

.log-entry.expanded .log-expand {
    transform: rotate(90deg);
    opacity: 1;
}

/* Expanded JSON detail */
.log-detail {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-size: 0.65rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
    max-height: 200px;
    overflow-y: auto;
}

.log-entry.expanded {
    flex-wrap: wrap;
    background: var(--bg-secondary);
}

/* Legacy Controls (centered, for other layouts) */
.controls-centered {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 100;
}

.controls-centered button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.controls-centered button:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

.controls-centered button:active {
    transform: scale(0.95);
}

.controls-centered button svg {
    width: 24px;
    height: 24px;
}

#mic-button {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none !important;
}

#mic-button:hover {
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
    box-shadow: 0 0 30px var(--accent-glow);
}

#mic-button svg {
    width: 32px;
    height: 32px;
}

#mic-button.recording {
    animation: recording-pulse 1.5s ease-in-out infinite;
}

@keyframes recording-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { box-shadow: 0 0 0 20px transparent; }
}

/* Text Input */
#text-input-container {
    position: fixed;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(90vw, 500px);
    z-index: 100;
}

#text-input {
    flex: 1;
    padding: 14px 20px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 100px;
    outline: none;
    transition: all var(--transition-fast);
}

#text-input::placeholder {
    color: var(--text-muted);
}

#text-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#send-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--accent-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

#send-button:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

#send-button:active {
    transform: scale(0.95);
}

#send-button svg {
    width: 20px;
    height: 20px;
}

/* Settings Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 1000;
    opacity: 1;
    visibility: visible;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    width: min(90vw, 480px);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    margin-top: 28px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 14px 24px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--text-primary);
}

.btn-primary:hover {
    background: var(--accent-secondary);
}

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

.btn-secondary:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 640px) {
    #controls {
        bottom: 16px;
    }

    #text-input-container {
        bottom: 100px;
        width: calc(100vw - 32px);
    }

    #subtitles {
        bottom: 160px;
        font-size: 1rem;
        padding: 12px 20px;
    }

    .modal-content {
        padding: 24px;
        margin: 16px;
    }
}

