:root {
  --left-w: 440px; --side-w: 300px; --side-wide-w: 380px;
  --bg: #f3f4f7; --card: #ffffff; --text: #1d2026; --muted: #6b7380; --line: #e3e6eb; --hover: #f2f4f8;
  --accent: #3a6ee8; --accent-soft: #e9f0fd; --ok: #1f9d55; --warn: #c27c0e; --err: #d64545;
  --viewport: #8a8f98; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15171b; --card: #1e2126; --text: #e6e8eb; --muted: #98a1ad; --line: #2e3238; --hover: #262a30;
    --accent: #7aa2ff; --accent-soft: #24324f; --ok: #45c47a; --warn: #e2a33a; --err: #f07272; --viewport: #3a3d43;
    --shadow: none; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.45 "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", "Segoe UI", system-ui, sans-serif; }
body { display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; }
h2 { font-size: 13px; margin: 0; font-weight: 600; }
h3 { font-size: 12px; margin: 14px 0 4px; color: var(--muted); font-weight: 600; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.brand { font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.logo { color: var(--accent); }
.ver { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }

.layout { flex: 1; display: flex; min-height: 0; }
.mode-note { flex: none; padding: 6px 16px; font-size: 12px; background: var(--accent-soft); color: var(--text, inherit);
  border-bottom: 1px solid var(--line); }
.mode-note b { color: var(--warn); }
.mode-note a { color: var(--accent); }
/* left column: settings scroll, the run bar stays at the bottom */
.left { width: var(--left-w); flex: none; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.left-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.right { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h2 { white-space: nowrap; }
.card-head .actions { display: flex; gap: 6px; }
.log-card .card-head { margin-bottom: 0; }

/* buttons */
.btn { background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 7px 16px; }
.btn.primary:disabled { opacity: .5; cursor: default; }
.link { background: none; border: none; cursor: pointer; padding: 0; font-weight: 600; }
.icon { background: none; border: none; cursor: pointer; color: var(--muted); padding: 2px 5px; border-radius: 5px; font-size: 12px; }
.icon:hover { background: var(--hover); color: var(--text); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: none; background: transparent; padding: 4px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg.small button { padding: 2px 8px; font-size: 12px; }
.tabs { display: inline-flex; gap: 2px; }
.tabs button { border: none; background: none; padding: 3px 9px; border-radius: 6px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* form */
.field { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.field > label { width: 92px; flex: none; color: var(--muted); }
.field input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.field output { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.seg.nowrap { flex-wrap: nowrap; flex: none; }
.input.jobs-num { flex: none; width: 64px; }
.input.jobs-num:disabled { color: var(--muted); }
.switch { display: flex; align-items: center; gap: 7px; margin: 6px 0; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.switch.sub, .field.sub { margin-left: 22px; }
.switch.small { margin: 0; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 4px 22px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8px; }
.folder-row .path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 6px; padding: 3px 8px; }
.input { flex: 1; min-width: 0; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font: inherit; }

/* files */
.drop { border: 1.5px dashed var(--line); border-radius: 8px; padding: 18px 10px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.compact { padding: 6px; font-size: 12px; }
.drop.over, body.dragging .drop { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.file-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 300px; overflow-y: auto; }
.file-list:empty::before { content: attr(data-empty); display: block; color: var(--muted); text-align: center; padding: 6px; font-size: 12px; }
.file { border-radius: 7px; padding: 6px 6px 6px 8px; }
.file:hover { background: var(--hover); }
.file.current { background: var(--accent-soft); }
.file .row1 { display: flex; align-items: center; gap: 6px; }
.file .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind { font-size: 10px; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.chip { font-size: 11px; border-radius: 10px; padding: 0 7px; background: var(--hover); color: var(--muted); white-space: nowrap; }
.chip.running { background: var(--accent-soft); color: var(--accent); }
.chip.done { color: var(--ok); }
.chip.error { color: var(--err); }
.file .outs { margin: 3px 0 0 4px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.file .outs a { color: var(--accent); cursor: pointer; text-decoration: none; }
.file .err { color: var(--err); font-size: 12px; margin: 2px 0 0 4px; word-break: break-all; }
.file .note { color: var(--muted); font-size: 12px; margin: 2px 0 0 4px; }

/* run bar */
.runbar { flex: none; display: grid; grid-template-columns: auto 1fr auto;  /* start or stop · status · open output */ align-items: center; gap: 6px 10px; padding: 10px 12px;
  background: var(--card); border-top: 1px solid var(--line); }
.progress { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.status { color: var(--muted); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--err); color: #fff; border-radius: 8px; padding: 0 6px; font-size: 11px; font-weight: 600; }
.caret { display: inline-block; transition: transform .15s; }
.log-card.open .caret { transform: rotate(90deg); }
.log { margin: 8px 0 0; max-height: 260px; overflow: auto; font: 11.5px/1.5 Consolas, "Cascadia Mono", monospace; white-space: pre-wrap; word-break: break-all; }
.log .ok { color: var(--ok); } .log .warn { color: var(--warn); } .log .err { color: var(--err); }
.log .head { font-weight: 700; } .log .info { color: var(--muted); }
.log .file-mark { color: var(--accent); margin-top: 2px; }

/* preview */
.pv-toolbar { display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pv-title { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.btn.on { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stage { flex: 1; display: flex; min-height: 0; }
.pv { flex: 1; position: relative; background: var(--viewport); min-height: 0; min-width: 0; }
.pv canvas { position: absolute; inset: 0; }
.pv-empty, .pv-busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #fff; text-shadow: 0 1px 3px #0008; pointer-events: none; font-size: 14px; }
.pv-busy { background: #0003; }
/* skeleton overlay: legend (bone roles with counts) and the hovered bone */
.pv-legend { position: absolute; left: 10px; bottom: 10px; padding: 6px 10px; border-radius: 6px; background: #000a; color: #fff;
  font-size: 12px; line-height: 1.7; pointer-events: none; }
.pv-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.pv-legend b { font-weight: 600; margin-left: 6px; }
.pv-tip { position: absolute; padding: 4px 8px; border-radius: 4px; background: #000c; color: #fff; font-size: 12px;
  line-height: 1.5; pointer-events: none; white-space: nowrap; transform: translate(12px, 12px); }
.pv-tip .k { opacity: 0.75; }
.pv-hint { position: absolute; right: 10px; bottom: 8px; color: #fff; opacity: 0.6; font-size: 11px;
  text-shadow: 0 1px 2px #0009; pointer-events: none; }
/* tune panel: chain rows with keep-shown / focus buttons */
.chain-head { display: flex; align-items: center; gap: 2px; }
.chain-head .switch { flex: 1; min-width: 0; }
.ibtn { flex: none; width: 24px; height: 22px; padding: 0; border: 1px solid transparent; border-radius: 4px;
  background: none; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.ibtn:hover { background: var(--accent-soft); color: var(--accent); }
.ibtn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ibtn svg { width: 15px; height: 15px; }
.chain.pinned { box-shadow: inset 3px 0 0 var(--accent); padding-left: 4px; }
.spinner { width: 18px; height: 18px; border: 2px solid #fff6; border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* side column next to the preview (one panel at a time) */
.side { width: var(--side-w); flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--card);
  border-left: 1px solid var(--line); }
.side.wide { width: var(--side-wide-w); }
/* drag handles between the columns (double-click resets) */
.splitter { width: 6px; margin: 0 -3px; flex: none; cursor: col-resize; position: relative; z-index: 5; }
.splitter::after { content: ""; position: absolute; top: 0; bottom: 0; left: 2px; width: 2px; background: transparent; transition: background .15s; }
.splitter:hover::after, .splitter.dragging::after { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .pv canvas { pointer-events: none; }
/* narrow windows (the app allows 1000 px): give the preview more of the width */
@media (max-width: 1200px) {
  :root { --left-w: 360px; --side-w: 260px; --side-wide-w: 330px; }
  .pv-title { max-width: 140px; }
}
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 12px; overflow-y: auto; }
.panel .field > label { width: 64px; }
.expr-list { overflow-y: auto; flex: 1; min-height: 0; }
.expr-list .field > label { width: 110px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatches { display: flex; gap: 6px; margin: 6px 0 2px; }
.swatches button { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); cursor: pointer; padding: 0; }
.swatches button.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 2px 0; font-size: 12px; }
.info dt { color: var(--muted); } .info dd { margin: 0; font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #000c; color: #fff; padding: 6px 14px;
  border-radius: 8px; font-size: 12px; opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 80vw; }
.toast.show { opacity: 1; }

/* metadata tab / texture hint */
.hint.flush { margin-left: 0; }
.dim { opacity: .45; }
.hint.warn { color: var(--warn); }
.tab-body[data-panel=meta] .field > label { width: 80px; }
.tab-body[data-panel=main] .field > label { width: 72px; }
/* settings: Advanced fold, per-format sections, options that only apply to one target */
details.adv { border-top: 1px solid var(--line); border-bottom: none; margin-top: 10px; padding-bottom: 0; }
details.adv > summary { font-weight: 600; color: var(--text); }
details.adv h3:first-of-type { margin-top: 6px; }
.settings-card.pmx .vrm-only, .settings-card:not(.pmx) .pmx-only, .settings-card.pmx .pmx-hidden { display: none; }
.fmt h3 { margin-top: 10px; }
#metaReset { margin-top: 10px; }

/* tune panel */
#tunePanel { overflow: hidden; }
.tune-body { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; }
details.sec { border-bottom: 1px solid var(--line); padding: 2px 0 6px; }
details.sec details.sec { border: none; padding: 0; }
details.sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; margin: 8px 0 4px;
  font-size: 12px; font-weight: 600; color: var(--muted); }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: "▸"; display: inline-block; transition: transform .15s; }
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec > summary:hover { color: var(--text); }
.tune-body .field > label { width: 96px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tune-body select { flex: 1; min-width: 0; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; font: inherit; }
.tune-body select.changed, .tune-body input.changed { border-color: var(--accent); }
.tune-body .field.preset > label { width: 60px; }
.tune-body .field.preset { gap: 6px; }
.tune-body .field.preset.missing select { color: var(--muted); font-style: italic; }
.tune-body input.strength { flex: none; width: 56px; }
.tune-body output.strength { width: 36px; }
.tune-body input.strength.changed { accent-color: var(--accent); filter: saturate(1.6); }
.tune-msg { color: var(--muted); padding: 12px 2px; }
.thumb-row { display: flex; align-items: center; gap: 8px; }
.thumb-row img, .thumb-row .noimg { width: 64px; height: 64px; border-radius: 6px; border: 1px solid var(--line); object-fit: cover; flex: none;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.thumb-row .col { display: flex; flex-direction: column; gap: 4px; }
.chain { border-top: 1px solid var(--line); padding: 4px 0; }
.chain .switch { margin: 2px 0; }
.chain .switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chain .field { margin: 2px 0 2px 22px; }
.chain .field > label { width: 40px; color: var(--muted); }
.chain.off .field { display: none; }
.chain-list { margin-top: 4px; }
.tune-foot { display: flex; align-items: center; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 6px; }
.tune-foot .muted { flex: 1; color: var(--muted); font-size: 12px; }
.chip.tuned { background: var(--accent-soft); color: var(--accent); }
.mini { background: none; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; padding: 0 5px; font-size: 11px; color: var(--muted); }
.mini:hover { color: var(--text); background: var(--hover); }
.tune-foot .btn.primary { padding: 2px 10px; font-weight: 600; }
