:root {
  --blue: #2e75b6;
  --dblue: #1f4e79;
  --gray: #7f7f7f;
  --line: #d7dee8;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #262626;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: linear-gradient(120deg, #1f4e79, #2e75b6);
  color: #fff;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 1px; }
.topbar .sub { margin: 4px 0 0; font-size: 13px; opacity: .85; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.topbar-actions .btn { white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .22);
}
.topbar-actions { display: flex; gap: 8px; }

.steps {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.steps button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--dblue);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}
.steps button.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 600;
}

main { padding: 20px 24px 60px; max-width: 1080px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.panel h2 { margin: 4px 0 6px; font-size: 18px; color: var(--dblue); }
.hint { color: var(--gray); font-size: 13px; margin: 0 0 14px; }

.btn {
  border: 1px solid var(--blue);
  background: #fff;
  color: var(--blue);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--blue); color: #fff; font-weight: 600; }
.btn.ghost { border-color: var(--line); color: #445; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.actions { display: flex; align-items: center; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.count { color: var(--gray); font-size: 13px; }
.step-nav {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 20px; padding-top: 14px; border-top: 1px dashed var(--line);
}

.dropzone {
  display: block;
  border: 2px dashed #b9c6d8;
  border-radius: 12px;
  background: #fff;
  padding: 34px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--blue); background: #eef4fb; }
.dz-icon { font-size: 34px; }
.dz-small { color: var(--gray); font-size: 12.5px; margin-top: 6px; }

.file-list { list-style: none; margin: 14px 0 0; padding: 0; }
.file-list li {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 6px; font-size: 13.5px;
}
.file-list .status { font-size: 12px; color: var(--gray); }
.file-list .status.err { color: #c0392b; }

.progress { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--dblue); }
.spinner {
  width: 18px; height: 18px; border: 3px solid #cfe0f0;
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.raw-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.raw-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--dblue); font-weight: 600;
}
.raw-head > div { display: flex; gap: 8px; }
#ocr-raw {
  width: 100%; min-height: 220px; border: 0; outline: none;
  padding: 12px; font-size: 14px; line-height: 1.7; resize: vertical;
  font-family: inherit;
}

