/* ===== CSS Custom Properties ===== */
:root {
  --bg-primary: #FCFAF5;
  --bg-secondary: #F5F1E8;
  --bg-sidebar: #EDE8DD;
  --bg-card: #FFFFFF;
  --bg-hover: rgba(0,0,0,0.04);
  --text-primary: #1E1B18;
  --text-secondary: #6B6560;
  --text-muted: #A09890;
  --accent: #B84C3A;
  --accent-rgb: 184, 76, 58;
  --accent-gold: #9B7B5A;
  --accent-bg: rgba(var(--accent-rgb), 0.08);
  --accent-bg-hover: rgba(var(--accent-rgb), 0.14);
  --border: #E0DAD0;
  --divider: #EAE5DC;
  --code-bg: #F4F1EA;
  --success: #4A8B5C;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.08);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "SimSun", "Times New Roman", serif;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
}

[data-theme="dark"] {
  --bg-primary: #1C1B22;
  --bg-secondary: #23222B;
  --bg-sidebar: #16151C;
  --bg-card: #2A2935;
  --bg-hover: rgba(255,255,255,0.05);
  --text-primary: #E8E4DD;
  --text-secondary: #A09B95;
  --text-muted: #6E6862;
  --accent: #E0745E;
  --accent-rgb: 224, 116, 94;
  --accent-gold: #C49A6C;
  --accent-bg: rgba(var(--accent-rgb), 0.12);
  --accent-bg-hover: rgba(var(--accent-rgb), 0.18);
  --border: #333142;
  --divider: #2E2C38;
  --code-bg: #2A2835;
  --success: #5CAB73;
  --shadow: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.3);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font-sans); color: var(--text-primary); background: var(--bg-primary); line-height: 1.75; -webkit-font-smoothing: antialiased; }

/* ===== App Layout ===== */
.app { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 260px;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
  overflow-y: auto; overflow-x: hidden;
}

.sidebar-header { padding: 28px 24px 20px; border-bottom: 1px solid var(--divider); }
.sidebar-logo { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.sidebar-logo-icon {
  width: 36px; height: 36px; border-radius: var(--radius); background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 13px; font-weight: 600; letter-spacing: 1px;
  flex-shrink: 0;
}
.sidebar-logo-text { font-family: var(--font-serif); font-size: 16px; font-weight: 600; color: var(--text-primary); letter-spacing: 1px; }

/* Sidebar Nav */
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.module-group { margin-bottom: 4px; }
.module-header {
  display: flex; align-items: center; padding: 12px 24px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  letter-spacing: 0.5px; transition: color var(--transition); user-select: none;
  gap: 8px;
}
.module-header:hover { color: var(--text-primary); }
.module-header .module-num {
  font-family: var(--font-mono); font-size: 11px; color: var(--accent);
  opacity: 0.7; min-width: 24px;
}
.module-header .module-arrow {
  width: 16px; height: 16px; transition: transform 0.2s; opacity: 0.4;
  margin-left: auto; flex-shrink: 0;
}
.module-header.open .module-arrow { transform: rotate(90deg); opacity: 0.7; }

.week-list { overflow: hidden; max-height: 0; transition: max-height 0.3s ease; }
.module-header.open + .week-list { max-height: 400px; }
.week-link {
  display: flex; align-items: flex-start; padding: 8px 20px 8px 48px;
  font-size: 13px; color: var(--text-muted); text-decoration: none;
  transition: all var(--transition); border-left: 2px solid transparent;
  gap: 8px;
}
.week-link:hover { color: var(--text-primary); background: var(--bg-hover); }
.week-link.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-bg); font-weight: 500; }
.week-link .week-dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  opacity: 0.5; flex-shrink: 0; margin-top: 6px;
}
.week-link .week-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.week-link .week-num { line-height: 1.4; }
.week-link .week-subtitle {
  font-size: 11px; line-height: 1.5; opacity: 0.85; font-weight: 400;
  overflow-wrap: break-word;
}
.week-link.completed .week-dot { opacity: 1; background: var(--success); }

