/* ============================================================
   创作工作台 · 阶段 03 Demo
   ------------------------------------------------------------
   视觉语言沿用 03_交互线/platform/styles.css 的探索模式（深色）：
   同一套 token、字号阶梯、字距、1px 细线、8px 圆角、单一冷蓝强调色。
   本文件只写本页需要的组件，不引 styles.css，避免两页全局样式互相污染。
   ============================================================ */

:root {
  --bg: #141518;
  --panel: #1c1d21;
  --panel-2: #242529;
  --surface: #1f2025;
  --ink: #eceded;
  --ink-2: #b6b7bb;
  --ink-3: #909197;
  --line: #2b2c31;
  --line-strong: #3c3d44;
  --accent: #7ea0c8;
  --accent-soft: rgba(126, 160, 200, 0.15);
  --accent-line: rgba(126, 160, 200, 0.55);
  --accent-weak: rgba(126, 160, 200, 0.4);
  --on-accent: #141518;
  --personal: #6faaa0;
  --personal-soft: rgba(111, 170, 160, 0.16);
  --warm: #c9a97a;
  --danger: #e08a80;
  --glass: rgba(20, 21, 24, 0.88);
  --node-fill: #e9e7e2;
  --shadow-float: 0 10px 28px rgba(0, 0, 0, 0.5);
  --radius: 8px;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
  --tracking-large-title: 0.22px;
  --tracking-title2: -0.43px;
  --tracking-title3: -0.23px;
  --tracking-body: 0.06px;
  --tracking-caption: 0.12px;
  --tracking-label-tight: 0.08em;
  --tracking-label: 0.12em;
  --tracking-label-wide: 0.14em;
  --tracking-label-xwide: 0.16em;
  --ease-out: cubic-bezier(0.22, 0.8, 0.3, 1);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* 本页多处用 hidden 属性切换显隐；组件自身的 display 会覆盖 UA 规则，这里统一兜住 */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: var(--tracking-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 16px;
  height: 16px;
  display: block;
  fill: currentColor;
  flex: none;
}

/* ============ 顶部 ============ */

.topbar {
  position: relative;
  z-index: 40;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 18px;
  background: #17181b;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  font-size: 10px;
  letter-spacing: var(--tracking-label-xwide);
  color: var(--ink-3);
  white-space: nowrap;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: var(--tracking-title3);
  white-space: nowrap;
}

.tag {
  font-size: 11px;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  white-space: nowrap;
}

.stage-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
}

.stage {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--ink-3);
  text-decoration: none;
  transition: color 0.18s, background 0.18s;
}

.stage i {
  font-style: normal;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-label-tight);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  line-height: 15px;
}

.stage.is-done:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.stage.is-current {
  color: var(--accent);
  background: var(--accent-soft);
}

.stage.is-current i {
  color: var(--accent);
  border-color: var(--accent-line);
}

.stage-sep {
  width: 12px;
  height: 1px;
  background: var(--line);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--ink-3);
  white-space: nowrap;
  margin-right: 2px;
}

.save-state i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--personal);
  box-shadow: 0 0 0 3px var(--personal-soft);
}

.save-state.is-saving i {
  background: var(--warm);
  box-shadow: 0 0 0 3px rgba(201, 169, 122, 0.16);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  border-radius: 7px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  color: var(--ink-2);
  background: var(--bg);
  transition: border-color 0.18s, color 0.18s, background 0.18s, filter 0.18s;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn .icon {
  width: 13px;
  height: 13px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  padding: 6px 16px;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

/* ============ 三栏骨架 ============ */

.workspace {
  position: relative;
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr) 352px;
  min-height: 0;
  transition: grid-template-columns 0.28s var(--ease-out);
}

.workspace.ai-collapsed {
  grid-template-columns: 372px minmax(0, 1fr) 0px;
}

.workspace.ai-collapsed .ai-pane {
  display: none;
}

/* ============ 左栏：问题 + 坐具 + 参考素材 ============ */

.story-pane {
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: #16171a;
  border-right: 1px solid var(--line);
  padding-bottom: 36px;
}

.story-pane::-webkit-scrollbar,
.ai-scroll::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 8px;
}

.story-pane::-webkit-scrollbar-thumb,
.ai-scroll::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: #2e2f35;
  border-radius: 4px;
}

