:root {
  color-scheme: light;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --text-caption: .75rem;
  --text-ui: .875rem;
  --text-body: 1rem;
  --text-heading: 1.25rem;
  --weight-regular: 400;
  --weight-semibold: 600;
  --weight-bold: 700;
  --bg: oklch(97.5% 0.004 25);
  --surface: oklch(100% 0 0);
  --surface-muted: oklch(96% 0.007 25);
  --surface-hover: oklch(94.5% 0.012 25);
  --surface-selected: oklch(94% 0.028 25);
  --line: oklch(87% 0.012 25);
  --line-strong: oklch(76% 0.02 25);
  --text: oklch(24% 0.016 25);
  --muted: oklch(43% 0.018 25);
  --subtle: oklch(51% 0.014 25);
  --accent: oklch(50% 0.185 25);
  --accent-hover: oklch(44% 0.175 25);
  --accent-soft: oklch(94% 0.035 25);
  --asset-progress: oklch(53% 0.14 240);
  --asset-progress-strong: oklch(44% 0.13 240);
  --success: oklch(40% 0.12 150);
  --success-soft: oklch(95% 0.025 150);
  --warning: oklch(43% 0.11 75);
  --warning-soft: oklch(95% 0.04 75);
  --danger-soft: oklch(95% 0.035 25);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --focus: oklch(57% 0.18 25);
  --topbar-height: 60px;
  --tabs-height: 52px;
  --z-dialog: 40;
  --z-toast: 50;
  --z-lightbox: 55;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overscroll-behavior-x: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  font-kerning: normal;
}

body {
  display: grid;
  grid-template-rows: var(--topbar-height) var(--tabs-height) minmax(0, 1fr);
  overflow: hidden;
}

button,
input,
textarea { font: inherit; }

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 180ms cubic-bezier(.22, 1, .36, 1), border-color 180ms cubic-bezier(.22, 1, .36, 1), color 180ms cubic-bezier(.22, 1, .36, 1), transform 120ms ease-out;
}

