/* Matches the Luz share mockups: light-grey field, top-left signature bar,
   responsive portrait grid. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #1c1c1e;
  --muted: #8a8a8e;
  --tile: #e2e2e2;
  --ring: rgba(0, 0, 0, 0.18);
  /* Filename caption — its own token (darker than --muted) so it meets WCAG AA
     4.5:1 against each backdrop; the caption is content, not chrome. */
  --caption: #6e6e6e;
}

/* Backdrop choices (set on <html data-bg> by the switcher). Text colors flip
   so the signature stays readable on any shade. Light = white (the default). */
/* --tile drives the loading skeleton; on the grey field it's set LIGHTER than the
   backdrop (not darker) so the placeholder reads clearly instead of blending in. */
html[data-bg="grey"] { --bg: #cfcfcf; --ink: #1c1c1e; --muted: #6a6a6a; --tile: #e0e0e0; --ring: rgba(0, 0, 0, 0.24); --caption: #505050; color-scheme: light; }
html[data-bg="dark"] { --bg: #1c1c1e; --ink: #f2f2f2; --muted: #8a8a8e; --tile: #2c2c2e; --ring: rgba(255, 255, 255, 0.28); --caption: #a6a6aa; color-scheme: dark; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.4 Helvetica, Arial, sans-serif;
}

/* The content area fills at least one full screen so the footer sits just below
   the fold — out of the way until you scroll down, never floating mid-page on a
   short collection and never pinned always-visible. */
#app { min-height: 100vh; padding: 28px 32px 48px; }

/* Header bar: signature left (intro + Save), "Sent by name" right. */
.bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}
.sig { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.intro { font-size: 20px; color: var(--ink); }
.expires { font-size: 12px; color: var(--muted); }
.save {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: rgba(127, 127, 127, 0.22);
  border: none;
  border-radius: 999px;
  padding: 4px 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.save:hover { background: var(--ink); color: var(--bg); }

.from { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.label { font-size: 12px; color: var(--muted); }
.name { font-size: 12px; color: var(--ink); }

/* Responsive grid. Each cell is a FIXED 4:3 PORTRAIT box (taller than wide —
   portrait is the dominant photo ratio) so the rows always line up. The image
   inside is NOT forced to the box shape: it's sized to its OWN true ratio (capped
   to fit), and the [image + caption] stack is centered in the cell as one group.
   So the caption always hugs the image — a short landscape floats centered with
   even space above and below, instead of the caption pinning to the box bottom.
   No tile fill — the surround is transparent, so the chosen page backdrop shows
   through the space around every image. The grid sizer sets a target TILE SIZE
   (--tile-min, computed in share.js from the chosen column density at the
   current width); auto-fill then reflows the column count responsively around
   it as the window resizes. min(…, 100%) prevents overflow on narrow screens. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--tile-min, 200px), 100%), 1fr));
  /* More space between rows than columns so mixed-height images read as
     separate rows rather than blurring together vertically. */
  gap: 40px 20px;
}
/* Each grid cell is a <button> (keyboard-operable; opens the lightbox): a 4:3
   portrait image box with an optional filename caption under it. Chrome reset. */
.tile {
  margin: 0;
  padding: 0;
  position: relative;   /* anchors the loading skeleton (.tile::before) */
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  width: 100%;
  /* Fixed 4:3 portrait cell — uniform across the grid so rows align. The image +
     caption stack is centered inside it as one group (see .tile img). */
  aspect-ratio: 3 / 4;
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.tile:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 3px;
}
.tile img {
  /* Sized to the image's OWN ratio (no forced aspect-ratio), capped to the cell.
     max-height reserves room for up to a 2-line caption (11px × 1.3 × 2 + the 6px
     gap ≈ 35px) so the centered group never overflows the fixed cell. The element
     box ends up matching the rendered picture, so the caption hugs it. */
  max-width: 100%;
  max-height: calc(100% - 36px);
  object-fit: contain;
  flex: 0 0 auto;
  display: block;
  /* Fade in once loaded (the .loaded class is added in share.js on img load),
     so the thumbnail dissolves over its skeleton instead of popping in. */
  opacity: 0;
  transition: opacity 0.3s ease, filter 0.18s ease;
  /* Casual-download deterrents (see the "Image-download deterrents" note in
     share.js): block drag-to-desktop and text/image selection. This raises the
     bar for people who'd only ever right-click-save or drag; it CANNOT stop a
     determined recipient — the Drive thumbnail URL is reachable directly and the
     original is anyone-readable on Drive by design. */
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}
.tile.loaded img { opacity: 1; }
/* Hover state — a subtle darkening tint over the image signals it's clickable
   (opens the lightbox). Only once loaded, so it never touches the skeleton. */
.tile.loaded:hover img { filter: brightness(0.9); }
.tile-name {
  font-size: 11px;
  line-height: 1.3;
  color: var(--caption);     /* AA-contrast token (see :root) */
  text-align: center;
  overflow-wrap: anywhere;   /* show the full name; wrap long ones rather than clip */
  unicode-bidi: isolate;     /* contain any residual directional chars (defense-in-depth) */
  flex: 0 0 auto;
  /* Bound long filenames to 2 lines so the image's max-height reserve holds (the
     full name still shows in the lightbox + the button's accessible name). */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* Loading skeleton: a shimmering placeholder over the image region of each cell
   (the caption area below — the bottom 36px the image reserves — is left clear,
   since the filename is already known and shows immediately). Drive thumbnails
   can take a moment, so without this the grid sits empty then pops. Uses the
   backdrop-aware --tile token as the base with a soft highlight sweeping across.
   Removed the instant the image paints (.loaded, set in share.js). The image
   fades in on top (see .tile img), so they cross-dissolve. */
.tile::before {
  content: "";
  position: absolute;
  inset: 0 0 36px 0;
  border-radius: 4px;
  background-color: var(--tile);
  background-image: linear-gradient(100deg,
    transparent 30%, rgba(255, 255, 255, 0.28) 50%, transparent 70%);
  background-size: 200% 100%;
  background-repeat: no-repeat;
  animation: tile-shimmer 1.4s linear infinite;
}
.tile.loaded::before { display: none; }
@keyframes tile-shimmer {
  from { background-position: 150% 0; }
  to   { background-position: -150% 0; }
}
/* Reduced motion: keep a static placeholder tint, no sweep. */
@media (prefers-reduced-motion: reduce) {
  .tile::before { background-image: none; animation: none; }
  .tile img { transition: none; }
}

/* ------------------------------------------------ Layouts (Spec 07)
   Three page layouts off ONE `data-layout` attribute on #app. There is a single
   tile-builder DOM path in share.js — everything below is presentation only, so
   captions, the lightbox, the download deterrents and the print flow are shared
   by every layout. `grid` is the pre-Spec-07 rendering and is what a legacy link
   (no `y` key) resolves to, so those pages are unchanged.

   The optional intro paragraph (manifest `s`) sits above the grid in every
   layout and collapses when empty. */
.body {
  max-width: 860px;
  margin: 0 auto 28px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--caption);
  unicode-bidi: isolate;
  overflow-wrap: anywhere;
}
.body:empty { display: none; }

/* Contact sheet — denser, square cells, filename always visible, frame numbers
   in the corner (the physical contact-sheet convention). */
#app[data-layout="sheet"] .grid {
  gap: 16px 8px;
  counter-reset: frame;
}
#app[data-layout="sheet"] .tile {
  aspect-ratio: 1;
  counter-increment: frame;
}
#app[data-layout="sheet"] .tile::after {
  content: counter(frame, decimal-leading-zero);
  position: absolute;
  top: 4px;
  left: 4px;
  font: 10px/1.2 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--caption);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  padding: 1px 4px;
  border-radius: 3px;
  pointer-events: none;
}
#app[data-layout="sheet"] .tile-name {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  -webkit-line-clamp: 1;
  line-clamp: 1;
}
@media print {
  #app[data-layout="sheet"] .tile { width: 15.5%; }
  #app[data-layout="sheet"] .tile:nth-child(3n-1) { margin-left: 0; margin-right: 0; }
}

