:root {
  --ink: #20201d;
  --muted: #6d6a61;
  --line: #d9d4c8;
  --surface: #f7f4ed;
  --panel: #fffdf8;
  --panel-strong: #ebe3d5;
  --accent: #c84e33;
  --accent-2: #286f6c;
  --accent-3: #92742f;
  --black: #141411;
  --white: #ffffff;
  --shadow: 0 18px 45px rgba(32, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--surface);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(32, 32, 29, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(32, 32, 29, 0.04) 1px, transparent 1px),
    var(--surface);
  background-size: 28px 28px;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 0 4px 18px;
  border-bottom: 1px solid var(--line);
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.brand-block {
  position: relative;
}

.brand-block small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.topbar-actions,
.card-actions,
.panel-toolbar,
.section-head {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 10px;
}

.primary-btn,
.dark-btn,
.ghost-btn,
.icon-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.primary-btn {
  border-color: rgba(200, 78, 51, 0.35);
  background: var(--accent);
  color: var(--white);
}

.dark-btn {
  border-color: var(--black);
  background: var(--black);
  color: var(--white);
}

.ghost-btn {
  background: transparent;
}

.icon-btn {
  width: 38px;
  padding: 0;
  font-size: 20px;
}

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

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(420px, 1fr) minmax(360px, 520px);
  gap: 16px;
  padding-top: 18px;
}

.input-panel,
.analysis-panel,
.result-panel {
  min-height: calc(100vh - 130px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.input-panel {
  padding: 14px;
}

.analysis-panel,
.result-panel {
  padding: 16px;
  overflow: hidden;
}

.panel-block + .panel-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section-head,
.panel-toolbar {
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  margin-bottom: 12px;
}

.section-head span,
.result-meta,
.switch-row small {
  color: var(--muted);
  font-size: 12px;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px dashed #b8ad9a;
  border-radius: 8px;
  background: #fbfaf5;
  text-align: center;
  padding: 18px;
}

.dropzone.dragging {
  border-color: var(--accent);
  background: #fff4ee;
}

.dropzone input {
  display: none;
}

.dropzone strong {
  display: block;
  font-size: 15px;
}

.dropzone span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.asset-card {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.asset-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.asset-card figcaption {
  overflow: hidden;
  padding: 6px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee8dc;
}

.segment,
.tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment {
  min-height: 34px;
}

.segment.active,
.tab.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

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

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  outline: none;
}

.field input,
.field select {
  height: 40px;
  padding: 0 10px;
}

.field textarea {
  resize: vertical;
  padding: 10px;
  line-height: 1.55;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(40, 111, 108, 0.12);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.switch input {
  display: none;
}

.switch span {
  position: relative;
  display: block;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #cac0ae;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 0.18s ease;
}

.switch input:checked + span {
  background: var(--accent-2);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.panel-toolbar {
  margin-bottom: 14px;
}

.panel-toolbar.compact {
  margin-bottom: 10px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--muted);
  background: #fbfaf5;
}

.status-item span {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e5dece;
  font-size: 12px;
  font-weight: 900;
}

.status-item b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-item.active {
  border-color: rgba(40, 111, 108, 0.45);
  color: var(--ink);
  background: #eef5f2;
}

.analysis-output {
  height: calc(100vh - 320px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.generation-cta {
  display: flex;
  justify-content: center;
  padding-top: 16px;
}

.generate-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(520px, 88%);
}

.generate-choice {
  min-height: 58px;
  border-radius: 8px;
  font-size: 18px;
  letter-spacing: 0;
}

.generate-all {
  grid-column: 1 / -1;
  min-height: 72px;
  font-size: 20px;
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 320px;
  padding: 30px;
  text-align: center;
}

.empty-state strong {
  font-size: 20px;
}

.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
}

.analysis-doc {
  padding: 18px;
}

.analysis-doc section + section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.analysis-doc h3 {
  margin-bottom: 9px;
  font-size: 15px;
}

.analysis-doc ul {
  margin: 0;
  padding-left: 18px;
}

.analysis-doc li {
  margin: 6px 0;
  line-height: 1.55;
}

.lock-box {
  border-left: 4px solid var(--accent);
  padding: 12px;
  background: #fff4ee;
  line-height: 1.65;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.server-status {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfaf5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.server-status.ready {
  border-color: rgba(40, 111, 108, 0.35);
  background: #eef5f2;
  color: var(--accent-2);
}

.server-status.warn {
  border-color: rgba(200, 78, 51, 0.4);
  background: #fff4ee;
  color: var(--accent);
}

.history-panel {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fffefa;
}

.history-list {
  display: grid;
  gap: 6px;
  max-height: 126px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 6px 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  background: #fbfaf5;
}

.history-item input {
  grid-row: 1 / span 2;
}

.history-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item small,
.history-empty {
  color: var(--muted);
  font-size: 11px;
}

.history-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.history-actions,
.preview-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.history-actions {
  margin-top: 8px;
}

.preview-actions {
  margin-bottom: 12px;
}

.history-actions .ghost-btn,
.preview-actions .ghost-btn {
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
}

.tab {
  min-height: 34px;
  border: 1px solid var(--line);
}

.result-grid {
  display: grid;
  gap: 12px;
  height: calc(100vh - 415px);
  overflow: auto;
  padding-right: 4px;
}

.result-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 10px;
}

.preview-frame {
  display: grid;
  place-items: center;
  min-height: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee8dc;
  overflow: hidden;
}

.preview-art {
  display: grid;
  place-items: center;
  width: 82px;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  background:
    linear-gradient(135deg, rgba(200, 78, 51, 0.16), transparent 45%),
    linear-gradient(45deg, rgba(40, 111, 108, 0.18), transparent 55%),
    #fffefa;
}

.result-card[data-kind="detail"] .preview-art {
  width: 64px;
  aspect-ratio: 9 / 16;
}

.generated-image {
  display: none;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: contain;
}

.result-card[data-kind="main"] .generated-image {
  aspect-ratio: 1;
}

.result-card[data-kind="detail"] .generated-image {
  aspect-ratio: 9 / 16;
}

.preview-index {
  color: var(--ink);
  font-weight: 900;
}

.result-body {
  min-width: 0;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  background: #e6f0ec;
  color: var(--accent-2);
  font-weight: 900;
}

.ratio {
  color: var(--accent-3);
  font-weight: 900;
}

.result-body h3 {
  margin-bottom: 5px;
  font-size: 15px;
}

.result-body p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.card-actions {
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  border: 1px solid rgba(40, 111, 108, 0.35);
  border-radius: 8px;
  background: var(--black);
  color: var(--white);
  padding: 10px 13px;
  box-shadow: var(--shadow);
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 310px 1fr;
  }

  .result-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
    max-height: 720px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

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

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 38px 1fr;
  }

  .workspace,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .input-panel,
  .analysis-panel,
  .result-panel {
    min-height: auto;
  }

  .analysis-output,
  .result-grid {
    height: auto;
    max-height: none;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .generate-choice-grid {
    width: 100%;
  }

  .result-grid {
    height: auto;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 24px;
  }

  .preview-frame {
    min-height: 180px;
  }

  .topbar-actions {
    grid-template-columns: 1fr;
  }

  .icon-btn {
    width: auto;
  }

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

  .generate-all {
    min-height: 62px;
  }
}
