/* 全局样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --bg-color: #f9fafb;
  --chat-bg: #ffffff;
  --user-message-bg: #4f46e5;
  --user-message-text: #ffffff;
  --assistant-message-bg: #f3f4f6;
  --assistant-message-text: #1f2937;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  background: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 欢迎屏幕 */
.welcome-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
  overflow-y: auto;
}

.welcome-content {
  background: white;
  border-radius: 1.5rem;
  padding: 3rem 2rem;
  max-width: 600px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.welcome-content h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: #111827;
  font-weight: 700;
}

.welcome-subtitle {
  color: #6b7280;
  margin-bottom: 2rem;
  font-size: 1rem;
}

.welcome-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.feature-item {
  padding: 1rem;
  background: #f9fafb;
  border-radius: 0.75rem;
  transition: transform 0.2s;
}

.feature-item:hover {
  transform: translateY(-4px);
}

.feature-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.feature-item h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
  color: #111827;
  font-weight: 600;
}

.feature-item p {
  font-size: 0.75rem;
  color: #6b7280;
}

.btn-start-config {
  background: #4f46e5;
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  margin-bottom: 1rem;
}

.btn-start-config:hover {
  background: #4338ca;
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(79, 70, 229, 0.3);
}

.welcome-hint {
  color: #6b7280;
  font-size: 0.875rem;
}

/* 应用容器 */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  background: var(--chat-bg);
  box-shadow: var(--shadow-lg);
}

/* 头部 */
.app-header {
  background: var(--primary-color);
  color: white;
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.character-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  backdrop-filter: blur(10px);
}

#characterName {
  display: inline-block;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  padding: 0.5rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.btn-icon.active {
  background: rgba(255, 255, 255, 0.3);
}

.btn-icon.playing {
  animation: pulse 1.5s ease-in-out infinite;
  background: rgba(255, 255, 255, 0.4);
}

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

/* 聊天容器 */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--bg-color);
  position: relative;
}

/* Live2D 容器 */
.live2d-container {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 300px;
  height: 400px;
  z-index: 50;
  pointer-events: none;
  transition: all 0.3s ease;
}

.live2d-container canvas {
  width: 100% !important;
  height: 100% !important;
  pointer-events: auto;
}

.live2d-controls {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 60;
  pointer-events: auto;
}

.btn-live2d-control {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.btn-live2d-control:hover {
  background: white;
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

/* 移动端 Live2D 调整 */
@media (max-width: 768px) {
  .live2d-container {
    width: 200px;
    height: 280px;
    top: 5px;
    right: 5px;
  }
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* 消息样式 */
.message {
  display: flex;
  gap: 0.75rem;
  animation: messageSlideIn 0.3s ease-out;
}

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

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

.message-avatar {
  font-size: 2rem;
  flex-shrink: 0;
}

.message-content {
  max-width: 70%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message-text {
  padding: 0.875rem 1rem;
  border-radius: 1rem;
  word-wrap: break-word;
  line-height: 1.5;
}

.user-message .message-text {
  background: var(--user-message-bg);
  color: var(--user-message-text);
  border-bottom-right-radius: 0.25rem;
}

.assistant-message .message-text {
  background: var(--assistant-message-bg);
  color: var(--assistant-message-text);
  border-bottom-left-radius: 0.25rem;
}

.error-message .message-text {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Skill徽章 */
.skill-badge {
  display: inline-block;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  align-self: flex-start;
  margin-left: 0.5rem;
}

/* 消息操作 */
.message-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0 0.5rem;
}

.btn-play-voice {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.375rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-play-voice:hover {
  background: var(--bg-color);
  border-color: var(--primary-color);
  color: var(--primary-color);
  transform: scale(1.05);
}

/* 加载指示器 */
.loading-indicator {
  padding: 1rem 0;
  display: flex;
  justify-content: center;
}

.typing-indicator {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background: var(--assistant-message-bg);
  border-radius: 1rem;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* 输入容器 */
.input-container {
  background: var(--chat-bg);
  border-top: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.chat-form {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.message-input {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 1.5rem;
  font-size: 1rem;
  resize: none;
  max-height: 120px;
  transition: all 0.2s;
  font-family: inherit;
}

.message-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.message-input:disabled {
  background: var(--bg-color);
  cursor: not-allowed;
}

.btn-send {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding-top: 0.25rem;
}

/* 响应式设计 - 平板 */
@media (max-width: 768px) {
  .app-container {
    max-width: 100%;
  }
  
  .chat-container {
    padding: 1rem;
  }
  
  .message-content {
    max-width: 80%;
  }
}

/* 响应式设计 - 手机 */
@media (max-width: 480px) {
  .app-header {
    padding: 0.875rem 1rem;
  }
  
  .app-title {
    font-size: 1.125rem;
  }
  
  .chat-container {
    padding: 0.75rem;
  }
  
  .message-content {
    max-width: 85%;
  }
  
  .message-avatar {
    font-size: 1.5rem;
  }
  
  .message-text {
    padding: 0.75rem 0.875rem;
    font-size: 0.9375rem;
  }
  
  .input-container {
    padding: 0.75rem 1rem;
  }
  
  .message-input {
    padding: 0.75rem 0.875rem;
    font-size: 0.9375rem;
  }
  
  .btn-send {
    width: 44px;
    height: 44px;
  }
  
  .skill-badge {
    font-size: 0.6875rem;
  }
}

/* 滚动条样式 */
.chat-container::-webkit-scrollbar {
  width: 6px;
}

.chat-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* 模态弹窗 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--chat-bg);
  border-radius: 1rem;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color 0.2s;
}

.btn-close:hover {
  color: var(--text-primary);
}

/* 角色列表 */
.character-list {
  padding: 1rem;
}

.character-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  margin-bottom: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.character-item:hover {
  border-color: var(--primary-color);
  background: var(--bg-color);
  transform: translateX(4px);
}

.character-item.active {
  border-color: var(--primary-color);
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.05) 0%, rgba(124, 58, 237, 0.05) 100%);
}

.character-info h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.125rem;
  color: var(--text-primary);
}

.character-version {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-select-character {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-select-character:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.character-item.active .btn-select-character {
  background: var(--text-secondary);
  cursor: default;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* 设置表单 */
.settings-content {
  padding: 1.5rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.form-group label input[type="checkbox"] {
  margin-right: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-hint {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 2rem;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-color);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
}

.btn-danger:hover {
  background: #fecaca;
}

.connection-status {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  text-align: center;
}

.connection-status.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.connection-status.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.connection-status.testing {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

/* 系统消息 */
.system-message {
  justify-content: center;
}

.system-message .message-content {
  max-width: 90%;
}

.system-message .message-text {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  text-align: center;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.message {
  animation: fadeIn 0.3s ease-out;
}

/* 深色模式支持（可选） */
@media (prefers-color-scheme: dark) {
  /* 如需深色模式，取消注释并调整以下变量 */
  /*
  :root {
    --bg-color: #111827;
    --chat-bg: #1f2937;
    --user-message-bg: #6366f1;
    --assistant-message-bg: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border-color: #374151;
  }
  */
}
