/* NISPS Workbench — Design B CSS */

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --elevated: #252525;
  --border: #222;
  --border-light: #333;
  --text: #e0e0e0;
  --text-dim: #888;
  --text-muted: #555;
  --accent-visual: #ff6a00;
  --accent-synth: #ff8c00;
  --accent: var(--accent-visual);
  --danger: #ff4444;
  --good: #ff8c00;
  --bad: #ff4444;
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 0.2s ease;
  /* Group accent colors */
  --group-motion: #00ccff;
  --group-color: #ff00cc;
  --group-particles: #ffcc00;
  --group-forces: #ff3366;
  --group-effects: #9b59b6;
  /* Synth group colors */
  --group-osc: #ff6b35;
  --group-shapers: #ff006e;
  --group-filters: #3a86ff;
  --group-comb: #06d6a0;
  --group-fx: #8338ec;
  --group-output: #ffd166;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body.synth-mode {
  --accent: var(--accent-synth);
}

/* === Layout === */
.workbench {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px;
  gap: 8px;
}

.wb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.wb-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wb-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid #333;
  background: var(--elevated);
  color: #666;
  font-size: 16px;
  text-decoration: none;
  transition: all var(--transition);
  flex-shrink: 0;
}
.wb-back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}

.wb-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.5px;
}

.wb-title-accent {
  color: var(--accent);
  font-weight: 400;
}

.wb-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wb-mode-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.wb-mode-badge.synth {
  background: var(--accent-synth);
}

.wb-help-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--elevated);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wb-help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === Grid === */
.wb-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 8px;
  flex: 1;
}

/* === Panel === */
.wb-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.wb-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}

.wb-panel-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

/* === Canvas Panel === */
.wb-canvas-panel {
  grid-column: 1;
  grid-row: 1;
  min-height: 300px;
}

.wb-canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 250px;
}

.wb-canvas-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#synth-vis-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}
#synth-vis-canvas.hidden {
  display: none !important;
}

/* Presets */
.presets {
  display: flex;
  gap: 4px;
}

.preset-pill {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: var(--elevated);
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.preset-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === Mapping Panel === */
.wb-mapping-panel {
  grid-column: 2;
  grid-row: 1;
}

.wb-mapping-panel.follow-active {
  border-color: var(--accent);
}

.wb-mapping-area {
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.wb-heatmap-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}

.wb-heatmap-wrap canvas {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  cursor: crosshair;
  touch-action: none;
  width: 100%;
  aspect-ratio: 1;
  max-width: 280px;
}

.wb-heatmap-label {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}

/* Follow toggle button */
.wb-follow-toggle-btn {
  font-size: 10px;
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}
.wb-follow-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.wb-follow-toggle-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

/* Follow badge */
.wb-follow-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  text-transform: uppercase;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 10;
}

/* Constellation */
.wb-constellation-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

.wb-constellation-wrap canvas {
  flex-shrink: 0;
}