/* Essay — one centered column at the image's natural aspect, generous rhythm,
   no density control (the sizer is hidden here and skipped in share.js). */
#app[data-layout="essay"] .grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 860px;
  margin: 0 auto;
  gap: 56px;
}
#app[data-layout="essay"] .tile {
  aspect-ratio: auto;
  width: 100%;
  overflow: visible;
}
#app[data-layout="essay"] .tile img {
  max-height: none;
  width: 100%;
}
#app[data-layout="essay"] .tile::before { inset: 0; padding-bottom: 66%; }
#app[data-layout="essay"] .tile-name {
  font-size: 12px;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}
#app[data-layout="essay"] .grid-sizer { display: none !important; }
@media print {
  #app[data-layout="essay"] .grid { display: block; }
  #app[data-layout="essay"] .tile { width: 100%; margin: 0 0 24px; }
}

/* Editorial — a repeating five-frame photographic phrase: normal-left with a
   small-right counterpoint, then the inverse, then one normal centred frame. */
#app[data-layout="stack"] .grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: center;
  width: 100%;
  max-width: none;
  margin: 0;
  column-gap: 0;
  row-gap: clamp(76px, 10vw, 152px);
}
#app[data-layout="stack"] .tile {
  aspect-ratio: auto;
  width: 100%;
  grid-row: var(--editorial-row);
  overflow: visible;
  justify-content: flex-start;
  gap: 9px;
}
/* Give the shimmer a real canvas before the image reports its natural size;
   once loaded, the photograph itself owns the height. */
