/* Motion for the home page and product pages (linked next to motion.js).
   Everything here enhances content that is already fully visible. The
   script adds data-motion-armed only when it can animate, and every rule
   that moves anything sits inside prefers-reduced-motion: no-preference,
   so reduced-motion visitors and no-JS visitors get the final state.
   Only transform, translate, scale, opacity, clip-path and filter animate. */

:root {
  --motion-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ─── Scroll reveal: data-motion="reveal | stagger | rows" ───────────── */

@media (prefers-reduced-motion: no-preference) {
  [data-motion-armed] { opacity: 0; }

  @keyframes motion-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes motion-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  [data-motion-in] { animation: motion-in 0.65s var(--motion-ease) backwards; }

  /* A full-width band fades only; moving it would open a gap at its edge. */
  .closing-cta[data-motion-in] { animation-name: motion-fade; }

  /* Sibling delay, assigned by the module per batch and capped at 5. */
  [data-motion-i="1"] { animation-delay: 60ms; }
  [data-motion-i="2"] { animation-delay: 120ms; }
  [data-motion-i="3"] { animation-delay: 180ms; }
  [data-motion-i="4"] { animation-delay: 240ms; }
  [data-motion-i="5"] { animation-delay: 300ms; }

  /* A table row settles in, then a wash of purple fades off its cells. */
  @keyframes motion-row-wash {
    from { background-color: color-mix(in oklch, var(--purple) 12%, transparent); }
    to   { background-color: transparent; }
  }

  tr[data-motion-flash] > th,
  tr[data-motion-flash] > td {
    animation: motion-row-wash 1.1s var(--motion-ease) both;
  }
}

/* ─── Hero entrance (CSS only) ───────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  /* Text never starts at opacity 0: the headline or lede is the largest
     paint, and held-back text delays it. Text rises into place; only the
     icon, badges and buttons fade. */
  @keyframes motion-rise {
    from { translate: 0 14px; }
    to   { translate: none; }
  }
  @keyframes motion-pop {
    from { opacity: 0; scale: 0.9; }
    to   { opacity: 1; scale: 1; }
  }

  /* Home hero: the product window rises, the finding card slides in, the
     three app icons pop one after another. Desktop only (the block is hidden
     below 1200px), and pointer-events stay off so nothing here takes a click. */
  @keyframes motion-rise-scale {
    from { opacity: 0; transform: translateY(28px) scale(0.975); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes motion-slide-in {
    from { opacity: 0; transform: translateX(-24px); }
    to   { opacity: 1; transform: none; }
  }
  .hero-visual-shot { animation: motion-rise-scale 1s var(--motion-ease) 0.1s backwards; }
  .hero-visual-card { animation: motion-slide-in 0.8s var(--motion-ease) 0.55s backwards; }
  .hero-visual-icons img { animation: motion-pop 0.7s var(--motion-ease) backwards; }
  .hero-visual-icons img:nth-child(1) { animation-delay: 0.35s; }
  .hero-visual-icons img:nth-child(2) { animation-delay: 0.45s; }
  .hero-visual-icons img:nth-child(3) { animation-delay: 0.55s; }

  .app-hero-icon { animation: motion-pop 0.8s var(--motion-ease) backwards; }
  .app-hero-phone { animation: motion-pop 0.9s var(--motion-ease) 0.2s backwards; }
  .app-hero-name,
  .app-hero-tagline,
  .app-hero-fine-print,
  :is(.catalog-hero, .kit-hero, .tools-hero) > * {
    animation: motion-rise 0.75s var(--motion-ease) backwards;
  }
  .app-hero-meta,
  .app-hero-actions,
  :is(.catalog-hero, .kit-hero, .tools-hero) > .eyebrow,
  .catalog-hero .catalog-actions {
    animation: motion-in 0.7s var(--motion-ease) backwards;
  }

  .app-hero-meta { animation-delay: 40ms; }
  .app-hero-name { animation-delay: 90ms; }
  .app-hero-tagline { animation-delay: 150ms; }
  .app-hero-actions { animation-delay: 220ms; }
  .app-hero-fine-print { animation-delay: 300ms; }
  :is(.catalog-hero, .kit-hero, .tools-hero) > :nth-child(2) { animation-delay: 70ms; }
  :is(.catalog-hero, .kit-hero, .tools-hero) > :nth-child(3) { animation-delay: 140ms; }
  :is(.catalog-hero, .kit-hero, .tools-hero) > :nth-child(n+4) { animation-delay: 210ms; }
}

/* ─── Scroll-linked touches (CSS only, where supported) ──────────────── */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* Reading progress: a thin bar across the top on <main data-progress>. */
    @keyframes motion-progress { to { transform: scaleX(1); } }
    [data-progress]::before {
      content: "";
      position: fixed;
      inset: 0 0 auto 0;
      height: 3px;
      z-index: 60;
      background: var(--purple);
      transform: scaleX(0);
      transform-origin: 0 50%;
      pointer-events: none;
      animation: motion-progress linear both;
      animation-timeline: scroll(root block);
    }

    /* Screenshots rise and settle as they enter, a slow depth cue. The
       individual translate/scale properties leave transform free for hover. */
    @keyframes motion-depth {
      from { translate: 0 34px; scale: 0.965; }
      to   { translate: none; scale: 1; }
    }
    @keyframes motion-settle {
      from { scale: 1.07; }
      to   { scale: 1; }
    }
    .screenshot-wide img,
    .screenshot-grid > *,
    .tools-shot,
    .catalog-feature-shot img,
    .founder-photo,
    .kit-bundle-covers,
    .pr-hero-visual .frame-browser {
      animation: motion-depth var(--motion-ease) backwards;
      animation-timeline: view();
      animation-range: entry 0% entry 75%;
    }
    .screenshot-grid > :nth-child(even) { animation-range: entry 10% entry 90%; }
    /* Card media settles as the card scrolls in, a touch slower than the card. */
    .peek > * {
      animation: motion-settle var(--motion-ease) backwards;
      animation-timeline: view();
      animation-range: entry 0% entry 90%;
    }
    .flagship-shot img {
      animation: motion-settle var(--motion-ease) backwards;
      animation-timeline: view();
      animation-range: entry 0% entry 100%;
    }

    /* Section headings draw a short accent rule as they come into view. */
    @keyframes motion-rule { from { transform: scaleX(0); } to { transform: scaleX(1); } }
    :is(.features-header h2, .screenshots-section > h2, .catalog-section-head h2)::after {
      animation: motion-rule var(--motion-ease) backwards;
      animation-timeline: view();
      animation-range: entry 20% entry 100%;
    }
  }
}

