/* =========================================
   1. 基础重置与暗色主题
   ========================================= */
:root {
    --bg-color: #000000;
    --panel-bg: #0F0F0F;
    --chat-bg: #000000;
    --text-main: #FFFFFF;
    --text-sub: #999999;
    --accent-color: #6B7FFF; /* 中性蓝紫色 */
    --accent-dim: rgba(107, 127, 255, 0.1);
    
    --ai-bubble-bg: #2A2A2A;
    --user-bubble-bg: #3A3A3A;
    --user-text-color: #FFFFFF;
    
    --border-color: #1a1a1a;
    --font-sans: "SF Pro Display", "Inter", -apple-system, sans-serif;
}

* { box-sizing: border-box; outline: none; }
body {
    margin: 0; padding: 0;
    background-color: var(--bg-color);
    font-family: var(--font-sans);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
}

/* =========================================
   2. 左侧面板：情绪感知 (Visual Hub)
   ========================================= */
.left-panel {
    width: 380px;
    background: #000;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 20;
}

/* 视频区域 */
.video-container {
    height: 320px;
    position: relative;
    background: #111;
    overflow: hidden;
    margin: 20px;
    border-radius: 24px;
    border: 1px solid #333;
}

/* 加载覆盖层 */
.loading-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
    z-index: 10;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #222;
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p {
    color: #888;
    font-size: 0.85rem;
    margin: 0;
}

video {
    width: 100%; height: 100%; object-fit: cover;
    transform: scaleX(-1); opacity: 0.8;
}
canvas#overlay {
    position: absolute; top: 0; left: 0; transform: scaleX(-1);
}

/* 视频状态条 */
.video-status-bar {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #999;
    background: rgba(0,0,0,0.5);
    padding: 8px 12px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}
.video-status-bar span {
    display: flex;
    align-items: center;
    gap: 5px;
}
.video-status-bar i {
    font-size: 0.8rem;
}

/* 仪表盘 (Dashboard) */
.dashboard-card {
    flex: 1;
    padding: 0 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 情绪主展示 */
.emotion-header-main {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}
.emoji-display { 
    font-size: 3rem; 
    line-height: 1;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}
.emotion-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.label { 
    font-size: 0.7rem; 
    color: var(--text-sub); 
    text-transform: uppercase; 
    letter-spacing: 1.5px; 
    font-weight: 500;
}
#currentEmotion { 
    font-size: 1.5rem; 
    font-weight: 700; 
    color: white; 
    margin: 0; 
}

/* 情绪能量条 (替代雷达图) */
.emotion-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
    padding: 12px;
    background: rgba(255,255,255,0.02);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
}
.bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
}
.bar-label {
    font-size: 0.8rem;
    color: #999;
    min-width: 60px;
}
.bar-track {
    flex: 1;
    height: 6px;
    background: #1a1a1a;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}
.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color) 0%, #A8B3FF 100%);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(107, 127, 255, 0.5);
}

/* 微表情洞察 */
.insight-box {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 15px;
    font-size: 0.9rem;
    color: #ccc;
    line-height: 1.5;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.insight-box i { color: var(--accent-color); margin-top: 3px; }

/* 捕捉按钮 (Apple AI 炫彩特效) */
.snap-btn-hero {
    width: 100%;
    background: linear-gradient(135deg, 
        #FF6B9D 0%, 
        #C239B3 20%, 
        #7301FA 40%, 
        #0E7AFE 60%, 
        #00C9FF 80%, 
        #92FE9D 100%
    );
    background-size: 200% 200%;
    color: white;
    border: none;
    padding: 0;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(115, 1, 250, 0.4);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    position: relative;
    margin-top: auto;
    margin-bottom: 30px;
    animation: gradient-shift 3s ease infinite;
}

@keyframes gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.snap-btn-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 24px;
    position: relative;
    z-index: 2;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.snap-btn-hero::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: linear-gradient(45deg, 
        transparent 30%, 
        rgba(255,255,255,0.3) 50%, 
        transparent 70%
    );
    opacity: 0;
    transform: rotate(45deg);
    transition: all 0.6s;
}

.snap-btn-hero:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 16px 48px rgba(115, 1, 250, 0.6),
                0 0 24px rgba(255, 107, 157, 0.4);
    animation: gradient-shift 1.5s ease infinite;
}

.snap-btn-hero:hover::before { 
    opacity: 1; 
    left: 100%;
}

.snap-btn-hero:active { 
    transform: translateY(-1px) scale(0.98); 
}

.snap-btn-hero i { 
    font-size: 1.3rem; 
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}


