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

:root {
  --bg: #000000;
  --surface: #121212;
  --surface-raised: #1e1e1e;
  --border: #404040;
  --border-active: #8fb3a4; /* accent — swap this one value to recolor the whole UI */
  --hover-surface: rgba(255, 255, 255, 0.07);
  --hover-border: rgba(255, 255, 255, 0.16);
  --param-group-bg: rgba(255, 255, 255, 0.05);
  --param-group-border: rgba(255, 255, 255, 0.09);
  --text: #ffffff;
  --text-secondary: #b3b3b3;
  --text-muted: #949494;
  --nav-active-bg: #252525;
  /* Helvetica Neue on Apple devices (system font + Figma design intent);
     Arimo is a free, Helvetica-metric web fallback for non-Apple platforms. */
  --font-sans: 'Helvetica Neue', Helvetica, 'Arimo', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-bar-height: 56px;
  --nav-clearance: calc(var(--nav-bar-height) + var(--safe-bottom));
  --page-header-pt: 16px;
  --page-header-px: 16px;
  --page-header-gap: var(--space-stack-relaxed);
  --page-title-size: calc(22px * 1.3 * 1.25 * 1.15 * 0.8);

  /* 8pt spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Semantic spacing */
  --space-inline: var(--space-2);
  --space-stack-tight: var(--space-3);
  --space-stack: var(--space-4);
  --space-stack-relaxed: var(--space-5);
  --space-module: calc(var(--space-6) + var(--space-5));
  --space-module-loose: calc(var(--space-7) + var(--space-5));
}

html {
  -webkit-text-size-adjust: 100%;
}

/* Consistent, palette-aligned keyboard focus ring (replaces the browser default blue) */
:focus-visible {
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  min-height: 100dvh;
  display: none;
  flex-direction: column;
  background: var(--bg);
}

/* ── Mobile splash (desktop-only gate) ── */

.mobile-splash {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 48px 32px;
  padding-top: calc(48px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  overflow: hidden;
}

.mobile-splash-glow {
  position: absolute;
  top: 42%;
  left: 50%;
  width: min(320px, 90vw);
  height: min(320px, 90vw);
  transform: translate(-50%, -50%);
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--border-active) 14%, transparent) 0%,
    color-mix(in srgb, var(--border-active) 4%, transparent) 42%,
    transparent 72%
  );
  pointer-events: none;
}

.mobile-splash-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
  max-width: 320px;
}

.mobile-splash-lockup {
  justify-content: center;
}

.mobile-splash-logo {
  height: 32px;
}

.mobile-splash-title {
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
}

.mobile-splash-copy {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.legal-disclaimer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  margin: 0;
  padding: 10px 20px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.45;
  text-align: center;
  color: rgba(255, 255, 255, 0.26);
  pointer-events: none;
}

.app-footer {
  display: none;
}

.app-footer-disclaimer {
  margin: 0;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.4);
}

.app-footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.app-footer-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-footer-link {
  background: none;
  border: none;
  padding: 0;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  -webkit-tap-highlight-color: transparent;
}

.app-footer-link:hover,
.app-footer-link:focus-visible {
  color: rgba(255, 255, 255, 0.65);
}

.app-footer-sep {
  color: rgba(255, 255, 255, 0.2);
  font-family: Helvetica, Arial, sans-serif;
  font-size: 11px;
  user-select: none;
}

.app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* ── Top bar ── */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  width: 100%;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.top-bar-brand {
  line-height: 0;
  flex-shrink: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-beta {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  line-height: 1;
  flex-shrink: 0;
}

.brand-tagline {
  display: none;
}

.brand-logo {
  display: block;
  height: 22px;
  width: auto;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, background 0.15s;
}

.icon-btn:active {
  opacity: 0.6;
}

.icon-btn--sm {
  padding: 6px;
}

/* ── Buttons ── */
/* Primary: solid fill. Secondary: same size, transparent + light border.
   Scale: compact (toolbar) → default → prominent (auth, key flows). */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: 8px;
  color: var(--bg);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 12px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}

.btn-primary:active:not(:disabled):not(.btn--disabled) {
  opacity: 0.85;
}

.btn-primary:disabled,
.btn-primary.btn--disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary--compact {
  padding: 6px 12px;
}

.btn-primary--prominent {
  padding: 16px 24px;
  font-size: 11px;
  letter-spacing: 0.1em;
  border-radius: 12px;
  min-height: 50px;
}

.btn-primary--block {
  width: 100%;
}

.modal-actions .btn-primary {
  padding: 14px 16px;
  border-radius: 10px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 12px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.btn-secondary:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.04);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-secondary--compact {
  padding: 6px 12px;
}

.btn-secondary--block {
  width: 100%;
}

.modal-actions .btn-secondary {
  padding: 14px 16px;
  border-radius: 10px;
}

.btn-primary svg,
.btn-secondary svg,
.small-btn svg,
.icon-btn svg,
.device-refresh-btn svg {
  flex-shrink: 0;
}

