:root {
  --bg: #16181c;
  --panel: #1e2126;
  --panel-2: #262a30;
  --line: #33383f;
  --text: #e7e9ec;
  --muted: #9aa1ab;
  --accent: #5fd068;
  --accent-ink: #0d1a0f;
  --danger: #ff6b6b;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }

.app { display: grid; grid-template-columns: 440px 1fr; height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }

details.section { border-bottom: 1px solid var(--line); }
details.section > summary { cursor: pointer; list-style: none; padding: 11px 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; user-select: none; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.section[open] > summary::before { transform: rotate(90deg); }
.section-body { padding: 2px 16px 14px; display: grid; gap: 8px; }
.subhead { margin: 8px 0 0; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.row { display: grid; grid-template-columns: 132px 1fr; align-items: center; gap: 10px; }
.row > span { color: var(--muted); }
.row.hidden { display: none; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

input[type=text], input[type=number], input[type=search], select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
input[type=number] { font-variant-numeric: tabular-nums; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -1px; }
input[type=color] { width: 100%; height: 30px; padding: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.range-num { display: grid; grid-template-columns: 1fr 72px; gap: 8px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #4a5058; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 6px; width: 30px; height: 30px; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- items ---------- */
.items { display: grid; gap: 6px; }
.item { display: grid; grid-template-columns: 52px 1fr 58px 14px 58px auto; gap: 6px; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 6px; }
.item.no-change { grid-template-columns: 52px 1fr 58px auto; }
.item .thumb { width: 52px; height: 52px; border-radius: 6px; border: 1px solid var(--line); background: #2d3238; cursor: pointer; padding: 0; display: grid; place-items: center; }
.item .thumb canvas { width: 46px; height: 46px; }
.item .name { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 12px; line-height: 1.25; }
.item .arrow { color: var(--muted); text-align: center; }
.item .tools { display: flex; }
.item .tools .icon-btn { width: 20px; height: 26px; font-size: 12px; }
.items-head { display: grid; grid-template-columns: 52px 1fr 58px 14px 58px auto; gap: 6px; color: var(--muted); font-size: 11px; padding: 0 7px; }
.items-head.no-change { grid-template-columns: 52px 1fr 58px auto; }

/* ---------- stage ---------- */
.stage { display: grid; grid-template-rows: 1fr auto auto; min-width: 0; min-height: 0; }
.viewport { position: relative; min-height: 0; display: grid; place-items: center; padding: 20px; overflow: hidden; }
.canvas-wrap { position: relative; box-shadow: 0 0 0 1px var(--line), 0 10px 40px rgba(0,0,0,.4); }
.canvas-wrap.checker {
  background-color: #b9b9b9;
  background-image: linear-gradient(45deg, #8f8f8f 25%, transparent 25%), linear-gradient(-45deg, #8f8f8f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8f8f8f 75%), linear-gradient(-45deg, transparent 75%, #8f8f8f 75%);
  background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
#preview { display: block; image-rendering: auto; }
.drop-hint { position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 12px; display: none; place-items: center; background: rgba(22,24,28,.75); font-size: 16px; }
.viewport.dragging .drop-hint { display: grid; }

.transport { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.transport input[type=range] { flex: 1; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 110px; text-align: right; }

.export-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding: 10px 16px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.export-opts { display: flex; flex-wrap: wrap; gap: 10px; flex: 1; }
.export-opts label { display: grid; gap: 3px; color: var(--muted); font-size: 11px; }
.export-opts select { min-width: 110px; }
.export-opts .size { align-self: end; color: var(--muted); font-size: 12px; padding-bottom: 7px; }
.export-actions { display: flex; gap: 8px; }
.progress { flex-basis: 100%; display: flex; align-items: center; gap: 12px; }
.progress .bar { flex: 1; height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.progress .bar div { height: 100%; width: 0; background: var(--accent); transition: width .1s; }
.progress span { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 150px; }

/* ---------- dialogs ---------- */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(860px, 94vw); max-height: 86vh; }
.dlg.narrow { width: min(460px, 94vw); }
.dlg::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.dlg-head h2 { margin: 0; font-size: 15px; white-space: nowrap; }
.dlg-head input { flex: 1; }
.dlg-head .icon-btn { margin-left: auto; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; padding: 14px; overflow-y: auto; max-height: calc(86vh - 60px); }
.pick { position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px 6px; cursor: pointer; display: grid; justify-items: center; gap: 4px; text-align: center; font-size: 11px; color: var(--muted); }
.pick:hover, .pick.current { border-color: var(--accent); color: var(--text); }
.pick canvas { width: 64px; height: 64px; }
.pick.upload { border-style: dashed; place-content: center; min-height: 104px; font-size: 12px; }
.pick.upload b { font-size: 26px; font-weight: 400; color: var(--accent); }
.pick .del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; font-size: 11px; }
.picker-sep { grid-column: 1 / -1; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin-top: 6px; }

.custom-body { padding: 14px; display: grid; gap: 10px; }
.model-row { grid-template-columns: 132px auto 1fr auto; }
.model-info { color: var(--muted); font-size: 12px; }
.face-inputs { display: grid; gap: 8px; }
.face-input { display: grid; grid-template-columns: 132px 40px 1fr auto; gap: 8px; align-items: center; }
.face-input span { color: var(--muted); }
.face-input .sw { width: 40px; height: 40px; border-radius: 6px; border: 1px solid var(--line); background: #2d3238; image-rendering: pixelated; object-fit: cover; }
.custom-preview { display: grid; place-items: center; background: #6e6e6e; border-radius: 8px; padding: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  .sidebar { max-height: none; border-right: 0; }
  .stage { order: -1; position: sticky; top: 0; z-index: 5; background: var(--bg); }
  .viewport { height: 46vh; padding: 10px; }
  .row { grid-template-columns: 110px 1fr; }
  .model-row { grid-template-columns: 110px auto 1fr auto; }
}

.item input[type=number] { padding: 6px 5px; }
