/* ==========================================================================
   剧情流程工作区（Story Workspace）
   三栏布局：节点库 / 节点画布 / 属性面板
   只使用 base.css 中的 CSS 变量，自动适配深色与浅色主题。
   ========================================================================== */

[data-workspace="story"] > .story-workspace {
  flex: 1;
}

.story-workspace {
  --story-node-w: 224px;
  --story-edge: var(--border-strong);
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  color: var(--text);
}

/* ==========================================================================
   左侧栏：节点库 / 章节大纲 / 数据管理
   ========================================================================== */

.story-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 264px;
  flex: none;
  min-height: 0;
  padding: 8px;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
}

.story-sidebar .panel {
  min-height: 0;
}

.story-sidebar .panel-header {
  height: 34px;
  padding: 0 8px 0 10px;
  font-size: 11px;
  letter-spacing: 0.05em;
}

.story-palette-library {
  flex: 1 1 auto;
  min-height: 180px;
}

.story-palette-outline {
  flex: 0 1 auto;
  min-height: 108px;
  max-height: 246px;
}

.story-palette-data {
  flex: none;
}

.story-panel-header-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ---- 节点库 ---- */

.story-palette-search {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
}

.story-palette-search .story-search-icon {
  display: flex;
  flex: none;
  margin-left: 2px;
}

.story-palette-search-input {
  height: 28px;
  padding-left: 4px;
  font-size: 12px;
  border-color: transparent;
  background: var(--bg-inset);
}
.story-palette-search-input:focus {
  border-color: var(--accent);
}

.story-palette-groups {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 5px 5px 10px;
}

.story-palette-group {
  margin-bottom: 2px;
}

.story-palette-group-head {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 6px 6px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  text-align: left;
  transition:
    background 0.12s var(--ease),
    color 0.12s var(--ease);
}
.story-palette-group-head:hover {
  background: var(--bg-hover);
  color: var(--text-dim);
}

.story-palette-group-count {
  margin-left: auto;
  font-weight: 500;
  opacity: 0.65;
}

.story-palette-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 1px 0 2px 2px;
}

.story-palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  cursor: grab;
  text-align: left;
  transition: background 0.12s var(--ease);
}
.story-palette-item:hover {
  background: var(--bg-hover);
}
.story-palette-item:active {
  cursor: grabbing;
}
.story-palette-item.is-dragging {
  opacity: 0.45;
}

.story-palette-item-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 6px;
  background: var(--node-color, var(--accent));
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
}

.story-palette-item-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  gap: 0;
}

.story-palette-item-label {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
}

.story-palette-item-hint {
  font-size: 10px;
  line-height: 1.35;
  color: var(--text-faint);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-palette-item-add {
  display: flex;
  flex: none;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.12s var(--ease);
}
.story-palette-item:hover .story-palette-item-add {
  opacity: 1;
}

.story-palette-empty {
  padding: 22px 12px;
  gap: 6px;
}

/* ---- 章节大纲 ---- */

.story-outline-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px;
}

.story-outline-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 7px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s var(--ease);
}
.story-outline-item:hover {
  background: var(--bg-hover);
}
.story-outline-item.is-active {
  background: var(--accent-weak);
  color: var(--accent-text);
}
.story-outline-item svg {
  color: var(--text-faint);
  flex: none;
}
.story-outline-item.is-active svg {
  color: var(--accent-text);
}

.story-outline-index {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 4px;
  background: var(--bg-elev);
  color: var(--text-faint);
  font-family: var(--font-code);
  font-size: 10px;
}

.story-outline-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.story-outline-title {
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-outline-sub {
  font-family: var(--font-code);
  font-size: 9.5px;
  color: var(--text-faint);
}

.story-outline-empty {
  padding: 16px 12px;
  gap: 6px;
}

/* ---- 数据管理入口 ---- */

.story-data-entries {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
}

.story-data-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s var(--ease);
}
.story-data-entry:hover {
  background: var(--bg-hover);
}
.story-data-entry > svg {
  color: var(--text-faint);
  flex: none;
}
.story-data-entry .chip {
  height: 18px;
  padding: 0 6px;
  font-size: 10px;
}

.story-data-entry-icon {
  display: flex;
  color: var(--text-dim);
}

/* ==========================================================================
   中间：画布
   ========================================================================== */

.story-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.story-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas-bg);
  outline: none;
  touch-action: none;
  user-select: none;
  cursor: default;
}
.story-canvas:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}
.story-canvas.is-space {
  cursor: grab;
}
.story-canvas.is-panning {
  cursor: grabbing;
}
.story-canvas.is-node-dragging,
.story-canvas.is-node-dragging .story-node {
  cursor: grabbing;
}
.story-canvas.is-connecting,
.story-canvas.is-connecting .story-node {
  cursor: crosshair;
}
.story-canvas.is-marqueeing,
.story-canvas.is-marqueeing .story-node {
  cursor: crosshair;
}
.story-canvas.is-palette-drop::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-m);
  background: var(--accent-weak);
  pointer-events: none;
  z-index: 15;
}

