/* ==========================================================
   佛法道靈珠風水 — "天盤 Celestial Luopan" design system (shared)
   Tokens, grain, header, buttons, section scaffolding, footer,
   reveals. Every public page and the staff portal load this.
   Page-specific styles live in home.css / tools-*.css / etc.
   Dark = 夜墨 (ink), Light (body.theme-bright) = 宣紙 (rice paper).
   ========================================================== */

:root {
  --bg: #0b0a09;
  --bg-2: #13110e;
  --bg-3: #1b1814;
  --fg: #efe6d4;
  --fg-2: #b9ae9a;
  --fg-3: #7d7465;
  --line: rgba(239, 230, 212, 0.12);
  --line-2: rgba(239, 230, 212, 0.24);
  --cinnabar: #e2462c;
  --cinnabar-2: #ff6a4d;
  --cinnabar-ink: #fff4ec;
  --jade: #5dbb9f;
  --gold: #d8b25a;
  --indigo: #6f86c9;
  --bone: #e9e2d2;
  --pool: #070605;

  /* 五方正色 — the five directions / five elements
     東 青(木)  南 赤(火)  西 白(金)  北 黑(水, shown as grey on ink)  中 黃(土) */
  --dir-e: #4caf6e;
  --dir-s: #e2462c;
  --dir-w: #eeeae2;
  --dir-w-ink: #eeeae2;   /* "white" when used as text/lines */
  --dir-n: #8b9097;
  --dir-c: #e6b83d;
  --dir-e-on: #07130b;    /* text colour on a flooded direction panel */
  --dir-s-on: #fff4ec;
  --dir-w-on: #15120e;
  --dir-n-on: #0b0c0e;
  --dir-c-on: #1a1203;
  --grain-opacity: 0.07;

  --f-han: 'Noto Serif TC', 'Songti TC', serif;
  --f-brush: 'Yuji Syuku', 'LXGW WenKai TC', 'Kaiti TC', 'STKaiti', 'Noto Serif TC', serif;
  /* kaishu with full 繁+简 coverage — for rare characters such as hexagram names */
  --f-kai: 'LXGW WenKai TC', 'Kaiti TC', 'STKaiti', 'Noto Serif TC', serif;
  --f-disp: 'Fraunces', 'Noto Serif TC', serif;
  --f-ui: 'Manrope', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'PingFang TC', 'Microsoft JhengHei', monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --gutter: clamp(16px, 4vw, 56px);
  --maxw: 1320px;
}

body.theme-bright {
  --bg: #f1e9da;
  --bg-2: #e9dfcc;
  --bg-3: #e1d5bf;
  --fg: #1c1712;
  --fg-2: #4f463b;
  --fg-3: #83786a;
  --line: rgba(28, 23, 18, 0.13);
  --line-2: rgba(28, 23, 18, 0.26);
  --cinnabar: #c3321b;
  --cinnabar-2: #de4a2f;
  --jade: #2d7c67;
  --gold: #9b7424;
  --indigo: #36508f;
  --bone: #fbf6ec;
  --dir-e: #2e7d4a;
  --dir-s: #c3321b;
  --dir-w: #ffffff;
  --dir-w-ink: #9a948a;
  --dir-n: #151515;
  --dir-c: #b8870f;
  --dir-e-on: #f3fbf5;
  --dir-s-on: #fff4ec;
  --dir-w-on: #15120e;
  --dir-n-on: #f1e9da;
  --dir-c-on: #fffaf0;
  --grain-opacity: 0.11;
}

/* 简体: the same three roles, matched fonts that actually contain the
   Simplified glyphs (Yuji Syuku has none of 结现传龙灵时…). Noto Serif SC is
   the same design as Noto Serif TC; Ma Shan Zheng is the brush kaishu. */
html[lang="zh-Hans"] {
  --f-han: 'Noto Serif SC', 'Noto Serif TC', 'Songti SC', serif;
  --f-brush: 'Ma Shan Zheng', 'LXGW WenKai TC', 'Kaiti SC', 'STKaiti', 'Noto Serif SC', serif;
  --f-kai: 'LXGW WenKai TC', 'Kaiti SC', 'STKaiti', 'Noto Serif SC', serif;
  --f-ui: 'Manrope', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'PingFang SC', 'Microsoft YaHei', monospace;
}
.brush { font-family: var(--f-brush); font-weight: 400; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--f-ui);
  font-size: 16px;
  line-height: 1.65;
  overflow-x: hidden;
  transition: background-color 0.5s var(--ease), color 0.5s var(--ease);
  -webkit-font-smoothing: antialiased;
}

