:root {
  --ground: #f2f4f3;
  --surface: #fff;
  --raised: #f7f8f7;
  --active: #e9edeb;
  --ink: #171c1b;
  --muted: #56605d;
  --faint: #68736f;
  --line: #e4e9e6;
  --line-strong: #c6d0cb;
  --accent: #1b6c80;
  --accent-soft: #e9f2f3;
  --danger: #a63535;
  --sans: "IBM Plex Sans", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--ground);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 1024px; font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:active:not(:disabled) { transform: translateY(1px); }
h1, h2, p { margin: 0; }
h1, h2 { font-size: 22px; font-weight: 600; line-height: 1.25; letter-spacing: -.02em; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 52px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  background: var(--ground);
}
.back-link { justify-self: start; color: var(--muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--ink); text-decoration: underline; }
.brand { display: flex; align-items: center; gap: 10px; justify-self: center; }
.brand-mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 24px;
  height: 24px;
  padding: 3px;
  background: var(--ink);
}
.brand-mark i { background: #fff; }
.brand-mark i:first-child { grid-row: span 2; }
.brand-copy strong { font-size: 16px; font-weight: 600; }
.edition { justify-self: end; color: var(--muted); font-size: 12px; }

/* The chrome is one quiet frame; the results and inspector share a single white sheet. */
.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: calc(100vh - 52px);
  min-height: 700px;
  padding: 0 8px 8px 0;
}
.settings {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 23px 18px 12px 22px;
  background: var(--ground);
}
.settings .panel-head { flex: none; padding-bottom: 16px; }
.settings .panel-head p, .results-header p, .detail-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.settings form { min-height: 0; flex: 1; overflow-y: auto; padding-right: 6px; scrollbar-gutter: stable; }
.settings-action {
  flex: none;
  display: grid;
  gap: 7px;
  padding: 12px 6px 0 0;
  background: var(--ground);
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.work-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 388px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.results, .detail { min-width: 0; min-height: 0; overflow-y: auto; padding: 24px; }
.detail { display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.detail > * { flex-shrink: 0; }

fieldset { margin: 0 0 20px; padding: 0; border: 0; }
fieldset + fieldset { padding-top: 19px; border-top: 1px solid #dce3df; }
legend { margin-bottom: 13px; padding: 0; font-size: 14px; font-weight: 600; }
legend small { color: var(--muted); font-weight: 400; }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 100%;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--active);
}
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented span { display: block; padding: 8px 4px; border-radius: 4px; color: var(--muted); font-size: 12px; text-align: center; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.field > span:first-child { color: var(--ink); font-weight: 500; }
.field small { color: var(--muted); font-size: 12px; font-weight: 400; }
.field input, .field select, .copy-row input, textarea, .image-spec select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
}
.field input:hover, .field select:hover, .copy-row input:hover, textarea:hover, .image-spec select:hover { border-color: #859791; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
body.is-long #canvas-dimensions { grid-template-columns: 1fr; }
.field-note { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.copy-row { display: grid; grid-template-columns: 57px 1fr 1.2fr; gap: 7px; align-items: end; margin-bottom: 10px; }
.copy-row > span { padding-bottom: 11px; font-size: 12px; font-weight: 600; }
.copy-row label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; }
.copy-row input { padding: 0 7px; }
.advanced { margin-top: 12px; padding-top: 11px; border-top: 1px solid #dce3df; }
.advanced summary { color: var(--ink); font-size: 12px; font-weight: 500; cursor: pointer; }
.advanced summary:hover { color: var(--accent); }
.advanced summary small { color: var(--muted); font-weight: 400; }
.advanced textarea { height: auto; min-height: 145px; margin-top: 12px; padding: 10px; resize: vertical; line-height: 1.6; }
.advanced .field-note { margin-top: 8px; }
.image-specs { display: grid; gap: 9px; margin-top: 12px; }
.image-spec { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.image-spec select { height: 34px; padding: 0 6px; }
.image-spec label { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.image-spec input, .remix-controls input { accent-color: var(--accent); }

.primary-button, .secondary-button, .text-button, .more-toggle, .file-button {
  min-height: 36px;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
}
.primary-button { width: 100%; min-height: 42px; border: 1px solid var(--ink); background: var(--ink); color: #fff; }
.primary-button:hover:not(:disabled) { background: #323c39; }
.secondary-button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
.secondary-button:hover:not(:disabled) { border-color: #7b8d87; background: var(--raised); }
.text-button { min-height: 30px; padding: 3px 7px; border: 0; background: transparent; color: var(--accent); }
.text-button:hover:not(:disabled) { text-decoration: underline; }

.results-header, .detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.results-header { margin-bottom: 17px; }
.results-header .secondary-button { flex: none; }
.status { min-height: 18px; margin-bottom: 15px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.status[data-state="error"] { color: var(--danger); }
.gallery { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: stretch; }
.gallery.is-collapsed .layout-card:nth-child(n + 4) { display: none; }
.layout-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  transition: border-color .15s ease, background-color .15s ease;
}
.layout-card:hover { border-color: #98a9a3; background: #fcfdfc; }
.layout-card[aria-pressed="true"] { border: 2px solid var(--accent); padding: 9px; }
.layout-card[data-compare-anchor="true"] .card-foot::after { content: "对比 A"; color: var(--accent); font-size: 12px; font-weight: 600; }
.card-badge { display: block; margin-bottom: 9px; color: var(--ink); font-size: 12px; font-weight: 600; }
.layout-card[aria-pressed="true"] .card-badge { color: var(--accent); }
.card-art {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 305px;
  padding: 10px;
  overflow: hidden;
  background: var(--raised);
}
.card-art svg { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; border: 1px solid #d9dfdc; }
.card-foot { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.card-name { font-size: 13px; font-weight: 600; }
.card-index { display: none; }
.card-desc { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.more-toggle { width: 100%; margin-top: 12px; border: 1px solid var(--line); background: var(--raised); color: var(--muted); }
.more-toggle:hover { color: var(--ink); background: var(--active); }
.history-panel { margin-top: 22px; padding-top: 17px; border-top: 1px solid var(--line); }
.history-panel summary, .principles-panel summary { cursor: pointer; color: var(--ink); font-size: 13px; font-weight: 600; }
.history-panel summary span { margin-left: 9px; color: var(--muted); font-size: 12px; font-weight: 400; }
.history-panel summary b { font-variant-numeric: tabular-nums; font-weight: 600; }
.replay-toolbar { display: grid; grid-template-columns: auto minmax(90px, 1fr) auto auto; gap: 8px; align-items: center; margin-top: 15px; }
.replay-toolbar > label:first-child { color: var(--muted); font-size: 12px; }
.replay-toolbar input[type="text"] { width: 100%; min-width: 0; height: 36px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); font-size: 12px; }
.file-button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line-strong); background: var(--surface); white-space: nowrap; cursor: pointer; }
.file-button:hover { background: var(--raised); }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.favorite-list { display: grid; gap: 8px; margin-top: 14px; }
.favorite-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 6px; }
.favorite-item strong { display: block; font-size: 13px; }
.favorite-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.favorite-item button { min-height: 32px; padding: 4px 9px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); font-size: 12px; }
.favorite-item button:hover { background: var(--raised); }

.detail-head { margin-bottom: 6px; }
.favorite-button { flex: none; min-width: 58px; }
.favorite-button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 11px; }
.tag { padding: 3px 7px; background: var(--active); color: #38433f; border-radius: 4px; font-size: 12px; }
.direction-note { margin-top: 9px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 16px; }
.preview-toolbar > span { font-size: 13px; font-weight: 600; }
.preview-toolbar > div { display: flex; gap: 4px; }
.preview-well {
  flex: 1;
  min-height: 350px;
  max-height: 520px;
  margin-top: 8px;
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
}
.preview { display: flex; align-items: flex-start; justify-content: center; min-height: 100%; }
.preview svg { display: block; width: 100%; height: auto; max-width: 360px; border: 1px solid #d9dfdc; background: #fff; }
.remix-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; align-items: center; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.remix-controls label { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.remix-controls button { grid-column: 1 / -1; }
.principles-panel { margin-top: 13px; }
.principles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.principle { position: relative; display: flex; align-items: center; justify-content: space-between; min-height: 29px; gap: 8px; padding: 4px 6px 7px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.principle b { color: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.principle i { position: absolute; bottom: 0; left: 0; height: 2px; background: #53635d; }
.detail-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 13px 0 10px; }
.seed-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.seed-row b { color: var(--ink); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.detail-meta { margin: 0; padding: 6px 0; font-size: 12px; }
.detail-meta div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; }
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; max-width: 70%; color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.detail-warning { margin-top: 8px; padding: 9px; background: #f7eeee; color: var(--danger); font-size: 12px; line-height: 1.5; }
.detail-foot { margin-top: auto; padding-top: 16px; color: var(--muted); font-size: 12px; }

.viewer-dialog { width: min(1060px, 92vw); height: min(900px, 92vh); max-width: none; max-height: none; padding: 0; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink); }
.viewer-dialog::backdrop { background: rgba(10, 20, 17, .62); }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 64px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.viewer-head > div:first-child { display: flex; flex-direction: column; gap: 3px; }
.viewer-head strong { font-size: 16px; }
.viewer-head span { color: var(--muted); font-size: 12px; }
.viewer-actions { display: flex; gap: 7px; }
.viewer-actions [aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.viewer-canvas { height: calc(100% - 64px); overflow: auto; padding: 24px; background: var(--raised); text-align: center; }
#viewer-art svg { display: block; width: min(100%, 680px); height: auto; margin: 0 auto; border: 1px solid var(--line); background: #fff; }
.viewer-canvas.is-actual #viewer-art svg { width: auto; max-width: none; }
.compare-dialog { width: min(1400px, 96vw); }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; height: calc(100% - 64px); background: var(--line); }
.compare-grid figure { min-width: 0; height: 100%; margin: 0; padding: 15px; overflow: auto; background: var(--raised); }
.compare-grid figcaption { margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.compare-grid svg { display: block; width: min(100%, 560px); height: auto; margin: 0 auto; border: 1px solid var(--line); background: #fff; }

@media (max-width: 1260px) {
  .workspace { grid-template-columns: 260px minmax(0, 1fr); }
  .work-sheet { grid-template-columns: minmax(0, 1fr) 350px; }
  .results, .detail { padding: 19px; }
  .gallery { gap: 8px; }
  .layout-card { padding: 8px; }
  .layout-card[aria-pressed="true"] { padding: 7px; }
  .card-art { height: 275px; }
}
@media (max-width: 1080px) {
  .work-sheet { grid-template-columns: minmax(0, 1fr); grid-template-rows: max-content max-content; align-content: start; overflow-y: auto; }
  .results, .detail { min-height: max-content; overflow: visible; }
  .detail { border-left: 0; border-top: 1px solid var(--line); }
  .preview-well { max-height: 540px; }
}