/* =========================================
   3. 右侧面板：对话 (Chat Room)
   ========================================= */
.right-panel {
    flex: 1;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    height: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    z-index: 10;
}
.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo-icon {
    width: 36px;
    height: 36px;
    background: transparent;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}
.logo-text h1 { 
    font-size: 1.1rem; 
    font-weight: 600; 
    letter-spacing: 0.5px; 
    margin: 0;
}
.logo-text p { 
    font-size: 0.7rem; 
    color: #555; 
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.icon-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid #333;
    border-radius: 10px;
    color: #999;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.icon-btn:hover {
    background: #222;
    border-color: #555;
    color: white;
}

/* 聊天容器 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 15%;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    padding-bottom: 120px;
}

/* 欢迎屏幕 */
.welcome-screen {
    margin: auto;
    text-align: center;
    max-width: 600px;
}
.welcome-title { 
    font-size: 2.2rem; 
    font-weight: 600; 
    margin-bottom: 15px; 
}
.welcome-desc { 
    color: var(--text-sub); 
    line-height: 1.5; 
    margin-bottom: 30px; 
    font-size: 0.95rem;
}
.suggestion-grid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.suggestion-pill {
    background: #1A1A1A; 
    border: 1px solid #333; 
    padding: 8px 16px;
    border-radius: 16px; 
    cursor: pointer; 
    transition: all 0.2s; 
    font-size: 0.85rem;
    color: #ccc;
}
.suggestion-pill:hover { 
    background: #2A2A2A; 
    border-color: #555; 
    color: white;
}

/* 消息样式 (Avatar + Bubble) - 紧凑版 */
.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
    margin-bottom: 12px;
}
@keyframes fadeIn { to { opacity: 1; transform: translateY(0); } }

.avatar {
    width: 32px; 
    height: 32px; 
    flex-shrink: 0;
    border-radius: 8px;
    display: flex; 
    justify-content: center; 
    align-items: center;
    font-size: 1.1rem;
}

/* xixi 头像 */
.message.ai .avatar { 
    background: #2A2A2A; 
    color: #999; 
    border: 1px solid #3a3a3a;
}

/* 用户头像 (使用 emoji，无背景) */
.message.user .avatar { 
    background: transparent;
    color: transparent;
    border: none;
    font-size: 1.5rem;
}

.message.user { 
    flex-direction: row-reverse; 
    justify-content: flex-start;
}

.bubble {
    max-width: 70%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
    position: relative;
    word-wrap: break-word;
}

.bubble p {
    margin: 0;
}

.bubble p + p {
    margin-top: 8px;
}

/* xixi 气泡 */
.message.ai .bubble {
    background: #2A2A2A;
    color: #E5E5E5;
    border-top-left-radius: 4px;
}

/* 用户气泡 */
.message.user .bubble {
    background: var(--user-bubble-bg);
    color: var(--user-text-color);
    border-top-right-radius: 4px;
}

/* Loading 态 (思考中) */
.loading-bubble {
    display: inline-flex; 
    gap: 6px; 
    padding: 12px 16px;
    background: #2A2A2A;
    border-radius: 16px; 
    border-top-left-radius: 4px;
}
.dot {
    width: 8px; 
    height: 8px; 
    background: var(--accent-color); 
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 
    0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; } 
    40% { transform: scale(1); opacity: 1; } 
}

/* TTS 播放动画 (声波) - 优化版 */
.tts-indicator {
    display: inline-flex; 
    align-items: center; 
    gap: 2px; 
    margin-left: 8px;
    padding: 3px 6px;
    background: rgba(107, 127, 255, 0.08);
    border-radius: 6px;
    vertical-align: middle;
    animation: fadeOut 0.3s ease-out forwards;
}

/* 淡出动画 */
@keyframes fadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.9); }
}

.bar {
    width: 3px; 
    background: var(--accent-color); 
    border-radius: 2px;
    animation: sound 0.8s infinite ease-in-out;
}
.bar:nth-child(1) { height: 8px; animation-delay: 0s; }
.bar:nth-child(2) { height: 12px; animation-delay: 0.1s; }
.bar:nth-child(3) { height: 16px; animation-delay: 0.2s; }
.bar:nth-child(4) { height: 10px; animation-delay: 0.3s; }
@keyframes sound { 
    0%, 100% { height: 6px; opacity: 0.4; } 
    50% { height: 18px; opacity: 1; } 
}


/* 输入区域 */
.input-area {
    position: absolute; bottom: 30px; left: 0; width: 100%;
    display: flex; justify-content: center;
    padding: 0 20px;
}

