:root {
  --paper: #F6F2EA;
  --panel: #FBF9F4;
  --ink: #26221F;
  --sub: #6F665D;
  --faint: #B8AEA1;
  --line: #E4DCCF;
  --accent: #B0372A;
  --accent-soft: #F3E3DD;
  --ok: #3E6B5A;
  --radius: 8px;
  --ui: "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif CJK SC", "SimSun", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--ui); color: var(--ink); background: var(--paper); font-size: 13.5px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* —— 顶栏 —— */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: .18em; }
.brand p { margin: 0; color: var(--sub); font-size: 12px; letter-spacing: .06em; }
.seal { flex: none; width: 34px; height: 34px; border-radius: 5px; background: var(--accent); color: #F8F4EB; display: grid; place-items: center; font-family: var(--serif); font-size: 19px; }
.top-actions { display: flex; gap: 8px; }

.btn { border: 1px solid var(--line); background: #fff; padding: 7px 14px; border-radius: var(--radius); cursor: pointer; letter-spacing: .04em; white-space: nowrap; transition: border-color .15s, background .15s, transform .1s; }
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #9c3024; }
.btn.primary-soft { background: var(--ink); color: #F8F4EB; border-color: var(--ink); }
.btn.wide { width: 100%; padding: 10px; font-size: 14px; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { background: transparent; color: var(--sub); }
.btn:disabled { opacity: .5; cursor: progress; }
.icon { flex: none; width: 30px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); cursor: pointer; font-size: 15px; line-height: 1; }

/* —— 工作台 —— */
.workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 59px); }
.panel { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 4px 20px 28px; }
.step { padding: 16px 0 18px; border-bottom: 1px solid var(--line); }
.step h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 15px; font-weight: 600; letter-spacing: .16em; display: flex; align-items: center; gap: 8px; }
.step h2 i { font-style: normal; font-family: var(--ui); font-size: 11.5px; letter-spacing: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: #F8F4EB; display: grid; place-items: center; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 10px 0 0; min-width: 0; }
.field > span { color: var(--sub); font-size: 12.5px; display: flex; justify-content: space-between; }
.field output { color: var(--ink); font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row.tight { gap: 8px; margin-top: 10px; }
.row .grow { flex: 1 1 120px; }
select, input[type=text], input[type=date] { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 6px 9px; min-height: 34px; width: 100%; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: #F8F4EB; }
.seg-5 { display: flex; } .seg-5 button { flex: 1; padding-inline: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; margin-top: 10px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 10px; }

.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.size { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 10px 6px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; transition: border-color .15s, box-shadow .15s; }
.size:hover { border-color: var(--faint); }
.size.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.size .shape { background: var(--paper); border: 1px solid var(--faint); border-top: 3px solid var(--sub); border-radius: 2px; }
.size b { font-weight: 500; font-size: 12.5px; }
.size small { color: var(--sub); font-size: 11px; line-height: 1.3; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px 4px 4px; background: #fff; cursor: pointer; }
.swatch i { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(0,0,0,.08); display: inline-block; position: relative; overflow: hidden; }
.swatch i::after { content: ""; position: absolute; right: 0; top: 0; width: 50%; height: 100%; background: var(--c2); }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink) inset; }
.zoom-row { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.zoom-row input { flex: 1; }
.hint { color: var(--sub); font-size: 12px; margin: 8px 0 0; line-height: 1.6; }
.more { padding: 14px 0; border-bottom: 1px solid var(--line); }
.more summary { cursor: pointer; color: var(--sub); font-size: 13px; letter-spacing: .08em; list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: "＋ "; }
.more[open] summary::before { content: "－ "; }
.lookup { padding: 8px 0 0; }
.lookup-result { font-size: 12.5px; margin-top: 8px; }
.lookup-result h3, .popover h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 15px; letter-spacing: .06em; }
.lookup-result dl, .popover dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.lookup-result dt, .popover dt { color: var(--sub); }
.lookup-result dd, .popover dd { margin: 0; word-break: keep-all; }
.foot { color: var(--faint); font-size: 11.5px; margin-top: 16px; line-height: 1.6; }

/* —— 画布 —— */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #ECE6DB; }
.stage-bar { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 18px; }
.stage-bar .title { font-family: var(--serif); letter-spacing: .12em; font-size: 14px; min-width: 12em; text-align: center; }
.nav { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 18px; line-height: 1; }
.nav:disabled { opacity: .35; cursor: default; }
.canvas { flex: 1; min-height: 0; overflow: hidden; padding: 8px 28px 12px; display: flex; align-items: center; justify-content: center; }
.page { position: relative; background: #fff; box-shadow: 0 1px 2px rgba(60,40,20,.08), 0 10px 32px rgba(60,40,20,.14); line-height: 0; flex: none; }
.page svg { display: block; width: 100%; height: 100%; }
.img-hit { cursor: grab; touch-action: none; }
.img-hit:active { cursor: grabbing; }
.day-hit { cursor: pointer; }
.day-hit:hover { fill: rgba(176,55,42,.05); }
.canvas.dragover .page { outline: 3px dashed var(--accent); outline-offset: 6px; }

.preflight { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; padding: 0 20px 8px; font-size: 12px; color: var(--sub); }
.preflight span { display: inline-flex; align-items: center; gap: 5px; }
.preflight .ok::before { content: "✓"; color: var(--ok); font-weight: 600; }
.preflight .warn { color: #8a3a1f; }
.preflight .warn::before { content: "!"; display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; }

.film { display: flex; gap: 10px; overflow-x: auto; padding: 10px 20px 14px; border-top: 1px solid var(--line); background: rgba(251,249,244,.75); scroll-behavior: smooth; }
.thumb { flex: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 0; }
.thumb .tp { background: #fff; box-shadow: 0 1px 4px rgba(60,40,20,.14); line-height: 0; outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s; }
.thumb .tp svg { width: 100%; height: 100%; display: block; }
.thumb.on .tp { outline-color: var(--accent); }
.thumb span { font-size: 11.5px; color: var(--sub); }
.thumb.on span { color: var(--accent); }
.thumb .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; margin-left: 3px; vertical-align: middle; }

.popover { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(40,25,10,.18); max-width: 300px; font-size: 12.5px; }
.popover .tag, .lookup-result .tag { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 11.5px; margin: 0 4px 2px 0; background: var(--accent-soft); color: var(--accent); }
.popover .tag.term, .lookup-result .tag.term { background: #E2ECE6; color: #3E6B5A; }
.popover .tag.minor, .lookup-result .tag.minor { background: #EFEBE4; color: var(--sub); }
.popover .src, .lookup-result .src { color: var(--faint); font-size: 11px; margin-top: 6px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #F8F4EB; padding: 9px 18px; border-radius: 8px; z-index: 80; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 90vw; }

.modal { position: fixed; inset: 0; z-index: 70; background: rgba(38,34,31,.38); display: grid; place-items: center; padding: 20px; }
.modal-card { background: var(--panel); border-radius: 12px; max-width: 520px; width: 100%; padding: 22px 24px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 90vh; overflow: auto; }
.modal-card h3 { margin: 0 0 12px; font-family: var(--serif); font-size: 18px; letter-spacing: .1em; }
.modal-card ul { margin: 8px 0; padding-left: 18px; }
.modal-card li { margin: 4px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 14px 0 6px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }

#printRoot { display: none; }

/* —— 移动端 —— */
@media (max-width: 900px) {
  .topbar { flex-direction: column; align-items: stretch; padding: 10px 12px; position: static; gap: 10px; }
  .top-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .top-actions .btn { padding: 8px 4px; font-size: 13px; white-space: normal; line-height: 1.3; min-width: 0; }
  .workspace { display: flex; flex-direction: column; height: auto; }
  .stage { order: -1; }
  .panel { border-right: 0; border-top: 1px solid var(--line); overflow: visible; padding: 4px 16px 28px; }
  .stage-bar .title { min-width: 0; font-size: 12.5px; letter-spacing: .04em; }
  .preflight { padding: 0 12px 8px; }
  .canvas { flex: none; padding: 8px 12px; }
  .film { padding: 8px 12px 10px; }
}

/* —— 家用打印：仅输出成品页面，按实际纸张尺寸 —— */
@media print {
  html, body { background: #fff !important; height: auto; }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }
  #printRoot .print-page { break-after: page; page-break-after: always; overflow: hidden; }
  #printRoot .print-page:last-child { break-after: auto; page-break-after: auto; }
  #printRoot svg { display: block; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
