/* ───────────────────────────────────────────────────────────
   Cai Xiang book — reading stylesheet
   The site-nav stays in cave register; the reading surface
   opens onto a warm parchment for long-form comfort.
   ─────────────────────────────────────────────────────────── */

:root {
  --book-ground:    #faf6ec;
  --book-ground-2:  #f3ecdb;
  --book-ink:       #2a2520;
  --book-ink-soft:  #473f35;
  --book-ink-faint: #6b6253;
  --book-rule:      #c9bca0;
  --book-accent:    #7c3a2b;
  --book-gilt:      #b89a6a;
  --book-note-bg:   #f5efe0;
  --book-verse-bg:  #f3ecdb;
  --book-mark:      rgba(184, 154, 106, 0.34);
  --book-mark-hit:  rgba(184, 154, 106, 0.55);
}

/* ── book-nav strip ────────────────────────────────────── */

.book-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 2rem;
  border-bottom: 1px solid var(--depth-line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--pearl);
  font-family: var(--serif-body);
  flex-wrap: wrap;
  position: relative;
  z-index: 3;
}

.book-nav a { color: var(--pearl); text-decoration: none; }

.book-nav-back {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  opacity: 0.85;
}
.book-nav-back:hover { color: var(--bio); opacity: 1; }

.book-nav-chapters {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.book-chapter-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.5rem;
  border: 1px solid var(--depth-line);
  border-radius: 999px;
  font-size: 0.82rem;
  font-family: var(--serif-display);
  color: var(--pearl);
  opacity: 0.72;
  transition: all 0.15s;
}
.book-chapter-link:hover { opacity: 1; border-color: var(--bio); color: var(--bio); }
.book-chapter-link.active {
  opacity: 1;
  background: var(--bio);
  color: var(--ink-deep);
  border-color: var(--bio);
  font-weight: 500;
}

.book-nav-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.book-search {
  position: relative;
}

.book-search-input {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--depth-line);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  color: var(--pearl);
  font-family: var(--serif-body);
  font-size: 0.88rem;
  min-width: 16rem;
  outline: none;
  transition: border-color 0.15s;
}
.book-search-input:focus { border-color: var(--bio); }
.book-search-input::placeholder { color: rgba(228, 255, 240, 0.5); }

.book-search-results {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 26rem;
  max-width: 34rem;
  max-height: 24rem;
  overflow-y: auto;
  list-style: none;
  padding: 0.5rem;
  margin: 0;
  background: rgba(5, 13, 26, 0.98);
  border: 1px solid var(--depth-line);
  border-radius: 6px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  z-index: 40;
}

.book-search-results li { list-style: none; }

.book-search-result {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: 4px;
}
.book-search-result a { text-decoration: none; color: inherit; display: block; }
.book-search-result.is-active,
.book-search-result:hover { background: rgba(97, 255, 139, 0.09); }

.book-search-result-loc {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(97, 255, 139, 0.72);
}
.book-search-result-snippet {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--serif-body);
  font-size: 0.88rem;
  color: var(--pearl);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-search-result mark {
  background: transparent;
  color: var(--bio);
  font-weight: 600;
}
.book-search-empty {
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  color: rgba(228, 255, 240, 0.65);
  font-style: italic;
}

.seams-toggle {
  background: transparent;
  border: 1px solid var(--depth-line);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  color: var(--pearl);
  font-family: var(--serif-body);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s;
}
.seams-toggle:hover { border-color: var(--bio); color: var(--bio); }
.seams-toggle[aria-pressed="true"] {
  background: var(--bio);
  color: var(--ink-deep);
  border-color: var(--bio);
  font-weight: 500;
}

/* ── reading surface ───────────────────────────────────── */

.chapter {
  background: var(--book-ground);
  background-image:
    radial-gradient(circle at 12% 6%, rgba(201, 188, 160, 0.14) 0%, transparent 42%),
    radial-gradient(circle at 88% 94%, rgba(124, 58, 43, 0.05) 0%, transparent 46%);
  color: var(--book-ink);
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 20px;
  line-height: 1.72;
  padding: 6vh 7vw 8vh;
  max-width: 44rem;
  margin: 0 auto;
  width: 100%;
  border-left: 1px solid var(--book-rule);
  border-right: 1px solid var(--book-rule);
}

