@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600;700&family=EB+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600&display=swap");

:root {
  --parchment: #f6f1e7;
  --parchment-mid: #eee7d6;
  --parchment-dark: #ddd3bd;
  --ink: #211c15;
  --ink-mid: #44392d;
  --ink-light: #665746;
  --rust: #842727;
  --rust-light: #a13a32;
  --gold: #7b6326;
  --rule: #c5b48f;
  --note-bg: #eee5cf;
  --note-border: #c0a070;
  --shadow: rgba(30, 25, 18, 0.16);
  --source-rail: 3.25rem;
  --source-label: 2.75rem;
  --contents-panel-width: 16rem;
  --header-height: 3.55rem;
  --body: "EB Garamond", "Noto Serif CJK TC", "Noto Serif CJK SC", Georgia, serif;
  --display: "Cinzel", "Noto Serif CJK TC", Georgia, serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 255, 255, 0.82), transparent 34rem),
    repeating-linear-gradient(0deg, rgba(83, 64, 32, 0.018) 0, rgba(83, 64, 32, 0.018) 1px, transparent 1px, transparent 4px),
    var(--parchment);
  font-family: var(--body);
  font-size: clamp(1.06rem, 0.98rem + 0.24vw, 1.24rem);
  line-height: 1.58;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--rust);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}

a:hover {
  color: var(--rust-light);
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.65rem 1rem;
  color: white;
  background: var(--rust);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: none;
}

.site-header {
  position: sticky;
  z-index: 30;
  top: 0;
  color: #f8f1df;
  background: rgba(32, 27, 20, 0.97);
  border-bottom: 2px solid var(--gold);
  box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.2);
}