/* The rule itself is static content: it shows whether or not it animates. */
:is(.features-header h2, .screenshots-section > h2, .catalog-section-head h2)::after {
  content: "";
  display: block;
  width: 44px;
  height: 3px;
  margin-top: 16px;
  border-radius: 2px;
  background: var(--purple);
  transform-origin: 0 50%;
}

/* ─── Cards, buttons and links ───────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  .btn {
    transition:
      transform 0.25s var(--motion-ease),
      box-shadow 0.25s var(--motion-ease),
      opacity 0.15s;
  }
  .btn:active {
    transform: translateY(0) scale(0.97);
    transition-duration: 0.08s;
  }

  .hero-lede a,
  .hero-proof a {
    transition: text-underline-offset 0.3s var(--motion-ease);
  }
  .hero-lede a:hover, .hero-lede a:focus-visible,
  .hero-proof a:hover, .hero-proof a:focus-visible { text-underline-offset: 6px; }

  /* An underline that draws in, for the quiet "read more" links. */
  .report-more {
    background: linear-gradient(currentColor, currentColor) 0 100% / 0 1.5px no-repeat;
    padding-bottom: 2px;
    transition: background-size 0.35s var(--motion-ease);
  }
  .report-more:hover, .report-more:focus-visible {
    text-decoration: none;
    background-size: 100% 1.5px;
  }

  .catalog-card-cta { transition: translate 0.3s var(--motion-ease); }
  .catalog-card:hover .catalog-card-cta,
  .catalog-card:focus-visible .catalog-card-cta { translate: 4px 0; }
  .catalog-card-static .catalog-card-cta { translate: none; }

  /* FAQ chevron eases instead of snapping. */
  .faq-item summary::after { transition: transform 0.3s var(--motion-ease), opacity 0.2s; }
  .faq-item summary:hover::after { opacity: 0.8; }
}

