/* 多宝塔碑字库 · PWA */
:root {
  --paper: #f5f2ef;
  --ink: #232323;
  --soft: #57534e;
  --seal: #b03527;
  --tray: #e8e2d9;
  --stone: #17140f;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", "SimSun", serif;
  --sans: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
}
.hidden { display: none !important; }

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

/* 顶栏 */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--tray);
}
.bar h1 { font-family: var(--kai); font-size: 22px; font-weight: 600; letter-spacing: 2px; }
.bar input {
  flex: 1; min-width: 0;
  font-size: 17px; padding: 8px 10px;
  border: 1px solid var(--ink); border-radius: 0;
  background: #fff; color: var(--ink);
  font-family: var(--kai);
}
.bar input:focus { outline: 2px solid var(--seal); outline-offset: -1px; }

.btn {
  border: 0; border-radius: 0; padding: 9px 14px;
  font-size: 15px; font-family: var(--kai); letter-spacing: 1px;
  white-space: nowrap;
}
.btn.ink  { background: var(--ink);  color: var(--paper); }
.btn.seal { background: var(--seal); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--soft); }
.btn:active { opacity: .75; }

.scroll-y { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 16px 20px; }

/* 检字结果 */
.char-head {
  font-family: var(--kai); font-size: 20px; margin: 14px 0 8px;
  display: flex; align-items: baseline; gap: 10px;
}
.char-head small { color: var(--soft); font-family: var(--sans); font-size: 12px; }
.forms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.form-cell { background: var(--stone); aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.form-cell canvas { width: 100%; height: 100%; display: block; }
.form-cap { text-align: center; font-size: 11px; color: var(--soft); padding: 3px 0 6px; }
.empty { color: var(--soft); text-align: center; margin-top: 60px; font-family: var(--kai); font-size: 16px; }

/* 集字 */
.ctl {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 8px 16px; border-bottom: 1px solid var(--tray);
  font-size: 13px; color: var(--soft);
}
.ctl label { display: flex; align-items: center; gap: 6px; }
.ctl input[type="range"] { width: 84px; accent-color: var(--ink); }
.ctl .chk { font-size: 14px; color: var(--ink); }
.ctl .chk input { width: 18px; height: 18px; accent-color: var(--seal); }
.ctl span { min-width: 2ch; color: var(--ink); }
#mz-stage { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; background: var(--tray); }
#mz-canvas { display: block; margin: 12px auto; max-width: none; }
.hint { text-align: center; font-size: 11px; color: var(--soft); padding: 4px 0 8px; }

/* 读帖：手卷，从右往左 */
#tab-scroll { background: var(--tray); }
#scroll-view {
  flex: 1; display: flex; align-items: stretch;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#scroll-view::-webkit-scrollbar { display: none; }
#scroll-view img { height: 100%; width: auto; display: block; flex: none; background: var(--stone); }
#scroll-view img + img { margin-left: 2px; }

/* 底部页签 */
#tabs {
  display: flex; border-top: 1px solid var(--tray);
  background: var(--paper);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs button {
  flex: 1; border: 0; background: none; padding: 12px 0;
  font-family: var(--kai); font-size: 17px; letter-spacing: 3px; color: var(--soft);
}
#tabs button.on { color: var(--seal); font-weight: 600; }

/* 临写大图 */
#lin {
  position: fixed; inset: 0; z-index: 10;
  background: var(--paper);
  display: flex; flex-direction: column;
}
#lin-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 18px; }
#lin-canvas { max-width: 100%; max-height: 100%; background: var(--stone); }
#lin.inv #lin-canvas { filter: grayscale(1) invert(1) contrast(1.06); background: #fff; }
#lin-grid { position: absolute; inset: 0; margin: auto; pointer-events: none; }
#lin-grid line, #lin-grid rect { stroke: rgba(176, 53, 39, .6); stroke-width: 2; fill: none; vector-effect: non-scaling-stroke; }
#lin-bar { display: flex; justify-content: center; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
#lin-cap { text-align: center; color: var(--soft); font-size: 12px; padding-bottom: 8px; }
