/* ===========================================================================
   PlayDDSP — Studio Console (minimal hardware-module aesthetic)
   - IBM Plex Mono for labels/numerics, IBM Plex Sans for status copy
   - Cold dark grays + single warm amber accent for state
   - Hairline 1px borders, no glow/gradient noise
   - Single-row 5-card layout, total <= 900px tall
   =========================================================================== */

:root {
  /* surfaces */
  --bg:           #0a0a0c;
  --surface-1:    #111114;
  --surface-2:    #16161a;
  --surface-3:    #1c1c22;

  /* hairlines */
  --line:         #1d1d22;
  --line-strong:  #2a2a30;

  /* text */
  --text:      #e6e6e8;
  --text-dim:  #8a8a92;
  --text-mute: #555560;

  /* one accent, used sparingly */
  --amber:      #ffb627;
  --amber-dim:  #6b4910;

  /* semantic */
  --ok:    #5dafff;     /* connection-blue */
  --bad:   #ff5b5b;
  --green: #5dd07e;     /* loop-running only */

  /* type */
  --ff-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ff-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont,
             "PingFang SC", "Microsoft YaHei", sans-serif;

  /* radii */
  --r-xs: 2px;
  --r-sm: 4px;
  --r-md: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff-sans);
  font-size: 13px;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

button { cursor: pointer; font-family: inherit; }
::selection { background: var(--amber); color: #1b1100; }

/* small uppercase mono caption helper */
.cap { font-family: var(--ff-mono); font-size: 10px;
       letter-spacing: 0.14em; text-transform: uppercase;
       color: var(--text-mute); }

/* ============================================================ Top bar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px;
  padding: 0 16px;
  height: 44px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: baseline; gap: 8px;
  font-family: var(--ff-mono);
  font-weight: 600;
}
.brand-mark {
  width: 8px; height: 8px; background: var(--amber);
  align-self: center;
  box-shadow: 0 0 6px rgba(255,182,39,0.4);
}
.brand-name { font-size: 12px; letter-spacing: 0.15em; color: var(--text); }
.brand-sub  { font-size: 10px; letter-spacing: 0.1em; color: var(--text-mute); }

/* center: loop controls */
.topctl {
  display: flex; align-items: center; gap: 14px;
  flex: 1;
}
.loop-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 26px; padding: 0 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-family: var(--ff-mono);
  font-size: 11px; font-weight: 600; letter-spacing: 0.12em;
  transition: border-color 120ms, color 120ms, background 120ms;
}
.loop-btn:hover:not(:disabled) { border-color: var(--amber); color: var(--amber); }
.loop-btn:disabled { opacity: 0.55; cursor: wait; }
.loop-btn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-mute);
  transition: background 120ms, box-shadow 120ms;
}
.loop-btn:hover:not(:disabled) .loop-btn-dot { background: var(--amber); }
.loop-btn.active {
  border-color: var(--green); color: var(--green);
  background: rgba(93,208,126,0.06);
}
.loop-btn.active .loop-btn-dot {
  background: var(--green);
  box-shadow: 0 0 6px rgba(93,208,126,0.6);
  animation: loop-pulse 1.4s ease-in-out infinite alternate;
}
@keyframes loop-pulse { from { opacity: 0.6; } to { opacity: 1; } }

.field { display: inline-flex; align-items: center; gap: 8px; }
.field-label {
  font-family: var(--ff-mono); font-size: 10px;
  color: var(--text-mute); letter-spacing: 0.14em; text-transform: uppercase;
}
select {
  height: 26px; padding: 0 8px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font-family: var(--ff-mono); font-size: 11px;
}
select:focus { outline: none; border-color: var(--amber); }

.status-text {
  font-family: var(--ff-mono); font-size: 11px;
  color: var(--text-dim);
}

/* right: MIDI pill */
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.midi-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 26px; padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
}
.midi-pill[data-state="ok"]  { border-color: rgba(93,175,255,0.45); }
.midi-pill[data-state="off"] { border-color: var(--line-strong); }
.midi-pill-label {
  font-family: var(--ff-mono); font-size: 10px;
  color: var(--text-mute); letter-spacing: 0.14em; text-transform: uppercase;
}
#midi-status-label { font-family: var(--ff-mono); font-size: 11px; color: var(--text); }

