/**
 * LAYOUT: GALLERY (opt-in; from agilehomedesign.com, live 2026-11-04, Neil:
 * "what I envisioned"). Full-screen photos stacked top to bottom, one per
 * screen, snapping. A wide photo fills a landscape screen; two tall photos
 * share one side by side; on a portrait screen every photo has its own. Three
 * short lines per piece over the photo; the description is not shown.
 * Built to dist/fluid-layout-gallery.min.css (export "./layout-gallery");
 * link it after core. One of the switchable layouts: same content, other
 * placement (_docs/layouts.md has the contract every layout keeps).
 *
 *   <div class="layout-gallery">
 *     <section class="layout-gallery__screen layout-gallery__screen--wide" aria-label="Oak table">
 *       <figure class="layout-gallery__frame" id="oak-table" data-n="1">
 *         <picture>
 *           <source media="(orientation: landscape)" srcset="oak-wide.jpg" width="1600" height="900">
 *           <img src="oak.jpg" alt="…" width="1200" height="900" fetchpriority="high">
 *         </picture>
 *         <figcaption class="piece-words">
 *           <span class="piece-words__kind">Tables</span>
 *           <span class="piece-words__name">Oak table</span>
 *           <span class="piece-words__shown">Shown: white oak, oiled</span>   (optional)
 *           <span class="piece-words__links">
 *             <a href="/inquiries/?about=oak-table">Inquire →</a>
 *             <button type="button" class="piece-words__more" data-photos="oak-table">3 photos</button>  (2+ photos)
 *           </span>
 *         </figcaption>
 *         <ul data-lightbox data-for="oak-table" hidden> <li><a href="oak.jpg" data-caption="Oak table"><img src="oak.jpg" alt="" loading="lazy"></a></li> … </ul>
 *       </figure>
 *       <div class="layout-gallery__intro"><p>We build in solid wood.</p><span aria-hidden="true">↓</span></div>  (first screen only, optional)
 *     </section>
 *     <section class="layout-gallery__screen layout-gallery__screen--pair" aria-label="A and B"> two frames </section>
 *     <section class="layout-gallery__screen layout-gallery__screen--tall" aria-label="C"> one tall frame, paper beside it </section>
 *   </div>
 *   <p class="layout-gallery__count" aria-hidden="true"><b data-count>01</b> / 12</p>   (optional)
 *   <script src="assets/js/lightbox.js" defer></script>
 *   <script src="assets/js/layouts.js" defer></script>   (counter and "N photos")
 *
 * Grouping (the template's job): a piece is tall when its main photo is
 * taller than wide and it has no wide photo. Tall pieces pair up in order; a
 * tall one left over gets a --tall screen; everything else is --wide. Mark a
 * landscape main photo `class="is-wide"` so a portrait screen shows it whole
 * (contain) instead of cropping it. A piece with no photo is left out.
 * The id on each frame makes /#<slug> land on it (the snap is CSS only).
 *
 * Look hooks, read with fallbacks and never declared: --layout-dark (behind
 * the photos), --layout-light (the words over them), --layout-shade (the
 * top and bottom gradient), --layout-name-font.
 */
