:root {
  --bg: #090b10;
  --panel: #0e1118;
  --text: #cbd5e1;
  --dim: #64748b;
  --violet: #a78bfa;
  --green: #4ade80;
  --blue: #60a5fa;
  --orange: #fb923c;
  --amber: #fbbf24;
  --cyan: #22d3ee;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse 80% 50% at 50% 0, rgba(167, 139, 250, .08), transparent), var(--bg);
  color: var(--text);
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
}

b { font-weight: 700; }
.dim { color: var(--dim); }
.c-violet { --c: var(--violet); color: var(--c); }
.c-green { --c: var(--green); color: var(--c); }
.c-blue { --c: var(--blue); color: var(--c); }
.c-orange { --c: var(--orange); color: var(--c); }
.c-amber { --c: var(--amber); color: var(--c); }
.c-cyan { --c: var(--cyan); color: var(--c); }
.c-dim { --c: #334155; }

.tui { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 32px 16px 16px; }
.top { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; margin-bottom: 20px; }
.brand { color: var(--violet); font-weight: 700; letter-spacing: .2em; }

.grid { display: grid; grid-template-columns: 1fr 230px; gap: 20px; align-items: start; }

/* 面板：边框取所在色，正文保持浅色 */
.box {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px;
  border: 1px solid var(--c);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  transition: box-shadow .4s, opacity .4s;
}
.box > b:first-child { color: var(--c); }
.node { text-align: center; align-items: center; }
.node.on { box-shadow: 0 0 0 1px var(--c), 0 0 22px -4px var(--c); }
.node.idle { opacity: .55; }

.flow { display: flex; flex-direction: column; align-items: center; }
.flow > .box { width: min(100%, 360px); }
#n-router { width: min(100%, 440px); text-align: left; align-items: stretch; }
.row { display: flex; justify-content: space-between; gap: 12px; white-space: nowrap; margin: 0 8px; }
#n-router .row:first-child b { color: var(--green); }

/* 连线：虚线 + 流动光点 */
.wire { position: relative; width: 1px; height: 30px; border-left: 1px dashed var(--c); }
.wire::after, .fan i::after {
  content: ""; position: absolute; left: -3px; top: 0;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 8px var(--c);
  animation: drop 1.3s linear infinite;
}
.wire.label { height: 46px; }
.wire.label span { position: absolute; top: 12px; left: 12px; white-space: nowrap; color: var(--text); }
@keyframes drop { from { top: -3px; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } to { top: calc(100% - 2px); opacity: 0; } }

.fan, .stages { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.fan { position: relative; height: 26px; }
.fan::before { content: ""; position: absolute; left: calc(100% / 6); right: calc(100% / 6); top: 0; border-top: 1px dashed #334155; }
.fan.merge::before { top: auto; bottom: 0; }
.fan i { position: relative; justify-self: center; width: 1px; border-left: 1px dashed var(--c); }
.fan.merge i::after { animation-delay: .4s; }
.stages .box { margin: 0 6px; }
.bar { color: var(--c); letter-spacing: -1px; }

/* 规划者侧栏 */
.side { gap: 1px; }
.side hr { width: 100%; margin: 8px 0; border: 0; border-top: 1px dashed #334155; }
.script { margin: 0; min-height: 10.5em; color: var(--violet); font: inherit; white-space: pre-wrap; }
.script::after { content: "▌"; color: var(--violet); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.kv { display: flex; justify-content: space-between; }
.kv b { color: var(--blue); font-weight: 400; }
.mark { color: var(--dim); }
.mark.on { color: var(--text); background: rgba(167, 139, 250, .18); }

/* 日志与状态栏 */
.logbox { position: relative; margin-top: 22px; padding-top: 14px; }
.legend { position: absolute; top: -9px; left: 12px; padding: 0 6px; background: var(--bg); color: var(--dim); }
.log { list-style: none; margin: 0; padding: 0; min-height: 9.3em; }
.log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: fadein .3s ease-out; }
.log time { color: var(--dim); margin-right: 10px; }
.log .src { display: inline-block; min-width: 8ch; font-weight: 700; }
@keyframes fadein { from { opacity: 0; } }

.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px;
  margin-top: 10px; padding: 6px 10px;
  background: #121620; border-radius: 4px;
}
.toggle {
  margin-left: auto; min-width: 44px; min-height: 32px; padding: 0 8px;
  border: 0; background: none; color: var(--dim); font: inherit; cursor: pointer;
}
.toggle:hover { color: var(--text); }
.toggle:focus-visible, a:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.paused .wire::after, .paused .fan i::after, .paused .script::after { animation-play-state: paused; }

/* 状态栏式页脚：细线与正文内容同宽对齐 */
footer {
  width: calc(100% - 32px); max-width: 1008px; margin: 8px auto 0; padding: 14px 0 24px;
  border-top: 1px solid #1a2030;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 24px;
  font-size: 11.5px; letter-spacing: .02em;
}
footer a { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); text-decoration: none; white-space: nowrap; transition: color .2s; }
footer a:hover, footer a:focus-visible { color: var(--text); }

@media (max-width: 760px) {
  body { font-size: 11px; }
  .grid { grid-template-columns: 1fr; }
  .stages .box { margin: 0 3px; padding: 8px 6px; }
  .side { order: 2; }
  .wire.label span { left: auto; right: 10px; }   /* 标签挪到连线左侧，窄屏不溢出 */
}

@media (prefers-reduced-motion: reduce) {
  .wire::after, .fan i::after, .script::after, .log li { animation: none; }
  .box { transition: none; }
}
