/* AIfred Studio — ultra-minimal */

:root {
  --bg: #232323;
  --bg-soft: #2c2c2c;
  --fg: #f5f5f4;
  --fg-dim: #b98ffa;
  --fg-faint: #8b6dc4;
  --accent: #fafaf9;
  --danger: #ef4444;
  --purple: #b98ffa;
  --purple-soft: rgba(185, 143, 250, 0.4);
  --purple-faint: rgba(185, 143, 250, 0.18);
  --line: rgba(185, 143, 250, 0.12);
  --shadow-mic: 0 24px 60px -12px rgba(0,0,0,.7), 0 0 0 1px var(--line);

  --font-display: 'Satoshi', system-ui, -apple-system, sans-serif;
  --font-body: 'Satoshi', system-ui, -apple-system, sans-serif;

  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.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;
}

/* -------- Screens -------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  opacity: 0;
  transition: opacity .5s var(--ease);
}
.screen.is-active {
  display: flex;
  opacity: 1;
}

/* -------- Welcome screen -------- */

#screen-welcome {
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,.03), transparent 60%),
    var(--bg);
}

.welcome {
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.logo {
  width: 56px;
  height: 56px;
  color: var(--fg);
  margin-bottom: .5rem;
}

.welcome h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 500;
  letter-spacing: -.02em;
}

.ai {
  font-weight: 700;
  letter-spacing: -.04em;
}
.ai-inline {
  font-weight: 700;
}

.welcome-copy {
  color: var(--fg-dim);
  font-size: .95rem;
  line-height: 1.6;
  max-width: 36ch;
}

.welcome-copy em {
  font-style: normal;
  color: var(--fg);
  font-weight: 500;
}

/* -------- Buttons -------- */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  padding: .8rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-family: inherit;
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform .2s var(--ease), opacity .2s var(--ease);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: progress; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  padding: .45rem .9rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: .8rem;
  cursor: pointer;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.btn-ghost:hover { color: var(--fg); border-color: rgba(255,255,255,.2); }

.error {
  color: var(--danger);
  font-size: .85rem;
  margin-top: .5rem;
  max-width: 36ch;
}

/* -------- App screen -------- */

#screen-app {
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -.01em;
  font-size: .95rem;
}
.logo-sm { width: 22px; height: 22px; color: var(--fg); }

/* New text-only brand: AIFRED.STUDIO | Image generation made easy */
.brand-text {
  gap: .65rem;
  font-size: .95rem;
  min-width: 0;
  overflow: hidden;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--fg);
  white-space: nowrap;
}
.brand-sep {
  color: var(--purple-soft);
  opacity: .55;
  font-weight: 300;
  flex-shrink: 0;
}
.brand-tag {
  color: var(--purple);
  font-weight: 400;
  font-size: .85rem;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.user {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}
.user-email {
  font-size: .8rem;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

@media (max-width: 600px) {
  .topbar {
    padding: .85rem 1rem;
  }
  .brand span {
    display: none; /* keep just the logo on small screens */
  }
  /* On small screens, drop the tagline; keep only the brand name */
  .brand-text .brand-sep,
  .brand-text .brand-tag {
    display: none;
  }
  .brand-text .brand-name {
    display: inline; /* override the generic .brand span hide above */
    font-size: .9rem;
  }
  .user {
    gap: .6rem;
  }
  .user-email {
    max-width: 140px;
    font-size: .75rem;
  }
  #btn-logout {
    padding: .35rem .7rem;
    font-size: .72rem;
    white-space: nowrap;
  }
}

/* -------- Stage (main area) -------- */

/* Top-menu height reference — used for scroll-margin so portrait images don't get cropped under the topbar */
:root {
  --topbar-h: 88px;
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
  padding: 1.5rem 2rem 2.5rem;
  position: relative;
  min-height: 0;
  /* Stage itself doesn't scroll — only the feed column scrolls. */
  overflow: hidden;
}

/* -------- Sidebar (sticky controls + mic) -------- */
.sidebar {
  position: sticky;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-height: calc(100vh - var(--topbar-h) - 2rem);
  overflow-y: auto;
  padding: .25rem .25rem .5rem;
  /* Hide scrollbar visually but keep scrollable */
  scrollbar-width: thin;
  scrollbar-color: var(--purple-faint) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--purple-faint); border-radius: 3px; }

