/**
 * @file
 * Feature carousel styles. The section is left-padded only and the card track
 * bleeds off the right viewport edge. Background is shared with the tabs panel.
 */

.ln-carousel {
  --ln-carousel-padding-block: 80px;

  /**
   * Left inset only, so the track keeps bleeding off the right edge. It cannot
   * just be the gutter: it has to land on the same line as the other sections'
   * content, which is the centred container's edge PLUS the gutter inside it.
   */
  --ln-carousel-padding-inline: calc(
    max(0px, (100% - var(--ln-container-max, 1440px)) / 2) +
    var(--ln-container-gutter, 15px)
  );

  /* Left column: content width plus the gutter before the track. */
  --ln-carousel-copy-width: 510px;
  --ln-carousel-copy-gutter: 64px;

  --ln-carousel-fg: #1c1c1c;
  --ln-carousel-heading-fg: #171717;
  --ln-carousel-accent: #cf0000;

  /* Shared with the tabs panel, so the two sections cannot drift apart. */
  --ln-carousel-surface: var(--ln-color-surface-gray, #ededed);

  --ln-carousel-card-width: 320px;
  --ln-carousel-card-height: 405px;
  --ln-carousel-card-gap: 16px;
  --ln-carousel-card-radius: 16px;

  /* Asymmetric: a constant space above the icon, copy runs as deep as it needs. */
  --ln-carousel-card-padding-start: 72px;
  --ln-carousel-card-padding-end: 32px;
  --ln-carousel-card-padding-inline: 32px;

  --ln-carousel-card-shadow: 0 6px 6px rgb(99 102 106 / 28%);

  /* Room for the card shadows; must be spent by the track, not the viewport. */
  --ln-carousel-shadow-room-block: 32px;
  --ln-carousel-shadow-room-inline: 24px;

  /* Left edge shadow; opacity is driven from the scroll position by carousel.js. */
  --ln-carousel-edge-shadow-width: 48px;
  --ln-carousel-edge-shadow-color: 99 102 106;
  --ln-carousel-edge-shadow-strength: 18%;
  --ln-carousel-edge-shadow-opacity: 0;

  /* Vertical envelope for that shadow. A mask reads alpha only, so the stops are
     the shape and the colour never renders. */
  --ln-carousel-edge-shadow-envelope: linear-gradient(
    180deg,
    rgb(0 0 0 / 0%) 0%,
    rgb(0 0 0 / 55%) 22%,
    rgb(0 0 0 / 100%) 50%,
    rgb(0 0 0 / 55%) 78%,
    rgb(0 0 0 / 0%) 100%
  );

  --ln-carousel-track-bg: #ffffff;
  --ln-carousel-button-size: 40px;
  --ln-carousel-button-gap: 32px;

  /* Pills are white on this surface; their own #ececec default disappears here. */
  --ln-pill-bg: #ffffff;

  --ln-carousel-font: Outfit, sans-serif;

  position: relative;
  box-sizing: border-box;
  color: var(--ln-carousel-fg);
  font-family: var(--ln-carousel-font);
}

.ln-carousel--bg-gray {
  background-color: var(--ln-carousel-surface);
}

.ln-carousel--bg-none {
  background-image: none;
}

.ln-carousel *,
.ln-carousel *::before,
.ln-carousel *::after {
  box-sizing: inherit;
}

/* Padded on the left only, so the track bleeds off the right edge. */
.ln-carousel__inner {
  display: flex;
  flex-direction: column;
  inline-size: 100%;
  padding-block: var(--ln-carousel-padding-block);
  padding-inline-start: var(--ln-carousel-padding-inline);     
}

/* Spans both columns, above the row. */
.ln-carousel__heading :is(h2, h3, p) {
  margin: 0;
  color: var(--ln-carousel-heading-fg);
  font-size: 48px;
  font-weight: 500;
  line-height: 1.3;
}

/**
 * Grid, not flex, because the media is placed differently at each breakpoint.
 *
 * The column gutter is column-gap, not padding on .ln-carousel__copy, so every
 * item placed in that column gets it.
 */
.ln-carousel__row {
  display: grid;
  grid-template-columns: var(--ln-carousel-copy-width) minmax(0, 1fr);
  grid-template-areas:
    "copy  viewport"
    "media viewport";
  column-gap: var(--ln-carousel-copy-gutter);
  align-items: start;
  min-inline-size: 0;
}

.ln-carousel__copy {
  grid-area: copy;
}

.ln-carousel__media {
  grid-area: media;
}

.ln-carousel__viewport {
  grid-area: viewport;
}

/**
 * Left column — a flex container for the pill and copy inside it.
 *
 * No `flex` shorthand: this is a grid item, sized by the row's template.
 */
.ln-carousel__copy {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding-block-start: 32px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

/**
 * Collapse the first and last elements' own margins.
 *
 * Descendant not child (Drupal field wrappers intervene); margin only, never
 * padding — the first element is usually the pill. (0,2,0): ties .ln-pill.ln-pill.
 */
.ln-carousel__copy :first-child {
  margin-block-start: 0;
}

.ln-carousel__copy :last-child {
  margin-block-end: 0;
}

/* Supporting media below the copy — a video or a still image. */
.ln-carousel__media {
  display: block;
  inline-size: 100%;

  /* A margin on the item, not a row-gap: the two layouts want the gap in
     different places. */
  margin-block-start: 32px;
}

/**
 * Keep a still image inside the wrapper (descendant selector: Drupal wrappers).
 *
 * block-size: auto, not height: 100% — a reserved aspect ratio on the wrapper is
 * anticipated, and 100% would then stretch every image to fill it.
 */
.ln-carousel__media img {
  display: block;
  inline-size: 100%;
  block-size: auto;
}

/**
 * The track column. Takes the remaining width and runs to the viewport edge.
 *
 * No `flex` shorthand: this is a grid item now. `flex: 1 1 0` here once computed
 * to zero HEIGHT in column mode, clipping the whole track away.
 */
.ln-carousel__viewport {
  position: relative;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  overflow: hidden;
}

/**
 * Left edge shadow, so the cards read as passing beneath the copy column.
 *
 * On the viewport, not the track: anything inside the scroll container scrolls
 * away with the cards. The 90deg is physical — mirror under :dir(rtl) for RTL.
 */
.ln-carousel__viewport::before {
  content: '';
  position: absolute;
  z-index: 1;
  inset-block: 0;
  inset-inline-start: 0;
  inline-size: var(--ln-carousel-edge-shadow-width);
  background-image: linear-gradient(
    90deg,
    rgb(var(--ln-carousel-edge-shadow-color) / var(--ln-carousel-edge-shadow-strength)) 0%,
    rgb(var(--ln-carousel-edge-shadow-color) / calc(var(--ln-carousel-edge-shadow-strength) * 0.36)) 40%,
    rgb(var(--ln-carousel-edge-shadow-color) / 0%) 100%
  );
  -webkit-mask-image: var(--ln-carousel-edge-shadow-envelope);
  mask-image: var(--ln-carousel-edge-shadow-envelope);
  opacity: var(--ln-carousel-edge-shadow-opacity);
  pointer-events: none;

  /* No transition: the opacity is recomputed every frame from the track position. */
  transition: none;
}

/**
 * A real scroll container, not a transformed strip; carousel.js only sets scrollLeft.
 *
 * The shadow room belongs here, not on the viewport: overflow-x: auto clips on
 * all four sides at this element's padding box.
 */
.ln-carousel__track {
  display: flex;
  gap: var(--ln-carousel-card-gap);
  padding-block: var(--ln-carousel-shadow-room-block);
  padding-inline: var(--ln-carousel-shadow-room-inline);
  overflow-x: auto;
  /* Insets the snapport to match the padding, so a snap cannot scroll the inset
     away and clip the shadow it exists to protect. */
  scroll-padding-inline: var(--ln-carousel-shadow-room-inline);

  /**
   * Both load-bearing: carousel.js assigns scrollLeft every frame, so snapping
   * would jump the cards and smooth scrolling would lag them. The arrows still
   * glide, because they pass behavior: 'smooth' to scrollTo() explicitly.
   */
  scroll-snap-type: none;
  scroll-behavior: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;

  /* Grab affordance for the mouse drag. Touch keeps native scrolling. */
  cursor: grab;
}

/* Without user-select: none a throw selects the card text and fights the next drag. */
.ln-carousel.is-dragging .ln-carousel__track {
  cursor: grabbing;
  user-select: none;
}

.ln-carousel__track::-webkit-scrollbar {
  display: none;
}

/**
 * Cards — direct flex children; field--field-cards.html.twig strips the wrappers.
 *
 * min-block-size, not block-size: the track stretches every card to the tallest,
 * but a card whose copy genuinely does not fit grows instead of spilling out.
 */
.ln-carousel__card {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  justify-content: flex-start;
  gap: 32px;
  inline-size: var(--ln-carousel-card-width);
  min-block-size: var(--ln-carousel-card-height);
  padding-block: var(--ln-carousel-card-padding-start) var(--ln-carousel-card-padding-end);
  padding-inline: var(--ln-carousel-card-padding-inline);
  border-radius: var(--ln-carousel-card-radius);
  /* A low-opacity metallic sheen raking across an opaque white base. */
  background-image:
    linear-gradient(
      223.269deg,
      rgb(229 229 232 / 30%) 2.124%,
      rgb(199 199 204 / 30%) 22.914%,
      rgb(255 255 255 / 30%) 45.437%,
      rgb(184 184 189 / 30%) 67.254%,
      rgb(241 241 241 / 30%) 79.151%,
      rgb(173 173 178 / 30%) 98.027%
    ),
    linear-gradient(90deg, #ffffff 0%, #ffffff 100%);
  box-shadow: var(--ln-carousel-card-shadow);
  scroll-snap-align: start;
}

.ln-carousel__card-text {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Sized by height: the glyphs vary in width but all stand 80px tall. */
.ln-carousel__card-icon img {
  display: block;
  inline-size: auto;
  block-size: 80px;
}

.ln-carousel__card-title {
  margin: 0;
  font-size: 24px;
  font-weight: 500;
  line-height: 1.2;
}

.ln-carousel__card-body {
  margin: 0;
  font-size: 18px;
  font-weight: 300;
  line-height: 1.3;
}

.ln-carousel__card-body > :first-child {
  margin-top: 0;
}

.ln-carousel__card-body > :last-child {
  margin-bottom: 0;
}

/**
 * The controls row, holding only the arrows.
 *
 * padding-inline-end reuses --ln-carousel-copy-gutter for an unrelated purpose,
 * keeping the arrows inside the bleed: changing the token moves both.
 */
.ln-carousel__controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  block-size: 40px;
  padding-inline-start: var(--ln-carousel-shadow-room-inline);
  padding-inline-end: var(--ln-carousel-copy-gutter);
}

.ln-carousel__buttons {
  display: flex;
  flex: 0 0 auto;
  gap: var(--ln-carousel-button-gap);
}

/* Class doubled to outrank Site Studio's global button styles. */
.ln-carousel__button.ln-carousel__button {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--ln-carousel-button-size);
  block-size: var(--ln-carousel-button-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--ln-carousel-track-bg);
  color: var(--ln-carousel-fg);
  cursor: pointer;
}

.ln-carousel__button.ln-carousel__button:hover,
.ln-carousel__button.ln-carousel__button:focus {
  background: var(--ln-carousel-track-bg);
  color: var(--ln-carousel-accent);
}

.ln-carousel__button:focus-visible {
  outline: 2px solid var(--ln-carousel-fg);
  outline-offset: 2px;
}

/* The shared chevron points down; rotate it for left and right. */
.ln-carousel__button--prev svg {
  transform: rotate(90deg);
}

.ln-carousel__button--next svg {
  transform: rotate(-90deg);
}

/* One column: 510px of copy beside the track does not fit at this width. */
@media (max-width: 64rem) {
  .ln-carousel {
    --ln-carousel-padding-block: 56px;
    --ln-carousel-card-width: 280px;
    --ln-carousel-card-padding-start: 40px;
    --ln-carousel-card-padding-end: 24px;
    --ln-carousel-copy-gutter: 0px;

    /* No bleed in one column. The block inset stays — the shadow needs it. */
    --ln-carousel-shadow-room-inline: 0px;

    /* Zeroed via the width, not the opacity: carousel.js sets opacity inline and
       would outrank any override from this stylesheet. */
    --ln-carousel-edge-shadow-width: 0px;
  }

  .ln-carousel__heading :is(h2, h3, p) {
    font-size: clamp(2rem, 6vw, 48px);
  }

  /* The same three boxes restacked: the media moves below the track. */
  .ln-carousel__row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "copy"
      "viewport"
      "media";
  }

  .ln-carousel__copy {
    max-inline-size: var(--ln-carousel-copy-width);
  }

}

/**
 * Phone: full-bleed track, centred copy, 16px gutter.
 *
 * 47.99rem is the page's single breakpoint (see css/layout.css). The 64rem block
 * above is separate and stays: it drops the two columns earlier.
 */
@media (max-width: 47.99rem) {
  .ln-carousel {
    --ln-carousel-padding-block: 32px;
    --ln-carousel-card-gap: 24px;

    /* A plain length, not the calc() above: the track negates this in a calc()
       and a percentage there would resolve against the wrong box. */
    --ln-carousel-padding-inline: var(--ln-container-gutter, 15px);
  }

  /* Both sides here; every wider width pads the start only. */
  .ln-carousel__inner {
    padding-inline: var(--ln-carousel-padding-inline);
  }

  .ln-carousel__heading,
  .ln-carousel__copy {
    text-align: center;
  }

  /* The pill is a block at fit-content width, so text-align cannot centre it. */
  .ln-carousel__copy .ln-pill {
    margin-inline: auto;
  }

  .ln-carousel__track {
    margin-inline: calc(-1 * var(--ln-carousel-padding-inline));
    padding-inline: var(--ln-carousel-padding-inline);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ln-carousel__track {
    transition: none;
    scroll-behavior: auto;
  }
}
