/* GPT-171 — the VU meter element: 20 segments, peak hold, thinking
   pulse, reduced motion. Styles only; the level maths and the rAF loop
   live in meter.js, the colours only in tokens.css.

   From the Figma handoff (sheet 22-11664 "Handoff / Behavior and
   tokens", blocks "Meter geometry" and "Meter / motion contract"; the
   four state components 22:12266 You / 22:12267 Mike / 22:12268
   Listening / 22:12269 Idle).

   Geometry — Meter geometry: 20 segments, 8 px high, 3 px gap, 1 px
   corner radius. The .vu-track carries the gap and the segments flex
   evenly into what is left, so the segment width follows the meter's
   width: (180 − 19×3) / 20 = 6.15 px in the phone meter,
   (328 − 19×3) / 20 = 13.55 px in the desktop one. meter.js exports
   the same numbers as SEGMENTS / HEIGHT_PX / GAP_PX / RADIUS_PX. */

.vu-meter {
  --vu-height: 8px;         /* Meter geometry: segments 8 px high       */
  --vu-gap: 3px;            /* Meter geometry: 3 px gap                 */
  --vu-tint: var(--meter-dim);   /* overruled per mode below; default
                                    is listening's dim so a meter with
                                    no mode set still reads as a meter  */
  display: block;
  width: 100%;
}

.vu-track {
  position: relative;       /* positions the peak tick on the grid      */
  display: flex;
  align-items: center;
  gap: var(--vu-gap);
  height: var(--vu-height);
}

.vu-seg {
  flex: 1 1 0;              /* equal widths → the derived numbers above */
  min-width: 0;
  height: var(--vu-height);
  border-radius: 1px;       /* Meter geometry: 1 px radius              */
  background: var(--meter-track);
}
.vu-seg.lit { background: var(--vu-tint); }

/* ---------- modes and tints (Meter / motion contract) ---------- */

.vu-meter[data-mode="idle"]      { --vu-tint: var(--meter-track); }
.vu-meter[data-mode="listening"] { --vu-tint: var(--meter-dim); }
.vu-meter[data-mode="you"]       { --vu-tint: var(--text); }
.vu-meter[data-mode="mike"]      { --vu-tint: var(--accent); }
.vu-meter[data-mode="thinking"]  { --vu-tint: var(--accent); }

/* Thinking: the rest of the meter stays track and only the first
   segment pulses — 1.6 s, ease-in-out, forever (Meter / motion
   contract). The pulse is an opacity breathe (0.25 → 1 → 0.25 per
   period) so it reads at every background. The period and easing are
   set here; meter.js only suppresses it under reduced motion ("thinking
   stays hollow, no pulse"). */
.vu-meter[data-mode="thinking"] .vu-seg { background: var(--meter-track); }
.vu-meter[data-mode="thinking"] .vu-seg:first-child {
  background: var(--vu-tint);
  animation: vu-pulse 1.6s ease-in-out infinite;
}
@keyframes vu-pulse {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

/* ---------- peak hold ---------- */

/* One segment slot (Meter / motion contract). The slot index comes in
   from meter.js as --slot (a bare number) and resolves against the
   track: slot s starts at s × (segment + gap), and a slot is 1/20 of
   (width + 19 gaps). The tick is a full-width, one-pixel-tall bar
   through the middle of the slot — a tick, not a second lit segment —
   in the dim tint; it hides whenever the level catches up with it. */
.vu-peak {
  display: none;
  position: absolute;
  top: calc(50% - 0.5px);            /* one hairline, centred on the 8 px track */
  left: calc(var(--slot, 0) * (100% + var(--vu-gap)) / 20);
  width: calc((100% - 19 * var(--vu-gap)) / 20);   /* exactly one segment */
  height: 1px;
  background: var(--meter-dim);
}
.vu-meter.show-peak .vu-peak { display: block; }

/* ---------- reduced motion ----------
   One 8 px dot instead of the moving segments (Meter / motion
   contract): solid for speech (you, mike), hollow for listening,
   hollow with no pulse for thinking, hollow in the track colour idle.
   Speaker tints kept. The rules hang on the [data-reduced] attribute,
   which meter.js mirrors from prefers-reduced-motion (and callers can
   set, so the test page shows both without changing the OS setting).
   The media query below only guards the frames before meter.js has run
   so a pulse can never animate under a reduce setting. */

@media (prefers-reduced-motion: reduce) {
  .vu-meter:not([data-reduced="true"]) .vu-seg { animation: none; }
}

.vu-meter[data-reduced="true"] .vu-track { display: none; }
.vu-meter-dot { display: none; }
.vu-meter[data-reduced="true"] .vu-meter-dot {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-sizing: border-box;
}
.vu-meter[data-reduced="true"][data-mode="idle"] .vu-meter-dot {
  border: 1px solid var(--meter-track);
}
.vu-meter[data-reduced="true"][data-mode="listening"] .vu-meter-dot {
  border: 1px solid var(--meter-dim);
}
.vu-meter[data-reduced="true"][data-mode="you"] .vu-meter-dot {
  border: 1px solid var(--text);
  background: var(--text);
}
.vu-meter[data-reduced="true"][data-mode="mike"] .vu-meter-dot {
  border: 1px solid var(--accent);
  background: var(--accent);
}
.vu-meter[data-reduced="true"][data-mode="thinking"] .vu-meter-dot {
  border: 1px solid var(--accent);
}