/* -------- Feed (scrollable column, newest at top) -------- */
.feed {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  width: 100%;
  /* No artificial max-width — the feed fills the entire viewport width minus the sidebar.
     Each image is capped by its own natural width via --img-natural-w on .result-image-wrap. */
  /* Top padding ensures portrait images never tuck under the top menu when scrolled */
  padding: 25px 0 4rem;
  /* Feed scrolls independently of the sidebar */
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--purple-faint) transparent;
}
.feed::-webkit-scrollbar { width: 8px; }
.feed::-webkit-scrollbar-track { background: transparent; }
.feed::-webkit-scrollbar-thumb { background: var(--purple-faint); border-radius: 4px; }

.feed-empty {
  color: var(--fg-faint);
  font-style: italic;
  text-align: center;
  padding: 4rem 1rem;
  font-size: .9rem;
}
.feed-empty[hidden] { display: none; }

/* -------- Feed item (formerly .result) -------- */

.feed-item,
.result {
  display: grid;
  /* Image column grows up to the image's natural pixel width (set per-item
     in JS as --img-natural-w), then stops. Prompt column sits flush against
     the image's right edge, with a fixed width. The unused right-side space
     (when an image is smaller than the viewport) is left empty — we never
     stretch the image past 100%. */
  grid-template-columns: minmax(0, var(--img-natural-w, 100%)) 360px;
  gap: 2rem;
  width: 100%;
  align-items: start;
  animation: fadeInUp .5s var(--ease);
  /* Ensure the image top sits 25px below the top menu when scrolled into view */
  scroll-margin-top: 25px;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}
.feed-item:last-child,
.result:last-child {
  border-bottom: none;
}
.result[hidden] { display: none; }
.upload-name[hidden],
#btn-upload-clear[hidden] { display: none; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-image-wrap {
  position: relative;
  /* aspect-ratio is set per-image at runtime via --img-aspect (e.g. "16/9") */
  aspect-ratio: var(--img-aspect, 3 / 2);
  /* Width fills the grid cell completely — the cell itself is already capped
     at --img-natural-w via the grid-template-columns rule above, so the image
     can never exceed its natural pixel size. */
  width: 100%;
  max-height: calc(100vh - 220px); /* don't let portrait images blow past the viewport */
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Floating action buttons over the generated image */
.image-actions {
  position: absolute;
  top: .5rem;
  right: .5rem;
  display: flex;
  gap: .35rem;
  opacity: 0;
  transition: opacity .15s var(--ease);
  z-index: 2;
  pointer-events: none;
}
.result-image-wrap:hover .image-actions,
.result-image-wrap:focus-within .image-actions {
  pointer-events: auto;
}
.result-image-wrap:hover .image-actions,
.result-image-wrap:focus-within .image-actions {
  opacity: 1;
}
@media (hover: none) {
  /* on touch devices: always show */
  .image-actions { opacity: 1; }
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--fg);
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.btn-icon:hover {
  background: rgba(0,0,0,.75);
  border-color: rgba(255,255,255,.4);
  transform: translateY(-1px);
}
.btn-icon:active { transform: translateY(0); }
.btn-icon svg { display: block; }

/* Image inside the wrap fills its container fully and is contained — never cropped.
   Targets both the legacy #result-image and the feed-template <img data-image>. */
#result-image,
.result-image-wrap img,
.result-image-wrap [data-image] {
  width: 100%;
  height: 100%;
  /* contain = never crop. Image keeps its native aspect ratio inside the wrapper. */
  object-fit: contain;
  display: block;
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.meta-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .15em;
  color: var(--fg-faint);
  font-weight: 500;
}

.meta-prompt {
  font-size: .95rem;
  line-height: 1.6;
  color: var(--fg);
  max-height: 40vh;
  overflow-y: auto;
}

.meta-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.meta-head .meta-label { flex: 1; min-width: 0; }
.meta-head .meta-tag   { flex-shrink: 0; }

/* Tiny round close/delete button in meta-head */
.btn-icon-tiny {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--purple-faint);
  background: transparent;
  color: var(--purple);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: all .15s var(--ease);
  flex-shrink: 0;
}
.btn-icon-tiny:hover {
  border-color: rgba(239, 68, 68, .6);
  color: rgba(239, 68, 68, 1);
  background: rgba(239, 68, 68, .08);
}
.btn-icon-tiny:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(185, 143, 250, .2);
}

