#gallery-viewer {
  --gallery-photo-height: min(510px, 55dvh);
  width: min(850px, calc(100vw - 2 * var(--photo-gutter)));
  height: min(820px, calc(100dvh - 16px));
}
#gallery-viewer[open] { display: flex; flex-direction: column; }
.gallery-viewer-content { flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable both-edges; }
.gallery-photo-stage {
  height: var(--gallery-photo-height);
  display: grid; grid-template-columns: minmax(0, 1fr); place-items: center;
}
#gallery-viewer .gallery-photo-stage img { max-width: 100%; max-height: var(--gallery-photo-height); }
#gallery-viewer .gallery-photo-stage .is-zoomed img { max-width: none; max-height: none; }
#gallery-viewer > .portal-photo-tools {
  align-items: center; gap: 2px; padding: 4px 10px 6px;
}
#gallery-viewer > .portal-photo-tools > :is(button, a:any-link):not([hidden]) {
  min-width: 34px; min-height: 34px; border: 0; border-radius: 5px;
  background: transparent; color: #cbd7dd;
}
#gallery-viewer > .portal-photo-tools > :is(button:not(:disabled), a:any-link):is(:hover, :focus-visible) {
  background: #ffffff14; color: #fff;
}
#gallery-viewer > .portal-photo-tools > :is(button, a):focus-visible {
  outline: 1px solid #a6b5bd; outline-offset: -2px;
}
.gallery-viewer-meta {
  display: flex; flex: 1; min-width: 0; align-items: baseline; gap: 10px; padding-inline: 3px 9px;
  font-size: 13px; line-height: 1.35;
}
#gallery-album { min-width: 0; margin: 0; font: inherit; }
#gallery-album a:any-link {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #c4d8e1; font: inherit; text-decoration: none;
}
#gallery-album a:is(:hover, :focus-visible) { color: #eef7fb; text-decoration: underline; text-underline-offset: 3px; }
#gallery-album a:focus-visible { outline: 1px solid #c4d8e1; outline-offset: 2px; border-radius: 2px; }
#gallery-index {
  flex: none; white-space: nowrap; color: #a6b5bd; font-size: 12px; font-variant-numeric: tabular-nums;
  border-inline-start: 1px solid #ffffff26; padding-inline-start: 10px;
}
#gallery-index:empty { display: none; }
#gallery-date, #gallery-viewer-status {
  display: block; margin: 0; padding: 3px 8px; text-align: center; color: #e0e8ec; font-size: .85rem;
}
.gallery-expand-icon {
  display: block; width: 20px; height: 20px; background: currentColor;
  mask: url("/gallery-expand.png") center / contain no-repeat;
}
.gallery-collapse-icon { display: none; width: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[data-gallery-expand][aria-pressed="true"] .gallery-expand-icon { display: none; }
[data-gallery-expand][aria-pressed="true"] .gallery-collapse-icon { display: block; }
#gallery-viewer[data-gallery-expanded] {
  width: calc(100vw - 2 * var(--photo-gutter));
  height: calc(100dvh - 12px);
  background: transparent;
}
#gallery-viewer[data-gallery-expanded] .gallery-viewer-content { overflow: hidden; scrollbar-gutter: auto; }
#gallery-viewer[data-gallery-expanded] .gallery-photo-stage { height: 100%; }
#gallery-viewer[data-gallery-expanded] .gallery-photo-stage > .portal-photo-viewport:not(.is-zoomed) { width: 100%; height: 100%; }
#gallery-viewer[data-gallery-expanded] .gallery-photo-stage .portal-photo-viewport:not(.is-zoomed) img {
  width: 100%; height: 100%; max-height: none;
}
#gallery-viewer[data-gallery-expanded] :where(#gallery-caption, #gallery-date, #gallery-comments) { display: none; }
#gallery-viewer[data-gallery-expanded] #gallery-viewer-status {
  position: absolute; inset-inline: 0; bottom: 8px; margin-inline: auto;
  width: fit-content; background: #171b1e;
}
#gallery-caption {
  box-sizing: border-box; margin: 0 auto; padding: 6px 14px; max-width: 700px;
  color: white; text-align: center; overflow-wrap: anywhere;
}
#gallery-caption p, .gallery-comment-text p { margin: .25em 0; }
#gallery-caption a:any-link { color: #b8deef; text-decoration: underline; }
#gallery-viewer [data-gallery-untag]:not([hidden]) {
  min-width: 30px; min-height: 30px; vertical-align: middle; color: #b8deef;
  background: transparent; border: 0;
}
#gallery-viewer [data-gallery-untag] svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; }
#gallery-comments {
  --comment-text: #e0e8ec;
  --comment-muted: #a8b7bf;
  --comment-link: #aed6e8;
  --comment-rule: #38434a;
  --comment-focus: #9cc9da;
  display: grid; gap: 7px; margin-top: 9px; padding: 12px 14px;
  border-top: 1px solid var(--comment-rule);
  background: #1c2226; color: var(--comment-text); color-scheme: dark;
  text-align: start; font-size: .9rem;
}
#gallery-comments :is(h2, label, .gallery-comment-text, .gallery-comment-text :where(*)) { color: var(--comment-text); }
#gallery-comments h2 { margin: 0; font-size: 1rem; }
#gallery-comments p { margin-block: 2px; overflow-wrap: anywhere; }
#gallery-comments :is(#gallery-comments-status, #gallery-comments-login, #gallery-comment-filename, time) { color: var(--comment-muted); }
#gallery-viewer #gallery-comments a:any-link { color: var(--comment-link); text-decoration: underline; text-underline-offset: 2px; }
#gallery-comment-entries { display: grid; gap: 6px; }
.gallery-comment { padding: 7px 0; border-top: 1px solid var(--comment-rule); overflow-wrap: anywhere; }
.gallery-comment header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.gallery-comment header time { font-size: .8em; }
.gallery-comment-text pre { white-space: pre-wrap; }
.gallery-comment-photo { display: inline-block; margin-top: 5px; }
.gallery-comment-photo img { display: block; max-width: min(160px, 100%); max-height: 120px; object-fit: contain; }
#gallery-comment-form { display: grid; gap: 5px; }
#gallery-comment-form textarea {
  padding: 5px 7px; box-sizing: border-box; width: 100%; font: inherit; resize: vertical;
  border: 1px solid #677780; border-radius: 4px; background: #252d32;
  color: var(--comment-text); caret-color: var(--comment-focus);
}
#gallery-comment-form textarea:focus-visible { outline: 2px solid var(--comment-focus); outline-offset: 2px; }
.gallery-comment-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 9px; }
#gallery-viewer #gallery-comments button { min-height: 28px; font: inherit; }
#gallery-viewer #gallery-comments button[type="submit"] {
  padding-inline: 9px; border-color: #566771; background: #2c3a43; color: #edf4f7;
}
#gallery-viewer #gallery-comments button[type="submit"]:hover { background: #3a4b56; }
#gallery-viewer #gallery-comments .gallery-comment-link {
  padding: 0; border: 0; color: var(--comment-link); background: none;
  text-decoration: underline; text-underline-offset: 2px;
}
#gallery-viewer #gallery-comments :is(a,button):focus-visible { outline-color: var(--comment-focus); }
#gallery-viewer [hidden] { display: none; }
.gallery-swipe-strip { display: none; }