.chapter-header {
  text-align: center;
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--book-rule);
  padding-bottom: 2rem;
}

.chapter-number {
  display: block;
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 0.85rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--book-ink-faint);
  margin-bottom: 0.9rem;
}

.chapter-title {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  line-height: 1.05;
  color: var(--book-ink);
}

.chapter-section,
.chapter-lead-in {
  margin-top: 2.4rem;
}

.section-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.5rem;
  color: var(--book-accent);
  margin: 2.6rem 0 1rem;
  border-top: 1px solid var(--book-rule);
  padding-top: 1.6rem;
  line-height: 1.25;
}
.section-roman {
  font-style: italic;
  color: var(--book-gilt);
  margin-right: 0.3rem;
}

.subsection-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--book-accent);
  margin: 1.6rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chapter p {
  margin: 0 0 1.1rem;
  scroll-margin-top: 5.5rem;
}

.chapter p:first-of-type::first-letter,
.chapter-section > p:first-of-type::first-letter {
  /* subtle initial in each section — not a full drop cap */
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  color: var(--book-accent);
}

.chapter em { font-style: italic; }
.chapter strong { font-weight: 600; color: var(--book-ink); }

.chapter blockquote {
  background: var(--book-verse-bg);
  border-left: 3px solid var(--book-gilt);
  padding: 1rem 1.3rem;
  margin: 1.4rem 0;
  border-radius: 2px;
  font-size: 0.96rem;
  line-height: 1.75;
}
.chapter blockquote p { margin-bottom: 0.6rem; }
.chapter blockquote p:last-child { margin-bottom: 0; }

.chapter hr {
  border: none;
  border-top: 1px solid var(--book-rule);
  margin: 2.4rem auto;
  width: 55%;
  opacity: 0.7;
}

.chapter a {
  color: var(--book-accent);
  text-decoration: underline;
  text-decoration-color: rgba(124, 58, 43, 0.4);
  text-underline-offset: 2px;
}
.chapter a:hover { text-decoration-color: currentColor; }

/* ── seams (hidden by default) ─────────────────────────── */

.seam,
.seam-mark { display: none; }

body.seams-on .seam {
  display: block;
  margin: 1.1rem 0;
  padding: 0.7rem 1rem;
  border-left: 2px solid var(--book-gilt);
  background: var(--book-note-bg);
  color: var(--book-ink-faint);
  font-size: 0.9rem;
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  border-radius: 2px;
}
body.seams-on .seam em { font-style: italic; }

body.seams-on .seam-mark {
  display: inline;
  padding: 0.05em 0.35em;
  margin: 0 0.15em;
  background: rgba(184, 154, 106, 0.18);
  border-radius: 2px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 0.78em;
  letter-spacing: 0.06em;
  color: var(--book-accent);
  text-transform: none;
}

.chapter-footer.seam { display: none; }
body.seams-on .chapter-footer.seam {
  display: block;
  margin-top: 3rem;
  padding: 1.4rem 1.4rem 1rem;
  border-top: 1px solid var(--book-rule);
  border-left: none;
  background: var(--book-note-bg);
  color: var(--book-ink-soft);
  font-size: 0.92rem;
  font-family: 'EB Garamond', Georgia, serif;
  font-style: normal;
  border-radius: 2px;
}
body.seams-on .chapter-footer.seam em { font-style: italic; }
body.seams-on .chapter-footer.seam p { margin-bottom: 0.7rem; }

/* Blockquote seams reuse the aside seam treatment. */
body.seams-on .chapter blockquote.seam {
  background: var(--book-note-bg);
  border-left: 2px solid var(--book-gilt);
  color: var(--book-ink-faint);
  font-style: italic;
}

/* ── search-hit highlight (?q= landing) ────────────────── */

