:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --danger: #c2410c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --page-bg: #dde1e6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --panel: #1b2129; --text: #e6e9ee; --muted: #9aa4b2; --line: #2c3440;
    --accent: #2dd4bf; --accent-ink: #062723; --accent-soft: #123430; --danger: #fb923c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); --page-bg: #0b0e12;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; white-space: nowrap; }
.logo { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 2px 6px; font-size: 13px; letter-spacing: .5px; }
.lang { margin-left: auto; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 13px; white-space: nowrap; }
.lang:hover { border-color: var(--accent); color: var(--accent); }
.topnav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.topnav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-size: 14px; }
.topnav a:hover, .topnav a.on { background: var(--accent-soft); color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 32px 16px 48px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 16px 28px; border-top: 1px solid var(--line); }

.hero { text-align: center; margin: 12px 0 32px; }
.hero h1 { font-size: 34px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px;
  text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .ic { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-size: 22px; background: var(--accent-soft); margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; vertical-align: 2px; font-weight: 400; }

.tool-head { text-align: center; margin-bottom: 24px; }
.tool-head h1 { margin: 0 0 6px; font-size: 28px; }
.tool-head p { margin: 0; color: var(--muted); }

.drop {
  border: 2px dashed var(--line); border-radius: 16px; background: var(--panel); padding: 48px 16px;
  text-align: center; cursor: pointer; transition: border-color .12s, background .12s; max-width: 720px; margin: 0 auto;
}
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 40px; }
.drop p { color: var(--muted); margin: 8px 0 0; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 12px 28px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 4px 8px; font-size: 13px; border-radius: 7px; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.opts { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; justify-content: center; margin: 16px 0 0; }
.opts label { display: inline-flex; gap: 6px; align-items: center; }
.opts input[type=text] { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 240px; }
.opts select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 8px; }

