/*
  gallery.css
  ---------------------------------------------------------------------
  Base image gallery: a responsive grid (.media-gallery) of cropped
  tiles (.media-gallery__item), each an image inside a
  .media-gallery__thumb (a lightbox trigger) or .media-gallery__frame
  (a plain link), with an optional .media-gallery__caption below. Just
  the grid and the frame - a title, body copy and call-to-action are
  added on top by gallery-card-addon.css, with gallery-product-addon.css,
  gallery-book-addon.css and gallery-route-addon.css specializing
  further from there.

  Requires: css/reset.css, css/core.css

  HTML STRUCTURE:
    <ul class="media-gallery">
      <li class="media-gallery__item">
        <figure>
          <div class="media-gallery__frame">
            <img class="media-gallery__image" src="..." alt="..." />
          </div>
          <figcaption class="media-gallery__caption">City skyline at dusk</figcaption>
        </figure>
      </li>
    </ul>

  FIXED COLUMNS INSTEAD OF AUTO-FIT:
    By default .media-gallery auto-fits as many --thumb-min-wide
    columns as the container allows. Set --col-count (and optionally
    --col-count-md / --col-count-lg), the same variables .grid uses,
    to force an exact column count per breakpoint instead:
      <ul class="media-gallery" style="--col-count: 1; --col-count-md: 2; --col-count-lg: 4;">
    --col-widths (plus -md/-lg) works the same way it does on .grid,
    for explicit, unequal track sizes instead of a repeated count.
    Setting neither changes nothing - auto-fit stays the default.
  ---------------------------------------------------------------------
*/

@layer components {
  .media-gallery {
    list-style: none;
    padding: 0;
    --thumb-min: 12rem;
    --col-layout: var(--col-widths, repeat(var(--col-count, auto-fit), minmax(min(100%, var(--thumb-min)), 1fr)));
    --col-layout-md: var(--col-widths-md, repeat(var(--col-count-md), minmax(min(100%, var(--thumb-min)), 1fr)));
    --col-layout-lg: var(--col-widths-lg, repeat(var(--col-count-lg), minmax(min(100%, var(--thumb-min)), 1fr)));
    display: grid;
    gap: var(--space-4);
    grid-template-columns: var(--col-layout);
  }

  @media (min-width: 768px) {
    .media-gallery {
      grid-template-columns: var(--col-layout-md, var(--col-layout));
    }
  }

  @media (min-width: 1024px) {
    .media-gallery {
      grid-template-columns: var(--col-layout-lg, var(--col-layout-md, var(--col-layout)));
    }
  }

  .media-gallery__item {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
  }

  .media-gallery__item > figure {
    display: flex;
    flex-direction: column;
    height: 100%;
    
  }

  .media-gallery__thumb,
  .media-gallery__frame {
    display: block;
    width: 100%;
    background: transparent;
    padding: 0;
    border: 0;
    border-radius: var(--frame-radius, 0);
    aspect-ratio: 4 / 3;
    overflow: hidden;
    flex: 0 0 auto;
  }

  /* A standalone frame (a single product image, not a grid tile
     already clipped by .media-gallery__item) sometimes needs a
     square crop instead of the 4/3 default. */
  .media-gallery__frame--square {
    aspect-ratio: 1 / 1;
  }

  /* .media-gallery__frame is an <a> when there's no separate .media-gallery__title
     link (see gallery-book-addon.css) - the native underline paints
     through any text content placed directly inside it (a child
     setting text-decoration: none on itself does not reliably stop a
     decoration line generated by an ancestor), so it's suppressed at
     the source here rather than on whatever ends up inside the frame. */
  .media-gallery__frame {
    text-decoration: none;
  }

  .media-gallery__thumb {
    cursor: pointer;
  }

  .media-gallery__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .media-gallery__caption {
    padding: var(--space-4);
    font-size: 0.9rem;
    color: var(--color-muted);
    background: color-mix(in oklab, var(--color-surface) 86%, black 14%);
    border-block-start: 1px solid var(--color-border);
    flex: 1 1 auto;
    /* flex: 0 0 auto; */
  }
        .media-gallery--card .media-gallery__item>figure {
          margin: 0;
        }
}
