/**
 * LAYOUT: GRID (opt-in; agilehomedesign.com's "grid", from its look 4, Swiss
 * Grid). Every piece on one page in masonry columns that read across, each
 * photo whole, numbered and named; a tile opens the piece's own page (the
 * piece page below), which carries the description and the extra photos.
 * Built to dist/fluid-layout-grid.min.css (export "./layout-grid"); link it
 * after core on the index and on every piece page. Contract: _docs/layouts.md.
 *
 *   <div class="layout-grid">
 *     <header class="layout-grid__head">
 *       <h1 class="layout-grid__title">We build in solid wood.</h1>
 *       <p class="layout-grid__sub">Interior and exterior.</p>
 *     </header>
 *     <div class="layout-grid__cols">
 *       <ul class="layout-grid__col" role="list">          (three columns)
 *         <li class="layout-grid__tile" id="oak-table" style="order: 0">
 *           <a href="/work/oak-table/">
 *             <img src="oak.jpg" alt="…" width="1200" height="900">      (or <span class="layout-grid__blank" aria-hidden="true"></span> with no photo)
 *             <span class="layout-grid__meta"><span class="layout-grid__n">01</span><span>Tables</span></span>
 *             <span class="layout-grid__name">Oak table</span>
 *           </a>
 *           <p class="layout-grid__shown">Shown: white oak, oiled</p>    (optional)
 *         </li>
 *       </ul>
 *     </div>
 *   </div>
 *
 * Masonry that reads across (the template's job): put each piece in the
 * shortest of three columns by its photo's shape (height / width, plus about
 * 0.35 for the words; 0.75 for a piece with no photo), so 01, 02, 03 sit side
 * by side at the top, and give each tile style="order: <index>". On a narrow
 * screen the columns dissolve and the order puts the pieces back in sequence.
 *
 * THE PIECE PAGE: the photo whole, then the words and the description; a tall
 * photo with no wide one sits beside the words on wide screens (add
 * .is-split). Every field may be missing: leave the element out.
 *
 *   <article class="layout-piece is-split">
 *     <figure class="layout-piece__photo"><picture>…<img …></picture></figure>
 *     <div class="layout-piece__text">
 *       <div class="layout-piece__head piece-words">
 *         <p class="piece-words__kind">Tables</p>
 *         <h1 class="layout-piece__title">Oak table</h1>
 *         <p class="piece-words__shown">Shown: white oak, oiled</p>
 *         <p class="piece-words__links"><a href="/inquiries/?about=oak-table">Inquire →</a></p>
 *       </div>
 *       <div class="layout-piece__body prose">…</div>
 *     </div>
 *   </article>
 *   <ul class="layout-piece__photos" role="list" data-lightbox> <li><a href="b.jpg" data-caption="…"><img …></a></li> … </ul>  (2+ photos)
 *   <nav class="layout-piece__steps" aria-label="More work">
 *     <a href="/work/walnut/" rel="prev">← Walnut</a> <a href="/#oak-table">All work</a> <a href="/work/cherry/" rel="next">Cherry →</a>
 *   </nav>   (an empty <span></span> holds a missing end's place)
 *
 * Look hooks, read with fallbacks and never declared: --layout-bar (the
 * header's height, default 4rem), --layout-name-font.
 */
