/* ============================================================
   SAGA — minimal dark-gray monochrome
   ============================================================ */

@import url('/fonts.css');

:root {
  --bg: #1A1A1C;
  --surface: #222327;
  --surface-2: #272930;
  --border: #33353C;
  --border-subtle: #2A2C32;
  --text: #F2F2F2;
  --text-muted: #9FA3AD;
  --text-dim: #6B6F78;
  --focus: #5A6070;
  --accent: #7A8FA4;           /* muted slate blue */
  --accent-hi: #94A6B8;
  --accent-dim: #4E5B6B;
  --warm: #B5A089;             /* warm taupe, secondary */
  --ok: #8FB48F;               /* desaturated sage */
  --warn: #C9A76A;             /* muted amber */
  --err: #C98686;              /* muted rose */
  --radius: 4px;
  --gap: 24px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 32px 120px;
}
@media (max-width: 720px) { .shell { padding: 24px 16px 80px; } }

/* ---- masthead ---- */
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
.masthead-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.masthead-title::after {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 8px;
  vertical-align: middle;
  transform: translateY(-3px);
}
.masthead-title .amp { color: var(--text-dim); font-weight: 400; }
.masthead-meta {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

/* ---- sections ---- */
.section {
  margin-bottom: 40px;
}
.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.section-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}
.section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.section-title em {
  font-style: normal;
  color: var(--text);
}
.section-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
}

/* ---- inputs ---- */
textarea, input[type=text], input[type=number], select {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  transition: border-color 120ms;
}
textarea::placeholder, input::placeholder { color: var(--text-dim); }
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px rgba(122, 143, 164, 0.12);
}
textarea { resize: vertical; min-height: 64px; }
select {
  padding-right: 32px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 12px) center;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
input[type=number] { text-align: center; }

#idea { font-size: 14px; min-height: 72px; }

.idea-wrap { position: relative; }
.idea-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  padding-left: 2px;
}
.idea-hint a { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent-dim); }
.idea-hint a:hover { color: var(--accent-hi); border-bottom-color: var(--accent-hi); }
.idea-drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(122, 143, 164, 0.08);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  z-index: 2;
}
.idea-wrap.drag .idea-drop-overlay { display: flex; }
.idea-wrap.drag #idea { border-color: var(--accent); }

/* ---- control row ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  margin-top: 16px;
}
.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.controls label > select,
.controls label > input {
  min-width: auto;
  width: auto;
  padding: 8px 10px;
  padding-right: 28px;
  font-size: 12px;
}
.controls label > input[type=number] { padding: 8px 6px; width: 56px; }
.controls-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---- buttons ---- */
button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 120ms, border-color 120ms;
}
button:hover:not(:disabled) { background: #2E2E2E; border-color: #404040; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button:not(.ghost)#generateBtn,
button:not(.ghost)#storylineFeedbackRegenBtn {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
button:not(.ghost)#generateBtn:hover:not(:disabled),
button:not(.ghost)#storylineFeedbackRegenBtn:hover:not(:disabled) {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
}

button.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
button.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--focus);
  background: var(--surface);
}

/* ---- pills (aspect ratio) ---- */
.pills {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pill {
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border);
  padding: 8px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  color: var(--text-muted);
  transition: background 120ms, color 120ms;
}
.pill:last-child { border-right: none; }
.pill:hover { background: var(--surface-2); color: var(--text); }
.pill.active { background: var(--accent); color: var(--bg); font-weight: 500; }
.pill.active:hover { background: var(--accent-hi); }

/* ---- file input ---- */
input[type=file] { color: var(--text-muted); font-size: 12px; padding: 0; background: transparent; border: none; }
input[type=file]::file-selector-button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  margin-right: 10px;
  transition: background 120ms;
}
input[type=file]::file-selector-button:hover { background: #2E2E2E; }
#imagePreviewWrap { display: flex; align-items: center; gap: 10px; }
#imagePreview {
  max-height: 44px;
  max-width: 88px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#imageClearBtn { padding: 4px 10px; font-size: 10px; }

/* ---- error banner ---- */
#error {
  background: var(--surface);
  color: var(--err);
  border: 1px solid var(--border);
  border-left: 2px solid var(--err);
  padding: 10px 14px;
  border-radius: var(--radius);
  display: none;
  margin-bottom: 16px;
  font-size: 12px;
}