.story-pane::-webkit-scrollbar-track,
.ai-scroll::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.issue-block,
.ref-block {
  padding: 16px 18px 18px;
  border-bottom: 1px solid var(--line);
}

.ref-block {
  border-bottom: none;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-number {
  margin: 0;
  font-size: 10px;
  letter-spacing: var(--tracking-label-xwide);
  color: var(--ink-3);
}

.count {
  font-size: 9px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.text-btn {
  font-size: 10px;
  color: var(--ink-3);
  padding: 2px 5px;
  border-radius: 4px;
  transition: color 0.18s, background 0.18s;
}

.text-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.block-head .text-btn {
  flex: none;
  white-space: nowrap;
}

/* 我的问题绑定下拉 */
.issue-select {
  flex: 0 1 150px;
  min-width: 0;
  max-width: 150px;
  margin-left: auto;
  margin-right: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink-2);
  font-size: 10px;
  padding: 3px 6px;
  outline: none;
}

.issue-select[hidden] { display: none; }

.issue-select:focus { border-color: var(--accent-line); }

.issue-text {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 2px solid var(--accent);
  font-size: 17px;
  line-height: 1.55;
  font-weight: 600;
  letter-spacing: var(--tracking-title2);
  color: var(--ink);
  text-wrap: pretty;
}

.issue-editor {
  width: 100%;
  margin: 0 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.issue-editor:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.issue-editor::placeholder {
  color: var(--ink-3);
}

.issue-meta {
  margin: 0;
  font-size: 10px;
  color: var(--ink-3);
}

.issue-meta b {
  color: var(--accent);
  font-weight: 600;
}

.case-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.case-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background 0.18s, border-color 0.18s;
}

.case-item:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.case-item img {
  width: 44px;
  height: 34px;
  object-fit: cover;
  border-radius: 4px;
  background: #101114;
  border: 1px solid var(--line);
  flex: none;
}

.case-name {
  font-size: 11px;
  color: var(--ink-2);
  line-height: 1.35;
  min-width: 0;
}

.case-tag {
  display: block;
  font-size: 9px;
  color: var(--ink-3);
  margin-top: 1px;
}

.case-item.is-empty {
  font-size: 10px;
  color: var(--ink-3);
  padding: 8px 6px;
}

.case-remove {
  flex: none;
  margin-left: auto;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  opacity: 0.45;
  transition: color 0.18s, background 0.18s, border-color 0.18s, opacity 0.18s;
}

.case-item:hover .case-remove {
  opacity: 1;
}

.case-remove:hover {
  color: #d06a5c;
  border-color: rgba(208, 106, 92, 0.4);
  background: rgba(208, 106, 92, 0.12);
}

.case-remove .icon {
  width: 11px;
  height: 11px;
}

/* 添加坐具 */

.add-case {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  margin-top: 8px;
  padding: 6px;
  font-size: 10px;
  color: var(--ink-3);
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: transparent;
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}

.add-case:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.add-case .icon {
  width: 11px;
  height: 11px;
}

.block-hint {
  margin: 10px 0 0;
  font-size: 10px;
  line-height: 1.65;
  color: var(--ink-3);
}

.block-hint b {
  color: var(--ink-2);
  font-weight: 600;
}

/* 参考素材 */

.ref-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.ref-card {
  position: relative;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #101114;
  cursor: grab;
  transition: border-color 0.18s, transform 0.18s;
}

.ref-card:hover {
  border-color: var(--accent-line);
  transform: translateY(-1px);
}

.ref-card:active {
  cursor: grabbing;
}

.ref-card img {
  width: 100%;
  height: 54px;
  object-fit: cover;
  display: block;
}

.ref-card figcaption {
  font-size: 9px;
  line-height: 1.35;
  color: var(--ink-3);
  padding: 3px 4px 4px;
  height: 28px;
  overflow: hidden;
}

.ref-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 14px 4px;
  font-size: 10px;
  text-align: center;
  color: var(--ink-3);
  border: 1px dashed var(--line);
  border-radius: 6px;
}

/* ============ 中栏：画布 ============ */

.canvas-pane {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #101114;
  touch-action: none;
}

.canvas-pane .stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

.canvas-pane[data-tool="pen"] .stage,
.canvas-pane[data-tool="line"] .stage,
.canvas-pane[data-tool="arrow"] .stage,
.canvas-pane[data-tool="rect"] .stage,
.canvas-pane[data-tool="ellipse"] .stage,
.canvas-pane[data-tool="triangle"] .stage {
  cursor: crosshair;
}

