/* ============================================================
   KHO SÁCH TINH HOA — Trung Hoa & Việt Nam
   Aesthetic: woodblock-print scholar's study (刻本 / thư phòng)
   ============================================================ */

/* ---------- 1. TOKENS ---------- */
:root {
  --paper:        #efe7d6;
  --paper-2:      #e8dfca;
  --paper-deep:   #ddd0b5;
  --paper-card:   #f6f0e2;

  --ink:          #221c16;
  --ink-soft:     #483d31;
  --ink-mute:     #7d6d59;
  --ink-faint:    #a3937c;

  --seal:         #9d2b19;
  --seal-bright:  #c2442b;
  --jade:         #3d6a58;
  --gold:         #9a7a38;

  --rule:         rgba(34, 28, 22, 0.16);
  --rule-strong:  rgba(34, 28, 22, 0.42);

  --f-display: "Cormorant Garamond", Georgia, serif;
  --f-body:    "Lora", Georgia, serif;
  --f-han:     "Noto Serif SC", "Songti SC", serif;
  --f-brush:   "Ma Shan Zheng", "Noto Serif SC", serif;

  --measure: 34rem;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

[data-theme="night"] {
  --paper:      #15120e;
  --paper-2:    #1c1813;
  --paper-deep: #241f18;
  --paper-card: #1e1a14;

  --ink:        #e6dcc6;
  --ink-soft:   #c3b69c;
  --ink-mute:   #8f8069;
  --ink-faint:  #6a5d4b;

  --seal:        #d1543a;
  --seal-bright: #e06a4c;
  --jade:        #6da88c;
  --gold:        #c8a45c;

  --rule:        rgba(230, 220, 198, 0.14);
  --rule-strong: rgba(230, 220, 198, 0.34);
}

/* ---------- 2. RESET ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.75;
  transition: background 0.5s var(--ease), color 0.5s var(--ease);
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
::selection { background: var(--seal); color: var(--paper); }

/* ---------- 3. PAPER TEXTURE ---------- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.42;
  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.82' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
[data-theme="night"] body::before { mix-blend-mode: screen; opacity: 0.14; }

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, transparent 0 3px, rgba(34,28,22,0.022) 3px 4px),
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(154,122,56,0.13), transparent 70%);
}
[data-theme="night"] body::after {
  background: radial-gradient(ellipse 90% 60% at 50% -10%, rgba(200,164,92,0.07), transparent 70%);
}

.shell { position: relative; z-index: 1; }

/* ---------- 4. TYPE PRIMITIVES ---------- */
.han {
  font-family: var(--f-han);
  font-weight: 500;
  letter-spacing: 0.06em;
}
.brush { font-family: var(--f-brush); font-weight: 400; }

.eyebrow {
  font-family: var(--f-body);
  font-size: 0.66rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.rule-double {
  border-top: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule-strong);
}

/* ---------- 5. SEAL STAMP ---------- */
.seal {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  border: 2px solid var(--seal);
  border-radius: 3px;
  color: var(--seal);
  font-family: var(--f-han);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0;
  text-align: center;
  transform: rotate(-4deg);
  opacity: 0.9;
}
.seal--lg { width: 4.6rem; height: 4.6rem; font-size: 1.2rem; border-width: 3px; }

/* ---------- 6. LAYOUT ---------- */
.wrap { width: min(100% - 2.5rem, 74rem); margin-inline: auto; }
.wrap--narrow { width: min(100% - 2.5rem, 52rem); margin-inline: auto; }

/* ---------- 7. TOP BAR ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--rule);
}
.topbar__in {
  width: min(100% - 2.5rem, 74rem);
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 1.4rem;
  height: 4.2rem;
}
.brand { display: flex; align-items: center; gap: 0.8rem; margin-right: auto; }
.brand__seal {
  width: 2.1rem; height: 2.1rem;
  border: 1.5px solid var(--seal);
  border-radius: 2px;
  display: grid; place-items: center;
  color: var(--seal);
  font-family: var(--f-han);
  font-size: 1.05rem;
  transform: rotate(-3deg);
  flex-shrink: 0;
}
.brand__txt { line-height: 1.15; }
.brand__cn { font-family: var(--f-han); font-size: 0.95rem; letter-spacing: 0.14em; }
.brand__vn {
  font-size: 0.6rem; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--ink-mute);
}

.navlink {
  font-size: 0.83rem;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
  transition: color 0.25s, border-color 0.25s;
}
.navlink:hover, .navlink[aria-current="true"] {
  color: var(--ink);
  border-color: var(--seal);
}

.iconbtn {
  width: 2.3rem; height: 2.3rem;
  display: grid; place-items: center;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink-mute);
  transition: all 0.25s var(--ease);
}
.iconbtn:hover {
  color: var(--seal);
  border-color: var(--seal);
  transform: translateY(-1px);
}

/* ---------- 8. HERO ---------- */
.hero {
  position: relative;
  padding: clamp(3.5rem, 9vw, 7rem) 0 clamp(2.5rem, 6vw, 4.5rem);
  overflow: hidden;
}
.hero__grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: clamp(1.5rem, 5vw, 4rem);
  align-items: start;
}
.hero__title {
  font-family: var(--f-display);
  font-weight: 300;
  font-size: clamp(2.6rem, 7.5vw, 5.4rem);
  line-height: 0.98;
  letter-spacing: -0.015em;
  margin: 0.7rem 0 0;
}
.hero__title em {
  font-style: italic;
  color: var(--seal);
}
.hero__vertical {
  font-family: var(--f-han);
  writing-mode: vertical-rl;
  font-size: clamp(1.1rem, 2.6vw, 1.7rem);
  letter-spacing: 0.42em;
  color: var(--ink-mute);
  border-left: 1px solid var(--rule-strong);
  border-right: 1px solid var(--rule-strong);
  padding: 0.6rem 0.5rem;
  max-height: 19rem;
}
.hero__lede {
  max-width: 33rem;
  margin: 1.6rem 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
}
.hero__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2.2rem;
  margin-top: 2.4rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule-strong);
}
.stat__n {
  font-family: var(--f-display);
  font-size: 2.1rem;
  line-height: 1;
  color: var(--seal);
}
.stat__l {
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-top: 0.3rem;
}

