:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: rgba(22, 25, 35, 0.92);
  --panel-soft: rgba(31, 35, 48, 0.82);
  --line: rgba(255, 255, 255, 0.11);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f7ff;
  --muted: #9aa3b7;
  --purple: #7c3cff;
  --purple-2: #a43dff;
  --green: #24d07a;
  --warning: #f7c948;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 28% 0%, rgba(124, 60, 255, 0.22), transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(0, 190, 255, 0.1), transparent 25%),
    var(--bg);
  color: var(--text);
  font-family: Inter, Arial, "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  gap: 14px;
  width: min(1880px, calc(100% - 20px));
  margin: 0 auto;
  padding: 14px 0;
}

.topbar {
  display: grid;
  grid-template-columns: 240px minmax(520px, 1fr) auto;
  align-items: center;
  gap: 18px;
  min-height: 54px;
}

.brand-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-name span {
  color: #b77aff;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.mode-tabs,
.account-bar,
.history-tabs,
.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-tabs {
  justify-content: center;
  overflow-x: auto;
}

.mode-tabs button,
.history-tabs button,
.side-item,
.circle-button,
.result-actions button,
.result-actions a,
.dialog-actions button,
.prompt-meta button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  min-height: 38px;
  padding: 0 14px;
  text-decoration: none;
  font-weight: 700;
}

.mode-tabs button.active,
.history-tabs button.active,
.side-item.active {
  border-color: rgba(124, 60, 255, 0.32);
  background: linear-gradient(135deg, rgba(124, 60, 255, 0.35), rgba(124, 60, 255, 0.14));
  color: #d9cbff;
}

.account-bar {
  justify-content: end;
}

