/* ════════════════════════════════════════════════════════════════════
   Notate drum bar lens — PRODUCTION beat-lens design, verbatim copy.
   Source: public/css/beat-lens.css (v1.5). D5 isolation: this is a COPY —
   the notate page loads nothing from /static/css. Class names stay bl-*
   so the sheet is pixel-identical to the transcription editor's lens.
   Diff against the source when production restyles:
     diff public/css/beat-lens.css public/notate/notate-lens.css
   Deltas from source: score-band section removed (#nt-lens-band in
   notate.css does that job), loop/hold chip styles kept (chips hidden
   until the nt-player loop lands), print hide added. Instrument keys
   section (end of file): html.gm-keys is html.nt-keys here, no note row
   rules (the sheet has none; its tools drawer has a row of its own), the
   strip lifts over the practice audio bar instead of the player, and the
   line's label sits inside the row.
   ════════════════════════════════════════════════════════════════════ */

/* ── bottom sheet ── */
#bl-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9600;
  margin: 0 auto; max-width: 620px;
  background: linear-gradient(180deg, #191b25, #14161f);
  border: 1px solid rgba(255, 255, 255, .12); border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -16px 44px rgba(0, 0, 0, .5);
  color: #eae8e1;
  transform: translateY(106%);
  transition: transform .28s cubic-bezier(.2, .9, .25, 1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
  font-family: system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', sans-serif;
}
#bl-sheet.bl-open { transform: none; }
/* The sheet must never exceed the viewport: at 320x568 (SE) / phone landscape
   the header row (grab/✕/undo) overflowed above the screen with no way out.
   Content taller than the cap scrolls inside the sheet instead. */
#bl-sheet {
  max-height: calc(100vh - 8px);
  max-height: calc(100dvh - 8px);
  /* no overscroll-behavior: when the content fits (the usual case) wheel/pan
     over the sheet must keep chaining to the score behind it, as before */
  overflow-y: auto;
}
@media (prefers-reduced-motion: reduce) { #bl-sheet { transition: none; } }

.bl-grab { display: flex; justify-content: center; padding: 7px 0 3px; cursor: pointer; }
.bl-grab span { width: 40px; height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .22); }

.bl-head {
  display: flex; align-items: center; gap: 6px; padding: 2px 12px 8px;
  overflow-x: auto; scrollbar-width: none; white-space: nowrap;
}
.bl-head::-webkit-scrollbar { display: none; }
.bl-spacer { flex: 1; min-width: 4px; }
.bl-title { font-size: 13px; font-weight: 700; letter-spacing: -.01em; padding: 0 2px; }

.bl-chip {
  flex: none; font-size: 11px; font-weight: 600; color: rgba(234, 232, 225, .8);
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 8px; padding: 6px 9px; cursor: pointer; line-height: 1;
}
.bl-chip:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.bl-chip.bl-x:hover { background: rgba(224, 122, 114, .18); color: #e07a72; border-color: rgba(224, 122, 114, .4); }
/* the ✕ stays reachable when the header scrolls (narrow phones, v1.5 🔁 chip) */
.bl-head .bl-x {
  position: sticky; right: 0; z-index: 1;
  background: #191b25;
  box-shadow: -10px 0 10px -6px rgba(0, 0, 0, .6);
}

.bl-dots { display: flex; gap: 5px; margin: 0 2px; flex: none; }
.bl-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .18); background: transparent; cursor: pointer;
  font-size: 10.5px; font-weight: 700; color: rgba(234, 232, 225, .55);
  display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0;
}
.bl-dot.bl-cur { background: #d9b46a; border-color: #d9b46a; color: #2a2008; }

.bl-subbadge {
  flex: none; font-size: 9.5px; font-weight: 700; letter-spacing: .04em;
  color: rgba(234, 232, 225, .5); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 6px; padding: 4px 7px; line-height: 1;
  font-family: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', monospace;
}

/* ── one-beat grid: lanes × N columns, sized to NEVER scroll ── */
.bl-grid {
  display: grid; gap: 4px; padding: 2px 12px 8px; align-items: stretch;
  /* grid-template-columns set from JS: 44px repeat(n, 1fr) */
  /* notate delta: the grid owns every gesture so PAINT-DRAG sweeps work on
     touch/pen (the ONE proven drag recipe — mobile audit 2026-07-16) */
  touch-action: none;
}
.bl-corner { min-height: 16px; }
.bl-colhead {
  font-size: 10px; font-weight: 700; color: rgba(234, 232, 225, .45);
  text-align: center; padding: 2px 0; line-height: 1;
  font-family: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', monospace;
}
.bl-colhead.bl-b1 { color: #eae8e1; font-size: 11px; }
.bl-lab {
  display: flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 700; color: rgba(234, 232, 225, .6);
  font-family: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', monospace;
}
.bl-sw { width: 3px; height: 16px; border-radius: 2px; flex: none; display: inline-block; }
.bl-cell {
  position: relative; min-height: 30px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .07); background: rgba(255, 255, 255, .025);
  display: flex; align-items: center; justify-content: center;
  transition: background .08s;
}
.bl-cell:hover { background: rgba(255, 255, 255, .09); }
/* toggled cell = whole-cell color fill (matches the classic grid look) */
.bl-cell.bl-on {
  border-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), 0 1px 3px rgba(0, 0, 0, .4);
}
.bl-cell.bl-ghost { opacity: .5; outline: 1.5px dashed rgba(255, 255, 255, .55); outline-offset: -2px; }
.bl-acc {
  position: absolute; top: 1px; right: 4px; font-size: 10px; font-weight: 900;
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); line-height: 1; pointer-events: none;
}
.bl-flam {
  position: absolute; top: 1px; left: 4px; font-size: 9px;
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); line-height: 1; pointer-events: none;
}
@keyframes blPulse { 0% { box-shadow: 0 0 0 0 rgba(217, 180, 106, .6); } 100% { box-shadow: 0 0 0 12px rgba(217, 180, 106, 0); } }
.bl-cell.bl-pulse { animation: blPulse .6s ease-out 2; }
@media (prefers-reduced-motion: reduce) { .bl-cell.bl-pulse { animation: none; } }

