/* 稳定暖色设置面板；风格变量只存在于 .page 试卷范围内 */
:root {
  /* 界面 */
  --ui-bg: #eef0ea;
  --ui-panel: #ffffff;
  --ui-ink: #2f2c26;
  --ui-ink-soft: #6f6a5f;
  --ui-line: #ddd7ca;
  --ui-input-bg: #fcfbf7;
  --ui-input-border: #bdb3a5;
  --ui-hover-border: #b9ae9e;
  --ui-block-bg: #fcfbf7;
  --ui-block-line: #d8d0c2;
  --ui-subtle-bg: #f7f5ef;
  --ui-batch-bg: #fffaf5;
  --ui-batch-line: #e4d7c9;
  --ui-btn-ghost-bg: #ffffff;
  --ui-seg-text: #514b42;
  --ui-shadow: rgba(60, 50, 30, .14);
  --ui-focus: rgba(217, 85, 63, .25);
  /* 强调（界面主色） */
  --accent: #d9553f;
  --accent-soft: #fbe9e4;
  --accent-hover: #b8432e;
  --accent-active: #f5d7cf;
  --ans-red: #c2311d;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: var(--ui-bg);
  color: var(--ui-ink);
  display: flex;
  min-height: 100vh;
}

[hidden] { display: none !important; }

#panel {
  width: 320px;
  flex: 0 0 320px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--ui-panel);
  padding: 20px 18px 28px;
  box-shadow: 1px 0 0 var(--ui-line);
}

.panel-head { position: relative; margin-bottom: 2px; }
.panel-head h1 { font-size: 19px; margin: 0 0 4px; letter-spacing: .5px; color: var(--ui-ink); }
.panel-head .sub { margin: 0 0 16px; font-size: 12px; color: var(--ui-ink-soft); }

/* ---------- 控制区层级 ---------- */
.ctrl-group { border-top: 1px dashed var(--ui-line); padding: 15px 0 8px; }
.ctrl-label { font-size: 14px; font-weight: 700; color: var(--ui-ink); margin-bottom: 9px; display: flex; align-items: center; gap: 6px; }
.ctrl-label .hint { font-weight: 400; font-size: 11px; color: var(--ui-ink-soft); }

select, input[type="text"], input[type="number"] {
  min-height: 40px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--ui-input-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--ui-input-bg);
  color: var(--ui-ink);
  outline: none;
}
input[type="number"] { text-align: center; }
select:hover, input[type="text"]:hover, input[type="number"]:hover { border-color: var(--ui-hover-border); }
select:focus-visible, input[type="text"]:focus-visible, input[type="number"]:focus-visible,
button:focus-visible, input[type="checkbox"]:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
  border-color: var(--accent);
}

.title-input {
  font-size: 16px !important;
  font-weight: 700;
  padding: 12px 13px !important;
  letter-spacing: .5px;
  background: var(--ui-panel) !important;
  min-height: 44px;
}
.field-label {
  display: flex; align-items: baseline; gap: 8px; margin: 0;
  color: var(--ui-ink); font-size: 14px; font-weight: 700; line-height: 1.35;
}
.field-hint { color: var(--ui-ink-soft); font-size: 12px; font-weight: 400; }

/* ---------- 试卷风格选择器（面板自身不随风格变化） ---------- */
.style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.style-card {
  display: flex; align-items: center; gap: 8px;
  min-width: 0; min-height: 66px; padding: 8px;
  border: 1.5px solid var(--ui-block-line);
  border-radius: 11px;
  background: var(--ui-block-bg);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease, transform .08s ease;
}
.style-card:hover { border-color: var(--accent); background: #fff; }
.style-card:active { transform: translateY(1px); }
.style-card.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 .5px var(--accent); }
.style-preview { display: grid; place-items: center; width: 38px; height: 48px; flex: none; }
.style-preview-svg { display: block; width: 38px; height: 46px; filter: drop-shadow(0 1px 1px rgba(60, 50, 30, .08)); transition: transform .16s ease; }
.style-card:hover .style-preview-svg { transform: translateY(-1px); }
.style-card .t-name { min-width: 0; font-size: 13px; font-weight: 700; color: var(--ui-ink); line-height: 1.2; }
.style-card .t-note { display: block; margin-top: 3px; font-size: 10.5px; font-weight: 400; line-height: 1.2; color: var(--ui-ink-soft); }
@media (prefers-reduced-motion: reduce) {
  .style-card, .style-preview-svg { transition: none; }
}

