/* Piano roll editor for recorded loop tracks. */

.roll-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.012), transparent 40%), var(--panel);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-1);
}

.piano-roll {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ----------------------------------------------------------------- toolbar */

.roll-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}

.roll-toolbar .field {
  flex: 0 0 auto;
}

.roll-toolbar .select {
  height: 28px;
  font-size: 11px;
  padding: 0 24px 0 8px;
}

.roll-toolbar .btn {
  height: 28px;
}

/* ------------------------------------------------------------------- grid */

.roll-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.roll-body {
  display: flex;
  align-items: flex-start;
  min-width: max-content;
}

.roll-labels {
  position: sticky;
  left: 0;
  z-index: 4;
  flex: 0 0 46px;
  width: 46px;
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
}

.roll-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: var(--row-h, 18px);
  padding-right: 6px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--dim);
  white-space: nowrap;
}

.roll-label.root {
  color: var(--accent-hi);
  background: var(--accent-soft);
}

.roll-lanes {
  position: relative;
  flex: 0 0 auto;
  background-color: rgba(0, 0, 0, 0.14);
  background-image:
    repeating-linear-gradient(
      90deg,
      var(--accent-line) 0 1px,
      transparent 1px calc(var(--cell, 22px) * 16)
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.1) 0 1px,
      transparent 1px calc(var(--cell, 22px) * 4)
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.04) 0 1px,
      transparent 1px var(--cell, 22px)
    ),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.04) 0 1px,
      transparent 1px var(--row-h, 18px)
    );
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Pan mode: the browser owns the gesture so a long loop can be scrolled. */
.roll-lanes.is-pan {
  touch-action: pan-x pan-y;
}

.roll-marks,
.roll-notes {
  position: absolute;
  inset: 0;
}

.roll-marks {
  pointer-events: none;
}

.roll-bar-num {
  position: absolute;
  top: 1px;
  font-family: var(--mono);
  font-size: 8px;
  color: var(--dim);
  pointer-events: none;
}

/* ------------------------------------------------------------------ notes */

.roll-note {
  position: absolute;
  box-sizing: border-box;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), var(--accent-lo));
  border: 1px solid var(--accent-line);
  box-shadow: 0 0 8px var(--accent-soft);
  touch-action: none;
  cursor: grab;
}

.roll-note.root {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
}

.roll-note.is-selected {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
  z-index: 2;
}

.roll-note-handle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}

.roll-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-2-glow);
  pointer-events: none;
  z-index: 3;
}

.roll-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ phone */

@media (max-width: 860px) {
  .roll-toolbar {
    padding: 6px;
    gap: 4px;
  }

  .roll-toolbar .field-label {
    display: none;
  }

  .roll-toolbar .select {
    height: 30px;
  }

  .roll-labels {
    flex-basis: 40px;
    width: 40px;
  }

  .roll-label {
    font-size: 8px;
    padding-right: 4px;
  }
}
