/* ====== Base ====== */
@font-face {
  font-family: 'Ma Shan Zheng';
  src: url('../fonts/MaShanZheng-subset.woff2?v=3') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #1e1208;
  --ink-light: #4a3728;
  --ink-faint: #8a7060;
  --paper: #fdf8f0;
  --paper-dark: #f5edd8;
  --paper-card: #fffcf6;
  --gold: #b8860b;
  --gold-light: #d4a017;
  --red: #8b1a1a;
  --border: #e2d5c0;
  --shadow: 0 2px 16px rgba(30,18,8,0.10);
  --shadow-lg: 0 8px 40px rgba(30,18,8,0.15);
  --radius: 8px;
  --sidebar-w: 280px;
  --header-h: 56px;
  --font-body: 'Noto Serif SC', 'STSong', 'SimSun', 'Songti SC', Georgia, serif;
  --font-ui: 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --reading-max: 700px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); text-decoration: underline; }

/* ====== Landing Page ====== */
.hero {
  min-height: 100vh;
  background: linear-gradient(160deg, #1e1208 0%, #3a2010 60%, #5c3418 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px 80px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('../img/calligraphy/dingfengbo-full.jpg');
  background-repeat: no-repeat;
  background-position: center 40%;
  background-size: 100% auto;
  filter: invert(1) grayscale(1) brightness(1.3) contrast(1.1);
  mix-blend-mode: screen;
  opacity: 0.14;
}
.hero-inner { position: relative; z-index: 1; max-width: 640px; }
.hero-badge {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold-light);
  border: 1px solid rgba(180,130,15,0.4);
  border-radius: 20px;
  padding: 5px 18px;
  margin-bottom: 36px;
}
.hero-title {
  margin-bottom: 16px;
  line-height: 1.1;
}
.hero-title img {
  width: clamp(300px, 50vw, 620px);
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 4px 24px rgba(0,0,0,0.4));
}
.hero-author {
  font-size: 20px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.3em;
  margin-bottom: 32px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
.hero-author span {
  color: #fff;
}
.hero-divider {
  width: 60px;
  height: 1px;
  background: var(--gold);
  margin: 0 auto 32px;
  opacity: 0.6;
}
.hero-tagline {
  font-size: clamp(14px, 2.5vw, 17px);
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  line-height: 2;
  max-width: 480px;
  margin: 0 auto 48px;
  font-style: italic;
  text-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--gold);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 36px;
  border-radius: 50px;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(180,130,15,0.4);
}
.hero-cta:hover {
  background: var(--gold-light);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(180,130,15,0.5);
  text-decoration: none;
  color: #fff;
}
.hero-scroll {
  position: absolute;
  z-index: 1;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.3);
  font-size: 22px;
  animation: bounce 2s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(8px); }
}

/* About section */
.about-section {
  padding: 80px 24px;
  max-width: 900px;
  margin: 0 auto;
}
.section-title {
  font-size: 13px;
  font-family: var(--font-ui);
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 16px;
}
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: start;
}
@media (max-width: 660px) {
  .about-grid { grid-template-columns: 1fr; gap: 32px; }
}
.about-text {
  font-size: 16px;
  line-height: 2;
  color: var(--ink-light);
  max-width: 720px;
  margin: 0 auto;
  background: rgba(253, 248, 240, 0.88);
  border-radius: var(--radius);
  padding: 36px 40px;
  box-shadow: 0 2px 24px rgba(30,18,8,0.06);
}
.about-text p { margin-bottom: 16px; }
.preface-text {
  font-family: 'Ma Shan Zheng', var(--font-body);
  font-size: 19px;
  line-height: 2.1;
  color: var(--ink);
}
.preface-text p { margin-bottom: 16px; }
@media (max-width: 660px) {
  .about-text { padding: 24px 22px; }
}

/* Ambient calligraphy backgrounds — faint ink-on-paper texture behind sections */
.ink-bg { position: relative; }
.ink-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  mix-blend-mode: multiply;
  filter: grayscale(60%) contrast(0.9);
  opacity: 0.24;
}
.ink-bg > * { position: relative; z-index: 1; }
.ink-bg-wanghaichao::before { background-image: url('../img/calligraphy/wanghaichao-full.jpg'); opacity: 0.34; }
.ink-bg-furonglou::before   { background-image: url('../img/calligraphy/furonglou-full.jpg'); opacity: 0.08; }

/* On narrow/tall mobile viewports, "cover" over-zooms a wide image trying to
   also cover the (often very tall) section height, shrinking it down to an
   unrecognizable sliver. Pin zoom to a fixed multiple of width instead. */
