/* ==========================================================================
   Gallery — ported from the Prestige Gallery reference screen.

   The reference kept layout inline on elements; it lives here as classes so it
   can be re-laid-out at breakpoints. Values come from prestige-tokens.css.

   The before/after slider's own parts (.data-compare="*") are styled here too:
   the behaviour is shared in site.js, but the tile geometry is the gallery's
   own (16:10, two-up) and differs from the home page's 1137:569 single tile.
   ========================================================================== */

/* --- Banner -------------------------------------------------------------- */

/* Photo under a flat 0.66 wash — above the 0.62 floor, and the measurement the
 * reference shipped. The header renders above this section, so the banner
 * starts under it and pulls back up by the measured header height. */
[data-g="banner"] {
  /* The header is fixed and out of flow, so only the padding is needed to
     start the content below it — no negative margin to cancel. */
  padding-top: var(--pr-header-height, 0px);
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.62)),
    var(--pr-banner-image);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

/* The lede is a WYSIWYG region, so it is .pr-prose; the banner's own measure
 * and colour still apply to the paragraphs inside it. */
[data-g="lede"] { max-width: 760px; }
[data-g="lede"] p {
  font-size: var(--body);
  line-height: var(--leading-body);
  color: var(--paper);
  text-wrap: pretty;
}
[data-g="lede"] p + p { margin-top: var(--leading-body); }
[data-g="lede"] a { color: var(--paper); text-decoration: underline; }

/* --- Shared section furniture -------------------------------------------- */

[data-g="sectiontitle"] {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--display-md);
  line-height: var(--leading-display);
  text-transform: uppercase;
  color: var(--ink);
  /* No negative top margin: this title follows a .pr-lockup__eyebrow, which now
     owns the gap. Keeping it here would pull twice. */
  margin-top: 0;
}

/* --- Before + after ------------------------------------------------------ */

[data-g="compare-section"] {
  padding-top: var(--section-pad);
  padding-right: var(--gutter-page);
  padding-left: var(--gutter-page);
  background: var(--paper);
}

[data-g="bagrid"] {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(24px, 2.4vw, 44px);
  margin-top: clamp(28px, 2.8vw, 52px);
}

[data-g="pair"] {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
}

[data-g="compare"] {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  touch-action: none;
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: var(--shadow-peek);
}

/* Slider parts. Markup contract is site.js's — this is geometry only. */
[data-g="compare"] [data-compare="before"] {
  width: 100%;
  aspect-ratio: 16 / 10;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: var(--surface);
}

[data-g="compare"] [data-compare="after"] {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: var(--surface);
  clip-path: inset(0 0 0 50%);
}

[data-g="compare"] [data-compare="line"] {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(-1px);
}

[data-g="compare"] [data-compare="handle"] {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  cursor: ew-resize;
}

[data-g="compare"] [data-compare="arrow-l"],
[data-g="compare"] [data-compare="arrow-r"] {
  display: block;
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
}
[data-g="compare"] [data-compare="arrow-l"] {
  border-left: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
[data-g="compare"] [data-compare="arrow-r"] {
  border-right: 2px solid var(--ink);
  border-top: 2px solid var(--ink);
}

/* Two lines: the project as the title in the display face, then the room in
   small plain copy under it. The bigger line is the heading, so it is clear
   which is which (BugHerd #96, #98). */
[data-g="paircap"] {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

[data-g="pairtitle"] {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--card-title);
  line-height: 1.15;
  color: var(--ink);
  text-wrap: balance;
}

[data-g="paircat"] {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  color: var(--muted);
}

/* --- Project gallery ----------------------------------------------------- */

[data-g="grid-section"] {
  padding-top: var(--section-pad);
  padding-right: var(--gutter-page);
  padding-bottom: var(--section-pad);
  padding-left: var(--gutter-page);
  background: var(--paper);
}

[data-g="grid-section"] .pr-sectionhead {
  margin-bottom: clamp(24px, 2.4vw, 42px);
}

/* One row at desktop widths (BugHerd #97): the chips are tightened here
   rather than in .pr-chip, which other pages share. They still wrap if a
   narrower screen needs it. */
[data-g="filters"] {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
[data-g="filters"] .pr-chip { padding: 0 clamp(12px, 0.94vw, 18px); font-size: 14px; letter-spacing: .04em; }

/* The select is the mobile form of the same control. Both are in the markup;
 * only the media query decides which one shows. */
[data-g="filterselect"] {
  display: none;
  flex-direction: column;
  gap: 9px;
}

[data-g="selectlabel"] {
  font-family: var(--font-cta);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
}

/*
 * The room filter is a .pr-field now, so its box, border and dropdown chevron
 * come from prestige-components.css — the same control as the blog's category
 * select. This block used to restate those values by hand, which is why it kept
 * the browser's native arrow when the shared select got the design's one.
 *
 * Nothing local is needed; the class covers it.
 */

[data-g="results"] { margin-top: clamp(18px, 1.6vw, 26px); }
[data-g="empty"] { margin-top: clamp(18px, 1.6vw, 26px); }

/* Filtering fades the grid out and the new set in (BugHerd #159). gallery.js
   sets data-g-fading on the click and clears it after the swap. */
[data-g="grid"] { transition: opacity .25s ease; }
[data-g="grid"][data-g-fading] { opacity: 0; }

[data-g="grid"] {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(16px, 1.6vw, 28px);
  margin-top: clamp(14px, 1.4vw, 22px);
}

[data-g="tile"] {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  aspect-ratio: 4 / 3;
  padding: clamp(16px, 1.4vw, 24px);
  border: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-peek);
  transition: box-shadow .3s ease;
}
[data-g="tile"]:hover,
[data-g="tile"]:focus-visible { box-shadow: var(--shadow-feature); }

/* Decorative photograph layer — not content, so absolute is allowed here.
 * It is a real <img> (srcset) cropped with object-fit, not a background. */
[data-g="shot"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform .55s cubic-bezier(.22, .61, .36, 1);
}
[data-g="tile"]:hover [data-g="shot"],
[data-g="tile"]:focus-visible [data-g="shot"] { transform: scale(1.06); }

/* Scrim over the photograph: only on hover now, under the + ring, as the
   tile carries no caption. */
[data-g="scrim"] {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.55) 100%);
  opacity: 0;
  transition: opacity .3s ease;
}
[data-g="tile"]:hover [data-g="scrim"],
[data-g="tile"]:focus-visible [data-g="scrim"] { opacity: 1; }