/* ---- 网格背景 ---- */

.story-grid {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, var(--canvas-dot) 1.6px, transparent 1.9px),
    radial-gradient(circle, var(--canvas-dot) 1px, transparent 1.25px);
  background-size:
    var(--grid-major, 100px) var(--grid-major, 100px),
    var(--grid-size, 20px) var(--grid-size, 20px);
  background-position:
    var(--grid-major-x, 0px) var(--grid-major-y, 0px),
    var(--grid-x, 0px) var(--grid-y, 0px);
}

/* ---- 世界变换层 ---- */

.story-transform {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  transform-origin: 0 0;
  will-change: transform;
}
.story-transform.is-animating {
  transition: transform 0.22s var(--ease);
}

.story-nodes {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 0;
  height: 0;
}

.story-edges {
  position: absolute;
  overflow: visible;
  z-index: 1;
  pointer-events: none;
}

/* ---- 连线 ---- */

.story-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
  cursor: pointer;
}

.story-edge-line {
  stroke: var(--story-edge);
  stroke-width: 1.8;
  stroke-linecap: round;
  fill: none;
  pointer-events: none;
  transition:
    stroke 0.12s var(--ease),
    stroke-width 0.12s var(--ease);
}
.story-edge:hover .story-edge-line {
  stroke: var(--accent-hover);
  stroke-width: 2.4;
}
.story-edge.is-selected .story-edge-line {
  stroke: var(--accent);
  stroke-width: 2.6;
  filter: drop-shadow(0 0 4px var(--accent-weak));
}
.story-edge.has-issues .story-edge-line {
  stroke: var(--danger);
  stroke-dasharray: 6 5;
}

.story-edge-label {
  fill: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 500;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--canvas-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s var(--ease);
}
.story-edge:hover .story-edge-label,
.story-edge.is-selected .story-edge-label {
  opacity: 0.95;
}

.story-edge-temp {
  stroke: var(--accent-hover);
  stroke-width: 2;
  stroke-dasharray: 7 5;
  stroke-linecap: round;
  pointer-events: none;
  opacity: 0.9;
}

/* ---- 节点卡片 ---- */

.story-node {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--story-node-w);
  min-height: 74px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-panel);
  box-shadow: var(--shadow-1);
  color: var(--text);
  cursor: grab;
  user-select: none;
  will-change: transform;
  transition:
    border-color 0.12s var(--ease),
    box-shadow 0.12s var(--ease);
}
.story-node::before {
  content: "";
  position: absolute;
  left: 0;
  top: 11px;
  bottom: 11px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--node-color, var(--accent));
  opacity: 0.9;
}
.story-node:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}
.story-node:active {
  cursor: grabbing;
}
.story-node.is-selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px var(--accent-weak),
    var(--shadow-2);
}
.story-node.is-selected::before {
  opacity: 1;
}
.story-node.has-errors {
  border-color: rgba(239, 68, 68, 0.5);
}
.story-node.is-in-marquee {
  border-color: var(--accent-hover);
  box-shadow:
    0 0 0 2px var(--accent-weak),
    var(--shadow-1);
}
.story-node.is-drop-target {
  border-color: var(--success);
  box-shadow:
    0 0 0 3px var(--success-weak),
    var(--shadow-2);
}
.story-node.is-drop-invalid {
  border-color: var(--danger);
  box-shadow:
    0 0 0 3px var(--danger-weak),
    var(--shadow-2);
}

.story-node-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: inherit;
}

.story-node-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px 6px 12px;
  border-bottom: 1px solid var(--border);
}

.story-node-icon {
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  flex: none;
  border-radius: 6px;
  background: var(--node-color, var(--accent));
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
}
.story-node-icon svg {
  width: 12px;
  height: 12px;
}

.story-node-kind {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-node-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--warn-weak);
  color: #fbbf24;
  font-size: 9.5px;
  font-weight: 700;
  flex: none;
  cursor: help;
}
.story-node.has-errors .story-node-badge {
  background: var(--danger-weak);
  color: #fca5a5;
}
html[data-theme="light"] .story-node-badge {
  color: #b45309;
}
html[data-theme="light"] .story-node.has-errors .story-node-badge {
  color: #b91c1c;
}

