:root {
  --bg: #12100e;
  --dock: #1c1814;
  --panel: #26201a;
  --line: #3f362c;
  --text: #f4ecdf;
  --muted: #cbb89a;
  --accent: #d4b06a;
  --ok: #6f9d72;
  --run: #c4843a;
  --err: #c56b5c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.module-home-link {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  font-size: 20px;
}

.module-home-link:hover {
  border-color: var(--accent);
  color: var(--text);
}
#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 48px 1fr;
  height: 100%;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #181410;
}
.brand { font-weight: 650; color: var(--accent); letter-spacing: 0.04em; }
.phase {
  font-size: 13px;
  color: var(--text);
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  max-width: min(52vw, 560px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-id,
.code-version {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.session-id code,
.code-version code {
  color: var(--text);
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
  letter-spacing: 0;
}
.code-version code {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.code-version.stale code { color: var(--err); }
.spacer { flex: 1; }

.play-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 4px 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.play-speed-label { color: var(--muted); }
.play-speed #speedLabel {
  min-width: 2.6em;
  text-align: center;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.speed-btn {
  min-width: 28px;
  padding: 2px 8px !important;
  line-height: 1.2;
  font-size: 14px;
}

.preview-perf {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 4px 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.preview-perf-label { color: var(--muted); }
.preview-perf-btn {
  min-width: 4.5em;
  padding: 2px 10px !important;
  line-height: 1.2;
  font-size: 12px;
  color: var(--accent);
}
.preview-perf-btn[aria-pressed="false"] {
  color: var(--muted);
}
.walk-compare.low-perf {
  min-height: 88px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 10px;
}

.dock {
  border-right: 1px solid var(--line);
  background: var(--dock);
  padding: 14px;
  overflow: auto;
}
.dock h2 {
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--accent);
}
.dock label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
.dock input[type="text"],
.dock input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #14110e;
  color: var(--text);
  font: inherit;
}
.identity-preview {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: -2px 0 10px;
}
.identity-preview img {
  width: 56px;
  height: 72px;
  object-fit: contain;
  background: #14110e;
  border: 1px solid var(--line);
}
.identity-preview span {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
}
.dock textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  resize: vertical;
  background: #14110e;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  line-height: 1.4;
}
.dock .check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
  color: var(--text);
}
.tree-hint {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}
.dock .row { display: flex; gap: 8px; }
.confirm-box {
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #2a2318;
}
.confirm-box p { margin: 0 0 10px; font-size: 13px; }

.export-tools {
  margin-top: 12px;
  padding-top: 2px;
  border-top: 1px solid var(--line);
}
.export-status {
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.export-hint {
  margin: 6px 0 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}
.export-panel-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 2px;
}
.export-tools button {
  margin: 4px 6px 4px 0;
}
.panel-export-dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  background: #241e16;
  color: var(--text);
  min-width: min(320px, 92vw);
}
.panel-export-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.panel-export-dialog h3 {
  margin: 0 0 10px;
  font-size: 15px;
}
.panel-export-dialog label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}
.panel-export-dialog input {
  display: block;
  width: 100%;
  margin-top: 6px;
  box-sizing: border-box;
}
.panel-export-dialog .row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
button {
  appearance: none;
  border: 1px solid var(--line);
  background: #302820;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary {
  width: 100%;
  background: #3d3420;
  border-color: var(--accent);
  color: #f3e4bc;
  margin-bottom: 8px;
}
button.ghost { background: transparent; }
.concept-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #14110e;
}
.concept-tab {
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.concept-tab + .concept-tab {
  border-left: 1px solid var(--line);
}
.concept-tab:hover {
  border-color: transparent;
  color: var(--text);
  background: #1c1814;
}
.concept-tab.is-active {
  background: #3d3420;
  color: #f3e4bc;
}
.concept-tab-panels {
  margin-bottom: 8px;
}
.concept-tab-panel[hidden] {
  display: none !important;
}
.concept-tab-lead {
  margin: 0 0 10px;
  color: #9a9178;
  font-size: 12px;
  line-height: 1.45;
}
.concept-upload {
  display: block;
  margin: 0 0 8px;
  color: var(--muted, #b7ae96);
  font-size: 12px;
}
.concept-upload input {
  display: block;
  width: 100%;
  margin-top: 4px;
}
.concept-upload-clothes {
  display: block;
  margin: 0 0 8px;
  color: var(--muted, #b7ae96);
  font-size: 12px;
}
.concept-upload-hint {
  margin: 0 0 4px;
  color: #9a9178;
  font-size: 12px;
  line-height: 1.45;
}
#btnUploadConcept,
#btnConcept {
  width: 100%;
  margin-bottom: 8px;
}

.log {
  font-size: 12px;
  color: var(--text);
  max-height: 320px;
  overflow: auto;
  line-height: 1.5;
  font-family: ui-monospace, Consolas, monospace;
}
.log div { padding: 3px 0; border-bottom: 1px dashed #3a3228; }
.log-time {
  display: inline-block;
  min-width: 5.4em;
  margin-right: 8px;
  color: #9a8b72;
  font-variant-numeric: tabular-nums;
}

.viewport {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 20%, #1c1814 0%, var(--bg) 55%);
  cursor: grab;
}
.viewport.panning { cursor: grabbing; }
.world {
  position: absolute;
  left: 0; top: 0;
  width: 8000px;
  height: 6000px;
  transform-origin: 0 0;
}
.grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
}
.wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

.node {
  position: absolute;
  width: 168px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  overflow: hidden;
  user-select: none;
}
.node.type-hub,
.node.type-stub,
.node.type-action_trigger,
.node.type-action {
  width: 168px;
  border-radius: 8px;
  background: #2a241c;
}
.node.type-hub .bd,
.node.type-stub .bd,
.node.type-action_trigger .bd,
.node.type-action .bd {
  height: auto;
  min-height: 40px;
  padding: 8px 10px 10px;
  background: #14110e;
  place-items: start;
}
.node .note {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  opacity: 0.92;
}
.node .placeholder {
  color: var(--text);
  font-size: 13px;
}
.node.type-stub {
  opacity: 0.72;
  border-style: dashed;
}
.node .hd {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  font-size: 11px;
  border-bottom: 1px solid var(--line);
  cursor: move;
}
.node.type-hub .hd,
.node.type-stub .hd,
.node.type-action_trigger .hd,
.node.type-action .hd {
  border-bottom: 1px solid var(--line);
}
.node .hd strong { font-weight: 600; color: var(--text); }
.canvas-action-button {
  width: 100%;
  margin: 0;
  padding: 9px 8px;
}
.node .bd {
  height: 148px;
  background-color: #737373;
  background-image:
    linear-gradient(45deg, #8a8a8a 25%, transparent 25%),
    linear-gradient(-45deg, #8a8a8a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8a8a8a 75%),
    linear-gradient(-45deg, transparent 75%, #8a8a8a 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  display: grid;
  place-items: center;
}
.node.type-walk {
  width: 252px;
}
.node.type-walk .bd {
  height: 188px;
  padding: 4px 5px 2px;
  position: relative;
}
.walk-compare {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.walk-compare .col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.walk-compare .cap {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.2;
}
.walk-compare .col.pose .cap {
  color: #8a9a7a;
}

.node .bd img,
.node .bd canvas.anim-canvas {
  max-width: 100%;
  max-height: 148px;
  display: block;
}
/* Seedream HD stills (概念/三视/八向/内观背包) — smooth downscale, not nearest-neighbor */
.node .bd img {
  image-rendering: auto;
}
/* Mir-scale action canvases stay crisp when zoomed */
.node .bd canvas.anim-canvas {
  image-rendering: pixelated;
}
.node.type-walk .bd canvas.anim-canvas {
  max-height: 164px;
}
.node.type-walk .bd canvas.anim-canvas {
  cursor: pointer;
}
.node.type-walk .bd canvas.gen-canvas {
  image-rendering: auto;
}
.node.type-concept .bd img,
.node.type-view3 .bd img,
.node.type-dir8 .bd img {
  max-height: 168px;
}
.walk-preview-open {
  position: absolute;
  top: 7px;
  right: 8px;
  min-width: 68px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid #806d47;
  border-radius: 3px;
  background: rgb(18 17 14 / 92%);
  color: #dac98b;
  font-size: 11px;
  cursor: pointer;
}
.walk-preview-open:hover,
.walk-preview-open:focus-visible {
  border-color: var(--accent);
  background: #29251b;
  outline: none;
}
.frame-preview {
  width: min(1120px, 96vw);
  height: min(900px, 94vh);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #080808;
  color: var(--text);
  overflow: hidden;
}
/* Only flex when open — unconditional display:flex overrides UA display:none
   on closed <dialog>, so × / Esc appear to do nothing. */
.frame-preview[open] {
  display: flex;
  flex-direction: column;
}
.frame-preview::backdrop {
  background: rgb(0 0 0 / 78%);
}
.frame-preview-bar {
  min-height: 48px;
  padding: 0 8px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #15130f;
  font-size: 12px;
  color: var(--muted);
}
.frame-preview-heading {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.frame-preview-heading strong {
  color: var(--text);
  white-space: nowrap;
}
.frame-preview-heading span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.frame-preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.frame-preview-regenerate,
.frame-preview-accept {
  height: 30px;
  padding: 0 11px;
  border: 1px solid #8f773d;
  border-radius: 3px;
  background: #2a2415;
  color: #f0df9f;
  font-size: 11px;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
}
.frame-preview-accept {
  border-color: #4d7a52;
  background: #162018;
  color: #b7e0bc;
}
.frame-preview-regenerate:hover,
.frame-preview-regenerate:focus-visible {
  border-color: #c6a955;
  background: #352d19;
  outline: none;
}
.still-preview-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(68vh, 720px);
  padding: 16px;
  background:
    linear-gradient(45deg, #1a1a1a 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1a 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1a 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #111;
  border: 1px solid #2c2c2c;
  border-radius: 4px;
}
.still-preview-stage img {
  max-width: min(92vw, 900px);
  max-height: min(68vh, 720px);
  object-fit: contain;
  image-rendering: auto;
}
.still-preview-hint {
  margin: 8px 0 0;
  color: #9a9178;
  font-size: 12px;
  line-height: 1.45;
}
.node .bd img {
  cursor: zoom-in;
}
.node-regen-still {
  display: block;
  width: 100%;
  margin-top: 6px;
  height: 26px;
  border: 1px solid #8f773d;
  border-radius: 3px;
  background: #2a2415;
  color: #f0df9f;
  font-size: 11px;
  cursor: pointer;
}
.node-regen-still:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.frame-preview-accept:hover,
.frame-preview-accept:focus-visible {
  border-color: #78b67f;
  background: #1d2c20;
  outline: none;
}
.frame-preview-regenerate:disabled,
.frame-preview-accept:disabled {
  border-color: var(--line);
  background: #17150f;
  color: var(--muted);
  cursor: default;
  opacity: 0.65;
}
.frame-preview-icon {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #0d0c09;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.frame-preview-icon:hover,
.frame-preview-icon:focus-visible {
  border-color: var(--accent);
  color: #e4d294;
  outline: none;
}
.frame-preview-counter {
  min-width: 42px;
  color: var(--text);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.frame-preview-review-reasons {
  flex: 0 0 auto;
  margin: 0;
  padding: 8px 14px 10px;
  border-bottom: 1px solid #5a3a28;
  background: #241810;
  color: #f0c9a0;
}
.frame-preview-review-reasons[hidden] {
  display: none;
}
.frame-preview-review-reasons strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: #ffc089;
}
.frame-preview-review-reasons ul {
  margin: 0;
  padding-left: 18px;
  max-height: 88px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
}
.frame-preview-review-reasons li + li {
  margin-top: 2px;
}
.frame-preview-generated-tools {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.frame-preview-shadow-modes {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
}
.frame-preview-shadow-modes[hidden] {
  display: none;
}
.frame-preview-shadow-modes button {
  min-width: 48px;
  height: 26px;
  padding: 0 7px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #0d0c09;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}
.frame-preview-shadow-modes button:last-child {
  border-right: 0;
}
.frame-preview-shadow-modes button:hover,
.frame-preview-shadow-modes button:focus-visible {
  color: var(--text);
  outline: none;
}
.frame-preview-shadow-modes button.active {
  background: #2a2415;
  color: #f0df9f;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.frame-preview-shadow-modes button:disabled {
  opacity: 0.4;
  cursor: default;
}
.frame-preview-candidates {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
}
.frame-preview-candidate {
  min-width: 48px;
  height: 26px;
  padding: 0 8px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #0d0c09;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.frame-preview-candidate:last-child {
  border-right: 0;
}
.frame-preview-candidate.selected {
  color: #d6c68c;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.frame-preview-candidate.viewing {
  background: #262219;
  color: var(--text);
}
.frame-preview-close {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.frame-preview-body {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(260px, 1fr) 104px auto 78px;
  overflow: hidden;
}
.frame-compare-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  background: var(--line);
}
.frame-compare-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
  background: #080808;
}
.frame-compare-panel > header {
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: #11100d;
  color: var(--muted);
  font-size: 11px;
}
.frame-compare-panel > header strong {
  margin-right: 7px;
  color: var(--text);
  font-size: 12px;
}
.frame-preview-stage {
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  background-color: #737373;
  background-image:
    linear-gradient(45deg, #8a8a8a 25%, transparent 25%),
    linear-gradient(-45deg, #8a8a8a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8a8a8a 75%),
    linear-gradient(-45deg, transparent 75%, #8a8a8a 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}
.frame-preview-stage img {
  position: absolute;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  display: block;
  object-fit: contain;
  image-rendering: auto;
}
.frame-preview-stage.original-stage img {
  image-rendering: pixelated;
}
.frame-preview-empty {
  color: var(--muted);
  font-size: 12px;
}
.frame-prompt-section {
  min-height: 0;
  padding: 7px 10px 9px;
  display: grid;
  grid-template-rows: 22px auto auto minmax(0, 1fr);
  gap: 6px;
  border-top: 1px solid var(--line);
  background: #0e0d0a;
}
.frame-correction-label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}
.frame-correction-input {
  width: 100%;
  min-height: 48px;
  max-height: 88px;
  resize: vertical;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #17150f;
  color: var(--text);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.frame-correction-input:focus {
  outline: 1px solid #8a7340;
  border-color: #8a7340;
}
.frame-correction-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.frame-section-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.frame-copy-prompt {
  min-width: 74px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #17150f;
  color: var(--text);
  font-size: 10px;
  cursor: pointer;
}
.frame-copy-prompt:hover,
.frame-copy-prompt:focus-visible {
  border-color: var(--accent);
  outline: none;
}
.frame-copy-prompt:disabled {
  cursor: default;
  opacity: 0.45;
}
.frame-prompt-text {
  min-width: 0;
  min-height: 0;
  margin: 4px 0 0;
  padding: 7px 9px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #050505;
  color: #ccc4b5;
  font-family: inherit;
  font-size: 11px;
  line-height: 1.55;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: text;
}
.frame-reference-section {
  padding: 8px 10px 9px;
  border-top: 1px solid var(--line);
  background: #0c0b09;
}
.frame-section-heading {
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
}
.frame-section-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.frame-reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 7px;
}
.frame-reference-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  border: 1px solid var(--line);
  background: #050505;
}
.frame-reference-item > header {
  padding: 7px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}
.frame-reference-item > header strong {
  color: var(--text);
  font-size: 11px;
}
.frame-reference-stage {
  height: 128px;
  position: relative;
  overflow: hidden;
  background-color: #737373;
  background-image:
    linear-gradient(45deg, #8a8a8a 25%, transparent 25%),
    linear-gradient(-45deg, #8a8a8a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8a8a8a 75%),
    linear-gradient(-45deg, transparent 75%, #8a8a8a 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}
.frame-reference-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.frame-reference-item.load-error {
  opacity: 0.45;
}
.frame-preview-strip {
  min-width: 0;
  padding: 7px 10px;
  display: flex;
  align-items: stretch;
  gap: 7px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  background: #11100d;
}
.frame-preview-thumb {
  width: 72px;
  min-width: 72px;
  height: 72px;
  padding: 3px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #050505;
  color: var(--muted);
  cursor: pointer;
}
.frame-preview-thumb:hover,
.frame-preview-thumb:focus-visible {
  border-color: #806d47;
  outline: none;
}
.frame-preview-thumb.active {
  border-color: var(--accent);
  color: #e4d294;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.frame-preview-thumb img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}
.frame-preview-thumb span {
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1120px) {
  .topbar { gap: 8px; }
  .session-id span,
  .code-version span,
  .play-speed-label {
    display: none;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }
  .module-home-link {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  font-size: 20px;
}

.module-home-link:hover {
  border-color: var(--accent);
  color: var(--text);
}
#app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto 420px;
    height: auto;
    min-height: 100vh;
  }
  .topbar {
    grid-column: 1;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 48px;
    padding: 7px;
    overflow: visible;
  }
  .brand {
    flex: 1 1 180px;
  }
  .phase {
    flex: 0 0 auto;
  }
  .session-id,
  .code-version {
    flex: 1 1 130px;
    overflow: hidden;
  }
  .session-id code,
  .code-version code {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .spacer {
    display: none;
  }
  .dock {
    grid-column: 1;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .viewport {
    grid-column: 1;
    min-height: 420px;
  }
  .session-id,
  .code-version {
    padding-left: 7px;
  }
  .session-id span,
  .code-version span,
  .play-speed-label {
    display: none;
  }
  .frame-preview {
    width: 98vw;
    height: 96vh;
  }
  .frame-preview-bar {
    padding-left: 9px;
  }
  .frame-preview-heading span {
    display: none;
  }
  .frame-preview-actions {
    gap: 4px;
  }
  .frame-preview-regenerate,
  .frame-preview-accept {
    width: 30px;
    min-width: 30px;
    max-width: none;
    padding: 0;
    font-size: 0;
  }
  .frame-preview-regenerate::before {
    content: "↻";
    display: block;
    font-size: 18px;
    line-height: 1;
  }
  .frame-preview-accept::before {
    content: "✓";
    display: block;
    font-size: 16px;
    line-height: 1;
  }
  .frame-preview-body {
    display: block;
    overflow-y: auto;
  }
  .frame-compare-grid {
    height: 580px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .frame-compare-panel {
    grid-template-rows: 34px minmax(0, 1fr);
  }
  .frame-prompt-section {
    height: 150px;
  }
  .frame-section-actions {
    gap: 4px;
  }
  .frame-reference-section {
    min-height: 180px;
  }
  .frame-reference-grid {
    display: flex;
    overflow-x: auto;
  }
  .frame-reference-item {
    width: 300px;
    min-width: 300px;
  }
  .frame-preview-strip {
    position: sticky;
    bottom: 0;
    height: 78px;
    z-index: 2;
  }
  .frame-preview-thumb {
    width: 62px;
    min-width: 62px;
    height: 62px;
  }
}
.node .ft {
  padding: 5px 9px 7px;
  font-size: 11px;
  color: var(--text);
  opacity: 0.9;
}
.node.running { border-color: var(--run); }
.node.await_confirm { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.node.done { border-color: #4a5d45; }
.node.weak { border-color: #b88746; }
.node.pending { opacity: 0.7; }
.node.error { border-color: var(--err); }

.badge {
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge.run { color: #f0c48a; border-color: var(--run); }
.badge.ok { color: #b6d7b4; border-color: var(--ok); }
.badge.warn { color: #efbd79; border-color: #b88746; }
.badge.wait { color: var(--accent); border-color: var(--accent); }
.badge.stub { color: #9a9386; border-color: #5a5348; border-style: dashed; }
.badge.ready { color: #d8bd82; border-color: #8a7350; }
