/* For the piano roll (to be implemented later) */
.piano-roll {
  background-color: #5a9fd4;
  height: 100%;
}

/* Piano Roll Panel */
.piano-roll-panel {
  position: fixed;
  background-color: #2d2d2d;
  border: 1px solid #3a3a3a;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Piano notes */
.piano-note {
  position: absolute;
  border: 1px solid #999;
  border-radius: 2px;
  z-index: 10;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
}

.piano-note:hover {
  filter: brightness(1.1);
}

.piano-note.dragging {
  opacity: 0.8;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  z-index: 100;
  cursor: grabbing;
}

.piano-note.resizing {
  opacity: 0.8;
  z-index: 100;
}

.piano-note.selected {
  border: 2px solid white;
  z-index: 50;
}

.piano-roll-header {
  height: 30px;
  background-color: #1e1e1e;
  border-bottom: 1px solid #3a3a3a;
  display: flex;
  align-items: center;
  padding: 0 10px;
  cursor: move;
  user-select: none;
}

/* Piano roll toolbar */
.piano-roll-toolbar {
  height: 30px;
  background-color: #252525;
  border-bottom: 1px solid #3a3a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  user-select: none;
  position: relative;
  z-index: 100;
  /* Ensure toolbar and its dropdowns appear above piano roll content */
}

/* Note attribute bar */
.note-attribute-bar {
  height: 30px;
  background-color: #252525;
  border-bottom: 1px solid #3a3a3a;
  display: flex;
  align-items: center;
  padding: 0 10px;
  user-select: none;
  gap: 24px;
  font-size: 11px;
  color: #aaa;
}

.note-attribute-bar .attr-item {
  display: flex;
  align-items: center;
}

.note-attribute-bar .attr-label {
  color: #777;
  margin-right: 4px;
}

.note-attribute-bar .attr-value {
  color: #ddd;
}

.note-attribute-bar .quant-button {
  font-size: 11px;
  margin-left: 0;
  padding: 2px 6px;
}

.note-attr-popup {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #2d2d2d;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 6px 8px;
  z-index: 1500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  margin-top: 2px;
  min-width: 120px;
}

.note-attr-input {
  background-color: #1e1e1e;
  border: 1px solid #555;
  border-radius: 2px;
  color: #e0e0e0;
  font-size: 11px;
  padding: 3px 6px;
  width: 100%;
  outline: none;
  box-sizing: border-box;
}

.note-attr-input:focus {
  border-color: #4a6b8a;
}

.piano-roll-toolbar .tool-button {
  --toolbar-button-bg: transparent;
  --toolbar-button-fg: #999;
  width: 20px;
  height: 20px;
  background-color: var(--toolbar-button-bg);
  color: var(--toolbar-button-fg);
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    transform 0.12s ease,
    box-shadow 0.18s ease;
}

.piano-roll-toolbar .tool-button svg {
  font-size: 14px;
  transition: color 0.18s ease, fill 0.18s ease;
}

.piano-roll-toolbar .sheet-track-scope-toggle {
  width: 20px;
  min-width: 20px;
  height: 20px;
}

.piano-roll-toolbar .sheet-track-scope-toggle .sheet-track-scope-icon {
  width: 12px;
  height: 12px;
  stroke-width: 2.5;
  overflow: visible;
}

.piano-roll-toolbar .piano-roll-tool-icon {
  width: 12px;
  height: 12px;
  overflow: visible;
}

.piano-roll-toolbar .tool-button.sheet-mode-toggle,
.piano-roll-toolbar .tool-button:not(.icon-only) {
  font-size: 13px;
  line-height: 1;
}

.piano-roll-toolbar .tool-button:hover {
  --toolbar-button-bg: #3a3a3a;
  --toolbar-button-fg: #e0e0e0;
}

.piano-roll-toolbar .tool-button.active {
  --toolbar-button-bg: #e0e0e0;
  --toolbar-button-fg: #2d2d2d;
  background-color: var(--toolbar-button-bg);
  color: var(--toolbar-button-fg);
}

.piano-roll-toolbar .tool-button.active:hover {
  --toolbar-button-bg: #f0f0f0;
}

.piano-roll-toolbar .tool-button:active {
  --toolbar-button-bg: #5a5a5a;
  transform: scale(0.95);
}

.piano-roll-toolbar .tool-button.active:active {
  --toolbar-button-bg: #d6d6d6;
}

.piano-roll-toolbar button:focus,
.piano-roll-toolbar button:focus-visible,
.piano-roll-toolbar .tool-button:focus,
.piano-roll-toolbar .tool-button:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Override pointer-events for piano roll toolbar sections */
.piano-roll-toolbar .toolbar-left,
.piano-roll-toolbar .toolbar-right {
  pointer-events: auto;
  /* max-width: 70%; */
  width: auto;
}

.piano-roll-toolbar .quant-button {
  font-size: 10px;
}

.piano-roll-toolbar .toolbar-left .quant-button {
  margin-left: 0px;
  margin-right: 5px;
}

.piano-roll-toolbar .toolbar-left .quant-dropdown {
  left: 0;
}

.piano-roll-automation-toolbar-group {
  display: flex;
  align-items: center;
  margin-right: 5px;
}

.piano-roll-toolbar .automation-toggle-button {
  width: 20px;
  min-width: 20px;
  margin: 0px 0px 0px 3px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border: 1px solid #444;
  border-right: 0px;
  font-size: 11px;
  font-weight: 700;
}

.piano-roll-toolbar .automation-toggle-button.active {
  border-color: #e0e0e0;
  border-right: 0;
}

.piano-roll-toolbar .automation-toggle-button.active:hover {
  border-color: #f0f0f0;
  border-right: 0;
}

.piano-roll-toolbar .automation-toggle-button.active:active {
  border-color: #d6d6d6;
  border-right: 0;
}

.piano-roll-toolbar .automation-type-dropdown {
  min-width: 92px;
  height: 20px;
  margin: 0;
  padding: 0 6px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  font-size: 10px;
}

/* Spectrogram toolbar controls */
.spectrogram-toolbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 5px;
}