/* ---------- 9. SEARCH ---------- */
.search {
  position: relative;
  margin: 0 0 2.6rem;
}
.search__field {
  width: 100%;
  background: var(--paper-card);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  padding: 0.95rem 1rem 0.95rem 2.9rem;
  font-family: var(--f-body);
  font-size: 0.97rem;
  color: var(--ink);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.search__field::placeholder { color: var(--ink-faint); }
.search__field:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--seal) 14%, transparent);
}
.search__ico {
  position: absolute;
  left: 1rem; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}

/* ---------- 10. FILTER CHIPS ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 2.8rem; }
.chip {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 0.42rem 0.9rem;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  color: var(--ink-mute);
  transition: all 0.22s var(--ease);
}
.chip:hover { color: var(--ink); border-color: var(--ink-mute); }
.chip[aria-pressed="true"] {
  background: var(--seal);
  border-color: var(--seal);
  color: #f6f0e2;
}

/* ---------- 11. SECTION HEADING ---------- */
.sec { padding: clamp(2rem, 5vw, 3.5rem) 0; }
.sec__head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 2rem;
}
.sec__head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule-strong);
}
.sec__title {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: clamp(1.5rem, 3.4vw, 2.2rem);
  margin: 0;
  letter-spacing: -0.01em;
}
.sec__han {
  font-family: var(--f-han);
  font-size: 0.95rem;
  color: var(--seal);
  letter-spacing: 0.2em;
}

/* ---------- 12. BOOK CARD ---------- */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  gap: 1.1rem;
}
.book {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1.5rem 1.3rem 1.3rem;
  overflow: hidden;
  transition: transform 0.32s var(--ease), box-shadow 0.32s var(--ease), border-color 0.32s;
}
.book::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--seal);
  opacity: 0.65;
  transition: width 0.32s var(--ease), opacity 0.32s;
}
.book:hover {
  transform: translateY(-4px);
  border-color: var(--rule-strong);
  box-shadow: -3px 10px 26px -8px rgba(34,28,22,0.28);
}
[data-theme="night"] .book:hover { box-shadow: -3px 10px 26px -8px rgba(0,0,0,0.6); }
.book:hover::before { width: 5px; opacity: 1; }

