/* ========== 基础变量 ========== */
:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary-light: #1e3a5f;
  --success-light: #14532d;
  --warning-light: #451a03;
  --danger-light: #450a0a;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.3);
}

/* ========== 全局样式 ========== */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; color: var(--text-muted); }

p { margin: 0; }
.muted { color: var(--text-muted); font-size: 0.875rem; }

/* ========== 顶部栏 ========== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--primary);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  background: var(--bg);
  border-radius: 20px;
  font-size: 0.875rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

.connection-status.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.connection-status.connecting .status-dot {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.connection-status.error .status-dot {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

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

/* ========== 步骤指示器 ========== */
.steps {
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 1.5rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0 2rem;
  position: relative;
  opacity: 0.4;
  transition: var(--transition);
}

.step.active, .step.done {
  opacity: 1;
}

.step:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -1rem;
  top: 12px;
  width: 2rem;
  height: 2px;
  background: var(--border);
}

.step.done:not(:last-child)::after {
  background: var(--primary);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

.step.active .step-num {
  background: var(--primary);
  color: white;
}

.step.done .step-num {
  background: var(--success);
  color: white;
}

.step-label {
  font-size: 0.75rem;
  font-weight: 500;
}

/* ========== 页面容器 ========== */
.pages {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.page {
  display: none;
  padding: 2rem 1rem;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: block;
}

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

.page-content {
  max-width: 800px;
  margin: 0 auto;
}

.page-content.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.page-header {
  text-align: center;
  margin-bottom: 2rem;
}

.page-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
}

/* ========== 连接页面 ========== */
.connect-card {
  background: var(--bg-card);
  padding: 3rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.connect-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.connect-form {
  margin: 2rem 0;
}

.connect-form .label {
  text-align: left;
  display: block;
  margin-bottom: 0.5rem;
}

.error-text {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 1rem;
}

/* ========== 选题页面 ========== */
.select-controls {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.question-preview {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-section {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
}

.preview-section h3 {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

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

.topic-item {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.part2-card {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--warning);
}

.cue-text {
  font-weight: 500;
  margin-bottom: 1rem;
}

.part2-card ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
}

.part2-card li {
  margin-bottom: 0.25rem;
}

/* ========== 考试页面 ========== */
.exam-header {
  text-align: center;
  margin-bottom: 1rem;
}

.exam-part-badge {
  display: inline-block;
  padding: 0.5rem 1.5rem;
  background: var(--primary);
  color: white;
  border-radius: 20px;
  font-weight: 600;
  margin-bottom: 1rem;
}

#currentQuestion {
  font-size: 1.25rem;
  color: var(--text);
}

/* 题目详情折叠 */
.question-details {
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

.question-details summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}

.question-details summary:hover {
  background: var(--bg-hover);
}

.question-detail-content {
  padding: 0 1rem 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.detail-topic {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.detail-topic strong {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.detail-topic ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.detail-topic li {
  margin-bottom: 0.25rem;
}

.detail-cue {
  padding: 1rem;
  background: var(--warning-light);
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
}

.detail-bullets {
  padding: 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.detail-bullets p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.detail-bullets ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.875rem;
}

/* 计时器 */
.exam-timers {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
}

.timer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 2rem;
  border-radius: var(--radius);
  font-size: 1.25rem;
}

.timer.prep {
  background: var(--warning-light);
  color: var(--warning);
}

.timer.speak {
  background: var(--success-light);
  color: var(--success);
}

.timer-value {
  font-size: 2rem;
  font-weight: 700;
  min-width: 60px;
  text-align: center;
}

.timer .btn.small {
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
}

/* 波形可视化 */
.exam-visualizer {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.5rem;
}

.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 60px;
  margin-bottom: 0.5rem;
}

.wave-bar {
  width: 6px;
  height: 20px;
  background: var(--border);
  border-radius: 3px;
  transition: height 0.1s ease;
}

.waveform.active .wave-bar {
  background: var(--primary);
  animation: wave 0.5s ease infinite;
}

.waveform.active .wave-bar:nth-child(1) { animation-delay: 0s; }
.waveform.active .wave-bar:nth-child(2) { animation-delay: 0.1s; }
.waveform.active .wave-bar:nth-child(3) { animation-delay: 0.2s; }
.waveform.active .wave-bar:nth-child(4) { animation-delay: 0.15s; }
.waveform.active .wave-bar:nth-child(5) { animation-delay: 0.25s; }
.waveform.active .wave-bar:nth-child(6) { animation-delay: 0.05s; }
.waveform.active .wave-bar:nth-child(7) { animation-delay: 0.2s; }

@keyframes wave {
  0%, 100% { height: 20px; }
  50% { height: 50px; }
}

.meter {
  width: 100%;
  max-width: 300px;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.meter-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.05s ease;
}

/* 控制按钮 */
.exam-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* 状态栏 */
.exam-status-bar {
  display: flex;
  justify-content: center;
  gap: 2rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-item strong {
  color: var(--primary);
}

#recordingIndicator {
  font-size: 1rem;
}

.recording #recordingIndicator {
  color: var(--danger);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* 转写区域 */
.exam-transcript {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.transcript-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

/* 播放控制 */
.playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.range {
  width: 100px;
  cursor: pointer;
}

.pill {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.125rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* 进度指示 */
.exam-progress {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
}

.progress-parts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.part-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  opacity: 0.4;
  transition: var(--transition);
}

.part-item.active, .part-item.done {
  opacity: 1;
}

.part-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.part-item.active .part-num {
  background: var(--primary);
  color: white;
}

.part-item.done .part-num {
  background: var(--success);
  color: white;
}

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

.part-line {
  width: 40px;
  height: 2px;
  background: var(--border);
}

.part-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

/* ========== 静默提示 ========== */
.silence-warning {
  background: linear-gradient(135deg, var(--warning-light), #fff7ed);
  border: 2px solid var(--warning);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin: 1rem 0;
  animation: pulseWarning 2s ease-in-out infinite;
}

.silence-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.silence-icon {
  font-size: 1.5rem;
  animation: shake 0.5s ease-in-out infinite;
}

.silence-text {
  color: var(--text);
  font-weight: 500;
}

.silence-countdown {
  background: var(--warning);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-small {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
}

@keyframes pulseWarning {
  0%, 100% { 
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); 
  }
  50% { 
    box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); 
  }
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

/* ========== 评分页面 ========== */
.grade-form, .grade-transcript {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.status-message {
  text-align: center;
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.status-message.loading {
  background: var(--primary-light);
  color: var(--primary);
}

.status-message.error {
  background: var(--danger-light);
  color: var(--danger);
}

.grade-results {
  animation: fadeIn 0.3s ease;
}

.score-hero {
  text-align: center;
  padding: 2rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.score-label {
  display: block;
  font-size: 0.875rem;
  opacity: 0.9;
  margin-bottom: 0.5rem;
}

.score-value {
  font-size: 4rem;
  font-weight: 700;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.score-card {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

.score-name {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.score-num {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary);
}

.feedback-section {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.feedback-section h3 {
  margin-bottom: 0.75rem;
}

.feedback-text {
  color: var(--text);
  line-height: 1.7;
}

.feedback-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.feedback-card {
  padding: 1rem;
  border-radius: var(--radius-sm);
}

.feedback-card.positive {
  background: var(--success-light);
}

.feedback-card.negative {
  background: var(--danger-light);
}

.feedback-card.neutral {
  background: var(--warning-light);
}

.feedback-card h4 {
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

.feedback-card ul {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.875rem;
}

.feedback-card li {
  margin-bottom: 0.25rem;
}

/* 详细分析折叠 */
.detail-accordion {
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.detail-accordion summary {
  padding: 1rem 1.5rem;
  cursor: pointer;
  font-weight: 500;
}

.detail-accordion summary:hover {
  background: var(--bg-hover);
  border-radius: var(--radius);
}

.detail-content {
  padding: 0 1.5rem 1.5rem;
}

.detail-section {
  padding: 1rem 0;
  border-top: 1px solid var(--border);
}

.detail-section h4 {
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

.detail-section p {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.detail-section ul {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.875rem;
}

/* ========== 日志面板 ========== */
.log-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  transition: height 0.3s ease;
  z-index: 50;
}

.log-panel.collapsed {
  height: 40px;
}

.log-panel.collapsed .log-content {
  display: none;
}

.log-toggle {
  width: 100%;
  padding: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.log-content {
  height: 200px;
  padding: 0.5rem 1rem;
}

.log-box {
  height: 100%;
  overflow-y: auto;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.log-box div {
  padding: 0.125rem 0;
}

/* ========== 通用组件 ========== */
.label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text-muted);
}

.input, .textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  transition: var(--transition);
}

.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.textarea {
  resize: vertical;
  font-family: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

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

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

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

.btn.large {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

.btn.small {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

/* 呼吸动画按钮 */
.btn.breathing:not(:disabled) {
  animation: breathing 2s ease infinite;
}

@keyframes breathing {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
}

.btn.pulse-ready {
  animation: breathing 2s ease infinite;
}

.btn-loading {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.btn.loading .btn-text {
  display: none;
}

.btn.loading .btn-loading {
  display: block;
}

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

.hidden {
  display: none !important;
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .topbar {
    padding: 0.5rem 1rem;
  }

  .logo {
    font-size: 1rem;
  }

  .steps {
    padding: 1rem 0.5rem;
  }

  .step {
    padding: 0 1rem;
  }

  .step-label {
    display: none;
  }

  .step:not(:last-child)::after {
    right: -0.5rem;
    width: 1rem;
  }

  .page {
    padding: 1rem 0.75rem;
  }

  .connect-card {
    padding: 2rem 1.5rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .score-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .feedback-grid {
    grid-template-columns: 1fr;
  }

  .exam-status-bar {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .playback-controls {
    flex-direction: column;
    gap: 1rem;
  }

  .timer {
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }

  .timer-value {
    font-size: 1.5rem;
    min-width: 40px;
  }
}

/* ========== 动画类 ========== */
.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.bounce {
  animation: bounce 0.5s ease;
}

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