/* ==========================================================================
   各章节专用样式：迭代进度条 / 首屏卡片 / 参数台账 / 演示工具栏 …
   ========================================================================== */

/* ---------- 一圈迭代的进度条 ---------- */
.phase-rail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 2px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.phase-rail > li {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.phase-pill {
  --pc: var(--brand);
  --pn-ink: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 13px 5px 6px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.25;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.phase-pill:hover {
  border-color: var(--pc);
}
.phase-pill.tone-fwd {
  --pc: var(--fwd);
}
.phase-pill.tone-loss {
  --pc: var(--loss);
  --pn-ink: #2d2000;
}
.phase-pill.tone-grad {
  --pc: var(--grad);
}
.phase-pill.tone-upd {
  --pc: var(--upd);
  --pn-ink: #04281d;
}
[data-theme='dark'] .phase-pill {
  --pn-ink: #0e1020;
}
.phase-pill .pn {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 800;
}
.phase-pill.done .pn {
  background: color-mix(in srgb, var(--pc) 30%, var(--surface-3));
  color: var(--text);
}
.phase-pill.active {
  border-color: var(--pc);
  background: color-mix(in srgb, var(--pc) 14%, var(--surface));
  color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 20%, transparent);
}
.phase-pill.active .pn {
  background: var(--pc);
  color: var(--pn-ink);
}
.phase-arrow {
  color: var(--muted);
  font-weight: 700;
  padding: 0 1px;
}
.phase-back {
  display: inline-flex;
  color: var(--muted);
  margin-left: 4px;
}
.phase-rail.compact .phase-pill {
  padding: 4px 11px 4px 5px;
  font-size: 12.5px;
}
.phase-rail.compact .phase-back {
  display: none;
}

/* ---------- 首屏：四张数字卡片排成一行（手机上沿用 layout.css 里的 2×2） ---------- */
@media (min-width: 521px) {
  .stat-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 480px;
  }
  .stat {
    min-width: 0;
  }
}

/* ---------- 首屏小卡片 ---------- */
.hero-cap {
  margin: 8px 0 0;
  min-height: 4.6em;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text-2);
}
.hero-cap b {
  color: var(--text);
}
.hero-meter {
  margin-top: 4px;
}
.hero-meter .spark {
  margin-top: 6px;
}

/* ---------- 演示工具栏里的提示行 ---------- */
.lab-bar .lab-note {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  line-height: 1.6;
}
.lab-note svg.icon {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
}

/* ---------- 参数台账 ---------- */
table.ledger td.sym {
  font-size: 15px;
  white-space: nowrap;
}
table.ledger td.role {
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}
table.ledger th.role {
  font-weight: 600;
}
table.ledger tr.grp td {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 14px;
}
table.ledger tr.pick {
  cursor: pointer;
}
table.ledger tr.sel td {
  background: var(--brand-soft);
}
table.ledger tr.sel td:first-child {
  box-shadow: inset 3px 0 0 var(--brand);
}
table.ledger td.g.pos {
  color: var(--grad);
}
table.ledger td.g.neg {
  color: var(--warn);
}
table.ledger td.g.zero {
  color: var(--muted);
}
table.ledger td.new {
  font-weight: 700;
}
table.ledger td.new.stuck {
  color: var(--muted);
  font-weight: 500;
}
table.ledger .dir {
  display: inline-block;
  min-width: 1em;
  font-weight: 800;
  color: var(--upd);
}
table.ledger.compact tr.grp td {
  padding: 2px 10px;
}

table.ledger .dir.down {
  color: var(--grad);
}
/* 表头里不想被拆开的一小段：折行时整体挪到下一行（“θ” 和 “（当前）” 之间可以断，“当”和“前”之间不能） */
table.ledger .nb,
table.audit .nb {
  display: inline-block;
}
.calc .sub.row-note {
  margin-left: 6px;
}
.calc .term sub {
  margin: 0 2px 0 1px;
}

