/*
 * diagrams.css — 图解、数学排版、"逐行代码讲解"组件,
 * 以及从项目讲解页迁移过来的交互实验台样式。
 */

/* ============================================================= */
/* 通用插图容器                                                   */
/* ============================================================= */

.figure {
  max-width: 60rem;
  margin: 2rem auto;
}

.figure--reading {
  max-width: var(--reading-width);
}

.figure__cap {
  margin: 0.7rem auto 0;
  max-width: var(--reading-width);
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
}

.figure img,
.figure__photo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.diagram {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1.2rem;
}

.diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

/* SVG 里常用的语义色, 通过 currentColor / class 控制 */
.svg-stroke {
  stroke: var(--line-strong);
}
.svg-text {
  fill: var(--text-soft);
  font-family: var(--font-sans);
}
.svg-text-strong {
  fill: var(--text);
  font-family: var(--font-sans);
  font-weight: 700;
}
.svg-accent {
  fill: var(--accent);
}
.svg-primary {
  fill: var(--primary);
}

/* 简单的"流程管线"图 (盒子 + 箭头) */
.pipe {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.6rem;
  justify-content: center;
}

.pipe__box {
  flex: 1 1 120px;
  min-width: 110px;
  text-align: center;
  padding: 0.9rem 0.7rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-weight: 700;
  color: var(--text);
  align-self: center;
}

.pipe__box small {
  display: block;
  font-weight: 500;
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-top: 0.25rem;
}

.pipe__arrow {
  align-self: center;
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 800;
}

/* 训练步骤时间轴 (第 15 章等) */
.step-track {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0 0.25rem 0.35rem;
  position: relative;
  max-width: 42rem;
  margin-inline: auto;
}

.step-track::before {
  content: "";
  position: absolute;
  left: 1.22rem;
  top: 1.6rem;
  bottom: 1.6rem;
  width: 2px;
  background: linear-gradient(
    180deg,
    rgba(106, 195, 255, 0.85) 0%,
    rgba(139, 123, 255, 0.85) 45%,
    rgba(255, 207, 114, 0.85) 75%,
    rgba(142, 240, 209, 0.85) 100%
  );
  border-radius: 2px;
}

.step-track__item {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  gap: 0.85rem 1rem;
  padding: 0.55rem 0;
  align-items: start;
}

.step-track__item + .step-track__item {
  margin-top: 0.15rem;
}

.step-track__badge {
  width: 2.45rem;
  height: 2.45rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #eef4ff;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.step-track__item--sample .step-track__badge {
  background: rgba(106, 195, 255, 0.18);
  border-color: rgba(106, 195, 255, 0.55);
}

.step-track__item--forward .step-track__badge {
  background: rgba(139, 123, 255, 0.18);
  border-color: rgba(139, 123, 255, 0.55);
}

.step-track__item--loss .step-track__badge {
  background: rgba(255, 207, 114, 0.16);
  border-color: rgba(255, 207, 114, 0.55);
}

.step-track__item--backward .step-track__badge {
  background: rgba(255, 120, 120, 0.14);
  border-color: rgba(255, 120, 120, 0.45);
}

.step-track__item--repeat .step-track__badge {
  background: rgba(142, 240, 209, 0.16);
  border-color: rgba(142, 240, 209, 0.55);
}

.step-track__body {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  padding: 0.75rem 0.95rem;
}

.step-track__title {
  display: block;
  font-weight: 700;
  color: var(--text);
  font-size: 0.98rem;
  margin-bottom: 0.3rem;
}

.step-track__detail {
  display: block;
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.55;
}

.step-track__detail code,
.step-track__formula {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--text-soft);
}

.step-track__phase {
  display: inline-block;
  margin-bottom: 0.55rem;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--primary);
  border: 1px solid rgba(106, 195, 255, 0.35);
  background: rgba(106, 195, 255, 0.08);
}

.step-track__mini-pipe {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.45rem;
}

.step-track__mini-pipe span {
  padding: 0.2rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.78rem;
  color: var(--text-soft);
}

.step-track__mini-pipe em {
  color: var(--primary);
  font-style: normal;
  font-weight: 700;
}

@media (max-width: 520px) {
  .step-track {
    padding-left: 0;
  }

  .step-track::before {
    left: 1.05rem;
  }

  .step-track__badge {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 0.85rem;
  }

  .step-track__item {
    grid-template-columns: 2.15rem minmax(0, 1fr);
    gap: 0.65rem;
  }
}

