.effects-column .matrix-panel {
  margin-top: auto !important; /* Push to bottom using flexbox - effects-column already has display: flex */
  margin-bottom: 0;
}

/* Modulation Matrix Styles */
.mod-matrix {
  user-select: none;
  margin-left: 0; /* Reset, panel handles positioning now */
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mod-matrix-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 6px;
  position: relative;
}

.mod-matrix h3 {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-primary, #e0e0e0);
  margin: 0;
  text-align: left;
  padding-left: 8px;
  position: relative;
  appearance: none;
  -webkit-appearance: none; 
  -moz-appearance: none;
}

.mod-matrix-pagination {
  display: flex;
  gap: 4px;
  align-items: center;
}

.mod-matrix-page-btn {
  background: rgba(26, 26, 26, 0.9);
  color: var(--text-secondary);
  border: none;
  border-radius: 2px;
  padding: 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  transition: transform 0.15s ease, background 0.15s ease;
  min-width: 16px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  outline: none;
}

.mod-matrix-page-btn:hover {
  background: rgba(26, 26, 26, 1);
  transform: translateY(-1px);
}

.mod-matrix-page-indicator {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 10px;
  color: var(--page-accent, var(--text-secondary, #a0a0a0));
  min-width: 60px;
  text-align: center;
  text-transform: uppercase;
  font-weight: 500;
  letter-spacing: 0.5px;
  padding-top: 2px;
}

/* Scroll container for custom scrollbar */
.mod-matrix-scroll-container {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

/* Grid layout for paginated matrix - 4 columns per page */
.mod-matrix-grid-wrapper {
  overflow-y: auto; /* Scrollable but native scrollbar hidden via CSS */
  overflow-x: hidden;
  height: 140px; /* Fixed height: header (~20px) + 3 source rows (3 * 42px = 126px) = 146px, using 140px to ensure only 3 rows visible */
  flex: 1;
  position: relative; /* Create stacking context for sticky headers */
  /* Ensure content is clipped - prevent overflow above scroll container */
  overflow-clip-margin: 0;
  /* Hide native scrollbar */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.mod-matrix-grid-wrapper::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

/* Custom scrollbar */
.mod-matrix-scrollbar {
  width: 4px;
  height: 116px;
  margin-top: 24px;
  display: none; /* Hidden by default, shown when needed */
  flex-shrink: 0;
}

.mod-matrix-scrollbar-track {
  width: 100%;
  height: 100%;
  background: transparent;
  position: relative;
  cursor: pointer;
  border: 1px solid rgba(160, 160, 160, 0.15); /* Faint outer delineation */
  border-radius: 2px;
  box-sizing: border-box;
}

.mod-matrix-scrollbar-thumb {
  position: absolute;
  width: calc(100% - 2px); /* Account for border */
  left: 1px; /* Center within border */
  background: var(--scrollbar-color, rgba(201, 201, 201, 0.3));
  border-radius: 2px;
  cursor: grab;
  transition: background 0.2s;
  min-height: 20px;
}

.mod-matrix-scrollbar-thumb:hover {
  background: var(--scrollbar-color-hover, rgba(201, 201, 201, 0.5));
}

.mod-matrix-scrollbar-thumb:active {
  cursor: grabbing;
  background: var(--scrollbar-color-hover, rgba(201, 201, 201, 0.7));
}

.mod-matrix-grid {
  display: grid;
  grid-template-columns: auto repeat(4, 45px);
  gap: 0px;
  column-gap: 0px;
  row-gap: 0px;
  align-items: center;
  justify-items: center;
  width: fit-content;
  /* Add padding-top to account for sticky header row */
  padding-top: 0;
}

/* Make first row (empty cell + headers) sticky */
.mod-matrix-grid > div:first-child {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel-bg);
  padding-bottom: 6px;
  padding: 11px 20px;
}

/* FX Matrix grid layout - 6 columns matching main matrix */
.fx-matrix-grid {
  display: grid;
  grid-template-columns: auto repeat(6, 45px); /* Narrower columns */
  gap: 0px;
  column-gap: 0px;
  row-gap: 0px;
  align-items: center;
  justify-items: center;
  width: fit-content;
}

/* Header row (column labels) */
.mod-matrix-header {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 9px;
  font-weight: 500;
  color: var(--header-color, rgba(201, 201, 201, 0.65));
  text-align: center;
  padding-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel-bg);
  margin-bottom: 0;
  will-change: transform;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  padding: 5px 4px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.mod-matrix-header.placeholder-dest {
  color: rgba(128, 128, 128, 0.5); /* Grayed out for placeholders */
  font-style: italic;
  cursor: not-allowed;
  text-decoration: line-through;
  opacity: 0.5;
}

/* Source row labels */
.mod-matrix-source {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 9px;
  font-weight: 500;
  color: var(--text-secondary, #a0a0a0);
  padding-right: 10px;
  text-align: right;
  letter-spacing: 1px;
}

/* Rectangular cell for modulation values */
.mod-matrix-cell {
  position: relative;
  height: 30px;
  width: 100%;
  max-width: 100%;
  margin: 0;
  background-color: var(--slider-bg, var(--surface, #232323));
  overflow: visible; /* Changed from hidden to allow toggle button to overflow slightly */
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  user-select: none;
  transition: background 0.1s ease;
}

.mod-matrix-cell.placeholder-cell {
  opacity: 0.3;
  pointer-events: none;
  background-color: rgba(35, 35, 35, 0.5);
}

/* Diagonal black lines for negative values */
.mod-matrix-cell.negative {
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(0, 0, 0, 0.4) 4px,
    rgba(0, 0, 0, 0.4) 8px
  );
}

/* Unidirectional toggle button */
.mod-matrix-uni-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  font-size: 9px;
  line-height: 9px;
  padding: 0;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: color 0.15s ease, opacity 0.15s ease;
  pointer-events: auto;
  opacity: 0;
}

/* Show toggle on cell hover and during dragging */
.mod-matrix-cell:hover .mod-matrix-uni-toggle,
.mod-matrix-cell.dragging .mod-matrix-uni-toggle {
  opacity: 1;
}

.mod-matrix-uni-toggle:hover {
  color: rgba(255, 255, 255, 1.0);
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
  opacity: 1;
}

.mod-matrix-uni-toggle.active {
  color: rgba(255, 255, 255, 1.0);
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
}

.mod-matrix-cell-value {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  pointer-events: auto;
  user-select: none;
  cursor: text;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.mod-matrix-cell:hover .mod-matrix-cell-value,
.mod-matrix-cell.dragging .mod-matrix-cell-value {
  opacity: 1;
}

/* Prevent text cursor during drag - use resize cursor instead */
.mod-matrix-cell.dragging .mod-matrix-cell-value {
  cursor: ns-resize !important;
}

/* Disable hover effects on other cells when dragging - must override hover state */
.mod-matrix-dragging .mod-matrix-cell:not(.dragging) {
  pointer-events: none;
}

.mod-matrix-dragging .mod-matrix-cell:not(.dragging):hover .mod-matrix-cell-value {
  opacity: 0 !important; /* Force hide even if hover state is active */
}

/* Prevent hover box-shadow on other cells during drag */
.mod-matrix-dragging .mod-matrix-cell:not(.dragging):hover {
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5) !important; /* Keep default shadow, no hover effect */
}

/* Force cursor to stay ns-resize on ALL cells during drag (prevents text cursor on hover) */
.mod-matrix-dragging .mod-matrix-cell .mod-matrix-cell-value {
  cursor: ns-resize !important;
}

/* Force cursor on cells themselves during drag */
.mod-matrix-dragging .mod-matrix-cell {
  cursor: ns-resize !important;
}

/* Hide toggle button on other cells during drag */
.mod-matrix-dragging .mod-matrix-cell:not(.dragging) .mod-matrix-uni-toggle {
  opacity: 0 !important;
}

/* Prevent toggle button hover effect on other cells during drag */
.mod-matrix-dragging .mod-matrix-cell:not(.dragging):hover .mod-matrix-uni-toggle {
  opacity: 0 !important;
}

.mod-matrix-dragging .mod-matrix-cell.dragging {
  pointer-events: auto;
}

.mod-matrix-dragging .mod-matrix-cell.dragging .mod-matrix-cell-value {
  opacity: 1 !important; /* Force show on dragged cell */
  cursor: ns-resize !important; /* Use resize cursor during drag, not text cursor */
}

.mod-matrix-cell-input {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  background: rgba(17, 17, 17, 0.95);
  border: 1px solid rgba(80, 80, 90, 0.8);
  border-radius: 2px;
  padding: 2px 4px;
  width: 45px;
  outline: none;
  display: none;
}

.mod-matrix-cell-input.editing {
  display: block;
}

.mod-matrix-cell:hover {
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.7);
}

/* ========== FX MATRIX SPECIFIC STYLES ========== */

.fx-matrix {
  user-select: none;
  margin-top: 0 !important;
  margin-left: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fx-matrix h3 {
  color: var(--text-primary, #e0e0e0);
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 3px;
  width: 100%;
  display: block;
}

/* FX Matrix headers */
.fx-matrix-header {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary, #a0a0a0);
  text-align: center;
  padding-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* FX Matrix source labels */
.fx-matrix-source {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary, #a0a0a0);
  padding-right: 10px;
  text-align: right;
  letter-spacing: 1px;
}

/* FX Matrix cells - same as main matrix */
.fx-matrix-cell {
  position: relative;
  height: 30px;
  width: 100%;
  max-width: 100%;
  margin: 0;
  background-color: var(--surface, #232323);
  overflow: hidden;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  user-select: none;
  transition: background 0.1s ease;
}

.fx-matrix-cell.placeholder-cell {
  opacity: 0.3;
  pointer-events: none;
  background-color: rgba(35, 35, 35, 0.5);
}

/* Diagonal black lines for negative values */
.fx-matrix-cell.negative {
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(0, 0, 0, 0.4) 4px,
    rgba(0, 0, 0, 0.4) 8px
  );
}

.fx-matrix-cell-value {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  pointer-events: auto;
  user-select: none;
  cursor: text;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.fx-matrix-cell:hover .fx-matrix-cell-value,
.fx-matrix-cell.dragging .fx-matrix-cell-value {
  opacity: 1;
}

/* Prevent text cursor during drag - use resize cursor instead */
.fx-matrix-cell.dragging .fx-matrix-cell-value {
  cursor: ns-resize !important;
}

/* Disable hover effects on other cells when dragging - must override hover state */
.mod-matrix-dragging .fx-matrix-cell:not(.dragging) {
  pointer-events: none;
}

.mod-matrix-dragging .fx-matrix-cell:not(.dragging):hover .fx-matrix-cell-value {
  opacity: 0 !important; /* Force hide even if hover state is active */
}

/* Prevent hover box-shadow on other cells during drag */
.mod-matrix-dragging .fx-matrix-cell:not(.dragging):hover {
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5) !important; /* Keep default shadow, no hover effect */
}

/* Force cursor to stay ns-resize on ALL FX cells during drag (prevents text cursor on hover) */
.mod-matrix-dragging .fx-matrix-cell .fx-matrix-cell-value {
  cursor: ns-resize !important;
}

/* Force cursor on FX cells themselves during drag */
.mod-matrix-dragging .fx-matrix-cell {
  cursor: ns-resize !important;
}

/* Hide toggle button on other FX cells during drag (if they have one) */
.mod-matrix-dragging .fx-matrix-cell:not(.dragging) .mod-matrix-uni-toggle {
  opacity: 0 !important;
}

/* Prevent toggle button hover effect on other FX cells during drag */
.mod-matrix-dragging .fx-matrix-cell:not(.dragging):hover .mod-matrix-uni-toggle {
  opacity: 0 !important;
}

.mod-matrix-dragging .fx-matrix-cell.dragging {
  pointer-events: auto;
}

.mod-matrix-dragging .fx-matrix-cell.dragging .fx-matrix-cell-value {
  opacity: 1 !important; /* Force show on dragged cell */
  cursor: ns-resize !important; /* Use resize cursor during drag, not text cursor */
}

.fx-matrix-cell-input {
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  background: rgba(17, 17, 17, 0.95);
  border: 1px solid rgba(80, 80, 90, 0.8);
  border-radius: 2px;
  padding: 2px 4px;
  width: 45px;
  outline: none;
  display: none;
}

.fx-matrix-cell-input.editing {
  display: block;
}

.fx-matrix-cell:hover {
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.7);
}

/* ============================================================================
   Destination Column Highlight Animation
   ============================================================================ */

/**
 * Highlight animation for destination columns when navigating via knob click
 * Uses page theme color for visual consistency - subtle background color pulse/flutter
 */

/* Apply subtle background color flutter to header and cells */
.mod-matrix-header.mod-matrix-dest-highlight,
.mod-matrix-cell.mod-matrix-dest-highlight {
  position: relative;
  /* Use pseudo-element for background so opacity animation doesn't affect text */
  isolation: isolate; /* Create new stacking context */
}

/* Make header background blend with glow when highlighted - brighter glow */
.mod-matrix-header.mod-matrix-dest-highlight {
  background: rgba(var(--panel-bg-rgb, 17, 17, 17), 0.75); /* More transparent to show brighter glow */
  position: relative;
}

.mod-matrix-header.mod-matrix-dest-highlight::before,
.mod-matrix-cell.mod-matrix-dest-highlight::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--highlight-bg-color, rgba(201, 201, 201, 0.06));
  z-index: 0;
  animation: mod-matrix-dest-flutter 5s ease-in-out;
  will-change: opacity; /* Optimize for animation */
  pointer-events: none;
}

/* Header-specific brighter glow */
.mod-matrix-header.mod-matrix-dest-highlight::before {
  background-color: var(--highlight-bg-color-header, rgba(201, 201, 201, 0.08)); /* Brighter for header */
}

/* Animated underline for header text */
.mod-matrix-header.mod-matrix-dest-highlight::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 4px;
  right: 4px;
  height: 1px;
  background-color: var(--highlight-bg-color-header, rgba(201, 201, 201, 0.08));
  z-index: 1;
  animation: mod-matrix-dest-flutter 5s ease-in-out;
  will-change: opacity;
  pointer-events: none;
}

/* Ensure content stays above the pseudo-element background */
.mod-matrix-header.mod-matrix-dest-highlight > *,
.mod-matrix-cell.mod-matrix-dest-highlight > * {
  position: relative;
  z-index: 1;
}

@keyframes mod-matrix-dest-flutter {
  0% {
    opacity: 0;
  }
  10% {
    /* Fade in quickly */
    opacity: 1;
  }
  20% {
    /* Flutter up - brighter */
    opacity: 1.5; /* 0.09 / 0.06 = 1.5 */
  }
  30% {
    /* Flutter down */
    opacity: 1;
  }
  40% {
    /* Flutter up */
    opacity: 1.5;
  }
  50% {
    /* Flutter down */
    opacity: 1;
  }
  60% {
    /* Flutter up */
    opacity: 1.5;
  }
  70% {
    /* Flutter down */
    opacity: 1;
  }
  80% {
    /* Flutter up */
    opacity: 1.5;
  }
  90% {
    /* Flutter down */
    opacity: 1;
  }
  100% {
    /* Fade out slowly */
    opacity: 0;
  }
}

/* Ensure header stays above other elements and preserve existing shadow */
.mod-matrix-header.mod-matrix-dest-highlight {
  z-index: 25; /* Above sticky header z-index (20) but below modals */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Cells preserve existing inset shadow */
.mod-matrix-cell.mod-matrix-dest-highlight {
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5);
}

/* Prevent highlight from interfering with hover states */
.mod-matrix-header.mod-matrix-dest-highlight:hover {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.mod-matrix-cell.mod-matrix-dest-highlight:hover {
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.7);
}

/* Smooth transition when highlight is removed */
.mod-matrix-header,
.mod-matrix-cell {
  transition: background-color 0.3s ease;
}

