/* ==================================================================
   GIA PHẢ — Nền tảng thiết kế
   Bảng màu lấy từ chất liệu truyền thống Việt Nam:
   giấy dó, mực nho, son triện, thếp vàng, gỗ mít, men lam Bát Tràng.
   ================================================================== */

:root {
  /* --- Giấy & mực --- */
  --giay: #f6efdd;
  --giay-sang: #fdf9ef;
  --giay-nhat: #efe4c8;
  --giay-toi: #e5d7b6;
  --muc: #2a2118;
  --muc-nhat: #5b4c3c;
  --muc-mo: #8a7a66;

  /* --- Son (đỏ triện, sơn mài) --- */
  --son: #9e2b25;
  --son-dam: #74190f;
  --son-sang: #c0392b;
  --son-mo: rgba(158, 43, 37, 0.1);

  /* --- Thếp vàng --- */
  --vang: #c9a227;
  --vang-sang: #e6c766;
  --vang-dam: #96741a;
  --vang-mo: rgba(201, 162, 39, 0.16);

  /* --- Gỗ & men lam --- */
  --go: #6b4423;
  --go-dam: #3f2712;
  --lam: #2f5d62;
  --lam-sang: #4a878e;
  --la: #4b6a3a;

  /* --- Vai trò --- */
  --nen: var(--giay);
  --nen-the: var(--giay-sang);
  --vien: rgba(107, 68, 35, 0.24);
  --vien-dam: rgba(107, 68, 35, 0.45);
  --chu: var(--muc);
  --chu-phu: var(--muc-nhat);
  --chu-mo: var(--muc-mo);

  /* --- Chữ --- */
  --font-title: 'Playfair Display', 'Noto Serif', Georgia, 'Times New Roman', serif;
  --font-serif: 'Noto Serif', Georgia, 'Times New Roman', serif;
  --font-ui: 'Be Vietnam Pro', 'Segoe UI', system-ui, -apple-system, sans-serif;

  /* --- Nhịp --- */
  --r-sm: 4px;
  --r: 8px;
  --r-lg: 14px;
  --bong-1: 0 1px 2px rgba(63, 39, 18, 0.08), 0 2px 8px rgba(63, 39, 18, 0.06);
  --bong-2: 0 2px 6px rgba(63, 39, 18, 0.1), 0 12px 32px rgba(63, 39, 18, 0.12);
  --bong-3: 0 8px 24px rgba(63, 39, 18, 0.16), 0 32px 64px rgba(63, 39, 18, 0.18);
  --max: 1180px;
}

/* ---------------- Chế độ tối: "sơn mài đêm" ---------------- */
:root[data-theme='toi'] {
  --giay: #1c1712;
  --giay-sang: #241d16;
  --giay-nhat: #2e251c;
  --giay-toi: #3a2f23;
  --muc: #f0e6d2;
  --muc-nhat: #cbbca2;
  --muc-mo: #9a8b74;
  --son: #d4553f;
  --son-dam: #a83b28;
  --son-sang: #e8735a;
  --son-mo: rgba(212, 85, 63, 0.16);
  --vang: #e3c266;
  --vang-sang: #f2dc9a;
  --vang-dam: #b99a3f;
  --vang-mo: rgba(227, 194, 102, 0.14);
  --go: #c19a6b;
  --lam: #7fb3b8;
  --lam-sang: #a3cdd1;
  --vien: rgba(227, 194, 102, 0.2);
  --vien-dam: rgba(227, 194, 102, 0.38);
  --bong-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  --bong-2: 0 2px 6px rgba(0, 0, 0, 0.45), 0 12px 32px rgba(0, 0, 0, 0.4);
  --bong-3: 0 8px 24px rgba(0, 0, 0, 0.5), 0 32px 64px rgba(0, 0, 0, 0.5);
}

/* ------------------------- Nền tảng ------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-serif);
  font-size: 16.5px;
  line-height: 1.72;
  color: var(--chu);
  background-color: var(--nen);
  background-image:
    radial-gradient(ellipse at 12% 0%, var(--vang-mo), transparent 55%),
    radial-gradient(ellipse at 88% 100%, var(--son-mo), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Thớ giấy dó — sợi xơ mảnh, rất nhạt */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
  background-image:
    repeating-linear-gradient(94deg, rgba(107, 68, 35, 0.035) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(4deg, rgba(107, 68, 35, 0.028) 0 1px, transparent 1px 11px);
}