/* ── Global button hover (pointer devices) ── */

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled):not(.btn--disabled),
  .btn-primary:focus-visible:not(:disabled):not(.btn--disabled) {
    background: #e8e8e8;
    border-color: #e8e8e8;
    opacity: 1;
  }

  .btn-secondary:hover:not(:disabled),
  .btn-secondary:focus-visible:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.42);
  }

  .icon-btn:hover:not(:disabled),
  .icon-btn:focus-visible:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
  }

  .small-btn:hover:not(:disabled),
  .small-btn:focus-visible:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.22);
    color: var(--text);
  }

  .text-btn:hover:not(:disabled),
  .text-btn:focus-visible:not(:disabled) {
    color: var(--text);
    opacity: 0.85;
  }

  .tab:hover:not(.tab--active),
  .tab:focus-visible:not(.tab--active) {
    color: var(--text);
  }

  .nav-item:hover:not(.nav-item--active),
  .nav-item:focus-visible:not(.nav-item--active) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
  }

  .nav-midi-status-btn:hover:not(.nav-midi-status-btn--active),
  .nav-midi-status-btn:focus-visible:not(.nav-midi-status-btn--active) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
  }

  .account-btn--rail:hover,
  .account-btn--rail:focus-visible {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
  }

  .account-btn--rail:hover .account-avatar,
  .account-btn--rail:focus-visible .account-avatar {
    filter: none;
  }

  .account-btn--rail:hover .account-avatar--guest,
  .account-btn--rail:focus-visible .account-avatar--guest {
    border-color: var(--border);
  }

  .knob-lock:hover:not(:disabled),
  .knob-lock:focus-visible:not(:disabled) {
    color: var(--text-secondary);
    opacity: 0.9;
  }

  .knob-lock--on:hover:not(:disabled),
  .knob-lock--on:focus-visible:not(:disabled) {
    color: var(--border-active);
  }

  .patch-row:hover,
  .patch-row:focus-visible {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
  }

  .patch-row-heart:hover,
  .patch-row-menu-btn:hover,
  .patch-row-heart:focus-visible,
  .patch-row-menu-btn:focus-visible {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
  }

  .patch-card-menu-btn:hover:not(:disabled),
  .patch-card-menu-btn:focus-visible:not(:disabled) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
  }

  .patch-menu-item:hover,
  .patch-menu-item:focus-visible {
    background: rgba(255, 255, 255, 0.06);
  }

  .bank-card-menu:hover,
  .bank-card-menu:focus-visible {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
  }

  .device-refresh-btn:hover:not(:disabled),
  .device-refresh-btn:focus-visible:not(:disabled) {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.05);
  }

  .ch-btn:hover:not(:disabled):not(.ch-btn--active),
  .ch-btn:focus-visible:not(:disabled):not(.ch-btn--active) {
    border-color: rgba(255, 255, 255, 0.28);
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
  }

  .action-btn:hover:not(:disabled):not(.action-btn--active),
  .action-btn:focus-visible:not(:disabled):not(.action-btn--active) {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.22);
  }

  .device-slot:hover:not(:disabled),
  .device-slot:focus-visible:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.04);
  }

  .device-slot--empty:hover:not(:disabled),
  .device-slot--empty:focus-visible:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.16);
  }

  .midi-output-row:hover:not(.midi-output-row--active),
  .midi-output-row:focus-visible:not(.midi-output-row--active) {
    border-color: rgba(255, 255, 255, 0.22);
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
  }

  .history-entry:hover:not(.history-entry--preview):not(.history-entry--current),
  .history-entry:focus-visible:not(.history-entry--preview):not(.history-entry--current) {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.02);
  }

  .modal-action--destructive:hover:not(:disabled),
  .modal-action--destructive:focus-visible:not(:disabled) {
    background: rgba(224, 128, 128, 0.08);
    border-color: rgba(224, 128, 128, 0.55);
  }
}

/* ── Patch card ── */

.patch-card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: var(--space-stack-tight);
  margin: 0 var(--page-header-px);
}

.patch-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.patch-new-btn {
  height: 100%;
  aspect-ratio: 1;
  width: auto;
  padding: 0;
  border-radius: 12px;
  justify-self: end;
}

.patch-card-icon {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.patch-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.patch-card-primary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 1 260px;
  min-width: 140px;
  max-width: 300px;
}

.patch-card-heading {
  flex: 1;
  min-width: 0;
}

.patch-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.patch-name {
  font-size: 15px;
  font-weight: 500;
  cursor: text;
  border-radius: 4px;
  padding: 2px 6px;
  margin: -2px -6px;
  outline: none;
}

.patch-name:hover,
.patch-name:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.patch-name-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-active);
  border-radius: 6px;
  padding: 2px 8px;
  outline: none;
}

.editor-chrome--disabled .patch-name,
.editor-chrome--disabled .patch-edit-btn,
.editor-chrome--disabled .patch-new-btn,
.editor-chrome--disabled .patch-save-btn,
.editor-chrome--disabled .patch-card-menu-btn {
  pointer-events: none;
  opacity: 0.45;
}

.patch-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  -webkit-tap-highlight-color: transparent;
}

.patch-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  display: block;
}

/* ── Patch tags (editor patch card) ── */
.patch-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 1 1 120px;
  min-width: 0;
}

.patch-tags:empty {
  display: none;
}

.patch-tags-icon {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 4px 0 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 160px;
}

.tag-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.tag-chip-remove:hover,
.tag-chip-remove:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  outline: none;
}

.tag-input {
  flex: 1 1 72px;
  max-width: 160px;
  min-width: 72px;
  height: 22px;
  padding: 0 4px;
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text);
  background: none;
  border: none;
  border-bottom: 1px dashed transparent;
  outline: none;
}

.tag-input::placeholder {
  color: var(--text-muted);
}

.tag-input:focus {
  border-bottom-color: var(--border-active);
}

.tag-input:disabled {
  display: none;
}

.editor-chrome--disabled .patch-tags {
  pointer-events: none;
  opacity: 0.45;
}

.patch-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.patch-card-actions .btn-primary--compact,
.patch-card-actions .btn-secondary--compact {
  min-height: 30px;
  padding: 0 12px;
  line-height: 1;
}

.patch-card-menu-btn {
  color: var(--text-muted);
}

.patch-save-btn.btn--disabled,
.editor-chrome--disabled .patch-save-btn {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Tabs ── */

.tabs {
  display: flex;
  margin: var(--space-module) var(--page-header-px) 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.tab--active {
  color: var(--text);
}

.tab--active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--text);
}

