:root {
  --bg: #f5f5f3;
  --panel: #ffffff;
  --line: #e3e2de;
  --text: #1d1d1b;
  --muted: #74726c;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --ok: #2e8b57;
  --err: #c0392b;
  --stage: #ecebe7;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --panel: #1f1f1d;
    --line: #34332f;
    --text: #ecebe7;
    --muted: #9b9990;
    --accent: #5b8ff0;
    --stage: #121211;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, select, input { font: inherit; color: inherit; }

.top {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 14px max(16px, env(safe-area-inset-left)) 10px;
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 17px; margin: 0; font-weight: 650; }
.status { color: var(--muted); font-size: 13px; }
.status.ready { color: var(--ok); }
.status.err { color: var(--err); }
.privacy { margin-left: auto; color: var(--muted); font-size: 12px; }

.layout {
  display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px;
  padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
  max-width: 1600px; margin: 0 auto;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.slot {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 92px; padding: 12px;
  background: var(--panel); border: 1.5px dashed var(--line); border-radius: var(--radius);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.slot:hover, .slot:focus-visible, .slot.drag { border-color: var(--accent); outline: none; }
.slot.drag { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.slot.filled { border-style: solid; }
.slot-title { font-weight: 600; }
.slot-hint, .slot-meta { color: var(--muted); font-size: 12px; }
.slot-body { flex: 1; min-width: 0; }
.slot-thumb { width: 64px; height: 80px; object-fit: cover; border-radius: 6px; background: var(--stage); }
#slotA.filled { flex-wrap: wrap; }
#slotA .slot-meta { width: 100%; }

.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.queue:empty { display: none; }
.queue li {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.queue li.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.queue img { width: 40px; height: 50px; object-fit: cover; border-radius: 4px; background: var(--stage); }
.queue .q-text { flex: 1; min-width: 0; }
.queue .q-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue .q-state { font-size: 12px; color: var(--muted); }
.queue .q-state.err { color: var(--err); }
.queue .q-state.ok { color: var(--ok); }
.queue .q-del { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 4px 6px; cursor: pointer; }

.settings {
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.settings .row { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 10px; }
.settings select { grid-column: 2 / 4; }
.settings output { font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; color: var(--muted); }
select, input[type=number] {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; min-width: 0;
}
input[type=number] { width: 5.5em; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.main { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.info { color: var(--muted); font-size: 13px; }

.stage {
  position: relative; background: var(--stage); border-radius: var(--radius);
  min-height: 360px; display: flex; align-items: center; justify-content: center;
  overflow: auto; max-height: 78vh;
}
.stage.face { align-items: flex-start; justify-content: flex-start; }
.placeholder { color: var(--muted); padding: 40px 16px; text-align: center; }
.compare { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 0; margin: auto; }
.compare canvas { display: block; }
.compare #cvAfter { position: absolute; left: 0; top: 0; }
.stage:not(.face) .compare canvas { max-width: 100%; max-height: 78vh; width: auto; height: auto; }
.handle {
  position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.25); cursor: ew-resize;
}
.handle span {
  position: absolute; top: 50%; left: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.handle span::before, .handle span::after {
  content: ""; position: absolute; top: 10px; border: 5px solid transparent;
}
.handle span::before { left: 3px; border-right-color: #555; }
.handle span::after { right: 3px; border-left-color: #555; }
.tag {
  position: absolute; top: 8px; padding: 2px 8px; border-radius: 4px; font-size: 12px; line-height: 1.6;
  background: rgba(0,0,0,.55); color: #fff; pointer-events: none;
}
.tag-l { left: 8px; }
.tag-r { right: 8px; }
.stage.face .tag { position: sticky; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .45; cursor: default; }

.gifbox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.gifbox summary { cursor: pointer; font-weight: 600; }
.gifopts { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 10px; }
.gifopts label { display: inline-flex; align-items: center; gap: 6px; }
.gifout { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.gifout img { max-width: 100%; max-height: 60vh; align-self: flex-start; border-radius: 6px; background: var(--stage); }
.gifbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }

.progress {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; width: min(420px, calc(100% - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.15);
}
.progress .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress .bar.indet i { width: 30%; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }
.progress span { font-size: 13px; color: var(--muted); white-space: nowrap; }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 10;
}
.toast.err { background: var(--err); color: #fff; }
[hidden] { display: none !important; }
