/* Studio 工作台样式 */
.studio-layout {
  display: flex;
  height: calc(100vh - 40px);
  overflow: hidden;
  margin: -8px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
}

/* 左侧调色板：双栏布局（分类栏 + 模块栏） */
.palette {
  display: flex;
  background: #f8f9fa;
  border-right: 1px solid #e0e0e0;
  flex-shrink: 0;
  overflow: hidden;
}
.palette-cats {
  width: 80px;
  background: #f0f1f2;
  border-right: 1px solid #e0e0e0;
  padding: 12px 0;
  overflow-y: auto;
  flex-shrink: 0;
}
.palette-cat-title {
  font-size: 11px;
  color: #999;
  font-weight: 600;
  padding: 0 12px 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.palette-cat {
  padding: 8px 12px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.palette-cat:hover {
  background: #e5e7eb;
  color: #333;
}
.palette-cat.active {
  background: #dbeafe;
  color: #2563eb;
  font-weight: 600;
}

.palette-items {
  width: 180px;
  padding: 12px;
  overflow-y: auto;
  flex-shrink: 0;
}
.palette-items-title {
  font-size: 11px;
  color: #999;
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.palette-items-empty {
  font-size: 12px;
  color: #bbb;
  padding: 20px 0;
  text-align: center;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: grab;
  font-size: 13px;
  transition: all 0.15s;
  user-select: none;
}
.palette-item:hover {
  border-color: #3b82f6;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.15);
}
.palette-item:active {
  cursor: grabbing;
}
.palette-item-icon {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  line-height: 1;
}
.palette-item-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

/* 右侧画布 */
.canvas-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
}
.canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#canvas-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: default;
  touch-action: none;   /* 触控：禁止浏览器手势干扰画布拖拽/缩放 */
  /* 网格背景由 JS 设置 */
}
/* 调色板触控拖拽幽灵元素 */
.palette-ghost {
  position: fixed;
  z-index: 99999;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 13px;
  pointer-events: none;
  opacity: 0.9;
  white-space: nowrap;
}
.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  z-index: 10;
}
.canvas-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}
.connection-path {
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}
.connection-hit {
  stroke: transparent;
  stroke-width: 12;
  fill: none;
  pointer-events: all;
  cursor: pointer;
}
.connection-drag {
  pointer-events: none;
}

/* 工具栏 */
.studio-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
  z-index: 95; /* 高于遮罩(90)，运行时仍可点按钮 */
}
.studio-toolbar button {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.studio-toolbar button:hover {
  border-color: #3b82f6;
  color: #3b82f6;
}
.studio-toolbar .run-btn {
  background: #22c55e;
  border-color: #22c55e;
  color: #fff;
  font-weight: 600;
}
.studio-toolbar .run-btn:hover {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}
.studio-toolbar .stop-btn {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  font-weight: 600;
}
.studio-toolbar .stop-btn:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}
.run-params-input {
  width: 220px;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 12px;
}

