:root {
  --surface: #fbf9f8;
  --surface-low: #f5f3f3;
  --surface-high: #efeded;
  --card: #ffffff;
  --ink: #1b1c1c;
  --muted: #584045;
  --line: #e0bec3;
  --line-soft: #f0dfe2;
  --pink: #b32053;
  --pink-bright: #ff5c8a;
  --pink-soft: #ffd9df;
  --blue: #2b6579;
  --blue-soft: #b0e8ff;
  --shadow: 0 14px 34px rgba(179, 32, 83, 0.08);
  --shadow-hover: 0 18px 42px rgba(179, 32, 83, 0.14);
  --radius-card: 28px;
  --radius-control: 18px;
}

* { box-sizing: border-box; }

html { min-width: 320px; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--surface);
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(255, 92, 138, 0.28);
  outline-offset: 2px;
}

.app-shell { width: 100%; min-height: 100vh; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  gap: 36px;
  min-height: 100px;
  padding: 18px 40px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(251, 249, 248, 0.94);
  box-shadow: 0 3px 18px rgba(179, 32, 83, 0.05);
  backdrop-filter: blur(14px);
}

.brand-lockup { flex: 0 0 auto; }
.brand-lockup h1 { margin: 0; color: var(--pink); font-size: clamp(28px, 3vw, 42px); line-height: 1; letter-spacing: -0.04em; }
.eyebrow { margin: 0 0 7px; color: var(--pink); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; }

.top-nav { display: flex; align-items: center; gap: 34px; margin-left: 18px; color: var(--muted); font-size: 18px; font-weight: 700; }
.top-nav .nav-link { position: relative; padding: 18px 0 14px; border: 0; color: var(--muted); background: transparent; font-weight: 700; }
.top-nav .nav-link:hover, .top-nav .nav-link.active { color: var(--pink); }
.top-nav .nav-link.active::after { position: absolute; right: 0; bottom: 4px; left: 0; height: 3px; border-radius: 4px; background: var(--pink); content: ""; }

.topbar-actions { display: flex; gap: 12px; align-items: center; margin-left: auto; }
.primary-button, .ghost-button {
  min-height: 44px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-weight: 700;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
.primary-button { color: #fff; border-color: var(--pink-bright); background: var(--pink-bright); box-shadow: 0 8px 18px rgba(255, 92, 138, 0.2); }
.ghost-button { color: var(--ink); background: var(--card); }
.primary-button:hover, .ghost-button:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.button-icon { display: inline-block; margin-right: 8px; font-size: 18px; line-height: 1; }

.workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 28px; width: min(1480px, calc(100% - 64px)); margin: 28px auto 52px; align-items: start; }

.library-panel, .selected-card, .control-card, .prompt-panel, .api-panel {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-card);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.library-panel { position: sticky; top: 128px; display: flex; flex-direction: column; height: calc(100vh - 156px); min-height: 0; padding: 28px 18px 18px; overflow: auto; }
.library-heading { padding: 0 12px 20px; }
.library-heading h2 { margin: 0 0 6px; font-size: 27px; letter-spacing: -0.04em; }
.library-heading p:last-child { margin: 0; color: var(--muted); font-size: 15px; }

.search-wrap { position: relative; margin: 0 6px 18px; }
.search-icon { position: absolute; top: 50%; left: 16px; color: #8c7075; font-size: 30px; line-height: 1; transform: translateY(-55%); }
.search-wrap input { width: 100%; height: 54px; padding: 0 16px 0 50px; border: 2px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--surface-low); }
.search-wrap input::placeholder { color: #8c7075; }

.category-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 0 6px; overflow: visible; }
.category-tabs button { display: inline-flex; align-items: center; justify-content: center; width: 100%; min-height: 40px; padding: 0 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--card); white-space: nowrap; font-size: 13px; font-weight: 700; transition: transform 160ms ease, background 160ms ease, color 160ms ease, border-color 160ms ease; }
.category-tabs button:hover { color: var(--pink); border-color: #e5aab5; background: var(--pink-soft); transform: translateY(-1px); }
.category-tabs button.active { color: #fff; border-color: var(--pink); background: var(--pink); box-shadow: 0 6px 14px rgba(179, 32, 83, 0.18); }

.facet-panel { display: grid; gap: 8px; margin: 16px 6px 10px; padding-top: 14px; border-top: 1px dashed var(--line); }
.facet-panel label { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }

select { width: 100%; min-height: 42px; padding: 0 34px 0 13px; border: 2px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--surface-low); outline: none; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--pink) 50%), linear-gradient(135deg, var(--pink) 50%, transparent 50%); background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
select:focus { border-color: var(--pink); }

