:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --accent: #e94560;
  --accent-light: #ff6b6b;
  --text-primary: #f0f0f0;
  --text-secondary: #b8b8b8;
  --text-muted: #888;
  --success: #4ecca3;
  --warning: #ffc107;
  --border: #2a3f5f;
  --teacher-serika: #ff9ff3;
  --teacher-tessa: #74b9ff;
  --teacher-cc: #a29bfe;
  --teacher-aideal: #55efc4;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===== 登录/设置页面 ===== */
.setup-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 2rem;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.setup-screen .logo {
  font-size: 4rem;
  margin-bottom: 0.5rem;
}

.setup-screen h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  text-align: center;
}

.setup-screen .subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

.setup-form {
  width: 100%;
  max-width: 360px;
}

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

.form-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 0.875rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.btn-primary:active {
  transform: translateY(0);
}

/* ===== 主应用布局 ===== */
.app-container {
  display: none;
  flex-direction: column;
  height: 100vh;
}

.app-container.active {
  display: flex;
}

/* 顶部导航 */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

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

.teacher-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: bold;
  color: white;
  flex-shrink: 0;
}

.teacher-avatar.serika { background: linear-gradient(135deg, #ff9ff3, #f368e0); }
.teacher-avatar.tessa { background: linear-gradient(135deg, #74b9ff, #0984e3); }
.teacher-avatar.cc { background: linear-gradient(135deg, #a29bfe, #6c5ce7); }
.teacher-avatar.aideal { background: linear-gradient(135deg, #55efc4, #00b894); }

.header-info h2 {
  font-size: 1rem;
  font-weight: 600;
}

.header-info .lesson-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 1.125rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* ===== 聊天区域 ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-primary);
}

/* 系统提示消息 */
.system-message {
  align-self: center;
  max-width: 80%;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* 消息气泡 */
.message {
  display: flex;
  gap: 0.75rem;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

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

.message.assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
  align-self: flex-end;
}

.message.user .message-avatar {
  background: var(--accent);
  color: white;
}

.message.assistant .message-avatar {
  background: var(--bg-card);
  color: var(--text-secondary);
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 18px;
  font-size: 0.9375rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message.assistant .message-bubble.typing {
  min-width: 60px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Markdown 样式 */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  font-size: 1rem;
  margin: 0.5rem 0;
  color: inherit;
}

.message-bubble p {
  margin: 0.375rem 0;
}

.message-bubble code {
  background: rgba(0,0,0,0.2);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: "SF Mono", Monaco, monospace;
  font-size: 0.875em;
}

.message-bubble pre {
  background: rgba(0,0,0,0.2);
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  margin: 0.5rem 0;
  color: var(--text-secondary);
}

/* ===== 输入区域 ===== */
.input-area {
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.input-area textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 0.625rem 1rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9375rem;
  resize: none;
  outline: none;
  line-height: 1.4;
}

.input-area textarea:focus {
  border-color: var(--accent);
}

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

.send-btn:hover {
  background: var(--accent-light);
}

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

/* ===== 文件查看器模态框 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h3 {
  font-size: 1rem;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-primary);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.file-item:hover {
  background: var(--bg-card);
}

.file-item .file-name {
  font-size: 0.875rem;
}

.file-item .file-size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-content-viewer {
  background: var(--bg-primary);
  border-radius: 10px;
  padding: 1rem;
  font-size: 0.875rem;
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 60vh;
  overflow-y: auto;
}

/* ===== 课程选择模态框 ===== */
.teacher-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.teacher-card {
  padding: 1rem;
  background: var(--bg-primary);
  border: 2px solid transparent;
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.teacher-card:hover {
  border-color: var(--border);
}

.teacher-card.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.teacher-card .teacher-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.teacher-card .teacher-name {
  font-size: 0.875rem;
  font-weight: 600;
}

.lesson-select {
  margin-bottom: 1rem;
}

/* ===== 加载状态 ===== */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== 响应式 ===== */
@media (max-width: 480px) {
  .message {
    max-width: 90%;
  }
  
  .teacher-grid {
    grid-template-columns: 1fr;
  }
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