/* ---- dashboard ---- */
#dashboard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
#dashboard .section-head {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.dash-elapsed {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.phase {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 0;
  font-size: 12px;
}
.phase-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 10px;
  border: 1px solid var(--border);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 500;
  transition: all 160ms;
}
.phase.active .phase-icon {
  border-color: var(--accent);
  color: var(--accent);
  animation: pulse 1.4s infinite;
}
.phase.done .phase-icon {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.phase.done .phase-icon::before { content: "✓"; font-size: 11px; font-weight: 600; }
.phase-label { flex: 1; color: var(--text); }
.phase.done .phase-label { color: var(--text-muted); }
.phase-time, .phase-progress {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
@keyframes pulse { 0%,100% {opacity:1} 50% {opacity:0.45} }

/* ---- scene tiles ---- */
.scene-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}
.scene-tile {
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 160ms;
  font-variant-numeric: tabular-nums;
}
.scene-tile:hover { border-color: var(--accent); color: var(--accent); }
.scene-tile.active { border-color: var(--accent); color: var(--accent); animation: pulse 1.4s infinite; }
.scene-tile.done { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.scene-tile.error { border-color: var(--err); color: var(--err); }

/* ---- style bible ---- */
#biblePanel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
#biblePanel .section-head {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}
#bibleView {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 24px;
}
@media (max-width: 720px) { #bibleView { grid-template-columns: 1fr; } }
.bible-field { margin: 0; }
.bible-field label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--warm);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}
.bible-field > div.prompt-text {
  background: transparent;
  border: none;
  border-left: 1px solid var(--accent-dim);
  padding: 2px 0 2px 12px;
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
  line-height: 1.55;
  white-space: normal;
}
.bible-field > textarea { min-height: 60px; font-size: 12px; padding: 10px 12px; }

#bibleModeBtn { padding: 6px 12px; font-size: 10px; }

/* ---- scene list ---- */
#sceneList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 120ms;
}
.scene-card:hover { border-color: var(--focus); }
.scene-card.expanded { border-color: var(--accent-dim); }

.scene-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
  user-select: none;
}
.scene-row .scene-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  min-width: 24px;
}
.scene-row b {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  font-style: normal;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scene-row .beat {
  color: var(--text-muted);
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scene-row .row-status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  font-style: italic;
}
.scene-row .wc { margin-left: 0; }
.scene-row .row-copy {
  padding: 6px 12px;
  font-size: 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.scene-row .row-copy:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.scene-row .chevron {
  color: var(--text-dim);
  font-size: 14px;
  transition: transform 160ms;
  display: inline-block;
}
.scene-card.expanded .scene-row .chevron { transform: rotate(90deg); color: var(--accent); }

.scene-body {
  padding: 0 18px 18px 18px;
  border-top: 1px solid var(--border-subtle);
  animation: expandIn 220ms ease-out;
}
@keyframes expandIn {
  0% { opacity: 0; transform: translateY(-4px); }
  100% { opacity: 1; transform: translateY(0); }
}

.scene-body > .prompt-text:first-child { margin-top: 16px; }
.scene-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.scene-header .scene-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  min-width: 28px;
}
.scene-header b {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  font-style: normal;
}
.scene-header .beat {
  color: var(--text-muted);
  font-size: 12px;
  flex: 1;
}

.prompt-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  background: var(--surface-2);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  border-left: 2px solid var(--accent-dim);
  white-space: pre-wrap;
}

/* Scene prompt rendered as an always-editable textarea (like the Style Bible). */
textarea.prompt-editable {
  display: block;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 80px;
  overflow: hidden;
}
textarea.prompt-editable:focus {
  outline: none;
  border-color: var(--accent-dim);
  border-left-color: var(--accent);
}