@media (max-width: 680px), (max-height: 480px) and (pointer: coarse) {
  #gallery-viewer {
    --photo-gutter: 8px;
    --photo-arrow-size: 44px;
    box-sizing: border-box;
    padding-block-end: env(safe-area-inset-bottom);
    background: transparent;
  }
  #gallery-viewer::backdrop { background: rgb(12 17 20 / 97%); }
  #gallery-viewer:has(> :is(.gallery-prev, .gallery-next):not([hidden])) {
    padding-block-end: calc(var(--photo-arrow-size) + 8px + env(safe-area-inset-bottom));
  }
  #gallery-viewer:has(> .gallery-next:not([hidden])) > .gallery-swipe-strip {
    display: block;
    position: absolute;
    inset: auto 0 0;
    height: calc(var(--photo-arrow-size) + 8px + env(safe-area-inset-bottom));
    touch-action: pan-y;
  }
  #gallery-viewer > .portal-photo-tools { flex-wrap: wrap; row-gap: 3px; padding: 3px 4px 6px; }
  #gallery-viewer > .portal-photo-tools > :is(button, a:any-link):not([hidden]) { min-width: 44px; min-height: 44px; }
  .gallery-viewer-meta {
    flex-basis: 100%; justify-content: space-between; gap: 8px; padding: 4px 4px 0;
    font-size: 12px;
  }
  #gallery-viewer > .portal-photo-tools > [data-gallery-expand]:not([hidden]) { display: none; }
  #gallery-index { border-inline-start: 0; padding-inline-start: 0; }
  .gallery-viewer-content { scrollbar-width: none; scrollbar-gutter: auto; overscroll-behavior: contain; }
  .gallery-photo-stage { height: auto; }
  #gallery-viewer > :is(.gallery-prev, .gallery-next):not([hidden]) {
    top: auto; bottom: env(safe-area-inset-bottom); transform: none;
    border: 0; background: transparent; color: #e0e8ec; touch-action: pan-y;
  }
  #gallery-viewer > :is(.gallery-prev, .gallery-next):disabled { pointer-events: none; }
  #gallery-viewer > .gallery-prev { left: 0; }
  #gallery-viewer > .gallery-next { right: 0; }
  #gallery-viewer #gallery-comments { border: 0; background: transparent; padding-inline: 8px; }
}

@media (orientation: landscape) and (max-height: 480px) and (pointer: coarse),
       (orientation: landscape) and (max-height: 480px) and (max-width: 680px) {
  #gallery-viewer { --gallery-photo-height: max(100px, calc(100dvh - 116px - env(safe-area-inset-bottom))); }
  #gallery-viewer > .portal-photo-tools { flex-wrap: nowrap; }
  .gallery-viewer-meta { flex-basis: 0; padding-block: 0; }
  .gallery-viewer-content { container-type: size; }
  .gallery-photo-stage { height: var(--gallery-photo-height); }
  @supports (height: 100cqh) {
    .gallery-photo-stage { height: 100cqh; }
  }
  .gallery-photo-stage > .portal-photo-viewport:not(.is-zoomed) { width: 100%; height: 100%; }
  #gallery-viewer .gallery-photo-stage .portal-photo-viewport:not(.is-zoomed) img {
    width: 100%; height: 100%; max-height: none;
  }
}