@layer components {
  .layout-grid { padding: clamp(1.5rem, 6vh, 4.5rem) var(--page-edge) clamp(3.5rem, 10vh, 7.5rem); }
  .layout-grid__head { max-inline-size: 40ch; margin-block-end: clamp(2rem, 7vh, 5.5rem); }

  .layout-grid__title {
    margin: 0;
    font-family: var(--layout-name-font, var(--font-display));
    font-weight: var(--weight-light);
    font-size: clamp(2rem, 1.3rem + 2.6vw, 3.6rem);
    line-height: 1;
    letter-spacing: -0.01em;
  }

  .layout-grid__sub { margin: var(--space-3) 0 0; color: var(--color-text-muted); }

  .layout-grid__cols {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(1.25rem, 2.6vw, 2.5rem);
    align-items: start;
  }

  .layout-grid__col { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
  .layout-grid__tile { margin: 0 0 clamp(2rem, 5vh, 3.5rem); scroll-margin-block-start: var(--space-5); }
  .layout-grid__tile a { display: grid; gap: var(--space-1); color: inherit; text-decoration: none; }

  .layout-grid__tile img {
    display: block;
    inline-size: 100%;
    block-size: auto;
    max-block-size: none;
    margin-block-end: var(--space-2);
    border-radius: 0;
    background: color-mix(in oklab, var(--color-text) 8%, var(--color-background));
  }

  @media (prefers-reduced-motion: no-preference) {
    .layout-grid__tile img { transition: opacity var(--duration-normal) var(--ease-fluid); }
  }

  .layout-grid__tile a:hover img { opacity: 0.88; }
  .layout-grid__tile a:hover .layout-grid__name { text-decoration: underline; text-underline-offset: 0.15em; text-decoration-thickness: 1px; }

  .layout-grid__blank {
    display: block;
    aspect-ratio: 4 / 3;
    margin-block-end: var(--space-2);
    border: 1px solid var(--color-border-subtle);
  }

  .layout-grid__meta {
    display: flex;
    gap: var(--space-3);
    font-size: var(--step--2);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .layout-grid__n { font-weight: var(--weight-semibold); color: var(--color-text); font-variant-numeric: tabular-nums; }

  .layout-grid__name {
    font-family: var(--layout-name-font, var(--font-display));
    font-weight: var(--weight-light);
    font-size: var(--step-2);
    line-height: 1.1;
  }

  .layout-grid__shown { margin: var(--space-1) 0 0; font-size: var(--step--1); line-height: 1.5; color: var(--color-text-muted); }

  /* ---------- The piece page ---------- */
  .layout-piece picture { display: contents; }
  .layout-piece { display: grid; gap: clamp(1.75rem, 5vh, 4rem); padding: clamp(0.5rem, 2vh, 1.5rem) var(--page-edge) 0; }
  .layout-piece__photo { display: flex; justify-content: center; margin: 0; }

  .layout-piece__photo img {
    display: block;
    inline-size: auto;
    block-size: auto;
    max-inline-size: 100%;
    max-block-size: calc(100svh - var(--layout-bar, 4rem) - 2rem);
    border-radius: 0;
  }

  .layout-piece__text {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    gap: clamp(1.5rem, 5vw, 6rem);
    inline-size: 100%;
    max-inline-size: 74rem;
    margin-inline: auto;
  }

  .layout-piece__head { gap: var(--space-2); align-content: start; }

  .layout-piece__title {
    margin: 0;
    font-family: var(--layout-name-font, var(--font-display));
    font-weight: var(--weight-light);
    font-size: clamp(2rem, 1.4rem + 2vw, 3.2rem);
    line-height: 1;
  }

  .layout-piece :is(.piece-words__kind, .piece-words__shown) { color: var(--color-text-muted); opacity: 1; }
  .layout-piece__body { font-size: var(--step-0); line-height: 1.7; max-inline-size: 62ch; }
  .layout-piece__body > :first-child { margin-block-start: 0; }

  .layout-piece.is-split { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: end; }
  .layout-piece.is-split .layout-piece__text { grid-template-columns: 1fr; padding-block-end: var(--space-5); }

  .layout-piece__photos {
    columns: 3 13.75rem;
    column-gap: var(--space-4);
    margin: clamp(2.5rem, 8vh, 6rem) var(--page-edge) 0;
    padding: 0;
    list-style: none;
  }

  .layout-piece__photos li { break-inside: avoid; margin-block-end: var(--space-4); }
  .layout-piece__photos img { display: block; inline-size: 100%; block-size: auto; max-block-size: none; border-radius: 0; }

  .layout-piece__steps {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: var(--space-4);
    align-items: center;
    margin: clamp(3rem, 10vh, 7.5rem) var(--page-edge) 0;
    padding: var(--space-5) 0 var(--space-10);
    border-block-start: 1px solid var(--color-border-subtle);
    font-size: var(--step--2);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  .layout-piece__steps a { color: inherit; text-decoration: none; }
  .layout-piece__steps a:hover { text-decoration: underline; text-underline-offset: 4px; }
  .layout-piece__steps a[rel="next"] { justify-self: end; text-align: end; }

  @media (orientation: portrait), (max-width: 47.5rem) {
    .layout-grid__cols { display: flex; flex-direction: column; gap: 0; }
    .layout-grid__col { display: contents; }
    .layout-piece.is-split, .layout-piece__text { grid-template-columns: 1fr; }
    .layout-piece__photo img { max-block-size: 80svh; }
  }

  /* ---------- 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; }
}