.wc {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.wc.ok { background: transparent; color: var(--ok); border: 1px solid var(--border); }
.wc.warn { background: transparent; color: var(--warn); border: 1px solid var(--border); }

.scene-row.drop-target {
  background: rgba(106, 166, 255, 0.12);
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  border-radius: var(--radius);
}
.scene-row.drop-target::before {
  content: 'Drop to attach + regenerate';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid var(--accent);
  pointer-events: none;
}
.scene-row { position: relative; }

.row-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 120ms;
  flex-shrink: 0;
}

/* Narrow viewport: allow row buttons to wrap onto a second line instead of
   overflowing or stacking awkwardly, and shrink title + beat to prevent eats. */
@media (max-width: 720px) {
  .scene-row {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .scene-row b { flex: 1 1 100%; order: -1; }
  .scene-row .beat { display: none; }
  .row-btn { font-size: 13px; padding: 5px 9px; }
}
.row-btn:hover:not(:disabled) {
  color: var(--fg, #eee);
  border-color: var(--fg, #eee);
  background: rgba(255, 255, 255, 0.04);
}
.row-btn:disabled { opacity: 0.4; cursor: default; }
.row-up:hover:not(:disabled) { color: #7ec97e; border-color: #7ec97e; }
.row-down:hover:not(:disabled) { color: #e27a7a; border-color: #e27a7a; }
.row-regen { font-size: 14px; padding: 3px 6px; }
.row-fight { font-size: 13px; padding: 3px 6px; }
.row-fight:hover:not(:disabled) { color: #e2a57a; border-color: #e2a57a; }
.row-video:hover:not(:disabled) { color: #7aa5e2; border-color: #7aa5e2; }
.row-video.has { color: #7aa5e2; border-color: #7aa5e2; }

/* Video prompt block inside expanded scene body */
.video-prompt-block {
  margin-top: 14px;
  padding: 14px;
  background: rgba(122, 165, 226, 0.06);
  border: 1px solid rgba(122, 165, 226, 0.3);
  border-radius: var(--radius);
}
.video-prompt-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.video-prompt-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: #7aa5e2;
}
.video-prompt-camera {
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 8px;
  border-radius: 3px;
}
.video-prompt-duration {
  font-size: 10px;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}
.video-prompt-block .video-copy,
.video-prompt-block .video-regen,
.video-prompt-block .video-del {
  font-size: 10px;
  padding: 4px 10px;
  margin-left: auto;
}
.video-prompt-block .video-regen,
.video-prompt-block .video-del { margin-left: 0; }
.video-prompt-block .video-del { padding: 4px 8px; }
.video-prompt-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}
.video-prompt-block.drag {
  background: rgba(122, 165, 226, 0.15);
  border-color: #7aa5e2;
  outline: 2px dashed #7aa5e2;
  outline-offset: -4px;
}
.video-prompt-block.empty {
  background: rgba(122, 165, 226, 0.03);
  border-style: dashed;
}
.video-browse-link {
  color: #7aa5e2;
  text-decoration: underline;
  cursor: pointer;
}
.video-browse-link:hover { color: #9cc0ff; }

/* Stunt / Video section (05) */
.stunt-blurb {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 8px 0 16px;
}
.stunt-controls {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.stunt-controls label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stunt-controls select,
.stunt-controls input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 8px 10px;
  min-width: 180px;
}
.stunt-controls input[type="number"] { min-width: 80px; }
.stunt-status {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 10px;
}

/* Close-up output cards (rendered in #stuntOutput) */
#stuntOutput {
  margin-top: 20px;
}
.stunt-output-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.stunt-output-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  flex: 1;
}
.stunt-output-head button { font-size: 10px; padding: 5px 10px; }

.closeup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid #e2a57a;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.closeup-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.closeup-num {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #e2a57a;
  font-weight: 600;
}
.closeup-framing {
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 8px;
  border-radius: 3px;
}
.closeup-head b {
  flex: 1;
  font-size: 12px;
  color: var(--text);
}
.closeup-head .row-btn,
.closeup-head .row-copy {
  margin-left: 0;
}
.closeup-prompt-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle, rgba(255,255,255,0.05));
}
.video-prompt-block .video-gen {
  font-size: 10px;
  padding: 4px 12px;
  margin-left: auto;
}
.video-ref-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.video-ref-thumbs .img-thumb {
  width: 56px;
  height: 56px;
}
.video-drop-hint {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  text-align: center;
  padding: 6px;
  border: 1px dashed rgba(122, 165, 226, 0.3);
  border-radius: 4px;
}

.scene-dropzone {
  margin-top: 14px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 120ms, background 120ms;
}
.scene-dropzone.drag {
  border-color: var(--accent, #6aa6ff);
  background: rgba(106, 166, 255, 0.08);
}
.scene-dropzone.has-images { background: rgba(255, 255, 255, 0.03); }
.scene-dropzone .dz-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.02em;
}
.scene-dropzone .dz-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.scene-dropzone .dz-thumbs .img-thumb {
  width: 72px;
  height: 72px;
}

.scene-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.scene-actions button { padding: 7px 14px; font-size: 11px; }

.feedback-wrap {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}
.feedback-wrap textarea {
  min-height: 44px;
  font-size: 12px;
  padding: 8px 12px;
}
.feedback-wrap .row { margin: 8px 0 0 0; gap: 6px; }
.feedback-wrap button { padding: 6px 12px; font-size: 10px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- storyline feedback panel ---- */
#storylineFeedbackPanel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
#storylineFeedbackPanel .section-head {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}
#storylineFeedbackPanel p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px 0;
}

/* ---- selection ---- */
::selection { background: var(--accent); color: var(--bg); }

/* ---- scrollbar ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--focus); }

/* ---- hide art-house decorations from prior design ---- */
.grain, .vignette, .colophon { display: none !important; }

/* ---- image thumbs ---- */
#imagePreviewWrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.img-thumb {
  position: relative;
  width: 68px;
  height: 68px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.img-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.72);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-remove:hover { background: var(--err); }
.img-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.img-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
}
.img-meta button { padding: 6px 10px; font-size: 10px; }

