/* ==========================================================================
 * pc/css/print.css —— A4 打印样式 + 屏幕纸张预览
 *
 * ★★★ 本文件是基线 错题本.html 打印样式的 **1:1 移植**，不要「顺手优化」★★★
 *
 * 这是使用者（父亲）已经用真实打印机验证过的核心资产：页高、分页、双栏、
 * 答案强制另起一页、页眉页脚措辞，都是反复调过的。任何视觉调整都必须先在
 * 打印预览里确认，否则会出现「预览好看、出纸串行」的经典事故。
 *
 * 与基线的唯一差异（已标注）：
 *   1. 基线把打印样式写在 <style> 里、可用 var(--brand) 等变量；本文件独立成文件，
 *      为不依赖 app.css 的加载顺序，颜色一律写成字面值（视觉等价）。
 *   2. 新增 .katex 打印微调（.katex{font-size:1.02em}），防止公式比正文小一截。
 *
 * 对应的分页算法在 shared/sheet.js（四端同一份），本文件只负责「怎么印」。
 * ========================================================================== */

/* 打印区：屏幕隐藏，打印显示（基线 #printArea{display:none}） */
#printArea {
  display: none;
}

/* ==========================================================================
 * 一、打印态（基线 @media print 整段 1:1）
 * ======================================================================== */
@media print {
  @page {
    size: A4;
    margin: 12mm 13mm 10mm 13mm;
  }

  body {
    background: #fff;
  }

  /* 只让打印区可见：其余节点 visibility:hidden，而不是 display:none，
     这样纸张高度计算不受影响（基线做法） */
  body * {
    visibility: hidden;
  }

  #printArea,
  #printArea * {
    visibility: visible;
  }

  #printArea {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }

  .no-print,
  .preview-page-tip {
    display: none !important;
  }

  /* 题目页：固定一页高度，题目按 flex 均分，答题区自动吃掉剩余空间 */
  .sheet-page {
    display: flex;
    flex-direction: column;
    height: calc(297mm - 22mm);
    overflow: hidden;
    border: none;
    padding: 0;
    page-break-after: always;
    break-after: page;
  }

  .sheet-page.last-qpage {
    page-break-after: auto;
    break-after: auto;
  }

  .q-block {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    margin-bottom: 7px;
  }

  .q-block .write {
    flex: 1 1 auto;
    min-height: 26px;
  }

  .q-block .wline.tall {
    flex: 1 1 auto;
    height: auto;
    min-height: 26px;
  }

  .q-block .wline {
    flex: 0 0 22px;
    height: 22px;
  }

  /* 横向：页高变 210mm，改为双栏 */
  body.orient-land .sheet-page {
    height: calc(210mm - 22mm);
  }

  body.orient-land .sheet-cols {
    flex-direction: row;
    gap: 10px;
  }

  body.orient-land .q-block {
    margin-bottom: 0;
  }

  body.orient-land .answer-block {
    break-inside: avoid;
  }

  /* 答案页：强制另起一页 */
  .ans-page {
    page-break-before: always;
    break-before: page;
  }

  body.orient-land .ans-page .ans-body {
    column-count: 2;
    column-gap: 14px;
  }
}

/* ==========================================================================
 * 二、屏幕预览：模拟 A4 纸张（基线 109-131 行 1:1）
 * ======================================================================== */
.print-preview {
  overflow-x: auto;
}

.sheet-page {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: none;
  padding: 0;
  margin: 0 auto 18px;
  max-width: 184mm;
  height: calc(297mm - 22mm);
  overflow: hidden;
}

.sheet-page .q-block {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
}

.sheet-page .q-block .write {
  flex: 1 1 auto;
  min-height: 26px;
}

.sheet-page .q-block .wline.tall {
  flex: 1 1 auto;
  height: auto;
  min-height: 26px;
}

.sheet-page .q-block .wline {
  flex: 0 0 22px;
  height: 22px;
}

