/* SimpleChem 文稿样式表
 *
 * 这份 CSS 有三个使用者，必须保持"所见即所得"：
 *   1. 编辑器里的排版预览 iframe（通过 /document.css 引用）
 *   2. 导出的独立 HTML 文件（被内联进 <style>）
 *   3. 编辑器画布本身（只借用 .ce-* 区块样式，页面外观由 styles.css 负责）
 *
 * 区块类名统一 ce- 前缀，由 simplechem/blocks.py 生成。
 */

:root {
  --ce-ink: #1f2933;
  --ce-muted: #6b7684;
  --ce-accent: #143d66;
  --ce-line: #c3ccd8;
  --ce-soft: #eef1f5;
  --ce-code-bg: #f4f6f8;
  --ce-danger: #b42b2b;
  --ce-sans: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
    "Source Han Sans SC", "Noto Sans CJK SC", -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  /* 西文走 Times New Roman、汉字回退到宋体一族：这是 ACS / RSC 文献正文的
     标准搭配（西文衬线 + 汉字宋体），也让「Times New Roman」字体选项名副其实。 */
  --ce-serif: "Times New Roman", Times, "Songti SC", "SimSun", "Noto Serif CJK SC",
    "Source Han Serif SC", STSong, serif;
  --ce-mono: "Cascadia Mono", Consolas, "SFMono-Regular", "DejaVu Sans Mono",
    "Courier New", monospace;
}

/* ------------------------------------------------------------ 页面外观 */

/* 纸张尺寸与四边边距不在这里写死：由 simplechem/pagelayout.py 通过
 * render_shell() 注入的 :root 变量提供，唯一真相是文稿的 page 字段。
 * 只单独打开本文件（没有那层注入）时这些变量的值为空 → 退化为无边距。 */

body.simplechem-page {
  margin: 0;
  padding: 26px 14px 40px;
  background: var(--ce-soft);
  font-family: var(--ce-sans);
  color: var(--ce-ink);
  -webkit-text-size-adjust: 100%;
}

.simplechem {
  box-sizing: border-box;
  width: var(--ce-page-w);
  min-height: var(--ce-page-h);
  margin: 0 auto;
  padding: var(--ce-mt) var(--ce-mr) var(--ce-mb) var(--ce-ml);
  background: #fff;
  border: 1px solid #dfe4ea;
  border-radius: 4px;
  box-shadow: 0 6px 22px rgba(20, 61, 102, 0.09);
  /* 五号字（10.5 pt）+ 1.45 倍行距：ACS / RSC 单栏正文的行距在 1.2~1.5 之间，
     10.5 pt 同时对齐 DOCX / PDF 出口的 BODY_SIZE，预览与导出才对得上。 */
  font-size: 10.5pt;
  line-height: 1.45;
}

/* 题名区按期刊首页排版：题名、作者、单位居中，不加分隔线，只靠留白分层。 */
.ce-doc-head {
  margin: 0 0 1.1em;
  text-align: center;
}

.ce-doc-title {
  margin: 0 0 0.3em;
  font-size: 1.55em;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ce-ink);
}

.ce-doc-meta {
  margin: 0;
  font-size: 0.86em;
  color: var(--ce-muted);
}

.ce-doc-body > *:first-child {
  margin-top: 0;
}

/* 分栏：整篇 1 栏 / 2 栏由 --ce-cols 决定（唯一真相在 pagelayout.py，前端只是
   var() 的消费者）。题名区不在 .ce-doc-body 里，所以标题天然横跨整幅。
   屏幕上是连续媒体，两栏会均高分布；分页时的「一页两栏」由浏览器按 @page 版心裁。 */
.ce-doc-body {
  column-count: var(--ce-cols, 1);
  column-gap: var(--ce-col-gap, 8mm);
}

/* ---------------------------------------------------------------- 标题 */

/* 各级标题比正文大半号到一号，段前留白比段后大，行距收到 1.35：
   文献里的层级是靠字号和留白区分的，不靠色块和横线。 */
.ce-h1,
.ce-h2,
.ce-h3,
.ce-h4 {
  font-family: var(--ce-sans);
  font-weight: 700;
  line-height: 1.35;
  color: var(--ce-ink);
  break-after: avoid;
}

.ce-h1 {
  margin: 1.15em 0 0.45em;
  font-size: 1.26em;
}

.ce-h2 {
  margin: 1em 0 0.4em;
  font-size: 1.13em;
}

.ce-h3 {
  margin: 0.9em 0 0.32em;
  font-size: 1.04em;
}

.ce-h4 {
  margin: 0.8em 0 0.28em;
  font-size: 1em;
}

/* ---------------------------------------------------------------- 正文 */

