:root {
  --ink: #171713;
  --panel: #fbfbf8;
  --paper: #fffdf9;
  --line: #dedbd1;
  --muted: #77756d;
  --accent: #ff563f;
  --accent-strong: #ee4c39;
  --accent-soft: #fff0ec;
  --focus: #2f6fea;
  --grid-line: rgba(52, 52, 42, 0.055);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #ededeb;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 新增：适配钥匙和清除图标的样式 */
svg.yaoshi-icon,
svg.clear-icon {
  fill: currentColor;
  stroke: none;
}

/* 按钮里的图标尺寸调整 */
.button svg.yaoshi-icon,
.button svg.clear-icon {
  width: 18px;
  height: 18px;
}

/* 标题里的钥匙图标尺寸 */
.config-section h2 svg.yaoshi-icon {
  width: 20px;
  height: 20px;
}

/* 已保存 Key 提示里的图标 */
.key-status svg.yaoshi-icon {
  width: 20px;
  height: 20px;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(240px, 14.65vw, 300px) minmax(360px, 1fr) clamp(260px, 17.6vw, 360px);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  background: #171613;
  color: #f6f3eb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #24231f;
  color: #ff614c;
}

.brand-mark img {
  display: block;
  width: 24px;
  height: 24px;
}

.brand span {
  display: block;
  color: #a6a197;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong {
  display: block;
  margin-top: 2px;
  font-size: 28px;
  line-height: 1;
}

.config-section {
  display: grid;
  gap: 10px;
}

.config-section h2,
.panel-section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 17px;
}

.config-section label {
  color: #c4bfb4;
  font-size: 14px;
}

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

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(47, 111, 234, 0.55);
  box-shadow: 0 0 0 3px rgba(47, 111, 234, 0.12);
}

.sidebar input,
.sidebar select {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border-color: rgba(255, 255, 255, 0.16);
  background: #2a2925;
  color: #f9f7f1;
}

.sidebar input::placeholder {
  color: #8c887f;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.button,
.generate-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.button {
  height: 42px;
  padding: 0 14px;
}

.button.primary {
  background: #fff;
  color: #202018;
}

.button.secondary {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: transparent;
  color: #fff;
}

.button svg,
.generate-button svg {
  width: 18px;
  height: 18px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: transparent;
  color: #f8f4ec;
}

.icon-button.small {
  width: 28px;
  height: 28px;
}

.key-status,
.buy-tip {
  color: #a9a49a;
  font-size: 14px;
  line-height: 1.55;
}

.key-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.key-status.saved {
  color: #d8f6d8;
}

.buy-tip {
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.generate-button {
  width: 100%;
  height: 50px;
  margin-top: auto;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  box-shadow: 0 14px 28px rgba(255, 86, 63, 0.18);
}

.generate-button:disabled {
  cursor: wait;
  background: #bd493a;
  color: rgba(255, 255, 255, 0.74);
}

.workspace {
  min-height: 100vh;
  padding: 30px 28px 34px;
  background: #efefeb;
  border-right: 1px solid var(--line);
}

.prompt-section {
  display: grid;
  gap: 10px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  color: #24241f;
  font-size: 14px;
  font-weight: 800;
}

.section-title span {
  color: #8e8b84;
  font-weight: 600;
}

textarea {
  width: 100%;
  min-height: 200px;
  padding: 18px;
  resize: vertical;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.65;
}

textarea::placeholder {
  color: #9b968e;
}

.drop-zone {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 70px;
  margin-top: 20px;
  padding: 12px;
  border: 1px dashed #ddd7cd;
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.75);
  cursor: pointer;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #fff6f2;
}

.drop-zone input {
  display: none;
}

.drop-icon {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone strong {
  font-size: 16px;
}

.drop-zone span {
  margin-top: 4px;
  color: #88847c;
  font-size: 13px;
}

.thumb-strip {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  overflow-x: auto;
}

.thumb-strip img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.generation-error {
  margin-top: 14px;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: #f8e4df;
  color: #c93228;
  font-size: 14px;
  line-height: 1.45;
}

.generation-error[hidden] {
  display: none;
}

.canvas-panel {
  position: relative;
  min-height: calc(100vh - 404px);
  margin-top: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.canvas-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
}

.canvas-status {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: #7d7971;
}

.canvas-status svg {
  color: var(--accent);
}

.progress-pill {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.92);
  color: #77736b;
  font-size: 14px;
}

.progress-pill svg {
  width: 16px;
  height: 16px;
}

.is-generating .canvas-status {
  color: #77736b;
}

.is-generating .canvas-status::before {
  content: "";
  width: 190px;
  height: 190px;
  margin-bottom: 18px;
  border: 1px solid #ddd8ce;
  border-radius: 8px;
  background:
    linear-gradient(90deg, #ededeb 0%, #f2f1ee 44%, #fff1ec 68%, #e7e5df 100%);
  background-size: 240% 100%;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.08);
  animation: shimmer 1.1s linear infinite;
}

.is-generating .canvas-status svg {
  display: none;
}

.is-generating .progress-pill svg {
  animation: spin 1s linear infinite;
}

.result-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(280px, 1fr);
  place-content: center;
  justify-items: center;
  gap: 20px;
  min-height: calc(100vh - 404px);
  padding: 54px 90px 70px;
}