@media (max-width: 660px) {
  .ink-bg-wanghaichao::before { background-size: 220% auto; background-position: center 15%; }
  .ink-bg-furonglou::before   { background-size: 160% auto; background-position: center 10%; }
}

/* Author feature section */
.author-section {
  position: relative;
  padding: 96px 24px;
  overflow: hidden;
}
.author-section::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url('../img/calligraphy/songtao-full.jpg');
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  mix-blend-mode: multiply;
  filter: grayscale(60%) contrast(0.9);
  opacity: 0.24;
}
.author-inner {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 56px;
  align-items: center;
}
.author-portrait-frame {
  background: var(--paper-card);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.author-portrait-frame img {
  width: 100%;
  aspect-ratio: 4/5;
  object-fit: cover;
  object-position: center 22%;
  border-radius: 4px;
  display: block;
}
.author-name { font-size: 32px; font-weight: 800; color: var(--ink); margin: 4px 0 6px; }
.author-name-sub {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink-faint);
  letter-spacing: 1px;
  margin-bottom: 22px;
}
.author-bio { font-size: 15.5px; line-height: 2; color: var(--ink-light); }
.author-bio p { margin-bottom: 14px; }
@media (max-width: 760px) {
  .author-inner { grid-template-columns: 1fr; gap: 28px; text-align: center; }
  .author-portrait-frame { max-width: 320px; margin: 0 auto; }
}

/* TOC section */
.toc-section {
  background: var(--paper-dark);
  padding: 72px 24px 80px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.toc-inner { max-width: 860px; margin: 0 auto; }
.toc-heading {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}
.toc-subheading {
  font-size: 14px;
  color: var(--ink-faint);
  font-family: var(--font-ui);
  margin-bottom: 48px;
}
.toc-part { margin-bottom: 40px; }
.toc-part-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  cursor: pointer;
  user-select: none;
}
.toc-part-badge {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 20px;
  flex-shrink: 0;
}
.badge-1 { background: #e8f4ea; color: #2e7d32; }
.badge-2 { background: #e8f0fb; color: #1a3a6e; }
.badge-3 { background: #fde8e8; color: #8b1a1a; }
.toc-part-name { font-size: 18px; font-weight: 700; color: var(--ink); }
.toc-part-sub { font-size: 13px; color: var(--ink-faint); font-family: var(--font-ui); margin-left: auto; }
.toc-toggle { color: var(--ink-faint); font-size: 14px; transition: transform 0.3s; }
.toc-part.collapsed .toc-toggle { transform: rotate(-90deg); }
.toc-part.collapsed .toc-list { display: none; }
.toc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px 12px;
  padding-left: 0;
  list-style: none;
}
.toc-item a {
  display: block;
  padding: 6px 0;
  font-family: var(--font-ui);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.6;
  letter-spacing: 0.2px;
  transition: color 0.15s;
  border-bottom: 1px solid transparent;
}
.toc-item a:hover {
  color: var(--gold);
  text-decoration: none;
}
.toc-num {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-faint);
  margin-right: 4px;
}

/* Landing footer */
.landing-footer {
  padding: 32px 24px;
  text-align: center;
  color: var(--ink-faint);
  font-family: var(--font-ui);
  font-size: 13px;
}

/* ====== Reader Page ====== */
.reader-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--paper-card);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--paper-card);
  z-index: 1;
}
.sidebar-home {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-faint);
  font-family: var(--font-ui);
  margin-bottom: 12px;
}
.sidebar-home:hover { color: var(--gold); text-decoration: none; }
.sidebar-book-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.05em;
  line-height: 1.3;
}
.sidebar-book-author {
  font-size: 12px;
  color: var(--ink-faint);
  font-family: var(--font-ui);
  margin-top: 2px;
}
.sidebar-nav { padding: 8px 0 24px; flex: 1; }
.sidebar-part-label {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 16px 16px 6px;
}
.sidebar-ch-link {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 16px;
  font-size: 13px;
  color: var(--ink-light);
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar-ch-link:hover { background: var(--paper-dark); color: var(--ink); }
.sidebar-ch-link.active {
  background: rgba(184,134,11,0.12);
  color: var(--gold);
  font-weight: 600;
}
.sidebar-ch-num {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-faint);
  flex-shrink: 0;
  min-width: 20px;
}
.sidebar-ch-link.active .sidebar-ch-num { color: var(--gold); }