.upgrade,
.generate-button,
.primary-action {
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #6636ff, #b238ee);
  color: white;
  min-height: 44px;
  padding: 0 22px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.key-pill {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 800;
}

.key-pill.ok {
  color: var(--green);
}

.key-pill.warn {
  color: var(--warning);
}

.hidden-config {
  display: none;
}

.circle-button,
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.circle-button {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: white;
  padding: 0;
}

.avatar {
  background: linear-gradient(135deg, #f7cda7, #7c3cff);
  color: white;
  font-weight: 900;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(470px, 690px) minmax(560px, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(27, 31, 43, 0.95), rgba(15, 18, 27, 0.95));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

.sidebar {
  display: grid;
  gap: 22px;
  align-content: start;
  padding: 20px;
  height: min(760px, calc(100vh - 192px));
  min-height: 620px;
  overflow: auto;
}

h2,
h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.sidebar h2 {
  margin-bottom: 12px;
}

.side-item {
  width: 100%;
  justify-content: flex-start;
  display: flex;
  margin-bottom: 8px;
}

.control-group {
  display: grid;
  gap: 10px;
}

.control-label,
label,
.prompt-block span {
  color: #e6e9f5;
  font-size: 14px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 8px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(7, 10, 18, 0.5);
  color: var(--text);
  outline: none;
  padding: 12px 14px;
}

textarea {
  resize: vertical;
  line-height: 1.65;
}

select:focus,
input:focus,
textarea:focus {
  border-color: rgba(124, 60, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(124, 60, 255, 0.18);
}

.generate-button {
  width: 100%;
  margin-top: 8px;
  min-height: 52px;
  font-size: 16px;
}

.fast-mode-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(124, 60, 255, 0.72);
  background: rgba(124, 60, 255, 0.16);
  color: #efe9ff;
  font-weight: 900;
}

.fast-mode-button:hover {
  border-color: rgba(180, 90, 255, 0.95);
  background: rgba(124, 60, 255, 0.26);
}

.generate-button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.cost-note {
  margin-top: -12px;
  color: #d9cbff;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.creator {
  padding: 20px;
  display: grid;
  gap: 16px;
  height: min(760px, calc(100vh - 192px));
  min-height: 620px;
  overflow: auto;
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.section-title span,
.prompt-block em {
  color: var(--muted);
  font-style: normal;
  font-weight: 600;
  font-size: 13px;
}

.reference-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 10px;
}

.upload-card,
.image-preview-item {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 126px;
  background: rgba(255, 255, 255, 0.04);
}

.upload-card {
  place-items: center;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}

.upload-card input {
  display: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 28px;
}

.upload-card strong {
  margin-top: 6px;
  color: white;
}

.upload-card small {
  margin-top: -2px;
  color: var(--muted);
}

.image-preview-list {
  display: contents;
}

.image-preview-item {
  aspect-ratio: 1.32 / 1;
}

.image-preview-item img,
.history-card img,
.thumb-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-preview-item > button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.56);
  color: white;
}

.image-preview-item span {
  position: absolute;
  left: 8px;
  bottom: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: white;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.link-drawer,
.advanced-json {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

summary {
  cursor: pointer;
  color: #d9cbff;
  font-weight: 800;
}

.link-drawer textarea,
.advanced-json textarea {
  margin-top: 10px;
}

.prompt-block {
  display: grid;
  gap: 8px;
}

.prompt-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 0;
  padding: 0;
}

.prompt-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.prompt-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.prompt-meta button {
  min-height: 34px;
  border-color: rgba(124, 60, 255, 0.32);
  background: rgba(124, 60, 255, 0.22);
  color: #d9cbff;
}

.result {
  display: grid;
  grid-template-columns: minmax(380px, 1fr) 230px;
  gap: 20px;
  padding: 20px;
  align-content: start;
  height: min(760px, calc(100vh - 192px));
  min-height: 620px;
  overflow: auto;
}

.result-head,
.preview-frame,
.thumb-strip {
  grid-column: 1;
}

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

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

.status-badge {
  border-radius: 6px;
  background: rgba(36, 208, 122, 0.16);
  color: var(--green);
  padding: 5px 10px;
  font-size: 13px;
}

.preview-frame {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: #0a0d14;
  min-height: 470px;
}

.preview-frame video,
.empty-preview {
  width: 100%;
  height: 100%;
  min-height: 470px;
}

.preview-frame video {
  object-fit: contain;
  background: #05070d;
}

.empty-preview {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
}

.progress {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 28px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

#progressBar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), #f0b4ff);
  transition: width 220ms ease;
}

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

.thumb-strip img {
  aspect-ratio: 1.35 / 1;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result-actions,
.info-card {
  grid-column: 2;
}

.result-actions {
  grid-row: 2;
  flex-direction: column;
  align-items: stretch;
  margin-top: 58px;
}

.result-actions button,
.result-actions a {
  justify-content: center;
  min-height: 54px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: #dfe5f5;
}

.result-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.info-card {
  grid-row: 3;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  padding: 18px;
}

.info-card h3 {
  margin-bottom: 18px;
}

dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  color: #e8ecf8;
}

.history {
  padding: 16px 20px 20px;
}

.history-head {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 14px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(120px, 1fr));
  gap: 14px;
}

.history-card {
  position: relative;
  overflow: hidden;
  min-height: 105px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.history-card span,
.history-card strong,
.history-card code,
.history-card button {
  position: absolute;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.58);
  color: white;
  padding: 4px 8px;
  font-size: 12px;
  border: 0;
}

.history-card span {
  right: 8px;
  top: 8px;
}

.history-card strong {
  left: 8px;
  bottom: 8px;
}

.history-card code {
  left: 8px;
  right: 8px;
  bottom: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 6px;
  font-family: Consolas, monospace;
}

.history-card button {
  right: 8px;
  bottom: 8px;
  background: rgba(124, 60, 255, 0.8);
  cursor: pointer;
}

.history-empty {
  grid-column: 1 / -1;
  min-height: 105px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.config-dialog {
  width: min(520px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #111521;
  color: var(--text);
  padding: 0;
}

.config-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.config-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.dialog-head button {
  border: 0;
  background: transparent;
  color: white;
  font-size: 24px;
}

.config-hint {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1420px) {
  .layout {
    grid-template-columns: 280px minmax(440px, 1fr);
  }

  .result {
    grid-column: 1 / -1;
  }

  .history-grid {
    grid-template-columns: repeat(4, minmax(140px, 1fr));
  }
}

@media (max-width: 980px) {
  .topbar,
  .layout,
  .result {
    grid-template-columns: 1fr;
  }

  .mode-tabs {
    justify-content: start;
  }

  .account-bar {
    justify-content: start;
    flex-wrap: wrap;
  }

  .result-actions,
  .info-card {
    grid-column: 1;
  }

  .result-actions {
    margin-top: 0;
  }

  .preview-frame,
  .preview-frame video,
  .empty-preview {
    min-height: 430px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 12px, 1880px);
  }

  .reference-board,
  .history-grid {
    grid-template-columns: 1fr 1fr;
  }

  .thumb-strip {
    grid-template-columns: repeat(4, 1fr);
  }
}
