:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #d9dee5;
  --line-strong: #b8c1cc;
  --text: #1f2933;
  --muted: #667085;
  --red: #ef3e42;
  --blue: #1d5fd1;
  --green: #20b15a;
  --green-dark: #14743c;
  --orange: #ff6a1a;
  --danger: #b42318;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

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

button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #7f2b24;
  font-weight: 800;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 95, 209, 0.12);
}

.window {
  min-height: 100vh;
  padding-bottom: 96px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--bg);
}

.login-card {
  width: min(100%, 390px);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.login-card h1 {
  margin: 0;
  color: #111827;
  font-size: 24px;
  font-weight: 900;
}

.app-mark.big {
  width: 42px;
  height: 42px;
  font-size: 26px;
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
  font-weight: 800;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.app-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
}

.window-title {
  overflow: hidden;
  color: #334155;
  font-size: 16px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lan-text {
  overflow: hidden;
  max-width: 58vw;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  grid-column: 1 / 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #c88700;
}

.dot.ok {
  background: var(--green);
}

.dot.bad {
  background: var(--danger);
}

.mini-btn {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  min-height: 38px;
  padding: 0 10px;
  font-size: 14px;
}

.user-pill {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.user-pill button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.app-main {
  width: min(100%, 980px);
  margin: 0 auto;
}

  .work-band,
  .video-band,
  .output-band,
  .gallery-band,
  .advanced-band {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 12px;
}

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

.section-head h1,
.section-head h2 {
  margin: 0;
  color: #111827;
  font-weight: 900;
  line-height: 1.1;
}

.section-head h1 {
  font-size: 24px;
}

.section-head h2 {
  font-size: 18px;
}

.small-head {
  margin-bottom: 8px;
}

.state-line,
#jobText {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.reference-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.upload-btn {
  min-height: 48px;
  border-color: #86a8e7;
  background: #edf4ff;
  color: #174ea6;
  font-size: 16px;
}

.inline-field,
.field-stack {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.inline-field span,
.field-stack span,
.subhead {
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

.path-field input {
  min-width: 0;
}

.reference-preview {
  min-height: 136px;
  margin: 10px 0 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.reference-preview img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #111827;
}

.media-workflow {
  display: grid;
  gap: 12px;
}

.current-reference-panel {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.current-reference-panel summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: #344054;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
}

.current-reference-panel .path-field,
.current-reference-panel .reference-preview {
  margin: 0 10px 10px;
}

.queue-panel {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

#queueSummary,
#galleryCount,
#videoCount {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

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

.plain-btn.primary {
  border-color: var(--green-dark);
  background: var(--green);
  color: #fff;
}

.queue-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.queue-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.queue-item.running {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 95, 209, 0.12);
}

.queue-thumb {
  width: 54px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 6px;
  background: #111827;
}

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

.queue-meta {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.queue-name {
  overflow: hidden;
  color: #1f2937;
  font-size: 13px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-state {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.queue-tools {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 38px);
  gap: 5px;
  justify-content: end;
}

.queue-tools button {
  min-height: 32px;
  padding: 0;
  font-size: 15px;
}

.library-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 0;
}

.compact-upload {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-height: 440px;
  overflow: auto;
  padding: 2px;
}

.asset-tile {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 5px;
  border-color: var(--line);
  background: #fff;
  text-align: left;
}

.asset-tile.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 95, 209, 0.14);
}

.asset-tile.focused {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 106, 26, 0.14);
}

.asset-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: #111827;
}

.asset-tile span {
  overflow: hidden;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 38;
  background: rgba(15, 23, 42, 0.22);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.asset-drawer-scrim.open {
  opacity: 1;
}

.asset-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 39;
  width: min(360px, 92vw);
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  border-left: 1px solid var(--line);
  background: #fff;
  box-shadow: -16px 0 40px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 0.18s ease;
}

.asset-drawer.open {
  transform: translateX(0);
}

.asset-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.asset-drawer-head h2 {
  margin: 0;
  color: #111827;
  font-size: 20px;
  font-weight: 900;
}

.asset-drawer-head button {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.asset-drawer-preview {
  min-height: 220px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #111827;
}

.asset-drawer-preview img {
  width: 100%;
  max-height: 56vh;
  object-fit: contain;
}

.asset-drawer-name {
  overflow-wrap: anywhere;
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

.asset-drawer-actions {
  display: grid;
  gap: 8px;
}

.prompt-box textarea {
  min-height: 168px;
  padding: 10px;
  resize: vertical;
  color: #7f2b24;
  font-size: 17px;
  line-height: 1.45;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 64px 1fr;
  gap: 8px;
  margin-top: 12px;
}

.quick-grid .field-stack {
  min-width: 0;
}

.quick-grid input,
.advanced-grid input,
.advanced-grid select {
  min-height: 42px;
  padding: 0 9px;
  font-size: 16px;
}

.swap-btn {
  align-self: end;
  min-height: 42px;
  padding: 0 6px;
  font-size: 14px;
}

.plain-btn {
  min-height: 40px;
  padding: 0 12px;
  font-size: 15px;
}

.plain-btn.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.progress {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

#barFill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.2s ease;
}

#barFill.busy {
  width: 45%;
  animation: loading 1s ease-in-out infinite alternate;
}

@keyframes loading {
  from {
    transform: translateX(-70%);
  }
  to {
    transform: translateX(170%);
  }
}

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

.image-tile {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.22;
  object-fit: contain;
  background: #111827;
}

.image-tile a {
  display: block;
  padding: 6px;
  color: #1f2937;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.image-name {
  display: block;
}

.source-tag {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
  font-size: 11px;
}

.empty-gallery {
  grid-column: 1 / -1;
  min-height: 64px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.video-layout {
  display: grid;
  gap: 12px;
}

.video-form,
.video-side,
.status-card {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.video-form textarea {
  min-height: 132px;
  padding: 10px;
  resize: vertical;
  color: #7f2b24;
  font-size: 16px;
  line-height: 1.45;
}

.video-preview {
  min-height: 180px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.video-preview img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: #111827;
}

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

.video-quick-grid input {
  min-height: 42px;
  padding: 0 9px;
  font-size: 16px;
}

.video-check {
  align-self: end;
}

.status-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.status-card strong {
  color: #111827;
  font-size: 16px;
  font-weight: 900;
}

#videoBarFill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.2s ease;
}

#videoBarFill.busy {
  width: 45%;
  animation: loading 1s ease-in-out infinite alternate;
}

.video-result,
.video-gallery {
  display: grid;
  gap: 10px;
}

.video-result video,
.video-tile video {
  display: block;
  width: 100%;
  max-height: 420px;
  border-radius: 8px;
  background: #111827;
}

.video-result a,
.video-tile a {
  display: block;
  color: #1f2937;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.video-tile {
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-actions {
  display: grid;
  padding: 0 6px 6px;
}

.image-actions button {
  min-height: 32px;
  border-color: #86a8e7;
  background: #edf4ff;
  color: #174ea6;
  font-size: 13px;
}

.advanced-band {
  padding: 0;
}

.advanced-band summary {
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: #111827;
  cursor: pointer;
  font-size: 17px;
  font-weight: 900;
}

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

.advanced-grid .full {
  grid-column: 1 / -1;
}

.advanced-grid textarea {
  min-height: 120px;
  padding: 9px;
  font-size: 15px;
  line-height: 1.45;
}

.lora-panel,
.pad-panel,
.runtime-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lora-list {
  display: grid;
  gap: 8px;
}

.lora-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 44px 58px;
  gap: 6px;
  align-items: center;
}

.lora-label,
.lora-weight-label {
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

.lora-row input {
  min-width: 0;
  min-height: 38px;
  padding: 0 7px;
  font-size: 13px;
}

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

.check-line {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  color: #344054;
  font-size: 14px;
  font-weight: 900;
}

.check-line input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
}

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

pre {
  min-height: 140px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  white-space: pre-wrap;
  font-size: 12px;
}

.hidden-controls {
  display: none;
}

.action-bar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.generate-btn {
  min-height: 52px;
  border-color: var(--green-dark);
  background: var(--green);
  color: #fff;
  font-size: 18px;
}

.danger {
  border-color: #f0b4ae;
  color: var(--danger);
}

.mobile-tabbar {
  display: none;
}

.desktop-tabbar {
  display: none;
}

@media (min-width: 760px) {
  .desktop-tabbar {
    position: sticky;
    top: 55px;
    z-index: 19;
    width: min(calc(100% - 32px), 1248px);
    margin: 12px auto 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  }

  .desktop-tabbar button {
    min-height: 58px;
    display: grid;
    place-items: center;
    gap: 2px;
    padding: 7px 12px;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
  }

  .desktop-tabbar button span {
    color: inherit;
    font-size: 17px;
    font-weight: 900;
  }

  .desktop-tabbar button small {
    color: inherit;
    font-size: 11px;
    font-weight: 700;
  }

  .desktop-tabbar button.active {
    border-color: #b8d1ff;
    background: #edf4ff;
    color: var(--blue);
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
  }

  .status-pill {
    grid-column: auto;
  }

  .user-pill {
    grid-column: auto;
  }

  .mini-btn {
    grid-column: auto;
    grid-row: auto;
  }

.work-band,
.video-band,
  .output-band,
  .gallery-band,
  .advanced-band {
    margin: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
  }

  .media-workflow {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    align-items: start;
  }

  .queue-panel {
    position: sticky;
    top: 74px;
  }

  .quick-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .swap-btn {
    order: 2;
  }

  .gallery,
  .output {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .video-layout {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
    align-items: start;
  }

  .video-side {
    position: sticky;
    top: 74px;
  }

  .video-quick-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .video-gallery {
    grid-template-columns: 1fr;
  }

  .asset-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .advanced-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .advanced-grid .full {
    grid-column: 1 / -1;
  }

  .button-row,
  .mini-grid,
  .queue-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .queue-item {
    grid-template-columns: 58px minmax(0, 1fr) 124px;
  }

  .queue-tools {
    grid-column: auto;
  }

  .action-bar {
    left: 50%;
    width: min(100%, 980px);
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
  }

  .window.mobile-view-assets .video-band,
  .window.mobile-view-assets .output-band,
  .window.mobile-view-assets .gallery-band,
  .window.mobile-view-assets .advanced-band,
  .window.mobile-view-make .video-band,
  .window.mobile-view-make .output-band,
  .window.mobile-view-make .gallery-band,
  .window.mobile-view-video .work-band,
  .window.mobile-view-video .output-band,
  .window.mobile-view-video .gallery-band,
  .window.mobile-view-video .advanced-band,
  .window.mobile-view-done .work-band,
  .window.mobile-view-done .video-band,
  .window.mobile-view-done .advanced-band {
    display: none;
  }

  .window.mobile-view-assets .queue-panel,
  .window.mobile-view-assets .current-reference-panel,
  .window.mobile-view-assets .prompt-box,
  .window.mobile-view-assets .quick-grid,
  .window.mobile-view-make .library-panel {
    display: none;
  }

  .window.mobile-view-assets .media-workflow,
  .window.mobile-view-make .media-workflow {
    display: block;
  }

  .window.mobile-view-make .queue-panel {
    position: static;
    margin-bottom: 14px;
  }

  .window.mobile-view-done .output-band,
  .window.mobile-view-done .gallery-band {
    display: block;
  }
}

@media (max-width: 759px) {
  .window {
    padding-bottom: 166px;
  }

  .mobile-tabbar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 34;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.98);
  }

  .mobile-tabbar button {
    min-height: 48px;
    display: grid;
    place-items: center;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    font-weight: 900;
  }

  .mobile-tabbar button.active {
    border-color: #b8d1ff;
    background: #edf4ff;
    color: var(--blue);
  }

  .action-bar {
    bottom: calc(64px + env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 1fr) 86px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
  }

  .window.mobile-view-assets .action-bar,
  .window.mobile-view-assets .video-band,
  .window.mobile-view-assets .output-band,
  .window.mobile-view-assets .gallery-band,
  .window.mobile-view-assets .advanced-band,
  .window.mobile-view-make .video-band,
  .window.mobile-view-video .action-bar,
  .window.mobile-view-video .work-band,
  .window.mobile-view-video .output-band,
  .window.mobile-view-video .gallery-band,
  .window.mobile-view-video .advanced-band,
  .window.mobile-view-done .work-band,
  .window.mobile-view-done .video-band,
  .window.mobile-view-done .advanced-band {
    display: none;
  }

  .window.mobile-view-assets .queue-panel,
  .window.mobile-view-assets .current-reference-panel,
  .window.mobile-view-assets .prompt-box,
  .window.mobile-view-assets .quick-grid,
  .window.mobile-view-make .library-panel,
  .window.mobile-view-make .output-band,
  .window.mobile-view-make .gallery-band {
    display: none;
  }

  .window.mobile-view-assets .work-band,
  .window.mobile-view-make .work-band,
  .window.mobile-view-video .video-band,
  .window.mobile-view-done .output-band,
  .window.mobile-view-done .gallery-band {
    display: block;
  }

  .window.mobile-view-make .queue-panel,
  .window.mobile-view-make .current-reference-panel,
  .window.mobile-view-make .prompt-box {
    display: grid;
  }

  .window.mobile-view-make .quick-grid {
    display: grid;
  }

  .window.mobile-view-make .advanced-band {
    display: block;
  }

  .media-workflow {
    gap: 0;
  }

  .video-form textarea {
    min-height: 104px;
  }

  .video-preview {
    min-height: 140px;
  }

  .video-preview img {
    max-height: 190px;
  }

  .video-buttons {
    position: sticky;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 28;
    padding: 8px 0;
    background: var(--panel);
  }

  .work-band,
  .video-band,
  .output-band,
  .gallery-band {
    min-height: calc(100vh - 222px);
  }

  .advanced-band {
    margin-bottom: 12px;
  }

  .asset-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
  }

  .queue-list {
    max-height: none;
    overflow: auto;
  }

  .asset-drawer {
    inset: auto 0 0 0;
    width: 100%;
    max-height: 84vh;
    overflow: auto;
    border-left: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 40px rgba(15, 23, 42, 0.18);
    transform: translateY(100%);
  }

  .asset-drawer.open {
    transform: translateY(0);
  }

  .asset-drawer-preview {
    min-height: 180px;
  }

  .asset-drawer-preview img {
    max-height: 42vh;
  }

  .queue-list {
    max-height: 260px;
    overflow: auto;
  }
}

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

  .quick-grid,
  .video-quick-grid,
  .advanced-grid,
  .mini-grid,
  .button-row,
  .queue-actions {
    grid-template-columns: 1fr;
  }

  .swap-btn {
    order: 3;
  }

  .gallery,
  .output {
    grid-template-columns: 1fr;
  }
}

