.wrap.wide { width: min(1320px, 100% - 2 * var(--gutter)); }
.lead { max-width: 640px; margin: 18px 0 0; color: var(--muted); font-size: 18px; line-height: 1.55; }
.chapter-lead { max-width: 640px; margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.stage-chapter { padding-top: 48px; }
.hero { padding-top: 64px; }
.hero .wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); align-items: center; column-gap: 48px; }
.hero h1, .hero .lead { grid-column: 1; }
.hero .hero-sketch { grid-column: 2; grid-row: 1 / span 2; width: 100%; margin: 0; }

.stage { overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.tabs { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 11px; }
.tabs button { height: 32px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--hover); color: var(--ink); }
.stage-tools { display: none; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
.stage [data-for] { display: none; }
.stage[data-mode="run"] .stage-tools[data-for="run"] { display: flex; }
.stage[data-mode="run"] .run-body[data-for="run"],
.stage[data-mode="run"] .run-foot[data-for="run"],
.stage[data-mode="code"] .codebook[data-for="code"] { display: grid; }
.stage .counter { min-width: 92px; color: var(--faint); font-family: var(--mono); font-size: 12.5px; text-align: center; font-variant-numeric: tabular-nums; }
.stage .icon-button:disabled { opacity: .4; cursor: default; }
.stage .icon-button.primary { border-color: var(--accent-line); color: var(--accent-ink); }

.run-body { grid-template-columns: 250px minmax(0, 1fr); gap: 20px; padding: 20px; background: var(--inset); }
.steps { display: grid; align-content: start; gap: 2px; max-height: 620px; overflow: auto; padding-right: 4px; }
.step { display: grid; gap: 2px; padding: 9px 12px; border: 0; border-left: 2px solid transparent; border-radius: 0 9px 9px 0; background: transparent; color: var(--muted); text-align: left; cursor: pointer; transition: background .15s, color .15s; }
.step:hover { background: var(--hover); color: var(--ink); }
.step.done { color: var(--ink); }
.step[aria-current="true"] { border-left-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.step-name { font-size: 14px; line-height: 1.35; }
.step-type { color: var(--faint); font-family: var(--mono); font-size: 11px; }

.run-main { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr); grid-template-areas: 'note note' 'scene cards'; align-items: start; align-content: start; gap: 12px 16px; min-width: 0; }
.run-main .scene-host { grid-area: scene; }
.run-main .run-note { grid-area: note; }
.run-main .cards { grid-area: cards; }
.scene-host { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.scene { display: block; width: 100%; height: auto; }
.scene .ring { fill: none; stroke: var(--line); stroke-width: 1.2; stroke-dasharray: 3 6; }
.scene .node circle { fill: var(--inset); stroke: var(--line-strong); stroke-width: 1.4; transition: fill .3s, stroke .3s; }
.scene .node.replica circle { stroke: var(--accent-line); stroke-width: 2; }
.scene .node.flash circle { animation: flash 900ms ease-out; }
.scene .node.down circle { fill: transparent; stroke: var(--faint); stroke-dasharray: 4 4; }
.scene .node.down text { fill: var(--faint); }
.scene-title { fill: var(--ink); font-family: var(--mono); font-size: 13px; font-weight: 600; }
.scene-sub { fill: var(--faint); font-family: var(--mono); font-size: 10.5px; }

@keyframes flash {
  0% { fill: var(--accent-soft); stroke: var(--accent); }
  100% { fill: var(--inset); stroke: var(--line-strong); }
}

.node-id { fill: var(--ink); font-family: var(--mono); font-size: 17px; font-weight: 600; }
.scene .cut { fill: none; stroke: var(--bad); stroke-width: 1.6; stroke-dasharray: 7 6; opacity: 0; transition: opacity .3s; }
.scene .cut.shown, .scene .cut-label.shown { opacity: 1; }
.scene .cut-label { fill: var(--bad-ink); opacity: 0; transition: opacity .3s; }
.scene .flight { stroke: var(--surface); stroke-width: 2; }
.scene .flight.request { fill: var(--accent); }
.scene .flight.reply { fill: var(--muted); }
.scene .flight.background { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.scene .flight.lost { fill: var(--bad); }
.scene .flight.burst { animation: burst 420ms ease-out forwards; }
.scene .bubble rect { stroke-width: 1.2; }
.scene .bubble rect.ask { fill: var(--surface); stroke: var(--line-strong); }
.scene .bubble rect.answer { fill: var(--accent-soft); stroke: var(--accent-line); }
.bubble-text { fill: var(--ink); font-family: var(--mono); font-size: 13px; }
.scene .node .scene-sub { font-size: 12px; }

@keyframes burst {
  to { r: 14; opacity: 0; }
}

.run-note { min-height: 1.5em; margin: 0; color: var(--muted); font-size: 14.5px; }


.steps-head { display: grid; gap: 2px; margin: 12px 12px 6px; }
.steps-head:first-child { margin-top: 0; }
.steps-title { font-size: 13px; font-weight: 600; }
.steps-test { color: var(--faint); font-family: var(--mono); font-size: 10.5px; }

.cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
.card { min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.card.down { opacity: .55; }
.card-head { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 8px; font-family: var(--mono); font-size: 12px; }
.card-node { font-weight: 600; }
.card-role { color: var(--faint); }
.card-empty { margin: 0; color: var(--faint); font-size: 12.5px; }
.card-hint { margin: 8px 0 0; color: var(--accent-ink); font-family: var(--mono); font-size: 12px; }
.version { display: grid; gap: 4px; padding: 7px 9px; border-radius: 8px; background: var(--inset); }
.version + .version { margin-top: 6px; }
.version.changed { background: var(--accent-soft); }
.version-value { display: flex; flex-wrap: wrap; gap: 4px; font-family: var(--mono); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.version-meta { color: var(--muted); font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums; }
.item { display: inline-flex; gap: 4px; align-items: baseline; }
.item-tag { color: var(--faint); font-size: 10.5px; font-weight: 400; }
.mono-block.trace { max-height: 260px; overflow: auto; white-space: pre; overflow-wrap: normal; font-size: 11px; font-variant-ligatures: none; }

.run-foot { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; padding: 18px 20px 20px; border-top: 1px solid var(--line); }
.foot-col { min-width: 0; }
.foot-title { margin: 0 0 8px; color: var(--faint); font-size: 12.5px; }
.mono-block { margin: 0; padding: 10px 12px; border-radius: 9px; background: var(--inset); color: var(--ink); font-family: var(--mono); font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.foot-meta { margin: 8px 0 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.foot-link { color: var(--accent-ink); font-size: 13px; }

.codebook { grid-template-columns: 240px minmax(0, 1fr); gap: 16px; min-height: clamp(440px, calc(100svh - 170px), 760px); padding: 20px; background: var(--inset); }
.files, .viewer { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.files { display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; }
.files-title { margin: 0 10px 8px; color: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.files-list { display: grid; gap: 2px; }
.file { display: grid; gap: 1px; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; transition: background .15s; }
.file:hover { background: var(--hover); }
.file[aria-current="true"] { background: var(--accent-soft); }
.file-dir { color: var(--faint); font-family: var(--mono); font-size: 10.5px; overflow-wrap: anywhere; }
.file-name { font-family: var(--mono); font-size: 13px; }
.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 520px; overflow: hidden; }
.viewer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 18px 0; }
.viewer-path { font-family: var(--mono); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.viewer-link { color: var(--accent-ink); font-size: 12.5px; white-space: nowrap; }
.viewer-about { margin: 6px 18px 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.viewer-body { position: relative; flex: 1; min-height: 0; max-height: 640px; margin-top: 8px; padding: 0 6px 12px; overflow: auto; }
.codebook .code { margin: 0; padding: 8px 0; font-size: 13px; line-height: 1.85; }
.codebook .code .ln { grid-template-columns: 44px minmax(0, 1fr) auto; border-radius: 6px; }
.codebook .code .ln.noted:hover { background: var(--hover); }
.codebook .code .ln .tag { border-color: var(--accent-line); color: var(--accent-ink); font-size: 11.5px; }

.stage-chapter .fine { margin-top: 12px; }

@media (max-width: 1100px) {
  .run-main { grid-template-columns: 1fr; grid-template-areas: 'note' 'scene' 'cards'; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
}

@media (max-width: 900px) {
  .hero .wrap { grid-template-columns: 1fr; }
  .hero .hero-sketch { grid-column: 1; grid-row: auto; max-width: 420px; margin-top: 24px; }
  .run-body { grid-template-columns: 1fr; }
  .steps { max-height: none; grid-auto-flow: column; grid-auto-columns: minmax(170px, 1fr); overflow-x: auto; padding-bottom: 6px; }
  .step { border-left: 0; border-bottom: 2px solid transparent; border-radius: 9px 9px 0 0; }
  .step[aria-current="true"] { border-bottom-color: var(--accent); }
  .run-foot { grid-template-columns: 1fr; }
  .codebook { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
}
