:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --ink-soft: #3f3f46;
  --muted: #8a8a8e;
  --faint: #b9b9be;
  --line: #ececec;
  --line-soft: #f1f1f0;
  --accent: #ff385c;
  --pos: #0ca678;
  --neg: #e8384f;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04), 0 1px 1px rgba(17, 24, 39, 0.03);
  --shadow: 0 6px 24px rgba(17, 24, 39, 0.06), 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-lg: 0 18px 50px rgba(17, 24, 39, 0.12);
  --r-planner: #6366f1;
  --r-reader: #2563eb;
  --r-implementer: #0ca678;
  --r-builder: #f08c00;
  --r-evaluator: #7c3aed;
  --r-finalizer: #e8384f;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}
.i { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 366px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "bar    bar"
    "stage  detail"
    "dock   dock";
  gap: 16px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 24px 18px;
}

/* ---------- top bar ---------- */
.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  display: grid; place-items: center;
}
.logo svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.brand-txt h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.brand-txt .sub { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

.metrics { display: flex; gap: 10px; }
.m {
  min-width: 92px;
  padding: 9px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  text-align: left;
}
.m strong { display: block; font-size: 18px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.m label { display: block; margin-top: 3px; font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.m:first-child strong { color: var(--pos); }

/* ---------- stage ---------- */
.stagewrap {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.stagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.stagehead-left { display: flex; align-items: center; gap: 12px; }
.stagehead h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.phase {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  box-shadow: var(--shadow-sm);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.phase.win { color: var(--pos); border-color: #c4ecdd; background: #eafaf3; }

.perf { text-align: right; line-height: 1; }
.perf-num {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--pos);
  font-variant-numeric: tabular-nums;
  display: inline-block;
}
.perf-num.flat { color: var(--muted); }
.perf-num.bump { animation: bump 0.6s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }
.perf-sub { margin-top: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.perf-sub .up { color: var(--pos); }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 20px;
  background: radial-gradient(120% 80% at 50% 0%, #ffffff 0%, #fbfbfa 70%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tier-tag {
  position: absolute;
  left: 18px;
  transform: translateY(-50%);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.stage.stepping .tier-tag { opacity: 1; }
.intro-head {
  position: absolute;
  top: 27%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(24px, 3.4vw, 38px);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.stage.intro .intro-head { opacity: 1; }
.winner-tag { top: 17%; }
.bid-tag-label { top: 50%; }
.idle-tag { top: 82%; }

.legend {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 999px; display: inline-block; }
.d-bid { background: #f6c945; }
.d-win { background: var(--pos); }
.d-new { background: #fff; border: 2px dashed var(--ink); }
.legend-hint { margin-left: auto; color: var(--faint); }

/* ---------- agent nodes ---------- */
.node {
  --c: var(--muted);
  position: absolute;
  width: 64px; height: 64px;
  margin: 0; padding: 0; border: 0;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.1);
  transition:
    left 560ms cubic-bezier(0.4, 0, 0.2, 1),
    top 560ms cubic-bezier(0.4, 0, 0.2, 1),
    width 560ms cubic-bezier(0.4, 0, 0.2, 1),
    height 560ms cubic-bezier(0.4, 0, 0.2, 1),
    opacity 460ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 460ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 4;
}
.node::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: color-mix(in srgb, var(--c) 16%, #fff);
  border: 2px solid color-mix(in srgb, var(--c) 70%, #fff);
}
.node .glyph {
  position: relative;
  z-index: 2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--c) 78%, #1d1d1f);
}
.node .wchip {
  position: absolute;
  z-index: 5;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  box-shadow: var(--shadow-sm);
}
.node .deltachip {
  position: absolute;
  z-index: 6;
  top: -10px;
  right: -6px;
  font-size: 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 6px;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.stage.checkout .node .deltachip { opacity: 1; transform: scale(1); }
.node .deltachip.up { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 45%, #fff); }
.node .deltachip.down { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 45%, #fff); }
.node .deltachip.nil { color: var(--muted); }
.stage.checkout .node.gain::before { border-color: color-mix(in srgb, var(--pos) 58%, #fff); }
.stage.checkout .node.loss::before { border-color: color-mix(in srgb, var(--neg) 58%, #fff); }
.node .name {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 96px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.7);
  padding: 1px 6px;
  border-radius: 6px;
}
.node .bidpill {
  position: absolute;
  z-index: 5;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #946200;
  background: #fff7e0;
  border: 1px solid #ffe49b;
  border-radius: 999px;
  padding: 1px 7px;
  opacity: 0;
  transition: opacity 0.35s ease;
}
.node:hover { z-index: 30; }

.node.idle { opacity: 0.4; filter: saturate(0.7); }
.node.idle .name { opacity: 0; }
.node.bidding { opacity: 1; }
.node.bidding .bidpill { opacity: 1; }
.node.bidding::before { box-shadow: 0 0 0 4px color-mix(in srgb, #f6c945 26%, transparent); }

.node.winner {
  width: 76px; height: 76px;
  z-index: 12;
}
.node.winner::before {
  border-color: color-mix(in srgb, var(--c) 85%, #fff);
  box-shadow:
    0 0 0 5px color-mix(in srgb, var(--c) 18%, transparent),
    0 0 0 11px color-mix(in srgb, var(--c) 8%, transparent);
}
.node.winner .glyph { color: color-mix(in srgb, var(--c) 92%, #1d1d1f); }
.node.selected::before { border-color: var(--ink); box-shadow: 0 0 0 4px rgba(29, 29, 31, 0.12); }
.node.born { animation: pop 0.5s cubic-bezier(0.2, 1.3, 0.4, 1); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.node.dead { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }

.delta {
  position: absolute;
  z-index: 20;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  pointer-events: none;
  animation: rise 1300ms ease-out forwards;
}
.delta.gain { color: var(--pos); }
.delta.loss { color: var(--neg); }
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, 6px); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -26px); }
}

/* ---------- detail panel ---------- */
.detail {
  grid-area: detail;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.detail .d-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0; }
.detail h3 { margin: 2px 0 0; font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.detail .d-narration { margin: 6px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-soft); }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv .cell {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 11px;
  background: #fcfcfb;
}
.kv .cell label { display: block; font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.kv .cell span { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }

.section-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 0; }
.bidrow { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: #fcfcfb;
  color: var(--ink-soft);
}
.chip .cdot { width: 8px; height: 8px; border-radius: 999px; background: var(--c, var(--muted)); flex: none; }
.chip.win { border-color: color-mix(in srgb, var(--pos) 45%, #fff); background: #e9f9f2; color: #0a7d5a; }

.thought, .prompt {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  background: #fbfbfa;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  white-space: pre-wrap;
  overflow: auto;
}
.thought { max-height: 200px; }
.prompt { flex: 1; min-height: 90px; }
.tool-pill {
  align-self: flex-start;
  font-size: 12px; font-weight: 700;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: #1d1d1f; color: #fff;
  border-radius: 8px; padding: 4px 9px;
}
.events { display: flex; flex-direction: column; gap: 6px; }
.event { font-size: 12px; color: var(--ink-soft); display: flex; gap: 7px; align-items: baseline; }
.event .tag { font-size: 9.5px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; border-radius: 5px; padding: 1px 5px; }
.event.birth .tag { color: #0a7d5a; background: #e7f8f1; }
.event.death .tag { color: #b22a3c; background: #fdeef0; }
.event.replay .tag { color: #946200; background: #fff7e0; }

.backbtn {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: none; border: none; cursor: pointer; padding: 0;
}
.backbtn:hover { color: var(--ink); }

/* ---------- dock ---------- */
.dock {
  grid-area: dock;
  display: flex;
  align-items: center;
  gap: 18px;
}
.transport { display: flex; align-items: center; gap: 8px; flex: none; }
.transport .icon, .transport .play {
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.1s, box-shadow 0.18s, background 0.18s, border-color 0.18s;
}
.transport .icon { width: 40px; }
.transport .icon .i { width: 18px; height: 18px; }
.transport #resetBtn, .transport #prevBtn, .transport #nextBtn { width: auto; gap: 7px; padding: 0 14px; font-size: 13px; font-weight: 600; }
.transport #resetBtn .i, .transport #prevBtn .i, .transport #nextBtn .i { width: 16px; height: 16px; }
.transport .play { gap: 8px; padding: 0 18px; font-size: 14px; font-weight: 700; background: var(--ink); color: #fff; border-color: var(--ink); }
.transport .play .i { width: 16px; height: 16px; }
.transport button:hover { box-shadow: var(--shadow); }
.transport button:active { transform: scale(0.95); }

.track { flex: 1; min-width: 0; }
.track-top { display: flex; justify-content: space-between; margin-bottom: 5px; }
.track-label { font-size: 11.5px; font-weight: 600; color: var(--ink-soft); }
.track-label.muted { color: var(--muted); }
.curve { width: 100%; height: 26px; display: block; }
.curve .area { fill: rgba(12, 166, 120, 0.1); stroke: none; }
.curve .ln { fill: none; stroke: var(--pos); stroke-width: 2; }
.curve .mk { fill: var(--pos); }

.timeline { display: flex; align-items: flex-end; gap: 3px; height: 26px; margin-top: 4px; }
.ep {
  flex: 1 1 0;
  height: 100%;
  border: none; background: none; padding: 0;
  display: flex; align-items: flex-end; justify-content: center;
  cursor: pointer;
}
.ep .bar { width: 100%; max-width: 14px; min-height: 4px; border-radius: 4px 4px 2px 2px; background: #e2e2df; transition: background 0.2s, transform 0.15s; }
.ep.done .bar { background: #bfe9d8; }
.ep.rollback .bar { background: #ececea; }
.ep.cur .bar { background: var(--pos); box-shadow: 0 0 0 2px color-mix(in srgb, var(--pos) 28%, transparent); }
.ep:hover .bar { transform: scaleX(1.12); }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 100;
  max-width: 260px;
  background: rgba(29, 29, 31, 0.96);
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  backdrop-filter: blur(6px);
}
.tooltip b { font-weight: 700; }
.tooltip .muted { color: #b9b9be; }

/* ---------- phase stepper ---------- */
.stagehead-right { display: flex; align-items: center; gap: 16px; }
.stepper { display: inline-flex; align-items: center; gap: 7px; }
.pstep { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--faint); text-transform: lowercase; transition: color 0.25s; }
.pstep i { width: 8px; height: 8px; border-radius: 999px; background: #dcdce0; transition: background 0.25s, box-shadow 0.25s, transform 0.25s; }
.pstep.done { color: var(--muted); }
.pstep.done i { background: var(--muted); }
.pstep.active { color: var(--ink); }
.pstep.active i { background: var(--c, var(--pos)); transform: scale(1.3); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c, var(--pos)) 18%, transparent); }
.parrow { width: 14px; height: 1.5px; background: #e2e2e2; border-radius: 2px; }

.progbtn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; box-shadow: var(--shadow-sm); cursor: pointer;
  transition: box-shadow 0.18s, border-color 0.18s, transform 0.1s;
}
.progbtn:hover { box-shadow: var(--shadow); }
.progbtn:active { transform: scale(0.96); }
.progbtn .i { width: 15px; height: 15px; }

/* ---------- node id badge + coin ---------- */
.node .idbadge {
  position: absolute; z-index: 6; top: -7px; right: -7px;
  min-width: 16px; height: 16px; padding: 0 3px;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 800; color: #fff;
  background: var(--c); border-radius: 999px;
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.2);
}
.node .wchip { top: -10px; left: -6px; transform: none; }
.coin {
  position: absolute; z-index: 25; transform: translate(-50%, -50%);
  font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: #946200; background: #fff7e0; border: 1px solid #ffe49b;
  border-radius: 999px; padding: 2px 9px; box-shadow: var(--shadow);
  pointer-events: none;
  transition: left 720ms cubic-bezier(0.4, 0, 0.2, 1), top 720ms cubic-bezier(0.4, 0, 0.2, 1), opacity 320ms ease;
}

/* ---------- payment line + sparkline ---------- */
.payline { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); flex-wrap: wrap; }
.payline.muted { color: var(--muted); font-weight: 500; }
.payline .cdot { width: 8px; height: 8px; border-radius: 999px; flex: none; }
.payline .arrow { color: var(--faint); }
.payline .amt { color: #946200; background: #fff7e0; border: 1px solid #ffe49b; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 42px; display: block; }
.spark .ln { fill: none; stroke: var(--pos); stroke-width: 2; }
.spark .area { fill: rgba(12, 166, 120, 0.1); stroke: none; }

/* ---------- timeline mutation marker ---------- */
.ep { position: relative; }
.ep .mut {
  position: absolute; top: -1px; left: 50%;
  width: 5px; height: 5px; background: var(--r-evaluator);
  transform: translateX(-50%) rotate(45deg); border-radius: 1px;
}

/* ---------- program modal ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: rgba(20, 22, 28, 0.42); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card {
  width: min(1060px, calc(100vw - 40px)); max-height: 86vh;
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-body { display: flex; min-height: 0; flex: 1; border-top: 1px solid var(--line); }
.modal-prog { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px 10px; }
.modal-head h3 { margin: 2px 0 0; font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.modal-close { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.modal-close:hover { color: var(--ink); box-shadow: var(--shadow-sm); }
.modal-close .i { width: 18px; height: 18px; }
.diffstat { padding: 12px 20px; font-size: 12.5px; font-weight: 700; color: var(--muted); display: flex; gap: 16px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.diffstat .add { color: var(--pos); }
.diffstat .del { color: var(--neg); }
.diff { margin: 0; padding: 0 0 16px; overflow: auto; flex: 1; min-height: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; line-height: 1.55; background: #fcfcfb; border-top: 1px solid var(--line); }
.diff .ln { display: block; padding: 0 20px; white-space: pre-wrap; word-break: break-word; }
.diff .ln.add { background: #e9f9f1; color: #0a7d5a; }
.diff .ln.del { background: #fdeef0; color: #b22a3c; }
.diff .ln.ctx { color: var(--ink-soft); }
.diff .ln .gutter { display: inline-block; width: 12px; opacity: 0.55; user-select: none; }

/* ---------- mutation markers + detail ---------- */
.node.mut::after {
  content: ""; position: absolute; inset: -5px; border-radius: 999px;
  border: 1.5px dashed color-mix(in srgb, var(--c) 60%, #fff); pointer-events: none;
}
.node.winner.mut::after { inset: -7px; }
.gentag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.03em; vertical-align: middle;
  border-radius: 999px; padding: 2px 8px; margin-left: 6px;
  color: var(--c, var(--muted)); background: color-mix(in srgb, var(--c, #888) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--c, #888) 30%, #fff);
}
.gentag.founder { color: var(--muted); background: #f4f4f2; border-color: var(--line); }
.mutbox { background: #fbfbfa; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
.mut-behavior { margin: 6px 0 0; font-size: 13px; font-weight: 600; line-height: 1.45; color: var(--ink); }
.mut-trigger { margin: 7px 0 0; font-size: 12px; line-height: 1.4; color: var(--muted); }
.mut-trigger b { color: var(--ink-soft); font-weight: 700; }

/* ---------- modal topology ---------- */
.modal-topo {
  flex: 0 0 336px; padding: 14px 18px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.modal-topo .section-label { margin-bottom: 8px; }
.topo-meta { font-weight: 500; color: var(--muted); text-transform: none; letter-spacing: 0; }
.modal-topo-stage { background: #fbfbfa; border: 1px solid var(--line); border-radius: 12px; padding: 6px; flex: 1; min-height: 0; display: flex; }
.mt-svg { width: 100%; height: 100%; min-height: 360px; display: block; }
.mt-svg .mt-label { font-size: 8.5px; fill: var(--ink-soft); text-anchor: middle; font-family: "Inter", sans-serif; font-weight: 600; }
.mt-svg .mt-tag { font-size: 7.5px; fill: var(--muted); text-anchor: middle; font-family: "Inter", sans-serif; font-weight: 800; letter-spacing: 0.06em; }
.modal-topo-legend { display: flex; align-items: center; gap: 14px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.modal-topo-legend span { display: inline-flex; align-items: center; gap: 5px; }
.modal-topo-legend i { width: 9px; height: 9px; border-radius: 999px; display: inline-block; }
.modal-topo-legend .mt-hint { margin-left: auto; color: var(--faint); }

/* ---------- payment flow + agent ledger ---------- */
.payflow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; font-weight: 600; margin-top: 4px; color: var(--ink-soft); }
.payflow.muted { color: var(--muted); font-weight: 500; }
.payflow .cdot { width: 8px; height: 8px; border-radius: 999px; }
.pf-a, .pf-b { display: inline-flex; align-items: center; gap: 5px; }
.pf-arrow { color: var(--faint); font-weight: 800; }
.payamt { font-variant-numeric: tabular-nums; font-weight: 800; border-radius: 999px; padding: 1px 6px; font-size: 11px; }
.payamt.out { color: #b22a3c; background: #fdeef0; }
.payamt.in { color: #0a7d5a; background: #e7f8f1; }
.paynote { margin: 5px 0 0; font-size: 11px; color: var(--muted); }
.payflow.self { color: var(--ink-soft); }
.pf-self { display: inline-flex; align-items: center; gap: 5px; }
.pf-loop { width: 15px; height: 15px; fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.pf-self-lbl { color: var(--muted); font-weight: 700; }
.pf-void { color: var(--faint); font-weight: 700; letter-spacing: 0.02em; }
.selfpay-tag {
  position: absolute;
  transform: translate(0, -50%);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: 12px; font-weight: 700; color: var(--ink-soft);
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.55s ease;
}
.selfpay-tag.show { opacity: 1; }
.selfpay-tag svg { width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.thought.clamp { margin: 8px 0 0; font-size: 12px; line-height: 1.5; color: var(--ink-soft); background: #fbfbfa; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; white-space: pre-wrap; max-height: 92px; overflow-y: auto; }
.thought.clamp::-webkit-scrollbar { width: 8px; }
.thought.clamp::-webkit-scrollbar-thumb { background: #d7d7d4; border-radius: 8px; border: 2px solid #fbfbfa; }
.thought.clamp::-webkit-scrollbar-thumb:hover { background: #c2c2bf; }

.ledger-title { margin-top: 14px; }
.ledger { display: flex; flex-direction: column; gap: 2px; }
.lrow { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 5px 7px; cursor: pointer; transition: background 0.15s; position: relative; }
.lrow:hover { background: #f6f6f4; }
.lrow.acting { background: color-mix(in srgb, var(--pos) 9%, #fff); }
.lcdot { width: 9px; height: 9px; border-radius: 999px; flex: none; }
.lname { font-size: 12px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; max-width: 104px; overflow: hidden; text-overflow: ellipsis; }
.lbadge { font-size: 8.5px; font-weight: 800; letter-spacing: 0.03em; border-radius: 5px; padding: 1px 4px; flex: none; }
.lbadge.new { color: #0a7d5a; background: #e7f8f1; }
.lbadge.gen { color: var(--c); background: color-mix(in srgb, var(--c) 13%, #fff); }
.lbadge.out { color: #b22a3c; background: #fdeef0; }
.lbarwrap { flex: 1; height: 6px; background: #ededeb; border-radius: 999px; overflow: hidden; min-width: 20px; }
.lbar { display: block; height: 100%; border-radius: 999px; transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.lwealth { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); min-width: 48px; text-align: right; flex: none; }
.lwealth.neg { color: #b22a3c; text-decoration: line-through; }
.lrow.dead { opacity: 0.55; cursor: default; }
.lrow.dead:hover { background: none; }
.lrow.dead.recent { animation: deadflash 1.1s ease; }
@keyframes deadflash { 0%, 100% { background: none; } 35% { background: #fdeef0; } }
.ledger-sep { margin: 9px 0 4px; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); padding: 0 7px; }
.ldelta { position: absolute; right: 8px; top: -3px; font-size: 10px; font-weight: 800; font-variant-numeric: tabular-nums; opacity: 0; pointer-events: none; animation: ldeltapop 1.25s ease-out; }
.ldelta.out { color: #b22a3c; }
.ldelta.in { color: #0a7d5a; }
@keyframes ldeltapop { 0% { opacity: 0; transform: translateY(5px); } 22% { opacity: 1; } 100% { opacity: 0; transform: translateY(-11px); } }
.lrow.pay-out { animation: flashout 0.95s ease; }
.lrow.pay-in { animation: flashin 0.95s ease; }
@keyframes flashout { 0%, 100% { background: none; } 30% { background: #fdeef0; } }
@keyframes flashin { 0%, 100% { background: none; } 30% { background: #e7f8f1; } }

/* ---------- view tabs ---------- */
.viewtabs { display: flex; gap: 2px; margin-left: 14px; background: #f1f1f0; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.viewtabs a { font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none; padding: 5px 11px; border-radius: 7px; transition: color 0.15s, background 0.15s; }
.viewtabs a:hover { color: var(--ink); }
.viewtabs a.on { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

.topo-sub { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.unit { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

/* ---------- topology stage ---------- */
.topo-stage { overflow: hidden; }
.edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; overflow: visible; }
.edge { fill: none; stroke: #cfd2d8; stroke-width: 2; opacity: 0.9; transition: opacity 0.4s ease; }
.edge.lo { stroke: #34b27a; }
.edge.mid { stroke: #e0a43a; }
.edge.hi { stroke: #e3675f; }
#arrow path { fill: context-stroke; }

.tnode {
  position: absolute; transform: translate(-50%, -50%);
  width: 18px; height: 18px; padding: 0; border: 0; background: none; cursor: pointer; z-index: 4;
  display: grid; place-items: center;
  transition: left 600ms cubic-bezier(0.4, 0, 0.2, 1), top 600ms cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
}
.tnode .ring {
  width: 16px; height: 16px; border-radius: 999px; background: var(--c);
  border: 2px solid #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 16%, transparent), 0 2px 6px rgba(17, 24, 39, 0.18);
  transition: transform 0.2s, box-shadow 0.2s;
}
.tnode:hover { z-index: 30; }
.tnode:hover .ring { transform: scale(1.2); }
.tnode .tlabel {
  position: absolute; top: calc(50% + 13px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 10.5px; font-weight: 600; color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.78); padding: 1px 5px; border-radius: 5px;
}
.tnode .tag {
  position: absolute; top: calc(50% - 25px); left: 50%; transform: translateX(-50%);
  font-size: 8.5px; font-weight: 800; letter-spacing: 0.06em; color: #fff;
  background: var(--c); border-radius: 4px; padding: 1px 5px;
}
.tnode.src .ring { width: 24px; height: 24px; box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 22%, transparent), 0 3px 8px rgba(17, 24, 39, 0.22); }
.tnode.dst .ring { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--c), 0 2px 6px rgba(17, 24, 39, 0.18); }
.tnode.sel .ring { box-shadow: 0 0 0 3px var(--ink); }
.tnode.pin { opacity: 0; }
.tnode.gone { opacity: 0; }

.legend .dot.ring-src { background: var(--ink-soft); }
.legend .dot.ring-dst { background: #fff; border: 2px solid var(--ink-soft); }

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "bar" "stage" "detail" "dock"; height: auto; }
  .stage { flex: none; height: 460px; min-height: 460px; }
  .metrics { display: none; }
}
@media (max-width: 720px) {
  .modal-body { flex-direction: column; }
  .modal-topo { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--line); }
  .modal-topo-stage { flex: none; }
  .mt-svg { min-height: 300px; }
}
