/* ============================================================
   画廊 — 古典画框 · 自适应长宽比 · Awwwards 风格
   使用 CSS columns 瀑布流，图片以原生比例展示
   ============================================================ */

/* --- Filter Bar --- */
.filter-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 64px;
}

.filter-btn {
  font-family: var(--font-classical);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 24px;
  border: 1px solid transparent;
  transition: color var(--dur-fast) var(--ease-out-expo),
              border-color var(--dur-fast) var(--ease-out-expo),
              background var(--dur-fast) var(--ease-out-expo);
}

.filter-btn:hover {
  color: var(--text-primary);
}

.filter-btn.active {
  color: var(--accent-light);
  border-color: var(--border-gold);
  background: rgba(201, 160, 80, 0.06);
}

/* ============================================================
   Gallery — CSS Columns masonry
   Images display at their natural aspect ratio, frames wrap perfectly
   ============================================================ */
.gallery {
  columns: 4;
  column-gap: 32px;
  max-width: var(--container-max);
  margin: 0 auto;
}

/* --- Gallery Item --- */
.gallery-item {
  break-inside: avoid;
  margin-bottom: 32px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.8s var(--ease-out-expo),
              transform 0.8s var(--ease-out-expo),
              box-shadow 0.6s var(--ease-out-expo);
}

.gallery-item.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
   Classical Picture Frame — 8-Layer Ornate Design
   Reference: 08331912_2.jpg

   Layers:
   1. Outer cream mat (warm paper gradient)
   2. V-groove (pressed channel in mat)          — ::before on inner
   3. Wood frame outer bevel (dark edge)         — box-shadow outset
   4. Wood frame face (rich mahogany gradient)
   5. Carved inner channel (deep shadow groove)  — box-shadow inset
   6. Inner cove (concave shadow transition)
   7. Gold fillet (inner gilt line)              — border on frame-inner
   8. Shadow recess → image
   ============================================================ */

/* --- Layer 1: Cream mat with warm paper texture --- */
.gallery-item-inner {
  position: relative;
  width: 100%;
  background: linear-gradient(175deg,
    #faf7f0 0%,
    #f6f0e4 30%,
    #f8f3eb 60%,
    #f4ede0 100%
  );
  padding: 16px 16px 44px 16px;            /* Wider mat: 16px top/sides, extra bottom for caption */
  box-shadow:
    0 2px 8px rgba(0,0,0,0.45),
    0 10px 30px rgba(0,0,0,0.3),
    0 1px 0 rgba(255,255,255,0.15),
    inset 0 0 0 1px rgba(0,0,0,0.03);
  border-radius: 1px;
  transition: box-shadow 0.6s var(--ease-out-expo),
              transform 0.6s var(--ease-out-expo);
}

.gallery-item:hover .gallery-item-inner {
  box-shadow:
    0 4px 20px rgba(0,0,0,0.55),
    0 14px 44px rgba(180, 130, 80, 0.14),
    0 1px 0 rgba(255,255,255,0.15),
    inset 0 0 0 1px rgba(0,0,0,0.03);
  transform: translateY(-4px);
}

/* --- Layer 2: V-groove — pressed channel in the mat --- */
.gallery-item-inner::before {
  content: '';
  position: absolute;
  inset: 16px;                              /* Aligns with frame outer edge */
  border: 1px solid rgba(160, 140, 110, 0.3);
  box-shadow:
    inset 0 1px 2px rgba(0,0,0,0.08),      /* Shadow inside groove */
    0 1px 0 rgba(255,255,255,0.4);          /* Highlight outside groove */
  pointer-events: none;
  z-index: 0;                               /* Below wood frame */
}

/* --- Layer 3-5: Rich mahogany wood frame with carved grooves --- */
.gallery-frame-outer {
  position: relative;
  z-index: 1;                                /* Above V-groove */
  width: 100%;
  padding: 10px;                             /* Slightly thicker frame */
  background: linear-gradient(160deg,
    #c8a878 0%,
    #b89060 6%,
    #a07848 12%,
    #785028 20%,
    #604020 27%,
    #8a5a30 33%,
    #b88040 40%,
    #d4a850 47%,
    #e0b858 50%,
    #d4a850 53%,
    #a87038 60%,
    #684828 68%,
    #503018 74%,
    #785028 80%,
    #a08050 88%,
    #c0a070 94%,
    #c8a878 100%
  );
  box-shadow:
    /* Outer bevel highlight */
    inset 1px 1px 2px rgba(255,255,255,0.2),
    inset 2px 2px 4px rgba(255,240,210,0.08),
    /* Inner carved channel shadow */
    inset -2px -2px 4px rgba(0,0,0,0.5),
    inset -3px -3px 6px rgba(0,0,0,0.25),
    /* Outer depth */
    0 2px 4px rgba(0,0,0,0.3),
    0 1px 0 rgba(255,255,255,0.05);
  transition: box-shadow 0.6s var(--ease-out-expo);
}