/* ── Sections ── */

.editor-panel,
.history-panel,
.library-panel,
.device-panel,
.settings-panel {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  padding-bottom: var(--nav-clearance);
}

.library-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.library-content {
  flex: 1 1 auto;
  min-height: 0;
}

.editor-shell {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--nav-clearance);
}

.editor-shell .editor-panel,
.editor-shell .history-panel {
  flex: 0 0 auto;
  overflow: visible;
  min-height: auto;
  padding-bottom: 0;
}

.editor-chrome {
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  padding-bottom: var(--space-stack);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.editor-chrome > .tabs {
  margin-top: calc(var(--space-module) / 2);
}

.editor-chrome > .preview-banner {
  margin-top: var(--space-module);
}

.editor-panel--disabled {
  opacity: 0.85;
}

.editor-panel--disabled .knob {
  cursor: not-allowed;
}

.var-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.small-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.section {
  padding: var(--space-module) var(--page-header-px) 0;
}

.editor-panel > .section:first-child,
.history-panel > .section:first-child {
  padding-top: calc(var(--space-module) * 0.75);
}

.section--last {
  padding-bottom: var(--space-module);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-stack);
}

.section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.small-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 10px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.small-btn:active {
  background: var(--surface-raised);
  border-color: var(--border-active);
  color: var(--text);
}

.text-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}

.text-btn:active {
  opacity: 0.6;
}

/* ── Parameter groups ── */

.param-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-stack-tight);
}

.param-group {
  background: var(--param-group-bg);
  border: 1px solid var(--param-group-border);
  border-radius: 12px;
  padding: var(--space-stack) var(--space-stack-tight) var(--space-stack);
}

.param-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-stack-tight);
  min-height: 36px;
  margin-bottom: var(--space-stack);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.param-group-header .param-group-label {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.param-group-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.param-group--disabled .knob-grid {
  opacity: 0.35;
  pointer-events: none;
}

.param-group-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.param-group-switch-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.toggle-switch {
  flex-shrink: 0;
  position: relative;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-switch--on {
  background: var(--border-active);
  border-color: var(--border-active);
}

.toggle-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s;
}

.toggle-switch--on .toggle-switch-thumb {
  transform: translateX(18px);
}

.param-group .knob-grid {
  margin-top: 0;
}

/* ── Knobs ── */

.knob-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 4px;
}

.knob-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 8px;
}

.knob-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
}

.knob-cell--locked .knob-ring {
  border-color: color-mix(in srgb, var(--border-active) 45%, transparent);
}

.knob-stack {
  position: relative;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
}

.knob-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 100%;
  min-width: 0;
}

.knob-lock {
  position: absolute;
  top: -8px;
  right: -9px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, opacity 0.2s;
}

/* Locks are quiet by default — only surface on hover/focus, or when actually locked */
.knob-lock {
  opacity: 0;
}

.knob-lock--on,
.knob-cell:hover .knob-lock,
.knob-lock:focus-visible {
  opacity: 1;
}

.knob-lock--on {
  color: var(--border-active);
}

.knob-lock-icon {
  display: block;
  flex-shrink: 0;
  width: 14.4px;
  height: 14.4px;
}

.knob-lock-body {
  transition: fill 0.2s, fill-opacity 0.2s;
}

.knob-lock--on .knob-lock-body {
  fill: currentColor;
  fill-opacity: 0.28;
}

.knob-lock-shackle {
  transform-origin: 10.5px 6.5px;
  transform: scaleY(0.22);
  transition: transform 0.25s cubic-bezier(0.34, 1.25, 0.64, 1);
}

.knob-lock--on .knob-lock-shackle {
  transform: scaleY(1);
}

@media (prefers-reduced-motion: reduce) {
  .knob-lock-shackle,
  .knob-lock-body,
  .knob-lock {
    transition: none;
  }
}

.knob-label {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-align: center;
}

.knob {
  position: relative;
  width: 56px;
  height: 56px;
  cursor: ns-resize;
  touch-action: none;
}

.knob-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1.5px solid #444;
  position: relative;
}

/* Value fill: an accent arc swept over the 270° travel (-135°..+135°),
   matching valueToAngle(). Masked to a thin outer band so it reads as a ring. */
.knob-ring::before {
  content: '';
  position: absolute;
  inset: -1.5px;
  border-radius: 50%;
  background: conic-gradient(from 225deg,
    var(--border-active) 0deg,
    var(--border-active) calc(var(--knob-pct, 50) * 2.7deg),
    transparent calc(var(--knob-pct, 50) * 2.7deg));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  pointer-events: none;
}

.knob-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.5px;
  height: 22px;
  background: var(--text);
  transform-origin: center bottom;
  transform: translate(-50%, -100%) rotate(0deg);
  border-radius: 1px;
}

.knob-value {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
}

/* ── Algorithm buttons ── */

.algorithm-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-stack);
}

.algorithm-row .var-btn--auto {
  flex: 0 0 auto;
  min-width: 0;
  padding: 11px 16px;
  font-size: 11px;
  letter-spacing: 0.08em;
}

/* ── Variation ── */

.variation-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-stack);
}

.variation-row .var-btn {
  font-size: 14px;
  letter-spacing: 0.04em;
  padding: 13px 0;
}

.var-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.48);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 11px 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.var-btn:hover:not(:disabled):not(.var-btn--active) {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.72);
}

.var-btn--active {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.55);
  color: var(--text);
}

.var-btn--active:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.17);
  border-color: rgba(255, 255, 255, 0.65);
}

/* ── Global controls ── */

.global-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.global-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.global-label {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-align: center;
}

