:root {
  --gold: #fdb813;
  --gold-deep: #e6a50a;
  --charcoal: #3d454c;
  --ink: #1f2428;
  --muted: #6b737a;
  --line: #e4e7ea;
  --surface: #ffffff;
  --wash: #f7f8f9;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(31, 36, 40, 0.10);
  --radius: 18px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --display: "Source Serif 4", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--wash);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(253, 184, 19, 0.28), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, rgba(61, 69, 76, 0.08), transparent 55%),
    linear-gradient(180deg, #fffef9 0%, #f3f5f7 45%, #eef1f3 100%);
}

.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.15rem 3rem;
}

.fill-progress {
  margin-bottom: 0.9rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(61, 69, 76, 0.08);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(31, 36, 40, 0.06);
}

.fill-progress[hidden] {
  display: none !important;
}

.fill-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--charcoal);
}

#progressPct {
  color: var(--gold-deep);
  flex-shrink: 0;
}

.fill-progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e8ebef;
  overflow: hidden;
}

.fill-progress-bar {
  height: 100%;
  width: 20%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  transition: width 0.35s ease;
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(61, 69, 76, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.45rem 1.35rem 1.25rem;
  animation: rise 0.45s ease-out;
}

.panel[hidden],
.success-panel[hidden] {
  display: none !important;
}

.panel-step {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.panel-step[hidden] {
  display: none !important;
}

.panel-step legend {
  padding: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  color: var(--charcoal);
  margin-bottom: 0.25rem;
}

.panel-lead {
  margin: 0 0 1.15rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.grid {
  display: grid;
  gap: 0.9rem 1rem;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field.full {
  grid-column: 1 / -1;
}

.field span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--charcoal);
  letter-spacing: 0.01em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field textarea {
  resize: vertical;
  min-height: 88px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(253, 184, 19, 0.25);
}

.field.is-invalid input,
.field.is-invalid select,
.field.is-invalid textarea {
  border-color: var(--danger);
}

.field.is-invalid .dob-field {
  border-color: var(--danger);
}

.field-hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.field .opt {
  font-style: normal;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.field select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.2rem;
  cursor: pointer;
}

.field select:disabled {
  background-color: #f3f5f7;
  color: var(--muted);
  cursor: not-allowed;
}

.dob-field {
  position: relative;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.dob-field:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(253, 184, 19, 0.25);
}

.dob-field input[name="dob"] {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  flex: 1;
  min-width: 0;
  padding-right: 0.4rem;
}

.dob-field input[name="dob"]:focus {
  border: 0;
  box-shadow: none;
}

.dob-native {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 46px;
  opacity: 0;
  cursor: pointer;
  border: 0;
  z-index: 2;
}

.dob-cal-btn {
  flex: 0 0 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-left: 1px solid var(--line);
  background: #fafbfc;
  color: var(--charcoal);
  cursor: pointer;
  pointer-events: none;
  transition: background 0.15s, color 0.15s;
  z-index: 1;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1.15rem;
}

.metric {
  background: linear-gradient(180deg, #fffdf6, #fff8e8);
  border: 1px solid rgba(253, 184, 19, 0.35);
  border-radius: 14px;
  padding: 0.85rem 0.8rem;
}

.metric-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7a6420;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.metric-value {
  font-size: 1.05rem;
  color: var(--charcoal);
  word-break: break-word;
}

.summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.summary > div {
  background: var(--wash);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
}

.summary span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
}

.summary strong {
  color: var(--charcoal);
  font-size: 0.98rem;
  word-break: break-word;
}

.terms-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.95rem;
  margin-bottom: 1rem;
  background: #fafbfc;
}

.terms-box summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--charcoal);
}

.terms-body {
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: #4a5157;
  max-height: 220px;
  overflow: auto;
  padding-right: 0.35rem;
}

.terms-body h3 {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.92rem;
  color: var(--charcoal);
}

.terms-body p,
.terms-body ol {
  margin: 0 0 0.55rem;
}

.check {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: var(--charcoal);
}

.check input {
  margin-top: 0.2rem;
  accent-color: var(--gold-deep);
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
}

.sign-block {
  border: 1px dashed rgba(61, 69, 76, 0.28);
  border-radius: 14px;
  padding: 0.75rem;
  background: #fff;
}

.sign-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--charcoal);
}

#sigCanvas {
  width: 100%;
  height: 160px;
  display: block;
  border-radius: 10px;
  background: linear-gradient(180deg, #fbfbfc, #f4f5f6);
  touch-action: none;
  cursor: crosshair;
}

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.form-error {
  margin: 1rem 0 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: var(--danger);
  font-size: 0.9rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.35rem;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1.35rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--ink);
  box-shadow: 0 10px 24px rgba(230, 165, 10, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.03);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--charcoal);
}

.success-panel {
  text-align: center;
  padding: 2rem 1.5rem 1.75rem;
}

.success-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--ink);
  font-size: 1.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 28px rgba(230, 165, 10, 0.35);
}

.success-panel h2 {
  margin: 0 0 0.65rem;
  font-family: var(--display);
  font-size: 1.65rem;
  color: var(--charcoal);
}

.success-lead {
  margin: 0 auto 0.75rem;
  max-width: 28rem;
  color: var(--ink);
  font-size: 1.02rem;
}

.success-note {
  margin: 0 auto 1.25rem;
  max-width: 26rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.success-actions {
  justify-content: center;
}

.site-footer {
  text-align: center;
  padding: 0 1rem 2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 36, 40, 0.48);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 1rem;
}

.overlay[hidden] {
  display: none !important;
}

.overlay-card {
  background: #fff;
  border-radius: 18px;
  padding: 1.4rem 1.5rem;
  width: min(360px, 100%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  animation: rise 0.25s ease-out;
}

.overlay-title {
  font-weight: 700;
  color: var(--charcoal);
  margin-bottom: 0.35rem;
}

.overlay-card p {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.overlay-bar {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  position: relative;
  overflow: hidden;
}

.overlay-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  animation: slide 1.1s linear infinite;
}

@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 720px) {
  .metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 0.75rem 0.7rem calc(2rem + env(safe-area-inset-bottom));
    max-width: 100%;
  }

  .fill-progress {
    padding: 0.7rem 0.8rem;
    border-radius: 12px;
    margin-bottom: 0.7rem;
  }

  .fill-progress-meta {
    font-size: 0.75rem;
    flex-wrap: wrap;
  }

  .panel {
    padding: 1rem 0.85rem 0.9rem;
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(31, 36, 40, 0.08);
  }

  .grid.two,
  .summary,
  .metrics {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column-reverse;
    gap: 0.5rem;
    position: sticky;
    bottom: 0;
    padding-top: 0.75rem;
    background: linear-gradient(180deg, transparent, #fff 28%);
  }

  .btn {
    width: 100%;
    min-height: 48px;
    font-size: 1rem;
  }

  .panel-step legend {
    font-size: 1.15rem;
  }

  .panel-lead {
    font-size: 0.88rem;
  }

  .field input,
  .field select,
  .field textarea {
    font-size: 16px; /* prevent iOS zoom */
    padding: 0.8rem 0.85rem;
  }

  #sigCanvas {
    height: 140px;
  }

  .success-panel {
    padding: 1.5rem 1rem 1.25rem;
  }

  .success-panel h2 {
    font-size: 1.4rem;
  }

  .success-actions .btn {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .shell {
    padding-left: 0.55rem;
    padding-right: 0.55rem;
  }
}
