/* ============================================================
   Prosody — Warm, tactile, natural-but-digital
   ============================================================ */

:root {
  --bg: #363636;
  --surface: #2E2E2E;
  --text: #E2DCD2;
  --muted: #7A7570;
  --accent: #548C2B;
  --accent-warm: #0388A6;
  --green: #548C2B;
  --border: #4A4A4A;
  --dark: #1E1C1A;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius: 10px;
  --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* --- Utility classes --- */
.mono-xs { font-family: var(--font-mono); font-size: 10px; font-weight: 400; color: var(--muted); }
.mono-sm { font-family: var(--font-mono); font-size: 11px; font-weight: 400; color: var(--muted); }
.mono-md { font-family: var(--font-mono); font-size: 13px; font-weight: 500; color: var(--text); }
.flex-1 { flex: 1; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.header-left { display: flex; align-items: center; gap: 14px; }
.header-logo { width: 36px; height: 36px; }
.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  color: var(--text);
  letter-spacing: -0.03em;
}
.header-right { display: flex; align-items: center; gap: 10px; }

.add-panel-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.add-panel-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Settings bar (collapsible) --- */
.settings-bar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.settings-toggle {
  display: block;
  padding: 6px 32px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
  list-style: none;
}
.settings-toggle::-webkit-details-marker { display: none; }
.settings-toggle::before {
  content: '+ ';
}
.settings-bar[open] .settings-toggle::before {
  content: '- ';
}
.settings-toggle:hover { color: var(--text); }
.settings-content {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  padding: 0 32px 12px;
  overflow-x: auto;
}
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.settings-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-slider-row .slider-input { width: 80px; }

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

/* --- Field primitives --- */
.field-group { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.textarea-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  transition: border-color 0.2s;
}
.textarea-wrap:focus-within { border-color: var(--accent); }

textarea {
  width: 100%;
  min-height: 100px;
  padding: 14px;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 22px;
  color: var(--text);
  resize: vertical;
  outline: none;
}
textarea::placeholder { color: var(--muted); opacity: 0.6; }

.char-count {
  display: flex;
  justify-content: flex-end;
  gap: 0;
}

/* Engine buttons */
.engine-buttons { display: flex; gap: 6px; }
.engine-btn {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  gap: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.engine-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}
.engine-name {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}
.engine-btn.active .engine-name { color: #fff; }
.engine-tag { letter-spacing: 0.05em; }
.engine-btn.active .engine-tag { color: rgba(255, 255, 255, 0.6); }

.slider-input { flex: 1; accent-color: var(--accent-warm); }

.input-field {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
  outline: none;
  appearance: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.input-field:focus { border-color: var(--accent); }

/* --- Panels container --- */
.panels-container {
  display: flex;
  gap: 0;
  overflow-x: auto;
  min-height: calc(100vh - 120px);
}

/* --- Panel --- */
.panel {
  display: flex;
  flex-direction: column;
  min-width: 520px;
  flex: 1;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.panel:last-of-type {
  border-right: none;
}

/* Panel input area */
.panel-input {
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  gap: 12px;
}

.panel-input-header {
  display: flex;
  align-items: center;
  gap: 6px;
}
.example-select {
  width: auto;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border-color: var(--border);
}
.save-example-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.save-example-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.run-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  flex-shrink: 0;
}
.run-btn:hover { opacity: 0.9; }
.run-btn:active { transform: scale(0.98); }
.run-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.upload-btn {
  padding: 10px 16px;
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.upload-btn:hover {
  color: var(--text);
  border-color: var(--accent-warm);
}

.panel-status {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.panel-status.running { color: var(--accent); }
.panel-status.error { color: #B54040; }

.close-panel-btn {
  margin-left: auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.close-panel-btn:hover {
  border-color: #B54040;
  color: #B54040;
}

/* Pipeline steps */
.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.pipeline-step {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
}
.step-indicator {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-spinner {
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.step-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.step-label { color: var(--muted); }
.step-time {
  margin-left: auto;
  color: var(--border);
  font-size: 9px;
}
.pipeline-step.done .step-label { color: var(--text); }

/* --- Panel results --- */
.panel-results {
  display: flex;
  flex-direction: column;
  padding: 0 24px 20px;
  gap: 16px;
}

.score-number-inline {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 24px;
  color: var(--accent);
  letter-spacing: -0.03em;
  line-height: 1;
}
.score-meta-inline {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

/* Score sections (shared between rhythm & F0) */
.score-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.score-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.score-header .field-label {
  flex-shrink: 0;
}
.score-header .score-number-inline {
  flex-shrink: 0;
}
.score-header .score-meta-inline {
  flex-shrink: 0;
}
.score-header .piano-roll-legend {
  margin-left: auto;
}

/* Rhythm matrix grid */
.rhythm-matrix {
  display: grid;
  grid-template-columns: 80px repeat(3, 1fr);
  gap: 3px;
}
.rhythm-matrix-col-header {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 0 3px;
}
.rhythm-matrix-row-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--muted);
  text-align: right;
  padding-right: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}
.rhythm-matrix-row-dot {
  width: 5px;
  height: 5px;
  border-radius: 2px;
  flex-shrink: 0;
}
.rhythm-matrix-cell {
  position: relative;
  height: 28px;
  border-radius: 4px;
  background: var(--dark);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}
.rhythm-matrix-cell-fill {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.rhythm-matrix-cell-value {
  position: relative;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text);
  z-index: 1;
}

/* Piano roll legend */
.piano-roll-legend { display: flex; gap: 10px; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; }

.piano-roll-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  background: #1E1C1A;
}
.piano-roll-canvas {
  height: 240px;
  min-width: 100%;
  display: block;
}

/* Transport bar */
.transport {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 0;
}
.transport-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.transport-btn:hover { border-color: var(--accent-warm); color: var(--accent-warm); }
.transport-time {
  flex-shrink: 0;
  width: 30px;
  text-align: center;
}
.scrub-wrap {
  flex: 1;
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
}
.scrub-track {
  position: absolute;
  left: 0; right: 0;
  height: 4px;
  background: var(--surface);
  border-radius: 2px;
  overflow: hidden;
  pointer-events: none;
}
.scrub-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-warm);
  border-radius: 2px;
  transition: width 0.05s linear;
}
.scrub-input {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  margin: 0;
  position: relative;
  z-index: 1;
}
.scrub-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dark);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.scrub-input::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dark);
  border: 2px solid var(--bg);
  cursor: pointer;
}
.scrub-input::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.scrub-input::-moz-range-track { height: 4px; background: transparent; }
.transport-toggles {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.toggle-btn {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.active {
  background: var(--toggle-color, var(--accent));
  border-color: var(--toggle-color, var(--accent));
  color: #fff;
}
.toggle-btn:hover:not(.active) { border-color: var(--text); color: var(--text); }

/* Source toggle (text vs recording) */
.source-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}
.source-toggle .close-panel-btn {
  margin-left: auto;
}
.source-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.source-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.source-btn:hover:not(.active) {
  border-color: var(--text);
  color: var(--text);
}

/* Upload zone (recording mode) */
.upload-zone {
  margin-bottom: 8px;
}
.upload-drop-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-drop-area:hover {
  border-color: var(--accent);
  background: rgba(3, 136, 166, 0.05);
}
.upload-icon { font-size: 24px; }
.upload-label {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
}
.upload-hint {
  color: var(--muted);
}

/* Mixer strip */
.mixer-strip {
  display: flex;
  gap: 16px;
  padding: 8px 0 4px;
}
.mixer-channel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.mixer-label {
  font-weight: 500;
}
.mixer-sliders {
  display: flex;
  gap: 6px;
}
.mixer-slider-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.mixer-vertical {
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: slider-vertical;
  width: 16px;
  height: 64px;
  accent-color: var(--accent);
}
.mixer-slider-val {
  color: var(--muted);
  min-width: 20px;
  text-align: center;
}
.mixer-slider-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
}
.pitch-nudge {
  width: 20px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  transition: all 0.1s;
}
.pitch-nudge:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.pitch-nudge:active {
  background: var(--accent);
  color: #fff;
}

/* --- Responsive --- */
@media (max-width: 700px) {
  .panels-container { flex-direction: column; }
  .panel { min-width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .settings-content { flex-wrap: wrap; }
}