.gallery-item:hover .gallery-frame-outer {
  box-shadow:
    inset 1px 1px 2px rgba(255,255,255,0.25),
    inset 2px 2px 5px rgba(255,240,210,0.12),
    inset -2px -2px 4px rgba(0,0,0,0.55),
    inset -3px -3px 7px rgba(0,0,0,0.3),
    0 0 20px rgba(180, 140, 80, 0.15),
    0 4px 14px rgba(0,0,0,0.35),
    0 1px 0 rgba(255,255,255,0.05);
}

/* --- Layer 6-7: Inner cove shadow + gold fillet --- */
.gallery-frame-inner {
  width: 100%;
  overflow: hidden;
  position: relative;
  border: 2px solid rgba(201, 160, 80, 0.45);   /* Gold inner fillet */
  background: #0d0b08;
  box-shadow:
    /* Deep shadow recess transitioning from gold fillet */
    inset 0 0 2px rgba(0,0,0,0.6),
    inset 0 0 8px rgba(0,0,0,0.45),
    inset 0 0 20px rgba(0,0,0,0.2),
    /* Subtle warm glow from gold fillet onto image */
    inset 0 0 3px rgba(201, 160, 80, 0.15);
  line-height: 0;
  transition: border-color 0.6s var(--ease-out-expo),
              box-shadow 0.6s var(--ease-out-expo);
}

.gallery-item:hover .gallery-frame-inner {
  border-color: rgba(224, 200, 120, 0.65);
  box-shadow:
    inset 0 0 2px rgba(0,0,0,0.6),
    inset 0 0 10px rgba(0,0,0,0.5),
    inset 0 0 24px rgba(0,0,0,0.25),
    inset 0 0 4px rgba(201, 160, 80, 0.2);
}

/* --- Layer 8: Image --- */
.gallery-item img {
  display: block;
  width: 100%;
  height: auto;                              /* Natural aspect ratio */
  background: #0d0b08;
  transition: transform 1.2s var(--ease-out-expo),
              filter 1.2s var(--ease-out-expo);
  filter: brightness(0.88) saturate(0.75) contrast(1.03);
}

.gallery-item:hover img {
  transform: scale(1.02);
  filter: brightness(1) saturate(0.9) contrast(1.02);
}

/* --- Ornate corner accents — gold L-brackets on wood frame --- */
.gallery-frame-outer::before,
.gallery-frame-outer::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.6s var(--ease-out-expo),
              border-color 0.6s var(--ease-out-expo),
              box-shadow 0.6s var(--ease-out-expo);
}

.gallery-frame-outer::before {
  top: 3px; left: 3px;
  border-top: 2px solid rgba(220, 190, 120, 0.55);
  border-left: 2px solid rgba(220, 190, 120, 0.55);
  box-shadow: -1px -1px 2px rgba(0,0,0,0.2);
  opacity: 0.6;
}

.gallery-frame-outer::after {
  bottom: 3px; right: 3px;
  border-bottom: 2px solid rgba(220, 190, 120, 0.55);
  border-right: 2px solid rgba(220, 190, 120, 0.55);
  box-shadow: 1px 1px 2px rgba(0,0,0,0.2);
  opacity: 0.6;
}

.gallery-item:hover .gallery-frame-outer::before,
.gallery-item:hover .gallery-frame-outer::after {
  opacity: 0.9;
  border-color: rgba(240, 215, 150, 0.8);
  box-shadow: 0 0 6px rgba(201, 160, 80, 0.3);
}

/* --- Caption on the mat (bottom margin area) --- */
.gallery-caption {
  position: absolute;
  bottom: 6px;
  left: 14px;
  right: 14px;
  text-align: center;
  z-index: 3;
  pointer-events: none;
}

.gallery-caption-loc {
  font-family: var(--font-classical);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: #6b5a3a;
  text-transform: uppercase;
  transition: color 0.6s;
}

.gallery-item:hover .gallery-caption-loc {
  color: #3a2a10;
}

