:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #121815;
  --muted: #65706a;
  --line: #dfe4df;
  --accent: #0f7b55;
  --accent-dark: #0a5d42;
  --warn: #9d2323;
  --shadow: 0 18px 50px rgba(23, 34, 29, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(140deg, rgba(15, 123, 85, 0.1), transparent 36%),
    linear-gradient(320deg, rgba(216, 242, 106, 0.2), transparent 32%),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

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

.app-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 480px) minmax(0, 1fr);
  gap: 18px;
  width: min(1220px, 100%);
}

.control-panel,
.result-panel {
  border: 1px solid rgba(18, 24, 21, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
}

.panel-head {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 22px;
}

.panel-head p,
.result-head p,
.hint {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.6;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.upload-field > span {
  color: #34423b;
  font-size: 14px;
  font-weight: 800;
}

.key-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.key-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.key-panel-head strong {
  font-size: 14px;
}

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

.key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.key-toggle {
  min-width: 74px;
}

.upload-field {
  display: grid;
  gap: 10px;
}

.upload-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.upload-preview {
  display: grid;
  min-height: 140px;
  place-items: center;
  overflow: hidden;
  border: 1px dashed #cbd5ce;
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.upload-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}

input[type="password"],
input[type="text"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfcfa;
}

input[type="password"],
input[type="text"] {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 250px;
  resize: vertical;
  padding: 14px;
  line-height: 1.65;
}

select {
  height: 44px;
  padding: 0 12px;
}

input[type="password"]:focus,
input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 123, 85, 0.15);
}

.grid-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.submit-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
}

.submit-button {
  border: 0;
  color: #fff;
  background: var(--accent);
}

.submit-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  color: #34423b;
  background: #fff;
}

.secondary-button:hover {
  background: #f4f6f3;
}

.submit-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.hint {
  font-size: 13px;
}

code {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  background: #f4f6f3;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.history-head strong {
  font-size: 14px;
}

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

#history-list {
  display: grid;
  gap: 10px;
  max-height: 180px;
  overflow-y: auto;
  margin: 0;
  padding: 12px;
  list-style: none;
}

#history-list:empty::before {
  display: block;
  color: var(--muted);
  content: "暂无记录。生成第一张图后，再输入修改意见即可延续上下文。";
  font-size: 13px;
  line-height: 1.6;
}

#history-list li {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 8px;
  align-items: start;
}

#history-list li span {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

#history-list li.failed span {
  background: var(--warn);
}

#history-list li p {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.result-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  min-height: 720px;
  padding: 24px;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.download-link {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--accent-dark);
  background: #fff;
  font-weight: 900;
  text-decoration: none;
}

.preview {
  display: grid;
  overflow: hidden;
  min-height: 520px;
  place-items: center;
  border: 1px dashed #cbd5ce;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f8faf7 25%, transparent 25%),
    linear-gradient(-45deg, #f8faf7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f8faf7 75%),
    linear-gradient(-45deg, transparent 75%, #f8faf7 75%),
    #ffffff;
  background-position:
    0 0,
    0 12px,
    12px -12px,
    -12px 0;
  background-size: 24px 24px;
  color: var(--muted);
}

.preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.error-box {
  overflow-x: auto;
  margin: 16px 0 0;
  border: 1px solid rgba(157, 35, 35, 0.26);
  border-radius: 8px;
  padding: 12px;
  color: var(--warn);
  background: #fff7f7;
  white-space: pre-wrap;
}

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

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

  .result-panel {
    min-height: 520px;
  }

  .preview {
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .control-panel,
  .result-panel {
    padding: 18px;
  }

  .grid-fields,
  .key-row,
  .result-head,
  .action-row {
    grid-template-columns: 1fr;
  }

  .grid-fields {
    display: grid;
  }

  .result-head {
    display: grid;
  }

  h1 {
    font-size: 22px;
  }
}
