/*
 * How it works — four build steps. On wide screens the section pins and the
 * steps slide sideways as the page scrolls; elsewhere they stack vertically.
 */
@layer sections {
  .how {
    padding-block: 40px 80px;
  }

  .how__title {
    margin-bottom: 10px;
  }

  .how__lead {
    max-width: 520px;
  }

  /* ---------- Progress rail ---------- */
  .how__rail {
    position: relative;
    display: flex;
    justify-content: space-between;
    margin: 40px 0 32px;
  }

  .how__line {
    position: absolute;
    top: 22px;
    inset-inline: 40px;
    height: 4px;
    border-radius: 4px;
    background: var(--color-line);
  }

  .how__fill {
    height: 4px;
    border-radius: 4px;
    background: var(--color-violet);
    transform-origin: right;
  }

  [dir="ltr"] .how__track {
    --slide-direction: -1;
  }

  [dir="ltr"] .how__fill {
    transform-origin: left;
  }

  .how__node {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 160px;
    text-align: center;
  }

  .how__dot {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--color-white);
    border: 2px solid var(--color-line);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: calc(19rem / 16);
    font-weight: 600;
    box-sizing: border-box;
  }

  .how__label {
    font-size: calc(15rem / 16);
    font-weight: 700;
  }

  /* ---------- Step panels ---------- */
  .how__viewport {
    overflow: hidden;
  }

  .how__track {
    --slide-direction: 1; /* RTL pages slide right; LTR pages flip it */
    display: flex;
    flex-direction: column;
    gap: 32px;
  }

  .how__panel {
    max-width: var(--container-width);
    margin: 0 auto;
    padding-inline: var(--gutter);
    box-sizing: border-box;
  }

  .how__step {
    display: flex;
    gap: 56px;
    align-items: center;
  }

  .how__text,
  .how__visual {
    flex: 1 1 0;
    min-width: 0;
  }

  .how__eyebrow {
    font-family: var(--font-display);
    font-size: calc(20rem / 16);
    font-weight: 600;
    color: var(--color-violet);
  }

  .how__heading {
    margin: 10px 0 14px;
    font-family: var(--font-display);
    font-size: calc(46rem / 16);
    line-height: 1.08;
    font-weight: 600;
    letter-spacing: -0.02em;
  }

  .how__desc {
    margin: 0;
    max-width: 460px;
    font-size: calc(19rem / 16);
    line-height: 1.65;
    color: var(--color-ink-soft);
  }

  /* ---------- Product mock-ups inside each step: light Mac-style windows ---------- */
  .mock {
    background: var(--color-white);
    border: 1px solid var(--color-line);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
  }

  /* Title bar: traffic lights on the left (as on a Mac, even in RTL), title centred. */
  .mock__bar {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    background: var(--color-cream-soft);
    border-bottom: 1px solid var(--color-line-soft);
  }

  .mock__dots {
    display: flex;
    gap: 7px;
    margin-inline-start: auto; /* inline-end is the left edge in RTL */
    direction: ltr;
  }

  [dir="ltr"] .mock__dots {
    margin-inline-start: 0;
  }

  .mock__dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
  }

  .mock__dot--close { background: #FF5F57; }
  .mock__dot--min { background: #FEBC2E; }
  .mock__dot--max { background: #28C840; }

  .mock__title {
    position: absolute;
    inset-inline: 72px;
    text-align: center;
    font-family: var(--font-display);
    font-size: calc(15rem / 16);
    font-weight: 600;
    color: var(--color-ink-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mock__file {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: calc(13rem / 16);
    font-weight: 500;
    color: var(--color-ink-muted);
  }

  /* In RTL the LTR file name sits left of the title, so the separator goes on its right. */
  .mock__file::after {
    content: " ·";
  }

  .mock__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 28px;
  }

  .mock--roomy .mock__body {
    gap: 16px;
  }

  .mock__footnote {
    margin-top: auto;
    font-size: calc(15rem / 16);
    color: var(--color-ink-soft);
  }

  /* The business prompt, styled as a Markdown file with line numbers. */
  .prompt {
    counter-reset: prompt-line;
    background: var(--color-cream);
    border: 1px solid var(--color-line-soft);
    border-radius: 14px;
    padding: 14px 0;
    font-size: calc(16rem / 16);
    line-height: 1.75;
  }

  .prompt__line {
    counter-increment: prompt-line;
    position: relative;
    margin: 0;
    padding-inline: 40px 16px;
  }

  .prompt__line::before {
    content: counter(prompt-line);
    position: absolute;
    inset-inline-start: 0;
    width: 36px;
    text-align: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: calc(12rem / 16);
    line-height: calc(1.75 * 16rem / 12);
    color: var(--color-violet-mist);
    user-select: none;
  }

  .prompt__line--heading {
    font-weight: 700;
    color: var(--color-ink);
  }

  .prompt__line--heading:not(:first-child) {
    margin-top: 8px;
  }

  .prompt__line:not(.prompt__line--heading) {
    color: var(--color-ink-soft);
  }

  .prompt__hash {
    margin-inline-end: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--color-violet);
  }

  .prompt__arrow {
    color: var(--color-violet);
  }

  .prompt__cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    margin-inline-start: 3px;
    vertical-align: -0.2em;
    background: var(--color-violet);
    animation: prompt-cursor 1.1s steps(1) infinite;
  }

  @keyframes prompt-cursor {
    50% { opacity: 0; }
  }

  .chip-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .chip {
    font-size: calc(14rem / 16);
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: var(--color-cream-soft);
    padding: 5px 11px;
  }

  .chip__key {
    font-weight: 600;
    color: var(--color-violet-strong);
  }

  /*
   * WhatsApp-style chat: the customer's messages in white on the right, the
   * business's replies in green on the left (RTL), each with a squared "tail"
   * corner at the top.
   */
  .chat {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    border-radius: 18px;
    background: var(--color-whatsapp-chat);
  }

  .bubble {
    max-width: 80%;
    padding: 8px 12px;
    font-size: calc(16rem / 16);
    color: var(--color-whatsapp-ink);
    border-radius: 10px;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  }

  .bubble--in {
    align-self: flex-start;
    background: var(--color-white);
    border-start-start-radius: 0;
  }

  .bubble--out {
    align-self: flex-end;
    background: var(--color-whatsapp-out);
    border-start-end-radius: 0;
  }

  /* Time (and ticks on sent messages), tucked into the last line's end when it fits. */
  .bubble__meta {
    float: inline-end;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin: 6px 0 -4px;
    padding-inline-start: 10px;
    font-size: calc(12rem / 16);
    line-height: 1;
    color: var(--color-whatsapp-meta);
  }

  .bubble__ticks {
    color: var(--color-whatsapp-tick);
  }

  .saved-note {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--color-violet-tint);
    border-radius: 16px;
    padding: 12px 14px;
    font-size: calc(15rem / 16);
    color: var(--color-violet-deep);
  }

  .source {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--color-line);
    border-radius: 16px;
    padding: 14px 16px;
    font-size: calc(16rem / 16);
  }

  .source--unanswered {
    border: 1px dashed var(--color-violet-line);
    color: var(--color-ink-soft);
  }

  .source__handoff {
    font-size: calc(13rem / 16);
    font-weight: 700;
    color: var(--color-violet-strong);
  }

  .channel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .channel-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--color-line);
    border-radius: 16px;
    padding: 9px 14px 9px 12px;
    font-size: calc(16rem / 16);
    font-weight: 600;
  }

  .channel-status__name {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    white-space: nowrap;
  }

  .channel-status__dot {
    color: var(--color-green-bright);
  }

  @media (max-width: 900px) {
    .mock__body {
      padding: 20px;
    }

    .channel-status {
      padding: 8px 10px;
      font-size: calc(15rem / 16);
    }

    .channel-status__name {
      gap: 8px;
    }

    .channel-status .channel-icon {
      width: 26px;
      height: 26px;
    }

    .mock__file {
      display: none;
    }

    .how__heading {
      font-size: calc(34rem / 16);
    }

    .how__step {
      flex-direction: column;
    }

    .how__node {
      width: 70px;
    }

    .how__label {
      display: none;
    }
  }

  /* Narrow phones: the icons carry the tiles, so the status dot steps aside. */
  @media (max-width: 420px) {
    .channel-status {
      font-size: calc(14rem / 16);
    }

    .channel-status__name {
      gap: 6px;
    }

    .channel-status .channel-icon {
      width: 24px;
      height: 24px;
    }

    .channel-status__dot {
      display: none;
    }
  }

  @supports (animation-timeline: view()) {
    @media (min-width: 901px) and (prefers-reduced-motion: no-preference) {
      .how {
        height: 2800px;
        view-timeline: --how block;
        padding: 0;
      }

      .how__sticky {
        position: sticky;
        top: 90px;
        height: 780px;
        padding-top: 20px;
      }

      .how__track {
        flex-direction: row;
        gap: 0;
        width: 400%;
      }

      .how__panel {
        flex: 0 0 25%;
        max-width: none;
        padding-inline: max(var(--gutter), 50vw - 588px);
      }

      .how__track,
      .how__fill,
      .how__dot {
        animation-timeline: --how;
        animation-range: contain 0% contain 100%;
        animation-fill-mode: both;
        animation-timing-function: linear;
        animation-duration: auto;
      }

      .how__track {
        animation-name: how-slide;
      }

      @keyframes how-slide {
        0%, 16% { translate: 0 0; }
        27%, 41% { translate: calc(25% * var(--slide-direction)) 0; }
        52%, 66% { translate: calc(50% * var(--slide-direction)) 0; }
        77%, 100% { translate: calc(75% * var(--slide-direction)) 0; }
      }

      .how__fill {
        animation-name: how-progress;
      }

      @keyframes how-progress {
        0%, 16% { scale: 0 1; }
        27%, 41% { scale: 0.333 1; }
        52%, 66% { scale: 0.666 1; }
        77%, 100% { scale: 1 1; }
      }

      .how__node--1 .how__dot { animation-name: how-dot-1; }
      .how__node--2 .how__dot { animation-name: how-dot-2; }
      .how__node--3 .how__dot { animation-name: how-dot-3; }
      .how__node--4 .how__dot { animation-name: how-dot-4; }

      @keyframes how-dot-1 {
        0%, 100% { background: var(--color-violet); color: var(--color-white); border-color: var(--color-violet); }
      }

      @keyframes how-dot-2 {
        0%, 22% { background: var(--color-white); color: var(--color-ink); border-color: var(--color-line); }
        27%, 100% { background: var(--color-violet); color: var(--color-white); border-color: var(--color-violet); }
      }

      @keyframes how-dot-3 {
        0%, 47% { background: var(--color-white); color: var(--color-ink); border-color: var(--color-line); }
        52%, 100% { background: var(--color-violet); color: var(--color-white); border-color: var(--color-violet); }
      }

      @keyframes how-dot-4 {
        0%, 72% { background: var(--color-white); color: var(--color-ink); border-color: var(--color-line); }
        77%, 100% { background: var(--color-violet); color: var(--color-white); border-color: var(--color-violet); }
      }
    }
  }

  /*
   * Accessibility menu: with animations stopped or enlarged text, use the
   * stacked layout — the pinned one depends on motion and fixed heights.
   */
  html:is([data-a11y-motion="off"], [data-a11y-text]) .how {
    height: auto;
    padding: 40px 0 80px;
  }

  html:is([data-a11y-motion="off"], [data-a11y-text]) .how__sticky {
    position: static;
    height: auto;
    padding-top: 0;
  }

  html:is([data-a11y-motion="off"], [data-a11y-text]) .how__track {
    flex-direction: column;
    gap: 32px;
    width: auto;
  }

  html:is([data-a11y-motion="off"], [data-a11y-text]) .how__panel {
    flex: none;
    max-width: var(--container-width);
    padding-inline: var(--gutter);
  }

  html:is([data-a11y-motion="off"], [data-a11y-text]) :is(.how__track, .how__fill, .how__dot) {
    animation: none;
  }
}
