/* ==========================================================================
   Francis Davis Millet Institute - Gallery page (view "gallery")
   Figma: "Page 2 · Gallery" (45:45, 1440 wide) and "Phone 2 · Gallery"
   (49:358, 390 wide). Loaded after tokens.css and base.css.
   Template: page-gallery.php. Script: assets/js/gallery.js.

   Copy of build/gallery/gallery.css. What the theme changed:
   - the italic line under the grid about a row left short on purpose is gone
     (it was a note to the client, not site content);
   - the tiles are printed by the template, so without JavaScript the grid is
     complete and only the controls that need a script are hidden;
   - real data has one chip more than the frame (1910s), so on a narrow
     desktop the count may move to a line of its own (section 3);
   - text written on the Gallery page in WordPress, if any, takes the place
     of the intro sentence (.fdm-gallery__intro).

   Contents
    1. Page values missing from tokens.css
    2. Page head
    3. Toolbar: search, decade chips, count
    4. Grid and tiles (with the "No image available" tile)
    5. Empty state, Show more, no JavaScript
    6. Tablet (600 to 1023.98px)
    7. Phone (up to 599.98px)
   ========================================================================== */

/* 1. Page values missing from tokens.css ----------------------------------- */

/* These sizes are drawn in the Gallery frames but have no token yet. They
   are kept here in one place so they can move to tokens.css unchanged. */
.fdm-gallery {
  --fdm-gallery-columns: 3;
  --fdm-gallery-col-gap: 29px;           /* 386 + 29 + 386 + 29 + 386 = 1216 */
  --fdm-gallery-row-gap: var(--fdm-space-36);
  --fdm-gallery-lead-measure: 760px;     /* intro text box in the frame */
  --fdm-gallery-search-width: 300px;
  --fdm-gallery-search-min: 200px;
  --fdm-gallery-lh-title: 23px;          /* 18 / 130%, snapped as Figma does */
  --fdm-gallery-lh-title-phone: 22px;    /* 17 / 130% */
  --fdm-gallery-lh-year-phone: 13px;     /* 11 / 120% */
  --fdm-gallery-focus-room: 6px;         /* space for the focus ring in the phone chip row */
}

/* 2. Page head ------------------------------------------------------------- */

/* The drawn intro sentence, or (.fdm-gallery__intro) the text written on the
   Gallery page in WordPress, which takes its place on every screen. */
.fdm-gallery__lead,
.fdm-gallery__intro {
  max-width: var(--fdm-gallery-lead-measure);
}

/* The phone frame shows a shorter intro. It repeats the long one, so it is
   hidden from screen readers and the long one stays in the reading order. */
.fdm-gallery__lead-short {
  display: none;
}

/* 3. Toolbar: search, decade chips, count ---------------------------------- */

/* One line at 1440, as drawn. Real data has one chip more than the frame, so
   on a narrow desktop the search field gives way first (300px down to 200px)
   and then the count moves to a line of its own, at the right, as it does on
   a tablet. */
.fdm-gallery__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--fdm-space-16);
  padding-bottom: var(--fdm-space-16);
}

/* 300 x 52 in the frame: it starts from its smallest width and takes the
   room that is left, up to the drawn 300px. */
.fdm-gallery__search {
  flex: 1 1 var(--fdm-gallery-search-min);
  min-width: var(--fdm-gallery-search-min);
  max-width: var(--fdm-gallery-search-width);
  cursor: text;
}

/* Top-aligned as drawn: the chosen chip has no border, so it is 30px tall
   beside the 32px chips and sits level with their top edge. */
.fdm-gallery__chips {
  flex: 0 1 auto;
  align-items: flex-start;
  min-width: 0;
}

.fdm-gallery__count {
  flex: none;
  margin-left: auto;
  white-space: nowrap;
}

/* 4. Grid and tiles -------------------------------------------------------- */

/* Three equal columns. Works stay in date order and the grid never moves a
   later work up to fill a hole, so a landscape that does not fit in the
   space left on a row starts the next row and leaves a gap behind it. */
.fdm-gallery__grid {
  display: grid;
  grid-template-columns: repeat(var(--fdm-gallery-columns), minmax(0, 1fr));
  grid-auto-flow: row;
  align-items: start;
  column-gap: var(--fdm-gallery-col-gap);
  row-gap: var(--fdm-gallery-row-gap);
  margin-bottom: var(--fdm-space-24);
}

.fdm-gallery__item {
  min-width: 0;
}

/* A landscape work takes two columns (801px at 1440). */
.fdm-gallery__item--landscape {
  grid-column: span 2;
}

.fdm-gallery__tile {
  display: flex;
  flex-direction: column;
  gap: var(--fdm-space-10);
  color: var(--fdm-color-text);
  text-decoration: none;
}

/* The picture fills the column and keeps its own proportions: no crop. The
   width and height attributes hold its place while it loads. */
.fdm-gallery__image {
  width: 100%;
  height: auto;
  background: var(--fdm-color-surface-alt);
}