.story-node-body {
  padding: 7px 12px 9px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.story-node-summary {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.story-node-terminal {
  align-self: flex-start;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--success-weak);
  color: var(--success);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
html[data-theme="light"] .story-node-terminal {
  color: #15803d;
}

/* ---- 出口端口 ---- */

.story-node-port-rows {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  padding: 2px 0 3px;
}

.story-node-port-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 14px 0 16px;
  font-size: 11.5px;
  color: var(--text-dim);
  cursor: crosshair;
  transition: background 0.12s var(--ease);
}
.story-node-port-row:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.story-node-port-row.is-open .story-node-port-text {
  color: var(--text-faint);
}
.story-node-port-row.is-open .story-node-port-dot,
.story-node-port-out.is-open .story-node-port-dot {
  opacity: 0.55;
}
.story-node-port-row.is-connected .story-node-port-dot,
.story-node-port-out.is-connected .story-node-port-dot {
  opacity: 1;
}
.story-node-port-row.is-connected .story-node-port-text {
  color: var(--text-dim);
}

.story-node-port-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-node-port-dot {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22);
  flex: none;
  transition: transform 0.12s var(--ease);
}
.story-node-port-row .story-node-port-dot {
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
}
.story-node-port-row:hover .story-node-port-dot {
  transform: translateY(-50%) scale(1.22);
  box-shadow: 0 0 0 2px var(--bg-panel);
}

.story-node-port {
  position: absolute;
  display: flex;
  align-items: center;
  z-index: 2;
}
/* 普通节点的唯一出口圆点正好落在卡片右边线上，方便贝塞尔曲线对齐 */
.story-node-port-out {
  right: -6px;
  top: 50%;
  width: 0;
  height: 0;
  cursor: crosshair;
}
.story-node-port-out::before {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
}
.story-node-port-out .story-node-port-dot {
  position: absolute;
  left: -11px;
  top: 0;
  transform: translateY(-50%);
  border-color: var(--bg-panel);
}
.story-node-port-out:hover .story-node-port-dot {
  transform: translateY(-50%) scale(1.22);
  box-shadow: 0 0 0 2px var(--bg-panel);
}
.story-node-port-in {
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px 4px 0;
  cursor: default;
}
.story-node-port-in .story-node-port-dot {
  width: 9px;
  height: 9px;
  background: var(--border-strong);
  border: 2px solid var(--bg-panel);
  box-shadow: none;
}

.story-node-port-tip {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  box-shadow: var(--shadow-1);
  color: var(--text);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s var(--ease);
  z-index: 30;
}
.story-node-port-row .story-node-port-tip {
  left: calc(100% + 4px);
  right: auto;
}
.story-node-port-out .story-node-port-tip {
  left: 18px;
  right: auto;
}
.story-node-port-row:hover .story-node-port-tip,
.story-node-port-out:hover .story-node-port-tip {
  opacity: 1;
}

/* ---- 画布覆盖层：工具栏 / 缩放 / 提示 / 框选 ---- */

.story-canvas-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-panel);
  box-shadow: var(--shadow-1);
}
.story-canvas-toolbar .btn {
  height: 27px;
  font-size: 12px;
}
.story-canvas-toolbar .btn-icon {
  width: 27px;
}
.story-canvas-toolbar .btn-icon.active {
  background: var(--accent-weak);
  color: var(--accent-text);
}
.story-canvas-toolbar .toolbar-sep {
  height: 18px;
  margin: 0 2px;
}

.story-zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-panel);
  box-shadow: var(--shadow-1);
}
.story-zoom .btn-icon {
  width: 25px;
  height: 25px;
}
.story-zoom .toolbar-sep {
  height: 16px;
  margin: 0 3px;
}

.story-zoom-percent {
  min-width: 52px;
  height: 25px;
  padding: 0 4px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-code);
  font-size: 11px;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    color 0.12s var(--ease);
}
.story-zoom-percent:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.story-canvas-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 19;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--text-faint);
  pointer-events: none;
  opacity: 0.85;
}
.story-canvas-hint .kbd {
  height: 17px;
  min-width: 17px;
  padding: 0 4px;
  font-size: 9px;
}
.story-hint-dot {
  opacity: 0.5;
  margin: 0 2px;
}

.story-marquee {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--accent-weak);
  pointer-events: none;
}

.story-connect-tip {
  position: absolute;
  z-index: 30;
  padding: 4px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-1);
  color: var(--text-dim);
  font-size: 10.5px;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- 添加节点弹窗 ---- */

.story-add-popup {
  position: absolute;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: 326px;
  max-height: min(460px, calc(100% - 20px));
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.story-add-popup-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
}
.story-add-popup-head > svg {
  color: var(--accent-hover);
}
.story-add-popup-head > button {
  margin-left: auto;
}

