:root {
    --primary-color: #ffffff;
    --primary-hover: #f8f9fa;
    --secondary-color: #f1f3f4;
    --success-color: #f0f9ff;
    --danger-color: #fef2f2;
    --warning-color: #fffbeb;
    --info-color: #f0f9ff;
    --light-color: #ffffff;
    --cream-color: #ffffff;
    --milk-color: #fafafa;
    --ivory-color: #ffffff;
    --pearl-color: #f8f9fa;
    --dark-color: #374151;
    --background-color: #ffffff;
    --text-color: #1f2937;
    --text-light: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --soft-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #ffffff;
    color: var(--text-color);
    line-height: 1.6;
    font-weight: 400;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

.header {
    background: #ffffff;
    color: var(--text-color);
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--soft-shadow);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    position: relative;
}

/* 有背景时，头部使用半透明效果 */
body.has-chat-background .header {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(229, 231, 235, 0.6);
}

.header h1 {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-color);
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

.main-container {
    flex: 1;
    display: flex;
    height: calc(100vh - 80px);
    position: relative;
}



.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-container {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: #ffffff;
    max-height: calc(100vh - 200px);
    position: relative;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 2rem;
    min-height: 100%;
}

.input-section {
    padding: 1.5rem;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    z-index: 20;
}


.role-generator {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.chat-input {
    display: flex;
    gap: 0.5rem;
    max-width: 800px;
    margin: 0 auto;
    align-items: flex-end; /* 确保所有元素底部对齐 */
}

.chat-input > div {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    width: 100%;
}

.input-field {
    flex: 1;
    padding: 1rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 1rem;
    resize: vertical;
    min-height: 56px; /* 统一高度 */
    max-height: 120px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-color);
    font-family: inherit;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    line-height: 1.4;
}

.input-field:focus {
    outline: none;
    border-color: var(--dark-color);
    box-shadow: 0 0 0 3px rgba(139, 125, 107, 0.15);
    background: rgba(255, 255, 255, 1);
}

.btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 20px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 56px; /* 统一高度，与input-field保持一致 */
    min-width: 56px;
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: #ffffff;
    color: var(--text-color);
    box-shadow: var(--soft-shadow);
    border: 1px solid var(--border-color);
}

.btn-primary:hover {
    background: var(--secondary-color);
    box-shadow: var(--shadow);
    color: var(--dark-color);
}

.btn-danger {
    background: var(--danger-color);
    color: var(--text-color);
    border: 1px solid #f87171;
}

.btn-danger:hover {
    background: #fee2e2;
    color: var(--dark-color);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--pearl-color);
    color: var(--dark-color);
}

/* 设置分组样式 */
.setting-group {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--light-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.setting-group h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.setting-group:last-child {
    margin-bottom: 0;
}


/* 语音范围输入样式 */
.voice-range-input {
    width: 150px;
    accent-color: var(--primary-color);
}

.voice-select {
    width: 200px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: white;
    font-size: 0.9rem;
}

.voice-test-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.voice-test-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-icon {
    background: #ffffff;
    color: var(--text-color);
    width: 48px;
    height: 48px;
    padding: 0;
    font-size: 1.2rem;
    border-radius: 50%;
    border: 1px solid var(--border-color);
}

.btn-icon:hover {
    background: var(--secondary-color);
    border-color: var(--dark-color);
    color: var(--dark-color);
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem;
    border-radius: 20px;
    max-width: 100%;
    margin-bottom: 1rem;
    box-shadow: var(--soft-shadow);
    backdrop-filter: blur(10px);
}

.message.user {
    background: var(--secondary-color);
    color: var(--text-color);
    margin-left: 20%;
    flex-direction: row-reverse;
    border: 1px solid var(--border-color);
}

.message.assistant {
    background: #ffffff;
    margin-right: 20%;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.message.system {
    background: var(--warning-color);
    color: var(--dark-color);
    margin: 0 10%;
    text-align: center;
    border: 1px solid var(--border-color);
}

.message-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--secondary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-weight: bold;
    flex-shrink: 0;
    font-size: 1.1rem;
    border: 2px solid #ffffff;
    box-shadow: var(--soft-shadow);
}

.message-content {
    flex: 1;
    word-wrap: break-word;
}

.message-time {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.1);
}

/* 有背景时，模态框背景稍微暗一些 */
body.has-chat-background .modal {
    background-color: rgba(0, 0, 0, 0.3);
}

.modal-content {
    background: #ffffff;
    margin: 5% auto;
    padding: 2.5rem;
    border-radius: 25px;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

/* 模态框滚动条样式 */
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: var(--secondary-color);
    border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

.close {
    color: var(--secondary-color);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--dark-color);
}

.setting-item {
    margin-bottom: 1rem;
}

.setting-item label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.setting-item input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--dark-color);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.toggle-label {
    font-size: 0.9rem;
    color: var(--text-light);
}

.context-options {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--secondary-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.context-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.context-option input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.command-textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}

.command-hint {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-light);
    font-size: 0.75rem;
    line-height: 1.4;
}

