:root {
  --bg-grad: linear-gradient(180deg, #f7f9fc 0%, #eef1f8 100%);
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #7b8194;
  --line: #e7eaf1;
  --line-soft: #f0f2f8;
  --primary: #5b6ef5;
  --primary-d: #4257e0;
  --primary-soft: #eef1ff;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(28, 38, 70, .08);
  --shadow-sm: 0 2px 10px rgba(28, 38, 70, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg-grad);
  color: var(--ink);
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-badge {
  width: 36px; height: 36px;
  border-radius: 11px;
  background: linear-gradient(135deg, #6d7ff7, #4257e0);
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(91, 110, 245, .35);
}
.logo-badge svg { width: 20px; height: 20px; }
.brand-text { font-size: 18px; font-weight: 700; letter-spacing: .3px; color: var(--ink); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 18px;
  border-radius: 11px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: #d7dcec; }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, #6d7ff7, #4257e0);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(91, 110, 245, .3);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(91, 110, 245, .42); }

/* 布局 */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  padding: 20px;
  align-items: start;
}

/* 控制面板 */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  position: sticky;
  top: 84px;
  box-shadow: var(--shadow);
}
.field { margin-bottom: 18px; }
.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 9px;
  letter-spacing: .4px;
}
.field.row { margin-bottom: 12px; }
.hint { color: var(--primary); font-weight: 700; }

/* 题数步进器：滑块 + 加减按钮 + 数字框 */
.stepper { display: flex; align-items: center; gap: 10px; }
.step-btn {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
  font-size: 18px; line-height: 1;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s ease;
  display: flex; align-items: center; justify-content: center;
}
.step-btn:hover { border-color: var(--primary); background: #f1f3ff; }
.step-btn:active { transform: scale(.94); }
.stepper input[type="range"] { flex: 1 1 auto; }
.num-input {
  flex: 0 0 58px;
  width: 58px; height: 32px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 14px; font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, box-shadow .15s;
}
.num-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,110,245,.18);
}
/* 隐藏数字框的上下箭头，避免与加减按钮重复 */
.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num-input { -moz-appearance: textfield; }

select, input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 14px;
  background: #fbfcfe;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
select:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 110, 245, .15);
}

.type-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fbfcfe;
}
.type-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
}
.type-item:hover { background: var(--primary-soft); }
.type-item input { width: 17px; height: 17px; accent-color: var(--primary); }

.cap-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-d);
  background: var(--primary-soft);
  border: 1px solid #dde2ff;
  border-radius: 11px;
  padding: 10px 12px;
  cursor: pointer;
}
.cap-opt input { width: 16px; height: 16px; accent-color: var(--primary); }

input[type="range"] { width: 100%; accent-color: var(--primary); }

.seg {
  display: flex;
  gap: 4px;
  background: var(--line-soft);
  border-radius: 11px;
  padding: 4px;
}
.seg button {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: .14s;
}
.seg button:hover { color: var(--ink); }
.seg button.active {
  background: #fff;
  color: var(--primary-d);
  box-shadow: var(--shadow-sm);
}

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); font-weight: 500; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }

.panel-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.panel-actions .btn { width: 100%; }
.panel-actions-row { display: flex; gap: 10px; }
.panel-actions-row .btn { flex: 1; }

/* 预览区 */
.preview {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 70vh;
  box-shadow: var(--shadow);
}
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.toolbar-info { font-size: 13px; color: var(--muted); }
.sheet-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; }

/* A4 试卷 */
.sheet {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  padding: 14mm 16mm;
  box-shadow: 0 8px 30px rgba(28, 38, 70, .12);
  border-radius: 8px;
  color: #2b2733;
}
.sheet .sheet-title {
  text-align: center;
  font-size: 23px;
  font-weight: 700;
  color: #2f3654;
  margin: 0 0 10px;
}
.sheet .sheet-sub {
  display: flex;
  justify-content: flex-end;
  gap: 22px;
  font-size: 13px;
  color: #555;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 18px;
}
.sheet .sheet-sub span { white-space: nowrap; }

.problems { display: grid; gap: 20px 28px; }
.problems.cols-1 { grid-template-columns: 1fr; }
.problems.cols-2 { grid-template-columns: 1fr 1fr; }
.problems.cols-3 { grid-template-columns: 1fr 1fr 1fr; gap: 18px 16px; }
.problems.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px 12px; }

.prob {
  display: flex;
  align-items: flex-start;
  font-size: 19px;
  line-height: 1.5;
  padding: 5px 0;
  break-inside: avoid;
  page-break-inside: avoid;
}
.prob .q { font-variant-numeric: tabular-nums; }

/* 竖式排版 */
.vprob {
  display: inline-block;
  text-align: right;
  font-size: 19px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.vrow { display: block; white-space: nowrap; }
.vop { margin-right: 6px; }
.vrule { border-top: 2px solid #444; margin: 4px 0; }
.vblank {
  display: inline-block;
  min-width: 46px;
  height: 24px;
  border-bottom: 2px solid #c2c9da;
  vertical-align: bottom;
}
.vans { color: #d6455b; font-weight: 700; }

.blank { display: inline-block; min-width: 52px; text-align: center; color: transparent; }
.blank.line {
  border-bottom: 2px solid #c2c9da;
  height: 30px;
  vertical-align: bottom;
}
.blank.circle {
  border: 2px solid #c2c9da;
  border-radius: 50%;
  width: 28px; height: 28px;
  line-height: 24px;
  min-width: 28px;
}
.ans { color: #d6455b; font-weight: 700; }

.sheet-answer-title {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #2f3654;
  margin: 0 0 14px;
}

/* 打印：仅保留试卷 */
@media print {
  @page { size: A4; margin: 0; }
  .topbar, .panel, .toolbar { display: none !important; }
  body { background: #fff; }
  .layout { display: block; padding: 0; }
  .preview { background: #fff; padding: 0; border: none; border-radius: 0; box-shadow: none; }
  .sheet-wrap { gap: 0; }
  .sheet {
    width: auto;
    min-height: auto;
    box-shadow: none;
    border-radius: 0;
    page-break-after: always;
    padding: 12mm 14mm;
  }
  .sheet:last-child { page-break-after: avoid; }
  .blank.line { border-bottom-color: #999; }
}
