/*
 * TextCrawl: a one-line window (the inherited `--dx-line-height`) over a column of lines, scrolled by translating the
 * column `--dx-text-crawl-index` lines up. The component toggles `data-animate` so a jump (first paint, reset, the
 * cyclic wrap) lands at once while an advance eases. The shown line is full strength and the rest dimmed, so a line
 * brightens as it arrives.
 */

@layer dx-components {
  .dx-text-crawl {
    position: relative;
    min-width: 0;
    height: var(--dx-line-height);
    overflow: hidden;
    font-size: var(--dx-font-size);
    line-height: var(--dx-line-height);
  }

  .dx-text-crawl-ribbon {
    display: flex;
    flex-direction: column;
    transform: translateY(calc(var(--dx-text-crawl-index, 0) * -1 * var(--dx-line-height)));
  }
  .dx-text-crawl-ribbon[data-animate] {
    transition: transform var(--dx-text-crawl-duration, 500ms) ease-in-out;
  }

  /* A block, not a flex line: on a flex line the text is an anonymous item and `text-overflow` never applies. */
  .dx-text-crawl-line {
    height: var(--dx-line-height);
    /* Matches the box, not the root: a text-size utility on the root resets its line height and would ride the text up. */
    line-height: var(--dx-line-height);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.5;
    /* A third of the scroll, so the arriving line is bright by the time it settles. */
    transition: opacity calc(var(--dx-text-crawl-duration, 500ms) / 3);
  }
  .dx-text-crawl-line[data-active] {
    opacity: 1;
  }

  @media (prefers-reduced-motion: reduce) {
    .dx-text-crawl-ribbon[data-animate],
    .dx-text-crawl-line {
      transition: none;
    }
  }
}
