:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --line: #e0e4ea;
  --ink: #15181d;
  --muted: #5c6572;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f1;
  --warn: #b45309;
  --warn-soft: #fdf0d5;
  --bad: #b91c1c;
  --bad-soft: #fde2e2;
  --ok: #15803d;
  --ok-soft: #dcf5e4;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --bn: "Noto Sans Bengali", "Kohinoor Bangla", "Nirmala UI", "Vrinda", "Bangla Sangam MN", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1115;
    --surface: #161a20;
    --surface-2: #1d222a;
    --line: #2a313b;
    --ink: #e8ebef;
    --muted: #9aa4b1;
    --accent: #2dd4bf;
    --accent-ink: #032420;
    --accent-soft: #0f2d2a;
    --warn: #fbbf24;
    --warn-soft: #3a2b0b;
    --bad: #f87171;
    --bad-soft: #3a1515;
    --ok: #4ade80;
    --ok-soft: #10301b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--bn);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; font-size: 14px; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-lg { min-height: 48px; font-size: 16px; padding: 0 22px; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }
.btn-danger { color: var(--bad); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 18px; line-height: 1;
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.run { background: var(--accent-soft); color: var(--accent); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.bar.indeterminate > i { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }

.error { color: var(--bad); background: var(--bad-soft); border-radius: 9px; padding: 10px 12px; margin: 12px 0 0; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 12, 16, 0.45); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog p { margin: 0 0 18px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
kbd { font: 12px ui-monospace, monospace; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 18px; font-size: 14px; }

/* Home */
.home { max-width: 760px; margin: 0 auto; padding: 32px 16px 56px; }
.hero h1 { font-size: clamp(26px, 5vw, 36px); line-height: 1.25; margin: 8px 0 12px; }
.hero .lead { color: var(--muted); font-size: 16.5px; margin: 0 0 24px; }
.upload-card { padding: 20px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 36px 16px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { width: 40px; height: 40px; color: var(--accent); margin-bottom: 6px; }
.drop strong { font-size: 17px; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.file-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.quality { border: 0; margin: 18px 0; padding: 0; }
.quality legend { font-weight: 600; margin-bottom: 8px; }
.quality-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quality label { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; }
.quality label small { color: var(--muted); font-size: 12.5px; }
.quality input { position: absolute; opacity: 0; pointer-events: none; }
.quality label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.quality label:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.start-row { display: flex; flex-direction: column; gap: 12px; }
.upload-progress { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.fineprint { color: var(--muted); font-size: 13px; margin: 14px 0 0; }
.section-title { font-size: 17px; margin: 36px 0 12px; }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recent-list a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.recent-list a:hover { background: var(--surface-2); border-radius: var(--radius); }
.recent-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.step { padding: 16px; }
.step b { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); margin-bottom: 8px; }
.step p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.tips { padding: 16px 20px; }
.tips ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.tips li + li { margin-top: 6px; }
footer.site { text-align: center; color: var(--muted); font-size: 13px; padding: 0 16px 32px; }

@media (max-width: 640px) {
  .steps, .quality-options { grid-template-columns: 1fr; }
  .home { padding-top: 20px; }
}

/* Job */
.page-job { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.job-bar .doc { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.job-bar .doc strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-bar .doc span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-actions { display: flex; align-items: center; gap: 6px; }
.save-state { font-size: 12.5px; color: var(--muted); margin-right: 4px; }
.save-state.bad { color: var(--bad); }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
}
.menu-list button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: none; border-radius: 7px; cursor: pointer; font-size: 14px; }
.menu-list button:hover { background: var(--surface-2); }

.processing { display: flex; align-items: center; gap: 16px; padding: 12px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.processing .info { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 6px; }
.processing .info strong { font-size: 14.5px; }
.processing .info span { font-size: 13px; color: var(--muted); }
.notice { margin: 16px; padding: 16px; border-radius: var(--radius); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

.page-strip { display: flex; gap: 6px; padding: 8px 16px; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--surface); scrollbar-width: thin; }
.page-chip {
  position: relative; flex: none; min-width: 44px; height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
}
.page-chip.current { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.page-chip.pending { color: var(--muted); border-style: dashed; cursor: progress; }
.page-chip .dot { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 99px; font-size: 11px; line-height: 18px; background: var(--warn); color: #fff; }
.page-chip .dot.done { background: var(--ok); }

.waiting { flex: 1; display: grid; place-content: center; gap: 16px; padding: 24px; text-align: center; color: var(--muted); }
.waiting .skeleton {
  width: min(300px, 70vw); height: 380px; max-height: 45vh; margin: 0 auto; border-radius: 10px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .waiting .skeleton, .bar.indeterminate > i { animation: none; } }
.tabs { display: none; }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.pane { min-height: 0; display: flex; flex-direction: column; }
.pane + .pane { border-left: 1px solid var(--line); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px 6px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); min-height: 42px; }
.zoom { display: flex; align-items: center; gap: 2px; }
.zoom span { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.scan-scroll { flex: 1; overflow: auto; padding: 16px; background: var(--surface-2); }
.scan-wrap { position: relative; margin: 0 auto; width: 100%; }
.scan-wrap img { display: block; width: 100%; height: auto; border-radius: 4px; box-shadow: var(--shadow); background: #fff; }
.box { position: absolute; border: 2px solid var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); border-radius: 3px; cursor: pointer; padding: 0; }
.box.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 16%, transparent); }
.box.reviewed { border-color: var(--ok); background: transparent; border-style: dashed; opacity: 0.6; }
.box.current { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 2; }

.review-card { margin: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.rc-head { display: flex; align-items: center; gap: 8px; }
.rc-head .count { font-weight: 700; font-size: 14px; }
.rc-head .nav { margin-left: auto; display: flex; gap: 4px; }
.rc-crop { position: relative; border-radius: 8px; overflow: hidden; background: #fff; border: 1px solid var(--line); min-height: 60px; display: grid; place-items: center; }
.rc-crop img { display: block; width: 100%; height: auto; }
.rc-crop .mark { position: absolute; border: 2px solid var(--accent); border-radius: 4px; background: color-mix(in srgb, var(--accent) 10%, transparent); pointer-events: none; }
.rc-edit { display: flex; gap: 8px; }
.rc-edit input {
  flex: 1; min-width: 0; min-height: 46px; padding: 0 12px; font-size: 20px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2);
}
.rc-edit input:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.rc-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.chip { border: 1px dashed var(--accent); color: var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 15px; }
.rc-foot .hint { margin-left: auto; }
.review-done { margin: 12px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--ok-soft); color: var(--ok); border-radius: var(--radius); font-weight: 600; }
.review-done .btn { margin-left: auto; }

.editor { position: relative; flex: 1; min-height: 0; }
.editor textarea, .editor .backdrop {
  position: absolute; inset: 0; margin: 0; border: 0; padding: 16px 18px;
  font: 18px/2 var(--bn); letter-spacing: normal; white-space: pre-wrap; overflow-wrap: break-word;
  overflow-y: scroll; scrollbar-gutter: stable;
}
.editor .backdrop { color: transparent; pointer-events: none; background: var(--surface); }
.editor .backdrop mark { color: transparent; background: var(--warn-soft); border-radius: 3px; }
.editor .backdrop mark.bad { background: var(--bad-soft); }
.editor .backdrop mark.current { background: color-mix(in srgb, var(--accent) 30%, transparent); box-shadow: 0 0 0 2px var(--accent); }
.editor textarea { background: transparent; resize: none; outline: none; caret-color: var(--accent); }

@media (max-width: 860px) {
  .bar-actions .label-wide { display: none; }
  .tabs { display: flex; gap: 4px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
  .tabs button { flex: 1; min-height: 36px; border: 0; border-radius: 8px; background: transparent; font-weight: 600; cursor: pointer; }
  .tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .pane + .pane { border-left: 0; }
  .workspace.show-text .scan-pane, .workspace.show-scan .text-pane { display: none; }
  .review-card { margin: 8px; }
  .rc-foot .hint { display: none; }
  .editor textarea, .editor .backdrop { font-size: 17px; padding: 12px 14px; }
}

/* Login */
.topbar .push { margin-left: auto; }
.login { min-height: calc(100dvh - 60px); display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 6px; }
.login-card label { font-weight: 600; font-size: 14px; }
.login-card input {
  min-height: 46px; padding: 0 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2);
}
.login-card input:focus { border-color: var(--accent); outline: none; background: var(--surface); }
