/* Everything decorative that moves. The resting state of every element lives in styles.css, so this file can fail or be removed without hiding anything. */
@media (prefers-reduced-motion: no-preference) {
  :root {
    --settle: cubic-bezier(0.2, 0.8, 0.2, 1);
    --slide: cubic-bezier(0.65, 0, 0.35, 1);
    interpolate-size: allow-keywords;
  }

  .crew { transition: grid-template-columns 520ms var(--settle), grid-template-rows 520ms var(--settle); }

  /* Moving between pages: the wordmark stays put while the page crossfades. */
  @view-transition { navigation: auto; }
  .brand { view-transition-name: brand-mark; }
  ::view-transition-old(root) { animation-duration: 180ms; }
  ::view-transition-new(root) { animation-duration: 280ms; }

  @keyframes rise {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes settle {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to { opacity: 1; transform: none; }
  }

  /* The three tiles work like a sliding puzzle: four cells, one empty. Twelve moves bring each tile home, so the loop has no visible jump. */
  @keyframes tile-1 {
    0% { transform: none; }
    7%, 21% { transform: translate(0, var(--step)); }
    28%, 42% { transform: translate(var(--step), var(--step)); }
    49%, 63% { transform: translate(var(--step), 0); }
    70%, 100% { transform: none; }
  }
  @keyframes tile-2 {
    0%, 7% { transform: none; }
    14%, 28% { transform: translate(calc(-1 * var(--step)), 0); }
    35%, 49% { transform: translate(calc(-1 * var(--step)), var(--step)); }
    56%, 70% { transform: translate(0, var(--step)); }
    77%, 100% { transform: none; }
  }
  @keyframes tile-3 {
    0%, 14% { transform: none; }
    21%, 35% { transform: translate(0, calc(-1 * var(--step))); }
    42%, 56% { transform: translate(calc(-1 * var(--step)), calc(-1 * var(--step))); }
    63%, 77% { transform: translate(calc(-1 * var(--step)), 0); }
    84%, 100% { transform: none; }
  }
  @keyframes tile-drop {
    from { opacity: 0; transform: translateY(calc(-1 * var(--step))); }
    to { opacity: 1; transform: none; }
  }
  @keyframes tile-cool {
    from, 55% { background-color: var(--tile); }
    to { background-color: #FFFFFF; }
  }

  .wm-tile-1 { --tile: var(--pink); }
  .wm-tile-2 { --tile: var(--coral); }
  .wm-tile-3 { --tile: var(--orange); }

  /* Logo: the tiles land once on the homepage, and solve the puzzle in brand color while the logo is hovered or focused. */
  /* One move is 24 units of the file, and a tile is 20 wide. */
  .wordmark { --step: 120%; }
  .wm-tile { transition: background-color 240ms ease-out; }
  body:has(.hero) .wm-tile {
    animation: tile-drop 620ms var(--settle) both, tile-cool 1800ms ease-out both;
  }
  body:has(.hero) .wm-tile-1 { animation-delay: 200ms; }
  body:has(.hero) .wm-tile-2 { animation-delay: 320ms; }
  body:has(.hero) .wm-tile-3 { animation-delay: 440ms; }
  .brand:hover .wm-tile, .brand:focus-visible .wm-tile { background-color: var(--tile); }
  body .brand:hover .wm-tile-1, body .brand:focus-visible .wm-tile-1 { animation: tile-1 3s var(--slide) 0s infinite; }
  body .brand:hover .wm-tile-2, body .brand:focus-visible .wm-tile-2 { animation: tile-2 3s var(--slide) 0s infinite; }
  body .brand:hover .wm-tile-3, body .brand:focus-visible .wm-tile-3 { animation: tile-3 3s var(--slide) 0s infinite; }

  /* Menu control: the same puzzle as the logo while hovered or focused. A move is one cell plus the gap. */
  .tile-glyph { --step: calc(var(--cell) + var(--gap)); }
  .masthead-link:focus-visible .tile-glyph > :nth-child(1) { animation: tile-1 3s var(--slide) infinite; }
  .masthead-link:focus-visible .tile-glyph > :nth-child(2) { animation: tile-2 3s var(--slide) infinite; }
  .masthead-link:focus-visible .tile-glyph > :nth-child(3) { animation: tile-3 3s var(--slide) infinite; }
  /* Touch screens keep :hover after a tap, so the hover movement in this file waits for a real pointer. */
  @media (hover: hover) {
    .masthead-link:hover .tile-glyph > :nth-child(1) { animation: tile-1 3s var(--slide) infinite; }
    .masthead-link:hover .tile-glyph > :nth-child(2) { animation: tile-2 3s var(--slide) infinite; }
    .masthead-link:hover .tile-glyph > :nth-child(3) { animation: tile-3 3s var(--slide) infinite; }
    .door-tile:hover { filter: brightness(1.06); }
    .door-tile:hover span { transform: translateY(-3px); }
    .btn-ghost:hover svg { transform: translateX(2px); }
    .faq-item summary:hover > span:first-child { transform: translateX(6px); }
    .faq-item summary:hover .faq-icon { transform: rotate(90deg); }
    .faq-item[open] summary:hover .faq-icon { transform: none; }
    .theme-toggle:hover svg { transform: rotate(calc(var(--theme-turn) + 30deg)); }
  }

  /* Menu opening: the tiles start one move out of place and each slides into the empty cell in turn, the last three moves of the puzzle. */
  .site-menu { opacity: 0; transition: opacity 200ms ease-out, overlay 200ms allow-discrete, display 200ms allow-discrete; }
  .site-menu[open] { opacity: 1; }
  @starting-style { .site-menu[open] { opacity: 0; } }
  @keyframes menu-tile-1 { from { transform: translateY(calc(100% + var(--tile-gap))); } }
  @keyframes menu-tile-2 { from { transform: translateX(calc(-100% - var(--tile-gap))); } }
  @keyframes menu-tile-3 { from { transform: translateY(calc(-100% - var(--tile-gap))); } }
  .site-menu[open] .menu-tiles li { animation: 460ms var(--slide) both; }
  .site-menu[open] .menu-tiles li:nth-child(3) { animation-name: menu-tile-3; animation-delay: 80ms; }
  .site-menu[open] .menu-tiles li:nth-child(2) { animation-name: menu-tile-2; animation-delay: 260ms; }
  .site-menu[open] .menu-tiles li:nth-child(1) { animation-name: menu-tile-1; animation-delay: 440ms; }

  /* About page mark: the same puzzle, slower, because nothing else on that row is moving. */
  .tile-mark { --step: 100px; }
  .tile-mark .wm-tile-1 { animation: tile-1 10s var(--slide) infinite; }
  .tile-mark .wm-tile-2 { animation: tile-2 10s var(--slide) infinite; }
  .tile-mark .wm-tile-3 { animation: tile-3 10s var(--slide) infinite; }

  /* Page openings */
  .hero-copy > *, .page-head-stack > *, .page-head-grid > *, .crumbs { animation: rise 700ms var(--settle) both; }
  .hero-copy > :nth-child(2), .page-head-stack > :nth-child(2), .page-head-grid > :nth-child(2) { animation-delay: 90ms; }
  .hero-copy > :nth-child(3), .page-head-stack > :nth-child(3) { animation-delay: 180ms; }

  /* The door tiles land in the same order as the logo tiles. */
  .doors li { animation: settle 640ms var(--settle) both; }
  .doors li:nth-child(1) { animation-delay: 360ms; }
  .doors li:nth-child(2) { animation-delay: 470ms; }
  .doors li:nth-child(3) { animation-delay: 580ms; }
  .door-tile { transition: box-shadow var(--ease), filter 240ms ease-out; }
  .door-tile:focus-visible { filter: brightness(1.06); }
  .door-tile span { transition: transform 280ms var(--settle); }
  .door-tile:focus-visible span { transform: translateY(-3px); }

  /* Every arrow on the site leans the way it points. */
  .arrow { transition: transform 280ms var(--settle); }
  a:hover > .arrow, a:focus-visible > .arrow { transform: translate(3px, -3px); }

  /* Buttons */
  .btn { transition: background-color var(--ease), color var(--ease), transform 120ms ease-out, background-position 600ms var(--settle); }
  .btn:active { transform: translateY(1px); }
  .btn-ghost svg { transition: transform 280ms var(--settle); }
  /* A double length gradient: at rest the left half matches the brand gradient, on hover it slides across. */
  .btn-colorful:not(.gradient *) {
    background: linear-gradient(90deg, var(--pink), var(--coral) 24%, var(--orange) 50%, var(--coral) 76%, var(--pink)) 0 0 / 200% 100%;
  }
  .btn-colorful:not(.gradient *):hover { background-position: 100% 0; }

  /* Underlines draw from the left. */
  .link {
    border-bottom-color: transparent;
    background:
      linear-gradient(var(--fg), var(--fg)) 0 100% / 0 2px no-repeat,
      linear-gradient(var(--coral), var(--coral)) 0 100% / 100% 2px no-repeat;
    background-origin: border-box;
    transition: background-size 340ms var(--settle);
  }
  .link:hover, .link:focus-visible { border-bottom-color: transparent; background-size: 100% 2px, 100% 2px; }
  .gradient .link, .gradient .link:hover, .gradient .link:focus-visible { border-bottom-color: transparent; }
  .gradient .link { background-image: linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--on-ink), var(--on-ink)); }
  .masthead-wa, .menu-links a, .footer-nav a {
    background: linear-gradient(var(--coral), var(--coral)) 0 100% / 0 2px no-repeat;
    background-origin: border-box;
    transition: background-size 300ms var(--settle);
  }
  .masthead-wa:hover, .menu-links a:hover, .menu-links a[aria-current="page"], .footer-nav a:hover { border-bottom-color: transparent; background-size: 100% 2px; }

  /* Accordion */
  .faq-item summary > span:first-child { transition: transform 280ms var(--settle); }
  .faq-item::after { transition: transform 520ms var(--settle); }
  .faq-icon { transition: background-color 240ms ease-out, color 240ms ease-out, transform 420ms var(--settle); }
  .faq-icon::after { transition: transform 420ms var(--settle); }
  .faq-item[open] .faq-answer, .transcript[open] > p { animation: rise 420ms var(--settle) both; }
  @supports (interpolate-size: allow-keywords) and selector(::details-content) {
    .faq-item::details-content, .transcript::details-content {
      block-size: 0; overflow: clip;
      transition: block-size 420ms var(--settle), content-visibility 420ms allow-discrete;
    }
    .faq-item[open]::details-content, .transcript[open]::details-content { block-size: auto; }
  }

  /* Hovering a story slides a tile into the corner of its still. */
  @media (hover: hover) {
    .card-link .still::after, .next .still::after {
      content: ""; position: absolute; right: 12px; bottom: 12px; width: 44px; height: 44px; border-radius: var(--r-button);
      background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111111' stroke-width='2'%3E%3Cpath d='M7 17 17 7M8 7h9v9'/%3E%3C/svg%3E") center / 18px no-repeat,
        var(--gradient);
      opacity: 0; transform: translate(16px, 16px); transition: opacity 200ms ease-out, transform 420ms var(--settle);
    }
    .card-link:hover .still::after, .card-link:focus-visible .still::after, .next:hover .still::after, .next:focus-visible .still::after { opacity: 1; transform: none; }
  }
  .card-link .t-card { text-decoration: underline 2px transparent; text-underline-offset: 4px; transition: text-decoration-color 240ms ease-out; }
  .card-link:hover .t-card { text-decoration-color: currentColor; }

  /* Client band: the row of glass tiles moves left without end, at one steady speed. The row is written twice and each copy travels its own width, so the seam never shows. It stops under the pointer, while it is dragged, and while Pause logos is on; the light behind the glass keeps moving. A sideways touch belongs to the drag in marquee.js, and an up or down touch still scrolls the page. glass-tiles.js reads where the row is each frame, so this must stay a transform. */
  @keyframes marquee {
    to { transform: translateX(-100%); }
  }
  .marquee { overflow: hidden; touch-action: pan-y; }
  .marquee.is-dragging .clients { animation-play-state: paused; }
  /* 5.5 seconds a tile, so the speed stays the same when a logo is added: 12 logos, 66 seconds. */
  .marquee .clients { animation: marquee 66s linear infinite; }
  .marquee .clients[aria-hidden] { display: flex; }
  .marquee-pause { display: inline-flex; }
  .clients-band:has(.marquee-pause :checked) .clients { animation-play-state: paused; }
  @media (hover: hover) {
    .marquee:hover .clients { animation-play-state: paused; }
  }

  /* A photo folder leans on its hinge and its sheets rise out just before its page loads, so the click reads as opening it. */
  .folder-front { transition: transform 800ms cubic-bezier(0.34, 1.36, 0.5, 1); }
  .folder-sheet { transition: transform 750ms cubic-bezier(0.34, 1.36, 0.5, 1) calc(var(--depth) * 40ms); }

  /* Filtered stories settle into place when they appear. */
  .story-grid[data-filtered] > :not([hidden]) { animation: settle 420ms var(--settle) both; }

  /* Play buttons send one ring outward on hover. */
  @keyframes ring {
    from { opacity: 0.7; transform: scale(1); }
    to { opacity: 0; transform: scale(1.5); }
  }
  .frame-play svg { transition: transform 280ms var(--settle); }
  .frame:hover .frame-play svg { transform: translateX(2px); }
  .frame-play::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--ivory); opacity: 0; }
  .frame:hover .frame-play::after { animation: ring 900ms ease-out; }

  /* Video dialog */
  @keyframes dialog-in {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: none; }
  }
  @keyframes backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  .video-dialog[open] { animation: dialog-in 320ms var(--settle); }
  .video-dialog[open]::backdrop { animation: backdrop-in 240ms ease-out; }

  /* Theme toggle: the half disc takes its time turning over. Which way up it rests is set in styles.css. */
  .theme-toggle svg { transition: transform 460ms var(--settle); }

  /* Forms */
  @keyframes nudge {
    0%, 100% { transform: none; }
    30% { transform: translateX(-4px); }
    65% { transform: translateX(3px); }
  }
  .field input, .field textarea { transition: border-color var(--ease), background-color var(--ease); }
  .field.is-invalid input, .field.is-invalid textarea { animation: nudge 280ms ease-out; }
  .field-error:not([hidden]), .form-status:not(:empty) { animation: rise 280ms var(--settle) both; }
  .form-success:not([hidden]), .notice:not([hidden]) { animation: settle 520ms var(--settle) both; }

  /* The phone bar holds the menu, so it is there from the first frame and stays put while the page crossfades. */
  .thumb-bar { view-transition-name: thumb-bar; }
  .skip { transition: top 200ms var(--settle); }

  /* Scroll driven parts. Browsers without view timelines show these at rest. */
  @supports (animation-timeline: view()) {
    @keyframes wipe {
      from { clip-path: inset(0 0 100% 0 round var(--r-card)); }
      to { clip-path: inset(0 0 0 0 round var(--r-card)); }
    }
    .story-grid .still, .stills-grid .still, .door > .wrap > .still {
      animation: wipe linear both; animation-timeline: view(); animation-range: entry 0% entry 60%;
    }
    /* The four steps arrive in reading order, because the order is what the list explains. */
    @keyframes step-in {
      from { opacity: 0; transform: translateY(20px); }
      to { opacity: 1; transform: none; }
    }
    .process li { animation: step-in linear both; animation-timeline: view(); animation-range: entry 5% entry 70%; }
    /* Inside a sideways row the nearest scroller never moves vertically, so the wipe would stay part way. */
    @media (max-width: 599px) {
      .head-row + .story-grid .still { animation: none; }
    }
  }
}

