/* ============================================
   Digital Persona — 全局样式
   ============================================ */

:root {
    /* 主色调 — 深灰色系 */
    --primary: #E67E22;
    --primary-light: #F39C12;
    --primary-dark: #D35400;
    --accent: #E67E22;
    --accent-light: #F5B041;

    /* 背景 */
    --bg-dark: #1A1A1A;
    --bg-card: #2D2D2D;
    --bg-input: #333333;
    --bg-message-user: #4A4A4A;
    --bg-message-ai: #2D2D2D;

    /* 文字 */
    --text-primary: #C8C8C8;
    --text-secondary: #A0A0A0;
    --text-dim: #707070;

    /* 边框 & 阴影 */
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --glow: 0 0 40px rgba(230, 126, 34, 0.15);

    /* 尺寸 */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --top-bar-height: 56px;
    --input-area-height: 64px;
    --avatar-height: 280px;

    /* 动画 */
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: #000;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   视频背景层
   ============================================ */
.video-bg {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}
.bg-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.8s ease;  /* 默认 0.8s 用于淡出 */
    z-index: 1;
}
.bg-video.idle-video {
    opacity: 1;   /* idle 永远显示，永远不淡出 */
    z-index: 1;
}
.bg-video.active {
    opacity: 1;
}
/* v60: reaction/sustain 叠在 idle 上面一层，淡入 0.3s */
#videoReaction,
#videoSustain {
    z-index: 2;
    transition: opacity 0.3s ease;
}

/* ============================================
   App 容器
   ============================================ */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

/* ============================================
   顶部导航栏
   ============================================ */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--top-bar-height);
    padding: 0 12px;
    padding-top: var(--safe-top);
    background: transparent;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: none;
    z-index: 100;
    flex-shrink: 0;
}

.top-bar-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.persona-name {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6B7280;
}
.status-dot.online {
    background: #34D399;
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
    animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 12px;
    transition: var(--transition);
}
.btn-icon:hover {
    background: rgba(108, 99, 255, 0.1);
    color: var(--primary-light);
}
.btn-icon:active {
    transform: scale(0.92);
}

/* BGM 浮动按钮 — 与设置按钮同款样式，定位在其正下方 */
.btn-bgm {
    position: fixed;
    top: calc(var(--top-bar-height) + var(--safe-top, 0px) + 4px);
    left: 12px;
    width: 40px !important;
    height: 40px !important;
    flex: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 12px;
    transition: var(--transition);
    z-index: 50;
    box-sizing: border-box;
    overflow: visible;
}
.btn-bgm:hover {
    background: rgba(108, 99, 255, 0.1);
    color: var(--primary-light);
}
.btn-bgm:active {
    transform: scale(0.92);
}
.btn-bgm.bgm-off {
    color: rgba(255, 255, 255, 0.35);
}
.btn-bgm.bgm-off::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 22px;
    height: 2px;
    background: #ff6464;
    transform: translate(-50%, -50%) rotate(-45deg);
    border-radius: 2px;
    pointer-events: none;
}

/* BGM 音量按钮 — 与垃圾桶按钮同款，定位在其正下方 */
.btn-bgm-vol {
    position: fixed;
    top: calc(var(--top-bar-height) + var(--safe-top, 0px) + 4px);
    right: 12px;
    width: 40px !important;
    height: 40px !important;
    flex: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 12px;
    transition: var(--transition);
    z-index: 50;
    box-sizing: border-box;
}
.btn-bgm-vol:hover {
    background: rgba(108, 99, 255, 0.1);
    color: var(--primary-light);
}
.btn-bgm-vol:active {
    transform: scale(0.92);
}