/* Main reading area */
.reader-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.reader-topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--paper-card);
  position: sticky;
  top: 0;
  z-index: 5;
  gap: 12px;
}
.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--ink-light);
  font-size: 20px;
}
.topbar-progress-wrap {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.topbar-progress-bar {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transition: width 0.3s;
}
.topbar-chapter-info {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Chapter content */
.chapter-wrap {
  max-width: var(--reading-max);
  margin: 0 auto;
  padding: 48px 32px 80px;
  width: 100%;
}
.chapter-meta {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.chapter-title {
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.4;
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.chapter-body p {
  font-size: clamp(15px, 2vw, 18px);
  line-height: 2;
  color: var(--ink);
  margin-bottom: 1.5em;
  text-indent: 2em;
  word-break: break-all;
  overflow-wrap: break-word;
}
.chapter-body p:last-child { margin-bottom: 0; }

/* Nav buttons */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px 48px;
  max-width: var(--reading-max);
  margin: 0 auto;
  width: 100%;
  gap: 12px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink-light);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  max-width: 48%;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.nav-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(184,134,11,0.05);
}
.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.nav-btn:disabled:hover { border-color: var(--border); color: var(--ink-light); background: var(--paper-card); }
.nav-btn-prev { flex-direction: row; }
.nav-btn-next { flex-direction: row-reverse; margin-left: auto; }
.nav-btn .btn-label { font-size: 11px; color: var(--ink-faint); display: block; }

/* Inline annotations (select text -> comment, like Google Docs) */
mark.hl-comment {
  background: rgba(184, 134, 11, 0.18);
  border-bottom: 2px solid var(--gold-light);
  color: inherit;
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
  transition: background 0.15s;
}
mark.hl-comment:hover { background: rgba(184, 134, 11, 0.32); }

.annot-btn {
  position: fixed;
  z-index: 40;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--paper);
  background: var(--gold);
  border: none;
  border-radius: 20px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  white-space: nowrap;
}
.annot-btn:hover { background: var(--gold-light); }

.annot-popup {
  position: fixed;
  z-index: 41;
  width: 280px;
  max-width: calc(100vw - 24px);
  background: var(--paper-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,0.22);
  padding: 14px;
  font-family: var(--font-ui);
}
.annot-popup-quote {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-light);
  background: var(--paper-dark);
  border-left: 3px solid var(--gold);
  padding: 8px 10px;
  margin-bottom: 10px;
  border-radius: 0 4px 4px 0;
  max-height: 4.5em;
  overflow: hidden;
  line-height: 1.5;
}
.annot-popup input,
.annot-popup textarea {
  font-family: var(--font-body);
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  resize: vertical;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.annot-popup input:focus,
.annot-popup textarea:focus { outline: none; border-color: var(--gold-light); }
.annot-popup-row { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.annot-hint { font-size: 11.5px; color: #b0392f; flex: 1; }
.annot-btn-cancel {
  font-family: var(--font-ui);
  font-size: 12.5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink-light);
  padding: 7px 14px;
  cursor: pointer;
}
.annot-btn-submit {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 700;
  background: var(--gold);
  color: var(--paper);
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
}
.annot-btn-submit:hover { background: var(--gold-light); }
.annot-btn-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.annot-thread {
  position: fixed;
  z-index: 41;
  width: 300px;
  max-width: calc(100vw - 24px);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--paper-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,0.22);
  padding: 14px;
  font-family: var(--font-ui);
}
.annot-thread-quote {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-light);
  background: var(--paper-dark);
  border-left: 3px solid var(--gold);
  padding: 8px 10px;
  margin-bottom: 12px;
  border-radius: 0 4px 4px 0;
  line-height: 1.5;
}
.annot-thread-item { margin-bottom: 12px; }
.annot-thread-item:last-of-type { margin-bottom: 4px; }
.annot-thread-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.annot-thread-name { font-weight: 700; color: var(--gold); font-size: 12.5px; }
.annot-thread-date { font-size: 10.5px; color: var(--ink-faint); }
.annot-thread-body {
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--ink);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.annot-thread-reply {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--gold);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0 0;
}
.annot-thread-reply:hover { text-decoration: underline; }
.annot-thread-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--ink-faint);
  cursor: pointer;
  line-height: 1;
}
@media (max-width: 480px) {
  .annot-popup, .annot-thread { width: calc(100vw - 24px); }
}

/* Mobile sidebar drawer */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 85vw);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 30;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-menu-btn { display: flex; }
  .reader-main { width: 100%; }
  .chapter-wrap { padding: 32px 20px 60px; }
  .chapter-nav { padding: 16px 20px 40px; }
}

/* Font loading fallback */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;700;900&display=swap');
