/* The fit check pop-up. Every Start Free Trial button ([data-trial]) opens it
   (fit-check.js). The page behind dims and blurs; the card is the site's dark
   ribbon (#book's tokens) holding the apply form's fields, so the inputs, error
   line, success mark and buttons are the ones flow.css already draws. Centred
   card on wide screens, a full-screen sheet on phones. Loaded after flow.css. */

html.fit-lock { overflow: hidden; scrollbar-gutter: stable; }   /* the page behind stays put */

/* ---- the layer: a native modal dialog filling the screen ---- */
.fit {
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 24px 16px; border: 0; background: transparent; overflow: hidden;
  display: none; place-items: center;
}
.fit[open] { display: grid; }
.fit::backdrop { background: rgba(22, 22, 19, 0.5); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.fit[open]::backdrop { animation: fit-fade .28s ease both; }
.fit.is-closing::backdrop { animation: fit-fade .2s ease reverse both; }

/* ---- the card: the black ribbon, as on #book ---- */
.fit-card {
  --text: #ffffeb;
  --dim: rgba(255, 255, 235, 0.68);
  --faint: rgba(255, 255, 235, 0.46);
  --line: rgba(255, 255, 235, 0.14);
  --line-strong: rgba(255, 255, 235, 0.3);
  --panel: #242420;
  position: relative; box-sizing: border-box;
  width: min(100%, 540px); max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain;
  padding: clamp(26px, 4vw, 40px);
  border-radius: 36px; background: #161613; color: var(--text);
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.55);
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 235, 0.25) transparent;
  display: grid; align-content: center;   /* the read and the answer sit in the middle of the held height */
}
.fit[open] .fit-card { animation: fit-in .32s cubic-bezier(.22, .61, .36, 1) both; }
.fit.is-closing .fit-card { animation: fit-out .2s ease both; }
@keyframes fit-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fit-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes fit-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(6px) scale(.97); } }