.sidebar-footer {
  padding: 16px 24px; border-top: 1px solid var(--divider);
  display: flex; align-items: center; justify-content: space-between;
}
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  width: 36px; height: 36px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; color: var(--text-secondary); transition: all var(--transition);
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-version { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* ===== Main Area ===== */
.main { grid-column: 2; min-height: 100vh; display: flex; flex-direction: column; min-width: 0; overflow-x: hidden; }

.top-bar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; padding: 12px 32px;
  background: var(--bg-primary); border-bottom: 1px solid var(--divider);
  gap: 16px; min-height: 56px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.menu-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 6px; }
.breadcrumb { font-size: 13px; color: var(--text-muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb a { color: var(--text-secondary); text-decoration: none; transition: color var(--transition); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { margin: 0 6px; opacity: 0.4; }

.progress-bar-container { width: 120px; height: 4px; background: var(--divider); border-radius: 2px; overflow: hidden; flex-shrink: 0; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s ease; width: 0; }

/* ===== Content Area ===== */
.content-area { flex: 1; padding: 32px 32px 64px; max-width: 840px; margin: 0 auto; width: 100%; word-break: break-word; overflow-wrap: break-word; overflow-x: hidden; min-width: 0; }

.lesson-loader { text-align: center; padding: 80px 20px; color: var(--text-muted); }
.lesson-loader p { font-family: var(--font-serif); font-size: 16px; letter-spacing: 1px; }

/* ===== Lesson Header ===== */
.lesson-header { margin-bottom: 40px; }
.lesson-week-badge {
  display: inline-block; padding: 4px 14px; border-radius: 20px;
  background: var(--accent-bg); color: var(--accent);
  font-size: 12px; font-weight: 600; letter-spacing: 1px;
}
.lesson-header h1 {
  font-family: var(--font-serif); font-size: 28px; font-weight: 700;
  line-height: 1.4; margin-top: 16px; color: var(--text-primary); letter-spacing: 1px;
}
.lesson-meta {
  display: flex; gap: 20px; margin-top: 12px; font-size: 13px; color: var(--text-muted);
}

/* ===== Section Content ===== */
.lesson-content section { margin-bottom: 36px; }
.lesson-content h2 {
  font-family: var(--font-serif); font-size: 20px; font-weight: 600;
  color: var(--text-primary); margin-bottom: 12px; letter-spacing: 0.5px;
  padding-bottom: 10px; border-bottom: 2px solid var(--divider);
  display: flex; align-items: center; gap: 10px;
}
.lesson-content h2::before {
  content: ''; width: 4px; height: 20px; background: var(--accent);
  border-radius: 2px; flex-shrink: 0;
}
.lesson-content h3 {
  font-family: var(--font-serif); font-size: 17px; font-weight: 600;
  color: var(--text-primary); margin: 20px 0 8px;
}
.lesson-content p {
  font-size: 15px; line-height: 1.85; color: var(--text-primary);
  margin-bottom: 12px; text-align: justify;
}

/* ===== Callout Blocks ===== */
.callout {
  padding: 18px 22px; border-radius: var(--radius); margin: 20px 0;
  font-size: 14px; line-height: 1.8;
}
.callout.tip      { background: rgba(74, 139, 92, 0.08); border-left: 3px solid var(--success); }
.callout.important { background: var(--accent-bg); border-left: 3px solid var(--accent); }
.callout.example  { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.callout.example .callout-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px;
  color: var(--accent); margin-bottom: 8px;
}

/* ===== Quote Block ===== */
.blockquote {
  margin: 28px 0; padding: 24px 32px; position: relative;
  background: var(--bg-secondary); border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.blockquote::before {
  content: '\201C'; font-family: var(--font-serif); font-size: 56px;
  color: var(--accent); opacity: 0.2; position: absolute;
  top: 8px; left: 16px; line-height: 1;
}
.blockquote p { font-family: var(--font-serif); font-size: 16px; font-style: italic; color: var(--text-primary); margin: 0; }
.blockquote .attribution { font-size: 13px; color: var(--text-muted); margin-top: 10px; font-style: normal; }

/* ===== Key Terms ===== */
.key-terms { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.key-term {
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); transition: all var(--transition);
}
.key-term:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.key-term .term { font-weight: 600; font-size: 14px; color: var(--accent); }
.key-term .def  { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ===== List Styles ===== */
.content-list { margin: 12px 0 12px 8px; }
.content-list li {
  font-size: 15px; line-height: 1.9; color: var(--text-primary); padding: 4px 0;
  position: relative; padding-left: 20px; list-style: none;
}
.content-list li::before {
  content: ''; position: absolute; left: 0; top: 12px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: 0.5;
}

/* ===== Code Block ===== */
.code-block { margin: 16px 0; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); }
.code-block .code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.code-block pre {
  padding: 20px 24px; margin: 0; overflow-x: auto;
  background: var(--code-bg); font-family: var(--font-mono);
  font-size: 13px; line-height: 1.7; color: var(--text-primary);
}
code.code-block {
  display: block;
  padding: 16px 20px;
  margin: 12px 0;
  background: var(--code-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: pre-wrap;
}
p code, li code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: var(--accent);
  border: 1px solid var(--border);
  font-weight: 500;
}

/* ===== Concept Cards ===== */
.concept-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin: 20px 0;
}
@media (max-width: 768px) {
  .concept-grid { grid-template-columns: 1fr; }
}
.concept-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  border-top: 3px solid var(--accent);
  box-shadow: var(--shadow);
}
.concept-card-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-family: var(--font-serif);
}
.concept-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin: 0;
}
.concept-card .code-example {
  display: block;
  background: var(--code-bg);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  border: 1px dashed var(--border);
  word-break: break-all;
}
.concept-card .code-note {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

/* ===== Practice Box ===== */
.practice-box {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 24px; margin: 24px 0; background: var(--bg-secondary);
}
.practice-box h3 { color: var(--accent); margin-bottom: 12px; font-family: var(--font-serif); }
.practice-box p { font-size: 14px; color: var(--text-secondary); }
.practice-box .practice-action {
  display: inline-block; margin-top: 14px; padding: 8px 20px;
  background: var(--accent); color: #fff; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer; border: none;
  transition: all var(--transition); letter-spacing: 0.5px;
}
.practice-box .practice-action:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: var(--shadow-lg); }

