/* ============================================================
   峰影 · 漫剧画布 —— 视觉基调
   深色工作台：画布要退到背景里，节点是唯一的主角。
   ============================================================ */

:root {
  --bg:          #0b0d12;
  --bg-2:        #101319;
  --panel:       #151922;
  --panel-2:     #1a1f2a;
  --line:        #232936;
  --line-soft:   #1b202b;
  --ink:         #e8ecf4;
  --ink-2:       #9aa4b8;
  --ink-3:       #626d82;
  --accent:      #6d8cff;
  --accent-2:    #8f6dff;
  --ok:          #35c98a;
  --warn:        #ffb648;
  --bad:         #ff5f6d;
  --hot:         #ff7a59;

  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 15px;

  --shadow-1: 0 2px 8px rgba(0,0,0,.35);
  --shadow-2: 0 12px 40px rgba(0,0,0,.55);
  --glow:     0 0 0 1px rgba(109,140,255,.55), 0 8px 28px rgba(109,140,255,.18);

  --topbar-h: 52px;
  --dock-h:   200px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Microsoft YaHei UI", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #2a3141; border-radius: 6px; border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #3a4358; background-clip: content-box; }

/* ══════════════════════════════ 顶栏 ══════════════════════════════ */

.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  flex-wrap: nowrap; white-space: nowrap;
  background: linear-gradient(180deg, #12161e 0%, #0e121a 100%);
  border-bottom: 1px solid var(--line);
  z-index: 60;
  user-select: none;
}

.brand { display: flex; align-items: baseline; gap: 7px; padding-right: 4px; flex: none; white-space: nowrap; }
.logo {
  font-size: 17px; color: var(--accent);
  text-shadow: 0 0 14px rgba(109,140,255,.7);
  line-height: 1;
}
.brand-name { font-size: 13.5px; font-weight: 650; letter-spacing: .3px; white-space: nowrap; }
.brand-sub {
  font-size: 10px; color: var(--ink-3); letter-spacing: .8px;
  text-transform: uppercase; white-space: nowrap;
}

.tb-sep { width: 1px; height: 20px; background: var(--line); flex: none; }
.tb-spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--panel); color: var(--ink);
  font-size: 12.5px; white-space: nowrap;
  transition: background .14s, border-color .14s, transform .1s;
}
.btn:hover  { background: var(--panel-2); border-color: #2e3648; }
.btn:active { transform: translateY(1px); }
.btn.ghost  { background: transparent; }
.btn.ghost:hover { background: rgba(255,255,255,.045); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 3px 14px rgba(109,140,255,.3);
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.node-add {
  height: 28px; padding: 0 9px; font-size: 12px;
  color: var(--ink-2);
}
.node-add:hover { color: var(--ink); }

.caret { font-size: 9px; color: var(--ink-3); margin-left: 2px; }

.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-3); flex: none;
}
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.run-state {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--ink-2);
  padding: 0 10px; height: 26px;
  border-radius: 13px; background: rgba(255,255,255,.03);
  max-width: 320px;
}
.run-state .pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-3); flex: none;
}
.run-state.busy .pulse {
  background: var(--hot);
  animation: pulse 1.1s ease-in-out infinite;
}
.run-state.busy { color: var(--hot); background: rgba(255,122,89,.08); }
@keyframes pulse {
  0%,100% { opacity: 1;  transform: scale(1); }
  50%     { opacity: .35; transform: scale(1.35); }
}
#run-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.zoom-box {
  display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  overflow: hidden; background: var(--panel);
}
.zbtn {
  width: 28px; height: 28px; border: 0; background: transparent;
  color: var(--ink-2); font-size: 14px; line-height: 1;
  display: grid; place-items: center;
}
.zbtn:hover { background: rgba(255,255,255,.06); color: var(--ink); }
.zbtn.zval { width: 50px; font-size: 11.5px; font-family: var(--mono); }

/* ══════════════════════════════ 画布 ══════════════════════════════ */

#viewport {
  position: fixed; inset: var(--topbar-h) 0 0 0;
  overflow: hidden; cursor: default;
  background: radial-gradient(1200px 700px at 50% 30%, #0f131b 0%, var(--bg) 70%);
}
#viewport.panning { cursor: grabbing; }

#grid-bg {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.032) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.032) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.055) 1px, transparent 1px);
  background-size: 26px 26px, 26px 26px, 130px 130px, 130px 130px;
  background-position: 0 0;
  opacity: 1;
}

