/* ============================================================
   AI 编程方法论 — 浅色文档风 + 三栏布局
   左：课程菜单  中：正文内容  右：本页导读
   ============================================================ */

:root {
  --c-bg: #f8fafc;
  --c-surface: #ffffff;
  --c-text: #1a1a2e;
  --c-text-secondary: #64748b;
  --c-text-dim: #94a3b8;
  --c-border: #e2e8f0;
  --c-border-soft: #f1f5f9;
  --c-accent: #2563eb;
  --c-accent-light: #eff6ff;
  --c-accent-hover: #1d4ed8;

  --c-tip-bg: #ecfdf5;
  --c-tip-border: #10b981;
  --c-warn-bg: #fffbeb;
  --c-warn-border: #f59e0b;
  --c-info-bg: #eff6ff;
  --c-info-border: #3b82f6;
  --c-danger-bg: #fef2f2;
  --c-danger-border: #ef4444;
  --c-summary-bg: #f0f9ff;
  --c-summary-border: #0ea5e9;

  --sidebar-w: 250px;
  --content-max: 720px;
  --toc-w: 180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
img { max-width: 100%; height: auto; display: block; }
html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.8;
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar (左栏：课程菜单) ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  padding: 28px 16px 40px;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.sidebar-logo {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 12px;
  color: var(--c-text);
  text-decoration: none;
  display: block;
}
.sidebar-logo .brand { color: var(--c-accent); }
.sidebar-section {
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--c-text-secondary);
  margin-top: 12px;
}
.sidebar nav { flex: 1; }
.sidebar nav a {
  display: block;
  padding: 7px 8px 7px 12px;
  border-radius: 5px;
  text-decoration: none;
  color: var(--c-text-secondary);
  font-size: 13px;
  transition: all 0.12s;
  border-left: 2px solid transparent;
  line-height: 1.5;
}
.sidebar nav a:hover {
  background: var(--c-accent-light);
  color: var(--c-accent);
}
.sidebar nav a.active {
  background: var(--c-accent-light);
  color: var(--c-accent);
  font-weight: 600;
  border-left-color: var(--c-accent);
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 8px 0;
  font-size: 11px;
  color: var(--c-text-secondary);
  border-top: 1px solid var(--c-border);
}

/* ---- Main (中栏 + 右栏) ---- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 28px;
  padding: 40px 24px 80px;
  min-height: 100vh;
}
.content {
  width: 100%;
  max-width: var(--content-max);
  min-width: 0;
}

/* ---- Page TOC (右栏：本页导读) ---- */
.page-toc {
  display: none;
}
@media (min-width: 1280px) {
  .page-toc {
    display: block;
    width: var(--toc-w);
    flex-shrink: 0;
    position: sticky;
    top: 24px;
    align-self: flex-start;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
  }
}
.page-toc-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--c-text-dim);
  margin-bottom: 10px;
  padding-left: 10px;
}
.page-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.page-toc li { margin: 0; }
.page-toc a {
  display: block;
  padding: 4px 10px;
  font-size: 12.5px;
  color: var(--c-text-secondary);
  text-decoration: none;
  border-left: 2px solid var(--c-border);
  transition: all 0.12s;
  line-height: 1.5;
}
.page-toc a:hover {
  color: var(--c-accent);
  border-left-color: var(--c-accent);
}
.page-toc a.toc-active {
  color: var(--c-accent);
  font-weight: 600;
  border-left-color: var(--c-accent);
  background: var(--c-accent-light);
}

/* ---- Home page hero ---- */
.home-hero {
  padding: 60px 0 40px;
  text-align: center;
}
.home-hero .badge {
  display: inline-block;
  padding: 4px 14px;
  background: var(--c-accent-light);
  color: var(--c-accent);
  font-size: 12px;
  font-weight: 600;
  border-radius: 20px;
  margin-bottom: 20px;
}
.home-hero h1 {
  font-size: 38px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.5px;
  margin-bottom: 16px;
}
.home-hero .tagline {
  font-size: 17px;
  color: var(--c-text-secondary);
  max-width: 500px;
  margin: 0 auto 28px;
}
.home-meta {
  display: flex;
  gap: 28px;
  justify-content: center;
  font-size: 13px;
  color: var(--c-text-secondary);
  margin-bottom: 40px;
}
.home-cta {
  display: inline-block;
  padding: 12px 28px;
  background: var(--c-accent);
  color: white;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s;
}
.home-cta:hover { background: var(--c-accent-hover); }

/* Chapter cards for home page */
.chapter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 48px;
}
.chapter-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 20px;
  text-decoration: none;
  color: var(--c-text);
  transition: all 0.15s;
}
.chapter-card:hover {
  border-color: var(--c-accent);
  box-shadow: 0 2px 12px rgba(37,99,235,0.08);
}
.chapter-card .num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--c-accent);
  font-weight: 700;
}
.chapter-card .title {
  font-size: 15px;
  font-weight: 700;
  margin: 6px 0 4px;
}
.chapter-card .desc {
  font-size: 13px;
  color: var(--c-text-secondary);
  line-height: 1.5;
}

/* ---- Chapter content ---- */
.chapter-header {
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--c-border);
}
.chapter-num {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--c-accent);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.chapter-header h1 {
  font-size: 28px;
  font-weight: 800;
  margin: 8px 0 12px;
  line-height: 1.3;
}
.chapter-header .lead {
  font-size: 15px;
  color: var(--c-text-secondary);
  max-width: 600px;
}

