:root {
  --bg: #0d1117;
  --bg2: #151b23;
  --bg3: #1c242e;
  --line: #2a3441;
  --fg: #dfe6ee;
  --dim: #8b97a6;
  --accent: #4da3ff;
  --accent2: #ffb454;
  --ok: #4ec9a0;
  --warn: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.hint { color: var(--dim); font-size: 11.5px; margin: 4px 0; }

/* header */
header {
  display: flex; align-items: center; gap: 18px; padding: 6px 14px;
  background: var(--bg2); border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
header h1 { font-size: 14px; margin: 0; font-weight: 600; white-space: nowrap; flex: 1; }
.tag {
  font-size: 10px; background: var(--bg3); color: var(--dim);
  padding: 1px 6px; border-radius: 8px; vertical-align: middle;
}
.meta-strip { display: flex; flex-direction: column; gap: 5px; }
.meta-strip label {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  color: var(--dim); font-size: 11px;
}
.meta-strip label input, .meta-strip label select { width: 160px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.status { color: var(--accent2); font-size: 11.5px; min-width: 150px; text-align: right; }

input, select, button, textarea {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 7px; font: inherit;
}
input[type=range] { padding: 0; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent); color: #06121f; border-color: var(--accent); font-weight: 600; }
button.mini { padding: 3px 7px; font-size: 11.5px; }
button.mode.active { background: var(--accent); color: #06121f; border-color: var(--accent); }

main { flex: 1; display: flex; min-height: 0; }

/* sidebar */
#sidebar {
  width: 330px; flex: 0 0 330px; overflow-y: auto;
  background: var(--bg2); border-right: 1px solid var(--line); padding: 8px;
}
.step { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.step h2 {
  font-size: 12.5px; margin: 0; padding: 7px 9px; display: flex; align-items: center; gap: 7px;
  border-bottom: 1px solid var(--line); font-weight: 600;
}
.step .num {
  width: 18px; height: 18px; border-radius: 50%; background: var(--bg3); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px;
}
.step .body { padding: 9px; display: flex; flex-direction: column; gap: 7px; }

/* A locked step explains itself instead of showing silently greyed-out controls. */
#next-step {
  background: rgba(77,163,255,.12); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 7px; padding: 8px 10px; margin-bottom: 8px; font-size: 12px; font-weight: 500;
}
.step .lock { display: none; }
.step.locked .lock {
  display: block; margin: 0; padding: 8px 9px; font-size: 11.5px; color: var(--accent2);
  background: rgba(255,180,84,.08); border-bottom: 1px solid var(--line);
}
.step.locked .body { opacity: .35; pointer-events: none; }
.step.locked .num { color: var(--dim); }
.howto { margin: 0; padding-left: 18px; font-size: 11.5px; color: var(--fg); }
.howto li { margin-bottom: 3px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row.modes { gap: 4px; }
.slider { display: flex; align-items: center; gap: 7px; color: var(--dim); font-size: 11.5px; }
.slider input[type=range] { flex: 1; }
.slider input[type=number] { width: 80px; }
.chk { color: var(--dim); font-size: 11.5px; display: flex; align-items: center; gap: 5px; }
label.small { color: var(--dim); font-size: 11.5px; }
label.small input { width: 62px; }

.picker { border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; }
.chosen {
  margin-top: 4px; font-family: ui-monospace, Menlo, monospace; font-size: 11px;
  color: var(--dim); word-break: break-all;
}
.chosen.ok { color: var(--ok); }

.branches { width: 100%; }
.legend { font-size: 10.5px; color: var(--dim); display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.sw { width: 11px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 3px; }
.sw.contrast { background: var(--accent); }
.sw.motion { background: var(--accent2); }
.sw.ed { background: var(--ok); height: 8px; width: 3px; }
.sw.es { background: var(--warn); height: 8px; width: 3px; }
/* Explicit CSS heights are required: these canvases have their width/height
   attributes rewritten on every redraw, and without a fixed CSS box the
   attribute would drive layout and the element would grow without bound. */
#phase-chart, #map-canvas { width: 100%; background: var(--bg3); border-radius: 5px; display: block; }
#phase-chart { height: 110px; }

table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
th { text-align: left; color: var(--dim); font-weight: 500; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid var(--line); padding: 2px 0; }
td.s { font-family: ui-monospace, Menlo, monospace; }
tr.active td { color: var(--accent); }

.labels { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--dim); }
.taglist { list-style: none; margin: 0; padding: 0; font-size: 11.5px; }
.taglist li { display: flex; justify-content: space-between; gap: 6px; border-bottom: 1px solid var(--line); padding: 3px 0; }

/* workspace */
#workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 8px; gap: 8px; overflow: hidden; }
.panels { flex: 1 1 auto; display: flex; gap: 8px; min-height: 320px; }
.panel {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px; padding: 5px 9px;
  border-bottom: 1px solid var(--line); background: var(--bg3);
}
.panel-head .title { font-weight: 600; font-size: 12px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; }
.canvas-wrap { flex: 1 1 auto; position: relative; min-height: 240px; background: #000; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#xa-canvas { cursor: crosshair; }
.transport { display: flex; align-items: center; gap: 6px; padding: 6px 9px; border-top: 1px solid var(--line); flex: 0 0 auto; }
.transport input[type=range] { flex: 1; }
.mapping { flex: 0 0 auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
#map-canvas { height: 120px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal.hidden { display: none; }
.modal-box { width: 820px; max-height: 78vh; background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.modal-path { padding: 7px 12px; display: flex; justify-content: space-between; gap: 12px; color: var(--dim); border-bottom: 1px solid var(--line); }
.filelist { list-style: none; margin: 0; padding: 4px; overflow-y: auto; }
.filelist li { padding: 6px 9px; border-radius: 5px; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.filelist li:hover { background: var(--bg3); }
.filelist li.dir::before { content: "📁"; }
.filelist li .thumb {
  width: 72px; height: 72px; object-fit: contain; background: #000;
  border: 1px solid var(--line); border-radius: 4px; flex: 0 0 auto;
}
.vmeta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vpath { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; word-break: break-all; }
.vsub { color: var(--dim); font-size: 11px; }

/* ---- browser-only build additions */
.engine {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line, #333);
  max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.engine.busy { color: var(--accent2); }
.engine.ok { color: var(--ok); }
.engine.err { color: var(--warn); }
.privacy { color: var(--dim); font-size: 11px; margin: 0 0 6px; padding: 0 9px; }
.modal-path { display: flex; flex-direction: column; gap: 4px; }

/* ---- demo mode */
.demo-notes {
  margin: 0 9px 8px; padding: 8px 10px; border: 1px solid var(--accent2); border-radius: 7px;
  font-size: 11.5px; color: var(--fg, #d8dee6); background: rgba(255, 180, 84, .06);
}
.demo-notes[hidden] { display: none; }
.demo-notes .demo-title { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--accent2); }
.demo-notes p { margin: 4px 0; color: var(--dim); }
.demo-notes ul { margin: 4px 0 0; padding-left: 16px; }
.demo-notes li { margin: 2px 0; }
.filelist li.demo-tools { cursor: default; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.filelist li.demo-tools:hover { background: none; }
.split { display: inline-flex; }
.split .demo-btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split .demo-btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: none; padding-left: 7px; padding-right: 7px; }
