:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d6d9df;
  --paper: #fffdf8;
  --accent: #b42318;
  --accent-dark: #8f1d14;
  --field: #f8fafc;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f2f4f7;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #f8f8f5 0%, #eef1f4 100%);
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 18px 14px 112px;
}

.letter {
  background: var(--paper);
  border: 1px solid #e4dfd2;
  padding: clamp(20px, 5vw, 46px);
  box-shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
}

.letter h1 {
  margin: 0 0 28px;
  color: #111827;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(25px, 7vw, 38px);
  line-height: 1.24;
  text-align: center;
  letter-spacing: 0;
}

.letter p {
  margin: 0 0 17px;
  font-size: clamp(17px, 4.4vw, 20px);
  line-height: 1.82;
  text-align: justify;
}

.letter .salutation {
  font-weight: 700;
  text-align: left;
}

.letter-footer {
  margin-top: 34px;
  text-align: right;
}

.letter-footer p {
  margin-bottom: 8px;
  text-align: right;
}

.floating-sign-button {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  min-width: 118px;
  min-height: 52px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(180, 35, 24, 0.32);
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  align-items: end;
  background: rgba(16, 24, 40, 0.52);
}

.form-panel {
  width: 100%;
  max-height: min(88vh, 620px);
  overflow: auto;
  border-radius: 18px 18px 0 0;
  background: #fff;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin: 0;
  font-size: 22px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: #344054;
  font-size: 26px;
  line-height: 1;
}

.signature-form {
  display: grid;
  gap: 16px;
}

.signature-form label,
.signature-field {
  display: grid;
  gap: 8px;
}

.signature-form span,
.field-label {
  color: #344054;
  font-weight: 700;
}

.field-label strong {
  margin-left: 6px;
  color: var(--accent);
  font-size: 14px;
}

.field-note {
  display: block;
  margin-top: 6px;
  color: #98a2b3;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

.signature-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  padding: 11px 12px;
  color: #111827;
}

.signature-trigger {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 118px;
  border: 1px dashed #98a2b3;
  border-radius: 10px;
  background: #fbfcfd;
  color: #667085;
}

.signature-trigger img {
  max-width: 100%;
  max-height: 96px;
  object-fit: contain;
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--accent);
  font-size: 15px;
}

.form-message.success {
  color: #067647;
}

.submit-button {
  min-height: 50px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.submit-button:disabled {
  background: #98a2b3;
}

.signature-pad-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #0b0f17;
}

.signature-pad-shell {
  position: fixed;
  inset: 0;
  display: grid;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.signature-landscape-stage {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
}

.signature-canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
}

#signatureCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
  touch-action: none;
}

.signature-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: rgba(102, 112, 133, 0.32);
  font-size: clamp(52px, 16vw, 132px);
  font-weight: 700;
  letter-spacing: 0;
  writing-mode: horizontal-tb;
}

.signature-placeholder.hidden {
  display: none;
}

.signature-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.signature-actions button {
  min-height: 48px;
  border: 1px solid #475467;
  border-radius: 10px;
  color: #fff;
  background: #1d2939;
  font-weight: 700;
}

.signature-actions button span {
  display: inline-block;
}

.signature-actions .confirm {
  border-color: var(--accent);
  background: var(--accent);
}

@media (orientation: portrait) and (max-width: 759px) {
  .signature-pad-shell {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .signature-landscape-stage {
    width: 100%;
    height: 100%;
  }

  .signature-placeholder {
    font-size: clamp(48px, 15vh, 96px);
    transform: rotate(90deg);
    transform-origin: center;
    white-space: nowrap;
  }

  .signature-actions {
    position: static;
    width: 100%;
    transform: none;
    height: 72px;
    align-items: stretch;
  }

  .signature-actions button {
    min-height: 0;
    height: 72px;
    overflow: hidden;
    writing-mode: horizontal-tb;
  }

  .signature-actions button span {
    transform: rotate(90deg);
    transform-origin: center;
    white-space: nowrap;
  }
}

[hidden] {
  display: none !important;
}

@media (min-width: 760px) {
  .modal-backdrop {
    align-items: center;
    padding: 24px;
  }

  .form-panel {
    width: min(520px, 100%);
    margin: 0 auto;
    border-radius: 16px;
  }
}
