/* MIDI editor look (redesign 2026-11).
   Loaded after styles.css. Only the open editor changes: a real piano
   keyboard with the octaves marked, rows shaded like the keys, notes coloured
   by velocity, a velocity lane at the bottom and a tidy MIDI Edit box in the
   track card. Geometry (row heights, note positions, scrolling) is untouched,
   so every pointer action keeps landing where it did. */

html body .lane.midi-editor-open {
  --sw-rh: calc(var(--midi-grid-height, 100%) / var(--midi-rows, 12));
  --sw-black-row: rgba(0, 0, 0, 0.24);
  --sw-row-line: rgba(255, 248, 232, 0.045);
  --sw-octave-line: rgba(241, 201, 121, 0.3);
}

/* The lane's own row stripes give way to the region's piano rows. */
html body .lane.midi-editor-open[data-track-type="keys"]::after,
html body .lane.midi-editor-open[data-track-type="drums"]::after {
  background: repeating-linear-gradient(to bottom, rgba(255, 248, 232, 0.035) 0 1px, transparent 1px var(--sw-rh));
}

/* Region = the note grid: dark, with the black-key rows darker and a gold
   line under every C. Rows run B, A#, A, G#, G, F#, F, E, D#, D, C#, C. */
html body .lane.midi-editor-open[data-track-type="keys"] .midi-region {
  border-color: color-mix(in srgb, var(--clip-color) 55%, rgba(255, 255, 255, 0.18));
  background-color: #191814;
  background-image:
    repeating-linear-gradient(to bottom,
      transparent 0 calc(var(--sw-rh) * 12 - 1px),
      var(--sw-octave-line) calc(var(--sw-rh) * 12 - 1px) calc(var(--sw-rh) * 12)),
    repeating-linear-gradient(to bottom, var(--sw-row-line) 0 1px, transparent 1px var(--sw-rh)),
    repeating-linear-gradient(to bottom,
      transparent 0 var(--sw-rh),
      var(--sw-black-row) var(--sw-rh) calc(var(--sw-rh) * 2),
      transparent calc(var(--sw-rh) * 2) calc(var(--sw-rh) * 3),
      var(--sw-black-row) calc(var(--sw-rh) * 3) calc(var(--sw-rh) * 4),
      transparent calc(var(--sw-rh) * 4) calc(var(--sw-rh) * 5),
      var(--sw-black-row) calc(var(--sw-rh) * 5) calc(var(--sw-rh) * 6),
      transparent calc(var(--sw-rh) * 6) calc(var(--sw-rh) * 8),
      var(--sw-black-row) calc(var(--sw-rh) * 8) calc(var(--sw-rh) * 9),
      transparent calc(var(--sw-rh) * 9) calc(var(--sw-rh) * 10),
      var(--sw-black-row) calc(var(--sw-rh) * 10) calc(var(--sw-rh) * 11),
      transparent calc(var(--sw-rh) * 11) calc(var(--sw-rh) * 12)),
    linear-gradient(180deg, color-mix(in srgb, var(--clip-color) 7%, transparent), color-mix(in srgb, var(--clip-color) 4%, transparent)) !important;
}

html body .lane.midi-editor-open[data-track-type="drums"] .midi-region {
  border-color: color-mix(in srgb, var(--clip-color) 55%, rgba(255, 255, 255, 0.18));
  background-color: #171613;
  background-image:
    repeating-linear-gradient(to bottom, var(--sw-row-line) 0 1px, transparent 1px var(--sw-rh)),
    repeating-linear-gradient(to bottom, transparent 0 var(--sw-rh), rgba(0, 0, 0, 0.18) var(--sw-rh) calc(var(--sw-rh) * 2)),
    linear-gradient(180deg, color-mix(in srgb, var(--clip-color) 7%, transparent), color-mix(in srgb, var(--clip-color) 4%, transparent)) !important;
}

/* The keyboard on the left already names every row. */
html body .lane.midi-editor-open .midi-region-row-guide,
html body .lane.midi-editor-open .midi-region-row-line {
  display: none;
}

html body .lane.midi-editor-open .midi-region-grid-line.major {
  background: rgba(241, 201, 121, 0.32);
}

