:root {
  --ink: #1e1e1e;
  --muted: #5a5a5a;
  --lav: #E4DDF4;
  --blue: #DCE8FA;
  --green: #DDF0D9;
  --yellow: #FBF1D0;
  --grey: #F6F6F6;
  --stop: #e03131;
  --hand: "Patrick Hand", "LXGW WenKai", "Comic Sans MS", cursive;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "PingFang SC", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: #fff;
  color: var(--ink);
  font-family: var(--hand);
  font-size: 18px;
  line-height: 1.45;
}
:lang(zh-CN) body, body:lang(zh-CN) { font-size: 17px; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
a { color: inherit; }
code, .mono, pre { font-family: var(--mono); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- header ---------- */
.top {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 16px 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.top h1 { font-size: 32px; line-height: 1.15; }
.lead { color: var(--muted); margin-top: 4px; }
.lang { display: flex; gap: 6px; flex-shrink: 0; }
.lang button, .chapters button, .controls button, .to-live, .live-actions button {
  border: 1.5px solid var(--ink);
  background: #fff;
  border-radius: 10px;
  padding: 4px 12px;
  cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--yellow); }
button:focus-visible, a:focus-visible { outline: 2.5px solid #1971c2; outline-offset: 2px; }
button:disabled { opacity: .4; cursor: default; }

main { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* ---------- walkthrough ---------- */
.chapters { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.chapters button[aria-current="step"] { background: var(--yellow); }

.walk-body {
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(300px, 1fr);
  gap: 16px;
  align-items: start;
}
.stage-wrap {
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage { width: 100%; }
.stage svg.stage-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 560px;
  animation: stage-in .35s ease;
}
@keyframes stage-in { from { opacity: 0; } to { opacity: 1; } }

/* Arrows are faint at rest. The arrow of the current hop is dark. */
.stage .flowchart-link {
  opacity: .16;
  transition: opacity .3s ease;
}
.stage .flowchart-link.is-hop {
  opacity: 1;
  stroke-width: 2.6px !important;
}

/* The active node. */
/* Patrick Hand has no bold face; a thin stroke makes node titles bold without changing their width. */
.stage .nodeLabel b { -webkit-text-stroke: .5px currentColor; }
.stage g.actor { transition: filter .3s ease; }
.stage g.actor.is-on {
  filter: drop-shadow(0 0 5px rgba(250, 176, 5, 1)) drop-shadow(0 0 10px rgba(250, 176, 5, .8));
}

/* The token that moves along the arrow. */
.stage .token {
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 2.5;
  transition: opacity .45s ease .15s;
}
.stage .token.is-done { opacity: 0; }

/* The red stop mark. */
.stage .stop-mark circle { fill: var(--stop); stroke: #fff; stroke-width: 2.5; }
.stage .stop-mark path { stroke: #fff; stroke-width: 3; stroke-linecap: round; fill: none; }
.stage .stop-mark { animation: pop .3s ease; transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { opacity: 0; } to { opacity: 1; } }

.narration {
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chapter-title { color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }
.step-title { font-size: 24px; line-height: 1.2; }
.step-text code, .live code {
  font-size: .86em;
  background: var(--grey);
  border: 1px solid #e2e2e2;
  border-radius: 5px;
  padding: 0 4px;
}
.databox {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--grey);
  border: 1.5px dashed #9a9a9a;
  border-radius: 10px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.databox[hidden] { display: none; }
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.controls button { padding: 6px 14px; }
.controls #next:not(:disabled) { background: var(--yellow); }
.counter { color: var(--muted); font-size: 16px; text-align: center; }
.to-live { align-self: flex-start; font-size: 16px; }

/* ---------- live panel ---------- */
.live {
  margin: 28px 0 8px;
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
}
.live h2 { font-size: 26px; margin-bottom: 8px; }
.live-intro { display: grid; gap: 2px; }
.live-rp { margin-top: 8px; font-family: var(--mono); font-size: 14px; }
.live-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 6px; }
.live-actions button { padding: 6px 14px; }
#btnCreate:not(:disabled) { background: var(--lav); }
#btnSignIn:not(:disabled) { background: var(--blue); }
.live-note, .live-stored { color: var(--muted); font-size: 16px; }
.live-stored { font-family: var(--mono); font-size: 13.5px; overflow-wrap: anywhere; margin-top: 4px; }
.live-status { margin-top: 8px; }
.live-status:empty { display: none; }
.live-status.is-error { color: #b42318; }
.live-status.is-info { color: var(--muted); }
.live-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 12px; }
.live-results > div:empty { display: none; }
.result-card {
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  padding: 12px;
  background: var(--grey);
  display: grid;
  gap: 10px;
  align-content: start;
}
.result-card h3 { font-size: 21px; }
.selftest { margin-top: 12px; max-width: 640px; }
.selftest ul { margin: 0; padding-left: 4px; list-style: none; display: grid; gap: 2px; }
.rgroup { background: #fff; border: 1px solid #d8d8d8; border-radius: 10px; padding: 8px 10px; }
.rgroup-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.rgroup-title { font-weight: bold; }
.steplink {
  font-family: var(--mono);
  font-size: 13px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 0 6px;
  text-decoration: none;
  background: var(--yellow);
}
.rows { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 10px; margin: 0; }
.rows dt { color: var(--muted); font-size: 15px; }
.rows dd { margin: 0; font-size: 13.5px; overflow-wrap: anywhere; word-break: break-all; }
.rows dd.note { grid-column: 1 / -1; font-family: var(--hand); font-size: 15px; word-break: normal; color: var(--muted); }
.rows dt.check-label { color: var(--ink); font-size: 15px; }
.rows dd.check { font-family: var(--hand); font-size: 15px; word-break: normal; }
.is-pass { color: #2b8a3e; }
.is-fail { color: #b42318; }
.is-unknown { color: var(--muted); }

.foot { max-width: 1240px; margin: 0 auto; padding: 14px 16px 28px; color: var(--muted); font-size: 15px; }

/* ---------- narrow screens ---------- */
@media (max-width: 1099px) {
  .walk-body { grid-template-columns: 1fr; }
}
@media (max-width: 899px) {
  .live-results { grid-template-columns: 1fr; }
}
@media (max-width: 639px) {
  body { font-size: 17px; }
  .top { flex-direction: column; gap: 10px; padding-top: 14px; }
  .top h1 { font-size: 27px; }
  .chapters button { padding: 3px 9px; font-size: 16px; }
  .stage-wrap { padding: 6px; }
  .stage svg.stage-svg { max-height: 50vh; }
  .step-title { font-size: 21px; }
  .rows { grid-template-columns: 1fr; }
  .rows dt { margin-top: 4px; }
  .controls {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    border-top: 1.5px solid var(--ink);
    z-index: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage svg.stage-svg, .stage .stop-mark { animation: none; }
  .stage .flowchart-link, .stage g.actor, .stage .token { transition: none; }
}