/* --- Loading shimmer --- */
.gallery-item.loading .gallery-item-inner {
  background: var(--bg-surface);
}

.gallery-item.loading .gallery-frame-outer {
  background: var(--bg-elevated);
}

.gallery-item.loading::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.02) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s infinite;
  z-index: 5;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* --- View More --- */
.gallery-more {
  text-align: center;
  margin-top: 64px;
}

/* ============================================================
   灯箱 — 沉浸式全屏浏览
   使用真实 DOM 嵌套替代伪元素，确保画框正确包裹图片
   ============================================================ */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  background: rgba(10, 9, 7, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease-out-expo);
  backdrop-filter: blur(8px);
}

.lightbox.open {
  opacity: 1;
  pointer-events: all;
}

.lightbox-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 80px;
}

/* --- Lightbox mat — matches gallery mat with V-groove --- */
.lightbox-img-wrap {
  position: relative;
  display: inline-block;           /* Shrink to fit image */
  max-width: 88vw;
  max-height: 85vh;
  line-height: 0;
  background: linear-gradient(175deg,
    #faf7f0 0%,
    #f6f0e4 30%,
    #f8f3eb 60%,
    #f4ede0 100%
  );
  padding: 18px;
  box-shadow:
    0 4px 24px rgba(0,0,0,0.55),
    0 18px 56px rgba(0,0,0,0.35),
    0 1px 0 rgba(255,255,255,0.12);
}

/* V-groove in lightbox mat */
.lightbox-img-wrap::before {
  content: '';
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(160, 140, 110, 0.3);
  box-shadow:
    inset 0 1px 2px rgba(0,0,0,0.08),
    0 1px 0 rgba(255,255,255,0.4);
  pointer-events: none;
  z-index: 0;                               /* Below wood frame */
}

/* --- Lightbox wood frame — matches gallery frame --- */
.lightbox-wood {
  position: relative;
  z-index: 1;                                /* Above V-groove */
  padding: 12px;
  background: linear-gradient(160deg,
    #c8a878 0%,
    #b89060 6%,
    #a07848 12%,
    #785028 20%,
    #604020 27%,
    #8a5a30 33%,
    #b88040 40%,
    #d4a850 47%,
    #e0b858 50%,
    #d4a850 53%,
    #a87038 60%,
    #684828 68%,
    #503018 74%,
    #785028 80%,
    #a08050 88%,
    #c0a070 94%,
    #c8a878 100%
  );
  box-shadow:
    inset 1px 1px 2px rgba(255,255,255,0.2),
    inset 2px 2px 4px rgba(255,240,210,0.08),
    inset -2px -2px 4px rgba(0,0,0,0.5),
    inset -3px -3px 6px rgba(0,0,0,0.25),
    0 2px 4px rgba(0,0,0,0.3),
    0 1px 0 rgba(255,255,255,0.05);
  line-height: 0;
}

/* Ornate corner accents on lightbox wood frame */
.lightbox-wood::before,
.lightbox-wood::after {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  z-index: 2;
  pointer-events: none;
}

.lightbox-wood::before {
  top: 4px; left: 4px;
  border-top: 2px solid rgba(220, 190, 120, 0.55);
  border-left: 2px solid rgba(220, 190, 120, 0.55);
  box-shadow: -1px -1px 3px rgba(0,0,0,0.2);
}

.lightbox-wood::after {
  bottom: 4px; right: 4px;
  border-bottom: 2px solid rgba(220, 190, 120, 0.55);
  border-right: 2px solid rgba(220, 190, 120, 0.55);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}

/* --- Lightbox inner recess — gold fillet + deep shadow --- */
.lightbox-inner {
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(201, 160, 80, 0.45);   /* Gold inner fillet */
  background: #0d0b08;
  box-shadow:
    inset 0 0 2px rgba(0,0,0,0.6),
    inset 0 0 10px rgba(0,0,0,0.45),
    inset 0 0 24px rgba(0,0,0,0.2),
    inset 0 0 4px rgba(201, 160, 80, 0.15);
  line-height: 0;
}

