/* Gallery block (gl-): photo grid, strip, before and after, video, and the lightbox. Tokens only; phone breakpoint 720.
   One surface language across the layouts: the photo is the stage, 12 px corners, captions in muted small type beneath, no overlays. */
.gl { --gl-gap: clamp(10px, 1.6vw, 18px); --gl-cols: 3; --gl-r: var(--radius-sm); }
.gl[data-cols="2"] { --gl-cols: 2; }
.gl[data-cols="4"] { --gl-cols: 4; }
.gl[data-rounded="false"] { --gl-r: 0px; }
.gl-head { display: flex; flex-direction: column; gap: 12px; max-width: var(--w-prose); margin-bottom: 40px; }
.gl-head h2 { text-wrap: balance; }
.gl-empty { margin: 0; padding: 28px 20px; border: 1px dashed var(--field); border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; text-align: center; }

/* shared picture frame */
.gl-fig { margin: 0; }
.gl-media { display: block; position: relative; aspect-ratio: var(--gl-ar, 4 / 3); overflow: hidden; border-radius: var(--gl-r); background: var(--placeholder); }
.gl-img { width: 100%; height: 100%; object-fit: cover; background: var(--placeholder); }
.gl-ph { display: grid; place-items: center; text-align: center; padding: 12px; }
.gl-open { cursor: zoom-in; }
.gl-open .gl-img { transition: transform var(--d-enter) var(--ease); }
.gl-cap { margin-top: 8px; font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--muted); overflow-wrap: anywhere; text-wrap: pretty; }

/* grid: columns give the masonry feel, every item keeps its own aspect (cropped only to the 0.6 to 1.8 range); order runs down each column */
.gl-grid { list-style: none; margin: 0; padding: 0; column-count: min(var(--gl-cols), var(--gl-n, 4)); column-gap: var(--gl-gap); }
.gl-item { break-inside: avoid; margin: 0 0 var(--gl-gap); }
.gl-item:has(.gl-cap) { margin-bottom: calc(var(--gl-gap) + 4px); }

/* strip: scroll-snap row that bleeds to the screen edge; arrows (computer) and dots (phone) are added by mount() */
.gl-strip { position: relative; overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none; margin-inline: calc(var(--pad) * -1); padding-inline: var(--pad); scroll-padding-inline: var(--pad); border-radius: var(--gl-r); }
.gl-strip::-webkit-scrollbar { display: none; }
.gl-strip:focus-visible { outline-offset: -2px; }
.gl-track { display: flex; gap: var(--gl-gap); list-style: none; margin: 0; padding: 0; }
.gl-slide { flex: 0 0 min(560px, 80%); scroll-snap-align: start; min-width: 0; }
.gl-slide .gl-media { aspect-ratio: 4 / 3; }
.gl-nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; margin-top: 16px; }
.gl-count { margin: 0; color: var(--muted); font-size: 14px; font-weight: 500; }
.gl-dots { display: none; }
.gl-arrows { display: flex; gap: 8px; }
.gl-arrow { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--field); display: grid; place-items: center; transition: background-color var(--d-fast) ease, opacity var(--d-fast) ease; }
.gl-arrow-prev svg { transform: scaleX(-1); }
.gl-arrow[aria-disabled="true"] { opacity: .35; cursor: not-allowed; }
.gl-dot { width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; padding: 0; }
.gl-dot span { display: block; width: 8px; height: 8px; border-radius: 999px; background: var(--field); transition: width var(--d) var(--ease), background-color var(--d) ease; }
.gl-dot[aria-current="true"] span { width: 22px; background: var(--brand); }

/* compare: with script the photos overlap and the handle slides; without it they stack, each with its label */
.gl-cmp { --pos: 50%; position: relative; aspect-ratio: var(--gl-ar, 4 / 3); border-radius: var(--gl-r); overflow: hidden; background: var(--placeholder); isolation: isolate; max-width: 960px; user-select: none; -webkit-user-select: none; }
.gl-pane { position: absolute; inset: 0; margin: 0; }
.gl-pane .gl-img, .gl-pane .gl-ph { width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; }
.gl-pane .gl-ph { border-radius: 0; }
.gl-before { z-index: 1; clip-path: inset(0 calc(100% - var(--pos)) 0 0); }
.gl-tag { position: absolute; top: 12px; left: 12px; margin: 0; padding: 5px 12px; border-radius: 999px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-size: 14px; font-weight: 600; line-height: 1.4; }
.gl-after .gl-tag { left: auto; right: 12px; }
.gl-handle { position: absolute; z-index: 2; top: 0; bottom: 0; left: var(--pos); width: 44px; margin-left: -22px; display: grid; place-items: center; touch-action: none; cursor: ew-resize; }
.gl-handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: var(--surface); box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 22%, transparent); }
.gl-handle:focus-visible { outline: none; }
.gl-knob { position: relative; width: 44px; height: 44px; border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; transition: transform var(--d) var(--ease); }
.gl-arr { display: grid; place-items: center; margin: 0 -3px; }
.gl-arr-l { transform: scaleX(-1); }
.gl-handle:focus-visible .gl-knob { outline: 2px solid var(--brand); outline-offset: 3px; }
.gl-cmp[data-dragging] .gl-knob { transform: scale(1.08); }
@media (scripting: none) {
  .gl-cmp { display: grid; gap: 16px; aspect-ratio: auto; overflow: visible; background: none; }
  .gl-pane { position: relative; inset: auto; aspect-ratio: var(--gl-ar, 4 / 3); border-radius: var(--gl-r); overflow: hidden; clip-path: none; background: var(--placeholder); }
  .gl-handle { display: none; }
}

