.media-gallery-panel {
  grid-column: 1 / -1;
}

.media-gallery-stage {
  min-height: 0;
}

.media-gallery {
  width: min(100%, 860px);
  margin: 0 auto;
}

.gallery-mosaic {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 2px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 16px 36px rgba(15, 20, 25, 0.14);
}

.gallery-mosaic--1 .gallery-mosaic-item {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
}

.gallery-mosaic--2 .gallery-mosaic-item {
  grid-row: 1 / -1;
}

.gallery-mosaic--3 .gallery-mosaic-item:first-child {
  grid-row: 1 / -1;
}

.gallery-mosaic-item {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #05080b;
}

.gallery-mosaic-item--photo {
  cursor: zoom-in;
}

.gallery-mosaic-item[data-requested="true"] {
  z-index: 1;
  box-shadow: inset 0 0 0 3px var(--x-blue);
}

.gallery-mosaic-item:focus-visible {
  z-index: 2;
  outline: 3px solid var(--x-blue);
  outline-offset: -3px;
}

.gallery-mosaic-image,
.gallery-mosaic-video {
  display: block;
  width: 100%;
  height: 100%;
  background: #05080b;
  object-fit: cover;
}

.gallery-mosaic-image {
  opacity: 0;
  transition: opacity 180ms ease-out;
}

.gallery-mosaic-image.is-loaded {
  opacity: 1;
}

/* iOS 在无 controls 时仍可能绘制原生启动按钮，预览态只保留站内控件。 */
.gallery-mosaic-video:not([controls])::-webkit-media-controls,
.gallery-mosaic-video:not([controls])::-webkit-media-controls-overlay-play-button,
.gallery-mosaic-video:not([controls])::-webkit-media-controls-start-playback-button {
  display: none !important;
}

.gallery-mosaic-play {
  position: absolute;
  z-index: 2;
  inset: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.gallery-mosaic-play::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(40px, 6vw, 54px);
  height: clamp(40px, 6vw, 54px);
  border: 3px solid white;
  border-radius: 50%;
  background: var(--x-blue);
  box-shadow: 0 8px 22px rgba(15, 20, 25, 0.28);
  content: "";
  transform: translate(-50%, -50%);
}

.gallery-mosaic-play::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 12px solid white;
  content: "";
  transform: translate(-35%, -50%);
}

.gallery-mosaic-play[hidden] {
  display: none;
}

.gallery-mosaic-play-label {
  position: absolute;
  bottom: 6px;
  left: 50%;
  max-width: calc(100% - 12px);
  padding: 2px 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(15, 20, 25, 0.76);
  color: white;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}

.gallery-mosaic-play-label[hidden] {
  display: none;
}

.gallery-mosaic-play:hover::before {
  background: #1688d4;
}

.gallery-mosaic-expand {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(15, 20, 25, 0.72);
  color: white;
  font-size: 18px;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.gallery-mosaic-expand:hover {
  background: rgba(29, 155, 240, 0.92);
}

.gallery-mosaic-expand[hidden] {
  display: none;
}

.gallery-mosaic-status {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  padding: 18px;
  place-items: center;
  background: linear-gradient(145deg, #172a3a, #0b1117);
  color: rgba(255, 255, 255, 0.86);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.gallery-mosaic-status[hidden] {
  display: none;
}

.gallery-mosaic-status[data-state="error"] {
  color: #fff;
}

.gallery-mosaic-overflow {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 20, 25, 0.58);
  color: white;
  font-size: 28px;
  font-weight: 800;
  pointer-events: none;
}

/* 放大预览使用浏览器顶层对话框，避免受卡片尺寸和页面滚动影响。 */
.gallery-lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #000;
  color: white;
}

.gallery-lightbox::backdrop {
  background: rgba(0, 0, 0, 0.96);
}

.gallery-lightbox-shell {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}

.gallery-lightbox-stage {
  position: absolute;
  inset: 0;
  display: grid;
  padding: 58px clamp(58px, 6vw, 92px) 64px;
  place-items: center;
}

.gallery-lightbox-slide {
  position: absolute;
  inset: 58px clamp(58px, 6vw, 92px) 64px;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
}

.gallery-lightbox-slide[hidden],
.gallery-lightbox-media[hidden],
.gallery-lightbox-error[hidden] {
  display: none;
}

.gallery-lightbox-media {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: #000;
  object-fit: contain;
}

.gallery-lightbox-error {
  display: flex;
  max-width: 320px;
  padding: 24px;
  align-items: center;
  flex-direction: column;
  gap: 14px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.gallery-lightbox-error a {
  display: inline-flex;
  min-height: 42px;
  padding: 9px 16px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(29, 155, 240, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.gallery-lightbox-error a:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.gallery-lightbox-close,
.gallery-lightbox-nav {
  position: absolute;
  z-index: 3;
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(15, 20, 25, 0.7);
  color: white;
  font-size: 26px;
  line-height: 1;
  backdrop-filter: blur(10px);
}

.gallery-lightbox-close {
  top: 14px;
  left: 14px;
  font-size: 24px;
}

.gallery-lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
}

.gallery-lightbox-nav--previous {
  left: 12px;
}

.gallery-lightbox-nav--next {
  right: 12px;
}

.gallery-lightbox-close:hover,
.gallery-lightbox-nav:hover:not(:disabled) {
  background: rgba(29, 155, 240, 0.92);
}

.gallery-lightbox-nav:disabled {
  visibility: hidden;
}

.gallery-lightbox-index {
  position: absolute;
  top: 17px;
  left: 50%;
  z-index: 3;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(15, 20, 25, 0.72);
  color: rgba(255, 255, 255, 0.9);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.gallery-source {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.gallery-source strong {
  color: var(--ink);
}

.gallery-source a {
  flex: 0 0 auto;
  color: var(--x-blue);
  font-weight: 700;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  .gallery-mosaic-image {
    transition: none;
  }
}