/* ============================================================= */
/* 数学排版 (零依赖)                                              */
/* ============================================================= */

var,
.var {
  font-family: "Cambria Math", "Latin Modern Math", Georgia, serif;
  font-style: italic;
  color: var(--text);
}

.mathblock {
  margin: 1.4rem auto;
  max-width: var(--reading-width);
  padding: 1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  text-align: center;
  font-size: 1.12rem;
  line-height: 2.1;
  overflow-x: auto;
}

.mathblock .label {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-style: normal;
}

/* 分式 */
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  margin: 0 0.25rem;
}

.frac > span {
  display: block;
  padding: 0 0.45rem;
  line-height: 1.3;
}

.frac > span:first-child {
  border-bottom: 1.5px solid var(--text-soft);
}

/* 上下标微调 */
.chapter sub,
.chapter sup {
  font-size: 0.72em;
}

/* ============================================================= */
/* 逐行代码讲解                                                   */
/* ============================================================= */

.code-walk {
  margin: 1.8rem auto;
  max-width: 56rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a1422;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.code-walk__file {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--line);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.code-walk__file::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 14px 0 0 var(--warn), 28px 0 0 var(--danger);
  margin-right: 1.6rem;
}

.code-walk__code {
  margin: 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.7;
  color: #d7e3f7;
  tab-size: 2;
}

.code-walk__code code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* 代码里的教学标记 (1)(2)(3) */
.cw-tag {
  display: inline-grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  margin-left: 0.4rem;
  border-radius: 999px;
  background: var(--primary);
  color: #06101f;
  font-family: var(--font-sans);
  font-size: 0.74rem;
  font-weight: 800;
  vertical-align: middle;
}

/* 注释行配色 */
.cw-cmt {
  color: #6f86a8;
  font-style: italic;
}
.cw-key {
  color: #8b7bff;
}
.cw-str {
  color: #8ef0d1;
}
.cw-fn {
  color: #6ac3ff;
}

.code-walk__notes {
  margin: 0;
  padding: 1rem 1.4rem 1.2rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  counter-reset: cw;
  list-style: none;
}

.code-walk__notes li {
  position: relative;
  margin: 0.7rem 0;
  padding-left: 2rem;
  color: var(--text-soft);
}

.code-walk__notes li::before {
  counter-increment: cw;
  content: counter(cw);
  position: absolute;
  left: 0;
  top: 0.15rem;
  width: 1.4rem;
  height: 1.4rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(106, 195, 255, 0.18);
  border: 1px solid rgba(106, 195, 255, 0.4);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
}

.code-walk__notes li code {
  font-size: 0.85em;
}

/* ============================================================= */
/* 交互实验台 (迁移自项目讲解页, class 名保持一致)                 */
/* ============================================================= */

.explain {
  color: var(--text-soft);
}

.formula-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.formula-card h3 {
  margin-top: 0;
}

.formula {
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--text);
}

.formula--sub {
  margin-top: 0.35rem;
  font-size: 0.98rem;
  color: var(--accent);
}

/* 神经元实验台 */
.lab {
  width: 100%;
  padding: 1.2rem;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.lab__controls {
  display: grid;
  gap: 1rem;
}

.lab__controls label,
.attention-lab__toolbar label {
  display: grid;
  gap: 0.4rem;
  color: var(--text-soft);
}

/* checkbox 类 label 例外: 勾选框与文字横向排成一行, 不走上面的 grid 竖排
   (选择器特异性需高于上面的 .attention-lab__toolbar label 才能覆盖) */
.lab__controls label.checkbox,
.attention-lab__toolbar label.checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.attention-lab__toolbar label.checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex: none;
}

input[type="range"],
select {
  width: 100%;
}

/* 实验台 select: 去掉系统默认白底方框 */
.lab__controls select,
.attention-lab__toolbar select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  margin: 0;
  padding: 0.58rem 2.35rem 0.58rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background-color: rgba(8, 17, 31, 0.72);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1.5 1.5L6 6.5L10.5 1.5' stroke='%236ac3ff' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 12px 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.35;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease;
}

.lab__controls select:hover,
.attention-lab__toolbar select:hover {
  border-color: rgba(106, 195, 255, 0.45);
  background-color: rgba(15, 26, 46, 0.95);
}

