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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1528 0%, #251d3a 50%, #1e1a2e 100%);
    color: #f0f0f5;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

#app {
    display: flex;
    width: 100%;
    max-width: 1100px;
    height: 80vh;
    max-height: 700px;
    background: rgba(35, 30, 55, 0.7);
    backdrop-filter: blur(24px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow:
        0 25px 60px -15px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Avatar Container */
#avatar-container {
    flex: 1;
    position: relative;
    background: linear-gradient(180deg, #383059 0%, #2d2647 100%);
    border-radius: 24px 0 0 24px;
    overflow: hidden;
}

#avatar-canvas {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 24px 0 0 24px;
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(56, 48, 89, 0.98) 0%, rgba(45, 38, 71, 0.98) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 10;
    border-radius: 24px 0 0 24px;
}

#loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #1a6a9e;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Chat Container */
#chat-container {
    width: 380px;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(45, 40, 70, 0.95) 0%, rgba(35, 30, 55, 0.98) 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
}

#chat-header {
    padding: 1.25rem 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

#chat-header h2 {
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    color: rgba(255, 255, 255, 0.9);
}

#connection-status {
    font-size: 0.65rem;
    padding: 0.35rem 0.85rem;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    transition: all 0.3s ease;
}

#connection-status.connected {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.1);
}

#connection-status.disconnected {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

#connection-status.connecting {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.25);
}

/* Chat Messages */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 82%;
    padding: 0.85rem 1.1rem;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 0.875rem;
    font-weight: 400;
    letter-spacing: 0.2px;
    animation: messageSlide 0.3s ease-out;
    position: relative;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background: linear-gradient(135deg, #0f4c75 0%, #1a6a9e 100%);
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(15, 76, 117, 0.3);
    color: #fff;
}

.message.npc {
    background: rgba(255, 255, 255, 0.08);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.92);
}

.message.system {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    text-align: center;
    align-self: center;
    padding: 0.5rem 1rem;
    border-radius: 100px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* Chat Input */
#chat-input-container {
    padding: 1.25rem 1.5rem;
    display: flex;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.15);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#text-input {
    flex: 1;
    padding: 0.85rem 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.25s ease;
    font-weight: 400;
}

#text-input:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(26, 106, 158, 0.5);
    box-shadow: 0 0 0 3px rgba(26, 106, 158, 0.15);
}

#text-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

#send-btn,
#mic-btn {
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #0f4c75 0%, #1a6a9e 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    box-shadow: 0 4px 12px rgba(15, 76, 117, 0.3);
    touch-action: none;
}

#send-btn svg,
#mic-btn svg {
    pointer-events: none;
}

#send-btn:hover,
#mic-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(15, 76, 117, 0.4);
}

#send-btn:active,
#mic-btn:active {
    transform: translateY(0) scale(0.98);
}

#mic-btn.recording {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* Mic Indicator */
#mic-indicator {
    padding: 0.6rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-size: 0.75rem;
    color: #f87171;
    font-weight: 500;
    letter-spacing: 0.5px;
}

#mic-indicator.hidden {
    display: none;
}

.mic-pulse {
    width: 8px;
    height: 8px;
    background: #f87171;
    border-radius: 50%;
    animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

/* Lip Sync Controls */
#lipsync-controls {
    padding: 0.85rem 1.5rem;
    background: rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
}

#lipsync-controls label {
    white-space: nowrap;
    font-weight: 500;
}

#speed-value {
    color: #1a6a9e;
    font-weight: 600;
    min-width: 36px;
}

#speed-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    outline: none;
    transition: background 0.2s;
}

#speed-slider:hover {
    background: rgba(255, 255, 255, 0.15);
}

#speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #0f4c75 0%, #1a6a9e 100%);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(15, 76, 117, 0.4);
}

#speed-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(15, 76, 117, 0.5);
}

#speed-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #0f4c75 0%, #1a6a9e 100%);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(15, 76, 117, 0.4);
}

/* Scrollbar */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 100px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(15, 76, 117, 0.4);
    border-radius: 100px;
    transition: background 0.2s;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(15, 76, 117, 0.6);
}

/* Responsive */
@media (max-width: 900px) {
    body {
        padding: 0.75rem;
    }

    #app {
        flex-direction: column;
        height: 95vh;
        max-height: none;
        border-radius: 24px;
    }

    #avatar-container {
        height: 45%;
        border-radius: 24px 24px 0 0;
    }

    #avatar-canvas {
        border-radius: 24px 24px 0 0;
    }

    #loading-overlay {
        border-radius: 24px 24px 0 0;
    }

    #chat-container {
        width: 100%;
        flex: 1;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.06);
    }

    #chat-messages {
        padding: 1rem;
    }

    #chat-input-container {
        padding: 1rem;
    }

    .message {
        max-width: 88%;
    }
}