h2 {
  font-size: 21px;
  font-weight: 700;
  margin: 40px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
}
h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 32px 0 10px;
}
h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 24px 0 8px;
}
p {
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--c-text);
}
strong { font-weight: 600; color: #0f172a; }
code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 3px;
  color: #1e293b;
}
pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 18px 22px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 20px 0;
  font-size: 13px;
  line-height: 1.7;
}
pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* ---- Callout boxes ---- */
.callout {
  padding: 16px 20px;
  border-radius: 8px;
  margin: 20px 0;
  font-size: 14px;
  border-left: 3px solid;
  line-height: 1.7;
}
.callout-title {
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}
.callout-tip { background: var(--c-tip-bg); border-color: var(--c-tip-border); }
.callout-tip .callout-title { color: #059669; }
.callout-warning { background: var(--c-warn-bg); border-color: var(--c-warn-border); }
.callout-warning .callout-title { color: #d97706; }
.callout-info { background: var(--c-info-bg); border-color: var(--c-info-border); }
.callout-info .callout-title { color: #2563eb; }
.callout-danger { background: var(--c-danger-bg); border-color: var(--c-danger-border); }
.callout-danger .callout-title { color: #dc2626; }
.callout-summary {
  background: var(--c-summary-bg);
  border-color: var(--c-summary-border);
  border-radius: 10px;
  padding: 20px 24px;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--c-border);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead th {
  background: #f8fafc;
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 12px;
  color: var(--c-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* ---- Lists ---- */
ul, ol {
  margin: 14px 0;
  padding-left: 22px;
}
li { margin-bottom: 5px; font-size: 15px; }
li strong { color: var(--c-text); }

/* ---- hr ---- */
hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 36px 0;
}

/* ---- Blockquote ---- */
blockquote {
  background: var(--c-accent-light);
  border-left: 3px solid var(--c-accent);
  padding: 14px 18px;
  margin: 20px 0;
  border-radius: 0 6px 6px 0;
}
blockquote p { margin: 0; font-size: 14px; color: #1e40af; }

/* ---- Chapter nav (prev/next) ---- */
.chapter-nav {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--c-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-prev, .nav-next {
  font-size: 13px;
  color: var(--c-accent);
  text-decoration: none;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-prev:hover, .nav-next:hover { text-decoration: underline; }
.nav-spacer { flex: 1; }

/* ---- Mobile top bar (仅 ≤820px 显示) ---- */
.m-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* ---- 移动端本页导读（正文顶部折叠块，由 toc.js 注入） ---- */
.toc-mobile { display: none; }

/* ---- Responsive ---- */
@media (max-width: 820px) {
  /* 顶栏 */
  .m-topbar {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    z-index: 101;
  }
  .m-menu-btn {
    width: 40px; height: 40px;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    gap: 5px;
    background: none; border: none;
    cursor: pointer; padding: 8px;
    flex-shrink: 0;
  }
  .m-menu-btn span {
    display: block;
    width: 22px; height: 2px;
    background: var(--c-text);
    border-radius: 2px;
  }
  .m-topbar-brand {
    font-size: 15px; font-weight: 700;
    color: var(--c-text); text-decoration: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-topbar-brand .brand { color: var(--c-accent); }

  /* 侧边栏 → 离屏抽屉 */
  .sidebar {
    top: 52px;
    height: calc(100vh - 52px);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 100;
    box-shadow: 2px 0 16px rgba(15, 23, 42, .12);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease;
    z-index: 90;
  }
  .sidebar-backdrop.show { opacity: 1; visibility: visible; }

  /* 主内容让出顶栏空间 */
  .main {
    margin-left: 0;
    padding: 68px 16px 48px;
  }
  .content h2 { scroll-margin-top: 64px; }

  .chapter-grid { grid-template-columns: 1fr; }
  .home-hero { padding: 32px 0 20px; }
  .home-hero h1 { font-size: 26px; }
  .home-meta { flex-wrap: wrap; gap: 16px; }

  /* 移动端本页导读：顶部折叠块 */
  .toc-mobile {
    display: block;
    margin: 0 0 24px;
    border: 1px solid var(--c-border);
    border-radius: 8px;
    background: var(--c-surface);
    overflow: hidden;
  }
  .toc-mobile summary {
    cursor: pointer;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--c-accent);
    list-style: none;
    display: flex;
    align-items: center;
  }
  .toc-mobile summary::-webkit-details-marker { display: none; }
  .toc-mobile summary::after {
    content: "▾";
    margin-left: auto;
    transition: transform .2s;
  }
  .toc-mobile[open] summary::after { transform: rotate(180deg); }
  .toc-mobile ul {
    list-style: none;
    margin: 0;
    padding: 0 16px 12px;
    border-top: 1px solid var(--c-border-soft);
  }
  .toc-mobile li { margin: 0; }
  .toc-mobile a {
    display: block;
    padding: 9px 0 9px 10px;
    font-size: 13.5px;
    color: var(--c-text-secondary);
    text-decoration: none;
    border-left: 2px solid var(--c-border);
  }
  .toc-mobile a.toc-active {
    color: var(--c-accent);
    font-weight: 600;
    border-left-color: var(--c-accent);
    background: var(--c-accent-light);
  }
}
@media print {
  .sidebar { display: none; }
  .page-toc { display: none; }
  .toc-mobile { display: none; }
  .main { margin-left: 0; }
}
