:root {
  --accent: #2d5aeb;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #dcdce0;
  --bg: #f2f2f6;
  --field: #ffd84d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 12px 140px;
}

/* 안내 화면 */
.state {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 0 16px;
}
.state h1 { font-size: 22px; margin: 6px 0 0; }
.state p { margin: 0; color: var(--muted); }
.state .button { margin-top: 18px; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  background: var(--muted);
}
.badge.done { background: #2fb457; }
.badge.warn { background: #e0912a; }

/* 문서 */
.intro { padding: 4px 8px 16px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 14px; }
.intro h1 { margin: 2px 0 0; font-size: 22px; line-height: 1.3; word-break: keep-all; }
.note {
  margin: 12px 0 0;
  padding: 12px 14px;
  background: #fff;
  border-radius: 12px;
  white-space: pre-wrap;
  font-size: 15px;
}

.pages { display: flex; flex-direction: column; gap: 12px; }
.page {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.page canvas { display: block; width: 100%; height: auto; }

.sign-field {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px dashed #c79a00;
  border-radius: 6px;
  background: rgba(255, 216, 77, 0.45);
  color: #6b5200;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  animation: pulse 1.6s ease-in-out infinite;
}
.sign-field.filled {
  border-color: transparent;
  background: transparent;
  animation: none;
}
.sign-field img { width: 100%; height: 100%; object-fit: contain; }
@keyframes pulse {
  50% { background: rgba(255, 216, 77, 0.8); }
}
@media (prefers-reduced-motion: reduce) {
  .sign-field, .spinner { animation: none; }
}

/* 하단 버튼 */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.hint { margin: 0 0 8px; text-align: center; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 10px; max-width: 820px; margin: 0 auto; }

.button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  background: #e6e6eb;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { background: var(--accent); color: #fff; }
.button:disabled { opacity: 0.45; cursor: default; }
.link {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  padding: 6px 2px;
  cursor: pointer;
}

/* 서명 입력 */
dialog {
  width: min(520px, calc(100vw - 24px));
  border: 0;
  border-radius: 20px;
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 12px; font-size: 19px; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
}

.pad-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}
#pad { display: block; width: 100%; height: 190px; touch-action: none; }
#pad-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #b9b9be;
  font-size: 18px;
  pointer-events: none;
}

.consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 8px 0 16px;
  font-size: 14px;
  color: #3a3a3c;
}
.consent input { width: 20px; height: 20px; margin-top: 1px; flex: none; }

#redo-button { flex: 0 0 auto; }
.button { white-space: nowrap; }
.state .button { flex: none; }
