﻿/* ============================================
   FastAPI 教程 v2 - 交互式课程系统
   ============================================ */

:root {
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-sidebar: #f8fafc;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --accent: #059669;
  --accent-light: #d1fae5;
  --accent-dark: #047857;
  --accent-soft: #ecfdf5;
  --link: #059669;
  --link-hover: #047857;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-soft: #fef2f2;
  --info: #3b82f6;
  --info-bg: #eff6ff;
  --info-soft: #eff6ff;
  --success: #10b981;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-sidebar: #0f172a;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --accent: #34d399;
  --accent-light: #064e3b;
  --accent-dark: #6ee7b7;
  --accent-soft: #064e3b;
  --link: #34d399;
  --link-hover: #6ee7b7;
  --warning: #fbbf24;
  --warning-bg: #451a03;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --danger-soft: #450a0a;
  --info: #60a5fa;
  --info-bg: #172554;
  --info-soft: #172554;
  --success: #34d399;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }

/* ---------- 顶部导航 ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 64px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.topbar-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.125rem; }
.topbar-brand svg { width: 32px; height: 32px; flex-shrink: 0; }
.topbar-brand span { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.btn-icon {
  width: 36px; height: 36px; border-radius: var(--radius); border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-secondary); color: var(--text); }

/* ---------- 侧边栏 ---------- */
.sidebar {
  position: fixed; top: 64px; left: 0; bottom: 0; width: 300px;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 20px 0; z-index: 90;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.sidebar-group { margin-bottom: 8px; }
.sidebar-group-title { padding: 8px 24px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.sidebar-link { display: block; padding: 7px 24px; color: var(--text-secondary); text-decoration: none; font-size: 0.875rem; border-left: 3px solid transparent; transition: all var(--transition); line-height: 1.5; }
.sidebar-link:hover { color: var(--text); background: var(--bg-secondary); }
.sidebar-link.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.sidebar-link.sub { padding-left: 44px; font-size: 0.8rem; }

/* ---------- 进度条 ---------- */
.progress-bar { height: 3px; background: var(--border); border-radius: 2px; margin: 4px 24px 12px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s ease; width: 0%; }

/* ---------- 主内容区 ---------- */
.main { margin-left: 300px; margin-top: 64px; min-height: calc(100vh - 64px); display: flex; justify-content: center; }
.content { width: 100%; max-width: 820px; padding: 40px 32px 120px; }

/* ---------- 排版 ---------- */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.25; color: var(--text); margin-top: 2.2em; margin-bottom: 0.7em; scroll-margin-top: 80px; }
h1 { font-size: 2.5rem; margin-top: 0; }
h2 { font-size: 1.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4em; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.1rem; }

p { margin-bottom: 1.2em; color: var(--text-secondary); }
a { color: var(--link); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--link-hover); text-decoration: underline; }
strong { color: var(--text); font-weight: 600; }

ul, ol { margin-bottom: 1.2em; padding-left: 1.5em; }
li { margin-bottom: 0.5em; color: var(--text-secondary); }
li::marker { color: var(--accent); }

/* ---------- 学习目标卡片 ---------- */
.learning-objectives {
  background: var(--accent-soft);
  border: 1px solid var(--accent-light);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 2em;
}
.learning-objectives h3 { margin-top: 0; font-size: 1rem; color: var(--accent-dark); display: flex; align-items: center; gap: 8px; }
.learning-objectives ul { margin-bottom: 0; }
.learning-objectives li { color: var(--text-secondary); }

/* ---------- 场景引入框 ---------- */
.scenario-box {
  background: var(--bg-secondary);
  border-left: 4px solid var(--info);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 20px 24px;
  margin-bottom: 2em;
}
.scenario-box h4 { margin-top: 0; color: var(--info); font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; }
.scenario-box p:last-child { margin-bottom: 0; }

/* ---------- 代码 ---------- */
code { font-family: var(--font-mono); font-size: 0.875em; background: var(--bg-tertiary); color: var(--text); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border); }
pre { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; overflow-x: auto; margin-bottom: 1.5em; position: relative; }
pre code { background: transparent; border: none; padding: 0; font-size: 0.8125rem; line-height: 1.7; color: var(--text); }