button:hover { color: var(--text); }
button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .52; transform: none; }
button:focus { outline: none; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand { min-width: 0; display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-size: var(--text-ui);
  font-weight: var(--weight-bold);
  letter-spacing: -.01em;
}
.brand h1 { min-width: 0; margin: 0; overflow: hidden; font-size: var(--text-heading); line-height: 1.2; font-weight: var(--weight-bold); text-overflow: ellipsis; white-space: nowrap; }

.topbar-actions { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.topbar-link {
  min-height: 34px;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-ui);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  white-space: nowrap;
}
.topbar-link:hover { border-color: var(--line-strong); background: var(--surface-hover); }

.connection {
  min-height: 34px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: var(--text-ui);
  font-weight: var(--weight-semibold);
}
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.connection.ready .connection-dot { background: var(--success); }
.connection.error .connection-dot { background: var(--accent); }

.tabs {
  padding: 5px 18px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a { min-height: 40px; padding: 7px 15px; display: inline-flex; align-items: center; flex: 0 0 auto; border-radius: var(--radius-sm); color: var(--text); font-size: var(--text-ui); font-weight: var(--weight-semibold); text-decoration: none; }
.tabs a:hover { background: var(--surface-hover); }
.tabs a.active { background: var(--accent-soft); color: var(--accent-hover); }

.app-shell,
.view { min-width: 0; min-height: 0; }

.story-view { height: 100%; display: grid; grid-template-columns: 360px minmax(0, 1fr); }
.navigation-pane,
.asset-navigation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: var(--surface-muted);
}
.pane-heading {
  min-height: 68px;
  padding: 12px 14px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.pane-heading > div { width: 100%; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pane-heading strong { font-size: var(--text-body); font-weight: var(--weight-bold); }
.pane-heading span { color: var(--muted); font-size: var(--text-caption); }
.story-progress { width: 100%; margin-top: 7px; }
.story-progress-copy { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.story-progress-copy span { overflow: hidden; color: var(--muted); font-size: var(--text-caption); text-overflow: ellipsis; white-space: nowrap; }
.story-progress-copy strong { flex: 0 0 auto; color: var(--accent-hover); font-size: var(--text-caption); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }
.story-progress-track { height: 8px; margin-top: 6px; overflow: hidden; border-radius: 4px; background: var(--line); }
.story-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms cubic-bezier(.22, 1, .36, 1);
}
.asset-progress .story-progress-copy strong { color: var(--asset-progress-strong); }
.asset-progress .story-progress-track span { background: var(--asset-progress); }
.story-task-filter {
  min-height: 34px;
  margin-top: 7px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.story-task-filter input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.pane-heading .story-task-filter span { color: var(--text); font-weight: var(--weight-semibold); }
.compact-action { min-height: 32px; padding: 4px 7px; border-color: var(--line); background: var(--surface); font-size: var(--text-caption); font-weight: var(--weight-semibold); }

.story-tree { min-height: 0; padding: 10px; overflow-y: auto; scrollbar-gutter: stable; }
.story-arc + .story-arc { margin-top: 8px; }
.tree-button { width: 100%; min-height: 40px; padding: 7px 8px; display: flex; align-items: center; gap: 7px; text-align: left; }
.tree-button:hover { background: var(--surface-hover); }
.tree-button .chevron { flex: 0 0 auto; width: 14px; color: var(--subtle); font-size: var(--text-caption); }
.tree-button .label { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-button .count { flex: 0 0 auto; color: var(--subtle); font-size: var(--text-caption); font-variant-numeric: tabular-nums; }
.arc-button { color: var(--text); font-size: var(--text-ui); font-weight: var(--weight-bold); }
.chapter-group { margin-left: 12px; }
.chapter-button { color: var(--text); font-size: var(--text-ui); font-weight: var(--weight-semibold); }
.story-node-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
}
.story-node-row.in-branch { margin-left: 12px; }
.node-button { padding-left: 29px; color: var(--muted); font-size: var(--text-ui); }
.node-button.active { background: var(--surface-selected); color: var(--accent-hover); }
.story-node-row.in-branch .node-button { padding-left: 17px; }
.story-node-row .tree-button .count { font-size: var(--text-caption); white-space: nowrap; }
.story-branch-header {
  min-height: 30px;
  margin: 5px 4px 2px 14px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid var(--line-strong);
}
.story-branch-index {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: var(--text-caption);
  font-weight: var(--weight-bold);
}
.story-branch-status { flex: 0 0 auto; margin-left: auto; color: var(--success); font-size: var(--text-caption); }
.story-task-empty { margin: 14px 8px; color: var(--muted); font-size: var(--text-ui); line-height: 1.5; }
.story-start-badge {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--success-soft);
  color: var(--success);
  font-size: var(--text-caption);
  font-weight: var(--weight-bold);
  line-height: 1.25;
}
.story-node-actions {
  display: grid;
  gap: 3px;
  padding: 2px 0;
}
.story-start-action {
  min-height: 30px;
  margin-right: 4px;
  padding: 3px 7px;
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--accent-hover);
  font-size: var(--text-caption);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}
.story-start-action:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); }

.content-pane { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--surface); }
.content-toolbar {
  min-height: 58px;
  padding: 7px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}
.toolbar-copy { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.toolbar-copy h2 { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-heading); line-height: 1.25; font-weight: var(--weight-bold); }
.toolbar-copy p { flex: 0 0 auto; margin: 0; color: var(--muted); font-size: var(--text-ui); white-space: nowrap; }
.button { min-height: 42px; padding: 8px 13px; font-size: var(--text-ui); font-weight: var(--weight-bold); white-space: nowrap; }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button.secondary:hover { border-color: var(--line-strong); background: var(--surface-hover); }

