@import "./tokens.css";

:root {
  color-scheme: light;
  --ink: var(--color-ink);
  --muted: var(--color-muted);
  --line: var(--color-hairline);
  --paper: var(--color-canvas);
  --accent: var(--color-primary-active);
  --tint: var(--color-surface-card);
  --accent-hover: color-mix(in srgb, var(--color-primary-active) 86%, var(--color-ink));
  --error-tint: color-mix(in srgb, var(--color-error) 5%, var(--color-canvas));
  --error-line: color-mix(in srgb, var(--color-error) 25%, var(--color-hairline));
  --error-text: color-mix(in srgb, var(--color-error) 75%, var(--color-ink));
  --backdrop: color-mix(in srgb, var(--color-surface-dark) 80%, transparent);
  --display-font: Georgia, "Songti SC", "Noto Serif CJK SC", "STSong", serif;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 14px; line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, .button { cursor: pointer; }
button, .button, select, input, textarea { border: 1px solid var(--line); border-radius: 9px; }
button, .button { background: var(--color-canvas); padding: 9px 14px; font-weight: 550; text-decoration: none; text-align: center; transition: background .2s ease, border-color .2s ease, color .2s ease, transform .2s ease; }
button:hover, .button:hover { background: var(--color-surface-soft); border-color: var(--color-surface-cream-strong); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--color-primary); outline-offset: 3px;
}
a { color: var(--accent); text-underline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-family: var(--display-font); font-size: clamp(27px, 3vw, 36px); line-height: 1.35; letter-spacing: -.8px; font-weight: 400; text-wrap: balance; }
h2 { font-size: 17px; letter-spacing: -.3px; font-weight: 650; }
h3 { font-size: 15px; }
.site-header { border-bottom: 1px solid var(--line); background: var(--color-canvas); }
.nav { max-width: 1440px; margin: auto; min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 32px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { width: 34px; height: 34px; object-fit: cover; border-radius: 9px; }
.brand strong { font-size: 16px; letter-spacing: -.3px; }
.brand span { color: var(--muted); margin-left: 9px; padding-left: 13px; border-left: 1px solid var(--line); font-size: 13px; }
.nav-links { display: flex; align-items: center; gap: 22px; font-size: 13px; }
.nav-links a { color: var(--muted); text-decoration: none; }
main { max-width: 1440px; margin: auto; padding: 30px 32px 48px; }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.intro p { color: var(--muted); margin-top: 8px; }
.intro-note { font-size: 12px; color: var(--muted); white-space: nowrap; }
.workspace { display: grid; grid-template-columns: minmax(320px, 410px) minmax(0, 1fr); gap: 24px; align-items: start; }
.controls { background: var(--color-canvas); border: 1px solid var(--line); border-radius: 16px; padding: 22px; min-width: 0; }
fieldset { padding: 0; margin: 0; border: 0; min-width: 0; }
.section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.section-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-weight: 600; }
.eyebrow { text-transform: uppercase; color: var(--muted); font-size: 10px; letter-spacing: 1.4px; margin-bottom: 3px; }
.small, .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.hint { margin-top: 8px; line-height: 1.65; }
summary { cursor: pointer; font-weight: 550; }
.connection summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.connection summary::after { content: "+"; font-size: 18px; font-weight: 400; }
.connection[open] summary::after { content: "−"; }
.connection input[type=password], .connection input[type=text] { width: 100%; margin: 12px 0 8px; }
.connection small { display: block; color: var(--muted); margin-top: 10px; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.text-button { border: 0; background: none; padding: 4px 0; font-size: 12px; color: var(--muted); }
.text-button:hover { background: none; color: var(--ink); }
.segments { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--color-surface-soft); border-radius: 10px; margin: 20px 0; }
.segments label { position: relative; cursor: pointer; text-align: center; }
.segments input { position: absolute; opacity: 0; }
.segments span { display: block; padding: 8px; border-radius: 7px; color: var(--muted); }
.segments input:checked + span { background: var(--color-canvas); color: var(--ink); box-shadow: 0 1px 4px color-mix(in srgb, var(--color-ink) 6%, transparent); font-weight: 600; }
.segments input:focus-visible + span { outline: 2px solid var(--accent); }
.segments input:disabled + span { opacity: .5; cursor: not-allowed; }
textarea, select, input[type=password], input[type=text], input[type=number] { background: var(--color-canvas); padding: 10px 12px; width: 100%; }
textarea { display: block; resize: vertical; min-height: 154px; max-height: 420px; line-height: 1.75; }
textarea::placeholder { color: var(--color-muted); }
.prompt-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
#prompt-count { font-variant-numeric: tabular-nums; }
.prompt-examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.prompt-examples button { font-size: 11px; padding: 5px 9px; border-color: transparent; background: var(--color-surface-soft); font-weight: 400; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid label, .field { display: grid; gap: 7px; font-size: 12px; font-weight: 550; }
.field-grid + .field-grid { margin-top: 14px; }
.field-grid select { min-width: 0; }
.model-id { display: block; font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); margin-top: 9px; }
.advanced { margin-top: 16px; }
.advanced .field-grid { margin-top: 12px; }
.upload-zone { padding: 15px; border: 1px dashed var(--color-surface-cream-strong); background: var(--color-canvas); border-radius: 10px; margin-bottom: 16px; }
.upload-zone.dragover { border-color: var(--accent); background: var(--tint); }
.upload-zone input { max-width: 100%; font-size: 12px; margin-top: 8px; }
.upload-zone input::file-selector-button { border: 0; background: var(--tint); color: var(--accent); padding: 7px 10px; border-radius: 6px; margin-right: 8px; cursor: pointer; }
.reference-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.reference-row img { width: 58px; height: 58px; object-fit: contain; border-radius: 6px; background: var(--color-canvas); }
#reference-name { overflow-wrap: anywhere; flex: 1; font-size: 12px; min-width: 0; }
.launch { margin-top: 22px; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--color-on-primary); }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
#generate { width: 100%; min-height: 46px; font-size: 14px; }
.launch .hint { text-align: center; font-size: 11px; }
.stage { min-width: 0; }
.stage-header { display: flex; align-items: center; justify-content: space-between; min-height: 30px; margin: 0 2px 12px; gap: 12px; }
.status-badge { font-size: 11px; padding: 3px 9px; border-radius: 5px; background: var(--tint); color: var(--color-body); white-space: nowrap; }
.canvas { background: var(--color-surface-soft); border: 1px solid var(--color-hairline); border-radius: 16px; min-height: 460px; overflow: hidden; }
.empty { min-height: 460px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 35px; }
.empty-art { width: clamp(180px, 24vw, 250px); height: auto; margin-bottom: 24px; color: var(--color-muted); }
.empty-art .paper { fill: var(--color-canvas); stroke: var(--color-surface-cream-strong); }
.empty-art .accent { stroke: var(--color-primary); }
.empty h3 { font-family: var(--display-font); font-size: 21px; font-weight: 400; margin-bottom: 8px; }
.empty p { font-size: 13px; color: var(--muted); max-width: 320px; }
.busy { border-radius: 11px; border: 1px solid var(--color-hairline); background: var(--color-surface-soft); padding: 16px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.busy p { font-size: 12px; color: var(--muted); margin-top: 4px; }
.spinner { display: inline-block; height: 12px; width: 12px; border: 2px solid var(--color-surface-cream-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg); } }
.message { padding: 13px 16px; border-radius: 9px; background: var(--color-surface-soft); border: 1px solid var(--line); margin-bottom: 14px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.error { background: var(--error-tint); border-color: var(--error-line); color: var(--error-text); }
.result { margin: 0; padding: 16px; }
.result + .result { border-top: 1px solid var(--line); }
.image-preview { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.image-preview:hover { background: none; }
.image-preview img { max-width: 100%; max-height: 640px; display: block; object-fit: contain; margin: auto; border-radius: 7px; }
.result figcaption { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.result figcaption .button { font-size: 12px; background: var(--color-canvas); }
.canvas-note { color: var(--muted); font-size: 12px; margin: 13px 3px 0; }
.history { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.history-head p { font-size: 12px; color: var(--muted); margin-top: 4px; }
.history-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.history-card { min-width: 0; background: var(--color-canvas); border: 1px solid var(--line); border-radius: 11px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.history-thumb { width: 100%; height: 135px; object-fit: contain; border-radius: 6px; background: var(--color-surface-soft); }
.history-prompt { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 12px; overflow-wrap: anywhere; }
.history-card time { color: var(--muted); font-size: 10px; }
.history-actions { display: flex; gap: 7px; margin-top: auto; flex-wrap: wrap; }
.history-actions button, .history-actions a { font-size: 11px; padding: 5px 8px; }
.history-empty { padding: 22px 0; color: var(--muted); font-size: 13px; }
#legacy-history { margin-top: 20px; }
#legacy-list { margin-top: 12px; }
footer { padding: 0 24px 28px; text-align: center; color: var(--muted); font-size: 11px; }
dialog { max-width: min(96vw, 1400px); max-height: 94dvh; width: fit-content; border: 0; border-radius: 12px; padding: 15px; background: var(--paper); }
dialog::backdrop { background: var(--backdrop); }
.dialog-toolbar { display: flex; justify-content: end; gap: 12px; margin-bottom: 12px; }
dialog img { display: block; max-width: 100%; max-height: 78dvh; object-fit: contain; }
@media (min-width: 1600px) { main { padding-top: 40px; } .canvas, .empty { min-height: 530px; } }
@media (max-width: 1050px) { .workspace { grid-template-columns: 350px minmax(0, 1fr); gap: 18px; } .controls { padding: 18px; } .history-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 800px) {
  .nav { padding: 12px 18px; } main { padding: 24px 18px 32px; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .intro-note { display: none; } .nav-links { gap: 16px; }
  .canvas, .empty { min-height: 300px; }
  .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-header { margin-top: 0; } .empty-art { width: 175px; }
}
@media (max-width: 430px) {
  .brand span { display: none; } .nav-links { font-size: 12px; gap: 12px; }
  main { padding: 20px 12px 30px; } .controls { padding: 16px; }
  .intro p { font-size: 12px; } .history-head { align-items: start; }
  .history-grid { gap: 10px; } .history-card { padding: 10px; }
  .busy { align-items: start; } .busy button { flex-shrink: 0; padding: 7px 9px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Only decorative controls lift. Generated images are never recolored or filtered. */
@keyframes studio-reveal {
  from { opacity: .65; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: no-preference) {
  .result { animation: studio-reveal .38s cubic-bezier(.2, .65, .3, 1); }
  .busy:not([hidden]), .message:not([hidden]), #reference-section:not([hidden]), dialog[open] {
    animation: studio-reveal .22s ease-out;
  }
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .primary:not(:disabled):hover, .prompt-examples button:not(:disabled):hover { transform: translateY(-1px); }
  .primary:not(:disabled):active, .prompt-examples button:not(:disabled):active { transform: translateY(0); }
}
textarea, select, input[type=password], input[type=text], input[type=number] {
  transition: border-color .2s ease, background .2s ease;
}
textarea:hover, select:hover { border-color: var(--color-surface-cream-strong); }
textarea:focus, input:focus, select:focus { border-color: var(--color-primary); }
.segments span { transition: background .2s ease, color .2s ease, box-shadow .2s ease; }
.history-card { transition: border-color .2s ease; }
.history-card:hover { border-color: var(--color-surface-cream-strong); }
