﻿/* ── Beat Intelligence Panel ──────────────────────────────────────────────── */

:root {
  --bdp-accent:      rgba(244, 192, 96,  0.95);
  --bdp-accent-dim:  rgba(244, 192, 96,  0.35);
  --bdp-accent-bg:   rgba(244, 192, 96,  0.06);
  --bdp-accent-glow: rgba(244, 192, 96,  0.28);
  --bdp-blue:        rgba(132, 205, 255, 0.80);
  --bdp-red:         rgba(255, 110,  90, 0.85);
}

.bdp-panel {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 46;
  width: min(520px, calc(100vw - 36px));
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--bdp-accent-dim);
  border-radius: 20px;
  background: rgba(5, 10, 24, 0.92);
  backdrop-filter: blur(22px);
  box-shadow: 0 28px 80px rgba(0,0,0,0.52), 0 0 0 1px rgba(244,192,96,0.05);
  overflow: hidden;
  transition: opacity 180ms ease, transform 180ms ease;
}

.bdp-panel.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px) scale(0.97);
}

/* ── Header ── */
.bdp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px 11px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}
.bdp-head:active { cursor: grabbing; }

.bdp-head-left .bdp-kicker {
  display: block;
  font: 700 0.58rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bdp-accent-dim);
  margin-bottom: 3px;
}
.bdp-head-left strong {
  font: 700 0.9rem/1 "Syne", sans-serif;
  color: rgba(244, 248, 255, 0.94);
}

.bdp-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bdp-timesig {
  font: 700 1.1rem/1 "Syne", sans-serif;
  color: var(--bdp-accent);
  letter-spacing: -1px;
  min-width: 32px;
  text-align: center;
}

.bdp-phrase-pips {
  display: flex;
  gap: 4px;
}
.bdp-phrase-pip {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  transition: background 120ms;
}
.bdp-phrase-pip.is-on { background: var(--bdp-accent); }

.bdp-close-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: rgba(244,248,255,0.55);
  font: 700 0.82rem/1 "IBM Plex Mono", monospace;
  cursor: pointer;
  transition: background 120ms, color 120ms;
  flex-shrink: 0;
}
.bdp-close-btn:hover { background: rgba(255,255,255,0.1); color: rgba(244,248,255,0.96); }

/* ── BPM + beat pulse row ── */
.bdp-top-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.bdp-bpm-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 90px;
}

.bdp-bpm-value {
  font: 800 4rem/0.9 "Syne", sans-serif;
  color: var(--bdp-accent);
  letter-spacing: -3px;
  line-height: 1;
  transition: color 120ms;
}
.bdp-bpm-value.is-silent { color: var(--bdp-accent-dim); }

.bdp-bpm-label {
  font: 700 0.58rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(198, 225, 242, 0.35);
}

.bdp-confidence-bar {
  width: 72px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.07);
  overflow: hidden;
  margin-top: 5px;
}
.bdp-confidence-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--bdp-accent-dim);
  transition: width 200ms ease;
}

/* Bar arc canvas */
.bdp-bar-arc {
  display: block;
  flex-shrink: 0;
  width: 88px; height: 88px;
}

/* Energy + groove block */
.bdp-meta-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.bdp-meta-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bdp-meta-label {
  font: 700 0.54rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(198, 225, 242, 0.3);
}

.bdp-energy-bar {
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.07);
  overflow: hidden;
}
.bdp-energy-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--bdp-accent);
  transition: width 80ms ease;
}

.bdp-groove-track {
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.07);
  position: relative;
}
.bdp-groove-pointer {
  position: absolute;
  top: -2px;
  width: 3px; height: 9px;
  border-radius: 2px;
  background: var(--bdp-accent);
  transform: translateX(-50%);
  transition: left 180ms ease;
}
.bdp-groove-labels {
  display: flex;
  justify-content: space-between;
  font: 400 0.52rem/1 "IBM Plex Mono", monospace;
  color: rgba(198, 225, 242, 0.28);
  margin-top: 2px;
}

/* ── Beat grid ── */
.bdp-grid-section {
  padding: 12px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.bdp-section-label {
  font: 700 0.56rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(198, 225, 242, 0.3);
  margin-bottom: 8px;
}

.bdp-beat-grid {
  display: flex;
  gap: 6px;
}

.bdp-beat-cell {
  flex: 1;
  padding: 10px 4px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.03);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: background 100ms, border-color 100ms, box-shadow 100ms;
}
.bdp-beat-cell.is-active {
  background: var(--bdp-accent-bg);
  border-color: var(--bdp-accent-dim);
  box-shadow: 0 0 18px var(--bdp-accent-glow);
}
.bdp-beat-cell.is-downbeat.is-active {
  background: rgba(244, 192, 96, 0.12);
  border-color: var(--bdp-accent);
  box-shadow: 0 0 28px rgba(244, 192, 96, 0.36);
}
.bdp-beat-cell.is-backbeat.is-active {
  background: rgba(132, 205, 255, 0.08);
  border-color: rgba(132, 205, 255, 0.4);
  box-shadow: 0 0 20px rgba(132, 205, 255, 0.22);
}

