/* ============ 设计变量 ============ */
:root {
  --bg: #0b0b0d; --dot: #222429; --panel: #141518; --panel-2: #1b1c20; --panel-3: #24262b;
  --glass: rgba(24, 25, 29, .86); --glass-line: rgba(255,255,255,.08);
  --line: #26282e; --line-2: #33363d; --text: #ececee; --text-2: #a5a8b0; --text-3: #6c6f78;
  --accent: #27c4e3; --accent-2: #5ad6ee; --accent-bg: rgba(39,196,227,.13); --accent-glow: rgba(39,196,227,.35); --accent-ink: #04161b;
  --ok: #3ccf8e; --bad: #ff5d6c; --warn: #f5b84b;
  --edge: #565b66; --edge-hi: #5ad6ee; --mm-node: #50545d;
  --shadow: 0 12px 34px rgba(0,0,0,.5); --radius: 12px;
  --k-image: #6dc6ff; --k-text: #f5b84b;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f1f2f4; --dot: #d3d6dc; --panel: #ffffff; --panel-2: #f5f6f8; --panel-3: #eceef1;
  --glass: rgba(255,255,255,.9); --glass-line: rgba(10,20,40,.08);
  --line: #e3e5ea; --line-2: #d4d7dd; --text: #1c1f25; --text-2: #5b606b; --text-3: #8d919a;
  --accent: #0ea5c6; --accent-2: #0b8fae; --accent-bg: rgba(14,165,198,.10); --accent-glow: rgba(14,165,198,.28); --accent-ink: #fff;
  --edge: #b6bcc7; --edge-hi: #0ea5c6; --mm-node: #b9bec8; --shadow: 0 12px 30px rgba(30,40,70,.14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: var(--text); }
.muted { color: var(--text-3); font-size: 12px; }
[hidden] { display: none !important; }
#app { display: flex; flex-direction: column; height: 100vh; }
.masked { -webkit-text-security: disc; text-security: disc; }

/* ============ 顶栏 ============ */
#topbar { height: 46px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px 0 14px; background: var(--bg); border-bottom: 1px solid var(--line); z-index: 30; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-slash { color: var(--text-3); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand-mark { width: 20px; height: 20px; border-radius: 6px; background: linear-gradient(135deg, #27c4e3, #6d7cff 55%, #c76dff); box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset; }
.notice { flex: 1; min-width: 0; text-align: center; color: var(--warn); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, color .12s; }
.btn:hover { border-color: var(--accent); color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-3); border-color: transparent; color: var(--text); }
.btn.sm { height: 24px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn.icon { width: 30px; padding: 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex: none; }
.chip-balance { display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 4px 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; }
.chip-balance b { color: var(--accent-2); font-weight: 650; }
.chip-balance .tag { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
#save-state { white-space: nowrap; margin-left: 4px; }
.proj-btn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; border-radius: 7px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text); max-width: 280px; }
.proj-btn:hover { background: var(--panel-3); }
.proj-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-btn svg { width: 13px; height: 13px; flex: none; color: var(--text-3); }

/* ============ 画布 ============ */
#viewport { flex: 1; position: relative; overflow: hidden; outline: none; background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.15px); background-size: 24px 24px; }
#viewport.tool-hand, #viewport.space-pan { cursor: grab; }
#viewport.panning { 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.edge { fill: none; stroke: var(--edge); stroke-width: calc(1.6px / var(--z, 1)); stroke-linecap: round; transition: opacity .15s, stroke .15s; opacity: .85; }
#edges path.edge.hi { stroke: var(--edge-hi); opacity: 1; stroke-width: calc(2.2px / var(--z, 1)); }
#edges path.edge.dim { opacity: .22; }
#edges path.hit { fill: none; stroke: transparent; stroke-width: calc(14px / var(--z, 1)); pointer-events: stroke; cursor: pointer; }
#edges g.edge-g:hover path.edge { stroke: var(--bad); opacity: 1; }
#edges g.edge-del { pointer-events: all; cursor: pointer; opacity: 0; transition: opacity .12s; }
#edges g.edge-g:hover g.edge-del { opacity: 1; }
#edges g.edge-del circle { fill: var(--bad); }
#edges g.edge-del path { stroke: #fff; stroke-width: 1.8; }
#edges path.temp { fill: none; stroke: var(--accent); stroke-width: calc(2px / var(--z, 1)); stroke-dasharray: 6 5; }
#selbox { position: absolute; border: 1px solid var(--accent); background: var(--accent-bg); pointer-events: none; z-index: 5; border-radius: 2px; }
#empty-hint { position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; color: var(--text-3); }
#empty-hint .eh-icon { width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 12px; background: linear-gradient(135deg, #27c4e3, #6d7cff 55%, #c76dff); opacity: .9; }
#empty-hint .eh-title { font-size: 18px; color: var(--text); margin-bottom: 6px; font-weight: 600; }

