/* Homepage fit section (index.html #outcomes): "Questioning if you're a fit?"
   A navy slab: a short question and the actions on the left (Apply for Free first, View Common
   Questions second), a late-night scene on the right with an iPhone-style thread of the questions
   people ask (fit.js, from questions-data.js, the same list as common-questions.html). On tablets and
   phones the scene sits between the question and the actions.
   --------------------------------------------------------------------------------------------- */

.fit-section {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  margin: 0 var(--slab-inset);
  padding: clamp(64px, 5vw + 24px, 104px) 0 0;
  border-radius: var(--slab-radius);
  background:
    radial-gradient(ellipse 46% 62% at 74% 70%, rgba(36, 126, 198, .18), transparent 70%),
    radial-gradient(ellipse 60% 50% at 12% 0%, rgba(92, 170, 226, .12), transparent 65%),
    linear-gradient(165deg, #0c2843 0%, #081d33 55%, #06172a 100%);
  color: #fff;
  box-shadow: 0 40px 90px -40px rgba(8, 29, 48, .55), 0 12px 30px -18px rgba(8, 29, 48, .35);
}

.fit-section::before {
  content: "";
  position: absolute;
  inset: 0 12% auto;
  z-index: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(190, 228, 255, .4), transparent);
  pointer-events: none;
}

.fit-grid {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  grid-template-areas:
    "copy scene"
    "actions scene";
  grid-template-rows: auto 1fr;
  column-gap: clamp(24px, 3vw, 48px);
}

/* ---- Copy ---- */

.fit-copy {
  grid-area: copy;
  position: relative;
  z-index: 2;
  align-self: end;
  padding-top: clamp(8px, 2vw, 32px);
}

.fit-copy h2 {
  max-width: 12em;
  margin: 0 0 22px;
  color: #fff;
  font-size: clamp(36px, 3.4vw + 6px, 56px);
  line-height: 1.06;
  letter-spacing: -.032em;
  text-wrap: balance;
}

.fit-lead {
  max-width: 22em;
  margin: 0;
  color: #e8f1f9;
  font-size: clamp(18px, .5vw + 14.5px, 21px);
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: -.01em;
  text-wrap: balance;
}

/* ---- Actions: the reassurance, then Apply for Free above View Common Questions ---- */

.fit-actions {
  grid-area: actions;
  position: relative;
  z-index: 2;
  align-self: start;
  padding: 32px 0 clamp(64px, 5vw + 24px, 104px);
}

.fit-note {
  max-width: 26em;
  margin: 0 0 18px;
  color: #b9cfdf;
  font-size: 15px;
  line-height: 1.5;
  text-wrap: pretty;
}

.fit-note strong {
  color: #fff;
  font-weight: 600;
}

/* One column of equal-width buttons: the main path first, the quieter one under it. */
.fit-buttons {
  display: grid;
  width: min(100%, 300px);
  gap: 12px;
}

/* Apply for Free: a soft blue halo breathes out from the edge every few seconds (the same halo as the
   hero's Apply button); the button itself stays still. With reduced motion the glow stays put. */
.fit-apply::before {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(36, 126, 198, .32), 0 0 16px 2px rgba(36, 126, 198, .22);
}

@media (prefers-reduced-motion: no-preference) {
  .fit-apply {
    --apply-pulse: 12px;
  }

  .fit-apply::before {
    box-shadow: none;
    animation: apply-halo 2.8s cubic-bezier(.4, 0, .2, 1) infinite;
    transition: opacity .25s var(--ease);
  }

  .fit-apply:hover::before,
  .fit-apply:focus-visible::before {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) and (max-width: 720px) {
  .fit-apply {
    --apply-pulse: 8px;
  }
}

/* View Common Questions: the quieter second choice. A soft frosted surface with a fine light border,
   a faint top highlight and no rim or glow, so it looks finished beside Apply for Free without
   competing with it. Same size and pill shape as Apply. */
.fit-buttons .fit-questions {
  color: #eef5fb;
  font-weight: 500;
  --lg-fill: rgba(206, 228, 247, .07);
  --lg-body: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, 0) 55%);
  --lg-sheen: transparent;
  --lg-solid: #173d5c;
  --lg-shadow: inset 0 0 0 1px rgba(196, 224, 248, .24), inset 0 1px 0 rgba(255, 255, 255, .1), 0 10px 24px -16px rgba(0, 6, 16, .7);
  -webkit-backdrop-filter: blur(6px) saturate(140%);
  backdrop-filter: blur(6px) saturate(140%);
}

.fit-buttons .fit-questions::after {
  content: none;
}