.lightbox-inner img {
  display: block;
  max-width: calc(88vw - 60px);    /* Account for mat(36) + wood(24) */
  max-height: calc(85vh - 60px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: #0d0b08;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.6s var(--ease-out-expo),
              transform 0.6s var(--ease-out-expo);
}

.lightbox.open .lightbox-inner img.loaded {
  opacity: 1;
  transform: scale(1);
}

/* --- Lightbox decorative outer frame line --- */
.lightbox-frame {
  position: absolute;
  inset: -24px;
  border: 1px solid rgba(180, 140, 100, 0.1);
  pointer-events: none;
}

.lightbox-frame::before {
  content: '';
  position: absolute;
  top: -2px;
  left: 20%;
  right: 20%;
  height: 1px;
  background: var(--accent);
}

/* --- Lightbox Caption --- */
.lightbox-caption {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

.lightbox-caption-title {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.lightbox-caption-loc {
  font-family: var(--font-classical);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--accent-light);
  text-transform: uppercase;
}

.lightbox-counter {
  font-family: var(--font-classical);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-top: 8px;
}

/* --- Lightbox Controls --- */
.lightbox-close {
  position: absolute;
  top: 32px;
  right: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 24px;
  transition: color var(--dur-fast);
  z-index: 10;
}

.lightbox-close:hover {
  color: var(--accent-light);
}

.lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color var(--dur-fast), transform var(--dur-fast);
  z-index: 10;
}

.lightbox-arrow:hover {
  color: var(--accent-light);
}

.lightbox-arrow.prev { left: 24px; }
.lightbox-arrow.prev:hover { transform: translateY(-50%) translateX(-4px); }
.lightbox-arrow.next { right: 24px; }
.lightbox-arrow.next:hover { transform: translateY(-50%) translateX(4px); }

.lightbox-arrow svg {
  width: 32px;
  height: 32px;
}

/* --- Lightbox Loading Spinner --- */
.lightbox-spinner {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-gold);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0;
  transition: opacity 0.3s;
}

.lightbox-spinner.active {
  opacity: 1;
}

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

/* ============================================================
   响应式 - 画廊 & 灯箱
   ============================================================ */

@media (max-width: 1024px) {
  .gallery {
    columns: 3;
    column-gap: 24px;
  }
  .gallery-item {
    margin-bottom: 24px;
  }

  .gallery-item-inner { padding: 12px 12px 36px 12px; }
  .gallery-item-inner::before { inset: 12px; }
  .gallery-frame-outer { padding: 8px; }

  .lightbox-content { padding: 48px; }
  .lightbox-img-wrap { padding: 14px; }
  .lightbox-img-wrap::before { inset: 14px; }
  .lightbox-wood { padding: 10px; }
  .lightbox-inner img {
    max-width: calc(90vw - 48px);
    max-height: calc(70vh - 48px);
  }
}

@media (max-width: 768px) {
  .gallery {
    columns: 2;
    column-gap: 16px;
  }
  .gallery-item {
    margin-bottom: 16px;
  }
  .gallery-item-inner { padding: 8px 8px 30px 8px; }
  .gallery-item-inner::before { inset: 8px; }
  .gallery-frame-outer { padding: 6px; }
  .gallery-frame-outer::before,
  .gallery-frame-outer::after { width: 16px; height: 16px; }

  .lightbox-arrow { display: none; }
  .lightbox-content { padding: 24px; }
  .lightbox-caption { bottom: 24px; }
  .lightbox-caption-loc { font-size: 14px; }
  .lightbox-img-wrap { padding: 10px; }
  .lightbox-img-wrap::before { inset: 10px; }
  .lightbox-wood { padding: 7px; }
  .lightbox-wood::before,
  .lightbox-wood::after { width: 18px; height: 18px; }
  .lightbox-inner img {
    max-width: calc(92vw - 34px);
    max-height: calc(75vh - 34px);
  }
}

@media (max-width: 480px) {
  .gallery {
    columns: 1;
    column-gap: 0;
    max-width: 420px;
    margin: 0 auto;
  }
  .gallery-item {
    margin-bottom: 16px;
  }
  .gallery-item-inner { padding: 6px 6px 24px 6px; }
  .gallery-item-inner::before { inset: 6px; }
  .gallery-frame-outer { padding: 5px; }
  .gallery-frame-outer::before,
  .gallery-frame-outer::after { width: 12px; height: 12px; }
  .gallery-item:hover .gallery-item-inner { transform: none; }

  .lightbox-img-wrap { padding: 8px; }
  .lightbox-img-wrap::before { inset: 8px; }
  .lightbox-wood { padding: 5px; }
  .lightbox-wood::before,
  .lightbox-wood::after { width: 14px; height: 14px; }
  .lightbox-inner img {
    max-width: calc(94vw - 26px);
    max-height: calc(78vh - 26px);
  }
}
