:root {
  --bg: #121418;
  --panel: #21242b;
  --panel-2: #2b2f37;
  --line: #3a3f49;
  --ink: #efe8d8;
  --muted: #9d9686;

  --c-mod: #e9b23c;
  --c-osc: #e5573f;
  --c-mix: #f0d35e;
  --c-util: #9bb8d6;
  --c-filt: #45a6d6;
  --c-env: #6cc27d;
  --c-arp: #b98ad8;
  --c-out: #ef8d3c;

  --knob: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.synth {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1500px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 10px; }

.logo {
  font-family: 'Archivo Black', system-ui, sans-serif;
  font-size: 28px;
  line-height: 1;
  background: linear-gradient(90deg, var(--c-osc), var(--c-mod) 35%, var(--c-env) 65%, var(--c-filt));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 12px;
}

.top-controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.hint { color: var(--c-mod); font-size: 14px; letter-spacing: 0.04em; margin-right: 6px; }

button, select {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 38px;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button:not(:disabled):active { transform: translateY(1px); }
button.on { border-color: var(--c-env); }
select { max-width: 180px; }


/* ---- panel ---- */

.panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
  justify-content: center;
  touch-action: pan-y;
}

.section {
  --hue: var(--c-mod);
  background: var(--panel);
  border-radius: 10px;
  border-top: 4px solid var(--hue);
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 2px 10px rgba(0, 0, 0, 0.35);
}
.hue-mod { --hue: var(--c-mod); }
.hue-osc { --hue: var(--c-osc); }
.hue-mix { --hue: var(--c-mix); }
.hue-util { --hue: var(--c-util); }
.hue-filt { --hue: var(--c-filt); }
.hue-env { --hue: var(--c-env); }
.hue-arp { --hue: var(--c-arp); }
.hue-out { --hue: var(--c-out); }

.section h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--hue);
  display: flex;
  align-items: center;
  gap: 8px;
}

.led.indicator {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--hue);
  box-shadow: 0 0 8px var(--hue);
  opacity: 0.15;
}

.controls { display: flex; gap: 8px 10px; align-items: flex-start; flex-wrap: wrap; }

.control { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 66px; }
.control .label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.control .value {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-height: 1.2em;
}
.control.active .value { color: var(--hue); }

