:root {
  --paper: #f9faf6;
  --ink: #171b1c;
  --muted: #5c6466;
  --soft: #eef3ef;
  --line: #d4ddd7;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --accent: #0f766e;
  --accent-deep: #0b4f4a;
  --flux: #4c5fb1;
  --qwen: #0f8a5f;
  --z: #b46b13;
  --red: #a43c31;
  --code: #141817;
  --shadow: 0 18px 46px rgba(18, 32, 32, 0.08);
  --serif: Georgia, "Times New Roman", "Noto Serif SC", serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --mono: "SFMono-Regular", "Cascadia Mono", "Liberation Mono", Menlo, monospace;
  --toc-width: 15rem;
  --toc-gap: 2.5rem;
}

html[data-theme="dark"] {
  --paper: #101213;
  --ink: #f4efe6;
  --muted: #b9b2a8;
  --soft: #181c1d;
  --line: #343b3d;
  --panel: rgba(27, 30, 31, 0.92);
  --panel-strong: #222729;
  --accent: #51b8c8;
  --accent-deep: #9ee8f2;
  --flux: #9daaf5;
  --qwen: #75d8a8;
  --z: #d89b47;
  --red: #d66f5d;
  --code: #0b0d0e;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

html[data-theme="dark"] body {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(0deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--paper);
}

html[data-theme="dark"] .site-header {
  background: rgba(16, 18, 19, 0.92);
}

html[data-theme="dark"] .module-nav a,
html[data-theme="dark"] .page-footer a {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] .module-nav a:first-child {
  color: #e8fbff;
  background: rgba(81, 184, 200, 0.12);
}

html[data-theme="dark"] .lecture-toc {
  background: rgba(16, 18, 19, 0.86);
}

html[data-theme="dark"] .lab-canvas,
html[data-theme="dark"] .data-pipeline,
html[data-theme="dark"] .timeline-roadmap article,
html[data-theme="dark"] .reward-board,
html[data-theme="dark"] .quality-board {
  background: var(--panel-strong);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.045) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(0deg, rgba(76, 95, 177, 0.035) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--paper);
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

canvas {
  display: block;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 60;
  width: 1px;
  height: 1px;
  padding: 0.55rem 0.75rem;
  overflow: hidden;
  color: #fff;
  text-decoration: none;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  background: var(--ink);
  border-radius: 4px;
}

.skip-link:focus {
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  clip-path: none;
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 80;
  width: 100%;
  height: 3px;
}

.reading-progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--flux), var(--z));
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.85rem max(1rem, calc((100vw - 1040px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(249, 250, 246, 0.94);
  backdrop-filter: blur(14px);
}

.brand,
.module-nav a,
.page-footer a {
  text-decoration: none;
}

.brand {
  font-family: var(--serif);
  font-weight: 800;
}

.module-nav {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.module-nav a,
.page-footer a {
  padding: 0.42rem 0.62rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.72);
}

.module-nav a:first-child {
  color: var(--accent-deep);
  background: rgba(15, 118, 110, 0.08);
}

.module-nav a:hover,
.module-nav a:focus-visible,
.page-footer a:hover,
.page-footer a:focus-visible {
  color: #fff;
  background: var(--accent);
  outline: none;
}

.lecture {
  width: min(100% - 2rem, 980px);
  min-width: 0;
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.paper-header {
  padding: 3.2rem 0 2.1rem;
  border-bottom: 3px double var(--line);
}

.kicker {
  margin: 0 0 0.82rem;
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.paper-header h1 {
  max-width: 930px;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3rem, 6.4vw, 5.15rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.subtitle {
  max-width: 840px;
  margin: 1.2rem 0 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.12rem, 2vw, 1.44rem);
  line-height: 1.5;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  max-width: 900px;
  margin-top: 1.25rem;
}

.hero-tags span {
  display: inline-flex;
  padding: 0.34rem 0.55rem;
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1.35;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.chapter {
  min-width: 0;
  padding: 4rem 0 0;
}

.chapter-header {
  margin-bottom: 1.35rem;
}

.chapter h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 2.72rem);
  line-height: 1.14;
  letter-spacing: 0;
}

.chapter h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.32rem;
  line-height: 1.28;
}

.chapter p,
.chapter li,
dd,
td,
th {
  overflow-wrap: anywhere;
}

.chapter p,
.chapter li {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.82;
}

.chapter p {
  margin: 1rem 0 0;
}

.chapter-summary {
  max-width: 820px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.12rem;
}

.thesis-card,
.route-card,
.layer-grid article,
.derivation-section,
.visual-example,
.algorithm-panel,
.judgement-card,
.warning-card,
.source-note,
.evidence-card,
.stack-card,
.diagram-card,
.final-card,
.recipe-grid article,
.infra-grid article,
.task-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.thesis-card,
.derivation-section,
.visual-example,
.algorithm-panel,
.judgement-card,
.warning-card,
.source-note,
.evidence-card,
.diagram-card,
.final-card {
  min-width: 0;
  padding: 1.25rem;
  margin-top: 1rem;
}

.thesis-card {
  border-left: 4px solid var(--accent);
}

.thesis-card.z {
  border-left-color: var(--z);
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-top: 1rem;
}

.route-card {
  min-height: 15rem;
  padding: 1rem;
}

.route-card h3 {
  color: var(--ink);
}

.route-card p {
  font-size: 0.94rem;
  line-height: 1.68;
}

.route-card span,
.tag-cloud span {
  display: inline-flex;
  margin: 0.55rem 0.35rem 0 0;
  padding: 0.28rem 0.48rem;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 850;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.route-card.flux {
  border-top: 4px solid var(--flux);
}

.route-card.qwen {
  border-top: 4px solid var(--qwen);
}

.route-card.z {
  border-top: 4px solid var(--z);
}

.route-card.common {
  border-top: 4px solid var(--accent);
}

.route-summary-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.pipeline-flow {
  display: grid;
  grid-template-columns: repeat(8, minmax(130px, 1fr));
  gap: 0.55rem;
  padding: 1rem;
  margin-top: 1rem;
  overflow-x: auto;
  contain: paint;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.pipeline-flow div {
  position: relative;
  min-height: 5.7rem;
  padding: 0.85rem;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 850;
  line-height: 1.45;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.pipeline-flow div:not(:last-child)::after {
  position: absolute;
  right: -0.45rem;
  top: 50%;
  z-index: 2;
  color: var(--accent);
  font-family: var(--mono);
  content: ">";
  transform: translateY(-50%);
}

.qwen-flow {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.rl-flow {
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  box-shadow: none;
}

.layer-grid,
.task-grid,
.infra-grid,
.recipe-grid {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.layer-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.layer-grid.five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.task-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.task-grid.tight {
  grid-template-columns: 1fr;
}

.infra-grid,
.recipe-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.layer-grid article,
.task-grid article,
.infra-grid article,
.recipe-grid article {
  padding: 0.95rem;
}

.layer-grid strong,
.task-grid strong {
  display: block;
  color: var(--ink);
}

.layer-grid p,
.task-grid p,
.infra-grid p,
.recipe-grid p {
  margin-top: 0.55rem;
  font-size: 0.92rem;
  line-height: 1.62;
}

.visual-example {
  display: grid;
  grid-template-columns: minmax(0, 0.52fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.visual-copy p {
  margin-top: 0.65rem;
}

.lab-card {
  min-width: 0;
}

.lab-controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.85rem;
}

.lab-controls-grid label {
  display: grid;
  gap: 0.38rem;
  min-width: 0;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

output {
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.lab-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 2.5 / 1;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.lab-readout {
  padding: 0.65rem 0.8rem;
  margin-top: 0.75rem;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.84rem;
  line-height: 1.5;
  background: var(--soft);
  border-radius: 4px;
}

.lab-explanation {
  margin-top: 0.65rem;
  font-size: 0.92rem;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  min-width: 0;
  margin-top: 1rem;
}

.two-col > *,
.visual-example > *,
.recipe-grid > *,
.infra-grid > *,
.task-grid > *,
.layer-grid > * {
  min-width: 0;
}

.stack-card {
  padding: 1.25rem;
}

.stack-card.flux {
  border-left: 4px solid var(--flux);
}

.stack-card.qwen {
  border-left: 4px solid var(--qwen);
}

.stack-card dl {
  display: grid;
  grid-template-columns: minmax(6rem, 0.34fr) minmax(0, 1fr);
  gap: 0.55rem 0.8rem;
  margin: 1rem 0 0;
}

.stack-card dt {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 900;
}

.stack-card dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.48;
}

.compact-list {
  padding-left: 1.2rem;
  margin: 0.75rem 0 0;
}

.equation {
  position: relative;
  margin: 1rem 0 0;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  contain: paint;
  background: var(--soft);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
}

.equation mjx-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.architecture-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 0.5rem;
  padding: 1rem;
  margin-top: 1rem;
  overflow-x: auto;
  contain: paint;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.architecture-strip span {
  min-height: 5rem;
  padding: 0.85rem;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 850;
  line-height: 1.45;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-left: 4px solid var(--flux);
  border-radius: 4px;
}

.evidence {
  display: inline-flex;
  align-items: center;
  margin-right: 0.45rem;
  padding: 0.22rem 0.42rem;
  color: #fff;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 900;
  border-radius: 4px;
}

.evidence.public {
  background: var(--accent);
}

.evidence.unknown {
  background: var(--red);
}

.evidence.inferred {
  background: var(--z);
}

.judgement-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 0.9rem;
}

.judgement-grid div {
  padding: 0.95rem;
  background: var(--soft);
  border-radius: 4px;
}

.judgement-grid strong {
  color: var(--ink);
}

.warning-card {
  border-left: 4px solid var(--red);
}

.warning-card h3 {
  color: var(--red);
}

.prompt-boxes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.prompt-boxes div {
  min-height: 9rem;
  padding: 1rem;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.prompt-boxes strong {
  color: var(--ink);
}

.table-scroll {
  margin-top: 1rem;
  overflow-x: auto;
  contain: paint;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.table-scroll.wide table {
  min-width: 1100px;
}

caption {
  padding: 0.85rem 1rem;
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th,
td {
  padding: 0.78rem 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--ink);
  font-weight: 900;
  background: rgba(15, 118, 110, 0.08);
}

tr:last-child td {
  border-bottom: 0;
}

.stage-list {
  padding-left: 1.3rem;
  margin: 1rem 0 0;
}

.stage-list.compact li {
  margin: 0.18rem 0;
  color: var(--ink);
  font-weight: 750;
}

.diagram-card {
  overflow: hidden;
}

.dual-branch {
  display: grid;
  grid-template-columns: 0.85fr 1.4fr 1.25fr 0.7fr 1fr;
  gap: 0.55rem;
  align-items: stretch;
  margin-top: 1rem;
  overflow-x: auto;
}

.dual-branch > div,
.branch-lines span {
  min-height: 5rem;
  padding: 0.85rem;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 850;
  line-height: 1.45;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.branch-lines {
  display: grid;
  gap: 0.55rem;
}

.branch-source,
.branch-output {
  border-left: 4px solid var(--qwen) !important;
}

.branch-join,
.branch-model {
  border-left: 4px solid var(--flux) !important;
}

.tag-cloud {
  margin-top: 0.75rem;
}

.algorithm-panel {
  background: #fffdf8;
}

.panel-title {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.algorithm,
.mini-code {
  width: 100%;
  max-width: 100%;
  padding: 1rem;
  margin: 0;
  overflow-x: auto;
  contain: paint;
  color: #f8f0de;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.72;
  white-space: pre;
  background: var(--code);
  border-radius: 4px;
}

.mini-code {
  margin-top: 1rem;
}

.timeline-roadmap {
  display: grid;
  grid-template-columns: repeat(8, minmax(170px, 1fr));
  gap: 0.5rem;
  align-items: stretch;
  padding: 1rem;
  margin-top: 1rem;
  overflow-x: auto;
  contain: paint;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.timeline-roadmap article {
  min-height: 16rem;
  padding: 0.9rem;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-top: 4px solid var(--z);
  border-radius: 4px;
}

.timeline-roadmap time {
  display: block;
  color: var(--z);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 900;
}

.timeline-roadmap strong {
  display: block;
  margin-top: 0.45rem;
  color: var(--ink);
  line-height: 1.35;
}

.timeline-roadmap p {
  margin-top: 0.55rem;
  font-size: 0.88rem;
  line-height: 1.58;
}

.final-card {
  border-left: 4px solid var(--accent);
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-top: 1rem;
}

.reference-grid article {
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.reference-grid a {
  display: block;
  padding: 0.5rem 0;
  color: var(--accent-deep);
  font-size: 0.88rem;
  font-weight: 760;
  line-height: 1.4;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.reference-grid a:last-child {
  border-bottom: 0;
}

.reference-grid a:hover,
.reference-grid a:focus-visible {
  color: var(--flux);
  outline: none;
}

.toc-toggle {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: none;
  padding: 0.58rem 0.78rem;
  color: #fff;
  font-weight: 850;
  cursor: pointer;
  background: var(--accent);
  border: 0;
  border-radius: 4px;
}

.lecture-toc {
  position: fixed;
  top: 6rem;
  left: max(1rem, calc((100vw - 1360px) / 2));
  z-index: 20;
  width: var(--toc-width);
  max-height: calc(100vh - 7rem);
  padding: 1rem;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.lecture-toc p {
  margin: 0 0 0.6rem;
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.lecture-toc nav {
  display: grid;
  gap: 0.2rem;
}

.lecture-toc a {
  padding: 0.42rem 0.5rem;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
  text-decoration: none;
  border-radius: 4px;
}

.lecture-toc a.active,
.lecture-toc a:hover,
.lecture-toc a:focus-visible {
  color: #fff;
  background: var(--accent);
  outline: none;
}

.page-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  width: min(100% - 2rem, 980px);
  padding: 2rem 0 3rem;
  margin: 0 auto;
  border-top: 1px solid var(--line);
}

@media (min-width: 1341px) {
  .lecture,
  .page-footer {
    width: min(calc(100vw - var(--toc-width) - var(--toc-gap) - 4rem), 980px);
    margin-left: calc(max(1rem, calc((100vw - 1360px) / 2)) + var(--toc-width) + var(--toc-gap));
    margin-right: auto;
  }
}

@media (max-width: 1340px) {
  .lecture-toc {
    display: none;
  }

  .toc-toggle {
    position: relative;
    right: auto;
    bottom: auto;
    display: flex;
    width: max-content;
    margin: 0.85rem 1rem 0 auto;
  }

  .lecture-toc.open {
    display: block;
    top: auto;
    right: 1rem;
    bottom: 4rem;
    left: auto;
    width: min(22rem, calc(100vw - 2rem));
  }
}

@media (max-width: 1080px) {
  .route-grid,
  .route-summary-grid,
  .layer-grid,
  .layer-grid.five,
  .reference-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .task-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .site-header,
  .module-nav,
  .panel-title,
  .visual-example {
    align-items: stretch;
  }

  .site-header,
  .panel-title {
    flex-direction: column;
  }

  .module-nav {
    flex-wrap: wrap;
  }

  .visual-example,
  .judgement-grid,
  .lab-controls-grid,
  .two-col,
  .infra-grid,
  .recipe-grid,
  .prompt-boxes,
  .dual-branch {
    grid-template-columns: 1fr;
  }

  .route-grid,
  .route-summary-grid,
  .layer-grid,
  .layer-grid.five,
  .task-grid,
  .reference-grid {
    grid-template-columns: 1fr;
  }

  .paper-header h1 {
    font-size: clamp(2.35rem, 11vw, 3.8rem);
  }

  .algorithm,
  .mini-code {
    font-size: 0.74rem;
  }

  .route-card {
    min-height: 0;
  }

  .pipeline-flow div,
  .architecture-strip span {
    min-height: 4.7rem;
  }
}
