:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dcdfe5;
  --text: #1b1f27;
  --muted: #667085;
  --accent: #1f5eff;
  --accent-text: #ffffff;
  --highlight: #ff1f8f;
  --highlight-fill: rgba(255, 31, 143, 0.28);
  --ok: #12a150;
  --warn: #d97706;
  --danger: #d92d20;
  --stage: #1d2129;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --surface: #1b1e24; --surface-2: #252932; --border: #333845;
    --text: #e8eaee; --muted: #9aa1ae; --accent: #4f80ff; --stage: #0c0e11;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --surface: #1b1e24; --surface-2: #252932; --border: #333845;
  --text: #e8eaee; --muted: #9aa1ae; --accent: #4f80ff; --stage: #0c0e11;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
mark { background: var(--highlight-fill); color: inherit; border-bottom: 2px solid var(--highlight); padding: 0 2px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 2; }
.model-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.model-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.model-status.ready .dot { background: var(--ok); }
.model-status.error .dot { background: var(--danger); }
.model-status.loading .dot { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 240px 1fr 280px; gap: 12px; padding: 12px;
}
.photos-panel, .options-panel, .editor-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 0;
}
.photos-panel { display: flex; flex-direction: column; padding: 10px; gap: 10px; overflow: hidden; }
.options-panel { padding: 14px; overflow-y: auto; }
.editor-panel { display: flex; flex-direction: column; overflow: hidden; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 16px 10px; border: 2px dashed var(--border); border-radius: var(--radius);
  cursor: pointer; color: var(--muted); font-size: 13px; transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--text); font-size: 14px; }
.dropzone svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.hint-mobile { display: none; }
@media (hover: none) { .hint-desktop { display: none; } .hint-mobile { display: inline; } }

.queue-status { font-size: 13px; color: var(--muted); }
.thumbs { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: grid; gap: 8px; flex: 1; min-height: 0; align-content: start; }
.thumb {
  position: relative; display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center;
  padding: 6px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; background: var(--surface-2);
}
.thumb.active { border-color: var(--accent); }
.thumb img { width: 64px; height: 48px; object-fit: cover; border-radius: 5px; display: block; background: #000; }
.thumb .name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb .state { font-size: 12px; color: var(--muted); }
.thumb .state.found { color: var(--highlight); font-weight: 600; }
.thumb .state.none { color: var(--warn); font-weight: 600; }
.thumb .state.done { color: var(--ok); font-weight: 600; }
.thumb .state.error { color: var(--danger); }
.thumb .remove {
  position: absolute; top: 2px; right: 4px; border: 0; background: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 2px 4px; line-height: 1;
}
.thumb .remove:hover { color: var(--danger); }

.editor-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.mode-badge {
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px;
  background: var(--highlight-fill); color: var(--highlight); white-space: nowrap;
}
.mode-badge.masked { background: rgba(18, 161, 80, .15); color: var(--ok); }
.editor-hint { margin: 0; flex: 1; font-size: 13px; color: var(--muted); min-width: 0; }
.toolbar-actions { display: flex; align-items: center; gap: 6px; }
.nav-pos { font-size: 13px; color: var(--muted); min-width: 40px; text-align: center; }

.stage { position: relative; flex: 1; min-height: 0; background: var(--stage); touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-empty, .stage-busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #d8dce4; text-align: center; padding: 20px; pointer-events: none;
}
.stage-empty p { margin: 4px 0; }
.stage-empty mark { color: #fff; }
.stage-busy { flex-direction: row; gap: 10px; background: rgba(0, 0, 0, .35); }
.spinner { width: 18px; height: 18px; border: 3px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 18px; height: 11px; border: 2px solid var(--highlight); background: var(--highlight-fill); border-radius: 2px; }
.swatch.dashed { border-style: dashed; }

.btn {
  font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); padding: 9px 14px; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-size: 16px; padding: 12px 16px; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { width: 32px; height: 32px; padding: 0; font-size: 20px; line-height: 1; }

.choice-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice-group.compact { margin-top: 6px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.chip {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px;
  border: 2px solid var(--border); cursor: pointer; font-size: 14px; font-weight: 600; background: var(--surface-2);
}
.choice input:checked + .chip { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.choice input:focus-visible + .chip { outline: 2px solid var(--accent); outline-offset: 2px; }
.mini {
  width: 26px; height: 16px; border-radius: 3px; border: 1px solid #9aa1ae; flex: none;
  display: inline-flex; align-items: center; justify-content: center; font-style: normal; font-size: 10px; font-weight: 800;
}
.mini.white { background: #fff; }
.mini.black { background: #111; }
.mini.text, .mini.logo { background: #fff; color: #111; }

.sub-options { margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.field-label { font-size: 13px; font-weight: 600; }
.field input[type="text"] {
  font: inherit; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.field input[type="file"] { font-size: 13px; color: var(--muted); max-width: 100%; }
.logo-preview { margin-top: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; text-align: center; }
.logo-preview img { max-width: 100%; max-height: 60px; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.download-actions { display: flex; flex-direction: column; gap: 8px; }
.note { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.help { margin-top: 20px; font-size: 13px; border-top: 1px solid var(--border); padding-top: 12px; }
.help summary { cursor: pointer; font-weight: 600; }
.help ol { padding-left: 18px; margin: 8px 0; }
.help li { margin-bottom: 4px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 200px 1fr; }
  .options-panel { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  body { height: auto; }
  .layout { display: flex; flex-direction: column; padding: 8px 16px 16px; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .photos-panel { overflow: visible; }
  .thumbs { grid-auto-flow: column; grid-auto-columns: 150px; overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
  .editor-panel { min-height: 0; }
  .stage { flex: none; height: 62vh; min-height: 300px; }
  .editor-footer { flex-direction: column; align-items: stretch; }
  .editor-hint { display: none; }
  .toolbar-actions { margin-left: auto; }
}