/* ============ 节点：卡片本身，无外框 ============ */
.node { position: absolute; transition: opacity .15s; }
.node-label { position: absolute; left: 0; bottom: 100%; margin-bottom: 6px; display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-3); white-space: nowrap; pointer-events: none;
  transform-origin: 0 100%; transform: scale(calc(1 / max(var(--z, 1), .35))); }
.node-label svg { width: 12px; height: 12px; }
.node.sel .node-label { color: var(--accent-2); }
.node-card { position: absolute; inset: 0; border-radius: var(--radius); overflow: hidden; background: var(--panel); box-shadow: 0 6px 22px rgba(0,0,0,.35); cursor: default; }
.node.sel .node-card { box-shadow: 0 0 0 calc(2px / var(--z, 1)) var(--accent), 0 6px 22px rgba(0,0,0,.35); }
.node.neighbor .node-card { box-shadow: 0 0 0 calc(2px / var(--z, 1)) var(--accent-glow), 0 6px 22px rgba(0,0,0,.35); }
.node.drop-ok .node-card { box-shadow: 0 0 0 calc(3px / var(--z, 1)) var(--accent), 0 0 30px var(--accent-glow); }
.node.dragging { opacity: .9; }
.node-card.drop-over { box-shadow: 0 0 0 3px var(--accent) !important; }
.node-resize { position: absolute; right: -6px; bottom: -6px; width: 18px; height: 18px; cursor: nwse-resize; opacity: 0; z-index: 3; }
.node-resize::after { content: ""; position: absolute; right: 6px; bottom: 6px; width: 8px; height: 8px; border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); border-radius: 0 0 3px 0; }
.node.sel .node-resize, .node:hover .node-resize { opacity: 1; }

/* 连接圆点：悬停或选中时出现在左右两侧中间 */
.port { position: absolute; top: 50%; width: calc(14px / var(--z, 1)); height: calc(14px / var(--z, 1)); max-width: 40px; max-height: 40px; border-radius: 50%; background: var(--panel); border: calc(2px / var(--z, 1)) solid var(--edge); cursor: crosshair; z-index: 4; transform: translate(-50%, -50%); opacity: 0; transition: opacity .12s, transform .1s, background .1s; }
.port.in { left: 0; }
.port.out { left: 100%; border-color: var(--accent); }
.port.out.k-text { border-color: var(--k-text); }
.node:hover .port, .node.sel .port, .connecting .port, .port.connected { opacity: 1; }
.port.connected { background: var(--edge); }
.port.out.connected { background: var(--accent); }
.port:hover { transform: translate(-50%, -50%) scale(1.35); }

/* 图片卡片 */
.card-img { position: absolute; inset: 0; background: var(--panel-2); }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; -webkit-user-drag: none; }
.card-err { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 10px; background: rgba(255,93,108,.88); color: #fff; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 14px; color: var(--text-3);
  background: var(--panel); border: 1.5px dashed var(--line-2); border-radius: var(--radius); }
