:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  --paper: #f7f8f6;
  --surface: #ffffff;
  --surface-muted: #eef1ef;
  --canvas: #e8ecec;
  --ink: #171a1c;
  --muted: #687075;
  --line: #d9dedd;
  --line-strong: #bdc5c3;
  --accent: #e4543d;
  --accent-dark: #c63d2c;
  --teal: #17776f;
  --yellow: #e7b53f;
  --danger: #b42318;
  --shadow: 0 16px 48px rgba(19, 27, 27, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  letter-spacing: 0;
}

body {
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button:not(:disabled),
label[for] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 3px solid rgba(23, 119, 111, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-frame {
  height: 100vh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 64px;
  flex: 0 0 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 246, 0.96);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(23, 26, 28, 0.12);
}

.brand-name {
  font-size: 20px;
  font-weight: 760;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
  padding-left: 10px;
  border-left: 1px solid var(--line-strong);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connection-status,
.icon-text-button,
.icon-button,
.text-button,
.secondary-button,
.primary-button {
  border: 0;
  background: transparent;
}

.connection-status {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}

.connection-status:hover {
  background: var(--surface-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: #9aa09f;
}

.connection-status.configured .status-dot {
  background: var(--yellow);
}

.connection-status.connected .status-dot {
  background: #1a9b65;
  box-shadow: 0 0 0 3px rgba(26, 155, 101, 0.13);
}

.connection-status.error .status-dot {
  background: var(--danger);
}

.icon-text-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 650;
}

.icon-text-button:hover,
.icon-button:hover,
.secondary-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.icon-text-button svg,
.icon-button svg,
.secondary-button svg,
.generate-button svg,
.privacy-note svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

.studio {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
}

.control-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 20px 10px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px;
  background: var(--surface-muted);
  border-radius: 7px;
}

.mode-tab {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.mode-tab svg {
  width: 17px;
  height: 17px;
}

.mode-tab.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(24, 31, 30, 0.1);
}

.control-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.field-heading {
  min-height: 22px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 9px;
  font-size: 13px;
  font-weight: 700;
}

.field-heading > :last-child {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

textarea,
select,
.dialog-field input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

textarea {
  display: block;
  min-height: 154px;
  padding: 12px 13px;
  resize: vertical;
  line-height: 1.65;
}

textarea::placeholder,
input::placeholder {
  color: #929998;
}

textarea:focus,
select:focus,
.dialog-field input:focus {
  border-color: var(--teal);
}

.prompt-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.prompt-presets button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  color: #525a5e;
  font-size: 12px;
}

.prompt-presets button:hover {
  color: var(--teal);
  border-color: rgba(23, 119, 111, 0.45);
  background: #f1f8f6;
}

.drop-zone {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px dashed #aab6b3;
  border-radius: 7px;
  background: #f7faf9;
  color: var(--muted);
  text-align: center;
  transition: 140ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--teal);
  background: #eef8f6;
}

.drop-zone svg {
  width: 24px;
  height: 24px;
  color: var(--teal);
}

.drop-zone strong {
  color: var(--ink);
  font-size: 13px;
}

.drop-zone span {
  font-size: 11px;
}

.reference-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.reference-item {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.reference-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.reference-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: rgba(16, 20, 21, 0.78);
  color: #fff;
}

.reference-remove svg {
  width: 14px;
  height: 14px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.option-button {
  min-width: 0;
  min-height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.option-button:hover {
  border-color: var(--line-strong);
  background: var(--paper);
}

.option-button.active {
  border-color: var(--teal);
  color: var(--teal);
  background: #f2f9f7;
  box-shadow: inset 0 0 0 1px rgba(23, 119, 111, 0.16);
}

.ratio-icon {
  display: block;
  border: 2px solid currentColor;
  border-radius: 2px;
}

.ratio-icon.square {
  width: 18px;
  height: 18px;
}

.ratio-icon.landscape {
  width: 24px;
  height: 16px;
}

.ratio-icon.portrait {
  width: 14px;
  height: 21px;
}

.compact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.control-field {
  min-width: 0;
}

.control-field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
}

select {
  height: 42px;
  padding: 0 30px 0 10px;
}

.quantity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 0;
}