/* 项目列表弹窗 */
.project-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.project-modal {
  background: #fff;
  border-radius: 10px;
  width: 480px;
  max-width: 90vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.project-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
}
.project-modal-close {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
}
.project-modal-close:hover { color: #ef4444; }
.project-modal-actions {
  padding: 10px 12px 0;
}
.project-new {
  width: 100%;
  padding: 10px 12px;
  border: 1px dashed #3b82f6;
  border-radius: 8px;
  background: #eff6ff;
  color: #2563eb;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.project-new:hover { background: #dbeafe; border-style: solid; }
.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.project-empty {
  padding: 30px;
  text-align: center;
  color: #999;
}
.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 8px;
}
.project-item:hover { border-color: #3b82f6; }
.project-item-name { font-weight: 600; font-size: 14px; }
.project-item-meta { font-size: 12px; color: #666; margin-top: 2px; }
.project-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.project-item-actions button {
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}
.project-load:hover { border-color: #3b82f6; color: #3b82f6; }
.project-del:hover { border-color: #ef4444; color: #ef4444; }

/* 运行时遮罩 */
.run-mask {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.35);
  z-index: 90;
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: center;
}
.run-mask-text {
  background: rgba(17, 24, 39, 0.75);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  pointer-events: none;
}

/* 运行结果面板（右侧侧栏） */
.run-panel {
  width: 320px;
  flex-shrink: 0;
  overflow-y: auto;
  background: #fbfbfc;
  border-left: 1px solid #e2e8f0;
  padding: 12px;
  font-size: 12px;
  transition: width 0.25s ease, padding 0.25s ease, border-width 0.25s ease;
}
.run-panel.run-collapsed {
  width: 0;
  padding: 0;
  border-left-width: 0;
  overflow: hidden;
}
/* 折叠/展开按钮 */
.run-panel-toggle {
  flex-shrink: 0;
  width: 20px;
  align-self: stretch;
  border: none;
  border-left: 1px solid #e2e8f0;
  background: #f1f5f9;
  color: #64748b;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 100;
}
.run-panel-toggle:hover {
  background: #e2e8f0;
  color: #334155;
}
/* 桌面端控制台拖拽调宽把手（手机端全屏 drawer 时隐藏） */
.run-panel-resizer {
  flex-shrink: 0;
  width: 6px;
  align-self: stretch;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  z-index: 100;
  touch-action: none;
}
.run-panel-resizer:hover,
.run-panel-resizer.dragging {
  background: #3b82f6;
  opacity: 0.35;
}
.run-status {
  color: #555;
  padding: 4px 0;
}
.run-ok { color: #16a34a; font-weight: 600; }
.run-error { color: #ef4444; font-weight: 600; }
.run-error-detail {
  margin-top: 6px;
  padding: 8px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: #b91c1c;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.run-section { margin-top: 8px; border-top: 1px solid #f0f0f0; padding-top: 8px; }
.run-section-title { font-weight: 600; color: #333; margin-bottom: 6px; }
.run-row { margin: 4px 0; word-break: break-word; }
.run-key { font-weight: 600; color: #f97316; }
.node-output {
  cursor: default;
  transition: background 0.15s;
}
.node-output:hover {
  background: #fefce8;
}
.run-text { white-space: pre-wrap; }
/* 可折叠文本：正文 4 行 / 思考 1 行 */
.run-text-collapse {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  max-width: 100%;
  vertical-align: top;
}
.run-text-content {
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  max-width: 100%;
}
.run-text-collapse.expanded .run-text-content {
  -webkit-line-clamp: unset;
}
.run-reasoning .run-text-content {
  -webkit-line-clamp: 1;
  color: #9ca3af;
  font-size: 12px;
}
.run-text-toggle {
  font-size: 11px;
  color: #3b82f6;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  line-height: 1.4;
}
.run-text-toggle:hover { text-decoration: underline; }
.run-image { width: 200px; height: 200px; object-fit: cover; border-radius: 4px; margin-top: 4px; cursor: zoom-in; }
.run-video { width: 200px; height: 200px; object-fit: cover; border-radius: 4px; margin-top: 4px; cursor: zoom-in; background: #000; }
.run-audio { max-width: 100%; margin-top: 4px; }
.run-empty { color: #999; padding: 8px 0; }

/* 实时输出控制台（无额外样式与大小限制，输出直接展示） */
.run-console .run-error-row {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  color: #b91c1c;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 节点运行状态高亮 */
.workspace-module.run-running {
  outline: 2px solid #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}
.workspace-module.run-success {
  outline: 2px solid #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}
.workspace-module.run-error {
  outline: 2px solid #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}
.workspace-module.run-queued {
  outline: 2px solid #9ca3af;
  box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.25);
  opacity: 0.7;
}
.workspace-module.run-skip {
  outline: 2px dashed #cbd5e1;
  opacity: 0.55;
}

/* 工作台模块 */
.workspace-module {
  position: absolute;
  width: 260px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-top: 3px solid var(--accent, #3b82f6);
  cursor: grab;
  user-select: none;
  z-index: 10;
  touch-action: none; /* 移动端：拖动模块时不触发页面滚动 */
}
.workspace-module:active {
  cursor: grabbing;
}
.mod-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f7f7f8;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: 14px;
}
.mod-icon {
  font-size: 15px;
}
.mod-node-number {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #64748b;
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.4;
  flex-shrink: 0;
}
.workspace-module.node-highlight {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.3);
  z-index: 50;
}
.mod-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mod-model-btn {
  flex: 1;
  font-size: 12px;
  color: #3b82f6;
  background: #e8f0fe;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mod-model-btn:hover {
  background: #dbe8fd;
}
.mod-think-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
}
.mod-think-toggle.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.mod-think-toggle input {
  margin-right: 2px;
  cursor: pointer;
}
.mod-think-toggle.disabled input {
  cursor: not-allowed;
}
.port-hint {
  font-size: 10px;
  color: #8b5cf6;
  background: rgba(139, 92, 246, 0.1);
  padding: 0 5px;
  border-radius: 3px;
  white-space: nowrap;
}
.mod-del-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: #999;
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
}
.mod-del-btn:hover {
  color: #ef4444;
}

/* 文字输出模块预览 */
.text-preview-content {
  min-height: 32px;
  max-height: 60px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  color: #444;
}
.text-preview-content:hover {
  border-color: #8b5cf6;
  background: #f5f3ff;
}

/* 文字编辑 modal */
.text-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.text-modal {
  background: #fff;
  border-radius: 10px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  padding: 0;
  overflow: hidden;
}
.text-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
}
.text-modal-close {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
}
.text-modal-close:hover {
  color: #ef4444;
}
.text-modal-textarea {
  width: 100%;
  min-height: 260px;
  border: none;
  outline: none;
  padding: 14px 16px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
}
.mod-body {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  position: relative;
}
.mod-ports {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 60px;
}
.mod-ports-left {
  align-items: flex-start;
  margin-left: 0;
}
.mod-ports-right {
  align-items: flex-end;
  margin-right: 0;
}
.port-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #444;
  position: relative;
  padding: 0 4px;
}
.port-input {
  justify-content: flex-start;
  flex-direction: row;
}
.port-output {
  justify-content: flex-end;
  flex-direction: row;
}
.port-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #64748b;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  touch-action: none; /* 移动端：拖拽连线时不触发页面滚动 */
}
.port-dot:hover {
  filter: brightness(1.2);
  transform: scale(1.3);
}
.port-dot-in {
  margin-left: -7px;
}
.port-dot-out {
  margin-right: -7px;
}
.port-dot-in.connected {
  background: var(--dot-color, #3b82f6);
  border-color: var(--dot-color, #3b82f6);
}
.port-dot-out.connected {
  background: var(--dot-color, #3b82f6);
  border-color: var(--dot-color, #3b82f6);
}
.port-label {
  font-size: 12px;
  white-space: nowrap;
}
.port-label-sortable {
  cursor: grab;
  padding: 2px 4px;
  border-radius: 3px;
  user-select: none;
}
.port-label-sortable:hover {
  background: #f0f5ff;
}
.port-label-selector {
  font-weight: 600;
  background: #fef3c7;
  color: #92400e;
  padding: 1px 5px;
  border-radius: 3px;
}

/* 输入列表 */
.input-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.input-del-btn {
  cursor: pointer;
  color: #ccc;
  font-size: 12px;
  margin-left: 4px;
  line-height: 1;
}
.input-del-btn:hover {
  color: #ef4444;
}
.port-item.dragging {
  opacity: 0.4;
}
/* 添加输入按钮 */
.port-add-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  color: #94a3b8;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
  margin-left: 4px;
}
.port-add-btn:hover {
  border-color: #3b82f6;
  color: #3b82f6;
}
.add-port-menu {
  position: absolute;
  left: 0;
  bottom: 24px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
  overflow: hidden;
}
.add-port-option {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
}
.add-port-option:hover {
  background: #f0f5ff;
}

/* 配置区 */
.mod-config {
  padding: 6px 10px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mod-config select, .mod-config textarea {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
}
.mod-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.mod-config-row select {
  flex: 1;
  min-width: 0;
  max-width: 110px;
}
.mod-config-label {
  color: #666;
  white-space: nowrap;
}
.mod-config-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
}
/* 滑块（TTS 音调/语速/音量） */
.mod-config-slider {
  flex: 1;
  min-width: 0;
  accent-color: #3b82f6;
  height: 18px;
  cursor: pointer;
}
.mod-config-slider-val {
  flex-shrink: 0;
  min-width: 34px;
  text-align: right;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  color: #3b82f6;
  font-variant-numeric: tabular-nums;
}
.mod-model-select-btn {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: #3b82f6;
  background: #e8f0fe;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mod-model-select-btn:hover {
  background: #dbe8fd;
}
.mod-file-upload-btn {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: #3b82f6;
  background: #e8f0fe;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px dashed #93c5fd;
}
.mod-file-upload-btn:hover {
  background: #dbe8fd;
}
.mod-file-upload-btn.has-file {
  color: #059669;
  background: #ecfdf5;
  border-style: solid;
}
/* 文件上传预览区 */
.mod-file-preview {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 6px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
}
.mod-file-preview.show {
  display: flex;
}
.mod-file-preview-media {
  max-width: 100%;
  max-height: 140px;
  border-radius: 4px;
  display: block;
  object-fit: contain;
}
video.mod-file-preview-media,
audio.mod-file-preview-media {
  width: 100%;
  outline: none;
}
audio.mod-file-preview-media {
  height: 32px;
}
.mod-file-remove-btn {
  font-size: 11px;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 2px 10px;
  cursor: pointer;
}
.mod-file-remove-btn:hover {
  background: #fee2e2;
}
.mod-config-input.invalid,
.port-key-input.invalid {
  border-color: #ef4444;
  background: #fef2f2;
}
.mod-config-input:focus,
.port-key-input:focus {
  outline: none;
  border-color: #3b82f6;
}

/* 值类型单选按钮组 */
.value-type-group {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.value-type-btn {
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  color: #555;
  cursor: pointer;
  transition: all 0.15s;
}
.value-type-btn:hover {
  border-color: #f97316;
  color: #f97316;
}
.value-type-btn.active {
  background: #f97316;
  border-color: #f97316;
  color: #fff;
}

/* API 返回端口键名输入框 */
.port-key-input {
  width: 70px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 11px;
  color: #444;
  background: #fbfbfc;
}

/* 合并方式滑块开关 */
.mod-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.mod-toggle-label {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
}
.mod-toggle {
  position: relative;
  width: 40px;
  height: 20px;
  border-radius: 10px;
  background: #22c55e;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
  flex-shrink: 0;
}
.mod-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.mod-toggle.on::after {
  transform: translateX(20px);
}
.mod-config textarea {
  resize: vertical;
  min-height: 60px;
}

/* 模型选择 modal */
.model-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.model-modal {
  background: #fff;
  border-radius: 10px;
  width: 560px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.model-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
}
.model-modal-close {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
}
.model-modal-close:hover {
  color: #ef4444;
}
.model-search {
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
}
.model-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.model-search-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.model-filter {
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 1px solid #eee;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.filter-group > span {
  color: #666;
}
.filter-btn, .sort-btn {
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #f8f9fa;
  cursor: pointer;
  font-size: 12px;
}
.filter-btn.active, .sort-btn.active {
  background: #3b82f6;
  color: #fff;
  border-color: #3b82f6;
}
.model-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.model-group-header {
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  margin: 4px 0;
}
.model-group-body {
  padding: 4px 0;
}
.model-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.model-item:hover {
  border-color: #3b82f6;
  background: #f0f5ff;
}
.model-item.selected {
  border-color: #3b82f6;
  background: #e8f0fe;
}
.model-item-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.model-item-fav {
  font-size: 16px;
  cursor: pointer;
  color: #f59e0b;
  margin-left: 8px;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.model-item-fav:hover { transform: scale(1.2); }
/* 模态 CSS 图标（彩色胶囊） */
.model-chips {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  white-space: nowrap;
}
.modal-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: #fff;
  line-height: 1;
}
.modal-chip.t { background: #3b82f6; }   /* 文本 蓝 */
.modal-chip.i { background: #22c55e; }   /* 图片 绿 */
.modal-chip.v { background: #8b5cf6; }  /* 视频 紫 */
.modal-chip.a { background: #f59e0b; }  /* 音频 橙 */
.modal-chip.r { background: #06b6d4; }  /* 参考图 青 */
.modal-chip.e { background: #ec4899; }  /* 尾帧 粉 */
.modal-chip.m { background: #64748b; }  /* 素材 灰 */
.modal-chip.plus { background: transparent; color: #94a3b8; min-width: 6px; padding: 0; font-weight: 400; }
.modal-chip.arrow { background: transparent; color: #94a3b8; min-width: 10px; padding: 0; font-weight: 400; }
.model-item-meta {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}
.model-item-ability {
  font-size: 12px;
  color: #f59e0b;
  margin-top: 2px;
}
.model-empty {
  padding: 30px;
  text-align: center;
  color: #999;
}

/* 模块选中高亮 */
.workspace-module.selected {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

/* 右键圈选矩形 */
.marquee {
  position: absolute;
  border: 1px solid #3b82f6;
  background: rgba(59, 130, 246, 0.12);
  pointer-events: none;
  z-index: 1000;
}

/* 右键菜单 */
.context-menu {
  position: fixed;
  z-index: 2000;
  min-width: 120px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  padding: 4px;
  user-select: none;
  font-size: 13px;
}
.context-menu-item {
  padding: 7px 14px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  color: #333;
}
.context-menu-item:hover {
  background: #f0f5ff;
  color: #3b82f6;
}
.context-menu-item.disabled {
  color: #cbd5e1;
  cursor: default;
}
.context-menu-item.disabled:hover {
  background: none;
  color: #cbd5e1;
}
.context-menu-sep {
  height: 1px;
  background: #eef2f7;
  margin: 4px 6px;
}
/* ════════════════════════════════════════════════════════════════════
 * 手机端适配（≤860px）
 * 1. 模块列表收回为左上角加号按钮 + 左侧滑出 drawer
 * 2. 控制台挪到页面下方（占 1/3），可全屏展开
 * 3. 项目操作栏收进「操作」下拉
 * ════════════════════════════════════════════════════════════════════ */

/* ── 操作下拉（桌面端平铺，手机端下拉） ── */
.studio-ops { position: relative; display: flex; align-items: center; }
.studio-ops-trigger { display: none; }
.studio-ops-menu { display: flex; gap: 6px; align-items: center; }

/* ── 手机端左上角加号按钮（默认隐藏） ── */
.studio-fab {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #3b82f6;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 90; /* 低于导航栏菜单(z-dropdown:100)，避免盖住导航栏 */
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  align-items: center;
  justify-content: center;
  padding: 0;
}
.studio-fab:active { transform: scale(0.92); }

/* ── 抽屉遮罩（默认隐藏；不遮导航栏与项目栏） ── */
.palette-overlay {
  display: none;
  position: fixed;
  top: 89px; /* 导航栏(≈45px) + 项目栏(44px) 下方开始 */
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 350;
}
.palette-overlay.show { display: block; }

/* ── 控制台标题栏（默认隐藏，手机端显示） ── */
.run-panel-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  font-weight: 600;
  font-size: 12px;
  color: #334155;
}
.run-panel-head-actions { display: flex; gap: 4px; }
.run-panel-head-btn {
  border: none;
  background: none;
  font-size: 15px;
  cursor: pointer;
  color: #64748b;
  padding: 2px 6px;
  border-radius: 4px;
}
.run-panel-head-btn:hover { background: #e2e8f0; color: #334155; }
/* 控制台关闭按钮（手机端全屏 drawer 左上角） */
.run-panel-close {
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 2px 8px;
  border-radius: 4px;
}
.run-panel-close:hover { background: #e2e8f0; color: #334155; }
.run-panel-head-title { flex: 1; text-align: center; margin-right: 28px; }
/* 手机端右上角控制台呼出按钮（默认隐藏，手机端显示） */
.studio-console-btn { display: none; }

@media (max-width: 860px) {
  /* ── 操作下拉 ── */
  .studio-ops-trigger { display: inline-block; }
  .studio-ops-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    flex-direction: column;
    align-items: stretch;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 6px;
    z-index: 300;
    min-width: 140px;
  }
  .studio-ops.open .studio-ops-menu { display: flex; }
  .studio-ops-menu .studio-topbar-btn { width: 100%; text-align: left; }

  /* ── 模块列表 drawer ── */
  .studio-fab { display: flex; }
  .palette {
    position: fixed;
    top: 89px; /* 导航栏(≈45px) + 项目栏(44px) 下方开始，不覆盖项目栏 */
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    z-index: 400;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }
  .palette.open { transform: translateX(0); }
  /* 手机端：模块项不设 touch-action，允许上下滑动列表；
     长按 0.3s 进入拖拽后由 JS preventDefault 阻止滚动 */
  .canvas-world, .canvas-svg { touch-action: none; }
  .canvas-area { touch-action: none; /* 画布触摸手势（拖拽/连线/平移/捏合）全部交给 JS 处理 */ }

  /* ── 主行：画布占满（控制台为全屏 drawer，不占布局） ── */
  .studio-main-row { flex-direction: column; }
  .canvas-panel { flex-direction: column; }
  .canvas-area { flex: 1; min-height: 0; }

  /* ── 右上角控制台呼出按钮（与左上角 + 号对称） ── */
  .studio-console-btn {
    display: flex;
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #334155;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 90; /* 低于导航栏菜单(z-dropdown:100)，避免盖住导航栏 */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    align-items: center;
    justify-content: center;
    padding: 0;
  }
  .studio-console-btn:active { transform: scale(0.92); }

  /* ── 控制台：全屏 drawer（从右侧滑入，覆盖全屏） ── */
  .run-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    background: #fbfbfc;
    border: none;
    border-radius: 0;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  .run-panel.show { transform: translateX(0); }
  .run-panel.run-collapsed { transform: translateX(100%); }
  .run-panel-toggle { display: none; } /* 全屏 drawer 不需要底部把手 */
  .run-panel-resizer { display: none; } /* 全屏 drawer 不需要拖拽调宽 */
  .run-panel-head { display: flex; }

  /* ── 顶部栏紧凑（手机端） ── */
  .studio-topbar { height: 44px; padding: 0 8px; }
  .studio-topbar-left { font-size: 12px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .studio-topbar-btn { padding: 4px 8px; font-size: 12px; }
  .studio-topbar-right { gap: 4px; }
}

/* ════════════════════════════════════════════════════════════════════
 * 编辑器全局禁止意外选中文字：
 * 拖拽模块 / 连线 / 平移画布时不出现文字选中高亮，避免干扰操作。
 * 例外：控制台输出可复制、表单控件可输入（input/textarea/select 浏览器
 * 本就允许交互，补 text 以保证内部文本可编辑）。
 * ════════════════════════════════════════════════════════════════════ */
.studio-layout,
.studio-layout * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none; /* iOS 长按不弹系统菜单 */
}
/* 控制台输出允许选中/复制 */
.studio-layout .run-console,
.studio-layout .run-console * {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
}
/* 表单控件保持可输入（input/textarea/select） */
.studio-layout input,
.studio-layout textarea,
.studio-layout select {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
}
