/*
 * Beat existing-voice: Patchbay, an audio-routing panel
 * (web/landing/sections/existing-voice.html). Linked in the page head by lib/landing.ts
 * while the beat is enabled; the shells' sheets it builds on are linked by the page
 * itself, once each and before every section sheet. Every class here starts with the
 * beat id and every rule is scoped by [data-beat]: the frame's variant
 * (existing-voice-patchbay) is styled here and nowhere else.
 *
 * Layout: three panels in a row, joined by two patch cables (pcm out of the audio, cues out
 * of the stream), each pulsing as a message passes; the wire rail under them when shown.
 * Narrow: the panels stack into a numbered sequence 1, 2, 3, the cables run down between
 * them.
 */

[data-beat="existing-voice"] .use-case-mount { margin-top: clamp(24px, 4vh, 40px); }

[data-beat="existing-voice"] .demo-frame-body { grid-template-areas: "main" "aside"; }

@container demo-frame (min-width: 640px) {
  [data-beat="existing-voice"] .demo-frame-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "main" "aside";
  }
}

/* ── The rack: three panels and the cables between them ────────────────── */

[data-beat="existing-voice"] .existing-voice-rack {
  --cable: 38px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--cable);
  margin: 0;
  padding: 0;
  list-style: none;
}

@container demo-frame (min-width: 760px) {
  [data-beat="existing-voice"] .existing-voice-rack {
    --cable: 44px;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) minmax(250px, .95fr);
    align-items: stretch;
  }
}

[data-beat="existing-voice"] .existing-voice-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 55%, var(--panel));
}

[data-beat="existing-voice"] .existing-voice-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  min-width: 0;
}

[data-beat="existing-voice"] .existing-voice-panel-n {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  align-self: center;
  border: 1px solid var(--accent);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}

[data-beat="existing-voice"] .existing-voice-panel-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

[data-beat="existing-voice"] .existing-voice-tag {
  margin-left: auto;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  color: var(--muted);
}

[data-beat="existing-voice"] .existing-voice-mono {
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

[data-beat="existing-voice"] .existing-voice-source {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin: 0;
  font-size: 13px;
}

[data-beat="existing-voice"] .existing-voice-source .existing-voice-mono { color: var(--muted); }

/* The waveform: dim, and lit up to what has been sent. */
[data-beat="existing-voice"] .existing-voice-wave {
  position: relative;
  height: 52px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--ink);
  color: color-mix(in srgb, var(--muted) 55%, transparent);
}

[data-beat="existing-voice"] .existing-voice-wave canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
}

[data-beat="existing-voice"] .existing-voice-wave-lit {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  overflow: hidden;
  color: var(--accent);
}

/* The frames: one cell per 100 ms frame of the connection, lit as it is sent. */
[data-beat="existing-voice"] .existing-voice-frames {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9px, 1fr));
  gap: 3px;
}

[data-beat="existing-voice"] .existing-voice-frames i {
  height: 9px;
  border-radius: 2px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line);
}

[data-beat="existing-voice"] .existing-voice-frames i[data-sent] {
  background: var(--accent);
  box-shadow: none;
}

[data-beat="existing-voice"] .existing-voice-readout {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
}

[data-beat="existing-voice"] .existing-voice-transcript {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

[data-beat="existing-voice"] .existing-voice-label {
  display: block;
  margin-bottom: 2px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

[data-beat="existing-voice"] .existing-voice-transcript-text { font-family: var(--serif); font-size: 15px; }

/* The cue strip: each cue a bar as tall as the mouth is open, on the audio's own axis. */
[data-beat="existing-voice"] .existing-voice-strip {
  position: relative;
  height: 56px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--ink);
}

[data-beat="existing-voice"] .existing-voice-cue {
  position: absolute;
  bottom: 0;
  min-width: 1px;
  height: calc(10px + 40px * var(--open, .3));
  border-left: 1px solid var(--ink);
  border-radius: 2px 2px 0 0;
  background: color-mix(in srgb, var(--accent) calc(25% + 60% * var(--open, .3)), var(--panel-2));
  animation: existing-voice-land .6s ease-out;
}

[data-beat="existing-voice"] .existing-voice-open {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  opacity: .5;
}

[data-beat="existing-voice"] .existing-voice-strip-head {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--t, 0) * 100%);
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  opacity: .8;
}