.canvas-pane[data-tool="text"] .stage {
  cursor: text;
}

.canvas-pane[data-tool="eraser"] .stage {
  cursor: cell;
}

.canvas-pane[data-tool="hand"] .stage,
.canvas-pane.is-panning .stage {
  cursor: grabbing;
}

.canvas-pane[data-tool="image"] .stage {
  cursor: copy;
}

.canvas-bg {
  pointer-events: none;
}

#scene g[data-id] {
  cursor: inherit;
}

.canvas-pane[data-tool="select"] #scene g[data-id] {
  cursor: move;
}

.canvas-pane[data-tool="eraser"] #scene g[data-id] {
  cursor: cell;
}

/* 工具条 */

.tool-rail {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  max-height: calc(100% - 120px);
  overflow-y: auto;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  scrollbar-width: none;
}

.tool-rail::-webkit-scrollbar {
  width: 0;
}

.tool {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: var(--ink-3);
  transition: background 0.16s, color 0.16s;
}

.tool:hover {
  background: var(--panel-2);
  color: var(--ink);
}

.tool.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tool.danger:hover {
  color: var(--danger);
  background: rgba(224, 138, 128, 0.1);
}

.tool:disabled {
  opacity: 0.3;
  cursor: default;
}

.rail-sep {
  height: 1px;
  background: var(--line);
  margin: 3px 4px;
}

.tip {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%) translateX(-3px);
  white-space: nowrap;
  font-size: 10px;
  color: var(--ink);
  background: rgba(28, 29, 33, 0.96);
  border: 1px solid var(--line-strong);
  padding: 3px 7px;
  border-radius: 5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 5;
}

.tool:hover .tip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* 样式停靠 */

.style-dock {
  position: absolute;
  left: 62px;
  bottom: 54px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 10px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-float);
}

.dock-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dock-label {
  width: 22px;
  font-size: 9px;
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
}

.swatches,
.widths {
  display: flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: box-shadow 0.16s, transform 0.16s;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.is-active {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);
}

.width-btn {
  width: 22px;
  height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  transition: background 0.16s;
}

.width-btn:hover {
  background: var(--panel-2);
}

.width-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.width-btn i {
  display: block;
  width: 14px;
  border-radius: 2px;
  background: currentColor;
}

.mini-toggle {
  font-size: 9px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 7px;
  transition: color 0.16s, border-color 0.16s, background 0.16s;
}

.mini-toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

/* 缩放 */

.zoom-controls {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.zoom-controls button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  transition: background 0.16s, color 0.16s;
}

.zoom-controls button:hover {
  background: var(--panel-2);
  color: var(--ink);
}

.zoom-controls .icon {
  width: 14px;
  height: 14px;
}

#zoom-level {
  min-width: 40px;
  text-align: center;
  font-size: 10px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* 选中操作条 */

.selection-bar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 4px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
}

.selection-bar button {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--ink-2);
  padding: 4px 7px;
  border-radius: 5px;
  transition: background 0.16s, color 0.16s;
}

.selection-bar button:hover {
  background: var(--panel-2);
  color: var(--ink);
}

.selection-bar button.danger:hover {
  color: var(--danger);
  background: rgba(224, 138, 128, 0.1);
}

.selection-bar .icon {
  width: 13px;
  height: 13px;
}

.sel-label {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  color: var(--ink-3);
  padding: 0 8px 0 5px;
  border-right: 1px solid var(--line);
  margin-right: 2px;
}

/* 空状态 / 提示 / toast */

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  text-align: center;
  pointer-events: none;
  color: var(--ink-3);
  transition: opacity 0.35s;
  z-index: 5;
}

.empty-state.is-hidden {
  opacity: 0;
}

.empty-mark {
  width: 44px;
  height: 44px;
  margin-bottom: 8px;
  border-radius: 50%;
  border: 1px dashed var(--line-strong);
  display: grid;
  place-items: center;
  color: var(--ink-3);
}

.empty-mark .icon {
  width: 18px;
  height: 18px;
}

