:root {
  color-scheme: dark;
  --bg: #07080a;
  --ink: #f7f3e9;
  --muted: #9ea3ad;
  --soft: rgba(255, 255, 255, 0.055);
  --soft-strong: rgba(255, 255, 255, 0.085);
  --panel: rgba(15, 17, 21, 0.94);
  --panel-strong: #14171d;
  --line: rgba(255, 255, 255, 0.11);
  --line-strong: rgba(255, 255, 255, 0.22);
  --amber: #f4b84f;
  --coral: #ff6b55;
  --mint: #38d8b5;
  --blue: #78a7ff;
  --danger: #ff867d;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
  font-family: "Segoe UI", Inter, ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(90deg, rgba(255, 107, 85, 0.08), transparent 22%),
    linear-gradient(180deg, rgba(56, 216, 181, 0.08), transparent 34%),
    var(--bg);
  color: var(--ink);
  overflow: auto;
}

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

button {
  border: 0;
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

.studio-root {
  display: grid;
  grid-template-rows: auto auto;
  min-height: 100vh;
}

.studio-header {
  align-items: center;
  background: rgba(7, 8, 10, 0.9);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 10px 18px;
}

.studio-brand {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 210px;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--amber), var(--coral) 48%, var(--mint));
  color: #08090a;
  display: grid;
  font-weight: 950;
  height: 42px;
  justify-content: center;
  letter-spacing: 0;
  border-radius: 8px;
  width: 42px;
}

.studio-brand h1 {
  font-size: 18px;
  line-height: 1;
}

.studio-brand p,
.stage-title span,
.field span,
.control-row span,
.asset-summary,
.upload-drop small,
.mini-upload small {
  color: var(--muted);
}

.studio-brand p {
  font-size: 12px;
  margin-top: 4px;
}

.studio-command {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
}

.api-status,
.generation-message {
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  padding: 10px 12px;
}

.api-status {
  max-width: 520px;
  min-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-status.ready {
  border-color: rgba(56, 216, 181, 0.5);
  color: #bdf6ed;
}

.api-status.missing,
.generation-message.error {
  border-color: rgba(255, 134, 125, 0.65);
  color: #ffd0cb;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-text {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 13px;
}

.primary-button {
  background: linear-gradient(135deg, var(--amber), var(--coral));
  border-color: rgba(244, 184, 79, 0.75);
  color: #130d05;
  font-weight: 950;
}

.secondary-button {
  background: linear-gradient(135deg, var(--mint), var(--blue));
  border-color: rgba(56, 216, 181, 0.75);
  color: #061311;
  font-weight: 900;
}

.ghost-button,
.icon-text {
  background: rgba(255, 255, 255, 0.055);
}

.icon-text {
  color: var(--muted);
  font-size: 12px;
  min-height: 30px;
  padding: 5px 9px;
}

#generateBtn[disabled],
#generateTitleBtn[disabled] {
  cursor: wait;
  opacity: 0.62;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(440px, 1fr) 370px;
  align-items: start;
  min-height: 0;
}

.panel {
  background: var(--panel);
  max-height: calc(100vh - 70px);
  overflow: auto;
  padding: 14px;
}

.asset-panel {
  border-right: 1px solid var(--line);
}

.director-panel {
  border-left: 1px solid var(--line);
}

.control-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  margin-bottom: 12px;
  padding: 14px;
}

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

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.eyebrow {
  color: var(--mint);
  display: block;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.12em;
  margin-bottom: 5px;
  text-transform: uppercase;
}