.quantity-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.quantity-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.stepper {
  height: 38px;
  display: grid;
  grid-template-columns: 36px 38px 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.stepper button {
  display: grid;
  place-items: center;
  border: 0;
  background: var(--paper);
}

.stepper button:hover {
  background: var(--surface-muted);
}

.stepper button svg {
  width: 15px;
  height: 15px;
}

.stepper output {
  display: grid;
  place-items: center;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font-weight: 700;
}

.generate-area {
  flex: 0 0 auto;
  padding: 14px 20px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.generate-button {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  box-shadow: 0 6px 18px rgba(228, 84, 61, 0.22);
}

.generate-button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.model-caption {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  overflow-wrap: anywhere;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
}

.workspace-toolbar {
  min-height: 70px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  border-bottom: 1px solid rgba(23, 26, 28, 0.09);
}

.workspace-toolbar h1,
.workspace-toolbar p,
.history-heading h2 {
  margin: 0;
}

.workspace-toolbar h1 {
  font-size: 16px;
}

.workspace-toolbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.workspace-actions {
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

.canvas-area {
  flex: 1;
  min-height: 420px;
  position: relative;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 26px;
}

.sample-stage {
  width: min(820px, 100%);
  margin: 0;
  position: relative;
  aspect-ratio: 943 / 622;
  overflow: hidden;
  background: #ccd3d2;
  border: 1px solid rgba(23, 26, 28, 0.12);
}

.sample-stage > img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.sample-stage figcaption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: 96px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 5px 16px;
  padding: 16px 18px;
  background: rgba(18, 23, 23, 0.8);
  color: #fff;
}

.sample-stage figcaption > span {
  grid-column: 1;
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
}

.sample-stage figcaption strong {
  grid-column: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.45;
}

.sample-stage figcaption button {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
}

.sample-stage figcaption button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sample-stage figcaption svg {
  width: 15px;
  height: 15px;
}

.result-grid {
  width: 100%;
  align-self: stretch;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 18px;
}

.result-grid.single {
  max-width: 900px;
  grid-template-columns: minmax(0, 1fr);
  align-self: center;
}

.result-item {
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: #d8dedd;
  border: 1px solid rgba(23, 26, 28, 0.13);
}

.result-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.result-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(-4px);
  transition: 150ms ease;
}

.result-item:hover .result-toolbar,
.result-item:focus-within .result-toolbar {
  opacity: 1;
  transform: translateY(0);
}

.result-toolbar .icon-button {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(16, 20, 21, 0.8);
  color: #fff;
}

.result-toolbar .icon-button:hover {
  background: rgba(16, 20, 21, 0.94);
}

.loading-state {
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  text-align: center;
}

.loading-visual {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  overflow: hidden;
  margin-bottom: 13px;
  background: #ccd3d2;
  border: 1px solid rgba(23, 26, 28, 0.14);
}

.loading-visual img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  filter: saturate(0.35) contrast(0.8);
  opacity: 0.25;
}

.scan-line {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  box-shadow: 0 8px 24px rgba(228, 84, 61, 0.4);
  animation: scan 2.2s ease-in-out infinite alternate;
}