.story-lines { min-height: 0; padding: 0 26px 60px; overflow-y: auto; scrollbar-gutter: stable; }
.story-line {
  --scene-height: 148px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 21px 4px;
  display: grid;
  grid-template-columns: 36px minmax(340px, 1fr) 230px;
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  content-visibility: auto;
  contain-intrinsic-size: 192px;
}
.story-line.changed { background: var(--warning-soft); }
.story-line.linked-target { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.line-number { padding-top: 3px; color: var(--subtle); font-size: var(--text-caption); font-variant-numeric: tabular-nums; text-align: right; }
.line-copy { min-width: 0; }
.line-heading { min-height: 32px; margin-bottom: 7px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.line-heading strong { font-size: var(--text-ui); line-height: 1.4; font-weight: var(--weight-bold); }
.speaker-input {
  width: min(180px, 48%);
  height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-ui);
  font-weight: var(--weight-semibold);
}
.speaker-input:focus { border-color: var(--accent); }
.save-record {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-caption);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-record.pending { color: var(--warning); font-weight: var(--weight-bold); }
.save-record.unprotected { color: var(--accent-hover); }
.line-copy textarea {
  width: 100%;
  height: var(--scene-height);
  min-height: var(--scene-height);
  padding: 10px 11px;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-body);
  line-height: 1.55;
}
.line-copy textarea:focus { border-color: var(--accent); }
.draft-conflict {
  margin-top: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--text);
}
.draft-conflict strong { font-size: var(--text-ui); font-weight: var(--weight-bold); }
.draft-conflict p { max-width: 72ch; margin: 5px 0 0; font-size: var(--text-ui); line-height: 1.45; overflow-wrap: anywhere; }
.draft-conflict-actions { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 7px; }
.draft-conflict-actions .compact-action { background: var(--surface); color: var(--text); }
.original-copy { margin-top: 7px; }
.original-copy summary { width: max-content; cursor: pointer; color: var(--muted); font-size: var(--text-ui); }
.original-copy p { max-width: 72ch; margin: 7px 0 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-muted); font-size: var(--text-body); line-height: 1.5; }
.scene-column { min-width: 0; padding-top: 39px; }
.scene-frame { position: relative; width: 100%; height: var(--scene-height); overflow: hidden; border-radius: var(--radius-sm); background: oklch(18% .01 25); }
.scene-frame.expandable { cursor: zoom-in; }
.scene-frame.expandable:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.scene-background,
.scene-layer,
.scene-character { position: absolute; display: block; max-width: none; }
.scene-background { inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene-layer { inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.scene-character { z-index: 2; object-fit: contain; object-position: center bottom; }
.scene-character.centered { left: 50%; bottom: 0; height: 92%; transform: translateX(-50%); }
.scene-character.reflected { transform: scaleX(-1); }
.scene-character.centered.reflected { transform: translateX(-50%) scaleX(-1); }
.scene-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; color: oklch(77% .01 25); font-size: var(--text-caption); text-align: center; }

.scene-lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  background: oklch(12% .01 25 / .78);
  cursor: zoom-out;
}
.scene-lightbox:focus { outline: none; }
.scene-lightbox-content {
  width: min(960px, calc(100vw - 48px), calc((100vh - 164px) * 1.5));
  display: grid;
  gap: 12px;
  cursor: default;
}
.scene-lightbox-frame {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  border-radius: var(--radius-md);
  cursor: default;
  box-shadow: 0 4px 8px oklch(8% .01 25 / .38);
}
.scene-asset-strip {
  min-height: 58px;
  padding-bottom: 30px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.scene-asset-thumb {
  position: relative;
  width: 76px;
  height: 58px;
  min-height: 58px;
  padding: 3px;
  flex: 0 0 auto;
  border-color: oklch(74% .01 25 / .7);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.scene-asset-thumb:hover,
.scene-asset-thumb:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.scene-asset-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.scene-asset-thumb::after {
  content: attr(data-filename);
  position: absolute;
  left: 50%;
  top: calc(100% + 7px);
  z-index: 1;
  max-width: min(320px, calc(100vw - 32px));
  padding: 5px 7px;
  border-radius: 4px;
  background: oklch(18% .01 25);
  color: white;
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  text-overflow: ellipsis;
  transform: translate(-50%, 3px);
  transition: opacity 150ms cubic-bezier(.22, 1, .36, 1), transform 150ms cubic-bezier(.22, 1, .36, 1);
  white-space: nowrap;
}
.scene-asset-thumb:hover::after,
.scene-asset-thumb:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }

.skeleton-list { max-width: 1120px; margin: 0 auto; padding-top: 20px; }
.skeleton-list div { height: 176px; margin-bottom: 12px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-muted), var(--surface-hover), var(--surface-muted)); background-size: 220% 100%; animation: skeleton 1.2s ease-in-out infinite; }
@keyframes skeleton { to { background-position: -220% 0; } }