.story-add-popup-search {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
}
.story-add-popup-search .input {
  height: 28px;
  font-size: 12px;
  border-color: transparent;
  background: var(--bg-inset);
}
.story-add-popup-search .input:focus {
  border-color: var(--accent);
}

.story-add-popup-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px;
}

.story-add-popup-group-title {
  padding: 7px 8px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.story-add-popup-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.story-add-popup-item:hover,
.story-add-popup-item.is-active {
  background: var(--accent-weak);
}

.story-add-popup-item-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 6px;
  background: var(--node-color, var(--accent));
  color: #fff;
}

.story-add-popup-item-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 0;
}

.story-add-popup-item-label {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
}

.story-add-popup-item-hint {
  font-size: 10px;
  line-height: 1.4;
  color: var(--text-faint);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-add-popup-item-add {
  display: flex;
  flex: none;
  color: var(--text-faint);
  opacity: 0;
}
.story-add-popup-item:hover .story-add-popup-item-add,
.story-add-popup-item.is-active .story-add-popup-item-add {
  opacity: 1;
}

.story-add-popup-foot {
  flex: none;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 10px;
}

.story-add-popup-empty {
  padding: 22px 12px;
  gap: 6px;
}

/* ---- 状态栏 ---- */

.story-statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  height: 32px;
  padding: 0 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.story-validation {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 5px;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    border-color 0.12s var(--ease);
}
.story-validation:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}
.story-validation-chip {
  height: 20px;
  padding: 0 7px;
  font-size: 10.5px;
}
.story-validation-more {
  font-size: 10px;
  color: var(--text-faint);
}
.story-validation:hover .story-validation-more {
  color: var(--text-dim);
}

.story-status-stats {
  font-family: var(--font-code);
  font-size: 10.5px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* ==========================================================================
   右侧：属性面板
   ========================================================================== */

.story-inspector {
  display: flex;
  flex-direction: column;
  width: 332px;
  flex: none;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
}

.story-inspector-head {
  flex: none;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.story-inspector-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 13px 12px 24px;
}

.inspector-node-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.inspector-node-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: var(--node-color, var(--accent));
  color: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.26);
}
.inspector-node-icon svg {
  width: 16px;
  height: 16px;
}

.story-inspector-node-meta {
  min-width: 0;
  padding-top: 1px;
}

.inspector-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.inspector-subtitle {
  margin-top: 2px;
  font-family: var(--font-code);
  font-size: 10px;
  color: var(--text-faint);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.inspector-head-actions {
  display: flex;
  gap: 1px;
  margin-left: auto;
  flex: none;
}

.inspector-overview-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inspector-overview-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: var(--accent-weak);
  color: var(--accent-text);
}

.inspector-overview {
  display: flex;
  flex-direction: column;
}

.story-inspector-desc {
  margin: 2px 0 14px;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.7;
}

.story-inspector-section {
  margin-bottom: 17px;
}
.story-inspector-section:last-child {
  margin-bottom: 4px;
}

.story-inspector-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 9px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.story-inspector-section-title > svg {
  opacity: 0.8;
}
.story-inspector-section-title .chip {
  margin-left: auto;
  height: 18px;
  font-size: 9.5px;
  text-transform: none;
  letter-spacing: 0;
}

.story-inspector-empty {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-s);
  color: var(--text-faint);
  font-size: 11.5px;
}
.story-inspector-empty svg {
  color: var(--success);
  flex: none;
}

/* ---- 概览统计 ---- */

.story-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.story-stat-card {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
}

.story-stat-icon {
  display: flex;
  margin-bottom: 2px;
  color: var(--text-faint);
}

.story-stat-value {
  font-family: var(--font-code);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
}

.story-stat-label {
  color: var(--text-faint);
  font-size: 10px;
}

.story-valid-ok {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-radius: var(--radius-s);
  background: var(--success-weak);
  color: var(--success);
  font-size: 12px;
  font-weight: 500;
}
html[data-theme="light"] .story-valid-ok {
  color: #15803d;
}

.story-valid-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.story-valid-preview {
  margin: 8px 0 0;
  padding-left: 16px;
  list-style: disc;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.65;
}

