:root {
  --navy: #1a2740;
  --navy-hover: #243559;
  --gold: #c9a84c;
  --gold-hover: #d8bb63;
  --gold-text: #735710;
  --paper: #f7f5ef;
  --paper-alt: #e8e0cd;
  --ink: #1f2430;
  --soft-ink: #454d60;
  --hairline: rgba(135,104,24,.25);
  --bar-h: 64px;
  --head-h: 60px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; color: var(--navy); }

.brand {
  height: var(--head-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--navy); color: #fff;
}
.brand img { width: 40px; height: 40px; }
.brand strong { font-family: Georgia, serif; font-weight: 500; font-size: 18px; letter-spacing: .02em; }
.brand span { display: block; font-size: 12px; color: var(--gold); letter-spacing: .08em; text-transform: uppercase; }

/* ---------- start screen ---------- */
.start { width: 100%; max-width: 680px; margin: 0 auto; padding: 32px 20px 56px; }
.start h1 { font-size: 34px; line-height: 1.2; margin: 8px 0 8px; }
.lead { color: var(--soft-ink); font-size: 18px; margin: 0 0 24px; }
.steps { padding-left: 1.4em; margin: 0 0 28px; }
.steps li { margin: 0 0 8px; padding-left: 4px; }
.steps li::marker { color: var(--gold-text); font-weight: 700; }

