:root {
  --bg: #ebe6dc;
  --paper: #f1ece1;
  --ink: #1a1814;
  --ink-soft: rgba(26, 24, 20, 0.55);
  --ink-faint: rgba(26, 24, 20, 0.18);
  --ink-trace: rgba(26, 24, 20, 0.07);
  --accent: #c43219;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  overflow: hidden;
  font-size: 12px;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}

/* ---- sidebar ---- */
#controls {
  background: var(--paper);
  border-right: 1px solid var(--ink);
  padding: 18px 18px 48px;
  overflow-y: auto;
}
.brand {
  margin-bottom: 6px; padding-bottom: 16px; border-bottom: 1px solid var(--ink);
}
.brand .title { font-weight: 500; font-size: 16px; letter-spacing: 0.08em; }
.brand .subtitle {
  color: var(--ink-soft); font-size: 9px;
  letter-spacing: 0.18em; margin-top: 4px;
}

h2 {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--ink); font-weight: 500; margin: 26px 0 12px; padding-bottom: 7px;
  border-bottom: 1px solid var(--ink-faint);
  display: flex; align-items: center; gap: 8px;
}
h2::before { content: ''; width: 5px; height: 5px; background: var(--accent); flex-shrink: 0; }
h2:first-of-type { margin-top: 18px; }

h3.sub {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--ink-soft); font-weight: 500; margin: 22px 0 10px; padding-bottom: 6px;
  border-bottom: 1px dashed var(--ink-faint);
  display: flex; align-items: center; gap: 8px;
}
h3.sub::before { content: ''; width: 5px; height: 5px; border: 1px solid var(--accent); flex-shrink: 0; }

.row { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 5px; }
.row label { color: var(--ink-soft); font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em; }
.row.check { align-items: center; margin-top: 14px; }
.row.check label { cursor: pointer; }
.val { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 10px; letter-spacing: 0.08em; }
.muted { color: var(--ink-soft); }
.small { font-size: 10px; line-height: 1.65; letter-spacing: 0.03em; }
b { font-weight: 500; }

/* ---- range slider (blueprint: 1px track, accent fill, ring handle) ---- */
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 14px; background: transparent; margin: 2px 0; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(to right,
    var(--accent) 0 calc(var(--p, 0) * 1%),
    var(--ink-faint) calc(var(--p, 0) * 1%) 100%);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 11px; height: 11px; margin-top: -5px; border-radius: 50%;
  background: var(--paper); border: 1px solid var(--ink);
}
input[type=range]:hover::-webkit-slider-thumb { background: var(--ink); }
input[type=range]::-moz-range-track { height: 1px; background: var(--ink-faint); }
input[type=range]::-moz-range-progress { height: 1px; background: var(--accent); }
input[type=range]::-moz-range-thumb {
  width: 11px; height: 11px; border: 1px solid var(--ink); border-radius: 50%; background: var(--paper);
}

/* ---- checkboxes (square, fills when checked) ---- */
input[type=checkbox] {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border: 1px solid var(--ink); background: transparent;
  cursor: pointer; flex-shrink: 0; display: inline-block; vertical-align: middle; margin: 0;
}
input[type=checkbox]:checked { background: var(--ink); box-shadow: inset 0 0 0 2px var(--paper); }

/* ---- colour swatch ---- */
input[type=color] {
  -webkit-appearance: none; appearance: none;
  width: 46px; height: 18px; border: 1px solid var(--ink); background: none;
  padding: 0; cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type=color]::-webkit-color-swatch { border: 1px solid var(--ink-faint); }
input[type=color]::-moz-color-swatch { border: 1px solid var(--ink-faint); }
.ctl { display: flex; align-items: center; gap: 8px; }

/* ---- buttons (bordered, invert on hover) ---- */
button, input[type=file]::file-selector-button {
  background: transparent; color: var(--ink);
  border: 1px solid var(--ink); border-radius: 0;
  padding: 9px 11px; font-size: 9.5px; cursor: pointer;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.16em;
  transition: background 0.14s, color 0.14s;
}
button:hover, input[type=file]::file-selector-button:hover { background: var(--ink); color: var(--paper); }
button:active { transform: translateY(1px); }
button.primary { background: var(--ink); color: var(--paper); }
button.primary:hover { background: var(--accent); border-color: var(--accent); }

input[type=file] {
  color: var(--ink-soft); font-size: 9px; width: 100%; margin-top: 10px;
  font-family: var(--mono); letter-spacing: 0.08em;
}
input[type=file]::file-selector-button { margin-right: 11px; padding: 7px 10px; }

.actions { display: flex; gap: 8px; margin: 10px 0; }
.actions button { flex: 1; }
.actions button.wide { flex: 1 0 100%; }
.transport { display: flex; gap: 8px; margin: 6px 0 10px; }
.transport button { flex: 1; }

#imgInfo, #endsInfo, #postInfo, #simInfo { margin-top: 12px; }

/* ---- debug layers ---- */
#layers { display: flex; flex-direction: column; gap: 0; }
.lyr {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px; cursor: pointer; color: var(--ink-soft);
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.1em;
  border-bottom: 1px dashed transparent;
}
.lyr:hover { color: var(--ink); border-bottom-color: var(--ink-faint); }

/* ---- stage ---- */
#stage { display: flex; flex-direction: column; min-width: 0; }
#toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; background: var(--paper);
  border-bottom: 1px solid var(--ink); flex: 0 0 auto;
}
#toolbar .sep { width: 1px; height: 16px; background: var(--ink-faint); }
.readout {
  font-variant-numeric: tabular-nums; color: var(--ink-soft);
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.12em;
}
.badge {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.16em;
  padding: 4px 10px; border-radius: 0; border: 1px solid var(--ink-faint);
  background: transparent; color: var(--ink-soft);
}
.badge.run { color: var(--accent); border-color: var(--accent); }
.badge.done { color: var(--paper); background: var(--ink); border-color: var(--ink); }
.badge.fail { color: var(--paper); background: var(--accent); border-color: var(--accent); }
#status { margin-left: auto; color: var(--ink-soft); font-size: 9.5px; letter-spacing: 0.05em; }

/* ---- workarea ---- */
#workarea {
  position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden;
  background-color: var(--bg);
}
#view { position: absolute; inset: 0; width: 100%; height: 100%; }

/* corner registration marks */
.wa-corner { position: absolute; width: 13px; height: 13px; color: var(--ink-soft); pointer-events: none; z-index: 2; }
.wa-corner svg { width: 100%; height: 100%; display: block; }
.wa-corner.tl { top: 12px; left: 12px; }
.wa-corner.tr { top: 12px; right: 12px; }
.wa-corner.bl { bottom: 12px; left: 12px; }
.wa-corner.br { bottom: 12px; right: 12px; }

#legend {
  position: absolute; left: 14px; bottom: 14px;
  background: rgba(241, 236, 225, 0.92); border: 1px solid var(--ink);
  border-radius: 0; padding: 11px 13px; font-size: 9px; color: var(--ink-soft);
  pointer-events: none; max-width: 270px; line-height: 1.95;
  text-transform: uppercase; letter-spacing: 0.07em;
}
#legend .k {
  display: inline-block; width: 9px; height: 9px; border-radius: 0;
  margin-right: 6px; vertical-align: -1px; border: 1px solid var(--ink-faint);
}