/* ===== Steps ===== */
.steps-list { margin: 20px 0; }
.step-item {
  display: flex; gap: 16px; padding: 18px 0; border-bottom: 1px solid var(--divider);
}
.step-item:last-child { border-bottom: none; }
.step-item:first-child { padding-top: 4px; }
.step-num {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; font-family: var(--font-mono);
}
.step-body { flex: 1; }
.step-label {
  font-weight: 600; font-size: 15px; color: var(--text-primary);
  margin-bottom: 4px;
}
.step-body p {
  font-size: 14px; color: var(--text-secondary); line-height: 1.7; margin: 0;
}
.step-tip {
  margin-top: 8px; padding: 8px 12px; border-radius: var(--radius);
  background: var(--accent-bg); font-size: 13px; color: var(--text-secondary);
}

/* ===== Detective Task Card ===== */
.task-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 28px 0;
  background: var(--bg-card);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.task-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.task-header {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 24px 24px 16px;
  background: linear-gradient(135deg, var(--accent-bg) 0%, transparent 100%);
  border-bottom: 1px solid var(--divider);
}
.task-badge {
  width: 48px; height: 48px; border-radius: 12px; flex-shrink: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; font-family: var(--font-mono);
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3);
}
.task-title-wrap { flex: 1; }
.task-title {
  font-size: 18px; font-weight: 600; color: var(--text-primary);
  margin: 0 0 4px; line-height: 1.4;
}
.task-subtitle {
  font-size: 14px; color: var(--text-secondary); margin: 0;
}
.task-meta {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  font-size: 13px; color: var(--text-muted);
}
.task-meta .task-tool-icon {
  width: 18px; height: 18px; border-radius: 4px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
}
.task-meta a { color: var(--accent); text-decoration: none; }
.task-meta a:hover { text-decoration: underline; }
.task-body { padding: 20px 24px 8px; }
.task-step {
  display: flex; gap: 14px; padding: 14px 0;
  border-bottom: 1px dashed var(--divider);
}
.task-step:last-child { border-bottom: none; }
.task-step-num {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--bg-secondary); color: var(--accent);
  border: 1.5px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; font-family: var(--font-mono);
}
.task-step-text {
  flex: 1; font-size: 14px; line-height: 1.75;
  color: var(--text-primary); padding-top: 2px;
}
.task-step-text a { color: var(--accent); }
.task-screenshot {
  margin: 16px 24px 20px;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.task-screenshot img {
  width: 100%; display: block;
}
.task-tip {
  margin: 0 24px 20px;
  padding: 14px 18px; border-radius: var(--radius);
  background: rgba(74, 139, 92, 0.06);
  border-left: 3px solid var(--success);
  font-size: 13px; line-height: 1.7;
  color: var(--text-secondary);
}
.task-tip::before {
  content: '💡 '; font-size: 14px;
}

/* ===== Image ===== */
.content-image { margin: 24px 0; text-align: center; }
.content-image img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.content-image .caption { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

/* ===== Section Divider ===== */
.section-divider { text-align: center; margin: 40px 0; color: var(--divider); font-size: 20px; letter-spacing: 8px; user-select: none; }

/* ===== Lesson Navigation ===== */
.lesson-nav { display: flex; justify-content: space-between; margin-top: 64px; padding-top: 32px; border-top: 1px solid var(--divider); }
.lesson-nav a {
  font-size: 14px; color: var(--text-secondary); text-decoration: none;
  display: flex; flex-direction: column; transition: color var(--transition);
  max-width: 45%;
}
.lesson-nav a:hover { color: var(--accent); }
.lesson-nav .nav-label { font-size: 11px; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 4px; }
.lesson-nav .nav-prev { align-items: flex-start; text-align: left; }
.lesson-nav .nav-next { align-items: flex-end; text-align: right; }

/* ===== Overview Card ===== */
.overview-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px; margin-bottom: 32px;
  box-shadow: var(--shadow);
}
.overview-card h3 {
  font-family: var(--font-serif); font-size: 18px; margin-bottom: 12px; color: var(--accent);
}
.overview-card ul { margin-left: 20px; }
.overview-card li { font-size: 14px; line-height: 2; color: var(--text-secondary); }

/* ===== Table Styles ===== */
.table-wrapper { overflow-x: auto; margin: 20px 0; max-width: 100%; }
.table-caption { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.content-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.content-table th {
  background: var(--bg-secondary); padding: 10px 14px; text-align: left;
  font-weight: 600; color: var(--accent); border-bottom: 2px solid var(--border);
  font-size: 13px; white-space: nowrap;
}
pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}
@media (max-width: 768px) {
  .content-table th { white-space: normal; font-size: 12px; padding: 8px 10px; }
  .content-table td { font-size: 12px; padding: 8px 10px; }
}
.content-table td { padding: 10px 14px; border-bottom: 1px solid var(--divider); color: var(--text-primary); font-family: var(--font-mono); font-size: 13px; }
.content-table tr:hover td { background: var(--bg-hover); }

/* ===== Sidebar Overlay (mobile) ===== */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 99; border: none; cursor: pointer; }

