:root {
  --bg: #050505;            /* core black from the sheet */
  --panel: rgba(8, 8, 8, 0.92);
  --line: rgba(120, 246, 255, 0.14);
  --accent: #78f6ff;        /* Backbeat OS primary light */
  --accent-dim: #2c6b73;
  --text: #e7ffff;
  --muted: #6f8a8e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  overflow: hidden;
}

/* ---- Projection stage ---- */
#stage {
  position: fixed;
  inset: 0;
  background: #000;
}
#output { display: block; width: 100%; height: 100%; }

#handles {
  position: absolute;
  inset: 0;
  pointer-events: none; /* handles re-enable individually */
}

/* In-progress polygon drawing overlay */
#draw-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
  z-index: 5; /* above vertex handles while drawing */
  cursor: crosshair;
}
#draw-layer polyline {
  fill: rgba(120, 246, 255, 0.12);
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 5;
}
#draw-layer circle { fill: var(--accent); }
#draw-layer circle.first { fill: #fff; stroke: var(--accent); stroke-width: 2; }
body.drawing #draw-layer { cursor: crosshair; }
.handle {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(120, 246, 255, 0.25);
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  transition: transform 0.08s ease, background 0.08s ease;
}
.handle:hover { background: rgba(120, 246, 255, 0.55); transform: scale(1.15); }
.handle:active { cursor: grabbing; }
.handle.corner {
  border-radius: 3px;
  border-color: #fff;
  width: 20px; height: 20px;
  margin: -10px 0 0 -10px;
}
.handle.bez {
  width: 13px; height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border-radius: 50%;
  border-color: var(--accent);
  background: rgba(120, 246, 255, 0.18);
}
.handle.bez:hover { background: rgba(120, 246, 255, 0.5); }

/* ---- Control panel ---- */
#panel {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 340px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--line);
  padding: 18px 18px 40px;
  overflow-y: auto;
  z-index: 10;
}
#panel header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
}
#panel header .sub { font-size: 11px; color: var(--muted); }

/* ---- Content / Mapping tabs ---- */
.tabs {
  display: flex;
  gap: 6px;
  margin-top: 16px;
}
.tab {
  flex: 1;
  padding: 9px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  background: #0e0e0e;
  border: 1px solid var(--line);
}
.tab.active {
  background: var(--accent);
  color: #050505;
  border-color: var(--accent);
  font-weight: 600;
}
#panel-content section:first-child,
#panel-mapping section:first-child { border-top: none; margin-top: 16px; }

#panel section {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
#panel h2 {
  margin: 0 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0;
  font-size: 13px;
}
.row > span { color: var(--muted); flex: 0 0 auto; }
.row.btns { flex-wrap: wrap; }

select, input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
}
select {
  background: #111111;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 13px;
}

button {
  background: #121212;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #1d1d1d; border-color: var(--accent-dim); }
button.active { background: var(--accent); color: #050505; border-color: var(--accent); font-weight: 600; }

.seg { display: flex; gap: 6px; }
.seg button { padding: 6px 12px; }

.monitor {
  flex: 1 1 auto;
  height: 64px;
  overflow-y: auto;
  background: #080808;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #9fb6b8;
}
.monitor .hot { color: var(--accent); }

.hint { font-size: 11px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }
.hint b { color: #bdeef2; }

/* ---- Mapping list rows ---- */
.map-row {
  display: grid;
  grid-template-columns: 14px 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.map-row:last-child { border-bottom: none; }
.map-row.selected { box-shadow: inset 2px 0 0 var(--accent); background: rgba(255,255,255,0.03); }
.map-row.on .note { color: #ff6a34; }
.map-row.on { background: rgba(255,90,36,0.06); }
.swatch { width: 14px; height: 14px; border-radius: 4px; }
.map-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-row .note { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); min-width: 56px; text-align: right; }
.map-row .learn { padding: 4px 9px; font-size: 11px; }
.map-row .learn.listening { background: var(--accent); color: #050505; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.map-row .out-pick {
  padding: 4px 7px;
  font-size: 10px;
  font-family: ui-monospace, Menlo, monospace;
  min-width: 34px;
  color: var(--muted);
}
.map-row .out-pick.out-A { color: #78f6ff; border-color: var(--accent-dim); }
.map-row .out-pick.out-B { color: #ffb27a; border-color: #7a4a2c; }
.map-row .out-pick.out-AB { color: #cdeef2; }

/* ---- Zone list + pad assignment ---- */
.subhead {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 14px 0 8px;
}
#zone-list { margin: 6px 0; }
.zone-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}
.zone-row.active .zone-name { color: var(--accent); font-weight: 600; }
.zone-pick {
  padding: 2px 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}
.zone-pick:hover { background: none; }
.zone-name {
  background: #111111;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 13px;
  min-width: 0;
}
.zone-count { font-size: 11px; color: var(--muted); white-space: nowrap; }

#zone-pad-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 6px;
}
.pad-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
}
.pad-check input { accent-color: var(--accent); }
.pad-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }

/* ---- Animation center XY pad ---- */
#center-pad {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 180px;
  margin: 4px 0 8px;
  background: #0b0b0b;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
  background-image: linear-gradient(var(--line), var(--line)), linear-gradient(var(--line), var(--line));
  background-size: 1px 100%, 100% 1px;
  background-position: center, center;
  background-repeat: no-repeat;
}
#center-dot {
  position: absolute;
  left: 50%; top: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: rgba(120, 246, 255, 0.4);
  border: 2px solid var(--accent);
  box-shadow: 0 0 10px var(--accent);
  pointer-events: none;
}

/* ---- Audio spectrum + band routing ---- */
#audio-spectrum {
  display: block;
  width: 100%;
  height: 150px;
  margin: 8px 0 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0807;
  touch-action: none;            /* let pointer-drag own the gesture */
}
#audio-bands {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 8px 0 4px;
}
.band-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.band-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
  box-shadow: 0 0 6px currentColor;
}
.band-name {
  flex: 0 0 54px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.band-pad { flex: 1 1 auto; }

/* ---- Performance mode ---- */
body.performance #panel,
body.performance #handles,
body.performance #draw-layer,
body.performance #show-panel { display: none; }
body.performance #stage { cursor: none; }

body.panel-hidden #panel { display: none; }
body.panel-hidden #show-panel { display: block; }

/* ---- Feed mode: nothing but the clean render, for Resolume capture ---- */
body.feed #panel,
body.feed #handles,
body.feed #draw-layer,
body.feed #show-panel { display: none; }
body.feed #stage { cursor: none; }
body.feed { background: #000; }

#show-panel {
  position: fixed;
  top: 14px; left: 14px;
  z-index: 11;
}

#errbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: #3a0d12;
  color: #ffd7dc;
  border-top: 1px solid #ff5a5a;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  padding: 10px 14px;
  white-space: pre-wrap;
}
