:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2024;
  --muted: #6b7280;
  --line: #e3e6ea;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --panel: #161c22; --ink: #e6e9ec; --muted: #9aa3ad;
    --line: #29323b; --brand: #3b82f6; --brand-ink: #fff;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.55;
}
header { padding: 22px 20px 8px; max-width: 960px; margin: 0 auto; }
header h1 { margin: 0; font-size: 24px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.badge {
  display: inline-block; margin-top: 8px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: var(--line); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.mock { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.connection-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.connection-row .badge { margin-top: 0; }
.auth-open { padding: 3px 0; border: 0; background: transparent; color: var(--brand); font-size: 12px; }

.access-dialog {
  width: min(420px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink);
}
.access-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.access-dialog h2 { margin: 0 0 6px; font-size: 18px; }
.access-dialog p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.access-dialog label { display: block; margin-bottom: 6px; font-size: 13px; }
.access-dialog input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.tabs { max-width: 960px; margin: 14px auto 0; padding: 0 20px; display: flex; gap: 8px; overflow-x: auto; }
.tab {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 9px 16px; border-radius: 10px 10px 0 0; cursor: pointer; font-size: 14px;
}
.tab.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }

.panel {
  display: none; max-width: 960px; margin: 0 auto; padding: 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 0 0 12px 12px;
}
.panel.active { display: block; }
.panel h2 { margin-top: 0; font-size: 18px; }

.row { margin: 14px 0; }
.row > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.notice {
  margin: 10px 0 14px; padding: 9px 11px; border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 9%, var(--panel)); color: var(--ink); font-size: 13px;
}
input[type=text], input[type=number] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font-size: 14px;
}
select {
  min-width: 220px; max-width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 13px;
}
input[type=file] { color: var(--muted); font-size: 13px; }
.file-control { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.file-input {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.file-button {
  display: inline-flex; align-items: center; min-height: 34px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  color: var(--ink); cursor: pointer; font-size: 13px;
}
.file-button:hover { border-color: var(--brand); color: var(--brand); }
.file-button:active { background: color-mix(in srgb, var(--brand) 12%, var(--bg)); }
.file-status { color: var(--muted); font-size: 12px; }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; }

button {
  cursor: pointer; border-radius: 8px; font-size: 14px; padding: 10px 18px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumbs img { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.thumbs .ph { width: 72px; height: 72px; display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 12px; }

.sample-picker { margin-top: 10px; }
.sample-picker summary { cursor: pointer; color: var(--brand); font-size: 13px; }
.library-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.library-toolbar label { color: var(--muted); font-size: 12px; }
.library-toolbar button { padding: 7px 10px; font-size: 12px; }
.sample-library { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; margin-top: 8px; }
.sample-item { border: 1px solid var(--line); border-radius: 8px; padding: 7px; background: var(--bg); }
.sample-item img { display: block; width: 72px; height: 72px; margin: 0 auto 6px; object-fit: contain; background: #fff; }
.sample-item .cap { text-align: center; color: var(--muted); font-size: 12px; }
.sample-item .sample-actions { display: flex; justify-content: center; gap: 4px; margin-top: 6px; }
.sample-item button { padding: 5px 7px; font-size: 12px; }
.synth-skeleton-library { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.sample-ids {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px;
  margin-top: 7px; padding: 7px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel);
}
.sample-ids code {
  min-width: 0; padding: 0; background: transparent; color: var(--ink); font-size: 13px;
  overflow-wrap: anywhere;
  font-family: "Segoe UI Symbol", "SimSun-ExtB", "SimSun", "Microsoft YaHei", ui-monospace, monospace;
}
.sample-ids button.copy-ids { padding: 4px 7px; white-space: nowrap; }
.sample-item.selectable img {
  cursor: pointer; border: 2px solid transparent; border-radius: 6px;
  transition: background-color .12s ease, filter .12s ease, border-color .12s ease;
}
.sample-item.selectable img:hover { background: #e7eefc; filter: brightness(.92); }
.sample-item.selectable img:active { background: #c9d8f6; filter: brightness(.78); }
.sample-item.selectable.selected { border-color: var(--brand); }
.sample-item.selectable.selected img { background: #dbe7ff; border-color: var(--brand); filter: brightness(.86); }
.sample-doc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.sample-doc-actions button { padding: 6px 10px; font-size: 12px; }
.document-library { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.document-item { border: 1px solid var(--line); border-radius: 8px; padding: 7px; background: var(--bg); }
.document-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #fff; }
.document-item .cap { margin: 6px 0; text-align: center; color: var(--muted); font-size: 12px; }
.document-item button { display: block; width: 100%; padding: 6px; font-size: 12px; }

.gallery { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.gallery .item { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); }
.gallery .item img { width: 140px; height: 140px; object-fit: contain; background: #fff; border-radius: 6px; }
.gallery .item .cap { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }
.ttf-packager { margin-top: 24px; max-width: 760px; }
.ttf-packager > label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.ttf-controls { display: flex; align-items: stretch; gap: 8px; }
.ttf-controls input { flex: 1 1 260px; min-width: 0; }
.ttf-download { flex: 0 0 auto; margin: 0; }
.ttf-note { margin-top: 8px; margin-bottom: 0; }

.result { margin-top: 14px; }
.result img { width: 192px; height: 192px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.result .mock-tag { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 6px; background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); font-size: 12px; }
.synth-result-item { width: 210px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); }
.synth-result-item img { display: block; width: 192px; height: 192px; object-fit: contain; }
.synth-result-item .cap { margin: 5px 0; text-align: center; color: var(--muted); font-size: 12px; }
.synth-result-item button { width: 100%; padding: 7px; }
.similarity-note { padding-left: 9px; border-left: 3px solid var(--brand); }

/* 多字生成结果网格 */
.result-grid { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.result-grid .item { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); }
.result-grid .item img { width: 140px; height: 140px; object-fit: contain; background: #fff; border-radius: 6px; }
.result-grid .item .cap { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }

.hist-candidate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin-top: 10px; }
.hist-candidate { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); }
.hist-candidate.selected { border-color: var(--ok); }
.hist-candidate.query { box-shadow: inset 0 0 0 2px var(--warn); }
.hist-candidate img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.hist-candidate label { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 7px; font-size: 12px; }
.hist-candidate .score { text-align: center; color: var(--muted); font-size: 12px; }

.adv { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.adv summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0; }
.hint.err { color: var(--danger); }
.hint.ok { color: var(--ok); }
.op-bar, .comp-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.op-bar button, .comp-bar button {
  padding: 5px 10px; font-size: 16px; min-width: 36px;
  font-family: "Segoe UI Symbol", "SimSun", "Microsoft YaHei", sans-serif;
}
.comp-bar button { font-size: 18px; }
#synth-ids, .gen-ids-cell { font-family: "Segoe UI Symbol", "SimSun", ui-monospace, monospace; }

.canvas-wrap { position: relative; }
#hist-canvas { max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: crosshair; touch-action: none; }
.op-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.op-row button { padding: 7px 14px; }
/* 逐字 IDS 预览（生成模块） */
.ids-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ids-row { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; background: var(--bg); font-size: 13px; }
.ids-row .ids-ch { font-size: 18px; font-weight: 600; }
.ids-row .ids-tok { color: var(--muted); font-family: ui-monospace, monospace; }
.ids-row.oov { border-color: var(--danger); }
.ids-row.oov .ids-msg { color: var(--danger); }
.hint.warn { color: var(--warn); }

/* 逐字 IDS 编辑框（生成模块，逐字符绑定） */
.ids-row input.gen-ids-cell {
  flex: 1; width: auto; min-width: 160px; font-family: ui-monospace, monospace;
  padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); font-size: 13px;
}
.ids-row.oov input.gen-ids-cell { border-color: var(--danger); }
.ids-msg { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ids-msg.ok { color: var(--ok); }
.ids-msg.err { color: var(--danger); }

/* 风格检索：缩略图可删除 */
.thumb-wrap { position: relative; display: inline-block; margin: 0 2px; }
.thumb-wrap .thumb-del {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--danger); color: #fff; border: none;
  font-size: 14px; line-height: 18px; padding: 0; cursor: pointer; opacity: .9;
}
.thumb-wrap .thumb-del:hover { opacity: 1; }

/* 进度条（生成/复刻期间显示，缓解等待焦虑） */
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress.hidden { display: none; }
.progress .bar { height: 100%; width: 40%; background: var(--brand); border-radius: 999px; animation: indet 1.1s infinite ease-in-out; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

footer { max-width: 960px; margin: 24px auto; padding: 0 20px; color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  .tabs { padding: 0 10px; }
  .tab { flex: 0 0 auto; padding: 8px 11px; }
  .panel { padding: 14px 12px; }
  .library-toolbar select { width: 100%; }
  .sample-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .synth-skeleton-library { grid-template-columns: 1fr; }
  .document-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ttf-controls { align-items: stretch; flex-direction: column; }
  .ttf-controls input { flex-basis: auto; }
}
