#viewer {
  --album-nav-height: 44px;
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  color-scheme: light;
}
#viewer[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.viewer-bar:focus {
  outline: none;
}
#viewer::backdrop {
  background: var(--canvas);
}
body:has(#viewer[open]) {
  overflow: hidden;
}
/* The server-rendered dialog enters the browser's modal layer when JS starts. */
body:has(#viewer[open][data-initial-item]) .library {
  visibility: hidden;
}
.viewer-bar,
.post-pager {
  display: flex;
  align-items: center;
}
.viewer-bar {
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) var(--gutter) 10px;
}
.post-pager {
  margin-inline-start: auto;
  gap: 4px;
}
.viewer-bar button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: var(--control);
  height: var(--control);
  padding: 0;
  border: none;
  border-radius: var(--button-radius, 8px);
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
}
.viewer-bar button, .album-dots button {
  touch-action: manipulation;
}
.chevron {
  width: 8px;
  height: 8px;
  border: solid currentColor;
  border-width: 0 0 1.5px 1.5px;
  transform: translateX(2px) rotate(45deg);
}
#next .chevron {
  transform: translateX(-2px) rotate(225deg);
}
.viewer-bar #back {
  gap: 7px;
  padding-inline: 12px;
  font-size: 0.875rem;
}
.viewer-bar #back,
.viewer-bar #close {
  background: var(--paper);
  box-shadow: var(--shadow);
}
.viewer-bar button:disabled {
  opacity: 0.35;
  cursor: default;
}
#position {
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#contents {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  container-type: size;
}
.shot {
  --media-height: calc(78cqh - var(--attachment-row, 0px));
  width: min(100%, 56rem);
  margin-inline: auto;
  padding-block: 4px max(32px, env(safe-area-inset-bottom));
}
.shot:has(.album) {
  --attachment-row: var(--album-nav-height);
}
@media (min-width: 741px) {
  .shot:has(.stage) {
    /* Keep the caption aligned with a portrait shot on wide screens. */
    max-width: max(28rem, calc(var(--media-height) * var(--shot-ratio, 1.3333) + 2 * var(--gutter)));
  }
}
.viewer-error, .attachment-error {
  place-self: center;
  padding: 16px;
  text-align: center;
}
.viewer-error { margin: 12vh auto; }
.viewer-error p, .attachment-error p { margin: 0 0 12px; }
#viewer-status:not(.visually-hidden) {
  position: absolute;
  inset: auto 12px max(12px, env(safe-area-inset-bottom));
  margin: 0 auto;
  width: fit-content;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-size: .875rem;
}
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
  min-width: 0;
  min-height: 0;
  padding-inline: var(--gutter);
}
.stage.album {
  grid-template-rows: minmax(0, auto) var(--attachment-row);
  padding-inline: 0;
}
.media-frame {
  display: flex;
  min-width: 0;
  min-height: 0;
  width: 100%;
  aspect-ratio: var(--shot-ratio, 4 / 3);
  max-height: var(--media-height);
}
.shot[aria-hidden] .media-frame {
  background: var(--soft);
  border-radius: var(--radius);
}
.album .media-frame {
  position: relative;
  box-sizing: content-box;
  width: calc(100% - 2 * var(--gutter));
  gap: 8px;
  padding-inline: var(--gutter);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.media-frame::-webkit-scrollbar {
  display: none;
}
.media-frame:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}
.slide {
  display: block;
  flex: 0 0 100%;
  min-width: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  scroll-snap-align: center;
}
img.slide, .slide video {
  object-fit: contain;
}
.slide > :is(video, iframe) {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: inherit;
}
.attachment-error {
  display: grid;
  align-content: center;
  justify-items: center;
}
.album-dots {
  display: flex;
  align-items: center;
  justify-content: center;
}
.album-dots button {
  display: grid;
  place-items: center;
  width: 28px;
  height: var(--album-nav-height);
}
.album-dots button::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 6px;
  background: #aaa;
}
.album-dots button[aria-current]::before {
  width: 16px;
  background: var(--ink);
}
.source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--control);
  padding: 6px 12px;
  background: var(--paper);
  border-radius: var(--button-radius, 8px);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
}
.post-details {
  margin: 18px var(--gutter) 0;
  overflow-wrap: anywhere;
}
.album + .post-details {
  margin-top: 2px;
}
.post-text {
  max-width: 64ch;
  margin: 0;
  white-space: pre-wrap;
  font-size: clamp(1.0625rem, 1.6vw, 1.25rem);
  line-height: 1.45;
}
.loading-text {
  width: min(80%, 32ch);
  height: 1rem;
  border-radius: 3px;
  background: var(--soft);
}
.post-byline {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 7px;
  align-items: baseline;
  color: var(--muted);
  font-size: .8125rem;
}
.post-text + .post-byline { margin-top: 10px; }
.post-byline strong {
  color: var(--ink);
  font-weight: 550;
}
.post-facets { margin-top: 18px; }
.post-facets h3 {
  margin: 0 0 6px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
}
.post-facets .chips { gap: 6px; }
.post-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: var(--control);
  font-size: .875rem;
}
.post-details > * + .post-source { margin-top: 14px; }
@media (hover: hover) and (pointer: fine) {
  .post-byline a:hover, .post-source:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  .viewer-bar button:hover:enabled,
  .source-link:hover {
    background: var(--soft);
  }
}
@media (pointer: coarse) {
  #viewer {
    --control: 44px;
  }
}
@media (max-width: 740px), (pointer: coarse) and (max-width: 960px) and (max-height: 520px) {
  .viewer-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 4px;
    padding-block: calc(4px + env(safe-area-inset-top, 0px)) 4px;
  }
  .viewer-bar #back {
    justify-self: start;
    padding-inline: 4px 8px;
    background: transparent;
    box-shadow: none;
    font-weight: 500;
  }
  .viewer-bar #close {
    display: none;
  }
  #position {
    justify-self: center;
    font-size: .75rem;
  }
  .post-pager {
    justify-self: end;
    position: relative;
    isolation: isolate;
    gap: 0;
  }
  .post-pager::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 5px 0;
    border-radius: var(--button-radius);
    background: var(--soft);
  }
  .viewer-bar button:active:enabled {
    color: var(--muted);
  }
}
@media (max-width: 740px) {
  #viewer {
    --control: 44px;
  }
}