.lab__controls select:focus,
.lab__controls select:focus-visible,
.attention-lab__toolbar select:focus,
.attention-lab__toolbar select:focus-visible {
  outline: none;
  border-color: rgba(106, 195, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(106, 195, 255, 0.14);
}

.lab__controls select option,
.attention-lab__toolbar select option {
  background: #0f1a2e;
  color: var(--text);
}

/* range 滑块与下拉框视觉统一 */
.lab__controls input[type="range"],
.attention-lab__toolbar input[type="range"] {
  height: 6px;
  margin: 0.35rem 0 0.15rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  accent-color: var(--primary);
  cursor: pointer;
}

.lab__controls input[type="range"]::-webkit-slider-thumb,
.attention-lab__toolbar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(8, 17, 31, 0.9);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px rgba(106, 195, 255, 0.25);
}

.lab__controls input[type="range"]::-moz-range-thumb,
.attention-lab__toolbar input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(8, 17, 31, 0.9);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px rgba(106, 195, 255, 0.25);
}

.lab__value {
  font-weight: 700;
  color: var(--text);
}

.lab__viz {
  display: grid;
}

.meter {
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.meter__bar {
  width: 50%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--warn), var(--accent));
  transition: width 180ms ease;
}

/* 传播动画 */
.propagation {
  width: 100%;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.propagation__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-bottom: 1rem;
  align-items: end;
}

.propagation__status {
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text-soft);
  font-weight: 700;
}

.propagation__lr {
  min-width: 220px;
  display: grid;
  gap: 0.35rem;
  color: var(--text-soft);
}

.propagation__stage {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 340px);
  gap: 1rem;
}

.propagation__left {
  display: grid;
  gap: 1rem;
}

.network {
  position: relative;
  min-height: 460px;
  padding: 1.4rem 1rem;
  border-radius: 22px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 20% 20%, rgba(106, 195, 255, 0.08), transparent 28%),
    rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.network__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.network__layers {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  min-height: 420px;
}

.network__layer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.15rem;
}

.network__node-wrap {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
}