/* ---------- 侧边栏折叠（贴边三角手柄） ---------- */
.side-handle {
  position: fixed;
  top: 50%;
  left: min(320px, 100vw);
  transform: translateY(-50%);
  z-index: 90;
  width: 16px;
  height: 64px;
  border: none;
  border-radius: 0 8px 8px 0;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: left .18s ease, background .15s ease;
}
.side-handle:hover { background: var(--accent-hover); }
body.panel-hidden #panel { display: none; }
body.panel-hidden .side-handle { left: 0; }
@media (max-width: 900px) {
  .side-handle { top: auto; bottom: 18px; }
}

/* ---------- 分段控件 ---------- */
.seg { display: flex; border: 1px solid var(--ui-line); border-radius: 9px; overflow: hidden; min-height: 40px; }
.seg button {
  flex: 1; border: none; background: transparent; padding: 8px 7px;
  min-height: 38px; font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--ui-seg-text);
  border-right: 1px solid var(--ui-line);
  font-family: inherit;
}
.seg button:last-child { border-right: none; }
.seg button:hover:not(.on) { background: var(--accent-soft); color: var(--ui-ink); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- 题型卡 ---------- */
.type-block { margin-bottom: 10px; border: 1px solid var(--ui-block-line); border-radius: 10px; padding: 12px; background: var(--ui-block-bg); }
.type-block .type-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.type-block .type-name { font-weight: 700; font-size: 14px; color: var(--ui-ink); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }
.type-block.disabled { opacity: .45; }
.stepper { display: inline-flex; align-items: center; gap: 4px; flex: none; white-space: nowrap; }
.stepper-button {
  width: 32px; height: 34px; margin: 0; border: 1px solid var(--ui-input-border);
  border-radius: 7px; background: var(--ui-btn-ghost-bg); color: var(--ui-ink); font-size: 17px;
  line-height: 1; cursor: pointer; font-family: inherit; flex: 0 0 32px;
}
.stepper .stepper-value { width: 52px; min-height: 34px; height: 34px; padding: 4px 6px; border-radius: 7px; font-size: 15px; font-weight: 700; flex: 0 0 52px; appearance: textfield; }
.stepper .stepper-value::-webkit-inner-spin-button, .stepper .stepper-value::-webkit-outer-spin-button { margin: 0; appearance: none; }
.stepper-button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.stepper-button:active { background: var(--accent-active); }
.kp-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  background: var(--ui-subtle-bg);
  border: 1px solid var(--ui-line);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--ui-ink);
  cursor: pointer;
  margin-bottom: 6px;
  font-family: inherit;
}
.kp-toggle:hover { border-color: var(--accent); color: var(--accent); }
.kp-toggle > span:first-child { font-weight: 700; color: var(--ui-ink); }
.kp-toggle .kp-hint { flex: 1; text-align: left; font-size: 11px; color: var(--ui-ink-soft); font-weight: 400; }
.kp-toggle .tri { font-style: normal; color: var(--accent); font-size: 11px; }
.kp-list.closed { display: none; }
.kp-list { display: flex; flex-direction: column; gap: 4px; max-height: 168px; overflow-y: auto; }
.kp-list label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; line-height: 1.35; color: var(--ui-ink); }
.kp-list input { accent-color: var(--accent); }
.sem-tag { font-size: 10px; color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: 0 3px; margin-left: auto; }

/* ---------- 其他选项 ---------- */
.other-options { display: grid; gap: 14px; }
.option-row { display: flex; align-items: center; gap: 10px; min-height: 40px; color: var(--ui-ink); cursor: pointer; }
.option-toggle { padding: 3px 1px; }
.option-toggle input[type="checkbox"] { width: 19px; height: 19px; flex: none; margin: 0; accent-color: var(--accent); cursor: pointer; }
.option-label { color: var(--ui-ink); font-size: 14px; font-weight: 700; line-height: 1.35; }
.field-block { display: grid; gap: 7px; }
.batch-settings {
  display: flex; align-items: center; gap: 12px; min-height: 44px;
  padding: 10px 11px; border: 1px solid var(--ui-batch-line); border-radius: 9px;
  background: var(--ui-batch-bg);
}
.batch-settings .field-label { flex: 1; }
.batch-settings .seg { flex: 1.45; }
#batchInput {
  width: 92px; min-height: 40px; height: 40px; padding: 7px 10px;
  border: 1px solid var(--ui-input-border);
  font-size: 18px; font-weight: 800;
  color: #111; -webkit-text-fill-color: #111; caret-color: #111;
  background: #fff; opacity: 1;
  text-align: center; letter-spacing: .5px;
  font-variant-numeric: tabular-nums;
}
#batchRow .field-label { flex: 1; margin: 0; color: var(--ui-ink); font-weight: 700; }
.mode-settings { align-items: stretch; }
.mode-settings .field-label { align-self: center; flex: 0 0 auto; }