.book__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.7rem;
}
.book__dot { width: 3px; height: 3px; border-radius: 50%; background: var(--seal); }
.book__han {
  font-family: var(--f-han);
  font-size: 1.42rem;
  line-height: 1.3;
  margin: 0 0 0.2rem;
  color: var(--ink);
}
.book__vn {
  font-family: var(--f-display);
  font-size: 1.16rem;
  font-weight: 500;
  line-height: 1.25;
  margin: 0 0 0.55rem;
  color: var(--seal);
}
.book__by {
  font-size: 0.76rem;
  color: var(--ink-mute);
  font-style: italic;
  margin: 0 0 0.75rem;
}
.book__desc {
  font-size: 0.85rem;
  line-height: 1.62;
  color: var(--ink-soft);
  margin: 0 0 1.1rem;
  flex: 1;
}
.book__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.book__go {
  color: var(--seal);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: gap 0.25s var(--ease);
}
.book:hover .book__go { gap: 0.65rem; }

.badge {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 2px;
  border: 1px solid;
}
.badge--full  { color: var(--jade); border-color: color-mix(in srgb, var(--jade) 45%, transparent); }
.badge--core  { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.badge--soon  { color: var(--ink-faint); border-color: var(--rule-strong); }

/* sách chưa có bản dịch: nhạt hơn, vẫn xem được thông tin */
.book--soon { opacity: 0.62; }
.book--soon:hover { opacity: 1; }
.book--soon .book__han { color: var(--ink-mute); }

/* ---------- 12b. TRANG "ĐANG BIÊN SOẠN" ---------- */
.soon {
  max-width: 42rem;
  margin: 4rem auto 6rem;
  text-align: center;
}
.soon .doc__facts { justify-content: center; }
.soon__desc {
  margin: 2rem 0 0;
  color: var(--ink-mute);
  font-size: 1.02rem;
  line-height: 1.85;
  text-align: left;
}
.soon__box {
  margin-top: 2.4rem;
  padding: 1.6rem 1.8rem;
  border: 1px solid var(--rule-strong);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--rule);
  text-align: left;
}
.soon__ttl {
  font-family: var(--f-display);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--seal);
  margin: 0 0 0.7rem;
}
.soon__box p { color: var(--ink-mute); font-size: 0.93rem; line-height: 1.8; margin: 0 0 0.8rem; }
.soon__box p:last-child { margin-bottom: 0; }
.soon__alt { border-top: 1px solid var(--rule); padding-top: 0.9rem; margin-top: 1.1rem !important; }
.soon__alt a { color: var(--seal); border-bottom: 1px solid color-mix(in srgb, var(--seal) 35%, transparent); }
.soon__alt a:hover { background: color-mix(in srgb, var(--seal) 8%, transparent); }

/* ---------- 13. FOOTER ---------- */
.foot {
  margin-top: 4rem;
  padding: 3rem 0 4rem;
  border-top: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule-strong);
}
.foot__grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2rem;
  align-items: start;
}
.foot__note {
  max-width: 34rem;
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--ink-mute);
}
.foot__note strong { color: var(--ink-soft); font-weight: 600; }

/* ---------- 14. REVEAL ANIMATION ---------- */
@keyframes riseIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
.reveal { animation: riseIn 0.7s var(--ease) both; }
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; }
  html { scroll-behavior: auto; }
}

/* ============================================================
   READER — trang đọc sách
   ============================================================ */

.reader {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  width: min(100% - 2.5rem, 80rem);
  margin-inline: auto;
  padding: 2.5rem 0 4rem;
  align-items: start;
}

/* ---------- TOC sidebar ---------- */
.toc {
  position: sticky;
  top: 5.6rem;
  max-height: calc(100vh - 7.5rem);
  overflow-y: auto;
  padding-right: 0.6rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}
.toc::-webkit-scrollbar { width: 5px; }
.toc::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 3px; }

