/* Cakela gallery. Loads on top of home.css so the header, buttons, footer and
   lightbox stay identical to the storefront. Everything here is about the two
   gallery views: the album index and the photos inside one album. Every tile is
   a square of the same size, so no row ends ragged and no photo is stretched. */
/* Cards, buttons and the lightbox arrows all set `display`, which would beat the
   browser default for [hidden]; the toggled elements need this to stay hidden. */
[hidden] { display: none !important; }
.gallery-page .home-section { padding-top: clamp(26px, 3vw, 38px); padding-bottom: clamp(26px, 3vw, 38px); }
.gallery-head { padding-bottom: 0 !important; }
.gallery-head h1 { color: var(--brown); font-size: clamp(1.6rem, 1.3rem + 1.6vw, 2.6rem); font-weight: 700; }
.gallery-head .section-title { max-width: 720px; margin-bottom: 16px; }
.gallery-head .section-title p:not(.home-kicker) { color: var(--muted); }
.gallery-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; margin-bottom: 10px; }
/* 44px cho ngón tay, không chỉ cao bằng dòng chữ. */
.gallery-crumbs a { display: inline-flex; align-items: center; min-height: 44px; color: var(--red); font-size: var(--text-sm); font-weight: 800; text-decoration: none; }
.gallery-crumbs a:hover { text-decoration: underline; }

/* Toolbar: photo count and actions inside one album. */
.gallery-toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 18px; }
.gallery-status { color: var(--muted); font-size: var(--text-sm); font-weight: 700; }
.gallery-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Album index: uniform square cover, name and photo count below the image.
   Số cột tự tính theo bề ngang thật: 2 ô trên điện thoại, 3 ở máy nhỏ, 4 ở máy
   tính và 5 khi màn rất rộng - không cần điểm ngắt nào, và không có bề ngang nào
   cho ra một hàng cụt. min(100%, ...) để ô không bao giờ rộng hơn khung. */
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, clamp(132px, 21vw, 240px)), 1fr)); gap: clamp(12px, 1.4vw, 18px); }
.album-card { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); color: var(--ink); text-decoration: none; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
.album-card__media { position: relative; display: block; aspect-ratio: 1 / 1; overflow: hidden; border-radius: 8px; background: var(--cream); }
/* Ô bìa đang chờ ảnh về thì nhấp nháy nhẹ như Facebook, khung vẫn giữ đúng chỗ.
   .is-near do gallery.js gắn đúng lúc bắt đầu tải bìa của ô đó, .is-loaded gắn khi
   ảnh về xong: nhịp nhấp nháy vì vậy chỉ chạy ở mấy ô khách đang nhìn. Trước đây
   luật chỉ có :not(.is-loaded) mà .is-loaded lại được gắn ngay khi gán src, nên hoá
   ra chạy đúng 22 animation vô hạn cho những ô còn nằm ngoài màn và không chạy cho
   ô đang thật sự chờ - ngược hẳn ý định. */
.album-card.is-near:not(.is-loaded) .album-card__media { animation: photo-pulse 1.4s ease-in-out infinite; }
.album-card img { width: 100%; height: 100%; object-fit: cover; transition: transform .28s ease; }
/* Ảnh bìa chỉ được gán src khi ô sắp vào khung nhìn. Trong lúc chờ, thẻ <img>
   chưa có src nên trình duyệt vẽ icon "ảnh vỡ" nhỏ ở góc ô - ẩn thẻ ảnh đi thì
   ô bìa chỉ còn khung kem nhấp nháy đúng như ý. */
.album-card img:not([src]), .photo-grid img:not([src]) { visibility: hidden; }
/* Tắt JS: thẻ <img> chờ không có src nên ẩn đi, ảnh trong <noscript> hiện thay. */
.no-js .album-card img[data-cover-src] { display: none; }
.no-js .album-card noscript { display: contents; }
/* Chỉ máy có chuột mới nhấc thẻ lên: trên màn cảm ứng trạng thái hover dính lại
   sau khi chạm, thẻ cứ nằm lệch cho tới lúc chạm chỗ khác. */
@media (hover: hover) {
  .album-card:hover { transform: translateY(-3px); border-color: rgba(181, 34, 29, .28); box-shadow: 0 14px 30px rgba(89, 50, 31, .18); }
  .album-card:hover img, .photo-grid a:hover img { transform: scale(1.04); }
}
/* Tên album do Facebook đặt, có thể rất dài: cho phép ngắt trong từ để không đẩy
   ô tràn ra ngoài, và cỡ chữ co lại một nhịp trên máy nhỏ. */
