:root {
  --violet: #5625e8;
  --violet-bright: #7552ff;
  --cyan: #7be8ff;
  --ink: #181526;
  --muted: #6f6b7b;
  --paper: #ffffff;
  --canvas: #f3f4f9;
  --rule: #e6e5ed;
  --sidebar: #100d1d;
  --sidebar-muted: #918ca2;
  --sidebar-width: 322px;
  --article-width: 790px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 100;
  pointer-events: none;
}
.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--violet-bright));
  box-shadow: 0 0 14px rgba(117, 82, 255, .45);
}

.site-shell { min-height: 100vh; }
.book-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  overflow: hidden;
  color: #fff;
  background:
    radial-gradient(circle at 92% 9%, rgba(111, 68, 255, .28), transparent 26%),
    linear-gradient(165deg, #161126 0%, var(--sidebar) 54%, #090812 100%);
  border-right: 1px solid rgba(255,255,255,.08);
}
.sidebar-top { padding: 28px 26px 18px; }
.book-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}
.mark-symbol {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: #120d22;
  background: var(--cyan);
  border-radius: 3px 12px 3px 3px;
  font: 800 17px/1 ui-monospace, monospace;
}
.mark-copy { display: flex; flex-direction: column; gap: 2px; }
.mark-copy b { font-size: 16px; letter-spacing: .08em; }
.mark-copy small { color: #817b94; font: 600 8px/1.3 ui-monospace, monospace; letter-spacing: .13em; }
.sidebar-close { display: none; }

.book-object {
  position: relative;
  height: 142px;
  margin: 25px 4px 14px;
  perspective: 700px;
}
.book-cover {
  position: absolute;
  inset: 8px 28px 12px 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 18px 15px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255,255,255,.14), transparent 45%),
    linear-gradient(145deg, #7651ff, #3d13c8 75%);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 2px 7px 7px 2px;
  box-shadow: 22px 18px 45px rgba(0,0,0,.4);
  transform: rotateY(-11deg) rotateZ(-2deg);
}
.book-cover::after {
  content: "";
  position: absolute;
  top: -45px;
  right: -25px;
  width: 110px;
  height: 180px;
  border: 1px solid rgba(123,232,255,.4);
  border-radius: 50%;
  transform: rotate(36deg);
}
.book-cover i { font: 800 46px/.9 "STKaiti", serif; font-style: normal; }
.book-cover em { font: 700 8px/1.45 ui-monospace, monospace; letter-spacing: .16em; font-style: normal; }
.book-spine {
  position: absolute;
  z-index: 2;
  top: 15px;
  bottom: 16px;
  left: 23px;
  width: 15px;
  background: #291078;
  transform: skewY(-21deg);
  box-shadow: inset -4px 0 8px rgba(0,0,0,.35);
}
.book-pages {
  position: absolute;
  right: 22px;
  bottom: 6px;
  left: 40px;
  height: 18px;
  background: repeating-linear-gradient(0deg, #c9c5d9 0 1px, #f4f1ff 1px 3px);
  transform: skewX(49deg) rotate(-2deg);
  border-radius: 0 0 5px 2px;
}
.book-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: rgba(255,255,255,.08); }
.book-stats span { padding: 10px 8px; color: var(--sidebar-muted); background: rgba(8,7,17,.62); font-size: 10px; text-align: center; }
.book-stats b { display: block; margin-bottom: 2px; color: #fff; font: 700 15px/1 ui-monospace, monospace; }

.chapter-nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 13px 24px;
  scrollbar-width: thin;
  scrollbar-color: #393247 transparent;
}
.chapter-nav details { border-top: 1px solid rgba(255,255,255,.07); }
.chapter-nav summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 11px 11px;
  color: #a8a2b8;
  cursor: pointer;
  list-style: none;
  font-size: 11px;
  letter-spacing: .04em;
}
.chapter-nav summary::-webkit-details-marker { display: none; }
.chapter-nav summary::before { content: "+"; color: #6d6682; font: 13px/1 ui-monospace, monospace; }
.chapter-nav details[open] summary::before { content: "−"; }
.chapter-nav .part-index { min-width: 23px; color: var(--cyan); font: 700 9px/1 ui-monospace, monospace; }
.chapter-list { padding: 0 0 10px 34px; }
.chapter-list a {
  position: relative;
  display: block;
  margin: 1px 0;
  padding: 8px 12px 8px 16px;
  color: #827c91;
  border-radius: 4px;
  text-decoration: none;
  font-size: 12px;
  line-height: 1.45;
  transition: color .2s, background .2s;
}
.chapter-list a:hover { color: #fff; background: rgba(255,255,255,.05); }
.chapter-list a.active { color: #fff; background: rgba(99,59,236,.24); }
.chapter-list a.active::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 0;
  width: 3px;
  height: 18px;
  background: var(--cyan);
  border-radius: 3px;
}
.sidebar-foot { padding: 13px 24px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot a { display: flex; justify-content: space-between; color: #888297; text-decoration: none; font-size: 11px; }
.sidebar-foot a:hover { color: #fff; }

.reader {
  display: grid;
  grid-template-columns: minmax(0, var(--article-width)) 210px;
  gap: 58px;
  max-width: 1170px;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 70px 56px 100px 76px;
}
.article {
  width: 100%;
  min-width: 0;
  padding: 0 68px 58px;
  background: var(--paper);
  box-shadow: 0 20px 70px rgba(35,25,67,.07);
}
.chapter-header { position: relative; padding: 62px 0 40px; overflow: hidden; }
.chapter-kicker { display: flex; align-items: center; gap: 10px; color: var(--violet); font: 700 10px/1.2 ui-monospace, monospace; letter-spacing: .08em; }
.chapter-kicker i { width: 26px; height: 1px; background: #beb4e2; }
.chapter-kicker span:last-child { color: #918b9e; font-weight: 500; }
.chapter-number {
  position: absolute;
  top: 32px;
  right: -8px;
  color: #f0edfb;
  font: 800 118px/.9 ui-monospace, monospace;
  letter-spacing: -.09em;
  user-select: none;
}
.chapter-header h1 {
  position: relative;
  max-width: 600px;
  margin: 22px 0 28px;
  color: #161222;
  font-family: "Songti SC", "STSong", serif;
  font-size: clamp(32px, 4vw, 48px);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: -.03em;
}
.chapter-rule { display: flex; align-items: center; gap: 14px; }
.chapter-rule span { width: 78px; height: 4px; background: var(--violet); }
.chapter-rule b { color: #aba6b4; font: 700 8px/1 ui-monospace, monospace; letter-spacing: .19em; }

.article-body { color: #35313e; font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif; font-size: 17px; line-height: 1.92; }
.article-body > p:first-child { color: #211d2b; font-size: 19px; line-height: 1.88; }
.article-body p { margin: 0 0 1.18em; }
.article-body h2, .article-body h3, .article-body h4 { color: #171321; font-family: "SF Pro Display", "PingFang SC", sans-serif; scroll-margin-top: 32px; }
.article-body h2 { margin: 3.4em 0 1.2em; padding-top: .5em; font-size: 27px; line-height: 1.45; letter-spacing: -.02em; }
.article-body h2::before { content: ""; display: block; width: 34px; height: 5px; margin-bottom: 17px; background: linear-gradient(90deg, var(--violet), var(--cyan)); }
.article-body h3 { margin: 2.6em 0 1em; font-size: 21px; line-height: 1.5; }
.article-body h4 { margin: 2.2em 0 .8em; font-size: 18px; }
.article-body b { color: #1c1726; font-weight: 700; }
.article-body a:not(.attachment) { color: #4f26ca; text-decoration-color: #c3b6f1; text-underline-offset: 4px; }
.article-body a:not(.attachment):hover { color: #2c0d9d; text-decoration-color: currentColor; }
.article-body ul, .article-body ol { margin: 1.1em 0 1.5em; padding-left: 1.5em; }
.article-body li { margin: .45em 0; padding-left: .3em; }
.article-body li::marker { color: var(--violet); font-weight: 700; }
.article-body blockquote {
  margin: 2em 0;
  padding: 20px 24px 20px 27px;
  color: #4c4658;
  background: #f7f5ff;
  border-left: 4px solid var(--violet);
}
.article-body blockquote p:last-child { margin-bottom: 0; }
.article-body pre {
  position: relative;
  max-width: 100%;
  margin: 1.7em 0 2em;
  padding: 44px 22px 22px;
  overflow-x: auto;
  color: #e8e2f7;
  background: #171321;
  border: 1px solid #2d263c;
  border-radius: 7px;
  font: 13px/1.7 "SFMono-Regular", Consolas, monospace;
  tab-size: 2;
}
.article-body pre::before {
  content: attr(data-language);
  position: absolute;
  top: 12px;
  left: 20px;
  color: #8f87a2;
  font: 700 9px/1 ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.article-body code { font-family: "SFMono-Regular", Consolas, monospace; }
.article-body p code, .article-body li code { padding: .15em .38em; color: #4421b2; background: #f0edfa; border-radius: 3px; font-size: .86em; }
.formula { display: inline-block; padding: 0 .24em; color: #3c21a1; font-family: "Times New Roman", serif; font-style: italic; }
.article-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 720px;
  margin: 2em auto;
  object-fit: contain;
  background: #fafafd;
  border: 1px solid #e9e7ee;
  border-radius: 5px;
  box-shadow: 0 12px 34px rgba(28,21,49,.09);
  cursor: zoom-in;
}
.table-scroll { max-width: 100%; margin: 1.9em 0; overflow-x: auto; border: 1px solid var(--rule); border-radius: 6px; }
.table-scroll .table-scroll { margin: 0; border: 0; border-radius: 0; }
.article-body table { width: 100%; min-width: 540px; border-collapse: collapse; font-family: "SF Pro Display", "PingFang SC", sans-serif; font-size: 14px; line-height: 1.55; }
.article-body th { color: #272130; background: #f2effd; font-weight: 700; text-align: left; }
.article-body th, .article-body td { padding: 11px 13px; border: 1px solid var(--rule); vertical-align: top; }
.article-body table p { margin: 0; }
.article-body table img { min-width: 160px; margin: 5px auto; box-shadow: none; }
.attachment {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: .5em 0 1.5em;
  padding: 12px 16px;
  color: #33256b;
  background: #f4f1ff;
  border: 1px solid #ddd5fb;
  border-radius: 5px;
  font-family: "SF Pro Display", "PingFang SC", sans-serif;
  font-size: 14px;
  text-decoration: none;
}
.attachment-mark { display: grid; width: 25px; height: 25px; place-items: center; color: white; background: var(--violet); border-radius: 50%; }

.chapter-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 70px; padding-top: 26px; border-top: 1px solid var(--rule); }
.pager-link { min-width: 0; padding: 15px 17px; color: #292432; border: 1px solid var(--rule); border-radius: 5px; text-decoration: none; transition: border-color .2s, transform .2s; }
.pager-link:hover { border-color: #aa98ee; transform: translateY(-2px); }
.pager-link small { display: block; margin-bottom: 5px; color: #98929f; font-size: 10px; }
.pager-link span { display: block; overflow: hidden; font-size: 13px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.pager-link.next { text-align: right; }
.pager-link.disabled { visibility: hidden; pointer-events: none; }

.local-toc { position: sticky; top: 44px; align-self: start; max-height: calc(100vh - 90px); padding-top: 10px; overflow: auto; }
.toc-label { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; border-bottom: 2px solid #272132; }
.toc-label span { color: #736e7c; font: 700 9px/1 ui-monospace, monospace; letter-spacing: .14em; }
.toc-label b { color: var(--violet); font: 800 18px/1 ui-monospace, monospace; }
.local-toc nav { padding: 14px 0 12px; border-bottom: 1px solid #dcd9e4; }
.local-toc a { position: relative; display: block; padding: 6px 6px 6px 15px; color: #89838f; text-decoration: none; font-size: 11px; line-height: 1.55; }
.local-toc a[data-level="h3"] { padding-left: 26px; font-size: 10px; }
.local-toc a[data-level="h4"] { padding-left: 36px; font-size: 10px; }
.local-toc a.active, .local-toc a:hover { color: #2f2840; }
.local-toc a.active::before { content: ""; position: absolute; top: 9px; bottom: 9px; left: 0; width: 3px; background: var(--violet); border-radius: 3px; }
.local-toc .back-top { margin-top: 13px; padding-left: 0; color: #676170; font-size: 10px; }

.mobile-header, .sidebar-scrim { display: none; }
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  padding: 50px;
  place-items: center;
  background: rgba(9,7,16,.92);
}
.image-viewer[hidden] { display: none; }
.image-viewer img { max-width: 95vw; max-height: 90vh; object-fit: contain; }
.image-viewer button { position: absolute; top: 20px; right: 24px; width: 40px; height: 40px; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.3); border-radius: 50%; cursor: pointer; font-size: 27px; }

@media (max-width: 1180px) {
  .reader { grid-template-columns: minmax(0, var(--article-width)); max-width: 940px; padding-right: 48px; }
  .local-toc { display: none; }
}

@media (max-width: 820px) {
  :root { --sidebar-width: min(88vw, 340px); }
  .mobile-header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 25;
    display: grid;
    grid-template-columns: 42px 1fr 42px;
    height: 58px;
    align-items: center;
    padding: 0 14px;
    color: white;
    background: rgba(16,13,29,.97);
    border-bottom: 1px solid rgba(255,255,255,.1);
    backdrop-filter: blur(12px);
  }
  .menu-button { position: relative; width: 36px; height: 36px; padding: 0; background: transparent; border: 0; cursor: pointer; }
  .menu-button span { position: absolute; left: 8px; width: 20px; height: 1px; background: white; }
  .menu-button span:first-child { top: 13px; }
  .menu-button span:last-child { top: 21px; }
  .mobile-brand { justify-self: center; font-size: 14px; font-weight: 700; letter-spacing: .1em; text-decoration: none; }
  .mobile-page { justify-self: end; color: var(--cyan); font: 700 12px/1 ui-monospace, monospace; }
  .book-sidebar { transform: translateX(-102%); transition: transform .26s ease; }
  .book-sidebar.open { transform: translateX(0); }
  .sidebar-close { position: absolute; top: 21px; right: 16px; display: block; width: 36px; height: 36px; color: white; background: transparent; border: 0; font-size: 25px; cursor: pointer; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 28; width: 100%; height: 100%; background: rgba(5,4,10,.58); border: 0; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-scrim.open { display: block; opacity: 1; pointer-events: auto; }
  .reader { display: block; max-width: none; margin-left: 0; padding: 82px 14px 50px; }
  .article { max-width: 720px; margin: 0 auto; padding: 0 clamp(22px, 6vw, 54px) 45px; }
  .chapter-header { padding: 48px 0 30px; }
  .chapter-number { top: 25px; right: 0; font-size: 80px; }
  .chapter-header h1 { margin-top: 18px; font-size: clamp(29px, 8vw, 40px); }
  .article-body { font-size: 16px; line-height: 1.9; }
  .article-body > p:first-child { font-size: 17px; }
  .article-body h2 { margin-top: 2.9em; font-size: 24px; }
  .article-body h3 { font-size: 20px; }
  .article-image { max-height: 78vh; }
  .chapter-pager { grid-template-columns: 1fr; }
  .pager-link.next { text-align: left; }
}

@media (max-width: 460px) {
  .reader { padding-right: 0; padding-left: 0; }
  .article { border-radius: 0; box-shadow: none; }
  .chapter-kicker { max-width: 72%; flex-wrap: wrap; }
  .article-body pre { margin-right: -8px; margin-left: -8px; border-radius: 4px; }
  .image-viewer { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