.midi-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-mute);
  transition: background 100ms, box-shadow 100ms;
}
.midi-dot.ok  { background: var(--ok); box-shadow: 0 0 6px rgba(93,175,255,0.55); }
.midi-dot.off { background: var(--text-mute); }
.midi-dot.flash { background: var(--amber); box-shadow: 0 0 8px var(--amber); }

.ghost-btn {
  height: 26px; padding: 0 10px;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font-family: var(--ff-mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  transition: border-color 120ms, color 120ms;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-dim); }
.ghost-danger:hover { color: var(--bad); border-color: var(--bad); }
.ghost-accent {
  display: inline-flex; align-items: center; gap: 5px;
  border-color: var(--amber-dim); color: var(--amber);
}
.ghost-accent:hover { border-color: var(--amber); color: #1b1100; background: var(--amber); }
.ghost-accent:active { transform: translateY(1px); }

/* LEARN toggle (prominent) */
.learn-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 26px; padding: 0 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--amber-dim); border-radius: var(--r-sm);
  font-family: var(--ff-mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em;
  transition: border-color 120ms, color 120ms, background 120ms, box-shadow 120ms;
}
.learn-btn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-mute);
  transition: background 120ms, box-shadow 120ms;
}
.learn-btn:hover:not(.active) { border-color: var(--amber); color: var(--amber); }
.learn-btn:hover:not(.active) .learn-btn-dot { background: var(--amber); }
.learn-btn.active {
  background: var(--amber); color: #1b1100;
  border-color: var(--amber);
  box-shadow: 0 0 0 0 var(--amber);
  animation: learn-btn-pulse 1.2s ease-in-out infinite;
}
.learn-btn.active .learn-btn-dot {
  background: #1b1100;
  box-shadow: 0 0 4px #1b1100 inset;
}
@keyframes learn-btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,182,39,0); }
  50%      { box-shadow: 0 0 0 6px rgba(255,182,39,0.12); }
}

/* ============================================================ Banner / Learn hint */
.midi-banner {
  margin: 10px 16px 0;
  padding: 10px 12px;
  background: rgba(255,182,39,0.05);
  border: 1px solid var(--amber-dim);
  border-left: 2px solid var(--amber);
  border-radius: var(--r-sm);
  font-family: var(--ff-sans);
  font-size: 12px;
  color: var(--text);
  line-height: 1.55;
}
.midi-banner strong { color: var(--amber); font-weight: 600; }
.midi-banner code {
  font-family: var(--ff-mono); font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 3px;
  color: var(--text);
}
.midi-banner ol { margin: 6px 0 0; padding-left: 18px; }
.midi-banner li { margin: 3px 0; }

.midi-learn-hint {
  margin: 10px 16px 0;
  padding: 7px 12px;
  background: rgba(255,182,39,0.06);
  border: 1px solid var(--amber);
  border-radius: var(--r-sm);
  font-family: var(--ff-mono); font-size: 11px;
  color: var(--amber);
  letter-spacing: 0.02em;
  animation: learn-pulse 1.2s ease-in-out infinite alternate;
}
@keyframes learn-pulse {
  from { background: rgba(255,182,39,0.04); }
  to   { background: rgba(255,182,39,0.12); }
}

/* ============================================================ Panels row */
.panels-row {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 16px;
  align-content: start;
  min-height: 0;
}

