/* =========================================================
   LEAD CAPTURE POPUP
   — matches The Story So Far PDF cover aesthetic
   — 15s delay + exit-intent fallback
   — session-scoped dismissal (no repeat annoyance per visit)
   ========================================================= */

.popup-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 22, 0.68);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  overflow-y: auto;
}
.popup-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.popup {
  background: var(--fog);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: 580px;
  width: 100%;
  padding: 2.5rem 2.25rem 2rem;
  position: relative;
  overflow: hidden;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.35);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}
.popup-backdrop.is-open .popup { transform: translateY(0) scale(1); }

/* Subtle purple halo top-right */
.popup::before {
  content: "";
  position: absolute;
  top: -30%; right: -35%;
  width: 130%; height: 130%;
  background: radial-gradient(circle at 65% 35%, var(--royal-ghost-2) 0%, transparent 45%);
  pointer-events: none;
}
.popup > * { position: relative; z-index: 1; }

.popup-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--steel);
  z-index: 2;
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.popup-close:hover {
  color: var(--royal);
  border-color: var(--royal);
  transform: rotate(90deg);
}
.popup-close svg { width: 14px; height: 14px; }

.popup-label {
  font-family: var(--f-mono);
  font-size: var(--step--1);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--royal);
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
}
.popup-label::before {
  content: "";
  width: 1.5rem;
  height: 1px;
  background: var(--royal);
  display: inline-block;
}

.popup h2 {
  font-family: var(--f-serif);
  font-weight: 400;
  font-size: clamp(1.7rem, 2vw + 1rem, 2.4rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 0.85rem;
  max-width: 22ch;
}
.popup h2 em {
  color: var(--royal);
  font-style: italic;
  font-weight: 500;
}

.popup-sub {
  font-family: var(--f-serif);
  font-style: italic;
  font-size: var(--step-1);
  line-height: 1.35;
  color: var(--charcoal);
  margin-bottom: 1.5rem;
  max-width: 40ch;
}

.popup-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.25rem;
}

.popup-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.popup-field label {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--steel);
  font-weight: 500;
}

.popup-field input {
  padding: 0.75rem 0.9rem;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--f-sans);
  font-size: var(--step-0);
  color: var(--ink);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.popup-field input:focus {
  outline: none;
  border-color: var(--royal);
  background: var(--fog);
  box-shadow: 0 0 0 3px var(--royal-ghost-2);
}
.popup-field input::placeholder { color: var(--steel); opacity: 0.7; }
.popup-field input:invalid:not(:placeholder-shown):not(:focus) {
  border-color: var(--blood);
}

.popup-consent {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-top: 0.5rem;
  font-size: var(--step--1);
  color: var(--charcoal);
  line-height: 1.4;
  cursor: pointer;
}
.popup-consent input {
  margin-top: 2px;
  accent-color: var(--royal);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}
.popup-consent span { user-select: none; }

.popup-submit {
  margin-top: 0.75rem;
  padding: 0.95rem 1.4rem;
  background: var(--royal);
  color: var(--fog);
  border: none;
  border-radius: 2px;
  font-family: var(--f-sans);
  font-size: var(--step-0);
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.25s ease;
  box-shadow: 0 8px 24px -12px var(--royal);
}
.popup-submit:hover:not(:disabled) {
  background: var(--royal-deep);
  transform: translateY(-1px);
  box-shadow: 0 12px 32px -10px var(--royal);
}
.popup-submit:disabled {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}
.popup-submit svg { width: 1em; height: 1em; transition: transform 0.2s ease; }
.popup-submit:hover:not(:disabled) svg { transform: translateX(3px); }

.popup-foot {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--steel);
  text-align: center;
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-weight: 500;
}

.popup-status {
  min-height: 1.2em;
  font-size: var(--step--1);
  margin-top: 0.4rem;
  line-height: 1.4;
  font-family: var(--f-sans);
}
.popup-status.is-error { color: var(--blood); }
.popup-status.is-ok    { color: var(--royal); }

/* Success state */
.popup-success {
  display: none;
  text-align: left;
  padding: 0.25rem 0 0.5rem;
}
.popup.is-success .popup-form,
.popup.is-success .popup-sub,
.popup.is-success .popup-foot { display: none; }
.popup.is-success .popup-success { display: block; }
.popup-success p {
  font-size: var(--step-1);
  color: var(--charcoal);
  line-height: 1.55;
  margin-bottom: 1rem;
  max-width: 42ch;
}
.popup-success p em {
  color: var(--royal);
  font-style: italic;
  font-family: var(--f-serif);
  font-weight: 500;
}
.popup-success .btn-row { margin-top: 1.5rem; }

@media (max-width: 540px) {
  .popup { padding: 2rem 1.25rem 1.5rem; border-radius: 0; min-height: 100vh; max-height: 100vh; }
  .popup-backdrop { padding: 0; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .popup-backdrop, .popup { transition: opacity 0.2s ease; }
  .popup { transform: none !important; }
}
