:root {
  --purple: #5852FF;
  --purple-dark: #3B35D9;
  --purple-tint: #F4F3FF;
  --purple-light: #CCCAFF;
  --black: #101011;
  --gray: #6B6B75;
  --gray-2: #9C9CA4;
  --bg: #F2F2F8;
  --border: #E8EAF2;
  --green: #2F9E5B;
  --white: #FFFFFF;
  --red: #E5484D;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--black);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--purple-dark); }
.hidden { display: none !important; }

/* Header */
.top {
  height: 60px; background: var(--white); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  position: sticky; top: 0; z-index: 10;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--black); }
.logo-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--purple); display: flex; align-items: center; justify-content: center; }
.logo-name { font-size: 16px; font-weight: 700; }
.secure { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--green); }

/* Buttons */
.btn {
  height: 56px; border-radius: 100px; border: none; padding: 0 24px; width: 100%;
  font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  text-decoration: none; transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--purple); color: var(--white); }
.btn-primary:disabled { background: var(--purple-light); cursor: default; }
.btn-light { background: var(--bg); color: var(--black); }
.btn-dark { background: var(--black); color: var(--white); }
.btn-white { background: var(--white); color: var(--black); }
.link-btn { background: none; border: none; color: var(--gray); font-size: 13px; font-weight: 600; padding: 8px; }

