:has(.jdgm-videos-carousel) { width: 100%; }
:has(.jdgm-testimonials-carousel) { width: 100%; }

.jdgm-testimonials-carousel, .jdgm-videos-carousel {
  margin: 0 auto;
  max-width: var(--max-width);
  padding: 20px 0;
  text-align: center;

  .jdgm-header { margin-bottom: 40px; }

  .jdgm-title {
    font-size: 32px;
    font-weight: normal;
    margin-bottom: 8px;
    color: var(--header-color, var(--text-color));
    line-height: 1.2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 1;
  }

  .jdgm-header-info {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
  }

  .jdgm-average-rating {
    display: flex;
    gap: 8px;

    .jdgm-star {
      color: var(--header-color, var(--text-color));
    }
  }

  .jdgm-rating-text {
    font-size: 16px;
    color: var(--header-color, var(--text-color));
    font-weight: normal;
  }

  .jdgm-verified-badge {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .jdgm-verified-text {
    font-size: 16px;
    color: var(--header-color, var(--text-color));
    font-weight: normal;
  }

  .jdgm-verified-checkmark {
    width: 20px;
    height: 20px;
    fill: #3EB2A2;
  }

  .jdgm-arrow {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--arrows-color);
    transition: opacity 0.2s;
    flex-shrink: 0;

    &:hover { opacity: 0.7; }

    svg {
      width: 20px;
      height: 34px;
      fill: currentColor;
    }
  }

  .jdgm-arrows--bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
  }

  .jdgm-card {
    background: var(--card-color);
    border-radius: var(--border-radius);
    border: var(--border);
    box-shadow: var(--box-shadow);
    padding: 40px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
  }

  .jdgm-card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
  }

  .jdgm-reviewer-verified-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    color: var(--text-color);
  }

  .jdgm-text {
    font-size: var(--text-size);
    color: var(--text-color);
    line-height: 1.2;
    text-align: center;
    font-weight: normal;
    max-width: 100%;
    min-height: calc(var(--line-clamp) * 1.2em);
    max-height: calc(var(--line-clamp) * 1.27em);
    display: grid;
    place-items: center;
    grid-template-rows: auto;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: var(--line-clamp);

    p {
      margin: 0;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      text-overflow: ellipsis;
      -webkit-line-clamp: var(--line-clamp);
      max-width: calc(var(--card-width) - 48px);
    }
  }

  .jdgm-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 40px;
  }

  .jdgm-rating-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;

    .jdgm-star {
      font-size: var(--stars-size);
      color: var(--stars-color);
    }
  }

  .jdgm-reviewer-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .jdgm-reviewer-info {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    width: 100%;
  }
}

.jdgm-testimonials-carousel {
  .jdgm-quote-marks {
    height: var(--quote-size);
    background-image: var(--quote-bg);
    aspect-ratio: var(--quote-aspect);
    background-repeat: no-repeat;
    background-size: contain;
  }

  .jdgm-reviewer-verified-text {
    background: transparent;
    color: var(--text-color);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 8px;
    letter-spacing: 0.05em;
    border-radius: var(--border-radius);
    border: 1px solid var(--text-color);
  }

  .jdgm-product-name {
    font-size: var(--product-name-size);
    color: var(--text-color);
    text-decoration: underline;
    text-decoration-skip-ink: none;
    text-underline-position: from-font;
    font-weight: normal;
    text-align: center;
    width: 510px;
    max-width: 100%;

    a {
      color: var(--text-color);
    }
  }

  .jdgm-testimonials-container {
    position: relative;
    height: auto;
    min-height: 200px;
    width: 100%;
  }

  .jdgm-testimonial {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none;
  }

  .jdgm-testimonial.active {
    opacity: 1;
    pointer-events: auto;
    position: relative;
  }
}

