/* ===========================================================================
   图库（/gallery/ 与 /gallery/<slug>/）
   只在这两类页面通过 front matter 的 caseStyle 加载，不进全站 hope.css。
   颜色、字体、圆角一律用模板既有的变量，保证和 Blog / Nav 是同一套视觉。
   =========================================================================== */

/* ---------- 工具条：搜索 + 分类 + 标签 ---------- */

.hope-gallery-toolbar {
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  margin-bottom: 4rem;
}

.hope-gallery-search {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  max-width: 52rem;
  border: 1px solid var(--st-medium);
  border-radius: 99rem;
  padding: 1.1rem 2rem;
  background: rgba(128, 128, 128, 0.06);
  transition: border-color 0.2s ease;
}

.hope-gallery-search:focus-within {
  border-color: var(--t-bright);
}

.hope-gallery-search__icon {
  font-size: 1.8rem;
  line-height: 1;
  color: var(--t-medium);
}

.hope-gallery-search input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--t-bright);
  font: normal 500 1.5rem/1.4 var(--_font-default);
}

.hope-gallery-search input:focus {
  outline: none;
}

/* search 类型输入框在 WebKit 上自带一个清除按钮，配色和站点对不上 */
.hope-gallery-search input::-webkit-search-cancel-button {
  filter: grayscale(1) opacity(0.5);
}

.hope-gallery-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.hope-gallery-filters button {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--st-medium);
  border-radius: 99rem;
  padding: 0.9rem 1.5rem;
  background: rgba(128, 128, 128, 0.06);
  color: var(--t-medium);
  font: normal 500 1.4rem/1 var(--_font-default);
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.hope-gallery-filters button:hover {
  border-color: var(--t-medium);
  color: var(--t-bright);
}

/* is-active 用 --base 当文字色（不是写死白），暗色模式下才不会糊 —— 同 .hope-nav-filter */
.hope-gallery-filters button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--base);
}

.hope-gallery-filters.is-tags button {
  padding: 0.7rem 1.2rem;
  font-family: var(--_font-accent);
  font-size: 1.2rem;
}

.hope-gallery-tags {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.2rem;
}

.hope-gallery-tags__list {
  width: 100%;
}

.hope-gallery-tags.is-collapsed .hope-gallery-tags__list button:nth-child(n + 13) {
  display: none;
}

.hope-gallery-tags__toggle {
  border: 1px solid var(--st-medium);
  border-radius: 99rem;
  padding: 0.7rem 1.2rem;
  background: transparent;
  color: var(--t-medium);
  font: 500 1.2rem/1 var(--_font-accent);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.hope-gallery-tags__toggle:hover {
  border-color: var(--t-medium);
  color: var(--t-bright);
}

.hope-gallery-filters__count {
  font-family: var(--_font-accent);
  font-size: 1.1rem;
  opacity: 0.7;
}

.hope-gallery-count {
  margin: 0;
  font: 500 1.2rem/1.4 var(--_font-accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--t-medium);
}

/* ---------- 网格与卡片 ---------- */

.hope-gallery-grid {
  columns: 5 20rem;
  column-gap: 2rem;
}

@media only screen and (max-width: 1199px) {
  .hope-gallery-grid {
    columns: 4 18rem;
  }
}

.hope-gallery-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  break-inside: avoid;
  margin: 0 0 3.2rem;
  border: 1px solid var(--st-medium);
  border-radius: 1.2rem;
  overflow: hidden;
  background: var(--base);
  transition: transform 0.3s var(--_animbezier), border-color 0.3s ease;
}

.hope-gallery-card:hover {
  transform: translateY(-0.6rem);
  border-color: var(--t-medium);
}

.hope-gallery-card__stack {
  overflow: hidden;
}

.hope-gallery-card__media {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--base-opp);
}

.hope-gallery-card__media img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  transition: transform 0.7s var(--_animbezier);
}

.hope-gallery-card:hover .hope-gallery-card__media img {
  transform: scale(1.04);
}

.hope-gallery-card__hover {
  position: absolute;
  right: 1.2rem;
  bottom: 1.2rem;
  display: flex;
  gap: 0.6rem;
  border-radius: 99rem;
  padding: 0.6rem 1.2rem;
  background: var(--base);
  color: var(--t-bright);
  font: 500 1.2rem/1 var(--_font-accent);
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(0.6rem);
  transition: opacity 0.3s ease, transform 0.3s var(--_animbezier);
}

