:root {
  --ink: #172033;
  --muted: #687086;
  --paper: #f7f8fc;
  --surface: #ffffff;
  --line: #e5e7ef;
  --accent: #635bff;
  --accent-dark: #4f46e5;
  --green: #087a55;
  --shadow: 0 20px 60px rgba(43, 49, 80, .12);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 50% 0, #fff 0, var(--paper) 42%); font-family: "DM Sans", sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.site-header { height: 72px; padding: 0 5vw; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(229,231,239,.8); background: rgba(255,255,255,.82); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 20px; font-weight: 800; letter-spacing: -.04em; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: white; background: linear-gradient(135deg, #786fff, #5147ec); box-shadow: 0 8px 20px rgba(99,91,255,.28); }
.header-actions { display: flex; align-items: center; gap: 18px; }
.free-badge { padding: 6px 10px; border: 1px solid #dddafe; border-radius: 999px; color: var(--accent-dark); background: #f3f2ff; font-size: 11px; font-weight: 700; }
.privacy-pill { color: var(--green); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.privacy-pill span { width: 8px; height: 8px; border-radius: 50%; background: #28a36f; box-shadow: 0 0 0 4px rgba(40,163,111,.12); }

.welcome { max-width: 980px; margin: 0 auto; padding: 8vh 24px 55px; text-align: center; }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; color: var(--accent); font-size: 12px; font-weight: 700; }
h1 { margin: 18px 0; font: clamp(44px, 6vw, 74px)/1.02 "DM Serif Display", serif; letter-spacing: -.035em; }
h1 em { color: var(--accent); font-weight: 400; }
.welcome > p { color: var(--muted); font-size: 18px; }
.upload-card { width: min(620px, 100%); min-height: 210px; margin: 38px auto 0; padding: 36px; border: 1.5px dashed #c5c8d8; border-radius: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(255,255,255,.82); transition: .2s ease; cursor: pointer; box-shadow: 0 8px 35px rgba(56,62,92,.05); }
.upload-card:hover, .upload-card.dragging { border-color: var(--accent); background: white; transform: translateY(-3px); box-shadow: var(--shadow); }
.upload-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; color: white; background: linear-gradient(135deg, #786fff, #5147ec); font-size: 28px; margin-bottom: 10px; box-shadow: 0 10px 25px rgba(99,91,255,.25); }
.upload-card strong { font-size: 18px; }
.upload-card span { color: var(--muted); font-size: 13px; }
.error { min-height: 20px; color: #b42318; font-size: 13px; }

.toolbar { min-height: 82px; padding: 14px 4vw; display: flex; justify-content: space-between; align-items: center; gap: 20px; background: white; border-bottom: 1px solid var(--line); position: sticky; top: 72px; z-index: 15; }
.toolbar > div:first-child { display: flex; flex-direction: column; }
.toolbar-label { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 700; }
.file-name { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-count { color: var(--muted); font-size: 12px; }
.toolbar-actions { display: flex; gap: 10px; }
.button { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; transition: .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button.primary { color: white; background: var(--accent); box-shadow: 0 8px 22px rgba(99,91,255,.24); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { color: var(--ink); background: #f0f1ec; }

.placement-hint { position: fixed; left: 50%; top: 170px; transform: translateX(-50%); z-index: 30; padding: 11px 18px; border-radius: 999px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: 13px; }
.workspace { min-height: calc(100vh - 154px); padding: 38px 300px 80px 30px; background: #eceef4; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 32px; }
.pdf-page { position: relative; overflow: visible; border-radius: 3px; background: white; box-shadow: 0 14px 40px rgba(35,42,70,.16); line-height: 0; }
.pdf-page.placement-mode { cursor: crosshair; outline: 3px solid rgba(232,93,63,.25); }
.pdf-page canvas { display: block; max-width: min(820px, calc(100vw - 170px)); height: auto; }
.page-number { position: absolute; right: 8px; bottom: -24px; color: #778078; font-size: 11px; line-height: 1; }
.placed-signature { position: absolute; width: 180px; height: auto; min-height: 36px; object-fit: contain; cursor: move; border: 1px dashed transparent; user-select: none; touch-action: none; }
.placed-signature.selected { border: 2px solid var(--accent); border-radius: 5px; background: rgba(99,91,255,.05); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }
.properties { width: 255px; padding: 20px; position: fixed; right: 24px; top: 180px; z-index: 10; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.96); box-shadow: var(--shadow); }
.properties-heading { display: flex; justify-content: space-between; align-items: center; }
.properties-heading strong { color: var(--accent); font-size: 12px; }
.properties label { display: block; margin-top: 18px; font-size: 13px; }
.properties input { width: 100%; accent-color: var(--accent); }
.size-stepper { margin-top: 10px; display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 8px; }
.size-stepper button { width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: white; font-size: 20px; font-weight: 700; }
.size-stepper button:hover { color: white; border-color: var(--accent); background: var(--accent); }
.size-presets { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.size-presets button { padding: 7px 3px; border: 0; border-radius: 7px; color: var(--muted); background: #f2f3f7; font-size: 10px; font-weight: 700; }
.size-presets button:hover { color: var(--accent); background: #efeeff; }
.properties-help { margin: 12px 0 0; color: var(--muted); font-size: 10px; }
.delete-button, .text-button { border: 0; padding: 0; color: #b42318; background: none; font-weight: 700; font-size: 13px; }
.delete-button { margin-top: 18px; }

.signature-dialog { width: min(760px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 20px; box-shadow: 0 30px 90px rgba(0,0,0,.25); }
.signature-dialog::backdrop { background: rgba(20,28,23,.64); backdrop-filter: blur(3px); }
.dialog-card { padding: 28px; }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.dialog-header h2 { margin: 5px 0 0; font: 32px "DM Serif Display", serif; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: #f0f1ec; font-size: 25px; }
.tabs { display: flex; gap: 6px; margin: 28px 0 14px; padding: 5px; border-radius: 10px; background: #f1f2ee; }
.tab { flex: 1; padding: 9px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { color: var(--ink); background: white; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.signature-panel { min-height: 250px; position: relative; }
#signatureCanvas { width: 100%; height: 240px; border: 1px solid var(--line); border-radius: 12px; background: repeating-linear-gradient(0deg, white 0, white 58px, #edf0eb 59px); touch-action: none; }
.text-button { position: absolute; right: 12px; top: 12px; }
.name-input { width: 100%; padding: 15px; border: 1px solid var(--line); border-radius: 10px; outline-color: var(--accent); }
.typed-preview { min-height: 170px; display: grid; place-items: center; font: 58px "Brush Script MT", "Snell Roundhand", cursive; border-bottom: 1px solid var(--line); }
.image-panel { padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.image-panel label { display: block; margin-bottom: 15px; font-weight: 700; }
.image-panel img { display: block; max-width: 100%; max-height: 150px; margin: 20px auto 0; }
.dialog-footer { justify-content: flex-end; margin-top: 12px; }
.busy { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 14px; color: white; background: rgba(20,28,23,.78); }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.steps { margin: 44px auto 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: left; }
.steps > div { display: flex; align-items: center; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.65); }
.steps b { width: 30px; height: 30px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; color: var(--accent); background: #efeeff; }
.steps span { display: flex; flex-direction: column; }
.steps strong { font-size: 13px; }
.steps small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.ad-slot { width: min(728px, 100%); min-height: 92px; margin: 35px auto 0; display: grid; place-content: center; border: 1px solid var(--line); border-radius: 12px; color: #a0a5b4; background: rgba(255,255,255,.45); font-size: 11px; }
.ad-slot span { text-transform: uppercase; letter-spacing: .12em; font-size: 8px; }
.ad-slot div { margin-top: 4px; }
.site-footer { min-height: 70px; padding: 20px 5vw; display: flex; justify-content: center; align-items: center; gap: 24px; border-top: 1px solid var(--line); color: var(--muted); background: white; font-size: 11px; }
.site-footer a { color: var(--accent); text-decoration: none; }
.legal-page { width: min(760px, calc(100% - 40px)); margin: 70px auto; padding: 42px; border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: var(--shadow); }
.legal-page h1 { margin: 12px 0 28px; font-size: clamp(40px, 6vw, 64px); }
.legal-page h2 { margin-top: 30px; font-size: 18px; }
.legal-page p { color: var(--muted); line-height: 1.75; }
.legal-page a { color: var(--accent); font-weight: 700; text-decoration: none; }

@media (max-width: 760px) {
  .privacy-pill { display: none; }
  .toolbar { align-items: flex-start; flex-direction: column; position: static; }
  .toolbar-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar-actions .primary { grid-column: 1 / -1; }
  .workspace { padding: 25px 12px 90px; }
  .pdf-page canvas { max-width: calc(100vw - 24px); }
  .properties { left: 12px; right: 12px; top: auto; bottom: 12px; width: auto; }
  .placement-hint { top: 90px; width: calc(100% - 30px); text-align: center; }
  .steps { grid-template-columns: 1fr; }
  .steps > div { padding: 12px; }
  .site-footer { flex-direction: column; gap: 6px; text-align: center; }
}
