:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --shell-width: 1780px;
  --panel: #15191f;
  --panel-2: #1c222b;
  --line: #2b3440;
  --ink: #f4f7fb;
  --muted: #9da8b5;
  --soft: #c8d0da;
  --accent: #d8b45b;
  --accent-2: #54c6a0;
  --danger: #d65a5a;
  --blue: #6ca8ff;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Tahoma, Arial, sans-serif;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, #0f1318 0%, var(--bg) 48%, #07090c 100%);
  background-size: 56px 56px, auto;
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.studio-shell {
  width: min(var(--shell-width), calc(100vw - 28px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

.topbar,
.metrics-strip,
.panel,
.preview-window,
.timeline-panel {
  border: 1px solid var(--line);
  background: rgba(21, 25, 31, 0.94);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(21, 25, 31, 0.98), rgba(28, 34, 43, 0.96) 62%, rgba(216, 180, 91, 0.14)),
    var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8f6c22);
  color: #15110a;
  font-size: 36px;
  font-weight: 900;
}

.kicker {
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 3vw, 44px);
  line-height: 1.1;
}

.brand p,
.timeline-head p,
.drop-zone small {
  color: var(--muted);
  line-height: 1.6;
}

.top-actions,
.timeline-actions,
.scene-tools,
.export-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.export-target {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 900;
}

.live-video-note {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid rgba(84, 198, 160, 0.34);
  border-radius: 8px;
  background: rgba(84, 198, 160, 0.09);
}

.live-video-note strong {
  display: block;
  margin-bottom: 6px;
  color: #9ef2d4;
}

.live-video-note p {
  color: var(--soft);
  line-height: 1.7;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202733;
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}

.icon-button:hover {
  border-color: rgba(216, 180, 91, 0.62);
}

.primary-button,
.ghost-button,
.danger-button,
.move-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: #15110a;
}

.ghost-button,
.move-button {
  border-color: var(--line);
  background: #202733;
}

.danger-button {
  border-color: rgba(214, 90, 90, 0.36);
  background: rgba(214, 90, 90, 0.14);
  color: #ffd1d1;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 12px 0;
  border-radius: 8px;
  overflow: hidden;
}

.metrics-strip div {
  min-height: 70px;
  display: grid;
  place-items: center;
  align-content: center;
  background: rgba(28, 34, 43, 0.72);
}

.metrics-strip strong {
  font-size: 24px;
  color: var(--accent-2);
}

.metrics-strip span {
  color: var(--muted);
  font-size: 13px;
}

.production-settings {
  display: grid;
  grid-template-columns: minmax(190px, 260px) minmax(180px, 230px) minmax(180px, 230px) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 25, 31, 0.94);
  box-shadow: var(--shadow);
}

.youtube-format {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid rgba(216, 180, 91, 0.4);
  border-radius: 8px;
  background: rgba(216, 180, 91, 0.1);
}

.youtube-format strong {
  color: var(--accent);
  font-size: 15px;
}

.youtube-format span {
  color: var(--soft);
  font-size: 12px;
}

.production-settings label {
  display: grid;
  gap: 7px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 900;
}

.identity-status {
  display: grid;
  grid-template-columns: 220px minmax(180px, 1fr) 1.6fr;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 25, 31, 0.94);
  box-shadow: var(--shadow);
}

.identity-status div:first-child {
  display: grid;
  gap: 4px;
}

.identity-status span,
.identity-status p {
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.identity-status strong {
  color: var(--accent-2);
  font-size: 20px;
}

.identity-meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #0f141b;
  border: 1px solid var(--line);
}

.identity-meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--accent), var(--accent-2));
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
  min-width: 0;
  direction: rtl;
}

.left-rail,
.right-rail {
  display: grid;
  gap: 12px;
  direction: rtl;
}

.left-rail {
  grid-column: 1;
  grid-row: 2;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.center-stage {
  grid-column: 1;
  grid-row: 1;
}

.right-rail {
  grid-column: 1;
  grid-row: 3;
  grid-template-columns: minmax(320px, 420px) minmax(320px, 1fr);
  align-items: start;
}

.panel,
.preview-window,
.timeline-panel {
  border-radius: 8px;
}

.panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(216, 180, 91, 0.14);
  color: var(--accent);
  font-weight: 900;
}

.panel h2,
.timeline-head h2 {
  font-size: 18px;
  line-height: 1.25;
}

.drop-zone {
  min-height: 120px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  padding: 16px;
  border: 1px dashed #4b5868;
  border-radius: 8px;
  background: #10141a;
  text-align: center;
}

.drop-zone input {
  display: none;
}

.hidden-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.identity-fields {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.identity-fields label {
  display: grid;
  gap: 6px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 900;
}

.identity-fields textarea {
  min-height: 68px;
  resize: vertical;
}

.thumb {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  width: 100%;
  background: #0d1117;
}

.scene-tools {
  margin-top: 10px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #0f141b;
  color: var(--ink);
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(216, 180, 91, 0.74);
}

#storyInput {
  min-height: 180px;
  resize: vertical;
}

.center-stage {
  display: grid;
  gap: 12px;
  min-width: 0;
  direction: rtl;
}

.preview-window {
  overflow: hidden;
  min-width: 0;
  width: min(100%, 1180px);
  max-width: 1180px;
  margin-inline: auto;
}