.global-label--sub {
  color: var(--text-muted);
  margin-top: -4px;
}

.global-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}

.action-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 12px 20px;
  margin-top: 4px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
  background: var(--surface-raised);
}

.action-btn--active {
  border-color: var(--border-active);
  color: var(--border-active);
}

/* ── Slider ── */

.slider-wrap {
  width: 100%;
  padding: 8px 4px 0;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

/* ── Bottom nav / side rail ── */

.nav-brand {
  display: none;
}


.bottom-nav {
  order: 99;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: none;
  display: flex;
  gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: rgba(20, 20, 20, 0.96);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0;
  box-shadow: none;
  z-index: 100;
}

.nav-items {
  display: flex;
  flex: 1;
  gap: 4px;
  min-width: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 8px 0 6px;
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, background 0.15s;
}

.nav-item:hover,
.nav-item:focus-visible {
  color: var(--text);
}

.nav-item--active {
  color: var(--text);
}

.nav-item svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  padding: 4px;
  border-radius: 8px;
  box-sizing: content-box;
}

.nav-item--active svg {
  background: rgba(255, 255, 255, 0.1);
}

.nav-midi-status.hidden {
  display: none;
}

.nav-midi-status--header {
  flex: 0 0 auto;
  margin-left: auto;
  transition: max-width 0.2s ease;
}

.nav-midi-status--header:has(.nav-midi-status-btn--connected) {
  flex: 1 1 auto;
  min-width: 0;
  max-width: min(240px, 52vw);
}

.nav-midi-status--header .nav-midi-status-btn {
  padding: 4px 8px;
  gap: 6px;
  border-radius: 8px;
  transition: width 0.2s ease, padding 0.2s ease;
}

.nav-midi-status--header .nav-midi-status-btn--connected {
  width: 100%;
}

.nav-midi-status--header .nav-midi-status-btn--disconnected,
.nav-midi-status--header .nav-midi-status-btn--unsupported {
  width: auto;
}

.nav-midi-status--header .nav-midi-status-label {
  font-size: 11px;
}

.nav-midi-status--header .nav-midi-status-detail {
  font-size: 9px;
}

@media (max-width: 767px) {
  .nav-midi-status--rail {
    display: none !important;
  }
}

.nav-midi-status-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, background 0.15s;
}

.nav-midi-status-btn--active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.nav-midi-status-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.nav-midi-status-copy--inline {
  flex-direction: row;
  align-items: center;
  flex: 0 1 auto;
  gap: 6px;
}

.nav-midi-status-copy--inline .nav-midi-status-action::before {
  content: '·';
  margin-right: 6px;
  color: var(--text-secondary);
  font-weight: 400;
}

.nav-midi-status-label {
  font-weight: 500;
  line-height: 1.2;
}

.nav-midi-status-detail {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-midi-status-action {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 500;
  color: var(--text);
}

.nav-midi-status-btn--connected .nav-midi-status-label {
  color: var(--text);
}

.nav-midi-status-btn--disconnected .nav-midi-status-label,
.nav-midi-status-btn--unsupported .nav-midi-status-label {
  color: var(--text-secondary);
}

.icon-btn--active {
  color: var(--border-active);
}

.settings-page-header,
.page-header {
  flex-shrink: 0;
  padding: var(--page-header-pt) var(--page-header-px) var(--page-header-gap);
}

.page-header--split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-stack) var(--space-stack-tight);
  flex-wrap: wrap;
}

.page-header--split .page-title {
  flex: 1 1 auto;
  min-width: 0;
}

.page-header--split .library-toolbar-actions {
  flex-shrink: 0;
  margin-left: auto;
}

.settings-page-title,
.page-title {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: var(--page-title-size);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

.settings-content {
  padding: 0 var(--page-header-px) var(--space-module);
  display: flex;
  flex-direction: column;
  gap: var(--space-module);
}

/* ── Preview banner ── */

.preview-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-stack-tight);
  margin: 0 var(--page-header-px);
  padding: var(--space-stack-tight) var(--space-stack);
  background: var(--surface-raised);
  border: 1px solid var(--border-active);
  border-radius: 10px;
}

.preview-banner-text {
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
}

.preview-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Version history ── */

.history-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-2);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-module);
  margin-top: var(--space-module);
}

.history-date-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.history-date-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.history-entry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.history-entry:active {
  opacity: 0.85;
}

.history-entry--preview,
.history-entry--current {
  border-color: var(--border-active);
}

.history-entry-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-entry-time {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.history-entry-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.history-entry-summary {
  font-size: 12px;
  color: var(--text-secondary);
}

.history-entry-changes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-entry-change {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 3px 7px;
  line-height: 1.35;
}

.history-empty {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 20px;
}

/* ── Library ── */

.library-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-stack);
  padding: 0 var(--page-header-px) var(--space-stack);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.library-search-row {
  display: flex;
  gap: var(--space-stack-tight);
  align-items: stretch;
}

.library-search-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}

.library-search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.38);
  pointer-events: none;
  transition: color 0.15s;
}

.library-search-wrap:focus-within .library-search-icon {
  color: rgba(255, 255, 255, 0.55);
}

.library-search {
  width: 100%;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.18);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 11px 36px 11px 38px;
  outline: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.library-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.library-search::-moz-search-clear-button {
  display: none;
}

.library-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.library-search-clear[hidden] {
  display: none;
}

.library-search-clear:hover,
.library-search-clear:focus-visible {
  color: var(--text);
  outline: none;
}

.library-search:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.18);
}

.library-search:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.library-search::placeholder {
  color: var(--text-muted);
}

/* ── Library filter (All / Favorites) ── */

.library-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.library-filter {
  display: inline-flex;
  flex-shrink: 0;
  align-items: stretch;
  gap: 2px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  box-sizing: border-box;
}

