:root {
  --bg: #f7f7f3;
  --surface: #ffffff;
  --surface-2: #f1f3ef;
  --text: #172018;
  --muted: #5d685f;
  --line: #d9ded8;
  --accent: #0c6b58;
  --accent-strong: #075547;
  --accent-soft: #dff3eb;
  --accent-faint: #eff9f5;
  --warm: #a84c21;
  --warm-soft: #fae9df;
  --code-bg: #111813;
  --code-text: #e7f1ea;
  --shadow: 0 16px 44px rgba(16, 32, 24, .08);
  --radius: 16px;
  --reading-size: 1rem;
  --sidebar-width: 288px;
  --toc-width: 250px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0e1310;
  --surface: #151c18;
  --surface-2: #1c2520;
  --text: #eef5f0;
  --muted: #aab8af;
  --line: #334039;
  --accent: #68c7aa;
  --accent-strong: #95ddc6;
  --accent-soft: #193b31;
  --accent-faint: #132c25;
  --warm: #f39a6d;
  --warm-soft: #40271d;
  --code-bg: #080c09;
  --code-text: #e7f1ea;
  --shadow: 0 16px 44px rgba(0, 0, 0, .28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 999;
  left: 1rem;
  top: -5rem;
  padding: .65rem 1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
}
.skip-link:focus { top: 1rem; }

.topbar {
  position: sticky;
  z-index: 40;
  top: 0;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}
.reading-progress {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .1s linear;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px 4px 12px 4px;
  background: var(--accent);
  color: white;
  font-weight: 850;
  letter-spacing: -.04em;
}
.brand strong, .brand small { display: block; line-height: 1.18; }
.brand strong { font-size: .95rem; }
.brand small { margin-top: .16rem; color: var(--muted); font-size: .72rem; }
.top-actions { display: flex; gap: .35rem; margin-left: auto; }
.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--line); background: var(--surface); }

.layout {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
  max-width: 1640px;
  margin: 0 auto;
}
.sidebar {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  overflow: auto;
  padding: 1.2rem .85rem 2rem;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}
.course-progress { padding: .65rem .7rem 1rem; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; }
.progress-label strong { color: var(--text); }
.progress-track { height: 6px; margin-top: .55rem; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .25s ease; }
#chapter-nav { display: grid; gap: .22rem; }
.chapter-link {
  position: relative;
  display: grid;
  grid-template-columns: 23px minmax(0, 1fr);
  gap: .62rem;
  align-items: start;
  padding: .62rem .72rem;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  line-height: 1.35;
}
.chapter-link:hover { color: var(--text); background: var(--surface-2); }
.chapter-link.active { border-color: color-mix(in srgb, var(--accent) 24%, var(--line)); background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; }
.chapter-number {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
}
.chapter-link.complete .chapter-number { border-color: var(--accent); background: var(--accent); color: #fff; }
.sidebar-links { display: grid; gap: .4rem; margin: 1.2rem .65rem 0; padding-top: 1rem; border-top: 1px solid var(--line); }
.sidebar-links a, .sidebar-links button { padding: .18rem 0; border: 0; background: transparent; color: var(--muted); text-align: left; text-decoration: none; font-size: .78rem; cursor: pointer; }
.sidebar-links a:hover, .sidebar-links button:hover { color: var(--text); }

.lesson { min-width: 0; padding: clamp(1.6rem, 4vw, 3.8rem) clamp(1.3rem, 4.6vw, 4.5rem) 7rem; }
.lesson-inner { max-width: 940px; margin: 0 auto; }
.loading { padding: 3rem; color: var(--muted); text-align: center; }
.lesson-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 2rem;
  min-height: 330px;
  margin-bottom: 2rem;
  padding: clamp(1.5rem, 4vw, 2.8rem);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
  border-radius: 26px;
  background: var(--surface);
}
.hero-copy { position: relative; z-index: 2; align-self: center; }
.breadcrumb { margin: 0 0 .75rem; color: var(--accent); font-size: .76rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.lesson-title { max-width: 18ch; margin: 0; font-size: clamp(2.05rem, 4.2vw, 3.55rem); line-height: 1.08; letter-spacing: -.045em; }
.lesson-lead { max-width: 62ch; margin: 1rem 0 0; color: var(--muted); font-size: 1rem; }
.topic-chips { display: flex; flex-wrap: wrap; gap: .42rem; margin-top: 1.15rem; }
.topic-chips span { padding: .25rem .58rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: .72rem; font-weight: 750; }
.hero-visual { position: relative; display: grid; place-items: center; min-height: 220px; }
.hero-visual::before { content: ""; position: absolute; width: 154px; height: 154px; border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent); border-radius: 50%; }
.hero-visual::after { content: ""; position: absolute; width: 106px; height: 106px; border-radius: 50%; background: var(--accent-soft); }
.hero-index { position: relative; z-index: 2; color: var(--accent-strong); font-size: 3.35rem; font-weight: 850; letter-spacing: -.08em; font-variant-numeric: tabular-nums; }
.hero-visual i { position: absolute; z-index: 3; width: 11px; height: 11px; border: 3px solid var(--surface); border-radius: 50%; background: var(--accent); }
.hero-visual i:nth-of-type(1) { top: 24px; right: 22px; }
.hero-visual i:nth-of-type(2) { bottom: 34px; left: 13px; width: 16px; height: 16px; background: var(--warm); }
.hero-visual i:nth-of-type(3) { right: 0; bottom: 76px; width: 8px; height: 8px; }
.lesson-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; margin: 1.5rem 0 2rem; }
.meta-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .34rem .65rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface); font-size: .76rem; }
.complete-button { margin-left: auto; padding: .55rem .9rem; border: 1px solid var(--accent); border-radius: 10px; background: transparent; color: var(--accent); font-weight: 700; cursor: pointer; }
.complete-button:hover, .complete-button.done { background: var(--accent); color: white; }

