/* ---------- The welcome after signing in (shared/_welcome.html.erb, welcome_controller.js) ----------
   0.0s  the toucan's colours slide in at the corners, a cream disc pops up
   0.3s  the toucan's pieces fly in and build the bird, the eye last
   1.0s  "¡Hola, …!" rises
   1.4s  a wink, then a hop
   2.1s  everything falls away and the view dives into the eye, which opens onto the app (--hole, from the eye's
         place on screen, --x/--y, set by the controller as it starts)
   The slate is the sign-in page's, so it feels like the same screen turning into the app. */

@property --hole {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

.welcome {
  --x: 50%;
  --y: 45%;
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--slate-800);
  cursor: pointer;
  -webkit-mask: radial-gradient(circle at var(--x) var(--y), transparent var(--hole), #000 calc(var(--hole) + 1px));
  mask: radial-gradient(circle at var(--x) var(--y), transparent var(--hole), #000 calc(var(--hole) + 1px));
  animation: welcome-open 0.8s cubic-bezier(0.65, 0, 0.35, 1) 2.15s forwards;
}

/* Quarter circles in the toucan's colours, as on the website, each sliding in from its own corner */
.welcome__corner {
  position: absolute;
  width: 34vmin;
  height: 34vmin;
  animation:
    welcome-corner 0.7s cubic-bezier(0.2, 0.9, 0.25, 1.1) both,
    welcome-fade-out 0.4s ease-in 2s forwards;
}

.welcome__corner--1 { top: 0; left: 0; --from: -100%, -100%; background: #e8af47; border-radius: 0 0 100% 0; }
.welcome__corner--2 { top: 0; right: 0; --from: 100%, -100%; background: var(--toucan-mint); border-radius: 0 0 0 100%; animation-delay: 0.08s, 2s; }
.welcome__corner--3 { bottom: 0; right: 0; --from: 100%, 100%; background: #d9702e; border-radius: 100% 0 0 0; animation-delay: 0.16s, 2s; }
.welcome__corner--4 { bottom: 0; left: 0; --from: -100%, 100%; background: var(--toucan-sage); border-radius: 0 100% 0 0; animation-delay: 0.24s, 2s; }

.welcome__stage {
  display: grid;
  justify-items: center;
  gap: var(--space-6);
}

/* The bird's black body needs a light ground on the slate. Grows from where the eye will be, and dives into it */
.welcome__disc {
  display: grid;
  place-items: center;
  width: 11rem;
  height: 11rem;
  border-radius: 50%;
  background: #fbf6ec;
  box-shadow: 0 1.5rem 3rem rgb(0 0 0 / 0.3);
  transform-origin: 57% 31%;
  animation:
    welcome-pop 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) both,
    welcome-dive 0.75s cubic-bezier(0.55, 0, 0.75, 0.3) 2.1s forwards;
}

/* overflow visible: the pieces start outside it */
.welcome__bird {
  width: 6.75rem;
  overflow: visible;
  transform-origin: 50% 100%;
  animation: welcome-hop 0.55s ease-in-out 1.55s both;
}

.welcome__piece,
.welcome__eye {
  transform-box: fill-box;
  transform-origin: center;
}

.welcome__piece { animation: welcome-fly-in 0.7s cubic-bezier(0.2, 0.9, 0.25, 1.15) both; }
.welcome__piece--1 { --from: -14rem, -10rem; --turn: -120deg; animation-delay: 0.3s; }
.welcome__piece--2 { --from: -16rem, 6rem; --turn: 90deg; animation-delay: 0.42s; }
.welcome__piece--3 { --from: 12rem, 14rem; --turn: -60deg; animation-delay: 0.54s; }
.welcome__piece--4 { --from: 10rem, -14rem; --turn: 120deg; animation-delay: 0.66s; }

/* Pops open, then a wink */
.welcome__eye {
  animation:
    welcome-eye 0.35s cubic-bezier(0.3, 1.8, 0.5, 1) 0.95s both,
    welcome-wink 0.28s ease-in-out 1.35s;
}

.welcome__hello {
  color: #f4efe4;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  text-align: center;
  animation:
    welcome-rise 0.5s cubic-bezier(0.2, 0.9, 0.3, 1) 1s both,
    welcome-fade-out 0.3s ease-in 1.95s forwards;
}

@keyframes welcome-corner {
  from { transform: translate(var(--from)); }
  to { transform: none; }
}

@keyframes welcome-pop {
  from { transform: scale(0); }
  to { transform: none; }
}

@keyframes welcome-fly-in {
  from { opacity: 0; transform: translate(var(--from)) rotate(var(--turn)) scale(0.3); }
  to { opacity: 1; transform: none; }
}

@keyframes welcome-eye {
  from { transform: scale(0); }
  to { transform: none; }
}

@keyframes welcome-wink {
  0%, 100% { transform: none; }
  45%, 55% { transform: scaleY(0.1); }
}

@keyframes welcome-hop {
  0% { transform: none; }
  20% { transform: scale(1.08, 0.9); }
  50% { transform: translateY(-1.25rem) rotate(-6deg) scale(0.96, 1.05); }
  80% { transform: scale(1.05, 0.94); }
  100% { transform: none; }
}

@keyframes welcome-rise {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: none; }
}

@keyframes welcome-fade-out {
  to { opacity: 0; }
}

@keyframes welcome-dive {
  to { transform: scale(14); opacity: 0; }
}

@keyframes welcome-open {
  to { --hole: 150vmax; }
}

/* The controller takes it away at once; this is in case it hasn't run yet */
@media (prefers-reduced-motion: reduce) {
  .welcome { display: none; }
}
