:root {
  --navy: #071a3a;
  --ink: #0b172a;
  --blue: #087fe4;
  --gold: #c29b38;
  --paper: #f7f3ea;
  --surface: #fffefa;
  --muted: #596579;
  --line: #d8e2ed;
  --warm-line: #ded5c4;
  --success: #2d8751;
  --danger: #a83838;
  --serif: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  --sans: "Avenir Next", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; background: var(--paper); }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--paper); font-family: var(--sans); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

.sign-header {
  min-height: 76px;
  padding: 0 clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  gap: 24px;
  color: #f9f7f1;
  background: var(--navy);
  border-bottom: 2px solid var(--gold);
}
.sign-brand { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.sign-brand img { width: 190px; height: auto; display: block; }
.sign-header p { margin: 0; padding-left: 24px; border-left: 1px solid rgb(255 255 255 / .42); font: 600 16px/1 var(--serif); }
.backed-by { margin-left: auto; display: grid; justify-items: end; gap: 5px; color: #dce5ef; text-decoration: none; }
.backed-by span { font-size: 9px; letter-spacing: .08em; }
.backed-by img { width: 84px; height: auto; display: block; }

#signing-app { min-height: calc(100vh - 164px); outline: none; }
.loading-state, .error-state, .empty-state {
  min-height: 520px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 40px 24px;
  text-align: center;
}
.loading-line { width: 180px; height: 2px; overflow: hidden; position: relative; background: var(--warm-line); }
.loading-line::after { content: ""; width: 45%; height: 100%; position: absolute; background: var(--blue); animation: load 1.3s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-120%); } to { transform: translateX(240%); } }

