:root {
  color: #172033;
  background: #f5f7fb;
  font-family: "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(242, 246, 251, 0.92)),
    #f5f7fb;
  overflow-x: clip;
}

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

button {
  cursor: pointer;
}

.shell {
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 590px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  min-width: 0;
}

.panel,
.form-section {
  min-width: 0;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 38px rgba(31, 41, 55, 0.07);
}

.controls {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.drawer-head,
.api-panel-head {
  display: none;
}

.mobile-scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
  background: rgba(15, 23, 42, 0.46);
}

.mobile-scrim.is-visible {
  display: block;
}

.api-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

body.modal-open {
  overflow: hidden;
}

.results {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 13px;
  min-width: 0;
  min-height: calc(100vh - 36px);
  overflow: hidden;
  padding: 16px;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.hero {
  align-items: flex-start;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow,
.response-id,
small,
.image-card span,
.subtitle,
.section-head p,
.muted {
  color: #667085;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.15;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 15px;
}

.subtitle {
  margin-top: 6px;
  line-height: 1.5;
}

button,
.primary,
.secondary {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.primary,
.titlebar button.primary {
  border: 0;
  background: #155eef;
  color: #fff;
}

.secondary {
  border: 1px solid #cfd8e6;
  background: #fff;
  color: #344054;
}

.danger-text {
  color: #b42318;
}

.notice,
.warning,
.error,
.empty,
.response-id {
  border-radius: 8px;
  padding: 12px;
  line-height: 1.55;
}

.notice {
  border: 1px solid #c7d7fe;
  background: #eef4ff;
}

.warning {
  border: 1px solid #fedf89;
  background: #fffaeb;
}

.error {
  border: 1px solid #fecdca;
  background: #fef3f2;
  color: #b42318;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed #cfd7e3;
  background: #f8fafc;
  text-align: center;
}

.form-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  box-shadow: none;
}

.api-section {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 100;
  display: none;
  width: min(92vw, 520px);
  max-height: min(86dvh, 680px);
  overflow: auto;
  transform: translate(-50%, -50%);
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.24);
}

.api-section.open,
.api-section.is-visible {
  display: grid;
}

.focus-flash {
  animation: focusFlash 1.1s ease;
}

@keyframes focusFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(21, 94, 239, 0);
  }
  35% {
    box-shadow: 0 0 0 5px rgba(21, 94, 239, 0.2);
    border-color: #155eef;
  }
  100% {
    box-shadow: none;
  }
}

.section-head {
  display: grid;
  gap: 4px;
}

.section-head p {
  font-size: 13px;
  line-height: 1.45;
}

.grid {
  display: grid;
  gap: 12px;
}

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

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

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

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

label small {
  font-weight: 500;
  line-height: 1.45;
}

.connection-space-note {
  display: grid;
  gap: 5px;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background: #f8fbff;
  padding: 10px 11px;
}

.connection-space-note strong {
  color: #344054;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd7e3;
  border-radius: 8px;
  background: #fff;
  color: #101828;
  outline: none;
  padding: 10px 11px;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #155eef;
  box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.14);
}

.check.inline {
  display: grid;
  grid-template-columns: auto 20px;
  align-items: center;
  justify-content: start;
  gap: 9px;
}

.check.inline small {
  grid-column: 1 / -1;
  max-width: 360px;
}

.check input {
  width: 20px;
  height: 20px;
}

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

.upload-box {
  min-height: 92px;
  border: 1px dashed #b9c6d8;
  background: #f8fbff;
  padding: 12px;
}

.upload-box input {
  padding: 8px;
}

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

.file-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #e3e9f2;
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

.main-file {
  border-color: #b7d4ff;
  background: #f2f7ff;
}

.file-chip span {
  min-width: 0;
  overflow: hidden;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip em {
  color: #667085;
  font-style: normal;
  font-weight: 500;
}

.file-chip button {
  flex: 0 0 auto;
  min-height: 30px;
  border: 1px solid #fecdca;
  background: #fff;
  color: #b42318;
  padding: 0 10px;
}

.advanced {
  gap: 12px;
}

.advanced summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 900;
}

.advanced summary small {
  font-weight: 500;
}

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