.hope-gallery-card:hover .hope-gallery-card__hover {
  opacity: 1;
  transform: translateY(0);
}

/* 组里几张：常驻显示，不等 hover。移动端没有 hover，
   不常驻就完全看不出这张卡片底下还有别的图。 */
.hope-gallery-card__count {
  position: absolute;
  top: 1.2rem;
  left: 1.2rem;
  border-radius: 99rem;
  padding: 0.5rem 1rem;
  background: color-mix(in srgb, var(--base) 82%, transparent);
  backdrop-filter: blur(6px);
  color: var(--t-bright);
  font: 500 1.1rem/1 var(--_font-accent);
  letter-spacing: 0.04em;
}

/* 同组其余图：封面下面一排，最多 3 张。
   底格用 6 列，按实际张数 span 6 / 3 / 2 —— 1~3 张都铺满整行、不留空格，
   而高度始终由 __stack 那一行定死，跟张数无关。
   （用「数量查询」选择器，模板和 renderCard 两边都不用加 class。） */
.hope-gallery-card__strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding-top: 2px;
  min-height: 0;
  background: var(--st-medium);
}

.hope-gallery-card__shot {
  grid-column: span 2; /* 3 张 */
}

/* 只有 1 张 */
.hope-gallery-card__shot:first-child:nth-last-child(1) {
  grid-column: span 6;
}

/* 只有 2 张 */
.hope-gallery-card__shot:first-child:nth-last-child(2),
.hope-gallery-card__shot:first-child:nth-last-child(2) ~ .hope-gallery-card__shot {
  grid-column: span 3;
}

.hope-gallery-card__shot {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  min-height: 0;
  overflow: hidden;
  background: var(--base-opp);
}

@media only screen and (max-width: 767px) {
  .hope-gallery-grid {
    columns: 1;
  }
}

.hope-gallery-card__shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.82;
  transition: opacity 0.3s ease, transform 0.5s var(--_animbezier);
}

.hope-gallery-card__shot:hover img {
  opacity: 1;
  transform: scale(1.06);
}

/* 超过 4 张时盖在最后一格上：+N。盖住的那张仍然可点，点进去就从它开始翻。 */
.hope-gallery-card__more {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--base) 62%, transparent);
  color: var(--t-bright);
  font: 500 1.6rem/1 var(--_font-accent);
}

/* 卡片正文只有标题和一行元信息 —— prompt 不上卡片，看图时不被文字挤掉 */
.hope-gallery-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1.8rem 2rem 2rem;
}

.hope-gallery-card__title {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.hope-gallery-card__title a {
  color: inherit;
  text-decoration: none;
}

.hope-gallery-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  margin-top: auto;
  padding-top: 0.6rem;
  font-family: var(--_font-accent);
  font-size: 1.2rem;
  text-transform: uppercase;
  color: var(--t-medium);
}

.hope-gallery-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--st-medium);
  border-radius: 99rem;
  padding: 0.7rem 1.3rem;
  background: transparent;
  color: var(--t-medium);
  font: 500 1.2rem/1 var(--_font-accent);
  text-transform: uppercase;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.hope-gallery-copy:hover {
  border-color: var(--t-bright);
  color: var(--t-bright);
}

.hope-gallery-copy.is-done {
  border-color: var(--accent);
  color: var(--accent);
}

.hope-gallery-empty {
  padding: 6rem 0;
  font-size: 1.8rem;
  color: var(--t-medium);
}

.hope-gallery-sentinel {
  height: 1px;
  margin-top: 4rem;
}

.hope-gallery-sentinel.is-loading::after {
  content: "Loading…";
  display: block;
  padding: 2rem 0;
  font: 500 1.2rem/1 var(--_font-accent);
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--t-medium);
}

/* ---------- 详情页 ---------- */

.hope-gallery-detail {
  display: grid;
  gap: 4rem;
}

/* 一组几张就竖着摆几张，原图比例不裁 —— 详情页是唯一能看到全尺寸的地方 */
.hope-gallery-detail__media {
  display: grid;
  gap: 2rem;
}

.hope-gallery-detail__shot {
  position: relative;
  margin: 0;
  border: 1px solid var(--st-medium);
  border-radius: 1.2rem;
  overflow: hidden;
  background: var(--base-opp);
}

.hope-gallery-detail__shot img {
  display: block;
  width: 100%;
  height: auto;
}

