:root {
  color-scheme: dark;
  --bg: #0d1321;
  --panel: rgba(17, 24, 39, 0.86);
  --panel-strong: #111827;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #9aa4b2;
  --blue: #4285f4;
  --green: #34a853;
  --yellow: #fbbc04;
  --red: #ea4335;
  --pink: #ec4899;
  --shadow: 0 20px 80px rgba(0, 0, 0, 0.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(135deg, rgba(66, 133, 244, 0.18), transparent 28%),
    linear-gradient(225deg, rgba(52, 168, 83, 0.14), transparent 32%),
    linear-gradient(0deg, rgba(251, 188, 4, 0.08), transparent 40%),
    var(--bg);
  color: var(--text);
}

button,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  gap: 16px;
}

.rail {
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(8, 13, 25, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: grid;
  place-items: center;
  gap: 6px;
  padding-bottom: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: #0b1020;
  font-weight: 900;
  background:
    linear-gradient(135deg, var(--blue), var(--green) 46%, var(--yellow) 72%, var(--red));
}

.brand-copy {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.rail-item,
.bottom-nav button {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 60px;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.rail-item span,
.bottom-nav span {
  font-size: 11px;
  font-weight: 700;
}

.rail-item svg,
.bottom-nav svg,
.icon-button svg,
.tool-button svg,
.primary-button svg,
.secondary-button svg,
.status-pill svg {
  width: 18px;
  height: 18px;
}

.rail-item.is-active,
.bottom-nav button.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 76px;
  padding: 8px 4px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 56px);
  line-height: 0.95;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 15px;
}

.status-pack {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 750;
}

.status-pill.is-ready {
  color: #bbf7d0;
  background: rgba(52, 168, 83, 0.16);
  border-color: rgba(52, 168, 83, 0.35);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(360px, 1fr) minmax(280px, 360px);
  gap: 16px;
  align-items: start;
}

.studio-panel,
.preview-stage,
.right-panel .queue-block {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.studio-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  border-radius: 24px;
}

.panel-head,
.section-head,
.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segmented,
.style-chips,
.stage-toolbar {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.16);
}

.style-chips {
  flex-wrap: wrap;
}

.segmented button,
.style-chips button,
.tool-button,
.preset-list button {
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segmented button,
.style-chips button {
  min-height: 38px;
  flex: 1;
  padding: 0 10px;
  white-space: nowrap;
}

.segmented button.is-active,
.style-chips button.is-active,
.tool-button.is-active {
  color: #09111f;
  background: #f8fafc;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: rgba(5, 9, 18, 0.72);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 176px;
  padding: 14px;
  line-height: 1.45;
}

select {
  height: 46px;
  padding: 0 14px;
}

textarea:focus,
select:focus {
  border-color: rgba(66, 133, 244, 0.75);
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.18);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  border: 1px dashed rgba(255, 255, 255, 0.24);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
  cursor: pointer;
}

.upload-zone input {
  display: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}

.toggle-row span {
  display: grid;
  gap: 2px;
}

.toggle-row strong {
  font-size: 13px;
}

.toggle-row small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.toggle-row input {
  position: relative;
  appearance: none;
  width: 44px;
  height: 26px;
  flex: 0 0 44px;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  outline: none;
  transition: background 160ms ease, border-color 160ms ease;
}

.toggle-row input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #f8fafc;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  transition: transform 160ms ease;
}

.toggle-row input:checked {
  border-color: rgba(66, 133, 244, 0.75);
  background: linear-gradient(135deg, var(--blue), var(--green));
}

.toggle-row input:checked::before {
  transform: translateX(18px);
}

.reference-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.reference-thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 14px;
  border: 1px solid var(--line);
}

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

.reference-thumb button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.55);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button,
.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button,
.secondary-button {
  gap: 9px;
  min-height: 52px;
  border-radius: 16px;
  padding: 0 18px;
  font-weight: 900;
}

.primary-button {
  color: #07111f;
  background: linear-gradient(135deg, #ffffff, #a7f3d0 44%, #fde68a);
}

.secondary-button,
.icon-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--line);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

.preview-stage {
  overflow: hidden;
  min-height: 620px;
  border-radius: 28px;
}

.stage-toolbar {
  margin: 16px;
}

.tool-button {
  flex: 1;
  gap: 7px;
  min-height: 40px;
  padding: 0 10px;
}

.image-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 470px;
  margin: 0 16px;
  overflow: hidden;
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(66, 133, 244, 0.28), transparent 42%),
    linear-gradient(225deg, rgba(236, 72, 153, 0.24), transparent 52%),
    #050914;
  border: 1px solid var(--line);
}

.image-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.75), transparent);
}

.image-frame img {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 72vh;
  object-fit: contain;
}

.empty-render {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  color: var(--text);
}

.render-mark {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 28px;
  color: #07111f;
  background: linear-gradient(135deg, var(--blue), var(--green), var(--yellow));
  font-size: 28px;
  font-weight: 950;
}

.empty-render strong {
  font-size: 28px;
}

.empty-render small {
  color: var(--muted);
  font-weight: 800;
}

.result-meta {
  min-height: 84px;
  padding: 16px 18px 18px;
}

.result-meta p {
  margin: 0 0 4px;
  font-weight: 900;
}

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

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

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.right-panel .queue-block {
  border-radius: 22px;
  padding: 16px;
}

.scene-list,
.history-list,
.preset-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.scene-card,
.history-item {
  display: grid;
  gap: 5px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.scene-card strong,
.history-item strong {
  font-size: 13px;
}

.scene-card span,
.history-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.preset-list button {
  min-height: 42px;
  padding: 0 12px;
  text-align: left;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  padding: 11px 14px;
  border-radius: 999px;
  background: #f8fafc;
  color: #0f172a;
  font-weight: 850;
  box-shadow: var(--shadow);
}

.bottom-nav {
  display: none;
}

@media (max-width: 1180px) {
  .content-grid {
    grid-template-columns: 360px minmax(0, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
    padding: max(12px, env(safe-area-inset-top)) 12px calc(88px + env(safe-area-inset-bottom));
  }

  .rail {
    display: none;
  }

  .topbar {
    min-height: auto;
    align-items: flex-start;
  }

  h1 {
    font-size: 34px;
  }

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

  .right-panel {
    grid-template-columns: 1fr;
  }

  .preview-stage {
    min-height: auto;
  }

  .image-frame {
    min-height: 360px;
  }

  .bottom-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 15;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(6, 10, 20, 0.9);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
  }

  .bottom-nav button {
    min-height: 52px;
  }
}

@media (max-width: 520px) {
  .topbar {
    display: grid;
  }

  .status-pack {
    justify-content: flex-start;
  }

  .studio-panel,
  .right-panel .queue-block {
    padding: 14px;
    border-radius: 20px;
  }

  .two-col,
  .action-row {
    grid-template-columns: 1fr;
  }

  .segmented,
  .style-chips {
    overflow: visible;
  }

  .segmented button,
  .style-chips button {
    min-width: 76px;
  }
}
