:root {
  color-scheme: light;
  --page: #fbfbfd;
  --surface: #ffffff;
  --surface-subtle: #f5f5f7;
  --border: #d2d2d7;
  --border-strong: #b8b8bd;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0067cc;
  --success: #248a3d;
  --error: #d70015;
  --radius: 6px;
}

* { box-sizing: border-box; }

html { background: var(--page); }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

a { color: inherit; text-decoration: none; }

button { color: inherit; }

[hidden] { display: none !important; }

.studio-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  min-height: 62px;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .96);
}

.studio-header > * { min-width: 0; }

.studio-brand {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 10px;
}

.studio-brand img { width: 30px; height: 30px; border-radius: var(--radius); }
.studio-brand strong,
.studio-brand small { display: block; }
.studio-brand strong { font-size: 14px; line-height: 1.2; }
.studio-brand small { margin-top: 2px; color: var(--text-secondary); font-size: 11px; }

.studio-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(68px, 1fr));
  align-self: stretch;
}

.nav-button {
  position: relative;
  min-width: 74px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.nav-button::after {
  position: absolute;
  right: 14px;
  bottom: 0;
  left: 14px;
  height: 2px;
  background: transparent;
  content: "";
}

.nav-button:hover,
.nav-button.active { color: var(--text); }
.nav-button.active::after { background: var(--accent); }

.studio-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  color: var(--text-secondary);
  font-size: 12px;
}

.studio-meta a { color: var(--text); font-weight: 650; }
.provider-state { white-space: nowrap; }
.provider-state[data-state="ready"] { color: var(--success); }
.provider-state[data-state="failed"] { color: var(--error); }

