:root {
  --bg: #121316;
  --panel: #1a1c20;
  --panel-2: #22252a;
  --line: #2f333a;
  --text: #e4e6ea;
  --muted: #8b919b;
  --accent: #38bdf8;
  --danger: #f87171;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 16px; margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }

button, select, input[type=number], input[type=text] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font: inherit;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: #4a505a; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #04202c; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
input[type=color] { width: 44px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
input:focus-visible, select:focus-visible, button:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100vh; }
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.dropzone { border: 1.5px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.dropzone p { margin: 0 0 8px; }
.dropzone.over { border-color: var(--accent); background: rgba(56, 189, 248, .08); }
.dropzone .row { justify-content: center; flex-wrap: wrap; }
.run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.group { border: 1px solid var(--line); border-radius: 8px; padding: 0 10px 8px; margin-bottom: 8px; }
.group summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) 160px; align-items: center; gap: 8px; margin: 6px 0; }
.field > span:first-child { color: var(--muted); font-size: 13px; }
.field select, .field input[type=number], .field input[type=text] { width: 100%; min-width: 0; }
.optcolor { display: flex; gap: 6px; align-items: center; }
.optcolor input[type=color] { opacity: .35; }
.optcolor.set input[type=color] { opacity: 1; }
.optcolor .clear { padding: 2px 8px; }

.toolbar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel); }
.seg button.active { background: var(--accent); color: #04202c; font-weight: 600; }

.stage-row { flex: 1; display: flex; min-height: 0; }
.viewport { position: relative; flex: 1; overflow: hidden; min-width: 0; cursor: grab; touch-action: none; }
.viewport.panning { cursor: grabbing; }
.bg-checker { background-color: #cfd2d8; background-image: linear-gradient(45deg, #9ea3ad 25%, transparent 25%, transparent 75%, #9ea3ad 75%), linear-gradient(45deg, #9ea3ad 25%, transparent 25%, transparent 75%, #9ea3ad 75%); background-size: 20px 20px; background-position: 0 0, 10px 10px; }
.bg-white { background: #fff; }
.bg-black { background: #000; }
#canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#original, #stage { position: absolute; left: 0; top: 0; width: 100%; height: 100%; user-select: none; }
#original { pointer-events: none; image-rendering: auto; }
#stage svg { width: 100%; height: 100%; display: block; overflow: visible; }
#split-handle { position: absolute; top: 0; bottom: 0; width: calc(14px / var(--scale, 1)); margin-left: calc(-7px / var(--scale, 1)); cursor: ew-resize; z-index: 3; }
#split-handle::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: calc(2px / var(--scale, 1)); margin-left: calc(-1px / var(--scale, 1)); background: var(--accent); }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #555b66; pointer-events: none; }
.busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(0, 0, 0, .45); color: #fff; z-index: 5; }
.spinner { width: 22px; height: 22px; 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); } }
.error { position: absolute; left: 12px; right: 12px; bottom: 12px; background: #3b1a1a; border: 1px solid var(--danger); color: #fecaca; padding: 8px 12px; border-radius: 8px; z-index: 6; white-space: pre-wrap; }

.sidebar { width: 250px; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 16px; }
.sidebar .field { grid-template-columns: 1fr auto; }
.palette { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.palette li { display: flex; align-items: center; gap: 8px; }
.palette .hex { font-family: ui-monospace, monospace; font-size: 12px; flex: 1; }
.palette .count { color: var(--muted); font-size: 12px; }
.palette button { padding: 2px 8px; }

.stats { display: flex; gap: 18px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 13px; }
.stats b { color: var(--muted); font-weight: 500; }
.stats i { font-style: normal; }
.toast { margin-left: auto; color: var(--accent); }
.report { border-top: 1px solid var(--line); padding: 6px 12px; }
.report summary { cursor: pointer; color: var(--muted); }
.report pre { max-height: 220px; overflow: auto; background: var(--panel); padding: 8px; border-radius: 6px; font-size: 12px; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 290px minmax(0, 1fr); }
  .stage-row { flex-direction: column; }
  .viewport { min-height: 55vh; }
  .sidebar { width: auto; border-left: 0; border-top: 1px solid var(--line); }
}

.stops { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.stops .field { margin: 0; grid-template-columns: 1fr auto; }
