/* ==========================================================================
   Free Preview questionnaire: the pop-up, the one-question-at-a-time card and
   the "Request Received" animation. The questions themselves live in
   /js/preview.js. Colours come from the variables at the top of style.css.
   ========================================================================== */

.quiz,
.pmodal {
  --card: #141416;
  --field: #0E0E10;
  --out: cubic-bezier(0.22, 0.61, 0.36, 1);      /* calm ease-out, used everywhere here */
}

/* --------------------------------------------------------------------------
   The pop-up
   -------------------------------------------------------------------------- */

.pmodal {
  position: fixed;
  inset: 0;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.32s var(--out), visibility 0s linear 0.32s;
}

/* The dark, blurred backdrop is a layer of its own, so that nothing moving in the card
   makes the browser blur the page again */
.pmodal::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(7, 7, 8, 0.74);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  transition: background-color 0.4s var(--out);
}

/* Set by preview.js on devices that cannot blur the page smoothly */
.pmodal--plain::before {
  background: rgba(7, 7, 8, 0.9);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.pmodal.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.32s var(--out), visibility 0s;
}

/* The pop-up scrolls by itself when the card is taller than the screen (phones, step 4) */
.pmodal__scroll {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.pmodal .quiz {
  margin: auto;
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition: opacity 0.4s var(--out), transform 0.5s var(--out);
}

.pmodal.is-open .quiz {
  opacity: 1;
  transform: none;
}

/* The page behind stays where it is while the pop-up is open */
html.quiz-open {
  overflow: hidden;
}

html.quiz-open body {
  padding-right: var(--scrollbar, 0px);
}

html.quiz-open .nav {
  right: var(--scrollbar, 0px);
}

/* --------------------------------------------------------------------------
   The card
   -------------------------------------------------------------------------- */

.quiz {
  position: relative;
  width: 100%;
  --pad: clamp(22px, 4.4vw, 40px);
  max-width: 620px;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) - 4px);
  background: var(--card);
  border: 1px solid rgba(var(--text-rgb), 0.12);
  border-radius: 18px;
  box-shadow: 0 50px 140px -50px rgba(0, 0, 0, 0.95), 0 0 90px -40px rgba(var(--accent-rgb), 0.22);
  color: var(--text);
  text-align: left;
}

/* A little lamp light on the top edge */
.quiz::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(70% 46% at 50% 0%, rgba(var(--accent-rgb), 0.09), rgba(var(--accent-rgb), 0) 72%);
}

.quiz > * {
  position: relative;
}

.quiz__close {
  position: absolute;
  top: clamp(10px, 2vw, 18px);
  right: clamp(10px, 2vw, 18px);
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(var(--text-rgb), 0.62);
  cursor: pointer;
  transition: color 0.3s var(--out), background-color 0.3s var(--out);
}

.quiz__close:hover,
.quiz__close:focus-visible {
  color: var(--text);
  background: rgba(var(--text-rgb), 0.07);
}

.quiz__close svg {
  width: 18px;
  height: 18px;
}

.quiz__head {
  display: grid;
  gap: 16px;
  padding-right: 48px;
  transition: opacity 0.3s var(--out);
}

.quiz__dots {
  display: flex;
  gap: 9px;
  height: 12px;
  align-items: center;
}

.quiz__dots li {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(var(--text-rgb), 0.2);
  transition: background-color 0.5s var(--out), box-shadow 0.5s var(--out);
}

.quiz__dots li.is-on {
  background: var(--accent);
}

.quiz__dots li.is-now {
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.16);
}

.quiz__count {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  line-height: 1.4;
  text-transform: uppercase;
}

.quiz__hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* The stage holds one question at a time. Its height glides to the next question's.
   It reaches out to the card's edges, so a sliding question is never cut off early. */
.quiz__stage {
  margin: 8px calc(var(--pad) * -1) 0;
  padding: 4px var(--pad);
  transition: height 0.38s var(--out);
}

.quiz__stage.is-moving {
  overflow: hidden;
}

.quiz__panel {
  transition: opacity 0.24s ease-in, transform 0.24s ease-in;
}

.quiz__panel[hidden] {
  display: none;
}

/* leaving: a short slide and fade to the left (or to the right, when going back) */
.quiz__panel.is-out {
  opacity: 0;
  transform: translate3d(-28px, 0, 0);
}

.quiz__panel.is-out.is-back {
  transform: translate3d(28px, 0, 0);
}

/* arriving: starts a little to the right (or left), then settles */
.quiz__panel.is-pre {
  opacity: 0;
  transform: translate3d(28px, 0, 0);
  transition: none;
}

.quiz__panel.is-pre.is-back {
  transform: translate3d(-28px, 0, 0);
}

.quiz__panel.is-arriving {
  transition: opacity 0.42s var(--out), transform 0.46s var(--out);
}

.quiz__q {
  font-size: clamp(1.6rem, 4.6vw, 2.1rem);
  line-height: 1.12;
  outline: none;
}

/* ---- Answers ---- */

.quiz__opts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: clamp(20px, 3.4vw, 30px);
}

