:root {
  --bg: #0d0b10;
  --panel: #17141c;
  --line: #2c2734;
  --text: #ece6dc;
  --muted: #8d8496;
  --vol: #ff8a3d;
  --pitch: #5fd4c4;
  --wire: #b9a6ff;
  --display: "Futura", "Avenir Next", "Century Gothic", "Trebuchet MS", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: radial-gradient(ellipse at 50% -10%, #241c2e 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--display);
  min-height: 100vh;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

header { text-align: center; }

h1 {
  margin: 8px 0 0;
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-weight: 500;
  padding-left: 0.32em; /* balance letter-spacing */
  background: linear-gradient(90deg, var(--vol), var(--pitch));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub {
  margin: 4px 0 0;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: lowercase;
  font-size: 0.9rem;
}

main {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  gap: 14px;
  width: 100%;
  max-width: 980px;
  align-items: stretch;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.stage video, .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1); /* mirror, so your left is on the left */
}

.stage video { object-fit: cover; filter: saturate(0.7) brightness(0.8); }

.splash {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(13, 11, 16, 0.86);
  font-size: 1.1rem;
  line-height: 1.5;
}
.splash p { margin: 0; }
.splash b:first-of-type { color: var(--vol); }
.splash b:last-of-type { color: var(--pitch); }
.splash .fine { font-size: 0.8rem; color: var(--muted); }
.splash .status { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.splash .status.error { color: #ff6b6b; }
.splash[hidden] { display: none; }

button, select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}
button:hover:not(:disabled), select:hover { border-color: var(--muted); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--pitch); outline-offset: 2px; }

#startBtn {
  font-size: 1.05rem;
  padding: 12px 26px;
  border: none;
  color: #120e16;
  background: linear-gradient(90deg, var(--vol), var(--pitch));
  font-weight: 600;
  letter-spacing: 0.04em;
}

.meter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.meter-track {
  position: relative;
  flex: 1;
  width: 18px;
  min-height: 120px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
}
.meter-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  border-radius: 999px;
}
#volMeter .meter-fill { background: var(--vol); box-shadow: 0 0 18px var(--vol); }
#pitchMeter .meter-fill { background: var(--pitch); box-shadow: 0 0 18px var(--pitch); }
.meter-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-align: center;
  line-height: 1.3;
  white-space: nowrap;
}
#volMeter .meter-label { color: var(--vol); }
#pitchMeter .meter-label { color: var(--pitch); }
.meter-label small { color: var(--muted); letter-spacing: 0.04em; font-size: 0.66rem; }

.readout {
  display: flex;
  gap: 28px;
  font-family: var(--mono);
  flex-wrap: wrap;
  justify-content: center;
}
.readout div { display: flex; flex-direction: column; align-items: center; min-width: 72px; }
.readout .k { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.16em; text-transform: uppercase; }
.readout .v { font-size: 1.4rem; font-variant-numeric: tabular-nums; }

#trace {
  width: 100%;
  max-width: 980px;
  height: 90px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: center;
  align-items: flex-end;
  max-width: 980px;
}
.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.controls select { text-transform: none; letter-spacing: normal; font-size: 0.9rem; }

footer {
  max-width: 620px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
  text-align: center;
}

@media (max-width: 600px) {
  main { grid-template-columns: 34px minmax(0, 1fr) 34px; gap: 8px; }
  .meter-track { width: 12px; }
  .meter-label small { display: none; }
  .meter-label { font-size: 0.6rem; letter-spacing: 0.06em; }
  .stage { aspect-ratio: 3 / 4; }
  .readout { gap: 16px; }
}

.soon {
  margin-top: 20px;
  color: var(--text);
  font-style: italic;
  letter-spacing: 0.04em;
}

