/* GSS Lightbox: video thumbnails ("facade"), zoomable article images and the lightbox. */

/* ---- Thumbnail in the article ---- */
a.gsslb-video {
  position: relative;
  display: block;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  background: #000;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}

a.gsslb-video.gsslb-video--block {
  width: 100%;
  margin: 1.5em 0;
}

/*
 * The picture is centred in its box and zooms from its centre. !important on geometry:
 * templates commonly force img { height: auto } or add their own transforms, which would
 * pin the picture to the top of the box.
 */
a.gsslb-video .gsslb-video-thumb {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  object-fit: cover !important; /* hqdefault is 4:3 with bars; cover crops them away evenly */
  object-position: 50% 50% !important;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
  transition: transform 0.35s ease, filter 0.35s ease;
}

/* No thumbnail available (Bilibili, Vimeo until its thumbnail arrives): a calm dark tile. */
a.gsslb-video .gsslb-video-thumb--blank {
  display: block;
  background:
    radial-gradient(120% 90% at 30% 20%, rgb(255 255 255 / 12%), transparent 60%),
    linear-gradient(135deg, #1f2733, #0d1117);
}

a.gsslb-video--bilibili .gsslb-video-thumb--blank {
  background:
    radial-gradient(120% 90% at 30% 20%, rgb(0 174 236 / 30%), transparent 60%),
    linear-gradient(135deg, #16324a, #0b1620);
}

/* Site name in the corner (for players without a recognisable thumbnail). */
a.gsslb-video .gsslb-video-source {
  position: absolute;
  top: 10px;
  left: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  font: 600 12px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0.02em;
  pointer-events: none;
}

/* Hover: the picture zooms slightly from the centre (the box itself never changes size). */
a.gsslb-video:hover .gsslb-video-thumb,
a.gsslb-video:focus-visible .gsslb-video-thumb {
  transform: translate(-50%, -50%) scale(1.04);
  filter: brightness(0.82);
}

a.gsslb-video .gsslb-video-play {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 68px;
  height: 48px;
  margin: -24px 0 0 -34px;
  border-radius: 14px;
  background: rgb(33 33 33 / 80%);
  transition: background 0.2s ease, transform 0.2s ease;
}

a.gsslb-video .gsslb-video-play::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -10px 0 0 -7px;
  border-width: 10px 0 10px 17px;
  border-style: solid;
  border-color: transparent transparent transparent #fff;
}

a.gsslb-video:hover .gsslb-video-play,
a.gsslb-video:focus-visible .gsslb-video-play {
  background: #f00;
  transform: scale(1.06);
}

/* "點擊放大播放" hint: appears on hover / keyboard focus. */
a.gsslb-video .gsslb-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgb(0 0 0 / 72%);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

a.gsslb-video .gsslb-hint::before {
  content: "";
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M9.5 2.5h4v4M13.5 2.5L9 7M6.5 13.5h-4v-4M2.5 13.5L7 9' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M9.5 2.5h4v4M13.5 2.5L9 7M6.5 13.5h-4v-4M2.5 13.5L7 9' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

a.gsslb-video:hover .gsslb-hint,
a.gsslb-video:focus-visible .gsslb-hint {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Touch screens have no hover: show the hint all the time. */
@media (hover: none) {
  a.gsslb-video .gsslb-hint {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

a.gsslb-video:focus-visible {
  outline: 3px solid #4b96e6;
  outline-offset: 2px;
}

/* The thumbnail stays in place (dimmed) while its video is open. */
a.gsslb-video.is-open .gsslb-video-thumb {
  filter: brightness(0.5);
}

/* ---- Lightbox ---- */
.gsslb {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
}

.gsslb-backdrop {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  cursor: zoom-out;
  transition: opacity 0.32s ease;
}

.gsslb.is-open .gsslb-backdrop {
  opacity: var(--gsslb-backdrop, 0.85);
}

.gsslb-stage {
  position: fixed;
  overflow: hidden;
  border-radius: 8px;
  background: #000;
  box-shadow: 0 20px 60px rgb(0 0 0 / 45%);
  transform-origin: 0 0;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 0.32s ease;
}

.gsslb.is-entering .gsslb-stage,
.gsslb.is-leaving .gsslb-stage {
  border-radius: 6px;
}

.gsslb-stage iframe,
.gsslb-stage .gsslb-stage-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  border: 0;
}

.gsslb-stage .gsslb-stage-video {
  background: #000;
  object-fit: contain;
}

/* The picture inside the growing lightbox: centred too, so it grows from the middle. */
.gsslb-stage-thumb {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  object-fit: cover !important;
  object-position: 50% 50% !important;
  transform: translate(-50%, -50%);
}

.gsslb-close {
  position: fixed;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 14%);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease 0.15s, background 0.2s ease;
}

.gsslb.is-open .gsslb-close {
  opacity: 1;
}

.gsslb-close:hover,
.gsslb-close:focus-visible {
  background: rgb(255 255 255 / 28%);
  outline: none;
}

.gsslb-close:focus-visible {
  box-shadow: 0 0 0 3px #4b96e6;
}

/* ---- Article images ---- */
img.gsslb-zoomable {
  cursor: zoom-in;
  transition: filter 0.2s ease;
}

img.gsslb-zoomable:hover {
  filter: brightness(0.94);
}

img.gsslb-zoomable:focus-visible {
  outline: 3px solid #4b96e6;
  outline-offset: 2px;
}

/* Floating hint (one element on <body>, so the article layout never changes). */
.gsslb-img-hint {
  position: absolute;
  z-index: 2147482000;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgb(0 0 0 / 72%);
  color: #fff;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -100%) translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.gsslb-img-hint::before {
  content: "";
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='4.5' fill='none' stroke='black' stroke-width='1.6'/%3E%3Cpath d='M10.5 10.5l3.5 3.5M7 5v4M5 7h4' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='4.5' fill='none' stroke='black' stroke-width='1.6'/%3E%3Cpath d='M10.5 10.5l3.5 3.5M7 5v4M5 7h4' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.gsslb-img-hint.is-visible {
  opacity: 1;
  transform: translate(-50%, -100%);
}

/* Image in the lightbox: shown whole (contain), centred. */
.gsslb-stage.is-image {
  background: transparent;
  box-shadow: none;
  border-radius: 2px;
  cursor: zoom-out;
}

.gsslb-stage-image {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  object-fit: contain !important;
  object-position: 50% 50% !important;
  box-shadow: 0 20px 60px rgb(0 0 0 / 45%);
}

/* Larger than the window: click (or the button) shows it at 1:1, drag to move. */
.gsslb-stage.is-image.is-zoomable {
  cursor: zoom-in;
}

.gsslb-stage.is-image.is-zoomed {
  border-radius: 0;
  cursor: grab;
  touch-action: none;
}

.gsslb-stage.is-image.is-zoomed.is-dragging {
  cursor: grabbing;
}

.gsslb-stage.is-zoomed .gsslb-stage-image {
  top: var(--gsslb-y) !important;
  left: var(--gsslb-x) !important;
  right: auto !important;
  bottom: auto !important;
  width: var(--gsslb-w) !important;
  height: var(--gsslb-h) !important;
  box-shadow: none;
  user-select: none;
  -webkit-user-drag: none;
}

.gsslb-stage.is-zoom-animating .gsslb-stage-image {
  transition: top 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), left 0.32s cubic-bezier(0.2, 0.8, 0.2, 1),
    width 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.gsslb-zoom {
  position: fixed;
  top: 12px;
  right: 64px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 14%);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease 0.15s, background 0.2s ease;
}

.gsslb-zoom[hidden] {
  display: none;
}

.gsslb.is-open .gsslb-zoom {
  opacity: 1;
}

.gsslb-zoom:hover,
.gsslb-zoom:focus-visible,
.gsslb-zoom[aria-pressed="true"] {
  background: rgb(255 255 255 / 28%);
  outline: none;
}

.gsslb-zoom:focus-visible {
  box-shadow: 0 0 0 3px #4b96e6;
}

/* Close / zoom / counter stay readable over a 1:1 picture. */
.gsslb-close,
.gsslb-zoom,
.gsslb-nav {
  box-shadow: 0 1px 6px rgb(0 0 0 / 25%);
}

.gsslb-caption {
  position: fixed;
  left: 50%;
  max-width: min(80vw, 900px);
  color: #fff;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  text-align: center;
  text-shadow: 0 1px 2px rgb(0 0 0 / 60%);
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.2s ease 0.15s;
}

.gsslb-counter {
  position: fixed;
  top: 22px;
  left: 20px;
  color: rgb(255 255 255 / 85%);
  font: 14px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  opacity: 0;
  transition: opacity 0.2s ease 0.15s;
}

.gsslb-nav {
  position: fixed;
  top: 50%;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 14%);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease 0.15s, background 0.2s ease;
}

.gsslb-prev {
  left: 16px;
}

.gsslb-next {
  right: 16px;
}

.gsslb.is-open .gsslb-caption,
.gsslb.is-open .gsslb-counter,
.gsslb.is-open .gsslb-nav {
  opacity: 1;
}

.gsslb-nav:hover,
.gsslb-nav:focus-visible {
  background: rgb(255 255 255 / 28%);
  outline: none;
}

.gsslb-nav:focus-visible {
  box-shadow: 0 0 0 3px #4b96e6;
}

@media (max-width: 600px) {
  .gsslb-nav {
    top: auto;
    bottom: 16px;
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  img.gsslb-zoomable,
  .gsslb-img-hint,
  .gsslb-caption,
  .gsslb-counter,
  .gsslb-nav,
  a.gsslb-video .gsslb-video-thumb,
  a.gsslb-video .gsslb-video-play,
  a.gsslb-video .gsslb-hint,
  .gsslb-backdrop,
  .gsslb-stage,
  .gsslb-stage-image,
  .gsslb-zoom,
  .gsslb-close {
    transition: none !important;
  }
}