.fit-x {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
  border-radius: 50%; border: 1px solid var(--line-strong); background: #161613; color: var(--text); cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}
.fit-x:hover { background: rgba(255, 255, 235, 0.08); border-color: rgba(255, 255, 235, 0.55); }
.fit-x svg { width: 16px; height: 16px; display: block; }

/* the dark ribbon's buttons and headline colours (as #book) */
.fit .btn-primary { border-color: var(--lav); }
.fit .apply-submit { justify-content: center; }
.fit .h2 { margin: 0; font-size: clamp(2.2rem, 4.6vw, 2.9rem); line-height: 1; padding-right: 44px; }
.fit .h2 .tone { color: rgba(255, 255, 235, 0.4); }
.fit .h2 .swing { color: var(--text); }
.fit-head { display: grid; gap: 10px; margin-bottom: 8px; }
.fit-lead { margin: 0; font-size: 15.5px; line-height: 1.5; color: var(--dim); max-width: 40ch; }
.fit .cta-terms { margin: 4px 0 0; color: rgba(255, 255, 235, 0.6); }

/* ---- the form's own touches (as the homepage's apply form) ---- */
.fit .apply-field input:focus { box-shadow: 0 0 0 3px rgba(255, 88, 32, 0.22); }
.fit .apply-field input[aria-invalid="true"] { border-color: #ffb4a0; }
.fit .apply-done-mark { animation: ad-pop .45s cubic-bezier(.3, 1.5, .5, 1) both; }
.fit .apply-done-mark svg { width: 24px; height: 24px; display: block; }
.fit .apply-done-mark .ad-tick { stroke-dasharray: 30; stroke-dashoffset: 30; animation: ad-tick .4s ease forwards .12s; }
@keyframes ad-pop { 0% { transform: scale(.3); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
@keyframes ad-tick { to { stroke-dashoffset: 0; } }

/* ---- the card's states: form, waiting, a fit, let's talk ---- */
.fc-state[hidden] { display: none !important; }
.fc-state:focus { outline: none; }
.fc-in { animation: fc-in .5s cubic-bezier(.22, .61, .36, 1) both; }
@keyframes fc-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.fc-kicker { margin: 0; font-family: 'Gloria Hallelujah', 'Comic Sans MS', cursive; font-size: 1rem; color: var(--accent-warm-bright); }
.fc-opt { font-family: var(--font-body); font-weight: 400; color: var(--faint); font-size: 12.5px; }

/* waiting: a small page of their website, read line by line */
.fc-wait { display: grid; justify-items: center; gap: 18px; padding: clamp(10px, 2vw, 22px) 0 6px; text-align: center; }
.fc-site { position: relative; width: min(100%, 300px); border-radius: 14px; overflow: hidden; background: #fffdf5; border: 1px solid rgba(255, 255, 235, .3); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .6); animation: fc-site-in .6s cubic-bezier(.22, .61, .36, 1) both; }
@keyframes fc-site-in { from { opacity: 0; transform: translateY(16px) rotate(-2deg) scale(.96); } to { opacity: 1; transform: rotate(-1.5deg); } }
.fc-bar { display: flex; align-items: center; gap: 5px; padding: 9px 11px; background: #f1eee2; border-bottom: 1px solid rgba(26, 26, 26, .08); }
.fc-bar i { width: 7px; height: 7px; border-radius: 50%; background: rgba(26, 26, 26, .18); flex: none; }
.fc-url { margin-left: 8px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 9px; border-radius: 99px; background: #fffdf5; font: 600 11px/1.3 var(--font-body); color: #3d3d3a; text-align: left; }
.fc-page { position: relative; display: grid; gap: 9px; padding: 16px 16px 18px; }
.fc-row { display: flex; gap: 12px; align-items: center; }
.fc-pic { position: relative; overflow: hidden; width: 62px; height: 46px; flex: none; border-radius: 8px; background: #ece6d6; }
.fc-lines { flex: 1; display: grid; gap: 8px; }
.fc-ln { display: block; height: 7px; border-radius: 99px; background: #ece6d6; position: relative; overflow: hidden; }
.fc-ln.t { height: 12px; width: 72%; }
.fc-ln::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--lav); transform: scaleX(0); transform-origin: left; animation: fc-read 4.8s cubic-bezier(.4, 0, .2, 1) infinite; animation-delay: calc(var(--d) * .32s); }
.fc-ln.t::after { background: var(--accent-warm-bright); }
.fc-pic::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, #ffb38a, #ff5820); opacity: 0; animation: fc-pic 4.8s ease infinite; animation-delay: calc(var(--d) * .32s); }
@keyframes fc-read { 0% { transform: scaleX(0); } 22% { transform: scaleX(1); } 78% { transform: scaleX(1); opacity: 1; } 92%, 100% { transform: scaleX(1); opacity: 0; } }
@keyframes fc-pic { 0% { opacity: 0; } 18%, 78% { opacity: .9; } 92%, 100% { opacity: 0; } }
.fc-scan { position: absolute; left: 0; right: 0; top: 0; height: 36px; background: linear-gradient(180deg, rgba(240, 215, 255, 0), rgba(240, 215, 255, .55) 70%, rgba(255, 88, 32, .55) 100%); mix-blend-mode: multiply; pointer-events: none; animation: fc-scan 2.4s cubic-bezier(.45, 0, .55, 1) infinite alternate; }
@keyframes fc-scan { from { transform: translateY(-36px); } to { transform: translateY(150px); } }
.fc-wait-line { margin: 4px 0 0; min-height: 1.3em; font-family: var(--font-display); font-size: clamp(1.35rem, 2.6vw, 1.6rem); letter-spacing: -.02em; color: var(--text); }
.fc-wait-text { display: inline-block; }
.fc-wait-text.swap { animation: fc-in .45s cubic-bezier(.22, .61, .36, 1) both; }
.fc-wait-sub { margin: 0; font-size: 14px; color: var(--dim); max-width: 32ch; }
.fc-dots { display: inline-flex; gap: 3px; margin-left: 2px; }
.fc-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .25; animation: fc-dot 1.2s ease-in-out infinite; }
.fc-dots i:nth-child(2) { animation-delay: .15s; }
.fc-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes fc-dot { 0%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }

/* the answers */
.fc-result { padding: clamp(18px, 3vw, 30px) 4px clamp(8px, 2vw, 16px); gap: 12px; }
.fc-result .fc-line { font-family: var(--font-display); font-size: clamp(1.5rem, 3.4vw, 1.9rem); line-height: 1.15; letter-spacing: -.025em; color: var(--text); margin: 0; max-width: 22ch; }
.fc-result .btn { margin-top: 10px; }
.fc-talk-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: rgba(240, 215, 255, .14); color: var(--lav); margin: 0 0 6px; }
.fc-talk-mark svg { width: 22px; height: 22px; display: block; }

/* ---- phones: a full-screen sheet ---- */
@media (max-width: 600px) {
  .fit { padding: 0; }
  .fit-card {
    width: 100%; height: 100%; max-height: none; border-radius: 0;
    padding: 72px 16px calc(24px + env(safe-area-inset-bottom));
    display: flex; flex-direction: column;
  }
  .fit-card > .fc-wait, .fit-card > .fc-result { margin: auto 0; }
  .fit-x { position: fixed; top: 14px; right: 16px; }
  .fit .h2 { padding-right: 0; }
  .fit .apply-field input { font-size: 16px; }   /* 16px, so phones don't zoom in on the field */
  .fit[open] .fit-card { animation-name: fit-sheet-in; }
  .fit.is-closing .fit-card { animation-name: fit-sheet-out; }
}
@keyframes fit-sheet-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes fit-sheet-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(16px); } }

@media (prefers-reduced-motion: reduce) {
  .fit[open]::backdrop, .fit.is-closing::backdrop, .fit[open] .fit-card, .fit.is-closing .fit-card { animation: none; }
  .fit .apply-done-mark { animation: none !important; }
  .fit .apply-done-mark .ad-tick { animation: none !important; stroke-dashoffset: 0 !important; }
  .fc-in, .fc-site, .fc-wait-text.swap { animation: none !important; }
  .fc-scan { animation: none; opacity: 0; }
  .fc-ln::after, .fc-pic::after { animation: none; }
  .fc-dots i { animation: none; opacity: .6; }
}