@keyframes existing-voice-land {
  from { box-shadow: 0 0 0 2px var(--accent); }
  to { box-shadow: 0 0 0 0 transparent; }
}

[data-beat="existing-voice"] .existing-voice-slices {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 2.6em;
  margin: 0;
  padding: 0;
  list-style: none;
}

[data-beat="existing-voice"] .existing-voice-slices li {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  animation: existing-voice-land .6s ease-out;
  border-radius: 4px;
}

[data-beat="existing-voice"] .existing-voice-slices li span:first-child { color: var(--accent); }
[data-beat="existing-voice"] .existing-voice-slices li span:nth-child(n + 4) { color: var(--muted); }

[data-beat="existing-voice"] .existing-voice-stage {
  align-self: center;
  max-width: 300px;
}

/* ── The cables ────────────────────────────────────────────────────────── */

/* Narrow: down from the bottom of one panel to the top of the next. */
[data-beat="existing-voice"] .existing-voice-cable {
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: var(--cable);
  margin-left: -1px;
  background: var(--line);
}

[data-beat="existing-voice"] .existing-voice-cable b {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font: 500 10.5px/1 var(--mono);
  letter-spacing: .06em;
  color: var(--muted);
  white-space: nowrap;
}

[data-beat="existing-voice"] .existing-voice-cable i {
  position: absolute;
  left: -2px;
  top: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: existing-voice-flow-y .45s linear forwards;
}

[data-beat="existing-voice"] .existing-voice-cable[data-lit] { background: var(--accent); }

@keyframes existing-voice-flow-y {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(calc(var(--cable) - 6px)); opacity: .2; }
}

@keyframes existing-voice-flow-x {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(calc(var(--cable) - 6px)); opacity: .2; }
}

/* Wide: across from the right edge of one panel to the left edge of the next. */
@container demo-frame (min-width: 760px) {
  [data-beat="existing-voice"] .existing-voice-cable {
    left: 100%;
    top: 50%;
    width: var(--cable);
    height: 2px;
    margin: -1px 0 0;
  }

  [data-beat="existing-voice"] .existing-voice-cable b {
    left: 50%;
    top: -16px;
    transform: translateX(-50%);
  }

  [data-beat="existing-voice"] .existing-voice-cable i {
    left: 0;
    top: -2px;
    animation-name: existing-voice-flow-x;
  }
}

/* ── The wire rail ─────────────────────────────────────────────────────── */

[data-beat="existing-voice"] .existing-voice-wire {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  max-height: 236px;
  overflow: auto;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
}

[data-beat="existing-voice"] .existing-voice-wire li {
  display: grid;
  grid-template-columns: 5.4em 2.8em 7.6em minmax(0, 1fr);
  gap: 0 10px;
  padding: 2px 12px;
}

[data-beat="existing-voice"] .existing-voice-wire .existing-voice-wire-t {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

[data-beat="existing-voice"] .existing-voice-wire .existing-voice-wire-d { color: var(--muted); }
[data-beat="existing-voice"] .existing-voice-wire li[data-dir="send"] .existing-voice-wire-d { color: var(--accent); }
[data-beat="existing-voice"] .existing-voice-wire .existing-voice-wire-k { color: var(--text); }

[data-beat="existing-voice"] .existing-voice-wire .existing-voice-wire-v {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

@container demo-frame (max-width: 480px) {
  [data-beat="existing-voice"] .existing-voice-wire li { grid-template-columns: 4.8em 2.6em minmax(0, 1fr); }
  [data-beat="existing-voice"] .existing-voice-wire .existing-voice-wire-v { grid-column: 2 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  [data-beat="existing-voice"] .existing-voice-cue,
  [data-beat="existing-voice"] .existing-voice-slices li { animation: none; }
}