.library-meta { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; color: var(--muted); font-size: 12px; }
.library-meta button { padding: 5px 0; border: 0; color: var(--pink); background: transparent; font-weight: 700; }
.style-list { flex: 0 0 auto; overflow: visible; padding: 0 2px 8px; }
.style-card { width: 100%; margin-bottom: 5px; padding: 11px 12px; border: 1px solid transparent; border-radius: 15px; color: var(--ink); background: transparent; text-align: left; transition: background 160ms ease, border-color 160ms ease, transform 160ms ease; }
.style-card:hover { border-color: var(--line); background: var(--surface-low); transform: translateX(2px); }
.style-card.active { border-color: #ffb1c0; background: var(--pink-soft); }
.style-card strong, .style-card em { display: block; }
.style-card strong { font-size: 14px; }
.style-card em { margin-top: 3px; color: var(--pink); font-size: 11px; font-style: normal; }
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; color: var(--blue); font-size: 10px; }
.tag-row i { padding: 3px 7px; border-radius: 999px; background: var(--blue-soft); font-style: normal; }
.library-footer { display: grid; gap: 4px; margin-top: 12px; padding: 15px 6px 0; border-top: 1px dashed var(--line); }
.footer-link { padding: 8px 10px; border: 0; border-radius: 14px; color: var(--muted); background: transparent; text-align: left; font-weight: 700; }
.footer-link:hover { color: var(--pink); background: var(--pink-soft); }
.footer-link span { display: inline-block; width: 28px; color: var(--pink); font-size: 22px; vertical-align: middle; }

