:root {
  --bg: #0b1220; --panel: #131c2e; --panel2: #1a2640; --line: #26334f;
  --text: #e8eefc; --muted: #94a3c0; --accent: #3b82f6; --accent2: #2563eb;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif; }
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
.top { padding: calc(14px + var(--safe-t)) 18px 10px; display: flex; align-items: baseline; justify-content: space-between; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.sub { color: var(--muted); font-size: 12px; }
main { padding: 8px 14px calc(24px + var(--safe-b)); max-width: 760px; margin: 0 auto; }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 11px 16px; cursor: pointer; min-height: 44px; }
.btn:active { filter: brightness(1.15); }
.btn.primary { background: var(--accent); border-color: var(--accent2); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 8px 12px; min-height: 40px; font-size: 14px; border-radius: 10px; }
.btn.big { width: 100%; padding: 20px; font-size: 18px; border-radius: 16px; min-height: 64px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.hero { display: flex; flex-direction: column; gap: 14px; margin-top: 8vh; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 6px 4px; }
.hint.small { font-size: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: grid; grid-template-columns: 72px 1fr; gap: 10px; }
.thumb { width: 72px; height: 96px; border-radius: 8px; background: #fff center/contain no-repeat; border: 1px solid var(--line); }
.thumb.empty { background-color: var(--panel2); }
.card .name { font-weight: 600; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.card .st { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.card .st.ok { color: var(--ok); } .card .st.bad { color: var(--bad); }
.pbar { height: 4px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
.pbar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #3a2d0e; color: #fbbf24; }
.badge.bad { background: #3b1414; color: #fca5a5; }
.card .acts { display: flex; flex-wrap: wrap; gap: 6px; }
.card .acts .btn { padding: 6px 12px; min-height: 36px; font-size: 13px; }

/* 编辑器 */
.editor { position: fixed; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.ed-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; background: var(--panel); border-radius: 10px; padding: 3px; }
.tab { border: 0; background: transparent; padding: 7px 18px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.tab.on { background: var(--accent); color: #fff; }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; padding-bottom: calc(12px + var(--safe-b)); }
#paneCrop { overflow: hidden; }
.stage-wrap { flex: 1; min-height: 200px; position: relative; display: flex; align-items: center; justify-content: center; background: #05080f; overflow: hidden; }
#paneFx .stage-wrap { flex: none; height: 52vh; }
#cropCanvas { touch-action: none; display: block; }
.live { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.6); border: 1px solid var(--line); border-radius: 8px; padding: 4px; text-align: center; pointer-events: none; }
.live canvas { display: block; background: #fff; max-width: 110px; max-height: 150px; }
.live small { font-size: 10px; color: var(--muted); }
.ctrl-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; justify-content: center; }
.msgs { padding: 0 12px 6px; display: flex; flex-direction: column; gap: 4px; }
.msg { font-size: 13px; padding: 6px 10px; border-radius: 8px; background: #3a2d0e; color: #fcd34d; }
.msg.bad { background: #3b1414; color: #fca5a5; }
.msg.ok { background: #0f2e1b; color: #86efac; }

.cmp { position: relative; background: #fff; }
.cmp canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cmpLine { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); box-shadow: 0 0 0 1px rgba(255,255,255,.7); pointer-events: none; }
.tag { position: absolute; top: 6px; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; pointer-events: none; }
.tag.l { left: 6px; } .tag.r { right: 6px; }
.cmp-range { width: calc(100% - 28px); margin: 12px 14px 4px; accent-color: var(--accent); }
.panel { padding: 6px 14px; }
.seg { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin: 8px 0 10px; }
.seg button { border: 1px solid var(--line); background: var(--panel); padding: 10px 4px; border-radius: 10px; font-size: 12px; cursor: pointer; }
.seg button.on { background: var(--accent); border-color: var(--accent2); color: #fff; font-weight: 600; }
.row { display: grid; grid-template-columns: 76px 1fr 44px; align-items: center; gap: 8px; margin: 4px 0; }
.row span { color: var(--muted); font-size: 13px; }
.row output { text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }
.row2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 2px; font-size: 13px; color: var(--muted); }
.row2 select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-left: 6px; }

.busy { position: fixed; inset: 0; background: rgba(5,8,15,.72); z-index: 50; display: flex; align-items: center; justify-content: center; }
.busy-box { width: min(86vw, 340px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.bar { height: 6px; background: var(--panel2); border-radius: 6px; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: #1f2a44; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: 90vw; font-size: 14px; }

/* 重排版 */
.rt { z-index: 30; }
.rt-title { font-weight: 600; }
.rt-body { padding: 0 0 calc(24px + var(--safe-b)); }
.rt-ocr { padding: 4px 14px 8px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.rt-count { color: var(--muted); font-size: 13px; align-self: center; }
.rt-list { list-style: none; margin: 0; padding: 0 12px; display: flex; flex-direction: column; gap: 10px; }
.rt-row { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.rt-row.digit { border-color: #b45309; }
.rt-row.done { border-color: var(--ok); }
.rt-crop { display: block; max-width: 100%; background: #fff; border-radius: 6px; }
.rt-row input[type=text] { width: 100%; margin-top: 6px; padding: 10px; font-size: 17px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
.rt-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; font-size: 13px; color: var(--muted); }
.rt-meta label { display: flex; align-items: center; gap: 6px; color: var(--text); }
.rt-meta input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--ok); }
.rt-tag { color: #fbbf24; }
#rtResult { padding: 10px 12px; }
#rtCanvas { width: 100%; background: #fff; border-radius: 6px; }

/* 文档高清模式：小屏上的五个模式按钮与校直开关 */
.check-row { grid-template-columns: 76px 28px 1fr; margin: 8px 0; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.check-row small { font-size: 12px; color: var(--muted); }
@media (max-width: 360px) { .seg { gap: 3px; } .seg button { font-size: 11px; padding: 9px 1px; } }

/* 本地 OCR 置信度提示（不会替代人工核对） */
.rt-row.rt-uncertain:not(.done) { box-shadow: inset 3px 0 #ef4444; }
.rt-ocr .hint { text-align: left; margin: 0; }
#rtOcrWarning { line-height: 1.6; overflow-wrap: anywhere; }

/* v3.2 自动 OCR 重排版：预览在最上方；仅异常项默认展示 */
.rt-quick-info { padding: 12px 14px 4px; }
.rt-info { font-size: 12px; color: var(--muted); }
.rt-quick-info .rt-count { display: block; margin-top: 4px; color: #dbeafe; }
.rt-review-header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; }
.rt-review-hint { font-size: 12px; color: var(--muted); width: 100%; }
.rt-source { padding: 8px 14px; font-size: 13px; color: var(--muted); }
.rt-source canvas { display: block; max-width: 100%; height: auto; margin-top: 8px; background: white; }
#rtResult { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding-top: 10px; }
#rtCanvas { max-width: 520px; height: auto; display: block; margin: 0 auto; }
#rtOcrWarning { margin-top: 6px; }