#world {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
#wires {
  position: absolute; top: 0; left: 0;
  overflow: visible; pointer-events: none;
  width: 1px; height: 1px;
}
#nodes { position: absolute; top: 0; left: 0; }

/* ---- 连线 ---- */
.wire {
  fill: none;
  stroke: #2f3a52;
  stroke-width: 1.6;
  transition: stroke .15s;
}
.wire.live {
  stroke: url(#grad-live);
  stroke-dasharray: 5 5;
  animation: flow 1s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -20; } }
.wire.hot { stroke: var(--accent); stroke-width: 2.2; }

/* ══════════════════════════════ 节点 ══════════════════════════════ */

.node {
  position: absolute;
  width: 300px;
  background: linear-gradient(180deg, #1a1f29 0%, #151a23 100%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  transition: box-shadow .16s, border-color .16s;
  overflow: hidden;
}
.node:hover { border-color: #313a4d; box-shadow: var(--shadow-2); }
.node.sel { border-color: rgba(109,140,255,.6); box-shadow: var(--glow); }
.node.dragging { transition: none; z-index: 999; }

.node-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line-soft);
  cursor: grab;
  user-select: none;
}
.node.dragging .node-head { cursor: grabbing; }
.node-head:active { cursor: grabbing; }

.node-icon {
  width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center;
  font-size: 12px; flex: none;
  background: rgba(109,140,255,.14); color: var(--accent);
}
.node-icon.c-character { background: rgba(53,201,138,.14); color: var(--ok); }
.node-icon.c-shots     { background: rgba(255,182,72,.14); color: var(--warn); }
.node-icon.c-image     { background: rgba(143,109,255,.14); color: var(--accent-2); }
.node-icon.c-video     { background: rgba(255,122,89,.14); color: var(--hot); }
.node-icon.c-output    { background: rgba(53,201,138,.14); color: var(--ok); }

.node-title {
  font-size: 12.5px; font-weight: 600; letter-spacing: .2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1;
}
.node-tag {
  font-size: 10px; color: var(--ink-3);
  font-family: var(--mono);
  flex: none;
}
.node-body { padding: 10px 11px 11px; max-height: 440px; overflow: hidden; }

.node-foot {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 11px;
  border-top: 1px solid var(--line-soft);
  background: rgba(0,0,0,.16);
}

.node-state {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--ink-3);
  font-family: var(--mono);
}
.node-state::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; flex: none;
}
.node-state.s-done    { color: var(--ok); }
.node-state.s-running { color: var(--hot); }
.node-state.s-failed  { color: var(--bad); }

