.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; }
.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; gap: 12px; min-width: 0; }
.scene-host { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.scene { display: block; width: 100%; height: auto; }
.scene .links path { fill: none; stroke: var(--line-strong); stroke-width: 1.4; }
.scene .links .dlq-link { stroke-dasharray: 5 5; }
.scene .ring { fill: none; stroke: var(--line); stroke-width: 1.2; stroke-dasharray: 3 6; }
.scene .box rect { fill: var(--inset); stroke: var(--line-strong); stroke-width: 1.2; }
.scene .kafka > rect { fill: transparent; }
.scene .lane rect { fill: var(--inset); stroke: var(--line); stroke-width: 1; transition: stroke .2s, fill .2s; }
.scene .lane.active rect { fill: var(--accent-soft); stroke: var(--accent-line); }
.scene .box.active > rect { fill: var(--accent-soft); stroke: var(--accent-line); }
.scene .node circle { fill: var(--inset); stroke: var(--line-strong); stroke-width: 1.4; transition: fill .3s, stroke .3s; }
.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; }
.scene-offset { fill: var(--muted); font-family: var(--mono); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.scene-outcome { fill: var(--accent-ink); font-family: var(--mono); font-size: 12.5px; font-weight: 600; opacity: 0; transition: opacity .25s; }
.scene-outcome.shown { opacity: 1; }
.scene .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.scene .dot.bad { fill: var(--bad); }

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

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

.tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.table-card { min-width: 0; padding: 12px 14px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.table-name { margin: 0 0 6px; color: var(--faint); font-family: var(--mono); font-size: 11px; overflow-wrap: anywhere; }
.table-card table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.table-card th { padding: 3px 4px; color: var(--faint); font-weight: 400; font-size: 10.5px; text-align: right; }
.table-card th:first-child, .table-card td:first-child { text-align: left; }
.table-card td { padding: 4px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
.table-card td.changed { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.table-card tr.static td { color: var(--muted); }
.table-card tr.static td.changed { color: var(--accent-ink); }
.table-card tr.empty td { color: var(--faint); text-align: left; }
.table-card tr.fresh td { background: var(--accent-soft); color: var(--accent-ink); }
.card-note { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.card-big { margin: 4px 0 0; font-family: var(--mono); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.heat { width: 100%; border-collapse: separate; border-spacing: 2px; font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.heat th { padding: 2px 4px; color: var(--faint); font-weight: 400; font-size: 10.5px; text-align: center; }
.heat td { height: 24px; padding: 0 4px; border: 0; border-radius: 4px; background: rgb(from var(--accent) r g b / var(--level)); color: var(--ink); text-align: center; }
.heat td.heat-strong { color: #fff; }
.heat td.heat-name { background: transparent; color: var(--muted); text-align: left; }
.heat td.heat-empty { background: var(--inset); }
.tables[data-count="4"] .table-card:last-child { grid-column: 1 / -1; }

.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; }
[data-part="extra"] > .foot-title { margin-top: 16px; }
.levels { display: grid; gap: 4px; font-family: var(--mono); font-size: 12.5px; }
.level { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px; padding: 6px 10px; border-radius: 8px; background: var(--inset); }
.level-name { color: var(--muted); }
.level.failed .level-value { color: var(--bad-ink); }
.levels + .foot-link { display: inline-block; margin-top: 8px; }

.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) {
  .tables { grid-template-columns: repeat(2, minmax(0, 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 { 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) {
  .tables { grid-template-columns: 1fr; }
}
.scene .lane.bad rect { fill: var(--bad-soft); stroke: var(--bad); }
.scene .scene-outcome { fill: var(--bad-ink); }