.quiz__opts--stack {
  grid-template-columns: minmax(0, 1fr);
}

.pill {
  min-height: 54px;
  padding: 12px 20px;
  border: 1px solid rgba(var(--text-rgb), 0.36);
  border-radius: 999px;
  background: rgba(var(--text-rgb), 0.015);
  color: var(--text);
  font: 500 1rem/1.25 var(--sans);
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.25s var(--out), border-color 0.25s var(--out), color 0.25s var(--out);
}

@media (hover: hover) {
  .pill:hover {
    border-color: rgba(var(--text-rgb), 0.85);
    background: rgba(var(--text-rgb), 0.06);
  }
}

.pill[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.pill.is-press {
  animation: pill-press 0.3s var(--out);
}

@keyframes pill-press {
  0%   { transform: scale(1); }
  42%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* ---- "Other": the text field that opens under the answers ---- */

.quiz__other {
  height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translate3d(0, 10px, 0);
  transition: height 0.35s var(--out), opacity 0.3s var(--out), transform 0.35s var(--out);
}

.quiz__other.is-open {
  opacity: 1;
  transform: none;
}

.quiz__other-in {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px 3px 3px;          /* room for the amber focus ring inside the clipped box */
}

.quiz .input {
  min-height: 50px;
  padding: 12px 15px;
  background: var(--field);
  border-color: rgba(var(--text-rgb), 0.22);
  border-radius: 10px;
}

.quiz .input:hover {
  border-color: rgba(var(--text-rgb), 0.45);
}

.quiz .input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.24);
}

.quiz .input.is-wrong {
  border-color: #E5806A;
}

.quiz .btn {
  border-radius: 10px;
}

.quiz__next {
  min-height: 50px;
  padding-inline: 26px;
  transition: opacity 0.3s var(--out), box-shadow 0.45s var(--ease);
}

.quiz__next:disabled {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}

/* ---- Step 4: contact details ---- */

.quiz__fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 14px;
  margin-top: clamp(18px, 3vw, 26px);
}

.quiz__fields > * {
  transition: opacity 0.3s var(--out);
}

.qfield {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.qfield--full {
  grid-column: 1 / -1;
}

.qfield label {
  color: var(--soft);
  font-size: 0.8125rem;
  font-weight: 500;
}

.qfield label span {
  color: var(--muted);
  font-weight: 400;
}

.qerror {
  color: #F0A08E;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.qerror[hidden] {
  display: none;
}

.qerror--reach {
  grid-column: 1 / -1;
  margin-top: -6px;
}

.qcheck {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 4px 12px;
  align-items: start;
  color: var(--soft);
  font-size: 0.875rem;
  line-height: 1.45;
}

.qcheck input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}

.qcheck .qerror {
  grid-column: 2;
}

.quiz__send {
  width: 100%;
  transition: box-shadow 0.45s var(--ease), opacity 0.3s var(--out), transform 0.5s var(--out);
}

.quiz__send span {
  transition: opacity 0.16s linear;
}

.quiz__back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 -10px;
  padding: 6px 8px 6px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: 500 0.875rem/1.2 var(--sans);
  cursor: pointer;
  transition: color 0.3s var(--out), opacity 0.3s var(--out);
}

.quiz__back svg {
  width: 14px;
  height: 14px;
}

.quiz__back:hover,
.quiz__back:focus-visible {
  color: var(--text);
}

/* --------------------------------------------------------------------------
   Sending, "Request Received" and the error message.
   Only transform, opacity and stroke-dashoffset move here.
   -------------------------------------------------------------------------- */

.quiz.is-sending .quiz__head,
.quiz.is-sending .quiz__back,
.quiz.is-sending .quiz__q,
.quiz.is-sending .quiz__fields > *:not(.quiz__sendrow) {
  opacity: 0;
  pointer-events: none;
}

.quiz.is-sending .quiz__send {
  opacity: 0;
  pointer-events: none;
  box-shadow: none;
}

.quiz.is-sending .quiz__send span {
  opacity: 0;
}

.quiz__status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
  text-align: center;
  visibility: hidden;
  pointer-events: none;
}

.quiz.is-sending .quiz__status {
  visibility: visible;
}

.quiz.is-done .quiz__status,
.quiz.is-error .quiz__status {
  pointer-events: auto;
}

.quiz__mark {
  position: relative;
  flex: none;
  width: 76px;
  height: 76px;
}

.quiz__glow {
  position: absolute;
  inset: -84px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(closest-side, rgba(var(--accent-rgb), 0.3), rgba(var(--accent-rgb), 0.09) 52%, rgba(var(--accent-rgb), 0) 74%);
  opacity: 0;
  transition: opacity 1.3s var(--out) 0.8s;
}