.code-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: var(--border-light); border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0; font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); }
.code-block { position: relative; margin-bottom: 1.5em; }
.code-block pre { border-radius: 0 0 var(--radius-lg) var(--radius-lg); margin-bottom: 0; }
.copy-btn { position: absolute; top: 6px; right: 8px; padding: 4px 10px; font-size: 0.6875rem; border: 1px solid var(--border); background: var(--bg); color: var(--text-muted); border-radius: 4px; cursor: pointer; opacity: 0; transition: opacity var(--transition); }
.code-block:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); }

/* ---------- 标签切换（Tab） ---------- */
.tab-group { margin-bottom: 1.5em; }
.tab-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 0; padding-left: 0; list-style: none; }
.tab-nav li { margin-bottom: 0; }
.tab-btn { padding: 8px 16px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-muted); cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: all var(--transition); }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; padding-top: 16px; }
.tab-panel.active { display: block; }

/* ---------- 对比块 ---------- */
.compare-group { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 1.5em; }
.compare-box { border-radius: var(--radius-lg); border: 1px solid var(--border); overflow: hidden; }
.compare-header { padding: 10px 16px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.compare-box.good .compare-header { background: var(--accent-soft); color: var(--accent-dark); }
.compare-box.bad .compare-header { background: var(--danger-soft); color: var(--danger); }
.compare-box pre { border: none; border-radius: 0; margin-bottom: 0; }

@media (max-width: 768px) { .compare-group { grid-template-columns: 1fr; } }

/* ---------- 可折叠面板 ---------- */
.accordion { border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 1em; overflow: hidden; }
.accordion-header { width: 100%; padding: 14px 20px; background: var(--bg-secondary); border: none; color: var(--text); font-size: 0.95rem; font-weight: 600; text-align: left; cursor: pointer; display: flex; align-items: center; justify-content: space-between; transition: background var(--transition); }
.accordion-header:hover { background: var(--bg-tertiary); }
.accordion-header::after { content: "+"; font-size: 1.25rem; color: var(--text-muted); transition: transform var(--transition); }
.accordion.open .accordion-header::after { transform: rotate(45deg); }
.accordion-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.accordion.open .accordion-body { max-height: 2000px; }
.accordion-content { padding: 0 20px 20px; }

/* ---------- 测验 ---------- */
.quiz-box { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 1.5em; }
.quiz-title { font-size: 1rem; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.quiz-question { font-size: 0.95rem; margin-bottom: 16px; color: var(--text); font-weight: 500; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option { padding: 12px 16px; border: 2px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: all var(--transition); font-size: 0.9rem; color: var(--text-secondary); background: var(--bg); }
.quiz-option:hover { border-color: var(--accent); background: var(--accent-soft); }
.quiz-option.correct { border-color: var(--success); background: #ecfdf5; color: #065f46; }
.quiz-option.wrong { border-color: var(--danger); background: var(--danger-soft); color: #991b1b; }
.quiz-option.disabled { pointer-events: none; }
.quiz-explanation { margin-top: 16px; padding: 16px; border-radius: var(--radius); background: var(--info-soft); border-left: 4px solid var(--info); font-size: 0.875rem; display: none; }
.quiz-explanation.show { display: block; }

/* ---------- 步骤流程图 ---------- */
.step-flow { display: flex; flex-direction: column; gap: 0; margin-bottom: 2em; }
.step-item { display: flex; gap: 16px; position: relative; }
.step-item:not(:last-child)::before { content: ""; position: absolute; left: 19px; top: 40px; bottom: -8px; width: 2px; background: var(--border); }
.step-badge { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.875rem; flex-shrink: 0; z-index: 1; }
.step-content { padding-bottom: 24px; flex: 1; }
.step-content h4 { margin-top: 8px; margin-bottom: 6px; font-size: 1rem; }
.step-content p { margin-bottom: 0; font-size: 0.9rem; }

/* ---------- 可视化图解 ---------- */
.diagram-box { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; margin-bottom: 2em; overflow-x: auto; }
.diagram-title { font-size: 0.875rem; font-weight: 600; color: var(--text-muted); text-align: center; margin-bottom: 20px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ASGI 生命周期动画 */
.asgi-flow { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.asgi-node { padding: 14px 20px; border-radius: var(--radius); border: 2px solid var(--border); background: var(--bg); text-align: center; min-width: 120px; position: relative; }
.asgi-node.primary { border-color: var(--accent); background: var(--accent-soft); }
.asgi-node.secondary { border-color: var(--info); background: var(--info-soft); }
.asgi-node .label { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.asgi-node .sublabel { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }
.asgi-arrow { color: var(--text-muted); font-size: 1.25rem; }

/* 依赖注入图解 */
.dep-diagram { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.dep-layer { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.dep-block { padding: 10px 18px; border-radius: var(--radius); font-size: 0.8rem; font-weight: 500; }
.dep-block.route { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.dep-block.dep { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.dep-block.service { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.dep-block.db { background: #f3e8ff; color: #6b21a8; border: 1px solid #d8b4fe; }
.dep-connector { width: 2px; height: 16px; background: var(--border); }

/* ---------- 提示框 ---------- */
.callout { border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 1.5em; border-left: 4px solid; display: flex; gap: 12px; align-items: flex-start; }
.callout.info { background: var(--info-soft); border-color: var(--info); }
.callout.warning { background: var(--warning-bg); border-color: var(--warning); }
.callout.danger { background: var(--danger-soft); border-color: var(--danger); }
.callout.tip { background: var(--accent-soft); border-color: var(--accent); }
.callout-icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 2px; }
.callout p:last-child { margin-bottom: 0; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; margin-bottom: 1.5em; font-size: 0.875rem; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text); background: var(--bg-secondary); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--bg-secondary); }

/* ---------- 目录 ---------- */
.toc { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; margin-bottom: 2em; }
.toc-title { font-size: 0.875rem; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.toc ul { list-style: none; padding-left: 0; margin-bottom: 0; }
.toc li { margin-bottom: 6px; }
.toc a { font-size: 0.8125rem; color: var(--text-secondary); }
.toc a:hover { color: var(--link); }

/* ---------- 标签 ---------- */
.tag { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 500; font-family: var(--font-mono); }
.tag.green { background: var(--accent-soft); color: var(--accent-dark); }
.tag.blue { background: var(--info-soft); color: var(--info); }
.tag.orange { background: var(--warning-bg); color: var(--warning); }
.tag.red { background: var(--danger-soft); color: var(--danger); }

/* ---------- 返回顶部 ---------- */
.back-to-top { position: fixed; bottom: 32px; right: 32px; width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px); transition: all var(--transition); z-index: 200; }
.back-to-top.visible { opacity: 1; transform: translateY(0); }
.back-to-top:hover { background: var(--accent-dark); transform: translateY(-2px); }

/* ---------- 首页 ---------- */
.hero { text-align: center; padding: 56px 24px 40px; }
.hero h1 { font-size: 3rem; margin-bottom: 0.5em; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.hero p { font-size: 1.2rem; color: var(--text-secondary); max-width: 620px; margin: 0 auto 1.5em; }

.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin-top: 40px; }
.course-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; text-decoration: none; color: inherit; transition: all var(--transition); display: block; position: relative; }
.course-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--accent); text-decoration: none; }
.course-card-status { position: absolute; top: 16px; right: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.course-card-status.done { background: var(--success); }
.course-card-num { font-size: 0.7rem; font-weight: 700; color: var(--accent); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.08em; }
.course-card h3 { font-size: 1.1rem; margin: 0 0 8px; color: var(--text); }
.course-card p { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0; }

/* ---------- 知识检测横幅 ---------- */
.check-banner { background: linear-gradient(135deg, var(--accent-soft), var(--bg-secondary)); border: 1px solid var(--accent-light); border-radius: var(--radius-lg); padding: 24px 28px; margin: 2em 0; text-align: center; }
.check-banner h3 { margin-top: 0; font-size: 1.1rem; }
.check-banner p { margin-bottom: 0; font-size: 0.9rem; }

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 85; opacity: 0; pointer-events: none; transition: opacity var(--transition); }
  .overlay.active { opacity: 1; pointer-events: auto; }
}
@media (max-width: 640px) {
  .content { padding: 28px 18px 80px; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.375rem; }
  .hero h1 { font-size: 2rem; }
  .course-grid { grid-template-columns: 1fr; }
  .compare-group { grid-template-columns: 1fr; }
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::selection { background: var(--accent-light); color: var(--accent-dark); }