@media (prefers-reduced-motion: no-preference) and (hover: hover) {
  .catalog-card:not(.catalog-card-static),
  .kit-card,
  .submit-grid a,
  .tool-chip {
    transition:
      translate 0.35s var(--motion-ease),
      border-color 0.2s,
      box-shadow 0.35s var(--motion-ease),
      background-color 0.2s,
      color 0.2s;
  }
  .catalog-card:not(.catalog-card-static):hover,
  .catalog-card:not(.catalog-card-static):focus-visible,
  .kit-card:hover,
  .kit-card:focus-within,
  .submit-grid a:hover,
  .submit-grid a:focus-visible { translate: 0 -3px; }
  .kit-card:hover,
  .kit-card:focus-within { box-shadow: 0 14px 34px oklch(50% 0.24 310 / 0.12); border-color: var(--purple-dim); }
  .tool-chip:hover, .tool-chip:focus-visible { translate: 0 -1px; }

  /* Feature grid: a short accent rule draws across the top of the hovered cell. */
  .feature-item { position: relative; }
  .feature-item::before {
    content: "";
    position: absolute;
    top: 0;
    left: 28px;
    width: 36px;
    height: 2px;
    background: var(--purple);
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform 0.5s var(--motion-ease);
  }
  .feature-item:hover::before,
  .feature-item:focus-within::before { transform: scaleX(1); }

  /* Gallery: a gentle zoom on bare phone screenshots (framed ones lift instead). */
  .screenshot-grid > img {
    transition: transform 0.6s var(--motion-ease), box-shadow 0.6s var(--motion-ease);
  }
  .screenshot-grid > img:hover {
    transform: scale(1.03);
    box-shadow: 0 16px 36px oklch(50% 0.24 310 / 0.16);
    position: relative;
    z-index: 1;
  }
}

/* ─── Smooth <details> (FAQ, comparison) where interpolate-size exists ── */

@supports (interpolate-size: allow-keywords) {
  @media (prefers-reduced-motion: no-preference) {
    :root { interpolate-size: allow-keywords; }
    :is(.faq-item, .tool-faq details, .pr-compare)::details-content {
      block-size: 0;
      overflow: clip;
      transition:
        block-size 0.4s var(--motion-ease),
        content-visibility 0.4s var(--motion-ease) allow-discrete;
    }
    :is(.faq-item, .tool-faq details, .pr-compare)[open]::details-content { block-size: auto; }
  }
}

/* ─── Slim sticky call to action (wired in site.js) ──────────────────── */

@media (min-width: 761px) {
  .sticky-cta:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 16px;
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 50;
    width: max-content;
    max-width: min(680px, calc(100vw - 32px));
    translate: -50% 0;
    padding: 8px 8px 8px 22px;
    border: 1px solid var(--line);
    border-radius: 100px;
    background: var(--panel);
    box-shadow: 0 10px 30px oklch(20% 0.08 310 / 0.16);
  }
  .sticky-cta-text { font-size: 0.85rem; color: var(--muted); line-height: 1.3; }
  .sticky-cta-text strong { color: var(--ink); font-size: 0.95rem; margin-right: 6px; }
  .sticky-cta .btn { flex: none; padding: 10px 20px; }
  body.has-sticky-cta { padding-bottom: 80px; }
}

.sticky-cta-close {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.sticky-cta-close:hover { background: var(--purple-light); color: var(--ink); }

@media (prefers-reduced-motion: no-preference) {
  @keyframes sticky-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
  }
  .sticky-cta:not([hidden]) { animation: sticky-in 0.45s var(--motion-ease) backwards; }
}

/* ─── Hero media slot: data-motion="video" ───────────────────────────── */

.hero-media { position: relative; }

.hero-media video {
  position: absolute;
  inset: 1px;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  object-fit: cover;
  border-radius: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--motion-ease);
}