.image-card {
  display: grid;
  gap: 10px;
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.image-card a {
  display: grid;
  place-items: center;
  min-height: 220px;
  border-radius: 6px;
  background:
    linear-gradient(45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f7 25%, transparent 25%),
    #f8fafc;
  background-position: 0 0, 0 10px;
  background-size: 20px 20px;
}

.image-card img {
  display: block;
  max-width: 100%;
  max-height: 460px;
  object-fit: contain;
  border-radius: 6px;
}

.image-card div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

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

.image-actions button,
.asset-card button,
.mini-gallery button {
  min-height: 34px;
  border: 1px solid #cfd8e6;
  border-radius: 7px;
  background: #fff;
  color: #155eef;
  font-size: 13px;
  font-weight: 800;
}

.image-card strong,
.image-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

details:not(.advanced) {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  background: #fbfcfe;
  padding: 12px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

pre {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  max-height: 420px;
  margin: 12px 0 0;
  border-radius: 6px;
  background: #101828;
  color: #f2f4f7;
  padding: 12px;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

code {
  border-radius: 5px;
  background: #eef2f7;
  padding: 2px 5px;
}

.cached-result {
  display: grid;
  gap: 10px;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background: #f8fbff;
  padding: 12px;
}

.result-body {
  display: grid;
  gap: 13px;
  min-width: 0;
  max-width: 100%;
}

.loading-card {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 320px;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background: #f8fbff;
  text-align: center;
  padding: 24px;
}

.loading-card p {
  max-width: 420px;
  color: #667085;
  line-height: 1.6;
}

.loading-card span {
  border-radius: 999px;
  background: #eef4ff;
  color: #155eef;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
}

.stream-preview img {
  width: min(100%, 520px);
  max-height: 56vh;
  object-fit: contain;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 35px rgba(31, 42, 68, 0.12);
}

.loader {
  width: 42px;
  height: 42px;
  border: 4px solid #d6e3ff;
  border-top-color: #155eef;
  border-radius: 999px;
  animation: spin 900ms linear infinite;
}

.is-generating .primary:disabled {
  opacity: 0.8;
  cursor: wait;
}

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

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

.mini-gallery a,
.mini-gallery button {
  display: grid;
  place-items: center;
  min-height: 78px;
  overflow: hidden;
  border: 1px solid #e3e9f2;
  border-radius: 7px;
  background: #fff;
  color: #155eef;
  font-size: 12px;
  text-decoration: none;
}

.mini-gallery img,
.mini-gallery button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.library-picker {
  display: grid;
  gap: 10px;
  border: 1px solid #e3e9f2;
  border-radius: 8px;
  background: #fbfdff;
  padding: 12px;
}

.library-chip span {
  color: #155eef;
}

.library-note {
  margin-top: 6px;
  color: #667085;
  line-height: 1.55;
}

.asset-library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.asset-card {
  display: grid;
  gap: 9px;
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  background: #fff;
  padding: 9px;
}

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

.asset-card div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.asset-card strong,
.asset-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-card span {
  color: #667085;
  font-size: 12px;
}

.empty.small {
  min-height: 120px;
  grid-column: 1 / -1;
}

.welcome-preview {
  display: grid;
  gap: 18px;
  min-height: 340px;
  align-content: center;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(21, 94, 239, 0.08), transparent 42%),
    #f8fbff;
  padding: clamp(20px, 4vw, 34px);
}

.welcome-preview h3 {
  margin-top: 4px;
  font-size: clamp(22px, 3vw, 30px);
}

.welcome-preview p:not(.eyebrow) {
  max-width: 620px;
  margin-top: 8px;
  color: #475467;
  line-height: 1.75;
}

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

.preview-steps span {
  border: 1px solid #e3e9f2;
  border-radius: 8px;
  background: #fff;
  color: #344054;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 800;
}

.matrix {
  margin-top: 14px;
  padding: 16px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.matrix-grid div {
  display: grid;
  gap: 8px;
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.matrix-grid span {
  color: #475467;
  font-size: 13px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  transform: translateY(16px);
  opacity: 0;
  border-radius: 8px;
  background: #101828;
  color: white;
  padding: 11px 14px;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1120px) {
  .workbench,
  .grid.two,
  .matrix-grid {
    grid-template-columns: 1fr;
  }

  .results {
    position: static;
    min-height: 0;
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 18px, 1500px);
    padding-top: 10px;
  }

  .hero,
  .titlebar {
    align-items: stretch;
    flex-direction: column;
  }

  .workbench {
    display: flex;
    flex-direction: column;
  }

  .results {
    order: 1;
    width: 100%;
  }

  .controls {
    display: contents;
  }

  .hero,
  .notice {
    order: 0;
    width: 100%;
  }

  .settings-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 30;
    display: grid;
    align-content: start;
    gap: 12px;
    width: min(92vw, 430px);
    max-width: 430px;
    height: 100vh;
    height: 100dvh;
    overflow: auto;
    transform: translateX(104%);
    border-left: 1px solid #dfe6f0;
    background: #f7f9fc;
    padding: 12px;
    box-shadow: -24px 0 60px rgba(15, 23, 42, 0.18);
    transition: transform 220ms ease;
  }

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

  .drawer-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid #dfe6f0;
    border-radius: 8px;
    background: #fff;
    padding: 12px;
  }

  .drawer-head p {
    margin-top: 4px;
    color: #667085;
    font-size: 13px;
    line-height: 1.45;
  }

  .api-section {
    width: min(92vw, 440px);
  }

  body.drawer-open,
  body.modal-open {
    overflow: hidden;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: stretch;
  }

  .toolbar .primary {
    grid-column: 1 / -1;
  }

  .toolbar button {
    min-width: 0;
    padding: 0 10px;
  }

  .notice {
    font-size: 13px;
  }

  .grid.three,
  .grid.four,
  .upload-grid,
  .preview-steps {
    grid-template-columns: 1fr;
  }

  .advanced summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .matrix {
    order: 2;
  }
}

@media (max-width: 460px) {
  .controls,
  .results,
  .form-section,
  .hero {
    padding: 12px;
  }

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