:root {
  color-scheme: light;
  --ink: #2d2927;
  --muted: #8f817a;
  --muted-strong: #5f514b;
  --bg: #fbf4ee;
  --panel: #fffaf6;
  --panel-strong: #f7ebe4;
  --line: #ead9ce;
  --line-soft: #f1e6df;
  --coral: #c96850;
  --coral-deep: #a95340;
  --teal: #4d7c9a;
  --yellow: #b78a42;
  --shadow: 0 18px 42px rgba(102, 72, 52, 0.09);
  --radius: 9px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.app-shell { min-height: 100vh; }
.topbar { height: 68px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: #fff9f4; position: sticky; top: 0; z-index: 20; }
.brand-lockup, .topbar-actions, .runtime-status, .section-heading-row, .field-label-row, .form-actions, .library-actions { display: flex; align-items: center; }
.brand-lockup { gap: 12px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--coral); border-radius: 50%; color: var(--coral); font-weight: 800; letter-spacing: -0.08em; font-size: 13px; }
.brand-title { font-size: 13px; font-weight: 800; letter-spacing: 0.18em; }
.brand-subtitle { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar-actions { gap: 14px; }
.runtime-status { gap: 7px; color: var(--muted-strong); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 3px rgba(231, 191, 107, 0.13); }
.status-dot.ready { background: var(--teal); box-shadow: 0 0 0 3px rgba(120, 194, 182, 0.13); }
.status-dot.error { background: var(--coral); box-shadow: 0 0 0 3px rgba(240, 123, 98, 0.13); }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; color: var(--muted-strong); border: 1px solid var(--line); background: transparent; border-radius: 6px; text-decoration: none; transition: color .18s ease, border-color .18s ease, background .18s ease; }
.icon-button:hover { color: var(--ink); border-color: #c9aaa0; background: var(--panel-strong); }

.app-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { padding: 28px 18px 24px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; background: #fff8f2; }
.sidebar-label, .section-kicker { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.16em; }
.sidebar-label { padding: 0 10px 10px; }
.nav-button, .side-prompt { width: 100%; min-height: 38px; padding: 0 10px; display: flex; align-items: center; gap: 10px; border: 1px solid transparent; color: var(--muted-strong); background: transparent; border-radius: 6px; text-align: left; }
.nav-button:hover, .nav-button.active { color: var(--ink); background: var(--panel-strong); border-color: #e4cfc3; }
.nav-icon { width: 18px; color: var(--coral); text-align: center; }
.nav-count { margin-left: auto; min-width: 20px; padding: 2px 6px; border: 1px solid var(--line); color: var(--muted); border-radius: 10px; font-size: 11px; text-align: center; }
.sidebar-rule { height: 1px; background: var(--line-soft); margin: 22px 10px 16px; }
.side-prompt { color: var(--muted); font-size: 12px; }
.side-prompt:hover { color: var(--ink); }
.sidebar-footer { margin-top: auto; padding: 16px 10px 0; color: #a58d82; font-size: 10px; letter-spacing: .14em; line-height: 1.7; }
.sidebar-footer span { color: #c8b5aa; letter-spacing: .05em; }

.main-content { min-width: 0; padding: 42px clamp(20px, 4vw, 64px) 70px; }
.workspace-grid { display: grid; grid-template-columns: minmax(380px, 0.88fr) minmax(480px, 1.12fr); gap: 24px; max-width: 1560px; margin: 0 auto; }
.composer-panel, .output-panel, .library-section { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.composer-panel, .output-panel { padding: 28px; }
.section-heading-row { justify-content: space-between; gap: 18px; }
h1, h2, p { margin: 0; }
h1 { margin-top: 8px; font-size: clamp(24px, 2.5vw, 32px); line-height: 1.15; letter-spacing: -0.025em; }
h2 { margin-top: 8px; font-size: 21px; letter-spacing: -0.015em; }
.section-note { margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.mode-chip { padding: 6px 8px; color: var(--teal); border: 1px solid rgba(120, 194, 182, 0.38); border-radius: 4px; font-size: 9px; font-weight: 800; letter-spacing: .13em; white-space: nowrap; }

form { margin-top: 32px; }
.field-block { min-width: 0; }
.field-block label, .field-label { display: block; margin-bottom: 9px; color: var(--muted-strong); font-size: 12px; font-weight: 650; }
.field-label-row { justify-content: space-between; margin-bottom: 9px; color: var(--muted); font-size: 11px; }
.field-label-row label { margin-bottom: 0; }
.label-hint { margin-left: 6px; color: var(--muted); font-size: 10px; font-weight: 400; }
textarea, input, select { width: 100%; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; background: #fffdfb; transition: border-color .18s ease, background .18s ease; }
textarea, input { padding: 11px 12px; }
select { min-height: 40px; padding: 0 10px; }
textarea { min-height: 134px; resize: vertical; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: #b6a59b; }
textarea:hover, input:hover, select:hover, textarea:focus, input:focus, select:focus { border-color: #caa99b; background: #fffaf7; outline: none; }
.prompt-suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.prompt-chip { padding: 6px 9px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; background: transparent; font-size: 11px; }
.prompt-chip:hover { color: var(--ink); border-color: #586777; background: var(--panel-strong); }
.field-block + .field-block { margin-top: 20px; }
.prompt-field + .field-block { margin-top: 26px; }
.muted { color: var(--muted); }

.dropzone { min-height: 70px; padding: 13px; display: flex; align-items: center; gap: 12px; border: 1px dashed #d4b9aa; border-radius: 6px; background: #fffaf7; }
.dropzone:hover, .dropzone.dragging { border-color: var(--teal); background: #f6f6f1; }
.dropzone-icon { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #c7aea1; border-radius: 50%; color: var(--teal); font-size: 21px; }
.dropzone strong, .dropzone span { display: block; }
.dropzone strong { font-size: 12px; }
.dropzone span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.reference-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.reference-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--line); border-radius: 5px; background: #fff7f2; }
.reference-item img { width: 100%; height: 100%; display: block; object-fit: cover; }
.remove-reference { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; display: grid; place-items: center; border: 0; border-radius: 50%; color: #fff; background: rgba(73, 54, 47, 0.7); font-size: 13px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.provider-grid { margin-top: 26px; }
.controls-grid { margin-top: 24px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.full-span { grid-column: 1 / -1; }
.key-field input { letter-spacing: .06em; }
.toggle-field { min-height: 40px; display: flex; align-items: center; gap: 8px; color: var(--muted-strong); font-size: 12px; }
.toggle-field input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui { width: 30px; height: 18px; position: relative; border: 1px solid #c8afa3; border-radius: 12px; background: #f7ebe4; transition: all .18s ease; }
.toggle-ui::after { content: ""; width: 12px; height: 12px; position: absolute; top: 2px; left: 2px; border-radius: 50%; background: #b79f94; transition: transform .18s ease, background .18s ease; }
.toggle-field input:checked + .toggle-ui { border-color: var(--teal); background: rgba(120, 194, 182, .16); }
.toggle-field input:checked + .toggle-ui::after { transform: translateX(12px); background: var(--teal); }

.advanced-details { margin-top: 22px; border-top: 1px solid var(--line-soft); }
.advanced-details summary { padding: 17px 0; color: var(--muted-strong); cursor: pointer; font-size: 12px; list-style-position: inside; }
.advanced-details summary::marker { color: var(--coral); }
.advanced-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; padding-bottom: 8px; }
.advanced-grid .field-block { min-width: 0; }
.advanced-grid .field-block + .field-block { margin-top: 0; }
.advanced-grid .toggle-field { align-self: end; }
.comfy-workflow-field { grid-column: 1 / -1; }
.comfy-workflow-field input[type=file] { padding: 9px; color: var(--muted); font-size: 11px; }
.comfy-workflow-field textarea { min-height: 90px; margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }

.form-actions { justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line-soft); }
.request-hint { min-width: 0; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.primary-button, .ghost-button { min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.primary-button { min-width: 136px; border: 1px solid var(--coral); color: #fffaf6; background: var(--coral); }
.primary-button:hover { background: #ff8d73; border-color: #ff8d73; }
.primary-button:disabled { opacity: .6; cursor: wait; }
.button-icon { font-size: 16px; }
.ghost-button { border: 1px solid var(--line); color: var(--muted-strong); background: transparent; }
.ghost-button:hover:not(:disabled) { color: var(--ink); border-color: #c9aaa0; background: var(--panel-strong); }
.ghost-button:disabled { color: #c0aca1; cursor: not-allowed; }

.output-panel { min-height: 650px; display: flex; flex-direction: column; }
.output-heading { margin-bottom: 22px; }
.output-grid { min-height: 490px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-content: start; }
.empty-state { grid-column: 1 / -1; min-height: 445px; display: grid; place-items: center; align-content: center; gap: 12px; border: 1px dashed #d4b9aa; border-radius: 6px; background: #fffaf7; text-align: center; }
.empty-state strong { font-size: 14px; }
.empty-state p { color: var(--muted); font-size: 12px; }
.empty-art { width: 100px; height: 100px; position: relative; margin-bottom: 8px; border: 1px solid #d6bbae; border-radius: 50%; }
.empty-art::before, .empty-art::after { content: ""; position: absolute; border: 1px solid #c8ada1; }
.empty-art::before { inset: 22px 16px; transform: rotate(-12deg); }
.empty-art::after { inset: 17px 31px; transform: rotate(28deg); border-color: var(--teal); }
.empty-art span { width: 5px; height: 5px; position: absolute; border-radius: 50%; background: var(--coral); }
.empty-art span:nth-child(1) { top: 21px; left: 20px; }.empty-art span:nth-child(2) { right: 17px; bottom: 23px; background: var(--yellow); }.empty-art span:nth-child(3) { top: 16px; right: 26px; background: var(--teal); }
.result-card, .gallery-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fffdfb; }
.result-image-wrap, .gallery-image-wrap { position: relative; background: #f7eee8; }
.result-image-wrap { aspect-ratio: 1; }
.result-image-wrap img, .gallery-image-wrap img { width: 100%; height: 100%; display: block; object-fit: cover; }
.result-image-wrap img { position: absolute; inset: 0; }
.result-card-body, .gallery-card-body { padding: 10px 11px 11px; }
.result-card-meta, .gallery-card-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; }
.result-card-title, .gallery-card-title { margin-top: 5px; color: var(--muted-strong); font-size: 11px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-actions { display: flex; gap: 6px; margin-top: 10px; }
.small-button { min-height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted-strong); background: transparent; font-size: 10px; }
.small-button:hover { border-color: #c9aaa0; color: var(--ink); background: #fff7f2; }
.small-button.accent { border-color: rgba(120, 194, 182, .45); color: var(--teal); }
.activity-log { min-height: 34px; display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 11px; }
.log-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); }

.library-section { max-width: 1560px; margin: 24px auto 0; padding: 28px; scroll-margin-top: 96px; }
.gallery-grid { margin-top: 24px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.gallery-image-wrap { aspect-ratio: 1; }
.gallery-empty { grid-column: 1 / -1; padding: 56px 20px; border: 1px dashed #d4b9aa; border-radius: 6px; color: var(--muted); font-size: 12px; text-align: center; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); padding: 11px 14px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fffaf6; box-shadow: var(--shadow); font-size: 12px; transform: translate(-50%, 120px); opacity: 0; pointer-events: none; transition: transform .2s ease, opacity .2s ease; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.toast.error { border-color: rgba(240, 123, 98, .55); }

@media (max-width: 1160px) {
  .app-body { grid-template-columns: 180px minmax(0, 1fr); }
  .main-content { padding-inline: 24px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .output-panel { min-height: 560px; }
  .gallery-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar { height: 64px; padding: 0 16px; }
  .brand-subtitle, .runtime-status { display: none; }
  .app-body { display: block; min-height: auto; }
  .sidebar { position: sticky; top: 64px; z-index: 10; height: 52px; padding: 8px 12px; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .sidebar-label, .sidebar-rule, .side-prompt, .sidebar-footer { display: none; }
  .nav-button { width: auto; min-width: max-content; padding-inline: 12px; }
  .main-content { padding: 20px 12px 42px; }
  .composer-panel, .output-panel, .library-section { padding: 18px; }
  h1 { font-size: 30px; }
  .controls-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .advanced-grid { grid-template-columns: 1fr; }
  .comfy-workflow-field { grid-column: auto; }
  .output-grid { grid-template-columns: 1fr 1fr; min-height: 360px; }
  .empty-state { min-height: 340px; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-actions { align-items: stretch; flex-direction: column; }
  .request-hint { white-space: normal; }
  .primary-button { width: 100%; }
}

@media (max-width: 420px) {
  .provider-grid, .controls-grid { grid-template-columns: 1fr; }
  .full-span { grid-column: auto; }
  .output-grid { grid-template-columns: 1fr; }
}
