/*
  carousel-arrow-addon.css
  ---------------------------------------------------------------------
  Adds previous/next arrow controls on top of carousel.css's scroll-
  snap track, plus the CSS that hides the native scrollbar once
  JavaScript confirms every required element exists for that specific
  carousel instance and adds .carousel--enhanced to it (see
  js/carousel-arrow-addon.js). Without the script, or for a carousel
  whose markup is missing a piece, the controls stay display: none,
  the native scrollbar stays visible, and the base carousel is
  otherwise unaffected.

  Requires: css/reset.css, css/core.css, css/components/carousel.css

  HTML STRUCTURE:
    <section class="carousel" aria-label="Recent projects">
      <div class="carousel__track" tabindex="0">
        <article class="carousel__slide grid" style="--col-count-lg: 2;">
          <figure class="carousel__media"><img src="..." alt="..." /></figure>
          <div class="carousel__copy stack">
            <h2>Slide heading</h2>
            <p>Slide content.</p>
          </div>
        </article>
      </div>
      <div class="carousel__status visually-hidden" aria-live="polite" aria-atomic="true" hidden></div>
      <button type="button" class="carousel__control carousel__control--prev" aria-label="Previous slide"></button>
      <button type="button" class="carousel__control carousel__control--next" aria-label="Next slide"></button>
    </section>

  Previous/next arrows have no text content - the chevron is drawn
  entirely with CSS (a rotated border corner on ::before, see below),
  not a Unicode character. ❮/❯ and similar glyphs render visibly low
  within their own line box in every engine tested (Chromium,
  Firefox, WebKit), a font-metrics quirk of those specific glyphs:
  their drawn ink isn't centered within the box the browser lays out
  for them, so no layout property (padding, line-height, a wrapper's
  own transform) can correct it - those all act on the box, and the
  box already measures as centered. A transform on the BUTTON itself
  doesn't help either: it moves the button and its content together
  as one rigid unit, so it can shift the whole circle but can never
  change the glyph's position relative to it. A border-drawn shape
  sidesteps the problem entirely, since its geometry comes from
  width/height/border-width, not font rendering - it centers exactly
  the same way in every browser and OS. aria-label supplies the
  accessible name either way, exactly as it did with the text glyph.
  ---------------------------------------------------------------------
*/

@layer tokens {
  :root {
    --carousel-control-size: 44px;
    /*
      Used only by .carousel__control below - not shared with any
      other component, so it lives here rather than in core.css.
    */

    /* Deliberately NOT var(--color-text): the control's background
       below is a fixed rgb(0 0 0 / 0.58) regardless of theme, so a
       foreground that inherits the page's own text color is only
       correct by accident in a dark theme, where that variable
       happens to already be light. In a light theme --color-text is
       dark, pairing dark-on-dark - the arrow, a piece of UI a user
       needs to actually see to identify the control, fails WCAG's
       non-text contrast criterion (3:1) at that point. A fixed light
       value is the only foreground that's always correct against a
       background that's always dark. */
    --carousel-control-color: #ffffff;
  }
}

@layer components {
  /* Arrows are positioned against .carousel, and they sit inside its
     bounds, so the base component's overflow: hidden never clips them. */
  .carousel {
    position: relative;
  }

  .carousel__control {
    display: none;
    position: absolute;
    font-size: 1rem; /* prevent inheriting body font-size from affecting glyph/icon scale */
    top: 50%;
    transform: translateY(-50%);
    width: var(--carousel-control-size);
    height: var(--carousel-control-size);
    border-radius: 50%;
    background: rgb(0 0 0 / 0.58);
    color: var(--carousel-control-color);
    border: 1px solid color-mix(in oklab, var(--carousel-control-color) 35%, transparent);
    cursor: pointer;
    z-index: 2;
  }

  .carousel__control:hover {
    background: rgb(0 0 0 / 0.72);
  }

  .carousel__control--prev {
    inset-inline-start: var(--space-2);
  }

  .carousel__control--next {
    inset-inline-end: var(--space-2);
  }

  /* The chevron itself: a clip-path triangle-notch shape, not a
     rotated border corner. A border-corner shape (an earlier version
     of this rule) has its two visible edges both on the SAME half of
     its box, so its own visual weight sits off toward that half no
     matter how the box itself is centered - and nudging it back with
     transform: translate() turned out fragile in practice: combined
     with the rotate() needed to orient the corner, equal-magnitude
     x/y inputs collapse to an almost purely VERTICAL result on
     screen (the horizontal components cancel via the rotation
     matrix), so it never actually corrected the horizontal
     mismatch it was meant to fix, only ever shifted things
     vertically - a trap that isn't obvious without doing the
     trigonometry.

     clip-path avoids the rotation trap: every vertex is placed
     explicitly, no transform involved at all. A bounding-box-
     symmetric first pass (x spanning 20%-80%, evenly around 50%)
     still read as slightly off-center visually, though - the tip is
     a single point while the opposite end is two full-width arms, so
     the shape's actual visual weight sits closer to the arms than a
     plain bounding-box midpoint accounts for. Confirmed and
     corrected empirically the same way: shift the whole shape a few
     points toward its own tip (the coordinates below are no longer
     symmetric around exactly 50% for this reason, on purpose). */
  .carousel__control--prev::before,
  .carousel__control--next::before {
    content: "";
    width: 16px;
    height: 16px;
    background: currentColor;
  }

  .carousel__control--prev::before {
    clip-path: polygon(65% 15%, 15% 50%, 65% 85%, 75% 85%, 40% 50%, 75% 15%);
  }

  .carousel__control--next::before {
    clip-path: polygon(35% 15%, 85% 50%, 35% 85%, 25% 85%, 60% 50%, 25% 15%);
  }

  .carousel__control[hidden] {
    display: none !important;
  }

  /* Scoped to .carousel--enhanced, a class the JS adds only after
     confirming a real track, both buttons, and at least one slide all
     exist for THIS specific carousel - not just a global .js class.
     A malformed carousel (missing a required piece) never gets its
     native scrollbar hidden behind arrows that were never wired up:
     the JS returns early for it and .carousel--enhanced is never
     added, so it keeps its default, functional scroll affordance. */
  .carousel--enhanced .carousel__track {
    scrollbar-width: none;
  }

  .carousel--enhanced .carousel__track::-webkit-scrollbar {
    display: none;
  }

  .carousel--enhanced .carousel__control {
    display: grid;
    place-items: center;
  }
}
