/* ============================================================
   style.css —— 现代化 UI(玻璃态导航 / 渐变 / 微动效 / 卡片质感)
   浅色清新基底 + 当代视觉语言
   ============================================================ */

/* ---------- 基础重置 ---------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* 主色系:从单一蓝 升级为 蓝紫渐变品牌色 */
  --c-bg: #f0f4fa;               /* 页面背景:柔和灰蓝 */
  --c-bg-grad: radial-gradient(1200px 600px at 80% -10%, #e3ecfb 0%, transparent 60%),
               radial-gradient(900px 500px at 0% 0%, #eef0fb 0%, transparent 55%),
               #f0f4fa;          /* 多层光晕背景 */
  --c-surface: #ffffff;          /* 卡片背景:纯白 */
  --c-surface-2: #fafbfd;        /* 次级表面 */
  --c-primary: #5b8def;          /* 主色:明亮蓝 */
  --c-primary-2: #7c5cff;        /* 副色:紫(用于渐变) */
  --c-primary-light: #eaf1ff;
  --c-primary-dark: #3f6fd6;
  --c-grad: linear-gradient(135deg, #5b8def 0%, #7c5cff 100%);
  --c-grad-soft: linear-gradient(135deg, #eaf1ff 0%, #f1ecff 100%);
  --c-text: #1f2937;             /* 主文字:深灰 */
  --c-text-light: #6b7280;       /* 次要文字 */
  --c-border: #e5eaf2;
  --c-border-soft: #eef2f7;
  --c-green: #16a34a;
  --c-green-bg: #ecfdf5;
  --c-red: #dc2626;
  --c-red-bg: #fef2f2;
  --c-orange: #ea580c;
  --c-orange-bg: #fff7ed;
  --c-code-bg: #f6f8fc;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-sm: 6px;
  --shadow-xs: 0 1px 2px rgba(31,41,55,0.04);
  --shadow-sm: 0 2px 8px rgba(91,141,239,0.08), 0 1px 2px rgba(31,41,55,0.04);
  --shadow-md: 0 8px 24px rgba(91,141,239,0.10), 0 2px 6px rgba(31,41,55,0.04);
  --shadow-grad: 0 8px 20px rgba(91,141,239,0.28);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--c-bg-grad);
  background-attachment: fixed;
  color: var(--c-text);
  line-height: 1.65;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- 顶部导航:玻璃态 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.72);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid rgba(229,234,242,0.7);
  box-shadow: 0 1px 12px rgba(31,41,55,0.05);
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.logo {
  font-size: 19px;
  font-weight: 800;
  background: var(--c-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.tabs {
  display: flex;
  gap: 4px;
  background: rgba(240,244,250,0.6);
  padding: 4px;
  border-radius: 12px;
}
.tab-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text-light);
  cursor: pointer;
  border-radius: 9px;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--c-primary); }
.tab-btn.active {
  background: var(--c-surface);
  color: var(--c-primary-dark);
  font-weight: 600;
  box-shadow: var(--shadow-xs), 0 0 0 1px rgba(229,234,242,0.5);
}
/* 记忆卡 tab:特殊高亮(渐变描边) */
.tab-btn-card.active {
  background: var(--c-grad);
  color: #fff;
  box-shadow: var(--shadow-grad);
}

/* ---------- 全局进度条 ---------- */
.progress-bar-wrap {
  height: 4px;
  background: rgba(229,234,242,0.5);
  position: sticky;
  top: 60px;
  z-index: 99;
}
.progress-bar-inner {
  height: 100%;
  background: var(--c-grad);
  border-radius: 0 4px 4px 0;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 0 8px rgba(91,141,239,0.5);
}

/* ---------- 页面容器 ---------- */
.tab-page { display: none; max-width: 1040px; margin: 0 auto; padding: 24px 20px 40px; }
.tab-page.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 控制栏 ---------- */
.controls {
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 18px;
  margin-bottom: 20px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: center;
  border: 1px solid var(--c-border-soft);
}
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.control-grow { flex: 1; min-width: 250px; }
.control-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-light);
  white-space: nowrap;
}

