/* ==========================================================================
   THIÊN MỆNH GIA PHẢ — TOP-TIER VIETNAMESE TỬ VI & THẦN SỐ HỌC PORTAL CSS
   Supports Imperial Dark Gold (default) & Parchment Giấy Dó Light Theme
   ========================================================================== */
:root {
  --bg-primary: #0b0e16;
  --bg-secondary: #121726;
  --bg-card: #161c2e;
  --bg-card-hover: #1d253d;
  --bg-palace: #131929;
  --bg-thienban: #0f1422;
  --border-subtle: rgba(212, 175, 55, 0.22);
  --border-strong: rgba(212, 175, 55, 0.58);
  --gold: #e2b94b;
  --gold-light: #f6dc8b;
  --gold-dim: #9e7e2a;
  --crimson: #d9464f;
  --jade: #2dd4bf;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-soft: #cbd5e1;
  --shadow-lg: 0 18px 42px rgba(0, 0, 0, 0.55);

  /* Ngũ Hành Colors */
  --hanh-kim: #e2e8f0;
  --hanh-moc: #34d399;
  --hanh-thuy: #38bdf8;
  --hanh-hoa: #fb7185;
  --hanh-tho: #fbbf24;
}

body.theme-light {
  --bg-primary: #f7f2e7;
  --bg-secondary: #efe6d5;
  --bg-card: #fffcf5;
  --bg-card-hover: #f9f1df;
  --bg-palace: #fffdf8;
  --bg-thienban: #f8f0df;
  --border-subtle: rgba(139, 30, 30, 0.22);
  --border-strong: rgba(139, 30, 30, 0.55);
  --gold: #9a2b2b;
  --gold-light: #7c1d1d;
  --gold-dim: #b45309;
  --crimson: #b91c1c;
  --jade: #0f766e;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-soft: #334155;
  --shadow-lg: 0 12px 30px rgba(92, 64, 28, 0.12);

  --hanh-kim: #475569;
  --hanh-moc: #059669;
  --hanh-thuy: #0284c7;
  --hanh-hoa: #dc2626;
  --hanh-tho: #d97706;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 0%, rgba(226, 185, 75, 0.08), transparent 45%), var(--bg-primary);
  color: var(--text-main);
  line-height: 1.62;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea, select, .allow-copy {
  -webkit-user-select: text;
  user-select: text;
}

/* ---------------- COMMERCIAL TRUST BANNER, MODALS & WATERMARK ---------------- */
.trust-strip {
  background: linear-gradient(90deg, rgba(226, 185, 75, 0.16), rgba(45, 212, 191, 0.10), rgba(226, 185, 75, 0.14));
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
}
.trust-strip-inner {
  max-width: 1460px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.choice-chip {
  padding: 0.42rem 0.82rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-soft);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
}
.choice-chip:hover {
  border-color: var(--gold);
}
.choice-chip.selected {
  background: rgba(226, 185, 75, 0.22);
  border-color: var(--gold);
  color: var(--gold-light);
}

.template-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.95rem 1.05rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.template-card:hover, .template-card.featured {
  border-color: var(--gold);
  background: var(--bg-card-hover);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.82);
  backdrop-filter: blur(6px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal-backdrop.open {
  display: flex;
}
.modal-box {
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  border-radius: 16px;
  max-width: 960px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.45rem 1.65rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
  position: relative;
}

.pkg-card {
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.pkg-card.active {
  border-color: var(--gold);
  background: linear-gradient(155deg, rgba(226, 185, 75, 0.16), var(--bg-secondary));
  box-shadow: 0 0 20px rgba(226, 185, 75, 0.18);
}

.qr-frame {
  background: #ffffff;
  padding: 0.75rem;
  border-radius: 12px;
  display: inline-block;
  max-width: 245px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.qr-frame img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.paywall-gate {
  border: 1.5px dashed var(--gold);
  background: linear-gradient(135deg, rgba(226, 185, 75, 0.11), rgba(18, 23, 38, 0.92));
  border-radius: 14px;
  padding: 1.4rem;
  text-align: center;
  margin: 1rem 0;
}

.watermark-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  opacity: 0.035;
  background-size: 360px 220px;
  background-repeat: repeat;
}

h1, h2, h3, .serif-title {
  font-family: 'Playfair Display', 'Cormorant Garamond', Georgia, serif;
  letter-spacing: 0.01em;
}

/* ---------------- HEADER & GLOBAL BAR ---------------- */
.imperial-header {
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, rgba(18, 23, 38, 0.96), rgba(11, 14, 22, 0.92));
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.85rem 1.5rem;
}
body.theme-light .imperial-header {
  background: linear-gradient(180deg, rgba(247, 242, 231, 0.96), rgba(239, 230, 213, 0.94));
}

.header-inner {
  max-width: 1460px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.bagua-crest {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  display: grid;
  place-items: center;
  font-size: 1.45rem;
  color: var(--gold);
  background: radial-gradient(circle, rgba(226, 185, 75, 0.18), transparent);
  box-shadow: 0 0 18px rgba(226, 185, 75, 0.25);
}

.brand-text h1 {
  font-size: 1.28rem;
  color: var(--gold-light);
  font-weight: 700;
}

.brand-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.ctrl-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text-soft);
}

.ctrl-pill select, .ctrl-pill input {
  background: transparent;
  border: none;
  color: var(--gold-light);
  font-weight: 600;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.ctrl-pill select option {
  background: var(--bg-card);
  color: var(--text-main);
}

.btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-main);
  padding: 0.48rem 0.95rem;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:hover {
  border-color: var(--gold);
  background: var(--bg-card-hover);
}
.btn-gold {
  background: linear-gradient(135deg, #d4af37, #b5891c);
  color: #0b0e16;
  border-color: #f6dc8b;
}
.btn-gold:hover {
  filter: brightness(1.08);
  color: #0b0e16;
}
.btn-danger {
  border-color: rgba(217, 70, 79, 0.45);
  color: var(--hanh-hoa);
}

/* ---------------- MEMBER BAR & NAVIGATION TABS ---------------- */
.main-container {
  max-width: 1460px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 4rem;
}

.member-Ribbon {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.member-card-mini {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  transition: all 0.22s ease;
  position: relative;
  overflow: hidden;
}
.member-card-mini:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}
.member-card-mini.active {
  border: 1.5px solid var(--gold);
  box-shadow: 0 0 24px rgba(226, 185, 75, 0.18);
  background: linear-gradient(145deg, var(--bg-card-hover), var(--bg-card));
}

.member-card-mini .m-role {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
  font-weight: 700;
}
.member-card-mini .m-name {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 0.15rem 0;
}
.member-card-mini .m-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
}

.tab-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-soft);
  padding: 0.58rem 1rem;
  border-radius: 9px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn:hover {
  border-color: var(--gold);
  color: var(--gold-light);
}
.tab-btn.active {
  background: linear-gradient(135deg, rgba(226, 185, 75, 0.22), rgba(226, 185, 75, 0.08));
  border-color: var(--gold);
  color: var(--gold-light);
  box-shadow: inset 0 0 12px rgba(226, 185, 75, 0.15);
}