.bdp-beat-number {
  font: 800 1.3rem/1 "Syne", sans-serif;
  color: rgba(244, 248, 255, 0.55);
  transition: color 100ms;
}
.bdp-beat-cell.is-active    .bdp-beat-number { color: var(--bdp-accent); }
.bdp-beat-cell.is-backbeat.is-active .bdp-beat-number { color: var(--bdp-blue); }

.bdp-beat-type {
  font: 700 0.5rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(198, 225, 242, 0.25);
  transition: color 100ms;
}
.bdp-beat-cell.is-active .bdp-beat-type { color: var(--bdp-accent-dim); }

/* ── Subdivision row ── */
.bdp-subdiv-section {
  padding: 8px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.bdp-subdiv-row {
  display: flex;
  gap: 5px;
  align-items: center;
}

.bdp-subdiv-dot {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  transition: background 60ms, box-shadow 60ms;
  position: relative;
}
.bdp-subdiv-dot.is-beat {
  height: 12px;
  border-radius: 6px;
  background: rgba(244, 192, 96, 0.15);
}
.bdp-subdiv-dot.is-lit {
  background: var(--bdp-accent);
  box-shadow: 0 0 8px var(--bdp-accent-glow);
}
.bdp-subdiv-dot.is-beat.is-lit {
  background: var(--bdp-accent);
  box-shadow: 0 0 16px rgba(244, 192, 96, 0.5);
}
.bdp-subdiv-dot.is-and.is-lit {
  background: var(--bdp-blue);
  box-shadow: 0 0 8px rgba(132, 205, 255, 0.35);
}

/* ── Pattern roll ── */
.bdp-pattern-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.bdp-pattern-canvas {
  width: 100%;
  height: 64px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  display: block;
  border: 1px solid rgba(255,255,255,0.06);
}

/* ── Event log ── */
.bdp-log-section {
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.bdp-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bdp-log-clear-btn {
  border: none;
  background: transparent;
  font: 700 0.54rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--bdp-accent-dim);
  cursor: pointer;
  transition: color 100ms;
}
.bdp-log-clear-btn:hover { color: var(--bdp-accent); }

.bdp-log-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 26px;
  max-height: 56px;
  overflow-y: auto;
  scrollbar-width: none;
}

.bdp-event-chip {
  padding: 3px 8px;
  border-radius: 6px;
  font: 700 0.6rem/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.05em;
  white-space: nowrap;
  animation: bdp-pop 120ms ease;
  border: 1px solid transparent;
}
@keyframes bdp-pop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.bdp-event-chip.is-downbeat    { background: rgba(244,192, 96,0.10); border-color: rgba(244,192, 96,0.22); color: rgba(244,192, 96,0.90); }
.bdp-event-chip.is-backbeat    { background: rgba(132,205,255,0.08); border-color: rgba(132,205,255,0.20); color: rgba(132,205,255,0.80); }
.bdp-event-chip.is-mid         { background: rgba(200,180,255,0.07); border-color: rgba(200,180,255,0.18); color: rgba(200,180,255,0.75); }
.bdp-event-chip.is-subdivision { background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.10); color: rgba(198,225,242,0.45); }
.bdp-event-chip.is-phrase_start{ background: rgba(157,243,196,0.08); border-color: rgba(157,243,196,0.22); color: rgba(157,243,196,0.85); }
.bdp-event-chip.is-energy_peak { background: rgba(255,110, 90,0.08); border-color: rgba(255,110, 90,0.22); color: rgba(255,110, 90,0.85); }
.bdp-event-chip.is-energy_drop { background: rgba(100,140,255,0.08); border-color: rgba(100,140,255,0.18); color: rgba(100,140,255,0.75); }
.bdp-event-chip.is-energy_build{ background: rgba(244,192, 96,0.07); border-color: rgba(244,192, 96,0.16); color: rgba(244,192, 96,0.65); }

/* ── Overlay button ── */
.aro-beat-btn {
  width: 100%;
  padding: 8px 14px;
  border: 1px solid rgba(244, 192, 96, 0.22);
  border-radius: 11px;
  background: rgba(244, 192, 96, 0.05);
  color: rgba(244, 192, 96, 0.72);
  font: 700 0.66rem/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.aro-beat-btn:hover {
  background: rgba(244, 192, 96, 0.12);
  border-color: rgba(244, 192, 96, 0.42);
  color: rgba(244, 192, 96, 0.96);
}

@media (max-width: 600px) {
  .bdp-panel {
    top: auto;
    right: 12px; left: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
  }
}