.quiz__ring,
.quiz__tick {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 1. the spinner: a thin amber arc going round */
.quiz__ring {
  opacity: 0;
  will-change: transform;
  transition: opacity 0.35s var(--out) 0.12s;
}

.quiz.is-sending .quiz__ring {
  opacity: 1;
  animation: quiz-spin 0.95s linear infinite;
}

.quiz__ring path {
  stroke-dasharray: 1;
  stroke-dashoffset: 0.72;
  transition: stroke-dashoffset 0.5s var(--out);
}

@keyframes quiz-spin {
  to { transform: rotate(360deg); }
}

/* 2. sent: the arc closes into a full circle, then the check mark draws itself */
.quiz.is-done .quiz__ring path {
  stroke-dashoffset: 0;
}

.quiz.is-done.is-still .quiz__ring {
  animation: none;                /* the circle is closed by now, so stopping the turn cannot be seen */
}

.quiz__tick path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: stroke-dashoffset 0.4s var(--out) 0.5s, opacity 0.01s linear 0.5s;
}

.quiz.is-done .quiz__tick path {
  stroke-dashoffset: 0;
  opacity: 1;
}

.quiz.is-done .quiz__mark {
  animation: quiz-settle 0.55s cubic-bezier(0.33, 0.5, 0.3, 1) 0.9s both;
}

@keyframes quiz-settle {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.quiz.is-done .quiz__glow {
  opacity: 1;
}

/* 3. the words fade and rise in underneath */
.quiz__done {
  display: grid;
  justify-items: center;
}

.quiz__done > * {
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  transition: opacity 0.8s var(--out), transform 0.9s var(--out);
}

.quiz.is-done .quiz__done > * {
  opacity: 1;
  transform: none;
}

.quiz.is-done .quiz__done > :nth-child(1) { transition-delay: 1.1s; }
.quiz.is-done .quiz__done > :nth-child(2) { transition-delay: 1.24s; }
.quiz.is-done .quiz__done > :nth-child(3) { transition-delay: 1.45s, 1.45s, 0s; }

/* the Close link keeps its own colour change on hover */
.quiz__done > .quiz__retry,
.quiz__done > .text-link {
  transition: opacity 0.8s var(--out), transform 0.9s var(--out), color 0.3s var(--out);
}

.quiz__done-title {
  margin-top: 26px;
  font-size: clamp(1.7rem, 4.6vw, 2.15rem);
  outline: none;
}

.quiz__done-text {
  max-width: 38ch;
  margin-top: 12px;
  color: var(--soft);
  font-size: 1rem;
}

.quiz__done .text-link,
.quiz__retry {
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.9375rem;
}

.quiz__sending {
  display: none;
  margin-top: 16px;
  color: var(--soft);
  font-size: 0.9375rem;
}

/* The calm error message */
.quiz__fail {
  display: none;
  justify-items: center;
  opacity: 0;
  transition: opacity 0.5s var(--out);
}

.quiz.is-failing .quiz__ring {
  opacity: 0;
  transition-delay: 0s;
}

.quiz.is-error .quiz__mark,
.quiz.is-error .quiz__done,
.quiz.is-error .quiz__sending {
  display: none;
}

.quiz.is-error .quiz__fail {
  display: grid;
}

.quiz.is-error.is-shown .quiz__fail {
  opacity: 1;
}

.quiz__fail-text {
  max-width: 30ch;
  font-family: var(--serif);
  font-size: clamp(1.3rem, 3.6vw, 1.6rem);
  font-weight: 340;
  line-height: 1.25;
  outline: none;
}

.quiz__fail .btn {
  margin-top: 24px;
}

.quiz__retry {
  padding: 6px 4px;
  border: 0;
  background: none;
  font-family: var(--sans);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 5px;
  transition: color 0.3s var(--out);
}

.quiz__retry:hover,
.quiz__retry:focus-visible {
  color: var(--text);
}

/* --------------------------------------------------------------------------
   The /free-preview/ page shows the same card directly on the page
   -------------------------------------------------------------------------- */

.preview__card {
  min-width: 0;
}

.preview__card .quiz {
  max-width: 660px;
}

/* The plain form underneath is only for browsers without JavaScript (and for Netlify,
   which reads the field names from it) */
.js .form--plain {
  display: none;
}

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

@media (max-width: 560px) {
  .quiz {
    border-radius: 16px;
  }

  .quiz__opts {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .pill {
    min-height: 52px;
  }

  .quiz__fields {
    grid-template-columns: minmax(0, 1fr);
    gap: 13px;
  }

  .qerror--reach {
    margin-top: -4px;
  }

  .quiz__other-in {
    grid-template-columns: minmax(0, 1fr);
  }

  .quiz__next {
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   Reduced motion: no sliding, spinning or drawing. Things simply fade.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .pmodal .quiz,
  .quiz__panel.is-out,
  .quiz__panel.is-pre,
  .quiz__other,
  .quiz__done > *,
  .quiz__send {
    transform: none !important;
  }

  .quiz.is-sending:not(.is-done) .quiz__sending {
    display: block;
  }

  .quiz__mark {
    opacity: 0.55;
    transition: opacity 0.6s linear;
  }

  .quiz.is-done .quiz__mark {
    opacity: 1;
  }

  .quiz__tick path {
    stroke-dashoffset: 0;
    transition: opacity 0.6s linear;
  }

  .quiz.is-done .quiz__done > :nth-child(n) {
    transition-delay: 0.35s;
  }
}