/* ---- busy states ---- */
.busy-text {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-style: italic;
}
.scene-card.busy { opacity: 0.92; }
.scene-card.busy .prompt-text { border-left-color: var(--accent); animation: borderPulse 1.6s infinite; }

/* Thin moving progress bar at the bottom of a scene row while the agent is working */
.scene-card { position: relative; }
.scene-card.busy {
  overflow: hidden;
}
.scene-card.busy::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 40%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent) 50%,
    transparent 100%
  );
  animation: sceneBusySweep 2.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  will-change: transform;
  pointer-events: none;
}
@keyframes sceneBusySweep {
  0%   { transform: translate3d(-100%, 0, 0); }
  100% { transform: translate3d(250%, 0, 0); }
}
@keyframes borderPulse {
  0%,100% { border-left-color: var(--accent-dim); }
  50%     { border-left-color: var(--accent-hi); }
}

.spinner-inline {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- video prompt loading bar ---- */
.video-prompt-block.busy { opacity: 0.95; }
.video-loading-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px dashed var(--accent-dim);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}
.video-loading-bar .spinner-inline { margin-right: 6px; vertical-align: middle; }
.video-loading-progress {
  position: relative;
  height: 3px;
  width: 100%;
  background: var(--accent-dim);
  border-radius: 2px;
  overflow: hidden;
}
.video-loading-progress-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 35%;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  animation: videoLoadingSweep 1.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  will-change: transform;
}
@keyframes videoLoadingSweep {
  0%   { transform: translate3d(-100%, 0, 0); }
  100% { transform: translate3d(300%, 0, 0); }
}

/* ---- stunt agent loading bar (mirrors video loading bar) ---- */
.stunt-loading-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.02);
  border: 1px dashed var(--accent-dim);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}
.stunt-loading-bar .spinner-inline { margin-right: 6px; vertical-align: middle; }

.stunt-macros-hint {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.02);
  border: 1px dashed var(--accent-dim);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}
