/* ============================================================================
 * Reactions (React tab, js/live/links-panel.js), the reaction flash layer
 * (js/core/links.js), the Beat Grid strip (js/core/beat-grid.js) and the
 * Auto Video "Reactions" card + timeline notes.
 * ========================================================================== */

/* ---------- flash layer on the stage ------------------------------------- */
#linkFlash {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: #fff; opacity: 0; mix-blend-mode: screen;
}

/* ---------- editor ------------------------------------------------------------ */
.lk { position: relative; }
.lk-master { margin-bottom: var(--space-2); }
.lk .lk-blurb { margin-top: 6px; min-height: 16px; }
.lk-list { list-style: none; margin: var(--space-3) 0; padding: 0; display: grid; gap: 8px; }
.lk-empty {
  padding: 14px 12px; border-radius: var(--radius-3); border: 1px dashed var(--hairline-2);
  color: var(--ink-3); font-size: 13px; text-align: center; line-height: 1.45;
}
.lk-card {
  --lit: 0;
  background: var(--surface-3); border: 1px solid var(--hairline); border-radius: var(--radius-4);
  transition: border-color .2s var(--ease-out), background .2s var(--ease-out);
}
.lk-card.open { background: var(--surface-4); border-color: var(--hairline-2); }
.lk-card.off .lk-title b, .lk-card.off .lk-title small { opacity: .45; }
.lk-top { display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 10px; min-height: 48px; }
.lk-light {
  flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) calc(var(--lit) * 100%), var(--surface-5));
  box-shadow: 0 0 calc(var(--lit) * 14px) calc(var(--lit) * 2px) var(--accent-glow);
}
.lk-title {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left;
  background: none; border: 0; color: inherit; font: inherit; padding: 6px 0; cursor: pointer;
}
.lk-title b { font-size: 13px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lk-title small { font-size: 11px; color: var(--ink-3); }
.lk-title em { font-style: normal; color: var(--ink-4); }
.lk-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.lk-body { padding: 2px 12px 12px; display: grid; gap: 8px; }
.lk-pair { display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: 6px; }
.lk-arrow { align-self: center; color: var(--ink-4); }
.lk-pick {
  display: flex; flex-direction: column; gap: 3px; min-width: 0; min-height: 56px; text-align: left; cursor: pointer;
  padding: 8px 10px; border-radius: var(--radius-3); border: 1px solid var(--hairline-2);
  background: var(--surface-3); color: inherit; font: inherit;
}
.lk-pick:hover { border-color: var(--ink-5); }
.lk-pick small { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-4); }
.lk-pick b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lk-pick .lk-sub { font-size: 11px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lk-meter {
  display: block; height: 4px; border-radius: 2px; background: var(--surface-5); overflow: hidden; margin-top: 2px;
}
.lk-meter i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 2px; }
.lk-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lk-seg button {
  min-height: 44px; border-radius: var(--radius-3); border: 1px solid var(--hairline-2); background: var(--surface-3);
  color: var(--ink-2); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.lk-seg button small { font-size: 10px; font-weight: 400; color: var(--ink-4); }
.lk-seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.lk-seg button:disabled { opacity: .35; cursor: not-allowed; }
.lk-slider { padding: 2px 0; }
.lk-slider label { width: 72px; }
.lk-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.lk-actions .live-mini { min-height: 40px; }
.lk-actions .armed { border-color: var(--accent); background: var(--accent-soft); animation: lkPulse 1s ease-in-out infinite; }
.lk-actions .lk-del { margin-left: auto; color: var(--err); }
@keyframes lkPulse { 50% { box-shadow: 0 0 0 4px var(--accent-soft); } }
.lk-add { margin-bottom: var(--space-2); }
.lk-file { margin-top: var(--space-2); flex-wrap: nowrap; }
.lk-file .action-btn { flex: 1 1 0; }

/* Source / action picker: a sheet over the editor. */
.lk-sheet {
  position: fixed; z-index: 60; inset: auto 0 0 0; max-height: 78vh; display: flex; flex-direction: column;
  background: #0e0e10; border-top: 1px solid var(--hairline-2); border-radius: 16px 16px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .6); padding-bottom: env(safe-area-inset-bottom);
}
.lk-sheet[hidden] { display: none; }
@media (min-width: 768px) {
  /* Desktop: over the drawer itself. */
  #panel .lk-sheet { position: absolute; inset: -8px -8px auto -8px; max-height: min(640px, 80vh); border-radius: var(--radius-5); border: 1px solid var(--hairline-2); }
  .lk-modal .lk-sheet { position: absolute; inset: 0; max-height: none; border-radius: var(--radius-5); }
}
.lk-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px; }
.lk-sheet-head b { font-size: 15px; }
.lk-x {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-4); color: var(--ink);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.lk-sheet-tools { display: flex; gap: 8px; padding: 4px 14px 8px; }
.lk-sheet-tools .lk-search { flex: 1 1 auto; min-width: 0; width: auto; margin: 0; }
.lk-sheet-tools .action-btn { width: auto; flex: 0 0 auto; padding-left: 16px; padding-right: 16px; }
.lk-options { overflow-y: auto; padding: 0 14px 14px; -webkit-overflow-scrolling: touch; }
.lk-group h4 {
  margin: 12px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4);
}
.lk-opt {
  width: 100%; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 10px; margin-bottom: 4px;
  text-align: left; cursor: pointer; border-radius: var(--radius-3); border: 1px solid transparent;
  background: var(--surface-3); color: inherit; font: inherit;
}
.lk-opt:hover, .lk-opt:focus-visible { border-color: var(--hairline-2); background: var(--surface-4); outline: none; }
.lk-opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lk-opt-text b { font-size: 13px; font-weight: 600; }
.lk-opt-text small { font-size: 11px; color: var(--ink-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lk-opt .lk-meter { flex: 0 0 64px; margin: 0; }
body.vz-learning .lk-learn-any { border-color: var(--accent); background: var(--accent-soft); animation: lkPulse 1s ease-in-out infinite; }

/* The editor in a sheet (Auto Video "Reactions" → Edit). */
.lk-modal {
  position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.lk-modal-card {
  position: relative; width: min(560px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  background: rgba(16, 16, 18, .98); border: 1px solid var(--hairline-2); border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom); color: var(--ink);
}
@media (min-width: 768px) { .lk-modal { align-items: center; } .lk-modal-card { border-radius: var(--radius-5); } }
.lk-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--hairline); }
.lk-modal-head b { font-size: 16px; }
.lk-modal-body { overflow-y: auto; padding: 12px 16px 16px; }

/* ---------- Beat Grid strip ------------------------------------------------- */
.icon-btn.bg-toggle.active { background: var(--accent-soft); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }
.bg-wrap { max-width: 1400px; margin: 10px auto 0; }
.bg-wrap[hidden] { display: none; }
.bg-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.bg-btn {
  height: 30px; min-width: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--hairline-2);
  background: var(--surface-4); color: var(--ink-2); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.bg-btn:hover:not(:disabled) { background: var(--surface-5); }
.bg-btn:disabled { opacity: .4; cursor: default; }
.bg-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.bg-rec .bg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-4); }
.bg-rec.on { background: rgba(255, 50, 70, .2); border-color: var(--record); color: #ffc2ca; }
.bg-rec.on .bg-dot { background: var(--record); box-shadow: 0 0 8px var(--record-glow); animation: lkPulse 1s ease-in-out infinite; }
.bg-seg { display: inline-flex; gap: 2px; }
.bg-snap, .bg-bpm {
  display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 4px 0 8px; border-radius: 8px;
  background: var(--surface-3); border: 1px solid var(--hairline); font-size: 11px; color: var(--ink-3);
}
.bg-snap select, .bg-bpm input {
  background: transparent; border: 0; color: var(--ink); font: inherit; font-size: 12px; font-weight: 600; height: 28px;
}
.bg-snap select option { background: #111; }
.bg-bpm input { width: 52px; text-align: right; font-family: var(--font-mono); }
.bg-bpm span { padding-right: 4px; }
.bg-status { flex: 1 1 160px; min-width: 0; font-size: 11px; color: var(--ink-3); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bg-body {
  display: flex; border-radius: var(--radius-3); overflow: hidden; border: 1px solid var(--hairline-2);
  background: rgba(10, 10, 12, .82); touch-action: none;
}
.bg-lanes { flex: 0 0 96px; display: flex; flex-direction: column; border-right: 1px solid var(--hairline-2); }
.bg-lane {
  --lit: 0;
  height: var(--row, 14px); display: flex; align-items: center; gap: 5px; padding: 0 6px; border: 0; background: none;
  color: var(--ink-2); font: inherit; font-size: 10px; cursor: pointer; text-align: left; overflow: hidden;
  background: color-mix(in srgb, var(--c) calc(var(--lit) * 45%), transparent);
}
.bg-lane i { flex: 0 0 6px; height: 6px; border-radius: 50%; background: var(--c); box-shadow: 0 0 calc(var(--lit) * 8px) var(--c); }
.bg-lane span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bg-lane kbd { font: inherit; font-family: var(--font-mono); color: var(--ink-4); margin-right: 4px; }
.bg-canvas { flex: 1; min-width: 0; display: block; cursor: crosshair; touch-action: none; }

@media (max-width: 767px) {
  /* Phones: the toggle sits above the transport row (the row is full). */
  #controls .bg-toggle { position: absolute; right: max(16px, env(safe-area-inset-right)); top: -14px; width: 40px; height: 32px; border-radius: 10px; }
  .bg-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .bg-bar::-webkit-scrollbar { display: none; }
  .bg-btn, .bg-snap, .bg-bpm { height: 36px; flex: 0 0 auto; }
  .bg-status { display: none; }
  .bg-lanes { flex-basis: 74px; }
  .bg-lane { font-size: 10px; }
}

/* ---------- Auto Video: Reactions card + grid notes on the timeline --------- */
.mv-links-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.mv-links-row .tts-select { flex: 1; margin: 0; }
.mv-tl-grid { position: relative; margin-top: 4px; border-radius: 4px; background: rgba(255, 255, 255, .03); overflow: hidden; }
.mv-tl-grid[hidden] { display: none; }
.mv-tl-grid canvas { display: block; width: 100%; height: 100%; }