.workspace {
  max-width: 1500px;
  margin: 0 auto;
  padding: clamp(30px, 4vw, 58px) clamp(20px, 4vw, 56px) 64px;
}
.flow-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 30px; align-items: end; margin-bottom: 28px; }
.eyebrow { margin: 0 0 10px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .15em; }
.flow-head h1 { margin: 0; font: 600 clamp(27px, 3vw, 42px)/1.28 var(--serif); letter-spacing: .01em; }
.flow-head > div > p:last-child { margin: 12px 0 0; color: var(--muted); line-height: 1.75; }
.step-track { min-width: min(540px, 42vw); display: flex; align-items: flex-start; }
.step { min-width: 0; flex: 1; display: grid; justify-items: center; gap: 7px; position: relative; color: #8490a0; font-size: 11px; text-align: center; }
.step:not(:last-child)::after { content: ""; width: calc(100% - 30px); position: absolute; top: 14px; left: calc(50% + 15px); border-top: 1px solid #c7d1dc; }
.step b { width: 28px; height: 28px; display: grid; place-items: center; position: relative; z-index: 1; background: var(--paper); border: 1px solid #aeb9c5; border-radius: 50%; font-size: 11px; }
.step.is-current { color: var(--navy); font-weight: 800; }
.step.is-current b, .step.is-done b { color: #fff; background: var(--blue); border-color: var(--blue); }
.step.is-done::after { border-color: var(--blue); }

.stage-grid { display: grid; grid-template-columns: minmax(245px, .55fr) minmax(0, 1.45fr); gap: 28px; align-items: start; }
.document-stage { grid-template-columns: minmax(0, 1.65fr) minmax(260px, .55fr); }
.sign-stage { grid-template-columns: minmax(300px, .8fr) minmax(0, 1.2fr); }
.summary-rail, .primary-panel, .document-rail, .signature-panel {
  background: var(--surface);
  border: 1px solid var(--warm-line);
  border-radius: 9px;
}
.summary-rail { padding: 25px; }
.summary-rail h2, .document-rail h2 { margin: 0 0 18px; font: 600 18px/1.4 var(--serif); }
.fact-list { margin: 0; display: grid; gap: 0; }
.fact-list div { padding: 14px 0; border-top: 1px solid var(--line); }
.fact-list div:first-child { border-top: 0; padding-top: 0; }
.fact-list dt { margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.fact-list dd { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.6; overflow-wrap: anywhere; }
.hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
.signer-flow { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--warm-line); }
.signer-flow h3 { margin: 0 0 16px; font-size: 14px; }
.signer-row { min-height: 52px; display: grid; grid-template-columns: 28px 1fr; gap: 12px; position: relative; }
.signer-row:not(:last-child)::after { content: ""; height: 24px; position: absolute; top: 27px; left: 13px; border-left: 1px solid #b9c3cd; }
.signer-row b { width: 28px; height: 28px; display: grid; place-items: center; z-index: 1; color: var(--muted); background: var(--surface); border: 1px solid #aeb9c5; border-radius: 50%; font-size: 11px; }
.signer-row span { display: grid; gap: 2px; align-content: start; font-size: 12px; }
.signer-row small { color: var(--muted); }
.signer-row.is-signed b { color: #fff; background: var(--success); border-color: var(--success); }
.signer-row.is-you b { color: #fff; background: var(--blue); border-color: var(--blue); }

.primary-panel { min-height: 500px; padding: clamp(26px, 4vw, 56px); }
.panel-rule { width: 30px; margin-bottom: 18px; border-top: 2px solid var(--blue); }
.primary-panel h2, .signature-panel h2 { margin: 0; font: 600 clamp(26px, 2.7vw, 40px)/1.3 var(--serif); }
.lead { max-width: 760px; margin: 15px 0 28px; color: var(--muted); line-height: 1.8; }
.notice { margin: 0 0 28px; padding: 18px 20px; display: flex; gap: 15px; align-items: center; background: #f1f6fb; border: 1px solid #d3e0eb; border-radius: 8px; }
.notice-icon { width: 36px; height: 36px; display: grid; place-items: center; flex: none; color: var(--blue); border: 1px solid var(--blue); border-radius: 50%; font-size: 18px; }
.notice p { margin: 0; line-height: 1.55; }
.notice small { color: var(--muted); }
.otp-form label { display: block; margin-bottom: 12px; font-weight: 700; }
.otp-input {
  width: min(100%, 420px);
  min-height: 68px;
  padding: 0 18px;
  color: var(--navy);
  background: #fff;
  border: 1px solid #aac7e4;
  border-radius: 8px;
  font: 600 30px/1 var(--serif);
  letter-spacing: .35em;
  text-align: center;
}
.otp-input:focus, input:focus, textarea:focus, button:focus-visible { outline: 3px solid rgb(8 127 228 / .24); outline-offset: 2px; border-color: var(--blue); }
.form-note { margin: 10px 0 22px; color: var(--muted); font-size: 12px; }
.primary-button, .secondary-button {
  min-height: 52px;
  padding: 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 800;
}
.primary-button { min-width: min(100%, 420px); color: #fff; background: var(--blue); border: 1px solid var(--blue); }
.primary-button:hover { background: #056ec9; }
.primary-button:disabled { cursor: wait; opacity: .58; }
.secondary-button { color: var(--navy); background: transparent; border: 1px solid #9eabb9; }
.text-button { padding: 12px 0; color: var(--blue); background: transparent; border: 0; text-decoration: underline; text-underline-offset: 4px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.inline-error { margin: 18px 0 0; color: var(--danger); font-weight: 700; }
.security-note { margin-top: 34px; padding-top: 24px; border-top: 1px solid var(--warm-line); color: var(--muted); font-size: 12px; line-height: 1.75; }

.pdf-panel { min-height: 680px; overflow: hidden; background: #e9eef3; border: 1px solid var(--warm-line); border-radius: 9px; }
.pdf-toolbar { min-height: 48px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; color: #fff; background: var(--navy); font-size: 12px; }
.pdf-toolbar a { color: inherit; font-weight: 700; }
.pdf-controls { display: flex; align-items: center; gap: 12px; }
.pdf-controls button { width: 32px; height: 32px; color: #fff; background: transparent; border: 1px solid rgb(255 255 255 / .45); border-radius: 5px; }
.pdf-controls button:disabled { cursor: default; opacity: .35; }
.pdf-page-stage { height: 632px; padding: 24px; overflow: auto; display: flex; align-items: flex-start; justify-content: center; background: #dfe3e7; }
.pdf-page-stage.is-loading::after, .signing-page.is-loading::after { content: "読み込み中…"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--navy); background: rgb(247 243 234 / .72); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.pdf-page-stage.is-loading, .signing-page.is-loading { position: relative; }
.pdf-page-stage img { width: auto; max-width: 100%; height: auto; display: block; background: #fff; box-shadow: 0 5px 20px rgb(7 26 58 / .12); }
.pdf-page-stage p { max-width: 420px; margin: auto; color: var(--muted); line-height: 1.8; text-align: center; }
.document-rail { padding: 25px; }
.review-action { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--warm-line); }
.review-action label { display: grid; grid-template-columns: 22px 1fr; gap: 10px; font-size: 13px; line-height: 1.65; }
.review-action input, .consent-list input { width: 18px; height: 18px; accent-color: var(--blue); }
.review-action .primary-button { width: 100%; min-width: 0; margin-top: 18px; }

.identity-panel { padding: 28px; background: var(--surface); border: 1px solid var(--warm-line); border-radius: 9px; }
.identity-panel h2 { margin: 0 0 20px; font: 600 20px/1.4 var(--serif); }
.identity-block { padding: 20px 0; border-top: 1px solid var(--warm-line); }
.identity-block h3 { margin: 0 0 13px; font-size: 14px; }
.identity-block .hash { overflow-wrap: anywhere; }
.identity-block p { margin: 7px 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.consent-list { display: grid; gap: 14px; }
.consent-list label { display: grid; grid-template-columns: 20px 1fr; gap: 11px; font-size: 13px; line-height: 1.6; }
.signature-panel { padding: 28px; }
.signature-tabs { display: flex; margin: 18px 0 14px; }
.signature-tabs button { flex: 1; min-width: 0; min-height: 44px; padding: 8px 10px; color: var(--navy); background: #fff; border: 1px solid var(--warm-line); font-size: 12px; }
.signature-tabs button + button { margin-left: -1px; }
.signature-tabs button:first-child { border-radius: 7px 0 0 7px; }
.signature-tabs button:last-child { margin-left: -1px; border-radius: 0 7px 7px 0; }
.signature-tabs .is-active { color: #fff; background: var(--navy); border-color: var(--navy); }
.canvas-wrap { position: relative; background: #fff; border: 1px solid #b8c5d1; border-radius: 8px; }
#signature-canvas { width: 100%; height: 300px; display: block; touch-action: none; }
.signature-line { position: absolute; right: 30px; bottom: 48px; left: 30px; border-top: 1px solid var(--gold); pointer-events: none; }
.signature-monogram { position: absolute; right: 22px; bottom: 30px; width: 30px; height: 30px; pointer-events: none; }
.clear-signature { margin: 8px 0 18px auto; display: block; padding: 8px 0; color: var(--blue); background: transparent; border: 0; }
.canvas-actions { display: flex; gap: 18px; align-items: center; justify-content: space-between; }
.canvas-actions .clear-signature { margin: 0; min-height: 44px; }
.signature-expanded { overflow: hidden; }
.signature-dialog { width: min(1100px, calc(100vw - 32px)); max-width: none; height: min(800px, calc(100dvh - 32px)); max-height: none; padding: 24px; color: var(--ink); background: var(--surface); border: 1px solid var(--warm-line); border-radius: 9px; }
.signature-dialog[open] { display: flex; flex-direction: column; gap: 16px; }
.signature-dialog::backdrop { background: rgb(7 26 58 / .7); }
.signature-dialog header { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
.signature-dialog h2 { margin: 0; font: 600 23px/1.4 var(--serif); }
.signature-dialog header p, .signature-dialog footer { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
#expanded-canvas-host { flex: 1; min-height: 0; }
#expanded-canvas-host .canvas-wrap, #expanded-canvas-host #signature-canvas { height: 100%; min-height: 0; }
.signature-dialog footer { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
.upload-picker { display: grid; gap: 10px; padding: 22px; color: var(--navy); background: #fff; border: 1px dashed #9eabb9; border-radius: 8px; font-size: 14px; }
.upload-picker span { color: var(--muted); font-size: 12px; }
.upload-picker input { width: 100%; min-width: 0; font-size: 12px; }
.upload-preview { display: grid; justify-items: center; margin: 18px 0; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.upload-preview img { max-width: 100%; width: auto; height: 160px; object-fit: contain; }
.upload-status { color: var(--muted); font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; }
.upload-confirm { display: grid; grid-template-columns: 20px 1fr; gap: 10px; margin-top: 18px; font-size: 13px; line-height: 1.6; }
.upload-confirm input { width: 18px; height: 18px; accent-color: var(--blue); }
.company-seal-panel { margin-top: 24px; }
.company-seal-panel .upload-confirm { min-height: 44px; align-items: start; }
#company-seal-controls { margin-top: 16px; }
#company-seal-preview { gap: 12px; }
#company-seal-name { font-size: 13px; overflow-wrap: anywhere; }
.company-seal-panel .inline-error { color: var(--danger); }
.company-seal-panel .text-button { min-height: 44px; }
.typed-signature { min-height: 300px; display: grid; place-content: center; padding: 30px; background: #fff; border: 1px solid #b8c5d1; border-radius: 8px; }
.typed-signature input { width: min(520px, 70vw); min-height: 64px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--gold); font: 600 32px/1.2 var(--serif); text-align: center; }
.field { display: grid; gap: 8px; margin-top: 16px; font-size: 12px; font-weight: 700; }
.field input, .field textarea { min-height: 48px; padding: 12px 14px; color: var(--ink); background: #fff; border: 1px solid #b8c5d1; border-radius: 7px; }
.irreversible { margin: 24px 0; padding: 16px 18px; color: #755a19; background: #fbf7ec; border: 1px solid #dbc58f; border-radius: 8px; font-size: 12px; line-height: 1.7; }
.signature-panel .primary-button { width: 100%; max-width: none; }
.decline-panel { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--warm-line); }
.decline-panel[hidden] { display: none; }
.decline-panel textarea { width: 100%; min-height: 100px; resize: vertical; }

.complete-grid { display: grid; grid-template-columns: .75fr 1.25fr; gap: 38px; align-items: start; }
.complete-hero { padding: 28px 8px 28px 0; }
.seal-check { width: 92px; height: 92px; display: grid; place-items: center; color: var(--gold); border: 2px solid var(--gold); border-radius: 50%; font-size: 46px; }
.complete-hero h1 { margin: 26px 0 12px; font: 600 clamp(34px, 3.6vw, 48px)/1.25 var(--serif); word-break: keep-all; }
.complete-hero > p { color: var(--muted); line-height: 1.75; }
.complete-card { padding: 28px; background: var(--surface); border: 1px solid var(--warm-line); border-radius: 9px; }
.complete-card h2 { margin: 0 0 20px; font: 600 21px/1.4 var(--serif); }
.progress-count { display: flex; align-items: baseline; justify-content: space-between; padding-bottom: 18px; border-bottom: 1px solid var(--warm-line); }
.progress-count b { font: 600 30px/1 var(--serif); }
.evidence-timeline { margin: 22px 0; padding: 0; display: grid; gap: 18px; list-style: none; }
.evidence-timeline li { display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: center; }
.evidence-timeline b { width: 28px; height: 28px; display: grid; place-items: center; color: #fff; background: var(--success); border-radius: 50%; }
.pending-note { margin: 20px 0; padding: 17px; color: var(--muted); background: #f1f6fb; border: 1px solid #d3e0eb; border-radius: 8px; line-height: 1.7; }

.error-state h1 { margin: 0; font: 600 34px/1.3 var(--serif); }
.error-state p { max-width: 560px; margin: 0; color: var(--muted); line-height: 1.8; }
.error-code { font-family: ui-monospace, monospace; font-size: 12px; }
.sign-footer { min-height: 88px; padding: 20px clamp(20px, 4vw, 64px); display: flex; align-items: center; justify-content: space-between; gap: 24px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--warm-line); font-size: 11px; }
.sign-footer p { margin: 0; display: flex; gap: 12px; align-items: center; }
.sign-footer strong { color: var(--navy); }

[hidden] { display: none !important; }

@media (max-width: 980px) {
  .backed-by span { display: none; }
  .flow-head, .stage-grid, .document-stage, .sign-stage, .complete-grid { grid-template-columns: 1fr; }
  .step-track { min-width: 0; width: 100%; }
  .summary-rail { order: 2; }
  .pdf-panel { min-height: 600px; }
  .pdf-page-stage { height: 552px; }
  .complete-hero { padding-right: 0; }
}

@media (max-width: 640px) {
  .sign-header { min-height: 64px; gap: 14px; }
  .sign-brand img { width: 142px; }
  .sign-header p { padding-left: 14px; font-size: 13px; }
  .backed-by { display: none; }
  .sign-header p { white-space: nowrap; }
  .notice p { min-width: 0; overflow-wrap: anywhere; }
  .field input, .field textarea, .upload-picker input { font-size: 16px; }
  .pdf-controls { flex-wrap: wrap; }
  .pdf-controls button { width: 44px; height: 44px; flex: none; }
  .pdf-toolbar strong { overflow-wrap: anywhere; }
  .complete-hero h1 { word-break: normal; overflow-wrap: anywhere; }
  .progress-count { flex-wrap: wrap; gap: 12px; }
  .complete-card .primary-button { max-width: 100%; padding: 12px 16px; text-align: center; text-wrap: balance; text-decoration: none; }
  .flow-head h1, .complete-hero h1 { text-wrap: balance; }
  .signature-dialog header { flex-wrap: wrap; }
  .signature-tabs button { padding-inline: 6px; }
  .workspace { padding-top: 24px; }
  .flow-head { gap: 22px; }
  .step span { font-size: 9px; }
  .primary-panel, .summary-rail, .document-rail, .signature-panel, .identity-panel, .complete-card { padding: 22px 18px; }
  .pdf-panel { min-height: 540px; }
  .pdf-toolbar { padding-block: 10px; gap: 10px; align-items: flex-start; flex-direction: column; }
  .pdf-page-stage { height: 492px; padding: 12px; }
  .sign-stage { display: flex; flex-direction: column; }
  .identity-panel { order: 2; }
  #signature-canvas, .typed-signature { height: 240px; min-height: 240px; }
  .typed-signature input { width: 100%; min-width: 0; font-size: 25px; }
  .signature-dialog { width: 100vw; height: 100dvh; margin: 0; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border-radius: 0; border: 0; }
  .signature-dialog header { align-items: flex-start; }
  .signature-dialog h2 { font-size: 20px; }
  .signature-dialog header .secondary-button { min-height: 44px; padding: 0 12px; white-space: nowrap; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions > * { width: 100%; }
  .sign-footer { align-items: flex-start; flex-direction: column; }
  .sign-footer p { align-items: flex-start; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@font-face { font-family: "ContractCaveat"; src: url("/sign/assets/fonts/Caveat.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: block; }
.handwriting, .typed-signature input.handwriting { font-family: "ContractCaveat", var(--serif); font-weight: 400; }
.sign-stage.with-document-fields { grid-template-columns: minmax(0, 1.5fr) minmax(310px, 1fr); align-items: start; }
.document-signing-viewer { position: sticky; top: 16px; min-width: 0; border: 1px solid var(--line); background: white; }
.signing-controls { display: grid; gap: 20px; min-width: 0; }
.signing-page { position: relative; }
.signing-page > img { width: 100%; height: auto; display: block; }
#document-fields { position: absolute; inset: 0; }
.document-field { position: absolute; padding: 0 2px; border: 1px dashed var(--blue); background: rgb(8 127 228 / .07); color: var(--ink); font-size: clamp(7px, .9vw, 13px); overflow: hidden; }
.document-field.field-signature { font-size: clamp(14px, 2vw, 32px); white-space: nowrap; line-height: 1; font-kerning: none; font-variant-ligatures: none; }
.document-field:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.document-field svg { display: block; width: 100%; height: 100%; }
.document-field img { width: 100%; height: 100%; object-fit: contain; }
.field-help { margin: 10px 16px; color: var(--muted); font-size: 12px; }
@media (max-width: 850px) { .sign-stage.with-document-fields { grid-template-columns: 1fr; } .document-signing-viewer { position: static; } }
.with-document-fields .typed-signature { display: flex; align-items: center; justify-content: center; min-width: 0; padding: 16px; }
.with-document-fields .typed-signature input { width: 100%; min-width: 0; }
.sign-stage.with-document-fields { display: grid; }
.signing-controls { grid-template-columns: minmax(0, 1fr); }
.signing-controls > *, .signing-controls input { min-width: 0; }
.signing-controls .hash { overflow-wrap: anywhere; }
@font-face { font-family: "ContractKlee"; src: url("/sign/assets/fonts/KleeOne.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: block; }
.handwriting, .typed-signature input.handwriting { font-family: "ContractCaveat", "ContractKlee", var(--serif); }
.with-document-fields .identity-panel { order: 0; }

.lark-login { margin: 20px 0; padding-bottom: 20px; border-bottom: 1px solid var(--line, #e1e5e9); }
.lark-login [role="status"] { font-size: .875rem; line-height: 1.6; }
