/* ===== Chinese readability ===== */
.markdown-section {
  /* 系统字体栈：各平台用本机中文黑体，无额外下载、WebView 友好 */
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei UI",
    "Microsoft YaHei",
    "Noto Sans CJK SC",
    "Source Han Sans SC",
    "WenQuanYi Micro Hei",
    sans-serif;
  line-height: 1.9;
  letter-spacing: 0.01em;
  text-rendering: optimizeLegibility;
}

.markdown-section p {
  margin: 0 0 1.15em;
  text-align: justify;
}

.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
  letter-spacing: 0;
}

.markdown-section h1 {
  margin-top: 1.35em;
  margin-bottom: 0.7em;
}

.markdown-section h2 {
  margin-top: 1.2em;
  margin-bottom: 0.65em;
}

.markdown-section h3 {
  margin-top: 1.05em;
  margin-bottom: 0.55em;
}

.markdown-section h4 {
  margin-top: 0.95em;
  margin-bottom: 0.5em;
}

.markdown-section .heading-with-share {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.markdown-section .share-anchor {
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  color: #4b5563;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1;
  padding: 6px 9px;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-1px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.markdown-section .heading-with-share:hover .share-anchor,
.markdown-section .heading-with-share:focus-within .share-anchor,
.markdown-section .heading-with-share.show-share .share-anchor {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.markdown-section .share-anchor--flash {
  border-color: rgba(59, 130, 246, 0.4);
}

.markdown-section a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ===== Code blocks ===== */
.markdown-section code {
  background: #f6f7f9;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  padding: 0.15em 0.35em;
}

.markdown-section pre {
  background: #f6f7f9;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.markdown-section pre > code {
  font-size: 0.9em;
  background: transparent;
  border: none;
  padding: 0;
}

/* ===== Tables: horizontal scroll on overflow ===== */
.markdown-section table {
  display: block;
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 10px;
}

.markdown-section table.table-scrollable {
  background-clip: padding-box;
}

.markdown-section table.table-hint-left {
  box-shadow: inset 12px 0 10px -10px rgba(0, 0, 0, 0.2);
}

.markdown-section table.table-hint-right {
  box-shadow: inset -12px 0 10px -10px rgba(0, 0, 0, 0.2);
}

.markdown-section table.table-hint-left.table-hint-right {
  box-shadow:
    inset 12px 0 10px -10px rgba(0, 0, 0, 0.2),
    inset -12px 0 10px -10px rgba(0, 0, 0, 0.2);
}

.markdown-section table th {
  white-space: nowrap;
}

.markdown-section table td {
  white-space: normal;
  word-break: break-word;
}

.markdown-section blockquote {
  color: #4b5563;
  border-left-color: rgba(0, 0, 0, 0.16);
}

/* ===== Images: prevent overflow ===== */
.markdown-section img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.5em 0;
}

/* ===== Mobile ===== */
@media (max-width: 600px) {
  .markdown-section {
    font-size: 16px;
  }

  .page-inner {
    padding: 16px 14px 40px 14px;
  }

  .markdown-section h1 { font-size: 1.75em; }
  .markdown-section h2 { font-size: 1.45em; }
  .markdown-section h3 { font-size: 1.25em; }

  .markdown-section pre {
    padding: 0.85em 0.9em;
  }

  /* Sidebar: larger touch targets */
  .book-summary ul.summary li a,
  .book-summary ul.summary li span {
    padding: 12px 15px;
  }

  /* Navigation arrows: larger tap area */
  .navigation {
    font-size: 36px;
    min-height: 50px;
    padding: 12px 8px;
  }

  .markdown-section .share-anchor {
    font-size: 12px;
    min-height: 32px;
    padding: 8px 10px;
  }
}

@media (max-width: 360px) {
  .markdown-section {
    font-size: 15px;
  }

  .page-inner {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* ===== Night theme readability ===== */
.book.color-theme-2 .markdown-section a {
  color: #8ec5ff;
}

.book.color-theme-2 .markdown-section a:hover,
.book.color-theme-2 .markdown-section a:focus {
  color: #b7dcff;
}

.book.color-theme-2 .markdown-section code {
  color: #e8edf5;
  background: #1f2633;
  border-color: rgba(255, 255, 255, 0.16);
}

.book.color-theme-2 .markdown-section pre {
  color: #e8edf5;
  background: #1f2633;
  border-color: rgba(255, 255, 255, 0.16);
}

.book.color-theme-2 .markdown-section pre > code {
  color: inherit;
}

.book.color-theme-2 .markdown-section blockquote {
  color: #cdd6e3;
  border-left-color: rgba(151, 197, 255, 0.6);
}

.book.color-theme-2 .markdown-section .share-anchor {
  color: #dbe7f8;
  background: #273247;
  border-color: rgba(255, 255, 255, 0.2);
}

.book.color-theme-2 .markdown-section table {
  background: #1b2230;
  border-color: rgba(255, 255, 255, 0.2);
}

.book.color-theme-2 .markdown-section table th {
  color: #ecf2fb;
  background: #283247;
}

.book.color-theme-2 .markdown-section table td {
  color: #d7deea;
}

.book.color-theme-2 .markdown-section table tr {
  background-color: #1f2736;
  border-top-color: rgba(255, 255, 255, 0.14);
}

.book.color-theme-2 .markdown-section table tr:nth-child(2n) {
  background-color: #252f42;
}

/* ===== Image Lightbox ===== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}

.lightbox-overlay.lightbox-visible {
  opacity: 1;
  visibility: visible;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 10000;
  background: none;
  border: none;
  color: #fff;
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  padding: 8px 12px;
  opacity: 0.8;
  transition: opacity 160ms ease;
}

.lightbox-close:hover,
.lightbox-close:focus {
  opacity: 1;
}

.lightbox-img-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transform-origin: center center;
}

.lightbox-img {
  max-width: 92vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ===== Back to Top ===== */
.back-to-top {
  position: fixed !important;
  bottom: 24px;
  right: 20px !important;
  left: auto !important;
  z-index: 900;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50% !important;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 22px;
  line-height: 42px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 200ms ease, visibility 200ms ease, transform 200ms ease, background 160ms ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  -webkit-appearance: none;
}

.back-to-top-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover,
.back-to-top:focus {
  background: rgba(0, 0, 0, 0.75);
}

@media (max-width: 600px) {
  .back-to-top {
    bottom: 18px;
    right: 14px !important;
    width: 40px;
    height: 40px;
    font-size: 20px;
    line-height: 40px;
  }
}

.book.color-theme-2 .back-to-top {
  background: rgba(255, 255, 255, 0.2);
}

.book.color-theme-2 .back-to-top:hover,
.book.color-theme-2 .back-to-top:focus {
  background: rgba(255, 255, 255, 0.35);
}

/* ===== TOC Toggle (mobile) ===== */
.toc-toggle {
  display: none;
}

@media (max-width: 600px) {
  .toc-toggle {
    display: block;
    position: fixed !important;
    bottom: 24px;
    left: 14px !important;
    right: auto !important;
    z-index: 900;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50% !important;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 20px;
    line-height: 40px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: background 160ms ease;
    -webkit-appearance: none;
  }

  .toc-toggle:hover,
  .toc-toggle:focus {
    background: rgba(0, 0, 0, 0.75);
  }

  .book.color-theme-2 .toc-toggle {
    background: rgba(255, 255, 255, 0.2);
  }

  .book.color-theme-2 .toc-toggle:hover,
  .book.color-theme-2 .toc-toggle:focus {
    background: rgba(255, 255, 255, 0.35);
  }
}