:root[data-theme='toi'] body::before {
  opacity: 0.3;
  background-image:
    repeating-linear-gradient(94deg, rgba(227, 194, 102, 0.05) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(4deg, rgba(227, 194, 102, 0.04) 0 1px, transparent 1px 11px);
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--son);
  text-decoration-color: color-mix(in srgb, var(--son) 35%, transparent);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--son-dam);
}

:focus-visible {
  outline: 2.5px solid var(--vang);
  outline-offset: 2px;
  border-radius: 3px;
}

::selection {
  background: var(--vang-mo);
  color: var(--chu);
}

/* --------------------------- Chữ ---------------------------- */

h1,
h2,
h3,
h4 {
  font-family: var(--font-title);
  font-weight: 700;
  /* Tiếng Việt có dấu mũ kép (Ầ, Ế, Ổ, Ữ…) cao hơn chữ Latin thường —
     line-height dưới 1.3 sẽ cắt mất nét trên. */
  line-height: 1.32;
  margin: 0 0 0.5em;
  color: var(--muc);
  letter-spacing: -0.005em;
}

h1 { font-size: clamp(1.9rem, 4.2vw, 2.9rem); }
h2 { font-size: clamp(1.4rem, 2.8vw, 2rem); }
h3 { font-size: clamp(1.15rem, 2vw, 1.35rem); }
h4 { font-size: 1.05rem; }

p { margin: 0 0 1em; }

/* Tiêu đề kiểu hoành phi: chữ hoa, giãn nét, có vạch son hai bên */
.hoanh-phi {
  font-family: var(--font-title);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: var(--son);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9em;
}

.hoanh-phi::before,
.hoanh-phi::after {
  content: '';
  height: 1px;
  flex: 1;
  max-width: 5rem;
  background: linear-gradient(90deg, transparent, var(--vang), transparent);
}

/* Câu đối — hai vế đối xứng */
.cau-doi {
  font-family: var(--font-title);
  font-style: italic;
  color: var(--go);
  text-align: center;
  line-height: 1.9;
  font-size: 1.02rem;
}

:root[data-theme='toi'] .cau-doi { color: var(--vang-sang); }

.chu-nho {
  font-size: 0.86rem;
  color: var(--chu-mo);
  line-height: 1.6;
}

.nhan {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--chu-mo);
}

.mo { color: var(--chu-mo); }
.phu { color: var(--chu-phu); }
.son-chu { color: var(--son); }
.vang-chu { color: var(--vang-dam); }
.giua { text-align: center; }
.dam { font-weight: 700; }
.nghieng { font-style: italic; }

/* --------------------- Hoa văn trang trí --------------------- */

/* Đường triện: hoa văn chữ Vạn/hồi văn chạy ngang */
.hoa-van-tri {
  height: 12px;
  background-image:
    repeating-linear-gradient(90deg,
      var(--vien-dam) 0 2px, transparent 2px 6px,
      var(--vien-dam) 6px 8px, transparent 8px 20px);
  opacity: 0.5;
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}

/* Vạch phân cách có hạt ngọc ở giữa */
.phan-cach {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 2rem 0;
  color: var(--vang);
}

.phan-cach::before,
.phan-cach::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--vien-dam), transparent);
}

.phan-cach .hat {
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  background: var(--vang);
  box-shadow: 0 0 0 3px var(--vang-mo);
}

/* Ngôi sao trống đồng Đông Sơn (SVG dựng sẵn dùng qua .sao-trong-dong) */
.sao-trong-dong {
  width: 46px;
  height: 46px;
  flex: none;
  color: var(--son);
  opacity: 0.9;
}

/* Con dấu son */
.con-dau {
  display: inline-grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border: 2.5px solid var(--son);
  border-radius: 6px;
  color: var(--son);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.15;
  text-align: center;
  letter-spacing: 0.04em;
  padding: 6px;
  transform: rotate(-7deg);
  opacity: 0.86;
  box-shadow: inset 0 0 0 1.5px var(--son);
}

/* Khung giấy có viền kép kiểu bìa gia phả */
.khung-kep {
  border: 1px solid var(--vien-dam);
  box-shadow: inset 0 0 0 1px var(--nen-the), inset 0 0 0 4px var(--vien);
  border-radius: var(--r);
}

/* ------------------------- Bố cục --------------------------- */

.bao {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
  position: relative;
  z-index: 1;
}

.hep { max-width: 760px; }

.luoi {
  display: grid;
  gap: 1.15rem;
}

.chong { display: flex; flex-direction: column; gap: 1rem; }
.hang { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.day { flex: 1 1 auto; }

.an-di { display: none !important; }

.chi-doc-man-hinh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
