/* The collection: its head (title, class tabs, view switch, search, caption) and the grid the
   tiles file into. The insides of .views and .find are rows.css's; this file places them. */
@layer collection {
  .collection {
    padding-block: clamp(1.25rem, 2.5vw, 2rem) 0;
    border-top: 1px solid var(--hair-strong);
  }

  .collection__head {
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--col-gap); row-gap: 0.75rem;
    align-items: end;
    padding-block-end: clamp(1rem, 2vw, 1.5rem);

    & > * { grid-column: 1 / -1; min-inline-size: 0; }
  }
  /* display type, kept compact so the first tiles reach screen one */
  .collection__title { font-size: clamp(2.25rem, 1.5rem + 2.4vw, 3.75rem); line-height: 0.9; letter-spacing: -0.035em; }
  .collection__caption { font-style: italic; color: var(--ink-2); text-wrap: pretty; }
  /* While examples share the shelf: one plain line above the grid saying which project is real */
  .collection__note {
    font: 400 var(--fs-mono) / 1.6 var(--mono); color: var(--ink-2); text-wrap: pretty;
    & b { font-weight: 500; color: var(--ink); }
    & .vh-example { margin-inline: 0.1rem; }
  }
  .classes { display: flex; flex-wrap: wrap; }
  /* Phones: the tabs are one row that scrolls sideways (the cut edge says so); room for the notch and focus ring */
  @media (width < 40rem) {
    .classes {
      flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain;
      padding: 4px 4px 9px 5px; margin: -4px -4px -9px -5px;
      scrollbar-width: none;
    }
    .classes__tab { flex: none; }

    /* Title and the Posters | Index switch share the first row (they wrap apart below ~22rem); the
       caption repeats the pressed tab, so it is read, not shown. Its live updates still announce. */
    .collection__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
    .collection__head > * { flex: 1 1 100%; }
    .collection__head > .collection__title { flex: 0 1 auto; order: -2; }
    .collection__head > .views { flex: 0 0 auto; order: -1; }
    .collection__head > .collection__caption {
      position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden;
      clip-path: inset(50%); white-space: nowrap;
    }
  }

  /* 40-64rem: the view switch and search share a row */
  @media (width >= 40rem) {
    .collection__head > .views { grid-column: 1 / span 5; }
    .collection__head > .find { grid-column: 6 / -1; }
  }
  /* 64rem+: two rows. Title | tabs, then caption | switch | search */
  @media (width >= 64rem) {
    .collection__head > .collection__title { grid-column: 1 / span 4; grid-row: 1; }
    .collection__head > .classes { grid-column: 5 / -1; grid-row: 1; justify-content: end; }
    .collection__head > .collection__caption { grid-column: 1 / span 4; grid-row: 2; align-self: center; }
    .collection__head > .views { grid-column: 5 / span 3; grid-row: 2; align-self: start; }
    .collection__head > .find { grid-column: 8 / -1; grid-row: 2; align-self: start; }
    .collection__head > .collection__note { grid-row: 3; }
  }

  .classes__tab {
    position: relative;
    display: inline-flex; align-items: center; gap: 0.45rem;
    min-block-size: 44px;
    padding: 0.55rem 0.95rem;
    margin-inline-start: -1px; margin-block-start: -1px;
    border: 1px solid var(--hair-strong);
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    color: var(--ink-2);
    transition: color 0.2s, background-color 0.2s;

    & i { font: italic 400 1.15rem / 0 var(--serif); letter-spacing: 0; text-transform: none; color: var(--accent-text); }
    & sup { font-size: 0.625rem; vertical-align: 0.5em; color: var(--ink-3); letter-spacing: 0; }

    &:hover { color: var(--ink); z-index: 1; border-color: var(--ink-2); }
    &:focus-visible { z-index: 3; outline: 2px solid var(--accent); outline-offset: 2px; }
    &[aria-pressed="true"] {
      z-index: 2;
      background: var(--white); color: var(--black); border-color: var(--white);
      & sup { color: var(--black); }
      /* the tab's notch: it is the drawer that is open */
      &::after {
        content: ''; position: absolute; left: 50%; bottom: -7px; translate: -50% 0;
        border: 6px solid transparent; border-top-color: var(--white); border-bottom: 0;
      }
    }
    &.htmx-request { cursor: progress; background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--hair) 4px 5px); }
  }

  .collection__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 17.5rem), 1fr));
    border-block-start: 1px solid var(--hair-strong);
    border-inline-start: 1px solid var(--hair);
  }
  /* Reserve room for a row of tiles while the first fragment loads (no layout shift); the index rows need none */
  .collection__grid:not(:has(> .row)) { min-block-size: 36rem; }
  /* Phones: Featured follows the list and loads as it nears the viewport, so until the first fragment lands
     the list holds a screen, keeping Featured out of reach of its intersect trigger (index.html) */
  @media (width < 40rem) { .collection__grid:has(> .collection__fallback) { min-block-size: 100svh; } }
  .collection__fallback, .collection__empty {
    padding: 2rem; font: 400 var(--fs-mono) / 1.4 var(--mono); color: var(--ink-3);
  }

  @media (prefers-reduced-motion: reduce) {
    .classes__tab { transition: none; }
  }
}
