:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --accent: #0f766e;
  --accent-soft: #f0fdfa;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --purple: #6d28d9;
  --purple-soft: #f5f3ff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Top Navbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
}

.nav-links {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-links a {
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav-links a:hover {
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
}

.nav-links a.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* Layout */
.container {
  max-width: 1060px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.hero {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #f8fafc;
  border-radius: 16px;
  padding: 2.25rem 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
}

.hero-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.22);
  color: #93c5fd;
  margin-bottom: 0.75rem;
}

.hero-tag.elective {
  background: rgba(167, 139, 250, 0.22);
  color: #ddd6fe;
}

.hero h1 {
  margin: 0 0 0.6rem;
  font-size: 1.85rem;
  line-height: 1.3;
}

.hero p {
  margin: 0;
  color: #cbd5e1;
  max-width: 780px;
}

.hero-meta {
  margin-top: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.status-btn {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.status-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.status-btn.done {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
  font-weight: 600;
}

/* Cards & Sections */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin-top: 0;
  font-size: 1.32rem;
  color: var(--text);
  border-bottom: 2px solid var(--surface-alt);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.card h3 {
  font-size: 1.08rem;
  color: #1e293b;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

/* Callout Boxes */
.callout {
  border-left: 4px solid var(--primary);
  background: var(--primary-soft);
  padding: 0.9rem 1.15rem;
  border-radius: 0 8px 8px 0;
  margin: 1rem 0;
}

.callout.theorem {
  border-left-color: var(--purple);
  background: var(--purple-soft);
}

.callout.tip {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.callout.warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.callout-title {
  font-weight: 700;
  margin-bottom: 0.3rem;
  display: block;
}

/* Syllabus Cards on index.html */
.chapter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow);
}

.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.chapter-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chapter-card h3 {
  margin: 0.35rem 0 0.5rem;
  font-size: 1.12rem;
}

.chapter-card p {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.chapter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--surface-alt);
}

.badge {
  font-size: 0.75rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
}

.badge-core {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-elective {
  background: var(--purple-soft);
  color: var(--purple);
}

.badge-done {
  background: #dcfce7;
  color: #15803d;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

/* Interactive Simulation Canvas */
.sim-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin: 1rem 0;
}

.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.85rem;
}

.sim-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.sim-control input[type="range"] {
  width: 120px;
}

.sim-control select {
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
}

canvas.sim-canvas {
  width: 100%;
  height: 280px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
}

.sim-stats {
  margin-top: 0.6rem;
  font-size: 0.86rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Code Block */
.code-wrap {
  position: relative;
  margin: 1rem 0;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e293b;
  color: #cbd5e1;
  padding: 0.45rem 0.9rem;
  border-radius: 8px 8px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
}

.copy-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #f8fafc;
  padding: 0.2rem 0.6rem;
  border-radius: 5px;
  font-size: 0.75rem;
  cursor: pointer;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

pre {
  margin: 0;
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 0 0 8px 8px;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.55;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

/* Exercises */
.exercise-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin-bottom: 0.9rem;
  background: #fff;
}

.exercise-item p {
  margin: 0 0 0.6rem;
}

.solution-box {
  display: none;
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface-alt);
  border-radius: 8px;
  font-size: 0.94rem;
}

.solution-box.open {
  display: block;
}

/* Notes */
.notes-area {
  width: 100%;
  min-height: 130px;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.6;
  resize: vertical;
}

.notes-status {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 0.35rem;
}

/* Chapter Footer Nav */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

table.clean-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.85rem 0;
  font-size: 0.92rem;
}

table.clean-table th,
table.clean-table td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: left;
}

table.clean-table th {
  background: var(--surface-alt);
  font-weight: 600;
}

.progress-bar-wrap {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  height: 10px;
  width: 220px;
  overflow: hidden;
}

.progress-bar-fill {
  background: #10b981;
  height: 100%;
  width: 0%;
  transition: width 0.3s ease;
}