.node.sel .card-empty { border-color: transparent; }
.card-empty .ce-icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--accent-bg); color: var(--accent-2); }
.card-empty .ce-icon svg { width: 18px; height: 18px; }
.card-empty .ce-title { color: var(--text); font-weight: 600; display: flex; align-items: center; gap: 4px; }
.card-empty .ce-title svg { width: 14px; height: 14px; }
.card-empty .ce-sub { font-size: 12px; line-height: 1.6; }
.card-empty a { color: var(--accent-2); cursor: pointer; }
.card-empty.fail .ce-title { color: var(--bad); }
.card-run { position: absolute; inset: 0; background: var(--panel-2); overflow: hidden; }
.card-run img { width: 100%; height: 100%; object-fit: cover; opacity: .35; filter: blur(2px); }
.run-shimmer { position: absolute; inset: 0; background: linear-gradient(110deg, transparent 20%, rgba(39,196,227,.16) 45%, rgba(109,124,255,.14) 55%, transparent 80%); background-size: 220% 100%; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.run-info { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text); font-size: 12px; }
.run-info .spinner { border-color: var(--line-2); border-top-color: var(--accent); }
.overlay-busy { position: absolute; inset: 0; background: #0009; color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 12px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 文字卡片 */
.card-text { position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: none; background: var(--panel); padding: 12px 14px; outline: none; line-height: 1.6; color: var(--text); }

/* 对比卡片 */
.cmp { position: absolute; inset: 0; overflow: hidden; background: var(--panel-2); user-select: none; cursor: ew-resize; }
.cmp img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; -webkit-user-drag: none; }
.cmp .cmp-top { position: absolute; inset: 0; }
.cmp .cmp-bar { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 6px #0008; transform: translateX(-1px); pointer-events: none; }
.cmp .cmp-knob { position: absolute; top: 50%; width: 28px; height: 28px; border-radius: 50%; background: #fff; transform: translate(-50%, -50%); box-shadow: 0 2px 8px #0008; pointer-events: none; display: flex; align-items: center; justify-content: center; color: #333; font-size: 12px; }
.cmp .cmp-lab { position: absolute; top: 6px; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: #000a; color: #fff; }

/* ============ 浮层 ============ */
#overlays { position: absolute; inset: 0; pointer-events: none; z-index: 12; }
.ov { position: absolute; pointer-events: auto; }
.ov-bar { display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); white-space: nowrap; }
.tb-btn { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 9px; border: none; border-radius: 8px; background: transparent; color: var(--text-2); cursor: pointer; font-size: 12px; }
.tb-btn:hover { background: var(--panel-3); color: var(--text); }
.tb-btn.danger:hover { color: var(--bad); }
.tb-btn svg { width: 15px; height: 15px; }
.tb-sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 3px; }
.ms-count { font-size: 12px; color: var(--text-2); padding: 0 8px; }
.ov-panel { width: 520px; max-width: calc(100% - 16px); padding: 12px; border-radius: 16px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); display: flex; flex-direction: column; gap: 10px; }
.ov-panel.warn .cp-go { background: var(--warn); }
.cp-head { display: flex; align-items: center; gap: 10px; min-height: 30px; }
.cp-title { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.cp-refs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.ref-chip { position: relative; width: 30px; height: 30px; border-radius: 7px; overflow: hidden; border: 1px solid var(--line-2); flex: none; }
.ref-chip img { width: 100%; height: 100%; object-fit: cover; }
.ref-chip.self { border-color: var(--accent); }
.ref-chip b { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9px; text-align: center; background: var(--accent); color: var(--accent-ink); line-height: 12px; font-weight: 600; }
.ref-pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: rgba(245,184,75,.14); color: var(--warn); }
.ref-add { width: 30px; height: 30px; border-radius: 7px; border: 1px dashed var(--line-2); background: transparent; color: var(--text-3); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.ref-add:hover { border-color: var(--accent); color: var(--accent-2); }
.ref-add svg { width: 14px; height: 14px; }
.cp-text { width: 100%; min-height: 64px; max-height: 180px; resize: none; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 9px 11px; outline: none; line-height: 1.55; }
.cp-text:focus { border-color: var(--accent); }
.cp-tpls { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl { height: 22px; padding: 0 9px; border-radius: 11px; border: 1px solid var(--line); background: transparent; color: var(--text-2); font-size: 11.5px; cursor: pointer; }
.tpl:hover { border-color: var(--accent); color: var(--accent-2); }
.cp-bar { display: flex; gap: 6px; align-items: center; }
.cp-bar .cp-model { flex: 1; min-width: 0; }
.mini-select { height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; font-size: 12px; cursor: pointer; outline: none; max-width: 100%; }
.mini-select:focus { border-color: var(--accent); }
.gen-go { height: 32px; padding: 0 14px; border-radius: 9px; border: none; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap; flex: none; }
.gen-go:hover { background: var(--accent-2); }
.gen-go:disabled { opacity: .5; cursor: not-allowed; }
.gen-go svg { width: 12px; height: 12px; }
.gen-go small { font-weight: 600; opacity: .8; }
.ov-pop { padding: 10px; border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); width: 260px; }
.pop-title { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.pop-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pg-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; font-size: 11px; color: var(--text-2); }
.pg-btn:hover { border-color: var(--accent); color: var(--accent-2); }
.pg-ico { display: grid; gap: 2px; width: 28px; height: 28px; }
.pg-ico i { background: var(--line-2); border-radius: 2px; }
.pg-btn:hover .pg-ico i { background: var(--accent); }
.pop-custom { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.inp.sm { width: 48px; height: 26px; padding: 0 6px; }

/* ============ 底部工具条 / 左下视图栏 / 小地图 / 资产 ============ */
#dock { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 5px; border-radius: 14px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); z-index: 14; }
.dk-btn { width: 36px; height: 36px; border-radius: 10px; border: none; background: transparent; color: var(--text-2); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.dk-btn:hover { background: var(--panel-3); color: var(--text); }
.dk-btn.on { background: var(--accent-bg); color: var(--accent-2); }
.dk-btn svg { width: 18px; height: 18px; }
.dk-add { background: var(--accent); color: var(--accent-ink); }
.dk-add:hover { background: var(--accent-2); color: var(--accent-ink); }
.dk-sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; }
#zoombar { position: absolute; left: 14px; bottom: 16px; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); z-index: 14; }
.zb-btn { height: 30px; min-width: 30px; padding: 0 7px; border-radius: 8px; border: none; background: transparent; color: var(--text-2); display: flex; align-items: center; justify-content: center; gap: 5px; cursor: pointer; font-size: 12px; }
.zb-btn:hover { background: var(--panel-3); color: var(--text); }
.zb-btn.on { background: var(--accent-bg); color: var(--accent-2); }
.zb-btn svg { width: 16px; height: 16px; }
.zb-sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 3px; }
.zb-val { width: 52px; height: 26px; text-align: center; border: 1px solid transparent; border-radius: 6px; background: transparent; font-size: 12px; color: var(--text-2); outline: none; }
.zb-val:hover, .zb-val:focus { border-color: var(--line-2); background: var(--panel); }
#minimap { position: absolute; left: 14px; bottom: 64px; width: 220px; height: 150px; border-radius: 12px; overflow: hidden; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); z-index: 14; }
#minimap canvas { width: 100%; height: 100%; display: block; cursor: pointer; }
#assets { position: absolute; left: 14px; top: 14px; bottom: 64px; width: 300px; border-radius: 14px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); display: flex; flex-direction: column; z-index: 15; overflow: hidden; }
.as-head { height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 14px; font-weight: 600; flex: none; }
.as-hint { padding: 0 14px 8px; flex: none; }
.as-list { flex: 1; overflow-y: auto; padding: 0 12px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start; }
.as-item { border-radius: 10px; overflow: hidden; background: var(--panel-2); cursor: pointer; display: flex; flex-direction: column; border: 1px solid transparent; }
.as-item:hover { border-color: var(--accent); }
.as-img { aspect-ratio: 1; background: var(--panel-3) center/cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--text-3); font-size: 11px; text-align: center; padding: 6px; }
.as-img.fail { color: var(--bad); }
.as-meta { padding: 5px 8px; font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-more { grid-column: 1 / -1; }

/* ============ 菜单 / 弹窗 / 提示 ============ */
.menu { position: fixed; min-width: 200px; background: var(--glass); border: 1px solid var(--glass-line); border-radius: 12px; box-shadow: var(--shadow); backdrop-filter: blur(16px); padding: 5px; z-index: 1000; }
.menu .m-title { font-size: 11px; color: var(--text-3); padding: 6px 10px 4px; }
.menu .m-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; background: transparent; border-radius: 8px; cursor: pointer; text-align: left; }
.menu .m-item:hover { background: var(--accent-bg); color: var(--accent-2); }
.menu .m-item svg { width: 15px; height: 15px; color: var(--text-2); flex: none; }
.menu .m-item .m-desc { font-size: 11px; color: var(--text-3); margin-left: auto; padding-left: 14px; }
.menu .m-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu .m-item.danger { color: var(--bad); }
.menu .m-item.cur { color: var(--accent-2); }
.mask-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 20px; }
.dialog { background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow); width: 400px; max-width: 100%; max-height: calc(100vh - 40px); overflow: auto; padding: 22px; }
.dialog h3 { margin: 0 0 16px; font-size: 16px; display: flex; align-items: center; justify-content: space-between; }
.dialog h3 .x { border: none; background: transparent; color: var(--text-3); cursor: pointer; font-size: 20px; line-height: 1; }
.dialog .field { margin-bottom: 12px; }
.inp { width: 100%; height: 38px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--panel-2); padding: 0 12px; outline: none; }
.inp:focus { border-color: var(--accent); }
.dialog .err { color: var(--bad); font-size: 12px; min-height: 18px; margin-bottom: 6px; }
.dialog .ok { color: var(--ok); font-size: 12px; min-height: 18px; margin-bottom: 6px; }
.dialog .btn.block { width: 100%; height: 40px; }
.dialog .foot { text-align: center; margin-top: 12px; font-size: 12px; color: var(--text-3); }
.dialog .foot a { color: var(--accent-2); cursor: pointer; }
.dialog table { width: 100%; border-collapse: collapse; font-size: 12px; }
.dialog th, .dialog td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.dialog th { color: var(--text-3); font-weight: 500; }
.toasts { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 2000; pointer-events: none; }
.toast { background: var(--panel-3); border: 1px solid var(--line-2); color: var(--text); padding: 8px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; animation: tin .18s ease-out; }
.toast.bad { border-color: var(--bad); }
.toast.ok { border-color: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }

/* 登录全屏 */
.gate { position: fixed; inset: 0; z-index: 800; display: flex; align-items: center; justify-content: center; background: radial-gradient(1100px 600px at 75% -10%, rgba(39,196,227,.16), transparent), radial-gradient(900px 500px at 0% 110%, rgba(199,109,255,.10), transparent), var(--bg); }
.gate .dialog { width: 380px; }
.gate .g-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.gate .g-brand .brand-mark { width: 28px; height: 28px; border-radius: 9px; }
.gate .g-sub { color: var(--text-3); font-size: 12px; margin-bottom: 18px; }

/* 灯箱 */
.lightbox { position: fixed; inset: 0; z-index: 950; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 6px; }
.lightbox .lb-bar { position: absolute; top: 16px; right: 16px; display: flex; gap: 8px; }
.lightbox .lb-info { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: #ccc; font-size: 12px; }

/* 全屏编辑器（局部重绘 / 裁切） */
.mask-editor { position: fixed; inset: 0; z-index: 950; background: rgba(5,5,7,.94); display: flex; flex-direction: column; }
.me-bar { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.me-bar .grow { flex: 1; }
.me-bar input[type=range] { width: 130px; accent-color: var(--accent); }
.me-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; min-height: 0; }
.me-stage .me-wrap { position: relative; }
.me-stage canvas { position: absolute; inset: 0; cursor: none; }
.me-stage img { display: block; user-select: none; -webkit-user-drag: none; }
.me-foot:empty { display: none; }
.me-foot { flex: none; padding: 12px 18px 16px; display: flex; justify-content: center; }
.me-prompt { width: 640px; max-width: 100%; display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line-2); }
.me-text { width: 100%; height: 60px; resize: none; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); padding: 9px 11px; outline: none; }
.me-text:focus { border-color: var(--accent); }
.me-ctrl { display: flex; gap: 6px; align-items: center; }
.me-ctrl .me-model { flex: 1; }
.me-cursor { position: fixed; border: 1.5px solid #fff; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 1px #000a; transform: translate(-50%, -50%); z-index: 960; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: transparent; padding: 0 11px; height: 30px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.crop-box { position: absolute; border: 1.5px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); cursor: move; touch-action: none; }
.crop-box i { position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 3px; }
.crop-box i[data-h=nw] { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-box i[data-h=ne] { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-box i[data-h=sw] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-box i[data-h=se] { right: -7px; bottom: -7px; cursor: nwse-resize; }

/* ============ 创作面板：编号参考 ============ */
.cp-limit { margin-left: auto; font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.cp-limit.bad { color: var(--bad); font-weight: 600; }
.ov-panel .cp-refs { margin-left: 0; gap: 8px; }
.ov-panel .ref-chip { width: auto; height: 40px; display: inline-flex; align-items: center; gap: 0; padding-right: 8px; background: var(--panel-2); cursor: pointer; overflow: visible; }
.ov-panel .ref-chip img { width: 38px; height: 38px; border-radius: 6px 0 0 6px; flex: none; }
.ov-panel .ref-chip b { position: static; background: none; color: var(--accent-2); font-size: 11.5px; line-height: 1; padding-left: 7px; }
.ov-panel .ref-chip.self b { color: var(--accent); }
.ov-panel .ref-chip:hover, .ov-panel .ref-pill:hover { border-color: var(--accent); }
.ov-panel .ref-pill { height: 26px; display: inline-flex; align-items: center; gap: 4px; padding: 0 6px 0 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; }
.rx { position: absolute; top: -6px; right: -6px; width: 16px; height: 16px; border-radius: 50%; border: none; background: var(--panel-3); color: var(--text-2); font-size: 11px; line-height: 16px; padding: 0; cursor: pointer; display: none; }
.ref-pill .rx { position: static; display: inline-block; background: transparent; }
.ref-chip:hover .rx { display: block; }
.rx:hover { background: var(--bad); color: #fff; }
.ov-panel .ref-add { width: auto; height: 40px; padding: 0 10px; gap: 4px; font-size: 12px; }

/* ============ 素材库 ============ */
.lib-tabs { margin-bottom: 12px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; max-height: 56vh; overflow: auto; padding: 2px; }
.lib-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 2px solid transparent; padding: 0; background: var(--panel-3); cursor: pointer; }
.lib-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-item:hover { border-color: var(--line-2); }
.lib-item.on { border-color: var(--accent); }
.lib-item i { position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.3); }
.lib-item.on i { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--panel); }
.lib-more { grid-column: 1 / -1; }
.lib-empty { grid-column: 1 / -1; padding: 30px 0; text-align: center; }
.lib-foot { display: flex; align-items: center; gap: 8px; margin-top: 14px; }

/* ============ 顶栏：画布 / 工作台 切换 ============ */
.mode-seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); margin-left: 6px; }
.mode-seg button { height: 26px; padding: 0 12px; border: none; border-radius: 7px; background: transparent; color: var(--text-2); cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.mode-seg button:hover { color: var(--text); }
.mode-seg button.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.mode-wb .canvas-only { display: none !important; }

/* ============ 生图工作台 ============ */
#workbench { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 20px; padding: 20px; overflow: hidden; background: var(--bg); }
.wb-left { min-height: 0; overflow: auto; }
.wb-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.wb-drop { border: 1.5px dashed var(--line-2); border-radius: 14px; min-height: 132px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: border-color .12s, background .12s; outline: none; }
.wb-drop:hover, .wb-drop.over, .wb-drop:focus-visible { border-color: var(--accent); background: var(--accent-bg); }
.wb-drop.has { align-items: stretch; justify-content: flex-start; padding: 10px; min-height: 0; }
.wb-drop-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-3); font-size: 12px; text-align: center; }
.wb-drop-empty svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: 4px; }
.wb-drop-empty b { color: var(--text); font-size: 13.5px; }
.wb-drop.has .wb-drop-empty { display: none; }
.wb-refs { display: flex; flex-wrap: wrap; gap: 8px; }
.wb-refs:empty { display: none; }
.wb-ref { position: relative; width: 76px; height: 76px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-3); cursor: pointer; }
.wb-ref img { width: 100%; height: 100%; object-fit: cover; border-radius: 9px; display: block; }
.wb-ref b { position: absolute; left: 4px; bottom: 4px; font-size: 10.5px; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; font-weight: 600; }
.wb-ref:hover { border-color: var(--accent); }
.wb-ref:hover .rx { display: block; }
.wb-ref.busy img { opacity: .5; }
.wb-ref .spinner { position: absolute; left: 50%; top: 50%; margin: -8px 0 0 -8px; }
.wb-ref.add { display: flex; align-items: center; justify-content: center; color: var(--text-3); border-style: dashed; background: transparent; }
.wb-ref.add svg { width: 20px; height: 20px; }
.wb-row-btns { display: flex; align-items: center; gap: 10px; }
.wb-row-btns .btn svg { width: 14px; height: 14px; }
.wb-limit { margin-left: auto; text-align: right; }
.wb-limit.bad { color: var(--bad); font-weight: 600; }
.wb-text { width: 100%; min-height: 120px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); padding: 11px 13px; outline: none; line-height: 1.6; }
.wb-text:focus { border-color: var(--accent); background: var(--panel); }
.wb-params { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.wb-params label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--text-3); }
.wb-params .mini-select { width: 100%; height: 34px; }
.wb-go-row { display: flex; gap: 8px; align-items: center; }
.wb-go-row .btn svg { width: 13px; height: 13px; }
.wb-go { flex: 1; height: 40px; justify-content: center; font-size: 14px; border-radius: 11px; }
.wb-right { min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.wb-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.wb-title { font-size: 18px; font-weight: 700; }
.wb-list { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 12px; align-content: start; padding-bottom: 20px; }
.wb-empty { grid-column: 1 / -1; padding: 60px 0; text-align: center; }
.wb-more { grid-column: 1 / -1; justify-self: center; }
.wb-item { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); min-width: 0; transition: border-color .12s; }
.wb-item:hover { border-color: var(--line-2); }
.wb-item.failed { border-color: rgba(255,93,108,.35); }
.wb-thumb { width: 72px; height: 72px; flex: none; border-radius: 10px; overflow: hidden; background: var(--panel-3); display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; cursor: zoom-in; color: var(--text-3); }
.wb-thumb img { width: 100%; height: 100%; object-fit: cover; }
.wb-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.wb-prompt { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wb-meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bad { color: var(--bad); }
.wb-acts { display: flex; gap: 2px; flex: none; }
.ib { width: 30px; height: 30px; border: none; border-radius: 8px; background: transparent; color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.ib svg { width: 16px; height: 16px; }
.ib:hover { background: var(--panel-3); color: var(--accent-2); }
.ib.danger:hover { color: var(--bad); }
@media (max-width: 900px) {
  #workbench { grid-template-columns: 1fr; overflow: auto; padding: 12px; gap: 14px; }
  .wb-left, .wb-right { overflow: visible; }
  .wb-list { overflow: visible; grid-template-columns: 1fr; }
  .wb-item { flex-wrap: wrap; }
  .wb-acts { width: 100%; justify-content: flex-end; }
  .mode-seg button { padding: 0 8px; }
}
.wb-thumb .spinner, .wb-ref .spinner { border-color: var(--line-2); border-top-color: var(--accent); }
@media (max-width: 900px) {
  #workbench { display: flex; flex-direction: column; }
  .wb-left, .wb-right { flex: none; min-height: auto; }
  .wb-list { flex: none; }
}
@media (max-width: 600px) {
  #site-name { display: none; }
  .chip-balance .muted, .chip-balance .tag { display: none; }
  #topbar { padding: 0 8px; gap: 6px; }
  .mode-seg { margin-left: 0; }
}

.me-mode {margin:0;font-size:12px;line-height:1.5;}
.me-stage canvas {touch-action:none;}
