/* =========================================================
   GIA PHẢ ĐẠI VIỆT — Template 3 "Từ Đường Cổ"
   Phong cách cổ kính — trang nghiêm đậm đặc: sơn son thếp vàng,
   gỗ mun/gỗ lim, hồi văn, vân mây, nhiều lớp khung chạm.
   ========================================================= */

:root {
  --ivory: #f2e6c9;
  --ivory-soft: #f8efd9;
  --paper: #f7ecd3;
  --ink: #1c1006;
  --ink-soft: #4a2f1a;

  --maroon-950: #1c0508;
  --maroon-900: #2a0a0d;
  --maroon-800: #3d0c10;
  --maroon-700: #501019;
  --maroon-600: #6d1721;
  --maroon-500: #8a1e29;
  --maroon-400: #a52a35;

  --gold-900: #5c4413;
  --gold-800: #7a5c1e;
  --gold-700: #8a6b1f;
  --gold-600: #b8860b;
  --gold-500: #cda63f;
  --gold-400: #ddc06a;
  --gold-300: #ecdca0;
  --gold-200: #f5e6c0;

  --wood-900: #2b1608;
  --wood-800: #3f2210;
  --wood-700: #5c341a;
  --wood-600: #7a4726;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--ivory);
  color: var(--ink);
  font-family: "Be Vietnam Pro", "Noto Sans", sans-serif;
  overflow-x: hidden;
}

.font-serif-display {
  font-family: "Noto Serif", "Noto Serif Display", serif;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--ivory); }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, var(--gold-600), var(--gold-800)); border-radius: 999px; border: 2px solid var(--ivory); }

/* ---------- Selection ---------- */
::selection { background: var(--gold-600); color: var(--gold-200); }

/* ---------- Texture nền giấy/lụa cổ ---------- */
.bg-paper-texture {
  background-color: var(--ivory);
  background-image:
    radial-gradient(rgba(92, 68, 19, 0.09) 1px, transparent 1px),
    radial-gradient(rgba(92, 68, 19, 0.07) 1px, transparent 1px),
    linear-gradient(135deg, rgba(122, 71, 38, 0.05) 0%, transparent 40%, rgba(122, 71, 38, 0.05) 100%);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  background-position: 0 0, 12px 12px, 0 0;
}

/* ---------- Nền sơn mài / gỗ trầm đậm đặc (thay cho bg-maroon-texture cũ) ---------- */
.bg-lacquer {
  background-color: var(--maroon-900);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(184, 134, 11, 0.14), transparent 38%),
    radial-gradient(circle at 88% 15%, rgba(184, 134, 11, 0.10), transparent 42%),
    radial-gradient(circle at 50% 100%, rgba(184, 134, 11, 0.08), transparent 55%),
    repeating-linear-gradient(118deg, rgba(0, 0, 0, 0.18) 0 1.5px, transparent 1.5px 7px),
    linear-gradient(180deg, var(--maroon-800) 0%, var(--maroon-900) 45%, var(--maroon-950) 100%);
}

/* ---------- Nền gỗ mun cho khối phụ ---------- */
.bg-wood {
  background-color: var(--wood-800);
  background-image:
    repeating-linear-gradient(92deg, rgba(0, 0, 0, 0.22) 0 2px, transparent 2px 9px),
    radial-gradient(circle at 30% 20%, rgba(205, 166, 63, 0.10), transparent 45%),
    linear-gradient(180deg, var(--wood-700), var(--wood-900));
}

/* ---------- Diềm hồi văn (hoạ tiết Á Đông dạng chữ Hồi / Greek-key) ---------- */
.meander-strip {
  height: 14px;
  width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 16'%3E%3Cpath d='M0 13 H9 V3 H18 V13 H27 V3 H36 V13 H40' fill='none' stroke='%23cda63f' stroke-width='2' stroke-linecap='square'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 40px 14px;
  background-position: center;
  opacity: 0.85;
}
.meander-strip.on-dark {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 16'%3E%3Cpath d='M0 13 H9 V3 H18 V13 H27 V3 H36 V13 H40' fill='none' stroke='%23ecdca0' stroke-width='2' stroke-linecap='square'/%3E%3C/svg%3E");
  opacity: 0.55;
}
.meander-strip.thin { height: 8px; background-size: 26px 8px; }