.tab-panel {
  display: none;
  animation: fadeIn 0.25s ease;
}
.tab-panel.active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- CARDS, BADGES & GRIDS ---------------- */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.35rem;
  box-shadow: var(--shadow-lg);
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
  margin-bottom: 1.1rem;
}
.section-header h2 {
  font-size: 1.35rem;
  color: var(--gold-light);
}
.section-header .sub {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.15rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.9rem; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  border: 1px solid currentColor;
}
.hanh-Kim { color: var(--hanh-kim); }
.hanh-Mộc { color: var(--hanh-moc); }
.hanh-Thủy { color: var(--hanh-thuy); }
.hanh-Hỏa { color: var(--hanh-hoa); }
.hanh-Thổ { color: var(--hanh-tho); }

.callout-gold {
  background: linear-gradient(90deg, rgba(226, 185, 75, 0.12), rgba(226, 185, 75, 0.03));
  border-left: 4px solid var(--gold);
  padding: 1rem 1.2rem;
  border-radius: 0 10px 10px 0;
  margin: 0.9rem 0;
}

/* ==========================================================================
   TRADITIONAL 12-PALACE TỬ VI BOARD (4x4 GRID + SVG TAM HỢP LINES)
   ========================================================================== */
.laso-wrapper {
  position: relative;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.laso-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(235px, 1fr));
  grid-template-rows: repeat(4, minmax(215px, auto));
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-palace);
  position: relative;
  min-width: 960px;
}