.toc__back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.73rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 1.5rem;
  transition: color 0.25s, gap 0.25s;
}
.toc__back:hover { color: var(--seal); gap: 0.65rem; }

.toc__bookhan {
  font-family: var(--f-han);
  font-size: 1.28rem;
  line-height: 1.3;
  margin: 0 0 0.15rem;
}
.toc__bookvn {
  font-family: var(--f-display);
  font-size: 0.98rem;
  color: var(--seal);
  margin: 0 0 1.4rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule-strong);
}
.toc__label {
  font-size: 0.62rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 1.5rem 0 0.7rem;
}
.toc__list { list-style: none; margin: 0; padding: 0; }
.toc__item a {
  display: flex;
  gap: 0.6rem;
  padding: 0.42rem 0.55rem;
  border-radius: 2px;
  font-size: 0.855rem;
  line-height: 1.45;
  color: var(--ink-soft);
  border-left: 2px solid transparent;
  transition: all 0.22s var(--ease);
}
.toc__item a:hover {
  background: color-mix(in srgb, var(--seal) 7%, transparent);
  color: var(--ink);
  border-left-color: var(--seal);
}
.toc__item a.is-active {
  background: color-mix(in srgb, var(--seal) 11%, transparent);
  border-left-color: var(--seal);
  color: var(--ink);
  font-weight: 600;
}
.toc__num {
  font-family: var(--f-display);
  font-size: 0.8rem;
  color: var(--seal);
  min-width: 1.5rem;
  flex-shrink: 0;
  padding-top: 1px;
}

/* ---------- Reader main column ---------- */
.doc { min-width: 0; }

.doc__head {
  padding-bottom: 1.8rem;
  margin-bottom: 2.4rem;
  border-bottom: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule-strong);
  position: relative;
}
.doc__kicker {
  font-size: 0.64rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.doc__han {
  font-family: var(--f-han);
  font-size: clamp(1.9rem, 5vw, 2.9rem);
  line-height: 1.2;
  margin: 0.5rem 0 0.2rem;
  letter-spacing: 0.06em;
}
.doc__vn {
  font-family: var(--f-display);
  font-weight: 400;
  font-style: italic;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  color: var(--seal);
  margin: 0 0 1rem;
}
.doc__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.6rem;
  font-size: 0.76rem;
  color: var(--ink-mute);
}
.doc__facts b { color: var(--ink-soft); font-weight: 600; }