.network__title {
  color: var(--text-soft);
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.network__edge-line {
  stroke: rgba(225, 233, 255, 0.72);
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke 220ms ease, stroke-width 220ms ease, filter 220ms ease;
}

.network__edge-label {
  font-size: 11px;
  font-family: var(--font-mono);
  fill: #c8d8f8;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(7, 16, 29, 0.94);
  stroke-width: 5px;
  stroke-linejoin: round;
  transition: fill 220ms ease, stroke 220ms ease;
}

.network__edge.is-active-forward .network__edge-line {
  stroke: #8ef0d1;
  stroke-width: 3;
  filter: drop-shadow(0 0 8px rgba(106, 195, 255, 0.65));
  marker-end: url(#prop-arrow-forward);
}

.network__edge.is-active-backward .network__edge-line {
  stroke: #ff9a8f;
  stroke-width: 3;
  filter: drop-shadow(0 0 8px rgba(255, 153, 143, 0.55));
  marker-end: url(#prop-arrow-backward);
}

.network__edge.is-pulse .network__edge-line {
  animation: edgePulse 700ms ease;
}

.network__edge.is-linked .network__edge-line {
  stroke: #ffffff;
  stroke-width: 3;
  filter: drop-shadow(0 0 10px rgba(106, 195, 255, 0.7));
}

.network__edge.is-linked .network__edge-label {
  fill: #ffffff;
  stroke: rgba(7, 16, 29, 0.98);
}

.network__node {
  width: 74px;
  height: 74px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(165, 192, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
  transition: transform 220ms ease, background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
  position: relative;
  z-index: 1;
}

.network__meta {
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 0.74rem;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.network__node.is-active-forward {
  transform: scale(1.08);
  background: linear-gradient(120deg, rgba(106, 195, 255, 0.92), rgba(142, 240, 209, 0.88));
  color: #04111d;
  border-color: transparent;
}

.network__node.is-active-backward {
  transform: scale(1.08);
  background: linear-gradient(120deg, rgba(255, 207, 114, 0.96), rgba(255, 122, 162, 0.86));
  color: #1b0b14;
  border-color: transparent;
}

.network__node.is-secondary-forward,
.network__node.is-secondary-backward {
  transform: scale(1.03);
  border-color: rgba(255, 255, 255, 0.34);
}

.network__node.is-linked {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18), 0 0 24px rgba(106, 195, 255, 0.5);
}

.network__pulse {
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), var(--primary));
  filter: blur(1px);
  opacity: 0;
  pointer-events: none;
  transition: transform 380ms ease, opacity 180ms ease;
  z-index: 2;
}

.network__pulse.is-visible {
  opacity: 1;
}

.network__pulse.is-backward {
  background: linear-gradient(120deg, var(--warn), #ff7aa2);
}

.propagation-flow,
.change-list {
  display: grid;
  gap: 0.8rem;
}

.propagation-formula {
  display: grid;
  gap: 1rem;
}

.flow-box,
.propagation-change {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  padding: 1rem;
}

.flow-box h4,
.propagation-change h3 {
  margin-top: 0;
  margin-bottom: 0.6rem;
}

.formula-link {
  display: inline-block;
  padding: 0.05rem 0.28rem;
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.formula-link:hover,
.formula-link.is-hovered {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(106, 195, 255, 0.55);
  color: #ffffff;
}

[data-prop-chain-main] {
  color: #ffe6aa;
}

[data-prop-chain-sub] {
  color: #ffd7dc;
}

.flow-box__line {
  margin: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.9;
}

.change-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0.9rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.change-item strong {
  color: var(--text);
}

.change-item span {
  color: var(--accent);
  font-family: var(--font-mono);
}

/* Attention 实验台 */
.attention-lab {
  width: 100%;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.attention-lab__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.attention-formula {
  margin-bottom: 1rem;
}

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

.attention-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.attention-panel h3 {
  margin-top: 0;
}

.token-picker,
.sentence-strip,
.bars,
.matrix {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.token-picker button,
.token-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.token-picker button:hover,
.token-picker button.is-active,
.token-chip.is-focus {
  transform: translateY(-1px);
  background: rgba(106, 195, 255, 0.16);
  border-color: rgba(106, 195, 255, 0.4);
}

.matrix {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
}

.matrix__cell,
.bars__item,
.vector-box {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.matrix__cell {
  padding: 0.8rem 0.6rem;
  text-align: center;
  transition: transform 160ms ease, background 160ms ease;
}

.matrix__cell.is-linked,
.bars__item.is-linked,
.vector-box.is-linked,
.token-chip.is-linked {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(106, 195, 255, 0.55);
  box-shadow: 0 0 22px rgba(106, 195, 255, 0.22);
}

.matrix__cell strong,
.bars__item strong {
  display: block;
  margin-bottom: 0.3rem;
}

.bars {
  display: grid;
  gap: 0.7rem;
}

.bars__item {
  padding: 0.75rem;
}

.bars__track {
  height: 12px;
  margin-top: 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.bars__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 180ms ease;
}

.vector-box {
  min-height: 88px;
  padding: 1rem;
  font-family: var(--font-mono);
  color: #f6f9ff;
}

/* 多头 / 真实权重热力图 */
.multihead {
  width: 100%;
  margin-top: 1.4rem;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 33, 55, 0.92);
  box-shadow: var(--shadow);
}

.multihead__intro {
  margin-bottom: 1rem;
}

.multihead__intro h3 {
  margin-top: 0;
}

.multihead__grid {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 1rem;
}

.multihead__panel {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  padding: 1rem;
}

.head-heatmaps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
}

.heatmap {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
  padding: 0.9rem;
}

.heatmap h4 {
  margin-top: 0;
  margin-bottom: 0.7rem;
}

.heatmap__grid {
  display: grid;
  gap: 0.45rem;
}

.heatmap__row {
  display: grid;
  grid-template-columns: 68px repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
  align-items: center;
}

.heatmap__label,
.heatmap__cell {
  border-radius: 12px;
  padding: 0.45rem 0.35rem;
  text-align: center;
  font-size: 0.84rem;
}

.heatmap__label {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-soft);
}

.heatmap__cell {
  color: #f9fcff;
  transition: transform 160ms ease;
}

.heatmap__cell:hover {
  transform: scale(1.04);
}

/* 真实权重回放 */
.real-attention {
  width: 100%;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.real-attention__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.real-attention__toolbar label {
  display: grid;
  gap: 0.4rem;
  color: var(--text-soft);
}

.real-attention__content {
  display: grid;
  gap: 1rem;
}

.real-attention__layer {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  padding: 1rem;
}

.real-attention__layer h3 {
  margin-top: 0;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

/* ============================================================= */
/* 手算示例的数值表格 (.table-wrap 负责窄屏横向滚动)              */
/* ============================================================= */

.table-wrap {
  margin: 1.3rem 0;
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid var(--line);
}

.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-soft);
  min-width: 460px;
}

.calc-table th,
.calc-table td {
  padding: 0.6rem 0.85rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.calc-table thead th {
  background: rgba(106, 195, 255, 0.12);
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.calc-table tbody tr:last-child td {
  border-bottom: 0;
}

.calc-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.calc-table td:first-child,
.calc-table th:first-child {
  text-align: left;
  color: var(--text);
  font-weight: 700;
}

.calc-table .is-hot {
  color: var(--accent);
  font-weight: 800;
}

.calc-table .is-cold {
  color: var(--text-dim);
}

.calc-table__cap {
  margin: 0.55rem 0 0;
  color: var(--text-dim);
  font-size: 0.86rem;
  text-align: center;
}

/* 文字较多的表格: 允许换行、左对齐、改用正文字体 (calc-table 默认是给短数字用的) */
.calc-table--wrap {
  font-family: var(--font-sans);
  min-width: 0;
}

.calc-table--wrap th,
.calc-table--wrap td {
  white-space: normal;
  text-align: left;
  vertical-align: top;
}

@keyframes edgePulse {
  0% { opacity: 0.45; filter: brightness(1); }
  35% { opacity: 1; filter: brightness(1.7); }
  100% { opacity: 1; filter: brightness(1); }
}

@media (max-width: 900px) {
  .lab,
  .multihead__grid,
  .propagation__stage {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .network {
    min-height: 400px;
    padding: 1rem 0.5rem;
  }
  .network__layers {
    min-height: 360px;
    gap: 0.5rem;
  }
  .network__node {
    width: 60px;
    height: 60px;
    font-size: 0.9rem;
  }
  .network__meta {
    font-size: 0.66rem;
    padding: 0.16rem 0.35rem;
  }
  .network__layer {
    gap: 0.85rem;
  }
  .network__edge-label {
    font-size: 9px;
  }
}

/* ============================================================= */
/* MoE / 稀疏注意力图 (第 21 章)                                  */
/* ============================================================= */

.pattern-mats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.8rem;
  justify-content: center;
  align-items: flex-start;
}

.pattern-mat {
  text-align: center;
}

.pattern-mat__title {
  margin: 0 0 0.6rem;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 700;
}

.pattern-mat__grid {
  display: grid;
  grid-template-columns: repeat(6, 20px);
  grid-auto-rows: 20px;
  gap: 3px;
  margin: 0 auto;
  width: max-content;
}

.pattern-mat__grid span {
  border-radius: 3px;
  background: rgba(149, 176, 227, 0.1);
}

.pattern-mat__grid span.on {
  background: var(--primary);
}

.pattern-mat__grid span.on--g {
  background: var(--accent);
}

.pattern-mat__cap {
  margin: 0.6rem auto 0;
  max-width: 11rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.5;
}

.diagram__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  justify-content: center;
  margin-top: 1.1rem;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.diagram__legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.diagram__legend i {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid var(--line);
}

/* ============================================================= */
/* 术语表 (glossary.html)                                        */
/* ============================================================= */

.glossary {
  list-style: none;
  padding-left: 0;
  margin: 1rem auto;
  max-width: var(--reading-width);
}

.glossary li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.65;
  color: var(--text-soft);
}

.glossary li strong {
  color: var(--text);
}

.glossary li a {
  white-space: nowrap;
  margin-left: 0.35rem;
  color: var(--primary);
  font-size: 0.86rem;
}

/* 实验台按钮组 (梯度下降等) */
.lab__btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.lab__btns .button {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

/* ============================================================= */
/* 章节链路导航 (chain-map): 把第 16~22 章串成一条可见的主线       */
/* 用在每章 lead 之后, 展示"这条流水线共几站, 你现在在第几站"      */
/* ============================================================= */

.chain-map {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.1rem;
  margin: 0.2rem 0 0;
}

.chain-map__step {
  display: inline-block;
  padding: 0.22rem 0.62rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

a.chain-map__step:hover {
  color: var(--text);
  border-color: var(--primary);
}

.chain-map__step.is-here {
  color: var(--text);
  font-weight: 800;
  border-color: var(--primary);
  background: rgba(106, 195, 255, 0.16);
}

.chain-map__sep {
  color: var(--text-dim);
  opacity: 0.5;
  font-size: 0.78rem;
  padding: 0 0.02rem;
}

.chain-map__note {
  margin: 0.7rem 0 0;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-soft);
}

.chain-map__note strong {
  color: var(--text);
}