/* ---- 端口 ---- */
.port {
  position: absolute; width: 11px; height: 11px;
  border-radius: 50%; background: #2b3346;
  border: 2px solid #3d4761;
  top: 50%; transform: translateY(-50%);
  cursor: crosshair; z-index: 5;
  transition: background .14s, border-color .14s, transform .12s;
}
.port:hover { background: var(--accent); border-color: #a9bcff; transform: translateY(-50%) scale(1.28); }
.port.in  { left: -6px; }
.port.out { right: -6px; background: var(--accent); border-color: #8ea6ff; }

/* ---- 节点内部元素 ---- */
.n-textarea {
  width: 100%; min-height: 120px; max-height: 300px;
  resize: vertical;
  background: #0d1117; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 9px; font-size: 12px; line-height: 1.65;
  outline: none;
}
.n-textarea:focus { border-color: rgba(109,140,255,.55); }

.n-meta {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  font-size: 11px; color: var(--ink-3);
  margin-bottom: 8px;
}
.n-meta b { color: var(--ink-2); font-weight: 500; font-family: var(--mono); }

.n-thumb {
  width: 100%; aspect-ratio: 9/16; max-height: 260px;
  object-fit: cover; border-radius: var(--r-sm);
  background: #0a0d12; display: block;
}
.n-thumb.wide { aspect-ratio: 16/9; }
.n-thumb-empty {
  width: 100%; aspect-ratio: 9/16; max-height: 260px;
  border: 1px dashed #2b3346; border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: var(--ink-3); font-size: 11px;
  background: repeating-linear-gradient(45deg, #0c1017, #0c1017 6px, #0e1219 6px, #0e1219 12px);
}

.n-avatars { display: flex; flex-wrap: wrap; gap: 7px; }
.n-avatar {
  width: 56px; text-align: center;
}
.n-avatar img {
  width: 56px; height: 56px; border-radius: 9px;
  object-fit: cover; background: #0a0d12;
  border: 1px solid var(--line);
  display: block;
}
.n-avatar .ph {
  width: 56px; height: 56px; border-radius: 9px;
  border: 1px dashed #2b3346; display: grid; place-items: center;
  color: var(--ink-3); font-size: 16px;
}
.n-avatar span {
  display: block; font-size: 10.5px; color: var(--ink-2);
  margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.n-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.n-table th {
  text-align: left; color: var(--ink-3); font-weight: 500;
  padding: 4px 6px; border-bottom: 1px solid var(--line-soft);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px;
}
.n-table td {
  padding: 5px 6px; border-bottom: 1px solid rgba(255,255,255,.028);
  color: var(--ink-2); vertical-align: middle;
}
.n-table tr:hover td { background: rgba(109,140,255,.055); }
.n-table td.id { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.n-table .pill {
  display: inline-block; padding: 1px 6px; border-radius: 9px;
  font-size: 10px; background: rgba(255,255,255,.06); color: var(--ink-2);
}
.pill.ok  { background: rgba(53,201,138,.16); color: var(--ok); }
.pill.run { background: rgba(255,122,89,.16); color: var(--hot); }
.pill.bad { background: rgba(255,95,109,.16); color: var(--bad); }
.pill.none{ background: rgba(255,255,255,.05); color: var(--ink-3); }

.n-scroll { max-height: 300px; overflow: auto; margin: -4px -6px; padding: 4px 6px; }

.n-progress {
  height: 3px; border-radius: 2px; background: #1e2534; overflow: hidden;
  margin-top: 8px;
}
.n-progress i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .3s ease;
}

.n-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ══════════════════════════════ 空态 ══════════════════════════════ */

#empty-state {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  pointer-events: none;
}
#empty-state.show { display: flex; }
#empty-state > * { pointer-events: auto; }
.es-icon {
  font-size: 44px; color: #232b3c;
  text-shadow: 0 0 40px rgba(109,140,255,.2);
}
.es-title { font-size: 15px; font-weight: 600; color: var(--ink-2); }
.es-desc  { font-size: 12.5px; color: var(--ink-3); margin-bottom: 6px; }

.hint {
  position: absolute; left: 14px; bottom: 14px;
  font-size: 11px; color: #3d4658;
  pointer-events: none; user-select: none;
}

/* ══════════════════════════════ 属性面板 ══════════════════════════════ */

.inspector {
  position: fixed; top: var(--topbar-h); right: 0; bottom: 0;
  width: 340px; background: var(--bg-2);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  z-index: 50; display: flex; flex-direction: column;
}
.inspector.open { transform: translateX(0); }

.insp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 13px; border-bottom: 1px solid var(--line);
  font-size: 12.5px; font-weight: 600;
}
.insp-body { flex: 1; overflow: auto; padding: 13px; }
.insp-empty { color: var(--ink-3); font-size: 12px; text-align: center; padding: 30px 0; }

.xbtn {
  width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: transparent; color: var(--ink-3); font-size: 17px;
  line-height: 1; display: grid; place-items: center;
}
.xbtn:hover { background: rgba(255,255,255,.07); color: var(--ink); }

.field { margin-bottom: 13px; }
.field label {
  display: block; font-size: 11px; color: var(--ink-3);
  margin-bottom: 5px; letter-spacing: .3px;
}
.field input[type=text],
.field input[type=number],
.field textarea,
.field select {
  width: 100%; background: #0d1117; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 7px 9px; font-size: 12px; outline: none;
}
.field textarea { min-height: 78px; resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: rgba(109,140,255,.55);
}
.field .row { display: flex; gap: 7px; }
.field .row > * { flex: 1; }

.switch {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0; font-size: 12px; color: var(--ink-2);
}
.switch input { width: 34px; height: 18px; appearance: none;
  background: #232b3a; border-radius: 9px; position: relative;
  cursor: pointer; outline: none; transition: background .16s; flex: none; }
.switch input:checked { background: var(--accent); }
.switch input::after {
  content: ''; position: absolute; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; top: 2px; left: 2px;
  transition: transform .16s;
}
.switch input:checked::after { transform: translateX(16px); }

/* ══════════════════════════════ 底部任务坞 ══════════════════════════════ */

.dock {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(14,18,26,.97);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 55;
  display: flex; flex-direction: column;
  transition: height .2s;
  height: 42px;
}
.dock.open { height: var(--dock-h); }

.dock-head {
  display: flex; align-items: center; gap: 9px;
  padding: 0 13px; height: 41px; flex: none;
  cursor: pointer; user-select: none;
}
.dock-title { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.dock-badge {
  min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 9px; background: rgba(109,140,255,.2);
  color: var(--accent); font-size: 10.5px; font-weight: 600;
  display: grid; place-items: center;
  font-family: var(--mono);
}
.dock-msg {
  font-size: 11.5px; color: var(--ink-3);
  font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 46vw;
}
.dock-toggle { color: var(--ink-3); font-size: 11px; transition: transform .2s; }
.dock.open .dock-toggle { transform: rotate(180deg); }

.dock-body {
  flex: 1; overflow: auto; padding: 0 13px 13px;
  display: none;
}
.dock.open .dock-body { display: block; }

.job-list { display: flex; flex-direction: column; gap: 7px; }
.job-empty { color: var(--ink-3); font-size: 12px; padding: 18px 0; text-align: center; }

.job {
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--panel); padding: 9px 11px;
}
.job-top {
  display: flex; align-items: center; gap: 8px; margin-bottom: 5px;
}
.job-title { font-size: 12px; font-weight: 550; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-time { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); }
.job-msg {
  font-size: 11.5px; color: var(--ink-2); font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.job-bar { height: 3px; border-radius: 2px; background: #1e2534; margin-top: 7px; overflow: hidden; }
.job-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .3s;
}
.job.done .job-bar i { background: var(--ok); }
.job.failed .job-bar i { background: var(--bad); }
.job-log {
  margin-top: 7px; max-height: 90px; overflow: auto;
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-3);
  line-height: 1.55; white-space: pre-wrap;
  border-top: 1px solid var(--line-soft); padding-top: 6px;
}
.job-x {
  border: 0; background: transparent; color: var(--ink-3);
  font-size: 11px; padding: 2px 6px; border-radius: 5px;
}
.job-x:hover { background: rgba(255,95,109,.14); color: var(--bad); }

/* ══════════════════════════════ 弹层 / 模态 ══════════════════════════════ */

.popover {
  position: fixed; top: calc(var(--topbar-h) + 6px); left: 150px;
  width: 330px; max-height: 60vh;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-2);
  z-index: 80; display: none; flex-direction: column; overflow: hidden;
}
.popover.show { display: flex; }
.pop-head {
  padding: 10px 13px; font-size: 11px; color: var(--ink-3);
  border-bottom: 1px solid var(--line); letter-spacing: .4px;
}
.pop-list { overflow: auto; padding: 5px; flex: 1; }
.pop-foot { padding: 8px; border-top: 1px solid var(--line); }

.pop-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 9px; border-radius: var(--r-sm);
  cursor: pointer; transition: background .12s;
}
.pop-item:hover { background: rgba(255,255,255,.05); }
.pop-item.cur { background: rgba(109,140,255,.13); }
.pop-item .pi-main { flex: 1; min-width: 0; }
.pop-item .pi-title {
  font-size: 12.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pop-item .pi-sub {
  font-size: 10.5px; color: var(--ink-3); font-family: var(--mono);
  margin-top: 2px;
}

.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  z-index: 100; display: none;
  align-items: center; justify-content: center;
}
.modal-mask.show { display: flex; }

