/* ============================================================
   Helpme Python 基础教程页专属样式
   基调复用 css/style.css：酷黑 + 蓝紫渐变 + 圆角细边框 + 悬停上浮
   布局：宽屏左右两栏（左讲解 / 右跟练），窄屏自动堆叠
   ============================================================ */

/* ---------- 导航栏当前页高亮（与 backend.css 保持一致） ---------- */
.nav-link.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
}

.nav-link.active:hover {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
}

.mobile-link.active {
  color: var(--text-primary);
}

/* ---------- 页面 Hero（比首页略矮） ---------- */
.page-hero {
  position: relative;
  min-height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(var(--nav-height) + 56px) 24px 56px;
  overflow: hidden;
}

.page-hero .hero-title {
  font-size: clamp(34px, 5vw, 56px);
  margin-bottom: 16px;
}

.page-hero .hero-subtitle {
  margin-bottom: 20px;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* ---------- 单元 Tab 栏 ---------- */
.unit-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}

.unit-tab {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.unit-tab:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.unit-tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

/* ---------- 左右两栏主体布局 ---------- */
.lesson-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
  padding-bottom: 100px;
}

.lesson-main {
  min-width: 0;
}

/* 跟练列表：横向置于主内容区上方，释放右侧空间给代码框 */
.lesson-side {
  min-width: 0;
  margin-bottom: 24px;
}

/* 跟练列表横向容器（可换行） */
.unit-list {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
}

/* 仅显示当前单元的题目列表（避免 display:flex 覆盖 hidden 属性） */
.unit-list[hidden] {
  display: none;
}

.side-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.side-title {
  font-size: 16px;
  font-weight: 700;
}

.side-unit-name {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ---------- 左栏：单元概览 / 知识点 ---------- */
.unit-overview {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 20px;
}

.unit-overview h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.overview-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.knowledge-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.knowledge-list li {
  font-size: 14px;
  color: var(--text-secondary);
  padding-left: 18px;
  position: relative;
}

.knowledge-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 9px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
}

.knowledge-list li b {
  color: var(--text-primary);
}

/* ---------- 左栏：题目讲解面板 ---------- */
.task-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
}

.task-panel-title {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 18px;
  letter-spacing: -0.01em;
}

.task-section {
  margin-bottom: 18px;
}

