/* ==========================================================================
   PAPER — GALLERY: a pile of prints on the table, the quote, the lightbox
   Scoped to #gallery / .gal-*
   ========================================================================== */
.gal { overflow-x: clip; }
@supports not (overflow: clip) { .gal { overflow: hidden; } }
/* --gu = 1% of the pile's width. Container-query units where they exist; the same number worked out
   from the viewport where they don't (Safari < 16, Chrome < 105), so the collage never collapses. */
.gal-pile { width: min(100% - var(--pp-gutter) * 2, 1360px); margin-inline: auto; --gu: calc(min(100vw - var(--pp-gutter) * 2, 1360px) / 100); }
@supports (width: 1cqw) { .gal-pile { container-type: inline-size; --gu: 1cqw; } }
.gal-label { text-align: center; margin-bottom: clamp(18px, 2.4vw, 30px); }

/* ---------- desktop: everything is placed in cqw so the collage scales as one piece ---------- */
.gal-table { position: relative; height: calc(119 * var(--gu)); }
.gal-title { font-weight: 400; }
.gal-col { display: contents; }
.gal-word {
  position: absolute; z-index: 0; display: block; white-space: nowrap; will-change: transform;
  font-family: var(--pp-f-display); text-transform: uppercase; font-size: calc(21 * var(--gu)); line-height: .86; color: var(--pp-red);
}
.gal-word--on { left: 0; top: 0; }
.gal-word--off { right: 0; top: calc(66 * var(--gu)); color: transparent; -webkit-text-stroke: max(2px, calc(.28 * var(--gu))) var(--pp-red); }

.gal-print { position: absolute; z-index: 1; display: block; text-decoration: none; cursor: zoom-in; will-change: transform; -webkit-tap-highlight-color: transparent; }
.gal-print:hover, .gal-print:focus-visible { z-index: 5; }
.gal-photo { display: block; padding: calc(.85 * var(--gu)) calc(.85 * var(--gu)) calc(1 * var(--gu)); transition: rotate .5s var(--pp-ease), scale .5s var(--pp-ease), box-shadow .3s; }
.gal-photo.pp-photo--polaroid { padding-bottom: calc(3.7 * var(--gu)); }
.gal-photo > img { aspect-ratio: 4 / 5; }
.gal-cap { position: absolute; left: 0; right: 0; bottom: calc(.75 * var(--gu)); text-align: center; font-size: clamp(13px, calc(1.55 * var(--gu)), 21px); line-height: 1.2; }
.gal-photo .pp-tape { width: 46%; max-width: 132px; height: clamp(18px, calc(2.5 * var(--gu)), 34px); top: calc(clamp(18px, calc(2.5 * var(--gu)), 34px) * -.5); }
.gal-photo .pp-tape--tr { left: auto; right: -13%; top: 3%; width: 40%; }
.gal-photo .pp-tape--tl { left: -13%; top: 3%; width: 40%; }
.gal-print:hover .gal-photo, .gal-print:focus-visible .gal-photo { rotate: 0deg; scale: 1.035; box-shadow: var(--pp-shadow-3); }
.gal-print.is-lifted .gal-photo { visibility: hidden; }

/* on stage */
.gal-print--1 { left: calc(1 * var(--gu));    top: calc(14 * var(--gu));   width: calc(24 * var(--gu)); } .gal-print--1 .gal-photo { --r: -4deg; }
.gal-print--2 { left: calc(29.5 * var(--gu)); top: calc(15.5 * var(--gu)); width: calc(17 * var(--gu)); } .gal-print--2 .gal-photo { --r: 3deg; }
.gal-print--3 { left: calc(51 * var(--gu));   top: calc(13 * var(--gu));   width: calc(19 * var(--gu)); } .gal-print--3 .gal-photo { --r: -2.5deg; }
.gal-print--3 .gal-photo > img { aspect-ratio: 2 / 3; }
.gal-print--4 { left: calc(75.5 * var(--gu)); top: calc(2 * var(--gu));    width: calc(23 * var(--gu)); } .gal-print--4 .gal-photo { --r: 4deg; }
.gal-print--5 { left: calc(27 * var(--gu));   top: calc(39 * var(--gu));   width: calc(20 * var(--gu)); } .gal-print--5 .gal-photo { --r: -5deg; }
/* off stage */
.gal-print--6 { left: 0;       top: calc(60 * var(--gu));   width: calc(20 * var(--gu)); } .gal-print--6 .gal-photo { --r: 3deg; }
.gal-print--6 .gal-photo > img { object-position: center 18%; }
.gal-print--7 { left: calc(24 * var(--gu));   top: calc(81 * var(--gu));   width: calc(24 * var(--gu)); } .gal-print--7 .gal-photo { --r: -3deg; }
.gal-print--8 { left: calc(52 * var(--gu));   top: calc(83 * var(--gu));   width: calc(18 * var(--gu)); } .gal-print--8 .gal-photo { --r: 4deg; }
.gal-print--8 .gal-photo > img { aspect-ratio: 1; }
.gal-print--9 { left: calc(73 * var(--gu));   top: calc(80 * var(--gu));   width: calc(26 * var(--gu)); } .gal-print--9 .gal-photo { --r: -2deg; }