/* BGM 音量滑块弹出面板 */
.bgm-vol-panel {
    position: fixed;
    top: calc(var(--top-bar-height) + var(--safe-top, 0px) + 50px);
    right: 12px;
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(20, 20, 20, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 60;
    animation: fadeIn 0.18s ease;
}
.bgm-vol-panel.visible {
    display: flex;
}
.bgm-vol-panel input[type="range"] {
    width: 140px;
    accent-color: var(--primary-light, #6c63ff);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    height: 4px;
    border-radius: 2px;
    outline: none;
}
.bgm-vol-panel input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.bgm-vol-panel input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.bgm-vol-value {
    color: #fff;
    font-size: 12px;
    min-width: 24px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   数字人形象区域
   ============================================ */
.avatar-stage {
    position: relative;
    width: 100%;
    height: var(--avatar-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center bottom, rgba(108, 99, 255, 0.08) 0%, transparent 70%);
    flex-shrink: 0;
    overflow: hidden;
}

#avatarCanvas {
    width: 260px;
    height: 260px;
    position: relative;
    z-index: 2;
}

.avatar-glow {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 60px;
    background: radial-gradient(ellipse, rgba(108, 99, 255, 0.25) 0%, transparent 70%);
    filter: blur(15px);
    z-index: 1;
}

/* 数字人说话气泡 */
.avatar-speech-bubble {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 56, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px 16px;
    max-width: 85%;
    z-index: 10;
    animation: fadeInUp 0.3s ease;
}
.avatar-speech-bubble span {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================
   聊天消息区域
   ============================================ */
.chat-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0; /* 关键：让 flex 子元素可以缩小，内部滚动才能生效 */
    margin-top: 62%;  /* 上面留空透出视频，避免遮挡角色形象 */
}

.chat-messages {
    height: 100%;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}
/* 让消息从底部开始（内容少时贴底，多时可滚动） */
.chat-messages::before {
    content: '';
    flex: 1;
}

/* 滚动条 */
.chat-messages::-webkit-scrollbar {
    width: 3px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(150, 150, 150, 0.4);
    border-radius: 3px;
}

/* 消息通用样式 */
/* 时间分隔戳（仿微信） */
.message-timestamp {
    text-align: center;
    font-size: 12px;
    color: var(--text-dim);
    padding: 12px 0 6px;
    user-select: none;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 88%;
    animation: messageIn 0.35s ease;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* AI 消息 — 左侧 */
.message.ai-message {
    align-self: flex-start;
}
.message.ai-message .message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3D3D3D, #E67E22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}
/* 有自定义头像图片时去掉渐变底色 */
.message.ai-message .message-avatar:has(img) {
    background: none;
}
.message-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* AI 消息气泡容器 */
.message-bubble {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.message.ai-message .message-content {
    background: rgba(30, 30, 30, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 4px 18px 18px 18px;
    padding: 12px 16px;
    color: #C8C8C8;
}

/* 播放语音按钮 */
/* 消息时间戳 */
.msg-time {
    font-size: 11px;
    color: #707070;
    margin-left: 8px;
    line-height: 24px;
}

/* Emoji / 贴纸面板 */
.emoji-panel {
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px 16px 0 0;
    padding: 8px;
    max-height: 220px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.emoji-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.emoji-tab {
    flex: 1;
    padding: 6px 0;
    font-size: 13px;
    color: #888;
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.emoji-tab.active {
    color: #D35400;
    border-bottom-color: #D35400;
}
.emoji-content {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    overflow-y: auto;
    max-height: 160px;
    padding: 4px;
}
.emoji-item {
    font-size: 24px;
    text-align: center;
    padding: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.emoji-item:hover,
.emoji-item:active {
    background: rgba(255,255,255,0.1);
}
.sticker-content {
    overflow-y: auto;
    max-height: 160px;
    padding: 4px;
}
.sticker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.sticker-item {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    object-fit: cover;
    transition: transform 0.15s;
}
.sticker-item:active {
    transform: scale(0.9);
}
.sticker-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    padding: 8px;
    border: 1px dashed rgba(255,255,255,0.2);
    border-radius: 8px;
    color: #888;
    font-size: 13px;
    cursor: pointer;
}
.btn-emoji {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}
/* 贴纸消息气泡 */
.message-sticker img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
}
/* AI 回复中的内联贴纸 */
.ai-sticker-inline {
    display: block;
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    margin: 4px 0;
}

/* 播放按钮 + 时间戳 行容器 */
.bubble-footer {
    display: flex;
    align-items: center;
}

/* 音色选择面板 */
.voice-options {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}
.voice-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 12px;
    background: rgba(50, 50, 50, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s;
}
.voice-card.selected {
    border-color: #D35400;
    background: rgba(211, 84, 0, 0.12);
}
.voice-name {
    font-size: 14px;
    color: #eee;
    font-weight: 500;
}
.btn-voice-preview {
    font-size: 12px;
    padding: 6px 16px;
    border-radius: 14px;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #ccc;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}
.btn-voice-preview:hover,
.btn-voice-preview:active {
    background: #D35400;
    color: white;
}

.btn-play-tts {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(230, 126, 34, 0.1);
    border: 1px solid rgba(230, 126, 34, 0.2);
    border-radius: 12px;
    color: var(--primary-light);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
    align-self: flex-start;
    opacity: 0.7;
}
.btn-play-tts:hover {
    opacity: 1;
    background: rgba(230, 126, 34, 0.18);
    border-color: var(--primary);
}
.btn-play-tts:active {
    transform: scale(0.93);
}
.btn-play-tts.playing {
    background: rgba(230, 126, 34, 0.15);
    border-color: rgba(230, 126, 34, 0.3);
    color: var(--accent);
    opacity: 1;
    animation: pulse-play 1.5s ease infinite;
}
@keyframes pulse-play {
    0%, 100% { box-shadow: 0 0 0 0 rgba(230, 126, 34, 0.2); }
    50% { box-shadow: 0 0 0 4px rgba(230, 126, 34, 0); }
}

/* 用户消息 — 右侧 */
.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.message.user-message .message-content {
    background: rgba(60, 60, 60, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 18px 4px 18px 18px;
    padding: 12px 16px;
    color: #D0D0D0;
}

/* 系统消息 */
.message.system-message {
    align-self: center;
    max-width: 95%;
}
.message.system-message .message-content {
    background: rgba(108, 99, 255, 0.08);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 18px;
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
}

.message-content p {
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
}
/* 动作/表情描述文字 — 暗橙色 */
.action-desc {
    color: #D35400;
    font-size: 14px;
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 10px;
    height: 9px;
    border-radius: 0;
    background: none;
    position: relative;
    animation: typingBounce 1.2s ease infinite;
}
.typing-indicator span::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 10px;
    height: 9px;
    background: #D35400;
    clip-path: path('M5 1.5C3.5 0 0 0.5 0 3.5c0 2 2.5 4 5 6 2.5-2 5-4 5-6C10 0.5 6.5 0 5 1.5z');
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* 语音消息标记 */
.voice-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
}
.voice-tag svg {
    width: 12px;
    height: 12px;
}

/* ============================================
   底部输入区域
   ============================================ */
.input-area {
    flex-shrink: 0;
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-bottom));
    background: transparent;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: none;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(50, 50, 50, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 6px 6px 6px 18px;
    transition: border-color var(--transition);
}
.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 6px 0;
}
#messageInput::placeholder {
    color: var(--text-dim);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.btn-attach {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    background: none;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-right: -4px;
}
.btn-attach:hover {
    color: var(--primary-light);
    background: rgba(108, 99, 255, 0.1);
}
.btn-attach:active {
    transform: scale(0.9);
}

/* 附件预览 */
.attachment-preview {
    padding: 6px 12px 0;
}
.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 10px;
}
.attachment-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
}
.attachment-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attachment-remove {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: var(--transition);
}
.attachment-remove:hover {
    background: rgba(239, 68, 68, 0.3);
}

.btn-voice, .btn-send {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.btn-voice {
    background: none;
    color: var(--text-secondary);
}
.btn-voice:hover {
    color: var(--accent);
    background: rgba(255, 107, 157, 0.1);
}
.btn-voice:active {
    transform: scale(0.9);
}
.btn-voice.recording {
    color: #EF4444;
    background: rgba(239, 68, 68, 0.15);
    animation: pulse-record 1s ease infinite;
}

@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.btn-send {
    background: var(--primary);
    color: white;
}
.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.btn-send:not(:disabled):hover {
    background: var(--primary-light);
    transform: scale(1.05);
}
.btn-send:not(:disabled):active {
    transform: scale(0.92);
}

/* 语音录制状态 */
.voice-recording {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 0;
}

.voice-waves {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 30px;
}
.voice-waves span {
    width: 4px;
    border-radius: 4px;
    background: var(--accent);
    animation: voiceWave 0.8s ease infinite;
}
.voice-waves span:nth-child(1) { height: 12px; animation-delay: 0s; }
.voice-waves span:nth-child(2) { height: 20px; animation-delay: 0.1s; }
.voice-waves span:nth-child(3) { height: 28px; animation-delay: 0.2s; }
.voice-waves span:nth-child(4) { height: 20px; animation-delay: 0.3s; }
.voice-waves span:nth-child(5) { height: 12px; animation-delay: 0.4s; }

@keyframes voiceWave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

.voice-timer {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.btn-voice-stop {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.15);
    border: 2px solid #EF4444;
    border-radius: 50%;
    color: #EF4444;
    cursor: pointer;
    transition: var(--transition);
}
.btn-voice-stop:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* iOS 风格 spinner — 12 道 spoke 依次渐隐旋转 */
.ios-spinner {
    position: relative;
    width: 28px;
    height: 28px;
    display: none;
    flex-shrink: 0;
}
.ios-spinner > div {
    position: absolute;
    left: 50%;
    top: 0;
    width: 2px;
    height: 7px;
    margin-left: -1px;
    background: #ffffff;
    border-radius: 1px;
    transform-origin: center 14px;
    animation: iosSpinnerFade 1s linear infinite;
    opacity: 0.15;
}
.ios-spinner > div:nth-child(1)  { transform: rotate(0deg);   animation-delay: -1.0000s; }
.ios-spinner > div:nth-child(2)  { transform: rotate(30deg);  animation-delay: -0.9167s; }
.ios-spinner > div:nth-child(3)  { transform: rotate(60deg);  animation-delay: -0.8333s; }
.ios-spinner > div:nth-child(4)  { transform: rotate(90deg);  animation-delay: -0.7500s; }
.ios-spinner > div:nth-child(5)  { transform: rotate(120deg); animation-delay: -0.6667s; }
.ios-spinner > div:nth-child(6)  { transform: rotate(150deg); animation-delay: -0.5833s; }
.ios-spinner > div:nth-child(7)  { transform: rotate(180deg); animation-delay: -0.5000s; }
.ios-spinner > div:nth-child(8)  { transform: rotate(210deg); animation-delay: -0.4167s; }
.ios-spinner > div:nth-child(9)  { transform: rotate(240deg); animation-delay: -0.3333s; }
.ios-spinner > div:nth-child(10) { transform: rotate(270deg); animation-delay: -0.2500s; }
.ios-spinner > div:nth-child(11) { transform: rotate(300deg); animation-delay: -0.1667s; }
.ios-spinner > div:nth-child(12) { transform: rotate(330deg); animation-delay: -0.0833s; }
@keyframes iosSpinnerFade {
    0%   { opacity: 1; }
    100% { opacity: 0.15; }
}

.voice-recognizing-label {
    display: none;
    color: var(--text-secondary, #888);
    font-size: 14px;
}

/* 识别中状态：显示 spinner + label，隐藏波形/计时器/停止按钮 */
.voice-recording.recognizing .voice-waves,
.voice-recording.recognizing .voice-timer,
.voice-recording.recognizing .btn-voice-stop {
    display: none !important;
}
.voice-recording.recognizing .ios-spinner {
    display: inline-block !important;
}
.voice-recording.recognizing .voice-recognizing-label {
    display: inline-block !important;
}

/* ============================================
   设置面板
   ============================================ */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.settings-panel {
    width: 100%;
    max-width: 480px;
    height: 85vh;
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px 24px 0 0;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.settings-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.settings-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.setting-group {
    margin-bottom: 24px;
}
.setting-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.setting-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.setting-toggle {
    width: 44px;
    height: 24px;
    appearance: none;
    -webkit-appearance: none;
    background: #555;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}
.setting-toggle:checked {
    background: var(--primary);
}
.setting-toggle::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}
.setting-toggle:checked::before {
    transform: translateX(20px);
}

/* 服务商选择标签 */
.provider-tabs {
    display: flex;
    gap: 8px;
}
.provider-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: 14px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.provider-tab:hover {
    border-color: rgba(108, 99, 255, 0.3);
    background: rgba(108, 99, 255, 0.05);
}
.provider-tab.active {
    border-color: var(--primary);
    background: rgba(108, 99, 255, 0.1);
    color: var(--primary-light);
}
.provider-icon {
    font-size: 20px;
    line-height: 1;
}

.setting-input-row {
    display: flex;
    gap: 8px;
}

.setting-input, .setting-select, .setting-textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.setting-input:focus, .setting-select:focus, .setting-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

.setting-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.setting-textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

.setting-hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 6px;
    line-height: 1.4;
}

.setting-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-input);
    outline: none;
    margin-top: 4px;
}
.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid var(--bg-card);
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.3);
}

.btn-toggle-eye {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition);
}
.btn-toggle-eye:hover {
    border-color: var(--primary);
    color: var(--primary-light);
}

