:root {
  --ink: #f7f3ea;
  --ink-muted: rgba(247, 243, 234, 0.62);
  --paper: rgba(255, 255, 255, 0.06);
  --cream: rgba(212, 175, 55, 0.12);
  --white: rgba(18, 18, 18, 0.55);
  --gold: #d4af37;
  --gold-bright: #f0d78c;
  --gold-deep: #a68523;
  --copper: var(--gold);
  --copper-dark: var(--gold-deep);
  --copper-soft: rgba(212, 175, 55, 0.22);
  --line: rgba(240, 215, 140, 0.22);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(255, 255, 255, 0.12);
  --success: #8fd4a8;
  --error: #ff8a80;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --font-display: "Cormorant Garamond", "Times New Roman", serif;
  --font-body: "Source Sans 3", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  color-scheme: dark;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background-color: #070707;
  background-image:
    radial-gradient(1000px 560px at 8% -12%, rgba(212, 175, 55, 0.28), transparent 55%),
    radial-gradient(780px 480px at 110% 8%, rgba(240, 215, 140, 0.12), transparent 50%),
    radial-gradient(700px 420px at 50% 120%, rgba(212, 175, 55, 0.08), transparent 55%),
    linear-gradient(180deg, #121212 0%, #070707 55%, #050505 100%);
  background-attachment: fixed;
  line-height: 1.55;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 28%),
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.05), transparent 32%);
}

.page {
  position: relative;
  z-index: 1;
  width: min(1120px, 100%);
  margin: 32px auto 56px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand svg {
  display: block;
  filter: drop-shadow(0 8px 16px rgba(212, 175, 55, 0.28));
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--gold-bright);
}

.brand-tag {
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.contract-chip {
  font-size: 0.8rem;
  color: var(--gold-bright);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 22px;
  align-items: start;
}

.card {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
}

.contract-card {
  padding: 28px 28px 22px;
}

.kicker {
  margin: 0 0 6px;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}

h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.7rem);
  font-weight: 600;
  line-height: 1.15;
  color: #fff8e8;
}

.lede {
  margin: 0 0 18px;
  color: var(--ink-muted);
}

.terms {
  max-height: min(52vh, 520px);
  overflow-y: auto;
  padding: 18px 18px 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 16px;
  scroll-behavior: smooth;
}

.terms h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-bright);
}

.terms p,
.terms li {
  font-size: 0.95rem;
  color: rgba(247, 243, 234, 0.82);
}

.terms ol {
  padding-left: 1.15rem;
}

.sign-card {
  padding: 26px;
  position: sticky;
  top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

label {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
input[readonly] {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  min-height: 48px;
  outline: none;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px var(--copper-soft);
  background: rgba(255, 255, 255, 0.1);
}

.canvas-wrap {
  border: 1px dashed rgba(240, 215, 140, 0.45);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.18)),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(212, 175, 55, 0.12) 28px
    );
  overflow: hidden;
}

#signature-canvas {
  display: block;
  width: 100%;
  height: 190px;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.canvas-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}

