:root {
  color-scheme: dark;
  --bg: #090a0f;
  --panel: rgba(22, 24, 34, 0.78);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f7ff;
  --muted: #9ba4b7;
  --blue: #6d7cff;
  --cyan: #5fddff;
  --violet: #b778ff;
  --green: #4de29a;
  --red: #ff6e79;
  --amber: #ffbd6b;
  --sans: Inter, "SF Pro Display", "PingFang SC", system-ui, sans-serif;
  --mono: "SF Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1180px;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(
      circle at 15% 0,
      rgba(109, 124, 255, 0.19),
      transparent 29rem
    ),
    radial-gradient(
      circle at 90% 15%,
      rgba(183, 120, 255, 0.13),
      transparent 26rem
    ),
    var(--bg);
}

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

button,
a {
  cursor: pointer;
}

.app-shell {
  max-width: 1880px;
  margin: auto;
  padding: 24px 28px 56px;
}

.glass-panel,
.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
}

.topbar {
  position: sticky;
  top: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  margin-bottom: 20px;
}

.brand-block,
.topbar-meta,
.key-row,
.stage-actions,
.image-actions {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #10111a;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 18px;
}

.brand-block p,
.subtle,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.topbar-meta {
  gap: 8px;
}

.studio-layout {
  display: grid;
  grid-template-columns: 230px minmax(700px, 1fr) 270px;
  gap: 18px;
  align-items: start;
}

.workflow-rail,
.task-panel {
  position: sticky;
  top: 100px;
  padding: 18px;
}

.workspace {
  display: grid;
  gap: 16px;
}

.eyebrow {
  color: #7f8aa6;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  margin-bottom: 5px;
}

.step-list {
  display: grid;
  gap: 10px;
  padding: 18px 0 0;
  margin: 0;
  list-style: none;
}

.step-list li {
  display: flex;
  gap: 10px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--muted);
}

.step-list li.active {
  color: var(--text);
  border-color: rgba(109, 124, 255, 0.45);
  background: rgba(109, 124, 255, 0.1);
}

.step-list span {
  font: 700 12px var(--mono);
  color: var(--cyan);
}

.step-list strong,
.step-list small {
  display: block;
}

.step-list strong {
  font-size: 13px;
}

.step-list small {
  font-size: 11px;
  margin-top: 3px;
}

.privacy-note {
  margin-top: 20px;
  padding: 11px;
  border-radius: 11px;
  color: #bac2d2;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11px;
  line-height: 1.55;
}