.result-grid.is-pending {
  position: absolute;
  inset: 0;
  display: block;
  min-height: 0;
  padding: 0;
  pointer-events: none;
}

.result-frame {
  position: relative;
  width: min(64%, 760px);
  min-width: 360px;
}

.result-frame img {
  display: block;
  width: 100%;
  max-height: min(56vh, 560px);
  object-fit: contain;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: zoom-in;
  box-shadow: none;
}

.result-frame img:hover {
  filter: brightness(0.98);
}

.result-meta {
  position: absolute;
  left: -114px;
  bottom: -48px;
  display: inline-flex;
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  background: rgba(76, 75, 69, 0.96);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.result-actions {
  position: absolute;
  right: -114px;
  bottom: -50px;
  display: flex;
  gap: 8px;
}

.result-actions a,
.result-actions button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: rgba(76, 75, 69, 0.96);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}

.result-actions svg {
  width: 18px;
  height: 18px;
}

.generation-list {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.result-switcher {
  position: relative;
  display: grid;
  width: min(100%, 1000px);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 58px;
}

.generation-card,
.result-tile {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  min-height: 72px;
  padding: 8px 10px;
  border: 1px solid #ff6655;
  border-radius: 0;
  background: rgba(255, 253, 249, 0.88);
  color: var(--ink);
  text-align: left;
}

.generation-card strong,
.result-tile strong {
  font-size: 15px;
}

.generation-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 6px;
  background: #ffe9e5;
  color: var(--accent);
}

.generation-icon svg {
  width: 22px;
  height: 22px;
  animation: spin 1s linear infinite;
}

.result-tile {
  border-color: #e7e1d6;
  cursor: pointer;
  border-radius: 12px;
}

.result-tile.is-active {
  border-color: #ff6655;
}

.result-tile.is-failed {
  border-color: #ff6655;
  cursor: default;
}

.result-tile img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
}

.result-fail-thumb {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 6px;
  background: #ffe9e5;
  color: #d7352d;
  font-size: 14px;
  font-weight: 800;
}

.image-preview-modal {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
}

.image-preview-modal[open] {
  display: grid;
  place-items: center;
}

.image-preview-modal::backdrop {
  background: rgba(12, 12, 10, 0.78);
}

.image-preview-modal img {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 96px);
  max-height: calc(100vh - 72px);
  margin: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  object-fit: contain;
}

.preview-close {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 2;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: #22201d;
  cursor: pointer;
}

.preview-close svg {
  width: 20px;
  height: 20px;
}

.right-panel {
  min-height: 100vh;
  padding: 30px 26px;
  background: #fafaf6;
}