/* file tiles (merge, images, split) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 20px; }
.tile {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  text-align: center; box-shadow: var(--shadow); cursor: grab; user-select: none;
}
.tile.dragging { opacity: .4; }
.tile.sel { outline: 3px solid var(--accent); }
.tile .thumb { height: 170px; display: grid; place-items: center; background: var(--page-bg); border-radius: 8px; overflow: hidden; }
.tile .thumb canvas, .tile .thumb img { max-width: 100%; max-height: 170px; box-shadow: 0 1px 3px rgba(0,0,0,.2); background: #fff; }
.tile .name { font-size: 12px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .sub { font-size: 11px; color: var(--muted); }
.tile .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; line-height: 1; }
.tile .num { position: absolute; top: 4px; left: 4px; background: var(--accent); color: var(--accent-ink); font-size: 11px; border-radius: 6px; padding: 0 6px; }
.tile.add { display: grid; place-items: center; border-style: dashed; cursor: pointer; color: var(--muted); min-height: 200px; font-size: 14px; }

/* find & replace, redact */
.rules { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.rule { display: flex; gap: 8px; align-items: center; }
.rule input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.rule .arrow { color: var(--muted); }
#frResult, #rdResult { margin-top: 16px; }
.counts { margin: 8px 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.diff { border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; display: grid; grid-template-columns: 70px 1fr; gap: 2px 10px; }
.diff .pg { grid-row: span 2; color: var(--muted); font-size: 12px; }
.diff .before { color: var(--muted); text-decoration: line-through; overflow-wrap: anywhere; }
.diff .after { overflow-wrap: anywhere; }
.rd-group { margin-top: 14px; }
.rd-kind { font-weight: 600; margin-bottom: 4px; }
.rd-item { display: flex; gap: 8px; align-items: center; padding: 3px 0; font-size: 14px; }
.rd-text { font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.rd-previews { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.rd-previews .tile { cursor: default; }
.rd-page { position: relative; display: inline-block; max-width: 100%; }
.rd-page canvas { display: block; }
.rd-box { position: absolute; background: rgba(0, 0, 0, .75); outline: 1.5px solid #dc2626; }
.opts input[type=checkbox] { width: 16px; height: 16px; }
#rdKeywords { flex: 1; }

/* convert result */
.result { max-width: 560px; margin: 24px auto 0; text-align: center; }
.filebar { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.filebar .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* editor */
.ed { display: grid; grid-template-columns: 170px 1fr; gap: 16px; }
.ed-bar {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; position: sticky; top: 58px; z-index: 10; box-shadow: var(--shadow);
}
.ed-bar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 6px; }
.ed-bar label { margin: 0 4px; }
.ed-bar .tb { padding: 6px 8px; border-radius: 8px; border: 1px solid transparent; background: none; cursor: pointer; font-size: 14px; white-space: nowrap; }
.ed-bar .tb:hover { background: var(--accent-soft); }
.ed-bar .tb.on { background: var(--accent); color: var(--accent-ink); }
.ed-bar label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.ed-bar input[type=color] { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.ed-bar input[type=number] { width: 56px; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.ed-bar .grow { flex: 1; }
.ed-side { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 140px); overflow-y: auto; position: sticky; top: 124px; align-self: start; padding-right: 4px; }
.th { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; text-align: center; cursor: pointer; }
.th.cur { border-color: var(--accent); }
.th canvas { max-width: 100%; display: block; margin: 0 auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.th .row { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 12px; color: var(--muted); }
.th .row button { border: 0; background: none; cursor: pointer; padding: 2px 3px; border-radius: 4px; font-size: 13px; }
.th .row button:hover { background: var(--accent-soft); }
.ed-pages { background: var(--page-bg); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 20px; min-width: 0; overflow-x: auto; }
.pg { position: relative; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); flex: none; }
.pg canvas { display: block; width: 100%; height: 100%; }
.ov { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.ov.t-text { cursor: text; } .ov.t-rect, .ov.t-white, .ov.t-hl, .ov.t-ink, .ov.t-image { cursor: crosshair; }
.ov svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ov svg polyline { pointer-events: stroke; cursor: move; }
.ob { position: absolute; transform-origin: 0 100%; }
.ln { position: absolute; cursor: text; border-radius: 2px; outline: 1px dashed rgba(37, 99, 235, .35); }
.ln:hover { background: rgba(37, 99, 235, .12); outline: 1.5px solid #2563eb; }
.ln-edit { position: absolute; background: #fff; white-space: pre; outline: 2px solid #2563eb; padding: 0 2px; margin-left: -2px; z-index: 2;
  font-family: Helvetica, Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.ob.sel { outline: 1.5px dashed #2563eb; outline-offset: 1px; }
.ob.txt { white-space: pre; line-height: 1.2; outline-offset: 2px; min-width: 6px; font-family: Helvetica, Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif; transform-origin: 0 0; }
.ob.txt:focus { outline: 1.5px solid #2563eb; }
.ob img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ob .rs { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: #2563eb; border: 2px solid #fff; border-radius: 50%; cursor: nwse-resize; }
.select-mode .ob { cursor: move; }
.select-mode .ov { touch-action: pan-x pan-y pinch-zoom; }
.pnum { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); }

.busy { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); display: grid; place-items: center; z-index: 100; }
.busy-box { background: var(--panel); padding: 24px 32px; border-radius: 14px; text-align: center; box-shadow: var(--shadow); min-width: 220px; }
.spinner { width: 32px; height: 32px; margin: 0 auto 10px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #1c2430; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 110; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.err { background: #b42318; }

@media (max-width: 760px) {
  .top { padding: 10px 16px; gap: 12px; }
  .topnav { display: none; }
  main { padding: 20px 16px 40px; }
  .hero h1 { font-size: 26px; }
  .ed { grid-template-columns: 1fr; }
  .ed-side { flex-direction: row; max-height: none; position: static; overflow-x: auto; }
  .th { flex: 0 0 110px; }
  .ed-bar { position: static; }
  .ed-pages { padding: 10px; }
  .opts input[type=text] { min-width: 0; width: 100%; }
}
