/* Ask the assistant (site/snippets/blocks/askassistant.php, the answer
   engine optimization page's demo; public/assets/js/askassistant.js). One
   sample question in a generic assistant box, beside the sample business's
   page in one of two styles (brochure-style, answer-ready), with a two-way
   switch on a pill track (the twometros switch). Linked by the block itself
   (peanut_page_css), once per page. Every selector names an askassist
   class. Tokens only. The shared hint, progress bar and sample controls are
   industry.css's (linked on any page with a demo- class).

   Finished by default (no script, reduced motion, ?fx=off, print): the
   switch hidden, both states one under the other, each under its label.
   The script adds .is-live (both states share one cell, the taller sets
   the height, the other is data-off and hidden), .is-typing while the
   question types in, .is-play on a state when it shows (the quoted
   sentences light in turn) and .is-free after the reader's first press. */

@layer blocks {
  .askassist__head {
    max-width: 44rem;
    margin-block-end: var(--space-5);
  }

  .askassist__title {
    margin: 0;
  }

  .askassist__intro {
    margin: var(--space-3) 0 0;
  }

  /* ---------- the frame ---------- */
  .askassist__demo {
    max-width: 72rem;
    padding: var(--space-3);
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
    color: var(--color-ink);
  }

  @media (min-width: 60rem) {
    .askassist__demo {
      padding: var(--space-4);
    }
  }

  .askassist__top {
    display: flex;
    margin-block-end: var(--space-3);
  }

  .askassist__sample {
    flex: none;
    padding: 0.0625rem 0.5rem;
    background: var(--color-butter);
    border: var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.6;
    text-transform: uppercase;
  }

  /* ---------- the switch (shown by the script) ---------- */
  .askassist__controls[hidden] {
    display: none;
  }

  .askassist__controls {
    display: grid;
    gap: var(--space-2);
    max-width: 32rem;
    margin-block-end: var(--space-4);
  }

  .askassist__switch {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0.25rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
  }

  .askassist__switch::before {
    content: "";
    position: absolute;
    inset-block: 0.25rem;
    inset-inline-start: 0.25rem;
    width: calc(50% - 0.25rem);
    background: var(--color-brand);
    border: var(--border);
    border-radius: var(--radius-pill);
  }

  .askassist__switch[data-at="1"]::before {
    transform: translateX(100%);
  }

  .askassist__pick {
    position: relative;
    min-height: 2.75rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    background: none;
    border: 0;
    border-radius: var(--radius-pill);
    color: var(--color-ink);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
  }

  .askassist__pick[aria-pressed="true"] {
    font-weight: 600;
  }

  .askassist__pick[aria-pressed="false"]:hover {
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  .askassist__pick:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
  }

  @media (max-width: 29.99rem) {
    .askassist__pick {
      padding-inline: 0.5rem;
      font-size: 0.8125rem;
    }
  }

  /* ---------- the two states: without the script, one under the other ---------- */
  .askassist__demo:not(.is-live) .askassist__state + .askassist__state {
    margin-block-start: var(--space-4);
    padding-block-start: var(--space-4);
    border-block-start: var(--border);
  }

  .askassist__demo.is-live .askassist__states {
    display: grid;
  }

  .askassist__demo.is-live .askassist__state {
    grid-area: 1 / 1;
  }

  .askassist__demo.is-live .askassist__state[data-off] {
    visibility: hidden;
  }

  /* after the reader's first tap (.is-free), narrow screens let the shown
     state set the height (the movedemo rule, owner 2026-11-27) */
  @media screen and (max-width: 59.99rem) {
    .askassist__demo.is-live.is-free .askassist__state[data-off] {
      display: none;
    }
  }

  /* the state's number and label, only where the switch does not show */
  .askassist__kicker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 var(--space-3);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.6;
    text-transform: uppercase;
  }

  .askassist__demo.is-live .askassist__kicker {
    display: none;
  }

  .askassist__kickernum {
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: 50%;
    font-size: 0.75rem;
    letter-spacing: 0;
    line-height: 1;
  }

  /* ---------- one state: the assistant, then the page (side by side from 60rem) ---------- */
  .askassist__stage {
    display: grid;
    gap: var(--space-3);
    align-items: start;
  }

  @media (min-width: 60rem) {
    .askassist__stage {
      grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
      gap: var(--space-4);
    }
  }

  /* ---------- the assistant: a generic box, no product, no logo ---------- */
  .askassist__assistant {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--color-paper);
    border: var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    line-height: 1.55;
  }

  .askassist__who {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.4;
    text-transform: uppercase;
  }

  .askassist__amark {
    flex: none;
  }

  /* the question: the visitor's bubble, on the right */
  .askassist__q {
    justify-self: end;
    max-width: 90%;
    margin: 0;
    padding: 0.625rem 0.875rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm) var(--radius-sm) 0.25rem var(--radius-sm);
    font-weight: 500;
  }

  .askassist__typed {
    display: inline;
  }

  .askassist__demo.is-typing .askassist__ch:not(.is-on) {
    visibility: hidden;
  }

  .askassist__a {
    display: grid;
    gap: var(--space-2);
  }

  .askassist__answer {
    margin: 0;
  }

  .askassist__name {
    font-weight: var(--weight-strong);
  }

  /* a sentence built from a quoted one: the page's highlight and its number */
  .askassist__sentence--quoted {
    padding: 0.0625rem 0.125rem;
    background: var(--color-butter);
    border-radius: 0.25rem;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }

  .askassist__sources {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
  }

  .askassist__sourceslabel {
    font-weight: 600;
  }

  /* the brochure answer: the business is missing */
  .askassist__note {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin: 0;
    padding: 0.5rem 0.75rem;
    background: var(--color-white);
    border: 1px dashed var(--color-ink);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.45;
  }

  .askassist__noicon {
    flex: none;
    margin-block-start: 0.0625rem;
  }

  /* a drawn input under the answer: a picture, never a field */
  .askassist__input {
    margin: var(--space-1) 0 0;
  }

  .askassist__field {
    display: block;
    padding: 0.5rem 0.875rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.8125rem;
    line-height: 1.4;
  }

  /* the number tag, the same on both sides */
  .askassist__tag {
    display: inline-grid;
    place-items: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding-inline: 0.25rem;
    background: var(--color-ink);
    border-radius: var(--radius-pill);
    color: var(--color-white);
    font-size: 0.6875rem;
    font-weight: var(--weight-strong);
    line-height: 1;
    vertical-align: 0.0625rem;
  }

  /* ---------- the sample business's page ---------- */
  .askassist__page {
    container-type: inline-size;
    min-width: 0;
    overflow: hidden;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    line-height: 1.55;
  }

  .askassist__bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.5rem var(--space-2);
    background: var(--color-paper);
    border-block-end: var(--border);
    font-size: 0.75rem;
  }

  .askassist__dots {
    flex: none;
    width: 0.4375rem;
    height: 0.4375rem;
    margin-inline-end: 1.75rem;
    background: var(--color-ink);
    border-radius: 50%;
    box-shadow: 0.75rem 0 0 var(--color-ink), 1.5rem 0 0 var(--color-ink);
    opacity: 0.35;
  }

  .askassist__url {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    padding: 0.125rem 0.625rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .askassist__brand {
    display: flex;
    gap: 0.625rem;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-block-end: var(--border);
    font-family: var(--font-heading);
    font-size: var(--step-1);
    font-weight: var(--weight-heading);
    line-height: 1.2;
  }

  .askassist__logo {
    display: grid;
    flex: none;
    place-items: center;
    width: 2rem;
    height: 2rem;
    background: var(--color-ink);
    border-radius: 50%;
    color: var(--color-white);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
  }

  .askassist__body {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
  }

  .askassist__heading {
    margin: 0;
    font-family: var(--font-heading);
    font-size: var(--step-3);
    font-weight: var(--weight-heading);
    line-height: 1.15;
  }

  .askassist__heading--q {
    font-size: var(--step-2);
  }

  .askassist__para {
    max-width: 36rem;
    margin: 0;
  }

  .askassist__para--lead {
    font-size: var(--step-0);
    font-weight: 500;
  }

  .askassist__claims {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .askassist__claims li {
    padding: 0.25rem 0.75rem;
    background: var(--color-mint-pale);
    border: var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 500;
  }

  /* a quoted sentence on the page: highlighted, its number after it */
  .askassist__mark {
    padding: 0.0625rem 0.125rem;
    background: var(--color-butter);
    border-radius: 0.25rem;
    color: inherit;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }

  .askassist__faq {
    padding: var(--space-2) var(--space-3);
    background: var(--color-paper);
    border: var(--border);
    border-radius: var(--radius-sm);
  }

  .askassist__faqtitle {
    margin: 0 0 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.6;
    text-transform: uppercase;
  }

  .askassist__faqlist {
    display: grid;
    gap: 0.5rem;
    margin: 0;
  }

  .askassist__faqitem dt {
    font-weight: 600;
  }

  .askassist__faqitem dd {
    margin: 0.125rem 0 0;
  }

  .askassist__cta {
    margin: 0;
  }

  .askassist__btn {
    display: inline-block;
    padding: 0.625rem var(--space-3);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  /* ---------- phones: a tighter frame, so the whole demo fits about one and a
     half screens (auto-play starts when half of it is in view) ---------- */
  @media (max-width: 47.99rem) {
    .askassist__demo {
      padding: var(--space-2);
    }

    .askassist__top {
      margin-block-end: var(--space-2);
    }

    .askassist__controls {
      margin-block-end: var(--space-3);
    }

    .askassist__stage {
      gap: var(--space-2);
    }

    .askassist__assistant {
      gap: 0.75rem;
      padding: var(--space-2);
      font-size: 0.875rem;
    }

    .askassist__input {
      display: none;
    }

    .askassist__page {
      font-size: 0.8125rem;
    }

    .askassist__brand {
      padding: 0.5rem var(--space-2);
      font-size: var(--step-0);
    }

    .askassist__logo {
      width: 1.5rem;
      height: 1.5rem;
      font-size: 0.75rem;
    }

    .askassist__body {
      gap: 0.75rem;
      padding: var(--space-2);
    }

    .askassist__heading {
      font-size: var(--step-2);
    }

    .askassist__heading--q {
      font-size: var(--step-1);
    }

    .askassist__para--lead {
      font-size: 0.875rem;
    }

    .askassist__faq {
      padding: 0.75rem var(--space-2);
    }
  }

  /* ---------- under the demo ---------- */
  .askassist__closing {
    max-width: var(--measure);
    margin: var(--space-4) 0 0;
  }

  .askassist__closing > :last-child {
    margin-block-end: 0;
  }

  /* ---------- print: both states, one under the other ---------- */
  @media print {
    .askassist__controls {
      display: none;
    }

    .askassist__demo.is-live .askassist__states {
      display: block;
    }

    .askassist__demo.is-live .askassist__state[data-off] {
      display: block;
      visibility: visible;
    }

    .askassist__demo.is-live .askassist__kicker {
      display: flex;
    }

    .askassist__demo.is-live .askassist__state + .askassist__state {
      margin-block-start: var(--space-4);
      padding-block-start: var(--space-4);
      border-block-start: var(--border);
    }

    .askassist__demo.is-typing .askassist__ch {
      visibility: visible;
    }

    .askassist__state {
      break-inside: avoid;
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    html[data-fx~="diagrams"] .askassist__switch::before {
      transition: transform 300ms var(--ease-out);
    }

    html[data-fx~="diagrams"] .askassist__demo.is-live .askassist__state:not([data-off]) {
      animation: askassist-in 400ms var(--ease-out) both;
    }

    /* the brochure answer waits for the question to finish typing */
    html[data-fx~="diagrams"] .askassist__demo.is-typing .askassist__state--brochure .askassist__a {
      opacity: 0;
    }

    html[data-fx~="diagrams"] .askassist__state--brochure .askassist__a {
      transition: opacity 450ms var(--ease-out) 150ms;
    }

    /* the answer-ready state: each quoted sentence and its number light in turn,
       on the page and in the answer at the same moment */
    html[data-fx~="diagrams"] .askassist__state--ready.is-play :is(.askassist__mark, .askassist__sentence--quoted) {
      animation: askassist-light 700ms var(--ease-out) both;
      animation-delay: calc(var(--q-at, 0) * 600ms + 500ms);
    }

    html[data-fx~="diagrams"] .askassist__state--ready.is-play :is(.askassist__mark, .askassist__sentence--quoted) .askassist__tag {
      animation: askassist-tag 500ms var(--ease-out) both;
      animation-delay: calc(var(--q-at, 0) * 600ms + 700ms);
    }

    .askassist__state--ready [data-q="2"] {
      --q-at: 1;
    }

    .askassist__state--ready [data-q="3"] {
      --q-at: 2;
    }
  }

  @keyframes askassist-in {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  @keyframes askassist-light {
    from {
      background-color: transparent;
    }

    to {
      background-color: var(--color-butter);
    }
  }

  @keyframes askassist-tag {
    from {
      opacity: 0;
      transform: scale(0.6);
    }

    to {
      opacity: 1;
      transform: scale(1);
    }
  }
}