.jdgm-videos-carousel {
  --carousel-width: calc(var(--active-width) + 2 * var(--card-width) + 48px);
  container-type: inline-size;

  .jdgm-videos-wrapper {
    overflow: hidden;

    @container (min-width: 1100px) {
      width: calc(var(--carousel-width) + 2 * max(0, min(5, var(--slides-count)) - 4) * (var(--scd-width) + 24px));
    }

    @container (min-width: 819px) and (max-width: 1099px) { width: var(--carousel-width); }

    .jdgm-videos-container {
      display: flex;
      flex-direction: row;
      gap: 24px;
      justify-content: flex-start;
      align-items: center;
      overflow: visible;
      transition: transform 600ms cubic-bezier(0.36, 0.66, 0.04, 1);
      position: relative;
      padding: 10px 0;
    }
  }

  .jdgm-content {
    overflow: hidden;
    overscroll-behavior-x: contain;
  }

  .jdgm-touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: auto;
  }

  .jdgm-media-card {
    position: relative;
    padding: 0;
    gap: 0;
    height: var(--card-height);
    overflow: hidden;
    background: var(--card-color);
    flex: 0 0 var(--card-width);
    max-width: var(--card-width);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    iframe {
      height: 100%;
      width: 100%;
      border: none;
      pointer-events: none;
      transform: scale(1.01);
      transform-origin: center;
    }

    .jdgm-text {
      --lines: calc((var(--height-abs) - 101) / var(--font-size-abs));
      --clamp: round(down, var(--lines));
      --h: calc(var(--clamp) * 1.2em + 16px);
      min-height: 0;
      max-height: var(--h);
      height: var(--h);
      -webkit-line-clamp: var(--clamp);
      overflow: hidden;
      word-wrap: break-word;
      overflow-wrap: break-word;

      p {
        max-width: calc(var(--card-width) - 48px);
        -webkit-line-clamp: var(--clamp);
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
      }
    }

    .jdgm-rating-section {
      gap: 0;
      position: absolute;
      z-index: 2;
      padding: 16px 8px;
      bottom: 0;

      .jdgm-star { font-size: 16px; }
    }
  }
  .jdgm-media-card.active {
    height: var(--active-height);
    flex: 0 0 var(--active-width);
    max-width: var(--active-width);

    .jdgm-star { font-size: var(--stars-size); }

    .jdgm-gradient-overlay { height: 88px; }

    .jdgm-text {
      --lines: calc((var(--active-height-abs) - 116) / var(--font-size-abs));

      p { max-width: calc(var(--active-width) - 48px); }
    }
  }

  .jdgm-media-card.secondary {
    flex: 0 0 var(--scd-width);
    max-width: var(--scd-width);
    height: var(--scd-height);

    .jdgm-text {
      --lines: calc((var(--scd-height-abs) - 116) / var(--font-size-abs));

      p { max-width: calc(var(--scd-width) - 48px); }
    }
  }

  .jdgm-text-card {
    justify-content: flex-start;

    .jdgm-text { padding: 16px 24px 0 24px; }
  }

  .jdgm-gradient-overlay {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 80px;
    background: linear-gradient(180deg, rgba(255, 0, 0, 0) 0%, var(--card-color) 100%);
    z-index: 1;
    pointer-events: none;
    display: block;
  }
}

@container (max-width: 376px) {
  .jdgm-videos-wrapper {
    --mobile-width: 217px;
    --mobile-height: 386px;
    --mobile-scd-height: 344px;
    --carousel-width: 630px;
    .jdgm-media-card.active {
      .jdgm-text {
        --lines: calc(285 / var(--font-size-abs));
      }
    }
  }
}

@container (max-width: 757px) {
  .jdgm-videos-wrapper { width: var(--mobile-width); }
}

@container (max-width: 818px) {
  .jdgm-videos-carousel {
    --carousel-width: calc(var(--mobile-width) + 2 * var(--card-width) + 48px);
    --lines: calc((var(--mobile-height-abs) - 101) / var(--font-size-abs));

    &:has(.jdgm-arrows--bottom) .jdgm-videos-wrapper {
      width: var(--carousel-width);
      margin-left: calc((100cqw - var(--carousel-width)) / 2);
    }
    &:has(.jdgm-arrows--bottom) .jdgm-content {
      overflow: hidden;
      display: block;
    }

    .jdgm-media-card {
      height: var(--mobile-scd-height)!important;

      iframe {
        height: var(--mobile-scd-height)!important;
        width: 221px!important;
      }
    }

    .jdgm-media-card.active {
      height: var(--mobile-height)!important;
      flex: 0 0 var(--mobile-width)!important;
      max-width: var(--mobile-width)!important;

      iframe {
        height: var(--mobile-height)!important;
        width: var(--mobile-width)!important;
      }
    }
  }
}

@media (max-width: 768px) {
  .jdgm-testimonials-carousel {
    .jdgm-header-info {
      flex-direction: column;
      gap: 8px;
    }

    .jdgm-card { padding: 24px; }

    .jdgm-card-content { gap: 16px; }

    .jdgm-title { font-size: 24px; }

    .jdgm-text {
      font-size: var(--text-size-mobile);
      min-height: calc(var(--line-clamp-mobile) * 1.2em);
      max-height: calc(var(--line-clamp-mobile) * 1.3em);
      -webkit-line-clamp: var(--line-clamp-mobile);
    }

    .jdgm-product-name { width: 100%; }

    .jdgm-header-info {
      flex-direction: column;
      gap: 8px;
    }
  }
}

.jdgm-video-card {
  position: relative;

  .jdgm-video-controls, .jdgm-video-controls-center {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    gap: 8px;
    z-index: 3;

    button {
      background: none;
      border: none;
      padding: 0;
      cursor: pointer;
      width: 40px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: opacity 0.2s ease;

      &:hover {
        opacity: 0.8;
      }

      svg {
        width: 40px;
        height: 40px;
        pointer-events: none;
      }
    }
  }

  .jdgm-video-controls {
    display: none;
  }

  .jdgm-video-controls-center {
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
  }

  &.active {
    .jdgm-video-controls { display: flex; }
    .jdgm-video-controls-center { display: flex; }
  }

  iframe {
    position: relative;
    z-index: 1;
  }
}
