:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ins: #d9f5e3;
  --ins-text: #0f6b34;
  --del: #fde2e1;
  --del-text: #a4221b;
  --hl: #fff1c2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Microsoft YaHei Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --panel: #171d24; --text: #e6e9ee; --muted: #98a2b3; --line: #2a323c;
    --accent: #6c9cff; --accent-soft: #1d2b45; --ins: #12361f; --ins-text: #7ee2a3;
    --del: #45191a; --del-text: #ff9b94; --hl: #4a3d10; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --panel: #171d24; --text: #e6e9ee; --muted: #98a2b3; --line: #2a323c;
  --accent: #6c9cff; --accent-soft: #1d2b45; --ins: #12361f; --ins-text: #7ee2a3;
  --del: #45191a; --del-text: #ff9b94; --hl: #4a3d10; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; font-size: 16px; white-space: nowrap; }
.brand svg { color: var(--accent); }
.search { position: relative; flex: 1; max-width: 520px; }
.search input {
  width: 100%; height: 36px; padding: 0 64px 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--panel); }
.search kbd { position: absolute; right: 8px; top: 8px; font: 11px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
#search-results {
  position: absolute; left: 0; right: 0; top: 40px; margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 60vh; overflow: auto;
}
#search-results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--accent-soft); }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; }
.only-mobile { display: none; }

/* layout */
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.nav { border-right: 1px solid var(--line); padding: 12px 8px 40px; overflow: auto; position: sticky; top: 56px; height: calc(100vh - 56px); background: var(--panel); }
.nav h2 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 10px 4px; letter-spacing: .02em; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .badge { font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }

main { padding: 20px 24px 40px; min-width: 0; }
.tool-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 12px; }
.tool-head h1 { font-size: 20px; margin: 0; }
.tool-head p { margin: 2px 0 0; }