.busy-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
}
.busy-card .spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.section-head.clickable {
  cursor: pointer;
  user-select: none;
}
.section-head.clickable:hover .section-title { color: var(--accent); }
#memoryChevron {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  transition: transform 160ms;
}
.memory-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.memory-toolbar button { font-size: 11px; padding: 6px 12px; }
.memory-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--bg-subtle, #1a1d22);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.mem-stat { white-space: nowrap; }
.mem-stat-warn { color: #d4a04e; }
.mem-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: background 120ms, color 120ms;
}
.mem-chip:hover {
  background: var(--bg-subtle, #1a1d22);
  color: var(--text);
}
.memory-empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 14px 0;
}
.memory-group {
  margin-top: 18px;
}
.memory-group-head {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 0 0 10px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.memory-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
}
.memory-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.memory-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.memory-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
  white-space: nowrap;
}
.memory-del {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 7px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
}
.memory-del:hover { color: #e27a7a; border-color: #e27a7a; }
.memory-body {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.55;
  margin-top: 8px;
  white-space: pre-wrap;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  backdrop-filter: blur(3px);
  animation: modal-fade 120ms ease-out;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px 18px;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 18px 64px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card .modal-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.modal-card .modal-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: -4px;
}
.modal-card textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 10px 12px;
  min-height: 72px;
  max-height: 180px;
  resize: vertical;
  outline: none;
  transition: border-color 120ms;
}
.modal-card textarea:focus { border-color: var(--accent); }
.modal-card .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.modal-card .modal-actions button {
  font-size: 11px;
  padding: 7px 14px;
  letter-spacing: 0.03em;
}

/* ── Character Sheet scene card ────────────────────────────────────────── */
.scene-card--sheet {
  border: 2px solid #d4a017;
  background: linear-gradient(180deg, rgba(212, 160, 23, 0.06), transparent 60%);
  position: relative;
}
.scene-card--sheet .sheet-badge {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #d4a017;
  text-transform: uppercase;
  padding: 6px 12px 4px;
  border-bottom: 1px dashed rgba(212, 160, 23, 0.3);
}
.scene-card--sheet .scene-num {
  background: #d4a017;
  color: #000;
}

/* ── v2.12: admin-key unlock bar ── */
.qp-unlock {
  position: sticky; top: 0; z-index: 60;
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--warn);
  color: var(--text); font-size: 14px;
}
.qp-unlock input {
  flex: 0 1 260px; padding: 6px 10px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
.qp-unlock input:focus { outline: none; border-color: var(--focus); }
.qp-unlock-status { font-size: 13px; color: var(--text-dim); }
.qp-unlock-status.err { color: var(--err); }

@media (max-width: 640px) {
  .qp-unlock {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px; padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }
  .qp-unlock > span:first-child {
    grid-column: 1 / -1; font-size: 12px; font-weight: 600;
  }
  .qp-unlock input {
    width: 100%; min-width: 0; min-height: 44px; font-size: 16px;
  }
  .qp-unlock .qp-btn { min-height: 44px; padding-inline: 16px; }
  .qp-unlock-status { grid-column: 1 / -1; font-size: 12px; }
  .qp-unlock-status:empty { display: none; }
}

/* ── v2.12: lint badge, used chips, progress strip, history browser ── */
.qp-lint-badge {
  display: inline-block; font-size: 11px; line-height: 1.6;
  color: #2a2208; background: var(--warn); border-radius: var(--radius);
  padding: 0 7px; margin-left: 6px; white-space: nowrap; cursor: help;
}
.qp-used-wrap { display: inline-flex; gap: 3px; margin-left: 6px; }
.qp-used-chip { font-size: 11px; color: var(--ok); }
.qp-menu-anchor { position: relative; display: inline-block; }
.qp-menu-anchor .qp-menu { right: 0; left: auto; }
.qp-menu .qp-menu-reset span:first-child { color: var(--text-dim); }

.qp-progress {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin: 0 0 14px; font-size: 12px;
}
.qp-slot-chip {
  border-radius: 10px; padding: 2px 9px; font-size: 11px;
  font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border-subtle);
}
.qp-slot-chip.writing { color: var(--accent-hi); border-color: var(--accent-dim); animation: qp-pulse 1.2s ease-in-out infinite; }
.qp-slot-chip.done { color: var(--ok); }
.qp-slot-chip.failed { color: var(--err); border-color: var(--err); }
.qp-slot-chip.cancelled { color: var(--text-dim); text-decoration: line-through; }
.qp-cancel { margin-left: 8px; }
@keyframes qp-pulse { 50% { opacity: .5; } }

