/**
 * Logo Carousel — logo strip with infinite scrolling.
 *
 * How the seam stays invisible
 * ----------------------------
 * The track (`__track`) is a row of identical groups. The animation shifts the track
 * by exactly the width of ONE group; when it restarts, the next group is already
 * at the pixel where the previous one was, and the repetition has no seam.
 *
 * For that, the group width must be the exact step. That is why the spacing
 * between logos lives as `gap` INSIDE the group plus a `padding-inline-end` of the
 * same size — and the track has no `gap` at all. If the trailing space came from the
 * track's `gap`, a group would measure less than the step and the seam would jump.
 *
 * `--usk-logos-groups` is written by the JS after measuring; the value 2 here is what
 * the component uses without JS, since PHP renders two groups.
 *
 * Why every descendant selector starts with `.usk-logos`
 * -------------------------------------------------------
 * Elementor's base CSS ships `.elementor img { height:auto; max-width:100% }`
 * (frontend.css:61). That is specificity (0,1,1) and beats a bare
 * `.usk-logos__img`, which is (0,1,0) — the height and max-width controls
 * simply had no effect. Scoping raises it to (0,2,0) and fixes the
 * whole class of problem, not just `img`.
 *
 * Plugin convention: Elementor controls only write `--usk-logos-*` custom properties
 * on `{{WRAPPER}} .usk-logos`. Never on the wrapper alone — a
 * declaration on the element itself beats the value inherited from any ancestor.
 */

.usk-logos {
  /* --------------------------------------------------------------- Layout */
  --usk-logos-gap: 3rem;
  --usk-logos-height: 2.5rem;
  --usk-logos-max-width: 10rem;
  --usk-logos-item-scale: 1;

  /* ----------------------------------------------------------- Animation */
  /* Overridden by the JS based on the speed in px/s. This value is only what
     runs while the JS has not measured yet (or if it fails to load). */
  --usk-logos-duration: 30s;
  --usk-logos-groups: 2;

  /* --------------------------------------------------------------- Color */
  --usk-logos-grayscale: 100%;
  --usk-logos-opacity: 1;
  --usk-logos-hover-opacity: 1;

  /* --------------------------------------------------------------- Faded */
  --usk-logos-fade: 6rem;

  --usk-logos-ring: var(--ring, #ff5e11);

  display: block;
  width: 100%;
}

/* ============================================================== Viewport */

.usk-logos .usk-logos__viewport {
  overflow: hidden;
}

/* The edges fade out so the strip does not "cut" the logo as it leaves. */
.usk-logos[data-fade='yes'] .usk-logos__viewport {
  -webkit-mask-image: linear-gradient(
    to right,
    transparent,
    #000 var(--usk-logos-fade),
    #000 calc(100% - var(--usk-logos-fade)),
    transparent
  );
  mask-image: linear-gradient(
    to right,
    transparent,
    #000 var(--usk-logos-fade),
    #000 calc(100% - var(--usk-logos-fade)),
    transparent
  );
}

/* ================================================================= Track */

.usk-logos .usk-logos__track {
  display: flex;
  width: max-content;
  animation: usk-logos-scroll var(--usk-logos-duration) linear infinite;
  will-change: transform;
}

@keyframes usk-logos-scroll {
  to {
    transform: translate3d(calc(-100% / var(--usk-logos-groups)), 0, 0);
  }
}

/* Without a `from` keyframe, `reverse` starts at the end and moves to the start: same
   animation, opposite direction, and the seam stays exact. */
.usk-logos[data-direction='right'] .usk-logos__track {
  animation-direction: reverse;
}

/* Outside the viewport the animation does not need to use CPU (the JS flags it). */
.usk-logos[data-paused] .usk-logos__track {
  animation-play-state: paused;
}

@media (hover: hover) {
  .usk-logos[data-pause='yes']:hover .usk-logos__track {
    animation-play-state: paused;
  }
}

/* Without this, keyboard users see the focused logo keep running away. */
.usk-logos[data-pause='yes']:focus-within .usk-logos__track {
  animation-play-state: paused;
}

/* ================================================================= Group */

.usk-logos .usk-logos__group {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--usk-logos-gap);
  /* The space after the last logo lives here, not in the track's `gap`: that is what
     makes the group width the exact animation step. */
  padding: 0 var(--usk-logos-gap) 0 0;
  margin: 0;
  list-style: none;
}

.usk-logos .usk-logos__item {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
}

.usk-logos .usk-logos__link,
.usk-logos .usk-logos__figure {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  text-decoration: none;
  outline: 0;
}

.usk-logos .usk-logos__link:focus-visible {
  outline: 2px solid var(--usk-logos-ring);
  outline-offset: 4px;
  border-radius: 2px;
}

.usk-logos .usk-logos__img {
  display: block;
  width: auto;
  /* The per-logo scale multiplies the box, not a `transform`: this way the spacing
     between logos stays correct when one of them is scaled down. */
  height: calc(var(--usk-logos-height) * var(--usk-logos-item-scale));
  max-width: calc(var(--usk-logos-max-width) * var(--usk-logos-item-scale));
  object-fit: contain;
  opacity: var(--usk-logos-opacity);
  transition:
    filter 250ms ease,
    opacity 250ms ease;
}

/* ================================================================= Color */

.usk-logos[data-color='grayscale'] .usk-logos__img,
.usk-logos[data-color='hover'] .usk-logos__img {
  filter: grayscale(var(--usk-logos-grayscale));
}

@media (hover: hover) {
  .usk-logos .usk-logos__item:hover .usk-logos__img {
    opacity: var(--usk-logos-hover-opacity);
  }

  /* Only the logo under the cursor regains its color. */
  .usk-logos[data-color='hover'] .usk-logos__item:hover .usk-logos__img {
    filter: grayscale(0);
  }
}

.usk-logos .usk-logos__link:focus-visible .usk-logos__img {
  opacity: var(--usk-logos-hover-opacity);
}

.usk-logos[data-color='hover'] .usk-logos__link:focus-visible .usk-logos__img {
  filter: grayscale(0);
}

/* ============================================================= Edit state */

.usk-logos .usk-logos__empty {
  padding: 1.5rem;
  border: 1px dashed var(--border, #e2e8f0);
  border-radius: var(--radius, 0.5rem);
  color: var(--muted-foreground, #64748b);
  font-size: 0.875rem;
  text-align: center;
}

/* ========================================================= Accessibility */

@media (prefers-reduced-motion: reduce) {
  .usk-logos .usk-logos__track {
    animation: none;
  }

  /* When stopped, the wide strip must remain reachable. */
  .usk-logos .usk-logos__viewport {
    overflow-x: auto;
  }

  /* The copies exist only for the animation; without it they become useless repetition.
     The rule also covers the no-JS case, where PHP has already sent two groups. */
  .usk-logos .usk-logos__group[aria-hidden='true'] {
    display: none;
  }

  .usk-logos .usk-logos__img {
    transition: none;
  }
}
