:root {
  --bg: #eef2f3;
  --panel: #ffffff;
  --panel-2: #f5f7f7;
  --line: #d7dfe1;
  --line-strong: #b7c4c7;
  --text: #182227;
  --muted: #64737a;
  --accent: #167a8b;
  --accent-dark: #0e6270;
  --orange: #d4783a;
  --green: #2e8054;
  --red: #b54a45;
  --topbar: #19272d;
  --shadow: 0 6px 18px rgba(24, 34, 39, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
}

body { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(22, 122, 139, 0.35);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--topbar);
  color: #fff;
  position: relative;
  z-index: 20;
}

.brand, .top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand { font-size: 17px; font-weight: 700; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 5px;
  color: #9ee4ef;
  font-size: 13px;
}

.edition {
  color: #b8c9ce;
  font-size: 12px;
  font-weight: 400;
}

.layout {
  display: grid;
  grid-template-columns: var(--settings-width, 310px) 12px minmax(0, 1fr);
  gap: 0;
  padding: 14px;
  height: calc(100vh - 58px);
  min-height: 0;
}

.panel, .tab-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  min-width: 0;
  padding: 16px;
  overflow-y: auto;
  container-type: inline-size;
}

.group { margin-bottom: 16px; }

.field-label, .tool-title {
  display: block;
  margin-bottom: 7px;
  color: #314149;
  font-size: 13px;
  font-weight: 700;
}

.input, .select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.input:focus, .select:focus { border-color: var(--accent); }

.textarea {
  height: auto;
  min-height: 66px;
  padding: 9px 10px;
  resize: vertical;
  line-height: 1.55;
}

.character-research > .input,
.character-research > .research-grid,
.character-research > .btn { margin-bottom: 8px; }

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

.research-result {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.research-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 700;
}

.confidence-badge {
  padding: 3px 7px;
  border: 1px solid #b8d8c8;
  border-radius: 5px;
  background: #edf7f2;
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
}

.research-result .field-caption {
  display: block;
  margin: 8px 0 5px;
  color: var(--muted);
  font-size: 12px;
}

.brief-textarea { min-height: 150px; }

.source-list {
  display: grid;
  gap: 5px;
  margin-top: 9px;
}

