@font-face { font-family: "Noto Nastaliq Urdu"; font-weight: 400; font-display: swap;
  src: url(fonts/noto-nastaliq-urdu-arabic-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Noto Nastaliq Urdu"; font-weight: 700; font-display: swap;
  src: url(fonts/noto-nastaliq-urdu-arabic-700-normal.woff2) format("woff2"); }

:root {
  --blue: #1a56db; --blue-d: #1446b4; --blue-l: #e8f0ff;
  --ink: #0f172a; --muted: #5b6475; --line: #e2e6ee; --bg: #f5f7fb; --card: #fff;
  --viewer: #e9ecf2;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.btn-primary { white-space: nowrap; background: var(--blue); color: #fff; border: 0; border-radius: 8px; padding: 8px 16px; font-weight: 600; }
.btn-primary:hover { background: var(--blue-d); }
.btn-primary.big { font-size: 18px; padding: 14px 34px; border-radius: 10px; box-shadow: 0 6px 18px rgba(26,86,219,.25); }
.btn-ghost { white-space: nowrap; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; color: var(--ink); }
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-link { background: none; border: 0; color: var(--blue); text-decoration: underline; padding: 6px; }

/* ---------- landing ---------- */
.site-head { display: flex; align-items: center; justify-content: space-between; max-width: 1100px; margin: 0 auto; padding: 18px 20px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-size: 18px; }
.brand b { color: var(--blue); }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; }
.head-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.head-link:hover { color: var(--blue); }
.hero { text-align: center; padding: 30px 16px 10px; max-width: 820px; margin: 0 auto; }
.hero h1 { font-size: clamp(32px, 6vw, 52px); margin: 0 0 10px; letter-spacing: -0.02em; }
.sub { color: var(--muted); font-size: clamp(16px, 2.4vw, 19px); margin: 0 auto 28px; max-width: 640px; line-height: 1.5; }
.drop { background: var(--card); border: 2px dashed #b9c8ec; border-radius: 18px; padding: 36px 16px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; transition: .15s; }
.drop.over { border-color: var(--blue); background: var(--blue-l); }
.drop-hint { color: var(--muted); font-size: 14px; }
.privacy { color: var(--muted); font-size: 14px; margin-top: 16px; }
.features { max-width: 1100px; margin: 30px auto 0; padding: 0 16px; display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.feat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.feat span { font-size: 26px; }
.feat h3 { margin: 10px 0 6px; font-size: 17px; }
.feat p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.site-foot { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 16px 30px; }
.site-foot a { color: var(--blue); text-decoration: none; }

/* ---------- editor ---------- */
#editor { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.brand.small { font-size: 15px; font-weight: 600; }
.brand.small .logo { width: 28px; height: 28px; }
.fname { font-size: 14px; color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp { display: flex; align-items: center; gap: 2px; background: var(--bg); border-radius: 8px; padding: 2px; }
.ib { width: 34px; height: 32px; border: 0; background: transparent; border-radius: 6px; font-size: 18px; color: var(--ink); }
.ib.txt { width: auto; padding: 0 10px; font-size: 13px; }
.ib:hover:not(:disabled) { background: #fff; color: var(--blue); }
.ib:disabled { opacity: .35; cursor: default; }
.zl { font-size: 13px; min-width: 44px; text-align: center; color: var(--muted); }
.spacer { flex: 1; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 40px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15,23,42,.14); padding: 6px; z-index: 30; min-width: 250px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 6px; font-size: 14px; }
.menu button:hover { background: var(--blue-l); color: var(--blue); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.tools { display: flex; gap: 4px; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; align-items: center; }
.tools button { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 7px 12px; border-radius: 8px; white-space: nowrap; font-size: 14px; color: var(--ink); }
.tools button:hover { background: var(--bg); }
.tools button.on { background: var(--blue); color: #fff; }
.colorpick { margin-left: 4px; display: flex; }
.colorpick input { width: 32px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; cursor: pointer; }
.hint { background: var(--blue-l); color: #1e3a8a; font-size: 13px; padding: 6px 14px; border-bottom: 1px solid #d3e0fb; }

.work { flex: 1; display: flex; min-height: 0; }
#thumbs { width: 150px; background: #f0f2f7; border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 0; }
.th { margin: 0 auto 12px; width: 118px; text-align: center; font-size: 12px; color: var(--muted); }
.th .tc { position: relative; background: #fff; border: 2px solid transparent; border-radius: 6px; cursor: pointer; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.th.cur .tc { border-color: var(--blue); }
.th canvas { display: block; width: 100%; }
.th .ta { position: absolute; inset: auto 0 0 0; display: none; justify-content: center; gap: 2px; background: rgba(15,23,42,.75); padding: 3px; }
.th:hover .ta { display: flex; }
.th .ta button { border: 0; background: none; color: #fff; font-size: 13px; padding: 2px 5px; border-radius: 4px; }
.th .ta button:hover { background: rgba(255,255,255,.2); }

#viewer { flex: 1; overflow: auto; background: var(--viewer); }
#pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 20px 12px 60px; min-width: fit-content; }
.pg { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(15,23,42,.18); }
.pg canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pg .ov { position: absolute; inset: 0; touch-action: auto; }
.pg .num { position: absolute; bottom: -17px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
body.t-draw .pg .ov { cursor: crosshair; touch-action: none; }
body.t-text .pg .ov { cursor: text; touch-action: none; }
.ln { position: absolute; border: 1px solid rgba(26,86,219,.35); border-radius: 2px; cursor: text; }
.ln:hover { background: rgba(26,86,219,.12); border-color: var(--blue); }
.sel { position: absolute; border: 1.5px dashed var(--blue); pointer-events: none; }
.sel.highlight { background: rgba(255,230,0,.4); }
.sel.whiteout { background: rgba(255,255,255,.9); }
.ink { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.card { background: #fff; border-radius: 14px; padding: 20px; width: min(520px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.card.wide { width: min(640px, 100%); }
.card h3 { margin: 0 0 12px; }
.card textarea, .card input[type=text] { width: 100%; font: 17px "Segoe UI", "Noto Nastaliq Urdu", system-ui, sans-serif; padding: 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.card textarea:focus, .card input:focus { outline: 2px solid var(--blue); border-color: transparent; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; font-size: 14px; }
.row label { display: flex; align-items: center; gap: 6px; }
.row input[type=number] { width: 70px; padding: 5px; border: 1px solid var(--line); border-radius: 6px; }
.row select { padding: 5px; border: 1px solid var(--line); border-radius: 6px; }
.row input[type=color] { width: 40px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#sigPad { width: 100%; aspect-ratio: 1000/360; border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.filebtn { cursor: pointer; }

#busy { position: fixed; inset: 0; background: rgba(255,255,255,.5); display: grid; place-items: center; z-index: 60; }
.spin { width: 42px; height: 42px; border: 4px solid var(--blue-l); border-top-color: var(--blue); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 70; max-width: calc(100% - 32px); text-align: center; }

@media (max-width: 760px) {
  #thumbs { display: none; }
  .hide-sm { display: none !important; }
  .fname { max-width: 110px; }
  .tools button span { font-size: 13px; }
  .topbar { gap: 6px; padding: 8px; }
  .btn-primary { padding: 8px 12px; }
}