.studio-main {
  width: min(1560px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.studio-view.active { display: block; }

.create-layout {
  display: grid;
  min-height: calc(100dvh - 120px);
  grid-template-columns: minmax(380px, 480px) minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.composer {
  padding: 22px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.panel-heading,
.result-header,
.view-heading,
.section-label,
.dialog-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.panel-heading p,
.result-header p,
.view-heading p {
  margin: 0 0 5px;
  color: var(--accent);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 10px;
  font-weight: 700;
}

h1,
h2,
h3,
p { margin-top: 0; }

.panel-heading h1,
.view-heading h1 { margin-bottom: 0; font-size: 23px; line-height: 1.2; }
.version-label { color: var(--text-secondary); font-family: Consolas, monospace; font-size: 11px; }

.workflow-switch,
.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  margin-top: 22px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--page);
}

.workflow-button,
.mode-button {
  min-height: 38px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.workflow-button.active,
.mode-button.active { background: var(--surface-subtle); color: var(--text); }

.scene-composer { margin-top: 20px; }

.scene-plan-block {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.scene-plan-block legend,
.fixed-scene-field > span {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

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

.plan-button {
  display: grid;
  min-width: 0;
  min-height: 68px;
  align-content: center;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.plan-button:hover { border-color: var(--border-strong); background: var(--surface-subtle); }
.plan-button.active { border-color: var(--accent); background: #f0f7ff; }
.plan-button strong { font-size: 13px; }
.plan-button small { overflow-wrap: anywhere; color: var(--text-secondary); font-size: 10px; line-height: 1.4; }

.scene-upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.upload-block { min-width: 0; }
.scene-drop { min-height: 132px; }
.scene-drop span { padding: 12px; }
.scene-drop img { max-height: 180px; aspect-ratio: 1; object-fit: contain; }

.fixed-scene-field {
  display: grid;
  gap: 0;
  margin-top: 18px;
}

.fixed-scene-field small {
  margin-top: 7px;
  color: var(--text-secondary);
  font-size: 10px;
  line-height: 1.5;
}

.size-card-row {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-subtle);
  cursor: pointer;
}

.size-card-row > span { display: grid; min-width: 0; gap: 4px; }
.size-card-row strong { font-size: 12px; }
.size-card-row small { color: var(--text-secondary); font-size: 10px; line-height: 1.4; }
.size-card-row input { width: 18px; height: 18px; flex: 0 0 auto; margin: 0; accent-color: var(--accent); cursor: pointer; }
.measurement-section { margin-top: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.measurement-section .field-block { margin-top: 0; } .measurement-section textarea { min-height: 82px; }
.measurement-confirm { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--text-secondary); font-size: 11px; } .measurement-confirm input { width: 16px; height: 16px; flex: 0 0 auto; margin: 0; accent-color: var(--accent); }
.output-summary {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 11px;
}

.output-summary strong { color: var(--text); font-size: 12px; text-align: right; }

.prototype-status {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-left: 3px solid var(--accent);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.5;
}

.free-composer { margin-top: 20px; }

.field-block,
.control-grid label { display: grid; gap: 8px; }
.field-block { margin-top: 20px; }
.field-block > span,
.control-grid label > span:first-child,
.section-label > span { color: var(--text); font-size: 12px; font-weight: 650; }

.field-block small {
  justify-self: end;
  color: var(--text-secondary);
  font-family: Consolas, monospace;
  font-size: 10px;
}

textarea,
select,
input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: 0;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 210px;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.65;
}

textarea::placeholder { color: #86868b; }
textarea:focus,
select:focus,
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 113, 227, .16); }

.reference-section { margin-top: 20px; }
.section-label { margin-bottom: 8px; }
.section-label button { border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; font-size: 12px; }

.reference-drop {
  position: relative;
  display: grid;
  min-height: 146px;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.reference-drop.dragging { border-color: var(--accent); background: #f0f7ff; }
.reference-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.reference-drop span { display: grid; gap: 6px; padding: 18px; text-align: center; }
.reference-drop strong { font-size: 13px; }
.reference-drop small { color: var(--text-secondary); font-size: 11px; }
.reference-drop img { display: block; width: 100%; max-height: 240px; object-fit: contain; }

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 112px;
  gap: 10px;
  margin-top: 20px;
}

select { min-height: 40px; padding: 0 10px; }

.count-stepper {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.count-stepper button {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
}

.count-stepper input { min-width: 0; border: 0; border-radius: 0; text-align: center; }
.count-stepper input::-webkit-inner-spin-button { appearance: none; }

.inline-error {
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(215, 0, 21, .28);
  border-radius: var(--radius);
  background: #fff2f4;
  color: var(--error);
  font-size: 12px;
  line-height: 1.5;
}

.composer-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 18px; }
.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #ffffff; }
.primary-button:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.primary-button:disabled { border-color: var(--border); background: #e8e8ed; color: #86868b; cursor: not-allowed; }
.secondary-button { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.secondary-button:hover { border-color: #86868b; background: var(--surface-subtle); }
.primary-button:active,
.secondary-button:active { transform: translateY(1px); }

.result-stage { min-width: 0; padding: 22px; background: var(--surface); }
.result-header { min-height: 44px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.result-header h2 { margin-bottom: 0; font-size: 18px; }
.result-header > span { color: var(--text-secondary); font-size: 12px; }

.empty-state,
.wide-empty {
  display: grid;
  min-height: 520px;
  place-content: center;
  justify-items: center;
  padding: 28px;
  text-align: center;
}

.empty-frame {
  display: grid;
  width: 116px;
  height: 116px;
  margin-bottom: 22px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.empty-frame span { width: 46px; height: 46px; border: 1px solid var(--border-strong); border-radius: 4px; box-shadow: 14px 14px 0 -1px var(--surface-subtle), 14px 14px 0 0 var(--border-strong); }
.empty-state h3,
.wide-empty h2 { margin-bottom: 8px; font-size: 17px; }
.empty-state p,
.wide-empty p { max-width: 36ch; margin-bottom: 0; color: var(--text-secondary); font-size: 12px; line-height: 1.6; }

.running-state {
  display: grid;
  min-height: 520px;
  place-content: center;
  justify-items: center;
  padding: 28px;
}

.running-visual { display: grid; width: 116px; height: 116px; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 28px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-subtle); }
.running-visual span { align-self: end; height: 22px; border-radius: 2px; background: #a7cef5; animation: studio-pulse 1.1s ease-in-out infinite; }
.running-visual span:nth-child(2) { height: 44px; animation-delay: 120ms; }
.running-visual span:nth-child(3) { height: 31px; animation-delay: 240ms; }
.running-copy { margin-top: 22px; text-align: center; }
.running-copy strong { font-size: 15px; }
.running-copy p { margin: 7px 0 0; color: var(--text-secondary); font-size: 12px; }

.phase-list { display: grid; grid-template-columns: repeat(4, auto); gap: 18px; margin: 25px 0 0; padding: 0; color: var(--text-secondary); font-size: 11px; list-style: none; }
.phase-list li { position: relative; padding-left: 13px; }
.phase-list li::before { position: absolute; top: 5px; left: 0; width: 5px; height: 5px; border-radius: 50%; background: var(--border-strong); content: ""; }
.phase-list li.current { color: var(--text); }
.phase-list li.current::before,
.phase-list li.done::before { background: var(--accent); }
.phase-list li.done { color: var(--text-secondary); }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  padding-top: 18px;
}

.result-item,
.history-card { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.result-image-button { display: block; width: 100%; padding: 0; border: 0; background: var(--surface-subtle); cursor: zoom-in; }
.result-image-button img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; }
.result-actions,
.history-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.result-actions a,
.result-actions button,
.history-actions a,
.history-actions button { min-height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 4px; background: transparent; color: var(--text); cursor: pointer; font-size: 11px; }

.view-heading { min-height: 68px; margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.history-card { padding: 12px; }
.history-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.history-card header strong { display: -webkit-box; overflow: hidden; font-size: 13px; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-card header time { flex: 0 0 auto; color: var(--text-secondary); font-family: Consolas, monospace; font-size: 10px; }
.history-thumbs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.history-thumbs img { display: block; width: 100%; aspect-ratio: 1; border-radius: 4px; background: var(--surface-subtle); object-fit: cover; }
.history-meta { margin: 10px 0 0; color: var(--text-secondary); font-family: Consolas, monospace; font-size: 10px; }
.wide-empty { min-height: 420px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

.settings-layout { display: grid; min-width: 0; grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr); gap: 14px; }
.settings-section { min-width: 0; padding: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.settings-section h2 { margin-bottom: 18px; font-size: 16px; }
.settings-section dl { margin: 0; }
.settings-section dl div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 18px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.settings-section dl div:last-child { border-bottom: 0; }
.settings-section dt { color: var(--text-secondary); font-size: 12px; }
.settings-section dd { margin: 0; overflow-wrap: anywhere; font-family: Consolas, monospace; font-size: 12px; }
.settings-note p { color: var(--text-secondary); font-size: 13px; line-height: 1.7; }
.settings-form { display: grid; gap: 10px; }
.settings-form label { color: var(--text-secondary); font-size: 12px; }
.settings-form input { width: 100%; min-height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--text); font: 12px Consolas, monospace; }
.settings-help { margin: 0; color: var(--text-secondary); font-size: 12px; line-height: 1.6; }
.settings-form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.provider-save-status { min-height: 18px; color: var(--text-secondary); font-size: 12px; }
.provider-save-status[data-state="success"] { color: var(--success); }
.provider-save-status[data-state="error"] { color: var(--error); }

.preview-dialog { width: min(940px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 12px 32px rgba(29, 29, 31, .12); }
.product-save-dialog { width: min(560px, calc(100% - 32px)); padding: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 12px 32px rgba(29, 29, 31, .12); }
.product-save-dialog::backdrop { background: rgba(245, 245, 247, .9); }
.product-save-body { display: grid; gap: 14px; padding: 20px 16px; }
.product-save-body > label { display: grid; gap: 6px; color: var(--text-secondary); font-size: 12px; }
.product-save-body select,
.product-save-body input:not([type="checkbox"]) { min-height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--text); font: 12px Consolas, monospace; }
.product-save-body fieldset { display: grid; gap: 8px; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 4px; color: var(--text-secondary); font-size: 12px; }
.product-save-body fieldset label { display: flex; align-items: center; gap: 8px; }
.product-save-dialog .dialog-actions { justify-content: flex-end; }
.preview-dialog::backdrop { background: rgba(245, 245, 247, .9); }
.dialog-bar { min-height: 52px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.dialog-bar button { width: 34px; height: 34px; border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; font-size: 24px; }
.dialog-stage { display: grid; max-height: calc(100dvh - 160px); place-items: center; overflow: auto; background: var(--surface-subtle); }
.dialog-stage img { display: block; max-width: 100%; max-height: calc(100dvh - 170px); object-fit: contain; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); }

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
select:focus-visible,
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes studio-pulse {
  0%, 100% { opacity: .35; transform: scaleY(.82); }
  50% { opacity: 1; transform: scaleY(1); }
}

@media (max-width: 960px) {
  .studio-header { grid-template-columns: 1fr auto; gap: 12px; padding: 0 16px; }
  .studio-nav { grid-row: 2; grid-column: 1 / -1; min-height: 44px; border-top: 1px solid var(--border); }
  .studio-meta .provider-state { display: none; }
  .create-layout { grid-template-columns: 1fr; }
  .composer { border-right: 0; border-bottom: 1px solid var(--border); }
  .settings-layout { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .studio-main { width: min(100% - 20px, 1560px); padding-top: 10px; }
  .studio-meta { gap: 0; }
  .studio-meta a { font-size: 11px; }
  .nav-button { min-width: 0; }
  .create-layout { min-height: 0; }
  .composer,
  .result-stage { padding: 16px; }
  .plan-options,
  .scene-upload-grid { grid-template-columns: 1fr; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .control-grid label:last-child { grid-column: 1 / -1; }
  .empty-state,
  .running-state { min-height: 360px; }
  .phase-list { grid-template-columns: 1fr 1fr; }
  .result-grid,
  .history-grid { grid-template-columns: 1fr; }
  .settings-section dl div { grid-template-columns: 1fr; gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.reference-composer { grid-column: span 1; }
.reference-list { display: grid; gap: 8px; margin-top: 10px; }
.reference-item { display: grid; grid-template-columns: 64px minmax(0, 1fr) 96px 32px; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-subtle); }
.reference-item img { width: 64px; height: 64px; object-fit: contain; border-radius: 6px; background: var(--surface); }
.reference-item-copy { min-width: 0; }
.reference-item-copy strong, .reference-item-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reference-item-copy small { margin-top: 4px; color: var(--text-secondary); font-size: 11px; }
.reference-item select, .selected-model-field select { width: 100%; min-width: 0; }
.reference-remove { width: 32px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text-secondary); cursor: pointer; }
.combine-model-row { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-subtle); }
.combine-model-row input { margin-top: 3px; }
.combine-model-row span { display: grid; gap: 3px; }
.combine-model-row small, .selected-model-field > span { color: var(--text-secondary); font-size: 11px; }
.selected-model-field { display: grid; gap: 6px; margin-top: 10px; }
@media (max-width: 620px) { .reference-item { grid-template-columns: 52px minmax(0, 1fr) 32px; } .reference-item img { width: 52px; height: 52px; } .reference-item select { grid-column: 2 / 4; } }