/* options */
.options { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 12px; }
.opt { display: flex; align-items: center; gap: 6px; }
.opt > label.name { color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 5px 11px; cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.opt > label.name { white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.opt input[type="text"], .opt input[type="number"], .opt select {
  height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: var(--panel); min-width: 0;
}
.opt input[type="number"] { width: 80px; }
.check { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }

/* workspace */
.workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.workspace.single { grid-template-columns: 1fr; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--line); min-height: 40px; }
.pane-head .title { font-weight: 600; font-size: 13px; }
.pane-head .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 3px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
textarea.io, .out {
  flex: 1; width: 100%; min-height: 360px; resize: vertical; border: 0; padding: 12px; background: transparent;
  font: 14px/1.7 var(--mono); white-space: pre-wrap; word-break: break-word; overflow: auto; outline: none;
}
.out { margin: 0; max-height: 70vh; }
.pane-foot { border-top: 1px solid var(--line); padding: 6px 12px; font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.drop-hint { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; padding: 12px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat.main { background: var(--accent-soft); border-color: transparent; }
.stat.main .v { color: var(--accent); }
.words { padding: 0 12px 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; font-size: 12px; }
.chip b { color: var(--accent); font-weight: 600; }

/* diff */
.diff-out ins { background: var(--ins); color: var(--ins-text); text-decoration: none; border-radius: 2px; }
.diff-out del { background: var(--del); color: var(--del-text); border-radius: 2px; }
.sbs { width: 100%; border-collapse: collapse; font: 13px/1.6 var(--mono); table-layout: fixed; }
.sbs td { padding: 1px 8px; vertical-align: top; white-space: pre-wrap; word-break: break-word; border-bottom: 1px solid var(--line); }
.sbs td.ln { width: 42px; color: var(--muted); text-align: right; user-select: none; }
.sbs tr.replace td.l, .sbs tr.delete td.l { background: var(--del); }
.sbs tr.replace td.r, .sbs tr.insert td.r { background: var(--ins); }
.summary { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 12px; font-size: 13px; }
.summary .plus { color: var(--ins-text); } .summary .minus { color: var(--del-text); }

/* marks */
mark.ent { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 1px; }
mark.ent[data-t]::after { content: attr(data-t); font: 10px system-ui; color: var(--muted); margin-left: 2px; }
mark.fix { background: var(--ins); color: var(--ins-text); border-radius: 3px; }
mark.fix s { color: var(--del-text); margin-right: 1px; }

/* qr */
.qr-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 18px; min-height: 360px; }
.qr-wrap img { max-width: 100%; width: 300px; image-rendering: pixelated; border-radius: 6px; background: #fff; }
.qr-drop { border: 2px dashed var(--line); border-radius: 10px; padding: 26px; text-align: center; cursor: pointer; width: 100%; }

.list-out { padding: 8px 12px; }
.piece { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; white-space: pre-wrap; word-break: break-word; position: relative; }
.piece .n { font-size: 11px; color: var(--muted); }
.piece .btn { position: absolute; right: 6px; top: 6px; }

.quick { display: flex; gap: 6px; margin: 0 0 14px; overflow-x: auto; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick a { flex: none; padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 13px; text-decoration: none; white-space: nowrap; }
.quick a:hover { color: var(--text); border-color: var(--muted); }
.quick a.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.ok { background: #22a35a; }
.dot.wait { background: #e0a100; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 8px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .only-mobile { display: inline-block; }
  .search kbd { display: none; }
  .brand span { display: none; }
  .layout { grid-template-columns: 1fr; }
  .nav { position: fixed; left: 0; top: 56px; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .nav.open { transform: none; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
  /* Long option groups scroll sideways instead of wrapping each label */
  .opt { max-width: 100%; }
  .seg { max-width: calc(100vw - 80px); overflow-x: auto; scrollbar-width: none; }
  .seg button { flex: none; }
  .seg::-webkit-scrollbar { display: none; }
  main { padding: 14px 16px 32px; }
  .workspace { grid-template-columns: 1fr; }
  textarea.io, .out { min-height: 220px; }
  .tool-head { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ---------- icons, category colours ---------- */
.ico { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; display: block; }
.ico text { fill: currentColor; stroke: none; font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif; }
.hue-blue { --h: #2563eb; } .hue-teal { --h: #0d9488; } .hue-violet { --h: #7c3aed; } .hue-orange { --h: #ea580c; }
.hue-sky { --h: #0284c7; } .hue-amber { --h: #b45309; } .hue-rose { --h: #e11d48; } .hue-green { --h: #16a34a; }
.hue-indigo { --h: #4f46e5; } .hue-slate { --h: #334155; } .hue-fuchsia { --h: #c026d3; }
.tile, .nav-ico, .dot-cat { --fg: var(--h); --tbg: color-mix(in srgb, var(--h) 11%, var(--panel)); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tile, :root:not([data-theme="light"]) .nav-ico, :root:not([data-theme="light"]) .dot-cat {
    --fg: color-mix(in srgb, var(--h) 55%, #fff); --tbg: color-mix(in srgb, var(--h) 26%, var(--panel));
  }
}
:root[data-theme="dark"] .tile, :root[data-theme="dark"] .nav-ico, :root[data-theme="dark"] .dot-cat {
  --fg: color-mix(in srgb, var(--h) 55%, #fff); --tbg: color-mix(in srgb, var(--h) 26%, var(--panel));
}
.tile { display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; background: var(--tbg); color: var(--fg); flex: none; }
.tile.sm { width: 32px; height: 32px; border-radius: 9px; }
.nav-ico { color: var(--fg); display: inline-flex; }
.nav a { justify-content: flex-start; gap: 9px; }
.nav a .badge { margin-left: auto; }
.tool-head h1 { display: flex; align-items: center; gap: 10px; }

/* ---------- home ---------- */
body[data-view="home"] #quick, body[data-view="home"] .tool-head,
body[data-view="home"] #options, body[data-view="home"] #workspace { display: none; }
body[data-view="tool"] #home { display: none; }
.home { max-width: 1320px; }
.hero { padding: 8px 0 6px; }
.hero h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: .01em; }
.hero p { margin: 0; max-width: 680px; }
.recent { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.recent a { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 9px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--text); text-decoration: none; font-size: 13px; }
.recent a:hover { border-color: var(--accent); color: var(--accent); }
.cats { display: flex; flex-wrap: wrap; gap: 0 20px; }
.cat { flex: 1 1 calc(var(--n) * 250px); max-width: 100%; min-width: min(100%, 250px); }
.cat h2 { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 650; margin: 24px 0 10px; }
.dot-cat { width: 8px; height: 8px; border-radius: 3px; background: var(--fg); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s, box-shadow .15s; }
.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16, 24, 40, .08); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-name { display: flex; align-items: center; gap: 6px; font-weight: 650; font-size: 15px; }
.card-desc { color: var(--muted); font-size: 12.5px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .badge { font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (max-width: 860px) {
  .hero h1 { font-size: 22px; }
  /* Phones: two columns of icon + name; the description is on the tool page itself. */
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 14px 8px 12px; }
  .card-name { justify-content: center; font-size: 14px; }
  .card-desc { display: none; }
  .cat h2 { margin: 18px 0 8px; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } .card:hover { transform: none; } }

/* image to text */
.ocr-text { white-space: pre-wrap; word-break: break-word; }
.ocr-ents { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); }
.ocr-ents .chip { background: none; color: inherit; cursor: pointer; font: inherit; font-size: 12px; }
.ocr-next { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.ocr-next .btn { display: inline-flex; align-items: center; gap: 4px; }
.qr-drop.compact { padding: 12px; }

/* about us / business */
.about { max-width: 760px; padding: 8px 0 24px; }
.about section { margin-bottom: 28px; }
.about h1 { font-size: 22px; margin: 0 0 10px; }
.about p, .about li { line-height: 1.8; }
.about ul { padding-left: 20px; margin: 8px 0; }
.about .btn { margin-left: 8px; vertical-align: middle; }
.site-foot { display: flex; flex-wrap: wrap; gap: 6px 10px; justify-content: center; padding: 28px 12px 18px; margin-top: 24px; border-top: 1px solid var(--line); }
.site-foot a { color: inherit; }

/* usage hints & next-step highlight */
.tip { margin: 4px 0 0; font-size: 12.5px; color: var(--accent); }
.steps { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0; padding: 0; list-style: none; counter-reset: step; font-size: 13px; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 6px; }
.steps li::before { content: counter(step); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; }
.pane.await { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.qr-drop.await { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.qr-drop.await:hover { filter: brightness(0.98); }

/* back to home: visible on every tool page, quieter than the tool's own primary button */
.back-home { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; padding: 2px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; }
.back-home:hover { filter: brightness(0.96); }

/* accounts */
.account-btn { margin-left: auto; max-width: 160px; overflow: hidden; text-overflow: ellipsis; height: 36px; padding: 0 14px; }
.account-btn.signed-in { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); font-weight: 600; }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 25, .45); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { position: relative; width: 100%; max-width: 380px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel);
  border-radius: 12px; padding: 22px 22px 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-card h2 { margin: 0 0 12px; font-size: 18px; }
.modal-x { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.modal-tabs button { flex: 1; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; }
.modal-tabs button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.modal-note { background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; }
.field input { height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--panel); }
.field input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.agree { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 4px 0 8px; }
.form-err { color: #dc2626; font-size: 13px; min-height: 18px; margin: 4px 0; }
.btn.wide { width: 100%; height: 38px; font-size: 14px; }
.btn.danger { color: #dc2626; border-color: #f3b4b4; }
.btn.danger:hover { background: #fdecec; color: #b91c1c; }
.modal-links { text-align: center; margin: 10px 0 0; font-size: 13px; }
.row-btn { display: flex; align-items: center; gap: 8px; margin: -2px 0 10px; }
.login-gate { text-align: center; padding: 28px 12px; }
.login-gate p { margin: 6px 0; }
.account section { margin-bottom: 22px; }
.account h2, .admin h2 { font-size: 16px; margin: 0 0 8px; }
.inline-form { max-width: 380px; }
.inline-form .btn { margin: 0 0 10px; }
.admin { max-width: 1100px; }
.admin-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 640px; margin: 12px 0 16px; }
.admin-search { display: flex; gap: 8px; max-width: 480px; margin-bottom: 12px; }
.admin-search input { flex: 1; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--panel); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.users { border-collapse: collapse; width: 100%; font-size: 13px; }
table.users th, table.users td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.users th { color: var(--muted); font-weight: 600; }
table.users .ops { display: flex; gap: 4px; }
table.users .off { color: #dc2626; }
@media (max-width: 760px) { .account-btn { max-width: 96px; padding: 0 8px; font-size: 12px; } .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
