:root {
  --paper: #f8f8f8;
  --paper-warm: #f4f4f2;
  --ink: #444444;
  --heading: #535353;
  --blue: #2052bb;
  --link: #0181eb;
  --red: #e92525;
  --yellow: #ebbc3f;
  --sky: #4797d9;
  --purple: #985fde;
  --line: #deded8;
  --white: #ffffff;
  --font-body: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-code: Menlo, Monaco, Consolas, "Microsoft YaHei", monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 82px; }
body {
  margin: 0;
  min-width: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.75;
}
button, input { font: inherit; }
button, a, input, summary { -webkit-tap-highlight-color: transparent; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 4px; }
a:hover { color: var(--blue); }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 4px; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; padding: 8px 14px; background: var(--white); color: var(--blue); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }

.manual-banner { background: var(--blue); color: var(--paper); }
.banner-inner { width: min(100% - 40px, 1120px); margin: 0 auto; padding: 28px 0 54px; }
.banner-topline { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 52px; font-family: var(--font-code); font-size: 12px; letter-spacing: .08em; }
.banner-topline a { color: var(--paper); }
.banner-topline a:hover { color: var(--yellow); }
.eyebrow, .lesson-number, .demo-label, .readout-kicker { margin: 0 0 12px; font-family: var(--font-code); font-size: 12px; font-weight: 600; letter-spacing: .12em; }
.banner-inner h1 { max-width: 16ch; margin: 0; color: var(--white); font-size: clamp(38px, 6.4vw, 72px); line-height: 1.12; letter-spacing: -.045em; }
.banner-intro { max-width: 46rem; margin: 28px 0 38px; color: #f8f8f8; font-size: 18px; line-height: 1.8; }
.manual-facts { display: flex; flex-wrap: wrap; gap: 28px 56px; margin: 0; padding-top: 22px; border-top: 1px solid rgb(255 255 255 / .35); }
.manual-facts div { display: flex; align-items: baseline; gap: 10px; }
.manual-facts dt { color: #f8f8f8; font-size: 12px; }
.manual-facts dd { margin: 0; color: var(--white); font-family: var(--font-code); font-size: 14px; }

.chapter-nav { position: sticky; top: 0; z-index: 20; background: rgb(248 248 248 / .96); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.chapter-nav-inner { display: flex; width: min(100% - 32px, 1120px); margin: 0 auto; overflow-x: auto; scrollbar-width: thin; }
.chapter-nav a { flex: 0 0 auto; min-height: 56px; display: inline-flex; align-items: center; padding: 0 17px; color: var(--heading); font-size: 13px; font-weight: 600; text-decoration: none; border-bottom: 3px solid transparent; }
.chapter-nav a:first-child { padding-left: 0; }
.chapter-nav a:hover, .chapter-nav a.is-current { color: var(--blue); border-bottom-color: var(--blue); }

.manual { padding-bottom: 48px; }
.reading-note { width: min(100% - 40px, 44rem); margin: 0 auto; padding: 24px 0; color: var(--heading); font-size: 14px; border-bottom: 1px solid var(--line); }
.lesson { width: min(100% - 40px, 44rem); margin: 0 auto; padding: 70px 0; border-bottom: 1px solid var(--line); }
.lesson-wide { width: min(100% - 40px, 1080px); }
.lesson-wide > p, .lesson-wide > h2, .lesson-wide > h3, .lesson-wide > .lesson-number, .lesson-wide > .table-wrap, .lesson-wide > .callout, .lesson-wide > .warning-box, .lesson-wide > .check-list { max-width: 44rem; margin-left: auto; margin-right: auto; }
.lesson-number { color: var(--blue); }
h2 { margin: 0 0 24px; color: var(--heading); font-size: clamp(29px, 4vw, 39px); line-height: 1.28; letter-spacing: -.025em; }
h3 { margin: 42px 0 14px; color: var(--heading); font-size: 21px; line-height: 1.4; }
p { margin: 16px 0; }
strong { color: var(--heading); font-weight: 650; }
code { padding: .12em .35em; background: #eaeaea; border-radius: 4px; color: #373737; font-family: var(--font-code); font-size: .82em; overflow-wrap: anywhere; }
pre { max-width: 100%; margin: 12px 0 0; padding: 14px 16px; overflow-x: auto; background: #eaeaea; border: 2px solid #e2e2de; border-radius: 8px; line-height: 1.6; }
pre code { padding: 0; background: transparent; font-size: 13px; }
.text-link { display: inline-block; font-weight: 650; }
.caption { color: #6d6d68; font-size: 13px; line-height: 1.65; }

.action-list, .experiment-steps, .roadmap { margin: 24px 0; padding: 0; list-style: none; }
.action-list > li { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 16px; padding: 22px 0; border-top: 1px solid var(--line); }
.action-list > li > span { display: grid; place-items: center; width: 30px; height: 30px; background: var(--blue); color: var(--white); border-radius: 50%; font-family: var(--font-code); font-size: 13px; }
.action-list p { margin: 4px 0; }
.callout, .warning-box { margin: 30px 0; padding: 22px 0 22px 24px; border-left: 4px solid var(--sky); }
.callout p, .warning-box { font-size: 15px; }
.warning-box { border-left-color: var(--red); }
.table-wrap { width: 100%; margin: 24px 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.6; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--heading); font-size: 12px; font-weight: 650; white-space: nowrap; }
td:first-child { color: var(--heading); font-weight: 600; }
.record-table td:not(:first-child) { color: #85857e; font-size: 12px; white-space: nowrap; }

.concept-list, .metric-definitions { margin: 30px 0; }
.concept-list > div, .metric-definitions > div { display: grid; grid-template-columns: 120px 1fr; gap: 20px; padding: 17px 0; border-top: 1px solid var(--line); }
.concept-list dt, .metric-definitions dt { color: var(--blue); font-weight: 650; }
.concept-list dd, .metric-definitions dd { margin: 0; }
.equation { margin: 28px 0; padding: 20px 16px; background: #efefeb; color: var(--heading); text-align: center; font-family: var(--font-code); font-size: clamp(15px, 2.2vw, 21px); line-height: 1.9; overflow-wrap: anywhere; }

.demo { margin: 32px auto 20px; background: var(--white); border: 1px solid #eaeaea; box-shadow: 0 0 0 3px #efefeb; }
.pipeline-demo { padding: 28px clamp(16px, 3vw, 34px) 22px; }
.pipeline { --step: 0; position: relative; padding: 8px 0 20px; }
.pipeline[data-step="1"] { --step: 1; }
.pipeline[data-step="2"] { --step: 2; }
.pipeline[data-step="3"] { --step: 3; }
.pipeline[data-step="4"] { --step: 4; }
.pipeline[data-step="5"] { --step: 5; }
.pipeline[data-step="6"] { --step: 6; }
.flow-line { position: absolute; top: 29px; left: 7.142%; right: 7.142%; height: 2px; background: #d5d5d0; }
.flow-token { position: absolute; top: 50%; left: calc(var(--step) * 100% / 6); width: 15px; height: 15px; background: var(--red); border: 3px solid var(--white); box-shadow: 0 0 0 1px var(--red); border-radius: 50%; transform: translate(-50%, -50%); transition: left 650ms cubic-bezier(.2, .75, .25, 1); }
.pipeline-nodes { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin: 0; padding: 0; list-style: none; }
.pipeline-nodes li { display: grid; justify-items: center; gap: 10px; color: #74746f; font-size: 13px; }
.pipeline-nodes li > span { display: grid; place-items: center; width: 42px; height: 42px; background: var(--paper); border: 1px solid #c8c8c2; border-radius: 50%; font-family: var(--font-code); font-size: 11px; transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease; }
.pipeline-nodes li.is-complete > span { background: var(--blue); border-color: var(--blue); color: var(--white); }
.pipeline-nodes li.is-active { color: var(--red); }
.pipeline-nodes li.is-active > span { background: var(--red); border-color: var(--red); color: var(--white); }
.demo-readout { min-height: 158px; padding: 28px 0 18px; text-align: center; }
.readout-kicker { color: var(--blue); }
.demo-readout h3 { margin: 0 0 8px; font-size: 25px; }
.demo-readout p:last-child { max-width: 50ch; margin: 0 auto; }
.demo-controls { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.demo button, .quiz-submit { min-height: 44px; padding: 9px 17px; background: var(--white); color: var(--blue); border: 1px solid var(--blue); border-radius: 3px; font-size: 14px; font-weight: 650; }
.demo button:hover, .quiz-submit:hover { background: #edf2fb; }
.demo button.primary-control, .quiz-submit { background: var(--blue); color: var(--white); }
.demo button.primary-control:hover, .quiz-submit:hover { background: #173f90; }

.timeline-demo { padding: 26px clamp(16px, 3vw, 30px); }
.timeline-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.timeline-heading h3 { margin: 0; font-size: 19px; }
.demo-label { display: block; color: var(--blue); }
.time-cells { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.time-cell { min-width: 0; padding: 18px 8px; text-align: center; border: 2px solid transparent; transition: background-color 240ms ease, border-color 240ms ease, transform 240ms ease; }
.time-cell small, .time-cell span { display: block; font-size: 11px; line-height: 1.45; }
.time-cell strong { display: block; margin: 8px 0; font-family: var(--font-code); font-size: 22px; }
.time-cell.train { background: #e7eff9; color: #27476e; }
.time-cell.predict { background: #faf0d4; border-color: var(--yellow); color: #58440c; }
.time-cell.future { background: #efefec; color: #777770; }
.timeline-explanation { min-height: 58px; margin: 22px 0 0; padding-top: 18px; border-top: 1px solid var(--line); font-size: 14px; }
.timeline-demo.is-leaky .time-cell.future { background: #fbe5e5; border-color: var(--red); color: #8f1d1d; transform: translateY(-6px); }
.timeline-demo.is-leaky .time-cell.train { opacity: .58; }
.timeline-demo.is-leaky #timeline-mode-title { color: var(--red); }
.check-list { padding-left: 24px; }
.check-list li { margin: 12px 0; padding-left: 5px; }
.check-list li::marker { color: var(--blue); }

.network-demo { overflow: hidden; }
#network-svg { display: block; width: 100%; height: auto; background: var(--paper-warm); }
.synapses line { stroke: #979797; stroke-width: 1.15; opacity: .32; }
.input-nodes circle { fill: var(--sky); stroke: var(--white); stroke-width: 3; }
.hidden-nodes circle { fill: var(--yellow); stroke: var(--white); stroke-width: 3; }
.output-node { fill: var(--red); stroke: var(--white); stroke-width: 4; }
.svg-labels { fill: var(--heading); font-family: var(--font-body); font-size: 14px; }
.network-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 24px; }
.network-footer p { margin: 0; color: #6c6c66; font-size: 13px; }
.network-footer button { flex: 0 0 auto; }
.network-demo.is-running .synapses line { stroke: var(--blue); stroke-dasharray: 7 8; opacity: .85; animation: signal-flow 850ms linear 2; }
.network-demo.is-running .hidden-nodes circle { animation: node-pulse 650ms ease 380ms 2; }
.network-demo.is-running .output-node { animation: node-pulse 650ms ease 760ms 2; }
@keyframes signal-flow { to { stroke-dashoffset: -30; } }
@keyframes node-pulse { 50% { stroke: var(--purple); stroke-width: 8; } }

.parameter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 44rem; margin: 24px auto; border-top: 1px solid var(--line); }
.parameter-grid > div { padding: 16px 12px 16px 0; border-bottom: 1px solid var(--line); }
.parameter-grid span, .parameter-grid strong { display: block; }
.parameter-grid span { color: #73736d; font-size: 12px; }
.parameter-grid strong { margin-top: 4px; font-family: var(--font-code); font-size: 14px; }
.experiment-steps { counter-reset: experiment; }
.experiment-steps li { padding: 14px 0; border-top: 1px solid var(--line); }
.metric-definitions > div { grid-template-columns: 100px 1fr; }
.lesson details { border-top: 1px solid var(--line); }
.lesson details:last-of-type { border-bottom: 1px solid var(--line); }
.lesson summary { position: relative; padding: 19px 34px 19px 0; color: var(--heading); font-weight: 650; cursor: pointer; list-style: none; }
.lesson summary::-webkit-details-marker { display: none; }
.lesson summary::after { content: "+"; position: absolute; right: 4px; color: var(--blue); font-family: var(--font-code); font-size: 22px; }
.lesson details[open] summary::after { content: "−"; }
.lesson details p { margin-top: 0; padding-bottom: 20px; }
.roadmap > li { display: grid; grid-template-columns: 74px 1fr; gap: 18px; padding: 22px 0; border-top: 1px solid var(--line); }
.roadmap > li > span { color: var(--blue); font-family: var(--font-code); font-size: 12px; font-weight: 650; }
.roadmap p { margin: 5px 0 0; }
.reference-list { padding-left: 20px; font-size: 14px; }
.reference-list li { margin: 8px 0; }

.quiz-section { border-bottom: 0; }
.quiz-section fieldset { margin: 28px 0; padding: 0; border: 0; }
.quiz-section legend { margin-bottom: 12px; color: var(--heading); font-weight: 650; }
.quiz-section fieldset label { display: block; margin: 8px 0; padding: 12px 14px; background: #efefeb; border: 2px solid transparent; cursor: pointer; }
.quiz-section fieldset label:has(input:checked) { background: #e7eff9; border-color: var(--sky); }
.quiz-section input { width: 18px; height: 18px; margin: 0 10px 0 0; vertical-align: -3px; accent-color: var(--blue); }
.quiz-submit { margin-top: 4px; }
.quiz-feedback { min-height: 56px; padding: 16px 0; color: var(--heading); font-size: 14px; }
.quiz-feedback.is-success { color: #205b36; }
.quiz-feedback.is-retry { color: #9b2828; }
.glossary { border-top: 1px solid var(--line); }
.manual-end { padding: 24px 0; color: var(--heading); font-size: 19px; }
.manual-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 30px; padding: 30px max(20px, calc((100% - 1120px) / 2)); background: #161616; color: #f8f8f8; font-size: 13px; }
.manual-footer a { color: #f8f8f8; }
.manual-footer p { flex-basis: 100%; margin: 0; color: #c4c4bf; }

.qlib-lesson-demo { padding: 28px clamp(16px, 3vw, 30px) 22px; }
.qlib-split-track { position: relative; display: grid; grid-template-columns: 3fr 1fr 1fr; min-height: 124px; gap: 4px; }
.qlib-split-track > div { display: grid; place-content: center; gap: 5px; padding: 12px; text-align: center; border: 2px solid transparent; transition: opacity 240ms ease, border-color 240ms ease, transform 240ms ease; }
.split-train { background: #e7eff9; color: #27476e; }
.split-valid { background: #faf0d4; color: #58440c; }
.split-test { background: #e8f1e9; color: #205b36; }
.qlib-split-track strong, .qlib-split-track span { display: block; }
.qlib-split-track strong { color: currentColor; font-family: var(--font-code); font-size: 16px; }
.qlib-split-track div span { font-size: 12px; }
.split-cursor { position: absolute; left: 0; bottom: -15px; width: 60%; height: 3px; background: var(--blue); transition: width 480ms cubic-bezier(.2, .75, .25, 1), left 480ms cubic-bezier(.2, .75, .25, 1); }
.qlib-lesson-demo[data-phase="valid"] .split-cursor { left: 60%; width: 20%; }
.qlib-lesson-demo[data-phase="test"] .split-cursor { left: 80%; width: 20%; }
.qlib-lesson-demo[data-phase="train"] .split-valid, .qlib-lesson-demo[data-phase="train"] .split-test,
.qlib-lesson-demo[data-phase="valid"] .split-train, .qlib-lesson-demo[data-phase="valid"] .split-test,
.qlib-lesson-demo[data-phase="test"] .split-train, .qlib-lesson-demo[data-phase="test"] .split-valid { opacity: .36; }
.qlib-lesson-demo[data-phase="valid"] .split-valid, .qlib-lesson-demo[data-phase="test"] .split-test { transform: translateY(-5px); border-color: currentColor; }
.qlib-phase-copy { min-height: 174px; padding: 38px 0 16px; text-align: center; }
.qlib-phase-copy h3 { margin: 0 0 10px; font-size: 24px; }
.qlib-phase-copy p:last-child { max-width: 53ch; margin: 0 auto; font-size: 14px; }
.engine-comparison td:first-child { white-space: nowrap; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .banner-inner { padding-bottom: 40px; }
  .banner-topline { padding-bottom: 38px; }
  .lesson, .lesson-wide { padding: 54px 0; }
  .pipeline { padding: 8px 0 8px; }
  .pipeline-nodes { grid-template-columns: 1fr; gap: 8px; }
  .pipeline-nodes li { display: flex; align-items: center; gap: 12px; }
  .pipeline-nodes li > span { width: 38px; height: 38px; flex: 0 0 auto; }
  .flow-line { top: 27px; bottom: 27px; left: 19px; right: auto; width: 2px; height: auto; }
  .flow-token { top: calc(var(--step) * 100% / 6); left: 50%; transition: top 650ms cubic-bezier(.2, .75, .25, 1); }
  .demo-readout { min-height: 142px; }
  .time-cells { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .timeline-heading, .network-footer { align-items: flex-start; flex-direction: column; }
  .network-footer button { width: 100%; }
  .svg-labels { font-size: 16px; }
}

@media (max-width: 520px) {
  .banner-inner, .lesson, .lesson-wide, .reading-note { width: min(100% - 30px, 44rem); }
  .banner-inner h1 { font-size: 38px; }
  .banner-intro { font-size: 16px; }
  .manual-facts { gap: 14px 26px; }
  .manual-facts div { display: block; }
  .chapter-nav-inner { width: calc(100% - 16px); }
  .chapter-nav a { padding: 0 12px; }
  .concept-list > div, .metric-definitions > div { grid-template-columns: 1fr; gap: 4px; }
  .parameter-grid { grid-template-columns: 1fr; }
  .demo-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .demo-controls .primary-control { grid-column: 1 / -1; grid-row: 1; }
  .timeline-heading { margin-bottom: 18px; }
  .time-cell { padding: 12px 4px; }
  .time-cell strong { font-size: 18px; }
  #network-svg { min-height: 240px; }
  .roadmap > li { grid-template-columns: 58px 1fr; gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  .chapter-nav, .demo-controls, .network-footer button, .quiz-section, .manual-footer, .skip-link { display: none; }
  .manual-banner { background: var(--white); color: #000; }
  .banner-inner h1, .banner-intro, .manual-facts dd, .manual-facts dt { color: #000; }
  .banner-topline { padding-bottom: 24px; }
  .lesson { break-inside: avoid; }
  body { background: var(--white); color: #000; }
}