.hero-media.is-playing video { opacity: 1; }

.motion-toggle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  min-height: 32px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: color-mix(in oklch, var(--bg) 92%, transparent);
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.motion-toggle:hover { background: var(--purple-light); }
.motion-toggle[hidden] { display: none; }

/* ─── Error to fix: data-motion="fix" ────────────────────────────────── */

.fix-demo .fix-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  max-width: 900px;
  margin: 1.6rem 0 1rem;
}

.fix-panel {
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.fix-label {
  margin: 0 0 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.fix-raw {
  background: color-mix(in oklch, var(--ink) 5%, var(--bg));
}

.fix-raw pre,
.fix-diff {
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  word-spacing: 0;
  white-space: pre;
  overflow-x: auto;
}

.fix-raw code { font: inherit; word-spacing: 0; }

.fix-bad {
  text-decoration: underline wavy var(--purple);
  text-underline-offset: 3px;
}

.fix-link {
  width: 2px;
  height: 22px;
  margin-left: 32px;
  background: var(--purple-dim);
  transform-origin: top;
}

.fix-explain { margin: 0; max-width: 62ch; }
.fix-explain code { font-size: 0.9em; }

.fix-diff { margin-top: 10px; white-space: normal; }
.fix-diff div { padding: 1px 8px; border-radius: 4px; white-space: pre-wrap; }
.fix-fix-panel { margin-top: 12px; }
.fix-diff .fix-minus { color: var(--muted); }
.fix-diff .fix-plus {
  background: color-mix(in oklch, var(--purple) 10%, var(--bg));
  color: var(--ink);
  font-weight: 600;
}

.fix-note {
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 62ch;
}

.fix-replay[hidden] { display: none; }
.fix-replay { margin-top: 0.8rem; }

@media (prefers-reduced-motion: no-preference) {
  /* Before it plays, only the raw error shows. Space stays reserved, so
     nothing below the demo moves. */
  .fix-demo.is-armed:not(.is-playing) .fix-step { opacity: 0; }
  .fix-demo.is-armed:not(.is-playing) .fix-link { transform: scaleY(0); }

  @keyframes fix-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes fix-draw {
    from { transform: scaleY(0); }
    to   { transform: scaleY(1); }
  }
  @keyframes fix-wash {
    from { background-color: color-mix(in oklch, var(--purple) 28%, var(--bg)); }
    to   { background-color: color-mix(in oklch, var(--purple) 10%, var(--bg)); }
  }

  .fix-demo.is-playing .fix-link {
    animation: fix-draw 0.5s var(--motion-ease) 0.9s both;
  }
  .fix-demo.is-playing .fix-explain-panel {
    animation: fix-in 0.6s var(--motion-ease) 1.3s both;
  }
  .fix-demo.is-playing .fix-fix-panel {
    animation: fix-in 0.6s var(--motion-ease) 2.1s both;
  }
  .fix-demo.is-playing .fix-plus {
    animation: fix-wash 1.2s var(--motion-ease) 2.5s both;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-motion-armed] { opacity: 1; }
  .hero-media video,
  .motion-toggle,
  .fix-replay { display: none; }
}

/* ─── YouTube embed: poster and link first, player once near the screen ── */
.yt-embed {
  position: relative;
  max-width: 1120px;
  margin-inline: auto;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--ink);
  box-shadow: 0 30px 80px oklch(20% 0.08 310 / 0.22), 0 4px 16px oklch(20% 0.08 310 / 0.1);
}
.yt-embed .yt-poster,
.yt-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.yt-embed .yt-poster { object-fit: cover; }
.yt-embed .yt-play {
  position: absolute;
  left: 50%;
  bottom: 24px;
  translate: -50% 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 8px 24px oklch(20% 0.08 310 / 0.25);
}
.yt-embed .yt-play:hover { background: var(--purple-light); }
.yt-embed.is-loaded .yt-poster,
.yt-embed.is-loaded .yt-play { display: none; }

.tour-section .section-intro { color: var(--muted); max-width: 640px; margin-bottom: 24px; }
.tour-section.catalog-section .yt-embed { margin-top: 8px; }