/* A work with no picture uses the shared panel .fdm-noimage (base.css) in
   place of the image. The tile around it is the link, so the panel's
   "See the details" line follows the tile's hover. */
.fdm-gallery__tile:hover .fdm-noimage__link {
  text-decoration-thickness: 2px;
}

.fdm-gallery__caption {
  display: flex;
  flex-direction: column;
  gap: var(--fdm-space-3);
}

/* Year: Raleway SemiBold 12/120%, +6% */
.fdm-gallery__year {
  font-family: var(--fdm-font-label);
  font-size: var(--fdm-fs-12);
  font-weight: var(--fdm-weight-semibold);
  line-height: var(--fdm-lh-12);
  letter-spacing: var(--fdm-ls-6);
  color: var(--fdm-color-label);
}

/* Title: Crimson Text 18/130% */
.fdm-gallery__title {
  font-size: var(--fdm-fs-18);
  line-height: var(--fdm-gallery-lh-title);
  overflow-wrap: anywhere;
}

.fdm-gallery__tile:hover .fdm-gallery__title {
  text-decoration: underline;
  text-decoration-thickness: from-font;
  text-underline-position: from-font;
}

/* 5. Empty state, Show more, no JavaScript --------------------------------- */

.fdm-gallery__body {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--fdm-space-80);
}

.fdm-gallery__empty {
  padding-block: var(--fdm-space-32) var(--fdm-space-24);
}

.fdm-gallery__empty .fdm-link {
  font-size: inherit;
  line-height: inherit;
}

.fdm-gallery__more {
  display: flex;
  justify-content: center;
  padding-top: var(--fdm-space-40);
}

/* Without JavaScript every tile is on the page. Search, chips, count and
   "Show more works" need the script, so they are left out. */
html:not(.fdm-js) .fdm-gallery__toolbar,
html:not(.fdm-js) .fdm-gallery__more {
  display: none;
}

/* 6. Tablet (600 to 1023.98px) --------------------------------------------- */

@media (max-width: 1023.98px) {
  .fdm-gallery {
    --fdm-gallery-columns: 2;
    --fdm-gallery-col-gap: var(--fdm-space-24);
    --fdm-gallery-row-gap: var(--fdm-space-32);
  }

  .fdm-gallery__search {
    flex: 1 1 100%;
    max-width: none;
  }

  .fdm-gallery__chips {
    flex: 0 1 auto;
  }
}

/* 7. Phone (up to 599.98px) ------------------------------------------------ */

@media (max-width: 599.98px) {
  .fdm-gallery {
    --fdm-gallery-columns: 1;
    --fdm-gallery-row-gap: var(--fdm-space-26);
  }

  /* Title, intro, search and chips are one stack with 12px gaps. */
  .fdm-gallery__head {
    --fdm-page-head-pb-phone: var(--fdm-space-12);
  }

  .fdm-gallery__lead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .fdm-gallery__lead-short {
    display: block;
  }

  .fdm-gallery__toolbar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: var(--fdm-space-12);
    padding-bottom: var(--fdm-space-20);
  }

  .fdm-gallery__search {
    flex: none;
    min-width: 0;
    max-width: none;
  }

  /* One row of chips, as drawn. The row runs to the screen edge and scrolls
     sideways, so a cut-off chip shows there are more. */
  .fdm-gallery__chips {
    flex: none;
    flex-wrap: nowrap;
    align-items: flex-start;
    margin: calc(-1 * var(--fdm-gallery-focus-room)) calc(-1 * var(--fdm-gutter));
    padding: var(--fdm-gallery-focus-room) var(--fdm-gutter);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .fdm-gallery__chips::-webkit-scrollbar {
    display: none;
  }

  .fdm-gallery__chips .fdm-chip {
    flex: none;
  }

  /* Not drawn on the phone frame; still read out when the list changes. */
  .fdm-gallery__count {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .fdm-gallery__item--landscape {
    grid-column: auto;
  }

  .fdm-gallery__grid {
    margin-bottom: 0;
  }

  .fdm-gallery__tile {
    gap: var(--fdm-space-8);
  }

  .fdm-gallery__caption {
    gap: var(--fdm-space-2);
  }

  /* Year 11/120%, title 17/130% */
  .fdm-gallery__year {
    font-size: var(--fdm-fs-11);
    line-height: var(--fdm-gallery-lh-year-phone);
  }

  .fdm-gallery__title {
    font-size: var(--fdm-fs-17);
    line-height: var(--fdm-gallery-lh-title-phone);
  }

  .fdm-gallery__body {
    padding-bottom: var(--fdm-space-36);
  }

  .fdm-gallery__more {
    padding-top: var(--fdm-space-28);
  }

  /* Without JavaScript the title block ends the head: give the grid the room
     the hidden toolbar would have left. */
  html:not(.fdm-js) .fdm-gallery__head {
    --fdm-page-head-pb-phone: var(--fdm-space-20);
  }
}