.qp-history {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 14px; margin: 0 0 16px;
}
.qp-hist-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.qp-hist-bar input[type="search"] {
  flex: 1 1 200px; min-width: 140px; padding: 6px 10px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-size: 13px;
}
.qp-hist-bar input[type="search"]:focus { outline: none; border-color: var(--focus); }
.qp-hist-count { font-size: 12px; color: var(--text-dim); margin-left: auto; }
.qp-hist-list { max-height: 46vh; overflow-y: auto; }
.qp-hist-row {
  display: flex; gap: 10px; align-items: center;
  padding: 7px 2px; border-bottom: 1px solid var(--border-subtle);
}
.qp-hist-row:last-child { border-bottom: none; }
.qp-hist-star {
  background: none; border: none; cursor: pointer; font-size: 15px;
  color: var(--text-dim); padding: 2px 4px; line-height: 1;
}
.qp-hist-star.fav { color: var(--warn); }
.qp-hist-meta { flex: 1; min-width: 0; }
.qp-hist-title { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qp-hist-meta .snippet { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qp-hist-empty { color: var(--text-dim); font-size: 13px; padding: 12px 2px; }
.qp-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.qp-compare:empty { display: none; }
.qp-hist-cmp .qp-card-body { max-height: none; }
@media (max-width: 800px) {
  .qp-compare { grid-template-columns: 1fr; }
  .qp-hist-row { flex-wrap: wrap; }
}

/* ── v2.14: refine bar, per-model dots, aspect glyph ── */
.qp-refine-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-2);
}
.qp-refine-bar input[type="text"] {
  flex: 1 1 220px; min-width: 0; padding: 7px 10px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-size: 12px;
}
.qp-refine-bar input[type="text"]:focus { outline: none; border-color: var(--focus); }
.qp-refine-bar .qp-edit-hint { flex-basis: 100%; }

/* model identity dots — the --m-* jewel vars are set in index.html's :root;
   fallbacks keep the dots sane anywhere the vars are absent */
.m-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 8px; vertical-align: 1px; background: var(--text-dim); flex: none;
}
.m-dot[data-m="nano-banana-pro"] { background: var(--m-nbp, #F5C518); }
.m-dot[data-m="gpt-image"]       { background: var(--m-gpt, #19C39A); }
.m-dot[data-m="flux"]            { background: var(--m-flux, #5B8DEF); }
.m-dot[data-m="midjourney"]      { background: var(--m-mj, #B49BFF); }
.qp-used-chip[data-m="nano-banana-pro"] { color: var(--m-nbp, #F5C518); }
.qp-used-chip[data-m="gpt-image"]       { color: var(--m-gpt, #19C39A); }
.qp-used-chip[data-m="flux"]            { color: var(--m-flux, #5B8DEF); }
.qp-used-chip[data-m="midjourney"]      { color: var(--m-mj, #B49BFF); }

/* live aspect-ratio preview beside the "Aspect" field label */
.ar-glyph {
  display: inline-block; height: 9px; aspect-ratio: 16 / 9;
  border: 1px solid currentColor; border-radius: 2px;
  margin-left: 7px; vertical-align: -1px; opacity: .8;
}


.img-mode-toggle{display:flex;gap:2px;margin:8px 0 2px 48px;width:fit-content;border-radius:9px;overflow:hidden;border:1px solid var(--border);font:600 11px var(--sans)}
.img-mode-toggle button{background:var(--card);border:0;color:var(--text-dim);padding:5px 12px;cursor:pointer;transition:.15s}
.img-mode-toggle button.on{background:var(--cyan,#35C7D6);color:#0A0B0D}