/* ---------- Layer toggle control ---------- */
.layers {
  position: sticky;
  top: 4.2rem;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 0;
  margin-bottom: 1.5rem;
  background: color-mix(in srgb, var(--paper) 93%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.layers__lbl {
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 0.3rem;
}
.tgl {
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  padding: 0.34rem 0.72rem;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  color: var(--ink-mute);
  transition: all 0.22s var(--ease);
}
.tgl:hover { color: var(--ink); border-color: var(--ink-mute); }
.tgl[aria-pressed="true"] {
  background: color-mix(in srgb, var(--seal) 13%, transparent);
  border-color: var(--seal);
  color: var(--seal);
  font-weight: 600;
}

/* ---------- Intro prose ---------- */
.prose { max-width: var(--measure); }
.prose h2 {
  font-family: var(--f-display);
  font-weight: 500;
  font-size: 1.5rem;
  margin: 2.6rem 0 0.9rem;
  letter-spacing: -0.01em;
}
.prose h3 {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 1.14rem;
  margin: 2rem 0 0.6rem;
  color: var(--ink-soft);
}
.prose p { margin: 0 0 1.05rem; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.3rem; }
.prose li { margin-bottom: 0.5rem; }
.prose strong { font-weight: 600; color: var(--ink); }
.prose em { font-style: italic; }
.prose blockquote {
  margin: 1.5rem 0;
  padding: 0.2rem 0 0.2rem 1.2rem;
  border-left: 2px solid var(--seal);
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- CHAPTER (đơn vị nội dung) ---------- */
.chap {
  padding: 2.4rem 0;
  border-bottom: 1px dashed var(--rule);
  scroll-margin-top: 8rem;
}
.chap:last-child { border-bottom: 0; }

.chap__head {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}
.chap__no {
  font-family: var(--f-display);
  font-size: 2.4rem;
  line-height: 0.85;
  color: var(--seal);
  opacity: 0.5;
  flex-shrink: 0;
}
.chap__ttl { min-width: 0; }
.chap__han {
  font-family: var(--f-han);
  font-size: 1.3rem;
  line-height: 1.35;
  margin: 0;
  letter-spacing: 0.05em;
}
.chap__vn {
  font-family: var(--f-display);
  font-size: 1rem;
  font-style: italic;
  color: var(--ink-mute);
  margin: 0.1rem 0 0;
}

/* ---------- LAYER: nguyên văn Hán ---------- */
.L-han {
  font-family: var(--f-han);
  font-size: 1.1rem;
  line-height: 2.15;
  letter-spacing: 0.09em;
  color: var(--ink);
  background: color-mix(in srgb, var(--paper-deep) 55%, transparent);
  border-left: 3px double var(--rule-strong);
  padding: 1.15rem 1.3rem;
  margin: 0 0 0.9rem;
}

/* ---------- LAYER: phiên âm ---------- */
.L-am {
  font-size: 0.9rem;
  line-height: 1.85;
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--ink-mute);
  padding: 0 0 0 1.3rem;
  border-left: 1px solid var(--rule);
  margin: 0 0 1.1rem;
}

/* ---------- LAYER 1: dịch cổ điển ---------- */
.L-dich {
  position: relative;
  font-size: 1.03rem;
  line-height: 1.92;
  color: var(--ink);
  padding: 0 0 0 1.3rem;
  border-left: 2px solid var(--seal);
  margin: 0 0 1.4rem;
  max-width: var(--measure);
}
.L-dich p { margin: 0 0 0.75rem; }
.L-dich p:last-child { margin-bottom: 0; }

/* ---------- LAYER 2: diễn giải hiện đại ---------- */
.L-giai {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1.15rem 1.3rem;
  margin: 0 0 1.1rem;
  font-size: 0.935rem;
  line-height: 1.78;
  color: var(--ink-soft);
}
.L-giai p { margin: 0 0 0.7rem; }
.L-giai p:last-child { margin-bottom: 0; }

/* ---------- LAYER 3: ứng dụng thực tiễn ---------- */
.L-dung {
  border-left: 2px solid var(--jade);
  background: color-mix(in srgb, var(--jade) 6%, transparent);
  padding: 1.05rem 1.25rem;
  margin: 0 0 1.1rem;
  font-size: 0.915rem;
  line-height: 1.75;
  color: var(--ink-soft);
}
.L-dung p { margin: 0 0 0.6rem; }
.L-dung p:last-child { margin-bottom: 0; }
.L-dung ul { margin: 0.4rem 0 0; padding-left: 1.15rem; }
.L-dung li { margin-bottom: 0.4rem; }

/* ---------- LAYER 4: kiến giải các nguồn ---------- */
.L-nguon {
  border-left: 2px solid var(--gold);
  padding: 0.5rem 0 0.5rem 1.25rem;
  margin: 0 0 1.1rem;
  font-size: 0.885rem;
  line-height: 1.72;
  color: var(--ink-mute);
}
.L-nguon p { margin: 0 0 0.6rem; }
.L-nguon p:last-child { margin-bottom: 0; }
.L-nguon b { color: var(--ink-soft); font-weight: 600; }

/* ---------- Layer caption ---------- */
.Lcap {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.45rem;
}
.Lcap::before {
  content: "";
  width: 0.8rem;
  height: 1px;
  background: currentColor;
}

/* ---------- Layer visibility (JS-driven) ---------- */
.reader.hide-han   .L-han,   .reader.hide-han   .Lcap--han   { display: none; }
.reader.hide-am    .L-am,    .reader.hide-am    .Lcap--am    { display: none; }
.reader.hide-dich  .L-dich,  .reader.hide-dich  .Lcap--dich  { display: none; }
.reader.hide-giai  .L-giai,  .reader.hide-giai  .Lcap--giai  { display: none; }
.reader.hide-dung  .L-dung,  .reader.hide-dung  .Lcap--dung  { display: none; }
.reader.hide-nguon .L-nguon, .reader.hide-nguon .Lcap--nguon { display: none; }

/* ---------- Reading progress bar ---------- */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  background: var(--seal);
  z-index: 90;
  width: 0;
  transition: width 0.1s linear;
}

/* ---------- Prev / next ---------- */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule-strong);
}
.pager a {
  max-width: 46%;
  font-size: 0.83rem;
  color: var(--ink-mute);
  transition: color 0.25s;
}
.pager a:hover { color: var(--seal); }
.pager__lbl {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.25rem;
}
.pager__r { text-align: right; margin-left: auto; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--ink-mute);
}
.empty__han {
  font-family: var(--f-han);
  font-size: 2.2rem;
  color: var(--ink-faint);
  margin-bottom: 0.8rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 950px) {
  .reader { grid-template-columns: 1fr; }
  .toc {
    position: static;
    max-height: none;
    overflow: visible;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--rule-strong);
  }
  .toc__list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.1rem;
    max-height: 17rem;
    overflow-y: auto;
  }
  .hero__grid { grid-template-columns: 1fr; }
  .hero__vertical { display: none; }
  .foot__grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar__in { height: 3.6rem; gap: 0.8rem; }
  .nav-desktop { display: none; }
  .brand__vn { display: none; }
  .hero { padding-top: 2.5rem; }
  .hero__stats { gap: 1.4rem; }
  .stat__n { font-size: 1.7rem; }
  .shelf { grid-template-columns: 1fr; }
  .chap__head { flex-direction: column; gap: 0.3rem; }
  .chap__no { font-size: 1.7rem; }
  .L-han { font-size: 1.03rem; padding: 0.95rem 1rem; }
  .layers { top: 3.6rem; }
  .toc { top: 4.9rem; }
}

