:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1f2330;
  --line: #2b3040;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --accent: #ffd23f;
  --accent-ink: #1a1400;
  --danger: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, kbd { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--panel-2);
  padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.logo { width: 26px; height: 36px; border-radius: 4px; background:
  linear-gradient(#866bff, #866bff) 4px 6px / 18px 13px no-repeat, var(--accent); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; user-select: none; }
.btn:hover { border-color: #3c4358; }
.btn:focus-visible, .tool:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.settings { position: relative; }
.settings summary { list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings-panel { position: absolute; right: 0; top: calc(100% + 6px); width: 300px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,.4); }
.settings-panel label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.settings-panel label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; }
.settings-panel output { color: var(--text); float: right; }
input[type=text] { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }
input[type=range] { accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.queue { display: flex; gap: 8px; padding: 10px 20px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.queue button { flex: none; width: 54px; height: 75px; padding: 0; border-radius: 5px; border: 2px solid transparent;
  background: var(--panel-2) center / cover no-repeat; cursor: pointer; position: relative; }
.queue button.on { border-color: var(--accent); }
.queue button[data-status=done]::after { content: "✓"; position: absolute; right: 2px; bottom: 2px; font-size: 11px;
  background: #2fbf71; color: #fff; border-radius: 50%; width: 15px; height: 15px; line-height: 15px; }
.queue button[data-status=error]::after { content: "!"; position: absolute; right: 2px; bottom: 2px; font-size: 11px;
  background: var(--danger); color: #fff; border-radius: 50%; width: 15px; height: 15px; line-height: 15px; }

.workspace { display: grid; grid-template-columns: minmax(260px, 0.9fr) minmax(340px, 1.4fr) minmax(260px, 0.9fr);
  gap: 16px; padding: 16px 20px 40px; align-items: start; }
@media (max-width: 1100px) { .workspace { grid-template-columns: 1fr 1fr; } #panel-art { grid-column: 1 / -1; order: -1; } }
@media (max-width: 700px) { .workspace { grid-template-columns: 1fr; } }

.dropzone { grid-column: 1 / -1; min-height: 50vh; display: grid; place-items: center; text-align: center;
  border: 2px dashed var(--line); border-radius: 16px; color: var(--muted); cursor: pointer; }
.dropzone .big { font-size: 20px; color: var(--text); margin: 0 0 8px; }
.dropzone.drag, .workspace.drag { border-color: var(--accent); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.badge { font-size: 11px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 99px; }
.badge.warn { color: #ffcf70; border-color: #6b5420; }

.canvas-wrap { position: relative; border-radius: 6px; overflow: hidden; background: #0a0c10; line-height: 0; }
.canvas-wrap canvas { width: 100%; height: auto; display: block; touch-action: none; }
.checker { background: repeating-conic-gradient(#20242f 0 25%, #171a22 0 50%) 0 0 / 18px 18px; }
#art-canvas { cursor: crosshair; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.tool { appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font: inherit; }
.tool.on { background: #2a2f40; border-color: var(--accent); color: var(--accent); }
.size { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); margin-left: 4px; }
.size input { width: 90px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--muted); padding: 5px 10px; cursor: pointer; font: inherit; font-size: 12px; }
.seg button.on { background: var(--panel-2); color: var(--text); }

.instances-head { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.instances { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.instances li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; }
.instances li.active { border-color: var(--accent); }
.instances .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.instances .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instances .score { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.instances .del { appearance: none; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0 4px; }
.instances .del:hover { color: var(--danger); }
.instances .empty { color: var(--muted); border-style: dashed; cursor: default; }

.holo-stage { display: grid; place-items: center; padding: 18px 8px; perspective: 900px; }
.holo { --mx: 50%; --my: 50%; --rx: 0deg; --ry: 0deg; --int: .75; --o: 0;
  position: relative; width: min(100%, 320px); border-radius: 4.5% / 3.3%; overflow: hidden;
  transform: rotateX(var(--rx)) rotateY(var(--ry)); transition: transform .4s ease-out; box-shadow: 0 16px 40px rgba(0,0,0,.5); }
.holo.active { transition: none; }
.holo img { display: block; width: 100%; height: auto; }
.holo .shine, .holo .glare { position: absolute; inset: 0; pointer-events: none; }
.holo .shine {
  -webkit-mask-image: var(--mask); mask-image: var(--mask);
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.0) 0 2px, rgba(255,255,255,.08) 2px 3px),
    repeating-linear-gradient(115deg,
      hsl(2 90% 70%) 0%, hsl(45 95% 68%) 6%, hsl(100 80% 66%) 12%, hsl(175 85% 65%) 18%,
      hsl(225 90% 72%) 24%, hsl(285 85% 72%) 30%, hsl(2 90% 70%) 36%);
  background-size: 100% 100%, 400% 400%;
  background-position: 0 0, var(--mx) var(--my);
  mix-blend-mode: color-dodge; opacity: calc(var(--int) * (0.55 + 0.45 * var(--o)));
  filter: brightness(.75) contrast(1.4) saturate(1.3);
}
.holo .glare { background: radial-gradient(circle at var(--mx) var(--my), rgba(255,255,255,.55) 0%, rgba(255,255,255,0) 45%);
  mix-blend-mode: overlay; opacity: var(--o); }
.slider { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; }
.slider input { flex: 1; }

.busy { position: fixed; inset: 0; background: rgba(8,10,14,.6); display: grid; place-content: center; justify-items: center;
  gap: 14px; z-index: 20; backdrop-filter: blur(2px); }
.busy[hidden] { display: none; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #333a4d; border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 90vw; }
.toast.error { border-color: var(--danger); }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { .holo { transition: none; } .spinner { animation-duration: 2s; } }

.name-row { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.name-row label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.name-row input { flex: 1; min-width: 0; }
#name-hint { margin-top: 4px; }

.check-inline { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; cursor: pointer; }
.check-inline input { accent-color: var(--accent); }
.muted { color: var(--muted); font-size: 12px; }

/* engine selector, steps, guide, model downloads */
.settings-panel select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }
#engine-badge { white-space: nowrap; }
.steps { text-align: left; display: inline-block; margin: 14px auto 6px; padding-left: 22px; color: var(--text); line-height: 1.7; }
.steps b { color: var(--accent); font-weight: 600; }
.guide { max-width: 640px; width: calc(100vw - 32px); max-height: calc(100vh - 48px); overflow: auto; background: var(--panel);
  color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.guide::backdrop { background: rgba(8,10,14,.65); backdrop-filter: blur(2px); }
.guide-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.guide h3 { margin: 16px 0 6px; color: var(--accent); text-transform: none; letter-spacing: 0; font-size: 14px; }
.guide ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.guide p { margin: 8px 0; }
.busy-models { display: grid; gap: 6px; min-width: min(420px, 86vw); }
.busy-models:empty { display: none; }
.model-row { display: grid; grid-template-columns: 1fr 120px 110px; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); }
.model-row progress { width: 100%; height: 8px; accent-color: var(--accent); }
.model-row .model-size { text-align: right; font-variant-numeric: tabular-nums; }
#busy-text { max-width: 86vw; text-align: center; }