.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px;
}
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.qnum {
  min-width: 52px; text-align: center; font-weight: 700; color: #fff;
  background: var(--blue); border-radius: 6px; padding: 4px 8px; font-size: 13px;
}
.card-head input.qnum-input {
  width: 64px; text-align: center; font-weight: 700; color: var(--dblue);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 13px;
}
.card-head .spacer { flex: 1; }
.card textarea {
  width: 100%; min-height: 64px; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; font-size: 14px; line-height: 1.6; font-family: inherit; resize: vertical;
}
.card .tools { display: flex; gap: 6px; }
.card .tools button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer; color: #445;
}
.card .tools button:hover { border-color: var(--blue); color: var(--blue); }
.card.wrong { border-color: var(--blue); box-shadow: 0 0 0 2px #e6f0fa; }

.items-mini { margin-top: 14px; }
.items-mini h3 { font-size: 14px; color: var(--dblue); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 6px 6px 0;
  background: #eef4fb; border: 1px solid #cfe0f0; color: var(--dblue);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
}
.chip button { border: 0; background: none; color: #99a; cursor: pointer; font-size: 13px; }

.item-list { display: flex; flex-direction: column; gap: 12px; }
.item {
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px;
}
.item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.item-head .qnum { background: var(--dblue); }
.item-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #445; }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 14px;
  font-family: inherit;
}
.field textarea { min-height: 60px; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 2px; }
.checks label { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; }

.tpl-controls {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px;
}
.tpl-controls label { font-size: 13.5px; color: #445; display: flex; align-items: center; gap: 8px; }
.tpl-controls select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 14px; }
.mapping { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 10px; font-size: 13px; color: #445; }
.mapping span { display: inline-flex; align-items: center; gap: 6px; }
.mapping select { border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 13px; }

.preview {
  margin-top: 16px; display: flex; flex-direction: column; gap: 18px; align-items: flex-start;
  overflow-x: auto; width: 100%;
}
.preview-summary {
  margin-top: 12px; font-size: 13px; color: var(--dblue);
  background: #eef4fb; border: 1px solid #cfe0f0; border-radius: 8px; padding: 8px 12px;
}
body.exporting .preview { gap: 0; zoom: 1 !important; }
body.exporting #preview { width: 210mm; }
body.exporting .page { box-shadow: none; page-break-after: auto; break-after: auto; margin: 0; }
.empty { color: var(--gray); padding: 40px; text-align: center; }

/* ============ A4 页面 ============ */
.page {
  width: 210mm; height: 297mm; background: #fff; padding: 9mm 10mm;
  box-shadow: 0 2px 14px rgba(20, 40, 80, .14);
  position: relative; overflow: hidden;
  page-break-after: always; break-after: page;
}
.page:last-child { page-break-after: auto; break-after: auto; }
.page-mark {
  position: absolute; top: 3mm; right: 5mm;
  font-size: 9px; color: #9aa7b8; letter-spacing: .3px;
  z-index: 2;
}

.tplA-title {
  text-align: center; color: #1a1a1a; font-size: 30px; letter-spacing: 10px;
  margin: 6px 0 14px; font-weight: 800;
}
.tplA { width: 100%; border-collapse: collapse; table-layout: fixed; }
.tplA th, .tplA td {
  border: 1px solid #286df8; padding: 7px 9px; vertical-align: top;
  font-size: 12.5px; line-height: 1.55; word-break: break-word;
}
.tplA th {
  width: 19%; background: #f2f7ff; color: #1f4e79; font-weight: 700;
  text-align: center; white-space: nowrap;
}
.tplA td.write { height: 34px; }
.tplA td .blank { display: block; height: 30px; }
.tplA .checks { flex-wrap: wrap; gap: 2px 10px; }
.tplA .checks label { font-size: 12px; }
.page.fill-page { display: flex; flex-direction: column; }
.tplA { flex: 1; height: 100%; }
.tplA tr.r-stem td { height: 40mm; }
.tplA tr.r-analysis td { height: 30mm; }
.tplA tr.r-knowledge td { height: 22mm; }
.tplA tr.r-answer td { height: 55mm; }
.tplA tr.r-summary td { height: 32mm; }

.tplB-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 2px solid #2e75b6; padding-bottom: 8px; margin-bottom: 10px;
}
.tplB-head .t { color: #1f4e79; font-weight: 700; font-size: 15px; }
.tplB-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tplB-tags span {
  border: 1px solid #2e75b6; color: #2e75b6; border-radius: 999px;
  padding: 2px 10px; font-size: 11.5px;
}
.tplB-tags span.on { background: #2e75b6; color: #fff; }
.tplB-sec { margin-top: 10px; }
.tplB-label {
  display: inline-block; background: #2e75b6; color: #fff; font-size: 12px;
  border-radius: 4px; padding: 2px 8px; margin-bottom: 6px; font-weight: 700;
}
.tplB-box { border: 1px solid #cfd9e6; border-radius: 6px; padding: 8px; min-height: 44px; font-size: 12.5px; line-height: 1.6; }
.tplB-row { display: flex; gap: 18px; font-size: 12.5px; color: #445; margin-top: 8px; }
.tplB-row b { color: #1f4e79; }
.tplB-stem { font-size: 13px; line-height: 1.7; white-space: pre-wrap; }
.tplB .checks { margin-top: 4px; }
.tplB-sec.grow { flex: 1; display: flex; flex-direction: column; }
.tplB-sec.grow .tplB-box { flex: 1; }
.page.fill-page .tplB-stem { min-height: 34mm; }

.tplC { border-collapse: collapse; width: 100%; table-layout: fixed; flex: 1; height: 100%; }
.tplC td { border: 1px solid #c9d6e6; vertical-align: top; padding: 6px 8px; font-size: 12.5px; }
.tplC .pill {
  display: inline-block; background: #2e75b6; color: #fff; border-radius: 999px;
  padding: 2px 10px; font-size: 11.5px; font-weight: 700;
}
.tplC .step-title { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: #1f4e79; font-weight: 700; }
.tplC .writebox { min-height: 150px; white-space: pre-wrap; line-height: 1.7; }
.tplC .writebox.sm { min-height: 90px; }
.tplC .fold { text-align: center; color: #1f4e79; font-weight: 700; padding: 6px; }
.tplC .checkline { font-size: 11.5px; color: #7f7f7f; margin-top: 4px; }
.tplC .stem-text { white-space: pre-wrap; line-height: 1.7; }

/* ---- 多题一页：紧凑卡片 ---- */
.page.fill { display: flex; flex-direction: column; }
.grid { flex: 1; display: flex; gap: 4mm; min-height: 0; }
.grid.p2 { flex-direction: column; }
.grid.p2 .mcard { flex: 1; }
.grid.p4 { flex-wrap: wrap; align-content: stretch; }
.grid.p4 .mcard { width: calc(50% - 2mm); height: calc(50% - 2mm); }
.grid.p4.count1 { flex-direction: column; }
.grid.p4.count1 .mcard { width: 100%; height: 100%; }
.grid.p4.count2 { flex-direction: column; }
.grid.p4.count2 .mcard { width: 100%; height: calc(50% - 2mm); }
.grid.p4.count3 .mcard { height: calc(50% - 2mm); }
.grid.p4.count3 .mcard:last-child { width: 100%; }
.mcard {
  border: 1.5px solid #286df8; border-radius: 6px;
  padding: 3.5mm 4mm; display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.mc-head {
  display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid #dbe7f7; padding-bottom: 3px; margin-bottom: 4px;
}
.mc-num { font-weight: 700; color: #1f4e79; font-size: 13px; }
.mc-tag { background: #2e75b6; color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 10.5px; }
.mc-date { margin-left: auto; color: #7f7f7f; font-size: 10.5px; }
.mc-stem { font-size: 12px; line-height: 1.55; white-space: pre-wrap; margin-bottom: 4px; }
.mc-line { font-size: 11.5px; line-height: 1.5; margin: 2px 0; }
.mc-line b { color: #1f4e79; }
.mc-write {
  font-size: 11.5px; line-height: 1.5; border-bottom: 1px dashed #b9c6d8;
  padding: 3px 0 6px; margin-top: 3px; flex: 1; min-height: 12mm;
}
.mc-write.blank { min-height: 20mm; }
.mc-step {
  margin: 5px 0 3px; font-size: 11.5px; color: #1f4e79; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.mcard .checks { gap: 1px 8px; }
.mcard .checks label { font-size: 10.5px; }
.mcard .pill { padding: 1px 7px; font-size: 10px; }

/* ---- 题目插图 ---- */
.qimg {
  display: block; max-width: 100%; margin: 4px 0;
  border: 1px solid #e3e9f2; border-radius: 4px; object-fit: contain;
}
.qimg-full { max-height: 60mm; }
.qimg-compact { max-height: 30mm; }
.grid.p4 .qimg-compact { max-height: 18mm; }
.qimg-wrap { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0; }
.qimg-wrap img { max-width: 240px; max-height: 140px; border: 1px solid #d7dee8; border-radius: 6px; }
.qimg-wrap button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer; color: #445;
}
.img-edit { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.img-edit .thumb { max-width: 180px; max-height: 110px; border: 1px solid #d7dee8; border-radius: 6px; }
.muted { color: #99a; font-size: 12.5px; }

/* ---- 双面打印：反面参考答案 ---- */
.switch-line { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: #445; margin-top: 10px; margin-right: 18px; }
.duplex-hint {
  margin-top: 8px; color: #8a6d3b; background: #fff8e8; border: 1px solid #f0d7b0;
  border-radius: 6px; padding: 6px 10px; font-size: 12.5px;
}
.answer-page .ans-head {
  display: flex; align-items: center; gap: 10px;
  border-bottom: 2px solid #e6a23c; padding-bottom: 8px; margin-bottom: 10px;
}
.ans-badge { background: #e6a23c; color: #fff; border-radius: 999px; padding: 3px 12px; font-size: 12px; font-weight: 700; }
.ans-title { font-size: 16px; font-weight: 700; color: #1f4e79; }
.ans-meta { margin-left: auto; color: #7f7f7f; font-size: 12px; }
.ans-question { font-size: 13px; line-height: 1.7; }
.answer-page .ans-question { min-height: 34mm; }
.ans-block { margin-top: 10px; }
.ans-block.grow { flex: 1; display: flex; flex-direction: column; }
.ans-label { display: inline-block; background: #e6a23c; color: #fff; font-size: 12px; border-radius: 4px; padding: 2px 8px; margin-bottom: 6px; font-weight: 700; }
.ans-answer { flex: 1; border: 1px solid #f0d7b0; border-radius: 6px; padding: 10px; font-size: 14px; line-height: 1.8; background: #fff; min-height: 40mm; }
.ans-text { border: 1px solid #f0d7b0; border-radius: 6px; padding: 8px; font-size: 12.5px; line-height: 1.6; background: #fff; min-height: 16mm; }
.ans-row { display: flex; gap: 10px; margin-top: 10px; }
.ans-block.half { flex: 1; margin-top: 0; }
.answer-card { border-color: #e6a23c; background: #fffaf2; }
.answer-card .mc-tag { background: #e6a23c; }

/* ---- 题库 ---- */
.bank-box { width: min(780px, 94vw); }.bank-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bank-toolbar input[type="number"] { border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; font-size: 13px; width: 76px; }
.bank-count { font-size: 13px; color: var(--gray); }
.bank-list { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.bank-item { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.bank-item:last-child { border-bottom: 0; }
.bank-item .t { flex: 1; line-height: 1.5; }
.bank-item .meta { color: #99a; font-size: 11.5px; margin-top: 2px; }
.bank-item img { max-width: 80px; max-height: 60px; border: 1px solid var(--line); border-radius: 4px; }
.bank-item button { border: 0; background: none; color: #c0392b; cursor: pointer; font-size: 12px; }
.match-badge { font-size: 11.5px; border-radius: 999px; padding: 2px 8px; background: #eef1f5; color: #7f8a99; border: 1px solid #dde4ee; white-space: nowrap; }
.match-badge.ok { background: #e8f7ee; color: #1e8e4e; border-color: #b9e4c9; }

/* ---- 直接打印 ---- */
.print-box { width: min(520px, 92vw); }
.print-form { display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; color: #445; }
.print-form label { display: flex; align-items: center; gap: 8px; }
.print-form select, .print-form input[type="number"] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 14px; }
.print-form select { flex: 1; min-width: 0; }

/* ---- 图片裁剪弹窗 ---- */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 20, 35, .62);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 12px; padding: 14px;
  max-width: 94vw; max-height: 94vh;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal-head { display: flex; flex-direction: column; gap: 3px; font-size: 14px; color: var(--dblue); }
.modal-head .muted { font-weight: normal; }
.crop-stage {
  position: relative; overflow: hidden; background: #111;
  display: flex; justify-content: center; align-items: center;
  max-height: 70vh; border-radius: 8px;
}
.crop-stage img { max-width: 100%; max-height: 70vh; display: block; user-select: none; -webkit-user-select: none; }
.crop-rect {
  position: absolute; border: 2px solid #3b8ed0; background: rgba(59, 142, 208, .18);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .38);
  pointer-events: none;
}
.modal-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1f4e79; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 99;
}

/* ============ 打印 ============ */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .topbar, .steps, .panel, .toast, .actions, .tpl-controls { display: none !important; }
  main { padding: 0; max-width: none; }
  #step-5 { display: block !important; }
  #step-5 h2, #step-5 .hint { display: none !important; }
  .preview { margin: 0; display: block; zoom: 1 !important; }
  .page { box-shadow: none; margin: 0; }
}
