/* SovoGen studio framework — workflow compositions + overlap-safe layout. */

.page-studio .content,
.page-character .content,
.page-world .content,
.page-director .content,
.page-feature .content,
.page-create .content,
.page-audio .content {
  width: min(1400px, 100%);
  min-width: 0;
  max-width: 100%;
  overflow: visible;
}

.page-studio .main,
.page-character .main,
.page-world .main,
.page-director .main,
.page-feature .main,
.page-create .main,
.page-audio .main {
  min-width: 0;
}

/* Neutralize the old one-size studio shell that clipped/overlapped. */
.studio-v2.studio-layout {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 16px !important;
  overflow: visible !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  border: 0 !important;
  background: transparent !important;
}
.studio-v2 .studio-panel,
.studio-v2 .canvas-panel {
  max-height: none !important;
  overflow: visible !important;
  min-width: 0;
}

.sg-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  width: 100%;
}

.sg-page__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}
.sg-page__titles { min-width: 0; }
.sg-page__titles h1 {
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
}

.sg-studio {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  width: 100%;
  container-type: inline-size;
}

.sg-tools {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.sg-tools__tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.sg-tools__tab.is-on {
  color: var(--text);
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  background: color-mix(in srgb, var(--primary) 14%, var(--panel));
}

.sg-studio__form {
  display: block;
  min-width: 0;
}

.sg-studio__body {
  display: grid;
  grid-template-columns: minmax(0, 24rem) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.sg-studio[data-layout="audio"] .sg-studio__body,
.sg-studio[data-layout="compare"] .sg-studio__body {
  grid-template-columns: minmax(0, 26rem) minmax(0, 1fr);
}

.sg-studio__editor,
.sg-stage {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.sg-studio__editor {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sg-studio__scroll {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  min-width: 0;
}

.sg-compose {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.sg-compose[hidden] { display: none !important; }
.sg-compose__head h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.sg-field,
.sg-field--prompt {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.sg-field label,
.sg-chips legend,
.sg-expand legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.sg-field textarea,
.sg-field input[type="text"],
.sg-field select,
.sg-field--prompt textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--field-bg, var(--bg-elevated));
  color: var(--field-text, var(--text));
  font: inherit;
  padding: 10px 12px;
}
.sg-field--prompt textarea { min-height: 140px; resize: vertical; }

.sg-chips { border: 0; margin: 0; padding: 0; min-width: 0; }
.sg-chips__row,
.sg-expand__mid,
.sg-expand__pad {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.sg-chip,
.sg-expand__btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.sg-chip.is-on,
.sg-expand__btn.is-on {
  color: var(--text);
  border-color: color-mix(in srgb, var(--primary) 50%, var(--border));
  background: color-mix(in srgb, var(--primary) 16%, var(--panel-2));
}

.sg-expand { border: 0; margin: 0; padding: 0; }
.sg-expand__pad {
  flex-direction: column;
  align-items: center;
}
.sg-expand__mid { justify-content: center; }

.sg-drop {
  position: relative;
  min-width: 0;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  background: var(--tint-soft);
  padding: 14px;
}
.sg-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.sg-drop__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  pointer-events: none;
}
.sg-drop__icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-2, #16151c);
  color: var(--text);
  border: 1px solid var(--border);
}
.sg-drop__icon svg { width: 18px; height: 18px; fill: currentColor; }
.sg-drop:hover .sg-drop__icon,
.sg-drop:focus-within .sg-drop__icon {
  border-color: color-mix(in srgb, var(--text) 30%, transparent);
  background: var(--panel, #1f1d27);
}
.sg-drop__frame img,
.sg-drop__frame video,
.sg-drop__frame audio {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
}
.sg-drop.is-on { border-color: var(--primary); }

.sg-preview-slot {
  min-width: 0;
  min-height: 120px;
  border-radius: 14px;
  background: var(--tint);
  display: grid;
  place-items: center;
}
.sg-preview-slot img,
.sg-preview-slot video {
  max-width: 100%;
  max-height: 280px;
  border-radius: 12px;
}
.sg-preview-slot:empty { display: none; }

.sg-mask { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sg-mask[hidden] { display: none !important; }
.sg-mask__toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.sg-mask__stage {
  min-width: 0;
  border-radius: 12px;
  background: var(--tint);
}
.sg-mask__stage canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.sg-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.sg-preserve {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.sg-preserve legend {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.sg-feature-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary-text);
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
}

.sg-compare-wrap { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sg-compare-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.sg-compare-slider {
  position: relative;
  min-width: 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--tint);
}
.sg-compare-slider__base,
.sg-compare-slider__top {
  min-width: 0;
}
.sg-compare-slider__top {
  position: absolute;
  inset: 0;
  clip-path: inset(0 50% 0 0);
  pointer-events: none;
}
.sg-compare-slider video,
.sg-compare-slider img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
}
.sg-compare-slider input[type="range"] {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 10px;
  width: calc(100% - 16px);
  z-index: 2;
}

.sg-wave {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 48px;
  padding: 8px 4px;
}
.sg-wave span {
  flex: 1;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 55%, var(--panel-2));
  min-height: 8px;
  animation: sg-wave 1.2s ease-in-out infinite alternate;
}
.sg-wave span:nth-child(2) { animation-delay: .1s; height: 60%; }
.sg-wave span:nth-child(3) { animation-delay: .2s; height: 90%; }
.sg-wave span:nth-child(4) { animation-delay: .15s; height: 40%; }
.sg-wave span:nth-child(5) { animation-delay: .25s; height: 75%; }
.sg-wave span:nth-child(6) { animation-delay: .05s; height: 50%; }
.sg-wave span:nth-child(7) { animation-delay: .3s; height: 85%; }
.sg-wave span:nth-child(8) { animation-delay: .18s; height: 35%; }
@keyframes sg-wave {
  from { transform: scaleY(0.45); }
  to { transform: scaleY(1); }
}

.sg-more {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.sg-more summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.sg-cast-pick__chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sg-cast-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  cursor: pointer;
}
.sg-cast-chip:has(input:checked) { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); }
.sg-cast-chip input { margin: 0; }

.sg-generate {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  min-width: 0;
}
.sg-generate__cost {
  display: flex;
  flex-direction: column;
  margin-right: auto;
  min-width: 0;
}
.sg-generate .btn { min-width: 0; }
.sg-errors {
  color: var(--danger);
  font-size: 13px;
  padding: 0 16px 14px;
}

.sg-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px;
  gap: 12px;
}
.sg-stage__tabs {
  display: flex;
  gap: 8px;
  min-width: 0;
}
.sg-stage__tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 6px 2px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.sg-stage__tab.is-on {
  color: var(--text);
  border-bottom-color: var(--primary);
}
.sg-stage__panel { min-width: 0; }
.sg-stage__panel[hidden] { display: none !important; }

.sg-state {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.sg-state__art {
  min-height: 160px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, var(--tint), transparent),
    repeating-linear-gradient(-12deg, transparent, transparent 12px, var(--hairline) 13px);
}
.sg-state.is-busy .sg-state__art {
  background: linear-gradient(90deg, var(--tint), var(--panel-2), var(--tint));
  background-size: 200% 100%;
  animation: sg-shimmer 1.2s linear infinite;
}
@keyframes sg-shimmer {
  to { background-position: -200% 0; }
}

.sg-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: lowercase;
  background: var(--tint);
  color: var(--muted);
}
.sg-badge[data-status="queued"] { color: var(--warning-text); background: color-mix(in srgb, var(--warning) 16%, transparent); }
.sg-badge[data-status="processing"],
.sg-badge[data-status="loading"] { color: var(--primary-text); background: var(--primary-soft); }
.sg-badge[data-status="completed"],
.sg-badge[data-status="success"] { color: var(--success-text); background: color-mix(in srgb, var(--success) 16%, transparent); }
.sg-badge[data-status="failed"],
.sg-badge[data-status="failure"] { color: var(--danger-text); background: color-mix(in srgb, var(--danger) 16%, transparent); }