@keyframes scan {
  from { transform: translateY(10px); }
  to { transform: translateY(440px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.loading-state > strong {
  font-size: 16px;
}

.loading-state > span {
  color: var(--muted);
  font-size: 12px;
}

.secondary-button,
.primary-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 680;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
}

.primary-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
}

.primary-button:hover {
  background: #303537;
}

.loading-state .secondary-button {
  margin-top: 9px;
}

.history-strip {
  flex: 0 0 auto;
  padding: 14px 22px 18px;
  border-top: 1px solid rgba(23, 26, 28, 0.09);
  background: rgba(247, 248, 246, 0.7);
}

.history-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.history-heading h2 {
  font-size: 13px;
}

.text-button {
  padding: 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.text-button:hover {
  color: var(--danger);
}

.history-list {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.history-item {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface-muted);
}

.history-item:hover,
.history-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(228, 84, 61, 0.13);
}

.history-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

dialog {
  padding: 0;
  border: 0;
}

dialog::backdrop {
  background: rgba(14, 18, 19, 0.54);
  backdrop-filter: blur(3px);
}

.settings-dialog {
  width: min(520px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-dialog form {
  max-height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-body {
  overflow-y: auto;
  padding: 20px 24px;
}

.dialog-field {
  display: block;
  margin-bottom: 17px;
}

.dialog-field > span,
.dialog-field-heading > label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 700;
}

.dialog-field-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.dialog-field-heading .text-button {
  margin-bottom: 3px;
}

.dialog-field input {
  height: 44px;
  padding: 0 12px;
}

.secret-input {
  position: relative;
}

.secret-input input {
  padding-right: 48px;
}

.secret-input .icon-button {
  position: absolute;
  top: 3px;
  right: 3px;
  border: 0;
  background: transparent;
}

.remember-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.remember-row strong,
.remember-row small {
  display: block;
}

.remember-row strong {
  font-size: 13px;
}

.remember-row small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

input[role="switch"] {
  width: 42px;
  height: 24px;
  flex: 0 0 42px;
  appearance: none;
  position: relative;
  border-radius: 12px;
  background: #b7bdbc;
  transition: 140ms ease;
}

input[role="switch"]::after {
  content: "";
  width: 18px;
  height: 18px;
  position: absolute;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: 140ms ease;
}

input[role="switch"]:checked {
  background: var(--teal);
}

input[role="switch"]:checked::after {
  transform: translateX(18px);
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 12px;
  border-left: 3px solid var(--teal);
  background: #eef7f5;
  color: #3d5551;
  font-size: 12px;
  line-height: 1.55;
}

.privacy-note svg {
  flex: 0 0 18px;
  margin-top: 1px;
}

.test-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.test-result.success {
  background: #eaf7f0;
  color: #17683f;
}

.test-result.warning {
  background: #fff7df;
  color: #7a5310;
}

.test-result.error {
  background: #fff0ee;
  color: var(--danger);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 15px 24px 20px;
  border-top: 1px solid var(--line);
}

.preview-dialog {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  background: rgba(10, 13, 14, 0.94);
}

.preview-dialog img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  padding: 28px;
}

.preview-close {
  position: fixed;
  z-index: 2;
  top: 16px;
  right: 16px;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  width: min(360px, calc(100% - 36px));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-left: 4px solid var(--teal);
  border-radius: 5px;
  background: #1d2324;
  color: #fff;
  box-shadow: 0 8px 28px rgba(10, 16, 16, 0.24);
  font-size: 13px;
  line-height: 1.5;
  animation: toast-in 180ms ease-out;
}

.toast.error {
  border-left-color: var(--accent);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .app-frame {
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .studio {
    display: block;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel-scroll {
    overflow: visible;
  }

  .generate-area {
    position: static;
  }

  .workspace {
    min-height: 720px;
  }

  .canvas-area {
    min-height: 520px;
  }
}

@media (max-width: 560px) {
  .topbar {
    height: 58px;
    flex-basis: 58px;
    padding: 0 12px;
  }

  .brand-subtitle,
  .connection-status span:not(.status-dot),
  .icon-text-button span {
    display: none;
  }

  .connection-status {
    width: 36px;
    justify-content: center;
    padding: 0;
  }

  .icon-text-button {
    width: 38px;
    justify-content: center;
    padding: 0;
  }

  .panel-scroll {
    padding: 16px 14px 8px;
  }

  .generate-area {
    padding: 12px 14px 14px;
  }

  .workspace-toolbar,
  .history-strip {
    padding-right: 14px;
    padding-left: 14px;
  }

  .canvas-area {
    min-height: 430px;
    padding: 14px;
  }

  .sample-stage {
    aspect-ratio: 4 / 5;
  }

  .sample-stage > img {
    object-position: center;
  }

  .sample-stage figcaption {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }

  .sample-stage figcaption button {
    grid-column: 1;
    grid-row: auto;
    width: max-content;
  }

  .result-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-toolbar {
    opacity: 1;
    transform: none;
  }

  .compact-grid {
    gap: 9px;
  }

  .dialog-header,
  .dialog-body,
  .dialog-actions {
    padding-right: 17px;
    padding-left: 17px;
  }

  .dialog-actions > button {
    flex: 1;
  }
}