.role-commands {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--secondary-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.role-commands .setting-item {
    margin-bottom: 0.75rem;
}

.context-hint {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-light);
    font-size: 0.8rem;
    font-style: italic;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.history-item {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-item:hover {
    background-color: var(--light-color);
}

.history-item-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.history-item-time {
    font-size: 0.8rem;
    color: var(--secondary-color);
}

.btn-voice {
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    color: var(--text-color);
    width: 52px;
    height: 52px;
    padding: 0;
    font-size: 1.3rem;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    overflow: hidden;
}

.btn-voice::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    background: radial-gradient(circle, transparent 30%, rgba(74, 85, 104, 0.1) 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-voice:hover {
    background: linear-gradient(145deg, #f8f9fa, #e9ecef);
    border-color: var(--dark-color);
    color: var(--dark-color);
    transform: translateY(-2px);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.btn-voice:hover::before {
    opacity: 1;
}

.btn-voice.recording {
    background: linear-gradient(145deg, #ef4444, #dc2626);
    color: white;
    border-color: #b91c1c;
    animation: voice-pulse 1.5s ease-in-out infinite;
    box-shadow: 
        0 6px 20px rgba(239, 68, 68, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-voice.recording::before {
    background: radial-gradient(circle, transparent 30%, rgba(255, 255, 255, 0.2) 70%);
    opacity: 1;
}

.voice-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border-radius: 25px;
    margin-top: 0.75rem;
    border: 2px solid var(--border-color);
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    animation: voice-status-enter 0.3s ease-out;
}

.voice-indicator {
    display: flex;
    gap: 3px;
    align-items: end;
    height: 24px;
}

.voice-wave {
    width: 4px;
    height: 8px;
    background: linear-gradient(to top, var(--dark-color), #6b7280);
    border-radius: 2px;
    animation: voice-wave-animate 1.4s ease-in-out infinite;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.voice-wave:nth-child(2) {
    animation-delay: 0.2s;
}

.voice-wave:nth-child(3) {
    animation-delay: 0.4s;
}

.voice-text {
    font-size: 0.95rem;
    color: var(--text-color);
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

@keyframes voice-pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 
            0 6px 20px rgba(239, 68, 68, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 
            0 8px 25px rgba(239, 68, 68, 0.6),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
}

@keyframes voice-wave-animate {
    0%, 100% { 
        height: 8px; 
        opacity: 0.7;
    }
    50% { 
        height: 24px; 
        opacity: 1;
    }
}

@keyframes voice-status-enter {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.hidden {
    display: none !important;
}

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.error {
    color: var(--danger-color);
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 0.75rem;
    border-radius: 8px;
    margin: 0.5rem 0;
}

.success {
    color: var(--success-color);
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    padding: 0.75rem;
    border-radius: 8px;
    margin: 0.5rem 0;
}

/* Voice record button styling */
.voice-record-btn {
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
    border: 1px solid #d1d5db;
    color: var(--text-color);
    padding: 1rem;
    border-radius: 20px; /* 与其他按钮保持一致 */
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px; /* 统一高度 */
    min-width: 56px;
}

.voice-record-btn:hover {
    background: linear-gradient(135deg, #e5e7eb, #d1d5db);
    transform: translateY(-2px); /* 与其他按钮保持一致 */
    box-shadow: var(--shadow);
}

.voice-record-btn:active {
    transform: translateY(0);
}

.voice-record-btn.recording {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-color: #b91c1c;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* 背景设置样式 */
.background-upload-input {
    padding: 0.5rem !important;
    border: 2px dashed var(--border-color) !important;
    border-radius: 8px !important;
    background: var(--secondary-color) !important;
    cursor: pointer;
    transition: all 0.3s ease;
}

.background-upload-input:hover {
    border-color: var(--dark-color) !important;
    background: var(--pearl-color) !important;
}

.background-preview {
    width: 100%;
    height: 120px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--secondary-color);
    position: relative;
    overflow: hidden;
    margin-top: 0.5rem;
}

.background-preview img,
.background-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

.preview-placeholder {
    color: var(--text-light);
    font-size: 0.9rem;
    text-align: center;
}

.chat-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.chat-background img,
.chat-background video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-background video {
    object-fit: cover;
}

.chat-container.has-background {
    position: relative;
    background: transparent !important;
}

.chat-container.has-background::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.3);
    z-index: 1;
    pointer-events: none;
}

.chat-container.has-background .messages {
    position: relative;
    z-index: 2;
}

.chat-container.has-background .messages .message {
    position: relative;
    z-index: 3;
}

/* 有背景时，消息使用半透明背景 */
.chat-container.has-background .message.user {
    background: rgba(241, 243, 244, 0.85) !important;
    backdrop-filter: blur(15px);
    border: 1px solid rgba(229, 231, 235, 0.5);
}

.chat-container.has-background .message.assistant {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(15px);
    border: 1px solid rgba(229, 231, 235, 0.5);
}

.chat-container.has-background .message.system {
    background: rgba(255, 251, 235, 0.85) !important;
    backdrop-filter: blur(15px);
    border: 1px solid rgba(229, 231, 235, 0.5);
}

/* 有背景时，输入区域也使用半透明背景 */
.chat-section:has(.chat-container.has-background) .input-section {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(229, 231, 235, 0.6);
}

.chat-section:has(.chat-container.has-background) .input-section .input-field {
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(229, 231, 235, 0.6);
}

.chat-section:has(.chat-container.has-background) .input-section .input-field:focus {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(55, 65, 81, 0.8);
}

/* 兼容性备选方案 - 使用body类 */
body.has-chat-background .input-section {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(229, 231, 235, 0.6);
}

body.has-chat-background .input-section .input-field {
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(229, 231, 235, 0.6);
}

body.has-chat-background .input-section .input-field:focus {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(55, 65, 81, 0.8);
}