.footnote {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.graph {
  margin: 0;
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.graph[hidden] { display: none; }
.graph figcaption {
  display: flex;
  gap: 16px;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.graph .key::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 2px;
}
.graph .key.vol { color: var(--vol); }
.graph .key.pitch { color: var(--pitch); }
.graph .key.vol::before { background: var(--vol); }
.graph .key.pitch::before { background: var(--pitch); }
#browGraph {
  width: 100%;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.controls label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}
.controls label.check input { accent-color: var(--pitch); width: 16px; height: 16px; margin: 0; }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tabs [role="tab"] {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 22px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.8rem;
}
.tabs [role="tab"][aria-selected="true"] {
  background: var(--text);
  color: var(--bg);
}

.tab-panel {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.tab-panel[hidden] { display: none; }

/* Smaller camera while patching, so the board has room. */
body[data-tab="patch"] main { max-width: 520px; }
body[data-tab="patch"] .stage { aspect-ratio: 4 / 3; }

/* ---------- patch board ---------- */

.patch-help {
  margin: 0;
  max-width: 720px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
  text-align: center;
}
.patch-help b { color: var(--text); font-weight: 500; }

.patch-note {
  margin: 0;
  max-width: 720px;
  padding: 10px 14px;
  border: 1px solid var(--wire);
  border-radius: 10px;
  background: rgba(185, 166, 255, 0.08);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
}
.patch-note b { color: var(--wire); font-weight: 500; }

.board-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(circle, rgba(141, 132, 150, 0.18) 1px, transparent 1.5px) 0 0 / 22px 22px,
    #121016;
}
.board { position: relative; min-height: 200px; }

.wires { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.wire {
  fill: none;
  stroke: var(--wire);
  stroke-width: 2px;
  stroke-linecap: round;
  opacity: 0.85;
  filter: drop-shadow(0 0 4px rgba(185, 166, 255, 0.5));
}
.wire.temp { stroke-dasharray: 6 6; opacity: 1; }

.node {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--display);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.node.in { width: 190px; }
.node.out { width: 250px; }
.node.linked { border-color: rgba(185, 166, 255, 0.45); }
.node.drop { border-color: var(--wire); box-shadow: 0 0 0 2px var(--wire); }
.node.dragging { z-index: 2; opacity: 0.92; }

.node header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  cursor: grab;
  touch-action: none; /* dragging a box shouldn't scroll the page */
  user-select: none;
  -webkit-user-select: none;
}
.node.in header { flex-direction: column; align-items: flex-start; gap: 1px; }
.node header b { font-weight: 500; font-size: 0.92rem; }
.node header small, .node .hint { color: var(--muted); font-size: 0.7rem; }
.node header output { font-family: var(--mono); font-size: 0.8rem; color: var(--wire); }
.node.dragging header { cursor: grabbing; }

.node .bar { height: 5px; border-radius: 999px; background: #0b0a0e; overflow: hidden; }
.node .bar i { display: block; height: 100%; width: 0; background: var(--muted); border-radius: 999px; }
.node.in.linked .bar i { background: var(--wire); }
.node.out .bar i { background: var(--text); }

.node .port {
  position: absolute;
  top: 16px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--wire);
  cursor: crosshair;
  touch-action: none;
}
.node .port::after { content: ""; position: absolute; inset: -10px; } /* bigger touch target */
.node.in .port { right: -9px; }
.node.out .port { left: -9px; }
.node.linked .port { background: var(--wire); }

.node .row { display: flex; gap: 8px; align-items: center; }
.node select { width: 100%; padding: 4px 10px; font-size: 0.82rem; }
.node .mapped select { padding: 3px 8px; font-size: 0.8rem; border-radius: 8px; }
/* Menus need the room: one per line, label beside it. */
.node .mapped.choices { flex-direction: column; align-items: stretch; gap: 4px; }
.node .mapped.choices label { flex-direction: row; align-items: center; gap: 8px; }
.node .mapped.choices label span { width: 2.4em; }
.node .mapped.choices select { flex: 1; }
.node .mapped.choices label.flip { padding-top: 0; }
.node label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  font-size: 0.66rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.node label.flip { flex: 0 0 auto; flex-direction: row; align-items: center; gap: 4px; padding-top: 10px; }
.node input[type="range"] { width: 100%; margin: 0; accent-color: var(--wire); }
.node input[type="checkbox"] { margin: 0; accent-color: var(--wire); }
.node.out:not(.linked) .mapped { display: none; }
.node.out.linked .manual-row { display: none; }

.patch-actions { display: flex; justify-content: center; }

/* Phones: narrower boxes so both columns fit on screen. */
@media (max-width: 600px) {
  .node { padding: 8px 9px; }
  .node.in { width: 116px; }
  .node.out { width: 188px; }
  .node header b { font-size: 0.82rem; }
  .node header small, .node .hint { font-size: 0.62rem; }
  .node.out .hint { display: none; }
  .node label.flip { font-size: 0.6rem; }
  .board-scroll { margin: 0 -8px; width: calc(100% + 16px); }
}