/* ===== Search ===== */
.search-panel { position: fixed; top: 16px; right: 32px; width: 400px; max-width: 90vw; background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); z-index: 200; border: 1px solid var(--border); display: none; }
.search-panel.active { display: block; }
.search-input-wrapper { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.search-input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; background: var(--bg-secondary); color: var(--text-primary);
  outline: none; font-family: var(--font-sans);
}
.search-input:focus { border-color: var(--accent); }
.search-results { max-height: 400px; overflow-y: auto; padding: 8px 0; }
.search-result {
  padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--divider); transition: background var(--transition);
}
.search-result:hover { background: var(--bg-hover); }
.search-result .result-title { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.search-result .result-loc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.search-empty { padding: 32px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }

.search-close {
  position: absolute; top: 8px; right: 12px; background: none; border: none;
  font-size: 18px; cursor: pointer; color: var(--text-muted); padding: 4px 8px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform 0.3s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; }
  .sidebar-overlay.hidden { display: none; }
  .menu-toggle { display: block; }
  .main { grid-column: 1; }
  .content-area { padding: 20px 16px 48px; }
  .top-bar { padding: 10px 16px; }
  .lesson-header h1 { font-size: 22px; }
  .lesson-content h2 { font-size: 18px; }
  .lesson-nav { flex-direction: column; gap: 16px; }
  .lesson-nav a { max-width: 100%; }
  .key-terms { grid-template-columns: 1fr; }
  .search-panel { right: 16px; width: calc(100vw - 32px); }
  .blockquote { padding: 18px 20px; }
}