/* bar strip: WRAPS so no button is ever cut off; roomier layout + slightly
   bigger buttons now that wrapping freed the space (owner feedback) */
.bl-foot {
  display: flex; align-items: center; gap: 7px 6px; flex-wrap: wrap; padding: 2px 12px 13px;
}
.bl-foot .bl-chip { font-size: 12px; padding: 8px 12px; border-radius: 9px; }
.bl-foot .bl-chip.bl-hp-on {  /* this bar has that crescendo: pressing again takes it off */
  background: rgba(217, 180, 106, .16);
  border-color: rgba(217, 180, 106, .5);
  color: #e7c987;
}

/* ── note-action row (score-tapped note; the unified replacement for the
   old floating chip card — one surface, always the lens) ── */
.bl-noterow {
  display: none; align-items: center; gap: 5px; padding: 0 12px 7px;
  overflow-x: auto; scrollbar-width: none; white-space: nowrap;
}
.bl-noterow::-webkit-scrollbar { display: none; }
.bl-nr-label {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 10.5px; font-weight: 700; color: rgba(234, 232, 225, .8);
  font-family: ui-monospace, 'Cascadia Mono', monospace;
  border: 1px dashed rgba(217, 180, 106, .45); border-radius: 8px; padding: 5px 8px;
}
.bl-noterow button {
  flex: none; font-size: 11.5px; font-weight: 600; color: #eae8e1;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; line-height: 1;
}
.bl-noterow button:hover { background: rgba(255, 255, 255, .14); }
.bl-noterow .bl-nr-drum { font-family: ui-monospace, monospace; font-size: 10px; padding: 5px 7px; }
.bl-noterow .bl-nr-drum.bl-cur { border-color: #d9b46a; color: #e7c987; background: rgba(217, 180, 106, .13); }
.bl-danger { color: #f0958d !important; }
.bl-danger:hover { background: rgba(224, 122, 114, .16) !important; }

/* ── desktop full-bar mode ── */
#bl-sheet.bl-wide { max-width: 960px; }
#bl-sheet.bl-wide .bl-cell { min-height: 26px; }
.bl-cell.bl-bs { border-left: 2px solid rgba(217, 180, 106, .35); }
.bl-colhead[data-bs] { cursor: pointer; }
.bl-colhead[data-bs]:hover { color: #e7c987; }
.bl-stick {
  position: absolute; bottom: 1px; right: 3px; font-size: 8px; font-weight: 800;
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); line-height: 1; pointer-events: none;
  font-family: ui-monospace, monospace;
}

/* ── bar loop chip: gold while looping (nt-player loop, phase B) ── */
#bl-loop:disabled { opacity: .3; cursor: default; }
#bl-loop.bl-loop-on {
  background: rgba(217, 180, 106, .22) !important;
  border-color: #d9b46a !important;
  animation: blLoopGlow 1.4s ease-in-out infinite;
}
@keyframes blLoopGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 180, 106, 0); }
  50% { box-shadow: 0 0 0 4px rgba(217, 180, 106, .28); }
}
@media (prefers-reduced-motion: reduce) { #bl-loop.bl-loop-on { animation: none; } }

/* ── mode row (grid-parity: arm a mode, then click a target) ── */
.bl-modes {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap; padding: 0 12px 7px;
}
.bl-msep { width: 1px; height: 18px; background: rgba(255, 255, 255, .14); margin: 0 3px; flex: none; }
.bl-mode-btn.bl-armed {
  background: rgba(217, 180, 106, .16) !important;
  border-color: rgba(217, 180, 106, .5) !important;
  color: #e7c987 !important;
}
.bl-selectable {
  outline: 1.5px dashed rgba(217, 180, 106, .65); outline-offset: -1px;
  cursor: pointer; color: #e7c987 !important;
}

/* ── cell popover (long-press) ── */
#bl-popover {
  position: fixed; z-index: 9660; display: none; flex-direction: column; gap: 4px;
  background: rgba(20, 22, 30, .97); border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 12px; padding: 6px; box-shadow: 0 12px 36px rgba(0, 0, 0, .55);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  font-family: system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', sans-serif;
}
#bl-popover.bl-show { display: flex; }
#bl-popover { max-width: calc(100vw - 16px); }
.bl-pop-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.bl-pop-row input[type="text"],
.bl-pop-row input[type="number"] {
  flex: 1; min-width: 110px; font-size: 12px; color: #eae8e1;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px; padding: 7px 9px; outline: none;
}
.bl-pop-row input:focus { border-color: rgba(217, 180, 106, .55); }
#bl-popover button {
  font-size: 12px; font-weight: 600; color: #eae8e1;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px; padding: 8px 11px; cursor: pointer; white-space: nowrap; line-height: 1;
}
#bl-popover button:hover { background: rgba(255, 255, 255, .14); }