.library-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.library-filter-btn .library-filter-heart {
  display: inline-flex;
  opacity: 0.7;
  transition: opacity 0.15s, color 0.15s;
}

.library-filter-btn--active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.library-filter-btn--active[data-filter="favorites"] .library-filter-heart {
  color: var(--border-active);
  opacity: 1;
}

@media (max-width: 720px) {
  .page-header--split .library-toolbar-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (hover: hover) and (pointer: fine) {
  .library-filter-btn:hover:not(.library-filter-btn--active) {
    color: var(--text);
  }
}

/* Favorites empty state */
.library-empty--favorites {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  margin: var(--space-module-loose) auto 0;
  max-width: 320px;
  color: var(--text-secondary);
}

.library-empty-heart {
  display: inline-flex;
  color: var(--text-muted);
  opacity: 0.7;
}

.library-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.library-empty-sub {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.library-content {
  padding: calc(var(--space-stack-relaxed) + var(--space-5)) var(--page-header-px) var(--space-module);
}

.library-content--error {
  padding: var(--space-stack-relaxed) var(--page-header-px);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.library-section {
  margin-top: var(--space-module);
}

.library-section:first-child {
  margin-top: 0;
}

.library-section > .section-label {
  display: block;
  margin-bottom: var(--space-stack);
}

.library-section--last {
  padding-bottom: var(--space-stack);
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-stack);
}

.section-header-row .section-label {
  margin-bottom: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.section-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.patch-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.patch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.patch-row--imported {
  border-color: var(--border-active);
}

.patch-row-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.patch-row-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.patch-row-primary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 1 260px;
  min-width: 140px;
  max-width: 300px;
}

.patch-row-heading {
  flex: 1;
  min-width: 0;
}

.patch-row-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.patch-row-sub {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.patch-row-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  flex: 1 1 120px;
  min-width: 0;
}

.patch-row-tag {
  max-width: 120px;
  padding: 1px 7px;
  font-family: var(--font-sans);
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-tap-highlight-color: transparent;
}

.patch-row-tag:hover,
.patch-row-tag:focus-visible {
  color: var(--text);
  border-color: var(--border-active);
  outline: none;
}

.patch-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.patch-row-time {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
}

.patch-row-heart,
.patch-row-menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.patch-row-heart--active {
  color: var(--border-active);
}

.bank-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.bank-scroll::-webkit-scrollbar {
  display: none;
}

.bank-card {
  flex: 0 0 140px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
}

.bank-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: auto;
}

.bank-card-icon {
  color: var(--text-secondary);
  display: flex;
}

.bank-card-menu {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
}

.bank-card-name {
  font-size: 13px;
  font-weight: 500;
  margin-top: 12px;
}

.bank-card-count {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.patch-menu {
  position: fixed;
  z-index: 200;
  min-width: 160px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.patch-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}

.patch-menu-item:active {
  background: var(--surface);
}

.patch-menu-item:disabled,
.patch-menu-item--disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.library-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: var(--space-stack-relaxed) 0;
  text-align: center;
}

.library-empty-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-stack-relaxed) var(--space-stack);
  min-height: 148px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.library-empty-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.library-empty-card-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 42ch;
}

.library-empty-card-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.library-empty-card-btn {
  margin-top: 6px;
}

.toast {
  position: fixed;
  bottom: var(--nav-clearance);
  left: 50%;
  transform: translateX(-50%);
  max-width: 380px;
  width: calc(100% - 32px);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  z-index: 150;
}

/* ── Device / MIDI panel ── */

.device-content {
  padding: 0 var(--page-header-px) var(--space-module);
  display: flex;
  flex-direction: column;
  gap: var(--space-module);
}

/* MIDI connection dot (nav status) */
.midi-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-midi-status-btn--connected .midi-dot {
  background: #6fcf6f;
  box-shadow: 0 0 8px #6fcf6f88;
}

.nav-midi-status-btn--disconnected .midi-dot {
  background: #e85d5d;
  box-shadow: 0 0 8px #e85d5d88;
}

.nav-midi-status-btn--unsupported .midi-dot {
  background: var(--text-muted);
}

/* Section layout */
.device-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-stack);
}

.device-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.device-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.device-refresh-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 9px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}

.device-refresh-btn:active {
  color: var(--text);
  border-color: var(--border-active);
}

.device-sync-btn {
  gap: 7px;
  padding: 9px 14px;
  font-size: 10px;
}

.device-sync-btn-icon {
  flex-shrink: 0;
}

.device-sync-btn--syncing .device-sync-btn-icon {
  animation: device-sync-spin 0.85s linear infinite;
}

@keyframes device-sync-spin {
  to { transform: rotate(360deg); }
}

.device-sync-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.midi-test-section {
  padding: var(--space-stack);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.device-section-header--stack {
  align-items: flex-start;
  gap: var(--space-stack);
}

.midi-test-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.midi-test-next {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.midi-test-btn {
  flex-shrink: 0;
  align-self: flex-start;
}

@media (max-width: 767px) {
  .device-section-header--stack {
    flex-direction: column;
    align-items: stretch;
  }

  .midi-test-btn {
    width: 100%;
    align-self: stretch;
  }
}

/* Output list */
.midi-output-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.midi-output-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 13px 14px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}

.midi-output-row--active {
  border-color: var(--border-active);
  color: var(--text);
}

.midi-output-name {
  font-family: var(--font-sans);
  font-size: 13px;
}

.midi-output-check {
  color: var(--border-active);
  flex-shrink: 0;
}

/* Channel grid */
.ch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 280px;
}

.ch-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 10px 0;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}

.ch-btn--active {
  border-color: var(--border-active);
  color: var(--text);
}

