/**
 * 文章图片灯箱
 *
 * 工具型组件：只保留浏览图片所需的遮罩、导航与说明。
 * 使用中性黑白色，不跟随文章主题色，也不做装饰性光晕。
 */

.iro-lightbox {
  --iro-lb-ease: cubic-bezier(0.22, 0.8, 0.3, 1);
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: inherit;
  line-height: 1.5;
  text-align: initial;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.iro-lightbox[hidden] {
  display: none !important;
}

.iro-lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

/* 中性遮罩；只做背景压暗，不叠加主题色或装饰光效 */
.iro-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.iro-lightbox__stage {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: clamp(56px, 8vh, 84px) clamp(44px, 7vw, 96px) clamp(20px, 4vh, 40px);
  box-sizing: border-box;
  overflow: hidden;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.iro-lightbox.is-open .iro-lightbox__stage {
  opacity: 1;
}

.iro-lightbox__topbar {
  position: absolute;
  top: clamp(12px, 2.5vh, 20px);
  right: clamp(12px, 2.5vw, 24px);
  left: clamp(12px, 2.5vw, 24px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.iro-lightbox__topbar > * {
  pointer-events: auto;
}

/* 计数是说明文字，不做胶囊容器 */
.iro-lightbox__counter {
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 按钮默认透明，仅在悬停/聚焦时出现中性底色 */
.iro-lightbox__close,
.iro-lightbox__nav {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  color: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.iro-lightbox__close {
  width: 44px;
  height: 44px;
}

.iro-lightbox__close:hover,
.iro-lightbox__close:focus,
.iro-lightbox__close:focus-visible,
.iro-lightbox__close:active,
.iro-lightbox__nav:hover,
.iro-lightbox__nav:focus,
.iro-lightbox__nav:focus-visible,
.iro-lightbox__nav:active {
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
  color: #fff;
}

.iro-lightbox__close:focus-visible,
.iro-lightbox__nav:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.92);
  outline-offset: 2px;
}

.iro-lightbox svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.iro-lightbox__nav {
  position: absolute;
  top: 50%;
  z-index: 4;
  width: 52px;
  height: 52px;
  transform: translateY(-50%);
}

.iro-lightbox__nav--prev {
  left: clamp(8px, 2vw, 24px);
}

.iro-lightbox__nav--next {
  right: clamp(8px, 2vw, 24px);
}

.iro-lightbox__nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.iro-lightbox.is-single .iro-lightbox__nav {
  opacity: 0;
  pointer-events: none;
}

.iro-lightbox__figure {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.5vh, 14px);
  max-width: 100%;
  max-height: 100%;
  margin: 0;
}

.iro-lightbox__frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 160px;
  min-height: 120px;
  max-width: 100%;
}

/* 原图完整展示：直角、无阴影、无背景装饰 */
.iro-lightbox__image {
  display: block;
  width: auto;
  height: auto;
  max-width: min(1180px, calc(100vw - clamp(88px, 14vw, 192px)));
  max-height: calc(100vh - 180px);
  max-height: calc(100dvh - 180px);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  transform: translate3d(var(--iro-lb-pan-x, 0px), var(--iro-lb-pan-y, 0px), 0)
    scale(var(--iro-lb-zoom, 1));
  transform-origin: 50% 50%;
  transition: opacity 0.2s ease, transform 0.2s var(--iro-lb-ease);
  cursor: zoom-in;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  will-change: transform;
}

.iro-lightbox__image.is-ready {
  opacity: 1;
}

.iro-lightbox__image.is-zoomed {
  cursor: grab;
}

.iro-lightbox__image.is-dragging {
  cursor: grabbing;
  transition: opacity 0.2s ease;
}

.iro-lightbox__image.is-error {
  opacity: 0;
}

.iro-lightbox__spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  animation: iro-lb-spin 0.75s linear infinite;
}

.iro-lightbox__frame.is-loading .iro-lightbox__spinner {
  opacity: 1;
}

@keyframes iro-lb-spin {
  to {
    transform: rotate(360deg);
  }
}

/* 错误提示同样保持纯文字，不加卡片装饰 */
.iro-lightbox__error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 240px;
  min-height: 140px;
  padding: 24px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 14px;
  text-align: center;
}

.iro-lightbox__error[hidden] {
  display: none !important;
}

/* 标题是辅助信息，直接排在图片下方 */
.iro-lightbox__caption {
  max-width: min(780px, 86vw);
  max-height: 18vh;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  color: rgba(255, 255, 255, 0.66);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.iro-lightbox__caption:empty {
  display: none;
}

/* 打开灯箱时锁定页面滚动，并补偿滚动条宽度 */
html.iro-lightbox-open {
  overflow: hidden !important;
}

html.iro-lightbox-open body {
  padding-right: var(--iro-lightbox-gutter, 0px);
}

/* 正文图片的可点击提示；只保留功能性的光标和键盘焦点 */
.entry-content img[data-iro-lightbox="ready"] {
  cursor: zoom-in;
}

.entry-content img[data-iro-lightbox="ready"]:focus-visible {
  outline: 2px solid rgba(80, 80, 80, 0.7);
  outline-offset: 4px;
}

body.dark .entry-content img[data-iro-lightbox="ready"]:focus-visible {
  outline-color: rgba(255, 255, 255, 0.72);
}

@media (max-width: 720px) {
  .iro-lightbox__stage {
    padding: 54px 8px 16px;
  }

  .iro-lightbox__topbar {
    top: 8px;
    right: 10px;
    left: 10px;
  }

  .iro-lightbox__counter {
    font-size: 11px;
  }

  .iro-lightbox__close {
    width: 40px;
    height: 40px;
  }

  .iro-lightbox__nav {
    width: 42px;
    height: 42px;
    background: rgba(0, 0, 0, 0.36);
  }

  .iro-lightbox__nav:hover {
    background: rgba(0, 0, 0, 0.52);
  }

  .iro-lightbox__nav--prev {
    left: 4px;
  }

  .iro-lightbox__nav--next {
    right: 4px;
  }

  .iro-lightbox__image {
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 150px);
    max-height: calc(100dvh - 150px);
  }

  .iro-lightbox__caption {
    max-width: calc(100vw - 24px);
    font-size: 12.5px;
  }
}

@media (max-height: 520px) {
  .iro-lightbox__stage {
    padding-top: 52px;
    padding-bottom: 10px;
  }

  .iro-lightbox__caption {
    max-height: 16vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .iro-lightbox,
  .iro-lightbox__stage,
  .iro-lightbox__image,
  .iro-lightbox__close,
  .iro-lightbox__nav {
    transition: none !important;
  }

  .iro-lightbox__spinner {
    animation-duration: 1.6s;
  }
}