/* Toolbar directly under the prompt textarea (Copy button row) */
.prompt-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-top: .4rem;
  margin-bottom: .25rem;
}
.prompt-toolbar .btn-tiny {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
.prompt-toolbar svg {
  display: block;
  flex-shrink: 0;
}

.prompt-editor {
  width: 100%;
  resize: vertical;
  min-height: 7.5rem;
  max-height: 40vh;
  padding: .8rem .9rem;
  font-family: inherit;
  font-size: .9rem;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  transition: border-color .2s var(--ease);
}
.prompt-editor:focus {
  border-color: var(--purple-soft);
}
.prompt-editor::placeholder {
  color: var(--fg-faint);
}

.quality-hint {
  margin: 0;
  padding: .65rem .85rem;
  font-size: .72rem;
  line-height: 1.45;
  color: var(--purple);
  background: rgba(185, 143, 250, 0.06);
  border: 1px solid var(--purple-faint);
  border-radius: 6px;
  letter-spacing: .005em;
}
.quality-hint[hidden] { display: none; }
.quality-hint strong {
  font-weight: 500;
  color: #d3b8ff;
}
.quality-hint em {
  font-style: normal;
  font-weight: 500;
  color: #d3b8ff;
}

.rationale {
  font-size: .78rem;
  color: var(--fg-faint);
  line-height: 1.45;
  font-style: italic;
  min-height: 1em;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .78rem;
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
}
.checkbox input {
  accent-color: var(--fg);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.meta-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.btn-sm {
  padding: .55rem 1rem;
  font-size: .82rem;
}
.btn-tiny {
  padding: .3rem .6rem;
  font-size: .72rem;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-top: .5rem;
  flex-wrap: wrap;
}

/* Input-mode group: checkbox + dropdown side-by-side */
.input-mode {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

.input-mode-select {
  background: transparent;
  color: var(--purple);
  border: 1px solid var(--purple-faint);
  border-radius: 999px;
  padding: .25rem .55rem;
  font-size: .72rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--purple) 50%), linear-gradient(135deg, var(--purple) 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 8px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  padding-right: 22px;
  transition: color .15s var(--ease), border-color .15s var(--ease);
}
.input-mode-select:hover,
.input-mode-select:focus {
  color: var(--fg);
  border-color: var(--purple-soft);
}
.input-mode-select option {
  background: var(--bg-soft);
  color: var(--fg);
}
/* Disable input-mode select when checkbox is unchecked (purely visual hint) */
.input-mode:has(input[type="checkbox"]:not(:checked)) .input-mode-select {
  opacity: .35;
  pointer-events: none;
}

.meta-tag {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--fg-dim);
  padding: .25rem .6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
}

@media (max-width: 1024px) {
  .stage {
    grid-template-columns: 1fr;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .sidebar {
    position: static;
    max-height: none;
    /* Stack horizontally on tablet — controls + mic side-by-side */
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
  }
  .feed {
    max-height: none;
    overflow-y: visible;
    padding-top: 1.5rem;
  }
  .feed-item,
  .result {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 900px;
  }
  .result-image-wrap {
    max-height: 70vh;
  }
}

@media (max-width: 720px) {
  .stage {
    padding: 1rem 1rem 1.5rem;
  }
  .sidebar {
    flex-direction: column;
  }
  .feed-item,
  .result {
    gap: 1.25rem;
  }
  .result-image-wrap {
    max-height: 60vh;
  }
}

/* -------- Controls (style / model / upload) -------- */

/* Legacy .controls-wrap kept as no-op for any external references */
.controls-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: .75rem 1rem;
  width: 100%;
  max-width: 760px;
}

/* In the sidebar, controls stack vertically and align left, full width */
.sidebar .controls {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: flex-start;
  gap: .9rem;
  max-width: none;
  width: 100%;
}
.sidebar .ctrl {
  width: 100%;
  align-items: stretch;
}
.sidebar .ctrl-select {
  width: 100%;
  min-width: 0;
  max-width: none;
}
.sidebar .ctrl-upload .upload-trigger {
  width: 100%;
  justify-content: flex-start;
}

.ctrl {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-width: 0;
}

.ctrl-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .15em;
  color: var(--fg-faint);
  font-weight: 500;
}

.ctrl-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%23b98ffa' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/%3E%3C/svg%3E") no-repeat right .8rem center;
  border: 1px solid var(--purple-faint);
  border-radius: 999px;
  color: var(--fg);
  font-family: inherit;
  font-size: .82rem;
  padding: .5rem 2rem .5rem .9rem;
  cursor: pointer;
  min-width: 180px;
  max-width: 240px;
  transition: border-color .2s var(--ease);
}
.ctrl-select:hover {
  border-color: var(--purple-soft);
}
.ctrl-select:focus {
  outline: none;
  border-color: var(--purple-soft);
  box-shadow: 0 0 0 3px rgba(185, 143, 250, 0.12);
}
.ctrl-select option,
.ctrl-select optgroup {
  background: var(--bg);
  color: var(--fg);
}