.source-list a {
  overflow: hidden;
  color: var(--accent-dark);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seg {
  display: grid;
  gap: 6px;
}

.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg.colors { grid-template-columns: repeat(3, 1fr); }

.seg-btn, .btn {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn:hover, .btn:hover { border-color: var(--line-strong); }
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.color-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 3px;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.22);
  flex: 0 0 auto;
}

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); background: transparent; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.btn.wide { width: 100%; height: 40px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.dimension-inputs label {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.dimension-inputs .input { padding: 0 7px; }

.construction-note {
  margin: -4px 0 16px;
  padding: 9px 10px;
  border-left: 3px solid var(--orange);
  background: #fff6ef;
  color: #7b4b2c;
  font-size: 12px;
}

.dropzone {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #9eafb4;
  border-radius: 6px;
  padding: 10px;
  background: var(--panel-2);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}

.dropzone input, .upload-row input { display: none; }
.dropzone.dragover { border-color: var(--accent); background: #e7f4f6; }

.checks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.checks label, .switch {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
}

.light-tone-controls {
  margin: 8px 0 10px;
}

.light-tone-controls .field-caption {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.light-tone-controls .seg-btn {
  padding: 0 5px;
  font-size: 12px;
}

.face-visibility-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.face-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.face-switch input,
.switch input {
  accent-color: var(--accent);
}

.state-line {
  min-height: 20px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 10px;
}

.workspace-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.tab {
  height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active { background: var(--accent); color: #fff; }

.history-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-wrap .select { width: min(360px, 32vw); }

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.tab-panel.active { display: block; }

.face-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-height: 320px;
}

.face-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.face-head {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.version { color: var(--muted); font-size: 12px; font-weight: 400; }

.face-image {
  flex: 1;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: repeating-conic-gradient(#edf1f2 0% 25%, #fff 0% 50%) 0 0 / 20px 20px;
}

.face-image img {
  display: none;
  max-width: 100%;
  max-height: 330px;
  object-fit: contain;
  background: #fff;
}

.face-actions {
  display: grid;
  gap: 8px;
  padding: 9px;
  border-top: 1px solid var(--line);
}

.face-prompt { width: 100%; min-width: 0; }

.face-action-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.face-quality { width: 108px; min-width: 108px; height: 30px; font-size: 12px; }

.face-actions .btn,
.download-all {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.result-summary {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-top: 12px;
}

.result-summary .quality {
  flex: 1;
  margin-top: 0;
}

.download-all {
  height: auto;
  min-height: 40px;
}

.quality {
  min-height: 40px;
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 3px solid var(--green);
  background: #f0f7f3;
  color: #2b6042;
  line-height: 20px;
}

#previewPanel { padding: 0; overflow: hidden; }

.preview-layout {
  display: grid;
  grid-template-columns: var(--preview-tools-width, 270px) 12px minmax(0, 1fr);
  height: 100%;
  min-height: 480px;
}

.preview-controls {
  min-width: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.tool-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.tool-section:last-child { border-bottom: 0; }

.upload-list {
  display: grid;
  gap: 7px;
  margin: 8px 0;
}

.upload-row {
  height: 34px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}

.upload-row b {
  overflow: hidden;
  color: var(--muted);
  font-weight: 400;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.background-row { margin-bottom: 8px; grid-template-columns: 70px minmax(0,1fr); }

.angle-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) 58px 12px;
  align-items: center;
  gap: 6px;
}

.angle-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.angle-number { height: 34px; padding: 0 6px; }

.angle-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.angle-preset.active { border-color: var(--accent); color: var(--accent); background: #edf8fa; }

.viewer-wrap {
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #dce4e6;
}

.viewer-topline {
  min-height: 42px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid rgba(24,34,39,.14);
  background: rgba(255,255,255,.88);
  color: #34454c;
  font-size: 13px;
}

.dimension { color: var(--muted); }

.viewer {
  width: 100%;
  flex: 1;
  height: auto;
  min-height: 438px;
  overflow: hidden;
  background: #dce4e6;
  cursor: grab;
  touch-action: none;
}

.viewer:active { cursor: grabbing; }
.viewer canvas { display: block; width: 100%; height: 100%; }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  font-size: 12px;
}

.badge.ok { background: var(--green); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17,25,29,.5);
}

.modal.hidden { display: none; }

.modal-box {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 55px rgba(0,0,0,.24);
}

.modal-head {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.modal-close { color: var(--text); background: #fff; border-color: var(--line); }
.modal-body { padding: 16px; }

.ai-control {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.ai-control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.ai-control .field-label { margin-bottom: 4px; }
.ai-control p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.proxy-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.proxy-grid label { color: var(--muted); font-size: 12px; }
.proxy-grid .select { margin-top: 5px; }
.proxy-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.ai-toggle {
  display: grid;
  grid-template-columns: 42px 48px;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  cursor: pointer;
}

.ai-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.ai-toggle-track {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: #9aa7aa;
  transition: background .18s ease;
}

.ai-toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.28);
  transition: transform .18s ease;
}

.ai-toggle input:checked + .ai-toggle-track { background: var(--green); }
.ai-toggle input:checked + .ai-toggle-track::after { transform: translateX(18px); }
.ai-toggle input:focus-visible + .ai-toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.ai-toggle input:disabled + .ai-toggle-track { opacity: .5; cursor: not-allowed; }
.ai-toggle b { color: var(--muted); font-size: 13px; }
.ai-toggle b.is-on { color: var(--green); }

.reference-upload-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.reference-slot { position: relative; min-height: 0; aspect-ratio: 1; overflow: hidden; padding: 0; }
.reference-slot.has-file { border-style: solid; border-color: var(--accent); background: #eef8f9; }
.reference-thumb { width: 100%; height: 100%; display: block; object-fit: cover; }
.reference-thumb[hidden] { display: none; }
.reference-index { position: absolute; z-index: 2; top: 5px; left: 5px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: rgba(19, 43, 49, .82); color: #fff; font-size: 11px; }
.reference-remove { position: absolute; z-index: 3; top: 5px; right: 5px; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 1px solid rgba(255,255,255,.82); border-radius: 50%; background: rgba(19,43,49,.86); color: #fff; font-size: 19px; line-height: 1; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.reference-remove:hover { background: #b33f3f; }
.reference-remove:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.reference-remove[hidden] { display: none; }
.reference-slot .drop-text { max-width: 100%; padding: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.reference-slot.has-file .drop-text { position: absolute; z-index: 2; right: 0; bottom: 0; left: 0; background: rgba(255, 255, 255, .9); color: #27383e; }
.proxy-subscription { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.proxy-subscription-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.proxy-subscription p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

@media (max-width: 540px) {
  .ai-control-head { align-items: flex-start; flex-direction: column; }
  .proxy-grid { grid-template-columns: 1fr; }
  .proxy-subscription-row { grid-template-columns: 1fr; }
}

.key-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 8px;
}

.key-list { list-style: none; margin: 10px 0 0; padding: 0; }

.key-list li {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  font-size: 13px;
}

.key-list li.active-key { border-color: rgba(46, 128, 84, .45); background: #f2f8f4; }
.key-summary { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.key-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex: none; }
.key-current { color: var(--green); font-weight: 700; white-space: nowrap; }
.btn.key-delete { color: var(--red); border-color: rgba(181, 74, 69, .35); background: #fff; }
.btn.key-delete:hover { border-color: var(--red); }
.key-list .muted { color: var(--muted); }
.btn.key-test { width: 100%; margin-top: 10px; }
.state-line.success { color: var(--green); }
.state-line.error { color: var(--red); }

.model-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}
.model-picker-row + .input { margin-top: 8px; }
.model-help { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

@media (max-width: 540px) {
  .key-list li { align-items: stretch; flex-direction: column; }
  .key-actions { justify-content: flex-start; }
  .model-picker-row { grid-template-columns: 1fr; }
}

@media (max-width: 1050px) {
  body { overflow: auto; }
  .layout { height: auto; min-height: calc(100vh - 58px); }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; gap: 14px; }
  .panel-splitter { display: none !important; }
  .workspace-bar { align-items: stretch; flex-direction: column; }
  .history-wrap .select { width: 100%; max-width: none; }
  .face-grid { grid-template-columns: 1fr; }
  .preview-layout { grid-template-columns: 1fr; }
  .preview-controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .viewer { height: 60vh; flex: none; }
}

.panel-splitter {
  position: relative;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  background: transparent;
}
.panel-splitter::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 4px;
  width: 4px;
  height: 44px;
  border-left: 1px solid #8a9b9f;
  border-right: 1px solid #8a9b9f;
}
.panel-splitter:hover, .panel-splitter:focus-visible, .panel-splitter.is-dragging {
  background: #d1e9ec;
  outline: 1px solid var(--accent);
  outline-offset: -2px;
}
body.resizing-panels, body.resizing-panels * { cursor: col-resize !important; user-select: none !important; }
body.resizing-panels iframe { pointer-events: none; }
.workspace { container-type: inline-size; }
@container (max-width: 650px) {
  .face-grid { grid-template-columns: 1fr; }
  .history-wrap { width: 100%; }
  .history-wrap .select { width: 100%; min-width: 0; }
}

@container (max-width: 430px) {
  .face-action-row { align-items: stretch; flex-direction: column; }
  .face-quality, .face-action-row .btn { width: 100%; }
}
fieldset.provider-options { border: 0; min-width: 0; padding: 0; }
.search-suggestions { display: block; width: 100%; height: 160px; border: 0; margin-top: 8px; }
.search-suggestions.hidden { display: none; }
.speed-control { display: grid; grid-template-columns: auto minmax(40px,1fr) 38px; align-items: center; gap: 8px; margin: 8px 0 12px; font-size: 12px; color: var(--muted); }
.speed-control input { width: 100%; min-width: 0; accent-color: var(--accent); }
.speed-control output { text-align: right; }
.provider-options > label { display: inline-flex; align-items: center; gap: 3px; margin: 4px 9px 4px 0; font-size: 13px; cursor: pointer; }
.provider-options input { accent-color: #297a65; }