.palace-cell {
  border: 1px solid var(--border-subtle);
  padding: 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  cursor: pointer;
  transition: background 0.18s ease, box-shadow 0.18s ease;
  background: var(--bg-palace);
  z-index: 2;
}
.palace-cell:hover {
  background: var(--bg-card-hover);
}
.palace-cell.selected-palace {
  box-shadow: inset 0 0 0 2px var(--gold);
  background: rgba(226, 185, 75, 0.08);
}
.palace-cell.tamhop-palace {
  box-shadow: inset 0 0 0 1.5px rgba(45, 212, 191, 0.55);
}
.palace-cell.is-menh-cell {
  background: linear-gradient(180deg, rgba(226, 185, 75, 0.10), transparent 45%);
}

.p-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.74rem;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.2);
  padding-bottom: 0.28rem;
  margin-bottom: 0.35rem;
}
.p-canchichi {
  color: var(--text-muted);
  font-weight: 600;
}
.p-cungname {
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--gold-light);
  letter-spacing: 0.03em;
}
.p-than-tag {
  background: var(--crimson);
  color: #fff;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.66rem;
  margin-left: 0.25rem;
  font-weight: 700;
}
.p-daivan {
  font-weight: 700;
  color: var(--jade);
  font-family: 'JetBrains Mono', monospace;
}

.p-chinh-list {
  text-align: center;
  min-height: 2.35rem;
  margin-bottom: 0.35rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
}
.chinh-star {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.vcd-label {
  font-size: 0.76rem;
  font-style: italic;
  color: var(--text-muted);
}

.p-phu-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  font-size: 0.73rem;
  line-height: 1.38;
  flex: 1;
}
.phu-cat { text-align: left; }
.phu-hung { text-align: right; }
.phu-item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.phu-item.tu-hoa {
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.p-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px dashed rgba(148, 163, 184, 0.2);
  padding-top: 0.28rem;
  margin-top: 0.38rem;
}
.p-trangsinh {
  font-weight: 700;
  color: var(--text-soft);
}
.p-tuan-triet {
  display: inline-flex;
  gap: 0.25rem;
}
.tt-pill {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.05rem 0.38rem;
  border-radius: 3px;
  letter-spacing: 0.04em;
}
.tt-triet { background: #991b1b; color: #fecaca; border: 1px solid #f87171; }
.tt-tuan  { background: #1e3a8a; color: #bfdbfe; border: 1px solid #60a5fa; }
.dv-active-tag {
  background: rgba(45, 212, 191, 0.18);
  color: var(--jade);
  border: 1px solid var(--jade);
  font-size: 0.64rem;
  padding: 0.04rem 0.32rem;
  border-radius: 3px;
  font-weight: 700;
}

/* Center Thiên Bàn (spans rows 2..3, cols 2..3) */
.thien-ban {
  grid-column: 2 / 4;
  grid-row: 2 / 4;
  background: var(--bg-thienban);
  border: 2px solid var(--border-strong);
  padding: 1.15rem 1.35rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.tb-svg-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.tb-header {
  text-align: center;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.6rem;
}
.tb-header .tb-subtitle {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
  font-weight: 700;
}
.tb-header h3 {
  font-size: 1.4rem;
  color: var(--gold-light);
  margin: 0.15rem 0;
}

.tb-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.8rem;
  margin: 0.65rem 0;
}
.tb-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted rgba(148, 163, 184, 0.18);
  padding: 0.18rem 0;
}
.tb-row span:first-child { color: var(--text-muted); }
.tb-row span:last-child { font-weight: 600; text-align: right; }

.tb-han-box {
  background: rgba(226, 185, 75, 0.07);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.78rem;
}

/* ---------------- TIMELINE & NUMEROLOGY ---------------- */
.wave-chart-box {
  width: 100%;
  overflow-x: auto;
  padding: 0.5rem 0;
}

.year-selector-strip {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.5rem 0 0.85rem;
}
.year-chip {
  padding: 0.35rem 0.68rem;
  border-radius: 7px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.year-chip.active {
  background: var(--gold);
  color: #0b0e16;
  border-color: var(--gold-light);
}

.pytha-grid {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  grid-template-rows: repeat(3, 68px);
  gap: 6px;
  margin: 0.75rem auto;
  justify-content: center;
}
.pytha-cell {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--gold-light);
}
.pytha-cell.empty {
  opacity: 0.35;
  border-style: dashed;
  color: var(--text-muted);
}
.pytha-cell small {
  font-size: 0.63rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------------- FORMS & CUSTOMIZER ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}
.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.86rem;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.data-table th, .data-table td {
  padding: 0.68rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  color: var(--gold);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.score-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
  margin-top: 0.35rem;
}
.score-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--jade), var(--gold));
  border-radius: 999px;
}

@media print {
  .imperial-header, .nav-tabs, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .section-card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