.ctrl-upload .upload-trigger {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  height: 36px;
}

.upload-name {
  font-size: .75rem;
  color: var(--fg-dim);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .ctrl-select {
    min-width: 0;
    max-width: none;
    width: 100%;
  }
  .ctrl-upload .upload-trigger {
    justify-content: flex-start;
  }
}

/* -------- Status -------- */

.status {
  font-size: .9rem;
  color: var(--fg-dim);
  text-align: center;
  max-width: 90vw;
  min-height: 1.4em;
  /* most status text is non-interactive, but interactive children
     (e.g. inline fallback button) still need to be clickable */
  pointer-events: none;
  margin: .5rem auto 1.25rem;
  transition: opacity .3s var(--ease);
}
.status > button,
.status > a {
  pointer-events: auto;
}
.status[data-kind="error"] {
  color: #ff8a7a;
}
.status .fallback-msg {
  margin-right: .5rem;
}
.btn-inline-fallback {
  display: inline-block;
  padding: .35rem .75rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.06);
  color: var(--fg);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.btn-inline-fallback:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.4);
  transform: translateY(-1px);
}
.btn-inline-fallback:active {
  transform: translateY(0);
}

/* -------- Mic button -------- */

.mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.mic {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: var(--fg);
  color: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-mic);
  transition: transform .15s var(--ease), background .2s var(--ease);
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: none;
}

.mic:active,
.mic.is-recording {
  transform: scale(.96);
  background: #fafaf9;
}

.mic-icon {
  width: 36px;
  height: 36px;
  position: relative;
  z-index: 2;
}

.mic-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4);
  opacity: 0;
  pointer-events: none;
}

.mic.is-recording .mic-ring {
  animation: pulse 1.6s var(--ease) infinite;
}
.mic.is-recording .mic-ring-2 {
  animation: pulse 1.6s var(--ease) infinite;
  animation-delay: .8s;
}

@keyframes pulse {
  0%   { opacity: .6; transform: scale(1); }
  100% { opacity: 0;  transform: scale(1.7); }
}

.mic:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.mic-hint {
  font-size: .8rem;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: .15em;
  user-select: none;
}

/* -------- Microphone device picker -------- */
.mic-device-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  width: 100%;
  max-width: 320px;
}
.mic-device-row[hidden] { display: none; }

.mic-device-label {
  font-size: .68rem;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: .15em;
  user-select: none;
}

.mic-device-select {
  width: 100%;
  padding: .45rem .7rem;
  background: rgba(0,0,0,0.25);
  color: var(--purple);
  border: 1px solid var(--purple-faint);
  border-radius: 8px;
  font-family: inherit;
  font-size: .8rem;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--purple) 50%), linear-gradient(135deg, var(--purple) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2rem;
  transition: border-color .15s var(--ease);
}
.mic-device-select:hover,
.mic-device-select:focus {
  border-color: var(--purple-soft);
  outline: none;
}
.mic-device-select option {
  background: #232323;
  color: var(--purple);
}

/* -------- Live audio level meter -------- */
.mic-level {
  width: 96px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
  margin-top: -.5rem;
}
.mic-level[hidden] { display: none; }

.mic-level-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--purple-soft), var(--purple));
  border-radius: 999px;
  transition: width 80ms linear, background 200ms var(--ease);
}
.mic-level-bar.is-silent {
  background: rgba(239, 68, 68, 0.6);
}

/* -------- Stop button (during generation) -------- */
.btn-stop {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin-top: .5rem;
  padding: .35rem .85rem .35rem .65rem;
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--purple-faint);
  border-radius: 999px;
  font-family: inherit;
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease);
}
.btn-stop[hidden] { display: none; }
.btn-stop:hover {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.06);
}
.btn-stop svg {
  display: block;
  opacity: .85;
}

/* -------- Loading state -------- */

.is-busy .mic { opacity: .6; cursor: progress; }

.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--fg-faint);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: -2px;
  margin-right: .5rem;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -------- Brand logo (bottom-left, fixed) -------- */
