:root {
  color-scheme: dark;
  --page: #070707;
  --ink: #f5f1e8;
  --muted: #a9a49a;
  --line: rgba(255, 255, 255, 0.16);
  --accent: #e33d33;
  --teal: #49d7c2;
  --amber: #ffbd5f;
  --blue: #7cb8ff;
  --rack-zoom: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.08), transparent 34rem),
    linear-gradient(180deg, #111 0%, var(--page) 54%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: linear-gradient(180deg, #f3f3f3 0%, #a7a7a7 100%);
  color: #101010;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 2.35rem;
  padding: 0.55rem 0.8rem;
  text-transform: uppercase;
}

button:active,
button.is-active {
  transform: translateY(1px);
  filter: brightness(0.85);
}

.primary-button {
  background: linear-gradient(180deg, #ff655b 0%, #ad1711 100%);
  color: white;
}

.app-shell {
  margin: 0 auto;
  max-width: none;
  padding: 18px clamp(10px, 2vw, 24px) 32px;
}

.topbar {
  align-items: center;
  background: rgba(12, 12, 12, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  margin-bottom: 14px;
  padding: 12px;
  position: sticky;
  top: 8px;
  z-index: 20;
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
}

h1 {
  font-size: clamp(1.05rem, 1.8vw, 1.45rem);
  letter-spacing: 0;
  line-height: 1;
  margin: 0 0 0.35rem;
  text-transform: uppercase;
}

.topbar p {
  color: var(--muted);
  font-size: 0.83rem;
  margin: 0;
}

.transport,
.meters {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meters {
  justify-content: flex-end;
}

.meter {
  background: #050505;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
  width: 76px;
}

.meter span {
  background: linear-gradient(90deg, var(--teal), var(--amber), var(--accent));
  display: block;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
}

.midi-chip {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  min-width: 4.7rem;
  padding: 0.34rem 0.65rem;
  text-align: center;
}

.midi-chip.is-live {
  border-color: rgba(73, 215, 194, 0.65);
  color: var(--teal);
}

.drift-control {
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: var(--ink);
  display: flex;
  gap: 7px;
  min-height: 2.2rem;
  padding: 0.25rem 0.62rem;
}

.drift-control span {
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.drift-control input {
  accent-color: var(--amber);
  cursor: pointer;
  width: 88px;
}

.zoom-controls {
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  display: flex;
  gap: 4px;
  padding: 3px;
}

.zoom-controls button {
  border-radius: 999px;
  font-size: 0.75rem;
  min-height: 1.85rem;
  min-width: 1.85rem;
  padding: 0.25rem 0.48rem;
}

#zoomReadout {
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 900;
  min-width: 3rem;
  text-align: center;
}

.help-dialog {
  background: transparent;
  border: 0;
  color: var(--ink);
  max-width: min(760px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.help-card {
  background:
    linear-gradient(180deg, rgba(32, 32, 32, 0.98), rgba(10, 10, 10, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.68);
  max-height: min(82vh, 720px);
  overflow: auto;
  padding: 18px;
}

.help-header {
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.help-header h2 {
  font-size: 1.2rem;
  line-height: 1.1;
  margin: 0;
  text-transform: uppercase;
}

.icon-button {
  align-items: center;
  border-radius: 50%;
  display: inline-flex;
  height: 2.25rem;
  justify-content: center;
  min-height: 0;
  padding: 0;
  width: 2.25rem;
}

.help-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.help-grid section {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 10px;
}

.help-grid h3 {
  color: var(--amber);
  font-size: 0.86rem;
  letter-spacing: 0;
  margin: 0 0 0.45rem;
  text-transform: uppercase;
}

.help-grid p {
  color: #ddd7cc;
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 0.55rem;
}

.rack {
  display: grid;
  gap: 18px;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 8px;
  position: relative;
}

.panel {
  border-radius: 12px;
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.48),
    0 1px 0 rgba(255, 255, 255, 0.12) inset;
  line-height: 0;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
  user-select: none;
  width: 100%;
}

.synth-panel {
  max-width: none;
  width: calc(940px * var(--rack-zoom));
}

.seq-panel {
  max-width: none;
  width: calc(1160px * var(--rack-zoom));
}

.panel img {
  display: block;
  height: auto;
  pointer-events: none;
  width: 100%;
}

.overlay,
.cable-layer {
  inset: 0;
  position: absolute;
}

.cable-layer {
  overflow: visible;
  pointer-events: none;
  z-index: 10;
}

.cable-path {
  cursor: pointer;
  filter: drop-shadow(0 7px 7px rgba(0, 0, 0, 0.55));
  pointer-events: stroke;
  stroke-linecap: round;
}

.cable-hit {
  cursor: pointer;
  opacity: 0;
  pointer-events: stroke;
  stroke-width: 18;
}

.cable-preview {
  opacity: 0.72;
  stroke-dasharray: 12 10;
}

.cable-end {
  cursor: grab;
  pointer-events: all;
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 2;
}

.cable-end:active {
  cursor: grabbing;
}

.hotspot,
.jack,
.led,
.panel-button,
.step-button,
.toggle-hit {
  position: absolute;
  touch-action: none;
}

.hotspot {
  border-radius: 50%;
  cursor: ns-resize;
}

.hotspot::before {
  border: 2px solid rgba(255, 255, 255, 0.74);
  border-radius: 999px;
  box-shadow: 0 0 14px rgba(124, 184, 255, 0.28);
  content: "";
  height: 42%;
  left: 50%;
  opacity: 0.92;
  position: absolute;
  top: 8%;
  transform: translateX(-50%);
  width: 7%;
}

.hotspot::after {
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  content: "";
  inset: -8%;
  opacity: 0;
  position: absolute;
  transition: opacity 140ms ease;
}

.hotspot:hover::after,
.hotspot.is-dragging::after {
  opacity: 1;
}

.toggle-hit {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  cursor: pointer;
  min-height: 0;
  padding: 0;
}

.toggle-hit.is-active {
  box-shadow:
    0 0 0 2px rgba(73, 215, 194, 0.42),
    0 0 22px rgba(73, 215, 194, 0.26);
  transform: none;
}

.switch-hit {
  border-color: rgba(255, 255, 255, 0.22);
  border-radius: 2px;
  overflow: hidden;
}

.switch-cap {
  background: linear-gradient(180deg, #e9e9e9 0%, #6f6f6f 48%, #171717 100%);
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 2px;
  box-shadow:
    0 5px 10px rgba(0, 0, 0, 0.65),
    inset 0 1px rgba(255, 255, 255, 0.55);
  display: block;
  height: 42%;
  left: 14%;
  position: absolute;
  top: 50%;
  transform: translateY(8%);
  transition: transform 120ms ease, top 120ms ease, filter 120ms ease;
  width: 72%;
}

.switch-hit.is-active .switch-cap {
  filter: brightness(1.1);
  top: 8%;
  transform: translateY(0);
}

.panel-button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  min-height: 0;
  padding: 0;
}

.panel-button:hover,
.panel-button:focus-visible {
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.34),
    0 0 22px rgba(255, 189, 95, 0.36);
  outline: none;
}

.panel-button:active,
.step-button:active {
  transform: none;
}

.jack {
  background: transparent;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  cursor: crosshair;
  min-height: 0;
  padding: 0;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.jack::before {
  background: rgba(8, 8, 8, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  content: "";
  inset: 24%;
  position: absolute;
}

.jack.input {
  box-shadow: 0 0 0 1px rgba(255, 189, 95, 0.34);
}

.jack.output {
  box-shadow: 0 0 0 1px rgba(73, 215, 194, 0.34);
}

.jack.is-pending,
.jack:hover {
  border-color: rgba(255, 255, 255, 0.92);
  box-shadow:
    0 0 0 3px rgba(124, 184, 255, 0.28),
    0 0 20px rgba(124, 184, 255, 0.45);
}

.jack:active {
  transform: translate(-50%, -50%);
}

.led {
  background: #270604;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  box-shadow: inset 0 0 5px #080101;
  transform: translate(-50%, -50%);
}

.led.is-on {
  background: #f33227;
  box-shadow:
    0 0 14px rgba(255, 63, 48, 0.94),
    inset 0 0 5px rgba(255, 232, 204, 0.65);
}

.step-button {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: rgba(20, 20, 20, 0.92);
  cursor: ns-resize;
  display: flex;
  font-size: clamp(9px, 1.2vw, 13px);
  font-weight: 900;
  justify-content: center;
  line-height: 1;
  min-height: 0;
  padding: 0;
  text-shadow: 0 1px rgba(255, 255, 255, 0.2);
}

.step-button::after {
  background: rgba(73, 215, 194, 0.92);
  border-radius: 999px;
  bottom: -13%;
  content: "";
  height: 8%;
  left: 15%;
  opacity: 0;
  position: absolute;
  transform: scaleX(var(--amount, 0.5));
  transform-origin: left center;
  width: 70%;
}

.step-button.is-muted {
  opacity: 0.64;
}

.step-button.is-current {
  box-shadow:
    0 0 0 2px rgba(255, 189, 95, 0.48),
    0 0 24px rgba(255, 189, 95, 0.35);
}

.step-button.is-current::after,
.step-button:hover::after {
  opacity: 1;
}

.ghost-readout {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
  left: 50%;
  line-height: 1;
  padding: 0.2rem 0.36rem;
  pointer-events: none;
  position: absolute;
  top: -1.4rem;
  transform: translateX(-50%);
}

@media (max-width: 760px) {
  .app-shell {
    padding: 8px 6px 22px;
  }

  .topbar {
    grid-template-columns: 1fr;
    position: static;
  }

  button {
    min-height: 2.15rem;
    padding: 0.48rem 0.62rem;
  }

  .transport,
  .meters {
    justify-content: flex-start;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }

  .rack {
    gap: 10px;
  }
}
