/* Moving between Rent, Roommates and Partner. Loaded after css/home.css, whose whole-screen slide
   these keyframes replace; js/tab-slide.js sets the direction in --hm-slide-from, marks a tab
   switch with html[data-tab-slide] before the old view is captured, and marks the arriving view
   with html[data-arriving].

   Layered, in order: the page colour holds still, the old view eases away a little and fades,
   the new one drifts in from the same side, then its words and search arrive one after another.
   The header is its own layer and never moves. Phones move differently: see the end of this file. */
@keyframes hm-slide-out { to { opacity: 0; transform: translateX(calc(var(--hm-slide-from) * -.05)) scale(.985); } }
@keyframes hm-slide-in { from { opacity: 0; transform: translateX(calc(var(--hm-slide-from) * .07)); } }

/* css/site-nav.css names <main> and the active header pill for the move between header pages.
   Here the whole view slides as one, so those names are taken back off. */
:root:active-view-transition main,
:root:active-view-transition .rr-links a[aria-current="page"] { view-transition-name: none; }

/* Behind both views, so a crossfade never shows a flash of another colour. */
::view-transition { background: var(--st-bg, #fff); }
::view-transition-group(root) { animation: none; }
::view-transition-image-pair(root) { isolation: auto; }
::view-transition-old(root), ::view-transition-new(root) { mix-blend-mode: normal; transform-origin: 50% 40vh; }
::view-transition-old(root) { animation: hm-slide-out .26s cubic-bezier(.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: hm-slide-in .64s .16s cubic-bezier(.16, 1, .3, 1) both; }

@keyframes rr-arrive { from { opacity: 0; transform: translateY(18px); } }
[data-arriving] #main .st-hero__copy > *,
[data-arriving] #main .rx-visual,
[data-arriving] #main .st-ch--hero .hm-search { animation: rr-arrive .52s calc(.2s + var(--rr-at, 0) * 70ms) cubic-bezier(.16, 1, .3, 1) both; }
[data-arriving] #main .st-hero__copy > :nth-child(2) { --rr-at: 1; }
[data-arriving] #main .st-hero__copy > :nth-child(3) { --rr-at: 2; }
[data-arriving] #main .rx-visual { --rr-at: 2; }
[data-arriving] #main .st-ch--hero .hm-search { --rr-at: 3; }

/* The active tab's pill fades in, so the press is answered at once. */
.hm-tab { transition: color .25s ease, background-color .25s ease, box-shadow .25s ease; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .hm-tab { transition: none; }
}

/* ── Phones ───────────────────────────────────────────────────────────────
   One rule above all: something opaque is always on screen. The old view holds still, fully
   opaque, and the new one fades in over it while drifting from the side of its tab. Nothing fades
   to transparent over the bare page colour, which showed as white bands in light mode and black
   bands in dark mode, and nothing is scaled, which left gaps at the edges.

   On a tab switch only <main> moves: the header, the cookie banner and the page colour behind are
   the same in both views and stay put, and the tab bar glides from where it sat in the old view
   to where it sits in the new one. */
@keyframes hm-view-in { from { opacity: 0; transform: translateX(calc(var(--hm-slide-from) * .06)); } }
@keyframes hm-hold { to { opacity: 1; } }

@media (max-width: 767px) {
  :root[data-tab-slide]:active-view-transition main { view-transition-name: hm-view; }
  :root[data-tab-slide]:active-view-transition #main .st-ch--hero .hm-tabs { view-transition-name: hm-tabs; }
  /* Fixed layers outside <main> would otherwise sink behind the moving view until it lands. */
  :root[data-tab-slide]:active-view-transition .rr-consent { view-transition-name: hm-consent; }
  :root[data-tab-slide]:active-view-transition #roomrr-toast-region { view-transition-name: hm-toasts; }

  /* Between pages (the logo, Back to a fresh page): the old page stays until the new one covers it. */
  ::view-transition-old(root) { animation: hm-hold .42s linear both; }
  ::view-transition-new(root) { animation: hm-view-in .38s cubic-bezier(.22, 1, .36, 1) both; }

  /* A tab switch: everything outside <main> is the same in both views, so it simply stays. */
  :root[data-tab-slide]::view-transition-old(root),
  :root[data-tab-slide]::view-transition-new(root) { animation: none; }
  :root[data-tab-slide]::view-transition-group(hm-view) { animation: none; overflow: clip; }
  :root[data-tab-slide]::view-transition-image-pair(hm-view) { isolation: auto; }
  :root[data-tab-slide]::view-transition-old(hm-view),
  :root[data-tab-slide]::view-transition-new(hm-view) { mix-blend-mode: normal; height: auto; }
  :root[data-tab-slide]::view-transition-old(hm-view) { animation: hm-hold .42s linear both; }
  :root[data-tab-slide]::view-transition-new(hm-view) { animation: hm-view-in .38s cubic-bezier(.22, 1, .36, 1) both; }
  /* Both snapshots of the bar already show the new tab chosen, so it only needs to move. */
  :root[data-tab-slide]::view-transition-group(hm-tabs) { z-index: 2; animation-duration: .38s; animation-timing-function: cubic-bezier(.22, 1, .36, 1); }
  :root[data-tab-slide]::view-transition-old(hm-tabs) { animation: none; opacity: 0; }
  :root[data-tab-slide]::view-transition-new(hm-tabs) { animation: none; }
  :root[data-tab-slide]::view-transition-group(rr-nav),
  :root[data-tab-slide]::view-transition-group(hm-consent),
  :root[data-tab-slide]::view-transition-group(hm-toasts) { z-index: 3; animation: none; }
  :root[data-tab-slide]::view-transition-old(hm-consent),
  :root[data-tab-slide]::view-transition-old(hm-toasts) { display: none; }
  :root[data-tab-slide]::view-transition-new(hm-consent),
  :root[data-tab-slide]::view-transition-new(hm-toasts) { animation: none; }

  /* The words rise in; the search card comes with the view, under the tab bar. */
  [data-arriving] #main .st-ch--hero .hm-search { animation: none; }
  [data-arriving] #main .st-hero__copy > *,
  [data-arriving] #main .rx-visual { animation-duration: .46s; animation-delay: calc(.12s + var(--rr-at, 0) * 60ms); }

  /* The new tab's pill shows at once, text and all. Easing the text colour on its own left white
     words on the pale glass for a moment, so the old tab looked blank. */
  .hm-tab { transition: box-shadow .25s ease; }
}

@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root),
  ::view-transition-group(hm-view), ::view-transition-old(hm-view), ::view-transition-new(hm-view),
  ::view-transition-group(hm-tabs) { animation: none; }
  [data-arriving] #main .st-hero__copy > *, [data-arriving] #main .rx-visual { animation: none; }
  .hm-tab { transition: none; }
}