@media print {
  .topbar, .layers, .toc, .pager, .progress, .foot { display: none !important; }
  body::before, body::after { display: none; }
  .reader { display: block; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .chap { page-break-inside: avoid; border-bottom: 1px solid #ccc; }
}

/* ---------- loading pulse ---------- */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.95); }
}

/* ============================================================
   3D MARTIAL & MERIDIAN VISUALIZER (THREE.JS) STYLING
   ============================================================ */
.m3d-wrapper {
  margin: 2.5rem 0 3.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper-card);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  position: relative;
  transition: all 0.3s ease;
}

[data-theme="night"] .m3d-wrapper {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  border-color: rgba(200, 164, 92, 0.28);
  background: #12100d;
}

.m3d-header {
  padding: 1.2rem 1.6rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  background: rgba(154, 122, 56, 0.04);
}

.m3d-badge {
  display: inline-block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--seal);
  background: rgba(157, 43, 25, 0.08);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.35rem;
}

.m3d-title {
  margin: 0;
  font-family: var(--f-display);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
}

.m3d-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-mute);
  max-width: 38rem;
  line-height: 1.5;
}

.m3d-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.m3d-btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
  user-select: none;
}

.m3d-btn:hover {
  background: var(--paper-2);
  color: var(--ink);
  border-color: var(--rule-strong);
}

.m3d-btn[aria-pressed="true"] {
  background: var(--seal);
  color: #fff;
  border-color: var(--seal);
}

.m3d-canvas-box {
  width: 100%;
  height: 520px;
  position: relative;
  background: radial-gradient(circle at 50% 50%, rgba(30, 45, 60, 0.22) 0%, rgba(10, 15, 20, 0.85) 100%);
  cursor: grab;
  overflow: hidden;
}

.m3d-canvas-box:active {
  cursor: grabbing;
}

[data-theme="day"] .m3d-canvas-box {
  background: radial-gradient(circle at 50% 45%, rgba(245, 238, 222, 0.9) 0%, rgba(220, 208, 185, 0.95) 100%);
}

#m3dCanvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.m3d-tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 20;
  background: rgba(18, 22, 28, 0.92);
  color: #f0ede6;
  border: 1px solid rgba(212, 175, 55, 0.6);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  max-width: 280px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  font-size: 0.85rem;
  line-height: 1.45;
  transform: translate(0, 0);
  transition: opacity 0.15s ease;
}

