/* The editor is a workspace: conversation, viewer, library and timeline. */
:root.scenvy-editor {
  --editor-shell: hsl(var(--scenvy-ui-sidebar-background));
  --editor-panel: hsl(var(--scenvy-ui-card));
  --editor-well: hsl(var(--scenvy-ui-background));
  --editor-line: hsl(var(--scenvy-ui-border));
  --editor-text: #202020;
  --editor-subtle: #5e626d;
  --editor-chat-width: clamp(250px, 25vw, 340px);
  --editor-library-width: clamp(190px, 17vw, 235px);
  --editor-accent: var(--ui-blue-color);
  --editor-icon-size: 16px;
  --editor-tool-rail: 40px;
  --label-w: 150px;
  --ruler-h: 42px;
}
:root.scenvy-editor.dark {
  --editor-shell: #000;
  --editor-panel: #111;
  --editor-well: #1c1c1c;
  --editor-line: #2b2b2b;
  --editor-text: #ededed;
  --editor-subtle: #9b9b9b;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

body.editor-ui:not(.editor-embedded) .editor:not(.hidden) {
  display: grid;
  grid-template-columns: var(--editor-chat-width) var(--editor-library-width) minmax(0, 1fr);
  grid-template-rows: 40px minmax(190px, 1fr) minmax(225px, 39%);
  grid-template-areas: "chat header header" "chat preview preview" "chat library timeline";
  gap: 3px;
  width: 100%;
  height: 100dvh;
  padding: 4px;
  background: var(--editor-shell);
  color: var(--editor-text);
  overflow: hidden;
}
body.editor-ui:not(.editor-embedded) .editor.chat-collapsed {
  grid-template-columns: var(--editor-library-width) minmax(0, 1fr);
  grid-template-areas: "header header" "preview preview" "library timeline";
}
body.editor-ui:not(.editor-embedded) .editor.chat-collapsed .direction-panel { display: none; }
body.editor-ui:not(.editor-embedded) .workspace { display: contents; }
body.editor-ui:not(.editor-embedded) .topbar { grid-area: header; }
body.editor-ui:not(.editor-embedded) .stage { grid-area: preview; }
body.editor-ui:not(.editor-embedded) .panel-left { grid-area: library; }
body.editor-ui:not(.editor-embedded) .timeline-shell { grid-area: timeline; }
body.editor-ui:not(.editor-embedded) .direction-panel { grid-area: chat; }

.scenvy-editor body.editor-ui .direction-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--editor-line);
  border-radius: 12px 4px 4px 12px;
  background: var(--editor-panel);
  color: var(--editor-text);
}
.direction-header { display: flex; min-height: 48px; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--editor-line); }
.direction-heading { display: flex; min-width: 0; align-items: center; gap: 9px; }
.direction-heading img { width: 27px; height: 27px; }
.direction-heading div { display: grid; gap: 2px; }
.direction-heading strong { color: var(--editor-text); font-size: var(--ui-type-control); font-weight: 650; }
.direction-heading span { color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.scenvy-editor .direction-messages { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 14px; overflow-y: auto; padding: 18px 14px; }
.direction-empty { margin: auto 10px; color: var(--editor-subtle); font-size: var(--ui-type-control); line-height: 1.5; text-align: center; }
.direction-message { max-width: 92%; color: var(--editor-text); font-size: var(--ui-type-reading); line-height: var(--ui-chat-line-height); overflow-wrap: anywhere; }
.direction-message p { margin: 0; white-space: pre-wrap; }
.direction-message strong { display: block; margin-bottom: 5px; font-size: var(--ui-type-caption); }
.direction-message small { display: block; margin-top: 6px; color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.direction-message.from-user { width: 100%; max-width: 100%; padding: 0; background: transparent; }
.direction-message.from-user strong { display: none; }
.direction-message.is-pending { opacity: .65; }
.direction-message.is-failed { gap: 6px; }
.direction-message.is-failed > div { outline: 1px solid #c96a65; }
.direction-message.is-failed button { height: var(--ui-control-size); flex: none; padding-inline: 10px; border: 0; background: transparent; color: var(--editor-accent); font-size: var(--ui-type-caption); cursor: pointer; }
.direction-form { flex: none; padding: 8px 12px 12px; }
.direction-composer { border: 1px solid var(--editor-line); border-radius: 12px; background: var(--editor-well); }
.scenvy-editor .direction-composer textarea { display: block; width: 100%; min-height: 86px; resize: vertical; padding: 12px; border: 0; outline: 0; background: transparent; color: var(--editor-text); font: inherit; font-size: var(--ui-type-reading); line-height: var(--ui-prompt-line-height); box-shadow: none; }
.direction-composer textarea::placeholder { color: var(--editor-subtle); }
.direction-composer-bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; padding: 5px 8px 8px; }
.direction-context { display: flex; min-width: 0; align-items: flex-start; gap: 5px; color: var(--editor-subtle); font-size: var(--ui-type-caption); line-height: 1.3; }
.direction-context input { width: 13px; height: 13px; flex: none; margin: 0; accent-color: var(--editor-accent); }
.direction-send { display: grid; width: 32px; height: 32px; flex: none; place-items: center; border: 0; border-radius: 9px; background: var(--editor-text); color: var(--editor-panel); cursor: pointer; }
.direction-send svg { width: 16px; height: 16px; }
.direction-send:disabled { opacity: .4; cursor: default; }
.direction-note { margin: 7px 2px 0; color: var(--editor-subtle); font-size: var(--ui-type-caption); line-height: 1.4; }
#direction-status, #direction-job { color: var(--editor-subtle); font-size: var(--ui-type-caption); }
#direction-job:not(:empty) { padding: 0 14px 6px; }
#direction-status:not(:empty) { padding: 7px 2px 0; }

.scenvy-editor body.editor-ui:not(.editor-embedded) .topbar {
  height: auto; min-height: 0; gap: 6px; padding: 0 9px; border: 0; border-radius: 4px; background: var(--editor-panel); box-shadow: none;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-brand { flex: 1 1 0; min-width: 0; gap: 7px; }
.scenvy-editor .topbar-brand .mark { width: 22px; height: 22px; }
.scenvy-editor .video-title { color: var(--editor-text); font-size: var(--ui-type-control); }
.scenvy-editor .save-status { color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-center { flex: none; gap: 2px; padding: 0; border: 0; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-right { flex: 0 0 auto; align-items: center; gap: 3px; }
.scenvy-editor .topbar-right .btn-primary { padding: 0 12px; border-radius: 6px; font-size: var(--ui-type-caption); }
.scenvy-editor .history-label { max-width: 95px; font-size: var(--ui-type-caption); }
.scenvy-editor .editor-icon-button, .scenvy-editor .tool-btn, .scenvy-editor .topbar-center .btn-icon {
  display: inline-grid; place-items: center; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--editor-subtle); line-height: 1; cursor: pointer;
}
.editor-icon-button svg, .tool-btn svg { width: 15px; height: 15px; }
.editor-icon-button:hover, .tool-btn:hover { background: color-mix(in srgb, var(--editor-text) 8%, transparent); color: var(--editor-text); }
.editor-icon-button:disabled, .tool-btn:disabled { opacity: .32; cursor: default; }
.scenvy-editor .tool-btn.active { background: var(--editor-accent); color: #fff; }
.editor-menu { position: relative; }
#btn-library { display: none; }
.editor-menu > summary { list-style: none; font-size: 19px; font-weight: 700; }
.editor-menu > summary::-webkit-details-marker { display: none; }
.editor-menu-items { position: absolute; z-index: 40; top: calc(100% + 4px); right: 0; display: grid; min-width: 205px; gap: 2px; padding: 5px; border: 1px solid var(--editor-line); border-radius: 8px; background: var(--editor-panel); box-shadow: 0 12px 32px #0004; }
.editor-menu-items button, .scenvy-editor .editor-menu-items .btn { display: flex; width: 100%; min-height: var(--ui-control-size); height: auto; align-items: center; justify-content: space-between; padding: 7px 9px; border: 0; border-radius: 5px; background: transparent; color: var(--editor-text); font: inherit; font-size: var(--ui-type-caption); text-align: left; white-space: nowrap; cursor: pointer; }
.editor-menu-items button:hover:not(:disabled) { background: color-mix(in srgb, var(--editor-text) 8%, transparent); }
.editor-menu-items button:disabled { opacity: .4; cursor: default; }
.editor-menu-items kbd { margin-left: 20px; color: var(--editor-subtle); font: inherit; }

.scenvy-editor body.editor-ui:not(.editor-embedded) .stage { min-width: 0; min-height: 0; gap: 0; overflow: hidden; border: 0; border-radius: 4px; background: var(--editor-panel); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .stage-heading { min-height: 28px; height: 28px; padding: 0 10px; border: 0; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .stage-heading strong { font-size: var(--ui-type-caption); font-weight: 500; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .stage-state { color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-frame { min-height: 0; flex: 1; padding: 0; border: 0; border-radius: 0; background: var(--editor-panel); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-viewport { border-radius: 0; box-shadow: none; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-empty { background: var(--editor-well); color: var(--editor-text); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-bar { display: grid; min-height: 33px; grid-template-columns: minmax(0, 1fr) auto minmax(max-content, 1fr); align-items: center; gap: 6px; padding: 0 8px; border-top: 1px solid var(--editor-line); }
.scenvy-editor .carrier-info { overflow: hidden; color: var(--editor-subtle); font-size: var(--ui-type-caption); text-overflow: ellipsis; white-space: nowrap; }
.transport-controls { display: flex; align-items: center; justify-content: center; }
.scenvy-editor .play-control { color: var(--editor-text); }
.scenvy-editor .preview-controls { justify-content: flex-end; gap: 3px; color: var(--editor-subtle); }
.scenvy-editor .preview-controls select { padding: 0 4px; color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.scenvy-editor .playhead-time { color: var(--editor-text); font-size: var(--ui-type-caption); }

.scenvy-editor body.editor-ui:not(.editor-embedded) .panel-left { min-width: 0; min-height: 0; border: 0; border-radius: 4px; background: var(--editor-panel); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .panel-titlebar { min-height: 32px; padding: 6px 10px; border-bottom: 1px solid var(--editor-line); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .panel-titlebar strong { color: var(--editor-text); font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs { width: 100%; margin: 0; padding: 0 3px; gap: 0; border-bottom: 1px solid var(--editor-line); border-radius: 0; background: transparent; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs button { min-width: 0; height: 31px; padding: 0 3px; border-radius: 0; color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs button.active { background: transparent; color: var(--editor-text); box-shadow: inset 0 -2px var(--editor-accent); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-body { min-height: 0; flex: 1; overflow: auto; padding: 7px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-search { margin: 0 0 7px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-search input { width: 100%; height: 30px; min-height: 30px; padding: 0 8px; border: 1px solid var(--editor-line); border-radius: 5px; background: var(--editor-well); color: var(--editor-text); font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-card { position: relative; display: flex; min-width: 0; flex-direction: column; align-items: stretch; gap: 3px; padding: 0; overflow: hidden; border: 0; border-radius: 5px; background: var(--editor-well); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-thumb { width: 100%; min-width: 0; height: auto; aspect-ratio: 16 / 9; border-radius: 4px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-meta { min-width: 0; padding: 0 5px 3px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-title { font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-sub { display: none; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-actions { display: flex; flex-wrap: wrap; gap: 1px; padding: 0 4px 4px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-actions .btn { min-height: 24px; height: auto; padding: 3px 5px; font-size: var(--ui-type-caption); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-upload { font-size: var(--ui-type-caption); }

.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-shell { position: relative; display: flex; min-width: 0; min-height: 0; height: auto; flex-direction: column; padding-left: 36px; overflow: visible; border: 0; border-radius: 4px; background: var(--editor-panel); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-toolbar { display: flex; min-height: 34px; height: 34px; flex: none; gap: 5px; padding: 0 7px; border-bottom: 1px solid var(--editor-line); background: var(--editor-panel); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-title { min-width: 0; margin-right: 5px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-title strong { color: var(--editor-text); font-size: var(--ui-type-caption); font-weight: 500; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .tl-tools { position: absolute; z-index: 4; top: 0; bottom: 0; left: 0; display: flex; width: 36px; flex-direction: column; align-items: center; gap: 2px; padding: 3px 2px; overflow-y: auto; border-right: 1px solid var(--editor-line); border-radius: 4px 0 0 4px; background: var(--editor-well); }
.timeline-actions { display: flex; align-items: center; }
.timeline-menu .editor-menu-items { top: auto; right: auto; bottom: calc(100% + 4px); left: 0; max-height: 45vh; overflow-y: auto; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .tl-zoom { min-width: 0; gap: 4px; margin-left: auto; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .tl-zoom input { width: clamp(48px, 7vw, 105px); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline { position: relative; min-height: 0; overflow: hidden; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .track-labels, .scenvy-editor body.editor-ui:not(.editor-embedded) .ruler { background: var(--editor-panel); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .track-label, .scenvy-editor body.editor-ui:not(.editor-embedded) .track-row { border-color: var(--editor-line); }
.scenvy-editor .track-label { gap: 7px; padding: 0 8px; color: var(--editor-subtle); font-size: var(--ui-type-caption); }
.scenvy-editor .track-label .track-code { flex: none; padding: 3px 4px; border-radius: 3px; background: #175989; color: #e5f5ff; font-size: var(--ui-type-micro); }
.scenvy-editor .track-label .track-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scenvy-editor .track-label .track-lock { width: 13px; height: 13px; margin-left: auto; color: var(--editor-subtle); }
.scenvy-editor .clip { top: 2px; bottom: 2px; border-width: 1px; border-radius: 4px; }
.scenvy-editor .clip-carrier { --clip-color: #5aa7dc; background-color: #275378; }
.scenvy-editor .clip-module { --clip-color: #8ab8d7; background-color: #365772; }
.scenvy-editor .clip-audio, .scenvy-editor .clip-voice { --clip-color: #73c5b5; background-color: #276f68; }
.scenvy-editor .clip-body { align-items: flex-start; gap: 3px; padding: 2px 5px; background: linear-gradient(#0008, transparent 55%); }
.scenvy-editor .clip-label, .scenvy-editor .clip-sub { color: #f5f5f5; font-size: var(--ui-type-micro); }
.scenvy-editor .playhead, .scenvy-editor .playhead-cap { background: #238fdc; }
.scenvy-editor .timeline.roll .clip, .scenvy-editor .timeline.slide .clip, .scenvy-editor .timeline.slip .clip { cursor: col-resize; }
.scenvy-editor .slip-indicator { position: absolute; z-index: 3; top: 1px; left: 2px; padding: 2px 4px; border-radius: 3px; background: #121212; color: white; font-size: var(--ui-type-micro); white-space: nowrap; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .panel-right { position: absolute; z-index: 20; top: 48px; right: 8px; bottom: calc(39% + 8px); width: min(310px, calc(100vw - 24px)); min-height: 150px; border: 1px solid var(--editor-line); border-radius: 8px; background: var(--editor-panel); box-shadow: 0 10px 30px #0003; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .editor:not(.inspector-open) .panel-right { display: none; }
.scenvy-editor .inspector { color: var(--editor-text); }

/* Embedded clients retain their configurable panel order and feature flags. */
body.editor-embedded .direction-panel { display: none !important; }
body.editor-embedded .editor-icon-button { color: var(--muted-fg); }
body.editor-embedded .timeline-actions, body.editor-embedded #btn-library, body.editor-embedded #btn-inspector, body.editor-embedded #tool-roll, body.editor-embedded #tool-slide, body.editor-embedded #tool-slip, body.editor-embedded #tool-split, body.editor-embedded #tool-delete, body.editor-embedded #tool-ripple { display: none; }

@media (max-width: 850px) {
  .scenvy-editor #btn-library { display: inline-grid; }
  body.editor-ui:not(.editor-embedded) .editor:not(.hidden), body.editor-ui:not(.editor-embedded) .editor.chat-collapsed {
    --editor-overlay-top: 47px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 42px minmax(200px, 40dvh) minmax(250px, 1fr);
    grid-template-areas: "header" "preview" "timeline";
    gap: 3px;
  }
  body.editor-ui:not(.editor-embedded) .direction-panel { position: absolute; z-index: 30; inset: var(--editor-overlay-top) auto 5px 5px; width: min(340px, calc(100vw - 10px)); box-shadow: 0 10px 35px #0005; }
  body.editor-ui:not(.editor-embedded) .editor.chat-collapsed .direction-panel { display: none; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .panel-left { position: absolute; z-index: 19; right: 5px; bottom: 5px; top: var(--editor-overlay-top); width: min(300px, calc(100vw - 10px)); box-shadow: 0 10px 35px #0005; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor:not(.library-open) .panel-left { display: none; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .panel-right { top: var(--editor-overlay-top); right: 5px; bottom: 5px; }
  .scenvy-editor .carrier-info { display: none; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .preview-bar { grid-template-columns: minmax(0, 1fr) auto; }
  .scenvy-editor .transport-controls { justify-content: flex-start; }
  .scenvy-editor .history-label, .scenvy-editor .save-status { display: none; }
  :root.scenvy-editor { --label-w: 92px; }
}
@media (max-width: 520px) {
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar { display: flex; align-items: center; gap: 2px; padding: 0 5px; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-brand,
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-center,
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-right { grid-area: auto; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-brand { flex: 1 1 0; overflow: hidden; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-title { overflow: hidden; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-right { flex: 0 0 auto; gap: 0; }
  .scenvy-editor .timeline-menu .editor-menu-items { left: -44px; max-width: calc(100vw - 96px); min-width: 0; }
  .scenvy-editor .timeline-menu .editor-menu-items button { white-space: normal; overflow-wrap: anywhere; }
  .scenvy-editor .timeline-menu .editor-menu-items kbd { flex-shrink: 0; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor:not(.hidden), body.editor-ui:not(.editor-embedded) .editor.chat-collapsed { --editor-overlay-top: calc(2 * var(--ui-control-size) + 11px); grid-template-rows: 42px minmax(180px, 38dvh) minmax(230px, 1fr); }
  .scenvy-editor .track-label .track-name { display: none; }
  .scenvy-editor .timeline-title { display: block; }
  .scenvy-editor .tl-zoom .zoom-ico, .scenvy-editor .zoom-value { display: none; }
}

/* Keep the standalone editor aligned with the app's shared chat and controls. */
.scenvy-editor body.editor-ui:not(.editor-embedded) .direction-panel {
  border: 0;
  border-radius: var(--ui-radius);
  background: hsl(var(--scenvy-ui-background));
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .direction-messages {
  flex: 1 1 0;
  max-height: none;
  gap: 16px;
  padding: 20px 16px;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .direction-message {
  align-self: stretch;
  width: 100%;
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: var(--chat-output-size);
  line-height: var(--ui-chat-line-height);
}
.scenvy-editor .direction-message.from-assistant > div {
  padding: 0;
  background: transparent;
  box-shadow: none;
}
.scenvy-editor .direction-message.is-failed { outline: 0; }
.scenvy-editor .direction-message.is-failed > div { outline: 1px solid #c96a65; }
.scenvy-editor .direction-form {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding: 8px 12px 12px;
}
.scenvy-editor .direction-composer { position: relative; min-width: 0; }
.scenvy-editor .direction-context { margin: 0; }
.scenvy-editor body.editor-ui .direction-composer .scenvy-prompt-textarea {
  resize: none;
  overflow-x: hidden;
  overflow-y: auto;
  line-height: var(--ui-prompt-line-height);
}
@media (max-width: 767px), (max-height: 500px) and (hover: none) and (pointer: coarse) {
  .scenvy-editor body.editor-ui .direction-composer .scenvy-prompt-textarea {
    max-height: min(calc(6 * 1em * var(--ui-prompt-line-height)), max(1lh, calc(var(--prompt-viewport-height, 100dvh) * .45))) !important;
  }
}
.scenvy-editor .direction-send svg { width: var(--editor-icon-size); height: var(--editor-icon-size); }
.scenvy-editor #direction-status:not(:empty) { padding: 0 4px; }
.scenvy-editor :is(#direction-status, #direction-job):empty { display: none; }

/* The hit area stays usable while the visible hover and selection discs stay small. */
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.editor-icon-button, .tool-btn, .topbar-center .btn-icon) {
  position: relative;
  isolation: isolate;
  display: inline-grid;
  flex: none;
  width: var(--ui-control-size) !important;
  min-width: var(--ui-control-size) !important;
  height: var(--ui-control-size) !important;
  min-height: var(--ui-control-size) !important;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--ui-radius-circle) !important;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--editor-subtle);
  transform: none !important;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.editor-icon-button, .tool-btn, .topbar-center .btn-icon)::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  border-radius: var(--ui-radius-circle);
  background: transparent;
  transform: translate(-50%, -50%);
}
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.editor-icon-button, .tool-btn, .topbar-center .btn-icon):hover:not(:disabled) {
  color: var(--editor-text);
}
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.editor-icon-button, .tool-btn, .topbar-center .btn-icon):hover:not(:disabled)::before {
  background: color-mix(in srgb, var(--editor-text) 10%, transparent);
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .tool-btn.active { color: #fff; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .tool-btn.active::before,
.scenvy-editor body.editor-ui:not(.editor-embedded) .tool-btn.active:hover::before { background: var(--editor-accent); }
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.editor-icon-button, .tool-btn, .topbar-center .btn-icon) svg {
  width: var(--editor-icon-size) !important;
  height: var(--editor-icon-size) !important;
  flex: none;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.track-lock, .zoom-ico, .clip-lock) {
  width: var(--editor-icon-size);
  height: var(--editor-icon-size);
  flex: none;
}
.scenvy-editor .topbar-right .btn-primary,
.scenvy-editor .editor-menu-items,
.scenvy-editor .editor-menu-items button { border-radius: var(--ui-radius-control) !important; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-right .btn-primary {
  height: var(--ui-control-size);
  min-height: var(--ui-control-size);
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-shell { padding-left: var(--editor-tool-rail); }
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-scroll { touch-action: pan-x pan-y; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .tl-tools {
  width: var(--editor-tool-rail);
  padding: 3px 0;
  scrollbar-width: thin;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-toolbar { min-width: 0; }
.scenvy-editor .track-label .track-code {
  min-width: 26px;
  padding: 4px 5px;
  border-radius: 8px;
  text-align: center;
}

.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  height: auto;
  flex: none;
  gap: 2px;
  padding: 4px;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs button {
  height: 28px;
  border-radius: var(--ui-radius-control) !important;
  background: transparent;
  box-shadow: none;
  transform: none;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs button:hover,
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-tabs button.active {
  background: var(--muted);
  color: var(--editor-text);
  box-shadow: none;
  transform: none;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.scene-item, .lib-card, .audio-card, .fx-tile) {
  box-shadow: none;
  transform: none;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-rows {
  flex: none;
  grid-auto-rows: max-content;
  align-content: start;
  overflow: visible;
  padding: 0;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-meta { flex: none; }
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.scene-item, .lib-card, .audio-card, .fx-tile):hover,
.scenvy-editor body.editor-ui:not(.editor-embedded) :is(.scene-item, .audio-card).active {
  background: var(--muted);
  box-shadow: none;
  transform: none;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .clip.selected { box-shadow: none; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-search input,
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-card,
.scenvy-editor body.editor-ui:not(.editor-embedded) .lib-thumb { border-radius: var(--ui-radius-control) !important; }

.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-controls {
  min-width: 0;
  flex-wrap: nowrap;
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-controls select {
  display: block;
  flex: none;
  min-width: 0;
  max-width: none;
  height: var(--ui-control-size);
  min-height: var(--ui-control-size);
  padding: 0 22px 0 8px;
  border: 0;
  border-radius: var(--ui-radius-control) !important;
  background-color: transparent;
  background-position: right 5px center;
  background-size: 14px;
  color: var(--editor-text);
  font-size: var(--ui-type-caption);
}
.scenvy-editor body.editor-ui:not(.editor-embedded) .preview-controls select:hover { background-color: var(--muted); }
.scenvy-editor body.editor-ui:not(.editor-embedded) #aspect-select { width: auto; }
.scenvy-editor body.editor-ui:not(.editor-embedded) #fps-select { width: 96px; }
.scenvy-editor body.editor-ui:not(.editor-embedded) .tl-zoom input {
  height: 24px;
  margin: 0;
  accent-color: var(--editor-accent);
}

@media (max-width: 850px) {
  :root.scenvy-editor { --editor-tool-rail: 44px; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .timeline-toolbar { height: 42px; min-height: 42px; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .panel-left { max-height: none; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .preview-bar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--ui-control-size) auto;
  }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .transport-controls { justify-content: center; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .preview-controls { flex-wrap: wrap; justify-content: center; }
}
@media (max-width: 520px) {
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor:not(.hidden),
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor.chat-collapsed {
    grid-template-rows: 84px minmax(180px, 38dvh) minmax(230px, 1fr);
  }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand playback" "actions actions";
    grid-template-rows: repeat(2, var(--ui-control-size));
    gap: 0;
  }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-brand { grid-area: brand; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-center { grid-area: playback; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .topbar-right { grid-area: actions; justify-content: flex-end; }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .preview-bar {
    min-height: calc(2 * var(--ui-control-size));
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--ui-control-size) auto;
    gap: 0;
    padding: 0 6px;
  }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .transport-controls,
  .scenvy-editor body.editor-ui:not(.editor-embedded) .preview-controls { justify-content: center; }
  :root.scenvy-editor { --label-w: 56px; }
}
@media (max-height: 600px) {
  body.editor-ui:not(.editor-embedded) .editor:not(.hidden),
  body.editor-ui:not(.editor-embedded) .editor.chat-collapsed {
    grid-template-rows: 40px minmax(90px, 1fr) minmax(130px, 42%);
  }
  .scenvy-editor body.editor-ui:not(.editor-embedded) .preview-frame {
    flex: 1 1 0;
    height: auto;
  }
}
@media (max-width: 850px) and (max-height: 600px) {
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor:not(.hidden),
  body.editor-ui:not(.editor-embedded) .editor.chat-collapsed {
    grid-template-rows: 42px minmax(100px, 1fr) minmax(130px, 43%);
  }
}
@media (max-width: 520px) and (max-height: 600px) {
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor:not(.hidden),
  .scenvy-editor body.editor-ui:not(.editor-embedded) .editor.chat-collapsed {
    grid-template-rows: 84px minmax(100px, 1fr) minmax(130px, 43%);
  }
}
