* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --bg-dark: #020617;
    --bg-card: rgba(15, 23, 42, 0.8);
    --bg-input: rgba(30, 41, 59, 0.6);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --border-color: rgba(59, 130, 246, 0.2);
    --shadow: 0 8px 32px rgba(59, 130, 246, 0.15);
    --glow: 0 0 20px rgba(59, 130, 246, 0.3);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    gap: 20px;
    padding: 20px;
}

/* Avatar Section */
.avatar-section {
    flex: 6;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow);
    order: 2; /* Avatar bên phải */
}

#avatar-container {
    flex: 1;
    min-height: 400px;
    position: relative;
    background:
        radial-gradient(ellipse at 50% 100%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
        linear-gradient(to bottom, #020617 0%, #0f172a 50%, #1e293b 100%);
    overflow: hidden;
}

/* 3D Room walls */
#avatar-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 40%;
    background:
        /* Back wall with subtle grid */
        linear-gradient(90deg, rgba(59, 130, 246, 0.08) 1px, transparent 1px),
        linear-gradient(rgba(59, 130, 246, 0.08) 1px, transparent 1px),
        /* Wall gradient */
        linear-gradient(to bottom, #020617 0%, #0f172a 100%);
    background-size: 80px 80px, 80px 80px, 100% 100%;
    pointer-events: none;
    z-index: 0;
}

/* 3D Grid floor */
#avatar-container::after {
    content: '';
    position: absolute;
    left: -50%;
    right: -50%;
    bottom: 0;
    height: 40%;
    background:
        /* Grid lines */
        linear-gradient(90deg, rgba(59, 130, 246, 0.25) 1px, transparent 1px),
        linear-gradient(rgba(59, 130, 246, 0.25) 1px, transparent 1px),
        /* Floor base color */
        linear-gradient(to bottom, #1e293b, #1e3a5f);
    background-size: 50px 50px, 50px 50px, 100% 100%;
    transform: perspective(400px) rotateX(75deg);
    transform-origin: center top;
    pointer-events: none;
    z-index: 0;
}

#avatar-container canvas {
    width: 100% !important;
    height: 100% !important;
    position: relative;
    z-index: 1;
}

.zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
}

.btn-zoom {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: rgba(59, 130, 246, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.btn-zoom:hover {
    background: rgba(59, 130, 246, 0.4);
    border-color: rgba(59, 130, 246, 0.6);
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-zoom:active {
    transform: scale(0.95);
}

.avatar-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--bg-input);
    border-top: 1px solid var(--border-color);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger-color);
    transition: background 0.3s;
}

.status-dot.connected {
    background: var(--secondary-color);
    animation: pulse 2s infinite;
}

.status-dot.speaking {
    background: var(--primary-color);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.avatar-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--bg-input);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.avatar-selector label {
    color: var(--text-secondary);
    font-size: 13px;
}

.avatar-selector select {
    flex: 1;
    min-width: 100px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

/* Chat Section */
.chat-section {
    flex: 4;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow);
    order: 1; /* Chat bên trái */
}

.chat-header {
    padding: 24px;
    background: linear-gradient(135deg, var(--primary-color), #0ea5e9, #06b6d4);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { transform: translate(-30%, -30%); }
    50% { transform: translate(30%, 30%); }
}

.chat-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-header p {
    font-size: 14px;
    opacity: 0.9;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: var(--primary-color);
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-input);
    border-bottom-left-radius: 4px;
}

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.message p {
    line-height: 1.5;
    word-wrap: break-word;
}

.message .timestamp {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
    text-align: right;
}

.message.assistant .timestamp {
    text-align: left;
}

/* Streaming message with typing cursor */
.message.streaming .streaming-text::after {
    content: '▋';
    animation: blink 0.7s infinite;
    margin-left: 2px;
    color: var(--primary-color);
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-input);
    border-radius: 16px;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Input Area */
.input-area {
    padding: 20px;
    background: var(--bg-input);
    border-top: 1px solid var(--border-color);
}

.text-input-container {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

#text-input {
    flex: 1;
    padding: 14px 18px;
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: all 0.3s ease;
}

#text-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
    background: rgba(30, 41, 59, 0.6);
}

#text-input::placeholder {
    color: var(--text-secondary);
}

.voice-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-send {
    background: linear-gradient(135deg, var(--primary-color), #0ea5e9);
    color: white;
    padding: 14px;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
    transition: all 0.3s ease;
}

.btn-send:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-hover), #0284c7);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    transform: translateY(-2px);
}

.btn-connect {
    background: linear-gradient(135deg, var(--secondary-color), #059669);
    color: white;
    padding: 12px 16px;
    border-radius: 14px;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
    transition: all 0.3s ease;
}

.btn-connect:hover:not(:disabled) {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
    transform: translateY(-2px);
}

.btn-connect:disabled {
    opacity: 0.7;
    cursor: wait;
}

.btn-connect.connected {
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-connect.connected:hover:not(:disabled) {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

.btn-connect svg.spin {
    animation: spin 1s linear infinite;
}

.btn-live-small {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
    transition: all 0.3s ease;
}

.btn-live-small:hover:not(:disabled) {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
    transform: translateY(-2px);
}

.btn-live-small.active {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
    animation: pulse-glow 1.5s infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 4px 25px rgba(239, 68, 68, 0.7); }
}

.btn-live-small.active:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

/* Settings Panel */
.settings-panel {
    padding: 10px 20px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.settings-panel details {
    cursor: pointer;
}

.settings-panel summary {
    color: var(--text-secondary);
    font-size: 13px;
    padding: 5px 0;
}

.settings-content {
    display: flex;
    gap: 20px;
    padding: 15px 0 5px;
    flex-wrap: wrap;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-item label {
    color: var(--text-secondary);
    font-size: 13px;
}

.setting-item select {
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 26, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 1000;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        flex-direction: column;
    }

    .avatar-section {
        flex: 0 0 300px;
    }

    #avatar-container {
        min-height: 300px;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 0;
        gap: 0;
        flex-direction: column;
        height: calc(100vh - 90px);
    }

    /* Avatar chiếm full màn hình */
    .avatar-section {
        flex: 1;
        order: 1;
        border-radius: 0;
        border: none;
        height: 100%;
    }

    #avatar-container {
        min-height: 100%;
        height: 100%;
    }

    /* Ẩn avatar selector và status trên mobile */
    .avatar-status,
    .avatar-selector {
        display: none !important;
    }

    /* Ẩn hoàn toàn chat section */
    .chat-section {
        display: none !important;
    }
}

/* Mobile controls - fixed bottom bar */
@media (max-width: 640px) {
    .mobile-controls {
        display: flex !important;
    }
}

.mobile-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 20px;
    z-index: 1000;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.mobile-controls .btn-connect {
    flex: 1;
    max-width: 200px;
    padding: 16px 24px;
    font-size: 16px;
    border-radius: 16px;
}

.mobile-controls .btn-live-small {
    width: 60px;
    height: 60px;
    border-radius: 16px;
}

.mobile-controls .btn-live-small svg {
    width: 28px;
    height: 28px;
}