.btn-save {
    width: 100%;
    padding: 14px;
    background: var(--bg-message-user);
    border: none;
    border-radius: 14px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
}
.btn-save:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}
.btn-save:active {
    transform: translateY(0) scale(0.98);
}

/* ============================================
   上传区域
   ============================================ */
.upload-area {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: 16px;
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}
.upload-area:hover {
    border-color: rgba(108, 99, 255, 0.4);
    background: rgba(108, 99, 255, 0.03);
}

.upload-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 24px 16px;
    color: var(--text-dim);
    font-size: 14px;
}
.upload-trigger svg {
    opacity: 0.5;
}
.upload-hint-text {
    font-size: 11px;
    color: var(--text-dim);
    opacity: 0.7;
}

/* 形象预览 */
.upload-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}
.upload-preview img {
    max-width: 100%;
    max-height: 160px;
    border-radius: 12px;
    object-fit: contain;
}
.upload-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.8);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}
.upload-remove:hover {
    background: #EF4444;
    transform: scale(1.1);
}

/* 音色预览 */
.voice-preview {
    justify-content: space-between;
    padding: 16px;
}
.voice-preview-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-size: 14px;
}
.voice-preview-info svg {
    color: var(--accent);
    flex-shrink: 0;
}
.voice-preview-info span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}
.btn-play-sample {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(108, 99, 255, 0.15);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--primary-light);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}
.btn-play-sample:hover {
    background: rgba(108, 99, 255, 0.25);
}
.btn-play-sample.playing {
    background: rgba(255, 107, 157, 0.2);
    color: var(--accent);
}