/* 按钮 */
.level-btn, .action-btn {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  padding: 7px 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--c-primary-dark);
  cursor: pointer;
  transition: all 0.18s ease;
}
.level-btn:hover, .action-btn:hover {
  background: var(--c-primary-light);
  border-color: var(--c-primary);
  transform: translateY(-1px);
}
.level-btn:active, .action-btn:active { transform: translateY(0); }
.level-btn.active {
  background: var(--c-grad);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
  box-shadow: var(--shadow-grad);
}

.select, .search-input {
  padding: 7px 11px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
  color: var(--c-text);
  outline: none;
  transition: all 0.18s;
}
.select:focus, .search-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(91,141,239,0.12);
}
.search-input { flex: 1; min-width: 120px; }

/* ---------- 填空:题目卡片 ---------- */
.quiz-problem { margin-bottom: 28px; }
.quiz-problem-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--c-text);
  padding: 12px 0 10px;
  margin-bottom: 16px;
  position: relative;
}
.quiz-problem-title::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 48px; height: 3px;
  background: var(--c-grad);
  border-radius: 2px;
}
.quiz-problem-desc {
  font-size: 13px;
  color: var(--c-text-light);
  margin-top: -8px;
  margin-bottom: 16px;
}

/* 步骤块 */
.quiz-block {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--c-border-soft);
  transition: box-shadow 0.2s;
}
.quiz-block:hover { box-shadow: var(--shadow-md); }
.quiz-block-header {
  background: var(--c-grad-soft);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--c-border-soft);
}
.quiz-block-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-primary-dark);
}
.quiz-block-meta {
  font-size: 12px;
  color: var(--c-text-light);
  background: rgba(255,255,255,0.7);
  padding: 2px 10px;
  border-radius: 20px;
}
.quiz-block-body { padding: 16px 18px; }

/* 单行填空 */
.quiz-line {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--c-border);
}
.quiz-line:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.quiz-line-comment {
  font-size: 13px;
  color: #92400e;
  margin-bottom: 8px;
  padding: 6px 12px;
  background: var(--c-orange-bg);
  border-left: 3px solid var(--c-orange);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.quiz-line-code {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  font-family: "Fira Code", "Consolas", "Courier New", monospace;
  font-size: 14px;
}
.code-segment {
  background: var(--c-code-bg);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  white-space: pre;
  border: 1px solid var(--c-border-soft);
}
.blank-input {
  display: inline-block;
  min-width: 120px;
  padding: 6px 10px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  outline: none;
  transition: all 0.18s;
}
.blank-input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(91,141,239,0.12); }
.blank-input.correct {
  border-color: var(--c-green);
  background: var(--c-green-bg);
  color: var(--c-green);
  font-weight: 600;
}
.blank-input.wrong {
  border-color: var(--c-red);
  background: var(--c-red-bg);
  animation: shake 0.35s;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* 反馈信息 */
.feedback {
  font-size: 12px;
  margin-top: 5px;
  min-height: 18px;
}
.feedback.ok { color: var(--c-green); }
.feedback.err { color: var(--c-red); }

/* 单行操作按钮 */
.line-actions { margin-top: 7px; display: flex; gap: 8px; }
.mini-btn {
  font-size: 12px;
  padding: 3px 11px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--c-text-light);
  cursor: pointer;
  transition: all 0.15s;
}
.mini-btn:hover { background: var(--c-primary-light); color: var(--c-primary); }

/* ---------- 代码讲解页 ---------- */
.read-problem { margin-bottom: 28px; }
.read-problem-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--c-text);
  padding: 12px 0 10px;
  margin-bottom: 16px;
  position: relative;
}
.read-problem-title::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 48px; height: 3px;
  background: var(--c-grad);
  border-radius: 2px;
}
.read-block {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--c-border-soft);
}
.read-block-header {
  background: var(--c-grad-soft);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  color: var(--c-primary-dark);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--c-border-soft);
}
.read-block-body { padding: 8px 0; }

.read-line {
  padding: 9px 18px;
  border-bottom: 1px solid var(--c-border-soft);
  scroll-margin-top: 120px;
  transition: background 0.15s;
}
.read-line:last-child { border-bottom: none; }
.read-line:hover { background: var(--c-surface-2); }
.read-line.highlight { background: #fffbeb; }
.read-code {
  font-family: "Fira Code", "Consolas", "Courier New", monospace;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--c-text);
}
.read-comment {
  font-size: 13px;
  color: var(--c-text-light);
  margin-top: 4px;
  padding-left: 14px;
  border-left: 3px solid var(--c-orange);
}
.read-code .search-hit {
  background: #fde68a;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 600;
}

