/* ═══════════════════════════════════════════
   gallery.css — Góc ảnh kỷ niệm 📸
   Thẻ gọn ngoài trang + Kho ảnh mở toàn màn hình dạng bảng ghim
   ═══════════════════════════════════════════ */

#gallery {
  position: relative;
  padding: 3rem 1rem 4rem;
  background: transparent;
  z-index: 4;
}
#gallery::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,250,247,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 0;
  transition: background 0.4s ease;
}
html.dark #gallery::before { background: rgba(10,6,8,0.62); }
html.dark #gallery { background: transparent; }
#gallery > * { position: relative; z-index: 1; }

.gallery-wrap { max-width: 620px; margin: 0 auto; }

/* ─── Thẻ gọn (entry point) ─── */
.gallery-entry-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.3rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  box-shadow: 0 6px 32px rgba(201,132,142,0.12);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
}
.gallery-entry-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(201,132,142,0.22);
  border-color: var(--blush);
}
.gallery-entry-icon {
  flex-shrink: 0;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(255,192,203,0.32), rgba(242,167,187,0.45));
  color: var(--rose-gold);
}
.gallery-entry-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.gallery-entry-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.2rem;
  font-style: italic;
  color: var(--ink);
}
.gallery-entry-sub {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  color: var(--mauve);
  opacity: 0.8;
}
.gallery-entry-arrow {
  flex-shrink: 0;
  color: var(--blush);
  transition: transform 0.2s;
}
.gallery-entry-card:hover .gallery-entry-arrow { transform: translateX(4px); }

html.dark .gallery-entry-card { background: var(--bg-card); border-color: var(--border-card); }

/* ═══════════════════════════════════════════
   KHO ẢNH — TOÀN MÀN HÌNH
   ═══════════════════════════════════════════ */
