:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eceef2; --line: #d9dce3;
  --text: #1b1e27; --muted: #5d6475; --accent: #3b5bdb; --accent-text: #fff; --danger: #c92a2a;
  --canvas: #e7eaf0; --shadow: 0 1px 2px rgba(20,24,40,.08), 0 8px 24px rgba(20,24,40,.06);
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101218; --surface: #181b23; --surface-2: #20242e; --line: #2c313d;
    --text: #e8eaf0; --muted: #9aa1b2; --accent: #7c93ff; --accent-text: #0c0f1a; --danger: #ff8787;
    --canvas: #0c0e13; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--accent); white-space: nowrap; }
.brand span { color: var(--text); font-size: 16px; }
.brand small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.stats { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats b { color: var(--text); font-weight: 600; }

.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 5; background: transparent; overflow: hidden; }
.progress .bar { height: 100%; width: 35%; background: var(--accent); border-radius: 2px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@media (prefers-reduced-motion: reduce) { .progress .bar { animation: none; width: 100%; opacity: .6; } }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px 1fr; gap: 12px; padding: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 12px; overflow: auto; box-shadow: var(--shadow); }
fieldset { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 10px; }
legend { padding: 0; margin-bottom: 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.row output { font-variant-numeric: tabular-nums; color: var(--muted); }
.row input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
select { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; }

button { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; text-align: center; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.primary.dirty { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
button.ghost { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; cursor: pointer; color: var(--muted); background: var(--surface-2); transition: border-color .15s, background .15s; }
.drop strong { color: var(--text); }
.drop .hint { font-size: 12px; opacity: .8; }
.drop:hover, .drop:focus-visible, body.dragging .drop { border-color: var(--accent); }

.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { display: inline-block; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.chip input:checked + span { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pane { position: relative; min-height: 220px; border-radius: var(--radius); background: var(--canvas); border: 1px solid var(--line); overflow: hidden; box-shadow: var(--shadow); }
.pane canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#atlas { image-rendering: pixelated; object-fit: contain; background: var(--canvas); }
.tag { position: absolute; top: 10px; left: 10px; z-index: 2; padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--surface) 85%, transparent); border: 1px solid var(--line); font-size: 12px; color: var(--muted); backdrop-filter: blur(6px); }
.empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); pointer-events: none; }
.empty:empty, .empty[hidden] { display: none; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); border: 1px solid var(--danger); border-left-width: 5px; border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); z-index: 10; overflow-wrap: anywhere; }
.veil { position: fixed; inset: 0; z-index: 9; display: none; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--bg) 80%, transparent); border: 3px dashed var(--accent); border-radius: 16px; margin: 8px; pointer-events: none; }
body.dragging .veil { display: grid; }
[hidden] { display: none !important; }

@media (max-width: 860px) {
  body { height: auto; min-height: 100%; }
  .layout { grid-template-columns: 1fr; }
  .panes { grid-template-columns: 1fr; }
  .pane { height: 56vw; min-height: 260px; }
  .brand small { display: none; }
  .top { flex-wrap: wrap; }
  .stats { margin-left: 0; width: 100%; text-align: left; white-space: normal; }
}

.foot { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--accent); }
