/* 公式渲染（配合 public/js/math.js 使用，纯 CSS，无外部字体依赖） */

.m-inline, .m-block {
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", "Times New Roman", "Segoe UI Symbol", var(--font);
  font-variant-ligatures: none;
  letter-spacing: 0;
}
.m-inline { display: inline; }

/* 行内公式整体不折行。
   正文是中文，几乎每个字之间都能断行，于是浏览器会把 `½mv₀²` 这种连写的项
   从中间拆开（截图里就是 `½` 留在上一行末尾、`mv₀²` 跑到下一行）。
   数学里一个项拆开就读不通了，所以按 KaTeX / MathJax 的老规矩让整段公式原子化：
   换行只发生在公式前后。代价是长公式会把整段挤到下一行，多占一行——
   比拆开一个项强。$$...$$ 的显示模式本来就是独占一块，不受这条影响。 */
.m-inline { white-space: nowrap; }
/* 一行塞不下的长公式退回可折行，免得溢出到卡片外面 */
.m-inline.m-inline-long { white-space: normal; }
.m-block {
  display: block;
  margin: 8px 0;
  padding: 2px 0;
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
}
.m-inline sup, .m-inline sub,
.m-block sup, .m-block sub { font-size: 0.72em; line-height: 0; }

.m-grp { display: inline; }

/* 分式 */
.m-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.16em;
  line-height: 1.22;
}
.m-frac > .m-num {
  display: block;
  padding: 0 0.3em 0.06em;
  border-bottom: 1px solid currentColor;
  text-align: center;
}
.m-frac > .m-den { display: block; padding: 0.06em 0.3em 0; text-align: center; }
.m-frac.m-tfrac { font-size: 0.86em; }
.m-frac.m-binom { margin: 0; }

/* 行内分式按 LaTeX 的行内样式（textstyle）缩小一号，再用负 margin 把它的
   margin-box 压回正文高度。
   为什么非要压：浏览器算行框高度看的是元素的 margin-box，而行内分式比正文高
   一倍多（14px 正文、36px 分式），一段中文里只要夹一个 ½，那一行的行距就从
   19px 跳到 37px，整段看着全是缝。负 margin 让它在行框里"少占地方"，内容溢出
   的那一点画在行间空隙里，读起来反而更接近正规排版。
   $$...$$ 的显示模式（.m-block）不走这条规则，那里就该用大号的。 */
.m-inline > .m-frac {
  font-size: 0.88em;
  margin: -0.26em 0.14em;
}
.m-inline > .m-frac > .m-num { padding: 0 0.28em 0.05em; }
.m-inline > .m-frac > .m-den { padding: 0.05em 0.28em 0; }

/* 根式：符号由 SVG 折线画，横线由伪元素画。
   不再依赖字体里的 √ 字形，所以横线一定和斜边顶部对齐，被开方数变高也能拉伸。 */