.asset-view { height: 100%; display: grid; grid-template-columns: 400px minmax(0, 1fr); }
.asset-navigation { grid-template-rows: auto minmax(0, 1fr); }
.asset-search { padding: 14px; border-bottom: 1px solid var(--line); }
.asset-search label { display: block; margin-bottom: 7px; color: var(--text); font-size: var(--text-ui); font-weight: var(--weight-semibold); }
.asset-search input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.asset-search input::placeholder { color: var(--muted); }
.asset-search-meta { min-height: 30px; margin-top: 7px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.asset-search-meta > span { color: var(--muted); font-size: var(--text-caption); text-align: right; }
.asset-search .asset-filter-toggle { min-width: 0; display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: var(--text-caption); font-weight: var(--weight-semibold); cursor: pointer; }
.asset-search .asset-filter-toggle input { width: 16px; min-height: 16px; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; accent-color: var(--accent); }
.asset-filter-toggle span { white-space: nowrap; }
.asset-list { min-height: 0; padding: 8px; overflow-y: auto; scrollbar-gutter: stable; }
.asset-folder + .asset-folder { margin-top: 2px; }
.asset-folder-button {
  width: 100%;
  min-height: 38px;
  padding: 5px 8px 5px calc(8px + var(--asset-depth, 0) * 14px);
  display: flex;
  align-items: center;
  gap: 7px;
  text-align: left;
}
.asset-folder-button:hover { background: var(--surface-hover); }
.asset-folder-chevron { width: 12px; flex: 0 0 auto; color: var(--subtle); font-size: var(--text-caption); }
.asset-folder-icon {
  position: relative;
  flex: 0 0 auto;
  width: 18px;
  height: 14px;
  overflow: hidden;
  color: transparent;
  font-size: 0;
}
.asset-folder-icon::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 1px;
  width: 16px;
  height: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--surface);
}
.asset-folder-icon::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 1px;
  width: 7px;
  height: 4px;
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  background: var(--surface);
}
.asset-folder-name { min-width: 0; flex: 1; overflow: hidden; color: var(--text); font-size: var(--text-ui); font-weight: var(--weight-semibold); text-overflow: ellipsis; white-space: nowrap; }
.asset-folder-count { flex: 0 0 auto; color: var(--subtle); font-size: var(--text-caption); font-variant-numeric: tabular-nums; }
.asset-item {
  width: 100%;
  min-height: 64px;
  padding: 6px 8px 6px calc(8px + var(--asset-depth, 0) * 14px);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}
