<script lang="ts">
  import { reveal } from '$lib/actions/reveal';
  import Icon from '$lib/components/Icon.svelte';
  import type { HowItWorksContent } from '$lib/types';

  export let content: HowItWorksContent;
</script>

<section id="how-it-works" use:reveal={{ delay: 30 }} class="reveal-block">
  <div class="how-it-works-inner">
    <div class="how-it-works-header">
      <h2 class="section-heading">{content.title}</h2>
      {#if content.intro}
        <p class="how-it-works-intro">{content.intro}</p>
      {/if}
    </div>

    <div class="how-it-works-flow" aria-label="How it works">
      {#each content.steps as step, index}
        <article class="how-it-works-step">
          <div class="how-it-works-badge" aria-hidden="true">
            <span class="how-it-works-count">0{index + 1}</span>
          </div>
          {#if step.icon}
            <div class="how-it-works-icon-bubble">
              <Icon name={step.icon} className="how-it-works-icon" />
            </div>
          {/if}
          <h3>{step.title}</h3>
          <p>{step.body}</p>
        </article>

        {#if index < content.steps.length - 1}
          <div class="how-it-works-connector" aria-hidden="true">
            <span class="how-it-works-connector-line"></span>
            <div class="how-it-works-connector-bubble">
              <Icon name="fas fa-paw" className="how-it-works-connector-icon" />
            </div>
            <span class="how-it-works-connector-line"></span>
          </div>
        {/if}
      {/each}
    </div>
  </div>
</section>

<style>
  :global(.reveal-ready.reveal-block) {
    opacity: 0;
    transform: translate3d(0, var(--reveal-distance, 24px), 0);
    transition:
      opacity 0.55s ease,
      transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: var(--reveal-delay, 0ms);
  }

  :global(.reveal-visible.reveal-block) {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }

  #how-it-works {
    background: #fff;
    padding-top: 20px;
  }

  .how-it-works-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 50px;
  }

  .how-it-works-header {
    text-align: center;
  }

  .how-it-works-intro {
    max-width: 640px;
    margin: 14px auto 0;
    color: #4c5056;
    font-size: 16px;
    line-height: 1.6;
  }

  .how-it-works-flow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 18px;
    align-items: stretch;
    margin-top: 34px;
  }

  .how-it-works-step {
    position: relative;
    padding: 26px 24px;
    border-radius: 28px;
    background:
      radial-gradient(circle at top center, rgba(255, 209, 0, 0.18), transparent 36%),
      linear-gradient(180deg, #fffaf0 0%, #f8f4ea 100%);
    box-shadow:
      inset 0 0 0 1px rgba(17, 20, 24, 0.05),
      0 14px 28px rgba(17, 20, 24, 0.04);
    text-align: center;
  }

  .how-it-works-badge {
    display: inline-flex;
    align-items: center;
    margin-bottom: 14px;
    padding: 8px 12px;
    border-radius: 999px;
    background: #fff;
    box-shadow: inset 0 0 0 1px rgba(17, 20, 24, 0.06);
  }

  .how-it-works-count {
    color: var(--green);
    font-family: var(--font-head);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
  }

  .how-it-works-icon-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--green);
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.08),
      0 16px 28px rgba(33, 48, 33, 0.16);
  }

  :global(.how-it-works-icon.icon) {
    color: #fff;
    font-size: 24px;
  }

  .how-it-works-step h3 {
    margin: 0 0 10px;
    font-size: 20px;
  }

  .how-it-works-step p {
    margin: 0;
    color: #4c5056;
    font-size: 15px;
    line-height: 1.6;
  }

  .how-it-works-connector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 90px;
  }

  .how-it-works-connector-line {
    width: 24px;
    height: 2px;
    border-radius: 999px;
    background: rgba(33, 48, 33, 0.22);
  }

  .how-it-works-connector-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(180deg, #254129 0%, #213021 100%);
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.08),
      0 14px 24px rgba(33, 48, 33, 0.14);
  }

  :global(.how-it-works-connector-icon.icon) {
    color: var(--green);
    color: #ffd54a;
    font-size: 16px;
  }

  @media (max-width: 768px) {
    #how-it-works {
      padding-top: 6px;
    }

    .how-it-works-inner {
      padding: 0 24px;
    }

    .how-it-works-intro {
      font-size: 15px;
      line-height: 1.55;
    }

    .how-it-works-flow {
      grid-template-columns: 1fr;
      gap: 14px;
      margin-top: 26px;
    }

    .how-it-works-step {
      display: grid;
      grid-template-columns: auto 1fr auto;
      grid-template-areas:
        'icon title badge'
        'body body body';
      column-gap: 14px;
      row-gap: 10px;
      padding: 20px 18px;
      text-align: left;
    }

    .how-it-works-badge {
      grid-area: badge;
      justify-self: end;
      align-self: start;
      margin-bottom: 0;
      padding: 7px 10px;
    }

    .how-it-works-icon-bubble {
      grid-area: icon;
      width: 64px;
      height: 64px;
      margin: 0;
      align-self: start;
      box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        0 12px 22px rgba(33, 48, 33, 0.14);
    }

    .how-it-works-step h3 {
      grid-area: title;
      align-self: center;
      margin: 0;
      font-size: 18px;
      line-height: 1.2;
    }

    .how-it-works-step p {
      grid-area: body;
      margin-top: 2px;
      font-size: 14px;
      line-height: 1.55;
    }

    .how-it-works-connector {
      display: none;
    }
  }
</style>
