/*!
 * Live Photo 组件样式
 * 由 scripts/livephoto.js 按需注入：只有真正包含 {% livephoto %} 的页面才会加载本文件，
 * 作为静态资源被浏览器缓存，不再内联进每个 HTML。
 */

/* 外层 figure：控制最大宽度与居中 */
.lp-figure {
  display: block;
  width: fit-content;
  max-width: min(100%, var(--lp-max-width, 100%));
  margin: 20px auto;
}

/* 媒体容器：图片 + 视频叠在一起，容器尺寸由静态图决定 */
.lp {
  position: relative;
  display: block;
  max-width: 100%;
  overflow: hidden;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.lp:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.lp:focus-visible {
  outline: 2px solid #ff2e4d;
  outline-offset: 3px;
}

/* 静态封面图（上层）
 * 用 .lp .lp-* 提高优先级：主题的 .markdown-body img 会强制 max-width:80% / margin:auto，
 * 不覆盖的话视频层和图片尺寸会对不上。
 * 叠在视频上层，等视频第一帧真正呈现后才切换（见 JS），
 * 避免“图片先消失、视频还没画出来”时露出白色页面背景。
 *
 * 这里区分两个方向：
 *   - 进入播放：默认 0s 立即切换，否则静态图会叠在已经开始运动的视频上产生重影；
 *     需要柔一点可以用 _config.yml 里的 fade 打开（--lp-fade）。
 *   - 结束/暂停：用 0.2s 淡回静态图（此时视频已经停住，不会重影）。 */
.lp .lp-picture {
  position: relative;
  z-index: 2;
  display: block;
  background: transparent;
  transition: opacity 0.2s ease;
}

.lp .lp-img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0;
  border-radius: 0;
  background: transparent;
}

/* 视频图层：常驻不透明，垫在静态图下面。
 * 不对它做 opacity 动画，避免视频合成层在首帧未就绪时被画成白/透明色。 */
.lp .lp-video {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 1;
  pointer-events: none;
}

.lp.is-playing .lp-picture {
  transition: opacity var(--lp-fade, 0s) ease;
  opacity: 0;
}

/* Live 徽标 */
.lp-badge {
  position: absolute;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.lp-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff2e4d;
}

.lp-badge--bottom-left { bottom: 12px; left: 12px; }
.lp-badge--bottom-right { bottom: 12px; right: 12px; }
.lp-badge--top-left { top: 12px; left: 12px; }
.lp-badge--top-right { top: 12px; right: 12px; }

/* 加载动画 */
.lp-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ff2e4d;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: lp-spin 0.9s linear infinite;
}

.lp.is-loading .lp-spinner {
  opacity: 1;
}

/* 图片说明 */
.lp-caption {
  margin-top: 8px;
  color: inherit;
  opacity: 0.65;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

/* 与 hexo-image-caption 插件共存：动态照片用自己的 figcaption 写说明，
 * 隐藏插件根据 alt 自动插入的说明，避免它撑高容器、被视频层盖住。 */
.lp .image-caption {
  display: none !important;
}

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

@media (max-width: 768px) {
  .lp {
    border-radius: 8px;
  }

  .lp-badge {
    padding: 3px 6px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lp,
  .lp-picture,
  .lp.is-playing .lp-picture {
    transition: none;
  }

  .lp-spinner {
    animation: none;
  }
}
