:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b0f17;
  color: #e8eef8;
  --bg: #0b0f17;
  --bg-deep: #070a10;
  --surface: #111827;
  --surface-raised: #151f2e;
  --surface-soft: #0f1520;
  --border: #2a374a;
  --border-strong: #3a4a61;
  --text: #e8eef8;
  --muted: #9baabd;
  --accent: #6aa0ff;
  --accent-strong: #3f7ee8;
  --accent-soft: #162848;
  --teal: #32c4a3;
  --danger: #ff8a80;
  --danger-bg: #351819;
  --shadow: 0 18px 50px rgb(0 0 0 / 34%);
  --shadow-soft: 0 10px 28px rgb(0 0 0 / 24%);
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, #0b0f17 0%, #10141c 52%, #080b10 100%);
  color: var(--text);
}

a {
  color: var(--accent);
}

.app-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.login-panel,
.panel {
  background: linear-gradient(180deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.login-panel {
  max-width: 420px;
  margin: 15vh auto 0;
}

label {
  display: block;
  font-weight: 650;
  margin-bottom: 8px;
}

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

input,
select,
textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #738397;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.generate-tabs a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent-strong);
  color: #ffffff;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

button:hover {
  background: #5c95ff;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.error {
  color: var(--danger);
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.top-nav a {
  color: #9fc0ff;
  font-weight: 650;
  text-decoration: none;
}

.top-nav a:hover,
.reuse-button:hover,
.completed-links a:hover,
.section-heading a:hover,
.empty-state a:hover {
  color: #c3d8ff;
}

.top-nav form {
  margin-left: auto;
}

.top-nav + .top-nav {
  display: none;
}

.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.tag-filter-list,
.overlay-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tag-filter-list span,
.overlay-tags span {
  border: 1px solid #38506d;
  border-radius: 999px;
  padding: 4px 9px;
  background: #172338;
  color: #d9e5f5;
  font-size: 0.9rem;
}

.selector-row {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin: 16px 0;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.image-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-deep);
}

.image-card form {
  display: flex;
  gap: 8px;
}

.image-card-actions {
  margin: 8px 0;
}

.generate-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.generate-main {
  min-width: 0;
}

.generate-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.generate-tabs a {
  flex: 0 0 auto;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 14px;
  background: #121a27;
  color: #c2ccda;
  font-weight: 650;
  text-decoration: none;
  box-shadow: var(--shadow-soft);
}

.generate-tabs a.is-active {
  border-color: #6aa0ff;
  background: var(--accent-strong);
  color: #ffffff;
}

.generate-tabs a:hover {
  border-color: #567096;
  color: #ffffff;
}

.generate-tab-panel {
  display: none;
}

.generate-tab-panel.is-active {
  display: block;
}

.generation-form {
  display: grid;
  gap: 10px;
}

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

.quick-form button {
  justify-self: start;
}

.advanced-panel {
  border-style: dashed;
}

.scene-section-list {
  display: grid;
  gap: 12px;
}

.scene-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: rgb(7 10 16 / 24%);
}

.scene-section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.7fr);
  gap: 12px;
  margin-bottom: 10px;
}

.save-section-row {
  display: flex;
  gap: 8px;
}

.save-section-row button {
  flex: 0 0 auto;
}

.field-stack {
  display: grid;
  gap: 12px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.inline-check input {
  width: auto;
  min-height: auto;
}

.empty-state {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.empty-state p,
.muted {
  color: var(--muted);
}

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

.queue-sidebar {
  position: sticky;
  top: 16px;
}

.queue-active {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: rgb(7 10 16 / 24%);
}

.queue-active span {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #344358;
  border-top-color: var(--teal);
  border-radius: 50%;
}

.queue-active.is-running .spinner {
  animation: spin 1s linear infinite;
}

.queue-empty {
  color: var(--muted);
}

.queue-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: rgb(7 10 16 / 18%);
}

.queue-list p {
  margin: 6px 0 0;
}

.completed-links {
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.gallery-overlay[hidden] {
  display: none;
}

.gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(3 6 12 / 86%);
}

.gallery-target-overlay {
  display: none;
}

.gallery-target-overlay:target {
  display: grid;
}

.gallery-overlay-frame {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: min(1100px, 100%);
  height: min(86vh, 900px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 28px 90px rgb(0 0 0 / 58%);
  overflow: hidden;
}

.gallery-overlay-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-deep);
}

.overlay-close,
.overlay-arrow {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgb(15 21 32 / 88%);
  color: #ffffff;
  text-decoration: none;
}

.overlay-close {
  top: 12px;
  right: 12px;
  min-height: 44px;
  padding: 0 14px;
}

.overlay-arrow {
  top: 50%;
  width: 48px;
  min-height: 64px;
  transform: translateY(-50%);
  font-size: 2rem;
}

.overlay-arrow-left {
  left: 12px;
}

.overlay-arrow-right {
  right: 12px;
}

.overlay-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-raised);
}

.overlay-bottom .overlay-tags {
  margin-bottom: 0;
}

.reuse-button {
  flex: 0 0 auto;
  color: #9fc0ff;
  font-weight: 650;
}

.overlay-open {
  overflow: hidden;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.panel + .panel {
  margin-top: 16px;
}

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

.section-heading h1 {
  margin: 0;
}

.workflow-list {
  display: grid;
  gap: 10px;
}

.workflow-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: rgb(7 10 16 / 18%);
}

.workflow-item h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.workflow-item p {
  margin: 0 0 4px;
}

.workflow-actions {
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.workflow-install-form {
  margin: 0;
}

.workflow-install-form button {
  white-space: nowrap;
}

.workflow-form {
  display: grid;
  gap: 10px;
}

.field-table {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(120px, 1fr) 110px 90px 110px 72px minmax(110px, 1fr);
  gap: 8px;
  min-width: 820px;
  align-items: center;
}

.field-row-head {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--muted);
}

.field-row input,
.field-row select {
  min-height: 38px;
}

.check-cell {
  display: flex;
  justify-content: center;
  margin: 0;
}

.check-cell input {
  width: auto;
  min-height: auto;
}

@media (max-width: 720px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    width: calc(100vw - 20px);
    padding: 10px 0;
  }

  .top-nav {
    flex-wrap: wrap;
  }

  .top-nav form {
    width: 100%;
    margin-left: 0;
  }

  .top-nav button {
    width: 100%;
  }

  .filter-row,
  .image-card form,
  .workflow-item,
  .queue-list li,
  .overlay-bottom,
  .save-section-row {
    flex-direction: column;
    align-items: stretch;
  }

  .generate-layout {
    grid-template-columns: 1fr;
  }

  .queue-sidebar {
    position: static;
    order: -1;
  }

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

  .quick-grid,
  .scene-section-head {
    grid-template-columns: 1fr;
  }

  .quick-form button {
    width: 100%;
  }

  .generate-tabs {
    padding-bottom: 4px;
  }

  .gallery-overlay {
    padding: 8px;
  }

  .gallery-overlay-frame {
    height: 92vh;
  }

  .overlay-arrow {
    width: 42px;
    min-height: 54px;
  }

  .workflow-actions {
    justify-content: flex-start;
  }

  .completed-links {
    flex-wrap: wrap;
  }

  .field-table {
    overflow-x: visible;
  }

  .field-row-head {
    display: none;
  }

  .field-row {
    grid-template-columns: 1fr;
    min-width: 0;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  .check-cell {
    justify-content: flex-start;
    gap: 8px;
  }

  .check-cell::after {
    content: "Required";
    font-weight: 500;
  }
}
