:root {
  color-scheme: dark;
  --bg: #07090e;
  --panel: #111722;
  --panel-2: #161d2a;
  --line: #283246;
  --text: #f4f7ff;
  --muted: #91a0b8;
  --blue: #5f94ff;
  --blue-soft: rgba(95, 148, 255, 0.2);
  --gold: #ffd15c;
  --gold-soft: rgba(255, 209, 92, 0.18);
  --purple: #c084fc;
  --purple-soft: rgba(192, 132, 252, 0.16);
  --danger: #ff5d73;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

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

button,
select,
input,
textarea {
  color: var(--text);
  background: #0b1019;
  border: 1px solid var(--line);
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.studio-shell {
  width: min(980px, 100%);
  min-height: calc(100vh - 24px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.studio-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.05;
}

.top-actions,
.actions,
.settings-row {
  display: flex;
  gap: 8px;
}

.ghost-btn,
.secondary-btn,
.primary-btn {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 760;
}

.ghost-btn,
.secondary-btn {
  background: #121929;
}

.primary-btn {
  flex: 1;
  background: linear-gradient(180deg, #6da0ff, #386eea);
  border-color: #74a8ff;
  box-shadow: 0 0 0 1px rgba(116, 168, 255, 0.18), 0 10px 26px rgba(54, 111, 234, 0.28);
}

.secondary-btn {
  width: 86px;
  color: #dfe8ff;
}

.engine-strip {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 34, 0.78);
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #4b5568;
  flex: 0 0 auto;
}

.status-dot.ready {
  background: #45dd86;
  box-shadow: 0 0 12px rgba(69, 221, 134, 0.65);
}

.status-dot.busy {
  background: var(--gold);
  animation: pulse 1s ease-in-out infinite;
}

.status-dot.bad {
  background: var(--danger);
  box-shadow: 0 0 12px rgba(255, 93, 115, 0.5);
}

.result-panel {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 7px;
}

.result-frame {
  position: relative;
  width: min(100%, 390px);
  aspect-ratio: 9 / 16;
  max-height: 58vh;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid #303b51;
  background: #05070b;
  box-shadow: 0 0 0 1px rgba(95, 148, 255, 0.1), 0 22px 60px rgba(0, 0, 0, 0.36);
}

.result-frame.wide {
  width: min(100%, 760px);
  aspect-ratio: 16 / 9;
}

#outputImage {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: #748198;
  font-size: 12px;
  line-height: 1.35;
}

.result-size {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 3px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.55);
  color: #d7def0;
  font-size: 10px;
}

.meter {
  width: min(100%, 320px);
  height: 4px;
  border-radius: 99px;
  overflow: hidden;
  background: #151b28;
}

.meter-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), #a7c2ff);
  transition: width 180ms ease;
}

.phase-text {
  min-height: 14px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.drawer,
.prompt-panel,
.debug-panel {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
}

.drawer > summary,
.debug-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 11px;
  color: #dce6ff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.drawer > summary::-webkit-details-marker,
.debug-panel > summary::-webkit-details-marker {
  display: none;
}

.drawer > summary::after,
.debug-panel > summary::after {
  content: "+";
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #0d1320;
  color: var(--blue);
}

.drawer[open] > summary::after,
.debug-panel[open] > summary::after {
  content: "-";
}

.drawer-tools {
  display: grid;
  grid-template-columns: 1fr 118px;
  gap: 8px;
  padding: 0 10px 9px;
}

.drawer-tools input,
.drawer-tools select {
  min-width: 0;
  height: 32px;
  border-radius: 7px;
  padding: 0 8px;
  font-size: 12px;
}

.tile-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0 10px 10px;
  scrollbar-color: #35435a #101622;
}

.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  padding: 0 10px 10px;
}

.recent-card {
  display: grid;
  gap: 5px;
  border: 1px solid #2b3549;
  border-radius: 8px;
  background: #0c111b;
  padding: 5px;
  color: var(--text);
  text-align: left;
}

.recent-card img {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: 6px;
  background: #05070b;
}

.recent-card.wide img {
  aspect-ratio: 16 / 9;
}

.recent-card span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lora-tile {
  flex: 0 0 84px;
  width: 84px;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-radius: 8px;
  border: 1px solid #2b3549;
  background: #0c111b;
  padding: 6px;
  color: var(--text);
  text-align: left;
}

.lora-tile.character.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 18px var(--gold-soft);
}

.lora-tile.concept.selected {
  border-color: var(--purple);
  box-shadow: 0 0 0 1px var(--purple), 0 0 18px var(--purple-soft);
}

.lora-preview {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #121827;
  color: #8090aa;
  font-size: 10px;
  text-align: center;
}

.lora-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lora-name {
  min-height: 27px;
  color: inherit;
  font-size: 11px;
  line-height: 1.15;
  font-weight: 780;
  overflow: hidden;
}

.lora-type {
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
}

.prompt-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.prompt-panel label {
  display: grid;
  gap: 5px;
}

.prompt-panel span,
.settings-row span {
  color: #9fb0ca;
  font-size: 11px;
  font-weight: 800;
}

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border-radius: 8px;
  padding: 10px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.35;
  outline: none;
}

textarea:focus,
input:focus,
select:focus,
button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-soft);
  outline: none;
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 120px 128px minmax(160px, 1.2fr);
}

.seed-box,
.select-box,
.bridge-box {
  display: grid;
  gap: 5px;
}

.seed-box input,
.select-box select,
.bridge-box input {
  min-width: 0;
  height: 36px;
  border-radius: 8px;
  padding: 0 8px;
  font-size: 12px;
}

.actions {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 5;
  padding-top: 2px;
}

.debug-panel pre {
  max-height: 240px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  border-top: 1px solid var(--line);
  color: #b9c7de;
  font-size: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.screen-pulse {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
  border: 3px solid var(--blue);
  box-shadow: inset 0 0 36px rgba(95, 148, 255, 0.55), 0 0 32px rgba(95, 148, 255, 0.48);
  animation: flash 620ms ease-out forwards;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.75;
  }
  50% {
    transform: scale(1.35);
    opacity: 1;
  }
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 380px) {
  body {
    padding-inline: 8px;
  }

  .settings-row {
    grid-template-columns: 1fr 1fr;
  }

  .settings-row .select-box:last-child {
    grid-column: span 2;
  }
}

@media (max-width: 620px) {
  .settings-row {
    grid-template-columns: 1fr 1fr;
  }

  .bridge-box {
    grid-column: 1 / -1;
  }
}

@media (min-width: 780px) {
  .studio-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    align-items: start;
  }

  .studio-top,
  .engine-strip,
  .result-panel,
  .actions,
  .debug-panel {
    grid-column: 1 / -1;
  }

  .prompt-panel,
  .settings-row {
    grid-column: 1 / 2;
  }

  .drawer,
  .recent-drawer {
    grid-column: 2 / 3;
  }
}