/* ---------- Khung ba lớp kiểu hoành phi / bia đá sơn son thếp vàng ---------- */
.frame-triple {
  position: relative;
  border: 2px solid var(--gold-600);
  box-shadow:
    inset 0 0 0 4px var(--paper),
    inset 0 0 0 6px var(--gold-700),
    inset 0 0 0 10px var(--paper),
    inset 0 0 0 12px var(--wood-700),
    0 25px 55px rgba(0, 0, 0, 0.35);
}
.frame-triple.on-dark {
  box-shadow:
    inset 0 0 0 4px var(--maroon-900),
    inset 0 0 0 6px var(--gold-600),
    inset 0 0 0 10px var(--maroon-900),
    inset 0 0 0 12px var(--gold-800),
    0 25px 55px rgba(0, 0, 0, 0.45);
}

/* ---------- Khung viền kép cũ, giữ cho phần tử nhỏ ---------- */
.frame-double {
  border: 1.5px solid var(--gold-600);
  outline: 1px solid var(--gold-700);
  outline-offset: 6px;
}

/* ---------- Khung góc chạm hoa văn (4 góc, mỗi góc một hoạ tiết vân mây) ---------- */
.corner-ornament {
  position: relative;
}
.corner-ornament .corner-svg {
  position: absolute;
  width: 34px;
  height: 34px;
  color: var(--gold-500);
  z-index: 10;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
}
.corner-ornament .corner-tl { top: -10px; left: -10px; }
.corner-ornament .corner-tr { top: -10px; right: -10px; transform: scaleX(-1); }
.corner-ornament .corner-bl { bottom: -10px; left: -10px; transform: scaleY(-1); }
.corner-ornament .corner-br { bottom: -10px; right: -10px; transform: scale(-1, -1); }

/* ---------- Kim ấn / triện đỏ trang trí (dùng nhiều nơi) ---------- */
.seal {
  width: 68px;
  height: 68px;
  background: linear-gradient(160deg, var(--maroon-600), var(--maroon-800));
  border: 2px solid var(--gold-500);
  color: var(--gold-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Serif", serif;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.05em;
  transform: rotate(-6deg);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(236, 220, 160, 0.25);
  border-radius: 5px;
}
.seal.seal-sm {
  width: 44px;
  height: 44px;
  font-size: 15px;
  transform: rotate(-8deg);
}

/* ---------- Tiêu đề mục: gạch hồi văn + thoi vàng hai bên ---------- */
.title-ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}
.title-ornament .line {
  height: 2px;
  width: 56px;
  background: linear-gradient(90deg, transparent, var(--gold-600));
}
.title-ornament .line.reverse {
  background: linear-gradient(90deg, var(--gold-600), transparent);
}
.title-ornament .diamond {
  width: 10px;
  height: 10px;
  background: var(--gold-600);
  border: 1px solid var(--gold-800);
  transform: rotate(45deg);
}

/* ---------- Chữ Hán-Nôm mờ trang trí nền lớn ---------- */
.hanviet-watermark {
  position: absolute;
  font-family: "Noto Serif", serif;
  font-weight: 900;
  color: var(--gold-400);
  opacity: 0.08;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

/* ---------- Ảnh tông màu hoài cổ (duotone), đậm hơn ---------- */
.duotone {
  position: relative;
  overflow: hidden;
}
.duotone img {
  filter: sepia(55%) saturate(150%) hue-rotate(-8deg) brightness(0.86) contrast(1.12);
  transition: transform 0.6s ease;
}
.duotone:hover img {
  transform: scale(1.06);
}
.duotone::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(42, 10, 13, 0.2), rgba(28, 5, 8, 0.65));
  mix-blend-mode: multiply;
}