.spectrogram-control-label {
  font-size: 10px;
  color: #aaa;
  white-space: nowrap;
}

.spectrogram-threshold-slider {
  /* Match the visual width of the Qua. Pos. / Qua. Len. buttons (~80px) */
  width: 80px;
  height: 4px;
  accent-color: #7a9ccf;
  cursor: pointer;
  margin: 0;
}

.spectrogram-threshold-value {
  font-size: 10px;
  color: #e0e0e0;
  min-width: 30px;
  text-align: right;
  white-space: nowrap;
}

.piano-roll-title {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  color: #e0e0e0;
  /* text-transform: uppercase; */
  cursor: pointer;
  padding: 5px;
  border-radius: 3px;
}

.close-button {
  background: transparent;
  border: none;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 14px;
  padding: 5px;
}

.close-button:hover {
  color: #ff4444;
}

.piano-roll-content-outer {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.piano-roll-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.piano-roll-main-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.piano-roll-main-section.with-automation {
  flex: 0 0 50%;
}

.piano-roll-note-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.piano-roll-automation-section {
  flex: 0 0 50%;
  min-height: 0;
  border-top: 1px solid #3a3a3a;
  overflow: hidden;
}

.spectrogram-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 100;
}

.spectrogram-loading-label {
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.6);
  color: #aaa;
  font-size: 11px;
  border-radius: 3px;
}

.piano-grid-header {
  display: grid;
  grid-template-columns: repeat(var(--max-number-of-bars), var(--region-grid-bar-width));
  width: calc(var(--max-number-of-bars) * var(--region-grid-bar-width) + var(--region-piano-key-width) - 1px);
  min-width: 100%;
  height: 20px;
  border-bottom: 1px solid #3a3a3a;
  background-color: #1e1e1e;
  padding-left: calc(var(--region-piano-key-width) - 1px);
  box-sizing: border-box;
  position: sticky;
  top: 0;
  z-index: 20;
  cursor: pointer;
  /* Show pointer cursor on hover to indicate interactivity */
}

.piano-grid-header:hover {
  cursor: url("data:image/svg+xml,%3csvg width='16' height='16' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M4 6h8l-4 4-4-4z' fill='%23e0e0e0'/%3e%3c/svg%3e") 8 8, pointer;
}