/* 搜索信息 */
.search-info {
  font-size: 13px;
  color: var(--c-text-light);
  margin-bottom: 12px;
  padding: 0 4px;
}

/* ---------- 随机抽查页 ---------- */
.exam-setup {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 32px;
  text-align: center;
  max-width: 560px;
  margin: 48px auto;
  border: 1px solid var(--c-border-soft);
}
.exam-title { font-size: 24px; font-weight: 800; color: var(--c-text); margin-bottom: 12px; }
.exam-desc { font-size: 14px; color: var(--c-text-light); margin-bottom: 28px; line-height: 1.8; }
.exam-options {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.big-btn {
  background: var(--c-grad);
  color: #fff;
  border: none;
  padding: 13px 44px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-grad);
}
.big-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(91,141,239,0.38); }
.big-btn:active { transform: translateY(0); }

/* 抽查进行中 */
.exam-progress-text {
  text-align: center;
  font-size: 15px;
  color: var(--c-text-light);
  margin-bottom: 16px;
}
.exam-progress-text strong { color: var(--c-primary-dark); font-weight: 700; }
.exam-question-card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 26px;
  margin-bottom: 16px;
  border: 1px solid var(--c-border-soft);
}
.exam-q-meta {
  font-size: 13px;
  color: var(--c-primary);
  margin-bottom: 8px;
  font-weight: 700;
}
.exam-q-comment {
  font-size: 14px;
  color: #92400e;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--c-orange-bg);
  border-left: 3px solid var(--c-orange);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.exam-input {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius);
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 15px;
  outline: none;
  transition: all 0.18s;
}
.exam-input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(91,141,239,0.12); }
.exam-input.correct { border-color: var(--c-green); background: var(--c-green-bg); }
.exam-input.wrong { border-color: var(--c-red); background: var(--c-red-bg); }

/* 抽查:代码上下文区域 */
.exam-context { margin-bottom: 16px; }
.exam-context-label {
  font-size: 12px;
  color: var(--c-text-light);
  margin-bottom: 8px;
  padding: 4px 0;
}
.exam-context-code {
  background: var(--c-code-bg);
  border-radius: var(--radius);
  padding: 13px 15px;
  border: 1px solid var(--c-border);
  overflow-x: auto;
}
.exam-ctx-line {
  font-family: "Fira Code", "Consolas", "Courier New", monospace;
  font-size: 13px;
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-all;
}
.exam-ctx-dim { color: #aab2c0; }
.exam-ctx-target {
  background: rgba(91,141,239,0.08);
  border-left: 3px solid var(--c-primary);
  padding: 8px 10px;
  margin: 4px -4px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.exam-ctx-hint {
  font-size: 12px;
  color: var(--c-orange);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  margin-bottom: 6px;
}
.exam-ctx-code-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.exam-ctx-seg { font-family: "Fira Code", "Consolas", monospace; font-size: 13px; }
.exam-input-inline {
  min-width: 100px;
  padding: 4px 9px;
  border: 2px solid var(--c-primary);
  border-radius: var(--radius-sm);
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 13px;
  background: #fff;
  outline: none;
  transition: all 0.18s;
}
.exam-input-inline:focus { box-shadow: 0 0 0 3px rgba(91,141,239,0.12); }
.exam-input-inline.correct { border-color: var(--c-green); background: var(--c-green-bg); }
.exam-input-inline.wrong { border-color: var(--c-red); background: var(--c-red-bg); animation: shake 0.35s; }

.exam-nav { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }

/* 抽查结果 */
.exam-result {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
  text-align: center;
  border: 1px solid var(--c-border-soft);
}
.exam-score {
  font-size: 56px;
  font-weight: 800;
  background: var(--c-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 10px 0;
  line-height: 1.1;
}
.exam-score-label { font-size: 14px; color: var(--c-text-light); }
.exam-review { text-align: left; margin-top: 24px; }
.exam-review-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; color: var(--c-text); }
.exam-review-item {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-family: monospace;
  font-size: 13px;
}
.exam-review-item.wrong { background: var(--c-red-bg); border-left: 3px solid var(--c-red); }
.exam-review-item.right { background: var(--c-green-bg); border-left: 3px solid var(--c-green); }

/* ---------- 记忆卡区(tab 页) ---------- */
.cheatsheet-section {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 28px;
  border: 1px solid var(--c-border-soft);
}
.cheatsheet-inner { max-width: 760px; margin: 0 auto; }
.cheatsheet-header { margin-bottom: 22px; text-align: center; }
.cheatsheet-badge {
  display: inline-block;
  background: linear-gradient(135deg, #fee2e2, #ffedd5);
  color: #b91c1c;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  margin-bottom: 12px;
}
.cheatsheet-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--c-text);
  margin-bottom: 10px;
}
.cheatsheet-desc {
  font-size: 14px;
  color: var(--c-text-light);
  line-height: 1.8;
}
.cheatsheet-thumb-link {
  display: block;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--c-border);
  margin-bottom: 22px;
  text-decoration: none;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.cheatsheet-thumb-link:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(31,41,55,0.14); }
