/* =========================================================
   TỨ PHỦ — Custom styles
   Typography, texture, motion, and heritage details
   ========================================================= */

:root {
  --bg-dark: #190F12;
  --surface-dark: #2A1A1C;
  --surface-elevated: #352326;
  --primary: #742B32;
  --primary-hover: #913C43;
  --gold: #C49A59;
  --gold-light: #E4C58C;
  --text-light: #F4E6D1;
  --text-muted: #D5BA99;
  --border-dark: #62443C;
  --paper: #F5EBDD;
  --paper-text: #33241F;
  --header-h: 72px;
}

@media (max-width: 767px) {
  :root {
    --header-h: 60px;
  }
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  background: var(--bg-dark);
  color: var(--text-light);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
.font-display {
  font-family: "Noto Serif", "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

/* Subtle lacquer / paper textures */
.texture-dark {
  --dark-texture: url("../images/textures/phuong-vu-hoa-may.jpg");
  background-color: var(--bg-dark);
  background-image:
    linear-gradient(
      180deg,
      rgba(25, 15, 18, 0.88) 0%,
      rgba(25, 15, 18, 0.78) 45%,
      rgba(25, 15, 18, 0.9) 100%
    ),
    linear-gradient(
      105deg,
      rgba(25, 15, 18, 0.72) 0%,
      rgba(25, 15, 18, 0.45) 55%,
      rgba(25, 15, 18, 0.7) 100%
    ),
    var(--dark-texture);
  background-size: auto, auto, cover;
  background-position: center;
  background-repeat: no-repeat;
}

.texture-dark:nth-child(3n + 2 of .texture-dark) {
  --dark-texture: url("../images/textures/phi-dieu-tu-phu.jpg");
}

.texture-dark:nth-child(3n of .texture-dark) {
  --dark-texture: url("../images/textures/long-phuong-ma-vang.png");
}

.texture-surface {
  background-color: var(--surface-dark);
  background-image:
    linear-gradient(180deg, rgba(196, 154, 89, 0.04), transparent 40%);
}

.texture-paper {
  --paper-ornament: url("../images/ornaments/trong-dong.png");
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(98, 68, 60, 0.06), transparent 60%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
}

/* Góc trang trí nhỏ — luân phiên 6 biểu tượng Đạo Mẫu */
.texture-paper:nth-child(6n + 2 of .texture-paper) {
  --paper-ornament: url("../images/ornaments/thanh-mau.png");
}

.texture-paper:nth-child(6n + 3 of .texture-paper) {
  --paper-ornament: url("../images/ornaments/den-phu.png");
}

.texture-paper:nth-child(6n + 4 of .texture-paper) {
  --paper-ornament: url("../images/ornaments/tu-linh.png");
}

.texture-paper:nth-child(6n + 5 of .texture-paper) {
  --paper-ornament: url("../images/ornaments/co-phuong.png");
}

.texture-paper:nth-child(6n of .texture-paper) {
  --paper-ornament: url("../images/ornaments/sen-huong.png");
}

.texture-paper::after {
  content: "";
  position: absolute;
  right: -0.75rem;
  bottom: -0.75rem;
  z-index: 0;
  width: min(300px, 58vw);
  aspect-ratio: 1;
  background: var(--paper-ornament) no-repeat center / contain;
  opacity: 0.13;
  pointer-events: none;
}

.texture-paper > * {
  position: relative;
  z-index: 1;
}

.texture-son {
  background-color: #5c2228;
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(196, 154, 89, 0.16), transparent 55%),
    linear-gradient(160deg, #6e2a31 0%, #4a1a1f 55%, #3a1519 100%);
}

/* Ornamental gold line */
.ornament-line {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--gold) 20%,
    var(--gold-light) 50%,
    var(--gold) 80%,
    transparent
  );
  opacity: 0.7;
}

.ornament-frame {
  position: relative;
  border: 1px solid rgba(196, 154, 89, 0.45);
  box-shadow:
    inset 0 0 0 4px rgba(25, 15, 18, 0.35),
    inset 0 0 0 5px rgba(196, 154, 89, 0.25);
}

.ornament-frame::before,
.ornament-frame::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: var(--gold);
  border-style: solid;
  opacity: 0.8;
  pointer-events: none;
}

.ornament-frame::before {
  top: 8px;
  left: 8px;
  border-width: 1px 0 0 1px;
}

