/* Studio shell and bounded episode workspace. Legacy document views share tokens. */
:root {
  color-scheme: light;
  --bg: #fff; --bg-panel: #f4f6f9; --bg-raised: #fff; --bg-topbar: #fff;
  --border: #d9e0ea; --border-soft: #e8edf3;
  --text: #253041; --text-muted: #63738e; --text-faint: #778398;
  --accent: #435ca6; --accent-ink: #fff; --accent-wash: #eef2ff; --accent-line: #b9c7ed;
  --ok: #256b53; --ok-wash: #eaf5ef; --ok-line: #b7dac6;
  --pending: #866121; --pending-wash: #fff5db; --pending-line: #e4d1a2;
  --fail: #a13b42; --fail-wash: #ffeded; --fail-line: #ebbdc1;
  --stale: #875029; --stale-wash: #fff0e4; --stage-width: 224px;
  --t-body: 15px; --read-width: 1080px; --topbar-height: 52px;
}
[hidden] { display: none !important; }
body { font-size: var(--t-body); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link:focus { position: fixed; z-index: 100; padding: 12px; background: var(--bg); }
.studio-topbar { position: sticky; top: 0; z-index: 40; display: flex; flex: 0 0 auto; align-items: center; min-height: var(--topbar-height); gap: 24px; padding: 0 24px; background: var(--bg); border-bottom: 1px solid var(--border); }
.studio-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); white-space: nowrap; }
.studio-brand:hover { text-decoration: none; }
.studio-brand > span:first-child { font-size: 26px; }
.studio-nav { display: flex; align-self: stretch; gap: 8px; }
.studio-nav a { display: flex; align-items: center; padding: 0 16px; color: var(--text-muted); border-bottom: 2px solid transparent; }
.studio-nav a[aria-current] { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.studio-more { position: relative; margin-left: auto; }
.studio-more summary { cursor: pointer; padding: 8px; color: var(--text-muted); }
.studio-more nav { position: absolute; right: 0; top: 100%; background: var(--bg); border: 1px solid var(--border); padding: 8px; border-radius: 8px; width: 210px; box-shadow: 0 8px 28px #25304118; }
.studio-more a, .studio-more button { display: block; padding: 9px 12px; border: 0; background: transparent; color: var(--text); text-align: left; width: 100%; border-radius: 4px; }
.studio-more a:hover, .studio-more button:hover { background: var(--bg-panel); text-decoration: none; }
.studio-content { width: 100%; max-width: 1360px; margin: 0 auto; padding: 28px 32px; min-width: 0; }
.status { font-family: var(--font-ui); text-transform: none; letter-spacing: 0; font-size: 13px; border-radius: 5px; }
.btn { border-radius: 6px; min-height: 34px; font-weight: 500; }
.btn-accent { border-color: var(--accent); }
.channel-list { max-width: none; }
.channel-row { margin: 0; border: 0; border-bottom: 1px solid var(--border-soft); border-radius: 0; padding: 20px 8px; background: var(--bg); }
.channel-row .channel-name { flex: 1 1 45%; font-size: 17px; color: var(--text); }
.channel-row > .muted { flex-basis: 25%; text-align: right; font-size: 13px; }
.filters { align-items: end; padding: 12px 0 22px; }
.filters label { font-size: 13px; }
.pagination { display: flex; align-items: center; gap: 20px; margin-top: 24px; }
.fields dd { min-width: 0; overflow-wrap: anywhere; }
.workspace-page { height: 100dvh; min-height: 0; overflow: hidden; }
.workspace-page > .studio-content { display: flex; flex: 1; flex-direction: column; padding: 0; margin: 0; max-width: none; min-height: 0; }
.episode-heading { display: flex; align-items: center; flex: 0 0 auto; gap: 16px; min-height: 94px; padding: 14px 24px 14px calc(var(--stage-width) + 24px); border-bottom: 1px solid var(--border); }
.episode-heading-text { min-width: 0; flex: 1; }
.episode-heading .back { margin: 0 0 4px; font-size: 12px; color: var(--text-muted); }
.episode-heading h1 { font-size: 22px; line-height: 1.3; margin: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.episode-heading > .status { flex-shrink: 0; }
.stages-toggle { display: none; }
.workspace-notice { margin: 0; padding: 8px 24px; border-radius: 0; flex: 0 0 auto; max-height: 80px; overflow: auto; }
#steps[data-workbench] { display: flex; flex: 1; min-height: 0; min-width: 0; }
.workbench { display: grid; grid-template-columns: var(--stage-width) minmax(0, 1fr); flex: 1; min-width: 0; min-height: 0; }
.stage-navigation { display: flex; flex-direction: column; background: var(--bg-panel); border-right: 1px solid var(--border); min-width: 0; min-height: 0; }
.stage-heading { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px; gap: 8px; font-size: 14px; }
.stage-heading > span { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.stage-buttons { flex: 1; min-height: 0; overflow: auto; padding: 0 10px 10px; scrollbar-width: thin; }
.stage-button { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: center; gap: 8px; text-align: left; width: 100%; min-height: 51px; margin: 4px 0; padding: 7px 10px; border: 1px solid transparent; border-radius: 7px; color: var(--text); background: #e9edf3; }
.stage-button strong { display: block; font-weight: 500; line-height: 1.25; overflow-wrap: anywhere; }
.stage-button small { display: block; font-size: 12px; line-height: 1.35; color: var(--text-muted); margin-top: 2px; }
.stage-symbol { font-size: 20px; line-height: 1; }
.stage-button.state-done { background: var(--ok-wash); }.stage-button.state-done .stage-symbol { color: var(--ok); }
.stage-button.state-waiting, .stage-button.state-paused { background: var(--pending-wash); }.stage-button.state-waiting .stage-symbol, .stage-button.state-paused .stage-symbol { color: var(--pending); }
.stage-button.state-stale { background: var(--stale-wash); }.stage-button.state-stale .stage-symbol { color: var(--stale); }
.stage-button.state-running { background: var(--accent-wash); }.stage-button.state-running .stage-symbol { color: var(--accent); }
.stage-button.state-failed { background: var(--fail-wash); }.stage-button.state-failed .stage-symbol { color: var(--fail); }
.stage-button.state-skipped { background: transparent; color: var(--text-muted); }
.stage-button[aria-current] { border-color: var(--accent); box-shadow: inset 3px 0 var(--accent); }
.stage-button:hover { border-color: var(--accent-line); }
.history-toggle { background: transparent; border: 0; border-top: 1px solid var(--border); color: var(--accent); padding: 12px; text-align: left; font-size: 13px; }
.workbench-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.material-panel, .version-panel { display: flex; flex: 1; flex-direction: column; min-height: 0; min-width: 0; }
.material-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 24px; border-bottom: 1px solid var(--border-soft); flex: 0 0 auto; }
.material-heading h2 { font-size: 18px; margin: 0; }
.material-heading .muted { font-size: 12px; }
.material-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.material-actions form { margin: 0; }
.material-scroll { flex: 1; min-height: 0; overflow: auto; padding: 16px 24px 24px; overscroll-behavior: contain; scrollbar-gutter: stable; }
.material-warning { flex: 0 0 auto; max-height: 100px; overflow: auto; margin: 0; padding: 8px 24px; background: var(--pending-wash); color: var(--pending); font-size: 13px; }
.material-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.material-empty { padding: 40px 0; max-width: 480px; color: var(--text-muted); }
.material-empty h3 { color: var(--text); font-size: 18px; margin: 0 0 8px; }
.material-result { max-width: none; min-width: 0; }
.material-result .fields { max-width: 1080px; }
.script-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.script-toolbar > div { display: flex; gap: 8px; }
.script-toolbar .muted { font-size: 12px; }
.script-row { display: grid; grid-template-columns: 34px minmax(0,1fr); gap: 14px; padding: 18px 12px; border: 1px solid transparent; border-top-color: var(--border); cursor: pointer; }
.script-row:hover { background: var(--bg-panel); }
.script-row.is-selected { background: var(--accent-wash); border-color: var(--accent-line); border-radius: 6px; }
.line-number { align-self: start; background: var(--bg-panel); border: 0; padding: 5px; min-height: 34px; border-radius: 5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.script-row.is-selected .line-number { background: var(--accent); color: var(--accent-ink); }
.script-copy { min-width: 0; max-width: 1050px; }
.script-copy .line-head { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.script-copy .line-head strong { font-weight: 500; }
.script-copy .line-text { font-size: 17px; line-height: 1.7; margin: 0; white-space: pre-wrap; }
.script-copy textarea { width: 100%; min-height: 100px; padding: 10px 12px; border: 1px solid var(--accent-line); border-radius: 6px; background: var(--bg); color: var(--text); resize: vertical; font-size: 16px; line-height: 1.65; }
.script-copy .line-notes { font-size: 12px; color: var(--text-muted); margin-top: 10px; }
.draft-status, .edit-consequence { font-size: 13px; padding: 8px 12px; background: var(--pending-wash); color: var(--pending); margin: 8px 0; }
.material-extra { margin-top: 20px; font-size: 13px; color: var(--text-muted); }
.ai-dock { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 8px 24px 10px; background: var(--bg); max-height: 42%; overflow: auto; }
.workspace-update { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 12px; color: var(--text-muted); }
.workspace-update:has(#ep-live:empty):not(:has(button:not([hidden]))) { display: none; }
.compose-context { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 4px 0 8px; font-size: 12px; }
.compose-context > strong { font-size: 13px; }
.scope-toggle { background: var(--accent-wash); color: var(--accent); border: 1px solid var(--accent-line); border-radius: 5px; padding: 2px 8px; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-input { display: flex; align-items: end; gap: 8px; }
.compose-input textarea { flex: 1; min-width: 0; height: 40px; min-height: 40px; max-height: 100px; resize: vertical; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; background: var(--bg); color: var(--text); }
.compose-input .btn { min-height: 40px; }
.compose-help { font-size: 12px; margin: 5px 0 0; }
.version-group { padding: 0 0 22px; margin-bottom: 18px; border-bottom: 1px solid var(--border-soft); }
.version-group h3 { font-size: 16px; margin: 0 0 10px; }
.version-links { display: flex; gap: 8px; flex-wrap: wrap; }
.version-links a { display: flex; flex-direction: column; min-width: 150px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.version-links a:hover { border-color: var(--accent); text-decoration: none; }
.version-links span, .version-links small { font-size: 12px; color: var(--text-muted); }
/* A selected scene fits the viewport. Thumbnails and text remain reachable. */
.scene-browser { display: grid; grid-template-columns: 170px minmax(0,1fr); gap: 20px; height: 100%; min-height: 0; }
.scene-list { overflow: auto; min-height: 0; padding: 2px; }
.scene-choice { display: block; width: 100%; text-align: left; padding: 0 0 8px; margin: 0 0 12px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; color: var(--text); }
.scene-choice img { width: 100%; height: 90px; object-fit: contain; background: var(--bg-panel); display: block; }
.scene-choice span { display: block; padding: 6px 8px 0; font-size: 12px; }
.scene-choice[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.scene-view { display: flex; min-height: 0; min-width: 0; flex-direction: column; }
.scene-view > img { width: 100%; flex: 1; min-height: 80px; object-fit: contain; background: var(--bg-panel); border-radius: 6px; }
.scene-caption { flex: 0 0 auto; max-height: 110px; overflow: auto; font-size: 13px; padding: 10px 0; }
.scene-caption p { margin: 0 0 4px; }
.material-panel.has-scenes .material-scroll { display: flex; flex-direction: column; overflow: hidden; }
.material-panel.has-scenes .material-result { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.material-panel.has-scenes .result-fields { display: flex; flex: 1; min-height: 0; flex-direction: column; margin: 0; max-width: none; }
.material-panel.has-scenes .result-fields > dt, .material-panel.has-scenes .result-fields > dd:not(:has(.scene-browser)) { display: none; }
.material-panel.has-scenes .result-fields > dd:has(.scene-browser) { display: flex; flex: 1; min-height: 0; margin: 0; }
.material-panel.has-scenes .field-objects { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.material-panel.has-scenes .objects-summary { flex: 0 0 auto; margin: 0 0 8px; font-size: 12px; }
.version-compare { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; }
.version-compare > section { padding: 16px; background: var(--bg-panel); border-radius: 8px; min-width: 0; }
.version-compare h2 { margin-top: 0; }
.version-compare .fields { display: block; }
.version-compare .fields dt { margin-top: 16px; }.version-compare .fields dd { margin: 4px 0 0; }
@media (max-width: 950px) {
  :root { --stage-width: 200px; }
  .episode-heading { padding-left: 20px; }
  .material-heading, .material-scroll { padding-left: 18px; padding-right: 18px; }
  .ai-dock { padding-left: 18px; padding-right: 18px; }
  .scene-browser { grid-template-columns: 120px minmax(0,1fr); gap: 12px; }
}
@media (max-width: 700px) {
  .studio-topbar { gap: 10px; padding: 0 10px; min-height: 48px; }
  .studio-brand > span:last-child { display: none; }
  .studio-nav { gap: 0; }.studio-nav a { padding: 0 10px; font-size: 14px; }
  .studio-more summary { padding: 8px 3px; }
  .studio-content { padding: 20px 16px; }
  .episode-heading { padding: 10px 12px; min-height: 80px; gap: 10px; }
  .episode-heading h1 { font-size: 16px; }.episode-heading > .status { display: none; }
  .stages-toggle { display: flex; flex-direction: column; padding: 5px 8px; font-size: 12px; flex-shrink: 0; }
  .stages-toggle span { color: var(--text-muted); }
  .workbench { grid-template-columns: minmax(0,1fr); position: relative; }
  .stage-navigation { display: none; position: absolute; left: 0; top: 0; bottom: 0; width: 240px; z-index: 25; box-shadow: 10px 0 35px #25304125; }
  .workbench.stages-open .stage-navigation { display: flex; }
  .material-heading { padding: 10px 12px; gap: 8px; }.material-heading h2 { font-size: 16px; }
  .material-actions { gap: 4px; }.material-actions .btn { font-size: 12px; padding: 5px 8px; }
  .material-scroll { padding: 12px; }.material-warning { padding: 8px 12px; }
  .script-row { padding: 12px 6px; gap: 8px; grid-template-columns: 30px minmax(0,1fr); }
  .script-copy .line-text { font-size: 15px; }.script-copy textarea { font-size: 16px; }
  .ai-dock { padding: 6px 12px; }.compose-context { gap: 6px; }.compose-input .btn { font-size: 12px; padding: 6px 10px; }
  .scene-browser { display: flex; flex-direction: column-reverse; gap: 10px; }
  .scene-list { display: flex; gap: 8px; flex: 0 0 90px; overflow: auto; }
  .scene-choice { flex: 0 0 110px; margin: 0; }.scene-choice img { height: 50px; }.scene-choice span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .scene-view { flex: 1; }.scene-caption { max-height: 72px; }
  .channel-row > .muted { flex-basis: 100%; text-align: left; }.channel-row .channel-name { flex-basis: 100%; }
  .version-compare { grid-template-columns: minmax(0,1fr); }
}
.material-panel.has-scenes .result-fields > dd:has(.scene-browser) { max-width: none; width: 100%; }
.scene-browser { width: 100%; flex: 1; }
.script-toolbar { position: sticky; top: -16px; z-index: 5; background: var(--bg); padding: 8px 0; }
.edit-request-history { font-size: 12px; margin: 0 0 6px; color: var(--text-muted); }
.edit-request-list { max-height: 160px; overflow: auto; }
.edit-request-list article { border-bottom: 1px solid var(--border); padding: 8px 0; }
.edit-request-list p { white-space: pre-wrap; color: var(--text); margin: 4px 0; }
html:has(.workspace-page) { height: 100%; overflow: hidden; }
@media (max-height: 850px) and (min-width: 701px) {
  .stage-heading { padding: 12px 14px 8px; }
  .stage-button { min-height: 34px; padding: 2px 9px; margin: 2px 0; font-size: 13px; }
  .stage-button strong { line-height: 1.15; }
  .stage-button small { font-size: 11px; line-height: 1.1; margin-top: 0; }
  .stage-symbol { font-size: 18px; }
  .history-toggle { padding: 9px 12px; }
}
.scene-choice small { display: block; padding: 3px 8px 0; font-size: 11px; color: var(--text-muted); }
[data-scene-empty] { flex: 1; display: grid; place-content: center; background: var(--bg-panel); }
.excluded-label { padding: 12px 10px 0; font-size: 11px; color: var(--text-muted); }
div.stage-button { cursor: default; }
@media (max-width: 700px) { .scene-list { flex-basis: 104px; } }

/* Character passports share the material area, with bounded portrait previews. */
.character-grid {display:grid;gap:20px;grid-template-columns:repeat(auto-fit,minmax(min(100%,360px),1fr))}
.character-card {border:1px solid var(--border);border-radius:8px;padding:16px;min-width:0}
.character-card h3 {margin:0 0 6px}
.character-portraits {display:flex;gap:12px;overflow-x:auto;margin:12px 0;padding-bottom:6px}
.character-portraits figure {margin:0;flex:0 0 140px}
.character-portraits img {width:140px;height:180px;object-fit:contain;background:repeating-conic-gradient(#eef0f4 0% 25%,#fff 0% 50%) 0/16px 16px;border-radius:6px}
.character-portraits figcaption {font-size:12px;color:var(--text-muted);margin-top:5px}

#panel-library .character-grid {margin:20px 0}
.library-card {border-bottom:1px solid var(--border);padding:16px 0}
.library-card img {max-width:min(100%,360px);max-height:220px;object-fit:contain;border-radius:6px}
.edit-scene-list {list-style: none; margin: 0; padding: 0;}
.edit-scene-list > li {display: grid; grid-template-columns: 10rem minmax(0,1fr); gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--border);}
.edit-scene-list p {margin: 0 0 .3rem; overflow-wrap: anywhere;}
.edit-scene-time {font-variant-numeric: tabular-nums; color: var(--text-muted);}
.edit-scene-caption {font-weight: 500;}
.source-versions {display: flex; flex-wrap: wrap; gap: .4rem 1rem; list-style: none; margin: 0; padding: 0;}
.edit-plan-summary h3 {margin: .5rem 0 .3rem; overflow-wrap: anywhere;}
.edit-plan-summary p {margin: 0 0 .6rem; font-size: 13px;}
.edit-plan-notes {font-size: 14px; color: var(--text-muted); white-space: pre-wrap; overflow-wrap: anywhere;}
.edit-scene-row {cursor: pointer; border-radius: 5px;}
.edit-scene-list > .edit-scene-row {padding: .6rem .7rem;}
.edit-scene-row:hover {background: var(--bg-panel);}
.edit-scene-row.is-selected {background: #edf1ff; box-shadow: inset 3px 0 #5063a5;}
@media (max-width: 600px) {.edit-scene-list > li {grid-template-columns: minmax(0,1fr); gap: .25rem;}}