#app[data-layout="stack"] .tile:not(.loaded) {
  min-height: clamp(240px, 48vw, 620px);
}
#app[data-layout="stack"] .tile img {
  width: 100%;
  max-height: none;
  object-fit: contain;
}
#app[data-layout="stack"] .tile::before { inset: 0; }
#app[data-layout="stack"] .tile-name {
  align-self: stretch;
  text-align: center;
  font-size: 11px;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* Seven tracks = the shared normal width; four tracks = the shared small
   width. One empty track between paired frames creates real negative space
   rather than an arbitrary margin. Outside frames touch the gallery edges. */
#app[data-layout="stack"] .tile:nth-child(5n + 1) {
  grid-column: 1 / 8;
  justify-self: start;
}
#app[data-layout="stack"] .tile:nth-child(5n + 2) {
  grid-column: 9 / 13;
  justify-self: end;
}
#app[data-layout="stack"] .tile:nth-child(5n + 3) {
  grid-column: 1 / 5;
  justify-self: start;
}
#app[data-layout="stack"] .tile:nth-child(5n + 4) {
  grid-column: 6 / 13;
  justify-self: end;
}
#app[data-layout="stack"] .tile:nth-child(5n + 5) {
  grid-column: 4 / 11;
  justify-self: center;
}
/* Small counterpoints are already reduced. Only tall normal/centre frames need
   the additional portrait reduction, anchored to their assigned edge. */
#app[data-layout="stack"] .tile.tile--tall:nth-child(5n + 1),
#app[data-layout="stack"] .tile.tile--tall:nth-child(5n + 4),
#app[data-layout="stack"] .tile.tile--tall:nth-child(5n + 5) { width: 78%; }
#app[data-layout="stack"] .grid-sizer { display: none !important; }

@media (max-width: 700px) {
  #app[data-layout="stack"] .grid {
    row-gap: clamp(58px, 16vw, 92px);
  }
  /* Paired desktop frames wrap into their own rows on narrow screens. The
     smaller counterpoints grow to 75% of the gallery, so they still read as a
     deliberate scale change without becoming thumbnail-sized. */
  #app[data-layout="stack"] .tile { grid-row: auto; }
  #app[data-layout="stack"] .tile:nth-child(5n + 1) { grid-column: 1 / 11; }
  #app[data-layout="stack"] .tile:nth-child(5n + 2) { grid-column: 4 / 13; }
  #app[data-layout="stack"] .tile:nth-child(5n + 3) { grid-column: 1 / 10; }
  #app[data-layout="stack"] .tile:nth-child(5n + 4) { grid-column: 3 / 13; }
  #app[data-layout="stack"] .tile:nth-child(5n + 5) { grid-column: 2 / 12; }
}

@media print {
  #app[data-layout="stack"] .grid { display: block; max-width: none; }
  #app[data-layout="stack"] .tile,
  #app[data-layout="stack"] .tile:nth-child(n),
  #app[data-layout="stack"] .tile.tile--tall {
    grid-row: auto;
    grid-column: auto;
    width: 100%;
    margin: 0 0 24px;
  }
}

