/**
 * The in-browser preview player (preview-player.js): A/B switch, transport,
 * piano roll and stats. Its own file so the admin console can use it without
 * the site stylesheet. Relies on the site's CSS variables (styles.css :root);
 * pages without them define their own.
 */

.pv {
  margin-top: var(--spacing-xl);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  background: white;
  padding: var(--spacing-md);
}

.pv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.pv-switch {
  display: inline-flex;
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 3px;
}

.pv-side {
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 36px;
}

.pv-side.is-active {
  background: white;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.pv.is-original .pv-side.is-active {
  color: #b91c1c;
}

.pv:not(.is-original) .pv-side.is-active {
  color: var(--primary-color);
}

.pv-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.pv-play {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  color: white;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.pv-play:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.pv-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-width: 82px;
}

.pv-loop {
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 32px;
}

.pv-loop.is-active {
  border-color: var(--primary-color);
  color: var(--primary-color);
  background: rgba(99, 102, 241, 0.08);
}

.pv-side:focus-visible,
.pv-play:focus-visible,
.pv-loop:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.pv-roll-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: white;
  -webkit-overflow-scrolling: touch;
}

.pv-roll-inner {
  position: relative;
  cursor: pointer;
}

.pv-roll {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

.pv-playhead {
  position: absolute;
  top: 0;
  left: -0.75px;
  width: 1.5px;
  background: #111827;
  pointer-events: none;
  will-change: transform;
}

/* The marker on top of the playhead line. */
.pv-playhead::before {
  content: '';
  position: absolute;
  top: 0;
  left: -4.25px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid #111827;
}

.pv-labels {
  position: sticky;
  left: 0;
  top: 0;
  width: 68px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(90deg, #fff 0%, #fff 80%, rgba(255, 255, 255, 0) 100%);
  z-index: 1;
}

.pv-labels span {
  position: absolute;
  left: 0;
  width: 60px;
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.pv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: var(--spacing-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.pv-legend + .pv-legend {
  margin-top: 0.3rem;
}

.pv-legend .pv-legend-title {
  font-weight: 700;
  color: var(--text-primary);
}

/* "What humanizing changed" over the band above the Timing and Velocity lanes:
   wider than the gutter, and it stays put when the roll scrolls sideways. */
.pv-labels .pv-label-head {
  width: auto;
  padding-right: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #4338ca;
  background: #eef2ff;
}

.pv-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.pv-sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.pv-sw-hum { background: #6366f1; }
.pv-sw-orig { border: 1.5px solid #6b7280; }
.pv-sw-late { height: 3px; background: #f59e0b; }
.pv-sw-early { height: 3px; background: #14b8a6; }
.pv-sw-louder { width: 4px; height: 11px; background: #db2777; }
.pv-sw-softer { width: 4px; height: 11px; background: #0284c7; }

.pv-stats {
  list-style: none;
  margin: var(--spacing-md) 0 0;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.pv-stats strong {
  color: var(--text-primary);
}

.pv-note {
  margin: var(--spacing-sm) 0 0;
  font-size: 0.75rem;
  color: var(--text-light);
}

.pv-zoom {
  display: inline-flex;
  gap: 2px;
}

.pv-zoom-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-secondary);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pv-zoom-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.pv-zoom-btn:not(:disabled):hover,
.pv-zoom-btn:focus-visible {
  border-color: var(--primary-color);
  color: var(--primary-color);
  outline: none;
}
