@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500&display=swap');

:root {
  --bg: #0a0a0f;
  --card-bg: #12121a;
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #e0e0e0;
  --text-dim: #666;
  --osc-color: #00e5ff;
  --filter-color: #ff00e5;
  --effect-color: #ffe500;
  --mod-color: #00ff88;
  --env-color: #ff8800;
  --route-color: #888888;
}

*, *::before, *::after {
  box-sizing: border-box;
}

/* ── START OVERLAY ──────────────────────────────────────────────────────── */

#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #0a0a0f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.overlay-content {
  text-align: center;
}

.glitch-title {
  font-size: 48px;
  font-weight: 300;
  letter-spacing: 16px;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 20px rgba(0, 229, 255, 0.8), 0 0 60px rgba(0, 229, 255, 0.3),
    -2px 0 #ff00e5, 2px 0 #00e5ff;
  margin: 0 0 16px 0;
  animation: glitch 3s infinite;
}

@keyframes glitch {
  0%, 90%, 100% { text-shadow: 0 0 20px rgba(0,229,255,0.8), -2px 0 #ff00e5, 2px 0 #00e5ff; }
  92% { text-shadow: 0 0 20px rgba(0,229,255,0.8), -4px -1px #ff00e5, 4px 1px #00e5ff; }
  94% { text-shadow: 0 0 20px rgba(0,229,255,0.8), 3px 2px #ff00e5, -3px -2px #00e5ff; }
  96% { text-shadow: 0 0 20px rgba(0,229,255,0.8), -2px 0 #ff00e5, 2px 0 #00e5ff; }
}

.overlay-content p {
  font-size: 13px;
  color: #888;
  margin: 4px 0;
  letter-spacing: 3px;
}

.overlay-content .dim {
  color: #555;
  font-size: 11px;
}

.start-prompt {
  display: inline-block;
  margin-top: 24px;
  font-size: 12px;
  color: #00e5ff;
  letter-spacing: 4px;
  text-transform: uppercase;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  background-color: var(--bg);
  overflow: hidden;
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  color: var(--text);
}

/* ── WEBGL BACKGROUND CANVAS ────────────────────────────────────────────── */

#gl-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  display: block;
}

/* ── TOOLBAR ─────────────────────────────────────────────────────────────── */

#toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: rgba(10, 10, 16, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.toolbar-group {
  display: flex;
  gap: 4px;
  margin-left: 12px;
  flex: 1;
}

.vol-label {
  font-size: 8px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

#toolbar h1 {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
  white-space: nowrap;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 4px;
}

.toolbar-btn {
  height: 26px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(200, 200, 200, 0.7);
  padding: 0 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-radius: 2px;
  transition: all 0.2s;
  white-space: nowrap;
}

.toolbar-btn:hover {
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

.toolbar-btn.active {
  border-color: rgba(0, 229, 255, 0.5);
  color: #00e5ff;
  box-shadow: 0 0 6px rgba(0, 229, 255, 0.2);
}

#toolbar select {
  height: 32px;
  background: #12121a;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #cccccc;
  padding: 0 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 1px;
  border-radius: 2px;
  transition: border-color 0.2s, color 0.2s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

#toolbar select:hover {
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
}

#toolbar select:focus {
  border-color: rgba(255, 255, 255, 0.4);
}

/* ── MODULE CONTAINER ────────────────────────────────────────────────────── */

#module-container {
  position: absolute;
  top: 40px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: transparent;
  z-index: 1;
}

/* ── MODULE CARDS ────────────────────────────────────────────────────────── */

.module-card {
  position: absolute;
  width: 160px;
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  border-radius: 3px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6), 0 0 0 0 transparent;
  cursor: grab;
  user-select: none;
  z-index: 10;
  transition: box-shadow 0.2s;
}

.module-card:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6), 0 0 16px rgba(255, 255, 255, 0.03);
  border-color: rgba(255,255,255,0.15);
}

.module-card.dragging {
  cursor: grabbing;
  z-index: 100;
  opacity: 0.9;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
}

/* ── MODULE HEADER ───────────────────────────────────────────────────────── */

.module-header {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 2px 2px 0 0;
}

.module-header .module-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-randomize {
  position: absolute;
  top: 2px;
  right: 20px;
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  padding: 3px;
  transition: color 0.15s;
  font-family: inherit;
}

.module-randomize:hover {
  color: #ffffff;
}

.module-header .close-btn {
  width: 14px;
  height: 14px;
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}

.module-header .close-btn:hover {
  color: #ff4444;
}

/* ── MODULE BODY ─────────────────────────────────────────────────────────── */