.ce-p {
  margin: 0.3em 0;
  font-family: var(--ce-serif);
  font-size: 1em;
  text-align: justify;
  text-indent: 2em;
  overflow-wrap: anywhere;
}

.ce-p-blank {
  margin: 0.3em 0;
  line-height: 1.45;
}

/* ------------------------------------------------------------ 字体选项 */

/* 与正文默认字体同族：文献正文本来就是「西文 Times New Roman + 汉字宋体」，
   这一项的作用是在整篇改成别的字体后，把某个区块单独按文献正文字体排。 */
.ce-font-times,
.ce-font-times p,
.ce-font-times li {
  font-family: "Times New Roman", Times, "Songti SC", "SimSun", "Noto Serif CJK SC",
    "Source Han Serif SC", STSong, serif;
}

.ce-font-hei,
.ce-font-hei p,
.ce-font-hei li {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
    "Source Han Sans SC", "Noto Sans CJK SC", "Heiti SC", "SimHei", sans-serif;
}

.ce-font-song,
.ce-font-song p,
.ce-font-song li {
  font-family: "Songti SC", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC",
    STSong, serif;
}

.ce-font-kai,
.ce-font-kai p,
.ce-font-kai li {
  font-family: "Kaiti SC", "KaiTi", STKaiti, "Noto Serif CJK SC", "SimSun", serif;
}

.ce-font-fangsong,
.ce-font-fangsong p,
.ce-font-fangsong li {
  font-family: "FangSong", "FangSong_GB2312", STFangsong, "Noto Serif CJK SC",
    "SimSun", serif;
}

.ce-font-mono,
.ce-font-mono p,
.ce-font-mono li {
  font-family: var(--ce-mono);
}

.simplechem sub,
.simplechem sup {
  font-size: 0.72em;
  line-height: 0;
}

.simplechem sub {
  vertical-align: -0.28em;
}

.simplechem sup {
  vertical-align: 0.48em;
}

.simplechem b,
.simplechem strong {
  font-weight: 700;
}

.simplechem i,
.simplechem em {
  font-style: italic;
}

.simplechem code {
  padding: 0.1em 0.32em;
  border-radius: 3px;
  background: var(--ce-code-bg);
  font-family: var(--ce-mono);
  font-size: 0.88em;
}