[data-g="tilebody"] {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 14px;
  width: 100%;
}

[data-g="plus"] {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  color: var(--paper);
  font-size: 22px;
  line-height: 1;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .3s ease, transform .3s ease;
}
[data-g="tile"]:hover [data-g="plus"],
[data-g="tile"]:focus-visible [data-g="plus"] {
  opacity: 1;
  transform: translateY(0);
}
/* Touch: no ring. With no caption band under it a white ring is lost on a
   light photo, and a photo in a gallery reads as tappable on its own. */
@media (hover: none) {
  [data-g="plus"] { display: none; }
}

/* --- Lightbox ------------------------------------------------------------ */

[data-g="lightbox"] {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 1.4vw, 22px);
  padding: clamp(16px, 2vw, 40px);
  background: rgba(0, 0, 0, 0.92);
}
[data-g="lightbox"] :focus-visible { outline-color: var(--paper); }

[data-g="lbbar"] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
[data-g="counter"] { color: var(--surface); }

[data-g="lbclose"],
[data-g="lbprev"],
[data-g="lbnext"] {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: transparent;
  color: var(--paper);
  cursor: pointer;
}
[data-g="lbclose"]:hover,
[data-g="lbprev"]:hover,
[data-g="lbnext"]:hover { background: rgba(255, 255, 255, 0.14); }

[data-g="lbclose"] {
  width: 44px;
  height: 44px;
  font-size: 22px;
  line-height: 1;
}
[data-g="lbprev"],
[data-g="lbnext"] { width: 52px; height: 52px; }

[data-g="arrowprev"],
[data-g="arrownext"] {
  display: block;
  width: 10px;
  height: 10px;
}
[data-g="arrowprev"] {
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(2px, -2px);
}
[data-g="arrownext"] {
  border-right: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, 2px);
}

/*
 * The arrows line up with the IMAGE, not the figure.
 *
 * align-items: center centred each child on the stage, and the figure is a
 * column holding the photograph AND its caption — so its midpoint sits below
 * the photograph's. Measured 31px out at 430px wide, which is what makes the
 * arrows look dropped beside the image as the screen shrinks.
 *
 * The figure stretches instead, and the arrows are pinned to the top by the
 * image's own height, so the two agree at any image size.
 */
[data-g="lbstage"] {
  /* 1 1 auto made the row fill the modal's leftover height — 667px against a
     530px image — so anything centred in the row sat below the photograph's
     middle. The row now hugs its contents and is centred in the modal as a
     whole, which puts the arrows on the image's centre at every size. */
  flex: 0 1 auto;
  margin-block: auto;
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.4vw, 24px);
  min-height: 0;
}

/*
 * The caption is centred UNDER the image without adding to the row's height.
 *
 * The figure is the flex item the arrows align against, and it is a column of
 * image + caption — so its centre sits below the image's by half the caption,
 * measured at a consistent 31px. Taking the caption out of flow leaves the
 * figure exactly as tall as the photograph, which is what the arrows should
 * align to. The figure keeps room for it via padding-bottom so the caption
 * never overlaps whatever follows.
 */
[data-g="lbfigure"] {
  position: relative;
  /*
   * NO padding-bottom to reserve the caption's space.
   *
   * That was the whole point: padding puts the caption's height back into the
   * figure, which is the box the arrows align against — the figure measured
   * 591px against a 530px image and the arrows stayed 30px low. The stage is
   * centred in the modal with room to spare below, so the absolutely
   * positioned caption has somewhere to sit without reserving it here.
   */
}

[data-g="lbfigure"] figcaption {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: clamp(12px, 1.2vw, 20px);
}

