/* ===== CSS Variables ===== */
:root {
  --bg: #f5f3ee;
  --bg2: #ffffff;
  --ink: #2c2c2c;
  --muted: #6e6e6e;
  --rule: #d8d4cc;
  --accent: #c45c3e;
  --accent2: #4a7c6f;
  --accent-light: #f0e6e1;
  --accent2-light: #e1ebe8;
  --hero-bg: #3d3a36;
  --hero-text: #f5f3ee;
  --code-bg: #2d2d2d;
  --code-text: #e8e6e3;
  --tag-bg: #f0e6e1;
  --tag-text: #c45c3e;
  --tag2-bg: #e1ebe8;
  --tag2-text: #4a7c6f;
  --note-bg: #f5f0eb;
  --note-border: #c45c3e;
  --example-bg: #f0ebe5;
  --example-border: #4a7c6f;
  --app-bg: #eef2f0;
  --app-border: #4a7c6f;
  --formula-bg: #f0ede8;
}

/* ===== Fonts ===== */
@font-face {
  font-family: 'CrimsonPro';
  src: url('../fonts/CrimsonPro-Regular.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'CrimsonPro';
  src: url('../fonts/CrimsonPro-Bold.ttf') format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: 'WorkSans';
  src: url('../fonts/WorkSans-Regular.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'WorkSans';
  src: url('../fonts/WorkSans-Bold.ttf') format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: 'JetBrainsMono';
  src: url('../fonts/JetBrainsMono-Regular.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'JetBrainsMono';
  src: url('../fonts/JetBrainsMono-Bold.ttf') format('truetype');
  font-weight: 700;
}

/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'WorkSans', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.75;
  font-size: 16px;
}

/* ===== Hero Header ===== */
.hero {
  background: var(--hero-bg);
  color: var(--hero-text);
  text-align: center;
  padding: 4rem 1.5rem 3.5rem;
}
.hero .series-label {
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #b8b4ae;
  margin-bottom: 1rem;
}
.hero h1 {
  font-family: 'CrimsonPro', serif;
  font-size: 2.6rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--hero-text);
}
.hero .subtitle {
  font-size: 1.1rem;
  color: #b8b4ae;
  margin-bottom: 0.5rem;
}
.hero .meta {
  font-size: 0.85rem;
  color: #9a958e;
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ===== Chapter Hero ===== */
.chapter-hero {
  background: var(--hero-bg);
  color: var(--hero-text);
  text-align: center;
  padding: 3rem 1.5rem 2.5rem;
}
.chapter-hero .series-label {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  color: #b8b4ae;
  margin-bottom: 0.75rem;
}
.chapter-hero h1 {
  font-family: 'CrimsonPro', serif;
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--hero-text);
}
.chapter-hero .subtitle {
  font-size: 1rem;
  color: #b8b4ae;
}

/* ===== Brand Bar ===== */
.brand-bar {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  padding: 0.6rem 2rem;
  font-family: 'CrimsonPro', serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}
.brand-bar a {
  color: var(--ink);
  text-decoration: none;
}
.brand-bar a:hover {
  color: var(--accent);
}

/* ===== Container ===== */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ===== TOC Section ===== */
.toc-section {
  padding: 3rem 0 2rem;
}
.toc-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.toc-header .toc-label {
  font-family: 'CrimsonPro', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}
.toc-header .toc-title {
  font-family: 'CrimsonPro', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
}
.toc-desc {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

/* ===== Part Divider ===== */
.part-divider {
  margin: 2.5rem 0 1.5rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--accent);
}
.part-divider h3 {
  font-family: 'CrimsonPro', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

/* ===== Chapter Cards ===== */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}
.chapter-card {
  display: block;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}
.chapter-card .card-num {
  font-family: 'CrimsonPro', serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.5;
  line-height: 1;
  margin-bottom: 0.5rem;
}
.chapter-card .card-title {
  font-family: 'CrimsonPro', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.5rem;
}
.chapter-card .card-desc {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 0.75rem;
}
.chapter-card .card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.tag {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-weight: 500;
}
.tag-red {
  background: var(--tag-bg);
  color: var(--tag-text);
}
.tag-green {
  background: var(--tag2-bg);
  color: var(--tag2-text);
}

/* ===== Plan Section ===== */
.plan-section {
  padding: 2rem 0 3rem;
}
.plan-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.plan-header .plan-label {
  font-family: 'CrimsonPro', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}
.plan-header .plan-title {
  font-family: 'CrimsonPro', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
}
.plan-desc {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.plan-card {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.25rem;
}
.plan-card .plan-week {
  font-family: 'CrimsonPro', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.plan-card .plan-content {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

/* ===== Chapter Content ===== */
.chapter-content {
  padding: 2rem 0 3rem;
}

/* Typography */
h2 {
  font-family: 'CrimsonPro', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  margin: 2.5rem 0 1rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
h2 .section-num {
  font-size: 1.3rem;
  color: var(--accent);
  opacity: 0.6;
}
h3 {
  font-family: 'CrimsonPro', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  margin: 1.75rem 0 0.75rem;
}
h4 {
  font-family: 'WorkSans', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin: 1.25rem 0 0.5rem;
}
p {
  margin-bottom: 1rem;
  color: var(--ink);
}

/* Lists */
ul, ol {
  margin: 0 0 1rem 1.5rem;
}
li {
  margin-bottom: 0.4rem;
}

/* Strong / Emphasis */
strong {
  font-weight: 700;
  color: var(--ink);
}

/* ===== Boxes ===== */
.note-box {
  background: var(--note-bg);
  border-left: 4px solid var(--note-border);
  border-radius: 0 8px 8px 0;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.note-box .box-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}
.note-box p:last-child {
  margin-bottom: 0;
}

/* ===== Example Box (Simple) ===== */
.example-box {
  background: var(--example-bg);
  border-left: 4px solid var(--example-border);
  border-radius: 0 8px 8px 0;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.example-box .box-title {
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}
.example-box p:last-child {
  margin-bottom: 0;
}

/* ===== Example Section (Detailed with steps) ===== */
.example-section {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  margin: 1.5rem 0;
}
.example-section .example-header {
  padding: 0.75rem 1.25rem;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
}
.example-section .example-header.accent {
  background: var(--accent);
}
.example-section .example-header.accent2 {
  background: var(--accent2);
}
.example-section .example-body {
  padding: 1.25rem;
}
.example-section .example-step {
  border-left: 2px solid var(--rule);
  padding-left: 1.25rem;
  margin: 1rem 0;
}
.example-section .step-label {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}
.example-section .step-content {
  font-size: 0.95rem;
}
.example-section .example-result {
  background: var(--accent-light);
  padding: 0.75rem 1.1rem;
  border-radius: 6px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 1rem;
}

.app-box {
  background: var(--app-bg);
  border-left: 4px solid var(--app-border);
  border-radius: 0 8px 8px 0;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.app-box .box-title {
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}
.app-box p:last-child {
  margin-bottom: 0;
}

/* ===== Formula Block ===== */
.formula {
  background: var(--formula-bg);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin: 1rem 0;
  text-align: center;
  font-family: 'JetBrainsMono', monospace;
  font-size: 0.95rem;
  overflow-x: auto;
}

/* ===== MATLAB Code ===== */
.matlab-block {
  background: var(--code-bg);
  color: var(--code-text);
  font-family: 'JetBrainsMono', monospace;
  font-size: 0.85rem;
  line-height: 1.7;
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.25rem 0;
}
.matlab-block .comment {
  color: #7a9e7a;
}
.matlab-block .output {
  color: #9ec5e0;
}
.matlab-block .keyword {
  color: #c586c0;
}
.matlab-block .string {
  color: #ce9178;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  margin: 1.25rem 0;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
th {
  background: var(--bg);
  font-weight: 700;
  color: var(--ink);
}
tr:hover {
  background: #faf9f7;
}

/* ===== Figures ===== */
figure {
  margin: 1.5rem 0;
  text-align: center;
}
figure img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.chart-figure {
  margin: 1.5rem 0;
}
.chart-figure figcaption {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.75rem;
}

/* ===== Chapter Nav ===== */
.chapter-nav {
  margin: 3rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.chapter-nav .prev-chapter,
.chapter-nav .next-chapter {
  display: block;
  padding: 0.9rem 1.25rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  transition: background 0.2s;
}
.chapter-nav .prev-chapter {
  color: var(--muted);
  border: 1px solid var(--rule);
}
.chapter-nav .next-chapter {
  color: var(--accent);
  border: 1px solid var(--accent);
  font-weight: 600;
}
.chapter-nav .next-chapter:hover {
  background: var(--accent-light);
}
.chapter-nav .nav-label {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.2rem;
}

/* ===== Footer ===== */
.site-footer {
  background: var(--hero-bg);
  color: #b8b4ae;
  text-align: center;
  padding: 2rem 1.5rem;
  margin-top: 3rem;
  font-size: 0.85rem;
}
.site-footer p {
  color: #b8b4ae;
  margin-bottom: 0.4rem;
}

/* ===== Back to Top ===== */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 100;
}
.back-to-top.visible {
  opacity: 1;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 1.9rem;
  }
  .chapter-hero h1 {
    font-size: 1.7rem;
  }
  .chapter-grid {
    grid-template-columns: 1fr;
  }
  .plan-grid {
    grid-template-columns: 1fr;
  }
  .container {
    padding: 0 1rem;
  }
}

/* ===== Print ===== */
@media print {
  .back-to-top { display: none; }
  .brand-bar { display: none; }
  .chapter-nav { display: none; }
}
