/* The loading screen of index.html: painted before any script runs, removed by loader.js once the
   app is mounted. Colours come from main.css (and the server's theme.css, so the brand applies);
   the fallbacks only matter if main.css is still missing. Nothing here may depend on JS. */

.tc-loader {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px;
  color: var(--text, #1d1d1d);
  font: var(--text-base, 14px) / 1.45 var(--font-ui, system-ui, sans-serif);
  transition: opacity 180ms ease-out;
}

/* The backdrop is its own layer, so the handover can fade it while the mark flies on. */
.tc-loader::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--bg, #f6f7f9);
  transition: opacity 420ms var(--ease-standard, cubic-bezier(0.2, 0, 0, 1)) 120ms;
}

@media (prefers-color-scheme: dark) {
  .tc-loader {
    color: var(--text, #e6eaf1);
  }

  .tc-loader::before {
    background: var(--bg, #161616);
  }
}

/* The handover (loader.js): the backdrop and the bar fade, the mark flies into the app's brand. */
.tc-loader.is-handing-over {
  pointer-events: none;
}

.tc-loader.is-handing-over::before {
  opacity: 0;
}

.tc-loader.is-handing-over .tc-loader-bar {
  opacity: 0;
  transition: opacity 120ms ease-out;
}

/* On its way out (loader.js `removeScreen`): hidden with its animations still holding, removed
   two frames later. */
.tc-loader.is-gone {
  visibility: hidden;
}

/* Reduced motion, or nothing to fly to: the whole screen fades. */
.tc-loader.is-done {
  opacity: 0;
  pointer-events: none;
}

/* The mark assembles once, then types until the app is there. All motion is transform and
   opacity on the mark's own parts. Lengths are in the mark's units (1130 across, 88 px wide). */
.tc-loader-mark {
  display: block;
  width: 88px;
  height: 88px;
  overflow: visible;
}

.tc-loader-mark * {
  transform-box: fill-box;
  transform-origin: center;
}

/* The heads swirl in around the mark's centre, one after the other (the spirit of Slack's
   classic loader), and grow into place. */
.tc-loader-mark .tc-loader-swirl {
  transform-box: view-box;
  transform-origin: 627px 642px;
  animation: tc-loader-swirl 820ms var(--ease-emphasized, cubic-bezier(0.05, 0.7, 0.1, 1)) both;
}

.tc-loader-swirl-left {
  animation-delay: 70ms;
}

.tc-loader-swirl-right {
  animation-delay: 140ms;
}

.tc-loader-head {
  animation: tc-loader-grow 820ms var(--ease-emphasized, cubic-bezier(0.05, 0.7, 0.1, 1)) both;
}

.tc-loader-swirl-left .tc-loader-head {
  animation-delay: 70ms;
}

.tc-loader-swirl-right .tc-loader-head {
  animation-delay: 140ms;
}

/* The bodies rise from below under the heads. */
.tc-loader-body {
  animation: tc-loader-rise 640ms var(--ease-emphasized, cubic-bezier(0.05, 0.7, 0.1, 1)) both;
}

.tc-loader-body-top {
  animation-delay: 160ms;
}

.tc-loader-body-left {
  animation-delay: 220ms;
}

.tc-loader-body-right {
  animation-delay: 280ms;
}

/* The speech bubble pops from its tail, then its dots type. Everything rests at 1040 ms, before the
   loops start: the Android app's system splash plays the same assembly up to there and hands
   over (scripts/brand/mark_parts.py). */
.tc-loader-mark .tc-loader-bubble {
  transform-origin: 48% 100%;
  animation: tc-loader-pop 460ms var(--ease-pop, cubic-bezier(0.34, 1.56, 0.64, 1)) 420ms both;
}

.tc-loader-dot {
  animation:
    tc-loader-dot-in 160ms ease-out 760ms both,
    tc-loader-hop 1.2s ease-in-out 1100ms infinite;
}

.tc-loader-dot:nth-child(2) {
  animation-delay: 820ms, 1250ms;
}

.tc-loader-dot:nth-child(3) {
  animation-delay: 880ms, 1400ms;
}

/* While it types, the team nods along: left, top, right. */
.tc-loader-nod {
  animation: tc-loader-nod 2.4s ease-in-out 1.1s infinite;
}

.tc-loader-swirl-top .tc-loader-nod {
  animation-delay: 1.3s;
}

.tc-loader-swirl-right .tc-loader-nod {
  animation-delay: 1.5s;
}

/* The second page load of a reload through the identity provider (loader.js): the mark is already
   assembled and goes on typing. */
.tc-loader.is-resumed .tc-loader-mark *,
.tc-loader.is-resumed .tc-loader-mark .tc-loader-swirl,
.tc-loader.is-resumed .tc-loader-mark .tc-loader-bubble {
  animation: none;
}

.tc-loader.is-resumed .tc-loader-mark .tc-loader-dot {
  opacity: 0.55;
  animation: tc-loader-hop 1.2s ease-in-out infinite;
}

.tc-loader.is-resumed .tc-loader-mark .tc-loader-dot:nth-child(2) {
  animation-delay: 150ms;
}

.tc-loader.is-resumed .tc-loader-mark .tc-loader-dot:nth-child(3) {
  animation-delay: 300ms;
}

.tc-loader.is-resumed .tc-loader-mark .tc-loader-nod {
  animation: tc-loader-nod 2.4s ease-in-out infinite;
}

.tc-loader.is-resumed .tc-loader-swirl-top .tc-loader-nod {
  animation-delay: 200ms;
}

.tc-loader.is-resumed .tc-loader-swirl-right .tc-loader-nod {
  animation-delay: 400ms;
}

.tc-loader.has-failed .tc-loader-mark * {
  animation-play-state: paused;
}

/* Indeterminate until the download size is known, then the share of the wasm already loaded. */
.tc-loader-bar {
  position: relative;
  width: 180px;
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface-3, rgba(127, 127, 127, 0.25));
}

.tc-loader-progress {
  position: absolute;
  inset: 0;
  background: var(--accent, #005dfc);
  transform-origin: left center;
  transform: translateX(-100%) scaleX(0.4);
  animation: tc-loader-sweep 1.4s ease-in-out infinite;
}

.tc-loader.has-progress .tc-loader-progress {
  animation: none;
  transform: scaleX(var(--tc-loader-progress, 0));
  transition: transform 120ms linear;
}

/* Downloaded, now compiling and starting: the bar is full and pulses. */
.tc-loader.is-starting .tc-loader-progress {
  transform: none;
  animation: tc-loader-pulse 1.2s ease-in-out infinite;
}

/* A long session check says so under the bar; until then the line keeps its place, so nothing
   moves when it appears. */
.tc-loader-status {
  min-height: 1.45em;
  margin: -16px 0 0;
  color: var(--text-muted, #566175);
  opacity: 0;
  transition: opacity 240ms ease-out;
}

.tc-loader.is-waiting .tc-loader-status {
  opacity: 1;
}

/* Fades with the bar; it keeps its place, so the mark does not move under the handover. */
.tc-loader.is-handing-over .tc-loader-status {
  opacity: 0;
  transition-duration: 120ms;
}

.tc-loader.has-failed .tc-loader-status {
  display: none;
}

.tc-loader-error {
  max-width: 360px;
  text-align: center;
}

.tc-loader-error[hidden] {
  display: none;
}

.tc-loader.has-failed .tc-loader-bar {
  display: none;
}

.tc-loader-error-title {
  margin: 0 0 4px;
  font-size: var(--text-md, 15px);
  font-weight: 600;
}

.tc-loader-error-body {
  margin: 0 0 16px;
  color: var(--text-muted, #566175);
}

.tc-loader-retry {
  padding: 7px 16px;
  border: 0;
  border-radius: var(--radius-sm, 5px);
  background: var(--accent, #005dfc);
  color: var(--on-accent, #ffffff);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tc-loader-retry:hover {
  background: var(--accent-strong, #004bd3);
}

.tc-loader-retry:focus-visible {
  outline: 2px solid var(--focus, #005dfc);
  outline-offset: 2px;
}

/* The script-free way out (index.html): invisible and unfocusable until the delay has passed, so
   a slow but working load never shows it; loader.js removes it when it starts. */
.tc-loader-reload {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2, rgba(127, 127, 127, 0.15));
  color: var(--text, #1d1d1d);
  opacity: 0;
  visibility: hidden;
  animation: tc-loader-reveal 240ms ease-out 30s forwards;
}

.tc-loader-reload:hover {
  background: var(--surface-3, rgba(127, 127, 127, 0.25));
}

.tc-loader-reload:focus-visible {
  outline: 2px solid var(--focus, #005dfc);
  outline-offset: 2px;
}

.tc-loader.has-failed .tc-loader-reload {
  display: none;
}

@keyframes tc-loader-reveal {
  from {
    opacity: 0;
    visibility: visible;
  }
  to {
    opacity: 1;
    visibility: visible;
  }
}

@keyframes tc-loader-swirl {
  from {
    opacity: 0;
    transform: rotate(-150deg);
  }
  40% {
    opacity: 1;
  }
}

@keyframes tc-loader-grow {
  from {
    transform: scale(0.4);
  }
}

@keyframes tc-loader-rise {
  from {
    opacity: 0;
    transform: translateY(18%);
  }
}

@keyframes tc-loader-pop {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  40% {
    opacity: 1;
  }
}

@keyframes tc-loader-appear {
  from {
    opacity: 0;
  }
}

/* Into the hop's resting opacity, so the hop starts without a flash. */
@keyframes tc-loader-dot-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.55;
  }
}

@keyframes tc-loader-hop {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  30% {
    transform: translateY(-40%);
    opacity: 1;
  }
}

@keyframes tc-loader-nod {
  0%,
  24%,
  100% {
    transform: translateY(0);
  }
  12% {
    transform: translateY(-6%);
  }
}

@keyframes tc-loader-sweep {
  0% {
    transform: translateX(-100%) scaleX(0.4);
  }
  100% {
    transform: translateX(250%) scaleX(0.4);
  }
}

@keyframes tc-loader-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* No movement: the mark fades in whole and its dots only brighten in turn. */
  .tc-loader-mark *,
  .tc-loader-mark .tc-loader-swirl,
  .tc-loader-mark .tc-loader-bubble,
  .tc-loader-progress,
  .tc-loader.is-starting .tc-loader-progress {
    animation: none;
  }

  .tc-loader-mark {
    animation: tc-loader-appear 240ms ease-out both;
  }

  .tc-loader-mark .tc-loader-dot {
    animation: tc-loader-pulse 1.2s ease-in-out infinite;
  }

  .tc-loader-mark .tc-loader-dot:nth-child(2) {
    animation-delay: 0.2s;
  }

  .tc-loader-mark .tc-loader-dot:nth-child(3) {
    animation-delay: 0.4s;
  }

  /* Resumed (above): no nodding or hopping either, and the mark stays put instead of fading in
     again. */
  .tc-loader.is-resumed .tc-loader-mark,
  .tc-loader.is-resumed .tc-loader-mark .tc-loader-nod {
    animation: none;
  }

  .tc-loader.is-resumed .tc-loader-mark .tc-loader-dot {
    animation: tc-loader-pulse 1.2s ease-in-out infinite;
  }

  .tc-loader.is-resumed .tc-loader-mark .tc-loader-dot:nth-child(2) {
    animation-delay: 0.2s;
  }

  .tc-loader.is-resumed .tc-loader-mark .tc-loader-dot:nth-child(3) {
    animation-delay: 0.4s;
  }

  .tc-loader-progress {
    transform: none;
    opacity: 0.6;
  }

  /* Same delay, no fade. */
  .tc-loader-reload {
    animation-duration: 1ms;
  }
}