.hope-gallery-detail__shot figcaption {
  position: absolute;
  top: 1.2rem;
  left: 1.2rem;
  border-radius: 99rem;
  padding: 0.5rem 1rem;
  background: color-mix(in srgb, var(--base) 82%, transparent);
  backdrop-filter: blur(6px);
  color: var(--t-medium);
  font: 500 1.1rem/1 var(--_font-accent);
}

.hope-gallery-detail__body {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.hope-gallery-detail__title {
  margin: 0;
  font-size: clamp(3rem, 4vw, 5.4rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.hope-gallery-detail__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hope-gallery-detail__tags a {
  display: inline-block;
  border: 1px solid var(--st-medium);
  border-radius: 99rem;
  padding: 0.6rem 1.2rem;
  color: var(--t-medium);
  font: 500 1.2rem/1 var(--_font-accent);
  text-decoration: none;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.hope-gallery-detail__tags a:hover {
  border-color: var(--t-bright);
  color: var(--t-bright);
}

.hope-gallery-detail__prompt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.6rem;
  margin-bottom: 1.2rem;
}

.hope-gallery-detail__prompt h2,
.hope-gallery-detail__note h2 {
  margin: 0;
  font: 500 1.3rem/1 var(--_font-accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--t-medium);
}

/* prompt 用 pre 保留原始换行，但要能自动折行，不能横向撑爆容器 */
.hope-gallery-detail__prompt-body {
  margin: 0;
  border: 1px solid var(--st-medium);
  border-radius: 1.2rem;
  padding: 2.4rem;
  background: rgba(128, 128, 128, 0.06);
  color: var(--t-bright);
  font: 400 1.4rem/1.75 var(--_font-accent);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.hope-gallery-detail__note p {
  margin: 1.2rem 0 0;
  color: var(--t-medium);
}

.hope-gallery-detail__back {
  display: inline-flex;
  gap: 0.8rem;
  margin-top: 1.6rem;
  color: var(--t-medium);
  font: 500 1.3rem/1 var(--_font-accent);
  text-decoration: none;
  text-transform: uppercase;
}

.hope-gallery-detail__back:hover {
  color: var(--t-bright);
}

@media only screen and (min-width: 992px) {
  .hope-gallery-detail {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    align-items: start;
    gap: 4rem;
  }
}

/* ---------- 灯箱 ---------- */

.hope-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1.6rem, 4vw, 4rem);
}

.hope-lightbox[hidden] {
  display: none;
}

.hope-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(0.6rem);
}

.hope-lightbox__frame {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(120rem, 100%);
  max-height: 100%;
  border-radius: 1.2rem;
  overflow: hidden;
  background: var(--base);
}

.hope-lightbox__stage {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 0;
  background: #0b0b0b;
}

.hope-lightbox__stage img {
  display: block;
  max-width: 100%;
  max-height: 62vh;
  object-fit: contain;
}

/* 原图没到位之前先转圈，避免黑屏里什么都没有 */
.hope-lightbox__spinner {
  position: absolute;
  width: 2.8rem;
  height: 2.8rem;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  opacity: 0;
  animation: hope-lightbox-spin 0.8s linear infinite;
}

.hope-lightbox.is-loading .hope-lightbox__spinner {
  opacity: 1;
}

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

@media (prefers-reduced-motion: reduce) {
  .hope-lightbox__spinner { animation: none; }
}

.hope-lightbox__panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 1.2rem;
  overflow-y: scroll;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: 2.4rem;
  border-top: 1px solid var(--st-medium);
}

/* 宽屏改成「图在左、详情在右」：prompt 往往几百字，横排才有地方铺开，
   图也不用为了给文字让位被压到很小。 */
@media only screen and (min-width: 992px) {
  .hope-lightbox__frame {
    flex-direction: row;
    height: min(82vh, 90rem);
  }

  .hope-lightbox__stage {
    flex: 1 1 62%;
    min-width: 0;
  }

  .hope-lightbox__stage img {
    max-height: 100%;
  }

  .hope-lightbox__panel {
    flex: 0 0 38%;
    min-height: 0;
    max-width: 46rem;
    max-height: none;
    border-top: 0;
    border-left: 1px solid var(--st-medium);
  }
}

.hope-lightbox__meta {
  margin: 0;
  font: 500 1.2rem/1.5 var(--_font-accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--t-medium);
}

