/* 林平摄影小站 · 作品集展示层
 * 默认：等格网格（uniform grid）——每格同尺寸、同间距，行列严格对齐，
 *       宽幅占两格、全景长卷独占一整行，格线始终成一条直线。
 * 备选：网址加 ?view=rows 回到「等高满宽行」（gallery.js 加 .is-justified 才生效）。
 * 全屏灯箱与两种布局共用。
 */

/* ========== 一、等格网格（默认） ========== */
body[data-page="gallery"] .masonry {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-flow: row dense;      /* 宽幅留出的空格由后面的单格补上 */
  align-items: start;
  gap: 14px;
  columns: auto;                  /* 关掉 style.css 里的多列瀑布流 */
  column-gap: 0;
  counter-reset: ph;              /* 格号 01、02…… */
}
body[data-page="gallery"] .masonry .ph {
  margin: 0;
  width: auto;
  height: auto;
  break-inside: auto;
  aspect-ratio: 1 / 1;            /* 正方格：竖图横图都只裁两成，格线最干净 */
  background: var(--surface);
  counter-increment: ph;
}
body[data-page="gallery"] .masonry .ph a { display: block; width: 100%; height: 100%; }
body[data-page="gallery"] .masonry .ph img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  transition: transform .6s cubic-bezier(.2, .6, .3, 1);
}
body[data-page="gallery"] .masonry .ph:hover img { transform: scale(1.035); }
/* 宽幅（约 16:9 ~ 2:1）：占两格，比例 2:1 */
body[data-page="gallery"] .masonry .ph--w2 { grid-column: span 2; aspect-ratio: 2 / 1; }
/* 全景长卷（≥2.5:1）：独占整行，撑满版心 */
body[data-page="gallery"] .masonry .ph--w4 { grid-column: 1 / -1; aspect-ratio: 4 / 1; }

/* 格号：像印样的张次，只在指到时出现，平时不打扰画面 */
body[data-page="gallery"] .masonry .ph::after {
  content: counter(ph, decimal-leading-zero);
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  padding: 6px 9px 7px;
  font-size: 11px;
  letter-spacing: .14em;
  font-variant-numeric: tabular-nums;
  color: rgba(247, 243, 240, .92);
  background: rgba(20, 18, 16, .56);
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
}
body[data-page="gallery"] .masonry .ph:hover::after { opacity: 1; }

/* 盘面：桌面四格 → 平板三格 → 手机两格 */
@media (max-width: 1199px) {
  body[data-page="gallery"] .masonry { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  body[data-page="gallery"] .masonry .ph--w4 { aspect-ratio: 3 / 1; }
}
@media (max-width: 760px) {
  body[data-page="gallery"] .masonry { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  body[data-page="gallery"] .masonry .ph--w2 { grid-column: span 2; aspect-ratio: 2 / 1; }
  body[data-page="gallery"] .masonry .ph--w4 { aspect-ratio: 12 / 5; }
  /* 手机没有 hover，格号常显但压淡，避免抢画面 */
  body[data-page="gallery"] .masonry .ph::after { opacity: .5; font-size: 10px; padding: 4px 6px; }
}

/* ---------- 等高满宽行：每行铺满、按原图比例、不裁切 ---------- */
body[data-page="gallery"] .masonry.is-justified {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  columns: auto;
  column-gap: 0;
}
body[data-page="gallery"] .masonry.is-justified .ph {
  margin: 0;
  flex: 0 0 auto;
  break-inside: auto;
  width: calc(33.333% - 6px);
  aspect-ratio: 4 / 3;            /* JS 算出精确尺寸前的兜底，避免布局跳动 */
  background: #e9e3dd;
  border-radius: 2px;
}
body[data-page="gallery"] .masonry.is-justified .ph a {
  display: block;
  width: 100%;
  height: 100%;
}
body[data-page="gallery"] .masonry.is-justified .ph img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;              /* 行高已按原图比例算出，实际不裁切 */
  transition: transform .55s cubic-bezier(.2, .6, .3, 1);
}
body[data-page="gallery"] .masonry.is-justified .ph:hover img {
  transform: scale(1.04);
}
body[data-page="gallery"] .masonry.is-justified .ph__ov {
  padding: 12px 14px;
  background: linear-gradient(to top, rgba(14, 12, 11, .86), rgba(14, 12, 11, .04) 70%);
}
body[data-page="gallery"] .masonry.is-justified .ph__ov h4 { font-size: 15px; }

/* 触屏没有 hover，信息常显，避免手机上看不到标题 */
@media (hover: none) {
  body[data-page="gallery"] .masonry.is-justified .ph__ov {
    opacity: 1;
    background: linear-gradient(to top, rgba(14, 12, 11, .72), rgba(14, 12, 11, 0) 58%);
  }
}

/* ---------- 全屏灯箱 ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: none;
  color: #f3eee9;
  background: rgba(12, 11, 10, .975);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  grid-template-columns: 76px minmax(0, 1fr) 76px;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.viewer.open { display: grid; }
/* 灯箱打开时锁住背景交互，避免触屏误点或键盘聚焦到后面的筛选栏 */
body.viewer-open #site-header,
body.viewer-open .filters,
body.viewer-open .masonry,
body.viewer-open .sec--page > .wrap > .small { pointer-events: none; }
.viewer__top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}
.viewer__count {
  font-size: 12px;
  letter-spacing: .22em;
  color: #a9a199;
  font-variant-numeric: tabular-nums;
}
.viewer__close {
  border: 0;
  background: none;
  color: #f3eee9;
  font-size: 13px;
  letter-spacing: .1em;
  cursor: pointer;
  opacity: .8;
}
.viewer__close:hover { opacity: 1; }
.viewer__nav {
  grid-row: 2;
  align-self: center;
  justify-self: center;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 50%;
  background: transparent;
  color: #f3eee9;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  transition: background .2s ease;
}
.viewer__nav:hover { background: rgba(255, 255, 255, .14); }
.viewer__nav--prev { grid-column: 1; }
.viewer__nav--next { grid-column: 3; }
.viewer__stage {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.viewer__stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
}
.viewer__foot {
  grid-column: 1 / -1;
  display: flex;
  gap: 24px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px 24px 26px;
}
.viewer__txt h3 { margin: 0 0 6px; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.viewer__txt p { margin: 0 0 4px; font-size: 14px; color: #d6cec6; }
.viewer__txt small { font-size: 12px; letter-spacing: .1em; color: #9b928a; }
.viewer__more {
  flex: none;
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, .36);
  border-radius: 2px;
  color: #f3eee9;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.viewer__more:hover { background: rgba(255, 255, 255, .12); }

@media (max-width: 640px) {
  .viewer { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .viewer__top { padding: 12px 14px; }
  .viewer__nav { width: 38px; height: 38px; font-size: 24px; }
  .viewer__foot { flex-direction: column; align-items: flex-start; gap: 12px; padding: 12px 16px 20px; }
  .viewer__txt h3 { font-size: 17px; }
  .viewer__txt p { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  body[data-page="gallery"] .masonry.is-justified .ph img { transition: none; }
  body[data-page="gallery"] .masonry.is-justified .ph:hover img { transform: none; }
}