/* Notes: colour by velocity (soft = darker, hard = full colour). */
html body .lane.midi-editor-open .midi-region .midi-clip {
  border: 1px solid color-mix(in srgb, var(--clip-color) 78%, #fff8e8 22%);
  border-radius: 3px;
  background: color-mix(in srgb, var(--clip-color) calc(30% + var(--sw-vel, 0.67) * 70%), #1c1a16) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

html body .lane.midi-editor-open .midi-region .midi-clip .midi-velocity-fill {
  display: none;
}

html body .lane.midi-editor-open .midi-region .midi-clip .midi-note-label {
  color: rgba(20, 18, 14, 0.86);
  font-weight: 900;
  text-shadow: none;
}

html body .lane.midi-editor-open .midi-region .midi-clip.sw-note-narrow .midi-note-label {
  display: none;
}

html body .lane.midi-editor-open .midi-region .midi-clip.selected {
  border-color: #fffaf0;
  box-shadow: 0 0 0 1px #fffaf0, 0 2px 8px rgba(0, 0, 0, 0.45) !important;
}

html body .lane.midi-editor-open .midi-region .midi-clip.selected::after {
  box-shadow: none;
}

/* Piano keyboard: cream keys, short black keys, octave names on the Cs. */
html body .lane.midi-editor-open .key-row-labels.editor-open {
  left: 0;
  width: 4.6rem;
  border: 0;
  border-right: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 0;
  background: #ece6d8;
  box-shadow: 0.25rem 0 0.9rem rgba(0, 0, 0, 0.35);
}

html body .lane.midi-editor-open .key-row-labels.editor-open .piano-row-key {
  position: relative;
  border-radius: 0;
  text-shadow: none;
}

html body .lane.midi-editor-open .key-row-labels.editor-open .white-key {
  width: 100%;
  border-bottom: 1px solid rgba(40, 36, 30, 0.14);
  background: linear-gradient(90deg, #f3eee2, #e6dfcf 85%, #d3cab6);
  color: transparent;
}

html body .lane.midi-editor-open .key-row-labels.editor-open .black-key {
  z-index: 1;
  width: 60%;
  border-bottom: 0;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, #0c0b09, #24211c 80%, #3a352d);
  color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

html body .lane.midi-editor-open .key-row-labels.editor-open .piano-row-key span {
  display: none;
}

html body .lane.midi-editor-open .key-row-labels.editor-open .root-key {
  border-bottom: 1px solid rgba(40, 36, 30, 0.42);
}

html body .lane.midi-editor-open .key-row-labels.editor-open .root-key span {
  display: block;
  margin-left: auto;
  padding: 0 0.32rem 0 0;
  color: #6b6253;
  font-size: 0.56rem;
  font-weight: 900;
}

html body .lane.midi-editor-open .key-row-labels.editor-open .root-key::after {
  display: none;
}

html body .lane.midi-editor-open .key-row-labels.editor-open .white-key.selected,
html body .lane.midi-editor-open .key-row-labels.editor-open .white-key:hover {
  background: linear-gradient(90deg, #f6dca3, #ecc77a);
  outline: 0;
}

html body .lane.midi-editor-open .key-row-labels.editor-open .black-key.selected,
html body .lane.midi-editor-open .key-row-labels.editor-open .black-key:hover {
  background: linear-gradient(90deg, #5b4a26, #8a6c30);
  outline: 0;
}

/* Drums: wider rows with the icon and the full short name. */
html body .lane.midi-editor-open .drum-row-labels.editor-open {
  left: 0;
  width: 6.6rem;
  border-right: 1px solid rgba(0, 0, 0, 0.5);
  background: #171613;
  box-shadow: 0.25rem 0 0.9rem rgba(0, 0, 0, 0.35);
}

html body .lane.midi-editor-open .drum-row-labels.editor-open button {
  border-radius: 0;
  border-bottom: 1px solid rgba(255, 248, 232, 0.05);
  background: transparent;
  padding-left: 0.45rem;
  color: #d9d3c6;
  text-shadow: none;
}

html body .lane.midi-editor-open .drum-row-labels.editor-open button:nth-child(even) {
  background: rgba(0, 0, 0, 0.18);
}

html body .lane.midi-editor-open .drum-row-labels.editor-open button:hover,
html body .lane.midi-editor-open .drum-row-labels.editor-open button.selected {
  background: rgba(241, 201, 121, 0.16);
  color: #f6dca3;
}

html body .lane.midi-editor-open .drum-row-labels.editor-open .drum-token {
  gap: 0.4rem;
}

html body .lane.midi-editor-open .drum-row-labels.editor-open .drum-token em {
  font-size: 0.64rem;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

/* Velocity lane: one stem per note, over the bottom of the editor (which
   scrolls further down while it is shown). Display only; it keeps its
   clicks so nothing gets drawn underneath. */
html body .lane.midi-editor-open .sw-vel-lane {
  position: absolute;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  height: 54px;
  border-top: 1px solid rgba(241, 201, 121, 0.22);
  background: rgba(15, 14, 12, 0.94);
  cursor: default;
  pointer-events: auto;
}

html body.sw-vel-lane-off .lane.midi-editor-open .sw-vel-lane {
  display: none;
}

@media (max-width: 760px) {
  html body .lane.midi-editor-open .sw-vel-lane,
  html body .track-card.midi-editor-open .sw-vel-lane-toggle {
    display: none;
  }
}

html body .lane.midi-editor-open .sw-vel-lane-stems {
  position: absolute;
  inset: 0.45rem 0 0.3rem;
}

html body .lane.midi-editor-open .sw-vel-lane-stems i {
  position: absolute;
  bottom: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--lane-color, #d4a855);
}

html body .lane.midi-editor-open .sw-vel-lane-stems i::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: inherit;
}

html body .lane.midi-editor-open .sw-vel-lane-stems i.selected {
  background: #fffaf0;
}

html body .lane.midi-editor-open .sw-vel-lane-label {
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  width: 4.6rem;
  padding-left: 0.5rem;
  background: #12110e;
  color: rgba(255, 248, 232, 0.62);
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  transform: translateX(var(--timeline-scroll-left, 0px));
}

html body .lane.midi-editor-open[data-track-type="drums"] .sw-vel-lane-label {
  width: 6.6rem;
}

/* MIDI Edit box in the track card: title, lane toggle, quantize, velocity. */
html body .track-card.midi-editor-open .midi-editor-q-panel {
  display: grid;
  gap: 0.4rem;
  width: auto;
  max-width: none;
  margin: 0.45rem 0.55rem 0 0.45rem;
  padding: 0.5rem;
  border: 1px solid rgba(241, 201, 121, 0.2);
  border-radius: 0.55rem;
  background: rgba(20, 19, 16, 0.92);
  box-shadow: none;
}

html body .track-card.midi-editor-open .sw-midi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

html body .track-card.midi-editor-open .midi-editor-q-title {
  color: var(--gold-2, #f1c979);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

html body .track-card.midi-editor-open .sw-vel-lane-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 1.45rem;
  padding: 0 0.45rem;
  border: 1px solid rgba(255, 248, 232, 0.14);
  border-radius: 0.35rem;
  background: transparent;
  color: rgba(255, 248, 232, 0.7);
  font-size: 0.6rem;
  font-weight: 800;
}

html body .track-card.midi-editor-open .sw-vel-lane-toggle svg {
  width: 0.8rem;
  height: 0.8rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

html body .track-card.midi-editor-open .sw-vel-lane-toggle[aria-pressed="true"] {
  border-color: rgba(241, 201, 121, 0.55);
  background: rgba(241, 201, 121, 0.14);
  color: #f6dca3;
}

html body .track-card.midi-editor-open .sw-midi-q-label {
  color: rgba(255, 248, 232, 0.55);
  font-size: 0.58rem;
  font-weight: 800;
}

html body .track-card.midi-editor-open .midi-editor-q-choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border: 1px solid rgba(255, 248, 232, 0.12);
  border-radius: 0.4rem;
  overflow: hidden;
}

html body .track-card.midi-editor-open .midi-editor-q-choices button {
  min-width: 0;
  height: 1.6rem;
  border: 0;
  border-right: 1px solid rgba(255, 248, 232, 0.08);
  border-bottom: 1px solid rgba(255, 248, 232, 0.08);
  border-radius: 0;
  background: rgba(255, 248, 232, 0.04);
  color: var(--cream, #fff8e8);
  font-size: 0.64rem;
  white-space: nowrap;
}

html body .track-card.midi-editor-open .midi-editor-q-choices button:nth-child(4n) {
  border-right: 0;
}

html body .track-card.midi-editor-open .midi-editor-q-choices button:nth-child(n + 5) {
  border-bottom: 0;
}

html body .track-card.midi-editor-open .midi-editor-q-choices button:hover {
  background: rgba(241, 201, 121, 0.18);
  color: #f6dca3;
}

html body .track-card.midi-editor-open .midi-editor-q-panel .midi-velocity-row {
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  margin: 0;
  padding: 0;
}

html body .track-card.midi-editor-open .midi-editor-q-panel .midi-velocity-value {
  min-width: 3.6rem;
  text-align: right;
  white-space: nowrap;
}