/* ===== Print ===== */
@media print {
  .sidebar, .top-bar, .lesson-nav, .sidebar-overlay { display: none; }
  .app { grid-template-columns: 1fr; }
  .main { grid-column: 1; }
  .content-area { max-width: 100%; padding: 0; }
  body { background: #fff; color: #000; }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
.lesson-content section { animation: fadeIn 0.4s ease both; }
.lesson-content section:nth-child(1) { animation-delay: 0.05s; }
.lesson-content section:nth-child(2) { animation-delay: 0.1s; }
.lesson-content section:nth-child(3) { animation-delay: 0.15s; }
.lesson-content section:nth-child(4) { animation-delay: 0.2s; }
.lesson-content section:nth-child(5) { animation-delay: 0.25s; }
.lesson-content section:nth-child(6) { animation-delay: 0.3s; }

/* ===== Scrollbar ===== */
::-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); }

/* ===== Selection ===== */
::selection { background: var(--accent-bg); color: var(--text-primary); }

/* ===== Focus ===== */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Utility */
.hidden { display: none; }

/* ===== Home Page ===== */
.home-page { animation: fadeIn 0.5s ease; }

.hero {
  text-align: center; padding: 64px 20px 56px;
  position: relative;
}
.hero-badge {
  display: inline-block; padding: 6px 18px; border-radius: 24px;
  background: var(--accent-bg); color: var(--accent);
  font-size: 13px; font-weight: 500; letter-spacing: 1px; margin-bottom: 24px;
}
.hero-title {
  font-family: var(--font-serif); font-size: 44px; font-weight: 700;
  color: var(--text-primary); letter-spacing: 3px; margin-bottom: 16px;
  line-height: 1.3;
}
.hero-subtitle {
  font-family: var(--font-serif); font-size: 18px; color: var(--text-secondary);
  max-width: 520px; margin: 0 auto 24px; line-height: 1.6; text-align: center;
}
.hero-desc {
  font-size: 14px; color: var(--text-muted); max-width: 600px;
  margin: 24px auto 32px; line-height: 1.85; text-align: center;
}
.hero-cta {
  display: inline-block; padding: 12px 36px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  text-decoration: none; letter-spacing: 1px; cursor: pointer; border: none;
  transition: all var(--transition); box-shadow: 0 2px 12px rgba(var(--accent-rgb), 0.3);
}
.hero-cta:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(var(--accent-rgb), 0.4); }
.hero-semester {
  display: flex; flex-direction: column; align-items: center; width: fit-content;
  margin: 16px auto 24px; padding: 8px 24px;
  font-size: 13px; color: var(--text-muted); letter-spacing: 2px; line-height: 1.8;
  border: 1px solid var(--divider); border-radius: 4px;
}
.hero-editor { font-size: 12px; color: var(--text-secondary); letter-spacing: 1px; }

