:root {
  --bg: #1f2228;
  --panel: #2a2e36;
  --panel-2: #323741;
  --line: #3d434f;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.18);
  --danger: #ff5c5c;
  --viewer: #4a4f5a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Bengali", "Nirmala UI", sans-serif;
  user-select: none;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #59606e; background: #3a404b; }
button:disabled, input:disabled, select:disabled { opacity: 0.4; cursor: default; }
button.active { background: var(--accent-soft); border-color: var(--accent); color: #fff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 8px 22px; font-size: 15px; }
select, input[type="number"], input[type="search"], input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.toolbar, .propbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.propbar { background: #262a31; padding: 4px 10px; }
.group { display: flex; align-items: center; gap: 4px; }
.tools { flex-wrap: wrap; }
.propbar label { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.propbar input[type="color"] { width: 30px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.propbar input[type="range"] { width: 64px; }
.propbar { gap: 8px; }
.propbar input[type="number"] { width: 58px; }
#pageNum { width: 56px; text-align: right; }
#search { width: 150px; }
#pDelete:not(:disabled) { border-color: var(--danger); color: #ffb3b3; }

.workspace { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 180px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-tools { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.side-tools button { padding: 3px 6px; font-size: 12px; }
.thumbs { flex: 1; overflow-y: auto; padding: 10px 0; }
.thumb {
  margin: 0 auto 12px;
  width: 132px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}
.thumb .box {
  background: #fff;
  border: 2px solid transparent;
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 4px;
  overflow: hidden;
}
.thumb canvas { display: block; }
.thumb.current .box { border-color: var(--accent); }
.thumb.current { color: var(--text); }
.thumb.drag-over .box { box-shadow: 0 -4px 0 var(--accent); }

.viewer { flex: 1; overflow: auto; background: var(--viewer); position: relative; }
.pages { padding: 20px 0 40px; display: flex; flex-direction: column; align-items: center; gap: 16px; min-width: min-content; }
.page {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  flex: none;
  margin: 0 20px;
}
.page canvas.render { position: absolute; inset: 0; width: 100%; height: 100%; }
.page svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 2; }
.page svg.overlay .obj { pointer-events: visiblePainted; }
.page svg.overlay .obj.fillhit { pointer-events: all; }
.page.drawing svg.overlay { pointer-events: all; cursor: crosshair; }
.page.drawing .textLayer { pointer-events: none; }
.page.edit-mode svg.overlay { pointer-events: all; cursor: default; }
.tool-select .page svg.overlay .obj { cursor: move; }
.editbox { fill: rgba(79, 140, 255, 0.08); stroke: rgba(79, 140, 255, 0.7); stroke-width: 1; stroke-dasharray: 3 2; cursor: text; }
.editbox:hover { fill: rgba(79, 140, 255, 0.22); }
.selbox { fill: none; stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; pointer-events: none; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5; cursor: nwse-resize; pointer-events: all; }
.search-hit { fill: rgba(255, 170, 0, 0.35); pointer-events: none; }
.search-hit.current { fill: rgba(255, 90, 0, 0.5); }
.page .placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #999; font-size: 14px; }

.inline-editor {
  position: absolute;
  z-index: 5;
  min-width: 60px;
  border: 1px solid var(--accent);
  background: rgba(255, 255, 255, 0.97);
  color: #000;
  padding: 0 2px;
  margin: 0;
  resize: none;
  overflow: hidden;
  line-height: 1.2;
  white-space: pre;
  user-select: text;
}

body.drop-target .viewer { outline: 3px dashed var(--accent); outline-offset: -8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #111318; border: 1px solid var(--line); color: var(--text);
  padding: 8px 16px; border-radius: 8px; opacity: 0; transition: 0.2s; pointer-events: none; z-index: 50;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; width: min(420px, calc(100vw - 24px)); max-width: 640px; max-height: calc(100dvh - 24px); overflow-y: auto; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.modal h2 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.modal .body { margin-bottom: 16px; color: var(--muted); }
.modal .body input[type="text"], .modal .body input[type="password"] { width: 100%; margin-top: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal textarea { width: 100%; min-height: 110px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; color: var(--text); font: inherit; user-select: text; resize: vertical; }
.sig-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.sig-pad { background: #fff; border-radius: 6px; display: block; cursor: crosshair; touch-action: none; width: 100%; height: auto; }
.sig-saved { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sig-saved .item { background: #fff; border-radius: 6px; padding: 4px; cursor: pointer; position: relative; border: 2px solid transparent; }
.sig-saved .item:hover { border-color: var(--accent); }
.sig-saved .item img { height: 48px; display: block; }
.sig-saved .item .x { position: absolute; top: -8px; right: -8px; padding: 0 5px; font-size: 11px; border-radius: 10px; }
.sig-type { font-family: "Segoe Script", "Lucida Handwriting", cursive; font-size: 28px; color: #000; background: #fff !important; }

.textLayer {
  position: absolute; text-align: initial; inset: 0; overflow: clip; opacity: 1; line-height: 1;
  -webkit-text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 1;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; user-select: text; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) {
  z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1; --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(0, 100, 255, 0.3); color: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }

#printRoot { display: none; }
@media print {
  @page { margin: 0; }
  body { background: #fff; overflow: visible; height: auto; }
  #app, .toast, #modalRoot { display: none !important; }
  #printRoot { display: block; }
  #printRoot img { display: block; width: 100%; page-break-after: always; break-after: page; }
  #printRoot img:last-child { page-break-after: auto; break-after: auto; }
}

/* ================= Web additions (Ishthan PDF) ================= */
:root { --bkash: #e2136e; --nagad: #f26522; --love: #ff5d8f; }
body.lang-bn { font-size: 14px; }
a { color: var(--accent); }
.modal.wide { width: min(600px, calc(100vw - 24px)); max-width: none; }
.modal .body { color: #c3c9d4; }

/* Header */
.toolbar { flex-wrap: nowrap; gap: 8px; }
.brand { display: flex; align-items: center; gap: 7px; color: var(--text); text-decoration: none; font-size: 16px; white-space: nowrap; margin-right: 4px; }
.brand img { border-radius: 6px; display: block; }
.brand b { color: #ff6b6b; }
.toolbar button { display: inline-flex; align-items: center; gap: 5px; }
.ico { font-size: 14px; line-height: 1; }
.ico.hl { background: #ffeb3b; color: #222; border-radius: 2px; padding: 0 2px; font-size: 12px; font-weight: 600; }
button.accent:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
.support-btn { border-color: #6b3446 !important; color: #ffd0dc; }
.support-btn .ico { color: var(--love); }
.support-btn:hover { background: #4a2633 !important; }

/* Tool strip: one row of tools under the header */
.toolstrip { display: flex; gap: 4px; padding: 5px 10px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.toolstrip button { display: inline-flex; align-items: center; gap: 5px; flex: none; }
.toolstrip button .ico { min-width: 14px; text-align: center; }

/* Landing (shown until a PDF is opened) */
body:not(.has-doc) .doc-only { display: none !important; }
body:not(.has-doc) .viewer { background: var(--bg); }
body.has-doc .landing { display: none; }
.landing { max-width: 980px; margin: 0 auto; padding: 28px 18px 10px; user-select: text; }
.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-size: clamp(26px, 5vw, 42px); margin: 0 0 10px; line-height: 1.2; }
.hero .lead { color: #c3c9d4; font-size: clamp(15px, 2.2vw, 18px); max-width: 680px; margin: 0 auto 22px; line-height: 1.6; }
.dropzone { border: 2px dashed #4a5262; border-radius: 16px; padding: 34px 16px; background: #252930; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 620px; margin: 0 auto; transition: 0.15s; }
body.drop-target .dropzone { border-color: var(--accent); background: var(--accent-soft); }
button.primary.big { font-size: 18px; padding: 14px 34px; border-radius: 10px; font-weight: 600; }
.privacy { color: #b9c7b9; margin: 16px auto 0; max-width: 620px; font-size: 14px; line-height: 1.6; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; margin: 34px 0 10px; }
.feat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; grid-template-columns: 40px 1fr; column-gap: 12px; align-items: start; }
.feat .fi { grid-row: span 2; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: #cfe0ff; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; }
.feat .fi.hl { background: #ffeb3b; color: #222; font-size: 15px; }
.feat h3 { margin: 0 0 3px; font-size: 15px; }
.feat p { margin: 0; color: var(--muted); line-height: 1.5; }
.steps, .faq, .donate-section { margin: 34px 0; }
.landing h2 { font-size: 21px; margin: 0 0 12px; }
.steps ol { margin: 0; padding-left: 22px; line-height: 2; color: #c3c9d4; font-size: 15px; }
.donate-section { background: linear-gradient(135deg, #2c2430, #262a33); border: 1px solid #4a3442; border-radius: 16px; padding: 22px 18px; }
.donate-section > p { margin: 0 0 16px; line-height: 1.6; }
.faq details { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.faq summary { cursor: pointer; font-weight: 600; font-size: 15px; }
.faq details p { color: #c3c9d4; margin: 10px 0 0; line-height: 1.6; }
.foot { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; color: var(--muted); padding: 24px 0 30px; border-top: 1px solid var(--line); margin-top: 20px; }

/* Donation panel */
.pay-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.pay-card { border-radius: 14px; padding: 16px; color: #fff; display: flex; flex-direction: column; gap: 8px; }
.pay-card.bkash { background: linear-gradient(135deg, #e2136e, #b30d57); }
.pay-card.nagad { background: linear-gradient(135deg, #f26522, #c9471a); }
.pay-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pay-name { font-size: 20px; font-weight: 700; }
.pay-tag { font-size: 12px; opacity: 0.9; background: rgba(0, 0, 0, 0.18); border-radius: 20px; padding: 2px 8px; white-space: nowrap; }
.pay-num { font-size: 26px; font-weight: 700; letter-spacing: 1px; user-select: all; font-variant-numeric: tabular-nums; }
.pay-copy { align-self: flex-start; background: rgba(255, 255, 255, 0.95) !important; color: #222 !important; border: 0 !important; font-weight: 600; padding: 7px 14px; }
.pay-steps { margin-top: 14px; color: #c3c9d4; }
.pay-steps-title { font-weight: 600; color: var(--text); }
.pay-steps ol { margin: 6px 0 10px; padding-left: 22px; line-height: 1.8; }
.pay-warn { background: rgba(255, 170, 0, 0.1); border: 1px solid rgba(255, 170, 0, 0.35); color: #ffd58a; border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.5; }
.pay-thanks { margin-top: 10px; color: #ffc2d4; }

/* Touch */
.page svg.overlay .obj { touch-action: none; }
.page.drawing svg.overlay { touch-action: none; }
.viewer { touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
.pages { transform-origin: 0 0; }
.side-back { display: none; }
@media (pointer: coarse) {
  button { padding: 7px 10px; }
  .toolstrip button { padding: 7px 10px; }
  .hide-touch { display: none; }
}

/* Phones and small tablets */
@media (max-width: 760px) {
  .toolbar { padding: 6px 8px; gap: 6px; }
  .brand span { display: none; }
  .toolbar .group button > span:not(.ico) { display: none; }
  .toolbar .group button.accent > span:not(.ico), .support-btn > span:not(.ico) { display: inline; }
  .toolbar .doc-only { gap: 4px; }
  .hide-narrow { display: none !important; }
  body.has-doc .support-btn > span:not(.ico) { display: none; }
  body.has-doc #langBtn { padding-left: 6px; padding-right: 6px; font-size: 12px; }
  body.has-doc .brand { display: none; }
  .toolbar .group button { padding-left: 8px; padding-right: 8px; }
  .toolstrip { padding: 5px 6px; }
  .toolstrip button { flex-direction: column; gap: 2px; font-size: 11px; padding: 5px 7px; min-width: 56px; }
  .toolstrip button .ico { font-size: 16px; }
  .propbar { flex-wrap: nowrap; overflow-x: auto; gap: 10px; padding: 5px 8px; }
  .propbar > * { flex: none; }
  .propbar .spacer { display: none; }
  #search { width: 120px; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; bottom: 0; width: 200px; transform: translateX(-105%); transition: transform 0.2s; box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5); }
  body.side-open .sidebar { transform: none; }
  body.side-open .side-back { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, 0.45); }
  .side-tools button { padding: 6px 8px; font-size: 13px; }
  .pages { padding: 10px 0 30px; gap: 10px; }
  .page { margin: 0 8px; }
  .landing { padding-top: 14px; }
  .dropzone { padding: 26px 12px; }
  .modal { padding: 14px; }
  .modal .actions { flex-wrap: wrap; }
  .toast { bottom: calc(14px + env(safe-area-inset-bottom)); }
}
@media (min-width: 761px) {
  body.side-open .sidebar { display: none; }
}

/* AdSense units on the landing page */
.ad-wrap { margin: 30px 0; text-align: center; min-height: 120px; }
.ad-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; letter-spacing: 0.5px; }
