:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1d2330; --muted: #5b6475; --line: #d6dae2;
  --accent: #1f5fbf; --accent-ink: #fff; --danger: #b3261e; --focus: #ffbf47;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 10; background: var(--panel); padding: 4px 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; }
.whoami { margin-left: auto; color: var(--muted); }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
body:has(#view-canvas:not([hidden])) { overflow: hidden; background: #f5f5f7; }
body:has(#view-canvas:not([hidden])) .topbar { display: none; }
body:has(#view-canvas:not([hidden])) main { max-width: none; margin: 0; padding: 0; }
body:has(#view-canvas:not([hidden])) > .status { position: fixed; z-index: 12; top: 66px; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: min(90vw, 520px); min-height: 0; padding: 7px 12px; border: 1px solid #e0e1e5;
  border-radius: 7px; background: rgba(255,255,255,.96); box-shadow: 0 4px 14px rgba(20,24,32,.1); }
h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }

button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; }
button[type="submit"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  width: 100%; background: #fff; color: var(--ink); }
label { display: block; color: var(--muted); font-size: 0.9rem; }
label > input, label > select, label > textarea { margin-top: 2px; color: var(--ink); }

.status { min-height: 1.5em; padding: 4px 16px; }
.status:empty { display: none; }
.status.error { background: #fdecea; color: var(--danger); }
.status.ok { color: #1e6b35; }
.notice { background: #fff8e1; border: 1px solid #f0d58a; padding: 8px 12px; border-radius: 6px; }

.card-form { display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px; margin-bottom: 14px; }
.narrow { max-width: 360px; }
.inline-form { display: flex; gap: 8px; align-items: end; margin-bottom: 10px; flex-wrap: wrap; }
.grow { flex: 1 1 200px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.cloud-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-top: 24px; }
.cloud-columns > section { min-width: 0; }
.cloud-columns > section:last-child { grid-column: 1 / -1; }
.check-label { display: flex; align-items: flex-start; gap: 8px; color: var(--ink); }
.check-label input { flex: 0 0 auto; width: auto; margin: 4px 0 0; }
#video-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
#credit-balance { font-size: 1.4rem; }
.list { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
.list li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.list li .name { flex: 1 1 160px; overflow-wrap: anywhere; }
.list li .meta { color: var(--muted); font-size: 0.85rem; }
.list.compact li { padding: 4px 8px; }
.empty { color: var(--muted); }

.canvas-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.canvas-head h1 { margin: 0; overflow-wrap: anywhere; }
.canvas-head-actions { margin-left: auto; display: flex; gap: 5px; align-items: center; }
#view-canvas { position: fixed; z-index: 2; inset: 0; max-width: none; padding: 0; overflow: hidden; background: #f7f8fa; }
#view-canvas:not([hidden]) { min-height: 100vh; }
.canvas-head { position: absolute; z-index: 5; top: 0; left: 0; right: 0; min-height: 56px; padding: 8px 14px;
  flex-wrap: nowrap; border-bottom: 1px solid #dfe2e7; background: rgba(255,255,255,.97); }
.canvas-head #canvas-back { flex: 0 0 auto; padding: 5px 9px; border-color: transparent; background: transparent; font-size: .86rem; }
.canvas-head #canvas-back:hover { background: #f1f2f4; }
.canvas-head h1 { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .94rem; }
.canvas-head-actions button { height: 32px; padding: 4px 9px; font-size: .8rem; }
.canvas-head-actions #canvas-inspector-toggle { width: 34px; padding: 4px; overflow: hidden; font-size: 0; }
.canvas-head-actions #canvas-inspector-toggle::before { content: ""; display: block; width: 15px; height: 13px; margin: auto;
  border: 1px solid currentColor; border-radius: 2px; background: linear-gradient(90deg,currentColor 0 3px,transparent 3px); opacity: .8; }
.canvas-layout { position: absolute; top: 56px; right: 0; bottom: 0; left: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) 352px; margin: 0; min-height: 0; overflow: hidden; }
#view-canvas.inspector-collapsed .canvas-layout { grid-template-columns: minmax(0, 1fr); }
#view-canvas.inspector-collapsed #canvas-inspector { display: none; }
.board-stage { position: relative; grid-column: 1; grid-row: 1; min-width: 0; min-height: 0; overflow: hidden; }
.board-wrap { position: absolute; inset: 0; overflow: auto; background: #f7f8fa; border: 0; border-radius: 0;
  min-height: 0; max-height: none; background-image: radial-gradient(#c8cdd5 1px, transparent 1px); background-size: 24px 24px;
  cursor: default; touch-action: none; scrollbar-width: none; }
.board-wrap::-webkit-scrollbar { display: none; }
.board-wrap[data-tool="pan"] { cursor: grab; }
.board-wrap.panning { cursor: grabbing; }
.board-wrap.drag-over { outline: 2px dashed #2477a5; outline-offset: -8px; }
.board-wrap.drag-over::after { content: "释放以添加素材"; position: absolute; z-index: 8; top: 50%; left: 50%;
  transform: translate(-50%, -50%); padding: 8px 12px; border: 1px solid #c7dbe5; border-radius: 6px;
  background: rgba(255,255,255,.97); color: #17648b; box-shadow: 0 4px 14px rgba(26,34,48,.1); pointer-events: none; }
.board-frame { position: relative; min-width: 0; min-height: 0; }
.board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.links line { stroke: #657389; stroke-width: 1.8; }
.links marker path { fill: #657389; }
.links .link-preview { stroke: #2674a8; stroke-width: 2; stroke-dasharray: 5 5; }
#arrow-preview path { fill: #2674a8; }
.node { position: absolute; display: flex; flex-direction: column; gap: 5px; padding: 10px;
  background: #fff; border: 1px solid #d8dce3; border-radius: 7px; overflow: visible;
  box-shadow: 0 4px 15px rgba(26,34,48,.09); touch-action: none; transition: box-shadow .14s ease, border-color .14s ease; }
.node:hover { box-shadow: 0 8px 22px rgba(26,34,48,.15); }
.node.selected { outline: 2px solid #2477a5; outline-offset: 2px; }
.node.copy-preview { outline: 2px dashed #b06b20; outline-offset: 3px; box-shadow: 0 4px 12px rgba(35, 42, 52, .16); }
.node.link-source { outline: 2px solid #c37b1d; outline-offset: 3px; }
.node[data-draggable="true"] { cursor: grab; }
.node[data-draggable="true"]:active { cursor: grabbing; }
.node:focus-within { border-color: #2477a5; }
.node .kind { font-size: .72rem; color: #687385; }
.node .asset-provenance {
  position: absolute;
  z-index: 4;
  top: 8px;
  right: 8px;
  max-width: calc(100% - 72px);
  padding: 3px 6px;
  border: 1px solid #e5c36d;
  border-radius: 4px;
  background: #fff8df;
  color: #735817;
  font-size: .68rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.node .title { font-weight: 650; overflow-wrap: anywhere; }
.node .body { white-space: pre-wrap; overflow: auto; flex: 1; overflow-wrap: anywhere; }
.node .placeholder { flex: 1; display: grid; align-content: center; justify-items: center; gap: 8px; text-align: center; color: #657080;
  border: 1px dashed #c9cfd8; border-radius: 6px; font-size: .85rem; padding: 8px; }
.node .node-attach-action { min-height: 30px; padding: 4px 9px; border-color: #cadbe4; background: #f4f8fa; color: #17648b; font-size: .8rem; }
/* ---- Node floating toolbar (matches Route A smart-node-floating-menu) ---- */
.node .actions {
  position: absolute; z-index: 18; top: -38px; left: 50%;
  transform: translateX(-50%) translateY(3px);
  display: inline-flex; align-items: center; gap: 2px;
  width: max-content; max-width: min(96vw, 640px); height: 32px;
  padding: 3px 5px;
  border: 1px solid rgba(216,220,227,.9); border-radius: 11px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 10px 28px rgba(26,34,48,.14);
  backdrop-filter: blur(14px);
  opacity: 0; pointer-events: none; white-space: nowrap; cursor: default;
  transition: opacity .13s ease, transform .13s ease; }
.node:hover .actions, .node.selected .actions { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
body.card-drag .actions { opacity: 0 !important; pointer-events: none !important; }
/* Primary action buttons */
.node .actions > .action-btn {
  height: 24px; min-width: 32px; padding: 0 8px;
  border: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: transparent; color: #5a6475; font-size: 10px; line-height: 1; font-weight: 400;
  cursor: pointer; white-space: nowrap;
  transition: background .12s ease, color .12s ease, transform .1s ease; }
.node .actions > .action-btn:hover { background: #f0f3f7; color: #1a2230; transform: translateY(-1px); }
.node .actions > .action-btn:disabled { opacity: .36; cursor: not-allowed; transform: none; }
.node .actions > .action-btn svg, .node .actions > .action-btn i { width: 12px; height: 12px; stroke-width: 2.1; flex: 0 0 auto; }
/* More overflow toggle */
.node .actions > .action-more-toggle {
  height: 24px; min-width: 24px; padding: 0;
  border: 0; border-left: 1px solid rgba(216,220,227,.8);
  border-radius: 0 8px 8px 0 !important;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: #7a8599; cursor: pointer;
  transition: background .12s ease, color .12s ease; }
.node .actions > .action-more-toggle:hover { background: #f0f3f7; color: #1a2230; }
/* Overflow popover menu */
.node .actions-popover {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 30;
  display: grid; grid-template-columns: minmax(0,1fr); gap: 2px;
  width: min(240px, calc(100vw - 32px)); max-height: min(400px, 55vh); overflow: auto;
  padding: 5px; border: 1px solid #d8dce3; border-radius: 10px;
  background: #fff; box-shadow: 0 12px 30px rgba(26,34,48,.14); }
.node .actions-popover[hidden] { display: none !important; }
.node .actions-popover .action-btn {
  width: 100%; min-height: 30px; justify-content: flex-start;
  padding: 0 9px; border-radius: 7px;
  background: transparent; color: #1a2230; font-size: 11px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  border: 0; white-space: nowrap;
  transition: background .1s ease; }
.node .actions-popover .action-btn:hover { background: #f0f3f7; }
.node .actions-popover .action-btn span { overflow: hidden; text-overflow: ellipsis; }
.node .actions-popover .action-btn svg, .node .actions-popover .action-btn i { width: 13px; height: 13px; stroke-width: 2; flex: 0 0 auto; }
/* Danger actions */
.node .actions .action-btn.danger, .node .actions-popover .action-btn.danger { color: #c0392b; }
.node .actions .action-btn.danger:hover, .node .actions-popover .action-btn.danger:hover { background: #fdf0ef; }

dialog { max-width: min(90vw, 900px); border: 1px solid var(--line); border-radius: 8px; padding: 0; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; overflow-wrap: anywhere; }
#preview-body { padding: 14px; }
#preview-body img, #preview-body video { max-width: 100%; max-height: 70vh; display: block; }
#preview-body pre { white-space: pre-wrap; max-height: 70vh; overflow: auto; }

.side { grid-column: 2; grid-row: 1; position: relative; min-width: 0; max-height: none; height: 100%;
  display: flex; flex-direction: column; overflow: hidden; background: #fff; border: 0; border-left: 1px solid #dfe2e7; }
@media (min-width: 901px) {
  .canvas-layout { grid-template-columns: minmax(0, 1fr); }
  #canvas-inspector { position: absolute; z-index: 5; top: 8px; right: 8px; bottom: 8px; width: min(352px, 34vw);
    height: auto; border: 1px solid #dfe2e7; border-radius: 7px; box-shadow: 0 7px 24px rgba(26,34,48,.14); }
}
#inspector-tabs { display: flex; flex: 0 0 auto; flex-wrap: nowrap; gap: 3px; padding: 8px; overflow-x: auto;
  border-bottom: 1px solid #e2e5e9; background: #fff; }
#inspector-tabs button { flex: 0 0 auto; padding: 5px 8px; border-color: transparent; }
#inspector-tabs button.active { color: #17648b; border-color: #d6e6ef; background: #edf5f8; }
.inspector-content { flex: 1; min-height: 0; padding: 15px; overflow: auto; }
.side .card-form { background: transparent; border: 0; border-radius: 0; padding: 0; margin-bottom: 16px; }
.inspector-details { border-top: 1px solid #e4e7ec; padding-top: 8px; }
.inspector-details summary { color: #485568; cursor: pointer; font-size: .86rem; }
.inspector-details .grid4 { margin-top: 10px; }
.panel-empty { min-height: 180px; display: grid; align-content: center; justify-items: start; gap: 12px; color: #687385; }
.panel-empty p { margin: 0; }
.history-compare-choice { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 6px; color: #475569; }
.history-compare-choice input { width: auto; margin: 0; }
.generation-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 14px; }
.generation-compare-column { min-width: 0; border-right: 1px solid #e0e4ea; padding-right: 14px; }
.generation-compare-column:last-child { border-right: 0; padding-right: 0; }
.generation-compare-prompt { white-space: pre-wrap; overflow-wrap: anywhere; }
.generation-compare-parameters { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: auto; background: #f4f6f8; padding: 8px; }
.generation-compare-media { display: grid; gap: 8px; }
.generation-compare-media img { display: block; width: 100%; height: auto; object-fit: contain; background: #f2f4f6; border: 1px solid #e1e5e9; }
[data-image-options], [data-video-options] { display: grid; gap: 9px; }
.reference-image-field { grid-column: 1 / -1; }
.reference-image-field select { min-height: 92px; }
#canvas-empty-state { position: absolute; z-index: 1; inset: 0; display: grid; place-items: center; pointer-events: none; }
#canvas-empty-state button { pointer-events: auto; padding: 9px 13px; border-color: #ccd4dd; box-shadow: 0 5px 18px rgba(26,34,48,.08); }
#canvas-empty-state svg { width: 16px; height: 16px; vertical-align: middle; margin-right: 5px; }
#canvas-controls { position: absolute; z-index: 3; left: 12px; bottom: 12px; display: flex;
  gap: 3px; align-items: center; padding: 4px; background: rgba(255,255,255,.97);
  border: 1px solid #d8dce3; border-radius: 7px; box-shadow: 0 3px 12px rgba(26,34,48,.08); }
#canvas-controls button { width: 32px; height: 32px; padding: 5px; }
#canvas-zoom-level { min-width: 44px; text-align: center; color: #596579; font-size: .8rem; font-variant-numeric: tabular-nums; }
#canvas-tool-rail { position: absolute; z-index: 4; top: 50%; left: 12px; transform: translateY(-50%); display: grid;
  align-content: start; gap: 3px; padding: 4px; background: rgba(255,255,255,.98); border: 1px solid #d8dce3;
  border-radius: 7px; box-shadow: 0 4px 14px rgba(26,34,48,.1); }
#canvas-tool-rail button { display: grid; place-items: center; width: 36px; height: 36px; min-height: 36px; padding: 8px;
  border: 0; border-radius: 5px; background: transparent; color: #515e70; }
#canvas-tool-rail button:hover, #canvas-controls button:hover { background: #f0f3f6; color: #232d3c; }
#canvas-tool-rail button.active { background: #e9f2f6; color: #17648b; }
#canvas-tool-rail button:disabled { opacity: .38; cursor: not-allowed; }
#canvas-tool-rail svg, #canvas-controls svg { display: block; width: 19px; height: 19px; }
.canvas-head-actions [data-icon] { display: inline-flex; align-items: center; gap: 6px; }
.canvas-head-actions [data-icon] svg { display: block; width: 15px; height: 15px; flex: 0 0 auto; }
.canvas-head-actions [data-icon] { justify-content: center; width: 34px; min-width: 34px; padding: 5px; overflow: hidden; font-size: 0; }
.canvas-head-actions [data-icon] svg { width: 17px; height: 17px; }
.canvas-add-node { position: relative; }
.canvas-add-menu { position: absolute; z-index: 6; top: 0; left: calc(100% + 9px); width: 168px; padding: 5px;
  display: grid; gap: 2px; background: #fff; border: 1px solid #d9dee5; border-radius: 7px; box-shadow: 0 8px 24px rgba(26,34,48,.16); }
.canvas-add-menu button { display: flex !important; flex-direction: row; justify-content: flex-start; gap: 9px; width: 100% !important; height: auto; min-height: 36px;
  padding: 6px 8px !important; text-align: left; font-size: .86rem; }
.canvas-add-menu button:hover { background: #f1f5f7; }
.canvas-add-menu svg { width: 17px; height: 17px; }
.node[data-kind="image"], .node[data-kind="video"] { padding: 0; }
.node[data-kind="image"] .kind, .node[data-kind="video"] .kind { position: absolute; z-index: 2; top: 8px; left: 8px;
  padding: 3px 7px; border-radius: 4px; color: #30333a; background: rgba(255,255,255,.9); font-size: 11px; }
.node[data-kind="image"] .title, .node[data-kind="video"] .title { display: none; }
.node[data-kind="image"] .media-linked, .node[data-kind="video"] .media-linked { position: absolute; inset: 0; width: 100%; height: 100%;
  background: #eceef1; }
.node[data-kind="image"] .actions, .node[data-kind="video"] .actions { position: absolute; z-index: 3; right: 7px; bottom: 7px; }
.node[data-kind="image"] .media-linked img, .node[data-kind="video"] .media-linked video { display: block; width: 100%; height: 100%;
  max-width: none; max-height: none; object-fit: cover; }
.node[data-kind="audio"] .media-linked { align-content: center; padding: 12px; }
.node[data-kind="audio"] .media-linked audio { width: 100%; }
.canvas-head-actions button, #canvas-controls button { white-space: nowrap; }
.canvas-context-menu { position: fixed; z-index: 20; display: grid; gap: 2px; width: 224px; max-height: min(70vh, 540px);
  overflow: auto; padding: 5px; border: 1px solid #d8dce3; border-radius: 7px; background: #fff;
  box-shadow: 0 9px 26px rgba(20,24,32,.18); }
.canvas-context-menu button { width: 100%; min-height: 36px; padding: 6px 9px; border: 0; border-radius: 4px;
  background: transparent; font-size: .84rem; text-align: left; }
.canvas-context-menu button:hover, .canvas-context-menu button:focus-visible { background: #edf3f6; color: #17648b; }
.canvas-generation-floating { position: absolute; z-index: 10; overflow: auto; overscroll-behavior: contain;
  padding: 12px; border: 1px solid #d8dce3; border-radius: 12px; background: #fff;
  box-shadow: 0 8px 24px rgba(26,34,48,.14); }
.canvas-composer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.canvas-composer-head h2 { margin: 0; font-size: .95rem; }
.canvas-generation-floating .canvas-generation { padding: 8px 0 0; border: 0; margin: 0; }
.canvas-generation-floating .canvas-generation > h2 { display: none; }
.canvas-image-tools { width: min(920px, calc(100vw - 24px)); max-height: min(90vh, 880px); }
.image-tools-body { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr); gap: 14px; padding: 14px; }
.image-tools-preview { min-width: 0; min-height: 280px; max-height: 62vh; display: grid; grid-template-rows: minmax(0, 1fr) auto;
  place-items: center; gap: 7px; padding: 10px; overflow: hidden; border: 1px solid #dce1e6; border-radius: 6px; background: #f3f5f6; }
.image-tools-preview img { max-width: 100%; max-height: 56vh; object-fit: contain; }
.image-tools-workspace { display: grid; align-content: start; gap: 10px; min-width: 0; }
.image-tools-form { margin: 0; padding: 12px; }
.image-tools-form h3 { margin: 0; font-size: .92rem; }
.image-crop-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.image-crop-grid label { min-width: 0; }
.image-tools-form button[type=submit] { width: 100%; }
.canvas-shortcuts-dialog { width: min(420px, calc(100vw - 24px)); }
.canvas-navigator { width: min(460px, calc(100vw - 24px)); }
.canvas-navigator > label { display: block; margin: 12px 14px 4px; }
.canvas-navigator > input { display: block; width: calc(100% - 28px); margin: 0 14px; }
.canvas-navigator > p { margin: 8px 14px; }
.canvas-navigator > ul { max-height: min(45vh, 420px); margin: 0 14px 14px; overflow: auto; }
.canvas-navigator li button { display: grid; gap: 3px; width: 100%; text-align: left; overflow-wrap: anywhere; }
.canvas-navigator li button:focus-visible { outline-offset: -2px; }
.canvas-shortcut-list { display: grid; gap: 0; padding: 6px 18px 18px; margin: 0; }
.canvas-shortcut-list > div { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 12px; align-items: center;
  padding: 9px 0; border-bottom: 1px solid #e3e6ea; }
.canvas-shortcut-list > div:last-child { border-bottom: 0; }
.canvas-shortcut-list dt { width: fit-content; padding: 3px 7px; border: 1px solid #d7dce2; border-radius: 4px; background: #f5f6f7;
  color: #3b4656; font-size: .78rem; font-weight: 600; }
.canvas-shortcut-list dd { margin: 0; color: #586579; font-size: .86rem; }

@media (max-width: 900px) {
  .columns, .cloud-columns { grid-template-columns: 1fr; }
  .cloud-columns > section:last-child { grid-column: auto; }
  .canvas-head { min-height: 52px; padding: 7px 9px; gap: 5px; }
  .canvas-head #canvas-back { max-width: 38px; height: 32px; overflow: hidden; padding: 4px; font-size: 0; }
  .canvas-head #canvas-back::first-letter { font-size: 18px; }
  .canvas-head h1 { font-size: .9rem; }
  .canvas-head-actions { flex: 0 0 auto; gap: 3px; }
  .canvas-head-actions button { height: 32px; padding: 4px 7px; font-size: .72rem; }
  .canvas-head-actions #canvas-inspector-toggle { width: 32px; }
  .canvas-layout { top: 52px; display: block; }
  .board-stage { position: absolute; inset: 0; }
  #canvas-tool-rail { top: 12px; left: 9px; transform: none; }
  #canvas-tool-rail button { width: 34px; height: 34px; min-height: 34px; }
  .side { position: absolute; z-index: 4; right: 8px; bottom: 8px; left: 8px; top: auto; width: auto;
    height: min(42vh, 350px); border: 1px solid #dfe2e7; border-radius: 7px; box-shadow: 0 6px 18px rgba(26,34,48,.12); }
  #canvas-controls { left: 8px; bottom: calc(min(42vh, 350px) + 16px); }
  #view-canvas.inspector-collapsed #canvas-controls { bottom: 8px; }
  #canvas-controls button { width: 30px; height: 30px; }
  #storyboard .inline-form { align-items: center; }
}
@media (max-width: 430px) {
  .canvas-head { padding: 5px; gap: 3px; }
  .canvas-head-actions button { padding: 4px 5px; }
  #canvas-organize, #canvas-save-template, #canvas-import-json, #canvas-export-json { display: grid; place-items: center; width: 32px; min-width: 32px;
    padding: 5px; overflow: hidden; font-size: 0; }
  .canvas-head-actions [data-icon] svg { width: 16px; height: 16px; }
  .side { right: 6px; left: 6px; bottom: 6px; height: min(40vh, 320px); }
  #canvas-controls { bottom: calc(min(40vh, 320px) + 12px); }
  #view-canvas.inspector-collapsed #canvas-controls { bottom: 6px; }
  #inspector-tabs { padding: 6px; gap: 1px; }
  #inspector-tabs button { padding: 5px 6px; font-size: .78rem; }
  .inspector-content { padding: 11px; }
  .canvas-add-menu { top: 0; left: calc(100% + 7px); width: 152px; }
  .generation-compare { grid-template-columns: 1fr; }
  .generation-compare-column { border-right: 0; border-bottom: 1px solid #e0e4ea; padding: 0 0 14px; }
  .generation-compare-column:last-child { border-bottom: 0; padding-bottom: 0; }
  .image-tools-body { grid-template-columns: 1fr; }
  .image-tools-preview { min-height: 180px; max-height: 38vh; }
  .image-tools-preview img { max-height: 32vh; }
}
@media (hover: none) {
  .node.selected .actions { opacity: 1; pointer-events: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.media-linked {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #eef2f6;
  color: var(--muted);
  font-size: 0.85rem;
}
.media-linked img, .media-linked video, .media-linked audio {
  max-width: 100%;
  max-height: 100%;
}
#storyboard-list .meta {
  flex: 0 1 100%;
}
.storyboard-shot-duration {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.storyboard-shot-duration label {
  display: flex;
  gap: 8px;
  align-items: center;
}
.storyboard-shot-duration input { width: 5rem; }

.comment-item { align-items: flex-start !important; }
.comment-content { flex: 1 1 100%; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-meta { display: flex; flex: 1 1 160px; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: .82rem; }
.comment-meta time { font-variant-numeric: tabular-nums; }

/* Canvas management */
.indicator {
  opacity: 0.7;
  font-size: 0.9em;
}

.list li.archived {
  opacity: 0.6;
}

.list li.archived .name {
  text-decoration: line-through;
}

.list li.shared .danger {
  display: none;
}

/* View toggle buttons */
.inline-form button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.inline-form button:not(.active) {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

/* Node toolbar: floats above the selected node, matching Route A style */
.node .actions {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px 6px;
  background: var(--surface, #1a1a2e);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 5;
  white-space: nowrap;
  margin-bottom: 4px;
}
.node.selected .actions,
.node:hover .actions {
  display: flex;
}
.node .actions button {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
}
.node .actions button.danger {
  color: #e74c3c;
}
/* For unselected nodes, show a compact hover toolbar */
.node:not(.selected) .actions {
  opacity: 0.7;
}

/* Multi-select marquee */
.marquee-select {
  position: absolute; z-index: 50; pointer-events: none;
  border: 1.5px dashed #2477a5; background: rgba(36,119,165,.08);
  border-radius: 4px;
}

.node.selected { outline: 2px solid #2477a5; outline-offset: 2px; }

/* Canvas group frames */
.canvas-group { position: absolute; z-index: 1; pointer-events: none;
  border: 2px dashed rgba(36,119,165,.5); border-radius: 12px;
  background: rgba(36,119,165,.04); }
.canvas-group-label { position: absolute; top: -20px; left: 8px; pointer-events: auto;
  font-size: .72rem; color: #2477a5; font-weight: 600;
  background: #fff; padding: 1px 6px; border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.group-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.group-item .group-title { font-weight: 600; flex: 1; }
.group-item button { min-height: 26px; padding: 2px 8px; font-size: .75rem; }
.video-merge-dialog { width: min(860px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.video-merge-panel { padding: 14px; display: grid; gap: 12px; }
.video-merge-previews { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.video-merge-previews section { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.video-merge-panel h3, .video-merge-panel p { margin: 0; }
.video-merge-previews video { width: 100%; max-height: 35vh; margin-top: 8px; background: #10151c; }
.video-merge-previews p { min-height: 62px; display: grid; align-items: center; color: #657080; }
.video-merge-previews [hidden] { display: none; }
.video-merge-panel select { max-width: 100%; }
.video-merge-list { margin: 0; padding-inline-start: 28px; max-height: 220px; overflow: auto; }
.video-merge-list li { padding-block: 4px; overflow-wrap: anywhere; }
.video-merge-list button { margin-inline-start: 8px; }
.video-merge-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.video-merge-note { font-size: .85rem; color: #657080; }
@media (max-width: 550px) { .video-merge-previews { grid-template-columns: 1fr; } }