.album-card strong { margin-top: 4px; color: var(--brown); font-family: var(--display); font-size: clamp(.98rem, .92rem + .32vw, 1.15rem); font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.album-card small { color: var(--muted); font-size: var(--text-xs); font-weight: 700; }
.gallery-empty { display: grid; justify-items: start; gap: 12px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--muted); }

/* Album view: one grid of equal squares, no spans, no featured tile. Ô ảnh nhỏ
   hơn ô album (không có chữ kèm) nên xếp dày hơn một nhịp: 2 ô ở 320px, 3 ô trên
   điện thoại thường, 5 ô từ máy tính trở lên - giống lưới ảnh của Facebook. */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, clamp(104px, 15vw, 220px)), 1fr)); gap: clamp(8px, 1vw, 12px); }
.photo-grid a, .photo-skeleton { aspect-ratio: 1 / 1; overflow: hidden; border-radius: var(--radius); background: var(--cream); box-shadow: var(--shadow); }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; transition: transform .28s ease; }
.photo-skeleton { animation: photo-pulse 1.4s ease-in-out infinite; }
/* Tắt JS thì không có gì thay ô chờ, nên ẩn chúng và để <noscript> lo phần ảnh. */
.no-js .photo-skeleton { display: none; }
/* Bìa hoặc ảnh lỗi cả bản dự phòng: ẩn thẻ ảnh và tắt nhịp nhấp nháy, ô còn lại là
   khung kem phẳng - tên album bên dưới vẫn đọc được bình thường. */
.album-card.is-broken .album-card__media { animation: none; }
.album-card.is-broken img, .photo-grid a.is-broken img { display: none; }
@keyframes photo-pulse { 0%, 100% { opacity: .55; } 50% { opacity: .95; } }
.gallery-more { display: grid; justify-items: center; gap: 10px; margin-top: 20px; }
.gallery-more .home-button { min-width: min(200px, 100%); }

@media (max-width: 780px) { .gallery-toolbar { align-items: stretch; } }
@media (max-width: 420px) { .gallery-actions .home-button { width: 100%; } }

/* Mobile browsing keeps the established cream/red palette and album cards. */
.gallery-mobile-tools { display: none; }
.no-js [data-gallery-album-select] { display: none; }
.gallery-photo-hint { margin: 0 0 12px; color: var(--muted); font-size: var(--text-md); }
.gallery-mobile-tools .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 780px) {
  .gallery-head .section-title { margin-bottom: 10px; }
  .gallery-mobile-tools { position: sticky; top: var(--header); z-index: 70; display: flex; align-items: center; gap: 10px; padding: 9px var(--gutter); border-bottom: 1px solid var(--line); background: var(--paper); }
  .gallery-mobile-tools > a { display: inline-flex; align-items: center; min-height: 44px; color: var(--red); font-size: 15px; font-weight: 800; text-decoration: none; white-space: nowrap; }
  .gallery-mobile-tools select { flex: 1; min-width: 0; width: 100%; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--brown); font-size: 16px; }
  .photo-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .gallery-page .floating-actions { display: flex; gap: 8px; }
  .gallery-page .floating-actions a { width: 44px; height: 44px; }
  .gallery-page.lightbox-open .floating-actions { visibility: hidden; }
}