.preview-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 1120px);
  max-height: 630px;
  margin-inline: auto;
  aspect-ratio: 16 / 9;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  direction: ltr;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, #111821, #07090c);
  background-size: 48px 48px, auto;
}

.preview-frame img,
.preview-frame video,
.preview-media {
  position: static;
  z-index: 1;
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: 50% 50%;
  border-radius: 6px;
  background: #05070a;
}

.preview-media-box {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0;
  background: #05070a;
}

.preview-media-box.youtube-image-preview {
  isolation: isolate;
}

.youtube-fill-bg,
.youtube-safe-image {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: 50% 50%;
}

.youtube-fill-bg {
  z-index: 0;
  background-size: cover;
  filter: blur(18px) saturate(1.05) brightness(0.62);
  transform: scale(1.08);
}

.youtube-fill-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
}

.youtube-safe-image {
  z-index: 1;
  inset: 2.8%;
  background-size: contain;
}

.preview-media-box img,
.preview-media-box video {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center center;
}

.generated-still-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.generated-still-label {
  position: absolute;
  right: 18px;
  bottom: 18px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.66);
  color: #f6e5b5;
  font-size: 13px;
}

.preview-empty {
  display: grid;
  gap: 6px;
  text-align: center;
  color: var(--muted);
}

.preview-empty strong {
  color: var(--ink);
  font-size: 22px;
}

.camera-overlay {
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(216, 180, 91, 0.54);
  pointer-events: none;
}

.camera-overlay::before,
.camera-overlay::after {
  content: "";
  position: absolute;
  inset-inline: 18%;
  top: 50%;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
}

.camera-overlay::after {
  inset-inline: auto;
  top: 18%;
  bottom: 18%;
  right: 50%;
  border-top: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.22);
}

.preview-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  min-height: 58px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.preview-caption strong,
.preview-caption span {
  min-width: 0;
}

.preview-caption span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-panel {
  padding: 14px;
  width: min(100%, 1180px);
  margin-inline: auto;
}

.timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.timeline {
  min-height: 220px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 170px;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.scene-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #10151c;
}

.scene-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(216, 180, 91, 0.22);
}

.scene-thumb {
  width: 100%;
  height: 96px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: linear-gradient(135deg, #1d2632, #0d1117);
  color: var(--muted);
  font-weight: 900;
  padding: 0;
}

.scene-thumb img,
.scene-thumb video {
  width: 100%;
  height: 96px;
  object-fit: contain;
  background: #070a0e;
}

.scene-thumb b {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.66);
  color: var(--accent);
  font-size: 11px;
}

.scene-thumb em {
  font-style: normal;
  color: var(--accent);
  font-size: 12px;
}

.scene-thumb:hover {
  background: linear-gradient(135deg, rgba(216, 180, 91, 0.2), #111821);
}

.scene-card-body {
  padding: 9px;
}

.scene-card strong {
  display: block;
  min-height: 38px;
  line-height: 1.35;
  font-size: 13px;
}

.scene-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.4;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 8px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.status-pill.is-generating {
  border-color: rgba(216, 180, 91, 0.5);
  color: var(--accent);
}

.status-pill.is-ready {
  border-color: rgba(84, 198, 160, 0.55);
  color: #9ef2d4;
}

.status-pill.is-failed {
  border-color: rgba(214, 90, 90, 0.55);
  color: #ffd1d1;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 8px;
}

.move-button {
  min-height: 30px;
  padding: 0;
}

.scene-editor label {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 900;
}

.risk-card {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151c;
}

.risk-card span,
.risk-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.risk-card strong {
  color: var(--accent-2);
  font-size: 18px;
}

.generation-card {
  display: grid;
  gap: 9px;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(84, 198, 160, 0.34);
  border-radius: 8px;
  background: rgba(84, 198, 160, 0.08);
}

.generation-card > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.generation-card span,
.generation-card p {
  color: var(--muted);
  line-height: 1.5;
}

.generation-card strong {
  color: #9ef2d4;
}

.generation-meter {
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(84, 198, 160, 0.28);
  border-radius: 999px;
  background: #0e1515;
}

.generation-meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 240ms ease;
}

.generation-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.generation-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.scene-editor textarea {
  min-height: 80px;
  resize: vertical;
}

.empty-editor {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

#exportPreview {
  min-height: 310px;
  margin-top: 10px;
  direction: ltr;
  text-align: left;
  font-family: Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.56);
}

.settings-drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(460px, 100%);
  display: grid;
  align-content: start;
  gap: 14px;
  overflow-y: auto;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #11161d;
  box-shadow: var(--shadow);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.settings-head span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.settings-head h2,
.settings-section h3 {
  margin: 0;
}

.settings-section {
  display: grid;
  gap: 11px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151b23;
}

.settings-section label {
  display: grid;
  gap: 7px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 900;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.settings-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 1180px) {
  .workspace,
  .right-rail {
    grid-template-columns: 1fr;
  }

  .left-rail,
  .center-stage,
  .right-rail {
    grid-column: 1;
    grid-row: auto;
  }

  .workspace {
    direction: rtl;
  }

  .left-rail,
  .right-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .studio-shell {
    width: min(100% - 18px, 1780px);
  }

  .topbar,
  .timeline-head,
  .preview-caption {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics-strip,
  .identity-status,
  .production-settings,
  .left-rail,
  .right-rail {
    grid-template-columns: 1fr;
  }

  .brand {
    align-items: flex-start;
  }
}