.story-overview-validation {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inspector-issues {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.story-valid-preview li.is-error {
  color: #fca5a5;
}
html[data-theme="light"] .story-valid-preview li.is-error {
  color: #b91c1c;
}

.story-overview-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
}
.story-overview-actions.wrap {
  flex-wrap: wrap;
}
.story-overview-actions .btn {
  height: 27px;
  font-size: 11.5px;
}
.story-overview-actions .btn:first-child {
  margin-right: 0;
}

.story-overview-start {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
}

.story-line-strong {
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.story-line-sub {
  color: var(--text-faint);
  font-size: 10.5px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-tips {
  margin: 0;
  padding-left: 16px;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.85;
}

/* ---- 校验列表 ---- */

.story-issue-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.story-issue-list li {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
  font-size: 11.5px;
  line-height: 1.55;
}
.story-issue-list li svg {
  flex: none;
  margin-top: 1px;
}
.story-issue-list li.is-error {
  border-color: rgba(239, 68, 68, 0.38);
  background: var(--danger-weak);
  color: #fca5a5;
}
.story-issue-list li.is-warn {
  border-color: rgba(245, 158, 11, 0.32);
  background: var(--warn-weak);
  color: #fcd34d;
}
html[data-theme="light"] .story-issue-list li.is-error {
  color: #b91c1c;
}
html[data-theme="light"] .story-issue-list li.is-warn {
  color: #b45309;
}
.story-issue-list li[title] {
  cursor: pointer;
}
.story-issue-list li[title]:hover {
  border-color: var(--border-strong);
}

.story-issue-list-modal {
  max-height: 48vh;
  overflow: auto;
  padding-right: 2px;
}

.story-issue-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.55;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    border-color 0.12s var(--ease);
}
.story-issue-row:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.story-issue-row > svg {
  flex: none;
  margin-top: 2px;
}
.story-issue-row.is-error > svg {
  color: var(--danger);
}
.story-issue-row.is-warn > svg {
  color: var(--warn);
}
.story-issue-row-message {
  flex: 1;
}
.story-issue-row .chip {
  flex: none;
  height: 18px;
  font-size: 10px;
}

.story-validation-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.story-validation-modal-head .story-valid-chips {
  flex: 1;
}

/* ---- 连线信息 ---- */

.story-connections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.story-connection-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.story-connection-title {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.story-connection-row {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    border-color 0.12s var(--ease);
}
.story-connection-row:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.story-connection-row > svg {
  flex: none;
  color: var(--text-faint);
}

.story-connection-port {
  max-width: 108px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent-text);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
}

.story-connection-target {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 0;
}

.story-connection-hint {
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.6;
}

/* ---- 连线属性 ---- */

.story-edge-flow {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.story-edge-node {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    border-color 0.12s var(--ease);
}
.story-edge-node:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.story-edge-arrow {
  display: flex;
  justify-content: center;
  padding: 1px 0;
  color: var(--text-faint);
}

.story-edge-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.story-edge-meta .field-label {
  font-size: 11px;
}

/* 属性面板内组合行避免溢出 */
.story-inspector .field-row {
  align-items: center;
}
.story-inspector .field-row > .input,
.story-inspector .field-row > .select {
  flex: 1;
  min-width: 0;
}
.story-inspector .field-row > .btn-icon {
  flex: none;
}
.story-inspector .color-row > .input {
  flex: 1;
  min-width: 0;
}

/* ---- choices / branches 列表编辑 ---- */

.story-list-editor {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
}

.story-list-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
  transition:
    border-color 0.12s var(--ease),
    box-shadow 0.12s var(--ease),
    opacity 0.12s var(--ease);
}
.story-list-row.is-dragging {
  opacity: 0.45;
}
.story-list-row.is-drop-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-weak);
}

.story-drag-handle {
  display: flex;
  align-items: center;
  padding: 4px 2px;
  color: var(--text-faint);
  cursor: grab;
  flex: none;
}
.story-drag-handle:active {
  cursor: grabbing;
}

.story-list-index {
  min-width: 15px;
  padding-top: 7px;
  color: var(--text-faint);
  font-family: var(--font-code);
  font-size: 10px;
  flex: none;
}

.story-list-fields {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 4px;
}
.story-list-fields .input {
  height: 28px;
  font-size: 11.5px;
}

.story-list-add {
  align-self: flex-start;
  height: 26px;
}

.story-branch-badge {
  align-self: flex-start;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent-text);
  font-size: 9.5px;
  font-weight: 600;
}
.story-branch-badge.is-else {
  background: var(--bg-elev);
  color: var(--text-faint);
}

.story-quick-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.story-quick-labels .chip {
  height: 20px;
  font-size: 10px;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    color 0.12s var(--ease);
}
.story-quick-labels .chip:hover {
  background: var(--accent-weak);
  border-color: transparent;
  color: var(--accent-text);
}

/* ---- 资源字段 / 代码输入 ---- */

.story-asset-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.story-asset-preview {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
}
.story-asset-preview img {
  width: 56px;
  height: 36px;
  flex: none;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

.story-asset-audio {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text-dim);
}

.story-asset-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.story-code-input {
  font-family: var(--font-code);
  font-size: 11.5px;
  line-height: 20px;
  min-height: 88px;
  resize: vertical;
  tab-size: 4;
}

/* ==========================================================================
   数据管理弹窗（角色 / 变量 / 资源）
   ========================================================================== */