.gal-scribble { z-index: 0; left: calc(72 * var(--gu)); top: calc(38 * var(--gu)); width: calc(22 * var(--gu)); height: calc(22 * var(--gu)); opacity: .8; }

/* ---------- the quote ---------- */
.gal-quote { display: grid; grid-template-columns: minmax(0, 1fr) clamp(220px, 26vw, 340px); align-items: center; gap: clamp(32px, 6vw, 96px); margin-top: clamp(72px, 11vw, 170px); }
.gal-quote-text { position: relative; }
.gal-quote-sparks { left: -10px; top: -58px; }
.gal-quote-line { font-size: clamp(38px, 5.6vw, 88px); line-height: .98; max-width: 13.5em; }
.gal-quote-red { color: var(--pp-red); }
.gal-quote-by { display: flex; align-items: center; gap: 16px; margin-top: clamp(18px, 2.4vw, 30px); }
.gal-quote-by i { width: clamp(40px, 5vw, 72px); height: 4px; background: var(--pp-red); border-radius: 3px; rotate: -3deg; }
.gal-quote-by .pp-script { font-size: clamp(34px, 4vw, 54px); padding: .1em .1em .1em 0; }
.gal-quote-photo { --r: 3.5deg; }
.gal-quote-photo > img { aspect-ratio: 1; }

/* ---------- phones + tablets: a clean two-column staggered stack ---------- */
@media (max-width: 899px) {
  /* two real columns (a grid of two wrappers). CSS multi-column paints rotated prints in the wrong place in WebKit. */
  .gal-table { height: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: clamp(14px, calc(4 * var(--gu)), 28px); align-items: start; }
  .gal-title { grid-column: 1 / -1; margin-bottom: clamp(26px, calc(7 * var(--gu)), 48px); }
  .gal-col { display: block; min-width: 0; }
  .gal-col--off { padding-top: calc(7 * var(--gu)); }
  .gal-word { position: static; font-size: calc(24.5 * var(--gu)); line-height: .88; }
  .gal-word--off { text-align: right; -webkit-text-stroke-width: 2px; }
  .gal-print, .gal-print[class] { position: relative; left: auto; top: auto; width: auto; padding-top: 14px; margin-bottom: clamp(14px, calc(4 * var(--gu)), 28px); }
  .gal-photo { padding: 7px 7px 8px; box-shadow: var(--pp-shadow-1); }
  .gal-photo.pp-photo--polaroid { padding-bottom: 34px; }
  .gal-cap { bottom: 7px; font-size: 15px; }
  .gal-photo .pp-tape { height: 22px; top: -11px; width: 50%; }
  .gal-print .gal-photo { --r: -1.6deg; }
  .gal-print:nth-of-type(even) .gal-photo { --r: 1.4deg; }
  .gal-print:nth-of-type(3n) .gal-photo { --r: 2.2deg; }
  .gal-scribble { display: none; }

  .gal-quote { grid-template-columns: minmax(0, 1fr); justify-items: start; gap: 44px; }
  .gal-quote-line { font-size: clamp(36px, 10.4vw, 72px); }
  .gal-quote-photo { width: min(62vw, 300px); justify-self: center; }
}