/* 拖拽上传高亮 */
.upload-area.drag-over {
    border-color: var(--primary) !important;
    background: rgba(108, 99, 255, 0.08) !important;
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}
.upload-area.drag-over .upload-trigger span:first-of-type {
    color: var(--primary-light);
}

/* ============================================
   头像裁切弹窗
   ============================================ */
.crop-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.crop-panel {
    width: 340px;
    max-width: 92vw;
    background: var(--bg-card);
    border-radius: 20px;
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.crop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.crop-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.crop-workspace {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 16px auto;
    border-radius: 16px;
    overflow: hidden;
    background: #111;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.crop-workspace:active {
    cursor: grabbing;
}

#cropCanvas {
    width: 300px;
    height: 300px;
    display: block;
}

.crop-circle-guide {
    position: absolute;
    top: 50%; left: 50%;
    width: 220px; height: 220px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    z-index: 2;
}

.crop-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px 12px;
}
.crop-label {
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.crop-controls .setting-slider {
    flex: 1;
}

.crop-actions {
    display: flex;
    gap: 10px;
    padding: 0 20px 18px;
}
.btn-crop-cancel, .btn-crop-confirm {
    flex: 1;
    padding: 11px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.btn-crop-cancel {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-crop-cancel:hover {
    background: rgba(108, 99, 255, 0.08);
}
.btn-crop-confirm {
    background: var(--bg-message-user);
    color: white;
}
.btn-crop-confirm:hover {
    opacity: 0.9;
}

/* ============================================
   Toast 提示
   ============================================ */
.toast {
    position: fixed;
    top: calc(var(--safe-top) + 70px);
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 24px;
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    z-index: 300;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.success {
    border-color: rgba(52, 211, 153, 0.3);
}
.toast.error {
    border-color: rgba(239, 68, 68, 0.3);
}

/* ============================================
   数字人说话中动画
   ============================================ */
.avatar-stage.speaking #avatarCanvas {
    animation: avatarBreathe 0.6s ease infinite;
}

@keyframes avatarBreathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.015); }
}