@layer components {
  :root:has(.layout-gallery) {
    scroll-snap-type: y mandatory;
    background: var(--layout-dark, #111);
  }

  @media (prefers-reduced-motion: no-preference) {
    :root:has(.layout-gallery) { scroll-behavior: smooth; }
  }

  .layout-gallery picture { display: contents; }

  .layout-gallery__screen {
    position: relative;
    display: flex;
    block-size: 100svh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }

  .layout-gallery__frame {
    position: relative;
    flex: 1 1 0;
    min-inline-size: 0;
    margin: 0;
    overflow: hidden;
    color: var(--layout-light, oklch(96% 0.012 75));
    background: var(--layout-dark, #111); /* until the photo loads */
  }

  /* Pinned to the frame: core caps a figure's image at 85svh. */
  .layout-gallery__frame img {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    max-inline-size: none;
    max-block-size: none;
    border-radius: 0;
    object-fit: cover;
  }

  /* A soft shade top and bottom, so light words always read. */
  .layout-gallery__frame::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: var(--layout-shade, linear-gradient(180deg, rgb(0 0 0 / 0.32), transparent 22%, transparent 62%, rgb(0 0 0 / 0.5)));
  }

  .layout-gallery__screen--tall .layout-gallery__frame { flex: 0 1 50%; }
  .layout-gallery__screen--tall::after { content: ""; flex: 1 1 50%; background: var(--color-background); }

  .layout-gallery .piece-words {
    position: absolute;
    z-index: 1;
    inset-inline: var(--page-edge);
    inset-block-end: clamp(1.25rem, 4.5vh, 2.75rem);
    margin: 0;
    max-inline-size: none;
    color: inherit;
    text-shadow: 0 1px 12px rgb(0 0 0 / 0.45);
  }

  .layout-gallery__frame :focus-visible { outline-color: currentColor; outline-offset: 4px; }

  /* The first screen carries the one line about what the site does. */
  .layout-gallery__intro {
    position: absolute;
    z-index: 2;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
    pointer-events: none;
    color: var(--layout-light, oklch(96% 0.012 75));
    text-shadow: 0 1px 18px rgb(0 0 0 / 0.55), 0 0 2px rgb(0 0 0 / 0.25);
    background: radial-gradient(ellipse 40% 22% at 50% 50%, rgb(0 0 0 / 0.22), transparent);
  }

  .layout-gallery__intro p {
    margin: 0;
    font-family: var(--layout-name-font, var(--font-display));
    font-weight: var(--weight-light);
    font-size: var(--step-2);
    line-height: 1.4;
  }

  .layout-gallery__intro > span { margin-block-start: var(--space-4); opacity: 0.8; }

  .layout-gallery__count {
    position: fixed;
    z-index: var(--z-raised);
    inset-inline-end: var(--page-edge);
    inset-block-end: clamp(1.25rem, 4.5vh, 2.75rem);
    margin: 0;
    color: var(--layout-light, oklch(96% 0.012 75));
    font-size: var(--step--2);
    letter-spacing: var(--tracking-caps);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 10px rgb(0 0 0 / 0.4);
    pointer-events: none;
  }

  .layout-gallery__count b { font-weight: var(--weight-semibold); }

  /* A portrait screen (a phone): every photo gets its own screen, and a wide
     photo shows whole on the dark ground. */
  @media (orientation: portrait) {
    .layout-gallery__screen--pair { display: contents; }

    .layout-gallery__screen--pair .layout-gallery__frame,
    .layout-gallery__screen--tall .layout-gallery__frame {
      flex: 1 1 auto;
      block-size: 100svh;
      scroll-snap-align: start;
      scroll-snap-stop: always;
    }

    .layout-gallery__screen--tall::after { display: none; }
    .layout-gallery__frame img.is-wide { object-fit: contain; }
    .layout-gallery .piece-words { inset-inline-end: calc(var(--page-edge) + 4rem); }
  }

  /* ---------- Piece words (every layout file carries this block) ---------- */
  .piece-words { display: grid; gap: var(--space-1); font-style: normal; text-align: start; }

  .piece-words__kind {
    margin: 0;
    font-size: var(--step--2);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    opacity: 0.85;
  }

  .piece-words__name {
    margin: 0;
    font-family: var(--layout-name-font, var(--font-display));
    font-weight: var(--weight-light);
    font-size: clamp(1.6rem, 1.1rem + 1.6vw, 2.6rem);
    line-height: 1.05;
  }

  .piece-words__shown { margin: 0; font-size: var(--step--1); opacity: 0.9; }

  .piece-words__links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    align-items: center;
    margin: var(--space-2) 0 0;
    font-size: var(--step--2);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  .piece-words__links a { color: inherit; text-decoration: none; border-block-end: 1px solid currentColor; padding-block-end: 2px; }

  .piece-words__links button {
    all: unset;
    /* core's button hover paints the accent; these stay text */
    --_btn-bg-hover: transparent;
    --_btn-color-hover: currentColor;
    cursor: pointer;
    opacity: 0.85;
    border-block-end: 1px solid transparent;
    padding-block-end: 2px;
  }

  .piece-words__links button:is(:hover, :focus-visible) { opacity: 1; border-block-end-color: currentColor; }
  /* The ring is the words' own colour: light over photos, ink on paper. */
  .piece-words__links :is(a, button):focus-visible { outline: 2px solid currentColor; outline-offset: 4px; }
}