.module-body {
  padding: 8px;
}

/* ── KNOBS ───────────────────────────────────────────────────────────────── */

.knob-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.knob-container {
  width: 44px;
  text-align: center;
}

.knob {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #1a1a24;
  border: 2px solid rgba(255, 255, 255, 0.1);
  margin: 0 auto;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s;
}

.knob:hover {
  border-color: rgba(255, 255, 255, 0.25);
}

.knob:active {
  border-color: rgba(255, 255, 255, 0.4);
}

.knob-indicator {
  position: absolute;
  width: 2px;
  height: 9px;
  background: currentColor;
  top: 3px;
  left: 50%;
  transform-origin: bottom center;
  margin-left: -1px;
  border-radius: 1px;
}

.knob-label {
  font-size: 7px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knob-value {
  font-size: 7px;
  color: var(--text);
  margin-top: 1px;
}

.module-viz {
  display: block;
  width: 100%;
  height: 32px;
  margin-top: 4px;
  border-radius: 2px;
  background: rgba(10, 10, 15, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* ── PORTS ───────────────────────────────────────────────────────────────── */

.port {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid;
  background: #0a0a0f;
  cursor: crosshair;
  position: absolute;
  transition: transform 0.2s, box-shadow 0.2s;
}

.port:hover {
  transform: scale(1.3);
}

.port.input {
  left: -5px;
}

.port.output {
  right: -5px;
}

.port-label {
  position: absolute;
  font-size: 6px;
  color: var(--text-dim);
  white-space: nowrap;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.port.input .port-label {
  left: 16px;
}

.port.output .port-label {
  right: 16px;
  text-align: right;
}

.ports-column {
  position: absolute;
  top: 28px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ports-column.inputs {
  left: 0;
}

.ports-column.outputs {
  right: 0;
}

.port-slot {
  position: relative;
  height: 12px;
  display: flex;
  align-items: center;
}

/* ── SVG OVERLAY ─────────────────────────────────────────────────────────── */

#svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#svg-overlay path {
  fill: none;
  stroke-width: 2;
  opacity: 0.6;
  pointer-events: stroke;
  cursor: pointer;
  stroke-dasharray: 8 4;
  animation: flowLine 1s linear infinite;
}

@keyframes flowLine {
  to { stroke-dashoffset: -12; }
}

#svg-overlay path:hover {
  opacity: 1;
  stroke-width: 3;
}

/* temp connection line during connecting */
#svg-overlay .temp-connection {
  stroke-dasharray: 6 3;
  animation: none;
  opacity: 0.5;
  pointer-events: none;
}

.master-volume {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  white-space: nowrap;
}

.master-volume input[type='range'] {
  width: 60px;
  accent-color: rgba(0, 229, 255, 0.5);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.master-volume input[type='range']:hover {
  opacity: 1;
}

/* ── ADD MODULE MENU ─────────────────────────────────────────────────────── */

#add-module-menu {
  position: absolute;
  background: #16161e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: none;
  max-height: 400px;
  overflow-y: auto;
  min-width: 180px;
}

#add-module-menu.visible {
  display: block;
}

.menu-category {
  padding: 4px 12px;
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 4px;
}

.menu-category:first-child {
  margin-top: 0;
}

.menu-item {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.05);
}
.menu-divider {
  padding: 4px 16px;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
  user-select: none;
}
.saved-patch {
  display: flex;
  align-items: center;
}
.patch-delete {
  padding: 0 6px;
  color: #666;
  font-size: 14px;
  cursor: pointer;
}
.patch-delete:hover {
  color: #f44;
}
.patch-name {
  position: fixed;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 4px;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 300;
  transition: opacity 1s ease;
}
.patch-name:empty {
  display: none;
}

/* ── SCROLLBARS ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: #0a0a0f;
}

::-webkit-scrollbar-thumb {
  background: #2a2a36;
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3a3a48;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #2a2a36 #0a0a0f;
}

/* ── EVOLUTION BUTTONS ───────────────────────────────────────────────────── */

.evo-btn.active {
  border-color: rgba(0, 255, 136, 0.5) !important;
  color: #00ff88 !important;
  box-shadow: 0 0 6px rgba(0,255,136,0.2) !important;
}

/* ── PRESETS / LOAD MENU ────────────────────────────────────────────────── */

#presets-menu {
  position: fixed;
  background: rgba(16, 16, 24, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  z-index: 300;
  max-height: 400px;
  overflow-y: auto;
  min-width: 200px;
}

/* ── TRANSFORM LAYER ─────────────────────────────────────────────────────── */

#transform-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}