/* 题目区容器：纵向=单列，横向=双列 */
.sheet-cols {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.sheet-col {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
}

.sheet-col > .q-block + .q-block {
  margin-top: 7px;
}

body.orient-land .sheet-page {
  max-width: 271mm;
  height: calc(210mm - 22mm);
}

body.orient-land .sheet-cols {
  flex-direction: row;
  gap: 10px;
}

body.orient-land .q-block {
  margin-bottom: 0;
}

body.orient-land .ans-page {
  max-width: 271mm;
}

body.orient-land .ans-page .ans-body {
  column-count: 2;
  column-gap: 14px;
}

.preview-page-tip {
  text-align: center;
  font-size: 12px;
  color: #a08e6a;
  margin: 0 0 18px;
}

/* 横向纸张在屏幕上整体缩放，便于一屏看完（不影响打印） */
@media screen {
  body.orient-land .print-preview {
    zoom: .72;
  }
}

/* 答案页在预览中也显示为一张纸（宽度/边距与题目页一致） */
.ans-page {
  background: #fff;
  max-width: 184mm;
  margin: 0 auto;
  border-top: 2px dashed #d8d2c4;
  padding-top: 10px;
}

@media print {
  .ans-page {
    border-top: none;
    margin: 0;
    padding-top: 0;
    max-width: none;
  }
}

/* ==========================================================================
 * 三、纸张内部元素（基线 132-167 行 1:1）
 * ======================================================================== */
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 2px solid #2b2b2b;
  padding-bottom: 8px;
  margin-bottom: 6px;
}

.sheet-title {
  font-size: 18px;
  font-weight: 800;
  font-family: "KaiTi", "STKaiti", serif;
}

.sheet-info {
  font-size: 12.5px;
  color: #444;
  text-align: right;
  line-height: 1.5;
}

.sheet-sub {
  font-size: 11.5px;
  color: #888;
  margin: 2px 0 14px;
}

.q-block {
  border: 1px solid #cfc9bb;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 13px;
  page-break-inside: avoid;
  background: #fffdf8;
}

.q-block .qno {
  font-weight: 800;
  color: #3b6ea5;   /* 基线为 var(--brand) */
  margin-right: 6px;
}

.q-block .kp {
  float: right;
  font-size: 11px;
  color: #a8542c;
  background: #fbeede;
  padding: 1px 8px;
  border-radius: 999px;
}

.q-block .stem {
  margin: 6px 0 0;
  white-space: pre-wrap;
  font-size: 14px;
}

.q-block .write {
  margin-top: 10px;
  border-top: 1px dashed #d8d2c4;
  padding-top: 6px;
}

.q-block .wline {
  height: 26px;
  border-bottom: 1px solid #e6e0d2;
}

.q-block .wline.tall {
  height: 64px;
}

.answer-block {
  border: 1px solid #cfc9bb;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 11px;
  page-break-inside: avoid;
  background: #fbfdfb;
}

.answer-block .qno {
  font-weight: 800;
  color: #3f8f6b;   /* 基线为 var(--ok) */
  margin-right: 6px;
}

.answer-block .ans {
  white-space: pre-wrap;
  font-size: 13.5px;
  margin-top: 4px;
}

.section-title {
  font-size: 14px;
  font-weight: 800;
  margin: 18px 0 8px;
  color: #2b2b2b;
  border-left: 4px solid #3b6ea5;   /* 基线为 var(--brand) */
  padding-left: 8px;
}

.footer-note {
  text-align: center;
  font-size: 12px;
  color: #aaa;
  margin-top: 8px;
}

/* ---------- 答案页强制分页（基线 .page-break） ---------- */
.page-break {
  page-break-before: always;
  break-before: page;
  border-top: 2px dashed #d8d2c4;
  margin: 16px 0 14px;
  padding-top: 10px;
}

.page-break::before {
  content: "📄 以下为参考答案，打印时强制另起一页";
  display: block;
  font-size: 12px;
  color: #a08e6a;
  margin-bottom: 10px;
}

@media print {
  .page-break {
    border-top: none;
    margin: 0;
    padding-top: 0;
    break-before: page;
    page-break-before: always;
  }

  .page-break::before {
    display: none;
  }
}

/* ==========================================================================
 * 四、PC 端新增（基线无，仅打印微调）
 * ======================================================================== */

/* 公式与正文的视觉字号对齐：KaTeX 默认 1.21em 行高在 14px 正文里偏小 */
.katex {
  font-size: 1.02em;
}

/* 打印时不要给纸张加圆角阴影（屏幕预览有，打印不需要） */
@media print {
  .q-block,
  .answer-block {
    border-radius: 6px;
  }
}
