/* ─── CSS 变量 ─────────────────────────────────────── */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --error: #dc2626;
  --error-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
  --transition: 0.2s ease;
}

/* ─── 全局重置 ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* ─── 导航栏 ─────────────────────────────────────── */
.navbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.navbar-brand .icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ─── 容器 ────────────────────────────────────────── */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ─── 卡片 ────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.card-header .icon-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.icon-blue {
  background: var(--primary-light);
  color: var(--primary);
}

.icon-green {
  background: var(--success-light);
  color: var(--success);
}

.icon-orange {
  background: var(--warning-light);
  color: var(--warning);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* ─── 表单元素 ────────────────────────────────────── */
textarea, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--card-bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
  outline: none;
}

textarea:focus, input[type="text"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
  min-height: 180px;
}

/* ─── 文件上传区域 ────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 1rem;
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone .upload-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  transition: color var(--transition);
}

.upload-zone:hover .upload-icon,
.upload-zone.drag-over .upload-icon {
  color: var(--primary);
}

.upload-zone p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.upload-zone .browse-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--primary);
}

.file-info .remove-file {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 0.25rem;
}

.knowledge-preview {
  margin-top: 0.75rem;
  padding: 1rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ─── 预设按钮 ────────────────────────────────────── */
.preset-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.preset-tag {
  padding: 0.4rem 0.9rem;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.preset-tag:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ─── 按钮 ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

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

.btn-success:hover:not(:disabled) {
  background: #15803d;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
}

.btn-ghost:hover {
  background: #f1f5f9;
  color: var(--text);
}

.btn-lg {
  width: 100%;
  padding: 1rem 2rem;
  font-size: 1.1rem;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

/* ─── Loading Spinner ─────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ─── 错误/消息提示 ───────────────────────────────── */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-top: 1rem;
  display: none;
}

.alert.show {
  display: block;
  animation: fadeIn 0.3s ease;
}

.alert-error {
  background: var(--error-light);
  color: var(--error);
  border: 1px solid #fecaca;
}

.alert-success {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid #bbf7d0;
}

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

/* ─── 答题页：题目卡片 ─────────────────────────────── */
.quiz-meta {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.question-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}

.question-card.correct {
  border-color: var(--success);
  background: var(--success-light);
}

.question-card.incorrect {
  border-color: var(--error);
  background: var(--error-light);
}

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

.question-number {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.question-type-badge {
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-single {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-multiple {
  background: #fef3c7;
  color: #b45309;
}

.badge-essay {
  background: #ede9fe;
  color: #6d28d9;
}

.question-text {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  line-height: 1.7;
}

/* ─── 选项样式 ────────────────────────────────────── */
.options-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.95rem;
}

.option-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-item input[type="radio"],
.option-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
}

.option-item input[type="checkbox"] {
  border-radius: 4px;
}

.option-item input[type="radio"]:checked,
.option-item input[type="checkbox"]:checked {
  border-color: var(--primary);
  background: var(--primary);
}

.option-item input[type="radio"]:checked::after,
.option-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
}

.option-item input[type="checkbox"]:checked::after {
  border-radius: 2px;
  width: 10px;
  height: 10px;
}

.option-item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* 批改模式下选项禁用点击 */
.review-mode .option-item {
  cursor: default;
  pointer-events: none;
}

.review-mode .option-item.correct-option {
  border-color: var(--success);
  background: #dcfce7;
}

.review-mode .option-item.wrong-option {
  border-color: var(--error);
  background: #fee2e2;
}

/* ─── 简答题输入框 ────────────────────────────────── */
.essay-input {
  width: 100%;
  min-height: 140px;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}

.essay-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* 批改模式下简答题显示参考答案 */
.correct-answer-display {
  margin-top: 1rem;
  padding: 1rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.6;
  display: none;
}

.review-mode .correct-answer-display {
  display: block;
}

.correct-answer-display strong {
  color: var(--success);
}

.result-icon {
  font-size: 1.5rem;
  font-weight: 700;
  display: none;
}

.review-mode .result-icon {
  display: inline;
}

/* ─── 底部操作区 ─────────────────────────────────── */
.bottom-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
  padding-bottom: 3rem;
}

/* ─── 未作答确认弹窗 ─────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ─── 首页加载遮罩 ─────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

.loading-overlay p {
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.loading-spinner-large {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ─── 回到顶部 ────────────────────────────────────── */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all var(--transition);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