.site-nav {
  width: min(100% - 2rem, 76rem);
  min-height: 3.55rem;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  font-family: var(--display);
  font-size: 0.72rem;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.nav-leading {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.site-nav a {
  color: inherit;
  text-decoration: none;
}

.contents-toggle,
.contents-close,
.contents-backdrop {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.contents-toggle {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: grid;
  place-items: center;
  color: #f8f1df;
  background: transparent;
  border-radius: 0.25rem;
  font-family: var(--body);
  font-size: 1.2rem;
  line-height: 1;
}

.contents-toggle:hover,
.contents-toggle[aria-expanded="true"] {
  color: #e3c46b;
  background: rgba(255, 255, 255, 0.08);
}

.nav-brand {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.55rem;
  row-gap: 0.08rem;
  font-size: 0.86rem;
  line-height: 1.3;
}

.nav-title {
  white-space: nowrap;
}

.nav-title-chinese {
  margin-right: 0.55rem;
  color: #d7b85b;
  font-family: var(--body);
  font-size: 1.05rem;
}

.nav-meta-group {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  white-space: nowrap;
}

.nav-separator {
  color: #d7b85b;
  font-size: 0.68rem;
}

.nav-meta {
  color: rgba(248, 241, 223, 0.82);
  font-size: 0.54rem;
  letter-spacing: 0.045em;
}

.top-link {
  white-space: nowrap;
}

main {
  min-height: 100vh;
  transition: margin-left 180ms ease;
}

.title-page {
  min-height: calc(100vh - 3.55rem);
  padding: clamp(3rem, 7vw, 6.5rem) 1.5rem 3rem;
  display: grid;
  justify-items: center;
  align-content: center;
  text-align: center;
  background:
    linear-gradient(rgba(246, 241, 231, 0.9), rgba(246, 241, 231, 0.95)),
    radial-gradient(circle, transparent 30%, rgba(115, 89, 42, 0.16));
}

.title-ornament {
  color: var(--gold);
  font-size: 0.84rem;
  letter-spacing: 0.55em;
}

.library-edition {
  margin: 0 0 0.55rem;
  color: var(--gold);
  font-family: var(--display);
  font-size: clamp(0.82rem, 1.8vw, 1.08rem);
  font-weight: 600;
  letter-spacing: 0.11em;
  line-height: 1.2;
  text-transform: uppercase;
}

.kicker,
.eyebrow {
  margin: 1rem 0 0.25rem;
  color: var(--rust);
  font-family: var(--display);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.title-page h1 {
  margin: 0;
  font-family: var(--body);
  font-size: clamp(3.5rem, 9vw, 7rem);
  font-weight: 500;
  line-height: 0.98;
}

.chinese-title {
  margin: 0.4rem 0 1.4rem;
  font-size: clamp(2rem, 5vw, 3.4rem);
  letter-spacing: 0.16em;
}

.cover-figure {
  width: min(16rem, 62vw);
  margin: 0;
  padding: 0.32rem;
  background: #2a251f;
  border: 1px solid #17130f;
  box-shadow: 0 1rem 2.5rem var(--shadow);
}

.cover-figure img {
  display: block;
  width: 100%;
  height: auto;
  filter: sepia(0.1) contrast(1.03);
}

.translator {
  margin: 1.3rem 0 0;
}

.edition {
  margin: 0;
  color: var(--rust);
  font-weight: 700;
}

.edition span {
  color: var(--ink);
}

.scroll-cue {
  margin-top: 1.3rem;
  font-family: var(--display);
  font-size: 0.67rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.document-section,
.chapter,
.book-divider {
  width: min(100% - 2rem, 48rem);
  margin-inline: auto;
}

.document-section {
  padding: clamp(3.5rem, 8vw, 7rem) 0;
}

.document-section > h2,
.book-divider h2 {
  margin: 0 0 1.5rem;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  line-height: 1.2;
  text-align: center;
}

.front-matter {
  position: relative;
  width: min(100% - 2rem, 52rem);
  max-width: 52rem;
  padding-right: var(--source-rail);
  box-sizing: border-box;
}

.copyright,
.permissions,
.resource-link,
.signature,
.revision-note {
  text-align: center;
}

.permissions {
  color: var(--ink-mid);
}

.note-box {
  margin: 1.5rem 0 1.5rem 1.6rem;
  padding: 0.7rem 0.9rem;
  background: var(--note-bg);
  border-left: 3px solid var(--note-border);
  color: var(--ink-mid);
  font-size: 0.85rem;
  line-height: 1.58;
  text-align: left;
  text-indent: 0;
}

.note-ref {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--rust);
  font-family: var(--display);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.3;
  text-transform: uppercase;
}

.note-box p {
  margin: 0 0 0.45rem;
  text-align: left;
  text-indent: 0;
}

.introduction .note-box p {
  text-indent: 0;
}

.note-box p:last-child {
  margin-bottom: 0;
}

.update-notice {
  margin-block: 2rem;
}

.update-notice p {
  margin-bottom: 0.45rem;
}

.front-matter h2 {
  margin-top: 3rem;
  text-align: left;
}

.front-matter > p:not(.permissions, .copyright, .resource-link, .signature, .revision-note, .page-ref),
.introduction > p,
.glossary-entry > p {
  text-align: justify;
  text-wrap: pretty;
}

.page-ref {
  color: var(--ink-light);
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.source-reference {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
}

.web-location {
  color: var(--rust);
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.source-page-origin {
  position: absolute;
  right: 0;
  float: none;
  width: var(--source-label);
  max-width: none;
  margin: 0.15rem 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-light);
  font-family: var(--display);
  font-size: 0.44rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1.15;
  text-align: right;
  text-transform: uppercase;
  scroll-margin-top: 6rem;
}

.source-page-origin span {
  display: block;
  white-space: nowrap;
}

.title-page {
  position: relative;
}

.title-page > .source-page-origin {
  right: max(1rem, calc(50% - 26rem));
  margin: 0;
}

.introduction {
  position: relative;
  width: min(100% - 2rem, 52rem);
  padding-right: var(--source-rail);
  box-sizing: border-box;
}

.introduction .page-continuation {
  margin-top: 0;
  text-indent: 0;
}

.contents {
  font-size: 1rem;
}

.glossary > .eyebrow {
  text-align: center;
}

.contents-panel {
  position: fixed;
  z-index: 40;
  top: var(--header-height);
  bottom: 0;
  left: 0;
  width: min(var(--contents-panel-width), calc(100vw - 3rem));
  padding: 1.25rem 1rem 2rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgba(83, 64, 32, 0.018) 0, rgba(83, 64, 32, 0.018) 1px, transparent 1px, transparent 4px),
    var(--parchment);
  border-right: 1px solid var(--rule);
  box-shadow: 0.5rem 0 1.4rem var(--shadow);
  transform: translateX(-105%);
  visibility: hidden;
  transition:
    transform 180ms ease,
    visibility 0s linear 180ms;
}

.contents-open .contents-panel {
  transform: translateX(0);
  visibility: visible;
  transition-delay: 0s;
}

.contents-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.contents-panel-head .eyebrow {
  margin-top: 0;
}

.contents-panel-head h2 {
  margin: 0;
  font-size: 1.65rem;
}

.contents-close {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: var(--ink-light);
  background: transparent;
  border-radius: 0.25rem;
  font-size: 1.6rem;
  line-height: 1;
}

.contents-close:hover {
  color: var(--rust);
  background: rgba(132, 39, 39, 0.07);
}

.contents-backdrop {
  position: fixed;
  z-index: 35;
  inset: var(--header-height) 0 0;
  display: none;
  padding: 0;
  background: rgba(22, 18, 14, 0.42);
}

.major-links {
  margin: 1.25rem 0 1.75rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

.major-links a {
  padding: 0.65rem 0.75rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid var(--rule);
  font-family: var(--display);
  font-size: 0.78rem;
  text-decoration: none;
  text-align: center;
}

.major-links span {
  display: block;
  margin-top: 0.35rem;
  color: var(--ink-light);
  font-family: var(--body);
  font-size: 0.82rem;
}

.toc-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.toc-group h3 {
  color: var(--rust);
  font-family: var(--display);
  font-size: 0.86rem;
  letter-spacing: 0.09em;
  text-align: left;
  text-transform: uppercase;
}

.toc-end h3 {
  margin: 0;
}

.toc-end a {
  color: inherit;
  text-decoration: none;
}

.chapter-links {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  list-style: none;
}

.chapter-links a {
  display: block;
  padding: 0.35rem 0.25rem;
  color: var(--ink-mid);
  border-bottom: 1px dotted var(--rule);
  text-align: center;
  text-decoration: none;
}

@media (min-width: 901px) {
  .contents-open main,
  .contents-open .site-footer {
    margin-left: var(--contents-panel-width);
  }

  .site-footer {
    transition: margin-left 180ms ease;
  }
}

@media (max-width: 900px) {
  body.contents-open {
    overflow: hidden;
  }

  .contents-open .contents-backdrop {
    display: block;
  }
}

.chapter-links span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.introduction {
  padding-bottom: 4rem;
}

.introduction h2 {
  margin-top: 0;
}

.introduction h3 {
  margin: 3rem 0 0.75rem;
  color: var(--rust);
  font-family: var(--display);
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

.introduction p {
  margin: 0.8rem 0;
  text-indent: 2em;
}

.introduction .source-quotation {
  margin: 1.5rem 2.5rem;
  color: var(--ink-mid);
  font-size: 0.96em;
  text-indent: 0;
}

.introduction .source-footnote {
  margin-block: 1.5rem;
  text-indent: 0;
}

.introduction .idea-item {
  margin: 1.25rem 2rem;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  text-indent: 0;
}

.chapters-wrap {
  padding-bottom: 6rem;
}

.book-divider {
  margin-block: 2rem 3rem;
  padding: 3.5rem 1rem;
  border-block: 1px solid var(--rule);
  text-align: center;
}

.book-divider span {
  color: var(--rust);
  font-family: var(--display);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.book-divider h2 {
  margin: 0.55rem 0 0;
}

.book-divider p {
  margin: 0;
  color: var(--ink-light);
  font-style: italic;
}

.chapter {
  position: relative;
  width: min(100% - 2rem, 52rem);
  padding: 3.5rem var(--source-rail) 3.5rem 0;
  box-sizing: border-box;
  border-bottom: 1px solid var(--rule);
}

.chapter-header {
  margin-bottom: 2rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
}

.chapter-header .eyebrow {
  margin: 0;
  text-align: right;
}

.chapter-header h2 {
  min-width: 4rem;
  margin: 0 0.9rem;
  color: var(--rust);
  font-family: var(--display);
  font-size: 2.2rem;
  line-height: 1;
  text-align: center;
}

.chapter-header .page-ref {
  text-align: left;
}

.chapter-header .source-reference {
  justify-self: start;
}

.chapter-text {
  width: min(100%, 42rem);
  margin-inline: auto;
  font-size: 1.03em;
  line-height: 1.45;
}

.verse-line {
  min-height: 1.45em;
  padding-left: 4.6rem;
  text-indent: -2.25rem;
  overflow-wrap: anywhere;
}

.verse-line.part {
  margin-top: 0.9rem;
  padding-left: 0;
  color: var(--ink);
  text-indent: 0;
}

.verse-line.base {
  padding-left: 2.4rem;
  text-indent: 0;
}

.verse-line.indent-1 {
  padding-left: 4.6rem;
  text-indent: 0;
}

.verse-line.indent-2 {
  padding-left: 6.8rem;
  text-indent: 0;
}

.verse-line strong {
  font-weight: 600;
}

.glossary {
  position: relative;
  width: min(100% - 2rem, 52rem);
  padding-right: var(--source-rail);
  box-sizing: border-box;
  border-top: 1px solid var(--rule);
}

.glossary-nav {
  margin: 1.5rem 0 3rem;
  padding: 1.1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.1rem;
  background: var(--note-bg);
  border: 1px solid var(--rule);
}

.glossary-entry {
  display: flow-root;
  padding: 2.5rem 0;
  border-top: 1px solid var(--rule);
}

.glossary-entry header {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.glossary-entry .source-reference {
  flex: 0 0 auto;
}

.glossary-entry h3 {
  margin: 0;
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.65rem;
  font-weight: 500;
}

.glossary-entry p {
  margin: 0.7rem 0;
}

.glossary-figure {
  float: right;
  width: 6rem;
  margin: 0.25rem 0 1rem 1.25rem;
  padding: 0.45rem;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--ink-mid);
}

.glossary-figure img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
}

.glossary-figure figcaption {
  margin-top: 0.3rem;
  color: var(--ink-light);
  font-size: 0.75rem;
  text-align: center;
}

.source-note {
  margin-bottom: 5rem;
  padding: 2.5rem;
  background: var(--note-bg);
  border: 1px solid var(--rule);
  box-shadow: 0 0.8rem 2rem var(--shadow);
}

.source-note h2 {
  font-size: 1.35rem;
  text-align: left;
}

.site-footer {
  padding: 2.5rem 1rem;
  color: #eee3ca;
  background: #241f18;
  border-top: 3px solid var(--gold);
  font-size: 0.86rem;
  text-align: center;
}

.site-footer p {
  margin: 0.2rem;
}

.site-footer a {
  color: #e3c46b;
}

:focus-visible {
  outline: 3px solid #d19135;
  outline-offset: 3px;
}

@media (max-width: 720px) {
  html {
    scroll-padding-top: 8rem;
  }

  .site-nav {
    min-height: var(--header-height);
    gap: 0.75rem;
  }

  .nav-brand {
    padding-block: 0.38rem;
  }

  .nav-meta {
    font-size: 0.5rem;
  }

  .title-page {
    min-height: calc(100vh - 6.5rem);
  }

  .chapter-links {
    grid-template-columns: repeat(4, 1fr);
  }

  .introduction p {
    text-align: left;
    text-indent: 1.25em;
  }

  .glossary-entry > p {
    text-align: left;
  }

  .introduction .source-quotation,
  .introduction .idea-item {
    margin-inline: 0.5rem;
  }

  .verse-line,
  .verse-line.base,
  .verse-line.indent-1,
  .verse-line.indent-2 {
    padding-left: 1rem;
    text-indent: 0;
  }

  .verse-line.indent-1 {
    padding-left: 2rem;
  }

  .verse-line.indent-2 {
    padding-left: 3rem;
  }

  .glossary-entry header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.2rem;
  }

  .source-page-origin {
    scroll-margin-top: 9rem;
  }

  .note-box {
    margin-left: 0.5rem;
  }

  .source-note {
    padding: 1.5rem;
  }
}

@media print {
  @page {
    size: letter;
    margin: 0.65in 0.7in;
  }

  body {
    color: #000;
    background: #fff;
    font-size: 11pt;
  }

  .site-header,
  .skip-link,
  .scroll-cue,
  .contents-backdrop,
  .contents-toggle,
  .contents-close,
  .page-ref,
  .web-location,
  .source-note,
  .site-footer {
    display: none !important;
  }

  .title-page {
    min-height: 9.4in;
    padding: 0.5in 0;
    break-after: page;
    background: #fff;
  }

  .document-section,
  .chapter,
  .book-divider {
    width: 100%;
  }

  .contents-panel {
    position: static;
    width: 100%;
    max-height: none;
    padding: 0.35in 0;
    overflow: visible;
    border-right: 0;
    box-shadow: none;
    transform: none;
    visibility: visible;
  }

  .contents,
  .front-matter,
  .introduction,
  .glossary {
    break-before: page;
  }

  .chapter {
    padding-block: 0.35in;
    break-inside: avoid;
  }

  .chapter-header {
    margin-bottom: 0.18in;
  }

  .book-divider {
    break-before: page;
  }

  .glossary-entry {
    break-inside: avoid;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  .update-notice,
  .glossary-nav {
    background: #fff;
  }
}

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