/* A calm hover: the border and surface brighten a little; it does not grow like the main button. */
@media (hover: hover) and (pointer: fine) {
  .fit-buttons .fit-questions:hover {
    transform: none;
    --lg-fill: rgba(206, 228, 247, .11);
    --lg-shadow: inset 0 0 0 1px rgba(196, 224, 248, .4), inset 0 1px 0 rgba(255, 255, 255, .12), 0 12px 26px -16px rgba(0, 6, 16, .75);
  }
}

/* ---- Scene ---- */

.fit-scene {
  --fit-h: clamp(460px, 40vw + 60px, 680px);
  grid-area: scene;
  position: relative;
  z-index: 1;
  align-self: end;
  height: var(--fit-h);
}

/* The picture keeps its proportions (1110 x 1066) at the full height of the scene, at its bottom right;
   where the scene is narrower it reaches left under the copy, where it is only faded background. It
   fades into the slab at the top and sides; on desktop it runs into the slab's bottom edge. */
.fit-art {
  --fit-fade-x: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
  --fit-fade-y: linear-gradient(180deg, transparent, #000 6%);
  position: absolute;
  right: 0;
  bottom: 0;
  height: 100%;
  aspect-ratio: 1110 / 1066;
  overflow: hidden;
  -webkit-mask-image: var(--fit-fade-x), var(--fit-fade-y);
  -webkit-mask-composite: source-in;
  mask-image: var(--fit-fade-x), var(--fit-fade-y);
  mask-composite: intersect;
}

/* The person: the picture, plus the near eyebrow and the hand at the chin as their own layers so they
   can move. Positions are percentages of the picture, from art-source/fit-person/build_fit_layers.py. */
.fit-figure {
  position: absolute;
  inset: 0;
  transform-origin: 62% 100%;
}

/* fit.js hides the person until all three images are ready, then it fades in. */
.fit-figure.is-loading {
  opacity: 0;
}

.fit-figure img {
  position: absolute;
  display: block;
  max-width: none;
  height: auto;
}

.fit-figure .fit-person {
  inset: 0;
  width: 100%;
  height: 100%;
}

.fit-brow {
  left: 58.018%;
  top: 22.702%;
  width: 6.757%;
  transform-origin: 92% 50%; /* its outer end */
}

.fit-hand {
  left: 58.198%;
  top: 37.711%;
  width: 15.225%;
  transform-origin: 79.882% 91.429%; /* where the forearm meets the sleeve */
}

/* Light from the phone screen. Color dodge brightens what is already lit (face, hands, the glow
   around the phone) and leaves the dark sweater and background almost unchanged. */
.fit-light {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 34% 40% at 55% 45%, rgb(72 78 90), rgb(72 78 90 / .45) 50%, transparent);
  mix-blend-mode: color-dodge;
  opacity: .5;
  pointer-events: none;
}

/* Quiet life: breathing, the screen light shifting as its content changes, and a small, continuous rub
   of the chin, with the brow tightening every other stroke cycle. Paused off screen, in background tabs and by the
   pause button, like the Apply halo (fit.js sets .is-live on the section); none with reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  .fit-figure {
    animation: fit-breathe 4.8s ease-in-out infinite alternate;
    transition: opacity .6s ease;
  }

  .fit-light {
    animation: fit-screen 12.6s ease-in-out infinite;
  }

  .fit-hand {
    animation: fit-rub 5.4s ease-in-out infinite;
  }

  .fit-brow {
    animation: fit-brow 10.8s ease-in-out infinite;
  }
}

.fit-section:not(.is-live) :is(.fit-figure, .fit-light, .fit-hand, .fit-brow),
.fit-section:not(.is-live) .fit-apply::before {
  animation-play-state: paused;
}

@keyframes fit-breathe {
  to { transform: scale(1.003); }
}

@keyframes fit-screen {
  0%, 9% { opacity: .5; }
  12%, 26% { opacity: .78; }
  28% { opacity: .62; }
  29.5% { opacity: .72; }
  31% { opacity: .6; }
  33%, 50% { opacity: .66; }
  53%, 69% { opacity: .38; }
  72%, 85% { opacity: .82; }
  89%, 100% { opacity: .5; }
}

/* Continuous, uneven fidgeting at the chin: strokes of different sizes, never a long pause and never
   away from the chin (all angles press the fingers into it). */
@keyframes fit-rub {
  0%, 100% { transform: rotate(.2deg); }
  14% { transform: rotate(.9deg); }
  27% { transform: rotate(.35deg); }
  41% { transform: rotate(1deg); }
  55% { transform: rotate(.4deg); }
  66% { transform: rotate(.7deg); }
  80% { transform: rotate(.25deg); }
  90% { transform: rotate(.55deg); }
}

/* The brow tightens with the larger strokes of every other rub, then relaxes (twice the rub's length). */
@keyframes fit-brow {
  0%, 4% { transform: none; }
  12%, 28% { transform: rotate(2.5deg); }
  38%, 100% { transform: none; }
}