@media (prefers-reduced-motion: no-preference) {
  .wa-widget { --spring: cubic-bezier(0.34, 1.45, 0.64, 1); }
  @keyframes wa-fit {
    from { opacity: 0; transform: translate(var(--from-x), 22px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes wa-word {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes wa-hop {
    0%, 60%, 100% { transform: none; }
    30% { transform: translateY(-7px); }
  }

  /* The launcher comes up and its tiles run the sliding puzzle once, then stay still until hovered. */
  .wa-launcher { transition: opacity 220ms ease-out, transform 320ms var(--spring), visibility 220ms, background-color var(--ease); }
  .wa-launcher.is-tucked[aria-expanded="false"] { opacity: 0; transform: translateY(14px); }
  .wa-launcher:not(.is-tucked) .tile-glyph > :nth-child(1) { animation: tile-1 3s var(--slide) 240ms; }
  .wa-launcher:not(.is-tucked) .tile-glyph > :nth-child(2) { animation: tile-2 3s var(--slide) 240ms; }
  .wa-launcher:not(.is-tucked) .tile-glyph > :nth-child(3) { animation: tile-3 3s var(--slide) 240ms; }
  .wa-launcher-labels > span { transition: transform 300ms var(--settle); }

  .wa-panel {
    transform-origin: 100% 100%;
    transition: opacity 200ms ease-out, transform 340ms var(--spring), display 340ms allow-discrete;
  }
  .wa-panel[hidden] { opacity: 0; transform: translateY(12px) scale(0.94); transition-timing-function: ease-out; transition-duration: 160ms; }
  @starting-style {
    .wa-panel:not([hidden]) { opacity: 0; transform: translateY(16px) scale(0.92); }
  }
  .wa-panel:not([hidden]) .wa-title { animation: rise 320ms var(--settle) 60ms both; }

  /* The brand's motion rule: the three pieces come together in sequence. */
  .wa-panel:not([hidden]) .wa-tile { animation: wa-fit 460ms var(--spring) 90ms both; }
  .wa-tile:nth-child(1) { --from-x: -22px; }
  .wa-tile:nth-child(2) { --from-x: 0px; }
  .wa-tile:nth-child(3) { --from-x: 22px; }
  .wa-panel:not([hidden]) .wa-tile:nth-child(2) { animation-delay: 160ms; }
  .wa-panel:not([hidden]) .wa-tile:nth-child(3) { animation-delay: 230ms; }

  .wa-tile { transition: color 180ms ease-out 80ms, background-color 0s; }
  .wa-tile:has(:checked) { transition: color 180ms ease-out 80ms, background-color 0s linear 420ms; }
  .wa-tile::before { transition: clip-path 420ms var(--settle); }
  .wa-tile::after { transition: transform 320ms var(--spring) 180ms; }
  .wa-tile:not(:has(:checked))::after { transition: transform 120ms ease-out; }

  .wa-compose { transition: grid-template-rows 360ms var(--settle); }
  .wa-typing > span { animation: wa-hop 620ms ease-in-out infinite; }
  .wa-typing > :nth-child(2) { animation-delay: 90ms; }
  .wa-typing > :nth-child(3) { animation-delay: 180ms; }
  .wa-word { animation: wa-word 340ms var(--settle) calc(var(--i) * 26ms) both; }
  .wa-slot { transition: border-color 240ms ease-out; }
  .wa-panel:not([hidden]) .is-ready .wa-send { animation: rise 380ms var(--settle) 260ms both; }
  .wa-send .arrow { transition: transform 220ms var(--spring); }

  @media (hover: hover) and (pointer: fine) {
    .wa-tile:not(:has(:checked)):hover::before { transition-duration: 220ms; }
    .wa-send:hover .arrow { transform: translate(3px, -3px); }
    .wa-launcher:hover .tile-glyph > :nth-child(1) { animation: tile-1 3s var(--slide) infinite; }
    .wa-launcher:hover .tile-glyph > :nth-child(2) { animation: tile-2 3s var(--slide) infinite; }
    .wa-launcher:hover .tile-glyph > :nth-child(3) { animation: tile-3 3s var(--slide) infinite; }
  }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
