:root {
  --green: #20a464;
  --green-d: #178a52;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #dfe3e8;
  --bg: #f1f3f5;
  --blue: #2f7cf6;
  --red: #d93b3b;
  --z: 1;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #fff;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; }
.break { word-break: break-all; }

/* ---------- top bar ---------- */
.topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--line); background: #fff;
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 6px; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--ink); }

/* ---------- buttons ---------- */
.btn { border: 1px solid transparent; border-radius: 6px; padding: 8px 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-d); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-lg { padding: 12px 26px; font-size: 16px; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ---------- landing ---------- */
.landing { max-width: 860px; margin: 0 auto; padding: 48px 20px; text-align: center; }
.landing h1 { font-size: 38px; margin: 0 0 10px; }
.lead { font-size: 17px; color: var(--muted); margin: 0 0 30px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  border: 2px dashed #b9c2cc; border-radius: 12px; padding: 48px 20px; cursor: pointer;
  background: #fafbfc; transition: .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--green); background: #effaf4; }
.features { list-style: none; padding: 0; margin: 32px 0 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; text-align: left; }
.features li { border: 1px solid var(--line); border-radius: 10px; padding: 14px; color: var(--muted); font-size: 13px; }
.features b { display: block; color: var(--ink); font-size: 14px; margin-bottom: 2px; }

/* ---------- editor ---------- */
.editor { display: flex; flex-direction: column; height: calc(100vh - 52px); }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 12px; border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap; z-index: 20;
}
.tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 62px;
  padding: 5px 8px; border: 1px solid transparent; border-radius: 6px; background: none; font-size: 12px;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: var(--bg); }
.tool.active { background: #e6f6ee; border-color: #a9dfc4; color: var(--green-d); }
.tool:disabled { opacity: .35; cursor: default; background: none; }
.sep { width: 1px; height: 34px; background: var(--line); margin: 0 6px; }
.dd { position: relative; }
.dd .menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 150px; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; z-index: 40;
}
.dd.open .menu { display: block; }
.dd .menu button { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 5px; }
.dd .menu button:hover, .dd .menu button.active { background: var(--bg); }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom button { width: 30px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 6px; }
.zoom span { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }

.props {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; min-height: 42px;
  padding: 6px 16px; background: #fafbfc; border-bottom: 1px solid var(--line); font-size: 13px;
}
.props-title { font-weight: 600; }
.props-hint { color: var(--muted); }
.prop { display: flex; align-items: center; gap: 6px; }
.prop select, .prop input[type=text] { padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.prop.wide input { width: 260px; }
.prop input[type=color] { width: 30px; height: 26px; padding: 0 2px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.nofill { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.tgl { width: 28px; height: 28px; border: 1px solid var(--line); background: #fff; border-radius: 5px; }
.tgl.on { background: #e6f6ee; border-color: var(--green); }
.prop-del { margin-left: auto; border: 1px solid #f1c4c4; color: var(--red); background: #fff; border-radius: 5px; padding: 4px 10px; }

.pages { flex: 1; overflow: auto; background: var(--bg); padding: 24px 20px 40px; }
.page-wrap { width: max-content; margin: 0 auto 26px; }
.page-bar { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; padding: 0 2px 5px; }
.page-bar button { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.page-bar button:hover { background: #e2e6ea; color: var(--ink); }
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); user-select: none; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page-wrap.deleted .page { opacity: .25; }
.page-wrap.deleted .page::after {
  content: "Page will be removed"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 22px; font-weight: 700; color: var(--red);
}
.layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; transform: scale(var(--z)); }
.textboxes { z-index: 1; display: none; }
.overlay { z-index: 2; pointer-events: none; }
body[data-tool=text] .textboxes { display: block; }
.tbox { position: absolute; cursor: text; border-radius: 1px; }
.tbox:hover { outline: calc(1px / var(--z)) solid var(--blue); background: rgba(47,124,246,.08); }

body[data-tool=text] .page { cursor: text; }
body[data-tool=rect] .page, body[data-tool=ellipse] .page, body[data-tool=line] .page,
body[data-tool=whiteout] .page, body[data-tool=highlight] .page, body[data-tool=link] .page,
body[data-tool=pen] .page, body.placing .page { cursor: crosshair; }

/* ---------- objects ---------- */
.obj { position: absolute; pointer-events: auto; }
body[data-tool=select] .obj { cursor: move; }
.obj.selected { outline: calc(1.5px / var(--z)) dashed var(--blue); outline-offset: calc(2px / var(--z)); }
.obj-text .txt { position: absolute; left: 0; top: 0; transform-origin: 0 0; white-space: pre; outline: none; font-synthesis: none; font-kerning: none; min-width: 40px; min-height: 1.2em; padding: 0; margin: 0; cursor: text; }
body[data-tool=select] .obj-text:not(.selected) .txt { cursor: move; }
.obj-text:hover:not(.selected) { outline: calc(1px / var(--z)) dotted #9bb7e6; }
.obj-image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.obj-highlight { mix-blend-mode: multiply; opacity: .45; }
.obj-link { border: calc(1px / var(--z)) dashed var(--blue); background: rgba(47,124,246,.1); }
.obj svg { position: absolute; left: 0; top: 0; overflow: visible; }
.obj-line { pointer-events: none; }
.obj-line .hit { pointer-events: stroke; stroke: transparent; }
.obj-line.selected { outline: none; }
.h {
  display: none; position: absolute; pointer-events: auto; z-index: 3;
  width: calc(16px / var(--z)); height: calc(16px / var(--z)); border-radius: 50%;
  font-size: calc(12px / var(--z)); line-height: calc(16px / var(--z)); text-align: center;
  font-family: Arial, sans-serif; font-style: normal; font-weight: 700; user-select: none;
}
.obj.selected .h { display: block; }
.h-del { right: calc(-22px / var(--z)); top: calc(-22px / var(--z)); background: var(--red); color: #fff; cursor: pointer; }
.h-rs { right: calc(-9px / var(--z)); bottom: calc(-9px / var(--z)); background: #fff; border: calc(2px / var(--z)) solid var(--blue); cursor: nwse-resize; }
.h-mv { left: calc(-22px / var(--z)); top: calc(-22px / var(--z)); background: var(--blue); color: #fff; cursor: move; }
.obj-line .h-rs { right: auto; bottom: auto; transform: translate(-50%, -50%); }
.obj-line .h-del { right: auto; top: auto; }

.applybar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-top: 1px solid var(--line); background: #fff;
}

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,28,38,.5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-card { position: relative; background: #fff; border-radius: 12px; padding: 24px; width: min(620px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-card h2 { margin: 0 0 16px; font-size: 20px; }
.x { position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 24px; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { border: 0; background: none; padding: 8px 16px; border-bottom: 2px solid transparent; color: var(--muted); }
.tab.active { border-color: var(--green); color: var(--ink); font-weight: 600; }
#sigPad { width: 100%; height: auto; aspect-ratio: 560 / 200; border: 1px solid var(--line); border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair;
  background-image: linear-gradient(to top, transparent 24%, #e3e7eb 24%, #e3e7eb calc(24% + 1px), transparent calc(24% + 1px)); }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatch.active { box-shadow: 0 0 0 2px var(--green); }
#sigText { width: 100%; padding: 10px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 8px; }
.sigfonts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.sigfonts button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 14px 6px; font-size: 26px; }
.sigfonts button.active { border-color: var(--green); background: #effaf4; }
.saved { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.saved:empty { display: none; }
.saved::before { content: "Saved:"; width: 100%; color: var(--muted); font-size: 12px; }
.saved button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px; height: 52px; }
.saved img { height: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 .span2 { grid-column: span 2; }
.grid2 select, .grid2 input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
.result { text-align: center; }
.result img { width: 180px; height: 180px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.result .kv { text-align: left; background: var(--bg); border-radius: 8px; padding: 12px 14px; margin: 14px 0; font-size: 13px; }
.result .kv div { margin: 3px 0; }
.result a { color: var(--blue); word-break: break-all; }
.warn { background: #fff4e5; border: 1px solid #f5c98b; color: #8a5300; border-radius: 8px; padding: 10px 12px; text-align: left; }

.busy { position: fixed; inset: 0; background: rgba(255,255,255,.75); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 200; font-weight: 600; }
.spinner { width: 38px; height: 38px; border: 4px solid #cfe9db; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 300; box-shadow: 0 6px 18px rgba(0,0,0,.25); }

/* ---------- verify page ---------- */
.verify-page { background: var(--bg); min-height: 100vh; }
.verify-wrap { max-width: 720px; margin: 0 auto; padding: 28px 16px 60px; }
.vcard { display: flex; gap: 16px; align-items: flex-start; border-radius: 12px; padding: 20px; margin-bottom: 18px; background: #fff; border: 1px solid var(--line); }
.vcard h1 { margin: 0 0 4px; font-size: 22px; }
.vcard p { margin: 4px 0; }
.vicon { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; font-weight: 800; color: #fff; }
.vcard.good { border-color: #a9dfc4; background: #f0fbf5; }
.vcard.good .vicon { background: var(--green); }
.vcard.bad { border-color: #f1c4c4; background: #fdf3f3; }
.vcard.bad .vicon { background: var(--red); }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.details { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 0 0 16px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.vform { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.vform.inline { flex-direction: row; align-items: flex-end; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.vform label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.vform input[type=text] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 15px; text-transform: uppercase; }

@media (max-width: 700px) {
  .tool span { display: none; }
  .tool { min-width: 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .grid2 .span2 { grid-column: auto; }
  .details { grid-template-columns: 1fr; gap: 2px; }
  .details dd { margin-bottom: 8px; }
  .landing h1 { font-size: 28px; }
}

/* touch: draw instead of scroll when a drawing tool is active */
body:not([data-tool=select]) .page, .obj { touch-action: none; }

/* ---------- font picker ---------- */
.font-btn {
  min-width: 150px; max-width: 220px; text-align: left; padding: 4px 26px 4px 8px; border: 1px solid var(--line);
  border-radius: 5px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7785'/%3E%3C/svg%3E") no-repeat right 8px center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px;
}
.size-in { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; }
.font-pop {
  position: fixed; z-index: 60; width: 320px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18); display: flex; flex-direction: column; max-height: min(480px, 70vh);
}
#fontSearch { margin: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.font-list { overflow: auto; flex: 1; padding: 0 6px 6px; }
.font-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 8px 4px; }
.font-item { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; text-align: left; border: 0; background: none; padding: 7px 8px; border-radius: 5px; }
.font-item:hover { background: var(--bg); }
.font-item.active { background: #e6f6ee; }
.font-item .fn { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-item .fs { font-size: 11px; color: var(--muted); white-space: nowrap; }
.font-empty { padding: 16px; color: var(--muted); text-align: center; }
.font-foot { border-top: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.font-foot button, .font-up { border: 0; background: none; text-align: left; padding: 7px 8px; border-radius: 5px; color: var(--blue); cursor: pointer; font-size: 13px; }
.font-foot button:hover, .font-up:hover { background: var(--bg); }
@media (max-width: 700px) { .font-pop { width: calc(100vw - 16px); } }

/* ---------- draggable verification QR ---------- */
.obj-qr { box-shadow: 0 0 0 calc(1px / var(--z)) rgba(32,164,100,.35); }
.obj-qr svg { width: 100%; height: 100%; display: block; }
.qr-placed { display: flex; flex-direction: column; gap: 8px; background: #effaf4; border: 1px solid #a9dfc4; border-radius: 8px; padding: 10px 12px; color: var(--ink) !important; font-size: 13px; }
.check-inline { display: flex !important; flex-direction: row !important; align-items: center; gap: 6px; color: var(--ink) !important; }
.qr-place-row { display: flex; align-items: flex-end; }