/* video: a 16:9 frame; YouTube is a cover photo and a play button until tapped, then the privacy-enhanced player */
.gl-videos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px var(--gl-gap); }
.gl-videos[data-n="1"] { max-width: 960px; grid-template-columns: minmax(0, 1fr); }
.gl-vid { margin: 0; min-width: 0; }
.gl-vid[data-wide] { grid-column: 1 / -1; }
.gl-frame { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--gl-r); background: var(--placeholder); }
.gl-frame.gl-ph { display: grid; place-items: center; }
.gl-poster, .gl-video, .gl-embed { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.gl-poster { object-fit: cover; }
.gl-video { object-fit: cover; background: var(--ink); }
.gl-play { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; padding: 0; background: none; display: grid; place-items: center; color: var(--ink); }
.gl-play:focus-visible { outline-offset: -5px; }
.gl-play-dot { width: 72px; height: 72px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; transition: transform var(--d) var(--ease); }
.gl-play-dot svg { margin-left: 3px; }
.gl-play:active .gl-play-dot { transform: scale(.96); }
.gl-vcap { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 16px; margin-top: 12px; }
.gl-vtitle { flex: 1 0 100%; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.gl-consent { font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--muted); }
.gl-vlink { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 15px; font-weight: 600; }

/* lightbox: its own backdrop layer (so the fade never dims the photo), photo stage in the middle, controls round it */
html:has(.gl-lb[open]) { overflow: hidden; scrollbar-gutter: stable; }
.gl-lb { --gl-lb-bg: color-mix(in srgb, var(--ink) 97%, transparent); --gl-lb-fg: var(--surface);
  position: fixed; inset: 0; width: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: none; color: var(--gl-lb-fg); overflow: hidden; overscroll-behavior: contain; }
:root[data-theme="dark"] .gl-lb { --gl-lb-bg: color-mix(in srgb, var(--ground) 97%, transparent); --gl-lb-fg: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .gl-lb { --gl-lb-bg: color-mix(in srgb, var(--ground) 97%, transparent); --gl-lb-fg: var(--ink); } }
.gl-lb[open] { display: grid; grid-template: "top top top" auto "prev stage next" minmax(0, 1fr) "cap cap cap" auto / 72px minmax(0, 1fr) 72px; }
.gl-lb::backdrop { background: none; }
.gl-lb-bg { position: absolute; inset: 0; background: var(--gl-lb-bg); }
.gl-lb-top { grid-area: top; position: relative; display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 24px; }
.gl-lb-count { margin: 0; font-size: 15px; font-weight: 600; }
.gl-lb-btn { position: relative; width: 44px; height: 44px; border: 0; border-radius: 50%; padding: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--gl-lb-fg) 16%, transparent); color: var(--gl-lb-fg); transition: background-color var(--d-fast) ease; }
.gl-lb-btn:focus-visible { outline-color: var(--gl-lb-fg); }
.gl-lb-prev { grid-area: prev; justify-self: center; align-self: center; }
.gl-lb-prev svg { transform: scaleX(-1); }
.gl-lb-next { grid-area: next; justify-self: center; align-self: center; }
.gl-lb-stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden; touch-action: pan-y pinch-zoom; }
.gl-lb-img { position: absolute; inset: 0; margin: auto; max-width: none; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.gl-lb-cap { grid-area: cap; position: relative; margin: 0 auto; max-width: 60ch; padding: 8px 24px 24px; text-align: center; font-size: 16px; line-height: 1.5; text-wrap: balance; }
@media (max-width: 720px) {
  .gl-lb[open] { grid-template: "top top top" auto "stage stage stage" minmax(0, 1fr) "prev cap next" auto / 44px minmax(0, 1fr) 44px; }
  .gl-lb-top { padding: 12px 12px 4px 16px; }
  .gl-lb-prev, .gl-lb-next { margin-bottom: 16px; }
  .gl-lb-prev { margin-left: 12px; } .gl-lb-next { margin-right: 12px; }
  .gl-lb-cap { padding: 8px 12px 16px; align-self: center; }
  .gl-lb-cap[hidden] { display: block !important; visibility: hidden; } /* keep the arrows apart when a photo has no caption */
}

/* hover only where there is a pointer to hover with */
@media (hover: hover) and (pointer: fine) {
  .gl-open:hover .gl-img { transform: scale(1.03); }
  .gl-arrow:hover:not([aria-disabled="true"]) { background: var(--line); }
  .gl-dot:hover span { background: var(--muted); }
  .gl-lb-btn:hover { background: color-mix(in srgb, var(--gl-lb-fg) 28%, transparent); }
  .gl-play:hover .gl-play-dot { transform: scale(1.06); }
  .gl-handle:hover .gl-knob { transform: scale(1.06); }
}

/* phone: two columns, a strip with peeking next photo and dots, one column of videos */
@media (max-width: 720px) {
  .gl-grid { column-count: min(2, var(--gl-n, 2)); }
  .gl-slide { flex-basis: 82%; }
  .gl-slide .gl-media { aspect-ratio: 5 / 4; }
  .gl-nav { justify-content: center; }
  .gl-arrows { display: none; }
  .gl-dots { display: flex; }
  .gl-nav[data-many] .gl-dots { display: none; }
  .gl-nav:not([data-many]) .gl-count { display: none; }
  .gl-videos { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .gl-open .gl-img, .gl-play-dot, .gl-knob, .gl-dot span { transition-property: opacity, background-color; }
  .gl-open:hover .gl-img, .gl-play:hover .gl-play-dot, .gl-play:active .gl-play-dot, .gl-handle:hover .gl-knob, .gl-cmp[data-dragging] .gl-knob { transform: none; }
}
