/* Khung chữ kèm ảnh: chữ và ảnh của cùng một ý nằm chung một khung ngà, viền vàng mảnh bên trong.
   Ảnh ở trên, chữ nội dung ở dưới; chỉ tiêu đề mới nằm trên ảnh. Bấm ảnh để xem lớn (xem chum-anh.js). */
.khoi-tieu { margin-bottom: 2rem; text-align: center; font-family: "Lora", Georgia, serif; font-weight: 500; letter-spacing: .04em }
.khoi-tieu::after { content: ""; display: block; width: 3.5rem; height: 1px; margin: 1rem auto 0; background: var(--color-gold) }

.khung-luoi { display: grid; gap: 1.25rem }
.khung { position: relative; display: flex; flex-direction: column; gap: 1rem; padding: 1.25rem; border-radius: 1.25rem; background: #fffdf8; box-shadow: 0 18px 48px -30px #1c191759 }
.khung::before { content: ""; position: absolute; inset: .375rem; border: 1px solid #ca8a0440; border-radius: 1rem; pointer-events: none }

/* chữ trong khung */
.khung-chu, .khung-cau { font-family: "Lora", Georgia, serif; color: #2b2622; font-variant-numeric: lining-nums }
.khung-chu { padding-inline: .25rem; font-size: 1.0625rem; line-height: 1.75 }
.khung-chu p + p { margin-top: .75rem }
.khung-cau { padding-inline: .25rem; text-align: center; font-size: 1.125rem; font-weight: 500; line-height: 1.6 }
/* khung rộng hết hàng: đoạn chữ thu hẹp cho dễ đọc, dòng cuối căn giữa */
.khung-rong .khung-chu { width: 100%; max-width: 52rem; margin-inline: auto; text-align-last: center }

/* ảnh trong khung: ảnh đầu lớn, các ảnh sau nhỏ */
.ghep-anh { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem }
.ghep-anh > a { position: relative; display: block; aspect-ratio: 4/3; overflow: hidden; border-radius: .625rem; cursor: zoom-in }
.ghep-3 > a:first-child, .ghep-5 > a:first-child, .ghep-1 > a { grid-column: span 2; aspect-ratio: 3/2 }
.ghep-anh img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover }
.xem-anh:focus-visible { outline: 3px solid var(--color-gold); outline-offset: 2px }
/* trong thẻ thế hệ */
.card .ghep-anh { margin-top: 1rem }

@media (min-width: 640px) {
  .khung { gap: 1.25rem; padding: 1.75rem; border-radius: 1.5rem }
  .khung::before { inset: .5rem; border-radius: 1.125rem }
  .khung-chu { font-size: 1.125rem }
  .khung-cau { font-size: 1.25rem }
  /* ảnh chiếm phần cao còn lại, để 2 khung cùng hàng bằng nhau dù chữ dài ngắn khác nhau */
  .khung .ghep-anh { flex: 1 1 auto }
  .ghep-3 { grid-template-columns: 3fr 2fr; grid-template-rows: 1fr 1fr; aspect-ratio: 3/2 }
  .ghep-3 > a, .ghep-3 > a:first-child { aspect-ratio: auto }
  .ghep-3 > a:first-child { grid-column: auto; grid-row: span 2 }
  .khung .ghep-3 { aspect-ratio: auto; min-height: 21rem }
  .khung .ghep-2 > a, .khung .ghep-1 > a { aspect-ratio: auto; min-height: 18rem }
  /* chùm 5 ảnh: ảnh đầu lớn bên trái, 4 ảnh nhỏ bên phải */
  .khung .ghep-5 { flex: none; grid-template-columns: 2fr 1fr 1fr; grid-template-rows: 1fr 1fr; aspect-ratio: 5/2 }
  .ghep-5 > a, .ghep-5 > a:first-child { aspect-ratio: auto }
  .ghep-5 > a:first-child { grid-column: auto; grid-row: span 2 }
}
@media (min-width: 1024px) {
  .khoi-tieu { margin-bottom: 3rem }
  .khung-luoi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem }
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .ghep-anh img { transition: transform .4s }
  .xem-anh:hover img { transform: scale(1.03) }
}

/* khung xem ảnh lớn: phủ kín màn hình */
#chum-xem { width: 100%; height: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #0f0a05f0; overflow: hidden; touch-action: pinch-zoom }
#chum-xem::backdrop { background: #0f0a05f0 }
#chum-xem > img { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; transform-origin: 0 0 }
/* chum-anh.js báo trước tỉ lệ (--tl) và bề ngang (--rong) của ảnh: khung ảnh có sẵn kích thước khi ảnh lớn chưa tải xong */
#chum-xem > img { width: min(100%, 100vh * var(--tl), var(--rong)); width: min(100%, 100dvh * var(--tl), var(--rong)); aspect-ratio: var(--tl) }
#chum-xem button { position: absolute; display: flex; align-items: center; justify-content: center; width: 3rem; height: 3rem; padding: 0; border: 0; border-radius: 9999px; background: #00000080; color: #fff; cursor: pointer }
#chum-xem button:hover { background: #000000b3 }
#chum-xem button:focus-visible { outline: 3px solid var(--color-gold-light); outline-offset: 2px }
#chum-xem button svg { width: 1.5rem; height: 1.5rem }
#chum-xem .chum-dong { top: .75rem; right: .75rem }
#chum-xem .chum-truoc, #chum-xem .chum-sau { top: 50%; margin-top: -1.5rem }
#chum-xem .chum-truoc { left: .5rem }
#chum-xem .chum-sau { right: .5rem }
#chum-xem .chum-dem { position: absolute; top: 1.125rem; left: 50%; transform: translateX(-50%); margin: 0; padding: .25rem .75rem; border-radius: 9999px; background: #00000080; font-size: .9375rem; font-weight: 500; color: #fff; pointer-events: none }
html.chum-mo { overflow: hidden }
/* mở: nền tối và các nút hiện dần, ảnh phóng ra từ chỗ ảnh nhỏ (xem chum-anh.js); đóng (lớp chum-thu): ngược lại */
@media (prefers-reduced-motion: no-preference) {
  #chum-xem[open] { animation: chum-nen .3s ease-out }
  #chum-xem[open]::backdrop { animation: chum-nen .3s ease-out }
  #chum-xem[open] > :not(img) { animation: chum-hien .3s ease-out .12s backwards }
  @keyframes chum-nen { from { background-color: #0f0a0500 } }
  @keyframes chum-hien { from { opacity: 0 } }
  #chum-xem.chum-thu, #chum-xem.chum-thu::backdrop { background-color: #0f0a0500; transition: background-color .3s ease-in }
  #chum-xem.chum-thu > :not(img) { opacity: 0; transition: opacity .15s }
}
