/* 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;
  --ce-serif: "Songti SC", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC",
    Georgia, "Times New Roman", serif;
  --ce-mono: "Cascadia Mono", Consolas, "SFMono-Regular", "DejaVu Sans Mono",
    "Courier New", monospace;
}

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

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: 100%;
  max-width: 21cm;
  min-height: 24cm;
  margin: 0 auto;
  padding: 2cm 2.1cm 2.4cm;
  background: #fff;
  border: 1px solid #dfe4ea;
  border-radius: 4px;
  box-shadow: 0 6px 22px rgba(20, 61, 102, 0.09);
  font-size: 15px;
  line-height: 1.78;
}

.ce-doc-head {
  margin: 0 0 1.3em;
  padding-bottom: 0.7em;
  border-bottom: 1px solid var(--ce-line);
  text-align: center;
}

.ce-doc-title {
  margin: 0 0 0.25em;
  font-size: 1.72em;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ce-accent);
  letter-spacing: 0.01em;
}

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

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

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

.ce-h1,
.ce-h2,
.ce-h3,
.ce-h4 {
  font-family: var(--ce-sans);
  font-weight: 700;
  line-height: 1.4;
  color: var(--ce-accent);
  break-after: avoid;
}

.ce-h1 {
  margin: 1.5em 0 0.6em;
  padding-bottom: 0.22em;
  font-size: 1.5em;
  border-bottom: 1px solid #dbe2ea;
}

.ce-h2 {
  margin: 1.35em 0 0.55em;
  font-size: 1.26em;
}

.ce-h3 {
  margin: 1.2em 0 0.5em;
  font-size: 1.12em;
}

.ce-h4 {
  margin: 1.05em 0 0.45em;
  font-size: 1em;
  color: #24507d;
}

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

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

.ce-p-blank {
  margin: 0.55em 0;
  line-height: 1.4;
}

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

.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: 1em 0;
  padding: 0.55em 0.2em;
  font-family: var(--ce-serif);
  font-size: 1.05em;
  line-height: 1.5;
  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: 1em 0 1.15em;
  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.85em 0 1.1em;
  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: 1em 0 1.2em;
  padding: 0.85em 1em;
  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.6em 0 0.9em;
  padding-left: 1.6em;
  font-family: var(--ce-serif);
}

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

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

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

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

.ce-callout {
  margin: 1em 0;
  padding: 0.7em 0.95em;
  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.85em 0 1em;
  border: 1px solid var(--ce-line);
  border-radius: 4px;
  background: var(--ce-code-bg);
}

.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.4em 0;
  border: 0;
  border-top: 1px solid var(--ce-line);
}

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

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

  .simplechem {
    padding: 1.1cm 0.9cm 1.4cm;
    font-size: 14px;
    box-shadow: none;
  }

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

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