.input-wrapper {
    width: 100%; max-width: 800px;
    background: #1A1A1A;
    border: 1px solid #333;
    border-radius: 24px;
    padding: 8px 15px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    transition: border 0.2s;
}
.input-wrapper:focus-within { border-color: #555; }

#textInput {
    flex: 1; background: transparent; border: none; color: white; font-size: 1rem; padding: 8px 0;
}
#textInput::placeholder { color: #555; }

.mic-btn, .send-btn {
    background: transparent; border: none; color: #888; cursor: pointer;
    width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.mic-btn:hover { color: white; background: #333; }
.mic-btn.listening { color: #E74C3C; background: rgba(231, 76, 60, 0.1); }
.send-btn:hover { color: var(--accent-color); background: #333; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.input-status {
    text-align: center;
    font-size: 0.75rem;
    color: #666;
    margin-top: 10px;
}

/* 模态框修正 */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 100; justify-content: center; align-items: center;
}
.modal.active { display: flex; }
.modal-content {
    background: #1A1A1A; 
    border: 1px solid #333; 
    color: white;
    padding: 30px; 
    border-radius: 16px; 
    width: 450px;
    max-width: 90vw;
}
.modal-content h3 {
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
}
.tabs {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    border-bottom: 1px solid #333;
}
.tab-btn {
    background: transparent;
    border: none;
    color: #888;
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab-btn.active {
    color: white;
    border-bottom-color: var(--accent-color);
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}
.form-group {
    margin-bottom: 15px;
}
.form-group label { 
    color: #888; 
    display: block; 
    margin-bottom: 8px; 
    font-size: 0.85rem;
}
.form-group input { 
    background: #111; 
    border: 1px solid #333; 
    color: white; 
    width: 100%; 
    padding: 10px; 
    border-radius: 8px;
    transition: border 0.2s;
}
.form-group input:focus {
    outline: none;
    border-color: var(--accent-color);
}
.form-group small {
    color: #666;
    font-size: 0.75rem;
    display: block;
    margin-top: 5px;
}
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}
.modal-actions button {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}
.model-select {
    background: #1A1A1A; 
    color: white; 
    border: 1px solid #333; 
    padding: 8px 12px; 
    border-radius: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.model-select:hover {
    border-color: #555;
    background: #222;
}
.model-select:focus {
    outline: none;
    border-color: var(--accent-color);
}
.primary { 
    background: var(--accent-color); 
    color: black; 
    border: none; 
    font-weight: 600;
}
.primary:hover {
    background: #E5B583;
    transform: translateY(-1px);
}
.secondary { 
    background: #333; 
    color: white; 
    border: none; 
}
.secondary:hover {
    background: #444;
}

/* =========================================
   4. 响应式适配 (Mobile-First)
   ========================================= */

/* 平板及以下 (< 900px) */
@media (max-width: 900px) {
    body { 
        overflow-y: auto; 
        overflow-x: hidden; 
        height: auto; 
    }
    
    .app-wrapper { 
        flex-direction: column; 
        height: auto; 
        min-height: 100vh;
    }
    
    /* 左侧面板 - 顶部固定高度 */
    .left-panel { 
        width: 100%; 
        height: auto; 
        flex: none; 
        border-right: none; 
        border-bottom: 1px solid #222; 
        padding-bottom: 20px;
    }
    
    /* 视频容器优化 */
    .video-container {
        height: 280px;
        margin: 15px;
        border-radius: 16px;
    }
    
    /* 仪表盘间距调整 */
    .dashboard-card {
        padding: 0 15px;
        gap: 15px;
    }
    
    /* 情绪能量条紧凑显示 */
    .emotion-bars {
        padding: 10px;
        gap: 6px;
    }
    
    .bar-label {
        min-width: 50px;
        font-size: 0.75rem;
    }
    
    /* 按钮优化 */
    .snap-btn-hero {
        margin-bottom: 15px;
    }
    
    .snap-btn-inner {
        padding: 14px 20px;
        font-size: 0.95rem;
    }
    
    /* 右侧面板 - 占据剩余空间 */
    .right-panel { 
        flex: 1;
        min-height: 70vh;
        position: relative;
    }
    
    /* 聊天容器 - 减少左右padding */
    .chat-container {
        padding: 20px 5%;
        padding-bottom: 140px;
    }
    
    /* 欢迎屏幕 */
    .welcome-title {
        font-size: 1.8rem;
    }
    
    .welcome-desc {
        font-size: 0.9rem;
    }
    
    /* 消息气泡更宽 */
    .bubble {
        max-width: 85%;
        font-size: 0.9rem;
    }
    
    /* 输入区域 - 固定在底部 */
    .input-area { 
        position: sticky; 
        bottom: 0; 
        padding: 15px; 
        background: var(--bg-color);
        border-top: 1px solid #222;
    }
    
    .input-wrapper {
        max-width: 100%;
    }
    
    /* Header 优化 */
    .chat-header {
        height: 60px;
        padding: 0 15px;
    }
    
    .logo-text h1 {
        font-size: 1rem;
    }
    
    .logo-icon {
        width: 32px;
        height: 32px;
        font-size: 1.3rem;
    }
    
    /* 模态框 */
    .modal-content {
        width: 90vw;
        padding: 25px;
    }
}

/* 手机竖屏 (< 600px) */
@media (max-width: 600px) {
    /* 视频容器进一步缩小 */
    .video-container {
        height: 240px;
        margin: 10px;
        border-radius: 12px;
    }
    
    /* 视频状态条 */
    .video-status-bar {
        font-size: 0.65rem;
        padding: 6px 10px;
    }
    
    /* 仪表盘 */
    .dashboard-card {
        padding: 0 10px;
    }
    
    /* 情绪主展示 - 更紧凑 */
    .emotion-header-compact {
        gap: 10px;
    }
    
    .emoji-large {
        font-size: 2.5rem;
    }
    
    #currentEmotion {
        font-size: 1.3rem;
    }
    
    .label {
        font-size: 0.65rem;
    }
    
    /* 能量条 */
    .bar-label {
        min-width: 45px;
        font-size: 0.7rem;
    }
    
    .bar-track {
        height: 5px;
    }
    
    /* 洞察盒子 */
    .insight-box {
        padding: 12px;
        font-size: 0.85rem;
    }
    
    /* 按钮 */
    .snap-btn-inner {
        padding: 12px 18px;
        font-size: 0.9rem;
        gap: 8px;
    }
    
    .snap-btn-hero i {
        font-size: 1.1rem;
    }
    
    /* 聊天区域 */
    .chat-container {
        padding: 15px 10px;
        padding-bottom: 140px;
    }
    
    /* Header */
    .chat-header {
        height: 55px;
        padding: 0 10px;
    }
    
    .logo-text h1 {
        font-size: 0.95rem;
    }
    
    .logo-icon {
        width: 28px;
        height: 28px;
        font-size: 1.2rem;
    }
    
    .icon-btn {
        width: 32px;
        height: 32px;
    }
    
    .model-select {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    
    /* 欢迎屏幕 */
    .welcome-title {
        font-size: 1.5rem;
    }
    
    .welcome-desc {
        font-size: 0.85rem;
    }
    
    .suggestion-pill {
        font-size: 0.8rem;
        padding: 7px 14px;
    }
    
    /* 消息 */
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.95rem;
    }
    
    .message.user .avatar {
        font-size: 1.3rem;
    }
    
    .bubble {
        max-width: 90%;
        font-size: 0.85rem;
        padding: 8px 12px;
        border-radius: 12px;
    }
    
    .message {
        margin-bottom: 10px;
    }
    
    /* 输入区域 */
    .input-area {
        padding: 12px 10px;
    }
    
    .input-wrapper {
        padding: 6px 12px;
        border-radius: 20px;
    }
    
    #textInput {
        font-size: 0.9rem;
        padding: 6px 0;
    }
    
    .mic-btn, .send-btn {
        width: 32px;
        height: 32px;
    }
    
    /* 模态框 */
    .modal-content {
        padding: 20px;
    }
    
    .modal-content h3 {
        font-size: 1.1rem;
    }
    
    .tabs {
        margin: 15px 0;
    }
    
    .tab-btn {
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    
    .form-group input {
        padding: 8px;
        font-size: 0.9rem;
    }
}

/* 超小屏幕 (< 400px) */
@media (max-width: 400px) {
    .video-container {
        height: 200px;
        margin: 8px;
    }
    
    .chat-header {
        height: 50px;
    }
    
    .logo-text h1 {
        font-size: 0.9rem;
    }
    
    .header-actions {
        gap: 6px;
    }
    
    .model-select {
        font-size: 0.75rem;
        padding: 5px 8px;
    }
    
    .icon-btn {
        width: 30px;
        height: 30px;
    }
    
    .welcome-title {
        font-size: 1.3rem;
    }
    
    .bubble {
        font-size: 0.82rem;
    }
    
    #textInput {
        font-size: 0.85rem;
    }
}