@font-face { font-family: "Great Vibes"; src: url("fonts/great-vibes.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Allura"; src: url("fonts/allura.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Dancing Script"; src: url("fonts/dancing-script.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Sacramento"; src: url("fonts/sacramento.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Mrs Saint Delafield"; src: url("fonts/mrs-saint-delafield.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Homemade Apple"; src: url("fonts/homemade-apple.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
:root {
  --bg: #eef0f4; --panel: #ffffff; --panel2: #f6f7f9; --ink: #1b2130; --muted: #646d7e;
  --line: #d9dde5; --accent: #2457d6; --accent-ink: #fff; --accent-soft: #e6edff;
  --sel: #e0402e; --shadow: 0 1px 2px rgba(16,24,40,.08), 0 8px 24px rgba(16,24,40,.12);
  --ink-blue: #0d33a6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216; --panel: #1b1e25; --panel2: #232730; --ink: #e9ebf0; --muted: #9aa3b2;
    --line: #343a46; --accent: #7aa2ff; --accent-ink: #0b1020; --accent-soft: #263154;
    --sel: #ff7a66; --shadow: 0 1px 2px rgba(0,0,0,.5), 0 10px 28px rgba(0,0,0,.55);
    --ink-blue: #6f94ff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.top {
  flex: none; height: 54px; display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.logo-bg { fill: var(--accent); }
.logo-tick { fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.filename { flex: 1; min-width: 0; text-align: center; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filename.has { color: var(--ink); font-weight: 550; }
.actions { display: flex; align-items: center; gap: 8px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px;
  cursor: pointer; line-height: 1.2; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.big { padding: 11px 22px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.icon-only { padding: 7px 11px; font-size: 18px; line-height: 1; list-style: none; }
.menu { position: relative; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 230px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.menu-pop button:hover:not(:disabled) { background: var(--accent-soft); }
.menu-pop button:disabled { opacity: .45; cursor: default; }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }

/* ---------- layout ---------- */
.work { flex: 1; min-height: 0; display: flex; }
#thumbs {
  flex: none; width: 150px; overflow-y: auto; padding: 12px 10px; background: var(--panel2);
  border-right: 1px solid var(--line); display: none;
}
body.loaded #thumbs { display: block; }
.thumbs-head { position: sticky; top: -12px; z-index: 2; margin: -12px -10px 10px; padding: 10px; background: var(--panel2); }
.thumbs-head .btn { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.thumbs-tip { margin: 6px 4px 0; font-size: 11.5px; color: var(--muted); }
#thumbs.over { outline: 2px dashed var(--accent); outline-offset: -4px; background: var(--accent-soft); }
.thumb { position: relative; margin: 0 0 12px; border: 2px solid transparent; border-left-width: 5px; border-radius: 8px; cursor: grab; }
.thumb.s0 { border-left-color: transparent; }
.thumb.s1 { border-left-color: #d9822b; } .thumb.s2 { border-left-color: #2b9d6b; } .thumb.s3 { border-left-color: #8a5bd0; }
.thumb.s4 { border-left-color: #d0467a; } .thumb.s5 { border-left-color: #2a8fb8; }
.thumb:hover { background: var(--accent-soft); }
.thumb.cur { border-color: var(--accent); background: var(--accent-soft); }
.thumb.s1.cur, .thumb.s2.cur, .thumb.s3.cur, .thumb.s4.cur, .thumb.s5.cur { border-left-width: 5px; }
.thumb.dragging { opacity: .4; }
.thumb.ins-before::before, #thumbList.ins-end::after { content: ""; position: absolute; left: 0; right: 0; top: -8px; height: 3px; border-radius: 2px; background: var(--accent); }
#thumbList { position: relative; }
#thumbList.ins-end::after { top: auto; bottom: 2px; }
.thumb-go { display: block; width: 100%; padding: 6px; text-align: center; cursor: inherit; background: transparent; border: 0; border-radius: 6px; }
.thumb-go canvas { display: block; margin: 0 auto 4px; max-width: 100%; box-shadow: 0 1px 4px rgba(0,0,0,.25); background: #fff; pointer-events: none; }
.thumb-go span { font-size: 12px; color: var(--muted); }
.thumb-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0; line-height: 1; font-size: 15px; border-radius: 50%;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); cursor: pointer; opacity: 0; transition: opacity .12s; }
.thumb:hover .thumb-del, .thumb:focus-within .thumb-del { opacity: 1; }
.thumb-del:hover { background: var(--sel); color: #fff; border-color: var(--sel); }
@media (hover: none) { .thumb-del { opacity: 1; } }

#stage { position: relative; flex: 1; min-width: 0; overflow-x: auto; overflow-y: scroll; outline: 0; scroll-behavior: auto; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 22px 22px 120px; width: max-content; min-width: 100%; }
.page { position: relative; flex: none; background: #fff; box-shadow: var(--shadow); }
.page canvas { display: block; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; touch-action: pan-y pan-x; }
.layer.tool-text { cursor: text; }
.layer.tool-check, .layer.tool-cross { cursor: crosshair; }
.layer.tool-select { cursor: default; pointer-events: none; }
.layer.tool-select .item { pointer-events: auto; }

/* invisible text layer: lets you select and copy the PDF's text (Select tool only) */
.textLayer { position: absolute; inset: 0; overflow: hidden; line-height: 1; text-align: initial; opacity: 1;
  pointer-events: none; user-select: none; -webkit-user-select: none; forced-color-adjust: none; }
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer ::selection { background: rgba(36, 87, 214, .35); color: transparent; }
body.mode-select .textLayer { pointer-events: auto; user-select: text; -webkit-user-select: text; }
.layer.locked { cursor: not-allowed; }
.page .num { position: absolute; left: 50%; bottom: -17px; transform: translateX(-50%); font-size: 11px; color: var(--muted); pointer-events: none; }

.item { position: absolute; user-select: none; -webkit-user-select: none; cursor: move; white-space: pre;
  font-family: Helvetica, Arial, sans-serif; line-height: 1; touch-action: none; }
.item.text { min-width: 6px; min-height: 1em; }
.item.bold { font-weight: 700; }
.item.sel { outline: 1.5px dashed var(--sel); outline-offset: 3px; }
.item[contenteditable="true"] { cursor: text; user-select: text; -webkit-user-select: text; outline: 1.5px solid var(--accent); outline-offset: 3px; background: rgba(255,230,90,.35); touch-action: auto; }
.item svg { display: block; overflow: visible; }
.item.sign img, .ghost img { display: block; max-width: none; -webkit-user-drag: none; user-select: none; pointer-events: none; }
.ghost { position: absolute; pointer-events: none; opacity: .4; display: none; }

/* ---------- empty state ---------- */
#empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; overflow: auto; }
body.loaded #empty { display: none; }
.drop-card {
  width: min(560px, 100%); text-align: center; padding: 34px 30px 28px; background: var(--panel);
  border: 2px dashed var(--line); border-radius: 18px; transition: border-color .15s, background .15s;
}
.drop-card.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-card h1 { margin: 10px 0 4px; font-size: 24px; letter-spacing: -.02em; }
.drop-card p { margin: 0 0 16px; color: var(--muted); }
.drop-doc { fill: var(--panel2); stroke: var(--muted); stroke-width: 2; }
.drop-fold { fill: none; stroke: var(--muted); stroke-width: 2; }
.drop-tick { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.points { list-style: none; margin: 24px 0 0; padding: 0; text-align: left; font-size: 13px; color: var(--muted); display: grid; gap: 8px; }
.points li { padding-left: 14px; position: relative; }
.points li::before { content: ""; position: absolute; left: 0; top: .6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.points b { color: var(--ink); }

/* ---------- floating toolbar ---------- */
.toolbar {
  position: sticky; bottom: 14px; left: 0; right: 0; margin: 0 auto; width: max-content; max-width: calc(100% - 20px);
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; z-index: 20;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar[hidden] { display: none; }
#stage > .toolbar { margin-top: -66px; }
.toolbar .div { width: 1px; height: 26px; background: var(--line); flex: none; }
.seg, .group { display: flex; align-items: center; gap: 4px; flex: none; }
.seg button {
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 52px; padding: 5px 8px 3px;
  background: none; border: 0; border-radius: 9px; cursor: pointer; color: var(--muted);
}
.seg button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.seg button span { font-size: 11px; }
.seg button:hover { background: var(--panel2); color: var(--ink); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.sq { width: 32px; height: 32px; display: grid; place-items: center; background: none; border: 0; border-radius: 8px; cursor: pointer; font-size: 17px; }
.sq:hover:not(:disabled) { background: var(--panel2); }
.sq:disabled { opacity: .35; cursor: default; }
.sq.bold { font-weight: 800; font-family: Georgia, serif; }
.sq.bold[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
output { min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 550; }
.zoom { min-width: 56px; padding: 6px 8px; background: none; border: 0; border-radius: 8px; cursor: pointer; font-variant-numeric: tabular-nums; }
.zoom:hover { background: var(--panel2); }
.sw { width: 28px; height: 28px; padding: 0; display: grid; place-items: center; background: none; border: 2px solid transparent; border-radius: 50%; cursor: pointer; }
.sw i { width: 16px; height: 16px; border-radius: 50%; background: #111; border: 1px solid var(--line); }
.sw[data-color="blue"] i { background: var(--ink-blue); }
@media (prefers-color-scheme: dark) { .sw[data-color="black"] i { background: #e9ebf0; } }
.sw.on { border-color: var(--accent); }

/* ---------- status, toast, drop veil ---------- */
.status {
  flex: none; display: flex; gap: 16px; align-items: center; padding: 6px 14px; font-size: 12.5px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--line);
}
#hint { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
#pageinfo { font-variant-numeric: tabular-nums; }
.priv { white-space: nowrap; }
#toast {
  position: fixed; left: 50%; bottom: 76px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 100;
  background: #1b2130; color: #fff; padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100% - 28px);
  transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.warn { background: #a8321f; }
#dropVeil { pointer-events: none; position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; font-size: 22px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 24%, transparent); color: var(--ink); backdrop-filter: blur(2px); border: 4px dashed var(--accent); }
#dropVeil[hidden] { display: none; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 22px 24px; max-width: 420px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; }
dt { font-weight: 600; white-space: nowrap; }
dd { margin: 0; color: var(--muted); }
dialog form { text-align: right; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  #thumbs { display: none !important; }
  .priv { display: none; }
  .filename { display: none; }
  .actions { margin-left: auto; }
  #pages { padding: 12px 8px 120px; gap: 14px; }
}
@media (max-width: 520px) {
  .zoomgrp, .zoomdiv, .toolbar .div { display: none; }
  .seg button { min-width: 31px; padding: 6px 2px; }
  .seg button span { display: none; }
  .toolbar { gap: 4px; padding: 5px 5px; }
  .sq { width: 28px; }
  .sw { width: 26px; height: 26px; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { body > *:not(#pages) { display: none; } }

/* ---------- signature dialog ---------- */
#signDialog { width: min(660px, calc(100vw - 24px)); max-width: none; }
.fld { display: grid; gap: 6px; font-weight: 600; margin-bottom: 14px; }
.fld input { font: inherit; font-size: 18px; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); color: var(--ink); }
.sigopts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.sigopt { text-align: left; padding: 8px 12px 6px; background: #fff; color: #111; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; overflow: hidden; }
.sigopt:hover { border-color: var(--accent); }
.sigopt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.sigtxt { display: block; font-size: 36px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sigopt small { display: block; color: #667085; font: 11px system-ui, sans-serif; }
.note { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 520px) { .sigopts { grid-template-columns: 1fr; } }