.story-data-manager {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 64vh;
}

.story-data-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.story-data-hint {
  flex: 1;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.6;
}

.story-data-list-head {
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
}

.story-data-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.story-data-empty {
  padding: 24px 12px;
  gap: 6px;
}

.story-data-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
}

.story-data-row-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 8px;
}

.story-data-row-head {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.story-character-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--bg-inset);
}

.story-variable-icon {
  display: flex;
  color: var(--text-faint);
}

.story-data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.story-data-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.story-data-field-label {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
}

.story-data-field .input,
.story-data-field .select {
  height: 28px;
  font-size: 11.5px;
}

.story-data-field-error {
  color: var(--danger);
  font-size: 10px;
  line-height: 1.4;
}

.input.is-invalid,
.select.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px var(--danger-weak);
}

.story-data-search {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-faint);
}
.story-data-search .input {
  height: 30px;
  font-size: 12px;
}

.story-asset-list {
  gap: 6px;
}

.story-asset-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
}
.story-asset-row.has-issues {
  border-color: rgba(245, 158, 11, 0.4);
}

.story-asset-thumb {
  display: grid;
  place-items: center;
  width: 58px;
  height: 40px;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-inset);
}
.story-asset-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-asset-row-meta {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 2px;
}

.story-asset-row-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.story-asset-row-title .chip {
  height: 18px;
  font-size: 9.5px;
}

.story-asset-row-actions {
  display: flex;
  flex-direction: column;
  flex: none;
  gap: 3px;
}

.story-asset-issues {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
}

.story-asset-issue {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--warn);
  font-size: 10px;
}

/* ==========================================================================
   自定义节点模板 / 函数快捷插入 / 代码编辑器入口（v1.1）
   ========================================================================== */

/* ---- 节点库「我的模板」分组 ---- */

.story-template-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}

.story-template-group-head {
  cursor: default;
  color: var(--text-faint);
  flex-wrap: wrap;
  row-gap: 2px;
}
.story-template-group-head:hover {
  background: transparent;
  color: var(--text-faint);
}
.story-template-group-head svg {
  color: var(--accent-hover);
  opacity: 0.85;
}

.story-template-empty {
  padding: 8px 9px 10px 18px;
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.6;
}

.story-template-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 1px 0 2px 2px;
}

.story-template-item {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 3px 2px 2px;
  border-radius: var(--radius-s);
  transition: background 0.12s var(--ease);
}
.story-template-item:hover {
  background: var(--bg-hover);
}
.story-template-item.is-dragging {
  opacity: 0.45;
}

.story-template-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.story-template-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 6px;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
}

.story-template-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 0;
}

.story-template-name {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-template-meta {
  font-size: 10px;
  line-height: 1.35;
  color: var(--text-faint);
}

.story-template-warn {
  display: flex;
  flex: none;
  color: var(--warn);
}

.story-template-delete {
  flex: none;
  width: 24px;
  height: 24px;
  opacity: 0;
  transition: opacity 0.12s var(--ease);
}
.story-template-item:hover .story-template-delete {
  opacity: 1;
}
.story-template-delete.btn-danger {
  background: transparent;
  color: var(--text-faint);
}
.story-template-delete.btn-danger:hover {
  background: var(--danger-weak);
  color: var(--danger);
}

/* ---- 模板悬浮预览 ---- */

.story-template-preview {
  position: fixed;
  z-index: 80;
  width: 252px;
  max-height: 320px;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elev);
  box-shadow: var(--shadow-2);
  pointer-events: none;
  animation: story-preview-in 0.13s var(--ease);
}
@keyframes story-preview-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.story-template-preview-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}
.story-template-preview-head > svg {
  color: var(--accent-hover);
  flex: none;
}

.story-template-preview-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.story-template-preview-meta .chip {
  height: 18px;
  padding: 0 6px;
  font-size: 9.5px;
}

.story-template-preview-desc {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.6;
  word-break: break-word;
}

.story-template-preview-nodes {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--border);
}

.story-template-preview-node {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 1.7;
}

.story-template-preview-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 3px;
  background: var(--bg-inset);
  color: var(--text-faint);
  font-family: var(--font-code);
  font-size: 9px;
  flex: none;
}

.story-template-preview-type {
  color: var(--text-dim);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.story-template-preview-type::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--node-color, var(--accent));
  vertical-align: middle;
}

.story-template-preview-more {
  color: var(--text-faint);
  font-size: 10px;
  padding-left: 21px;
}

.story-template-preview-foot {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.5;
}

/* ---- 保存为模板弹窗 ---- */

.story-template-save {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.story-template-save-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.story-template-save-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

.story-template-save-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.story-template-preview-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 120px;
  overflow: auto;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
}