.empty-state strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.empty-state p {
  margin: 2px 0 0;
  max-width: 260px;
  font-size: 11px;
  line-height: 1.65;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 8;
  margin: 0;
  padding: 4px 11px;
  font-size: 10px;
  color: var(--ink-3);
  background: rgba(16, 17, 20, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 52px;
  z-index: 30;
  transform: translate(-50%, 8px);
  padding: 7px 14px;
  font-size: 11px;
  color: var(--ink);
  background: #26272c;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  max-width: 70%;
  text-align: center;
}

.toast.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* AI 面板把手 */

.ai-handle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 14;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 11px 5px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-right: none;
  border-radius: 8px 0 0 8px;
  color: var(--ink-3);
  backdrop-filter: blur(10px);
  transition: color 0.18s, background 0.18s;
}

.ai-handle span {
  writing-mode: vertical-rl;
  font-size: 10px;
  letter-spacing: var(--tracking-label-xwide);
}

.ai-handle i {
  display: flex;
  transition: transform 0.28s var(--ease-out);
}

.ai-handle .icon {
  width: 13px;
  height: 13px;
}

.ai-handle:hover {
  color: var(--accent);
  background: var(--panel);
}

.workspace.ai-collapsed .ai-handle i {
  transform: rotate(180deg);
}

/* ============ 右栏：生成式 AI ============ */

.ai-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #17181b;
  border-left: 1px solid var(--line);
  overflow: hidden;
}

.ai-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.ai-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: var(--tracking-title2);
}

.badge {
  flex: none;
  margin-top: 2px;
  padding: 2px 7px;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--warm);
  border: 1px solid rgba(201, 169, 122, 0.35);
  background: rgba(201, 169, 122, 0.08);
  border-radius: 999px;
  white-space: nowrap;
}

.badge.is-live {
  color: #93c9ba;
  border-color: rgba(111, 170, 160, 0.42);
  background: rgba(111, 170, 160, 0.1);
}

.badge.is-live::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 5px;
  border-radius: 50%;
  background: #6faaa0;
  vertical-align: 1px;
}

.ai-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 30px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label {
  font-size: 10px;
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
}

.field-label b {
  color: var(--accent);
  font-weight: 600;
}

.field-actions {
  display: flex;
  gap: 4px;
}

.prompt {
  width: 100%;
  min-height: 72px;
  padding: 9px 10px;
  background: #101114;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.65;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.prompt:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.prompt::placeholder {
  color: var(--ink-3);
  opacity: 0.85;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  padding: 3px 8px;
  font-size: 10px;
  text-align: left;
  color: var(--ink-2);
  background: #191a1e;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: color 0.16s, border-color 0.16s, background 0.16s;
}

.chip:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.ref-upload {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  font-size: 9px;
  color: var(--ink-2);
  background: #191a1e;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.ref-upload:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.ref-upload .icon {
  width: 10px;
  height: 10px;
}

.ref-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.ref-slot {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: #141519;
  color: var(--ink-3);
  font-size: 9px;
}

.ref-slot.is-filled {
  border-style: solid;
  border-color: var(--line);
}

.ref-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ref-slot .ref-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(16, 17, 20, 0.86);
  color: var(--ink-2);
  opacity: 0;
  transition: opacity 0.16s;
}

.ref-slot .ref-x .icon {
  width: 9px;
  height: 9px;
}

.ref-slot:hover .ref-x {
  opacity: 1;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  background: #101114;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.segmented.is-four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field-note {
  font-size: 9px;
  color: var(--ink-3);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 9px;
  line-height: 1.4;
  color: var(--ink-3);
  cursor: pointer;
}

.check-row input {
  flex: none;
  width: 12px;
  height: 12px;
  margin: 0;
  accent-color: var(--accent);
}

.segmented button {
  padding: 5px 0;
  font-size: 10px;
  color: var(--ink-3);
  border-radius: 5px;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}

.segmented button:hover {
  color: var(--ink-2);
}