.panel-section {
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.panel-section + .panel-section {
  margin-top: 28px;
}

.parameter-section {
  display: grid;
  gap: 28px;
}

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

.control-group select {
  display: none;
}

.control-header {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.control-header span {
  display: grid;
  gap: 4px;
}

.control-header strong {
  font-size: 15px;
}

.control-header em {
  color: #77736b;
  font-size: 13px;
  font-style: normal;
}

.control-header svg {
  width: 16px;
  height: 16px;
  color: #77736b;
  transition: transform 0.16s ease;
}

.control-group:not(.is-open) .control-header svg {
  transform: rotate(180deg);
}

.option-grid {
  overflow: hidden;
  border: 1px solid #dedbd1;
  border-radius: 8px;
  background: #fffdf9;
}

.control-group:not(.is-open) .option-grid {
  display: none;
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 4px;
}

.count-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 4px;
}

.option-tile {
  display: grid;
  min-height: 58px;
  place-items: center;
  gap: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #6c675e;
  cursor: pointer;
  font-weight: 800;
}

.size-grid .option-tile {
  min-height: 64px;
}

.option-tile strong {
  color: inherit;
  font-size: 16px;
}

.option-tile span {
  color: inherit;
  font-size: 12px;
  font-weight: 600;
}

.option-tile.is-active {
  background: #171613;
  color: #fff;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-list p {
  margin: 0;
  color: #8a867f;
}

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

.history-heading h2 {
  margin: 0;
}

.history-heading button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.history-heading button[hidden] {
  display: none;
}

.history-item {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 70px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #2f2e29;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}

.history-item.is-active {
  border-color: var(--accent);
}

.history-item img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-item strong {
  display: block;
  overflow: hidden;
  color: #2f2e29;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  display: block;
  margin-top: 4px;
  color: #8b877f;
  font-size: 12px;
}

.history-meta {
  color: #3e3c36;
  font-size: 14px;
  font-weight: 600;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #1f1e1b;
  color: #fff;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

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

.model-modal {
  width: min(740px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
}

.model-modal::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

.modal-card {
  position: relative;
  margin: 0;
  overflow: hidden;
  border: 1px solid #e4e3df;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.18);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #f0f0ef;
  color: #55534e;
  cursor: pointer;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 30px 30px 32px;
}

.openai-mark {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.openai-mark svg {
  width: 42px;
  height: 42px;
  stroke-width: 1.6;
}

.modal-header h2 {
  margin: 0;
  font-size: 26px;
}

.copy-dot {
  width: 15px;
  height: 15px;
  border: 3px solid #0a83ff;
  border-radius: 3px;
  box-shadow: 5px -5px 0 -2px #fff, 5px -5px 0 0 #0a83ff;
}

.model-block {
  padding: 18px 30px 22px;
  border-top: 1px solid #ebe9e4;
}

.block-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.block-heading h3,
.block-heading p {
  margin: 0;
}

.block-heading h3 {
  font-size: 18px;
}

.block-heading p {
  color: #1a1a17;
  font-size: 14px;
}

.round-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.13);
}

.round-icon svg {
  width: 18px;
  height: 18px;
}

.blue {
  background: #5aaeff;
}

.purple {
  background: #c85ad7;
}

.amber {
  background: #ffbd5b;
}

.empty-desc,
.route-line {
  margin: 22px 0 0;
  font-size: 17px;
}

.route-line span,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 10px;
  border: 1px solid #d8d8d4;
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
}

.endpoint-line {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin-top: 26px;
  font-size: 17px;
}

.green-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #35ba55;
}

.endpoint-line code {
  color: #0e2143;
  font-family: inherit;
}

.endpoint-line strong {
  justify-self: end;
  font-size: 13px;
  font-weight: 500;
}

.pricing-table {
  margin-top: 24px;
}

.pricing-head,
.pricing-row {
  display: grid;
  grid-template-columns: 1fr 0.9fr 1.1fr;
  align-items: center;
  min-height: 66px;
  padding: 0 20px;
  border-bottom: 1px solid #e8e6e0;
}

.pricing-head {
  min-height: 42px;
  color: #6d6a64;
  font-weight: 800;
}

.pricing-row b {
  display: block;
  font-size: 16px;
}

.pricing-row small {
  font-size: 15px;
}

.pill {
  display: inline-flex;
  width: max-content;
  align-items: center;
  min-height: 26px;
  padding: 0 12px;
  border-radius: 999px;
  background: #dcfbf7;
  color: #007f7a;
  font-size: 14px;
}

@keyframes shimmer {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -120% 0;
  }
}

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

@media (max-width: 1280px) {
  .app-shell {
    grid-template-columns: 250px minmax(340px, 1fr) 270px;
  }

  .sidebar,
  .right-panel {
    padding: 24px 18px;
  }

  .workspace {
    padding: 26px 18px 30px;
  }

  .brand strong {
    font-size: 24px;
  }

  textarea {
    min-height: 190px;
  }
}

@media (max-width: 940px) {
  .app-shell {
    grid-template-columns: 220px minmax(300px, 1fr) 250px;
  }

  .sidebar,
  .right-panel {
    padding: 20px 14px;
  }

  .workspace {
    padding: 20px 14px 24px;
  }

  .brand {
    gap: 10px;
  }

  .brand strong {
    font-size: 22px;
  }

  .result-grid {
    padding-inline: 56px;
  }

  .result-frame {
    min-width: 260px;
    width: min(74%, 620px);
  }
}