/* ---------- 通用小件 ---------- */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
.good-text {
  color: var(--good);
}
.bad-text {
  color: var(--bad);
}
.sub-h4 {
  font-size: 17px;
  margin: 34px 0 12px;
}
.step-viz + .table-wrap {
  margin-top: 14px;
}
/* 小节后面直接接工具栏 / 步进器时，留出呼吸的空间 */
.subsec + .lab-bar,
.subsec + .stepper {
  margin-top: 40px;
}

/* 双栏：一边宽一边窄（窄屏时在 layout.css 里的 900px 断点处统一变成单栏） */
.duo.wide-left {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
}
.duo.wide-right {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
}

/* ---------- 总览：一圈迭代的四张卡片 ---------- */
.loop-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.loop-card {
  --lc: var(--brand);
  --lc-ink: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--lc);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.loop-card.tone-fwd {
  --lc: var(--fwd);
}
.loop-card.tone-loss {
  --lc: var(--loss);
  --lc-ink: #2d2000;
}
.loop-card.tone-grad {
  --lc: var(--grad);
}
.loop-card.tone-upd {
  --lc: var(--upd);
  --lc-ink: #04281d;
}
.loop-card:not(:last-child)::after {
  content: '→';
  position: absolute;
  right: -17px;
  top: 24px;
  z-index: 1;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.lc-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.lc-n {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--lc);
  color: var(--lc-ink);
  font-size: 14px;
  font-weight: 800;
}
.lc-ic svg {
  width: 24px;
  height: 24px;
  color: var(--lc);
}
.loop-card h4 {
  font-size: 18px;
  margin: 2px 0 0;
}
.loop-card p {
  flex: 1 1 auto;
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-2);
}
.lc-tex {
  padding: 8px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  text-align: center;
  font-size: 15px;
  overflow-x: auto;
}
.lc-out {
  font-size: 13px;
  color: var(--muted);
}
.lc-out b {
  color: var(--text);
}
.lc-link {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 13.5px;
  font-weight: 700;
  color: color-mix(in srgb, var(--lc) 60%, var(--text));
  text-decoration: none;
}
.lc-link:hover {
  text-decoration: underline;
}
.loop-back {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 18px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.5;
}
.loop-back svg {
  flex: none;
  color: var(--upd);
}
.ov-map {
  margin-top: 16px;
}
.pgroups {
  display: grid;
  gap: 8px;
}
.pgroup {
  display: grid;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
}
.pg-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
}
.pg-items {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
}
.pchip b {
  font-family: var(--font-mono);
  font-size: 13.5px;
}
table.symtab td:last-child {
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- 3.1 一次更新 / 3.3 学习率 ---------- */
.update-sum {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.lr-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.lr-presets button {
  appearance: none;
  padding: 3px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.lr-presets button:hover {
  border-color: var(--brand);
  color: var(--text);
}
.lr-presets button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.lr-read {
  margin: 14px 0 6px;
}
.lr-verdict {
  margin: 6px 0 10px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  border-left: 4px solid var(--border-strong);
  background: var(--surface-2);
  font-weight: 600;
}
.lr-verdict.good {
  border-left-color: var(--good);
  background: var(--good-soft);
}
.lr-verdict.warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}
.lr-verdict.bad {
  border-left-color: var(--bad);
  background: var(--bad-soft);
}
table.lrtab tr.ok td:last-child {
  color: var(--good);
  font-weight: 600;
}
table.lrtab tr.no td:last-child {
  color: var(--bad);
  font-weight: 600;
}
table.lrtab td:last-child {
  white-space: normal;
  min-width: 220px;
}

/* ---------- 对账表 / 总结 ---------- */
table.audit td.num {
  white-space: nowrap;
}
.audit-sum {
  margin: 12px 0 0;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-2);
}
.audit-sum .badge {
  margin-right: 6px;
}
table.tbl tr.cur td {
  background: var(--brand-soft);
}
table.recap td {
  vertical-align: middle;
}
.recap-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--rc, var(--brand));
}
table.recap tr.tone-fwd {
  --rc: var(--fwd);
}
table.recap tr.tone-loss {
  --rc: var(--loss);
}
table.recap tr.tone-grad {
  --rc: var(--grad);
}
table.recap tr.tone-upd {
  --rc: var(--upd);
}
.reading {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.reading li {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) auto minmax(0, 1.7fr);
  align-items: baseline;
  gap: 4px 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.reading a {
  color: var(--brand-ink);
  text-decoration: none;
}
.reading a:hover {
  text-decoration: underline;
}
.reading a svg {
  margin-left: 4px;
  vertical-align: -2px;
}
.reading .by {
  font-size: 13px;
  color: var(--muted);
}
.reading .note {
  font-size: 14px;
  color: var(--text-2);
}

/* ---------- 3.2 慢放播放器 ---------- */
.panel.player {
  padding: 16px 18px;
}
.player-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
}
.player-lap {
  font-size: 13.5px;
  color: var(--muted);
}
.player-lap b {
  color: var(--text);
  font-family: var(--font-mono);
}
.player-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.player-viz {
  min-width: 0;
}
@media (min-width: 901px) {
  /* 右边的算式很长时，左边的网络图跟着页面滚动，始终能对照着看 */
  .player-viz {
    position: sticky;
    top: 78px;
  }
}
.player-cap {
  min-height: 5.2em;
  margin: 8px 0 0;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text-2);
}
.player-cap b {
  color: var(--text);
}
.player-calc {
  min-width: 0;
}
.player-calc .calc {
  margin-top: 0;
}
/* 控制条放在步骤条正下方：不管下面的内容多高，按钮的位置都不会随步骤跳动 */
.player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 22px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--border-strong);
}
.player-opts {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 24px;
}
.player-opts .field {
  min-width: 190px;
}
.player-opts .group {
  display: grid;
  gap: 6px;
}
.player-opts .cap,
.lab-speed .cap {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.order-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ochip {
  padding: 0 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.ochip.done {
  opacity: 0.55;
  text-decoration: line-through;
}
.ochip.cur {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 800;
}

/* ---------- 3.4 训练实验室 ---------- */
.lab-actions {
  margin: 2px 0 18px;
}
.lab-speed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.seg-row {
  margin-bottom: 10px;
}
.lab-replay {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--warn-soft);
}
.lab-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.stat-chip {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
}
.stat-chip i {
  font-style: normal;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
}
.stat-chip b {
  font-family: var(--font-mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.lab-diag {
  min-height: 4.6em;
  margin: 12px 0 0;
  padding: 9px 12px;
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  font-size: 14.5px;
  line-height: 1.6;
}
.lab-diag.good {
  border-left-color: var(--good);
  background: var(--good-soft);
}
.lab-diag.warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}
.lab-diag.bad {
  border-left-color: var(--bad);
  background: var(--bad-soft);
}
.lab-watch {
  --ec: var(--brand);
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--ec);
  border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--ec) 7%, var(--surface));
  font-size: 14px;
  line-height: 1.65;
}
.lab-watch b {
  display: block;
  margin-bottom: 2px;
  color: var(--ec);
}
.lab-watch.tone-good {
  --ec: var(--good);
}
.lab-watch.tone-warn {
  --ec: var(--warn);
}
.lab-watch.tone-bad {
  --ec: var(--bad);
}
.exp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.exp {
  --ec: var(--brand);
  appearance: none;
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--ec);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.exp:hover {
  box-shadow: var(--shadow-1);
  transform: translateY(-1px);
}
.exp.active {
  border-color: var(--ec);
  background: color-mix(in srgb, var(--ec) 9%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ec) 18%, transparent);
}
.exp.tone-good {
  --ec: var(--good);
}
.exp.tone-warn {
  --ec: var(--warn);
}
.exp.tone-bad {
  --ec: var(--bad);
}
.exp-tag {
  justify-self: start;
  padding: 1px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ec) 14%, transparent);
  color: var(--ec);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.exp b {
  font-size: 15px;
  line-height: 1.4;
}
.exp-desc {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-2);
}
.exp-run {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ec);
}