/* ---------- 操作按钮 ---------- */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 20px; }
.btn {
  min-height: 42px; padding: 10px 8px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1.5px solid transparent; transition: transform .06s ease;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn.primary { grid-column: span 2; background: var(--accent); color: #fff; font-weight: 800; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--ui-btn-ghost-bg); border-color: var(--ui-line); color: var(--ui-ink); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible { outline: 3px solid var(--ui-focus); outline-offset: 3px; }
.footnote { font-size: 11px; color: var(--ui-ink-soft); line-height: 1.5; }

#stage { flex: 1; padding: 26px 30px 60px; display: flex; justify-content: center; }
#sheetHost { display: flex; flex-direction: column; gap: 22px; align-items: center; }

/* ---------- A4 试卷页面（局部风格令牌） ---------- */
.page {
  --sheet: #fffdf8; --sheet-frame: #eebf9c; --sheet-frame-inner: #f3d9c4;
  --sheet-badge-bg: #fff3e6; --sheet-ink: #2f2c26; --sheet-ink-soft: #6f6a5f;
  --sheet-blank-line: #ddd7ca; --sheet-blank-print: #bbb;
  width: 210mm;
  min-height: 297mm;
  background: var(--sheet);
  box-shadow: 0 2px 14px var(--ui-shadow);
  padding: 8mm;
  font-size: var(--q-size, 17px);
  color: var(--sheet-ink);
}
.page-frame {
  border: 2.5px solid var(--sheet-frame);
  border-radius: 10px;
  outline: 1px dashed var(--sheet-frame-inner);
  outline-offset: -7px;
  padding: 6mm 8mm;
  min-height: calc(297mm - 16mm);
  position: relative;
  display: flex;
  flex-direction: column;
}
.page-foot { margin-top: auto; padding-top: 6mm; text-align: center; font-size: .72em; color: var(--sheet-ink-soft); }

.sheet-title { text-align: center; font-size: 1.55em; font-weight: 900; letter-spacing: 2px; margin: 0 0 3.5mm; color: var(--sheet-ink); }
.meta-row {
  display: flex; justify-content: space-between; gap: 4mm;
  font-size: .88em; font-weight: 600; margin-bottom: 4mm; color: var(--sheet-ink);
}
.meta-row .tier-note { color: var(--accent); font-weight: 700; }

.section { margin-bottom: 6.5mm; }
.sec-badge {
  display: inline-flex; align-items: center; gap: .35em;
  background: var(--sheet-badge-bg);
  border: 1.5px solid var(--sheet-frame);
  border-radius: 999px;
  padding: .12em .95em;
  font-size: 1.02em; font-weight: 800; letter-spacing: 1px;
  color: var(--sheet-ink);
  transform: rotate(-1.2deg);
  margin-bottom: 3.5mm;
}
.sec-glyph { font-size: .82em; color: var(--accent); transform: rotate(8deg); }
.sec-title { margin: 0 0 3.5mm; font-size: 1.02em; font-weight: 800; color: var(--sheet-ink); }
.score-table { width: 100%; border-collapse: collapse; margin: 0 0 4mm; color: var(--sheet-ink); font-size: .82em; }
.score-table th, .score-table td { border: 1px solid var(--sheet-ink); height: 7mm; text-align: center; }

.page[data-style="exam"] { --sheet: #fff; --sheet-frame: #222; --sheet-frame-inner: #222; --sheet-badge-bg: transparent; --sheet-ink: #111; --sheet-ink-soft: #444; --sheet-blank-line: #aaa; font-family: SimSun, "宋体", serif; }
.page[data-style="exam"] .page-frame { border: 0; outline: 0; border-radius: 0; padding: 5mm 6mm; }
.page[data-style="exam"] .sheet-title { font-family: SimSun, "宋体", serif; letter-spacing: 3px; border-top: 3px double #111; border-bottom: 3px double #111; padding: 2mm 0; }
.page[data-style="exam"] .meta-row { border-bottom: 1px solid #111; padding-bottom: 3mm; }
.page[data-style="exam"] .sec-title { font-family: SimSun, "宋体", serif; font-size: 1.08em; }
.page[data-style="cute"] { --sheet: #f8fbff; --sheet-frame: #4f8fcb; --sheet-frame-inner: #b8d7ef; --sheet-badge-bg: #eaf4fc; --sheet-ink: #26455f; --sheet-ink-soft: #5b7387; --sheet-blank-line: #bed4e5; }
.page[data-style="cute"] .page-frame { border: 3px solid var(--sheet-frame); border-radius: 12px; outline: 1px dashed var(--sheet-frame-inner); }
.page[data-style="cute"] .sec-badge { border-radius: 8px; transform: rotate(-1deg); }
.page[data-style="cute"] .sec-glyph { color: #2f78b7; }
.page[data-style="cute"] .sheet-title::before { content: "✦ "; color: #2f78b7; }
.page[data-style="cute"] .sheet-title::after { content: " ✦"; color: #2f78b7; }
.page[data-style="plain"] { --sheet: #fff; --sheet-frame: #999; --sheet-frame-inner: transparent; --sheet-badge-bg: transparent; --sheet-ink: #111; --sheet-ink-soft: #444; --sheet-blank-line: #aaa; }
.page[data-style="plain"] .page-frame { border: 0; outline: 0; border-radius: 0; padding: 4mm 5mm; }
.page[data-style="plain"] .sheet-title { letter-spacing: 1px; }
.page[data-style="plain"] .section { margin-bottom: 4mm; }
.page[data-style="plain"] .sec-title { border-bottom: 1px solid #777; padding-bottom: 1.5mm; margin-bottom: 2mm; }

.oral-grid { display: grid; grid-template-columns: repeat(var(--oral-cols, 4), 1fr); column-gap: 6mm; }
.oral-item { padding: .42em .05em; font-weight: 700; white-space: nowrap; overflow: hidden; }

.col-grid, .step-grid { display: grid; gap: 3mm 7mm; }
.col-grid { grid-template-columns: repeat(var(--col-cols, 3), 1fr); }
.step-grid { grid-template-columns: repeat(2, 1fr); }
.col-item, .step-item { break-inside: avoid; }
.q-line { font-weight: 700; display: flex; align-items: baseline; gap: .35em; white-space: nowrap; overflow: hidden; }
.q-no { color: var(--sheet-ink-soft); font-size: .78em; font-weight: 600; min-width: 1.6em; flex: none; }
.work-blank { border-bottom: 1px dotted var(--sheet-blank-line); margin-top: .25em; }
.col-grid { column-gap: 11mm; row-gap: 6mm; }
.col-item .work-blank { height: 30mm; }
.step-item .work-blank { height: 34mm; }

.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.08; margin: 0 .12em; }
.frac .fn { border-bottom: .09em solid currentColor; padding: 0 .18em; }
.frac .fd { padding: 0 .18em; }

.answer-page .ans-note, .ans-note { font-size: .72em; color: var(--sheet-ink-soft); text-align: center; margin: -1.5mm 0 4mm; }
.ans-red { color: var(--ans-red); font-weight: 800; margin-left: .18em; }
@media print {
  .ans-red, .sec-glyph { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 900px) {
  body { flex-direction: column; }
  #panel { position: static; width: auto; height: auto; flex: none; box-shadow: none; border-bottom: 1px solid var(--ui-line); }
  #stage { padding: 16px 8px 40px; }
  .page { width: 100%; min-height: 0; }
  .page-frame { min-height: 0; }
  .batch-settings { flex-wrap: wrap; }
  .mode-settings .seg { flex: 1 1 100%; }
}

/* ---------- 打印：隐藏界面，仅输出试卷 ---------- */
@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; display: block; }
  #panel { display: none !important; }
  .side-handle { display: none !important; }
  #stage { padding: 0; }
  #sheetHost { gap: 0; display: block; }
  .page {
    box-shadow: none; width: 210mm; height: 296.5mm;
    break-after: page; page-break-after: always;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .page:last-child { break-after: auto; page-break-after: auto; }
  .work-blank { border-bottom-color: var(--sheet-blank-print); }
}
