/* Synth Playground — Virtual Eurorack */

/* Import project design system */
@import url('../style.css');

/* === Layout === */

.playground-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg, #fafafa);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* --- Header --- */

.playground-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #ffffff);
  gap: 12px;
  flex-shrink: 0;
}

.playground-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text, #1a1a1a);
  margin: 0;
}

.playground-header .btn {
  font-size: 0.75rem;
  padding: 4px 10px;
}

.preset-bar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.preset-bar .btn {
  font-size: 0.6875rem;
  padding: 3px 8px;
}

/* --- Main area: side panel + rack --- */

.playground-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Side Panel --- */

.side-panel {
  width: 180px;
  min-width: 180px;
  border-right: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #ffffff);
  overflow-y: auto;
  flex-shrink: 0;
}

.side-panel.collapsed {
  width: 36px;
  min-width: 36px;
}

.side-panel.collapsed .panel-content {
  display: none;
}

.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
  font-size: 0.75rem;
}

.panel-toggle:hover {
  background: var(--bg, #fafafa);
}

.panel-category {
  padding: 4px 12px;
}

.panel-category-title {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary, #6b7280);
  margin: 8px 0 4px;
}

.panel-module-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: grab;
  font-size: 0.75rem;
  color: var(--text, #1a1a1a);
  user-select: none;
}

.panel-module-item:hover {
  background: var(--bg, #fafafa);
}

.panel-module-item:active {
  cursor: grabbing;
}

.panel-module-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.panel-module-dot.audio { background: #6b7280; }
.panel-module-dot.cv { background: #2563eb; }
.panel-module-dot.source { background: #22c55e; }
.panel-module-dot.processor { background: #6b7280; }
.panel-module-dot.modulator { background: #2563eb; }
.panel-module-dot.sequencer { background: #f59e0b; }
.panel-module-dot.utility { background: #8b5cf6; }

/* --- Rack Area --- */

.rack-container {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
}

.rack-container:active {
  cursor: grabbing;
}

.rack-grid {
  position: relative;
  min-height: 100%;
}

/* --- Cable Canvas --- */

.cable-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 10;
}

/* === Module Faceplate === */

.rack-module {
  position: absolute;
  background: var(--surface, #ffffff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
  user-select: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.rack-module:hover {
  box-shadow: 0 2px 6px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
}

.rack-module.selected {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.rack-module.limiter-active {
  border-color: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

/* Module name label */
.module-name {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary, #6b7280);
  text-align: center;
  padding: 6px 4px 3px;
  cursor: grab;
  flex-shrink: 0;
}

/* Port containers */
.module-ports {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
}

.module-ports-in {
  left: -6px;
}

.module-ports-out {
  right: -6px;
}

/* Port jack */
.port-jack {
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 2px 0;
}

.module-ports-in .port-jack {
  flex-direction: row;
}

.module-ports-out .port-jack {
  flex-direction: row-reverse;
}

.port-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--port-color, #6b7280);
  background: var(--surface, #ffffff);
  flex-shrink: 0;
  transition: background 0.1s;
}

.port-jack:hover .port-dot {
  background: var(--port-color, #6b7280);
}

.port-jack.connected .port-dot {
  background: var(--port-color, #6b7280);
}

.port-label {
  font-size: 0.5625rem;
  font-weight: 600;
  font-family: ui-monospace, 'SF Mono', monospace;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════
   FACEPLATE DESIGN LANGUAGE — All modules are 1HP (160px wide)

   Every module follows this vertical stack:
     1. Name label (drag handle, provided by module-base.js)
     2. Controls: buttons (2×2 grid or row) → sliders → readouts
     3. Display canvas (40px, anchored to bottom)

   Port jacks sit on left (inputs) and right (outputs) edges.

   Manual controls (sliders, buttons) set a base value.
   CV inputs ADD to that base value via Web Audio connect(AudioParam).
   This means: slider sets the center, CV modulates around it.
   Example: VCF cutoff slider at 1000 Hz + LFO depth ±500 Hz = sweep 500-1500 Hz.
   ═══════════════════════════════════════════════════════════════════ */

/* Faceplate content area */
.faceplate-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 2px 12px 4px;  /* 12px horizontal padding — labels need breathing room from edges */
  min-height: 0;
  overflow: hidden;
}

/* --- Canvas displays --- */

/* Standard scope canvas (2HP modules) */
.module-canvas {
  width: 100%;
  height: 48px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: auto; /* push to bottom of faceplate */
}

/* Tall meter for 1HP modules (vertical bar) */
.module-meter {
  width: 24px;
  flex: 1;
  min-height: 40px;
  max-height: 90px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* --- Readouts --- */

.module-readout {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 0.625rem;
  color: var(--text-secondary, #6b7280);
  text-align: center;
  line-height: 1.2;
}

.module-readout-lg {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text, #1a1a1a);
  text-align: center;
  line-height: 1.2;
}

/* --- Buttons (waveform/type select) --- */

/* Horizontal row (3 items: LP HP BP) */
.module-btn-row {
  display: flex;
  gap: 2px;
  justify-content: center;
}

/* 2×2 grid (4 items: SIN SAW SQR TRI) */
.module-btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 100%;
}

.module-btn {
  font-size: 0.5625rem;
  font-family: ui-monospace, 'SF Mono', monospace;
  padding: 3px 6px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 3px;
  background: var(--surface, #ffffff);
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  line-height: 1;
}

.module-btn:hover {
  background: var(--bg, #fafafa);
}

.module-btn.active {
  background: var(--accent, #2563eb);
  color: white;
  border-color: var(--accent, #2563eb);
}

/* --- Slider rows (label : range : value) --- */

.module-slider-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 0 2px;
}

.module-slider-row label {
  font-size: 0.5625rem;
  font-family: ui-monospace, 'SF Mono', monospace;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
  min-width: 32px;
}

.module-slider-row input[type="range"] {
  flex: 1;
  height: 16px;
  accent-color: var(--accent, #2563eb);
  min-width: 0;
}

.module-slider-row .module-readout {
  min-width: 36px;
  text-align: right;
  font-size: 0.5rem;
}

/* --- ADSR compact slider columns --- */

.module-adsr-row {
  display: flex;
  gap: 0;
  width: 100%;
  padding: 0 2px;
  box-sizing: border-box;
}

.module-adsr-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.module-adsr-col label {
  font-size: 0.5rem;
  font-family: ui-monospace, 'SF Mono', monospace;
  color: var(--text-secondary, #6b7280);
  line-height: 1;
}

.module-adsr-col input[type="range"] {
  width: 100%;
  height: 16px;
  accent-color: var(--accent, #2563eb);
}

.module-adsr-col .module-readout {
  font-size: 0.375rem;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* --- Gate / status indicators --- */

.module-gate-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #1a1a2e;
  transition: background 0.05s;
  flex-shrink: 0;
}

.module-gate-dot.active {
  background: #22c55e;
}

/* --- Limiter indicator --- */

.limiter-indicator {
  font-size: 0.5rem;
  font-weight: 700;
  color: #ef4444;
  text-align: center;
  animation: limiter-blink 1s step-end infinite;
}

@keyframes limiter-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.limiter-message {
  font-size: 0.375rem;
  color: var(--text-secondary, #6b7280);
  text-align: center;
  line-height: 1.2;
  padding: 0 2px;
}

/* --- Compact vertical slider (label above, slider, readout below) --- */

.module-vslider {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  gap: 0;
  padding: 0 2px;
  box-sizing: border-box;
}

.module-vslider-label {
  font-size: 0.5rem;
  font-family: ui-monospace, 'SF Mono', monospace;
  color: var(--text-secondary, #6b7280);
  text-align: center;
  line-height: 1;
  margin-bottom: 1px;
}

.module-hslider {
  width: 100%;
  height: 16px;
  accent-color: var(--accent, #2563eb);
  display: block;
  box-sizing: border-box;
}

/* Readout below slider — never overlaps */
.module-vslider .module-readout {
  text-align: center;
  font-size: 0.4375rem;
  line-height: 1;
  margin-top: 1px;
}

/* --- Help Overlay --- */

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.help-content {
  background: var(--surface, #ffffff);
  border-radius: 12px;
  padding: 24px;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.help-content h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.help-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.help-content td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

.help-content kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  background: var(--bg, #fafafa);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 3px;
  padding: 1px 5px;
}

/* --- Debug Panel --- */

.debug-panel {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17,17,17,0.9);
  color: #a5f3fc;
  font-family: ui-monospace, monospace;
  font-size: 0.6875rem;
  padding: 4px 12px;
  border-radius: 6px;
  z-index: 999;
  white-space: nowrap;
}

/* --- Port Scope (inline mini oscilloscope on hover) --- */

.port-scope {
  position: absolute;
  z-index: 20;
  background: rgba(26, 26, 46, 0.95);
  border: 1px solid rgba(96, 165, 250, 0.3);
  border-radius: 4px;
  padding: 2px;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.port-scope canvas {
  display: block;
  border-radius: 2px;
}

/* --- Indicator rows (gate dot + label, used by Clock Div/Mul, Drum) --- */

.module-indicator-row {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100%;
}

.module-indicator-row .module-readout {
  min-width: 18px;
}

.module-indicator-row .module-hslider {
  flex: 1;
  min-width: 0;
}

/* --- Noise color indicator --- */
.module-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin: 4px auto;
  flex-shrink: 0;
}

/* --- Transport Bar --- */

.transport-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  border-top: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #ffffff);
  flex-shrink: 0;
  font-size: 0.75rem;
}

.transport-bar .btn {
  font-size: 0.75rem;
  padding: 4px 10px;
}

.transport-bar .btn.is-muted {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}

/* --- Keyboard Area --- */

.keyboard-area {
  border-top: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #ffffff);
  flex-shrink: 0;
  overflow: hidden;
  transition: max-height 0.2s;
}

.keyboard-area.collapsed {
  max-height: 0;
  border-top: none;
}

/* --- Empty state --- */

.rack-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-secondary, #6b7280);
  pointer-events: none;
  z-index: 1;
}

.rack-empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 8px;
}

.rack-empty-state p {
  font-size: 0.8125rem;
  margin: 0;
}

/* --- Drag-from-palette ghost --- */

.palette-drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.7;
  background: var(--surface, #ffffff);
  border: 1px solid var(--accent, #2563eb);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent, #2563eb);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* --- Grid dot overlay --- */
.grid-dots {
  opacity: 0.4;
}

/* --- Drop zone feedback --- */
.drop-highlight {
  position: absolute;
  background: rgba(37, 99, 235, 0.08);
  border: 2px dashed rgba(37, 99, 235, 0.3);
  border-radius: 8px;
  pointer-events: none;
  z-index: 4;
  transition: all 0.1s;
}

.drop-highlight.invalid {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}
