/* ===== 全局基础 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.8;
  color: #2c3e50;
  background: #f8f9fa;
  font-size: 16px;
}

/* ===== 顶部导航条 ===== */
.top-nav {
  background: #1a1a2e;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.top-nav .nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.top-nav a {
  color: #b8c1ec;
  text-decoration: none;
  padding: 12px 14px;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.top-nav a:hover {
  background: #16213e;
  color: #eef1ff;
}

.top-nav a.active {
  background: #7f5af0;
  color: #fff;
  font-weight: 600;
}

.top-nav .brand {
  font-weight: 700;
  font-size: 15px;
  color: #7f5af0;
  padding: 12px 16px;
  letter-spacing: 0.5px;
}

/* ===== 下拉导航 ===== */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-label {
  color: #b8c1ec;
  padding: 12px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  display: block;
  transition: background 0.2s, color 0.2s;
  background: none;
  border: none;
  font-family: inherit;
  line-height: inherit;
}

.nav-dropdown-label:hover {
  background: #16213e;
  color: #eef1ff;
}

.nav-dropdown-label.active {
  background: #7f5af0;
  color: #fff;
  font-weight: 600;
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #1a1a2e;
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 200;
  border-radius: 0 0 8px 8px;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
}

.nav-dropdown-menu a {
  display: block;
  padding: 10px 16px;
  color: #b8c1ec;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.2s;
}

.nav-dropdown-menu a:hover {
  background: #16213e;
  color: #eef1ff;
}

.nav-dropdown-menu a.active {
  background: #7f5af0;
  color: #fff;
  font-weight: 600;
}

/* ===== 主内容区 ===== */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ===== 标题 ===== */
h1 {
  font-size: 2rem;
  color: #1a1a2e;
  margin-bottom: 8px;
  border-bottom: 3px solid #7f5af0;
  padding-bottom: 12px;
}

.chapter-subtitle {
  color: #6c757d;
  font-size: 1rem;
  margin-bottom: 36px;
}

h2 {
  font-size: 1.5rem;
  color: #1a1a2e;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-left: 12px;
  border-left: 4px solid #7f5af0;
}

h3 {
  font-size: 1.2rem;
  color: #2d3748;
  margin-top: 32px;
  margin-bottom: 12px;
}

/* ===== 段落与列表 ===== */
p {
  margin-bottom: 16px;
}

ul, ol {
  margin-bottom: 16px;
  padding-left: 28px;
}

li {
  margin-bottom: 6px;
}

strong {
  color: #1a1a2e;
}

/* ===== 代码 ===== */
code {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

/* 行内代码 */
p code, li code, td code, h3 code {
  background: #e8e3f3;
  color: #5b21b6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

/* 代码块 */
pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 20px 24px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 24px;
  line-height: 1.6;
  font-size: 0.9rem;
  border: 1px solid #313244;
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* 语法高亮 — Catppuccin 风格 */
.kw { color: #cba6f7; }          /* 关键字: fun, val, var, class, if, when ... */
.type { color: #f9e2af; }        /* 类型: Int, String, List ... */
.str { color: #a6e3a1; }         /* 字符串 */
.num { color: #fab387; }         /* 数字 */
.cmt { color: #6c7086; font-style: italic; } /* 注释 */
.fn { color: #89b4fa; }          /* 函数名 */
.ann { color: #f38ba8; }         /* 注解 @xxx */
.op { color: #89dceb; }          /* 操作符 */
.param { color: #eba0ac; }       /* 参数 */

/* ===== 导师卡片 ===== */
.mentor-card {
  background: linear-gradient(135deg, #1a1a2e 0%, #2d1b69 100%);
  color: #e0e0e0;
  padding: 24px 28px;
  border-radius: 12px;
  margin-bottom: 36px;
  border: 1px solid #7f5af044;
  box-shadow: 0 4px 16px rgba(127, 90, 240, 0.1);
}

.mentor-card .mentor-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.mentor-card .mentor-icon {
  font-size: 2.4rem;
  line-height: 1;
}

.mentor-card .mentor-info h3 {
  color: #cba6f7;
  font-size: 1.1rem;
  margin: 0 0 2px 0;
}

.mentor-card .mentor-info .mentor-method {
  color: #89b4fa;
  font-size: 0.85rem;
  margin: 0;
}

.mentor-quote {
  font-style: italic;
  color: #b8c1ec;
  line-height: 1.8;
  margin: 12px 0 0;
  padding-left: 16px;
  border-left: 2px solid #7f5af066;
}

.mentor-quote p {
  margin-bottom: 8px;
}

/* ===== C++ 对比提示 ===== */
.cpp-note {
  background: #f0fdf4;
  border-left: 4px solid #22c55e;
  padding: 16px 20px;
  margin: 24px 0;
  border-radius: 0 8px 8px 0;
}

.cpp-note .tip-title {
  color: #16a34a;
}

/* ===== 练习题 ===== */
.exercise {
  background: #faf5ff;
  border: 1px solid #e9d5ff;
  border-radius: 12px;
  padding: 24px 28px;
  margin: 48px 0 24px;
}

.exercise > h2 {
  color: #7f5af0;
  border-left: none;
  padding-left: 0;
  margin-top: 0;
  font-size: 1.4rem;
}

.exercise-item {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e9d5ff;
}

.exercise-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.exercise-item h3 {
  margin-top: 0;
}

.exercise-item .difficulty {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}

.difficulty-easy {
  background: #dcfce7;
  color: #166534;
}

.difficulty-medium {
  background: #fef9c3;
  color: #854d0e;
}

.difficulty-hard {
  background: #fce7f3;
  color: #9d174d;
}

details {
  margin: 8px 0;
}

details summary {
  cursor: pointer;
  color: #7f5af0;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 0;
  user-select: none;
}

details summary:hover {
  color: #6d48d0;
}

details[open] summary {
  margin-bottom: 8px;
}

details .answer-content {
  background: #f8f9fa;
  padding: 16px 20px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

/* ===== 提示卡片 ===== */
.tip {
  background: #f0f4ff;
  border-left: 4px solid #7f5af0;
  padding: 16px 20px;
  margin: 24px 0;
  border-radius: 0 8px 8px 0;
}

.tip-title {
  font-weight: 700;
  color: #7f5af0;
  margin-bottom: 4px;
}

.warning {
  background: #fff8e1;
  border-left: 4px solid #f59e0b;
  padding: 16px 20px;
  margin: 24px 0;
  border-radius: 0 8px 8px 0;
}

.warning .tip-title {
  color: #d97706;
}

/* ===== 对比表格 ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.95rem;
}

th {
  background: #1a1a2e;
  color: #fff;
  padding: 10px 16px;
  text-align: left;
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid #e2e8f0;
}

tr:nth-child(even) td {
  background: #f1f5f9;
}

/* ===== 底部导航 ===== */
.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid #e2e8f0;
}

.bottom-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #7f5af0;
  text-decoration: none;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  transition: background 0.2s;
}

.bottom-nav a:hover {
  background: #f0f4ff;
}

.bottom-nav .placeholder {
  width: 120px;
}

/* ===== 首页专用 ===== */
.hero {
  text-align: center;
  padding: 60px 0 40px;
}

.hero h1 {
  font-size: 2.4rem;
  border: none;
  padding: 0;
  margin-bottom: 12px;
}

.hero .tagline {
  font-size: 1.1rem;
  color: #6c757d;
  margin-bottom: 40px;
}

.toc {
  max-width: 680px;
  margin: 0 auto;
}

.toc-part {
  margin-bottom: 32px;
}

.toc-part h2 {
  font-size: 1.1rem;
  color: #7f5af0;
  border-left: none;
  padding-left: 0;
  margin-top: 0;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.toc-list {
  list-style: none;
  padding: 0;
}

.toc-list li {
  margin-bottom: 0;
}

.toc-list a {
  display: block;
  padding: 12px 20px;
  color: #2c3e50;
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.2s, transform 0.1s;
}

.toc-list a:hover {
  background: #f0f4ff;
  transform: translateX(4px);
}

.toc-list .chapter-num {
  color: #7f5af0;
  font-weight: 700;
  margin-right: 8px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .container {
    padding: 24px 16px 60px;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  pre {
    padding: 14px 16px;
    font-size: 0.82rem;
  }

  .top-nav a {
    padding: 10px 10px;
    font-size: 12px;
  }

  .nav-dropdown-label {
    padding: 10px 10px;
    font-size: 12px;
  }

  .nav-dropdown-menu {
    min-width: 180px;
  }

  .nav-dropdown-menu a {
    font-size: 12px;
    padding: 8px 14px;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 8px 10px;
  }
}

/* ===== 代码复制按钮 ===== */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #45475a;
  color: #cdd6f4;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  font-family: inherit;
}

pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: #585b70;
}

.copy-btn.copied {
  background: #a6e3a1;
  color: #1e1e2e;
}

@media (max-width: 480px) {
  .top-nav .nav-inner {
    justify-content: center;
  }

  .bottom-nav {
    flex-direction: column;
    gap: 12px;
  }

  .bottom-nav .placeholder {
    display: none;
  }
}