/* Main builder */
.builder-panel { min-width: 0; }
.selected-card { display: grid; grid-template-columns: 260px minmax(0, 1fr) auto; align-items: center; gap: 28px; min-height: 218px; padding: 24px; }
.upload-box { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 162px; gap: 10px; overflow: hidden; border: 1.5px dashed #d9a4af; border-radius: 24px; background: linear-gradient(145deg, #fff8f9 0%, #fff0f3 100%); color: var(--pink); text-align: center; transition: border-color 160ms ease, background 160ms ease, transform 160ms ease; }
.upload-box input { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-box:hover { border-color: var(--pink); background: #fff1f4; transform: translateY(-1px); }
.upload-placeholder { display: grid; width: 42px; height: 42px; place-items: center; border: 1px solid #e2a8b4; border-radius: 14px; background: #fff; font-size: 25px; line-height: 1; }
.upload-title { font-size: 16px; font-weight: 800; }
.upload-note { color: #9c737b; font-size: 12px; }
.image-preview { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; pointer-events: none; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview:empty { display: none; }
.upload-box:has(.image-preview:not(:empty)) > :not(input):not(.image-preview) { opacity: 0; }
.selected-info { min-width: 0; }
.selected-info h2 { margin: 0 0 12px; color: var(--ink); font-size: clamp(28px, 3.2vw, 44px); line-height: 1.08; letter-spacing: -.04em; }
.selected-info p { margin: 0 0 18px; color: var(--muted); font-size: 15px; }
.selected-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.selected-info .eyebrow { margin: 0 0 6px; }
.selected-info .selected-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.selected-info .selected-tags span { display: inline-flex; align-items: center; min-height: 31px; padding: 0 16px; border-radius: 999px; background: #eee9ea; color: #5a4b4f; font-size: 14px; font-weight: 700; }
.selected-info .selected-tags span:last-child { background: var(--blue-soft); color: var(--blue); }
.selected-info .tag { display: inline-flex; align-items: center; min-height: 31px; padding: 0 16px; border-radius: 999px; background: #eee9ea; color: #5a4b4f; font-size: 14px; font-weight: 700; }
.selected-info .tag.blue { background: var(--blue-soft); color: var(--blue); }
.favorite-button { align-self: start; width: 58px; height: 58px; border: 0; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-size: 0; cursor: pointer; transition: transform .2s ease, background .2s ease; }
.favorite-button::before { content: '♡'; font-size: 30px; line-height: 1; }
.favorite-button.active::before { content: '♥'; }
.favorite-button:hover { transform: translateY(-2px); }
.favorite-button.active { background: var(--pink-soft); color: var(--pink); }

.controls-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 18px; align-items: start; }
.control-card { min-height: 210px; padding: 24px; }
.control-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.control-title-row h3, .control-card > h3 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.control-card > h3, .control-title-row h3 { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.control-icon { color: var(--pink); font-size: 24px; }
.help-dot { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-left: auto; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-size: 12px; }
.control-field + .control-field { margin-top: 16px; }
.field-label { display: block; margin: 0 0 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.control-field select { width: 100%; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 4px; border: 2px solid var(--line); border-radius: 999px; background: #fffafb; }
.segmented select { min-height: 44px; border: 0; background: transparent; }
.identity-card { display: flex; flex-direction: column; }
.identity-card .control-field { margin-top: 0; }
.realism-guide { margin-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.realism-guide summary { padding: 13px 0 7px; color: var(--pink); font-weight: 800; cursor: pointer; }
.realism-guide-grid { display: grid; gap: 8px; padding: 0 0 10px; }
.realism-guide-grid p { margin: 0; line-height: 1.55; }
.realism-recommendation { color: var(--blue); font-weight: 700; }
.realism-note { color: var(--muted); }

.prompt-panel { margin-top: 18px; overflow: hidden; padding: 0; }
.prompt-tabs { display: flex; gap: 28px; padding: 0 28px; border-bottom: 1px solid var(--line); }
.tab { position: relative; padding: 20px 0 16px; border: 0; background: none; color: var(--muted); font-size: 16px; font-weight: 800; cursor: pointer; }
.tab.active { color: var(--pink); }
.tab.active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 4px; border-radius: 4px 4px 0 0; background: var(--pink); content: ''; }
.prompt-editor-wrap { padding: 24px 28px 18px; }
#promptOutput { display: block; width: 100%; min-height: 230px; resize: vertical; padding: 22px; border: 2px solid var(--line); border-radius: 24px; background: #fffdfd; color: #292329; font: 500 15px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
#promptOutput:focus { border-color: var(--pink); outline: none; box-shadow: 0 0 0 4px rgba(255, 92, 138, .12); }
.prompt-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 28px 22px; color: var(--muted); font-size: 13px; }
.prompt-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* API and generation panel */
.api-panel { margin-top: 18px; padding: 24px 28px 28px; }
.api-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 4px; }
.api-header h3 { margin: 0; font-size: 22px; }
.api-toggle { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; font-weight: 700; white-space: nowrap; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; font-size: 24px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.status-pill::before { width: 8px; height: 8px; border-radius: 50%; background: #c7c0c2; content: ''; }
.status-pill.ready::before { background: #50b48a; }
.switch { position: relative; display: inline-block; flex: 0 0 auto; width: 54px; height: 30px; }
.switch input { width: 0; height: 0; opacity: 0; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: #dfd8da; cursor: pointer; transition: background .2s ease; }
.switch-track::before { position: absolute; bottom: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(66, 42, 47, .15); content: ''; transition: transform .2s ease; }
.switch input:checked + .switch-track { background: var(--pink); }
.switch input:checked + .switch-track::before { transform: translateX(24px); }
.api-body { display: none; padding-top: 4px; }
.api-body.visible { display: block; }
.api-auth-box, .api-settings-box { margin: 12px 0 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-low); }
.settings-panel { display: none; width: min(900px, calc(100% - 64px)); margin: 28px auto 60px; padding: 28px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); }
.app-shell.settings-view .workspace, .app-shell.settings-view .topbar-actions { display: none; }
.app-shell.settings-view .settings-panel { display: block; }
.settings-heading { display: grid; gap: 8px; }
.settings-heading .text-button { justify-self: start; margin-bottom: 8px; }
.settings-heading h2 { margin: 0 0 8px; }
.settings-heading p:last-child { margin: 0 0 18px; color: var(--muted); }
.text-button { border: 0; padding: 0; color: var(--pink); background: transparent; font: inherit; font-weight: 800; cursor: pointer; }
.api-auth-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.api-auth-row input { flex: 1 1 190px; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.settings-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.settings-grid .settings-endpoint-field { grid-column: 1 / -1; display: none; }
.settings-grid .settings-endpoint-field.visible { display: grid; }
.settings-grid input { min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.api-auth-box p, .api-settings-box p { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.api-disabled-note, .api-flow-note { margin: 10px 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.api-flow-note { padding: 10px 14px; border-radius: 14px; background: var(--surface-low); }
.api-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 110px; gap: 14px; }
.api-grid > label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.api-grid > label input, .api-grid > label select { width: 100%; }
.api-field label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.api-field input { width: 100%; }
.api-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
#apiHint { margin: 0; color: var(--muted); font-size: 13px; }
.generation-status { min-height: 22px; margin: 16px 0 0; color: var(--pink); font-size: 14px; font-weight: 700; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.result-card { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #fff; }
.result-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.result-card p { margin: 0; padding: 10px 12px; color: var(--muted); font-size: 12px; }
#toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(360px, calc(100vw - 48px)); padding: 13px 18px; border-radius: 14px; background: #382b30; color: #fff; box-shadow: var(--shadow); font-size: 14px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease; }
#toast.show { opacity: 1; transform: translateY(0); }
.load-error { display: grid; gap: 6px; margin-bottom: 18px; padding: 16px 18px; border: 1px solid #efb0bc; border-radius: 18px; background: #fff0f2; color: var(--pink); }
.load-error span { color: var(--muted); font-size: 13px; line-height: 1.6; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 250px minmax(0, 1fr); }
  .selected-card { grid-template-columns: 210px minmax(0, 1fr) auto; gap: 20px; }
  .api-grid { grid-template-columns: 1fr 1fr; }
  .api-grid > label:last-child { max-width: 180px; }
}
@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .top-actions { margin-left: auto; }
  .workspace { grid-template-columns: 1fr; }
  .library-panel { position: static; height: auto; min-height: 0; }
  .style-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls-grid { grid-template-columns: 1fr 1fr; }
  .identity-card { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .page-shell { padding: 14px; }
  .topbar { padding: 16px 18px; }
  .brand { font-size: 25px; }
  .main-nav { order: 3; width: 100%; }
  .main-nav a { flex: 1; text-align: center; }
  .top-actions .ghost-button span:last-child, .top-actions .primary-button span:last-child { display: none; }
  .top-actions { gap: 7px; }
  .ghost-button, .primary-button { padding: 0 14px; }
  .selected-card { position: relative; grid-template-columns: 1fr; padding: 18px; }
  .upload-box { min-height: 190px; }
  .favorite-button { position: absolute; top: 18px; right: 18px; width: 46px; height: 46px; font-size: 22px; }
  .controls-grid { grid-template-columns: 1fr; }
  .identity-card { grid-column: auto; }
  .style-list { grid-template-columns: 1fr; }
  .prompt-tabs { gap: 18px; padding: 0 18px; overflow-x: auto; }
  .prompt-editor-wrap { padding: 18px; }
  .prompt-footer { align-items: flex-start; flex-direction: column; padding: 0 18px 18px; }
  .api-grid { grid-template-columns: 1fr; }
  .api-grid > label:last-child { max-width: none; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