/* Home modules */
.home-modules { padding: 32px 0 40px; }
.home-modules h2 {
  font-family: var(--font-serif); font-size: 18px; font-weight: 600;
  color: var(--text-secondary); text-align: center; margin-bottom: 28px;
  letter-spacing: 2px;
}
.module-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.module-card {
  padding: 20px 16px; border-radius: var(--radius-lg); cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card);
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.module-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent); opacity: 0; transition: opacity var(--transition);
}
.module-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.module-card:hover::before { opacity: 1; }
.module-card-num {
  font-family: var(--font-mono); font-size: 12px; color: var(--accent);
  opacity: 0.5; letter-spacing: 2px; margin-bottom: 8px;
}
.module-card h3 {
  font-family: var(--font-serif); font-size: 15px; color: var(--text-primary);
  margin: 0 0 6px; font-weight: 600;
}
.module-card p { font-size: 12px; color: var(--text-muted); margin: 0; }

/* Home features */
.home-features { padding: 32px 0 40px; }
.home-features h2 {
  font-family: var(--font-serif); font-size: 18px; font-weight: 600;
  color: var(--text-secondary); text-align: center; margin-bottom: 28px;
  letter-spacing: 2px;
}
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.feature-item {
  padding: 24px 18px; border-radius: var(--radius-lg);
  border: 1px solid var(--divider); background: var(--bg-secondary);
  text-align: center; transition: all var(--transition);
}
.feature-item:hover { background: var(--bg-card); border-color: var(--border); }
.feature-icon {
  width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-bg); color: var(--accent);
}
.feature-item h3 {
  font-family: var(--font-serif); font-size: 14px; font-weight: 600;
  color: var(--text-primary); margin-bottom: 6px;
}
.feature-item p { font-size: 12px; color: var(--text-muted); line-height: 1.6; margin: 0; }

/* Nav home link */
.nav-home {
  padding: 10px 24px 10px 24px; font-weight: 500; gap: 8px;
  border-bottom: 1px solid var(--divider); margin-bottom: 4px;
  color: var(--text-secondary);
}
.nav-home:hover { color: var(--text-primary); }
.nav-home.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-bg); }
.nav-home svg { flex-shrink: 0; }

/* Method cards — 方法论地图五张卡片 */
.method-cards-grid {
  display: flex; flex-direction: column; gap: 1px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; background: var(--border);
}
.method-card {
  display: flex; align-items: flex-start; gap: 20px;
  padding: 20px 24px; background: var(--bg-card);
  transition: background var(--transition);
}
.method-card:hover { background: var(--bg-secondary); }
.method-card-num {
  flex-shrink: 0; width: 44px; height: 44px;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 18px; font-weight: 700;
  background: var(--accent-bg); color: var(--accent);
  letter-spacing: 0;
}
.method-card-body { flex: 1; min-width: 0; }
.method-card-title {
  font-family: var(--font-serif); font-size: 16px; font-weight: 600;
  color: var(--text-primary); margin-bottom: 2px;
}
.method-card-sub {
  font-size: 12px; color: var(--accent); margin-bottom: 6px; font-weight: 500;
  letter-spacing: 1px;
}
.method-card-desc {
  font-size: 13px; color: var(--text-muted); line-height: 1.7; margin: 0;
}

/* ===== Lesson Figure / Image ===== */
.lesson-figure {
  margin: 28px 0; text-align: center;
}
.lesson-figure img {
  max-width: 100%; height: auto; border-radius: var(--radius-md);
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
  border: 1px solid var(--border);
}
.lesson-figure img.lightbox-trigger {
  cursor: zoom-in;
  transition: opacity 0.2s;
}
.lesson-figure img.lightbox-trigger:hover {
  opacity: 0.85;
}
.lesson-figure .zoom-hint {
  display: inline-block; margin-top: 6px;
  font-size: 11px; color: var(--text-muted);
  opacity: 0.6; letter-spacing: 1px;
}
.lesson-figure figcaption {
  margin-top: 10px; font-size: 13px; color: var(--text-muted);
  line-height: 1.6; max-width: 640px; margin-left: auto; margin-right: auto;
}
.figure-credit {
  display: block; margin-top: 4px; font-size: 11px; color: var(--text-muted);
  opacity: 0.65; font-style: italic;
}

