/* 移动端阅读适配层：把原站 980px 固定宽度改为流式 */
html, body {
  width: auto !important;
  min-width: 0 !important;
  max-width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  font-size: 17px;
  line-height: 1.68;
  -webkit-text-size-adjust: 100%;
}

.nonumber_header, .section, .footer, .left_footer, .right_footer {
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding-left: 14px !important;
  padding-right: 14px !important;
}

.section { margin-bottom: 40px !important; }

/* 侧栏/边注改为流式插入正文 */
#toc, .marginnote, .marginequation {
  position: static !important;
  left: auto !important;
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

#toc {
  padding: 10px 14px 0 14px !important;
  border-bottom: 1px solid #e2ddd2;
  margin-bottom: 18px;
}

.marginnote, .marginequation {
  display: block;
  margin: 14px 0 !important;
  padding: 8px 12px !important;
  border-left: 3px solid #d9d2c2;
  background: #faf7ee;
  font-size: 0.9em !important;
  line-height: 1.55;
}

img, video, svg, table, pre, div.highlight {
  max-width: 100% !important;
  height: auto !important;
  box-sizing: border-box !important;
}

pre, div.highlight {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  font-size: 12.5px !important;
}

tt { font-size: 14px !important; }

/* 公式过宽时允许横向滚动，不撑破版面 */
.MathJax_Display, .MathJax_SVG_Display, .MathJax_CHTML_Display {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  max-width: 100% !important;
}

table { display: block; overflow-x: auto; }

h1.nonumber_header { font-size: 1.7em !important; line-height: 1.25; }
h2 { font-size: 1.38em !important; text-align: left !important; }
h3 { font-size: 1.16em !important; }
p { max-width: 100%; }

/* 交互式示例画布 */
canvas { max-width: 100% !important; }

/* 头部标题：原站 nowrap + 绝对定位导致溢出 */
.header, .nonumber_header {
  height: auto !important;
  min-height: 0 !important;
  padding: 14px 0 !important;
}
.header h1, .nonumber_header h1, h1 {
  position: static !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  white-space: normal !important;
  font-size: 1.5rem !important;
  line-height: 1.3 !important;
  padding: 0 14px !important;
  word-break: break-word;
}
h1.chapter_number { font-size: 1.15rem !important; margin-top: 0 !important; }

/* MathJax 2 的宽公式与超宽内联元素兜底 */
span.MathJax_FullWidth, .MathJax_Display {
  display: block !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
}
.section, .nonumber_header { overflow-x: hidden !important; }
a { overflow-wrap: anywhere; }
svg { max-width: 100% !important; height: auto !important; }

/* 折叠目录 */
#toc { padding: 0 !important; border-bottom: none !important; margin: 0 !important; }
.tocwrap { border: 1px solid #d9d2c2; background: #faf7ee; margin: 12px 14px; border-radius: 6px; }
.tocwrap summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  color: #2A6EA6;
}
.tocwrap summary::-webkit-details-marker { display: none; }
.tocwrap > *:not(summary) { padding: 0 14px 10px 14px; }

/* 头部书名 h2 */
.nonumber_header h2, .header h2 {
  position: static !important;
  white-space: normal !important;
  text-align: left !important;
  font-size: 1rem !important;
  line-height: 1.3 !important;
  padding: 0 14px !important;
  margin: 0 !important;
  word-break: break-word;
}

/* 章节标题强制换行 */
.section h2, .section h3, .section h4,
.section h2 a, .section h3 a {
  white-space: normal !important;
  word-break: break-word;
}
.section h2, .section h3 {
  text-align: left !important;
  margin-left: 0 !important;
  padding-left: 0 !important;
}

/* 最终兜底：禁止页面级横向滚动（公式容器内部可横向滚动） */
html, body { overflow-x: hidden !important; max-width: 100vw !important; }

/* 语言切换条（中英共用） */
.langbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px 14px;
  background: #f3efe4;
  border-bottom: 1px solid #e2ddd2;
  font: 14px/1.2 -apple-system, "PingFang SC", "Hiragino Sans GB", sans-serif;
}
.langbar a { color: #2A6EA6; text-decoration: none; }
.langbar strong { color: #3a3226; font-weight: 600; }
.langbar .sep { color: #c4bcab; }

/* pandoc 产出的独立公式容器（中文页） */
.math.display { display: block !important; max-width: 100% !important; }
.math.display .MathJax_Display,
.math.display .MathJax_SVG_Display {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
}