.m3d-tip-name {
  font-weight: 600;
  color: #ffd700;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.m3d-tip-desc {
  font-size: 0.82rem;
  color: #c9d1d9;
}

.m3d-overlay-hint {
  position: absolute;
  bottom: 0.8rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.m3d-overlay-hint span {
  font-size: 0.76rem;
  color: var(--ink-faint);
  background: rgba(0, 0, 0, 0.4);
  color: #e0e0e0;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}

[data-theme="day"] .m3d-overlay-hint span {
  background: rgba(255, 255, 255, 0.75);
  color: #483d31;
  border: 1px solid rgba(0,0,0,0.08);
}

.m3d-footer-panel {
  padding: 1.2rem 1.6rem;
  border-top: 1px solid var(--rule);
  background: rgba(154, 122, 56, 0.03);
}

.m3d-formula {
  margin-bottom: 0.8rem;
  font-size: 0.94rem;
  line-height: 1.55;
  color: var(--ink);
}

.m3d-formula-label {
  font-weight: 600;
  color: var(--seal);
  margin-right: 0.4rem;
}

.m3d-formula-text {
  font-style: italic;
  color: var(--ink-soft);
}

.m3d-meridian-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.m3d-tag {
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--ink-mute);
}

@media (max-width: 768px) {
  .m3d-canvas-box { height: 400px; }
  .m3d-header { flex-direction: column; }
  .m3d-tools { width: 100%; justify-content: flex-start; }
}

#martial3DHost {
  scroll-margin-top: 5rem;
}

.badge--3d {
  background: rgba(157, 43, 25, 0.12) !important;
  color: var(--seal) !important;
  border: 1px solid rgba(157, 43, 25, 0.28) !important;
  font-weight: 600 !important;
  letter-spacing: 0.04em;
}

[data-theme="night"] .badge--3d {
  background: rgba(220, 75, 50, 0.18) !important;
  color: #ff7d66 !important;
  border-color: rgba(220, 75, 50, 0.4) !important;
}

.toc__link--3d {
  position: relative;
  transition: all 0.2s ease;
}

.toc__link--3d:hover {
  text-decoration: none;
  background: rgba(157, 43, 25, 0.08);
  border-radius: 4px;
}

/* ---------- THANH CHỌN ĐỘNG TÁC VÕ THUẬT & VẬN KHÍ ---------- */
.m3d-motion-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.75rem 1.6rem;
  background: rgba(154, 122, 56, 0.03);
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}

[data-theme="night"] .m3d-motion-bar {
  background: rgba(200, 164, 92, 0.04);
}

.m3d-motion-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.m3d-motion-btns {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.m3d-motion-btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink-mute);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  user-select: none;
}

.m3d-motion-btn:hover {
  background: var(--paper-2);
  color: var(--ink);
  border-color: var(--rule-strong);
}

.m3d-motion-btn.active {
  background: var(--seal);
  color: #ffffff;
  border-color: var(--seal);
  box-shadow: 0 2px 8px rgba(157, 43, 25, 0.25);
  font-weight: 500;
}

[data-theme="night"] .m3d-motion-btn.active {
  background: #c84b31;
  border-color: #c84b31;
  box-shadow: 0 2px 10px rgba(200, 75, 49, 0.4);
}

.m3d-motion-icon {
  font-size: 0.95rem;
  line-height: 1;
}

#m3dBtnViewMode.active {
  background: rgba(157, 43, 25, 0.12);
  color: var(--seal);
  border-color: var(--seal);
}

/* ---------- CHUNKED CHAPTER LAZY LOADING ---------- */
.chap--chunked .chap__content {
  min-height: 4rem;
  transition: opacity 0.3s ease;
}

.chap__loading {
  padding: 1.8rem 0;
  color: var(--ink-mute);
  font-family: var(--f-body);
  font-size: 0.95rem;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chap__loading .han {
  font-size: 1.35rem;
  color: var(--seal);
  animation: pulse 1.4s ease infinite;
}