.brand-logo {
  position: fixed;
  left: 40px;
  bottom: 40px;
  width: 110px;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  z-index: 100;
  opacity: .92;
}
@media (max-width: 640px) {
  .brand-logo {
    left: 20px;
    bottom: 20px;
    width: 80px;
  }
}

/* ============================================================
   SCRIPT MODE — Director + DOP workflow
   Sidebar toggle, script upload, storyboard panel, scene cards,
   bible approval modal.
   ============================================================ */

/* -------- Sidebar: Script Mode toggle switch + inline upload -------- */
.ctrl-script .script-mode-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0 0;
  flex-wrap: wrap;
}

/* Toggle switch (proper iOS-style) */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: var(--fg-dim);
}
.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  transition: background 0.2s var(--ease);
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--fg);
  border-radius: 50%;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle[aria-checked="true"] .toggle-track {
  background: var(--purple);
}
.toggle[aria-checked="true"] .toggle-thumb {
  transform: translateX(16px);
  background: #fff;
}
.toggle[aria-checked="true"] .toggle-label {
  color: var(--purple);
}
.toggle-label {
  font-size: 13px;
  white-space: nowrap;
}
.toggle:hover .toggle-track {
  background: rgba(255, 255, 255, 0.2);
}
.toggle[aria-checked="true"]:hover .toggle-track {
  background: var(--purple-soft);
}
.toggle:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 999px;
}

.script-upload-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.script-upload-inline[hidden] { display: none; }

/* -------- Storyboard panel (lives above feed) -------- */
.script-panel {
  margin: 0 0 24px;
  padding: 18px 20px;
  background: rgba(185, 143, 250, 0.04);
  border: 1px solid var(--purple-faint, rgba(185, 143, 250, 0.18));
  border-radius: 14px;
}
.script-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.script-panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg);
}
.script-panel-actions {
  display: flex;
  gap: 8px;
}
.script-status {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--fg-dim);
  min-height: 1em;
}

/* -------- Bible summary block (collapsed view in panel) -------- */
.script-bible-summary {
  padding: 12px 14px;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--fg-dim);
  line-height: 1.5;
}
.script-bible-summary strong { color: var(--fg); font-weight: 600; }
.script-bible-summary .bible-row { margin-bottom: 6px; }
.script-bible-summary .bible-row:last-child { margin-bottom: 0; }
.script-bible-summary .bible-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 4px;
}
.script-bible-summary .bible-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(185, 143, 250, 0.12);
  border-radius: 4px;
  font-size: 11px;
  color: var(--purple);
}

/* -------- Shot cards -------- */
.script-shots {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.script-scene-group {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.script-scene-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  user-select: none;
}
.script-scene-head:hover { background: rgba(255, 255, 255, 0.04); }
.script-scene-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}
.script-scene-title .scene-meta {
  font-weight: 400;
  color: var(--fg-dim);
  margin-left: 8px;
}
.script-scene-toggle {
  font-size: 12px;
  color: var(--fg-dim);
  transition: transform 0.2s var(--ease);
}
.script-scene-group[data-collapsed="true"] .script-scene-toggle {
  transform: rotate(-90deg);
}
.script-scene-group[data-collapsed="true"] .script-scene-body {
  display: none;
}
.script-scene-body {
  padding: 6px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Individual shot card */
.script-shot-card {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s var(--ease);
}
.script-shot-card:hover { background: rgba(255, 255, 255, 0.04); }
.script-shot-num {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--purple);
  padding-top: 2px;
}
.script-shot-body { font-size: 12.5px; line-height: 1.5; color: var(--fg-dim); }
.script-shot-body .shot-type {
  font-weight: 600;
  color: var(--fg);
  margin-right: 6px;
}
.script-shot-body .shot-action { display: block; margin-top: 4px; }
.script-shot-body .shot-note {
  display: block;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--fg-faint);
  font-style: normal;
}
.script-shot-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.script-shot-card[data-status="generating"] {
  border-left: 2px solid var(--purple);
  background: rgba(185, 143, 250, 0.05);
}
.script-shot-card[data-status="done"] .script-shot-num::after {
  content: " ✓";
  color: #6fcf97;
}

/* -------- Modal -------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: min(820px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--fg-dim);
}
.modal-body h3 {
  margin: 18px 0 8px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--purple);
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body .bible-block {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
}
.modal-body .bible-block strong { color: var(--fg); font-weight: 600; }
.modal-body textarea.bible-json-edit {
  width: 100%;
  min-height: 320px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}