.hint {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-ghost,
.btn-primary {
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--gold-bright);
  border-color: var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.btn-ghost:hover {
  color: #fff;
  border-color: var(--gold);
  background: rgba(212, 175, 55, 0.12);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, #f0d78c 0%, #d4af37 52%, #b8941f 100%);
  color: #14110a;
  border-color: rgba(255, 232, 170, 0.55);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 10px 24px rgba(212, 175, 55, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #ffe7a8 0%, #e0bc48 55%, #c9a227 100%);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.consent input {
  margin-top: 3px;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: var(--gold);
}

.pdf-toolbar {
  display: none;
  gap: 8px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}

.sign-dock {
  margin-top: 4px;
}

#sign-panel {
  scroll-margin-top: 12px;
}

a.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.status {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.status.is-visible {
  display: block;
}

.status.is-success {
  background: rgba(143, 212, 168, 0.16);
  color: var(--success);
  border: 1px solid rgba(143, 212, 168, 0.28);
}

.status.is-error {
  background: rgba(255, 138, 128, 0.14);
  color: var(--error);
  border: 1px solid rgba(255, 138, 128, 0.28);
}

.success-panel {
  display: none;
  text-align: center;
  padding: 18px 8px 6px;
}

.success-panel.is-visible {
  display: block;
}

.success-panel h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 8px 0 6px;
  color: var(--gold-bright);
}

.ref {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: rgba(212, 175, 55, 0.14);
  color: var(--gold-bright);
  display: inline-block;
  padding: 6px 10px;
  border-radius: 10px;
  margin-top: 8px;
  border: 1px solid var(--line);
}

.form-body.is-hidden {
  display: none;
}

.narrow-card {
  max-width: 560px;
}

.stack-form {
  margin-top: 8px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.optional {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: rgba(247, 243, 234, 0.45);
}

input[readonly] {
  color: var(--ink-muted);
}

.pdf-frame {
  width: 100%;
  height: min(62vh, 640px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.35);
}

.link-panel {
  margin: 0 0 22px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.link-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.link-row input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.btn-ghost.btn-small,
.btn-small {
  padding: 7px 12px;
  font-size: 0.8rem;
  width: auto;
}

.btn-danger {
  color: #ffb4ab;
  border-color: rgba(255, 138, 128, 0.38);
}

.btn-danger:hover {
  color: #fff;
  border-color: #ff8a80;
  background: rgba(255, 138, 128, 0.16);
}

.delete-form {
  margin: 0;
}

.btn-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 220px;
  text-decoration: none;
  text-align: center;
}

.records-card {
  margin-top: 22px;
}

.section-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
  color: #fff8e8;
}

.table-wrap {
  overflow-x: auto;
}

.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.records th,
.records td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.records th {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  text-transform: capitalize;
  border: 1px solid transparent;
}

.badge-pending {
  background: rgba(212, 175, 55, 0.14);
  color: var(--gold-bright);
  border-color: var(--line);
}

.badge-signed {
  background: rgba(143, 212, 168, 0.14);
  color: var(--success);
  border-color: rgba(143, 212, 168, 0.28);
}

.badge-expired {
  background: rgba(255, 138, 128, 0.12);
  color: var(--error);
  border-color: rgba(255, 138, 128, 0.28);
}

.steps {
  margin: 0 0 22px;
  padding-left: 1.2rem;
}

.steps li {
  margin-bottom: 12px;
}

.steps strong {
  display: block;
  color: var(--gold-bright);
}

.steps span {
  color: var(--ink-muted);
}

.steps a {
  color: var(--gold-bright);
}

.callout {
  margin-top: 8px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink-muted);
  font-size: 0.95rem;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.instruct-list {
  margin: 0 0 16px;
  padding-left: 1.2rem;
}

.instruct-list li {
  margin-bottom: 10px;
  color: rgba(247, 243, 234, 0.82);
}

.contract-card a:not(.btn-primary):not(.btn-ghost) {
  color: var(--gold-bright);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: rgba(212, 175, 55, 0.12);
  color: var(--gold-bright);
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.records td {
  word-break: break-word;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .page {
    margin: 16px auto 32px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .sign-card {
    position: static;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .contract-card {
    padding: 20px 16px 16px;
  }

  .brand-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 18px;
  }

  .brand-name {
    font-size: 1.3rem;
  }

  .contract-chip {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  h1 {
    font-size: clamp(1.65rem, 7vw, 2.2rem);
  }

  .pdf-toolbar {
    display: flex;
  }

  .pdf-frame {
    height: min(42vh, 360px);
  }

  #signature-canvas {
    height: min(46vw, 260px);
    min-height: 180px;
  }

  .field-grid,
  .link-row {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .link-row .btn-ghost {
    width: 100%;
  }

  .sign-dock {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 8px -16px 0;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(7, 7, 7, 0), rgba(10, 10, 10, 0.78) 28%);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .btn-inline {
    width: 100%;
    min-width: 0;
  }

  .btn-ghost.btn-small,
  .btn-small {
    min-height: 44px;
    padding: 10px 14px;
  }

  .records thead {
    display: none;
  }

  .records,
  .records tbody,
  .records tr,
  .records td {
    display: block;
    width: 100%;
  }

  .records tr {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.04);
  }

  .records td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 0;
    padding: 8px 0;
  }

  .records td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
    flex-shrink: 0;
  }

  .records td[data-label="Delete"] .btn-danger,
  .records td[data-label="Link"] .btn-ghost,
  .records td[data-label="File"] .btn-ghost {
    width: auto;
    min-width: 110px;
  }

  .canvas-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .pdf-frame {
    height: 34vh;
  }

  .hint {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .terms {
    scroll-behavior: auto;
  }

  html {
    scroll-behavior: auto;
  }
}
