/* One move, shared by every live case study. Only the box name changes
   (case-closet, case-attentive, case-knotel, case-transactional), so the
   clicked card is the only thing that travels. Atlassian has no name. */

@view-transition { navigation: auto; }

::view-transition-group(root),
::view-transition-old(root),
::view-transition-new(root) { animation: none; }

/* The root layer has to last as long as the box move, or the fade
   would be cut off when the group's own timer ends. */
@keyframes case-hold {
  from { opacity: 1; }
  to { opacity: 1; }
}
@keyframes case-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes case-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Going in: the homepage fades away over the first part of the move.
   The case page snapshot is already blank except for the box. */
:active-view-transition-type(case-in)::view-transition-group(root) {
  animation: case-hold 650ms linear both;
}
:active-view-transition-type(case-in)::view-transition-old(root) {
  animation: case-fade-out 400ms ease-out both;
}

/* Coming home: the case page fades out across the whole shrink,
   and the homepage fades in over the last part of that same move. */
:active-view-transition-type(case-back)::view-transition-group(root) {
  animation: case-hold 650ms linear both;
}
:active-view-transition-type(case-back)::view-transition-old(root) {
  animation: case-fade-out 650ms ease-in-out both;
}
:active-view-transition-type(case-back)::view-transition-new(root) {
  animation: case-fade-in 400ms ease-out 250ms both;
}

@media (prefers-reduced-motion: no-preference) {
  /* The homepage name is added only on the way home, and only for the
     case that was open. Naming every card would pull the others out of
     the page fade. */
  html.is-case-return[data-case-move="closet"] .card[data-case="closet"] .case-visual,
  body[data-case="closet"] .case-hero { view-transition-name: case-closet; }
  html.is-case-return[data-case-move="attentive"] .card[data-case="attentive"] .case-visual,
  body[data-case="attentive"] .case-hero { view-transition-name: case-attentive; }
  html.is-case-return[data-case-move="knotel"] .card[data-case="knotel"] .case-visual,
  body[data-case="knotel"] .kn-hero { view-transition-name: case-knotel; }
  html.is-case-return[data-case-move="transactional"] .card[data-case="transactional"] .case-visual,
  body[data-case="transactional"] .case-hero { view-transition-name: case-transactional; }

  /* The hero was mostly off screen, so no box flies home. */
  html.is-case-fade .card .case-visual { view-transition-name: none; }
}

::view-transition-group(case-closet),
::view-transition-image-pair(case-closet),
::view-transition-old(case-closet),
::view-transition-new(case-closet),
::view-transition-group(case-attentive),
::view-transition-image-pair(case-attentive),
::view-transition-old(case-attentive),
::view-transition-new(case-attentive),
::view-transition-group(case-knotel),
::view-transition-image-pair(case-knotel),
::view-transition-old(case-knotel),
::view-transition-new(case-knotel),
::view-transition-group(case-transactional),
::view-transition-image-pair(case-transactional),
::view-transition-old(case-transactional),
::view-transition-new(case-transactional) {
  border-radius: 2px;
  overflow: hidden;
}

::view-transition-group(case-closet),
::view-transition-group(case-attentive),
::view-transition-group(case-knotel),
::view-transition-group(case-transactional),
::view-transition-group(closet-phone) {
  animation-duration: 650ms;
  animation-timing-function: cubic-bezier(.32, .72, 0, 1);
}

/* Size the phone from its height so a changing box cannot stretch it.
   Only the closet picture uses this name. */
::view-transition-image-pair(closet-phone) { height: 100%; }
::view-transition-old(closet-phone),
::view-transition-new(closet-phone) {
  height: 100%;
  width: auto;
  object-fit: contain;
  overflow: clip;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

/* Hero is off screen: the whole case page fades, including the picture. */
html.is-case-fade-leave body {
  opacity: 0;
  transition: opacity 200ms ease-out;
}

/* Homepage arrival when nothing flies. Hidden until each piece rises in. */
html.is-case-fade .site-header,
html.is-case-fade .intro-inner > *,
html.is-case-fade .rail > .card,
html.is-case-fade .site-foot {
  opacity: 0;
}

/* Arriving: the title block is closed, and the rest of the page is hidden
   until the box has finished moving. */
html.is-case-arrive body[data-case] .closet-intro { grid-template-rows: 0fr; }
html.is-case-arrive body[data-case] .case-card > .case-hero,
html.is-case-arrive body[data-case] .case-card > .kn-hero { margin-top: 0; }
html.is-case-arrive.is-case-push body[data-case] .closet-intro {
  grid-template-rows: 1fr;
  transition: grid-template-rows 600ms cubic-bezier(.32, .72, 0, 1);
}
html.is-case-arrive.is-case-push body[data-case] .case-card > .case-hero,
html.is-case-arrive.is-case-push body[data-case] .case-card > .kn-hero {
  margin-top: 56px;
  transition: margin-top 600ms cubic-bezier(.32, .72, 0, 1);
}

html.is-case-arrive .site-header,
html.is-case-arrive .sq-badge,
html.is-case-arrive .back,
html.is-case-arrive .case-kicker,
html.is-case-arrive .case-lead h1,
html.is-case-arrive .facts,
html.is-case-arrive .case-cap,
html.is-case-arrive .case-main,
html.is-case-arrive .case-next,
html.is-case-arrive .site-foot { opacity: 0; }

html.is-case-push .back {
  animation: case-rise 600ms cubic-bezier(.32, .72, 0, 1) both;
}
html.is-case-push .case-kicker,
html.is-case-push .case-lead h1 {
  animation: case-rise 600ms cubic-bezier(.32, .72, 0, 1) 60ms both;
}
html.is-case-push .facts {
  animation: case-rise 600ms cubic-bezier(.32, .72, 0, 1) 120ms both;
}
html.is-case-push .site-header,
html.is-case-push .sq-badge {
  animation: case-fade 300ms ease-out both;
}
html.is-case-push .case-cap,
html.is-case-push .case-main,
html.is-case-push .case-next,
html.is-case-push .site-foot {
  animation: case-fade 300ms ease-out 150ms both;
}

@keyframes case-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes case-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