/* State machine: show only what matches data-state. */
.notice {
  display: none;
  margin-top: 64px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
#app[data-state="live"] .notice { display: none; }
#app[data-state="expired"] .grid,
#app[data-state="expired"] .save { display: none; }
#app[data-state="expired"] .notice-expired { display: block; }
#app[data-state="unavailable"] .bar,
#app[data-state="unavailable"] .grid { display: none; }
#app[data-state="unavailable"] .notice-unavailable { display: block; }
#app[data-state="loading"] .notice { display: none; }

/* Backdrop switcher — sits centered in the header (scrolls with the page, never
   covers images). Each dot is filled with the shade it sets. Live state only. */
.bg-switcher {
  display: none;
  align-self: center;
  gap: 8px;
}
#app[data-state="live"] .bg-switcher { display: flex; }
.bg-switcher .dot {
  width: 13px; height: 13px; padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(127, 127, 127, 0.5);
  cursor: pointer;
  outline: 1px solid transparent; outline-offset: 2px;
  transition: outline-color 0.12s ease, transform 0.12s ease;
}
.bg-switcher .dot:hover { transform: scale(1.12); }
.bg-switcher .dot[data-bg="light"] { background: #ffffff; }
.bg-switcher .dot[data-bg="grey"]  { background: #cfcfcf; }
.bg-switcher .dot[data-bg="dark"]  { background: #1c1c1e; }
.bg-switcher .dot[aria-pressed="true"] { outline-color: var(--ink); }
/* Visible keyboard focus (the transparent base outline otherwise hides the UA
   ring). A 2px ring reads distinctly from the 1px pressed outline. */
.bg-switcher .dot:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Layout switcher — deliberately quiet text tabs. No pill, icon, or raised
   selected state competing with the photographs. */
.layout-switcher {
  display: none;
  align-items: center;
  gap: 16px;
  user-select: none;
  -webkit-user-select: none;
}
#app[data-state="live"] .layout-switcher { display: flex; }
.layout-switcher button {
  min-height: 24px;
  padding: 2px 0 5px;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font: 500 11px/1 Helvetica, Arial, sans-serif;
  cursor: pointer;
}
.layout-switcher button:hover { color: var(--ink); }
.layout-switcher button[aria-pressed="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.layout-switcher button:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }

/* Grid sizer — floats bottom-right (live state only, like the app's resizer).
   Sets the column count (1–6, default 4); the choice persists. Floats
   bottom-center, always visible while live. `bottom` is tuned so that when the
   page is scrolled to the end, the pill lines up with the legal row's text line
   (expires / Privacy · Terms). Hidden in print and on expired/unavailable. */
.grid-sizer {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 33px;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#app[data-state="live"] .grid-sizer { display: flex; }
.grid-sizer-label { font-size: 11px; color: var(--muted); }
/* The sizer is chrome, not content — never let a drag/double-click select the
   "Grid" label or slider parts. */
.grid-sizer { user-select: none; -webkit-user-select: none; }

/* While the grid sizer is being dragged (class set on <html> in share.js),
   suppress page-wide selection so the drag doesn't rubber-band a text/image
   selection across the grid. Active only for the duration of the drag, so it
   changes no normal interaction. */
html.sizer-dragging, html.sizer-dragging * {
  user-select: none;
  -webkit-user-select: none;
}

/* shadcn-style slider (custom div — native range won't click-to-jump in Safari).
   A 6px rounded muted track with an --ink fill, and a 15px white thumb with an
   --ink border + soft shadow that gains a focus/hover ring. --range-pct (set in
   share.js) positions both the fill width and the thumb. */
.slider {
  position: relative;
  width: 108px;
  height: 16px;
  /* Horizontal padding leaves room for the thumb's overhang at each end, so at
     the far-left value it doesn't collide with the "Grid" label. */
  padding: 0 8px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  outline: none;
}
.slider-track {
  position: relative;
  height: 4px;
  width: 100%;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.30);
}
.slider-range {
  position: absolute;
  left: 0;
  height: 100%;
  width: var(--range-pct, 50%);
  border-radius: 999px;
  background: var(--ink);
  transition: width 0.12s ease;
}
/* Thumb lives inside the track so its position maps to the track, not the
   padded outer box. */
.slider-thumb {
  position: absolute;
  left: var(--range-pct, 50%);
  top: 50%;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.25px solid var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transform: translate(-50%, -50%);
  transition: left 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}
.slider:hover .slider-thumb,
.slider:focus-visible .slider-thumb {
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: 0 0 0 4px var(--ring);
}

/* While dragging, the thumb tracks the pointer 1:1 (no transition lag, no hard
   stops); on release it glides to the snapped position via the base transition.
   The grid tiles morph their resize via inline transform transitions set in JS
   (FLIP). Reduced-motion disables the slider glide (and the FLIP is JS-guarded). */
.slider.dragging .slider-thumb,
.slider.dragging .slider-range { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .slider-thumb, .slider-range { transition: none; }
}

/* Click-to-enlarge lightbox. The overlay blurs only the viewport behind it
   (backdrop-filter), so its cost is bounded regardless of page length. The
   enlarged image reuses the already-loaded thumbnail — no new request. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6vh 6vw;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: lb-fade 0.16s ease;
}
.lightbox[hidden] { display: none; }
.lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  animation: lb-in 0.18s ease;
}
.lightbox-img {
  max-width: 100%;
  max-height: 82vh;   /* leave room under the image for the filename caption */
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
  /* Same casual-download deterrents as the grid thumbnails (see share.js). */
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}
.lightbox-name {
  max-width: 100%;
  font-size: 12px;
  /* Opaque white over the dark scrim (rgba(0,0,0,0.35) + blur) that always sits
     behind the lightbox — legible on any backdrop the viewer picked. */
  color: #fff;
  text-align: center;
  overflow-wrap: anywhere;
  unicode-bidi: isolate;
}
.lightbox-name:empty { display: none; }
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 38px;
  height: 38px;
  color: #fff;
  outline: none;
  background: rgba(127, 127, 127, 0.32);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.12s ease;
}
.lightbox-close:hover { background: rgba(127, 127, 127, 0.55); }
/* Visible keyboard focus (base sets outline:none). White ring reads on the scrim. */
.lightbox-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lb-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox-figure { animation: none; }
}

/* Bottom bar — expires on the left, legal links on the right. Below the fold. */
.legal {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px 16px;
  margin: 24px 32px 40px;
  font-size: 12px;
  color: var(--muted);
}
.legal a { color: var(--muted); text-decoration: none; }
.legal a:hover { color: var(--ink); text-decoration: underline; }
.legal .sep { margin: 0 8px; }

@media (max-width: 600px) {
  .bar { flex-direction: column; gap: 12px; }
  .intro { font-size: 17px; }
  .layout-switcher button { min-height: 28px; }
}

/* Print = the PDF. A clean reflection of the page: the signature line, then
   the images grid. The recipient's print dialog picks the paper size and
   Save-as-PDF. Interactive chrome (Save button, expiry) is hidden. */
@media print {
  @page { margin: 0.5in; }
  /* Always print on white with dark text — never inherit the chosen screen
     backdrop (a dark backdrop would make the title white-on-white in the PDF).
     !important so this beats the higher-specificity html[data-bg="dark"] rule. */
  html { --bg: #fff !important; --ink: #1c1c1e !important; --muted: #6a6a6a !important; --tile: #e2e2e2 !important; --caption: #5a5a5a !important; }
  html, body { background: #fff; }
  #app { padding: 0; min-height: 0; }
  .save, .expires, .bg-switcher, .layout-switcher, .grid-sizer, .legal, .lightbox { display: none !important; }
  .bar { margin-bottom: 18px; }
  .intro, .name { font-size: 14px; }
  .label { font-size: 10px; }
  /* Lay the printed grid out as atomic inline-flex tiles in plain block flow
     instead of CSS grid. CSS-grid items fragment unreliably — Chrome/Safari can
     slice an image across a page break even with break-inside:avoid. An
     inline-flex box is an *atomic* inline-level box the print engine never
     splits, so a tile that won't fit drops whole to the next page (its row line
     moves with it) and images are never cut. Screen layout (the real .grid) is
     untouched — this is @media print only. 3 columns: 32% each + 2% gutters on
     the middle column = 100%. (The DOM has no whitespace between tiles, so
     inline-block spacing gaps don't apply.) */
  .grid {
    display: block;
    gap: 0;
  }
  .tile {
    display: inline-flex;       /* atomic → unbreakable across pages */
    vertical-align: top;
    width: 32%;
    margin: 0 0 14px;
    break-inside: avoid;        /* belt-and-suspenders; the atomic box already won't split */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .tile:nth-child(3n-1) { margin-left: 2%; margin-right: 2%; }
  /* No loading shimmer in the printed PDF, and never hold an image at opacity 0
     if it somehow prints before its load event fired. */
  .tile::before { display: none !important; }
  .tile img { opacity: 1 !important; }
}