/* Media workspace refinement */
.window {
  padding-bottom: 24px;
}

.app-main {
  width: min(100%, 1280px);
}

.library-panel,
.queue-panel,
.output-band,
.gallery-band,
.video-form,
.video-side {
  min-width: 0;
}

.asset-grid,
.gallery,
.output,
.video-gallery {
  align-items: start;
}

.asset-tile,
.image-tile,
.video-tile {
  contain: layout paint;
}

.asset-tile {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.asset-tile:hover {
  border-color: #8da2ba;
  transform: translateY(-1px);
}

.image-tile {
  display: grid;
  grid-template-rows: auto auto auto;
  min-width: 0;
}

.image-preview-button {
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #111827;
}

.image-preview-button img {
  transition: transform 0.18s ease;
}

.image-preview-button:hover img {
  transform: scale(1.015);
}

.image-info {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  padding: 8px 8px 6px;
}

.image-name {
  overflow: hidden;
  color: #1f2937;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-tag {
  margin-top: 0;
}

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

.image-actions button {
  min-width: 0;
}

.image-actions .view-image-btn {
  border-color: var(--line-strong);
  background: #fff;
  color: #344054;
}

.recipe-btn {
  width: 100%;
  min-height: 34px;
  border-color: #b9c7d8;
  background: #f8fbff;
  color: #1f4e79;
  font-size: 12px;
  font-weight: 900;
}

.recipe-btn:hover {
  border-color: #7aa7d9;
  background: #eef6ff;
}

.video-tile {
  grid-template-rows: auto auto;
  padding: 7px;
}

.video-tile video {
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: none;
  object-fit: contain;
}

.video-tile-foot {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.video-tile-foot span {
  overflow: hidden;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-tile-foot button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--blue);
  font-size: 12px;
}

.video-result {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.video-result:empty {
  display: none;
}

body.media-viewer-open {
  overflow: hidden;
}

.media-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 0;
  transition: opacity 0.16s ease;
}

.media-viewer.open {
  opacity: 1;
}

.media-viewer-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: rgba(8, 15, 27, 0.88);
}

