/* Motion: page transitions, load-in, and interaction feedback.
   Everything here is off under prefers-reduced-motion. */

:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --dur-fast: 140ms;
  --dur: 220ms;
}

/* Cross-document page transitions */

@view-transition {
  navigation: auto;
}

.sidebar { view-transition-name: sidebar; }
.nav { view-transition-name: side-nav; }
.nav-pill { view-transition-name: nav-pill; }
.header { view-transition-name: top-bar; }
.phone-header { view-transition-name: phone-bar; }
.bottom-nav { view-transition-name: bottom-bar; }
.bottom-pill { view-transition-name: bottom-pill; }
.main { view-transition-name: page; }

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

::view-transition-group(*) {
  animation-duration: 260ms;
  animation-timing-function: var(--ease-out);
}

::view-transition-group(page) {
  animation: none;
}

::view-transition-old(page) {
  animation: vt-page-out 110ms var(--ease-in) both;
}

::view-transition-new(page) {
  animation: vt-page-in 230ms var(--ease-out) 70ms both;
}

::view-transition-image-pair(page) {
  isolation: auto;
}

::view-transition-old(page),
::view-transition-new(page) {
  mix-blend-mode: normal;
}

/* The current-page indicator slides between items under the nav labels. */
::view-transition-group(nav-pill) { z-index: 1; }
::view-transition-group(side-nav) { z-index: 2; }

::view-transition-old(nav-pill),
::view-transition-new(nav-pill),
::view-transition-old(bottom-pill),
::view-transition-new(bottom-pill) {
  animation: none;
}

::view-transition-new(nav-pill),
::view-transition-new(bottom-pill) {
  opacity: 0;
}

@keyframes vt-page-out {
  to { opacity: 0; }
}

@keyframes vt-page-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* Load-in stagger, first direct load only */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
}

@keyframes fill-in {
  from { transform: scaleX(0); }
}

@keyframes ring-in {
  from { box-shadow: 0 0 0 0 var(--attention-soft); }
}

@media (prefers-reduced-motion: no-preference) {
  html:not(.vt-arrival):not(.is-settled) .container > * {
    animation: rise 420ms var(--ease-out) both;
  }

  html:not(.vt-arrival):not(.is-settled) .container > :nth-child(2) { animation-delay: 50ms; }
  html:not(.vt-arrival):not(.is-settled) .container > :nth-child(3) { animation-delay: 100ms; }
  html:not(.vt-arrival):not(.is-settled) .container > :nth-child(4) { animation-delay: 150ms; }
  html:not(.vt-arrival):not(.is-settled) .container > :nth-child(5) { animation-delay: 200ms; }
  html:not(.vt-arrival):not(.is-settled) .container > :nth-child(n + 6) { animation-delay: 250ms; }

  html:not(.is-settled) .progress span.done {
    transform-origin: left center;
    animation: fill-in 700ms var(--ease-out) 280ms both;
  }

  html:not(.is-settled) .progress span.done:nth-child(2) { animation-delay: 380ms; }

  /* Schedule: the reply status builds step by step when it appears. */
  [data-confirm-done]:not([hidden]) .status-stack li {
    animation: rise 320ms var(--ease-out) both;
  }

  [data-confirm-done]:not([hidden]) .status-stack li:nth-child(2) { animation-delay: 90ms; }
  [data-confirm-done]:not([hidden]) .status-stack li:nth-child(3) { animation-delay: 180ms; }

  [data-confirm-done]:not([hidden]) .status-stack .current .step-mark {
    animation: ring-in 600ms var(--ease-out) 260ms both;
  }
}

/* Interaction feedback */

.btn,
.icon-btn,
.slot,
.tabs button,
.nav a,
.bottom-nav a,
.text-link,
.map-caption a,
.recent-photo {
  -webkit-tap-highlight-color: transparent;
}

.btn {
  transition:
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur) ease,
    background-color var(--dur) ease,
    border-color var(--dur) ease;
}

.btn:active:not(:disabled),
.icon-btn:active:not(:disabled),
.slot:active,
.tabs button:active,
.nav a:active,
.map-caption a:active {
  transform: scale(0.98);
  transition-duration: 60ms;
}

.icon-btn {
  transition:
    background-color var(--dur) ease,
    border-color var(--dur) ease,
    transform var(--dur-fast) var(--ease-out);
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--nav-current-border);
}

.nav a {
  transition: color var(--dur) ease, background-color var(--dur) ease, transform var(--dur-fast) var(--ease-out);
}

.bottom-nav a {
  transition: color var(--dur) ease;
}

.bottom-nav a .icon {
  transition: transform var(--dur-fast) var(--ease-out);
}

.bottom-nav a:active .icon {
  transform: scale(0.9);
}

.text-link {
  transition: color var(--dur) ease;
}

.map-caption a {
  transition: background-color var(--dur) ease, transform var(--dur-fast) var(--ease-out);
}

.slot {
  transition:
    border-color var(--dur) ease,
    background-color var(--dur) ease,
    color var(--dur) ease,
    transform var(--dur-fast) var(--ease-out);
}

.slot.is-picked {
  border-color: var(--p-ink);
  background: var(--p-ink);
  color: var(--p-bg);
}

.slot.is-picked .slot-tag {
  color: inherit;
}

.recent-photo .photo-frame img {
  transition: transform 420ms var(--ease-out), filter var(--dur) ease;
}

@media (hover: hover) {
  .recent-photo:hover .photo-frame img {
    transform: scale(1.025);
  }
}

.recent-photo:active .photo-frame img {
  transform: scale(1.01);
  transition-duration: 80ms;
}

/* Documents tabs: one sliding indicator instead of per-tab fills. */
.tabs {
  position: relative;
  isolation: isolate;
}

.tab-indicator {
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  height: 44px;
  border-radius: 999px;
  background: #fff;
  pointer-events: none;
}

.tabs.is-ready .tab-indicator {
  transition: transform 280ms var(--ease-out), width 280ms var(--ease-out);
}

.tabs.has-indicator button[aria-selected="true"] {
  border-color: transparent;
  background: transparent;
}

.tabs button {
  transition: color var(--dur) ease, background-color var(--dur) ease, transform var(--dur-fast) var(--ease-out);
}

.tabs button:hover:not([aria-selected="true"]) {
  color: var(--p-ink);
}

:root[data-theme="light"] .tab-indicator {
  background: var(--p-accent);
}

:root[data-theme="light"] .tabs.has-indicator button[aria-selected="true"] {
  border-color: transparent;
  background: transparent;
}

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

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }

  .btn:active:not(:disabled),
  .icon-btn:active:not(:disabled),
  .slot:active,
  .tabs button:active,
  .nav a:active,
  .map-caption a:active,
  .recent-photo:hover .photo-frame img,
  .recent-photo:active .photo-frame img,
  .bottom-nav a:active .icon {
    transform: none;
  }
}