.device-slot-clear:hover {
  color: var(--text-secondary);
}

/* ── App modal ── */

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: min(80dvh, 560px);
  display: flex;
  flex-direction: column;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.modal-dialog--wide {
  max-width: 520px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.45;
}

.sync-slot-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
}

.sync-slot-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.sync-slot-list li:last-child {
  border-bottom: none;
}

.modal-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  cursor: pointer;
  user-select: none;
}

.modal-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--border-active);
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-action {
  width: 100%;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.modal-action--secondary {
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  padding: 8px;
}

.modal-action--secondary:hover,
.modal-action--secondary:focus-visible {
  color: var(--text);
}

.modal-action--destructive {
  background: var(--surface);
  border: 1px solid rgba(224, 128, 128, 0.35);
  border-radius: 10px;
  color: #e08080;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  padding: 14px 16px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.modal-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 4px;
}

.modal-list-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  padding: 12px 14px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s;
}

.modal-list-item:hover,
.modal-list-item:focus-visible {
  border-color: var(--border-active);
}

.modal-list-item-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.modal-list-item-heart {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--border-active);
}

.modal-list-group-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 14px 0 8px;
}

.modal-list-group-label:first-child {
  margin-top: 0;
}

.modal-list-group-label svg {
  color: var(--border-active);
}

.modal-list-item-name {
  font-size: 14px;
  font-weight: 500;
}

.modal-list-item-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.modal-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.modal-field-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.modal-field-input {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: background 0.15s, border-color 0.15s;
}

.modal-field-input:hover:not(:focus):not(.modal-field-input--error) {
  background: var(--hover-surface);
  border-color: var(--hover-border);
}

.modal-field-input:focus {
  border-color: var(--border-active);
}

.modal-field-input--error {
  border-color: rgba(224, 128, 128, 0.65);
}

.modal-field-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.45;
  font-weight: 400;
}

.modal-field-optional {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.modal-field-error {
  font-size: 12px;
  color: #e08080;
  margin: -10px 0 12px;
  line-height: 1.4;
}

.modal-radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-radio {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.modal-radio:has(input:checked) {
  color: var(--text);
}

.modal-radio input {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.modal-radio input:checked {
  border-color: var(--border-active);
  background: var(--border-active);
  box-shadow: inset 0 0 0 3px var(--surface-raised);
}

.modal-radio input:focus-visible {
  outline: 1px solid rgba(255, 255, 255, 0.3);
  outline-offset: 2px;
}

.contact-form fieldset.modal-field {
  border: none;
  margin: 0 0 16px;
  padding: 0;
}

.contact-form fieldset.modal-field .modal-field-label {
  margin-bottom: 6px;
}

@media (min-width: 768px) {
  .modal {
    align-items: center;
    padding-bottom: 16px;
  }
}

@media (min-width: 480px) {
  .ch-grid {
    grid-template-columns: repeat(8, 1fr);
    max-width: 360px;
  }
}

/* Action buttons */
.device-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 14px 12px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.action-btn:active {
  background: var(--surface);
}

.action-btn--active {
  border-color: var(--border-active);
  color: var(--border-active);
}

.device-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Device user slots ── */

.device-hint--tight {
  margin-top: calc(var(--space-2) - var(--space-stack));
}

.device-hint--note {
  margin-top: var(--space-stack);
  padding-top: var(--space-stack);
  border-top: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.55;
}

.device-slot-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.device-slot-grid--modal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.device-slot--picker {
  min-height: 76px;
}

.device-slot--picker:hover,
.device-slot--picker:focus-visible {
  border-color: var(--border-active);
  background: var(--surface);
}

.assign-modal-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0 4px;
  text-align: center;
}

.assign-modal-state .modal-hint {
  margin: 0;
}

.assign-modal-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  color: var(--text-muted);
}

.assign-modal-spinner svg {
  width: 28px;
  height: 28px;
  animation: device-sync-spin 0.85s linear infinite;
}

.assign-modal-success-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  color: var(--accent);
}

.assign-modal-state--error .modal-hint {
  color: var(--text-muted);
}

.assign-modal-state .modal-action {
  width: 100%;
  margin-top: 4px;
}

.device-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 88px;
  padding: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.12s, background 0.12s;
}

.device-slot:active {
  background: var(--surface);
}

.device-slot--occupied {
  border-color: color-mix(in srgb, var(--border-active) 35%, transparent);
}

/* Empty slots recede so assigned patches read as the foreground. */
.device-slot--empty {
  background: var(--surface);
  border-style: dashed;
  border-color: #2c2c2c;
}

.device-slot--empty .device-slot-num {
  color: var(--text-muted);
}

.device-slot-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.device-slot-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-slot--empty .device-slot-name {
  color: var(--text-muted);
  font-weight: 400;
}

.device-slot-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* PC number is a power-user footnote, not a peer of the slot name. */
.device-slot-pc {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  opacity: 0.65;
}

.device-slot-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: color 0.12s;
}

.device-slot-clear:hover {
  color: var(--text-secondary);
}

@media (min-width: 768px) {
  .device-slot-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* MIDI log */
.midi-log {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-height: 220px;
  overflow-y: auto;
}

.midi-log-empty {
  padding: 14px;
  font-size: 12px;
  color: var(--text-muted);
}

.midi-log-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.midi-log-row:last-child { border-bottom: none; }

.midi-log-row--unsent {
  opacity: 0.4;
}

.midi-log-hex {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--border-active);
  flex-shrink: 0;
  min-width: 72px;
}

.midi-log-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Placeholder ── */

.hidden {
  display: none;
}