/* ---- The message thread (fit.js) ---- */

/* A column from the scene's left edge to 45% across the picture (left of the face), ending just above
   the phone. Messages are placed from the bottom up. */
.fit-thread {
  --fit-art-w: calc(var(--fit-h) * 1110 / 1066);
  position: absolute;
  z-index: 2;
  top: 8%;
  bottom: 55%;
  left: 0;
  right: calc(var(--fit-art-w) * .55);
  pointer-events: none;
}

/* iPhone "sent" message: blue, white text, rounded, newest one with a tail. */
.fit-msg {
  position: absolute;
  right: 10px;
  bottom: 0;
  width: max-content;
  max-width: min(calc(100% - 10px), 290px);
  padding: 9px 14px 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, #1f73dc, #1866cf);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", var(--font);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.32;
  letter-spacing: -.012em;
  text-decoration: none;
  box-shadow: 0 12px 26px -16px rgba(0, 0, 0, .7);
  transform-origin: 100% 100%;
  pointer-events: auto;
  cursor: pointer;
  will-change: transform, opacity;
  transition: transform .6s var(--ease-out), opacity .5s ease, background-color .2s;
}

.fit-msg.has-tail::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 0;
  width: 17px;
  height: 21px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 17 21'%3E%3Cpath fill='%231866cf' d='M0 0h6c0 8.5 3.3 15.2 10.6 19.9-5.3 1.4-11.6.2-16.6-3.9z'/%3E%3C/svg%3E") no-repeat right bottom / 100% 100%;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .fit-msg:hover {
    background: linear-gradient(180deg, #2a7de6, #1d6fd8);
  }
}

.fit-thread.is-still .fit-msg,
.fit-thread.is-filling .fit-msg {
  transition: none;
}

/* Pause / play for the thread (WCAG 2.2.2), quiet in the corner of the scene. */
.fit-pause {
  grid-area: scene;
  position: relative;
  z-index: 3;
  align-self: end;
  justify-self: start;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: 0 0 18px 6px;
  padding: 0;
  border: 1px solid rgba(190, 228, 255, .22);
  border-radius: 50%;
  background: rgba(9, 32, 56, .55);
  color: #cfe3f2;
  cursor: pointer;
  transition: background-color .2s, border-color .2s;
}

.fit-pause:hover {
  border-color: rgba(190, 228, 255, .4);
  background: rgba(18, 52, 86, .8);
}

.fit-pause svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fit-pause[aria-pressed="true"] path {
  fill: currentColor;
}

/* ---- Tablet: one column, the scene between the question and the buttons ---- */

@media (max-width: 990px) {
  .fit-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "copy"
      "scene"
      "actions";
    grid-template-rows: auto auto auto;
  }

  .fit-copy {
    padding-top: 0;
  }

  .fit-copy h2 {
    max-width: 13em;
  }

  /* The picture stays on the right at its own proportions and fades out above the buttons; the
     thread can use the open slab to its left. */
  .fit-scene {
    --fit-h: clamp(440px, 64vw, 580px);
    margin-top: 12px;
  }

  .fit-art {
    --fit-fade-y: linear-gradient(180deg, transparent, #000 6%, #000 84%, transparent);
  }

  .fit-actions {
    padding-top: 28px;
  }
}

/* ---- Phones ---- */

@media (max-width: 720px) {
  .fit-section {
    padding-top: 60px;
  }

  .fit-copy h2 {
    margin-bottom: 16px;
    font-size: clamp(31px, 8.2vw, 40px);
  }

  .fit-lead {
    font-size: 18px;
  }

  .fit-scene {
    --fit-h: clamp(330px, 92vw, 400px);
    margin-top: 6px;
  }

  /* Nudged right (the far shoulder crops a little) so the thread has room beside the face. */
  .fit-art {
    --fit-fade-x: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
    right: -16%;
  }

  .fit-thread {
    top: 4%;
    left: 6px;
    right: calc(var(--fit-art-w) * .55 - 16%);
  }

  .fit-msg {
    right: 8px;
    max-width: min(calc(100% - 8px), 210px);
    padding: 8px 12px 9px;
    border-radius: 18px;
    font-size: 14.5px;
  }

  .fit-msg.has-tail::after {
    right: -5px;
    width: 15px;
    height: 19px;
  }

  .fit-pause {
    margin: 0 0 12px 2px;
  }

  /* Full-width, easy-to-tap buttons, Apply for Free on top. */
  .fit-actions {
    padding: 22px 0 56px;
  }

  .fit-note {
    margin-bottom: 16px;
  }

  .fit-buttons {
    width: 100%;
  }

  .fit-buttons .button {
    justify-content: center;
  }
}