[data-g="lbprev"],
[data-g="lbnext"] {
  /*
   * Centred on the IMAGE, not the figure.
   *
   * The figure is a column holding the photograph AND its caption, so centring
   * the arrows on the figure puts them below the photograph's middle — 31px
   * out, measured.
   *
   * No arithmetic: an earlier attempt offset them by half of
   * `min(70vh, 720px)`, which is only the image's height when height is what
   * constrains it. On a narrow screen the image is limited by WIDTH instead and
   * is shorter than that, so the arrows overshot by 45px. Aligning to the top
   * of the stage and letting the image's own line box set the centre works at
   * every size, because the stage is only as tall as its contents.
   */
  align-self: center;
}



[data-g="lbfigure"] {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* flex-start, not center: with the stage stretched the figure would grow to
     the full stage height and centre its contents inside it, so where the
     image begins depended on the leftover space. Hugging the top makes the
     image's position predictable, which is what the arrows' offset assumes. */
  justify-content: flex-start;
  gap: clamp(12px, 1.2vw, 20px);
  min-width: 0;
  min-height: 0;
  margin: 0;
}

/* Explicit height — the photograph is a background on a box in normal flow, so
 * it needs one or it collapses. */
[data-g="lbimage"] {
  width: 100%;
  max-width: 1280px;
  height: min(70vh, 720px);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  border-radius: var(--radius-sm);
}

[data-g="lbcap"] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
}

[data-g="lbtitle"] {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(22px, 2vw, 36px);
  line-height: 1.1;
  color: var(--paper);
}
[data-g="lbcat"] { color: var(--surface); }

/* --- Breakpoints --------------------------------------------------------- */

@media (max-width: 1199px) {
  [data-g="grid"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 991px) {
  /* Standing rule: titles and copy centre at tablet and below. */
  [data-g="lede"] { margin-left: auto; margin-right: auto; text-align: center; }
  [data-g="filters"] { justify-content: center; }
  [data-g="selectlabel"] { text-align: center; } /* BugHerd #157 */
  [data-g="results"],
  [data-g="empty"] { text-align: center; }
  [data-g="bagrid"] { grid-template-columns: minmax(0, 1fr); }
  [data-g="paircap"] { align-items: center; text-align: center; }
}

@media (max-width: 767px) {
  /* The chips become a select. Both are in the markup — nothing re-renders. */
  [data-g="filters"] { display: none; }
  [data-g="filterselect"] { display: flex; }
  [data-g="compare"] [data-compare="handle"] { width: 52px; height: 52px; }

  /* ---------------------------------------------------------------------
   * Arrows BELOW the photograph, so it gets the modal's full width.
   *
   * Beside the image the two 52px buttons plus their gaps took ~124px of a
   * 375px screen — a third of it — and the photograph shrank to fit what was
   * left. Below, it can use the lot.
   *
   * Source order is prev, figure, next; `order` puts the figure first without
   * touching the markup, so the tab order still runs prev → next and a screen
   * reader still meets them as a pair.
   * ------------------------------------------------------------------- */
  [data-g="lbstage"] {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  [data-g="lbfigure"] {
    order: -1;
    flex: 1 1 100%;
  }

  /* The caption returns to normal flow.
   *
   * Above this width it is absolutely positioned into the stage's spare room,
   * which keeps it out of the box the arrows align against. Once the arrows
   * wrap underneath, that room is where THEY are — an absolute caption would
   * sit on top of them. In flow it simply pushes them down, and a title that
   * wraps to two lines still works, which a reserved fixed height would not. */
  [data-g="lbfigure"] figcaption {
    position: static;
    margin-top: 12px;
  }

  [data-g="lbprev"],
  [data-g="lbnext"] {
    /* Not align-self: center — that centres each button on the wrapped row,
       which is only as tall as the button itself and reads as a jump on the
       first frame. */
    align-self: auto;
  }
}

@media (max-width: 575px) {
  [data-g="grid"] { grid-template-columns: minmax(0, 1fr); }
  [data-g="lbimage"] { height: min(58vh, 480px); }
}

/*
 * The resize cursor across the whole comparison widget.
 *
 * Setting it on the container alone was not enough, and neither was adding a
 * descendant selector: the handle is a <button role="slider">, and Safari keeps
 * NATIVE CONTROL styling on a button — including its own cursor — until
 * `appearance: none` is set. An author `cursor` at ordinary specificity does
 * not displace that, so the handle kept an arrow in Safari while Chrome (which
 * has no such native styling here) looked correct.
 *
 * So: reset the appearance on the handle, and mark every layer !important. The
 * !important is doing real work against a UA control style, not papering over
 * an author-order problem.
 */
[data-compare="root"],
[data-compare="root"] * {
  cursor: ew-resize !important;
}

[data-compare="handle"] {
  -webkit-appearance: none;
  appearance: none;
}

/* Dragging: keep the resize cursor even as the pointer leaves the widget, so it
   does not flicker back to an arrow mid-drag. */
[data-compare="root"][data-dragging="1"],
[data-compare="root"][data-dragging="1"] * {
  cursor: ew-resize !important;
}