.placeholder-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.placeholder-text {
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Desktop layout ── */

@media (min-width: 768px) {
  :root {
    --rail-width: 272px;
    --nav-clearance: 0px;
    --content-max: 960px;
    --app-body-max: 960px;
  }

  body {
    background: var(--bg);
  }

  .mobile-splash {
    display: none;
  }

  .legal-disclaimer--mobile {
    display: none;
  }

  .app {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    max-width: none;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    min-height: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
    box-sizing: border-box;
  }

  .top-bar {
    display: none;
  }

  .nav-midi-status--header {
    display: none !important;
  }

  .app-shell {
    flex: 1;
    flex-direction: row;
    align-items: stretch;
    gap: 16px;
    min-height: 0;
    padding: 16px;
    overflow: hidden;
  }

  .nav-brand {
    display: block;
    padding: 0 18px var(--space-stack-relaxed);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 14px;
  }

  .nav-brand .brand-lockup {
    line-height: 0;
    align-items: center;
  }

  /* Horizontal lockup: boxed logo + "Microcosm Editor" to the right (matches Figma frame) */
  .nav-brand .brand-logo-stack {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    line-height: normal;
  }

  .nav-brand .brand-tagline {
    display: flex;
    flex-direction: column;
    width: auto;
    max-width: 118px;
    margin-top: 0;
    padding-left: 0;
    text-align: left;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: #fff;
    line-height: 1.08;
  }

  .brand-tagline-line {
    display: block;
  }

  .nav-brand .brand-tagline-beta {
    color: rgba(255, 255, 255, 0.5);
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
  }

  /* Beta pill is not part of the lockup frame; keep the rail clean */
  .nav-brand .brand-beta {
    display: none;
  }

  .nav-brand .brand-logo {
    height: 30px;
    width: auto;
  }

  .bottom-nav {
    order: 0;
    position: relative;
    top: auto;
    left: auto;
    bottom: auto;
    transform: none;
    flex-shrink: 0;
    width: var(--rail-width);
    max-width: var(--rail-width);
    height: 100%;
    max-height: 100%;
    align-self: stretch;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 22px 18px;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    flex-wrap: nowrap;
  }

  .nav-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
  }

  .nav-midi-status--rail {
    margin-top: auto;
    flex: 0 0 auto;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .nav-midi-status-btn {
    gap: 12px;
    padding: 12px 14px;
    font-size: 14px;
    border-radius: 12px;
  }

  .nav-midi-status-detail {
    font-size: 12px;
  }

  .nav-midi-status-action {
    font-size: 13px;
  }

  .nav-item {
    flex: 0;
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    padding: 12px 14px;
    font-size: 14px;
    letter-spacing: 0.02em;
    text-align: left;
    width: 100%;
  }

  .nav-item svg {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 5px;
    border-radius: 9px;
  }

  .nav-item--active {
    background: rgba(255, 255, 255, 0.08);
  }

  .nav-item--active svg {
    background: rgba(255, 255, 255, 0.1);
  }

  .app-body {
    flex: 1 1 0;
    width: 100%;
    max-width: var(--app-body-max);
    margin: 0 auto;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .app-footer {
    display: block;
    flex-shrink: 0;
    margin-top: auto;
    padding: var(--space-stack) 24px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }

  .tabs {
    margin-left: var(--page-header-px);
    margin-right: var(--page-header-px);
  }

  .preview-banner {
    margin-left: var(--page-header-px);
    margin-right: var(--page-header-px);
  }

  .section {
    padding-left: var(--page-header-px);
    padding-right: var(--page-header-px);
  }

  :root {
    --page-header-pt: 20px;
    --page-header-px: 24px;
  }

  .library-toolbar {
    padding: 0 var(--page-header-px) var(--space-stack);
  }

  .page-header,
  .settings-page-header {
    max-width: var(--content-max);
  }

  .library-panel {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .library-content {
    padding: calc(var(--space-stack-relaxed) + var(--space-5)) var(--page-header-px) var(--space-module);
    max-width: var(--content-max);
  }

  .editor-panel .section,
  .history-panel .section {
    max-width: var(--content-max);
  }

  .param-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-stack-tight);
  }

  .device-panel .device-content,
  .settings-panel .settings-content {
    max-width: var(--content-max);
    padding-left: 24px;
    padding-right: 24px;
  }

  .device-panel .page-header,
  .settings-panel .page-header,
  .settings-panel .settings-page-header {
    max-width: var(--content-max);
  }

  .toast {
    bottom: 24px;
    left: auto;
    right: 24px;
    transform: none;
    max-width: 360px;
  }
}

@media (min-width: 1100px) {
  .param-groups {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ─── Onboarding ──────────────────────────────────────────────────────────── */
body.onboarding-open { overflow: hidden; }

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 1;
  transition: opacity 0.2s ease;
}
.onboarding.is-leaving { opacity: 0; }

.onboarding-sheet {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.onboarding-brandline {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  line-height: 0;
}

.onboarding-brandline-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1;
}

.onboarding-brandline-logo {
  display: block;
  height: 22px;
  width: auto;
}

.onboarding-viewport { overflow: hidden; }
.onboarding-track {
  display: flex;
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.onboarding-card {
  flex: 0 0 100%;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 8px 4px;
}
.onboarding-connect {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 8px 4px;
}

.onboarding-card-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--border-active);
  margin-bottom: 4px;
}
.onboarding-card-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--border-active);
}
.onboarding-card-title {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  margin: 0;
}
.onboarding-card-body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
  max-width: 30ch;
}

.onboarding-card-note {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 8px 0 0;
  max-width: 30ch;
}

.onboarding-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.onboarding-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s, width 0.2s;
}
.onboarding-dot.is-active {
  width: 18px;
  border-radius: 3px;
  background: var(--border-active);
}