.media-viewer-dialog {
  position: relative;
  width: min(1180px, 100%);
  height: min(92vh, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #0f172a;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.media-viewer-head,
.media-viewer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: #e2e8f0;
  background: #111827;
}

.media-viewer-head > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.media-viewer-label,
.media-viewer-foot span {
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
}

.media-viewer-head strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-viewer-close {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  padding: 0;
  border-color: #64748b;
  background: #1f2937;
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.media-viewer-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  background: #05080f;
}

.media-viewer-stage img,
.media-viewer-stage video {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.media-viewer-stage video {
  width: 100%;
  height: 100%;
}

.media-viewer-foot a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid #64748b;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

@media (min-width: 760px) {
  .work-band,
  .video-band,
  .output-band,
  .gallery-band,
  .advanced-band {
    margin-inline: 16px;
  }

  .media-workflow {
    grid-template-columns: minmax(0, 1.55fr) minmax(340px, 0.85fr);
    gap: 16px;
  }

  .asset-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-height: 620px;
  }

  .gallery,
  .output {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .video-layout {
    grid-template-columns: minmax(360px, 0.8fr) minmax(0, 1.5fr);
    gap: 18px;
  }

  .video-side {
    position: static;
  }

  .video-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 760px;
    overflow: auto;
    padding-right: 4px;
  }

  .gallery {
    max-height: 980px;
    overflow: auto;
    padding-right: 4px;
  }

  .action-bar {
    width: min(100%, 1280px);
  }
}

@media (max-width: 759px) {
  .window {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .section-head h1 {
    font-size: 21px;
  }

  .work-band,
  .video-band,
  .output-band,
  .gallery-band {
    padding-inline: 10px;
  }

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

  .image-tile img {
    aspect-ratio: 1 / 1.28;
  }

  .image-info {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .source-tag {
    width: fit-content;
  }

  .video-gallery {
    grid-template-columns: 1fr;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .gallery {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .window.mobile-view-done {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .window.mobile-view-done .action-bar {
    display: none;
  }

  .window.mobile-view-done .output-band {
    min-height: 0;
  }

  .window.mobile-view-done .gallery-band {
    min-height: calc(100vh - 190px);
  }

  .media-viewer {
    padding: 0;
  }

  .media-viewer-dialog {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  .media-viewer-head {
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .media-viewer-foot {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}