/* knob */
.knob.big { --knob: 80px; }
.knob-body {
  position: relative;
  width: var(--knob);
  height: var(--knob);
  border-radius: 50%;
  touch-action: none;
  cursor: ns-resize;
  outline: none;
}
.knob-body:focus-visible { box-shadow: 0 0 0 2px var(--hue); }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; }
.ring path { fill: none; stroke-width: 6; stroke-linecap: round; }
.ring .track { stroke: #393d46; }
.ring .fill { stroke: var(--hue); }
.cap {
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4b4e56, #18191c 58%, #0b0b0d);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.18);
}
.pointer {
  position: absolute;
  left: 50%;
  top: 7%;
  width: 3px;
  height: 34%;
  margin-left: -1.5px;
  border-radius: 2px;
  background: #f4efe2;
}

/* switch */
.switch .options { display: flex; flex-direction: column; gap: 1px; }
.opt {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 2px 6px;
  min-height: 24px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 5px;
  touch-action: manipulation;
}
.opt .led {
  width: 8px; height: 8px; border-radius: 50%;
  background: #34312d;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6);
}
.opt.on { color: var(--ink); }
.opt.on .led { background: var(--hue); box-shadow: 0 0 6px var(--hue); }

.scope {
  width: 170px;
  height: 84px;
  background: #0b0d0f;
  border-radius: 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
  color: var(--c-out);
  align-self: center;
}

/* ---- performance area ---- */

.perform {
  display: flex;
  gap: 10px;
  padding: 8px 12px 12px;
  height: clamp(140px, 32vh, 240px);
  flex-shrink: 0;
  background: linear-gradient(#1a1c21, #101114);
  border-top: 1px solid #2a2e36;
}

.left { display: flex; flex-direction: column; gap: 6px; }
.oct { display: flex; align-items: center; gap: 4px; }
.oct button { min-width: 34px; padding: 4px 8px; font-size: 16px; }
.oct-label { font-size: 12px; letter-spacing: 0.08em; color: var(--muted); white-space: nowrap; }
.oct-label b { color: var(--ink); display: inline-block; min-width: 1.4em; text-align: center; }

.wheels { flex: 1; min-height: 0; display: flex; gap: 10px; justify-content: center; }
.wheel { width: 38px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wlabel { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.wheel-slot {
  --pos: 0;
  position: relative;
  flex: 1;
  width: 100%;
  border-radius: 8px;
  background: repeating-linear-gradient(#0a0b0d 0 5px, #15171a 5px 7px);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.9);
  touch-action: none;
  cursor: ns-resize;
}
.wheel-center {
  display: none;
  position: absolute; left: 4px; right: 4px; top: 50%; height: 1px;
  background: rgba(255, 255, 255, 0.2);
}
.wheel.spring .wheel-center { display: block; }
.wheel-thumb {
  position: absolute;
  left: 3px;
  right: 3px;
  height: 22px;
  bottom: calc(var(--pos) * (100% - 22px));
  border-radius: 5px;
  background: linear-gradient(#61656e, #2b2d32);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.wheel-thumb.returning { transition: bottom 0.15s ease-out; }

.keyboard {
  flex: 1;
  min-width: 0;
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  touch-action: none;
}
.key { position: absolute; top: 0; }
.key.white {
  height: 100%;
  background: linear-gradient(#f4efe4, #e2dacb);
  border: 1px solid #7d786d;
  border-top: none;
  border-radius: 0 0 5px 5px;
}
.key.white.down { background: linear-gradient(#d9d1bf, #c8bfab); box-shadow: inset 0 -5px 0 var(--c-osc); }
.key.black {
  z-index: 2;
  height: 60%;
  transform: translateX(-50%);
  background: linear-gradient(#2c2c30, #0b0b0c);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.55), inset 0 -4px 0 #26262a;
}
.key.black.down { background: linear-gradient(#3c3c42, #1b1b1e); box-shadow: inset 0 -4px 0 var(--c-osc); }
.klabel {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  text-align: center;
  font-size: 11px;
  color: #8a8478;
  pointer-events: none;
}

@media (pointer: coarse) {
  .opt { min-height: 30px; padding: 3px 8px; }
}

@media (max-width: 600px) {
  :root { --knob: 56px; }
  .knob.big { --knob: 68px; }
  .sub { display: none; }
  .logo { font-size: 24px; }
  .topbar { padding: 8px 12px; }
  .panel { padding: 4px 8px 12px; gap: 8px; }
  .section { flex: 1 1 100%; }
  .perform { padding: 6px 8px 8px; gap: 8px; }
  .wheel { width: 30px; }
}

/* ---- patch bay ---- */

.hue-patch { --hue: #d9d2c0; }
.patchbay { flex: 1 1 100%; }
.bay { position: relative; }
.pgroups { display: flex; flex-wrap: wrap; gap: 10px 14px; justify-content: center; }
.pgroup { border-left: 3px solid var(--hue); padding: 0 4px 0 8px; display: flex; flex-direction: column; gap: 4px; }
.ptitle {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--hue);
}
.pjacks { display: flex; gap: 4px; }

.jack {
  width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  border-radius: 8px;
  touch-action: none;
  cursor: grab;
}
.socket {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, #050505 0 28%, #8d9097 31% 40%, #3b3e45 43% 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: box-shadow 0.1s;
}
.jlabel {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  padding: 0 4px;
  border-radius: 3px;
  color: var(--ink);
}
/* outputs get inverted labels, as on the hardware */
.jack.out .jlabel { background: var(--ink); color: #15171c; }

.bay.want-in .jack.in .socket,
.bay.want-out .jack.out .socket { box-shadow: 0 0 0 2px var(--hue), 0 0 10px var(--hue); }
.jack.hover { background: rgba(255, 255, 255, 0.08); }

.cables {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}
.cable { fill: none; stroke-width: 5; stroke-linecap: round; opacity: 0.92; }
.cable-shadow { fill: none; stroke: rgba(0, 0, 0, 0.45); stroke-width: 8; stroke-linecap: round; transform: translateY(3px); }
.plug { stroke: rgba(0, 0, 0, 0.5); stroke-width: 2; }
.live .cable { opacity: 0.75; }

@media (max-width: 600px) {
  .jack { width: 44px; }
}

/* ---- SEQ-1 sequencer device ---- */

.seqbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 8px 12px;
  flex-shrink: 0;
  background: linear-gradient(#2a2d34, #202228);
  border-top: 1px solid #3a3f49;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.seq-title {
  font-family: 'Archivo Black', system-ui, sans-serif;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--c-mix);
}
.seq-play { width: 46px; display: inline-flex; align-items: center; justify-content: center; }
.seq-play .tri {
  width: 0; height: 0;
  border-left: 13px solid var(--c-env);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  margin-left: 3px;
}
.seq-play.on { border-color: var(--c-osc); }
.seq-play.on .tri { width: 12px; height: 12px; border: none; margin: 0; background: var(--c-osc); border-radius: 2px; }
.seq-demo { max-width: 170px; }
.seq-tempo { display: flex; align-items: center; gap: 4px; }
.seq-tempo button { min-width: 34px; padding: 4px 8px; font-size: 16px; touch-action: none; }
.seq-bpm {
  min-width: 3.4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--c-mix);
  background: #0c0d10;
  border-radius: 5px;
  padding: 6px 4px;
}
.seq-bpm::after { content: ' BPM'; font-size: 10px; color: var(--muted); font-weight: 600; }
.seq-sound { display: inline-flex; align-items: center; gap: 6px; }
.seq-sound .led { width: 8px; height: 8px; border-radius: 50%; background: #34312d; }
.seq-sound.on .led { background: var(--c-mix); box-shadow: 0 0 6px var(--c-mix); }
.seq-steps { flex: 1; min-width: 160px; display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.sled { width: 10px; height: 10px; border-radius: 2px; background: #15171b; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8); }
.sled.has { background: #3d3a2a; }
.sled.beat { outline: 1px solid #4a4e58; }
.sled.now { background: var(--c-mix); box-shadow: 0 0 8px var(--c-mix); }

.key.white.seq { background: linear-gradient(#f7eab7, #e8d78f); box-shadow: inset 0 -5px 0 var(--c-mix); }
.key.black.seq { background: linear-gradient(#5a5228, #2e2a14); box-shadow: inset 0 -4px 0 var(--c-mix); }

@media (max-width: 600px) {
  .seqbar { padding: 6px 8px; gap: 6px; }
  .seq-title { display: none; }
  .seq-demo { max-width: 130px; }
  .seq-steps { flex-basis: 100%; }
  .sled { width: 8px; height: 8px; }
}

button.icon { min-width: 40px; padding: 4px 8px; font-size: 20px; line-height: 1; }

/* compact header and SEQ-1 strip on phones */
@media (max-width: 600px) {
  .top-controls { gap: 5px; }
  .top-controls button, .top-controls select { padding: 4px 9px; min-height: 34px; font-size: 13px; }
  .top-controls select { max-width: 120px; }
  .hint { flex-basis: 100%; order: -1; font-size: 13px; }
  .seq-demo { max-width: 112px; }
  .seqbar button, .seqbar select { padding: 4px 8px; min-height: 34px; font-size: 13px; }
  .seq-tempo button { min-width: 30px; }
}
@media (max-width: 600px) {
  .seq-demo { max-width: 98px; }
  .seq-sound { padding: 4px 7px; gap: 4px; }
  .seq-play { width: 38px; }
}

/* ---- 3D view ---- */

.view3d { flex: 1; min-height: 0; position: relative; touch-action: none; }
.view3d canvas { display: block; position: absolute; inset: 0; }
.view-3d .panel,
.view-3d .seqbar,
.view-3d .perform { display: none; }