.asset-item:hover { background: var(--surface-hover); }
.asset-item.active { background: var(--surface-selected); color: var(--accent-hover); }
.asset-thumbnail {
  width: 64px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.asset-thumbnail img { display: block; width: 100%; height: 100%; object-fit: contain; }
.asset-item-copy { min-width: 0; flex: 1; }
.asset-item strong,
.asset-item-copy > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-item strong { color: inherit; font-size: var(--text-ui); font-weight: var(--weight-semibold); }
.asset-item-copy > span { margin-top: 3px; color: var(--subtle); font-size: var(--text-caption); }
.asset-list-empty { margin: 0; padding: 18px 10px; color: var(--muted); font-size: var(--text-ui); text-align: center; }
.asset-preview { min-width: 0; min-height: 0; padding: 28px; overflow-y: auto; background: var(--surface); }
.empty-state { min-height: 100%; display: grid; place-content: center; justify-items: center; padding: 30px; color: var(--muted); text-align: center; }
.empty-mark { width: 62px; height: 62px; display: grid; place-items: center; margin-bottom: 13px; border-radius: var(--radius-lg); background: var(--surface-muted); color: var(--accent-hover); font-size: var(--text-body); font-weight: var(--weight-bold); }
.empty-state h2 { margin: 0; color: var(--text); font-size: var(--text-heading); font-weight: var(--weight-bold); }
.empty-state p { max-width: 48ch; margin: 7px 0 0; font-size: var(--text-body); line-height: 1.5; }
.asset-detail { max-width: 940px; margin: 0 auto; }
.asset-detail-header { margin-bottom: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.asset-detail-header h2 { margin: 0; overflow-wrap: anywhere; font-size: var(--text-heading); font-weight: var(--weight-bold); }
.asset-detail-header p { margin: 6px 0 0; color: var(--muted); font-size: var(--text-caption); overflow-wrap: anywhere; }
.asset-actions { flex: 0 0 auto; display: flex; gap: 7px; }
.asset-stage { min-height: 420px; display: grid; place-items: center; padding: 20px; border-radius: var(--radius-md); background: var(--surface-muted); }
.asset-stage img,
.asset-stage video { display: block; max-width: 100%; max-height: min(62vh, 650px); object-fit: contain; }
.asset-stage audio { width: min(560px, 100%); }
.asset-facts { margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: var(--text-ui); }

.art-overview-view { height: 100%; min-height: 0; overflow-y: auto; background: var(--surface); }
.art-overview-grid { padding: 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); align-content: start; gap: 16px; }
.art-overview-card { min-width: 0; }
.art-overview-image { aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-muted); }
.art-overview-image img { display: block; width: 100%; height: 100%; object-fit: contain; }
.art-overview-filename { margin-top: 7px; color: var(--muted); font-size: var(--text-caption); line-height: 1.35; overflow-wrap: anywhere; }
.art-overview-upload-meta { margin-top: 4px; color: var(--subtle); font-size: var(--text-caption); line-height: 1.35; }
.art-overview-upload-meta.modified { color: var(--text); }
.art-overview-chapters { min-height: 24px; margin-top: 7px; display: flex; flex-wrap: wrap; gap: 4px; color: var(--muted); font-size: var(--text-caption); line-height: 1.35; }
.art-overview-chapter-link { padding: 3px 6px; border-radius: 4px; background: var(--surface-muted); color: inherit; text-decoration: none; }
.art-overview-chapter-link:hover { background: var(--accent-soft); color: var(--accent-hover); }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: var(--z-toast); width: max-content; max-width: min(420px, calc(100vw - 36px)); padding: 11px 13px; border-radius: var(--radius-md); background: var(--text); color: white; font-size: var(--text-ui); line-height: 1.45; box-shadow: 0 4px 8px oklch(20% .01 25 / .18); }
.toast.error { background: var(--accent-hover); }
.toast.success { background: var(--success); }
.toast.working { min-width: min(320px, calc(100vw - 36px)); background: oklch(29% .025 25); }
.toast-copy { display: block; overflow-wrap: anywhere; }
.toast-progress { position: relative; display: block; height: 5px; margin-top: 9px; overflow: hidden; border-radius: 3px; background: oklch(100% 0 0 / .22); }
.toast-progress-fill { display: block; width: 34%; height: 100%; border-radius: inherit; background: white; transition: width 180ms cubic-bezier(.22, 1, .36, 1); }
.toast-progress.indeterminate .toast-progress-fill { animation: toast-progress 1.15s cubic-bezier(.65, 0, .35, 1) infinite; }

@keyframes toast-progress {
  from { transform: translateX(-120%); }
  to { transform: translateX(320%); }
}