/* Sign page layout */
.layout { display: flex; flex-direction: column; min-height: calc(100vh - 60px); }
.intro { background: var(--white); padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.who { display: flex; align-items: center; gap: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 20px; background: var(--purple-light); color: var(--purple-dark); font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.who-title { font-size: 17px; font-weight: 600; line-height: 22px; }
.who-sub { font-size: 13px; color: var(--gray); margin-top: 2px; }
.bubble { border-radius: 4px 16px 16px 16px; background: var(--bg); padding: 10px 12px; font-size: 14px; line-height: 20px; white-space: pre-wrap; }

.doc { flex: 1; padding: 16px 14px 24px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.page-wrap { position: relative; width: 100%; max-width: 620px; background: var(--white); border-radius: 6px; box-shadow: 0 8px 24px rgba(16,16,17,0.10); overflow: hidden; }
.page-wrap img.page { display: block; width: 100%; height: auto; }
.page-num { position: absolute; top: 8px; right: 8px; height: 24px; padding: 0 9px; border-radius: 100px; background: rgba(16,16,17,0.72); color: var(--white); font-size: 11px; font-weight: 600; display: flex; align-items: center; }
.field {
  position: absolute; border: 2px dashed var(--purple); background: rgba(244,243,255,0.88); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; color: var(--purple-dark); font-size: 13px; font-weight: 700;
  box-shadow: 0 0 0 6px rgba(88,82,255,0.14); cursor: pointer; animation: pulse 2s ease-in-out infinite;
}
.field.signed { border: none; background: transparent; box-shadow: none; animation: none; cursor: default; }
.field img { max-width: 100%; max-height: 100%; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 4px rgba(88,82,255,0.12); } 50% { box-shadow: 0 0 0 10px rgba(88,82,255,0.05); } }

.bar { background: var(--white); padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); position: sticky; bottom: 0; z-index: 5; }
.bar-note { font-size: 13px; color: var(--gray); text-align: center; }
.fine { font-size: 11px; line-height: 16px; color: var(--gray-2); text-align: center; }
.fine button { font-size: 11px; color: var(--gray-2); text-decoration: underline; background: none; border: none; padding: 0; }

.side { display: none; }

/* Sheet / modal */
.scrim { position: fixed; inset: 0; background: rgba(16,16,17,0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--white); border-radius: 28px 28px 0 0; padding: 12px 18px calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; max-height: 94vh; overflow: auto; }
.handle { width: 36px; height: 4px; border-radius: 2px; background: #D6D6DE; align-self: center; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); }
.seg button { height: 40px; border-radius: 10px; border: none; background: transparent; font-size: 14px; font-weight: 600; color: var(--gray); }
.seg button.on { background: var(--white); color: var(--black); box-shadow: 0 1px 4px rgba(16,16,17,0.10); }
.pad { position: relative; height: 170px; border-radius: 18px; border: 1.5px solid var(--border); background: #FCFCFE; touch-action: none; }
.pad canvas { width: 100%; height: 100%; display: block; border-radius: 18px; }
.pad-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--gray-2); font-size: 14px; pointer-events: none; }
.pad-line { position: absolute; left: 24px; right: 24px; bottom: 38px; height: 1px; background: var(--border); pointer-events: none; }
.pad-clear { position: absolute; right: 10px; top: 8px; border: none; background: none; color: var(--purple); font-size: 13px; font-weight: 600; padding: 6px; }
.input { height: 52px; border-radius: 14px; border: 1.5px solid var(--border); padding: 0 14px; font-family: inherit; font-size: 16px; color: var(--black); width: 100%; outline: none; }
.input:focus { border-color: var(--purple); }
.label { font-size: 13px; font-weight: 600; color: var(--gray); margin-bottom: -4px; }
.inks { display: flex; gap: 10px; align-items: center; }
.ink { width: 30px; height: 30px; border-radius: 15px; border: none; padding: 0; }
.ink.on { box-shadow: 0 0 0 3px var(--white), 0 0 0 5px currentColor; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 12px; line-height: 17px; color: var(--gray); }
.consent input { width: 20px; height: 20px; accent-color: var(--purple); margin: 0; flex-shrink: 0; }
.error { color: var(--red); font-size: 13px; text-align: center; }

/* Done */
.done { max-width: 560px; margin: 0 auto; padding: 22px 18px 28px; display: flex; flex-direction: column; gap: 16px; }
.done-head { display: flex; align-items: center; gap: 12px; }
.ok { width: 46px; height: 46px; border-radius: 23px; background: var(--green); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.done h1 { margin: 0; font-size: 22px; }
.done-sub { font-size: 13px; color: var(--gray); margin-top: 2px; }
.copy-card { border-radius: 26px; background: var(--purple-tint); border: 1.5px solid var(--purple-light); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.copy-card h2 { margin: 0; font-size: 21px; line-height: 26px; }
.copy-row { display: flex; gap: 14px; align-items: center; }
.thumb { width: 100px; flex-shrink: 0; background: var(--white); border-radius: 5px; box-shadow: 0 8px 20px rgba(16,16,17,0.14); position: relative; overflow: hidden; }
.thumb img.page { width: 100%; display: block; }
.thumb .sig { position: absolute; }
.ticks { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: #4A4A55; }
.ticks b { color: var(--black); font-size: 15px; }
.tick { display: flex; align-items: center; gap: 6px; }
.code-box { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 16px; background: var(--white); border: 1.5px solid var(--border); }
.code-box .k { font-size: 12px; color: var(--gray); }
.code-box .v { font-size: 22px; font-weight: 700; letter-spacing: .12em; }
.qr { width: 220px; height: 220px; padding: 14px; background: var(--white); border-radius: 18px; border: 1.5px solid var(--border); }
.qr img { width: 100%; height: 100%; }
.desk-only { display: none; }
.center-msg { max-width: 460px; margin: 60px auto; padding: 0 20px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.center-msg h1 { margin: 0; font-size: 24px; }
.center-msg p { margin: 0; color: var(--gray); line-height: 22px; }
.spinner { width: 34px; height: 34px; border-radius: 17px; border: 3px solid var(--purple-light); border-top-color: var(--purple); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Desktop */
@media (min-width: 960px) {
  .top { padding: 0 32px; height: 64px; }
  .layout { flex-direction: row; min-height: calc(100vh - 64px); }
  .intro, .bar { display: none; }
  .doc { padding: 28px 24px 40px; }
  .side {
    display: flex; flex-direction: column; gap: 16px; width: 380px; flex-shrink: 0;
    background: var(--white); border-left: 1px solid var(--border); padding: 28px;
    position: sticky; top: 64px; height: calc(100vh - 64px); overflow: auto;
  }
  .steps { border-radius: 18px; border: 1.5px solid var(--border); padding: 6px 16px; }
  .step { display: flex; align-items: center; gap: 12px; min-height: 40px; font-size: 14px; font-weight: 600; }
  .step .dot { width: 22px; height: 22px; border-radius: 11px; border: 2px solid #D6D6DE; flex-shrink: 0; }
  .step.s-done .dot { background: var(--purple); border-color: var(--purple); }
  .step.s-now .dot { border-color: var(--purple); box-shadow: inset 0 0 0 4px var(--white); background: var(--purple); }
  .step.s-todo { color: var(--gray-2); }
  .scrim { align-items: center; }
  .sheet { border-radius: 28px; }
  .handle { display: none; }
  .done { max-width: 960px; padding-top: 48px; }
  .done-grid { display: grid; grid-template-columns: 1fr 280px; gap: 40px; align-items: center; background: var(--white); border-radius: 32px; padding: 40px; box-shadow: 0 20px 50px rgba(16,16,17,0.08); }
  .desk-only { display: flex; }
  .mobile-only { display: none !important; }
}