/* ============================================
   响应式
   ============================================ */
@media (max-height: 600px) {
    :root {
        --avatar-height: 180px;
    }
}

@media (min-width: 481px) {
    .app-container {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

/* ============================================
   v19: 长期记忆候选卡片（v52 触发后弹出）
   白色半透明 + 背景模糊（毛玻璃风）
   ============================================ */
.longterm-card {
    margin: 12px 16px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    color: rgba(255, 255, 255, 0.95);
    animation: longterm-card-in 0.25s ease-out;
}

@keyframes longterm-card-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.longterm-card-header {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 8px;
}

.longterm-card-rule {
    font-size: 14px;
    line-height: 1.5;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    border-left: 3px solid #D35400;
    color: rgba(255, 255, 255, 0.95);
    word-break: break-word;
}

.longterm-card-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.longterm-btn {
    padding: 6px 16px;
    font-size: 13px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    font-family: inherit;
}

.longterm-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.longterm-btn:active {
    transform: scale(0.96);
}

.longterm-btn-save {
    background: rgba(211, 84, 0, 0.85);
    border-color: rgba(211, 84, 0, 0.9);
    color: #fff;
}

.longterm-btn-save:hover {
    background: rgba(211, 84, 0, 1);
}

/* ============================================
   v20: 启动加载占位（v55 — 一个小爱正在赶来）
   ============================================ */
.startup-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px 40px;
    width: 100%;
    animation: startup-fade-in 0.3s ease-out;
}

@keyframes startup-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.startup-loading .startup-hearts {
    /* 复用 .typing-indicator 的爱心 + 弹跳，仅放大间距更醒目 */
    gap: 8px;
}

.startup-loading-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.65);
    letter-spacing: 0.5px;
    user-select: none;
}