.segmented button.is-active {
  color: var(--ink);
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.btn.generate {
  width: 100%;
  height: 38px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.btn.generate:hover {
  filter: brightness(1.07);
}

.btn.generate:disabled {
  opacity: 0.6;
  cursor: progress;
  filter: none;
}

.btn.generate .icon {
  width: 14px;
  height: 14px;
}

.gen-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10px;
  color: var(--ink-3);
}

.gen-steps li {
  display: flex;
  align-items: center;
  gap: 7px;
  transition: color 0.2s;
}

.gen-steps li::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.gen-steps li.is-active {
  color: var(--ink-2);
}

.gen-steps li.is-active::before {
  border-color: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.gen-steps li.is-done::before {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.gen-timer {
  margin: -8px 0 0;
  font-size: 9px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.ai-error {
  padding: 8px 10px;
  border: 1px solid rgba(224, 138, 128, 0.4);
  background: rgba(224, 138, 128, 0.08);
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.6;
  color: #e0a49c;
}

.ai-error strong {
  display: block;
  margin-bottom: 2px;
  font-size: 10px;
  color: #e8b4ad;
}

.ai-error span {
  display: block;
  word-break: break-word;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101114;
  animation: rise 0.35s var(--ease-out) both;
}

.result:hover {
  border-color: var(--accent-line);
}

.result > img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  cursor: grab;
}

.result-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 6px 6px;
}

.result-title {
  font-size: 9px;
  line-height: 1.35;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-meta {
  font-size: 8px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
}

.result-actions button,
.result-actions a {
  padding: 2px 0;
  font-size: 8.5px;
  text-align: center;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  transition: color 0.16s, border-color 0.16s, background 0.16s;
}

.result-actions button:hover,
.result-actions a:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.ai-note {
  margin: 4px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 9px;
  line-height: 1.75;
  color: var(--ink-3);
}

/* ============ 弹层 ============ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(10, 11, 13, 0.62);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: min(720px, 92vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #1b1c20;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink);
}

.modal-close {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--ink-3);
}

.modal-close:hover {
  background: var(--panel-2);
  color: var(--ink);
}

.modal-body {
  padding: 14px;
  overflow: auto;
}

.modal-body p {
  margin: 0;
  font-size: 12px;
  line-height: 1.75;
  color: var(--ink-2);
}

.modal-body img {
  width: 100%;
  display: block;
  border-radius: 8px;
  background: #101114;
}

.modal-body .modal-caption {
  margin-top: 10px;
  font-size: 11px;
  color: var(--ink-3);
}

/* 添加坐具选择器 */

.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.picker-card {
  position: relative;
  overflow: hidden;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101114;
  transition: border-color 0.16s, transform 0.16s, opacity 0.16s;
}

.picker-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.picker-card img {
  width: 100%;
  height: 78px;
  object-fit: cover;
  display: block;
}

.picker-card span {
  display: block;
  height: 30px;
  padding: 4px 6px 5px;
  overflow: hidden;
  font-size: 9px;
  line-height: 1.35;
  color: var(--ink-2);
}

.picker-card.is-on {
  opacity: 0.42;
  border-color: var(--accent-line);
  transform: none;
}

.picker-check {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 16px;
  height: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}

.picker-card.is-on .picker-check {
  display: flex;
}

.picker-check .icon {
  width: 10px;
  height: 10px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.modal-foot .btn.danger {
  color: var(--danger);
  border-color: rgba(224, 138, 128, 0.35);
}

.modal-foot .btn.danger:hover {
  background: rgba(224, 138, 128, 0.1);
  border-color: var(--danger);
}

/* ============ 画布内 SVG 元素 ============ */

.sel-outline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}

.sel-handle {
  fill: var(--accent);
  stroke: #0f1013;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.pen-preview {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-editor {
  position: absolute;
  z-index: 16;
  min-width: 60px;
  padding: 2px 4px;
  background: rgba(16, 17, 20, 0.92);
  border: 1px solid var(--accent-line);
  border-radius: 4px;
  color: var(--ink);
  line-height: 1.3;
  outline: none;
  resize: none;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ============ 响应式 ============ */

@media (max-width: 1440px) {
  .workspace {
    grid-template-columns: 348px minmax(0, 1fr) 336px;
  }
  .workspace.ai-collapsed {
    grid-template-columns: 348px minmax(0, 1fr) 0px;
  }
}

@media (max-width: 1220px) {
  .workspace,
  .workspace.ai-collapsed {
    grid-template-columns: 320px minmax(0, 1fr);
  }
  .ai-pane {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 340px;
    z-index: 20;
    display: flex;
    box-shadow: -18px 0 46px rgba(0, 0, 0, 0.5);
    transition: transform 0.28s var(--ease-out);
  }
  .workspace.ai-collapsed .ai-pane {
    display: flex;
    transform: translateX(100%);
  }
  .brand .tag {
    display: none;
  }
}

@media (max-width: 1040px) {
  .stage-nav {
    display: none;
  }
  .save-state {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