.tensor-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: flex; flex-direction: column;
  min-width: 0;
}
.tensor-card-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 8px 10px 7px;
  border-bottom: 1px solid var(--line);
}
.tensor-card-label {
  font-family: var(--ff-mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.16em; color: var(--text);
}
.tensor-card-tag {
  font-family: var(--ff-mono); font-size: 9.5px;
  letter-spacing: 0.08em; color: var(--text-mute);
}

/* small accent stripe on each card (color comes from class) */
.tensor-card { position: relative; }
.tensor-card::before {
  content: ""; position: absolute;
  top: 0; left: 0; height: 2px; width: 24px;
  background: var(--card-accent, var(--amber));
}
.tensor-g_f0    { --card-accent: #5dafff; }
.tensor-g_amp   { --card-accent: #ffb627; }
.tensor-g_harm  { --card-accent: #5dd07e; }
.tensor-g_noise { --card-accent: #c08bff; }
.tensor-g_post  { --card-accent: #8a8a92; }

.tensor-card-body {
  display: flex; flex-direction: column;
  gap: 6px;
  padding: 8px 8px 10px;
  min-height: 0;
}

/* HARMONICS card 内的附加：spectrum + preset */
.harm-extras {
  display: flex; flex-direction: column;
  gap: 6px;
  padding: 6px 8px 0;
  border-bottom: 1px dashed var(--line);
}
.harm-spectrum {
  width: 100%;
  height: 36px;
  background: #0a0a0c;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  image-rendering: pixelated;
}
.harm-preset-wrap {
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 4px;
}
.harm-preset-label {
  font-family: var(--ff-mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-mute);
}
.harm-preset-wrap select {
  flex: 1; height: 22px; padding: 0 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-xs);
  font-family: var(--ff-mono); font-size: 11px;
}
.harm-preset-wrap select:focus { outline: none; border-color: var(--amber); }

.subpanel {
  background: transparent;
  border-top: 1px dashed var(--line);
  padding-top: 6px;
}
.subpanel:first-child { border-top: none; padding-top: 0; }
.subpanel-title {
  font-family: var(--ff-mono);
  font-size: 9.5px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-mute);
  padding: 0 2px 4px;
}
.subpanel-knobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 4px 2px;
  align-items: start;
}

/* ============================================================ Knob */
.knob-group {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 2px 4px;
  border-radius: var(--r-xs);
  user-select: none;
  cursor: ns-resize;
  transition: background 100ms;
}
.knob-group:hover { background: var(--surface-2); }

.knob-svg {
  width: 42px; height: 42px;
  display: block;
}
.ring-bg {
  fill: none; stroke: var(--surface-3); stroke-width: 3.5;
  stroke-linecap: round;
}
.ring-fg {
  fill: none; stroke: var(--text-dim); stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke 100ms;
}
.indicator-line {
  stroke: var(--text); stroke-width: 1.6; stroke-linecap: round;
}

/* tinted ring per tensor */
.tensor-g_f0    .ring-fg { stroke: #5dafff; }
.tensor-g_amp   .ring-fg { stroke: #ffb627; }
.tensor-g_harm  .ring-fg { stroke: #5dd07e; }
.tensor-g_noise .ring-fg { stroke: #c08bff; }
.tensor-g_post  .ring-fg { stroke: #c2c2c8; }

.knob-label {
  margin-top: 3px;
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-align: center;
  white-space: nowrap;
  max-width: 64px; overflow: hidden; text-overflow: ellipsis;
}
.knob-readout {
  margin-top: 1px;
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

/* MIDI binding */
.knob-cc-badge {
  position: absolute;
  top: 2px; right: 2px;
  font-family: var(--ff-mono);
  font-size: 8px; font-weight: 600;
  color: #1b1100;
  background: var(--amber);
  padding: 1px 3px;
  border-radius: 2px;
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 3;
  line-height: 1;
}
.knob-group.midi-bound .ring-fg {
  stroke: var(--amber) !important;
}
.knob-group.midi-learning {
  outline: 1px dashed var(--amber);
  outline-offset: -1px;
  background: rgba(255,182,39,0.06);
}
.knob-group.midi-flash .ring-fg {
  filter: brightness(1.6);
}

/* LEARN-mode: every knob becomes click-to-bind. Subtle dashed border + amber-tint hover */
body.learn-mode-on .knob-group { cursor: pointer; }
.knob-group.midi-armable {
  outline: 1px dashed rgba(255,182,39,0.18);
  outline-offset: -2px;
}
.knob-group.midi-armable:hover {
  outline-color: var(--amber);
  background: rgba(255,182,39,0.06);
}

/* ============================================================ MIDI Monitor */
.midi-monitor {
  position: fixed;
  right: 16px; bottom: 90px;
  width: 320px;
  background: var(--surface-1);
  border: 1px solid var(--amber-dim);
  border-radius: var(--r-sm);
  box-shadow: 0 10px 32px rgba(0,0,0,0.6);
  z-index: 60;
  overflow: hidden;
}
.midi-monitor-head {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(255,182,39,0.06), transparent);
  border-bottom: 1px solid var(--line);
}
.midi-monitor-title {
  font-family: var(--ff-mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.16em; color: var(--amber);
}
.midi-monitor-hint {
  font-family: var(--ff-sans); font-size: 10.5px;
  color: var(--text-dim);
}
.midi-monitor-list {
  padding: 4px 4px;
  max-height: 220px; overflow-y: auto;
}
.mm-row {
  display: grid;
  grid-template-columns: 44px 32px 36px 1fr 56px;
  gap: 6px;
  padding: 4px 6px;
  font-family: var(--ff-mono); font-size: 10.5px;
  color: var(--text);
  border-radius: var(--r-xs);
  align-items: center;
}
.mm-row + .mm-row { margin-top: 1px; }
.mm-row.bound { background: rgba(255,182,39,0.06); }
.mm-row.bound .mm-tag { color: var(--amber); }
.mm-empty {
  display: block;
  text-align: center;
  color: var(--text-mute);
  padding: 10px;
  font-size: 11px;
}
.mm-tag { font-weight: 600; color: var(--text); white-space: nowrap; }
.mm-ch  { color: var(--text-mute); font-size: 9.5px; }
.mm-val { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.mm-bar {
  position: relative;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.mm-bar > i {
  display: block; height: 100%;
  background: var(--amber);
  transition: width 80ms linear;
}
.mm-row.bound .mm-bar > i { background: var(--amber); }
.mm-row:not(.bound) .mm-bar > i { background: var(--text-dim); }
.mm-t {
  font-size: 9px; color: var(--text-mute); text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================ Bool toggle */
.check-group {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 2px 4px;
}
.check-group input[type="checkbox"] {
  width: 32px; height: 18px;
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.check-group input[type="checkbox"]::before {
  content: "";
  position: absolute; top: 1px; left: 1px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: left 120ms, background 120ms;
}
.check-group input[type="checkbox"]:checked {
  background: rgba(255,182,39,0.18);
  border-color: var(--amber);
}
.check-group input[type="checkbox"]:checked::before {
  left: 15px; background: var(--amber);
}

/* ============================================================ Context menu */
.midi-context-menu {
  position: fixed;
  z-index: 100;
  min-width: 220px;
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  box-shadow: 0 8px 28px rgba(0,0,0,0.6);
  padding: 6px;
}
.midi-ctx-header {
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  font-family: var(--ff-mono);
  font-size: 11px; color: var(--text);
}
.midi-ctx-header span {
  display: block; margin-top: 2px;
  font-size: 9.5px;
  color: var(--text-mute); font-weight: 400;
  letter-spacing: 0.04em;
}
.midi-context-menu button {
  display: block; width: 100%;
  text-align: left;
  padding: 7px 9px;
  background: transparent;
  color: var(--text);
  border: none; border-radius: var(--r-xs);
  font-family: var(--ff-mono);
  font-size: 11px; letter-spacing: 0.02em;
}
.midi-context-menu button:hover:not(:disabled) {
  background: var(--surface-2); color: var(--amber);
}
.midi-context-menu button:disabled { color: var(--text-mute); cursor: default; }

/* ============================================================ Piano strip */
.play-strip {
  display: flex; align-items: stretch; gap: 12px;
  padding: 8px 16px 10px;
  border-top: 1px solid var(--line);
  background: var(--surface-1);
}
.play-strip-meta {
  display: flex; flex-direction: column; justify-content: center;
  min-width: 200px;
}
.play-strip-title {
  font-family: var(--ff-mono); font-size: 10px;
  letter-spacing: 0.16em; color: var(--text-mute);
}
.play-strip-sub {
  font-family: var(--ff-mono); font-size: 10px;
  color: var(--text-dim); margin-top: 2px;
}

.piano-strip {
  position: relative;
  height: 60px; flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.pk-white {
  height: 100%;
  background: #d4d4d8;
  border-right: 1px solid #0a0a0c;
  display: inline-block;
  vertical-align: top;
  position: relative;
  cursor: pointer;
  transition: background 60ms;
}
.pk-white::after {
  content: attr(data-keyhint);
  position: absolute; bottom: 3px; left: 0; right: 0;
  text-align: center;
  font-family: var(--ff-mono); font-size: 8px;
  color: #555560;
}
.pk-white[data-label]::before {
  content: attr(data-label);
  position: absolute; top: 3px; left: 2px;
  font-family: var(--ff-mono); font-size: 8px;
  color: #888892;
}
.pk-white.active { background: var(--amber); }
.pk-black {
  position: absolute;
  top: 0; height: 60%;
  background: #1b1b22;
  border: 1px solid #050507;
  cursor: pointer;
  z-index: 2;
  transition: background 60ms;
}
.pk-black::after {
  content: attr(data-keyhint);
  position: absolute; bottom: 2px; left: 0; right: 0;
  text-align: center;
  font-family: var(--ff-mono); font-size: 8px;
  color: #aaa;
}
.pk-black.active { background: var(--amber-dim); }

/* ============================================================ Footer */
.appfoot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 16px 8px;
  font-family: var(--ff-mono);
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: 0.06em;
  border-top: 1px solid var(--line);
}
.appfoot .foot-right { color: var(--text-dim); }

/* ============================================================ Responsive */
@media (max-width: 1280px) {
  .panels-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .panels-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 10px; }
  .topctl { order: 3; width: 100%; }
  .topbar-right { order: 2; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Engine toggle (direct ↔ lead16) — segmented pill, top-right
   ============================================================ */
.engine-toggle {
  display: inline-flex; align-items: center;
  height: 26px; padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
}
.engine-opt {
  height: 100%; padding: 0 10px;
  background: transparent;
  color: var(--text-mute);
  border: 0; border-radius: var(--r-xs);
  font-family: var(--ff-mono); font-size: 10px;
  letter-spacing: 0.16em; text-transform: uppercase;
  cursor: pointer;
  transition: color 120ms, background 120ms;
}
.engine-opt:hover:not(.active) { color: var(--text-dim); }
.engine-opt.active {
  background: var(--amber);
  color: #1b1100;
  font-weight: 600;
}

/* ============================================================
   Lead16 strip — only shown when engine = lead16
   ============================================================ */
.lead16-strip {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line-strong);
}
.lead16-strip-meta { display: flex; align-items: baseline; gap: 10px; }
.lead16-tag {
  font-family: var(--ff-mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.18em; color: var(--amber);
  padding: 2px 6px;
  border: 1px solid var(--amber-dim); border-radius: var(--r-xs);
}
.lead16-sub {
  font-family: var(--ff-mono); font-size: 10px;
  color: var(--text-mute); letter-spacing: 0.08em;
}

/* primary action button — amber-filled, used for RENDER */
.primary-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 14px;
  background: var(--amber); color: #1b1100;
  border: 1px solid var(--amber); border-radius: var(--r-sm);
  font-family: var(--ff-mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase;
  cursor: pointer;
  transition: background 120ms, opacity 120ms;
}
.primary-btn:hover:not(:disabled) { background: #ffc14d; }
.primary-btn:disabled { opacity: 0.55; cursor: wait; }
.primary-btn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #1b1100;
}

/* When lead16 engine is on, dim the direct-mode knob panels —
   visual cue that those controls don't drive the sound right now. */
body.engine-lead16 #knob-panels { opacity: 0.28; pointer-events: none; filter: saturate(0.4); }
body.engine-lead16 .play-strip   { opacity: 0.55; }

/* MACRO engine — donor playback strip (reuses .lead16-strip styles) */
.macro-tag {
  /* same shape as .lead16-tag but cyan-leaning to differentiate */
  border-color: rgba(93,175,255,0.45);
  color: var(--ok);
}
body.engine-macro #knob-panels { opacity: 0.28; pointer-events: none; filter: saturate(0.4); }
body.engine-macro .play-strip   { opacity: 0.55; }

/* ============================================================
   Macro panel (Phase B 12-macro layer) — device-rack layout,
   rotary knobs (K1-K8) + vertical faders (F1-F4)
   ============================================================ */
.macro-panel {
  display: flex; flex-direction: column;
  padding: 14px 22px 22px;
  background: var(--surface-1);
  border-top: 1px solid var(--line-strong);
  gap: 16px;
}

.macro-header {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.macro-auto {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--ff-mono); font-size: 10px;
  color: var(--text-mute); letter-spacing: 0.1em; text-transform: uppercase;
}
.primary-btn-cyan {
  background: var(--ok); border-color: var(--ok); color: #001020;
}
.primary-btn-cyan:hover:not(:disabled) { background: #78bcff; }
.primary-btn-cyan .primary-btn-dot { background: #001020; }

/* device rack: bordered sections in a single row, hairline dividers between */
.macro-sections {
  display: flex; align-items: stretch;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  overflow: hidden;
}
.macro-section {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 20px;
  border-right: 1px solid var(--line);
}
.macro-section:last-child { border-right: none; }
.macro-section-title {
  font-family: var(--ff-mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--text-mute);
}
.macro-row {
  display: flex; align-items: flex-end; gap: 18px;
  flex: 1;
}
.macro-section-spectrum { flex: 3; }
.macro-section-perform  { flex: 1.3; }
.macro-section-mix      { flex: 2.2; }

/* --- knob cells (reuse .knob-group/.knob-svg/.ring-* from DIRECT mode) --- */
.macro-knob { cursor: ns-resize; }
.macro-knob .ring-fg { stroke: var(--amber); }
.macro-knob .knob-label {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  max-width: none;
}
.knob-id-tag {
  font-family: var(--ff-mono); font-size: 9px; font-weight: 600;
  color: var(--amber); letter-spacing: 0.1em;
}
.knob-label-name {
  font-family: var(--ff-mono); font-size: 8.5px;
  color: var(--text-mute); letter-spacing: 0.1em; text-transform: uppercase;
}

/* --- vertical faders (F1-F4), Ableton mixer-strip look --- */
.fader-group {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 4px 6px 0;
  cursor: ns-resize;
  user-select: none;
}
.fader-track {
  position: relative;
  width: 26px; height: 128px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xs);
  overflow: hidden;
}
.fader-track::before {
  content: "";
  position: absolute; left: 50%; top: 6px; bottom: 6px; width: 2px;
  transform: translateX(-50%);
  background: var(--line);
}
.fader-fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
  background: linear-gradient(180deg, rgba(93,175,255,0.4), rgba(93,175,255,0.08));
}
.fader-thumb {
  position: absolute; left: 50%; bottom: 0%;
  width: 32px; height: 13px;
  transform: translate(-50%, 50%);
  background: var(--ok);
  border: 1px solid #001824;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.fader-thumb::before {
  content: "";
  position: absolute; left: 4px; right: 4px; top: 50%; height: 1px;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.35);
}
.fader-label {
  font-family: var(--ff-mono); font-size: 9px;
  color: var(--text-mute); letter-spacing: 0.06em;
  text-align: center; white-space: nowrap;
}
.fader-id {
  color: var(--ok); font-weight: 600; margin-right: 4px;
}
.fader-readout {
  font-family: var(--ff-mono); font-size: 10px;
  color: var(--text); font-variant-numeric: tabular-nums;
}

/* F3 emphasis: wider two-tone track, amber accent (REF ⟷ MACRO) */
.fader-group-emph .fader-track {
  width: 44px;
  background: linear-gradient(180deg, rgba(255,182,39,0.2), rgba(93,175,255,0.2));
  border-color: var(--amber);
}
.fader-group-emph .fader-thumb {
  width: 40px; height: 15px;
  background: var(--amber); border-color: #1b1100;
}
.fader-group-emph .fader-id { color: var(--amber); }

@media (max-width: 900px) {
  .macro-sections { flex-direction: column; }
  .macro-section { border-right: none; border-bottom: 1px solid var(--line); }
  .macro-section:last-child { border-bottom: none; }
  .macro-row { flex-wrap: wrap; }
}