.m-sqrt {
  position: relative;
  display: inline-block;
  padding-left: 0.62em;
  vertical-align: baseline;
  line-height: 1.25;
}
.m-sqrt > .m-rad {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0.62em;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.m-sqrt::before {
  content: "";
  position: absolute;
  left: 0.56em;
  right: 0;
  top: 0;
  height: 1px;
  background: currentColor;
}
.m-sqrt > .m-radicand {
  display: inline-block;
  padding: 0.2em 0.06em 0 0;
  line-height: 1.25;
}
.m-sqrt > .m-root-idx {
  position: absolute;
  left: -0.02em;
  top: 0;
  font-size: 0.62em;
  line-height: 1;
  padding-right: 0.08em;
}

/* 同时带上标下标 */
.m-ss { display: inline-flex; align-items: baseline; }
.m-ss > .m-ss-b { display: inline-block; }
.m-ss > .m-ss-s {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: 0.7em;
  line-height: 0.98;
  margin-left: 0.05em;
  /* 往上一提，让下标刚好压在基线下方，不再把整行撑开 */
  position: relative;
  top: -0.62em;
}

/* 求和、积分、lim 等上下限 */
.m-lim { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 0.14em; }
.m-lim > .m-lim-up, .m-lim > .m-lim-dn { font-size: 0.7em; line-height: 1.15; }
.m-lim > .m-lim-mid { font-size: 1.3em; line-height: 1.05; }

/* 符号 */
.m-opx { font-size: 1.24em; line-height: 1; vertical-align: -0.06em; margin: 0 0.06em; }
.m-sym { margin: 0 0.08em; }
/* 关系符前后留白更宽，算式才看得清 */
.m-rel { margin: 0 0.26em; }
.m-bin { margin: 0 0.18em; }
.m-punct { margin-right: 0.12em; }

/* 括号 */
.m-fence { display: inline-flex; align-items: stretch; vertical-align: middle; }
.m-fence > .m-fence-c { display: inline-block; padding: 0 0.06em; }
.m-fence > .m-fence-l, .m-fence > .m-fence-r {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  font-size: 1.15em;
}
/* 大括号：矢量绘制，随内容高度拉伸 */
.m-fence.big {
  display: inline-block;
  position: relative;
  padding: 0 0.44em;
  vertical-align: baseline;
}
.m-fence.big.no-l { padding-left: 0.06em; }
.m-fence.big.no-r { padding-right: 0.06em; }
.m-fence.big > .m-fence-l,
.m-fence.big > .m-fence-r {
  position: absolute;
  top: -0.02em;
  bottom: -0.02em;
  width: 0.42em;
  display: block;
  line-height: 1;
  overflow: visible;
  pointer-events: none;
}
.m-fence.big > .m-fence-l { left: 0; }
.m-fence.big > .m-fence-r { right: 0; }
.m-fence.big > .m-fence-l > svg,
.m-fence.big > .m-fence-r > svg {
  display: block;
  width: 100%;
  height: 100%;
}
.m-fence.big > .m-fence-c { display: inline-block; vertical-align: baseline; }
.m-fence-mid { display: inline-flex; align-items: center; font-size: 1.6em; line-height: 1; }

/* 矩阵、方程组 */
.m-matrix { display: inline-flex; flex-direction: column; gap: 0.16em; }
.m-mrow { display: flex; align-items: baseline; }
.m-mcell { padding: 0 0.34em; text-align: center; }
.m-mcell.r { text-align: right; }
.m-mcell.l { text-align: left; }

/* 文字与字体 */
.m-text { font-family: var(--font); }
.m-rm { font-style: normal; }
.m-it { font-style: italic; }
.m-bf { font-weight: 700; }
.m-bb { font-family: "Cambria Math", "Times New Roman", serif; }
.m-tt { font-family: var(--mono); }
.m-fn { font-family: var(--font); font-style: normal; padding-right: 0.1em; }
.m-var { font-style: italic; }
.m-unknown { color: var(--danger); font-family: var(--font); }

/* 上划线、箭头、点 */
.m-ovl { display: inline-block; border-top: 1px solid currentColor; padding-top: 0.04em; }
.m-unl { display: inline-block; border-bottom: 1px solid currentColor; padding-bottom: 0.02em; }
.m-vec, .m-vec2, .m-hat, .m-tilde, .m-dot, .m-ddot { position: relative; display: inline-block; padding-top: 0.34em; }
.m-vec::before, .m-vec2::before, .m-hat::before, .m-tilde::before,
.m-dot::before, .m-ddot::before {
  position: absolute;
  top: -0.06em;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.8em;
  line-height: 1;
}
/* 矢量箭头用线 + 三角画，长度自动跟字母数量对齐，不用 → 字形（字形长度固定，两个字母就盖不住） */
.m-vec::before, .m-vec2::before {
  content: "";
  position: absolute;
  left: -0.02em;
  right: 0.16em;
  top: 0.13em;
  height: 1px;
  background: currentColor;
  font-size: inherit;
}
.m-vec::after, .m-vec2::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0.06em;
  width: 0;
  height: 0;
  border-left: 0.2em solid currentColor;
  border-top: 0.08em solid transparent;
  border-bottom: 0.08em solid transparent;
}
.m-hat::before { content: "^"; }
.m-tilde::before { content: "~"; }
.m-dot::before { content: "\00b7"; }
.m-ddot::before { content: "\00a8"; }
.m-cancel { text-decoration: line-through; }

/* 叠放（overset / xrightarrow） */
.m-over { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; }
.m-over > .m-over-top { font-size: 0.7em; line-height: 1.1; }
.m-over > .m-over-base { line-height: 1.1; }

/* 化学式 */
.m-ce { white-space: normal; }
.m-ce-arrow { margin: 0 0.12em; font-size: 1.1em; }

/* 间距 */
.m-sp { display: inline-block; width: 0.16em; }
.m-sp2 { display: inline-block; width: 0.3em; }
.m-sp3 { display: inline-block; width: 0.6em; }
.m-spn { display: inline-block; margin-left: -0.1em; }
.m-q { display: inline-block; width: 1em; }
.m-q2 { display: inline-block; width: 2em; }

/* ===== 表格 =====
   题干里的实验数据表、对照表（对照组/实验组、正常/异常）都走这里。
   外框用 div 包一层，窄屏上左右滚动，不把整页撑宽。 */
.m-table-wrap {
  display: block;
  margin: 10px 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: normal;
  line-height: 1.55;
}
.m-table-cap {
  margin-bottom: 5px;
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: center;
  white-space: normal;
}

.m-table {
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  background: transparent;
  max-width: 100%;
}
.m-table th,
.m-table td {
  padding: 5px 11px;
  white-space: normal;
  word-break: break-word;
  vertical-align: middle;
  /* 单元格里默认允许公式，行高按内容走 */
  line-height: 1.6;
}
.m-table th {
  color: var(--text-strong);
  font-weight: var(--strong-weight, 560);
  background: var(--bg-hover);
  white-space: nowrap;
}
.m-table th:only-child { white-space: normal; }

/* 只有横线（Markdown 竖线表、tabular 没写竖线） */
.m-table.rule th,
.m-table.rule td {
  border: 0;
  border-bottom: 1px solid var(--divider);
}
.m-table.rule tr:last-child td { border-bottom: 0; }
.m-table.rule thead th { border-bottom: 1px solid var(--border-strong); }

/* 有竖线（列定义里写了 |） */
.m-table.grid th,
.m-table.grid td {
  border: 1px solid var(--border-strong);
}
.m-table.grid { border: 1px solid var(--border-strong); }
.m-table.grid th { border-color: var(--border-strong); }

/* \hline 出现在这一行前面时，这一行顶上补一条更明显的线 */
.m-table tr.rule-top > * { border-top: 1px solid var(--border-strong); }

/* 单元格里的公式别把行高撑开太多 */
.m-table .m-block { margin: 2px 0; padding: 0; text-align: inherit; }
.m-table .m-frac { font-size: 0.94em; }

/* 手机上表格要能读：字号略小、内边距收紧 */
@media (max-width: 820px) {
  .m-table { font-size: 12.5px; }
  .m-table th,
  .m-table td { padding: 4px 8px; }
}
