:root {
  color-scheme: light;
  --page: #f4f3ed;
  --paper: #fffefa;
  --surface: #f8f8f2;
  --ink: #212f28;
  --secondary: #536158;
  --muted: #657268;
  --line: #d9dfd5;
  --soft-line: #e6e9e0;
  --forest: #236447;
  --forest-strong: #174b35;
  --tint: #e8f0e7;
  --tint-line: #c5d7c7;
  --button-ink: #fff;
  --danger: #a43831;
  --canvas: #f8f8f3;
  --dot: #dde3d8;
  --shadow: 0 3px 12px #35473508;
  font: 15px/1.5 "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--page);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #151c18;
  --paper: #1d2721;
  --surface: #232e27;
  --ink: #e5ede4;
  --secondary: #b5c4b6;
  --muted: #a6b4a7;
  --line: #3a473d;
  --soft-line: #303d33;
  --forest: #a0d4ad;
  --forest-strong: #b8e6c3;
  --tint: #2c4032;
  --tint-line: #415c48;
  --button-ink: #142a1c;
  --danger: #f2a49d;
  --canvas: #1b251f;
  --dot: #344038;
  --shadow: 0 3px 12px #07100a18;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; padding: 0; color: inherit; border: 0; background: transparent; }
button:disabled, select:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
:is(button, a, input, select, textarea):focus-visible { outline: 2px solid var(--forest); outline-offset: 3px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
p, h1, h2, h3, figure { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.topbar { border-bottom: 1px solid var(--line); background: var(--paper); }
.topbar-inner { max-width: 1584px; min-height: 75px; padding: 8px clamp(20px, 3vw, 48px); margin: auto; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 7px; }
.brand, .toolbar, .toolbar-button, .gallery-title, .selection, .selection label, .price-line, .field-heading, .usage-tip, .modal-heading, .modal-actions, .dialog-button, .generate { display: flex; align-items: center; }
.brand { gap: 11px; flex: none; white-space: nowrap; }
.brand-mark { display: block; width: 64px; height: auto; flex: none; }
.brand-name { font-family: "Songti SC", "STSong", "SimSun", serif; font-size: 27px; font-weight: 700; letter-spacing: .06em; line-height: 1.1; }
.toolbar { gap: 7px; justify-content: flex-end; flex-wrap: wrap; min-width: 0; }
.toolbar-button, .balance, .square-button { min-height: 35px; border-radius: 7px; font-size: 13px; white-space: nowrap; }
.toolbar-button { gap: 7px; padding: 0 10px; font-weight: 550; }
.toolbar-button svg, .square-button svg { width: 16px; height: 16px; }
.toolbar-button:hover, .square-button:hover, .balance:enabled:hover { background: var(--tint); }
.toolbar-rule { flex: none; width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.balance { max-width: 190px; padding: 0 8px; color: var(--secondary); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.balance:enabled { color: var(--forest); }
.toolbar .key-button { color: var(--forest-strong); background: var(--tint); border: 1px solid var(--tint-line); padding-inline: 12px; }
.toolbar .key-button:hover { border-color: var(--forest); }
.square-button { display: grid; place-items: center; width: 36px; border: 1px solid var(--line); }
.sun, [data-theme="dark"] .moon { display: none; }
[data-theme="dark"] .sun { display: block; }
.workspace { max-width: 1584px; margin: 0 auto; padding: clamp(20px, 2.3vw, 36px) clamp(20px, 3vw, 48px) 40px; display: grid; grid-template-columns: clamp(346px, 31.5%, 430px) minmax(0, 1fr); align-items: stretch; gap: clamp(18px, 1.7vw, 28px); }
.panel { min-width: 0; border: 1px solid var(--line); background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); }
.creation-panel { display: flex; flex-direction: column; }
.panel-title, .gallery-heading { padding: 20px 24px; min-height: 72px; border-bottom: 1px solid var(--soft-line); display: flex; align-items: center; gap: 11px; }
.panel h1, .panel h2 { font-size: 21px; font-weight: 650; line-height: 1.3; letter-spacing: .015em; }
.section-icon { color: var(--forest); display: grid; place-items: center; }
.section-icon svg { width: 22px; height: 22px; }
.form-content { padding: 21px 24px 22px; display: grid; gap: 19px; }
.field, .prompt-field, .upload-controls, .reference-section { min-width: 0; display: grid; gap: 8px; align-content: start; }
.field-heading { gap: 10px; justify-content: space-between; }
label, .field-label, .field-heading { color: var(--ink); font-size: 13px; font-weight: 600; }
.field-label small { margin-left: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }
.inline-button { color: var(--forest); font-size: 12px; font-weight: 500; }
.inline-button:hover { text-decoration: underline; text-underline-offset: 3px; }
#clear-input { color: var(--muted); }
textarea, select, #access-key { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); }
textarea, select { font-size: 14px; }
textarea:hover, select:enabled:hover, #access-key:hover { border-color: var(--tint-line); }
textarea::placeholder, input::placeholder { color: var(--muted); opacity: 1; }
#custom-size input { width: 100%; min-width: 0; min-height: 40px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--paper); }
#custom-size input[aria-invalid="true"] { border-color: var(--danger); }
#fixed-resolution { display: flex; align-items: center; min-height: 40px; padding: 7px 11px; border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 14px; }
#prompt { display: block; min-height: 119px; padding: 12px 13px; line-height: 1.7; resize: vertical; background: var(--surface); }
.model-fields, .spec-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.select-wrap { position: relative; min-width: 0; display: flex; }
.select-wrap::after { content: ""; position: absolute; pointer-events: none; width: 6px; height: 6px; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; right: 14px; top: calc(50% - 4px); transform: rotate(45deg); }
select { min-height: 40px; appearance: none; padding: 7px 30px 7px 11px; text-overflow: ellipsis; }
select:enabled { cursor: pointer; }
select:disabled { color: var(--muted); background: var(--surface); }
.upload-area { width: 100%; min-height: 82px; padding: 14px 12px; display: flex; align-items: center; justify-content: center; gap: 11px; border: 1px dashed var(--tint-line); border-radius: 9px; color: var(--forest); background: var(--surface); text-align: left; }
.upload-area:hover, .upload-area.drag-over { background: var(--tint); border-color: var(--forest); }
.upload-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: none; background: var(--tint); border-radius: 8px; }
.upload-icon svg { width: 22px; height: 22px; }
.drop-copy { display: grid; gap: 3px; }
.drop-copy strong { font-size: 13px; font-weight: 600; }
.drop-copy > span { color: var(--muted); font-size: 11px; }
.reference-section { gap: 9px; }
.reference-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.reference { margin: 0; min-width: 0; position: relative; }
.reference img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; border-radius: 7px; border: 1px solid var(--line); }
.reference figcaption { font-size: 10px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remove-reference, .result-remove { position: absolute; z-index: 1; right: 4px; top: 4px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #1d3025db; color: white; font: 17px/1 sans-serif; }
.remove-reference:hover, .result-remove:hover { background: #9d3731; }
.form-footer { display: grid; gap: 12px; margin-top: auto; padding: 17px 24px 22px; background: var(--surface); border-top: 1px solid var(--soft-line); border-radius: 0 0 14px 14px; }
.price-line { gap: 10px; justify-content: space-between; font-size: 12px; color: var(--muted); }
.price-line strong { color: var(--secondary); font: inherit; font-weight: 600; text-align: right; white-space: pre-line; font-variant-numeric: tabular-nums; }
.generate { width: 100%; justify-content: center; gap: 9px; min-height: 44px; padding: 10px 15px; color: var(--button-ink); background: var(--forest); border-radius: 8px; font-size: 15px; font-weight: 600; }
.generate:hover:enabled, .dialog-button.primary:hover { background: var(--forest-strong); }
.generate svg { width: 18px; height: 18px; }
.generate:disabled { opacity: .7; }
.inline-status, .pending-submission, .usage-tip { color: var(--secondary); font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.inline-status:empty, .result-grid:empty, .ledger-list:empty { display: none; }
.inline-status.error { color: var(--danger); }
.pending-submission { display: grid; justify-items: start; gap: 8px; }
.gallery-panel { display: flex; flex-direction: column; overflow: hidden; }
.gallery-heading { justify-content: space-between; flex-wrap: wrap; }
.gallery-title { gap: 11px; }
.selection { gap: 12px; flex-wrap: wrap; }
.selection label { display: flex; gap: 6px; color: var(--secondary); font-size: 12px; font-weight: 400; cursor: pointer; }
.selection input, .result-select { width: 14px; height: 14px; accent-color: var(--forest); margin: 0; }
.history-button { padding: 5px 10px; color: var(--secondary); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.history-button:hover { color: var(--danger); border-color: var(--danger); }
.gallery-body { padding: 20px; flex: 1; display: flex; flex-direction: column; min-height: 360px; background-color: var(--canvas); background-image: radial-gradient(circle, var(--dot) .85px, transparent .95px); background-size: 16px 16px; }
.gallery-body:has(.result-grid > *) { background: var(--surface); }
.gallery-body:has(.result-grid > *) .gallery-empty { display: none; }
.gallery-empty { flex: 1; padding: 20px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.empty-icon { width: 85px; height: 85px; display: grid; place-items: center; margin-bottom: 6px; border-radius: 22px; color: var(--forest); background: var(--tint); border: 1px solid var(--tint-line); }
.empty-icon svg { width: 65px; height: 65px; stroke-width: 1.55; }
.back-frame { fill: var(--tint-line); stroke: var(--forest); }
.front-frame { fill: var(--paper); }
.gallery-empty h3 { font-size: 18px; font-weight: 600; }
.gallery-empty p { color: var(--muted); font-size: 13px; }
#history-status:not(:empty) { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 8px 11px; }
#history-status:not(:empty) + .gallery-empty + .result-grid:not(:empty) { margin-top: 12px; }
.usage-tip { gap: 9px; padding: 13px 22px; border-top: 1px solid var(--soft-line); color: var(--secondary); }
.usage-tip p { flex: 1; }
.usage-tip button { flex: none; }
.usage-tip svg { width: 15px; height: 15px; color: var(--forest); }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 155px), 1fr)); align-items: start; gap: 12px; }
.result-card { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; padding: 7px; min-width: 0; background: var(--paper); }
.result-card.selected { border-color: var(--forest); box-shadow: inset 0 0 0 1px var(--forest); }
.result-select { position: absolute; z-index: 1; left: 12px; top: 12px; }
.result-remove { top: 10px; right: 10px; }
.result-image { display: block; width: 100%; border-radius: 6px; overflow: hidden; aspect-ratio: 1; background: var(--surface); }
.result-image img { width: 100%; height: 100%; display: block; object-fit: cover; }
.result-caption, .job-meta, .job-prompt { padding: 4px 3px 0; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.result-caption { color: var(--ink); }
.result-caption > strong { display: block; margin-top: 3px; }
.result-caption .job-prompt { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; padding-inline: 0; }
.result-caption .job-meta { padding-inline: 0; }
.restore-job { margin-top: 7px; padding: 3px 7px; border-radius: 5px; color: var(--forest); background: var(--tint); font-size: 11px; }
.restore-job:hover { text-decoration: underline; }
.job-meta { color: var(--muted); font-size: 11px; }
.job-status { display: block; margin: 24px 2px 6px; font-size: 13px; font-weight: 600; }
.modal { width: min(100% - 32px, 448px); max-width: none; max-height: min(86vh, 860px); margin: auto; padding: 24px; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: var(--paper); box-shadow: 0 22px 76px #12241833; overflow-y: auto; }
.modal::backdrop { background: #16241c78; backdrop-filter: blur(3px); }
.modal-heading { align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-heading h2 { font-size: 20px; font-weight: 650; line-height: 1.4; }
.modal-heading p, .modal-copy, .wallet-status, .image-meta { color: var(--secondary); font-size: 13px; }
.modal-heading p { margin-top: 5px; }
.notice-copy { display: grid; gap: 12px; }
.notice-copy p { margin: 0; color: var(--secondary); font-size: 14px; line-height: 1.7; }
.notice-copy strong { color: var(--ink); }
.modal-close { flex: none; width: 30px; height: 30px; border-radius: 6px; color: var(--muted); font: 24px/1 sans-serif; }
.modal-close:hover { background: var(--surface); color: var(--ink); }
#access-key { margin-top: 7px; padding: 10px 12px; background: var(--surface); }
#login-form .inline-status:not(:empty) { margin-top: 7px; }
.modal-actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 21px; }
.dialog-button { justify-content: center; min-height: 36px; padding: 6px 15px; border: 1px solid var(--line); background: var(--paper); border-radius: 7px; color: var(--ink); font-size: 13px; font-weight: 550; cursor: pointer; }
.dialog-button:hover { background: var(--surface); }
.dialog-button.primary { background: var(--forest); border-color: transparent; color: var(--button-ink); }
.dialog-button.danger { background: #a23c34; border-color: transparent; color: #fff; }
.dialog-button:disabled { opacity: .5; cursor: default; }
.ledger-modal { width: min(100% - 32px, 720px); }
.wallet-balances { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wallet-balances > div { display: grid; gap: 4px; padding: 11px; border-radius: 8px; background: var(--surface); border: 1px solid var(--soft-line); }
.wallet-balances span { color: var(--muted); font-size: 12px; }
.wallet-balances strong { color: var(--ink); font-size: 16px; overflow-wrap: anywhere; }
.wallet-status { margin: 16px 0; }
.ledger-row { padding: 11px 0; border-top: 1px solid var(--soft-line); }
.ledger-header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; font-size: 14px; }
.ledger-meta { color: var(--muted); font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; }
.image-modal { width: min(100% - 32px, 830px); }
.large-preview { display: block; max-height: 50vh; width: 100%; object-fit: contain; background: var(--surface); border-radius: 8px; }
.image-description { margin-top: 14px; }
.image-description h3 { color: var(--muted); font-size: 12px; font-weight: 550; margin-bottom: 4px; }
#dialog-prompt { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.image-meta { margin-top: 5px; overflow-wrap: anywhere; }
@media (min-width: 1120px) { .creation-panel, .gallery-panel { min-height: min(69vh, 700px); } }
@media (max-width: 850px) {
  .topbar-inner { gap: 8px; }
  .toolbar { gap: 4px; }
  .toolbar-button { padding-inline: 7px; }
  .workspace { grid-template-columns: minmax(295px, 43%) minmax(0, 1fr); gap: 15px; }
  .panel-title, .gallery-heading { padding: 17px; min-height: 65px; }
  .form-content { padding: 17px; gap: 16px; }
  .form-footer { padding: 15px 17px 17px; }
  .gallery-body { padding: 13px; }
  .usage-tip { padding: 12px 15px; align-items: flex-start; }
  .usage-tip svg { margin-top: 2px; }
  .gallery-heading, .selection { gap: 7px; }
}
@media (max-width: 690px) {
  .topbar-inner { padding: 8px 15px; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .topbar-inner .theme-button { grid-column: 2; grid-row: 1; }
  .toolbar .balance:disabled { display: none; }
  .brand { gap: 8px; }
  .brand-mark { width: 48px; }
  .brand-name { font-size: 24px; }
  .toolbar { grid-column: 1 / -1; grid-row: 2; width: 100%; justify-content: flex-start; gap: 6px; }
  .toolbar-button, .balance { padding-inline: 6px; font-size: 12px; }
  .toolbar .key-button { padding-inline: 8px; }
  .toolbar-rule { display: none; }
  .toolbar-button { gap: 4px; }
  .toolbar-button, .balance, .square-button { min-height: 32px; }
  .square-button { width: 32px; }
  .workspace { padding: 15px 12px 24px; grid-template-columns: minmax(0, 1fr); gap: 15px; }
  .panel { border-radius: 12px; }
  .panel h1, .panel h2 { font-size: 19px; }
  .panel-title, .gallery-heading { min-height: 57px; padding: 13px 16px; }
  .form-content { padding: 16px; gap: 15px; }
  .form-footer { border-radius: 0 0 12px 12px; }
  #prompt { min-height: 103px; }
  .gallery-body { min-height: 245px; }
  .gallery-empty p { max-width: 240px; }
  .gallery-title { gap: 7px; }
  .selection { gap: 8px; }
  .modal { padding: 19px; }
  .wallet-balances > div { padding: 7px; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
}
@media (max-width: 480px) {
  .model-fields { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .model-fields .field { grid-template-columns: 2em minmax(0, 1fr); align-items: center; gap: 10px; }
}
@media (max-width: 380px) {
  .toolbar { gap: 4px; }
  .toolbar-button svg { display: none; }
  .toolbar-button, .balance { padding-inline: 4px; }
}
