/* 基础样式 */
* {
  box-sizing: border-box;
}

html, body {
  touch-action: manipulation;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: #fafafa;
  color: #424242;
  line-height: 1.9;
}

/* 桌面端布局（≥768px） */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 25%;
  min-width: 250px;
  max-width: 300px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #e0e0e0;
}

.book-title {
  font-size: 18px;
  color: #263238;
  margin: 0 0 8px 0;
  font-weight: 600;
}

.book-author {
  font-size: 14px;
  color: #757575;
  margin: 0;
}

.toc-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.toc-item {
  display: block;
  padding: 12px 20px;
  color: #555;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.toc-item:hover {
  background: #f5f5f5;
}

.toc-item.active {
  color: #1565c0;
  background: #e3f2fd;
  border-left-color: #1565c0;
  font-weight: 500;
}

/* 内容区域 */
.content {
  flex: 1;
  margin-left: 25%;
  padding: 40px;
  max-width: 900px;
}

.chapter-title {
  font-size: 24px;
  color: #263238;
  font-weight: 500;
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e0e0e0;
}

.chapter-body {
  font-size: 16px;
}

.chapter-body a,
.chapter-body a:visited {
  color: #1565c0;
}

.chapter-body a:hover {
  color: #0d47a1;
}

.chapter-body p {
  margin: 0 0 1.5em 0;
  /* text-indent: 2em; */
  line-height: 1.9;
}

/* 覆盖EPUB内联样式，统一正文格式 */
.chapter-body p.bodycontent-text {
  text-indent: 2em;
  margin: 0 0 1em 0;
  color: #424242;
  font-size: 16px;
  text-align: justify;
}

/* 小标题样式 */
.chapter-body h2.bodycontent-second-title1,
.chapter-body h2.bodycontent-second-title1a {
  font-size: 18px;
  color: #263238;
  font-weight: 500;
  margin: 2em 0 1em 0;
  text-indent: 0;
  page-break-before: auto;
}

/* 图片样式 */
.chapter-body img {
  max-width: 100%;
  height: auto;
  margin: 20px auto;
  display: block;
}

.chapter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}

.chapter-body th,
.chapter-body td {
  border: 1px solid #e0e0e0;
  padding: 10px;
  text-align: left;
}

/* 视频样式 */
.chapter-body video {
  max-width: 100%;
  margin: 20px auto;
  display: block;
}

/* 隐藏不必要的元素 */
.chapter-body .image-static {
  text-align: center;
  margin: 1em 0;
}

/* 脚注标记图标 */
.chapter-body a.footnote img,
.chapter-body img.inline10 {
  width: 1em;
  height: 1em;
  vertical-align: super;
  margin: 0 2px;
  display: inline;
}

/* 省略号图标 */
.chapter-body img[alt="shengluehao"] {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  display: inline;
}

/* 脚注样式 */
.chapter-body .footnote-content {
  margin-top: 3em;
  padding-top: 1em;
  border-top: 1px solid #e0e0e0;
  font-size: 14px;
  color: #666;
}

.chapter-body .footnote-item {
  margin-bottom: 0.5em;
}

/* 章节导航 */
.chapter-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px 0;
  margin-top: 40px;
  border-top: 1px solid #e0e0e0;
}

.chapter-nav a {
  padding: 10px 20px;
  background: #fff;
  border: 1px solid #e0e0e0;
  color: #1565c0;
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.2s;
}

.chapter-nav a:hover {
  background: #1565c0;
  color: #fff;
}

.chapter-nav a.disabled {
  color: #bdbdbd;
  pointer-events: none;
}

.chapter-position {
  padding: 0 20px;
  color: #757575;
  font-size: 14px;
}

/* 移动端样式（<768px） */
@media (max-width: 767px) {
  .sidebar {
    display: none;
  }

  .content {
    margin-left: 0;
    padding: 20px;
  }

  .mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .toc-toggle {
    padding: 8px 12px;
    background: #1565c0;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }

  .current-chapter {
    font-size: 14px;
    color: #424242;
  }

  .toc-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 200;
    flex-direction: column;
  }

  .toc-overlay.active {
    display: flex;
  }

  .toc-overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    font-weight: 600;
  }

  .toc-close {
    padding: 8px 12px;
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
  }

  .toc-overlay-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .chapter-title {
    font-size: 20px;
  }

  .chapter-nav {
    flex-wrap: wrap;
  }

  .chapter-nav a {
    padding: 12px 24px;
  }
}

/* 桌面端隐藏移动端元素 */
@media (min-width: 768px) {
  .mobile-header {
    display: none;
  }

  .toc-overlay {
    display: none !important;
  }
}

body.toc-open {
  overflow: hidden;
}
.floating-avatar {
  position: fixed;
  top: 80px;
  right: 10px;
  width: 70px;
  height: 70px;
  border: 0;
  outline: 0;
  padding: 0;
  display: block;
  z-index: 10000;
  overflow: hidden;
  background: transparent;
  background-color: transparent;
  -webkit-appearance: none;
  appearance: none;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: left 0.2s ease, top 0.15s ease;
  z-index: 5;
}

.floating-avatar.is-dragging {
  cursor: grabbing;
  transition: none;
}

.floating-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

@media (min-width: 768px) {
  .floating-avatar {
    right: 28px;
    bottom: 78px;
    top: auto;
    left: auto;
    cursor: pointer;
    touch-action: auto;
  }
}