/* ─── 响应式：平板 ────────────────────────────────── */
@media (max-width: 768px) {
  .container {
    max-width: 100%;
    padding: 1rem 0.75rem;
  }

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

  .navbar {
    padding: 0 0.75rem;
    height: 56px;
  }

  .navbar-brand {
    font-size: 1rem;
    gap: 0.5rem;
  }

  .navbar-brand .icon {
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
  }

  .navbar-actions {
    gap: 0.5rem;
  }

  .navbar-actions .btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.78rem;
  }

  .btn-lg {
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
  }

  .question-card {
    padding: 1rem 0.85rem;
  }

  .question-text {
    font-size: 0.98rem;
    line-height: 1.65;
  }

  .option-item {
    padding: 0.75rem 0.85rem;
    font-size: 0.9rem;
    gap: 0.5rem;
  }

  .bottom-actions {
    flex-direction: column;
    gap: 0.75rem;
    padding: 0 1rem 2rem;
  }

  .bottom-actions .btn {
    width: 100%;
  }

  .preset-tags {
    gap: 0.4rem;
  }

  .preset-tag {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
  }

  .upload-zone {
    padding: 1.5rem 1rem;
  }

  .upload-zone .upload-icon {
    font-size: 2rem;
  }

  .modal-dialog {
    max-width: 90vw;
    padding: 1.5rem;
  }

  .quiz-meta {
    font-size: 0.82rem;
    margin-bottom: 1.25rem;
  }
}

/* ─── 响应式：手机 ────────────────────────────────── */
@media (max-width: 480px) {
  .container {
    padding: 0.75rem 0.5rem;
  }

  .card {
    padding: 1rem 0.75rem;
    margin-bottom: 1rem;
  }

  .card-header {
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .card-header .icon-circle {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .card-title {
    font-size: 0.95rem;
  }

  .card-subtitle {
    font-size: 0.78rem;
  }

  .navbar {
    height: 48px;
    padding: 0 0.5rem;
  }

  .navbar-brand {
    font-size: 0.9rem;
    gap: 0.35rem;
  }

  .navbar-brand .icon {
    width: 26px;
    height: 26px;
    font-size: 0.85rem;
    border-radius: 6px;
  }

  .navbar-actions {
    gap: 0.35rem;
  }

  .navbar-actions .btn-sm {
    padding: 0.3rem 0.5rem;
    font-size: 0.72rem;
    border-radius: 6px;
  }

  textarea {
    min-height: 140px;
    font-size: 0.9rem;
    padding: 0.7rem 0.8rem;
  }

  input[type="text"] {
    font-size: 0.9rem;
    padding: 0.7rem 0.8rem;
  }

  .btn-lg {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    border-radius: var(--radius-sm);
  }

  .question-card {
    padding: 0.85rem 0.7rem;
    margin-bottom: 0.85rem;
    border-width: 1.5px;
    border-radius: var(--radius-sm);
  }

  .question-header {
    margin-bottom: 0.6rem;
  }

  .question-number {
    font-size: 0.85rem;
  }

  .question-type-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
  }

  .question-text {
    font-size: 0.9rem;
    margin-bottom: 0.85rem;
  }

  .option-item {
    padding: 0.7rem 0.75rem;
    font-size: 0.85rem;
    gap: 0.5rem;
    border-width: 1.5px;
    border-radius: 6px;
    /* 增大触摸目标 */
    min-height: 44px;
  }

  .option-item input[type="radio"],
  .option-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
  }

  .essay-input {
    min-height: 120px;
    font-size: 0.9rem;
    padding: 0.7rem 0.8rem;
  }

  .preset-tags {
    gap: 0.3rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .preset-tag {
    flex-shrink: 0;
    padding: 0.3rem 0.65rem;
    font-size: 0.75rem;
  }

  .upload-zone {
    padding: 1.25rem 0.75rem;
  }

  .upload-zone p {
    font-size: 0.8rem;
  }

  .file-info {
    font-size: 0.8rem;
    padding: 0.6rem 0.75rem;
  }

  .knowledge-preview {
    font-size: 0.78rem;
    max-height: 100px;
    padding: 0.7rem;
  }

  .quiz-meta {
    font-size: 0.78rem;
    margin-bottom: 1rem;
  }

  .correct-answer-display {
    font-size: 0.82rem;
    padding: 0.7rem 0.85rem;
    margin-top: 0.75rem;
  }

  .modal-dialog {
    padding: 1.25rem;
    border-radius: var(--radius-sm);
  }

  .modal-title {
    font-size: 1rem;
  }

  .modal-body {
    font-size: 0.85rem;
  }

  .modal-actions {
    flex-direction: column;
    gap: 0.5rem;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .back-to-top {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
    bottom: 1rem;
    right: 1rem;
  }

  .bottom-actions {
    padding: 0 0.5rem 1.5rem;
    gap: 0.5rem;
  }

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