.story-template-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 10.5px;
  white-space: nowrap;
}
.story-template-chip svg {
  color: var(--node-color, var(--accent));
}

/* ---- Python 代码字段 ---- */

.story-code-control {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.story-code-editor-btn {
  flex: none;
  height: 24px;
  padding: 0 8px;
  font-size: 10.5px;
}
.story-code-editor-btn svg {
  opacity: 0.8;
}

/* ---- 自定义函数快捷插入 ---- */

.story-function-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 7px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
}

.story-function-chips-label {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  margin-right: 2px;
}

.story-function-chip {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  height: 21px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--accent-text);
  font-size: 10.5px;
  cursor: pointer;
  transition:
    background 0.12s var(--ease),
    border-color 0.12s var(--ease),
    color 0.12s var(--ease);
}
.story-function-chip:hover {
  background: var(--accent-weak);
  border-color: transparent;
  color: var(--accent-text);
}
.story-function-chip.is-disabled {
  opacity: 0.55;
  color: var(--text-faint);
  text-decoration: line-through;
}
.story-function-chip .mono {
  font-size: 10px;
}

.story-function-more {
  color: var(--text-faint);
  font-size: 10px;
}

.story-function-hint {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-s);
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.5;
}
.story-function-hint svg {
  flex: none;
  opacity: 0.8;
}

.story-branches-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 13px;
}
.story-branches-field > .field {
  margin-bottom: 0;
}

/* ==========================================================================
   v1.2：多选 / Ctrl 拖动复制 / 模板多选排序 / 侧栏调宽
   ========================================================================== */

/* ---- 画布多选计数条 ---- */

.story-selection-chip {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 21;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-1);
  color: var(--accent-text);
  font-size: 11.5px;
  font-weight: 500;
  animation: story-chip-in 0.14s var(--ease);
}
@keyframes story-chip-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.story-selection-chip > svg {
  flex: none;
  opacity: 0.9;
}

.story-selection-chip-label {
  white-space: nowrap;
}

.story-selection-chip-clear {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--accent-text);
  cursor: pointer;
}
.story-selection-chip-clear:hover {
  background: var(--accent-weak);
  color: var(--text);
}

/* ---- Ctrl/Cmd 拖动复制的克隆视觉 ---- */

.story-node.is-clone {
  pointer-events: none;
  border-style: dashed;
  border-color: var(--accent);
  opacity: 0.82;
  box-shadow: 0 0 0 2px var(--accent-weak);
}
.story-node.is-clone::before {
  opacity: 0.55;
}

.story-clone-edges .story-edge-line.is-clone {
  stroke: var(--accent-hover);
  stroke-dasharray: 6 4;
  opacity: 0.9;
}

/* ---- 拖到「我的模板」区域 ---- */

.story-canvas.is-template-drop {
  cursor: copy;
}

.story-template-drop-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  margin: 0 0 2px;
  padding: 7px 9px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-s);
  background: var(--accent-weak);
  color: var(--text);
  cursor: copy;
  animation: story-drop-in 0.14s var(--ease);
}
@keyframes story-drop-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.story-template-drop-hint > svg {
  color: var(--accent-hover);
  flex: none;
}
.story-template-drop-hint-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.story-template-drop-hint-title {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.35;
}
.story-template-drop-hint-sub {
  font-size: 10px;
  color: var(--text-faint);
  line-height: 1.35;
}
.story-template-drop-hint.is-drop-target {
  border-style: solid;
  background: var(--accent);
  color: #fff;
}
.story-template-drop-hint.is-drop-target > svg,
.story-template-drop-hint.is-drop-target .story-template-drop-hint-sub {
  color: rgba(255, 255, 255, 0.85);
}

.story-template-group.is-drop-target {
  position: relative;
  border-radius: var(--radius-s);
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: var(--accent-weak);
  animation: story-drop-pulse 1.4s ease-in-out infinite;
}
.story-template-group.is-drop-target::after {
  content: "松开保存为节点模板";
  display: block;
  margin: 4px 6px 8px;
  padding: 6px 8px;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
}
@keyframes story-drop-pulse {
  0%,
  100% {
    outline-color: var(--accent);
  }
  50% {
    outline-color: var(--accent-hover);
  }
}

/* ---- 模板多选 / 排序 ---- */

