/* ===============================================================
   card.css — one clip. Head (slot + name), stage (waveform and
   every overlay that sits on it), foot (transport + status).
   =============================================================== */

.clip {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background:
    linear-gradient(180deg, rgba(17, 24, 35, 0.86), rgba(8, 11, 16, 0.86));
  transition: border-color var(--t-mid), transform var(--t-mid) var(--ease);
  content-visibility: auto;
  contain-intrinsic-size: 172px;

  /* Cue-stepping and the slot jump both use scrollIntoView. Without
     these the card lands flush against the viewport edge — which
     means underneath the sticky header or the fixed transport.
     --topbar-h is kept current by ui/controls.js, since the drawer
     changes the header's height. */
  scroll-margin-top: calc(var(--topbar-h, 56px) + 10px);
  scroll-margin-bottom: calc(var(--bar-h) + 14px);
}

.clip:hover { border-color: var(--line); }

.clip.is-hidden { display: none; }

/* Cued: keyboard cursor sits here. Quiet holo edge, no glow. */
.clip.is-cued { border-color: var(--holo-line); }

/* Live: the one clip making sound. Ember edge, and the flame
   canvas is parented in here by fx/flame.js. */
.clip.is-live {
  border-color: var(--ember-line);
  background:
    linear-gradient(180deg, rgba(31, 22, 10, 0.44), rgba(8, 11, 16, 0.92));
}

.clip.is-failed { border-color: rgba(255, 92, 106, 0.3); }

/* Entry — the card resolves in place rather than sliding around. */
@keyframes clip-in {
  from { opacity: 0; transform: translateY(6px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

.clip.is-new { animation: clip-in var(--t-slow) var(--ease) both; }

/* Content sits above the flame canvas. */
.clip__head, .clip__stage, .clip__foot { position: relative; z-index: 1; }

/* ---------------------------------------------------------------
   Head
   --------------------------------------------------------------- */
.clip__head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.clip__slot {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  margin-top: 1px;
  transition: color var(--t-fast), border-color var(--t-fast);
}

.clip.is-live .clip__slot {
  color: var(--ember);
  border-color: var(--ember-line);
  background: var(--ember-soft);
}

.clip.is-cued .clip__slot { color: var(--holo); border-color: var(--holo-line); }

.clip__id { min-width: 0; flex: 1 1 auto; }

.clip__name {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip__spec {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--muted-dim);
  letter-spacing: .04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip__remove {
  flex: none;
  width: 24px; height: 24px;
  border-color: transparent;
  background: transparent;
  color: var(--muted-dim);
  opacity: 0;
  transition: opacity var(--t-fast), color var(--t-fast);
}

.clip__remove svg { width: 10px; height: 10px; }
.clip:hover .clip__remove,
.clip:focus-within .clip__remove { opacity: 1; }
.clip__remove:hover { color: var(--danger); border-color: rgba(255, 92, 106, 0.4); }

/* ---------------------------------------------------------------
   Stage — waveform and its overlays
   --------------------------------------------------------------- */
.clip__stage {
  position: relative;
  height: 62px;
  border-radius: var(--r-sm);
  background: rgba(4, 6, 9, 0.72);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

.clip__stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* The progress copy is the same drawing in ember, revealed left to
   right with clip-path — paint only, never a layout pass. */
.wave__prog {
  clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0);
  will-change: clip-path;
}

.wave__head {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--p, 0%);
  width: 1px;
  background: var(--ember-hot);
  box-shadow: 0 0 8px rgba(255, 226, 166, 0.7);
  opacity: 0;
  transition: opacity var(--t-fast);
}

.clip.is-live .clip__stage { background: rgba(2, 3, 5, 0.86); }

.clip.is-live .wave__head,
.clip.is-cued .wave__head { opacity: .85; }

/* ASCII rendering of the same peaks — swapped in by the Asciify
   control. Kept in the DOM so toggling never re-measures. */
.wave__ascii {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0 2px;
  display: none;
  flex-direction: column;
  justify-content: center;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0;
  color: var(--wave-idle-2);
  white-space: pre;
  overflow: hidden;
  user-select: none;
}

/* One string, drawn twice: the upper row is flipped so the block
   glyphs meet at the centre line and read as a waveform. */
.wave__ascii > span { display: block; }
.wave__ascii > span:first-child { transform: scaleY(-1); }

.clip.is-ascii .wave__ascii { display: flex; }
.clip.is-ascii .wave__base,
.clip.is-ascii .wave__prog { display: none; }
.clip.is-ascii.is-live .wave__ascii { color: var(--ember); }

/* Loading strip: block glyphs breathing until real peaks land. */
.wave__glyphs {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 0 2px;
  color: var(--wave-idle);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
  transition: opacity var(--t-mid);
}

.wave__glyphs.is-gone { opacity: 0; }
.wave__glyphs.is-dead { color: rgba(255, 92, 106, 0.5); }

/* Scanline sweep — one keyframe, GPU transform, live card only. */
@keyframes stage-scan {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.wave__scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg,
    transparent,
    rgba(255, 226, 166, 0.10) 45%,
    rgba(255, 226, 166, 0.16) 50%,
    transparent);
}

.clip.is-live .wave__scan {
  opacity: 1;
  animation: stage-scan 2.6s linear infinite;
}

/* ---------------------------------------------------------------
   Foot
   --------------------------------------------------------------- */
.clip__foot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clip__time {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.clip.is-live .clip__time { color: var(--ember-hot); }

.clip__flag {
  margin-left: auto;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted-dim);
  white-space: nowrap;
}

.clip__flag.is-error { color: var(--danger); }

/* Three-bar meter, driven by the shared analyser for the live clip
   only; every other card holds it flat. */
.meter {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  flex: none;
  opacity: 0;
  transition: opacity var(--t-mid);
}

.clip.is-live .meter { opacity: 1; }

.meter i {
  display: block;
  width: 2px;
  height: 2px;
  background: var(--muted-dim);
  border-radius: 1px;
  transform-origin: bottom;
  transition: height var(--t-fast) linear, background var(--t-fast);
}

.clip.is-live .meter i { background: var(--ember); }