/* Paper / ink grain over everything */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.45 0 0 0 0 0.4 0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}
body.theme-bright::after { mix-blend-mode: multiply; }

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--cinnabar); color: var(--cinnabar-ink); }

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

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 200;
  background: var(--cinnabar); color: var(--cinnabar-ink);
  padding: 10px 16px; border-radius: 2px; font-weight: 600;
}
.skip-link:focus { top: 12px; }

.han { font-family: var(--f-han); }
.mono { font-family: var(--f-mono); }

/* ---------- Qi-field canvas ---------- */
#qi-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}
main, .site-header, .site-footer { position: relative; z-index: 2; }

/* ==========================================================
   Header
   ========================================================== */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  transition: background-color 0.4s var(--ease), border-color 0.4s var(--ease), backdrop-filter 0.4s;
  border-bottom: 1px solid transparent;
}
.site-header.is-scrolled {
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom-color: var(--line);
}
.hdr-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 14px var(--gutter);
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.seal {
  width: 44px; height: 44px;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  background: var(--cinnabar);
  color: var(--cinnabar-ink);
  font-family: var(--f-han);
  font-weight: 900;
  font-size: 15px;
  line-height: 1;
  writing-mode: vertical-rl;
  letter-spacing: 1px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px var(--cinnabar), inset 0 0 0 3.5px var(--cinnabar-ink);
  transform: rotate(-3deg);
  transition: transform 0.5s var(--ease);
}
.brand:hover .seal { transform: rotate(3deg) scale(1.06); }
.brand-words { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-family: var(--f-han); font-weight: 900; font-size: 1.12rem; letter-spacing: 0.08em; }
.brand-sub { font-family: var(--f-mono); font-size: 0.6rem; letter-spacing: 0.22em; color: var(--fg-3); margin-top: 3px; }

.main-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-links { display: flex; align-items: center; gap: 2px; }
.nav-link {
  position: relative;
  padding: 8px 10px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--fg-2);
  transition: color 0.25s;
  white-space: nowrap;
}
.nav-link::after {
  content: '';
  position: absolute;
  left: 50%; bottom: 2px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--cinnabar);
  transform: translateX(-50%) scale(0);
  transition: transform 0.3s var(--ease);
}
.nav-link:hover, .nav-link:focus-visible { color: var(--fg); }
.nav-link:hover::after, .nav-link:focus-visible::after { transform: translateX(-50%) scale(1); }

.nav-extras { display: flex; align-items: center; gap: 8px; margin-left: 10px; }
.hdr-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23887d6d' fill='none' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 6px 26px 6px 12px;
  font-size: 0.78rem;
  color: var(--fg-2);
  cursor: pointer;
  max-width: 118px;
  text-overflow: ellipsis;
}
.hdr-select option { background: var(--bg-2); color: var(--fg); }

.hdr-cta {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px;
  background: var(--cinnabar);
  color: var(--cinnabar-ink);
  font-weight: 600;
  font-size: 0.86rem;
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.25s, transform 0.25s var(--ease);
}
.hdr-cta:hover { background: var(--cinnabar-2); transform: translateY(-1px); }