.pick { font-size: 22px; margin: 0 0 12px; }
.forms { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-card {
  font: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px; border-radius: 12px;
  background: #fff; border: 1px solid var(--hairline); border-left: 4px solid var(--gold);
  color: var(--ink);
}
.form-card strong { font-family: Georgia, serif; font-weight: 500; font-size: 18px; color: var(--navy); line-height: 1.25; }
.form-card span { font-size: 14px; color: var(--soft-ink); }
.form-card:hover { border-color: var(--gold); background: #fffdf5; }
.form-card:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.form-card[aria-busy="true"], .form-card:disabled { opacity: .55; cursor: progress; }
body:not(.ready) .drop { opacity: .55; cursor: progress; }
.which { font-size: 14px; color: var(--soft-ink); margin: 10px 0 24px; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 22px 16px;
  border: 2px dashed var(--hairline); border-radius: 12px;
  background: transparent; cursor: pointer; text-align: center;
}
.drop.over { background: #fbf6e6; border-style: solid; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { outline: 3px solid var(--navy); outline-offset: 2px; }
.hint { color: var(--soft-ink); font-size: 14px; }
.error { color: #9b1c1c; background: #fdecec; border-radius: 8px; padding: 10px 14px; }

.private { margin-top: 28px; padding: 18px 20px; border-left: 3px solid var(--gold); background: var(--paper-alt); border-radius: 0 8px 8px 0; }
.private h2 { font-size: 19px; margin: 0 0 6px; }
.private p { margin: 0; color: var(--soft-ink); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 15px; font-weight: 600;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; line-height: 1.2;
  min-height: 40px;
}
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.gold:hover:not(:disabled) { background: var(--gold-hover); }
.btn.gold:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--navy); border-color: var(--hairline); }
.btn.ghost:hover { border-color: var(--gold); }
.btn.link { background: none; color: var(--gold-text); text-decoration: underline; padding-left: 6px; padding-right: 6px; }
.btn.sq { width: 40px; padding: 0; font-size: 20px; }
.btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }

/* ---------- working screen ---------- */
.work { position: fixed; top: var(--head-h); left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; }
.bar {
  min-height: var(--bar-h);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: #fff; border-bottom: 1px solid var(--hairline);
}
.fname { font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 200px; min-width: 0; }
.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.zoom { display: inline-flex; gap: 4px; }
.notice { margin: 0; padding: 10px 16px; background: #fbf6e6; border-bottom: 1px solid var(--hairline); font-size: 14px; }

.viewer-wrap { position: relative; flex: 1; min-height: 0; }
/* pdf.js needs its container absolutely positioned */
#viewerContainer { position: absolute; inset: 0; overflow: auto; background: #d9d4c7; }
.pdfViewer { padding: 12px 0 40px; }
.pdfViewer .page { box-shadow: 0 2px 10px rgba(26,39,64,.18); }

/* signature boxes laid over the form */
.sig-spot {
  position: absolute; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--gold); border-radius: 4px;
  background: rgba(252,244,214,.92);
  color: var(--navy); font: 600 13px/1.1 system-ui, sans-serif;
  cursor: pointer; padding: 0 6px; overflow: visible; white-space: nowrap;
}
.sig-spot:hover, .sig-spot:focus-visible { background: #f6e7b4; outline: none; border-style: solid; }
.sig-spot .who { opacity: .75; font-weight: 500; margin-left: 6px; }
.sig-spot.signed { background: rgba(255,255,255,.55); border: 1px solid rgba(201,168,76,.6); justify-content: flex-start; }
.sig-spot.signed img { position: absolute; left: 4px; bottom: 1px; max-height: 130%; max-width: 70%; pointer-events: none; }
.sig-spot.signed .change { position: absolute; right: 4px; bottom: 2px; font-size: 11px; color: var(--gold-text); text-decoration: underline; }
.sig-spot.flash { animation: flash 1.2s ease-out 1; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(201,168,76,.9); } 100% { box-shadow: 0 0 0 14px rgba(201,168,76,0); } }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(26,39,64,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.sheet { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; padding: 22px 22px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.sheet h2 { margin: 0 0 4px; font-size: 24px; }
.sub { margin: 0 0 12px; color: var(--soft-ink); }
.padbox { position: relative; width: 100%; height: 200px; border: 1px solid var(--hairline); border-radius: 10px; background: #fffdf7; }
#padCanvas {
  position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; border-radius: 10px;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='M3 25l2-7L19 4l5 5-14 14z' fill='%23c9a84c' stroke='%231a2740' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M3 25l2-7 5 5z' fill='%231a2740'/%3E%3C/svg%3E") 3 25, crosshair;
}
.padbox .line { position: absolute; left: 7%; right: 7%; bottom: 46px; border-bottom: 1.5px solid var(--gold); pointer-events: none; }
.padbox .x { position: absolute; left: 3%; bottom: 48px; color: var(--gold-text); font-size: 18px; pointer-events: none; }
.consent { font-size: 13px; color: var(--soft-ink); margin: 12px 0 14px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.btn.dl { display: block; text-align: center; text-decoration: none; padding: 13px 16px; font-size: 17px; }
.savedname { font-weight: 600; color: var(--navy); background: var(--paper); padding: 8px 12px; border-radius: 8px; word-break: break-word; }

@media (max-width: 640px) {
  :root { --head-h: 54px; }
  .brand { padding: 0 16px; }
  .start { padding: 22px 16px 40px; }
  .start h1 { font-size: 27px; }
  .lead { font-size: 16px; }
  .forms { grid-template-columns: 1fr; }
  .form-card strong { font-size: 17px; }
  .bar { padding: 8px 12px; gap: 8px; }
  /* phone toolbar: row 1 = file name + "Open a different form"; row 2 = zoom + a full-width Save */
  .tools { display: contents; }
  .fname { order: 0; flex: 1 1 0; font-size: 14px; }
  #another { order: 1; font-size: 13px; white-space: nowrap; min-height: 32px; padding-right: 0; }
  .bar::after { content: ""; order: 2; flex-basis: 100%; height: 0; }  /* forces the line break */
  .zoom { order: 3; }
  #save { order: 4; flex: 1; white-space: nowrap; }
  #toSign { display: none; }
  .sheet { padding: 18px 16px 14px; }
  .sheet h2 { font-size: 21px; }
  .padbox { height: 170px; }
  .actions .btn { flex: 1 1 auto; }
  .actions .grow { display: none; }
  .sig-spot { font-size: 11px; }
  .sig-spot .who { display: none; }
}