.gallery-fullscreen-overlay {
  position: fixed; inset: 0;
  z-index: 9000;
  background: radial-gradient(ellipse at 30% 20%, #241220 0%, #14090f 55%, #0a0509 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  overflow: hidden;
}
.gallery-fullscreen-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Sao lấp lánh + trôi nhẹ trên nền — thuần CSS (transform/opacity) để mượt, không giật lag */
.gallery-fs-stars {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.gallery-fs-star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: gallery-star-drift ease-in-out infinite;
  /* Mặc định TẠM DỪNG — chỉ chạy khi kho ảnh đang mở (xem quy tắc .active bên dưới).
     Tránh animation chạy ngầm vô ích khi overlay đang ẩn → đỡ hao pin/CPU khi xem lâu. */
  animation-play-state: paused;
  will-change: transform, opacity;
}
.gallery-fullscreen-overlay.active .gallery-fs-star {
  animation-play-state: running;
}
@keyframes gallery-star-drift {
  0%, 100% { opacity: 0.15; transform: translate(0, 0) scale(1); }
  50%       { opacity: 0.9;  transform: translate(var(--sx, 6px), var(--sy, -6px)) scale(1.4); }
}

/* Nút đóng */
.gallery-fs-close {
  position: fixed;
  top: 1.1rem; right: 1.2rem;
  z-index: 20;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(8px);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.gallery-fs-close:hover { background: rgba(255,255,255,0.18); transform: rotate(90deg); }

/* Vùng cuộn nội dung — có perspective để hiệu ứng nghiêng ảnh (tilt) trông có chiều sâu */
.gallery-fs-scroll {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow-y: auto;
  padding: 4.2rem 1rem 7rem;
  -webkit-overflow-scrolling: touch;
  perspective: 900px;
}

.gallery-fs-heading {
  text-align: center;
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  font-style: italic;
  font-weight: 400;
  color: #fce4ea;
  text-shadow: 0 0 24px rgba(242,167,187,0.5);
  margin-bottom: 0.3rem;
}
.gallery-fs-subheading {
  text-align: center;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.82rem;
  color: rgba(252,228,234,0.65);
  margin-bottom: 2rem;
  letter-spacing: 0.02em;
}

/* ─── Bảng ghim ảnh (collage) ───
   transform ở đây được JS cập nhật để tạo hiệu ứng nghiêng theo cảm biến điện thoại
   (toàn bộ ảnh nghiêng cùng lúc). Chỉ 1 transform trên CHÍNH container này — rẻ cho
   trình duyệt (1 layer composite), không phải tính lại từng ảnh riêng lẻ → không giật lag. */
.gallery-collage {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  column-count: 2;
  column-gap: 1.1rem;
  transform-origin: 50% 30%;
  will-change: transform;
  /* Không đặt CSS transition ở đây — JS đã tự làm mượt (lerp) theo từng khung hình,
     thêm transition CSS nữa sẽ bị "mượt chồng mượt" gây trễ/giật khi nghiêng máy. */
}
@media (min-width: 640px)  { .gallery-collage { column-count: 3; } }
@media (min-width: 980px)  { .gallery-collage { column-count: 4; } }

/* Chữ trang trí bay lơ lửng + nhấp nháy giữa các ảnh — thuần CSS, tự tạm dừng khi đóng overlay */
.gallery-collage-caption {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  font-family: 'Cormorant Garamond', 'Caveat', serif;
  font-style: italic;
  color: #ffb6c9;
  text-shadow: 0 0 14px rgba(255,150,180,0.65), 0 0 3px rgba(255,150,180,0.4);
  white-space: nowrap;
  user-select: none;
  animation: gallery-caption-drift ease-in-out infinite;
  animation-play-state: paused;
  will-change: transform, opacity;
}
.gallery-fullscreen-overlay.active .gallery-collage-caption {
  animation-play-state: running;
}
@keyframes gallery-caption-drift {
  0%   { transform: translate(0, 0) rotate(var(--rot, 0deg)); opacity: var(--op-min, 0.3); }
  25%  { transform: translate(var(--dx1, 10px), var(--dy1, -10px)) rotate(calc(var(--rot, 0deg) + 4deg)); opacity: var(--op-max, 0.7); }
  50%  { transform: translate(var(--dx2, -8px), var(--dy2, 8px)) rotate(var(--rot, 0deg)); opacity: var(--op-min, 0.3); }
  75%  { transform: translate(var(--dx1, 10px), var(--dy2, 8px)) rotate(calc(var(--rot, 0deg) - 4deg)); opacity: var(--op-max, 0.7); }
  100% { transform: translate(0, 0) rotate(var(--rot, 0deg)); opacity: var(--op-min, 0.3); }
}

/* Người dùng chọn giảm hiệu ứng chuyển động (accessibility) → tắt hết animation/tilt cho nhẹ máy */
@media (prefers-reduced-motion: reduce) {
  .gallery-fs-star,
  .gallery-collage-caption { animation: none !important; }
  .gallery-collage { transform: none !important; }
}

.gallery-tile {
  position: relative;
  z-index: 2;
  break-inside: avoid;
  margin-bottom: 1.1rem;
  border-radius: 14px;
  overflow: hidden;
  background: #1a0f14;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.gallery-tile:hover {
  transform: scale(1.03) rotate(0deg) !important;
  box-shadow: 0 16px 40px rgba(0,0,0,0.55);
  z-index: 5;
}
.gallery-tile img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}

.gallery-tile-caption {
  padding: 0.55rem 0.7rem 0.65rem;
  background: linear-gradient(0deg, rgba(10,5,8,0.92), rgba(10,5,8,0.4));
  font-family: 'Lora', serif;
  font-size: 0.76rem;
  line-height: 1.4;
  color: #fce4ea;
}

.gallery-tile-author {
  position: absolute;
  top: 0.5rem; left: 0.5rem;
  font-size: 0.62rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  color: #fff;
  background: rgba(20,8,12,0.5);
  padding: 2px 8px;
  border-radius: 50px;
  letter-spacing: 0.03em;
  z-index: 3;
}

.gallery-tile-delete {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(20,8,12,0.55);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0.85;
  transition: background 0.2s, transform 0.15s;
  z-index: 3;
}
.gallery-tile-delete:hover { background: rgba(224,60,90,0.85); transform: scale(1.1); }

/* Ô tải lên đang chờ */
.gallery-tile.uploading {
  display: flex; align-items: center; justify-content: center;
  min-height: 120px;
}
.gallery-tile.uploading .gallery-spinner {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,182,201,0.25);
  border-top-color: #ffb6c9;
  animation: gallery-spin 0.8s linear infinite;
}
@keyframes gallery-spin { to { transform: rotate(360deg); } }

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.9rem;
  color: rgba(252,228,234,0.7);
}

/* Nút thêm ảnh nổi */
.gallery-fs-add {
  position: fixed;
  bottom: 1.8rem; right: 1.4rem;
  z-index: 20;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--petal), var(--blush));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(242,167,187,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
.gallery-fs-add:hover { transform: scale(1.1) rotate(90deg); box-shadow: 0 8px 30px rgba(242,167,187,0.55); }

/* Kéo-thả ảnh trực tiếp vào kho ảnh */
.gallery-fs-scroll.drag-over::after {
  content: 'Thả ảnh vào đây 🌸';
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.4rem;
  font-style: italic;
  color: #fce4ea;
  background: rgba(242,167,187,0.15);
  border: 2px dashed rgba(255,182,201,0.6);
  pointer-events: none;
}

/* ─── Upload composer modal ─── */
.gallery-upload-overlay {
  position: fixed;
  inset: 0;
  z-index: 9100;
  background: rgba(30, 8, 16, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.gallery-upload-overlay.active { opacity: 1; pointer-events: auto; }
.gallery-upload-board {
  position: relative;
  width: min(560px, calc(100vw - 2.4rem));
  max-height: 88vh;
  background: var(--bg-letter-card);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  box-shadow:
    0 12px 60px rgba(201,132,142,0.22),
    0 2px 12px rgba(201,132,142,0.12),
    inset 0 0 0 1px rgba(255,255,255,0.55);
  padding: 1.8rem 1.8rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.35s cubic-bezier(0.4,0,0.2,1),
              transform 0.35s cubic-bezier(0.34,1.3,0.64,1);
}
.gallery-upload-overlay.active .gallery-upload-board {
  opacity: 1;
  transform: translateY(0) scale(1);
}
html.dark .gallery-upload-board {
  background: var(--bg-letter-card);
  border-color: rgba(242,167,187,0.14);
  box-shadow: 0 12px 60px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(242,167,187,0.06);
}

.gallery-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 0.5rem;
  max-height: 160px;
  overflow-y: auto;
  padding-right: 0.2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--petal) transparent;
}
.gallery-preview-list::-webkit-scrollbar { width: 3px; }
.gallery-preview-list::-webkit-scrollbar-thumb { background: var(--petal); border-radius: 2px; }

.gallery-preview-item {
  position: relative;
  aspect-ratio: 1/1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-card);
}
.gallery-preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-preview-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(20,8,12,0.6);
  color: #fff;
  font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

