/* Punjabi badge that pops in next to a pronunciation player while it plays.
   Markup from layouts/_shortcodes/audio.html (reveal parameter), toggled by
   static/js/audio-reveal.js adding .is-playing to .gt-audio-pair. */

.gt-audio-pair {
  display: inline-flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 0.4em;
}

/* The player must never be squeezed by the badge beside it. Without this the
   flex default (shrink: 1) compresses the <audio> in narrow cells and the play
   button gets clipped — it showed up on exactly the rows with the longest
   badge text. Let the badge wrap underneath instead. */
.gt-audio-pair .pronunciation-audio {
  flex: 0 0 auto;
}

.gt-audio-reveal {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  /* No `white-space: nowrap` and no `flex: 0 0 auto`. The badge sits in a
     table cell, and in the A1 self-introduction lesson it carries a pair of
     whole sentences rather than a single word. Unbreakable, that text set the
     column's width: the Listen column grew to fit it, the German and English
     columns were starved down to two or three words a line, and the table
     overflowed into a horizontal scrollbar with the badge clipped at the edge.
     Wrapping within the width the cell already has keeps the row stable. */
  max-width: 100%;
  gap: 0.45em;
  padding: 0.15em 0.7em;
  border: 1px solid var(--color-primary);
  border-radius: 999px;
  font-size: 0.95em;
  line-height: 1.6;

  /* Hidden until the player starts. */
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* German word, then its meaning — the pairing the reader is hearing. */
.gt-audio-de {
  color: var(--color-primary);
  font-weight: 600;
}

.gt-audio-pa {
  color: var(--color-text-secondary);
}

/* Thin divider between the two, so they read as one unit rather than two. */
.gt-audio-de::after {
  content: "·";
  margin-left: 0.45em;
  color: var(--color-text-muted);
  font-weight: 400;
}

.gt-audio-pair.is-playing .gt-audio-reveal {
  opacity: 1;
  transform: scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .gt-audio-reveal { transition: none; transform: none; }
  .gt-audio-pair.is-playing .gt-audio-reveal { transform: none; }
}

/* Keep the Listen column to the width of the player rather than the badge.
   Without a cap the cell is as wide as its widest content, which is the
   sentence badge, and the text columns lose the space. */
.table td .gt-audio-pair {
  max-width: 22em;
}

@media (max-width: 767px) {
  .table td .gt-audio-pair {
    max-width: 14em;
  }

  .gt-audio-reveal {
    font-size: 0.85em;
    padding: 0.15em 0.55em;
  }
}

/* Left-align the cell that holds a player.

   bootstrap.min.css centres every td and th (`td,th{padding:10px;text-align:
   center;...}`). A player's rendered width varies with the length of its
   audio, so centring gives each row a different left edge and the play
   buttons wander down the column in a diagonal instead of a line.

   Scoped to cells that actually contain a player, so ordinary tables keep
   the centring Bootstrap gives them. The players are the last column in
   every lesson table, and a left edge is what the eye tracks down. */
.table td:has(.pronunciation-audio) {
  text-align: left;
}

/* No non-:has() fallback here. The obvious one — making .gt-audio-pair a
   block-level flex with margin-right:auto — backfires: it shares a selector
   with the max-width:22em cap above, and a block-level box takes that full
   22em in every row instead of hugging its player, which is the column-width
   problem that cap was added to solve. A browser without :has() keeps
   Bootstrap's centring and the players stagger as before: cosmetic, and the
   same as it was. */