@media (prefers-reduced-motion: reduce) {
  .toast-progress.indeterminate .toast-progress-fill { width: 100%; animation: none; opacity: .72; }
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: var(--bg);
}
.login-panel {
  width: min(390px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.login-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 11px;
  background: var(--accent);
  color: white;
  font-size: var(--text-ui);
  font-weight: var(--weight-bold);
}
.login-panel h2 { margin: 0; font-size: var(--text-heading); font-weight: var(--weight-bold); }
.login-panel > p { margin: 8px 0 20px; color: var(--muted); font-size: var(--text-body); line-height: 1.5; }
.login-panel label { display: block; margin: 13px 0 6px; color: var(--text); font-size: var(--text-ui); font-weight: var(--weight-semibold); }
.login-panel input { width: 100%; min-height: 44px; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.login-panel .button { width: 100%; margin-top: 18px; }
.login-panel .login-error { margin: 10px 0 0; padding: 9px 10px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--accent-hover); font-size: var(--text-ui); }

.dialog { z-index: var(--z-dialog); width: min(480px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--text); }
.dialog::backdrop { background: oklch(12% .01 25 / .46); }
.dialog form { padding: 22px; }
.dialog h2 { margin: 0; font-size: var(--text-heading); font-weight: var(--weight-bold); }
.dialog p { margin: 10px 0 0; color: var(--muted); font-size: var(--text-body); line-height: 1.55; white-space: pre-line; }
.dialog-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 860px) {
  body { height: auto; min-height: 100%; display: block; overflow: auto; }
  .topbar { min-height: var(--topbar-height); position: sticky; top: 0; z-index: 10; }
  .tabs { min-height: var(--tabs-height); position: sticky; top: var(--topbar-height); z-index: 9; }
  .app-shell { min-height: calc(100vh - var(--topbar-height) - var(--tabs-height)); }
  .story-view,
  .asset-view { height: auto; min-height: inherit; display: block; }
  .navigation-pane,
  .asset-navigation { border-right: 0; border-bottom: 1px solid var(--line); }
  .navigation-pane.collapsed .story-tree { display: none; }
  .story-tree,
  .asset-list { max-height: none; overflow: visible; }
  .content-pane { display: block; }
  .content-toolbar { position: sticky; top: calc(var(--topbar-height) + var(--tabs-height)); z-index: 8; background: var(--surface); }
  .story-lines,
  .asset-preview { overflow: visible; }
  .story-line { grid-template-columns: 30px minmax(0, 1fr); }
  .scene-column { grid-column: 2; padding-top: 0; }
  .asset-stage { min-height: 280px; }
}

@media (max-width: 560px) {
  :root { --topbar-height: 66px; --tabs-height: 48px; }
  .topbar { padding: 9px 12px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand h1 { font-size: var(--text-body); }
  .connection { padding-inline: 8px; }
  .connection span:last-child { display: none; }
  .topbar-link { padding-inline: 8px; font-size: var(--text-caption); }
  #trustDeviceButton,
  #logoutButton { display: none; }
  .tabs { padding-inline: 8px; }
  .tabs a { min-height: 38px; padding-inline: 11px; font-size: var(--text-ui); }
  .content-toolbar { padding: 10px 12px; align-items: flex-start; }
  .toolbar-copy { display: block; }
  .toolbar-copy p { display: none; }
  .story-lines { padding: 0 10px 42px; }
  .story-line { --scene-height: 180px; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; padding-block: 18px; }
  .line-number { font-size: var(--text-caption); }
  .scene-column { grid-column: 2; padding-top: 0; }
  .scene-lightbox { padding: 12px; }
  .scene-lightbox-content { width: min(960px, calc(100vw - 24px), calc((100vh - 144px) * 1.5)); }
  .asset-preview { padding: 18px 12px 42px; }
  .asset-detail-header { display: block; }
  .asset-actions { margin-top: 12px; }
  .art-overview-grid { padding: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