.story-template-item.is-multi-selected {
  background: var(--accent-weak);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.story-template-item.is-multi-selected .story-template-icon {
  box-shadow: 0 0 0 2px var(--accent);
}

.story-template-item.is-drop-before {
  box-shadow: inset 0 2px 0 0 var(--accent);
}
.story-template-item.is-drop-after {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

.story-template-batch-delete {
  height: 20px;
  padding: 0 6px;
  font-size: 10px;
  color: var(--danger);
  flex: none;
}
.story-template-batch-delete:hover {
  background: var(--danger-weak);
  color: var(--danger);
}

.story-template-end-drop {
  display: none;
  margin: 4px 2px 2px;
  padding: 5px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-s);
  color: var(--text-faint);
  font-size: 10px;
  text-align: center;
}
.story-template-items:has(.is-dragging) + .story-template-end-drop,
.story-template-group.is-template-dragging .story-template-end-drop,
.story-template-end-drop.is-drop-target {
  display: block;
}
.story-template-end-drop.is-drop-target {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent-text);
}
.story-template-end-drop {
  font-size: 0;
}
.story-template-end-drop::after {
  content: "拖到此处移动到末尾";
  font-size: 10px;
}

/* ---- 章节大纲多选 ---- */

.story-outline-item.is-multi-selected {
  background: var(--bg-hover);
  box-shadow: inset 2px 0 0 0 var(--accent);
}
.story-outline-item.is-multi-selected.is-active {
  background: var(--accent-weak);
}

.story-sidebar .story-panel-header-actions .chip {
  height: 18px;
  padding: 0 6px;
  font-size: 9.5px;
}

/* ---- 可调宽侧栏适配 ---- */

.story-workspace > .er-splitter {
  background: transparent;
}
.story-workspace > .story-sidebar {
  overflow: hidden;
}
.story-workspace > .er-splitter:hover::before {
  background: var(--accent-hover);
}

/* ---- 框选追加模式视觉 ---- */

.story-marquee.is-additive {
  border-style: dashed;
  border-color: var(--success);
  background: var(--success-weak);
}

/* ==========================================================================
   v1.3：高级代码块（raw 节点）与高级节点分组
   ========================================================================== */

.story-node.is-raw {
  background:
    linear-gradient(135deg, rgba(124, 58, 237, 0.16), rgba(124, 58, 237, 0.02) 58%),
    var(--bg-panel);
  border-color: rgba(124, 58, 237, 0.42);
}
.story-node.is-raw:hover {
  border-color: rgba(124, 58, 237, 0.68);
}
.story-node.is-raw.is-selected {
  border-color: #8b5cf6;
  box-shadow:
    0 0 0 2px rgba(124, 58, 237, 0.22),
    var(--shadow-2);
}
.story-node.is-raw .story-node-head {
  border-bottom-color: rgba(124, 58, 237, 0.24);
}
.story-node.is-raw .story-node-icon {
  background: linear-gradient(140deg, #7c3aed, #a855f7);
}

.story-node-raw-tag {
  flex: none;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(124, 58, 237, 0.2);
  color: #c4b5fd;
  font-family: var(--font-code);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.5;
}
html[data-theme="light"] .story-node-raw-tag {
  background: rgba(124, 58, 237, 0.12);
  color: #6d28d9;
}

.story-node-body-code {
  padding-top: 6px;
  padding-bottom: 8px;
}

.story-node-code-snippet {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--text-dim);
  font-family: var(--font-code);
  font-size: 10.5px;
  line-height: 1.55;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.story-node.is-raw .story-node-code-snippet {
  border-color: rgba(124, 58, 237, 0.22);
  color: #ddd6fe;
}
html[data-theme="light"] .story-node.is-raw .story-node-code-snippet {
  color: #5b21b6;
}

/* ---- 节点库「高级节点」分组（默认折叠） ---- */

.story-palette-advanced {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}

.story-palette-advanced-head {
  color: var(--text-faint);
}
.story-palette-advanced-head:hover {
  color: var(--text-dim);
}

.story-palette-advanced-tip {
  margin-left: 2px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
}

.story-palette-advanced-desc {
  padding: 2px 8px 5px 18px;
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.5;
}

.story-palette-item.is-advanced {
  border: 1px dashed transparent;
}
.story-palette-item.is-advanced:hover {
  border-color: rgba(124, 58, 237, 0.32);
}

.story-palette-item-tag {
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(124, 58, 237, 0.18);
  color: #c4b5fd;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
  vertical-align: middle;
}
html[data-theme="light"] .story-palette-item-tag {
  background: rgba(124, 58, 237, 0.12);
  color: #6d28d9;
}

/* ==========================================================================
   响应式：窄屏时压缩两侧面板
   ========================================================================== */

@media (max-width: 1280px) {
  .story-sidebar {
    width: 238px;
  }
  .story-inspector {
    width: 300px;
  }
}

@media (max-width: 1080px) {
  .story-sidebar {
    width: 220px;
  }
  .story-inspector {
    width: 280px;
  }
  .story-palette-item-hint {
    display: none;
  }
  .story-canvas-hint {
    display: none;
  }
}
