/* Article photo viewer, built by js/article-lightbox.js as a modal <dialog> (Esc and the back gesture close it natively).
   Photo first: a neutral dark viewer over the whole viewport, the photo contained, compact controls, thumbnails at the
   bottom. Same look in both themes on purpose. Sizes in rem/em so the viewer follows OS text scaling. */
@layer components {
  .c-article__cover > a[data-js="lightbox"], .blk-image > a[data-js="lightbox"] { display: block; }
  [data-article-gallery] a[data-js="lightbox"] { cursor: zoom-in; }

  .c-viewer {
    --v-bg: #141414; --v-fg: #f2f2f2; --v-muted: #b8b8b8; --v-btn: rgba(255, 255, 255, 0.14); --v-ring: #ffffff;
    /* Pinned to the viewport edges, not sized from 100dvw/100dvh: no overflow from scrollbars or Safari's dialog defaults. */
    position: fixed; inset: 0; box-sizing: border-box; inline-size: auto; block-size: auto; max-inline-size: none; max-block-size: none;
    margin: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); overflow: hidden;
    border: 0; background: var(--v-bg); color: var(--v-fg); font: inherit;
  }
  .c-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  .c-viewer:modal { overscroll-behavior: contain; }
  .c-viewer::backdrop { background: #000; overflow: hidden; overscroll-behavior: contain; }

  .c-viewer__top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .c-viewer__count { margin: 0; font-size: 0.875rem; font-variant-numeric: tabular-nums; color: var(--v-muted); }
  .c-viewer__btn, .c-viewer__zoom {
    display: inline-grid; place-items: center; inline-size: 2.75rem; block-size: 2.75rem; padding: 0; border: 1px solid transparent;
    border-radius: 50%; background: var(--v-btn); color: var(--v-fg); cursor: pointer; touch-action: manipulation;
  }
  .c-viewer__btn:hover { background: rgba(255, 255, 255, 0.26); }
  .c-viewer__btn:focus-visible, .c-viewer__thumb:focus-visible { outline: 3px solid var(--v-ring); outline-offset: 2px; }
  .c-viewer__btn[hidden] { display: none; }
  .c-viewer__icon { inline-size: 1.5rem; block-size: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.5; }

  .c-viewer__stage { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr); align-items: center; gap: 0.25rem; min-block-size: 0; padding-inline: 0.5rem; }
  .c-viewer__stage[data-single] { grid-template-columns: minmax(0, 1fr); }
  /* Swipe sideways is ours, vertical scroll and pinch stay native. */
  .c-viewer__figure { display: grid; grid-template-rows: minmax(0, 1fr) auto; justify-items: center; gap: 0.5rem; align-self: stretch; min-block-size: 0; margin: 0; touch-action: pan-y pinch-zoom; }
  /* The photo fills an absolutely positioned frame: no percentage heights for browsers to resolve differently. */
  .c-viewer__frame { position: relative; justify-self: stretch; min-block-size: 0; }
  .c-viewer__img { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; object-fit: contain; }
  .c-viewer__caption { max-inline-size: 60ch; max-block-size: 7em; overflow: auto; overflow-wrap: anywhere; padding-inline: 0.5rem; font-size: 0.875rem; line-height: 1.4; text-align: center; color: var(--v-muted); }
  .c-viewer__caption:empty { display: none; }
  .c-viewer__credit { margin-inline-start: 0.5em; font-style: italic; }

  .c-viewer__thumbs { position: relative; display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem 0.75rem; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; touch-action: pan-x pinch-zoom; }
  .c-viewer__thumbs[hidden] { display: none; }
  .c-viewer__thumb { flex: none; inline-size: 4.5rem; aspect-ratio: 3 / 2; padding: 0; border: 0; border-radius: 0.25rem; background: #333; color: var(--v-fg); opacity: 0.75; cursor: pointer; touch-action: manipulation; }
  .c-viewer__thumb:first-child { margin-inline-start: auto; }
  .c-viewer__thumb:last-child { margin-inline-end: auto; }
  .c-viewer__thumb img { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; border-radius: inherit; }
  .c-viewer__thumb:hover { opacity: 0.85; }
  .c-viewer__thumb[aria-current="true"]:not(:focus-visible) { opacity: 1; outline: 2px solid currentColor; outline-offset: -2px; }

  /* Phones: the arrows overlay the photo edges instead of taking columns from it. */
  @media (width < 40em) {
    .c-viewer__stage { grid-template-columns: minmax(0, 1fr); padding-inline: 0; }
    .c-viewer__stage > * { grid-area: 1 / 1; }
    .c-viewer__nav { z-index: 1; margin-inline: 0.25rem; background: rgba(0, 0, 0, 0.55); }
    .c-viewer__nav[data-act="prev"] { justify-self: start; }
    .c-viewer__nav[data-act="next"] { justify-self: end; }
    .c-viewer__thumb { inline-size: 3.5rem; }
  }

  /* Zoom button beside a photo that links to another page (the link itself is left alone). */
  .c-viewer__zoom { position: relative; inline-size: 2.25rem; block-size: 2.25rem; margin-inline-start: 0.25rem; background: #141414; color: #fff; }
  .c-viewer__zoom:focus-visible { outline: 3px solid currentColor; outline-offset: 2px; }
}

@media print {
  .c-viewer, .c-viewer__zoom { display: none !important; }
}