.chapter mark.search-hit {
  background: var(--book-mark);
  color: inherit;
  padding: 0 0.1em;
  border-radius: 2px;
  transition: background-color 0.6s ease-out;
}
.chapter p.search-target {
  background: var(--book-mark-hit);
  border-radius: 3px;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  margin-left: -0.5rem;
  margin-right: -0.5rem;
  transition: background-color 1.2s ease-out;
}
body.search-faded .chapter mark.search-hit { background: transparent; }
body.search-faded .chapter p.search-target { background: transparent; }

/* ── book cover / TOC ──────────────────────────────────── */

.book-cover .book-cover-header {
  padding: 8vh 2rem 4vh;
  text-align: center;
  max-width: 44rem;
  margin: 0 auto;
}

.book-cover-kicker {
  display: inline-block;
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(97, 255, 139, 0.75);
  margin-bottom: 1.4rem;
}

.book-cover-title {
  font-family: var(--serif-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 4rem);
  line-height: 1.05;
  color: var(--pearl);
  margin-bottom: 1.2rem;
}

.book-cover-byline {
  font-family: var(--serif-display);
  font-size: 0.95rem;
  color: rgba(228, 255, 240, 0.7);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 1.6rem;
}

.book-cover-dek {
  font-family: var(--serif-body);
  font-size: 1.05rem;
  color: rgba(228, 255, 240, 0.85);
  line-height: 1.6;
  max-width: 36rem;
  margin: 0 auto 2rem;
}

.book-cover-search {
  position: relative;
  max-width: 30rem;
  margin: 0 auto;
}
.book-cover-search .book-search-input {
  width: 100%;
  min-width: 0;
}
.book-cover-search .book-search-results {
  right: 0;
  left: 0;
}

/* ── TOC ───────────────────────────────────────────────── */

.book-cover-main { padding: 0 2rem 8vh; }

.toc {
  max-width: 44rem;
  margin: 3rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-eyebrow {
  text-align: center;
  margin-bottom: 1.4rem;
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(97, 255, 139, 0.6);
}

.toc-entry {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  align-items: center;
  gap: 1.2rem;
  padding: 1.1rem 1.4rem;
  border: 1px solid var(--depth-line);
  border-radius: 4px;
  text-decoration: none;
  color: var(--pearl);
  background: rgba(0, 0, 0, 0.14);
  transition: all 0.15s;
}
.toc-entry:hover {
  border-color: var(--bio);
  background: rgba(97, 255, 139, 0.06);
}
.toc-num {
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 1.5rem;
  color: rgba(97, 255, 139, 0.75);
  text-align: center;
}
.toc-body { display: flex; flex-direction: column; gap: 0.15rem; }
.toc-label {
  font-family: var(--serif-body);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(228, 255, 240, 0.55);
}
.toc-title {
  font-family: var(--serif-display);
  font-size: 1.2rem;
  color: var(--pearl);
  line-height: 1.25;
}
.toc-arrow {
  font-family: var(--serif-display);
  font-size: 1.2rem;
  color: rgba(97, 255, 139, 0.55);
}

/* ── book page footer ──────────────────────────────────── */

.book-footer {
  padding: 2rem;
  text-align: center;
  font-size: 0.82rem;
  color: rgba(228, 255, 240, 0.55);
  border-top: 1px solid var(--depth-line);
}
.book-footer a { color: rgba(228, 255, 240, 0.75); }
.book-footer a:hover { color: var(--bio); }

/* ── narrow viewports ──────────────────────────────────── */

@media (max-width: 700px) {
  .chapter {
    font-size: 18px;
    padding: 4vh 5vw 6vh;
    border-left: none;
    border-right: none;
  }
  .book-nav {
    padding: 0.6rem 1rem;
    gap: 0.5rem;
  }
  .book-nav-controls { width: 100%; justify-content: space-between; }
  .book-search-input { min-width: 0; flex: 1; }
  .book-search-results { left: 0; right: 0; min-width: 0; }
  .toc-entry { grid-template-columns: 2.4rem 1fr auto; padding: 0.9rem 1rem; }
}

@media print {
  body { background: #fff; }
  .site-nav, .book-nav, .book-footer, .book-search-results { display: none; }
  .chapter { border: none; max-width: none; padding: 0; }
  .seam, .seam-mark, .chapter-footer.seam { display: none !important; }
}
