[hidden] { display: none !important; }
:root {
  --bg: #efece4;
  --dot: #cfc8b8;
  --ink: #23262b;
  --muted: #6d6a62;
  --line: #d8d2c4;
  --card: #fffdf8;
  --accent: #1f3a37;
  --accent-2: #e76f51;
  --gold: #e9c46a;
  --text-c: #8a6d3b;
  --image-c: #2a9d8f;
  --video-c: #c0503a;
  --sel: #3b6ff5;
  --ok: #2e8b57;
  --bad: #c0392b;
  --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 6px 20px rgba(40, 30, 10, .08);
  --top-h: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

/* ---------- top bar */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; background: rgba(255, 253, 248, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); z-index: 30; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); position: relative; flex: none; }
.logo i { position: absolute; left: 6px; top: 6px; width: 11px; height: 11px; border-radius: 50%; background: var(--gold); }
.logo b { position: absolute; right: 5px; bottom: 6px; width: 12px; height: 9px; border-radius: 2px; background: var(--accent-2); }
.brand-name { font-weight: 700; letter-spacing: .08em; }
.proj-name { border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: 6px; min-width: 0; width: 180px; }
.proj-name:hover, .proj-name:focus { border-color: var(--line); background: #fff; outline: none; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.tbtn { border: 1px solid var(--line); background: #fff; padding: 5px 10px; border-radius: 8px; white-space: nowrap; }
.tbtn:hover { border-color: #b9b09c; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 12px; text-align: center; }
.count.zero { background: #b9b09c; }
.badge { border: 0; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge.demo { background: #f6e7c1; color: #7a5a12; }
.badge.live { background: #d6eadf; color: #1c5a3a; }

/* ---------- toolbar */
.toolbar { position: fixed; left: 12px; top: calc(var(--top-h) + 12px); z-index: 25; display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: var(--shadow); }
.toolbar button { border: 0; background: transparent; border-radius: 9px; width: 58px; padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.toolbar button:hover { background: #f1ede3; }
.toolbar button.active { background: var(--accent); color: #fff; }
.toolbar button em { font-style: normal; font-size: 11px; }
.toolbar hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.ico { width: 20px; height: 20px; display: inline-block; }
.ico svg { width: 20px; height: 20px; display: block; }

/* ---------- canvas */
.viewport { position: fixed; inset: var(--top-h) 0 0 0; overflow: hidden; outline: none; touch-action: none;
  background-color: var(--bg); background-image: radial-gradient(var(--dot) 1.1px, transparent 1.2px); background-size: 24px 24px; cursor: default; }
.viewport.panning, .viewport.hand { cursor: grab; }
.viewport.panning:active { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.edges path.hit { stroke: transparent; stroke-width: 16; fill: none; pointer-events: stroke; cursor: pointer; }
.edges path.wire { fill: none; stroke-width: 2.5; pointer-events: none; }
.edges path.wire.text { stroke: var(--text-c); stroke-dasharray: 6 5; }
.edges path.wire.image { stroke: var(--image-c); }
.edges path.wire.video { stroke: var(--video-c); }
.edges path.wire.sel { stroke: var(--sel); stroke-width: 4; }
.edges path.wire.ghost { stroke: var(--sel); stroke-dasharray: 4 4; }
.marquee { position: absolute; border: 1.5px solid var(--sel); background: rgba(59, 111, 245, .08); pointer-events: none; z-index: 5; }
.empty-hint { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; color: var(--muted); max-width: 520px; padding: 0 24px; pointer-events: none; }
.empty-hint h2 { color: var(--ink); font-size: 20px; margin: 0 0 8px; }
.empty-hint .muted { font-size: 12px; }
.zoom-ctl { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 4; }
.zoom-ctl button { border: 0; background: transparent; width: 32px; height: 30px; font-size: 18px; }
.zoom-ctl span { min-width: 48px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- nodes */
.node { position: absolute; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); user-select: none; }
.node.sel { outline: 2.5px solid var(--sel); outline-offset: 1px; }
.node .head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: grab; border-radius: 12px 12px 0 0; }
.node .head .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.node .head .title { font-weight: 600; font-size: 13px; flex: 1; }
.node .head .st { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eee8da; color: var(--muted); }
.node .head .st.queued { background: #f6e7c1; color: #7a5a12; }
.node .head .st.running { background: #dbe6fb; color: #2547a8; }
.node .head .st.succeeded { background: #d6eadf; color: #1c5a3a; }
.node .head .st.failed { background: #f6d5cf; color: #8e2a1b; }
.node[data-type=prompt] .head .dot { background: var(--text-c); }
.node[data-type=upload] .head .dot { background: var(--image-c); border-radius: 50%; }
.node[data-type=imagegen] .head .dot { background: var(--image-c); }
.node[data-type=videogen] .head .dot { background: var(--video-c); }
.node[data-type=preview] .head .dot { background: var(--video-c); border-radius: 50%; }
.node .body { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.node textarea { width: 100%; resize: vertical; min-height: 64px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; user-select: text; }
.node textarea:focus, .node select:focus, .node input:focus { outline: 2px solid rgba(31, 58, 55, .35); border-color: var(--accent); }
.node .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.node label.f { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; flex: 1; min-width: 70px; }
.node select, .node input[type=number] { border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; background: #fff; width: 100%; }
.node .chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.node .est { font-size: 12px; color: var(--accent); background: #edf3f1; border-radius: 7px; padding: 5px 8px; }
.node .est b { font-size: 14px; }
.node .gen { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 8px; font-weight: 600; }
.node .gen:disabled { opacity: .5; cursor: default; }
.node .small { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 3px 8px; font-size: 12px; }
.node .err { color: var(--bad); font-size: 12px; white-space: pre-wrap; }
.node .note { color: var(--muted); font-size: 11px; }
.node .media { width: 100%; border-radius: 8px; background: #e6e1d5; display: block; max-height: 260px; object-fit: contain; }
.node .thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.node .thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; background: #e6e1d5; }
.node .thumbs img.on { border-color: var(--image-c); }
.node .drop { border: 1.5px dashed #bdb39d; border-radius: 9px; padding: 18px 8px; text-align: center; color: var(--muted); font-size: 12px; cursor: pointer; }
.node .progress { height: 6px; border-radius: 3px; background: #e6e1d5; overflow: hidden; }
.node .progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .6s; }
.node .progress.indet i { width: 30% !important; animation: indet 1.3s infinite ease-in-out; }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
.node .inputs-sum { font-size: 11px; color: var(--muted); }

/* ports */
.port { position: absolute; width: 16px; height: 16px; border-radius: 50%; background: var(--card); border: 2.5px solid #999; z-index: 2; cursor: crosshair; }
.port.in { left: -9px; }
.port.out { right: -9px; }
.port.text { border-color: var(--text-c); }
.port.image { border-color: var(--image-c); }
.port.video { border-color: var(--video-c); }
.port.filled { background: currentColor; }
.port.text.filled { background: var(--text-c); }
.port.image.filled { background: var(--image-c); }
.port.video.filled { background: var(--video-c); }
.port.ok { box-shadow: 0 0 0 5px rgba(59, 111, 245, .25); }
.port .pl { position: absolute; top: -2px; font-size: 10px; color: var(--muted); white-space: nowrap; pointer-events: none; }
.port.in .pl { right: 18px; }
.port.out .pl { left: 18px; }
.port:hover { transform: scale(1.2); }

/* ---------- panels, modal, toast */
.panel { position: fixed; right: 12px; top: calc(var(--top-h) + 12px); width: 320px; max-height: calc(100% - var(--top-h) - 70px); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); z-index: 26; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.panel-head h3 { margin: 0; font-size: 15px; }
.x { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 0 4px; }
.task-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.task { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; background: #fff; }
.task:hover { border-color: #b9b09c; }
.task .t1 { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; }
.task .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-empty { color: var(--muted); padding: 16px; text-align: center; font-size: 13px; }
.modal { position: fixed; inset: 0; background: rgba(25, 22, 15, .35); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--card); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); width: min(460px, 100%); max-height: 90vh; overflow: auto; padding: 18px; }
.modal-card h3 { margin: 0 0 10px; font-size: 17px; }
.modal-card table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.modal-card td { padding: 4px 0; border-bottom: 1px dashed var(--line); vertical-align: top; }
.modal-card td:first-child { color: var(--muted); width: 90px; }
.modal-card .big { font-size: 22px; font-weight: 700; color: var(--accent); }
.modal-card .warn { background: #f6e7c1; color: #6a4e0e; border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.modal-card .okbox { background: #d6eadf; color: #1c5a3a; border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.modal-card .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-card .btns button { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 14px; }
.modal-card .btns button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.modal-card input[type=password], .modal-card input[type=text] { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.modal-card .usage { font-size: 12px; width: 100%; }
.modal-card .usage td { width: auto !important; padding: 3px 4px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 60; font-size: 13px; max-width: 90vw; }
.quick-add { position: fixed; z-index: 40; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column; }
.quick-add button { border: 0; background: transparent; text-align: left; padding: 7px 12px; border-radius: 8px; }
.quick-add button:hover { background: #f1ede3; }

/* ---------- phone */
@media (max-width: 720px) {
  :root { --top-h: 48px; }
  .brand-name { display: none; }
  .proj-name { width: 96px; }
  .tbtn { padding: 4px 7px; font-size: 12px; }
  #btnImport { display: none; }
  .badge { padding: 4px 8px; font-size: 12px; }
  .toolbar { top: auto; bottom: 10px; left: 8px; right: 8px; flex-direction: row; overflow-x: auto; padding: 4px; border-radius: 12px; }
  .toolbar button { width: 52px; flex: none; }
  .toolbar hr { border-top: 0; border-left: 1px solid var(--line); margin: 4px 2px; }
  .zoom-ctl { bottom: 84px; }
  .panel { left: 8px; right: 8px; width: auto; }
}