.piano-bar-number {
  border-left: 1px solid #3a3a3a;
  padding-left: 10px;
  font-size: 10px;
}

.piano-roll-body {
  display: flex;
  min-height: calc(8 * 12 * var(--region-piano-key-height));
  width: calc(var(--max-number-of-bars) * var(--region-grid-bar-width));
}

.piano-roll-body.sheet-music-body {
  min-height: 0;
  width: max-content;
}

.sheet-music-view {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 240px;
  background: linear-gradient(180deg, #faf7ef 0%, #f2ede0 100%);
  color: #1f1f1f;
}

.sheet-music-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  height: 20px;
  background: rgba(34, 34, 34, 0.92);
  color: #ddd;
  border-bottom: 1px solid #3a3a3a;
  cursor: pointer;
}

.sheet-music-bar-number {
  flex: 0 0 auto;
  box-sizing: border-box;
  border-left: 1px solid #4a4a4a;
  padding-left: 10px;
  font-size: 10px;
  line-height: 20px;
}

.sheet-music-strip {
  position: relative;
  min-height: 220px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 100%);
}

.sheet-music-notice {
  position: sticky;
  top: 8px;
  left: 8px;
  margin: 8px 0 0 8px;
  width: fit-content;
  max-width: min(420px, calc(100% - 20px));
  padding: 5px 9px;
  background: rgba(42, 42, 42, 0.72);
  color: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
  backdrop-filter: blur(4px);
  z-index: 3;
  pointer-events: none;
}

.sheet-music-measures {
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  min-width: 100%;
  padding: 12px 0 24px;
}

.sheet-music-ties {
  position: absolute;
  top: 12px;
  left: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.sheet-music-tie-path {
  fill: #111;
  stroke: none;
}

.sheet-music-measure {
  flex: 0 0 auto;
  position: relative;
  z-index: 0;
}

.sheet-music-measure-host {
  position: relative;
  width: 100%;
  height: 100%;
}

.sheet-music-measure svg {
  display: block;
  overflow: visible;
}

.sheet-music-measure svg path,
.sheet-music-measure svg rect,
.sheet-music-measure svg line,
.sheet-music-measure svg text {
  stroke: #111 !important;
  fill: #111 !important;
}

.sheet-music-measure svg path[fill="none"] {
  fill: none !important;
  stroke: #111 !important;
}

.sheet-music-measure svg .vf-stave path {
  stroke-width: 1.5px !important;
}

.piano-keys-container {
  width: var(--region-piano-key-width);
  flex-shrink: 0;
  overflow: hidden;
  border-right: 1px solid #3a3a3a;
  background-color: #252525;
  position: sticky;
  left: 0;
  z-index: 15;
}

.piano-grid-container {
  flex: 1;
  width: 100%;
  min-width: calc(var(--max-number-of-bars) * var(--region-grid-bar-width));
  min-height: calc(8 * 12 * var(--region-piano-key-height));
  z-index: 5;
}

.piano-octave {
  display: flex;
  flex-direction: column;
}

.piano-key {
  width: var(--region-piano-key-width);
  height: var(--region-piano-key-height);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #3a3a3a;
  position: relative;
  transition: background-color 0.08s ease;
}

.piano-key.natural {
  background-color: #e0e0e0;
  color: #222;
}

.piano-key.sharp {
  background-color: #222;
  color: #e0e0e0;
}

.piano-key.natural.visual-active {
  background-color: #b8b8b8;
}

.piano-key.sharp.visual-active {
  background-color: #5a5a5a;
}

.key-label {
  font-size: 10px;
  padding-left: 5px;
  padding-right: 18px;
  position: relative;
  z-index: 1;
}

.piano-key-activity-dot {
  position: absolute;
  right: 6px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 999px;
  background-color: #000;
  border: 1px solid #000;
}

.piano-key.sharp .piano-key-activity-dot {
  background-color: #fff;
  border-color: #fff;
}

.piano-grid {
  width: 100%;
  height: 100%;
  position: relative;
  background-size:
    var(--region-grid-bar-width) var(--region-piano-key-height),
    var(--region-grid-beat-width) var(--region-piano-key-height),
    100% 100%;
  /* background-image is now set dynamically via React inline styles in PianoGrid component */
}

.piano-grid.pencil-cursor {
  cursor: crosshair;
}

.piano-roll-automation-scroll-layer.pencil-cursor {
  cursor: crosshair;
}

/* Piano Grid Cursor Highlights */
.piano-grid-pitch-highlight {
  position: absolute;
  left: 0;
  right: 0;
  background-color: rgba(135, 206, 250, 0.15);
  border-top: 1px solid rgba(135, 206, 250, 0.3);
  border-bottom: 1px solid rgba(135, 206, 250, 0.3);
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.1s ease;
}

.piano-grid-beat-highlight {
  position: absolute;
  top: 0;
  bottom: 0;
  background-color: rgba(135, 206, 250, 0.1);
  border-left: 1px solid rgba(135, 206, 250, 0.25);
  border-right: 1px solid rgba(135, 206, 250, 0.25);
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.1s ease;
}

.piano-grid-chord-highlight {
  position: absolute;
  background-color: rgba(255, 77, 77, 0.25);
  border: 1px solid rgba(255, 77, 77, 0.8);
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.1s ease;
}

.piano-grid-recording-note {
  position: absolute;
  border: 1px solid transparent;
  pointer-events: none;
  z-index: 3;
}

.piano-roll-automation-lane {
  position: relative;
  height: 100%;
  background: linear-gradient(180deg, #343434 0%, #2e2e2e 100%);
  overflow: hidden;
}

.piano-roll-automation-track {
  position: relative;
  height: 100%;
  min-height: 160px;
  min-width: calc(var(--max-number-of-bars) * var(--region-grid-bar-width) + var(--region-piano-key-width));
}

.piano-roll-automation-scroll-layer {
  position: absolute;
  inset: 0;
  will-change: transform;
  z-index: 0;
}

.piano-roll-automation-track::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--region-piano-key-width);
  width: 1px;
  background-color: rgba(255, 255, 255, 0.08);
}