.sg-output { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sg-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  gap: 10px;
  min-width: 0;
}
.sg-gallery img,
.sg-output video,
.sg-output audio {
  width: 100%;
  max-width: 100%;
  border-radius: 12px;
}
.sg-compare {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}
.sg-compare figure {
  margin: 0;
  min-width: 0;
}
.sg-compare figcaption {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.sg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.sg-history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.sg-history__item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  min-width: 0;
}
.sg-history__item:hover { border-color: var(--border-strong); }
.sg-history__meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.sg-sheet { display: none; }
.sg-sheet-launch { display: none; }

/* Character / world / director — same language, specialized UX */
.sg-cast,
.sg-world,
.sg-director {
  display: grid;
  grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}
.sg-cast__form,
.sg-world__form,
.sg-director__form,
.sg-cast__board,
.sg-world__board,
.sg-director__board {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
}
.sg-cast-card {
  display: flex;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-2);
}

.sg-director .director-scene {
  margin: 0 0 16px;
  min-width: 0;
}
.sg-director .director-scene header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.sg-director-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}
.sg-director-steps li {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted, #8a8494);
}
.sg-director-steps li.is-done,
.sg-director-steps li.is-on {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  color: var(--text);
}
.sg-director-decisions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
}
.sg-director-decisions span {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.sg-director-queue .sg-state {
  padding: 8px 0;
}

.sg-library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0 0 16px;
}
.sg-library-filters input[type="search"] {
  flex: 1 1 180px;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
}
.sg-library-filters .sg-prod__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sg-library-filters .sg-prod__chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.sg-library-filters .sg-prod__chip.is-on {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--border));
  background: color-mix(in srgb, var(--primary) 12%, var(--panel));
}

.sg-cast__grid,
.sg-world__scenes,
.sg-director .shot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  min-width: 0;
}

@media (max-width: 1100px) {
  .sg-studio[data-layout="split"] .sg-studio__body,
  .sg-studio[data-layout="audio"] .sg-studio__body,
  .sg-studio[data-layout="compare"] .sg-studio__body,
  .sg-cast,
  .sg-world,
  .sg-director {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 800px) {
  .sg-studio__body,
  .sg-studio[data-layout="split"] .sg-studio__body,
  .sg-studio[data-layout="audio"] .sg-studio__body,
  .sg-studio[data-layout="compare"] .sg-studio__body,
  .sg-compare,
  .sg-cast,
  .sg-world,
  .sg-director {
    grid-template-columns: minmax(0, 1fr);
  }

  .sg-generate {
    position: sticky;
    bottom: calc(var(--mobile-nav-h, 64px) + env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 5;
    background: var(--panel);
  }

  .sg-studio__scroll {
    padding-bottom: 5.5rem;
  }

  .sg-sheet-launch {
    display: inline-flex;
  }

  .sg-sheet:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0, 0, 0, 0.45);
  }
  .sg-more.is-sheet {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--mobile-nav-h, 64px) + env(safe-area-inset-bottom, 0px) + 8px);
    z-index: 80;
    max-height: min(70vh, 560px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 14px;
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .sg-page__head { flex-direction: column; }
  .sg-field--prompt textarea { min-height: 110px; }
}

