:root {
  --bg: #0f1117;
  --panel: #171b24;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b8cff;
  --danger: #ff5c5c;
  --mouth: #f66;
  --nose: #fc6;
  --eye: #6cf;
  --sidebar-left-w: 280px;
  --sidebar-tools-w: 312px;
  --sidebar-agent-w: 420px;
  --canvas-display-scale: 2;
  --source-editor-font-size: 12px;
  --source-editor-line-height: 1.45;
  --source-editor-padding-y: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.hint { font-size: 11px; color: var(--muted); line-height: 1.4; margin: 6px 0; }

.topbar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  min-height: 0;
}
.brand-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.brand-desc { font-weight: 400; font-size: 13px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: nowrap; }
.top-actions input[type="number"] { width: 68px; }

.doc-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: #12161f;
  min-width: 0;
}
.doc-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  min-width: 0;
}
.doc-field-grow { flex: 1; }
.doc-field input {
  min-width: 0;
  width: 140px;
  padding: 4px 8px;
  font-size: 12px;
}
.doc-field-grow input { width: 100%; flex: 1; }

.tabs {
  flex-shrink: 0;
  display: flex;
  gap: 4px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}
.tab-btn.active { color: var(--text); background: #222838; border-color: var(--border); }

.layout {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns:
    var(--sidebar-left-w)
    minmax(0, 1fr)
    var(--sidebar-tools-w)
    var(--sidebar-agent-w);
  grid-template-rows: minmax(0, 1fr);
}
.layout.agent-collapsed {
  grid-template-columns:
    var(--sidebar-left-w)
    minmax(0, 1fr)
    var(--sidebar-tools-w)
    36px;
}
.layout > * { min-height: 0; }

.sidebar {
  background: var(--panel);
}
.sidebar.left {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px;
  border-right: 1px solid var(--border);
}
.sidebar.left > .panel-tab:not(.hidden) {
  flex: 0 1 auto;
  overflow-y: auto;
  max-height: 42%;
  min-height: 0;
}
.sidebar.right {
  display: contents;
}
.right-pair {
  display: contents;
}
.right-tools {
  grid-column: 3;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  border-left: 1px solid var(--border);
  background: var(--panel);
}
.right-tools .right-section {
  flex-shrink: 0;
  margin-bottom: 10px;
}
.right-tools .right-section:last-child {
  margin-bottom: 0;
}
.right-tools .play-preview {
  margin-bottom: 8px;
}
.right-tools .shape-section .shape-palette {
  max-height: min(240px, 26vh);
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.panel-tab.hidden { display: none; }
.hidden { display: none !important; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-head h2, .sidebar.right h2 { margin: 0 0 8px; font-size: 15px; }
.right-section { margin-bottom: 16px; }
.right-section h2 { font-size: 14px; margin: 0 0 6px; }

.shape-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  overflow-x: hidden;
}
.shape-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #12161f;
  cursor: grab;
  user-select: none;
  transition: border-color .15s, background .15s;
}
.shape-tile:hover { border-color: var(--accent); background: #1a2030; }
.shape-tile.dragging { opacity: 0.55; cursor: grabbing; }
.shape-tile-preview {
  display: block;
  border-radius: 4px;
  image-rendering: pixelated;
}
.shape-tile-label {
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.color-section .hint { margin: 4px 0; }
.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  min-height: 22px;
  transition: transform .12s, border-color .12s;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}
.color-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.color-custom input[type="color"] {
  width: 36px;
  height: 28px;
  padding: 2px;
  cursor: pointer;
}

.prop-color {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 10px;
}
.prop-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.prop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.stage {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 10px 12px;
  gap: 8px;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}
.stage.stage-source-mode {
  padding: 10px 12px;
}
#stage-edit {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  gap: 0;
}
.stage-canvas-block {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: auto;
  padding-bottom: 8px;
}
#stage-edit.hidden { display: none; }
.stage-source {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.stage-source.hidden { display: none; }
.source-find-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: #12161f;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.source-find-bar.hidden { display: none; }
.source-find-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.source-find-label input {
  width: min(320px, 40vw);
  padding: 4px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: #0f131c;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.source-editor-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f131c;
}
.source-line-gutter {
  flex: 0 0 auto;
  overflow: hidden;
  padding: var(--source-editor-padding-y) 10px var(--source-editor-padding-y) 12px;
  background: #0a0d14;
  border-right: 1px solid var(--border);
  user-select: none;
}
.source-line-gutter pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--source-editor-font-size);
  line-height: var(--source-editor-line-height);
  color: var(--muted);
  text-align: right;
}
.source-editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  overflow-y: auto;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--source-editor-font-size);
  line-height: var(--source-editor-line-height);
  padding: var(--source-editor-padding-y) 12px;
  background: #0f131c;
  border: none;
  border-radius: 0;
  color: var(--text);
}
.json-editor-section.hidden { display: none; }
.source-actions { margin-top: 8px; }
.canvas-wrap {
  position: relative;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  background: #111;
  transition: border-color .2s, box-shadow .2s;
  line-height: 0;
}
.marquee-box {
  position: absolute;
  border: 1px dashed var(--accent);
  background: rgba(91, 140, 255, 0.12);
  pointer-events: none;
  z-index: 2;
}
.marquee-box.hidden { display: none; }
.canvas-wrap.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.25), 0 8px 32px rgba(0,0,0,.35);
}
#face-canvas {
  display: block;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.canvas-hint { font-size: 11px; color: var(--muted); margin: 0; text-align: center; }
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
  width: 100%;
  max-width: var(--canvas-display-w, 568px);
  justify-content: center;
}
.toolbar select { min-width: 140px; }
.list-item {
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #12161f;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}
.list-item.active { border-color: var(--accent); background: #1a2540; }
.list-item.base-scene { border-color: #3a4a6a; }

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(420px, 90vw);
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
  background: #2a1a1a;
  border: 1px solid #5a3030;
  color: #ffb4b4;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateX(12px);
  transition: opacity .28s ease, transform .28s ease;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success {
  background: #1a2a1f;
  border-color: #2a5a3a;
  color: #a8e6b8;
}
.toast-error {
  background: #2a1a1a;
  border-color: #5a3030;
  color: #ffb4b4;
}

.layer-lock-hint {
  font-size: 12px;
  color: var(--muted);
  flex: 1;
  min-width: 180px;
}

.frame-timeline {
  flex-shrink: 0;
  width: 100%;
  max-width: var(--canvas-display-w, 568px);
  margin: 0 auto;
  padding: 10px 8px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #12161f;
  align-self: center;
}
.frame-timeline.hidden { display: none; }
.frame-timeline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.frame-timeline-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
.frame-timeline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.frame-timeline-actions input[type="number"] { width: 72px; }

.frame-track {
  display: flex;
  align-items: stretch;
  min-height: 100px;
  padding: 8px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 0;
}

.frame-card {
  position: relative;
  flex-shrink: 0;
  padding: 4px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #0f131c;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.frame-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.25);
}

.frame-card:hover:not(.active) {
  border-color: #4a5878;
}

.frame-thumb {
  display: block;
  width: 88px;
  height: auto;
  image-rendering: pixelated;
  border-radius: 4px;
  background: #111;
}

.frame-label {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 1px 5px;
  border-radius: 999px;
}

.frame-gap {
  position: relative;
  flex-shrink: 0;
  min-width: 32px;
  margin: 8px 0;
  background: repeating-linear-gradient(
    90deg,
    #1a2540 0,
    #1a2540 6px,
    #12161f 6px,
    #12161f 12px
  );
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.frame-gap.hold {
  background: repeating-linear-gradient(
    90deg,
    #2a2030 0,
    #2a2030 6px,
    #1a1520 6px,
    #1a1520 12px
  );
}

.frame-gap-inner {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
  text-align: center;
}

.frame-gap-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.frame-gap-hint {
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
}

.frame-gap-handle {
  position: absolute;
  right: -4px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  background: var(--accent);
  border-radius: 4px;
  opacity: 0.7;
  transition: opacity 0.15s;
  z-index: 2;
}

.frame-gap-handle:hover {
  opacity: 1;
}

.frame-timeline .hint {
  margin: 6px 0 0;
  text-align: center;
}

.play-preview {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #12161f;
}
.play-preview.is-playing {
  border-color: var(--accent);
}
.play-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  margin-bottom: 8px;
}
#play-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}
.play-time {
  margin: 0 0 8px;
  font-size: 11px;
  text-align: center;
}
.play-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #12161f;
  color: var(--muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text); }

.meta-form label { display: block; font-size: 12px; margin-bottom: 8px; }
.meta-form textarea, .meta-form input { width: 100%; margin-top: 4px; }

.json-editor-section {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  overflow: hidden;
}
.json-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.json-editor-head h3 { margin: 0; font-size: 13px; }
.json-editor-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.json-mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.json-editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
}
.json-tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  background: #0f131c;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 4px;
}
.json-tree.hidden { display: none; }
.json-editor.hidden { display: none; }
.json-tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 20px;
  white-space: nowrap;
}
.json-tree-toggle {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
}
.json-tree-toggle:hover { color: var(--text); }
.json-tree-key { color: #9ec5ff; }
.json-tree-value { color: #c5e1a5; }
.json-tree-summary { color: var(--muted); font-size: 10px; }
.json-tree-leaf .json-tree-key { margin-left: 22px; }

.props label.prop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.props label.prop-row .prop-label {
  flex: 0 0 44px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
.props label.prop-row input,
.props label.prop-row select {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  padding: 4px 6px;
  font-size: 12px;
}
.props label:not(.prop-row) { display: block; font-size: 12px; margin-bottom: 8px; }
.props input:not(.prop-row input), .props select:not(.prop-row select) { width: 100%; margin-top: 4px; }
.row { display: flex; gap: 8px; }
.io-row, .preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.preset-row select { flex: 1; min-width: 120px; }

.prop-head { font-weight: 600; margin-bottom: 10px; font-size: 13px; }

.btn {
  border: 1px solid var(--border);
  background: #222838;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.secondary { background: transparent; }
.btn.danger { color: var(--danger); border-color: #5a3030; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
label.inline { font-size: 12px; display: flex; align-items: center; gap: 6px; }

input, select, textarea {
  background: #0f131c;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
}
input:disabled, select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
kbd {
  background: #222;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.status {
  flex-shrink: 0;
  padding: 6px 16px;
  font-size: 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
}
.status.err { color: var(--danger); }

/* Agent 面板（右侧固定列） */
.agent-panel {
  grid-column: 4;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  border: none;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: #141824;
  position: relative;
  overflow: hidden;
}
.agent-panel.collapsed {
  width: 36px;
  min-width: 36px;
}
.agent-panel.collapsed .agent-panel-body,
.agent-panel.collapsed .agent-config-inline,
.agent-panel.collapsed .agent-focus-hint {
  display: none;
}
.agent-resize-handle { display: none; }
.agent-panel.collapsed .agent-panel-head {
  padding: 8px 4px;
  height: 100%;
  border-bottom: none;
}
.agent-panel.collapsed .agent-head-row {
  flex-direction: column;
  height: 100%;
}
.agent-panel.collapsed #agent-panel-toggle {
  writing-mode: vertical-rl;
  padding: 10px 4px;
  flex: 1;
}
.agent-panel-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.agent-head-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.agent-focus-hint {
  font-size: 11px;
  flex: 1;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.agent-config-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.agent-field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.agent-field-label {
  flex: 0 0 38px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}
.agent-field-row input {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  padding: 3px 6px;
}
.agent-config-inline #agent-save-config {
  align-self: flex-end;
  margin-top: 2px;
}
.agent-config-inline #agent-temperature {
  max-width: 56px;
  flex: 0 0 56px;
}
.agent-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.agent-sessions-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--border);
  background: #12161f;
}
.agent-session-list {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 6px;
}
.agent-session-row {
  display: flex;
  flex-shrink: 0;
  gap: 0;
  align-items: stretch;
  max-width: 140px;
}
.agent-session-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: #0f131c;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-session-item.active {
  color: var(--text);
  border-color: var(--accent);
  background: #1a2540;
}
.agent-session-item.running:not(.active) {
  border-color: rgba(91, 140, 255, 0.45);
  color: var(--accent);
}
.agent-session-item.running.active {
  box-shadow: inset 0 -2px 0 var(--accent);
}
.agent-session-del {
  flex: 0 0 22px;
  border: 1px solid var(--border);
  border-left: none;
  border-bottom: none;
  border-radius: 0 6px 0 0;
  background: #0f131c;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}
.agent-session-row:has(.agent-session-item.active) .agent-session-del {
  border-color: var(--accent);
  background: #1a2540;
}
.agent-session-del:hover { color: var(--danger); }
#agent-new-session {
  flex-shrink: 0;
  width: 28px;
  padding: 4px 0;
  margin-bottom: 6px;
}
.agent-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.agent-messages {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  margin-bottom: 0;
  padding: 8px 8px 0;
}
.agent-empty { margin: 12px 0; font-size: 12px; }
.agent-msg {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #12161f;
}
.agent-msg-user { border-color: #334466; }
.agent-msg-assistant { border-color: #2a4030; }
.agent-msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  background: #1a2030;
  color: var(--muted);
}
.agent-msg-label {
  flex-shrink: 0;
}
.agent-msg-copy {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.agent-msg-copy:hover {
  color: var(--text);
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.06);
}
.agent-msg-head-live .agent-msg-copy {
  margin-left: 0;
}
.agent-msg-head-live .agent-msg-abort {
  margin-left: auto;
}
.agent-msg-head-live {
  display: flex;
  align-items: center;
  gap: 8px;
}
.agent-msg-title {
  flex-shrink: 0;
}
.agent-msg-running {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  flex-shrink: 0;
}
.agent-msg-abort {
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--danger);
  border-color: rgba(255, 92, 92, 0.55);
  background: rgba(255, 92, 92, 0.08);
  padding: 1px 7px;
}
.agent-msg-abort:hover {
  background: rgba(255, 92, 92, 0.18);
  border-color: var(--danger);
}
.agent-msg-streaming {
  border-color: rgba(91, 140, 255, 0.45);
}
.agent-msg-body pre {
  margin: 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  max-height: 240px;
  overflow: auto;
}
.agent-msg-actions {
  padding: 6px 10px 8px;
  border-top: 1px solid var(--border);
}
.agent-msg-pending {
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.agent-msg-streaming pre::after {
  content: "▋";
  color: var(--accent);
  animation: agent-blink 0.9s step-end infinite;
}
@keyframes agent-blink {
  50% { opacity: 0; }
}
.agent-tool-events {
  padding: 6px 10px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.agent-tool-events-live { border-top: none; padding-top: 0; }
.agent-tool-event {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.agent-tool-event.error { color: var(--danger); }
.agent-compose {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  padding: 8px;
  border-top: 1px solid var(--border);
  background: #12161f;
}
.agent-compose textarea {
  width: 100%;
  resize: vertical;
  min-height: 100px;
  max-height: 240px;
  font-size: 12px;
  line-height: 1.45;
}
.agent-compose .btn { width: 100%; }

@media (max-width: 1200px) {
  :root {
    --sidebar-left-w: 260px;
    --sidebar-tools-w: 286px;
    --sidebar-agent-w: 360px;
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .layout.agent-collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar.left { grid-column: 1; max-height: 40vh; }
  .stage { grid-column: 1; }
  .right-tools,
  .agent-panel { display: none; }
  .doc-bar { flex-wrap: wrap; }
}

/* 项目选择器 */
.project-picker {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 10, 16, 0.88);
  backdrop-filter: blur(4px);
}
.project-picker.hidden { display: none; }
body.project-picker-open { overflow: hidden; }
.project-picker-dialog {
  width: min(620px, 100%);
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.project-picker-head {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.project-picker-head h2 {
  margin: 0 0 6px;
  font-size: 18px;
}
.project-picker-head p {
  margin: 0;
  font-size: 13px;
}
.project-picker-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.project-section-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
}
.project-section .project-list {
  max-height: min(220px, 32vh);
}
.project-list {
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.project-card-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.project-card-readonly {
  border-color: #3a4a6a;
}
.doc-file-label {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.doc-readonly-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #5a4030;
  background: rgba(255, 180, 80, 0.12);
  color: #ffc896;
  white-space: nowrap;
}
.save-as-dialog {
  width: min(420px, 100%);
}
.save-as-form {
  padding: 12px 16px;
}
.save-as-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}
.save-as-field input {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
body.save-as-open { overflow: hidden; }
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.project-card-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.project-card-row .project-card {
  flex: 1;
  min-width: 0;
}
.project-card-del {
  flex-shrink: 0;
  width: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #12161f;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.project-card-del:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.project-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #12161f;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.project-card:hover {
  border-color: var(--accent);
  background: #1a2030;
}
.project-card-name {
  font-size: 14px;
  font-weight: 600;
}
.project-card-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}
.project-card-file {
  font-size: 11px;
}
.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}
.project-loading,
.project-empty {
  margin: 12px 0;
  font-size: 13px;
  text-align: center;
}
.project-empty.err { color: var(--danger); }