.piano-roll-automation-gutter {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--region-piano-key-width);
  background: linear-gradient(180deg, #343434 0%, #2e2e2e 100%);
  z-index: 2;
}

.piano-roll-automation-grid {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--region-piano-key-width);
  right: 0;
  background: linear-gradient(180deg, #343434 0%, #2e2e2e 100%);
  background-image:
    repeating-linear-gradient(to right,
      transparent,
      transparent calc(var(--region-grid-beat-width) - 1px),
      rgba(255, 255, 255, 0.08) calc(var(--region-grid-beat-width) - 1px),
      rgba(255, 255, 255, 0.08) var(--region-grid-beat-width));
}

.piano-roll-automation-lane-label {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 3;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #87cefa;
  text-transform: uppercase;
}

.piano-roll-automation-svg {
  position: absolute;
  inset: 0;
  overflow: visible;
  z-index: 1;
}

.piano-roll-automation-line {
  filter: drop-shadow(0 0 2px rgba(135, 206, 250, 0.3));
  pointer-events: none;
}

.piano-roll-automation-point {
  cursor: pointer;
}

.piano-roll-automation-point.selected {
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.6));
}

.piano-roll-automation-value {
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(30, 30, 30, 0.8);
  stroke-width: 2px;
  pointer-events: none;
}

.piano-roll-automation-selection-box {
  position: absolute;
  border: 1px solid rgba(135, 206, 250, 0.95);
  background: rgba(135, 206, 250, 0.18);
  pointer-events: none;
  z-index: 2;
}

.piano-roll-automation-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7893a5;
  font-size: 11px;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.piano-roll-zoom-popup {
  position: absolute;
  top: 100%;
  right: 0;
  background-color: #2d2d2d;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 8px 12px;
  z-index: 1500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  margin-top: 2px;
}

.piano-roll-zoom-popup input[type="range"] {
  width: 120px;
}

.piano-roll-zoom-value {
  font-size: 12px;
  color: #e0e0e0;
  min-width: 20px;
  text-align: center;
}