.menu-toggle {
  display: none;
  width: 44px; height: 44px;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.menu-toggle span {
  position: absolute; left: 13px; right: 13px; height: 1.5px;
  background: var(--fg);
  transition: transform 0.4s var(--ease), top 0.4s var(--ease);
}
.menu-toggle span:nth-child(1) { top: 18px; }
.menu-toggle span:nth-child(2) { top: 25px; }
.menu-toggle[aria-expanded="true"] span:nth-child(1) { top: 21px; transform: rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:nth-child(2) { top: 21px; transform: rotate(-45deg); }

@media (max-width: 1320px) {
  .menu-toggle { display: block; }
  .hdr-inner { gap: 12px; }
  .hdr-cta { margin-left: auto; }
  .main-nav {
    position: fixed;
    inset: 0;
    z-index: -1;
    margin: 0;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 28px;
    padding: 90px var(--gutter) 40px;
    background: var(--bg);
    clip-path: circle(0% at calc(100% - 40px) 36px);
    visibility: hidden;
    transition: clip-path 0.7s var(--ease), visibility 0s linear 0.7s;
    overflow-y: auto;
  }
  .main-nav.nav-open {
    clip-path: circle(150% at calc(100% - 40px) 36px);
    visibility: visible;
    transition: clip-path 0.7s var(--ease), visibility 0s;
  }
  .nav-links { flex-direction: column; align-items: flex-start; gap: 0; }
  .nav-link {
    font-family: var(--f-han);
    font-size: clamp(1.8rem, 7vw, 2.6rem);
    font-weight: 700;
    color: var(--fg);
    padding: 6px 0;
  }
  .nav-link::after { left: auto; right: -14px; bottom: 50%; transform: translateY(50%) scale(0); width: 7px; height: 7px; }
  .nav-link:hover::after { transform: translateY(50%) scale(1); }
  .nav-extras { margin: 0; padding-top: 20px; border-top: 1px solid var(--line); }
  .hdr-select { font-size: 0.95rem; padding: 10px 34px 10px 16px; max-width: none; }
}
@media (max-width: 520px) {
  .brand-sub { display: none; }
  .brand-title { font-size: 1rem; }
  .seal { width: 38px; height: 38px; font-size: 13px; }
  .hdr-cta { padding: 8px 14px; font-size: 0.8rem; }
}

/* ==========================================================
   Buttons
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 28px;
  font-weight: 600;
  font-size: 0.98rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.35s var(--ease), color 0.35s, border-color 0.35s, background 0.35s;
}
.btn svg { width: 18px; height: 18px; transition: transform 0.35s var(--ease); flex-shrink: 0; }
.btn:hover svg { transform: translateX(4px); }
.btn-seal { background: var(--cinnabar); color: var(--cinnabar-ink); }
.btn-seal::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--fg);
  transform: translateY(101%);
  transition: transform 0.45s var(--ease);
  z-index: -1;
}
.btn-seal:hover { color: var(--bg); }
.btn-seal:hover::before { transform: translateY(0); }
.btn-ghost { border-color: var(--line-2); color: var(--fg); }
.btn-ghost:hover { border-color: var(--fg); }
.btn-block { width: 100%; }

/* ==========================================================
   Section scaffolding
   ========================================================== */
.section {
  position: relative;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(72px, 9vw, 124px) var(--gutter);
}
.sec-head {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: clamp(20px, 4vw, 60px);
  align-items: end;
  margin-bottom: clamp(48px, 7vw, 90px);
}
.sec-num {
  grid-row: 1 / span 3;
  font-family: var(--f-han);
  font-weight: 900;
  font-size: clamp(5rem, 13vw, 11rem);
  line-height: 0.8;
  color: transparent;
  -webkit-text-stroke: 1px var(--line-2);
  align-self: start;
  user-select: none;
}
.sec-tag {
  font-family: var(--f-mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cinnabar);
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 12px;
}
.sec-tag::before { content: ''; width: 28px; height: 1px; background: currentColor; }
.sec-title {
  font-family: var(--f-han);
  font-weight: 900;
  font-size: clamp(2.2rem, 5vw, 4.2rem);
  line-height: 1.1;
  letter-spacing: 0.02em;
  margin-bottom: 14px;
}
html[lang="en"] .sec-title { font-family: var(--f-disp); font-weight: 500; letter-spacing: -0.015em; }
.sec-sub { max-width: 620px; color: var(--fg-2); font-size: 1.05rem; }
@media (max-width: 640px) {
  .sec-head { grid-template-columns: 1fr; }
  .sec-num { grid-row: auto; font-size: 5.2rem; margin-bottom: 8px; }
}

/* ==========================================================
   Footer
   ========================================================== */
.site-footer {
  border-top: 1px solid var(--line);
  padding: clamp(60px, 8vw, 110px) var(--gutter) 30px;
  overflow: hidden;
}
.ft-giant {
  display: flex;
  justify-content: space-between;
  font-family: var(--f-han);
  font-weight: 900;
  font-size: clamp(3.4rem, 13.5vw, 15rem);
  line-height: 0.9;
  max-width: 1480px;
  margin: 0 auto clamp(40px, 6vw, 80px);
  user-select: none;
}
.ft-giant span { color: transparent; -webkit-text-stroke: 1px var(--line-2); transition: color 0.6s var(--ease), -webkit-text-stroke-color 0.6s; }
.ft-giant span:hover { color: var(--cinnabar); -webkit-text-stroke-color: var(--cinnabar); }
.ft-grid {
  max-width: 1480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 40px;
  padding-bottom: 50px;
  border-bottom: 1px solid var(--line);
}
.footer-logo-text { font-family: var(--f-han); font-weight: 900; font-size: 1.4rem; margin-bottom: 8px; }
.footer-slogan { color: var(--fg-2); max-width: 380px; }
.ft-grid h5 { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--cinnabar); margin-bottom: 14px; font-weight: 400; }
.ft-grid p { color: var(--fg-2); font-size: 0.94rem; margin-bottom: 6px; }
.ft-grid a:hover { color: var(--fg); }
.ft-bottom {
  max-width: 1480px;
  margin: 0 auto;
  padding-top: 24px;
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  font-family: var(--f-mono);
  font-size: 0.72rem;
  color: var(--fg-3);
}
.ft-bottom a:hover { color: var(--fg); }
@media (max-width: 800px) { .ft-grid { grid-template-columns: 1fr; gap: 28px; } }

/* ==========================================================
   Scroll reveals (reveal.js toggles .is-revealed)
   ========================================================== */
[data-reveal] { transition: opacity 1s var(--ease), transform 1.1s var(--ease), filter 1s var(--ease); }
.reveal-init [data-reveal]:not(.is-revealed) { opacity: 0; transform: translateY(36px); filter: blur(6px); }
.reveal-init [data-reveal="scale"]:not(.is-revealed) { transform: scale(0.9); }
.reveal-init [data-reveal="left"]:not(.is-revealed) { transform: translateX(-40px); }

/* ==========================================================
   Reduced motion
   ========================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .crystal-ornament, .jade-sphere, .mineral-bead .bead-orbit-corrector, .lp-ring { animation: none !important; }
  .ht-2::after { clip-path: none; animation: none; }
  .mq-track { animation: none; }
  .reveal-init [data-reveal]:not(.is-revealed) { opacity: 1; transform: none; filter: none; }
}


/* ==========================================================
   Page-to-page ink transition (cross-document View Transitions).
   The new page blooms out of the point you clicked, like ink
   spreading on paper; the header stays put. Browsers without
   support simply navigate normally.
   ========================================================== */
@view-transition { navigation: auto; }
.site-header { view-transition-name: site-header; }
::view-transition-old(root) { animation: 0.5s cubic-bezier(0.4, 0, 0.2, 1) both lzInkOut; }
::view-transition-new(root) { animation: 0.75s cubic-bezier(0.16, 1, 0.3, 1) both lzInkIn; }
@keyframes lzInkIn {
  from { clip-path: circle(0% at var(--vt-x, 50%) var(--vt-y, 50%)); filter: blur(6px); }
  to   { clip-path: circle(150% at var(--vt-x, 50%) var(--vt-y, 50%)); filter: blur(0); }
}
@keyframes lzInkOut { to { opacity: 0.35; transform: scale(0.985); filter: saturate(0.4); } }

/* Ink drop that spreads from where a button is pressed */
.btn, .hdr-cta { position: relative; overflow: hidden; }
.ink-drop {
  position: absolute;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  pointer-events: none;
  transform: scale(0);
  animation: inkDrop 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes inkDrop { to { transform: scale(26); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .ink-drop { display: none; }
}

/* backdrop-filter makes the header a containing block for fixed children,
   which shrank the full-screen mobile menu to the header strip once the
   page was scrolled. Drop the blur while the menu is open. */
.site-header:has(.main-nav.nav-open) { -webkit-backdrop-filter: none; backdrop-filter: none; }