.simplechem a {
  color: #0b57d0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* -------------------------------------------------------------- 反应式 */

.ce-reaction {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.1em;
  margin: 0.85em 0;
  padding: 0.45em 0.2em;
  font-family: var(--ce-serif);
  font-size: 1.05em;
  line-height: 1.45;
  break-inside: avoid;
  overflow-x: auto;
}

.ce-side {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.06em;
}

.ce-species {
  white-space: nowrap;
}

.ce-plus {
  padding: 0 0.06em;
  color: var(--ce-muted);
  font-weight: 600;
}

.ce-arrowbox {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 4.4em;
  margin: 0.1em 0.7em;
  line-height: 1.3;
  text-align: center;
}

.ce-above,
.ce-below {
  font-size: 0.74em;
  line-height: 1.25;
  color: var(--ce-muted);
  white-space: nowrap;
}

.ce-arrow {
  font-size: 1.2em;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ce-note {
  flex-basis: 100%;
  margin-top: 0.35em;
  font-size: 0.82em;
  color: var(--ce-muted);
  text-align: center;
}

/* ------------------------------------------------------------ 结构式图 */

.ce-figure {
  margin: 0.9em 0 1em;
  text-align: center;
  break-inside: avoid;
}

.ce-figure figcaption {
  margin-top: 0.4em;
  font-size: 0.84em;
  color: var(--ce-muted);
  text-indent: 0;
}

.ce-structure-img {
  max-width: 100%;
  height: auto;
  background: #fff;
}

.ce-missing {
  margin: 0.9em 0;
  padding: 0.7em 0.9em;
  border: 1px dashed #e0b4b4;
  border-radius: 4px;
  background: #fdf3f3;
  color: var(--ce-danger);
  font-size: 0.88em;
  text-align: center;
}

/* ---------------------------------------------------------------- 表格 */

.ce-table {
  width: 100%;
  margin: 0.75em 0 0.95em;
  border-collapse: collapse;
  font-family: var(--ce-sans);
  font-size: 0.92em;
  break-inside: avoid;
}

.ce-table caption {
  padding-bottom: 0.35em;
  font-size: 0.88em;
  color: var(--ce-muted);
  text-align: left;
}

.ce-table th,
.ce-table td {
  padding: 0.42em 0.62em;
  border: 1px solid var(--ce-line);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.ce-table th {
  background: #e8eef6;
  font-weight: 700;
  color: var(--ce-accent);
  text-align: center;
}

.ce-table tbody tr:nth-child(even) td {
  background: #fafbfd;
}

.ce-empty-cell {
  color: var(--ce-muted);
  text-align: center;
}

/* ------------------------------------------------------------ 计算区块 */

.ce-calc {
  margin: 0.9em 0 1em;
  padding: 0.75em 0.95em;
  border: 1px solid var(--ce-line);
  border-left: 3px solid var(--ce-accent);
  border-radius: 4px;
  background: #fbfcfe;
  break-inside: avoid;
}

.ce-calc-title {
  margin-bottom: 0.5em;
  font-family: var(--ce-sans);
  font-size: 0.98em;
  font-weight: 700;
  color: var(--ce-accent);
}

.ce-calc-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.22em 0.85em;
  margin: 0 0 0.7em;
  font-size: 0.94em;
}

.ce-calc-summary dt {
  color: var(--ce-muted);
}

.ce-calc-summary dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.ce-calc-table {
  margin: 0.6em 0 0.3em;
  font-size: 0.88em;
}

.ce-calc-error {
  padding: 0.5em 0.7em;
  border-radius: 4px;
  background: #fdf3f3;
  color: var(--ce-danger);
  font-size: 0.9em;
}

.ce-calc-note {
  margin: 0.55em 0 0;
  font-size: 0.82em;
  color: var(--ce-muted);
  text-indent: 0;
}

.ce-calc-figure {
  margin: 0.6em 0 0.3em;
}

/* ---------------------------------------------------------------- 列表 */

.ce-list {
  margin: 0.5em 0 0.8em;
  padding-left: 1.6em;
  font-family: var(--ce-serif);
}

.ce-list li {
  margin: 0.18em 0;
  overflow-wrap: anywhere;
}

.ce-list-ul {
  list-style: disc;
}

.ce-list-ol {
  list-style: decimal;
}

/* ------------------------------------------------------------ 提示框 */

.ce-callout {
  margin: 0.85em 0;
  padding: 0.65em 0.9em;
  border-left: 3px solid var(--ce-accent);
  border-radius: 0 4px 4px 0;
  background: #eaf2fb;
  break-inside: avoid;
}

.ce-callout-title {
  margin-bottom: 0.28em;
  font-family: var(--ce-sans);
  font-weight: 700;
  color: var(--ce-accent);
}

.ce-callout-body {
  font-family: var(--ce-serif);
  text-indent: 0;
}

.ce-callout-body p {
  margin: 0.3em 0;
}

.ce-callout-info {
  border-left-color: #2f6fb5;
  background: #eaf2fb;
}

.ce-callout-warn {
  border-left-color: #c77700;
  background: #fff7e6;
}

.ce-callout-warn .ce-callout-title {
  color: #8a5300;
}

.ce-callout-tip {
  border-left-color: #1e8a5a;
  background: #e8f6ee;
}

.ce-callout-tip .ce-callout-title {
  color: #166b46;
}

.ce-callout-danger {
  border-left-color: #c0392b;
  background: #fdecec;
}

.ce-callout-danger .ce-callout-title {
  color: #96271b;
}

/* ------------------------------------------------------------ 代码块 */

.ce-code-wrap {
  position: relative;
  margin: 0.8em 0 0.9em;
  border: 1px solid var(--ce-line);
  border-radius: 4px;
  background: var(--ce-code-bg);
  break-inside: avoid;
}

.ce-code-lang {
  padding: 0.28em 0.75em;
  border-bottom: 1px solid #e2e7ee;
  font-family: var(--ce-mono);
  font-size: 0.74em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ce-muted);
}

.ce-code {
  margin: 0;
  padding: 0.75em 0.9em;
  overflow-x: auto;
  font-family: var(--ce-mono);
  font-size: 0.86em;
  line-height: 1.6;
  tab-size: 4;
}

.ce-code code {
  padding: 0;
  background: none;
  font-size: 1em;
  white-space: pre;
}

/* ------------------------------------------------------------ 分隔线 */

.ce-divider {
  margin: 1.2em 0;
  border: 0;
  border-top: 1px solid var(--ce-line);
}

/* --------------------------------------------------------- 窄屏适配 */

@media (max-width: 780px) {
  body.simplechem-page {
    padding: 10px 6px 24px;
  }

  /* 窄屏只缩字号：纸面尺寸与四边边距一律不改（等比缩放由 paginate.js 做），
     否则「边距改了预览也得跟着改」就不成立。 */
  .simplechem {
    font-size: 14px;
    box-shadow: none;
  }

  .ce-calc-summary {
    grid-template-columns: 1fr;
    gap: 0.1em;
  }

  .ce-calc-summary dd {
    margin-bottom: 0.4em;
  }
}