.hope-lightbox__title {
  margin: 0;
  font-size: 2.4rem;
  line-height: 1.15;
}

/* 同组图的缩略图条。单张的组由 JS 把两个子元素都 hidden 掉，
   :has 让整块跟着塌掉，省得留一段空白（不支持 :has 的浏览器只是多一段间距）。 */
.hope-lightbox__group {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.hope-lightbox__group:has([data-lightbox-shots][hidden]) {
  display: none;
}

.hope-lightbox__counter {
  flex: none;
  font: 500 1.2rem/1 var(--_font-accent);
  letter-spacing: 0.06em;
  color: var(--t-medium);
}

.hope-lightbox__shots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

/* display:flex 会盖掉 hidden 的默认 display:none —— 不写这条，
   单图时那条空的缩略图条还是会占位（老坑，别删）。 */
.hope-lightbox__shots[hidden] {
  display: none;
}

.hope-lightbox__shot {
  width: 6.4rem;
  aspect-ratio: 4 / 3;
  border: 1px solid transparent;
  border-radius: 0.6rem;
  padding: 0;
  overflow: hidden;
  background: var(--base-opp);
  opacity: 0.6;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}

.hope-lightbox__shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hope-lightbox__shot:hover {
  opacity: 1;
}

.hope-lightbox__shot.is-current {
  border-color: var(--accent);
  opacity: 1;
}

.hope-lightbox__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hope-lightbox__tags:empty {
  display: none;
}

.hope-lightbox__tags li {
  border: 1px solid var(--st-medium);
  border-radius: 99rem;
  padding: 0.4rem 1rem;
  font: 500 1.1rem/1 var(--_font-accent);
  color: var(--t-medium);
}

.hope-lightbox__prompt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.6rem;
  margin-top: 0.4rem;
}

.hope-lightbox__prompt-head h3 {
  margin: 0;
  font: 500 1.2rem/1 var(--_font-accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--t-medium);
}

/* prompt 用 pre 保留原始换行，但必须能自动折行，否则长英文提示词会横向撑爆弹层 */
.hope-lightbox__prompt {
  margin: 0;
  border: 1px solid var(--st-medium);
  border-radius: 0.8rem;
  padding: 1.6rem;
  background: rgba(128, 128, 128, 0.06);
  font: 400 1.4rem/1.7 var(--_font-accent);
  color: var(--t-bright);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.hope-lightbox__link {
  display: inline-flex;
  gap: 0.6rem;
  color: var(--t-medium);
  font: 500 1.2rem/1 var(--_font-accent);
  text-decoration: none;
  text-transform: uppercase;
}

.hope-lightbox__link:hover {
  color: var(--t-bright);
}

.hope-lightbox__nav,
.hope-lightbox__close {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4.8rem;
  height: 4.8rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 2.4rem;
  line-height: 1;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.hope-lightbox__nav:hover,
.hope-lightbox__close:hover {
  border-color: #fff;
  background: rgba(0, 0, 0, 0.85);
}

.hope-lightbox__nav {
  top: 50%;
  transform: translateY(-50%);
}

.hope-lightbox__nav.is-prev { left: clamp(0.8rem, 2vw, 2.4rem); }
.hope-lightbox__nav.is-next { right: clamp(0.8rem, 2vw, 2.4rem); }
.hope-lightbox__nav[hidden] { display: none; }

.hope-lightbox__close {
  top: clamp(0.8rem, 2vw, 2.4rem);
  right: clamp(0.8rem, 2vw, 2.4rem);
  font-size: 1.8rem;
}

/* 灯箱打开时锁住背景滚动。Lenis 那边也会 stop()，这条是没拿到实例时的兜底 */
body.hope-lightbox-open {
  overflow: hidden;
}

@media only screen and (max-width: 767px) {
  .hope-lightbox {
    padding: 0;
  }

  .hope-lightbox__frame {
    height: 100%;
    border-radius: 0;
  }

  /* 竖屏是上图下文：图按内容定高，剩下的全给可滚动的详情面板 */
  .hope-lightbox__stage {
    flex: 0 0 auto;
  }

  .hope-lightbox__stage img {
    max-height: 45vh;
  }

  .hope-lightbox__panel {
    flex: 1;
    min-height: 0;
    max-height: none;
    padding: 1.8rem;
  }

  .hope-lightbox__nav {
    width: 4rem;
    height: 4rem;
    font-size: 2rem;
  }
}
