:root {
  --lab-bg: #f5f2ea;
  --lab-surface: #fbf8f1;
  --lab-surface-2: #f1ede4;
  --lab-border: #d8d1c3;
  --lab-text: #221f18;
  --lab-muted: #69645b;
  --lab-accent: #8e6a12;
  --lab-accent-hover: #6f530e;
  --lab-midi: #2a7a4b;
  --lab-mono: "Roboto Mono", monospace;
  --lab-body: "Satoshi", sans-serif;
  --lab-display: "Boska", serif;
}

[data-theme="dark"] {
  --lab-bg: #171511;
  --lab-surface: #1e1b16;
  --lab-surface-2: #26221c;
  --lab-border: #3b352b;
  --lab-text: #ece6da;
  --lab-muted: #b7ae9e;
  --lab-accent: #d5a53a;
  --lab-accent-hover: #e2b85c;
  --lab-midi: #6fcf97;
}

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

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--lab-bg) 88%, #000);
  backdrop-filter: blur(6px);
}

.overlay.is-hidden { display: none; }

.overlay-panel {
  max-width: 28rem;
  padding: 2rem;
  text-align: center;
  background: var(--lab-surface);
  border: 1px solid var(--lab-border);
  border-radius: 1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

.overlay-eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--lab-muted);
  margin-bottom: 0.5rem;
}

.overlay-panel h1 {
  font-family: var(--lab-display);
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.overlay-lede {
  color: var(--lab-muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.overlay-panel button {
  font: inherit;
  border: none;
  background: var(--lab-accent);
  color: #faf7f0;
  padding: 0.75rem 2rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.overlay-panel button:hover { background: var(--lab-accent-hover); }

.overlay-note {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--lab-muted);
}

.lab-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--lab-bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--lab-border);
}

.lab-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.lab-brand { display: flex; align-items: baseline; gap: 0.75rem; }

.lab-back {
  font-size: 0.75rem;
  color: var(--lab-muted);
  text-decoration: none;
}

.lab-back:hover { color: var(--lab-accent); }

.lab-brand h1 {
  font-family: var(--lab-display);
  font-size: 1.25rem;
  font-weight: 500;
}

.lab-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.control-inline {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.control-inline span { color: var(--lab-muted); white-space: nowrap; }

select {
  font: inherit;
  font-family: var(--lab-mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--lab-border);
  border-radius: 0.35rem;
  background: var(--lab-surface);
  color: var(--lab-text);
  max-width: 14rem;
}

.midi-status {
  font-family: var(--lab-mono);
  font-size: 0.7rem;
  color: var(--lab-muted);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.midi-activity {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--lab-border);
  transition: background 0.05s;
}

.midi-activity.is-on { background: var(--lab-midi); box-shadow: 0 0 6px var(--lab-midi); }

.text-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--lab-border);
  border-radius: 999px;
  background: var(--lab-surface);
  color: var(--lab-text);
  cursor: pointer;
}

.text-btn:hover { border-color: var(--lab-accent); color: var(--lab-accent); }

.lab-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1rem 0;
  max-width: 1200px;
  margin: 0 auto;
  overflow-x: auto;
}

.lab-tab {
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.6rem 0.9rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--lab-muted);
  cursor: pointer;
  white-space: nowrap;
}

.lab-tab.is-active {
  color: var(--lab-accent);
  border-bottom-color: var(--lab-accent);
}

.lab-tab.is-soon {
  opacity: 0.45;
  cursor: not-allowed;
}

.lab-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.lab-panel { display: none; }
.lab-panel.is-active { display: block; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head h2 {
  font-family: var(--lab-display);
  font-size: 1.35rem;
  margin-bottom: 0.35rem;
}

.panel-intro {
  max-width: 52ch;
  color: var(--lab-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.panel-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: flex-start; }

.monitor-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
}

.monitor-filters label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }

.monitor-table-wrap {
  overflow: auto;
  border: 1px solid var(--lab-border);
  border-radius: 0.65rem;
  background: var(--lab-surface);
  max-height: min(60vh, 520px);
}

