/* 画布样式：前端预览与服务端出图共用这一份，两份文件必须逐字节相同。
   app/static/css/canvas.css 是本文件的副本，启动时断言哈希一致。
   见 PRD/07-business-logic.md 7.1 业务规则 2、docs/spec.md 5.2。

   颜色与字号取自 DESIGN.md 的 canvas-* 族。画布内不使用外壳的 chrome-* token，
   画布上也不出现任何界面装饰（描边、阴影、角标），用户看到的就是图里有的。

   三个 CSS 变量由注入方给出：
     --changtu-canvas-width   画布宽，锁死 690
     --changtu-padding-y      上下内边距，默认 36（参数面板可改）
     --changtu-padding-x      左右内边距，固定 40
     --changtu-font-family    正文字族，前后端同一份字体 */

#card,
#card * {
  box-sizing: border-box;
}

#card {
  width: var(--changtu-canvas-width, 690px);
  max-width: var(--changtu-canvas-width, 690px);
  margin: 0;
  padding: var(--changtu-padding-y, 36px) var(--changtu-padding-x, 40px);
  background-color: #ffffff; /* colors.canvas-bg */
  color: #1a1c1f; /* colors.canvas-text，白底约 17:1，余量留给平台二次压缩 */
  font-family: var(--changtu-font-family, "Source Han Sans SC"), sans-serif;
  /* 正文基准字号，由 CHANGTU_BODY_FONT_SIZE 注入。
     690 宽的长图在手机上是按屏宽缩小显示的（690 -> 390 CSS px），
     它的取值同时影响两件事：字在图里占的比例（越大、放大看越清楚），
     以及整张图的高度（越大越容易碰到 65500/scale 的逻辑高度上限）。
     标题阶梯用 em 写成相对值，改基准时整条阶梯跟着缩放。 */
  font-size: var(--changtu-font-size, 16px);
  font-weight: 400;
  line-height: 1.75;
  text-align: left;
  overflow-wrap: normal;
  word-break: normal;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 段落：段距 12px（栅格 md）。段内的行高由 #card 的 1.75 决定 */
#card p {
  margin: 0 0 12px;
}

/* 真正空的段落（没有 <br> 也没有文字）也要占一行，否则前后端高度会差一行。
   零宽空格只用来撑出行盒，不显示任何东西。 */
#card p:empty::before,
#card li:empty::before,
#card blockquote:empty::before {
  content: "\200B";
}

/* 标题阶梯：相对正文字号的 1.75 / 1.5 / 1.25 / 1.125 倍
   （正文 16px 时对应 DESIGN.md 的 28 / 24 / 20 / 18） */
#card h1 {
  margin: 24px 0 12px;
  font-size: 1.75em;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

#card h2 {
  margin: 24px 0 12px;
  font-size: 1.5em;
  font-weight: 700;
  line-height: 1.4;
}

#card h3 {
  margin: 16px 0 8px;
  font-size: 1.25em;
  font-weight: 600;
  line-height: 1.45;
}

#card h4 {
  margin: 16px 0 8px;
  font-size: 1.125em;
  font-weight: 600;
  line-height: 1.5;
}

#card h1:first-child,
#card h2:first-child,
#card h3:first-child,
#card h4:first-child,
#card p:first-child {
  margin-top: 0;
}

/* 引用块：左侧 3px 竖线（canvas-quote-rule）加 16px 缩进 */
#card blockquote {
  margin: 12px 0;
  padding: 0 0 0 16px;
  border-left: 3px solid #d0d4d9; /* colors.canvas-quote-bar */
  color: #3e444c; /* colors.canvas-quote-text */
  font-size: 16px;
  line-height: 1.75;
}

#card blockquote p:last-child {
  margin-bottom: 0;
}

/* 单元格与引用块里的末段不留额外段距，否则表格底部会多出一道空白 */
#card td > p:last-child,
#card th > p:last-child,
#card li > p:last-child {
  margin-bottom: 0;
}

/* 表格：边框由 canvas.css 统一给，导入的单元格自带 border-* 会覆盖到具体边上 */
#card table {
  width: 100%;
  margin: 12px 0;
  border-collapse: collapse;
  font-size: 15px; /* typography.canvas-body-compact，只用于表格单元格 */
  line-height: 1.7;
}

#card th,
#card td {
  padding: 6px 10px; /* components.canvas-table-cell */
  border: 1px solid #c9cdd2; /* colors.canvas-border */
  text-align: left;
  vertical-align: top;
}

#card th {
  font-weight: 700;
}

/* 列表：19px 缩进位留给标记，marker 不越出画布 */
#card ul,
#card ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

#card li {
  margin: 0 0 4px;
}

#card li > ul,
#card li > ol {
  margin: 4px 0 0;
}

#card ul ul,
#card ol ol,
#card ul ol,
#card ol ul {
  margin-bottom: 0;
}

/* 图片：只接受内嵌 data URI，宽度不超出内容区 */
#card img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

#card hr {
  margin: 20px 0;
  border: 0;
  border-top: 1px solid #c9cdd2; /* colors.canvas-border */
}

/* 等宽场景：V1 的编辑器不产出 code/pre，但导入路径与清洗白名单会带来它们 */
#card code,
#card pre {
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

#card code {
  padding: 1px 4px;
  border-radius: 4px; /* rounded.sm */
  background-color: #edeff1; /* colors.chrome-surface-sunken，画布内的代码底色 */
  font-size: 0.92em;
}

#card pre {
  margin: 12px 0;
  padding: 12px;
  border-radius: 4px;
  background-color: #edeff1;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

#card pre code {
  padding: 0;
  background-color: transparent;
  font-size: inherit;
}