.task-label {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #c7d2fe;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.35);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.task-section p,
.task-section li {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.task-section ul,
.task-section ol {
  padding-left: 20px;
}

/* ---------- 跟练区：用户代码 + 参考答案 ---------- */
.code-input {
  width: 100%;
  min-height: 180px;
  padding: 16px;
  background: #1a1a2e;
  color: #e5e7eb;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.code-input:focus {
  outline: none;
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.code-input::placeholder {
  color: #4b5563;
}

.code-actions {
  display: flex;
  gap: 10px;
  margin: 12px 0;
}

/* 提交代码按钮 */
.btn-submit-code {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-submit-code:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(168, 85, 247, 0.4);
}

/* 返回修改按钮 */
.btn-back-edit {
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

/* 覆盖全局 .btn 的 display:inline-flex，确保 hidden 属性生效 */
.btn-back-edit[hidden] {
  display: none;
}

.btn-back-edit:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

/* 运行结果面板 */
.run-result {
  background: #0d0d0f;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}

.run-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
}

.run-result-title {
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.run-result-status {
  font-size: 12px;
  font-weight: 600;
}

.run-result.run-success .run-result-status {
  color: #34d399;
}

.run-result.run-error .run-result-status {
  color: #f87171;
}

.run-result.run-error {
  border-color: rgba(248, 113, 113, 0.35);
}

.run-output {
  padding: 14px 16px;
  margin: 0;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  color: #e5e7eb;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
}

.run-result.run-error .run-output {
  color: #fca5a5;
}

/* 结果展示时编辑区加边框提示 */
.code-area.has-result .CodeMirror {
  border-color: rgba(99, 102, 241, 0.45);
}

.answer-code {
  background: #0d0d0f;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  overflow-x: auto;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  color: #e5e7eb;
}

/* Java 代码着色 */
.tok-kw {
  color: #a78bfa;
  font-weight: 600;
}

.tok-str {
  color: #fbbf24;
}

.tok-cmt {
  color: #6b7280;
  font-style: italic;
}

.tok-num {
  color: #f97316;
}

/* ---------- 跟练列表：题目卡片（横向紧凑排列） ---------- */
.task-group-title {
  width: 100%;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 12px 0 4px;
  letter-spacing: 0.04em;
}

.task-group-title:first-child {
  margin-top: 0;
}

.task-card {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.task-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
}

.task-card.active {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.06);
}

.task-card.done {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.07);
}

.task-card.done .task-title {
  text-decoration: line-through;
  color: #86efac;
}

/* 题号 + 标题 + 类型标签 + 完成按钮 排成一行 */
.task-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.task-no {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.task-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 完成勾选按钮 */
.btn-done {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: transparent;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.25s ease;
  flex-shrink: 0;
  line-height: 1;
}

.btn-done:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.task-card.done .btn-done {
  background: #22c55e;
  border-color: #22c55e;
  color: #fff;
}

/* 单元进度（横向，整行） */
.unit-progress {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.progress-track {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-text {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* 类型标签（基础/拔高/综合） */
.tag-accent {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
}

.tag-soft {
  background: rgba(168, 85, 247, 0.12);
  border-color: rgba(168, 85, 247, 0.35);
  color: #e9d5ff;
}

.tag-warm {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.35);
  color: #fed7aa;
}

/* ---------- 响应式 ---------- */
@media (max-width: 992px) {
  .lesson-layout {
    grid-template-columns: 1fr;
  }

  .unit-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }

  .unit-tab {
    flex-shrink: 0;
  }
}

/* ============================================================
   CodeMirror 暗色代码编辑器（跟练区重构）
   布局：task-panel 内「左栏概念讲解 / 右栏代码编辑器」
   主题：酷黑 #0d0d0f 底 + 蓝紫渐变高亮，适配暗色
   ============================================================ */

/* ---------- task-panel 内部左右两栏 ---------- */
.task-body {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 24px;
  align-items: start;
}

.task-left {
  min-width: 0;
}

.task-right {
  min-width: 0;
}

/* ---------- CodeMirror 编辑器容器（暗色） ---------- */
.code-area .CodeMirror {
  height: auto;
  min-height: 240px;
  background: #0d0d0f;
  color: #e5e7eb;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.code-area .CodeMirror:hover,
.code-area .CodeMirror-focused {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.code-area .CodeMirror-scroll {
  min-height: 240px;
}

.code-area .CodeMirror-gutters {
  background: #111118;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.code-area .CodeMirror-linenumber {
  color: #4b5563;
}

.code-area .CodeMirror-cursor {
  border-left: 2px solid #a78bfa;
}

.code-area .CodeMirror-selected {
  background: rgba(99, 102, 241, 0.25);
}

.code-area .CodeMirror-activeline-background {
  background: rgba(255, 255, 255, 0.045);
}

.code-area .CodeMirror-matchingbracket {
  color: #fff !important;
  background: rgba(99, 102, 241, 0.4);
  border-radius: 3px;
}

/* ---------- CodeMirror 语法高亮配色（暗色） ---------- */
.code-area .cm-keyword { color: #a78bfa; font-weight: 600; }
.code-area .cm-string,
.code-area .cm-string-2 { color: #fbbf24; }
.code-area .cm-comment { color: #6b7280; font-style: italic; }
.code-area .cm-number { color: #f97316; }
.code-area .cm-def { color: #93c5fd; }
.code-area .cm-variable { color: #e5e7eb; }
.code-area .cm-variable-2 { color: #a5b4fc; }
.code-area .cm-variable-3 { color: #86efac; }
.code-area .cm-type { color: #93c5fd; }
.code-area .cm-builtin { color: #fbbf24; }
.code-area .cm-property { color: #a5b4fc; }
.code-area .cm-operator { color: #c4b5fd; }
.code-area .cm-atom { color: #f472b6; }
.code-area .cm-meta { color: #e9d5ff; }
.code-area .cm-error { color: #f87171; }

/* ---------- 自动补全弹层（暗色） ---------- */
.CodeMirror-hints {
  background: #17171f;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 12px;
  z-index: 9999;
  padding: 6px;
}

.CodeMirror-hint {
  color: #d1d5db;
  padding: 4px 10px;
  border-radius: 6px;
}

.CodeMirror-hint-active {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff;
}

/* ---------- 窄屏堆叠 ---------- */
@media (max-width: 900px) {
  .task-body {
    grid-template-columns: 1fr;
  }

  .task-title {
    max-width: 200px;
  }
}
