/* ============================================================
   理解深度学习 · 交互版 — 设计系统
   Direction: Learning Platform Friendly / Theme: light
   Tokens from DESIGN.md
   ============================================================ */

:root {
  --canvas: #F5F7FF;
  --surface: #FFFFFF;
  --surface-alt: #E8ECFF;
  --text: #20233A;
  --muted: #6B7280;
  --accent: #4F46E5;
  --accent-strong: #4338CA;
  --accent-soft: #EEF0FE;
  --border: #D7DCF2;

  --good: #059669;
  --good-soft: #E7F8F1;
  --warn: #D97706;
  --warn-soft: #FEF4E4;
  --bad: #DC2626;
  --bad-soft: #FDECEC;

  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(32, 35, 58, 0.05);
  --shadow-md: 0 4px 16px rgba(79, 70, 229, 0.08);
  --shadow-lg: 0 12px 40px rgba(32, 35, 58, 0.10);

  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "JetBrains Mono", Menlo, monospace;

  --content-w: 840px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(79, 70, 229, 0.18); }

h1, h2, h3, h4 {
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: -0.01em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }

code, kbd {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1em 0.4em;
}

/* ---------------- 顶部导航 ---------------- */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-nav-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  color: var(--text);
  white-space: nowrap;
}
.site-logo:hover { text-decoration: none; }
.site-logo .logo-dot {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8B5CF6);
  display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 800;
}

.site-nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav-links::-webkit-scrollbar { display: none; }

.site-nav-links a {
  color: var(--muted);
  font-size: 14px;
  padding: 6px 11px;
  border-radius: 8px;
  white-space: nowrap;
}
.site-nav-links a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.site-nav-links a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* 阅读进度条 */
.read-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #8B5CF6);
  z-index: 60;
  transition: width 0.1s linear;
}

/* ---------------- 页面容器 ---------------- */