/* ===== Lightbox ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  opacity: 1; transition: opacity 0.25s ease;
}
.lightbox.hidden {
  opacity: 0; pointer-events: none;
}
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  background: none; border: none; color: #fff;
  font-size: 40px; line-height: 1; cursor: pointer;
  opacity: 0.7; transition: opacity 0.2s;
  z-index: 1001; padding: 8px;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-content {
  width: 100vw; height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.lightbox-content img {
  width: 96vw; height: 90vh;
  object-fit: contain; border-radius: 0;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.lightbox-caption {
  position: absolute; bottom: 20px;
  font-size: 13px; color: rgba(255,255,255,0.8);
  text-align: center; max-width: 800px; line-height: 1.6;
  padding: 0 20px;
}

/* ===== CBDB Query Tool ===== */
.cbdb-tool {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 28px 0;
  background: var(--bg-card);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cbdb-tool-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--accent-bg) 0%, transparent 100%);
  border-bottom: 1px solid var(--divider);
  font-size: 14px; font-weight: 600; color: var(--accent);
}
.cbdb-tool-body { padding: 20px; }
.cbdb-input-row {
  display: flex; gap: 10px;
}
.cbdb-input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px;
  background: var(--bg-secondary); color: var(--text-primary);
  font-family: var(--font-sans); outline: none;
  transition: border-color var(--transition);
}
.cbdb-input:focus { border-color: var(--accent); }
.cbdb-btn {
  padding: 10px 24px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.cbdb-btn:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3); }
.cbdb-btn:active { transform: translateY(0); }

.cbdb-result { margin-top: 16px; }
.cbdb-placeholder {
  text-align: center; padding: 32px 20px; color: var(--text-muted);
}
.cbdb-placeholder svg { margin-bottom: 12px; }
.cbdb-placeholder p { font-size: 13px; line-height: 1.8; margin: 0; }

.cbdb-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 24px; color: var(--text-muted); font-size: 14px;
}
.cbdb-spinner {
  width: 18px; height: 18px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.cbdb-error {
  padding: 16px; border-radius: var(--radius);
  background: rgba(var(--accent-rgb), 0.08); color: var(--accent);
  font-size: 14px; text-align: center;
}
.cbdb-empty {
  padding: 24px; text-align: center; color: var(--text-muted); font-size: 14px;
}
.cbdb-count { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.cbdb-cache-badge { font-size: 12px; color: #b8860b; }

.cbdb-person-card {
  padding: 14px 16px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-secondary);
  transition: all var(--transition);
}
.cbdb-person-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.cbdb-person-name {
  font-family: var(--font-serif); font-size: 16px; font-weight: 600;
  color: var(--text-primary); margin-bottom: 6px;
}
.cbdb-person-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--text-secondary);
}
.cbdb-tag {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  background: var(--accent-bg); color: var(--accent);
  font-size: 12px; font-weight: 500;
}
.cbdb-person-eng {
  font-size: 12px; color: var(--text-muted); margin-top: 4px; font-style: italic;
}
.cbdb-person-alias {
  font-size: 13px; color: var(--text-muted); margin-top: 4px;
}
.cbdb-person-birthplace {
  font-size: 13px; color: var(--text-muted); margin-top: 2px;
}
.cbdb-person-notes {
  font-size: 12px; color: var(--text-muted); margin-top: 6px;
  line-height: 1.5; border-top: 1px solid var(--border);
  padding-top: 6px;
}

/* ===== Scheme Card (for CBDB three-scheme) ===== */
.scheme-number {
  display: inline-block; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  text-align: center; line-height: 28px; font-weight: 700;
  font-size: 14px; font-family: var(--font-mono);
  margin-right: 8px; flex-shrink: 0;
}

@media (max-width: 768px) {
  .cbdb-input-row { flex-direction: column; }
  .cbdb-btn { width: 100%; text-align: center; }
}

@media (max-width: 768px) {
  .hero { padding: 40px 16px 36px; }
  .hero-title { font-size: 30px; letter-spacing: 2px; }
  .hero-subtitle { font-size: 15px; }
  .module-cards { grid-template-columns: repeat(2, 1fr); }
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
}
