/* ==================== 基础重置与全局样式 ==================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f6ef7;
    --primary-light: #7b93fa;
    --danger: #e74c3c;
    --bg: #0a0e1a;
    --bg-panel: rgba(20, 25, 50, 0.95);
    --text: #e8ecf4;
    --text-secondary: #8892a8;
    --radius: 12px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

#main-app {
    width: 100%;
    height: 100%;
}

/* ==================== 视频容器 ==================== */
#video-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
}

#video-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    z-index: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

#video-container video.active {
    opacity: 1;
    z-index: 2;
}

/* ==================== 波形图 ==================== */
#waveform-canvas {
    position: absolute;
    bottom: calc(14% + 270px);
    left: 50%;
    transform: translateX(-50%);
    width: 55%;
    height: 80px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    filter: drop-shadow(0 0 8px rgba(79, 110, 247, 0.3));
}

#waveform-canvas.visible {
    opacity: 1;
}

/* ==================== 对话气泡 ==================== */
#chat-bubbles {
    position: absolute;
    bottom: calc(18% + 270px);
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    max-width: 600px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.chat-bubble {
    padding: 12px 20px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.5;
    max-width: 90%;
    word-break: break-word;
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.chat-bubble.hidden {
    opacity: 0;
    pointer-events: none;
}

.bubble-user {
    align-self: flex-end;
    background: #4f6ef7;
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
.bubble-user.hidden {
    transform: translateX(30px);
}

.bubble-ai {
    align-self: flex-start;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
.bubble-ai.hidden {
    transform: translateX(-30px);
}

.bubble-ai.thinking-text {
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.75);
    font-style: italic;
}

.spinner {
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    color: rgba(255, 255, 255, 0.6);
}
.spinner-user {
    margin-right: 6px;
    margin-left: 0;
}

/* ==================== 状态指示器 ==================== */
#status-indicator {
    position: absolute;
    bottom: 490px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 20px;
    z-index: 10;
}

#status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    transition: background var(--transition);
}

#status-dot.listening {
    background: #facc15;
    animation: pulse 1s ease-in-out infinite;
}

#status-dot.thinking {
    background: #a78bfa;
    animation: pulse 0.8s ease-in-out infinite;
}

#status-dot.answering {
    background: var(--primary);
    animation: pulse 0.6s ease-in-out infinite;
}

#status-text {
    font-size: 14px;
    color: #fff;
}

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

/* ==================== 底部控制栏 ==================== */
#control-bar {
    position: absolute;
    bottom: 360px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    z-index: 20;
}

.control-btn {
    width: 60px;
    height: 60px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.control-btn:hover {
    background: rgba(0, 0, 0, 0.65);
    border-color: rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.control-btn:active {
    transform: scale(0.92);
}

.record-btn {
    width: 72px;
    height: 72px;
    background: var(--primary);
    box-shadow: 0 4px 20px rgba(79, 110, 247, 0.4);
}

.record-btn:hover {
    background: var(--primary-light);
    box-shadow: 0 6px 28px rgba(79, 110, 247, 0.6);
}

.record-btn.recording {
    background: var(--danger);
    box-shadow: 0 4px 20px rgba(231, 76, 60, 0.4);
    animation: record-pulse 1.5s ease-in-out infinite;
}

@keyframes record-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 4px 36px rgba(231, 76, 60, 0.7); }
}

/* ==================== 设置面板 ==================== */
#settings-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 85vw;
    height: 100%;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 30;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    transform: translateX(0);
    transition: transform var(--transition);
    display: flex;
    flex-direction: column;
}

#settings-panel.hidden {
    transform: translateX(100%);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.settings-body {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}

.setting-item span {
    font-size: 16px;
    color: var(--text);
}

.setting-item input[type="text"],
.setting-item input[type="number"] {
    width: 140px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: border var(--transition);
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
}

.setting-item input[type="number"]::-webkit-inner-spin-button,
.setting-item input[type="number"]::-webkit-outer-spin-button {
    opacity: 0.5;
    filter: invert(1);
}

.setting-item input:focus,
.setting-item textarea:focus {
    border-color: var(--primary);
}

.setting-item textarea {
    width: 180px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-size: 14px;
    outline: none;
    resize: both;
    font-family: inherit;
    min-height: 36px;
}

/* Toggle 开关 */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 26px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.save-btn {
    margin-top: auto;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.save-btn:hover {
    background: var(--primary-light);
}

/* ==================== Toast 软提示 ==================== */
.toast {
    position: fixed;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    background: rgba(0, 0, 0, 0.95);
    color: #ffffff;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.toast:not(.hidden) {
    opacity: 1;
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
    #subtitle-text {
        font-size: 16px;
        padding: 10px 20px;
    }

    .control-btn {
        width: 50px;
        height: 50px;
    }

    .record-btn {
        width: 64px;
        height: 64px;
    }

    #settings-panel {
        width: 100%;
        max-width: 100%;
    }
}

@media (min-width: 1920px) {
    #subtitle-text {
        font-size: 24px;
        padding: 16px 36px;
    }

    .control-btn {
        width: 64px;
        height: 64px;
    }

    .record-btn {
        width: 80px;
        height: 80px;
    }
}

/* ==================== 登录/选择页覆盖层 ==================== */
.overlay-page {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.overlay-page.hidden { display: none; }

.overlay-card {
    width: 360px;
    max-width: 90vw;
    padding: 40px 32px;
    background: var(--bg-panel);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    gap: 18px;
    align-items: center;
}
.overlay-card h2 {
    font-size: 22px;
    font-weight: 600;
    text-align: center;
}
.overlay-card .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
}
.overlay-card input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    background: rgba(255,255,255,0.05);
    color: #fff;
    font-size: 15px;
    outline: none;
    font-family: inherit;
    transition: border var(--transition);
}
.overlay-card input:focus {
    border-color: var(--primary);
}
.primary-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.primary-btn:hover { background: var(--primary-light); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.text-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
    font-family: inherit;
}
.text-btn:hover { color: #fff; }
.error-msg {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
}
.error-msg.hidden { display: none; }

/* 展厅列表 */
.hall-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 260px;
    overflow-y: auto;
}
.hall-item {
    padding: 14px 16px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.hall-item:hover { border-color: rgba(255,255,255,0.25); }
.hall-item.selected {
    border-color: var(--primary);
    background: rgba(79,110,247,0.12);
}
.hall-item .hall-name { font-size: 15px; font-weight: 500; }
.hall-item .hall-ext { font-size: 12px; color: var(--text-secondary); }
.hall-item select {
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.12);
    font-size: 13px;
    outline: none;
    font-family: inherit;
}

/* ==================== 设置密码验证 ==================== */
#settings-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
#settings-overlay.hidden { display: none; }
.settings-pwd-card {
    width: 320px;
    max-width: 90vw;
    padding: 32px 24px;
    background: var(--bg-panel);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    cursor: default;
}
.settings-pwd-card h3 {
    font-size: 18px;
    font-weight: 600;
}
.settings-pwd-card input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    background: rgba(255,255,255,0.05);
    color: #fff;
    font-size: 15px;
    outline: none;
    font-family: inherit;
    color-scheme: dark;
}
.settings-pwd-card input:focus { border-color: var(--primary); }

/* ==================== 右下角设置按钮 ==================== */
.settings-corner-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 25;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: rgba(255,255,255,0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition), transform var(--transition);
    padding: 0;
}
.settings-corner-btn:hover {
    color: rgba(255,255,255,0.55);
    transform: rotate(30deg);
}

/* hidden 通用 */
.hidden { display: none !important; }