.learning-objectives, .update-panel, .quiz-panel, .source-panel, .reflection-panel, .lab-panel {
  margin: 2rem 0;
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--line) 65%, transparent);
}
.learning-objectives { border-left: 4px solid var(--accent); }
.update-panel { border-left: 4px solid var(--warm); }
.panel-kicker, .eyebrow { margin: 0 0 .45rem; color: var(--accent); font-size: .72rem; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.update-panel .panel-kicker { color: var(--warm); }
.panel-title { margin: 0 0 .65rem; font-size: 1.16rem; }
.learning-objectives ol { margin: .65rem 0 0; padding-left: 1.3rem; }
.learning-objectives li + li { margin-top: .35rem; }

.lab-panel {
  position: relative;
  margin: 2.4rem 0 3rem;
  padding: clamp(1.2rem, 3vw, 1.8rem);
  overflow: hidden;
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
  background: var(--accent-faint);
}
.lab-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.lab-heading .panel-title { font-size: clamp(1.3rem, 3vw, 1.65rem); }
.lab-badge { padding: .28rem .52rem; border-radius: 999px; background: var(--accent); color: white; font-size: .64rem; font-weight: 900; letter-spacing: .12em; }
.lab-intro { max-width: 70ch; margin: .6rem 0 1.4rem; color: var(--muted); }
.prose > .lab-panel { font-size: 1rem; overflow-wrap: normal; }
.prose .lab-panel .panel-title { margin: 0 0 .65rem; padding: 0; border: 0; font-size: clamp(1.3rem, 3vw, 1.65rem); }
.live-formula {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .38rem;
  margin: 0 0 .65rem;
  padding: .85rem 1rem;
  overflow-x: auto;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
  border-radius: 12px;
  background: var(--surface);
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  white-space: nowrap;
}
.live-formula strong { color: var(--accent-strong); font-size: 1.08em; }
.formula-term { padding: .02rem .3rem; border-radius: 5px; background: var(--accent-soft); color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.formula-input { background: var(--warm-soft); color: var(--warm); }
.formula-explanation { margin: .55rem 0 1rem; color: var(--muted); font-size: .82rem; }
.lab-layout { display: grid; grid-template-columns: minmax(190px, .62fr) minmax(0, 1.38fr); gap: 1.25rem; align-items: stretch; }
.lab-controls, .diffusion-controls { display: flex; flex-direction: column; gap: .72rem; padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.range-control { display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .8rem; font-weight: 750; }
.range-control output { min-width: 3.6rem; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.lab-reset { align-self: flex-start; padding: .42rem .66rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: .74rem; cursor: pointer; }
.lab-reset:hover { border-color: var(--accent); color: var(--accent-strong); }
.lab-metric { display: grid; gap: .14rem; margin-top: auto; padding: .85rem; border-radius: 12px; background: var(--surface-2); }
.lab-metric span, .lab-metric small { color: var(--muted); font-size: .72rem; }
.lab-metric strong { color: var(--accent-strong); font-size: 1.65rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.lab-solved .lab-metric { outline: 2px solid var(--accent); }
.lab-canvas { min-width: 0; padding: .7rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.lab-canvas svg { display: block; width: 100%; height: auto; }
.chart-grid line, .signal-axis { stroke: var(--line); stroke-width: 1.5; }
.prediction-line { stroke: var(--accent); stroke-width: 5; stroke-linecap: round; }
.residuals line { stroke: var(--warm); stroke-width: 2.5; stroke-dasharray: 6 5; }
.data-points .point-hit { fill: transparent; stroke: transparent; }
.data-points .point-dot { fill: var(--text); stroke: var(--surface); stroke-width: 4; transition: r .15s ease, fill .15s ease; }
.data-points g { cursor: pointer; }
.data-points g.selected .point-dot { fill: var(--warm); r: 10px; }
.data-points g:focus-visible { outline: none; }
.data-points g:focus-visible .point-hit { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 2; }
.axis-label { fill: var(--muted); font-size: 18px; font-style: italic; }

.softmax-controls { justify-content: center; }
.probability-stage { display: grid; gap: 1rem; align-content: center; padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.probability-bars { display: grid; gap: .8rem; }
.probability-row { display: grid; grid-template-columns: 58px minmax(100px, 1fr) 58px; gap: .65rem; align-items: center; }
.probability-row > strong { display: grid; line-height: 1.1; }
.probability-row small { color: var(--accent); font-size: .58rem; font-weight: 800; }
.probability-row output { color: var(--text); text-align: right; font-size: .76rem; font-variant-numeric: tabular-nums; }
.probability-track { height: 22px; overflow: hidden; border-radius: 6px; background: var(--surface-2); }
.probability-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .16s ease; }

.convolution-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(190px, .75fr); gap: 1rem; }
.convolution-controls, .convolution-output-panel { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.convolution-controls fieldset, .return-toolbar fieldset { margin: 0 0 .8rem; padding: .65rem .8rem .85rem; border: 1px solid var(--line); border-radius: 11px; }
.convolution-controls legend, .return-toolbar legend { padding: 0 .25rem; color: var(--muted); font-size: .74rem; font-weight: 750; }
.matrix-pair { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(90px, .55fr); gap: 1rem; align-items: start; margin: .8rem 0; }
.matrix-pair > div > strong, .convolution-output-panel > strong { display: block; margin-bottom: .45rem; color: var(--muted); font-size: .75rem; }
.matrix-grid { display: grid; gap: .28rem; }
.matrix-4 { grid-template-columns: repeat(4, minmax(36px, 1fr)); }
.matrix-3 { grid-template-columns: repeat(3, minmax(42px, 1fr)); }
.matrix-2 { grid-template-columns: repeat(2, minmax(38px, 1fr)); }
.matrix-grid button, .matrix-grid span { display: grid; place-items: center; min-height: 42px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--text); font-size: .76rem; font-variant-numeric: tabular-nums; }
.matrix-grid button { cursor: pointer; }
.matrix-grid button.in-window { border-color: var(--warm); background: var(--warm-soft); }
.matrix-grid button.selected { outline: 3px solid var(--warm); outline-offset: 2px; }
#convolution-output button { background: color-mix(in srgb, var(--accent) var(--shade), var(--surface)); color: var(--text); font-weight: 800; }
.convolution-output-panel { display: flex; flex-direction: column; }
.convolution-output-panel .lab-metric { margin-top: 1rem; }

.return-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.return-toolbar .attention-temperature { align-content: center; }
.return-terms { display: grid; grid-template-columns: repeat(5, 1fr); gap: .55rem; min-height: 190px; margin: 1rem 0; padding: 1rem; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.return-term { display: grid; grid-template-rows: auto 1fr auto auto; gap: .25rem; min-width: 0; color: var(--muted); text-align: center; font-size: .68rem; }
.return-term strong { color: var(--accent-strong); font-size: .82rem; font-variant-numeric: tabular-nums; }
.return-term small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.return-bar-track { position: relative; align-self: stretch; min-height: 100px; overflow: hidden; border-radius: 7px; background: var(--surface-2); }
.return-bar-track i { position: absolute; right: 0; bottom: 0; left: 0; min-height: 3px; background: var(--accent); transition: height .16s ease; }

.attention-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.attention-toolbar fieldset, .attention-temperature { margin: 0; padding: .8rem 1rem 1rem; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.attention-toolbar legend { padding: 0 .25rem; color: var(--muted); font-size: .75rem; font-weight: 750; }
.segmented { display: flex; flex-wrap: wrap; gap: .35rem; }
.segmented button { padding: .4rem .68rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.segmented button.active { border-color: var(--accent); background: var(--accent); color: white; }
.attention-temperature { display: grid; gap: .5rem; }
.attention-stage { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 1rem; }
.attention-table-wrap { min-width: 0; overflow-x: auto; }
.attention-map { min-width: 500px; border-collapse: separate; border-spacing: .35rem; table-layout: fixed; }
.attention-map th { padding: .25rem; border: 0; background: transparent; color: var(--muted); text-align: center; font-size: .72rem; }
.attention-cell { height: 58px; padding: .2rem; border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line)); border-radius: 9px; background: color-mix(in srgb, var(--accent) var(--weight), var(--surface)); color: var(--text); text-align: center; font-size: .72rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.attention-cell.high-weight { color: white; }
.attention-cell.selected-row { outline: 2px solid var(--warm); outline-offset: 1px; }
.attention-stage .lab-metric { margin: 0; align-content: center; }

.diffusion-controls { display: grid; grid-template-columns: minmax(130px, .4fr) minmax(180px, 1fr) auto; align-items: center; margin-bottom: 1rem; }
.diffusion-controls .lab-reset { align-self: center; }
.coefficient-balance { display: flex; height: 9px; margin: -.2rem 0 .7rem; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.coefficient-balance span { transition: width .16s ease; }
#diffusion-signal-share { width: 100%; background: var(--accent); }
#diffusion-noise-share { width: 0; background: var(--warm); }
.clean-signal, .noisy-signal { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.clean-signal { stroke: var(--muted); stroke-width: 2.5; stroke-dasharray: 8 6; opacity: .55; }
.noisy-signal { stroke: var(--accent); stroke-width: 4; }
.signal-legend { display: flex; flex-wrap: wrap; gap: .8rem 1.2rem; align-items: center; padding: .25rem .45rem .45rem; color: var(--muted); font-size: .75rem; }
.signal-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.signal-legend i { width: 18px; height: 3px; border-radius: 99px; background: var(--muted); }
.signal-legend .legend-noisy { background: var(--accent); }
.signal-legend strong { margin-left: auto; color: var(--accent-strong); font-variant-numeric: tabular-nums; }

.prose { font-size: var(--reading-size); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { scroll-margin-top: 96px; color: var(--text); line-height: 1.25; letter-spacing: -.025em; }
.prose h1 { margin: 3.2rem 0 1rem; font-size: 2rem; }
.prose h2 { margin: 3rem 0 .85rem; padding-top: .6rem; border-top: 1px solid var(--line); font-size: 1.65rem; }
.prose h3 { margin: 2.2rem 0 .65rem; font-size: 1.28rem; }
.prose h4 { margin: 1.7rem 0 .55rem; font-size: 1.06rem; }
.prose p { margin: 1rem 0; }
.prose li + li { margin-top: .34rem; }
.prose blockquote { margin: 1.3rem 0; padding: .7rem 1rem; border-left: 4px solid var(--accent); background: var(--accent-soft); color: var(--text); }
.prose blockquote > :first-child { margin-top: 0; }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose img { display: block; max-width: 100%; height: auto; margin: 1.5rem auto; border-radius: 10px; box-shadow: var(--shadow); }
.prose hr { margin: 3rem 0; border: 0; border-top: 1px solid var(--line); }
.prose code { padding: .13em .35em; border-radius: 5px; background: var(--surface-2); font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .88em; }
.prose pre { position: relative; margin: 1.5rem 0; padding: 1.2rem; overflow: auto; border-radius: 13px; background: var(--code-bg); color: var(--code-text); line-height: 1.55; box-shadow: var(--shadow); }
.prose pre code { padding: 0; background: transparent; color: inherit; font-size: .85rem; }
.code-wrap { position: relative; }
.copy-code { position: absolute; z-index: 2; top: .55rem; right: .55rem; padding: .28rem .55rem; border: 1px solid rgba(255,255,255,.24); border-radius: 7px; background: rgba(0,0,0,.28); color: white; font-size: .7rem; cursor: pointer; }
.copy-code:hover { background: rgba(0,0,0,.55); }
.table-scroll { max-width: 100%; margin: 1.5rem 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .68rem .82rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.admonition { margin: 1.5rem 0; padding: .95rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.admonition-title { margin: -.95rem -1rem .75rem; padding: .55rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface-2); font-weight: 800; }
.headerlink { margin-left: .35rem; opacity: 0; text-decoration: none; }
h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .headerlink, .headerlink:focus { opacity: .6; }
.notebook-output summary { cursor: pointer; color: var(--muted); }

.glossary-term { position: relative; padding: 0 .08em; border: 0; border-bottom: 1px dotted var(--accent); background: transparent; color: inherit; font: inherit; cursor: help; }
.glossary-tooltip { position: fixed; z-index: 100; width: min(330px, calc(100vw - 2rem)); padding: .75rem .85rem; border: 1px solid var(--line); border-radius: 11px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: .82rem; line-height: 1.5; pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity .12s ease, transform .12s ease; }
.glossary-tooltip.show { opacity: 1; transform: translateY(0); }
.glossary-tooltip strong, .glossary-tooltip span { display: block; }
.glossary-tooltip span { margin-top: .18rem; opacity: .82; font-size: .73rem; }

.quiz-question { margin: .35rem 0 1rem; font-weight: 750; }
.quiz-options { display: grid; gap: .55rem; }
.quiz-option { display: grid; grid-template-columns: 22px 1fr; gap: .65rem; align-items: start; padding: .68rem .75rem; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.quiz-option:hover { background: var(--surface-2); }
.quiz-option.correct { border-color: var(--accent); background: var(--accent-soft); }
.quiz-option.incorrect { border-color: var(--warm); background: var(--warm-soft); }
.quiz-actions { display: flex; align-items: center; gap: .8rem; margin-top: 1rem; }
.primary-button { padding: .55rem .9rem; border: 0; border-radius: 9px; background: var(--accent); color: white; font-weight: 750; cursor: pointer; }
.primary-button:disabled { opacity: .5; cursor: not-allowed; }
.quiz-feedback { display: none; margin: .9rem 0 0; padding: .75rem .85rem; border-radius: 9px; background: var(--surface-2); }
.quiz-feedback.show { display: block; }

.reference-list { display: grid; gap: .8rem; margin-top: 1rem; }
.reference-card { padding: .85rem .95rem; border: 1px solid var(--line); border-radius: 11px; background: color-mix(in srgb, var(--surface) 75%, var(--warm-soft)); }
.reference-card h4 { margin: 0; font-size: .95rem; line-height: 1.4; }
.reference-card p { margin: .4rem 0 0; color: var(--muted); font-size: .82rem; }
.reference-card .reference-checked { font-size: .7rem; }
.reference-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .4rem; }
.ref-badge { padding: .15rem .4rem; border-radius: 999px; background: var(--warm-soft); color: var(--warm); font-size: .68rem; font-weight: 800; }
.ref-verified { color: var(--accent); }
.update-note { color: var(--muted); font-size: .82rem; }

.source-panel { color: var(--muted); font-size: .82rem; }
.source-panel code { overflow-wrap: anywhere; }
.reflection-prompt { margin: .5rem 0 0; font-weight: 650; }
.lesson-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2.5rem; }
.lesson-nav a { min-width: 0; padding: 1rem; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); text-decoration: none; }
.lesson-nav a:last-child { text-align: right; }
.lesson-nav small, .lesson-nav strong { display: block; }
.lesson-nav small { color: var(--muted); }
.lesson-nav strong { margin-top: .2rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toc-panel { padding: 2rem 1.2rem 2rem 1rem; }
.toc-sticky { position: sticky; top: 104px; }
#toc { display: grid; gap: .24rem; max-height: 58vh; overflow: auto; scrollbar-width: thin; }
#toc a { padding: .24rem .45rem; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: .76rem; line-height: 1.35; }
#toc a[data-level="3"] { padding-left: .95rem; }
#toc a[data-level="4"] { padding-left: 1.35rem; }
#toc a:hover, #toc a.active { border-left-color: var(--accent); color: var(--text); }
.chapter-meta { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .72rem; }
.chapter-meta p { margin: .2rem 0; }

.search-dialog { width: min(720px, calc(100vw - 2rem)); max-height: min(760px, calc(100vh - 3rem)); padding: 1.1rem; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.search-dialog::backdrop { background: rgba(8, 14, 10, .52); backdrop-filter: blur(4px); }
.search-dialog form { float: right; }
.dialog-close { width: 36px; height: 36px; border: 0; border-radius: 9px; background: var(--surface-2); color: var(--text); cursor: pointer; }
.search-dialog label { display: block; margin-bottom: .45rem; font-weight: 800; }
#search-input { width: calc(100% - 48px); padding: .78rem .9rem; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); color: var(--text); }
.search-results { display: grid; gap: .45rem; margin-top: 1rem; overflow-y: auto; }
.search-result { display: block; padding: .75rem .85rem; border: 1px solid transparent; border-radius: 11px; color: var(--text); text-decoration: none; }
.search-result:hover { border-color: var(--line); background: var(--surface-2); }
.search-result strong, .search-result span { display: block; }
.search-result span { margin-top: .22rem; color: var(--muted); font-size: .78rem; }
.search-empty { padding: 2rem; color: var(--muted); text-align: center; }
mark { padding: 0 .08em; border-radius: 3px; background: var(--warm-soft); color: var(--text); }

.toast { position: fixed; z-index: 120; right: 1.2rem; bottom: 1.2rem; padding: .7rem .9rem; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.mobile-only { display: none; }

/* Pygments token classes */
.codehilite .c, .codehilite .c1, .codehilite .cm { color: #8da399; }
.codehilite .k, .codehilite .kc, .codehilite .kd, .codehilite .kn { color: #a9d6ff; }
.codehilite .s, .codehilite .s1, .codehilite .s2 { color: #c8e6a0; }
.codehilite .m, .codehilite .mi, .codehilite .mf { color: #f1c38e; }
.codehilite .nf, .codehilite .nc { color: #f3a7bd; }
.codehilite .o, .codehilite .p { color: #d8e3dc; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .toc-panel { display: none; }
}
@media (max-width: 780px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { height: 64px; padding: 0 .7rem; }
  .brand-mark { width: 35px; height: 35px; }
  .brand strong { font-size: .84rem; }
  .brand small { display: none; }
  .layout { display: block; min-height: calc(100vh - 64px); }
  .sidebar { position: fixed; z-index: 60; inset: 64px auto 0 0; width: min(88vw, 330px); height: calc(100vh - 64px); transform: translateX(-105%); background: var(--bg); box-shadow: var(--shadow); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .lesson { padding: 2.1rem 1.1rem 5rem; }
  .lesson-title { max-width: none; font-size: clamp(1.9rem, 10vw, 2.8rem); }
  .lesson-hero { grid-template-columns: 1fr; min-height: 0; padding: 1.35rem; border-radius: 19px; }
  .hero-visual { position: absolute; top: .4rem; right: .65rem; min-height: 0; opacity: .16; }
  .hero-visual::before { width: 100px; height: 100px; }
  .hero-visual::after { width: 68px; height: 68px; }
  .hero-index { font-size: 2.2rem; }
  .hero-visual i { display: none; }
  .complete-button { width: 100%; margin-left: 0; }
  .lab-layout, .attention-stage, .attention-toolbar, .convolution-layout, .return-toolbar { grid-template-columns: 1fr; }
  .matrix-pair { grid-template-columns: minmax(150px, 1fr) minmax(88px, .55fr); }
  .diffusion-controls { grid-template-columns: 1fr; }
  .attention-cell { min-height: 48px; font-size: .64rem; }
  .research-summary { grid-template-columns: 1fr 1fr; }
  .lesson-nav { grid-template-columns: 1fr; }
  .lesson-nav a:last-child { text-align: left; }
  .search-dialog { padding: .85rem; }
}
@media print {
  .topbar, .sidebar, .toc-panel, .complete-button, .quiz-actions, .lesson-nav, .copy-code, .lab-reset, .math-explore-toggle, .math-explorer, input[type="range"] { display: none !important; }
  .layout { display: block; }
  .lesson { padding: 0; }
  .lesson-inner { max-width: none; }
  body { background: white; color: black; }
  .learning-objectives, .update-panel, .quiz-panel, .source-panel, .reflection-panel { break-inside: avoid; box-shadow: none; }
  a { color: black; text-decoration: underline; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

.math-inline {
  display: inline-flex;
  align-items: baseline;
  margin: 0 .08em;
  padding: 0 .08em;
  color: var(--text);
  vertical-align: baseline;
}
.math-inline math { font-size: 1.05em; }
.math-display {
  position: relative;
  max-width: 100%;
  margin: 1.6rem 0;
  padding: 2.55rem 1rem 1rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 13px;
  background: var(--surface);
  text-align: center;
}
.math-scroll { max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.math-display math { min-width: min-content; font-size: 1.18em; }
.math-inline math, .math-display math { font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif; }
.math-explore-toggle {
  position: absolute;
  top: .55rem;
  left: .65rem;
  padding: .22rem .52rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: .72rem;
  font-weight: 750;
  cursor: pointer;
}
.math-explore-toggle:hover, .math-explore-toggle:focus-visible { border-color: var(--accent); }
.math-explorer { margin: .9rem 0 0; padding: .75rem .85rem; border-radius: 10px; background: var(--accent-faint); color: var(--text); text-align: left; }
.math-explorer > p { margin: 0 0 .55rem; color: var(--muted); font-size: .72rem; }
.math-symbols { display: flex; flex-wrap: wrap; gap: .35rem; }
.math-symbols button { min-width: 34px; padding: .28rem .48rem; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--text); font-family: "STIX Two Math", "Cambria Math", serif; cursor: pointer; }
.math-symbols button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: white; }
.math-symbol-note { display: block; margin-top: .65rem; color: var(--text); font-size: .78rem; line-height: 1.55; }
.math-term-active { color: var(--warm) !important; background: var(--warm-soft); }
.math-source { margin-top: .75rem; color: var(--muted); text-align: left; font-size: .72rem; }
.math-source summary {
  position: absolute;
  top: .55rem;
  right: .65rem;
  padding: .22rem .52rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}
.math-source summary:hover, .math-source summary:focus-visible { border-color: var(--accent); color: var(--accent-strong); }
.math-source pre {
  margin: .8rem 0 0;
  padding: .75rem .85rem;
  overflow-x: auto;
  border-radius: 9px;
  background: var(--code-bg);
  color: var(--code-text);
  text-align: left;
  white-space: pre;
}
.math-source code { padding: 0; background: transparent; color: inherit; font-size: .74rem; }
.standalone-page {
  width: min(880px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(2rem, 7vw, 5rem) 0 6rem;
}
.standalone-page > h1 {
  margin: .25rem 0 1rem;
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -.04em;
}
.research-index {
  display: grid;
  gap: 1rem;
  margin-top: 1.25rem;
}
.research-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; margin: 2rem 0; }
.research-summary p { display: grid; gap: .12rem; margin: 0; padding: .9rem 1rem; border-top: 3px solid var(--accent); background: var(--surface); }
.research-summary strong { color: var(--accent-strong); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.research-summary span { color: var(--muted); font-size: .72rem; }
.research-group { margin-top: 4rem; }
.research-group > h2 { margin: .2rem 0 .5rem; font-size: clamp(1.45rem, 4vw, 2rem); line-height: 1.25; }
.research-entry {
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}
.research-entry h3 {
  margin: .25rem 0 .55rem;
  font-size: 1.05rem;
  line-height: 1.4;
}
.research-entry p { margin: .45rem 0; }
.research-latest { border-left: 4px solid var(--accent); }
.ref-status { background: var(--accent-soft); color: var(--accent-strong); }
.research-checked { margin: -.45rem 0 0 1rem; color: var(--muted); font-size: .7rem; }

.static-lab-fallback { margin: 2rem 0; padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 13px; background: var(--accent-faint); }
.static-lab-fallback h2 { margin: .2rem 0 .55rem; font-size: 1.2rem; }
.static-lab-fallback p { margin: .55rem 0; }

.static-chapter > .prose {
  margin-top: 2rem;
  font-size: var(--reading-size);
}
.static-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .75rem;
  margin: 1.5rem 0;
  padding: .9rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.static-nav a {
  min-width: 0;
  padding: .45rem .65rem;
  border-radius: 8px;
  background: var(--surface-2);
  text-decoration: none;
}
.chapter-source { color: var(--muted); font-size: .85rem; }
.nojs-chapters { columns: 2; gap: 2rem; padding-left: 1.4rem; }
.nojs-chapters li { break-inside: avoid; margin-bottom: .45rem; }
@media (max-width: 640px) {
  .nojs-chapters { columns: 1; }
  .static-nav { display: grid; }
}