.ornament-frame::after {
  bottom: 8px;
  right: 8px;
  border-width: 0 1px 1px 0;
}

/* Header */
.site-header {
  height: var(--header-h);
  transition: background-color 0.25s ease, box-shadow 0.25s ease, backdrop-filter 0.25s ease;
}

.site-header.is-scrolled {
  background-color: rgba(25, 15, 18, 0.94);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 0 rgba(196, 154, 89, 0.18);
}

.nav-dropdown {
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

.nav-dropdown.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-trigger[aria-expanded="true"] {
  color: var(--gold-light);
}

/* Mobile drawer */
.mobile-drawer {
  transform: translateX(100%);
  transition: transform 0.28s ease;
}

.mobile-drawer.is-open {
  transform: translateX(0);
}

.mobile-overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.mobile-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.accordion-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.28s ease;
}

.accordion-panel.is-open {
  max-height: 480px;
}

/* Search overlay */
.search-overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s;
}

.search-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

/* Prototype modal / toast */
.proto-modal-backdrop {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
}

.proto-modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.proto-modal {
  transform: translateY(10px) scale(0.98);
  transition: transform 0.22s ease;
}

.proto-modal-backdrop.is-open .proto-modal {
  transform: translateY(0) scale(1);
}

/* Hero banner — phượng vũ / họa mây chìm dưới chữ (dùng chung mọi trang) */
.hero-banner {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background-color: var(--bg-dark);
  background-image:
    linear-gradient(
      105deg,
      rgba(25, 15, 18, 0.92) 0%,
      rgba(25, 15, 18, 0.78) 38%,
      rgba(25, 15, 18, 0.58) 68%,
      rgba(25, 15, 18, 0.78) 100%
    ),
    linear-gradient(
      180deg,
      rgba(25, 15, 18, 0.55) 0%,
      rgba(25, 15, 18, 0.32) 28%,
      rgba(25, 15, 18, 0.4) 58%,
      rgba(25, 15, 18, 0.9) 100%
    ),
    url("../images/hero/phuong-vu-hoa-may.png");
  background-size: auto, auto, cover;
  background-position: center;
  background-repeat: no-repeat;
}

.hero-banner--tall {
  min-height: min(78vh, 720px);
}

/* Lớp media tùy chọn (ảnh khác / section phụ) */
.hero-banner__media {
  z-index: 0;
}

.hero-banner__image {
  opacity: 0.42;
  filter: brightness(0.55) contrast(0.92) saturate(0.85);
  transform: scale(1.02);
}

.hero-banner__veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      105deg,
      rgba(25, 15, 18, 0.92) 0%,
      rgba(25, 15, 18, 0.78) 38%,
      rgba(25, 15, 18, 0.55) 68%,
      rgba(25, 15, 18, 0.72) 100%
    ),
    linear-gradient(
      180deg,
      rgba(25, 15, 18, 0.55) 0%,
      transparent 28%,
      transparent 58%,
      rgba(25, 15, 18, 0.88) 100%
    ),
    radial-gradient(ellipse at 72% 48%, rgba(116, 43, 50, 0.18), transparent 55%);
}

.hero-glow {
  background:
    radial-gradient(ellipse at 50% 40%, rgba(196, 154, 89, 0.18), transparent 62%),
    radial-gradient(ellipse at 70% 80%, rgba(116, 43, 50, 0.35), transparent 55%);
}

/* Placeholder image panels */
.img-placeholder {
  background:
    linear-gradient(145deg, #3a2427 0%, #2a1a1c 45%, #41282c 100%);
  position: relative;
  overflow: hidden;
}

.img-placeholder::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 40%, rgba(196, 154, 89, 0.08) 50%, transparent 60%);
  pointer-events: none;
}