.gallery-author-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.gallery-author-label {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  font-weight: 300;
  color: var(--mauve);
  letter-spacing: 0.04em;
  opacity: 0.85;
  white-space: nowrap;
}
.gallery-author-pills { display: flex; gap: 0.5rem; }
.gallery-author-pill {
  display: flex;
  align-items: center;
  gap: 0.38rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.8rem;
  color: var(--soft-ink);
  background: rgba(255,192,203,0.08);
  border: 1.5px solid var(--border-card);
  border-radius: 50px;
  padding: 0.3rem 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.gallery-author-pill:hover {
  background: rgba(255,192,203,0.18);
  border-color: rgba(242,167,187,0.5);
  color: var(--rose-gold);
}
.gallery-author-pill.active {
  background: rgba(242,167,187,0.18);
  border-color: var(--blush);
  color: var(--rose-gold);
}

.gallery-caption-input {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  background: rgba(255,192,203,0.04);
  border: 1.5px solid var(--border-card);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  font-family: 'Lora', serif;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s, background 0.2s;
}
.gallery-caption-input::placeholder { color: var(--mauve); opacity: 0.5; font-style: italic; }
.gallery-caption-input:focus {
  border-color: rgba(242,167,187,0.6);
  background: rgba(255,192,203,0.06);
}
html.dark .gallery-caption-input { background: rgba(255,192,203,0.03); color: var(--ink); }

.gallery-upload-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding-top: 0.2rem;
}
.gallery-upload-progress {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.72rem;
  color: var(--mauve);
  opacity: 0.8;
}
.gallery-btn-cancel {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  color: var(--mauve);
  background: none;
  border: 1px solid var(--border-card);
  border-radius: 50px;
  padding: 0.42rem 1rem;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.2s, background 0.2s;
}
.gallery-btn-cancel:hover { opacity: 1; background: rgba(255,192,203,0.1); }
.gallery-btn-submit {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  color: var(--bg-letter-card);
  background: var(--rose-gold);
  border: 1px solid transparent;
  border-radius: 50px;
  padding: 0.42rem 1.15rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}
.gallery-btn-submit:hover { background: var(--blush); transform: translateY(-1px); }
.gallery-btn-submit[disabled] { opacity: 0.6; cursor: wait; }

/* ─── Lightbox xem ảnh full ─── */
.gallery-lightbox-overlay {
  position: fixed; inset: 0;
  background: rgba(10,5,8,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 9200;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.gallery-lightbox-overlay.active { opacity: 1; pointer-events: auto; }
.gallery-lightbox-card {
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  transform: scale(0.94);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.gallery-lightbox-overlay.active .gallery-lightbox-card { transform: scale(1); }
.gallery-lightbox-card img {
  max-width: 92vw;
  max-height: 70vh;
  border-radius: 16px;
  box-shadow: 0 20px 70px rgba(0,0,0,0.4);
  object-fit: contain;
}
.gallery-lightbox-caption {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem;
  font-style: italic;
  color: #fff;
  text-align: center;
  max-width: 560px;
}
.gallery-lightbox-meta {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.gallery-lightbox-actions { display: flex; gap: 0.6rem; }
.gallery-lightbox-delete,
.gallery-lightbox-close {
  display: flex; align-items: center; gap: 0.35rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  padding: 0.4rem 1rem;
  border-radius: 50px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: #fff;
  transition: background 0.2s, transform 0.15s;
}
.gallery-lightbox-delete:hover { background: rgba(224,60,90,0.75); }
.gallery-lightbox-close:hover  { background: rgba(255,255,255,0.22); }
.gallery-lightbox-delete:hover, .gallery-lightbox-close:hover { transform: translateY(-1px); }

@media (max-width: 480px) {
  .gallery-upload-board { padding: 1.4rem 1.2rem 1.1rem; border-radius: 18px; }
  .gallery-collage { column-gap: 0.8rem; }
  .gallery-tile { margin-bottom: 0.8rem; }
}