.cheatsheet-thumb {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: cover;
  object-position: top center;
  transition: transform 0.4s ease;
}
.cheatsheet-thumb-link:hover .cheatsheet-thumb { transform: scale(1.02); }
.cheatsheet-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 8px;
}
.cheatsheet-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 13px 32px;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  background: #fff;
  color: var(--c-primary-dark);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}
.cheatsheet-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.cheatsheet-btn.primary {
  background: var(--c-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-grad);
}
.cheatsheet-btn.primary:hover { box-shadow: 0 12px 28px rgba(91,141,239,0.38); }

/* ---------- 底部 ---------- */
.footer {
  background: var(--c-surface);
  border-top: 1px solid var(--c-border-soft);
  padding: 36px 20px;
  margin-top: 32px;
}
.footer-inner { max-width: 1040px; margin: 0 auto; text-align: center; }
.footer-brand { font-size: 15px; font-weight: 700; color: var(--c-text); margin-bottom: 12px; }
.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--c-primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: color 0.15s;
}
.footer-links a:hover { color: var(--c-primary-dark); text-decoration: underline; }
.footer-sep { color: var(--c-border); font-size: 14px; }
.footer-copy { font-size: 12px; color: var(--c-text-light); }

/* ============================================================
   响应式:移动端
   ============================================================ */
@media (max-width: 768px) {
  .footer { padding: 28px 16px; }

  .topbar-inner {
    flex-direction: column;
    height: auto;
    padding: 10px 12px;
    gap: 10px;
  }
  .logo { font-size: 17px; }
  .tabs { width: 100%; justify-content: center; flex-wrap: wrap; }
  .tab-btn { padding: 6px 11px; font-size: 13px; }

  .progress-bar-wrap { top: auto; position: relative; margin-top: 0; }

  .tab-page { padding: 16px 12px 32px; }

  .controls { padding: 12px; gap: 12px; }
  .control-group { width: 100%; flex-wrap: wrap; }

  .quiz-line-code { flex-direction: column; align-items: stretch; }
  .code-segment { display: block; overflow-x: auto; }
  .blank-input { width: 100%; min-width: 0; }

  .quiz-line-comment, .exam-q-comment { font-size: 12px; }

  .exam-setup { padding: 28px 18px; margin: 24px auto; }
  .exam-options { flex-direction: column; align-items: center; }
  .read-code { font-size: 13px; }
  .read-comment { font-size: 12px; padding-left: 10px; }

  /* 移动端:抽查上下文输入框换行铺满 */
  .exam-ctx-code-row { flex-direction: column; align-items: stretch; }
  .exam-input-inline { width: 100%; min-width: 0; }
  .exam-ctx-seg { display: block; overflow-x: auto; }
  .exam-context-code { font-size: 12px; padding: 10px; }
  .exam-ctx-line { font-size: 12px; }

  /* 记忆卡移动端 */
  .cheatsheet-section { padding: 24px 16px; }
  .cheatsheet-title { font-size: 20px; }
  .cheatsheet-btn { width: 100%; padding: 12px 20px; }
}

/* 尊重"减少动效"系统偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