/* Beginner-Friendly Components */
.plain-intro {
  background: linear-gradient(135deg, #f0fdfa 0%, #eff6ff 100%);
  border: 1px solid #bae6fd;
  border-left: 5px solid #0284c7;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.plain-intro h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  color: #0369a1;
  border: none;
  padding: 0;
}

.glossary-details {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.glossary-details summary {
  cursor: pointer;
  font-weight: 700;
  color: #1e293b;
  font-size: 1rem;
  user-select: none;
}

.glossary-details[open] summary {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--surface-alt);
}

.formula-decode {
  background: #f8fafc;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  padding: 0.85rem 1.1rem;
  margin: 0.75rem 0 1rem;
  font-size: 0.92rem;
}

.formula-decode strong.decode-title {
  display: block;
  color: #334155;
  margin-bottom: 0.35rem;
}

.pitfall-box {
  background: #fef2f2;
  border-left: 4px solid #ef4444;
  border-radius: 0 8px 8px 0;
  padding: 0.85rem 1.1rem;
  margin: 1rem 0;
  font-size: 0.94rem;
}

.pitfall-box .callout-title {
  color: #b91c1c;
}

.level-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.level-must {
  background: #dcfce7;
  color: #15803d;
}

.level-core {
  background: #dbeafe;
  color: #1d4ed8;
}

.level-adv {
  background: #f3e8ff;
  color: #6d28d9;
}

/* Teacher Key Point & Beginner Rescue Styles */
.level-teacher {
  background: linear-gradient(135deg, #dc2626 0%, #ea580c 100%);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25);
}

.teacher-banner {
  background: linear-gradient(135deg, #fff1f2 0%, #fff7ed 100%);
  border: 1px solid #fecdd3;
  border-left: 5px solid #e11d48;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.teacher-banner h2 {
  margin: 0 0 0.5rem;
  font-size: 1.18rem;
  color: #be123c;
  border: none;
  padding: 0;
}

.teacher-focus-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 5px solid #d97706;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

.teacher-focus-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 0.45rem;
  font-size: 1rem;
}

.noob-rescue {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-left: 5px solid #16a34a;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

.noob-rescue-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  color: #15803d;
  margin-bottom: 0.4rem;
  font-size: 0.98rem;
}

.proof-walkthrough {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  margin: 1rem 0;
}

.proof-walkthrough-title {
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.75rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.proof-step {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid #e2e8f0;
  align-items: center;
}

.proof-step:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.proof-math {
  background: #ffffff;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  overflow-x: auto;
}

.proof-explain {
  font-size: 0.9rem;
  color: #334155;
}

.hw-card {
  background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
  border: 1px solid #d8b4fe;
  border-left: 5px solid #7e22ce;
  border-radius: 10px;
  padding: 1.1rem 1.3rem;
  margin: 1.1rem 0;
}

.hw-card-title {
  font-weight: 700;
  color: #6b21a8;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.typo-alert {
  background: #fff1f2;
  border: 1px dashed #f43f5e;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin: 0.65rem 0;
  font-size: 0.9rem;
  color: #881337;
}

.note-order-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.note-order-item {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  font-size: 0.86rem;
}

.note-order-item strong {
  display: block;
  color: var(--primary-dark);
  margin-bottom: 0.25rem;
}

.note-img-preview {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  margin-top: 0.45rem;
  cursor: pointer;
}

.toc-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.toc-pill {
  background: #ffffff;
  border: 1px solid #fecdd3;
  color: #be123c;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  transition: all 0.15s;
}

.toc-pill:hover {
  background: #ffe4e6;
  text-decoration: none;
}

@media (max-width: 720px) {
  .proof-step {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }
}

@media (max-width: 640px) {
  .hero {
    padding: 1.5rem 1.25rem;
  }
  .card {
    padding: 1.15rem 1rem;
  }
}