/* The photograph owns the viewport. Controls occupy just two compact rows. */
.gallery-page .lightbox { padding: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; place-items: stretch; height: 100vh; height: 100dvh; background: #180f0a; overscroll-behavior: contain; transition: opacity .2s ease; color: #fff8f1; }
.lightbox-topbar { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: max(4px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) 4px max(16px,env(safe-area-inset-left)); }
.lightbox-topbar [data-lightbox-count] { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: #e8d8ca; }
.lightbox-topbar__actions { display: flex; gap: 4px; }
.gallery-page .lightbox .lightbox-icon { position: static; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; min-width: 44px; height: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 50%; transform: none; background: transparent; color: #fff8f1; text-decoration: none; cursor: pointer; }
.lightbox svg { flex-shrink: 0; pointer-events: none; }
.gallery-page .lightbox figure { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; width: 100%; height: 100%; max-width: none; margin: 0; }
.gallery-page .lightbox img { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 0; touch-action: pan-y pinch-zoom; }
.gallery-page .lightbox { transition: opacity 160ms ease-out, visibility 0s linear 160ms; }
.gallery-page .lightbox.is-open { transition: opacity 220ms cubic-bezier(.16,1,.3,1), visibility 0s; }
.gallery-page .lightbox img { transform: none; transition: none; }
.gallery-page.lightbox-open .photo-skeleton, .gallery-page.lightbox-open .album-card__media { animation-play-state: paused; }
.motion-ready .gallery-page .reveal { transition-duration: 350ms; }
.gallery-page .lightbox-icon, .lightbox-contact { -webkit-tap-highlight-color: transparent; }
.gallery-page .lightbox .lightbox-icon:active:not(:disabled) { background: #49362a; }
@media (prefers-reduced-motion: reduce) {
  .gallery-page .lightbox, .gallery-page .lightbox.is-open,
  .gallery-page .album-card, .gallery-page .album-card img, .gallery-page .photo-grid img { transition: none; }
}
.lightbox .lightbox-feedback { position: absolute; left: 16px; right: 16px; bottom: 12px; display: grid; justify-items: center; gap: 8px; text-align: center; pointer-events: none; }
.lightbox-feedback p:not([hidden]) { max-width: 420px; padding: 8px 12px; background: #180f0a; color: #fff8f1; font-size: 14px; }
.lightbox [data-lightbox-retry] { pointer-events: auto; min-height: 44px; padding: 8px 16px; border: 1px solid #e8d8ca; border-radius: 6px; background: #180f0a; color: #fff8f1; font-size: 15px; }
.lightbox-controls { display: flex; align-items: center; justify-content: center; gap: 24px; padding: 8px max(12px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left)); }
.lightbox-contact { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px; border-radius: 6px; background: #fff3e5; color: #6b3023; font-size: 15px; font-weight: 700; text-decoration: none; }
.lightbox-contact { border: 0; font-family: var(--sans); cursor: pointer; }
.lightbox-contact-panel { position: absolute; z-index: 2; bottom: calc(72px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(350px,calc(100% - 24px)); max-height: calc(100% - 140px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y: auto; padding: 8px 12px; border-radius: 12px; background: #fff3e5; color: #6b3023; box-shadow: 0 8px 32px #0006; }
.lightbox-contact-panel__head { display: flex; align-items: center; justify-content: space-between; padding-left: 8px; font-size: 16px; }
.gallery-page .lightbox-contact-panel .lightbox-icon { color: #6b3023; }
.lightbox-channel { display: flex; align-items: center; gap: 12px; padding: 12px 8px; min-height: 68px; border-top: 1px solid #dbc4af; color: #6b3023; text-decoration: none; }
.gallery-page .lightbox .lightbox-channel img { flex: 0 0 32px; width: 32px; height: 32px; max-width: 32px; max-height: 32px; object-fit: contain; }
.lightbox-channel > span { display: grid; flex: 1; gap: 2px; }
.lightbox-channel strong { font-size: 16px; }
.lightbox-channel small { font-size: 14px; }
.lightbox-contact-panel__footer { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid #dbc4af; }
.lightbox-contact-panel__footer button, .lightbox-contact-panel__footer a { display: inline-flex; align-items: center; min-height: 44px; padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; color: #6b3023; font: 600 13px var(--sans); cursor: pointer; text-decoration: none; transition: background-color 120ms ease-out; }
.lightbox-contact-panel__footer button:active, .lightbox-contact-panel__footer a:active { background: #efdfcf; }
.lightbox-contact-panel [data-contact-status]:not(:empty) { padding: 4px 8px 8px; font-size: 13px; }
.lightbox .lightbox-contact-panel :focus-visible { outline-color: #6b3023; outline-offset: -2px; }
@media (hover:hover) {
  .lightbox-channel:hover { background: #f5e3ce; }
  .lightbox-contact-panel__footer button:hover, .lightbox-contact-panel__footer a:hover { background: #f5e3ce; }
  .gallery-page .lightbox .lightbox-contact-panel .lightbox-icon:not(:disabled):hover { background: #efdfcf; color: #6b3023; }
}
.gallery-page .lightbox .lightbox-contact-panel .lightbox-icon:not(:disabled):active { background: #efdfcf; color: #6b3023; }
.gallery-page .lightbox .lightbox-icon:disabled { opacity: .3; cursor: default; }
.lightbox button:focus-visible, .lightbox a:focus-visible { outline: 2px solid #ffd9ae; outline-offset: 2px; }
@media (hover: hover) { .gallery-page .lightbox .lightbox-icon:not(:disabled):hover { background: #49362a; } .lightbox-contact:hover { background: #ffdfb7; } }
@media (max-height: 500px) and (orientation: landscape) { .lightbox-topbar { min-height: 44px; padding-top: 0; padding-bottom: 0; } .lightbox-controls { padding-top: 2px; padding-bottom: max(2px,env(safe-area-inset-bottom)); } }

/* ===========================================================================
   Trang danh sách album.

   Đầu trang là một khối chữ ngắn, từ đó xuống là phần của ảnh: một lưới album duy
   nhất, không tiêu đề nhóm, không câu dẫn - tên album đã tự nói nó là bánh gì rồi.
   Mọi ô một cỡ, ảnh bìa vuông như nhau: album 1.129 ảnh hay album 2 ảnh cũng một ô,
   nên không hàng nào cụt và mắt khách đi hết lưới theo đúng một nhịp.
   =========================================================================== */

/* Lưới album nằm trong .album-index nên không còn là con trực tiếp của <main>: khoảng
   trên gọn lại một nhịp cho ảnh nhích lên cao, khoảng dưới giữ nguyên. */
.gallery-page .album-list { padding-top: clamp(14px, 1.8vw, 22px); padding-bottom: clamp(24px, 3vw, 40px); }

/* Chữ trong ô album gom vào một bọc, nhờ vậy ảnh với chữ xếp được theo nhiều kiểu mà
   không phải đổi cấu trúc thẻ. min-width: 0 để tên album dài không đẩy cột chữ nở ra
   ngoài ô. */
.album-card__text { display: grid; align-content: start; gap: 4px; min-width: 0; }

@media (max-width: 420px) {
  /* Trang một album có tới ba nút: để nút đặt bánh riêng một hàng, hai nút phụ chia
     nhau hàng dưới - ba nút xếp dọc chiếm gần hết một màn điện thoại. */
  .gallery-actions .home-button.outline { flex: 1 1 44%; width: auto; padding-left: 12px; padding-right: 12px; }
}

/* Keep album switching available while browsing on desktop, as on mobile. */
@media(min-width:781px){
 .gallery-mobile-tools{position:sticky;top:var(--header);z-index:70;display:flex;align-items:center;gap:18px;padding:10px var(--gutter);border-top:1px solid var(--line);border-bottom:1px solid var(--line);background:var(--paper)}
 .gallery-mobile-tools>a{display:inline-flex;align-items:center;min-height:44px;color:var(--brown);font:800 14px/1.5 var(--sans);text-decoration:none;white-space:nowrap}
 .gallery-mobile-tools>a:hover{text-decoration:underline;text-underline-offset:4px}
 .gallery-mobile-tools .sr-only{position:static;width:auto;height:auto;padding:0;margin:0 0 0 16px;overflow:visible;clip:auto;white-space:nowrap;color:var(--muted);font:700 13px/1.5 var(--sans)}
 .gallery-mobile-tools select{flex:1;min-width:0;max-width:560px;min-height:44px;padding:9px 36px 9px 12px;border:1px solid var(--line);border-radius:8px;background:#fffdf9;color:var(--brown);font:700 14px/1.5 var(--sans);cursor:pointer}
 .gallery-mobile-tools a:focus-visible,.gallery-mobile-tools select:focus-visible{outline:2px solid var(--brown);outline-offset:3px}
}

@media(min-width:781px){
 .gallery-mobile-tools{gap:14px;padding:12px var(--gutter);border-top:0;background:var(--bg);box-shadow:0 4px 14px #6e2c1d04}
 .gallery-mobile-tools>a{padding-right:14px;border-right:1px solid var(--line);font-size:13px}
 .gallery-mobile-tools .sr-only{margin-left:4px;font-size:12px;color:#80685a}
 .gallery-mobile-tools select{max-width:460px;border-radius:999px;padding:10px 42px 10px 18px;background-color:var(--paper);appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e2c1d' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 16px center;transition:border-color .16s,background-color .16s}
 .gallery-mobile-tools select:hover{border-color:#b69a86;background-color:var(--cream)}
}