.onboarding-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.onboarding-actions .btn-primary {
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 11px;
}
.onboarding-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 6px 10px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.onboarding-link:hover,
.onboarding-link:focus-visible { color: var(--text); }

/* ─── Onboarding channel grid ─────────────────────────────────────────────── */
.onboarding-ch-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}
.onboarding-ch-btn {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 9px 4px;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.onboarding-ch-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}
.onboarding-ch-btn.is-active {
  background: var(--border-active);
  border-color: var(--border-active);
  color: var(--bg);
}

@media (min-width: 768px) {
  .onboarding {
    align-items: center;
    padding: 24px;
  }
}

/* ─── Coachmarks ──────────────────────────────────────────────────────────── */
.coach-layer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}
.coach-spotlight {
  position: absolute;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72);
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
  transition: left 0.2s, top 0.2s, width 0.2s, height 0.2s;
  pointer-events: none;
}
.coach-tooltip {
  position: absolute;
  width: min(280px, calc(100vw - 24px));
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}
.coach-title {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
}
.coach-body {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

.coach-note {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  line-height: 1.45;
  color: var(--text-muted);
  margin: -6px 0 12px;
}

.coach-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.coach-foot-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-end {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Auth overlay ── */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-overlay.hidden { display: none; }

.auth-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.auth-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
}
.auth-close:hover { color: var(--text); background: var(--surface-raised); }

.auth-title {
  font-size: 19px;
  font-weight: 600;
  margin-bottom: 4px;
}
.auth-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.45;
}

.auth-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px;
  background: #ffffff;
  color: #1f1f1f;
  border: none;
  border-radius: 9px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.auth-google:hover { background: #f1f1f1; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.auth-field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}

.auth-field input:hover:not(:focus) {
  background: var(--hover-surface);
  border-color: var(--hover-border);
}

.auth-field input:focus {
  outline: none;
  border-color: var(--border-active);
}

.auth-pw-wrap { position: relative; display: flex; }
.auth-pw-wrap input { padding-right: 40px; }
.auth-pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
.auth-pw-toggle:hover { color: var(--text); }

.auth-meter {
  display: block;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-raised);
  overflow: hidden;
}
.auth-meter-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: #e0564f;
  transition: width 0.2s ease, background 0.2s ease;
}
.auth-meter-fill[data-score="2"] { background: #e0a84f; }
.auth-meter-fill[data-score="3"] { background: #cdd44a; }
.auth-meter-fill[data-score="4"] { background: #5ec46a; }

.auth-hint { font-size: 11px; color: var(--text-muted); }
.auth-error { font-size: 11px; color: #e0564f; }
.auth-error:empty { display: none; }
.auth-form-error { font-size: 12px; color: #e0564f; }
.auth-form-error:empty { display: none; }

.auth-submit {
  width: 100%;
  margin-top: 8px;
}

.auth-switch {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
}
.auth-switch button {
  background: none;
  border: none;
  color: var(--border-active);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}
.auth-switch button:hover { text-decoration: underline; }

.auth-notice { text-align: center; padding: 8px 0; }
.auth-notice-icon { color: var(--border-active); margin-bottom: 12px; }
.auth-notice .auth-sub { margin-bottom: 18px; }

/* Header account control */
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.account-btn:hover { border-color: var(--border-active); }
.account-btn svg { flex-shrink: 0; }

/* Avatar circle, always — drop the pill chrome entirely. An optional text
   label sits beside it (shown only on the desktop rail instance, see below). */
.account-btn--avatar {
  padding: 0;
  gap: 9px;
  background: none;
  border: none;
  border-radius: 999px;
}
.account-btn--avatar:hover { border: none; }

.account-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--border-active);
  color: #1a1626;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  line-height: 0;
}

.account-avatar svg {
  display: block;
  flex-shrink: 0;
  margin: 0;
}

.account-avatar--guest svg {
  transform: translateY(-0.5px);
}
.account-btn--avatar:hover .account-avatar { filter: brightness(1.08); }

/* Signed-out: same circle treatment, neutral fill + person icon instead of
   an initial. */
.account-avatar--guest {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  box-sizing: border-box;
}
.account-btn--avatar:hover .account-avatar--guest { border-color: var(--border-active); filter: none; }

/* Rail sign-in: light neutral hover on the row + avatar (no brand accent). */
.account-btn--rail:hover .account-avatar--guest,
.account-btn--rail:focus-visible .account-avatar--guest {
  border-color: var(--hover-border);
  background: var(--hover-surface);
  color: var(--text);
}

.account-btn--rail:hover .account-avatar,
.account-btn--rail:focus-visible .account-avatar {
  filter: none;
}

.account-btn--rail:hover .account-avatar:not(.account-avatar--guest),
.account-btn--rail:focus-visible .account-avatar:not(.account-avatar--guest) {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

/* Text label beside the avatar — desktop rail only (see .account-btn--rail
   below); hidden on the mobile/top-bar instance so it's avatar-only there. */
.account-label {
  display: none;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Rail account control: hidden on mobile (lives in the top bar there),
   shown at the bottom of the desktop left rail with its label revealed. */
.account-btn--rail { display: none; }
@media (min-width: 768px) {
  .account-btn--rail:not(.hidden) { display: flex; }
  .account-btn--rail {
    align-self: stretch;
    width: 100%;
    margin-top: 4px;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: left;
    transition: color 0.15s, background 0.15s;
  }
  .account-btn--rail.account-btn--avatar:hover {
    border: none;
  }
  .account-btn--rail .account-label {
    display: inline-block;
    min-width: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
  }
}

.account-menu {
  position: absolute;
  z-index: 1001;
  min-width: 200px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.account-menu-email {
  padding: 8px 10px 6px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  word-break: break-all;
}
.account-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
}
.account-menu-item:hover { background: var(--nav-active-bg); }
