:root {
  --paper: #f4f1e8;
  --ink: #23302b;
  --muted: #5e6d66;
  --line: #d5d8cc;
  --green: #2a5d4a;
  --green-soft: #e7efe9;
  --warn: #8a3b22;
  --warn-soft: #f6ebe6;
  --white: #fffcf6;
  --term: #ffffff;
  --shadow: 0 1px 0 rgba(35, 48, 43, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font: 16px/1.7 "Source Han Serif SC", "Songti SC", "Noto Serif CJK SC", serif;
}
button {
  font: 15px/1.4 "PingFang SC", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  cursor: pointer;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 28px 22px 64px; }
header { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 22px; }
.eyebrow {
  font: 600 11px/1.3 "PingFang SC", sans-serif;
  letter-spacing: 0.14em;
  color: var(--green);
  margin: 0 0 6px;
}
h1 { font-weight: 600; font-size: 28px; line-height: 1.35; margin: 0 0 8px; }
.lead { margin: 0; color: var(--muted); font-size: 15px; }
h2 { font-size: 18px; margin: 0 0 8px; font-weight: 600; }
.stem, .stage-wrap, .panel { margin-bottom: 18px; }
.stem p { margin: 0.4em 0; }
.stage-wrap {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 16px 16px 14px;
}
.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
  font: 13px/1.4 "PingFang SC", sans-serif;
  color: var(--muted);
}
.steps span {
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 3px;
}
.steps span.active {
  color: var(--green);
  border-color: var(--green);
  background: var(--green-soft);
}
.steps span.done { color: var(--green); background: var(--green-soft); border-color: #b7cfc3; }
.stage {
  position: relative;
  min-height: 200px;
  overflow: visible;
}
.eq {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 96px;
  padding-top: 56px;
  flex-wrap: nowrap;
}
.term, .op, .eqs, .slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
}
.term {
  background: var(--term);
  border: 1px solid #cfd5c8;
  border-radius: 3px;
  padding: 6px 12px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}
.term.flying { z-index: 5; box-shadow: 0 6px 16px rgba(35, 48, 43, 0.12); }
.term .minus-badge {
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translate(-70%, -50%) scale(0.4);
  opacity: 0;
  color: var(--warn);
  font: 700 22px/1 "PingFang SC", sans-serif;
  pointer-events: none;
}
.op, .eqs { font-size: 28px; color: var(--ink); min-width: 1.1em; padding: 0 2px; }
.slot { min-width: 12px; }
.frac { display: flex; flex-direction: column; align-items: center; padding: 2px 8px; }
.frac .bar { height: 1px; background: var(--ink); width: 100%; margin: 2px 0; }
.frac .cancel {
  position: relative;
}
.frac .cancel::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 2px;
  background: var(--warn);
  transform: scaleX(0);
  transform-origin: left center;
}
.frac .cancel.struck::after { transform: scaleX(1); }
.div-badge {
  position: absolute;
  font: 700 14px/1 "PingFang SC", sans-serif;
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid #b7cfc3;
  border-radius: 3px;
  padding: 3px 7px;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.caption {
  min-height: 3.2em;
  margin: 8px 0 0;
  font: 16px/1.55 "PingFang SC", sans-serif;
  color: var(--ink);
  text-align: center;
}
.caption .why { color: var(--warn); }
.note {
  text-align: center;
  font: 14px/1.5 "PingFang SC", sans-serif;
  color: var(--muted);
  min-height: 1.5em;
  margin-top: 4px;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  justify-content: center;
}
.controls button {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 3px;
}
.controls button.primary {
  background: var(--ink);
  color: var(--white);
  border-color: var(--ink);
}
.controls button:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.controls button:disabled { opacity: 0.45; cursor: not-allowed; }
details.fold {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}
details.fold summary {
  cursor: pointer;
  font: 600 15px/1.5 "PingFang SC", sans-serif;
}
details.fold .body { padding: 8px 0 4px; }
footer {
  margin-top: 28px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font: 13px/1.55 "PingFang SC", sans-serif;
}
@media (max-width: 640px) {
  h1 { font-size: 24px; }
  .wrap { padding: 20px 14px 48px; }
  .eq { transform: scale(0.92); }
}

.term .katex { font-size: 1.28em; }
.frac { min-width: 2.2em; }
.frac .num, .frac .den { display: inline-flex; align-items: center; justify-content: center; }
.caption .katex { font-size: 1.05em; }
.stem .katex, .lead .katex, .fold .katex { font-size: 1.05em; }