.wb-constellation-label {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* === Params Panel === */
.wb-params-panel {
  grid-column: 1;
  grid-row: 2;
  max-height: 400px;
  overflow-y: auto;
}

.wb-output-toggle {
  display: flex;
  gap: 2px;
}

.wb-toggle-btn {
  font-size: 10px;
  padding: 2px 10px;
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.wb-toggle-btn:first-child { border-radius: 10px 0 0 10px; }
.wb-toggle-btn:last-child { border-radius: 0 10px 10px 0; }
.wb-toggle-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.wb-param-groups {
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Param group card */
.wb-group {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
}

.wb-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.wb-group-header:hover {
  background: var(--elevated);
}

.wb-group-accent {
  width: 3px;
  height: 18px;
  border-radius: 2px;
  flex-shrink: 0;
}

.wb-group-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.wb-group-sparkline {
  width: 40px;
  height: 12px;
  flex-shrink: 0;
}

.wb-group-chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.wb-group.open .wb-group-chevron {
  transform: rotate(90deg);
}

.wb-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.wb-group.open .wb-group-body {
  max-height: 500px;
}

.wb-group-params {
  padding: 4px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Individual param bar */
.wb-param {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 20px;
}

.wb-param-name {
  font-size: 10px;
  color: var(--text-dim);
  width: 60px;
  flex-shrink: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wb-param-track {
  flex: 1;
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  touch-action: none;
}

.wb-param-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.1s ease;
  min-width: 1px;
  pointer-events: none;
}

.wb-param-value {
  font-size: 10px;
  color: var(--text-muted);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* === Controls Panel === */
.wb-controls-panel {
  grid-column: 2;
  grid-row: 2;
  gap: 0;
}

.wb-mode-toggle {
  display: flex;
  padding: 8px 12px 4px;
  gap: 4px;
}

.wb-mode-btn {
  flex: 1;
  padding: 6px 12px;
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.wb-mode-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.wb-action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px 8px;
}

/* Buttons */
.wb-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-light);
  background: var(--elevated);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.wb-btn:hover { border-color: var(--text-muted); }
.wb-btn:active { transform: scale(0.97); }

.wb-btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.wb-btn-primary:hover { filter: brightness(1.15); }

.wb-btn-accent {
  border-color: var(--accent);
  color: var(--accent);
}
.wb-btn-accent:hover { background: var(--accent); color: var(--bg); }

.wb-btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}
.wb-btn-danger:hover { background: var(--danger); color: var(--bg); }

.wb-btn-good {
  background: rgba(0, 200, 160, 0.12);
  color: #00c8a0;
  border-color: rgba(0, 200, 160, 0.4);
  font-weight: 600;
}
.wb-btn-good:hover {
  background: rgba(0, 200, 160, 0.25);
}
.wb-btn-bad {
  background: rgba(220, 60, 20, 0.12);
  color: #dc3c14;
  border-color: rgba(220, 60, 20, 0.4);
  font-weight: 600;
}
.wb-btn-bad:hover {
  background: rgba(220, 60, 20, 0.25);
}

.wb-btn.flash {
  filter: brightness(1.8);
}

.wb-btn-bad,
.wb-btn-good {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding-top: 4px;
  padding-bottom: 3px;
}

.wb-btn-label {
  font-weight: 600;
}

.wb-key-hint {
  font-size: 11px;
  font-family: inherit;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  line-height: 1;
}

/* Synth controls */
.wb-synth-controls {
  padding: 4px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
}

.wb-synth-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wb-synth-row label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 70px;
}
.wb-synth-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}
.wb-synth-row select {
  flex: 1;
  background: var(--elevated);
  border: 1px solid var(--border-light);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
}

.wb-synth-status {
  font-size: 10px;
  color: var(--text-muted);
}

/* Loss plot */
.wb-loss-wrap {
  padding: 4px 12px;
  border-top: 1px solid var(--border);
}
.wb-loss-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.wb-loss-wrap canvas {
  width: 100%;
  height: 60px;
  display: block;
  border-radius: var(--radius-sm);
}

/* Metrics */
.wb-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

.wb-metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wb-metric-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.wb-metric-value {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

/* === Toast === */
.wb-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.5px;
  z-index: 2000;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s ease;
}
.wb-toast.fade-out {
  opacity: 0;
}

/* === Help Overlay === */
.wb-help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.wb-help-content {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  color: var(--text);
}
.wb-help-content h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--accent);
}
.wb-help-content h3 {
  font-size: 14px;
  margin: 16px 0 6px;
  color: var(--text);
}
.wb-help-content p, .wb-help-content ol {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.wb-help-content ol {
  padding-left: 20px;
}
.wb-help-content li {
  margin-bottom: 4px;
}

/* === Utility === */
.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Mobile: single column === */
@media (max-width: 767px) {
  .workbench {
    padding: 4px;
    gap: 4px;
  }

  .wb-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
  }

  .wb-canvas-panel { grid-column: 1; grid-row: 1; min-height: 220px; }
  .wb-mapping-panel { grid-column: 1; grid-row: 2; }
  .wb-params-panel { grid-column: 1; grid-row: 3; max-height: 300px; }
  .wb-controls-panel { grid-column: 1; grid-row: 4; }

  .wb-mapping-area {
    justify-content: center;
    gap: 8px;
    padding: 8px;
  }

  #mapping-canvas {
    max-width: 220px !important;
  }

  .wb-title { font-size: 14px; }
  .presets { display: none; }

  /* Collapsible sections on mobile */
  .wb-panel.collapsible > .wb-panel-header {
    cursor: pointer;
  }
  .wb-panel.collapsible.collapsed > *:not(.wb-panel-header) {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    border: none;
  }
}

/* === Tablet and up === */
@media (min-width: 768px) {
  .wb-canvas-panel {
    min-height: 380px;
  }

  .wb-mapping-area {
    gap: 16px;
    padding: 16px;
  }
}

/* Large screens */
@media (min-width: 1100px) {
  .wb-canvas-panel {
    min-height: 450px;
  }
}