.modal {
  width: 480px; max-width: 92vw; max-height: 86vh;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 600;
}
.modal-body { padding: 16px; overflow: auto; flex: 1; }
.modal-foot {
  padding: 11px 16px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
}

.toast-wrap {
  position: fixed; right: 16px; bottom: 58px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  padding: 9px 14px; border-radius: var(--r-md);
  background: #1d2431; border: 1px solid var(--line);
  color: var(--ink); font-size: 12px;
  box-shadow: var(--shadow-2);
  animation: toastIn .22s ease;
  max-width: 380px;
}
.toast.ok  { border-color: rgba(53,201,138,.4); }
.toast.bad { border-color: rgba(255,95,109,.45); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- 通用 ---- */
.mono { font-family: var(--mono); }
.dim  { color: var(--ink-3); }
.spin {
  display: inline-block; width: 10px; height: 10px;
  border: 1.5px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ------------------------------------------------------------ 集数下拉 */
.ep-sel {
  height: 21px; padding: 0 5px; font-size: 11px; line-height: 1;
  background: #131822; color: var(--ink);
  border: 1px solid var(--line); border-radius: 5px;
  max-width: 168px; cursor: pointer; outline: none;
  font-family: inherit;
}
.ep-sel:hover { border-color: var(--accent-dim, #3a4560); }
.ep-sel:focus { border-color: var(--accent); }
.ep-sel option { background: #131822; color: var(--ink); }