.settings-card,
.stage-card,
.library-card {
  padding: 20px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.settings-grid,
.stage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

.field {
  display: grid;
  gap: 7px;
}

.field > span,
.field-heading label {
  color: #c6ccda;
  font-size: 12px;
}

.field-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.api-key-link {
  color: var(--cyan);
  font-size: 11px;
  text-decoration: none;
}

.api-key-link:hover {
  text-decoration: underline;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  transition: 0.15s;
}

input,
select {
  min-height: 40px;
}

textarea {
  line-height: 1.55;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(109, 124, 255, 0.16);
}

.key-row {
  gap: 8px;
}

.key-row input {
  font-family: var(--mono);
}

.stage-card {
  position: relative;
  border-color: rgba(255, 255, 255, 0.1);
}

.stage-number {
  position: absolute;
  right: 20px;
  top: 16px;
  color: rgba(109, 124, 255, 0.22);
  font: 800 40px var(--mono);
}

.stage-card .section-heading {
  padding-right: 52px;
}

.stage-grid {
  align-items: stretch;
}

.prompt-column {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
}

.upload-zone {
  display: grid;
  min-height: 132px;
  place-items: center;
  align-content: center;
  gap: 4px;
  border: 1px dashed rgba(95, 221, 255, 0.48);
  border-radius: 13px;
  background: rgba(95, 221, 255, 0.05);
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    box-shadow 0.15s;
}

.upload-zone.is-dragging {
  border-color: var(--cyan);
  background: rgba(95, 221, 255, 0.13);
  box-shadow: 0 0 0 3px rgba(95, 221, 255, 0.12);
}

.upload-zone.compact {
  min-height: 98px;
}

.upload-zone input {
  display: none;
}

.upload-icon {
  font-size: 27px;
  color: var(--cyan);
}

.upload-zone strong {
  font-size: 13px;
}

.upload-zone small {
  color: var(--muted);
  font-size: 11px;
}

.reference-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.reference-thumb {
  position: relative;
  width: 78px;
  height: 78px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.reference-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-thumb button {
  position: absolute;
  right: 4px;
  top: 4px;
  border: 0;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.72);
  color: white;
}

.stage-actions {
  gap: 12px;
  margin-top: 12px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  border-radius: 10px;
  padding: 0 14px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.primary-button {
  border: 0;
  background: linear-gradient(110deg, var(--blue), #875cf5);
  font-weight: 700;
}

.secondary-button {
  border-color: rgba(95, 221, 255, 0.36);
  background: rgba(95, 221, 255, 0.09);
  color: #b9f3ff;
}

.danger-button {
  color: var(--red);
  border-color: rgba(255, 110, 121, 0.38);
  background: rgba(255, 110, 121, 0.08);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: #c5ccda;
  font: 11px var(--mono);
  background: rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}

.badge-warn {
  color: var(--amber);
  border-color: rgba(255, 189, 107, 0.35);
}

.badge-ok {
  color: var(--green);
  border-color: rgba(77, 226, 154, 0.35);
}

.selected-reference {
  min-height: 160px;
}

.selected-reference:not(.empty-state) {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px;
  border: 1px solid rgba(77, 226, 154, 0.35);
  border-radius: 13px;
  background: rgba(77, 226, 154, 0.05);
}

.selected-reference img {
  width: 130px;
  height: 130px;
  object-fit: contain;
  border-radius: 9px;
  background: #111;
}

.selected-reference strong {
  display: block;
  margin-bottom: 7px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 130px;
  border: 1px dashed var(--line);
  border-radius: 13px;
  color: #788197;
  font-size: 13px;
}

.final-stage {
  border-color: rgba(183, 120, 255, 0.35);
  background:
    linear-gradient(135deg, rgba(183, 120, 255, 0.08), transparent 48%),
    var(--panel);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.2);
}

.image-button {
  width: 100%;
  aspect-ratio: 1/1;
  border: 0;
  background: #111;
}

.image-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-info {
  padding: 10px;
}

.image-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.image-title-row strong {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-meta {
  margin: 6px 0;
  color: var(--muted);
  font-size: 10px;
}

.image-actions {
  gap: 6px;
  flex-wrap: wrap;
}

.image-actions button,
.image-actions a {
  min-height: 29px;
  padding: 0 8px;
  font-size: 11px;
}

.library-actions {
  display: flex;
  gap: 8px;
}

.task-list {
  display: grid;
  gap: 9px;
}

.task-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.22);
}

.task-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.task-title {
  font-size: 12px;
}

.task-detail,
.task-error {
  font-size: 11px;
  line-height: 1.5;
}

.task-detail {
  color: var(--muted);
}

.task-error {
  color: var(--red);
}

.mono {
  font-family: var(--mono);
}

.preview-dialog {
  width: min(1100px, calc(100vw - 50px));
  padding: 0;
  border: 0;
  background: transparent;
}

.preview-dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

.preview-shell {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.preview-shell img {
  max-width: 100%;
  max-height: 78vh;
  margin: auto;
  object-fit: contain;
}

.close-button {
  position: absolute;
  right: 14px;
  top: 14px;
}

.preview-meta {
  color: var(--muted);
  font: 11px var(--mono);
  white-space: pre-wrap;
}

@media (max-width: 1320px) {
  .studio-layout {
    grid-template-columns: 210px minmax(650px, 1fr);
  }

  .task-panel {
    display: none;
  }
}
