/* SIGN PDF — how it looks. Phone first: big buttons, plain words, one thing at a time. */
:root {
  --ink: #0b2373; --ink2: #1d3fa6; --paper: #f4f1ea; --card: #ffffff; --text: #1b1f33; --muted: #666b80; --line: #dcd7ca;
  --good: #17703f; --bad: #b3261e; --desk: #cdc8ba;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--text); font: 16px/1.45 var(--sans); overscroll-behavior: none; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; border: 0; background: none; }
button:disabled { opacity: .45; cursor: default; }
b { font-weight: 650; }

.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }   /* vh first: a phone with an older Chrome ignores dvh */
.narrow { width: 100%; max-width: 520px; margin: 0 auto; padding: 18px 18px calc(24px + var(--safe-b)); gap: 14px; }
.lead { font-size: 18px; line-height: 1.4; }
.center { text-align: center; }
.small { font-size: 14px; color: var(--muted); }
.err { color: var(--bad); font-weight: 600; background: #fdecea; border-radius: 10px; padding: 10px 12px; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 6px; font-size: 17px; }
#setupIntro, #setupWork, #setupCheck { display: grid; gap: 14px; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 28px; color: var(--ink); letter-spacing: -.3px; }
.brand img { border-radius: 14px; }
.brand.small h1 { font-size: 22px; }
.brand.small img { border-radius: 10px; }
.homebar { display: flex; align-items: center; justify-content: space-between; }

.btn { display: block; width: 100%; min-height: 48px; padding: 12px 16px; border-radius: 14px; font-weight: 650; text-align: center; line-height: 1.2; }
.btn.big { min-height: 56px; font-size: 17px; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.good { background: var(--good); color: #fff; }
.btn.ghost { background: #fff; color: var(--ink); border: 2px solid var(--ink); }
.btn.ghost.danger { color: var(--bad); border-color: var(--bad); }
.btn.link { color: var(--ink2); text-decoration: underline; min-height: 44px; font-weight: 600; }
.btn:active:not(:disabled) { filter: brightness(.92); }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; font-size: 24px; line-height: 1; color: var(--ink); flex: none; }
.iconbtn.light { color: #fff; }
.iconbtn:active { background: rgba(0, 0, 0, .1); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: grid; gap: 12px; }
.card h2 { font-size: 22px; color: var(--ink); }
.card h3 { font-size: 16px; color: var(--muted); font-weight: 650; }

.sigpaper { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; place-items: center; min-height: 120px;
  background-image: linear-gradient(to bottom, transparent calc(100% - 34px), #d5d2c8 calc(100% - 34px), #d5d2c8 calc(100% - 33px), transparent calc(100% - 33px)); }
.sigpaper canvas, .sigpaper img { max-width: 100%; max-height: 240px; display: block; }
.sigpaper.mini { min-height: 90px; } .sigpaper.mini img { max-height: 110px; }
.slider { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); }
.slider input { width: 100%; accent-color: var(--ink); height: 32px; }

.spin { width: 36px; height: 36px; border-radius: 50%; border: 4px solid #cdd3ea; border-top-color: var(--ink); animation: spin .9s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- the editor */
#editor { height: 100vh; height: 100dvh; min-height: 0; background: var(--desk); }
.topbar { display: flex; align-items: center; gap: 6px; padding: 5px 6px; background: var(--ink); color: #fff; min-height: 54px; flex: none; }
.fname { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage { flex: 1; min-height: 0; overflow: auto; padding: 10px; display: flex; align-items: center; justify-content: center; }
.pagebox { position: relative; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .35); flex: none; }
.pagebox canvas { display: block; width: 100%; height: 100%; }
.stamps { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; }   /* four sides, not inset: older phones */
.stamp { position: absolute; transform: translate(-50%, -50%); touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.stamp::before { content: ""; position: absolute; top: -16px; right: -16px; bottom: -16px; left: -16px; }
.stamp img { display: block; width: 100%; height: auto; pointer-events: none; -webkit-user-drag: none; }
.stamp.sel { outline: 2px dashed var(--ink2); outline-offset: 2px; }
.stamp .handle, .stamp .del { position: absolute; width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; background: var(--ink2); box-shadow: 0 1px 4px rgba(0, 0, 0, .4); touch-action: none; display: none; color: #fff; font-size: 16px; line-height: 24px; text-align: center; }
.stamp.sel .handle, .stamp.sel .del { display: block; }
.stamp .handle { right: -16px; bottom: -26px; cursor: nwse-resize; }               /* far enough out that the two never cover each other, even on the date */
.stamp .del { right: -16px; top: -26px; background: var(--bad); cursor: pointer; }

.pagenav { display: flex; align-items: center; justify-content: center; gap: 6px; background: #e4e0d4; padding: 2px 8px; min-height: 44px; flex: none; }
.navbtn { width: 52px; height: 40px; border-radius: 10px; color: var(--ink); font-size: 18px; }
.navbtn:active { background: rgba(0, 0, 0, .08); }
.pgtext { min-width: 150px; height: 40px; border-radius: 10px; font-weight: 650; color: var(--ink); }
.pgtext:active { background: rgba(0, 0, 0, .08); }
.pagenav.single .navbtn { visibility: hidden; }

.selrow { background: #e4e0d4; padding: 0 10px 6px; min-height: 58px; display: flex; align-items: center; flex: none; }
.hint { font-size: 14px; color: #4b4f62; text-align: center; width: 100%; }
.selbar { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; width: 100%; }
.selbar .btn { min-height: 44px; padding: 8px 6px; font-size: 15px; }
.toolbar { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; padding: 8px 10px calc(10px + var(--safe-b)); background: #fff; border-top: 1px solid var(--line); flex: none; }
.btn.tool { min-height: 54px; font-size: 16px; padding: 8px 6px; }

/* ---------------------------------------------------------------- menus, sheets, messages */
.menu { position: fixed; z-index: 30; min-width: 230px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; padding: 13px 14px; border-radius: 10px; font-size: 16px; }
.menu button:active { background: #eef0f8; }
.menu .menuinfo { padding: 8px 14px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }
.scrim { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 40; background: rgba(15, 20, 40, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: #fff; border-radius: 22px 22px 0 0; padding: 20px 18px calc(18px + var(--safe-b)); display: grid; gap: 12px; max-height: 92vh; max-height: 92dvh; overflow: auto; }
.sheet h2 { font-size: 21px; color: var(--ink); }
.sheet .bigtext { font-size: 24px; font-weight: 700; color: var(--ink); text-align: center; padding: 6px 0; }
.sheet .note { font-size: 14px; color: #5b4a12; background: #fff6d6; border-radius: 10px; padding: 10px 12px; }
.sheet input[type=password], .sheet input[type=number] { width: 100%; min-height: 50px; font: inherit; font-size: 18px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 12px; }
.sheet input:focus { outline: none; border-color: var(--ink2); }
#busy { align-items: center; z-index: 60; }
.busybox { background: #fff; border-radius: 18px; padding: 22px 26px; min-width: 240px; text-align: center; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 70; background: #20243a; color: #fff; padding: 12px 16px; border-radius: 14px; max-width: min(92vw, 460px); text-align: center; font-size: 15px; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); }
.updatebar { position: fixed; left: 0; right: 0; top: 0; z-index: 80; background: #c28a2c; color: #1b1300; font-weight: 700; padding: 14px 16px; text-align: center; }

@media (min-width: 700px) {
  .toolbar { max-width: 640px; width: 100%; margin: 0 auto; border-radius: 16px 16px 0 0; }
  .selrow, .pagenav { justify-content: center; }
  .selbar { max-width: 560px; }
}