/* ---------- Header shadow khi scroll ---------- */
header.is-scrolled {
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}

/* ---------- Card hover nâng nhẹ ---------- */
.rise-on-hover {
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.rise-on-hover:hover {
  transform: translateY(-6px);
  box-shadow: 0 22px 44px rgba(28, 16, 6, 0.28);
}

/* ---------- Nút viền vàng ---------- */
.btn-gold-outline {
  border: 1.5px solid var(--gold-500);
  color: var(--gold-300);
  transition: all 0.3s ease;
}
.btn-gold-outline:hover {
  background: var(--gold-500);
  color: var(--maroon-950);
}

/* ---------- Ánh sáng nến / đèn lồng ấm áp toả ở điểm nhấn ---------- */
.candle-glow {
  position: relative;
}
.candle-glow::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 520px;
  height: 520px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 196, 107, 0.30), rgba(255, 196, 107, 0.08) 45%, transparent 70%);
  filter: blur(10px);
  pointer-events: none;
  z-index: 0;
}

/* ---------- Huy hiệu dòng họ — hào quang toả sáng (hero) ---------- */
.hero-emblem-rays {
  background: repeating-conic-gradient(
    from 0deg,
    rgba(221, 192, 106, 0.65) 0deg 1.2deg,
    transparent 1.2deg 9deg
  );
  animation: hero-emblem-spin 60s linear infinite;
}
@keyframes hero-emblem-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .hero-emblem-rays { animation: none; }
}

/* ---------- Cột trụ cổng tam quan (hero đối xứng) ---------- */
.gate-pillar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 34px;
  background: linear-gradient(90deg, var(--wood-900), var(--wood-700) 45%, var(--wood-900));
  box-shadow: inset 0 0 0 2px rgba(205, 166, 63, 0.35);
}
.gate-pillar::before,
.gate-pillar::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 54px;
  height: 54px;
  transform: translateX(-50%) rotate(45deg);
  background: linear-gradient(135deg, var(--gold-600), var(--gold-800));
  border: 2px solid var(--gold-300);
}
.gate-pillar::before { top: -27px; }
.gate-pillar::after { bottom: -27px; }
.gate-pillar.left { left: 0; }
.gate-pillar.right { right: 0; }

/* ---------- Fade-in nhẹ khi cuộn tới ---------- */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.reveal.in-view {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Ẩn thanh cuộn (chuyên mục trượt ngang, v.v.) ---------- */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }

/* ---------- Cây phả hệ mini (teaser trang chủ) ---------- */
.tree, .tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
}
.tree ul {
  padding-top: 28px;
  position: relative;
}
.tree li {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  padding: 28px 14px 0 14px;
}
.tree li::before,
.tree li::after {
  content: "";
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 2px solid var(--gold-600);
  width: 50%;
  height: 28px;
}
.tree li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid var(--gold-600);
}
.tree li:only-child::before,
.tree li:only-child::after {
  display: none;
}
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before { border: 0 none; }
.tree li:last-child::after { border: 0 none; }
.tree li:last-child::before {
  border-right: 2px solid var(--gold-600);
  border-radius: 0 6px 0 0;
}
.tree li:first-child::after {
  border-radius: 6px 0 0 0;
}
.tree ul ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid var(--gold-600);
  width: 0;
  height: 28px;
}
.tree li .node {
  border: 1.5px solid var(--gold-600);
  background: linear-gradient(180deg, var(--paper), #ecd9ab);
  padding: 10px 16px;
  border-radius: 4px;
  min-width: 132px;
  box-shadow: 0 8px 18px rgba(28, 16, 6, 0.22), inset 0 0 0 3px var(--paper);
  outline: 1px solid var(--gold-700);
  outline-offset: -6px;
}

/* ---------- Accordion đời (details/summary) ---------- */
details.gen-accordion summary { cursor: pointer; list-style: none; }
details.gen-accordion summary::-webkit-details-marker { display: none; }
details.gen-accordion[open] .chevron { transform: rotate(180deg); }
.chevron { transition: transform 0.3s ease; }

/* ---------- Mobile nav (off-canvas drawer) ---------- */
#mobile-menu {
  position: fixed; top: 0; left: 0; height: 100vh; width: 82%; max-width: 320px;
  transform: translateX(-100%); transition: transform 0.35s ease; z-index: 60; overflow-y: auto;
}
#mobile-menu.open { transform: translateX(0); }
#mobile-menu-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 55;
  opacity: 0; pointer-events: none; transition: opacity 0.35s ease;
}
#mobile-menu-backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- Sơ đồ phả hệ tương tác (D3.js) ---------- */
#tree-chart {
  cursor: grab;
}
#tree-chart svg { display: block; }
#tree-chart .node { transition: opacity 0.3s ease; }
#tree-chart .node:hover rect.tree-node-rect {
  stroke: var(--gold-400);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45));
}
.tree-node-dim { opacity: 0.22; }
.tree-node-match {
  stroke: var(--gold-300) !important;
  stroke-width: 3px !important;
  filter: drop-shadow(0 0 10px rgba(205, 166, 63, 0.95)) !important;
}

/* Khung sơ đồ phả hệ — uy nghi, nhiều lớp viền như bằng sắc phong cổ */
.tree-frame {
  border: 3px solid var(--gold-700);
  box-shadow:
    inset 0 0 0 3px var(--maroon-900),
    inset 0 0 0 5px var(--gold-600),
    inset 0 0 0 8px var(--maroon-900),
    0 25px 60px rgba(0, 0, 0, 0.5);
  background: var(--maroon-950);
}

.tree-frame-ribbon {
  background: linear-gradient(90deg, var(--wood-900), var(--maroon-800) 50%, var(--wood-900));
  border-bottom: 1px solid rgba(205, 166, 63, 0.35);
}

/* Bộ lọc phả đồ trên mobile: thu gọn thành 1 nút, bấm mới mở */
#tree-filter-panel {
  animation: tree-filter-in 0.2s ease;
}
#tree-filter-panel.is-open {
  display: block !important;
}
@keyframes tree-filter-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.tree-canvas-bg {
  position: relative;
  background:
    radial-gradient(ellipse at center, rgba(205, 166, 63, 0.16), transparent 55%),
    radial-gradient(ellipse at center, transparent 55%, rgba(28, 5, 8, 0.35) 100%),
    var(--ivory);
}

.tree-zoom-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--gold-500);
  background: linear-gradient(180deg, var(--paper), #ecd9ab);
  color: var(--maroon-700);
  border-radius: 9999px;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(28, 16, 6, 0.35);
  transition: all 0.25s ease;
}
.tree-zoom-btn:hover {
  background: var(--maroon-700);
  color: var(--gold-300);
}

/* ---------- Thẻ thành viên (lưới danh sách) ---------- */
.member-card { text-align: center; }
.member-card .avatar-ring {
  box-shadow: 0 8px 18px rgba(28, 16, 6, 0.28), 0 0 0 3px var(--paper);
}

/* ---------- Album ---------- */
.album-card { cursor: pointer; }
.album-card:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}

/* ---------- Fancybox: chỉnh tông màu cho khớp theme ---------- */
.fancybox__backdrop {
  background: rgba(28, 5, 8, 0.96);
}
.fancybox__caption {
  font-family: "Be Vietnam Pro", sans-serif;
  color: var(--gold-300);
}
.fancybox__toolbar,
.fancybox__nav {
  --f-button-color: var(--gold-300);
}
.fancybox__thumbs {
  --f-thumb-selected-outline-color: var(--gold-500);
}