/* ── toast (v6 showToast stand-in — the notate page has no shared toast) ── */
#bl-toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 9700;
  background: rgba(20, 22, 30, .96); color: #eae8e1;
  border: 1px solid rgba(255, 255, 255, .16); border-radius: 10px;
  padding: 9px 14px; font-size: 12.5px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); pointer-events: none;
  opacity: 0; transition: opacity .18s;
  font-family: system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', sans-serif;
}
#bl-toast.bl-show { opacity: 1; }

/* ── small screens: lanes must fit with the score still visible above ── */
@media (max-width: 600px) {
  .bl-cell { min-height: 24px; border-radius: 6px; }
  .bl-grid { gap: 3px; padding: 2px 10px 6px; }
  .bl-chip { padding: 6px 8px; }
  .bl-lab { font-size: 9.5px; }
}
@media (max-height: 520px) {
  .bl-cell { min-height: 18px; }
  .bl-grid { gap: 2px; }
  .bl-grab { padding: 4px 0 2px; }
  .bl-head { padding-bottom: 4px; }
  .bl-foot { padding-bottom: 6px; }
}

@media print {
  #bl-sheet, #bl-popover, #bl-toast { display: none !important; }
}

/* ── instrument keys: PC only, these elements exist only for an account DRUMSHEET_LENS_KEYS admits ── */
.bl-key {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 3px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  font: 800 12.5px/1 ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', monospace;
  color: #14161f; background: #eae8e1;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25);
}
.bl-colhead.bl-kb { color: #e7c987; }
.bl-cell.bl-kb:not(.bl-on) { background: rgba(217, 180, 106, .16); }
.bl-cell.bl-kb.bl-on { outline: 2px solid rgba(255, 255, 255, .8); outline-offset: -2px; }
.bl-keyhint { padding: 6px 12px 0; font-size: 11.5px; line-height: 1.35; color: rgba(234, 232, 225, .6); }
.bl-keyhint[hidden] { display: none; }
/* the keys in number order, in the header's empty middle: the sheet does not grow */
.bl-legend { display: flex; align-items: center; gap: 4px; flex: none; margin-left: 6px; }
.bl-lg {
  display: inline-flex; align-items: center; gap: 3px; padding: 2px 5px 2px 2px; border-radius: 6px;
  font: 700 10px/1 ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', monospace;
  color: rgba(234, 232, 225, .78); background: rgba(255, 255, 255, .05);
  box-shadow: inset 0 -2px 0 var(--lg);
}
.bl-lg kbd {
  min-width: 16px; height: 16px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center;
  font: 800 11px/1 ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', monospace; color: #14161f; background: #eae8e1;
}
.bl-lg.bl-has { color: #fff; background: var(--lg); }
/* where a number lands: one line, over any bar. Its label stays in the row's headroom above the staff */
#bl-aim { position: absolute; display: none; width: 3px; margin-left: -1.5px; border-radius: 2px; background: #ea7a1c; pointer-events: none; z-index: 16; }
#bl-aim span {
  position: absolute; top: 1px; left: 50%; transform: translateX(-50%); padding: 1px 4px; border-radius: 4px; white-space: nowrap;
  font: 700 12px/1.2 system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', sans-serif; color: #fff; background: #ea7a1c;
}
/* grid folded: only the key strip, so nearly the whole score shows */
#bl-sheet.bl-strip .bl-grab,
#bl-sheet.bl-strip .bl-modes,
#bl-sheet.bl-strip .bl-grid,
#bl-sheet.bl-strip .bl-keyhint,
#bl-sheet.bl-strip .bl-foot { display: none; }
#bl-sheet.bl-strip { border-radius: 12px; border-bottom: 1px solid rgba(255, 255, 255, .12); }
#bl-sheet.bl-strip .bl-head { padding: 7px 10px; }
#bl-sheet.bl-strip.bl-open { bottom: var(--bl-strip-lift, 0px); }
html.nt-keys #bl-toast { bottom: max(18px, var(--bl-strip-top, 18px)); }
/* PC: a lighter shadow keeps the last score row above the sheet readable; short windows get smaller cells */
html.nt-keys #bl-sheet.bl-wide { box-shadow: 0 -4px 14px rgba(0, 0, 0, .28); }
@media (max-height: 720px) { html.nt-keys #bl-sheet.bl-wide .bl-cell { min-height: 22px; } }
/* a narrow PC window: the fold button shrinks to an arrow (its title keeps the name) so the keys and the ✕ all fit */
@media (max-width: 959px) {
  #bl-strip-btn { font-size: 0; padding: 6px 8px; }
  #bl-strip-btn::before { content: '▾'; font-size: 12px; }
  #bl-sheet.bl-strip #bl-strip-btn::before { content: '▴'; }
}
/* a narrow PC window: header + grid + one tool row, the mode row and the bar strip open from its chip (.bl-compact, public/css/beat-lens.css) */
#bl-sheet.bl-compact .bl-modes,
#bl-sheet.bl-compact .bl-foot { display: none; }
#bl-sheet:not(.bl-wide) .bl-noterow { padding-bottom: 8px; }
#bl-sheet .bl-noterow .bl-tools-btn {
  position: sticky; right: 0; z-index: 1;
  border-color: rgba(217, 180, 106, .45); color: #e7c987;
  background: #171922;
  box-shadow: -10px 0 10px -6px rgba(0, 0, 0, .6);
}
#bl-sheet .bl-noterow .bl-tools-btn.bl-on {
  background: linear-gradient(rgba(217, 180, 106, .16), rgba(217, 180, 106, .16)), #171922;
}
#bl-sheet .bl-noterow .bl-armed-chip {
  display: inline-flex; align-items: center; gap: 4px; flex: 0 1 auto; min-width: 0;
  background: rgba(217, 180, 106, .16); border-color: rgba(217, 180, 106, .5); color: #e7c987;
}
#bl-sheet .bl-noterow .bl-armed-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* where the edit landed: a column at the edited beat (solid orange = added or changed, dashed red = removed), and on close an outline around every bar the session edited */
.bl-note-flash {
  position: absolute; width: 22px; pointer-events: none; z-index: 6;
  border-radius: 6px; box-sizing: border-box;
  background: rgba(249, 115, 22, .26); border: 2px solid #f97316;
  animation: blEditFade 1.6s ease-out forwards;
}
.bl-note-flash.bl-removed { border-style: dashed; border-color: #ef4444; background: rgba(239, 68, 68, .16); }
.bl-edit-flash {
  position: absolute; pointer-events: none; z-index: 6;
  border-radius: 6px; box-sizing: border-box;
  border: 2px solid #f97316; background: rgba(249, 115, 22, .12);
  animation: blEditFade 2.6s ease-out forwards;
}
@keyframes blEditFade { 0% { opacity: 1; } 65% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .bl-note-flash, .bl-edit-flash { animation: none; } }
@media print {
  #bl-aim, .bl-note-flash, .bl-edit-flash { display: none !important; }
}