.monitor-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--lab-mono);
  font-size: 0.68rem;
}

.monitor-table th,
.monitor-table td {
  padding: 0.4rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid color-mix(in srgb, var(--lab-border) 70%, transparent);
  white-space: nowrap;
}

.monitor-table th {
  position: sticky;
  top: 0;
  background: var(--lab-surface-2);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.62rem;
  color: var(--lab-muted);
}

.monitor-table tbody tr:hover { background: var(--lab-surface-2); }

.monitor-table .msg-note { color: var(--lab-midi); }
.monitor-table .msg-cc { color: var(--lab-accent); }

.reaper-tip {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--lab-surface-2);
  border: 1px dashed var(--lab-border);
  border-radius: 0.5rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--lab-muted);
}

.reaper-tip strong {
  display: block;
  color: var(--lab-accent);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.learn-hint {
  font-size: 0.82rem;
  color: var(--lab-muted);
  margin-bottom: 1rem;
}

.sampler-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.sampler-pad {
  background: var(--lab-surface);
  border: 1px solid var(--lab-border);
  border-radius: 0.65rem;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sampler-pad.is-playing {
  border-color: var(--lab-midi);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--lab-midi) 35%, transparent);
}

.sampler-pad.is-learning {
  border-color: var(--lab-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--lab-accent) 35%, transparent);
}

.sampler-pad-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sampler-pad-head strong {
  font-family: var(--lab-mono);
  font-size: 0.75rem;
}

.sampler-note {
  font-family: var(--lab-mono);
  font-size: 0.68rem;
  color: var(--lab-muted);
}

.sampler-pad-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.sampler-pad-actions label {
  font-size: 0.68rem;
  cursor: pointer;
  color: var(--lab-accent);
  font-weight: 600;
}

.sampler-pad-actions input[type="file"] { display: none; }

.sampler-pad-name {
  font-size: 0.72rem;
  color: var(--lab-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.num-input {
  font: inherit;
  font-family: var(--lab-mono);
  font-size: 0.75rem;
  width: 4.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--lab-border);
  border-radius: 0.35rem;
  background: var(--lab-surface);
  color: var(--lab-text);
}

.status-line {
  font-family: var(--lab-mono);
  font-size: 0.75rem;
  color: var(--lab-muted);
  margin-bottom: 0.75rem;
}

.event-list {
  list-style: none;
  font-family: var(--lab-mono);
  font-size: 0.68rem;
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--lab-border);
  border-radius: 0.5rem;
  background: var(--lab-surface);
  padding: 0.5rem;
}

.event-list li {
  padding: 0.25rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--lab-border) 50%, transparent);
}

.file-btn {
  cursor: pointer;
  display: inline-flex;
}

.file-btn input { display: none; }

.quantize-canvas {
  width: 100%;
  height: 320px;
  border: 1px solid var(--lab-border);
  border-radius: 0.65rem;
  background: var(--lab-surface);
  display: block;
}

.synth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.synth-block {
  border: 1px solid var(--lab-border);
  border-radius: 0.65rem;
  padding: 0.85rem 1rem;
  background: var(--lab-surface);
}

.synth-block legend {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lab-accent);
  padding: 0 0.25rem;
}

.synth-block label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  margin-top: 0.5rem;
}

.range-label span { color: var(--lab-muted); }

.instrument-rack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.instrument-gui,
.instrument-note {
  border: 1px solid var(--lab-border);
  border-radius: 0.65rem;
  padding: 1rem;
  background: var(--lab-surface);
}

.instrument-gui label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.instrument-note p {
  font-size: 0.85rem;
  color: var(--lab-muted);
  line-height: 1.5;
}

@media (max-width: 640px) {
  .instrument-rack { grid-template-columns: 1fr; }
}

.lab-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.75rem;
  color: var(--lab-muted);
}

.lab-footer a { color: var(--lab-accent); text-decoration: none; }
.lab-footer a:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .lab-header-inner { flex-direction: column; align-items: stretch; }
  .lab-controls { justify-content: flex-start; }
}