.page {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.page-wide {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

/* ---------------- 章节正文排版 ---------------- */

.chapter-head { margin-bottom: 32px; }

.chapter-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.chapter-head h1 {
  font-size: clamp(28px, 4.5vw, 40px);
  margin: 0 0 12px;
}

.chapter-head .lede {
  font-size: 18px;
  color: var(--muted);
  margin: 0;
}

.page h2 {
  font-size: 26px;
  margin: 56px 0 16px;
  padding-top: 8px;
}
.page h3 {
  font-size: 20px;
  margin: 36px 0 12px;
}
.page p { margin: 14px 0; }
.page ul, .page ol { padding-left: 24px; }
.page li { margin: 6px 0; }

.math-inline {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  white-space: nowrap;
}

.formula {
  display: block;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 19px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin: 20px 0;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.formula sub, .formula sup { font-size: 0.68em; }

/* ---------------- 提示框（callout） ---------------- */

.callout {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 18px;
  margin: 22px 0;
  font-size: 15.5px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.callout .callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}
.callout p:last-child { margin-bottom: 0; }
.callout p:first-of-type { margin-top: 0; }

.callout-intuition { background: var(--accent-soft); border-color: #C9D0F5; }
.callout-intuition .callout-title { color: var(--accent-strong); }

.callout-pitfall { background: var(--warn-soft); border-color: #F3DFB8; }
.callout-pitfall .callout-title { color: var(--warn); }

.callout-math { background: var(--surface-alt); border-color: var(--border); }
.callout-math .callout-title { color: var(--text); }

.callout-good { background: var(--good-soft); border-color: #BDE8D7; }
.callout-good .callout-title { color: var(--good); }

/* ---------------- 交互演示卡片 ---------------- */

.demo {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  margin: 28px 0;
  overflow: hidden;
}

.demo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 22px 0;
}
.demo-head h4 {
  margin: 0;
  font-size: 16px;
}
.demo-head .demo-tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.demo-body {
  padding: 14px 22px 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 760px) {
  .demo-body.has-side {
    grid-template-columns: minmax(0, 1fr) 260px;
  }
}

.demo canvas, .demo svg.demo-figure {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  background: var(--canvas);
  border: 1px solid var(--border);
  touch-action: manipulation;
}

.demo-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.demo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.demo-row.wrap-gap { row-gap: 8px; }

.demo-note {
  font-size: 13.5px;
  color: var(--muted);
  margin: 10px 2px 0;
}

/* ---------------- 控件 ---------------- */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-strong); color: #fff; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-group { display: inline-flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.btn-group .btn { border: 0; border-radius: 0; box-shadow: none; }
.btn-group .btn + .btn { border-left: 1px solid var(--border); }
.btn-group .btn.on { background: var(--accent); color: #fff; }
.btn-group .btn.on:hover { color: #fff; }

.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.ctl label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
}
.ctl label output {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  font-size: 12.5px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(32, 35, 58, 0.3);
  margin-top: -7px;
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
}

select, input[type="number"] {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
}
select:focus, input[type="number"]:focus {
  outline: 2px solid rgba(79, 70, 229, 0.35);
  border-color: var(--accent);
}

/* 数值读出徽章 */
.readout {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  min-width: 86px;
}
.readout b {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text);
  font-weight: 700;
}
.readout.readout-accent b { color: var(--accent); }
.readout.readout-good b { color: var(--good); }
.readout.readout-bad b { color: var(--bad); }

/* ---------------- 静态配图 ---------------- */

.figure {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 26px 0;
  box-shadow: var(--shadow-sm);
}
.figure svg { display: block; width: 100%; height: auto; }
.figure figcaption {
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
  margin-top: 12px;
}

/* ---------------- 章节结尾导航 ---------------- */

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 64px;
}
.chapter-nav a {
  display: block;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.chapter-nav a:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow-md); }
.chapter-nav .cn-label { font-size: 12.5px; color: var(--muted); display: block; }
.chapter-nav .cn-title { font-weight: 700; }
.chapter-nav a.next { text-align: right; }
.chapter-nav a.disabled { opacity: 0.45; pointer-events: none; }

.mark-done {
  margin-top: 40px;
  display: flex;
  justify-content: center;
}

/* ---------------- 首页 ---------------- */

.hero {
  position: relative;
  border-radius: 26px;
  overflow: hidden;
  background: linear-gradient(150deg, #232147 0%, #3B2F8F 55%, #4F46E5 100%);
  color: #fff;
  margin-top: 28px;
  box-shadow: var(--shadow-lg);
}
.hero canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.55;
}
.hero-inner {
  position: relative;
  padding: clamp(40px, 7vw, 84px) clamp(24px, 5vw, 64px);
  max-width: 720px;
}
.hero .hero-kicker {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(34px, 5.6vw, 56px);
  margin: 0 0 16px;
  letter-spacing: -0.02em;
}
.hero p {
  font-size: clamp(16px, 2vw, 19px);
  color: rgba(255, 255, 255, 0.85);
  margin: 0 0 28px;
  max-width: 560px;
}
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.hero .btn { font-size: 15px; padding: 11px 22px; border-radius: 12px; }
.hero .btn-primary { background: #fff; color: var(--accent-strong); border-color: #fff; }
.hero .btn-primary:hover { background: #EEF0FE; color: var(--accent-strong); }
.hero .btn-ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: none;
}
.hero .btn-ghost:hover { border-color: #fff; color: #fff; }

.section-head { margin: 64px 0 24px; }
.section-head h2 { font-size: 28px; margin: 0 0 8px; }
.section-head p { color: var(--muted); margin: 0; }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.chapter-card {
  position: relative;
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
  text-decoration: none;
}
.chapter-card .cc-num {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}
.chapter-card h3 { font-size: 19px; margin: 8px 0 8px; }
.chapter-card p { font-size: 14.5px; color: var(--muted); margin: 0; line-height: 1.6; }
.chapter-card .cc-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.chapter-card .cc-badge {
  margin-left: auto;
  font-weight: 700;
  color: var(--good);
  background: var(--good-soft);
  padding: 3px 10px;
  border-radius: 999px;
  display: none;
}
.chapter-card.done .cc-badge { display: inline-block; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.feature-card .fc-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-size: 20px;
  margin-bottom: 14px;
}
.feature-card h3 { font-size: 17px; margin: 0 0 8px; }
.feature-card p { font-size: 14px; color: var(--muted); margin: 0; line-height: 1.65; }

.about-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  font-size: 15.5px;
  color: var(--text);
}
.about-block p { margin: 10px 0; }
.about-block .muted { color: var(--muted); font-size: 14px; }

/* ---------------- 页脚 ---------------- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 80px;
  background: var(--surface);
}
.site-footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: var(--muted);
}

/* ---------------- 小屏适配 ---------------- */

@media (max-width: 640px) {
  body { font-size: 16px; }
  .site-nav-inner { gap: 10px; }
  .chapter-nav { grid-template-columns: 1fr; }
  .chapter-nav a.next { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