.img-placeholder-paper {
  background:
    linear-gradient(160deg, #ebe0d0 0%, #dccfba 100%);
}

/* Quote marks */
.quote-mark::before {
  content: "“";
  font-family: "Noto Serif", serif;
  font-size: 2.5rem;
  line-height: 1;
  color: var(--gold);
  opacity: 0.55;
  display: block;
  margin-bottom: 0.25rem;
}

/* Scroll top */
.scroll-top {
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.scroll-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Carousel */
.carousel-track {
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.carousel-track::-webkit-scrollbar {
  display: none;
}

.carousel-track > * {
  scroll-snap-align: start;
}

/* Focus */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Utility helpers beyond Tailwind CDN config */
.text-balance {
  text-wrap: balance;
}

.section-pad {
  padding-top: 4rem;
  padding-bottom: 4rem;
}

@media (min-width: 1024px) {
  .section-pad {
    padding-top: 5rem;
    padding-bottom: 5rem;
  }
}

body.is-locked {
  overflow: hidden;
}

/* ---------- Sacred council diagram ---------- */
.diagram-shell {
  border: 1px solid rgba(196, 154, 89, 0.35);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(116, 43, 50, 0.18), transparent 55%),
    var(--surface-dark);
}

.diagram-node {
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--border-dark);
  background: var(--surface-elevated);
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.diagram-node:hover,
.diagram-node:focus-visible {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.diagram-node.is-active {
  border-color: var(--gold-light);
  box-shadow: 0 0 0 1px rgba(228, 197, 140, 0.35);
}

.diagram-node__media {
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--bg-dark);
}

.diagram-node__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.diagram-node__body {
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem 1rem;
}

.diagram-node__icon {
  display: inline-flex;
  width: 1.75rem;
  height: 1.75rem;
  margin-bottom: 0.4rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.4rem;
  border: 1px solid rgba(196, 154, 89, 0.35);
  color: var(--gold);
}

.featured-tab.is-active {
  color: var(--gold-light);
  border-color: var(--gold);
  background: rgba(196, 154, 89, 0.1);
}

.directory-toolbar select,
.directory-toolbar input {
  min-height: 42px;
}

/* ---------- Sacred directory (danh-sach) ---------- */
.quick-groups {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.quick-group-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  scroll-snap-align: start;
  border-radius: 999px;
  border: 1px solid var(--border-dark);
  background: var(--surface-dark);
  padding: 0.45rem 0.85rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.quick-group-btn:hover,
.quick-group-btn:focus-visible {
  border-color: var(--gold);
  color: var(--gold-light);
}

.quick-group-btn.is-active {
  border-color: var(--gold);
  background: rgba(116, 43, 50, 0.35);
  color: var(--text-light);
}

.quick-group-count {
  border-radius: 999px;
  background: rgba(25, 15, 18, 0.45);
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
  color: var(--gold-light);
}

.alpha-index {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.alpha-btn {
  min-width: 2rem;
  height: 2rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-dark);
  background: var(--surface-elevated);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.alpha-btn:hover:not(:disabled),
.alpha-btn:focus-visible:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold-light);
}

.alpha-btn.is-active {
  border-color: var(--gold);
  background: rgba(196, 154, 89, 0.12);
  color: var(--gold-light);
}

.alpha-btn:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.dir-results--grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

@media (min-width: 480px) {
  .dir-results--grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .dir-results--grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .dir-results--grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.dir-results--list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dir-grid-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--border-dark);
  background: var(--surface-dark);
  transition: border-color 0.15s ease;
}

.dir-grid-card:hover {
  border-color: rgba(196, 154, 89, 0.55);
}

.dir-list-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 0.85rem;
  align-items: start;
  padding: 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-dark);
  background: var(--surface-dark);
}

@media (min-width: 768px) {
  .dir-list-item {
    grid-template-columns: 88px 1fr auto;
    align-items: center;
  }
}

.dir-list-thumb {
  overflow: hidden;
  border-radius: 8px;
  aspect-ratio: 1;
  background: var(--bg-dark);
}

.dir-list-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dir-list-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  grid-column: 2 / -1;
}

@media (min-width: 768px) {
  .dir-list-meta {
    grid-column: auto;
    align-items: flex-end;
    text-align: right;
  }
}

.view-toggle-btn.is-active {
  border-color: var(--gold);
  color: var(--gold-light);
  background: rgba(196, 154, 89, 0.1);
}

.page-btn {
  display: inline-flex;
  min-width: 2.25rem;
  height: 2.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.45rem;
  border: 1px solid var(--border-dark);
  background: var(--surface-elevated);
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.page-btn:hover:not(:disabled),
.page-btn:focus-visible:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold-light);
}

.page-btn.is-active {
  border-color: var(--gold);
  color: var(--text-light);
  background: rgba(116, 43, 50, 0.4);
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
