:root {
  color-scheme: light;
  --paper: #f7f7f2;
  --surface: #fffefa;
  --ink: #253d37;
  --muted: #69756e;
  --line: #dfe4db;
  --accent: #356d60;
  --accent-light: #eaf1eb;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-underline-offset: 4px; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; }
button:disabled { opacity: .48; }
button, select, textarea { color: var(--ink); }
button { border: 0; }
button, a, input, select, textarea, summary { touch-action: manipulation; }
:focus-visible { outline: 3px solid #548f7b; outline-offset: 4px; }
h1, h2, h3, p, figure, dl, dd { margin: 0; }
h1, h2, h3 { font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 17px; }
img { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.page-width { width: min(1344px, calc(100% - 80px)); margin-inline: auto; }
.skip-link { position: fixed; top: -100px; left: 20px; z-index: 10; background: var(--surface); padding: 12px 20px; }
.skip-link:focus { top: 10px; }

.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font-size: 21px; font-weight: 650; letter-spacing: -.6px; }
.brand svg { color: var(--accent); }
.brand-divider { margin: 0 9px; color: #b8c1b6; font-weight: 400; }
.brand-section { color: var(--muted); font-size: 13px; font-weight: 400; letter-spacing: .02em; }
.back-link { padding: 10px 0 10px 12px; text-decoration: none; font-size: 13px; white-space: nowrap; }
.back-link span { margin-left: 10px; }
.back-link:hover, .site-footer a:hover { color: var(--accent); text-decoration: underline; }
.page-intro { padding: 36px 0 12px; display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.eyebrow { font-size: 10px; font-weight: 600; letter-spacing: .15em; color: var(--muted); }
.preview-badge { display: inline-block; margin-left: 10px; padding: 2px 7px; border: 1px solid #d7e3d8; border-radius: 4px; background: var(--accent-light); color: var(--accent); letter-spacing: .03em; font-size: 10px; }
h1 { margin-top: 7px; font-size: clamp(27px, 3vw, 35px); letter-spacing: -.035em; line-height: 1.4; }
.page-intro > div > p { margin-top: 6px; color: var(--muted); font-size: 14px; }
.preview-note { color: var(--muted); font-size: 12px; text-align: right; line-height: 1.8; }
.status-line { min-height: 24px; margin: 0 0 17px; color: var(--accent); font-size: 12px; }
.notice { padding: 13px 17px; margin-bottom: 18px; border: 1px solid; border-radius: 9px; overflow-wrap: anywhere; font-size: 13px; }
.notice.error { color: #933e32; background: #fff1eb; border-color: #eccfc4; }
.notice.warning { color: #775723; background: #fbf3dc; border-color: #e6d8b4; }

.workspace { display: grid; grid-template-columns: 346px minmax(0, 1fr); gap: 24px; align-items: start; }
.workspace > *, .setting-section, .canvas-panel > * { min-width: 0; }
.settings-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.setting-section { padding: 20px 22px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.step { margin-right: 10px; font-size: 10px; font-weight: 500; color: var(--muted); letter-spacing: .05em; }
.text-button { padding: 6px 0; min-height: 32px; background: transparent; font-size: 12px; color: var(--accent); text-align: left; text-decoration: underline; text-decoration-color: #c2d0c4; text-underline-offset: 4px; }
.text-button:hover:not(:disabled) { text-decoration-color: var(--accent); }
.drop-zone { margin-top: 12px; border: 1px dashed #becabf; border-radius: 9px; background: #f7f8f3; transition: background .15s, border-color .15s; }
.drop-zone:focus-within { outline: 3px solid #548f7b; outline-offset: 3px; }
.drop-zone:hover, .drop-zone.drag-over { background: var(--accent-light); border-color: var(--accent); }
.upload-target { padding: 17px 8px; min-height: 125px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; text-align: center; }
.upload-target svg { color: var(--accent); margin-bottom: 9px; }
.upload-target strong { font-size: 13px; font-weight: 500; }
.upload-target span { color: var(--muted); font-size: 10px; margin-top: 4px; }
fieldset:disabled .upload-target { cursor: not-allowed; opacity: .55; }
.source-info { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.source-info img { border-radius: 5px; width: 48px; height: 48px; object-fit: contain; border: 1px solid var(--line); background: #f0f1eb; }
.source-info div { min-width: 0; }
.source-info strong { display: block; font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-info span { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.field-help { color: var(--muted); font-size: 11px; line-height: 1.8; margin-top: 9px; overflow-wrap: anywhere; }
.style-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 15px; }
.style-option { position: relative; min-width: 0; }
.style-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.style-card { display: flex; flex-direction: column; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; cursor: pointer; transition: border-color .15s, background .15s; }
.style-card strong { font-size: 11px; font-weight: 500; margin-top: 5px; }
.style-card small { font-size: 9px; color: var(--muted); }
.style-option input:checked + .style-card { border-color: var(--accent); background: var(--accent-light); box-shadow: inset 0 0 0 1px var(--accent); }
.style-option input:focus-visible + .style-card { outline: 3px solid #548f7b; outline-offset: 3px; }
.style-option input:disabled + .style-card { opacity: .55; cursor: not-allowed; }
.style-option:hover .style-card { border-color: #8eac98; }
.style-swatch { height: 33px; border-radius: 3px; overflow: hidden; background-color: #eeece2; }
.sketch { background: repeating-linear-gradient(132deg, transparent 0 3px, #737a7066 3px 4px, transparent 4px 7px), linear-gradient(90deg, #edece4, #c9cbbf); }
.oil { background: repeating-linear-gradient(160deg, #8b9e8377 0 8px, #c2b381aa 8px 17px, #506e5866 17px 22px), #b4b99b; }
.watercolor { background: radial-gradient(ellipse at 30% 80%, #689e9777, transparent 65%), radial-gradient(ellipse at 75% 15%, #cbb884aa, transparent 75%), #edf0e3; }
.anime { background: linear-gradient(135deg, #e6cdac 0 42%, #536c68 42% 45%, #cbdace 45% 78%, #667e79 78%); }
.lineart { background: repeating-radial-gradient(ellipse at 90% 100%, #f3f2e9 0 6px, #63716a 6px 7px, #f3f2e9 7px 13px); }
.custom { background: linear-gradient(90deg, transparent 49%, #8b9a8640 49% 51%, transparent 51%), linear-gradient(transparent 49%, #8b9a8640 49% 51%, transparent 51%), #eef0e6; background-size: 15px 15px; }
.field-label { display: block; margin: 15px 0 7px; font-size: 12px; font-weight: 500; }
.field-label span { margin-left: 5px; font-size: 10px; font-weight: 400; color: var(--muted); }
textarea, select { width: 100%; min-width: 0; background: #fffefa; border: 1px solid #d5dbd0; border-radius: 7px; padding: 10px; font-size: 12px; }
textarea { resize: vertical; min-height: 88px; line-height: 1.7; display: block; }
textarea::placeholder { color: #788278; }
[aria-invalid="true"] { outline: 2px solid #aa5746; outline-offset: 2px; }
#upload-input[aria-invalid="true"] + .upload-target { outline: 2px solid #aa5746; border-radius: 8px; }
.revision-panel { display: flex; gap: 10px; padding: 12px; margin-top: 12px; background: var(--accent-light); border-radius: 7px; }
.revision-panel img { width: 42px; height: 42px; object-fit: contain; background: #fff; border-radius: 4px; }
.revision-panel div { min-width: 0; }
.revision-panel strong { font-size: 12px; font-weight: 500; }
.revision-panel p { color: var(--muted); font-size: 10px; }
.revision-panel .text-button { font-size: 10px; }
.output-fields { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; }
.output-fields select { min-height: 42px; }
.generate-section { padding: 20px 22px; }
.consent-label { display: flex; align-items: flex-start; gap: 9px; font-size: 11px; line-height: 1.8; cursor: pointer; }
.consent-label input { accent-color: var(--accent); width: 16px; height: 16px; margin: 3px 0 0; flex-shrink: 0; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 10px 16px; background: var(--surface); border: 1px solid #cbd6ca; border-radius: 7px; font-size: 12px; font-weight: 500; }
.button:hover:not(:disabled) { background: var(--accent-light); border-color: var(--accent); }
.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button.primary:hover:not(:disabled) { background: #29594d; }
.generate-button { width: 100%; margin-top: 17px; font-size: 13px; min-height: 46px; }
.generation-footnote { margin-top: 8px; font-size: 10px; color: var(--muted); text-align: center; }

.canvas-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: sticky; top: 20px; }
.canvas-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.canvas-toolbar h2 { font-size: 16px; margin-top: 3px; }
.canvas-toolbar .eyebrow { font-size: 9px; }
.state-label { padding: 4px 9px; border-radius: 5px; background: var(--accent-light); color: var(--accent); font-size: 11px; white-space: nowrap; }
.empty-canvas { min-height: 555px; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 50px 24px; text-align: center; background-image: radial-gradient(#a9b4a33d .7px, transparent .7px); background-size: 17px 17px; }
.empty-frame { width: 128px; height: 150px; display: grid; place-items: center; border: 1px solid #d4ddcf; border-radius: 3px; background: #fafbf6; color: #98ad9b; box-shadow: 9px 10px 0 -1px #f0f2e9, 9px 10px 0 0 #dfe5d7; transform: rotate(-5deg); margin-bottom: 32px; }
.empty-canvas h3 { font-size: 19px; font-weight: 500; letter-spacing: .03em; }
.empty-canvas p { margin-top: 12px; line-height: 1.9; color: var(--muted); font-size: 12px; }
.empty-caption { margin-top: 55px; color: var(--muted); font-size: 10px; letter-spacing: .1em; }
.result-controls { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 15px 20px 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #f3f5ee; }
.segmented button { font-size: 11px; min-height: 34px; padding: 6px 10px; border-radius: 4px; background: transparent; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px #20382012; }
.image-stage { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 20px; }
.image-stage.result-only { grid-template-columns: minmax(0, 1fr); }
.image-figure { min-width: 0; }
.image-figure figcaption { display: flex; flex-wrap: wrap; gap: 5px; align-items: baseline; justify-content: space-between; font-size: 11px; margin-bottom: 9px; }
.image-figure figcaption span { color: var(--muted); font-size: 9px; }
.image-well { height: clamp(320px, 36vw, 500px); display: flex; align-items: center; justify-content: center; background: #eef0e8; border: 1px solid #e4e8de; border-radius: 7px; overflow: hidden; }
.image-well > img { width: 100%; height: 100%; object-fit: contain; }
.result-well { background: #f5f5ee; }
.result-placeholder { padding: 24px 15px; text-align: center; width: 100%; }
.result-placeholder h3 { font-size: 14px; font-weight: 500; }
.result-placeholder p { margin-top: 9px; color: var(--muted); font-size: 11px; line-height: 1.9; overflow-wrap: anywhere; }
.result-placeholder .elapsed-time { color: var(--accent); font-variant-numeric: tabular-nums; font-size: 16px; margin-top: 20px; }
.spinner { display: block; width: 24px; height: 24px; border: 2px solid #d6e1d4; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 20px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.canvas-note { padding: 0 20px 17px; font-size: 10px; color: var(--muted); }
.result-details { padding: 18px 20px; border-top: 1px solid var(--line); }
.result-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; margin-bottom: 20px; }
.result-metadata { font-size: 10px; display: grid; gap: 5px; }
.result-metadata > div { display: grid; grid-template-columns: 65px minmax(0, 1fr); gap: 10px; }
.result-metadata dt { color: var(--muted); }
.result-metadata dd { overflow-wrap: anywhere; }
#result-model, #result-request { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.parameter-details { margin-top: 10px; font-size: 11px; }
.parameter-details summary { cursor: pointer; color: var(--accent); padding: 5px 0; }
.parameter-details p { margin-top: 7px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
#save-state.unsaved { color: #95652a; font-weight: 500; }

.history-section { margin-top: 38px; }
.history-heading { margin-bottom: 18px; }
.history-heading .section-heading { justify-content: flex-start; flex-wrap: wrap; gap: 14px; }
.history-heading h2 { font-size: 18px; }
.local-badge { font-size: 10px; color: var(--muted); }
.history-heading p { margin-top: 7px; font-size: 11px; color: var(--muted); }
.history-empty { border-block: 1px solid var(--line); padding: 31px 16px; color: var(--muted); text-align: center; font-size: 12px; }
.history-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 16px; }
.history-list li { min-width: 0; }
.history-card { width: 100%; padding: 0; border-radius: 9px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; text-align: left; }
.history-card:hover:not(:disabled), .history-card[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.history-card img { width: 100%; height: 155px; object-fit: contain; background: #eaece3; }
.history-card span { display: block; padding: 11px 12px; }
.history-card strong { display: block; font-size: 12px; font-weight: 500; }
.history-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.site-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 14px; padding: 25px 0; margin-top: 36px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.site-footer a { text-decoration: none; }

@media (min-width: 1600px) { .workspace { grid-template-columns: 364px minmax(0, 1fr); gap: 28px; } }
@media (max-width: 1100px) {
  .page-width { width: calc(100% - 40px); }
  .workspace { grid-template-columns: 310px minmax(0, 1fr); gap: 18px; }
  .setting-section, .generate-section { padding-inline: 17px; }
  .image-stage { padding: 16px; gap: 10px; }
  .canvas-toolbar { padding-inline: 18px; }
  .image-well { height: 370px; }
}
@media (max-width: 820px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .canvas-panel { position: static; }
  .setting-section, .generate-section { padding: 20px 24px; }
  .style-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .style-card { padding: 8px; }
  .style-swatch { height: 40px; }
  .empty-canvas { min-height: 390px; }
  .image-well { height: 420px; }
}
@media (max-width: 560px) {
  .page-width { width: calc(100% - 28px); }
  .topbar { min-height: 62px; }
  .brand { font-size: 19px; gap: 8px; }
  .brand-divider, .brand-section { display: none; }
  .page-intro { padding-top: 25px; display: block; }
  .preview-note { margin-top: 12px; text-align: left; font-size: 11px; }
  .preview-note br { display: none; }
  .status-line { margin-bottom: 13px; }
  .settings-panel, .canvas-panel { border-radius: 12px; }
  .setting-section, .generate-section { padding: 18px; }
  .style-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
  .style-card strong { font-size: 12px; }
  .style-card small { font-size: 10px; }
  .style-swatch { height: 42px; }
  .canvas-toolbar { padding: 16px; }
  .canvas-note { padding-inline: 16px; }
  .image-stage { grid-template-columns: minmax(0, 1fr); }
  .image-well { height: min(100vw, 400px); }
  .image-figure figcaption { margin-bottom: 6px; }
  .image-stage:not(.result-only) { gap: 20px; }
  .result-controls { padding: 13px 15px 0; }
  .result-details { padding: 16px; }
  .result-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .result-actions .button { width: 100%; }
  .history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .history-card img { height: 145px; }
  .history-section { margin-top: 28px; }
  .site-footer { margin-top: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