h2 {
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

.upload-section {
  background:
    linear-gradient(135deg, rgba(244, 184, 79, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(56, 216, 181, 0.11), transparent 42%),
    var(--soft);
}

.upload-drop,
.mini-upload {
  align-items: center;
  background: rgba(8, 10, 13, 0.82);
  border: 1px dashed rgba(255, 255, 255, 0.28);
  color: var(--ink);
  display: grid;
  border-radius: 8px;
  gap: 5px;
  justify-items: center;
  min-height: 98px;
  padding: 14px;
  text-align: center;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.upload-drop:hover,
.mini-upload:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(56, 216, 181, 0.8);
  transform: translateY(-1px);
}

.upload-hero {
  min-height: 168px;
}

.upload-icon {
  align-items: center;
  background: linear-gradient(135deg, var(--amber), var(--mint));
  color: #08100f;
  display: grid;
  font-size: 24px;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  line-height: 1;
  border-radius: 8px;
  width: 42px;
}

.upload-drop strong,
.mini-upload strong {
  font-size: 14px;
}

.upload-drop small,
.mini-upload small {
  font-size: 11px;
  line-height: 1.3;
}

.upload-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.mini-upload.compact {
  min-height: 54px;
}

input[type="file"] {
  display: none;
}

.asset-summary {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  font-size: 12px;
  gap: 6px;
  margin-top: 12px;
  padding: 10px;
}

.asset-summary span {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.asset-summary b {
  color: var(--ink);
  font-weight: 800;
}

.fields,
.layer-editor {
  display: grid;
  gap: 10px;
}

.compact-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide-field {
  grid-column: 1 / -1;
}

label.field,
.control-row {
  display: grid;
  font-size: 11px;
  gap: 6px;
}

.field input,
.field textarea,
.field select,
.control-row input,
.control-row select {
  background: rgba(7, 9, 12, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 38px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: rgba(56, 216, 181, 0.72);
  box-shadow: 0 0 0 3px rgba(56, 216, 181, 0.12);
}

.field textarea {
  min-height: 82px;
  resize: vertical;
}

.template-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.template-card {
  background: #0a0c10;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 78px;
  overflow: hidden;
  padding: 10px;
  position: relative;
  text-align: left;
}

.template-card.active {
  border-color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(244, 184, 79, 0.85);
}

.template-card strong,
.template-card span {
  position: relative;
}

.template-card strong {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.template-card span {
  color: rgba(255, 255, 255, 0.72);
  display: block;
  font-size: 11px;
  line-height: 1.25;
}

.template-swatch {
  inset: 0;
  opacity: 0.44;
  position: absolute;
}

.stage-wrap {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 24%),
    radial-gradient(circle at 50% 0%, rgba(244, 184, 79, 0.18), transparent 35%),
    #090a0d;
  display: grid;
  grid-template-rows: auto auto auto auto;
  min-width: 0;
}

.topbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  padding: 12px 16px;
}

.stage-title {
  display: grid;
  gap: 3px;
}

.stage-title strong {
  font-size: 14px;
}

.stage-title span {
  font-size: 11px;
}

.segmented {
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  padding: 3px;
}

.segmented button {
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  min-width: 64px;
  padding: 8px 10px;
}

.segmented button.active {
  background: var(--mint);
  color: #061513;
  font-weight: 850;
}

.canvas-frame {
  align-items: center;
  display: grid;
  justify-content: center;
  overflow: auto;
  padding: 22px;
}

#posterCanvas {
  background: #151515;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.08);
  display: block;
  border-radius: 2px;
  max-height: calc(100vh - 178px);
  max-width: min(100%, 760px);
}

.generation-message {
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  max-height: 150px;
  overflow: auto;
  white-space: pre-wrap;
}

.generation-message:empty {
  display: none;
}

.layer-list {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.layer-button {
  align-items: center;
  background: rgba(8, 10, 13, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-height: 38px;
  padding: 8px;
  text-align: left;
}

.layer-button.active {
  border-color: var(--mint);
}

.layer-button small {
  color: var(--muted);
}

.layer-dot {
  background: var(--amber);
  display: inline-block;
  height: 8px;
  margin-right: 6px;
  border-radius: 99px;
  width: 8px;
}

.layer-control-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 10px;
  padding: 12px;
}

.field.overlay-control,
.layer-section,
.finish-section {
  display: none;
}

.gallery-strip {
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  padding: 12px 16px 16px;
}

.gallery-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.empty-gallery {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  padding: 18px;
  text-align: center;
}

.gallery-card {
  background: rgba(8, 10, 13, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 8px;
}

.gallery-card img {
  aspect-ratio: 4 / 3;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
    #11141a;
  border-radius: 6px;
  object-fit: contain;
  width: 100%;
}

.gallery-card div {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.gallery-card strong {
  font-size: 12px;
}

.gallery-card span {
  color: var(--muted);
  font-size: 11px;
}

.gallery-card button {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 32px;
}

.title-card-section {
  background:
    linear-gradient(135deg, rgba(120, 167, 255, 0.12), transparent 40%),
    linear-gradient(315deg, rgba(244, 184, 79, 0.12), transparent 42%),
    var(--soft);
}

.title-card-preview {
  background-color: #15171d;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.08) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  margin-bottom: 12px;
  min-height: 142px;
  overflow: hidden;
  place-items: center;
}

#titleCanvas {
  display: block;
  max-width: 100%;
  width: 100%;
}

.title-card-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.layer-control-card h2 {
  margin-bottom: 10px;
}

.two-col {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-row {
  align-items: center;
  grid-template-columns: 88px 1fr;
  margin-bottom: 12px;
}

.check-row {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 34px;
}

.check-row input {
  accent-color: var(--mint);
  height: 16px;
  width: 16px;
}

@media (max-width: 1220px) {
  body {
    overflow: auto;
  }

  .studio-root {
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
  }

  .studio-header,
  .studio-command {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .api-status {
    flex: 1 1 100%;
    max-width: none;
  }

  .app-shell {
    grid-template-columns: 370px minmax(360px, 1fr);
  }

  .director-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-column: 1 / -1;
  }
}

@media (max-width: 920px) {
  .studio-header {
    display: grid;
  }

  .studio-command {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .api-status {
    min-width: 0;
    grid-column: 1 / -1;
  }

  .app-shell {
    display: block;
  }

  .panel {
    border-left: 0;
    border-right: 0;
    max-height: none;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .compact-fields,
  .layer-list,
  .title-card-fields {
    grid-template-columns: 1fr;
  }

  .canvas-frame {
    padding: 14px;
  }
}