/* ---------- lightbox: the photo picked up off the table ---------- */
html.gal-lock, html.gal-lock body { overflow: hidden; }
.gal-lb {
  /* the room the print may take; the bar, the tape and the notch are subtracted here */
  --lb-w: min(calc(100vw - 64px), 1040px);
  --lb-h: calc(100vh - 230px);
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 99990; display: grid; grid-template-rows: minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
  background: rgba(243,242,238,.965) url(../../images/paper/paper.webp) repeat; background-size: 420px 420px;
  opacity: 0; transition: opacity .3s ease; overscroll-behavior: contain; touch-action: manipulation;   /* pinch-zoom stays; s-gallery.js stops the page scrolling underneath */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
@supports (height: 100svh) { .gal-lb { --lb-h: calc(100svh - 230px); } }
.gal-lb.is-open { opacity: 1; }
.gal-lb-stage { min-height: 0; display: grid; place-items: center; padding: clamp(56px, 8vh, 84px) clamp(16px, 6vw, 96px) 10px; cursor: zoom-out; }
.gal-lb-print { width: fit-content; rotate: -1.4deg; padding: clamp(8px, 1.2vw, 14px); box-shadow: var(--pp-shadow-3); cursor: default; }
/* sized from the photo's own proportions (--ar, --nat set by JS) so the small preview and the large file occupy the same box */
.gal-lb-print > img { display: block; width: min(var(--lb-w), calc(var(--lb-h) * var(--ar, .8)), var(--nat, 1440px)); height: auto; aspect-ratio: var(--ar, .8); object-fit: contain; }
.gal-lb-bar { display: flex; align-items: center; justify-content: center; gap: clamp(14px, 3vw, 30px); padding: 14px 16px max(18px, env(safe-area-inset-bottom, 0px)); }
.gal-lb-meta { display: grid; justify-items: center; gap: 2px; min-width: 120px; text-align: center; }
.gal-lb-cap { font-size: 20px; min-height: 1.3em; }
.gal-lb-count { font-weight: 800; font-size: 12px; letter-spacing: .28em; color: var(--pp-ink); }
.gal-lb-btn {
  flex: none; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%;
  color: var(--pp-ink); background: var(--pp-paper-hi); border: 2px solid var(--pp-ink);
  transition: background .25s, color .25s, transform .35s var(--pp-ease);
}
@media (hover: hover) {
  .gal-lb-btn:hover { background: var(--pp-ink); color: #fff; transform: translateY(-2px); }
}
.gal-lb-btn:active { transform: scale(.94); }
.gal-lb-btn svg { width: 22px; height: 22px; }
.gal-lb-close { position: absolute; z-index: 2; top: calc(clamp(12px, 2vw, 24px) + env(safe-area-inset-top, 0px)); right: calc(clamp(12px, 2vw, 24px) + env(safe-area-inset-right, 0px)); }

/* phones + tablets, upright: every control sits in the thumb zone; close moves down next to the arrows */
@media (max-width: 899px) and (orientation: portrait) {
  .gal-lb { --lb-w: calc(100vw - 48px); --lb-h: calc(100vh - 176px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
  @supports (height: 100svh) { .gal-lb { --lb-h: calc(100svh - 176px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); } }
  .gal-lb-stage { padding: 30px 16px 6px; }
  .gal-lb-print { padding: 8px; }
  .gal-lb-bar { justify-content: space-between; gap: 10px; padding: 12px 16px max(18px, calc(env(safe-area-inset-bottom, 0px) + 8px)) 82px; }
  .gal-lb-meta { flex: 1; min-width: 0; }
  .gal-lb-cap { font-size: 18px; }
  .gal-lb-close { top: auto; right: auto; left: calc(16px + env(safe-area-inset-left, 0px)); bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 8px)); background: var(--pp-ink); color: #fff; }
}
/* phones on their side: the photo gets the full height, arrows wait at the edges where the thumbs are */
@media (max-height: 520px) and (orientation: landscape) {
  .gal-lb { --lb-w: calc(100vw - 200px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); --lb-h: calc(100vh - 84px); }
  @supports (height: 100svh) { .gal-lb { --lb-h: calc(100svh - 84px); } }
  .gal-lb-stage { padding: 22px 84px 2px; }
  .gal-lb-print { padding: 7px; }
  .gal-lb-bar { padding: 4px 16px max(8px, env(safe-area-inset-bottom, 0px)); }
  .gal-lb-meta { display: flex; align-items: baseline; gap: 12px; }
  .gal-lb-cap { font-size: 16px; min-height: 0; }
  .gal-lb-prev, .gal-lb-next { position: absolute; top: 50%; margin-top: -26px; }
  .gal-lb-prev { left: calc(16px + env(safe-area-inset-left, 0px)); }
  .gal-lb-next { right: calc(16px + env(safe-area-inset-right, 0px)); }
  .gal-lb-close { top: 12px; right: calc(16px + env(safe-area-inset-right, 0px)); }
}