/* ---------- 响应式 ---------- */
@media (max-width: 1000px) {
  .loop-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .loop-card:nth-child(2)::after {
    display: none;
  }
}
@media (max-width: 900px) {
  .duo.wide-left,
  .duo.wide-right,
  .player-grid,
  .lab-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (max-width: 640px) {
  .panel {
    padding: 14px 14px;
  }
  .panel.player {
    padding: 14px 12px;
  }
  .loop-cards {
    grid-template-columns: minmax(0, 1fr);
  }
  /* 选择器要和上面“→”箭头的规则一样具体，否则盖不掉它，箭头会伸出屏幕 2px，整个页面能横着滑 */
  .loop-card:not(:last-child)::after {
    display: none;
  }
  .loop-back {
    align-items: flex-start;
    border-radius: var(--radius-sm);
  }
  /* 台账有 5 列，要挤进 330px 左右：收紧左右留白、表头允许折行，免得最关键的 θ′ 那一列要横着滑才看得到 */
  table.tbl.ledger th,
  table.tbl.ledger td {
    padding-left: 6px;
    padding-right: 6px;
  }
  table.tbl.ledger thead th {
    white-space: normal;
    line-height: 1.25;
    vertical-align: bottom;
  }
  table.tbl.ledger thead th:first-child {
    white-space: nowrap;
  }
  /* 学习率对比表有 6 列：手机上不显示“100 步后”，这样最关键的“学会用了”“发生了什么”不用横着滑就能看到 */
  table.tbl.lrtab .c100 {
    display: none;
  }
  table.tbl.lrtab th,
  table.tbl.lrtab td {
    padding-left: 6px;
    padding-right: 6px;
  }
  table.tbl.lrtab thead th {
    white-space: normal;
    line-height: 1.25;
    vertical-align: bottom;
  }
  /* “1511 步”这种数字不许断成两行；富余的宽度由最后一列的文字去让 */
  table.tbl.lrtab td.num {
    white-space: nowrap;
  }
  table.tbl.lrtab td:last-child {
    min-width: 0;
  }
  /* 一页纸回顾：4 列塞不进手机屏幕，改成每个动作一张小卡片，“产出”“要保存吗”用 data-label 当小标题 */
  table.tbl.recap,
  table.tbl.recap tbody,
  table.tbl.recap tr,
  table.tbl.recap td {
    display: block;
    width: 100%;
  }
  table.tbl.recap thead {
    display: none;
  }
  table.tbl.recap tr {
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
  }
  table.tbl.recap tbody tr:last-child {
    border-bottom: 0;
  }
  table.tbl.recap td,
  table.tbl.recap tbody tr:last-child td {
    padding: 2px 0;
    border: 0;
  }
  table.tbl.recap td.rc-f {
    padding: 6px 0 8px;
  }
  table.tbl.recap td[data-label]::before {
    content: attr(data-label) '：';
    color: var(--muted);
    font-size: 12.5px;
    margin-right: 2px;
  }
  /* 对账表：数字是 8 位小数，字号和左右留白收一收，让 5 列尽量一屏放下 */
  table.tbl.audit th,
  table.tbl.audit td {
    padding-left: 5px;
    padding-right: 5px;
  }
  table.tbl.audit td.num {
    font-size: 11.5px;
  }
  table.tbl.audit thead th {
    white-space: normal;
    line-height: 1.25;
    vertical-align: bottom;
    font-size: 12px;
  }
  table.tbl.audit thead th:first-child {
    white-space: nowrap;
  }
  .lab-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .lab-speed {
    width: 100%;
    margin-left: 0;
  }
  .player-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .player-opts {
    align-items: stretch;
  }
  .player-opts .field {
    min-width: 0;
    flex: 1 1 100%;
  }
  .reading li {
    grid-template-columns: minmax(0, 1fr);
  }
  .phase-arrow {
    display: none;
  }
}

/* 320–380 宽的小屏手机：学习率对比表再让出一列，把宽度留给“发生了什么”，免得一句话被挤成四五行 */
@media (max-width: 380px) {
  table.tbl.lrtab .c3000 {
    display: none;
  }
}
