/* Home page carousel of the newest articles. Native scroll + scroll snap; carousel.js adds controls, markers, status and looping. */
@layer components {
  .c-carousel { position: relative; display: flex; flex-direction: column; min-width: 0; overflow: clip; border-radius: var(--radius-md); background: var(--surface-inverse); color: var(--on-inverse); }
  /* Author display rules would otherwise beat the reset's [hidden] rule (later layer). */
  .c-carousel [hidden] { display: none; }

  .c-carousel__track {
    flex: 1;
    display: flex;
    overflow-x: auto;
    /* mandatory: the track always rests on a slide, which the settled-scroll status relies on */
    scroll-snap-type: x mandatory;
    /* x only, so the page still scrolls vertically over the carousel */
    overscroll-behavior-x: contain;
    touch-action: manipulation;
  }
  /* Without JS there are no controls, so the native scrollbar stays as the only cue. */
  .c-carousel:has(.c-carousel__controls:not([hidden])) .c-carousel__track { scrollbar-width: none; }
  .c-carousel__track:focus-visible { outline-color: var(--focus-on-dark); outline-offset: calc(-1 * var(--focus-width)); }
  @media (prefers-reduced-motion: no-preference) {
    .c-carousel__track { scroll-behavior: smooth; }
  }

  /* Looping: the script keeps --current (index of the current slide) on the track and parks an end slide next to it.
     --children-count is only set by the script where sibling-count() is unsupported.
     With exactly 3 slides the plain formulas park both ends around the middle slide and reverse the order, so the
     thresholds are clamped (max/min); for 4 or more slides the result is unchanged. */
  .c-carousel__track > :first-child { order: clamp(0, var(--current) - (max(var(--children-count, sibling-count()), 4) - 3), 1); }
  .c-carousel__track > :last-child { order: calc(-1 * clamp(0, min(2, var(--children-count, sibling-count()) - 2) - var(--current), 1)); }

  /* Slide: image on top, text below on small screens; text over a scrim from 48em. */
  .c-slide { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; flex: 0 0 100%; min-width: 0; scroll-snap-align: center; }
  .c-slide__img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-alt); }
  .c-slide__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); align-content: start; padding: var(--space-4); }
  .c-slide__labels { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
  .c-slide .c-label { color: var(--accent-on-brand); }
  .c-slide a.c-label:hover, .c-slide a.c-label.is-hover { color: var(--on-inverse); }
  .c-slide__title { font-size: var(--fs-h3-sm); line-height: var(--lh-snug); hyphens: auto; color: var(--on-inverse); }
  .c-slide__title a { color: inherit; text-decoration: none; }
  .c-slide__title a::after { content: ""; position: absolute; inset: 0; }
  .c-slide:hover .c-slide__title a { color: var(--on-inverse); text-decoration: underline; }
  .c-slide:has(.c-slide__title a:focus-visible) { outline: var(--focus-width) solid var(--focus-on-dark); outline-offset: calc(-1 * var(--focus-width)); }
  .c-slide__title a:focus-visible { outline: none; }
  .c-slide__lead { display: none; font-family: var(--font-serif); font-size: var(--fs-lg); line-height: var(--lh-normal); color: var(--on-inverse); }
  .c-slide__meta { color: var(--on-inverse-muted); }

  /* Previous / next sit over the image area (16:9 from the top), before the track in DOM order. */
  .c-carousel__controls { position: absolute; inset-inline: 0; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; aspect-ratio: 16 / 9; padding-inline: var(--space-2); pointer-events: none; }
  .c-carousel__btn { display: grid; place-items: center; inline-size: var(--tap); block-size: var(--tap); padding: 0; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 50%; background: rgba(36, 26, 19, 0.78); color: var(--on-inverse); touch-action: manipulation; pointer-events: auto; transition: background-color var(--dur-1); }
  .c-carousel__btn:hover { background: var(--surface-inverse); }
  .c-carousel__btn:focus-visible { outline: var(--focus-width) solid var(--focus-on-dark); outline-offset: var(--focus-offset); }
  .c-carousel__btn:disabled { opacity: 0.45; cursor: default; }

  /* Markers: 28px targets; the active one is a long pill, the others small dots (shape, not colour alone). */
  .c-carousel__markers { display: flex; flex-wrap: wrap; justify-content: center; padding-block: var(--space-2); }
  .c-carousel__marker { display: grid; place-items: center; inline-size: 1.75rem; block-size: 1.75rem; padding: 0; border: 0; background: none; touch-action: manipulation; }
  .c-carousel__marker::before { content: ""; inline-size: 0.5rem; block-size: 0.5rem; border-radius: 999px; background: var(--on-inverse-muted); transition: inline-size var(--dur-2), background-color var(--dur-2); }
  .c-carousel__marker:hover::before { background: var(--on-inverse); }
  .c-carousel__marker[aria-current="true"]::before { inline-size: 1.5rem; background: var(--accent-on-brand); }
  .c-carousel__marker:focus-visible { outline: var(--focus-width) solid var(--focus-on-dark); outline-offset: calc(-1 * var(--space-1)); }

  @media (min-width: 48em) {
    /* The image keeps its 16:9 as the minimum height; when the row is taller (hero list) the slide grows and the image covers it. */
    .c-slide { grid-template-areas: "stack"; align-content: stretch; }
    .c-slide > * { grid-area: stack; }
    .c-slide__img { align-self: stretch; }
    .c-slide__body { align-self: end; z-index: 1; padding: var(--space-12) calc(var(--tap) + var(--space-6)) var(--space-6); background: linear-gradient(to top, rgba(20, 12, 6, 0.92) 0%, rgba(20, 12, 6, 0.78) 55%, rgba(20, 12, 6, 0) 100%); }
    .c-slide__title { font-size: var(--fs-h2); line-height: var(--lh-tight); }
    .c-slide__lead { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
    .c-carousel__controls { inset-block: 0 calc(1.75rem + var(--space-4)); aspect-ratio: auto; padding-inline: var(--space-4); }
  }
}
