/*
 * Android app launch animation: orange juice pours from above into the TRUEAISERVE logo,
 * fills its letters, then settles into the real logo colours.
 * Shown only inside the Android app (see splash.js); web and desktop never see it.
 * Timeline (seconds): stream falls .15–.6 · splash .6 · letters fill .55–2.1 ·
 * stream ends 1.95–2.35 · real logo 2.1–2.7 · shine 2.55–3.25.
 */
#app-splash {
  --aps-lw: min(84vw, 560px);
  --aps-lh: calc(var(--aps-lw) * 0.09568); /* logo is 10556 × 1010 */
  --aps-logo: url("/splash/trueaiserve.png");
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 46%, #ffffff 0%, #fff8f1 55%, #ffefdf 100%);
  transition: opacity 0.45s ease, transform 0.45s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html.app-splash-on #app-splash { display: block; }
#app-splash.is-leaving { opacity: 0; transform: scale(1.03); pointer-events: none; }

#app-splash .aps-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Soft warm glow that grows as the logo fills. */
#app-splash .aps-glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--aps-lw) * 1.15);
  height: calc(var(--aps-lw) * 0.6);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 150, 45, 0.2), rgba(255, 150, 45, 0));
  transform: translate(-50%, -50%) scale(0.55);
  opacity: 0;
  animation: aps-glow 1.8s ease-out 0.6s forwards;
}

#app-splash .aps-logo {
  position: relative;
  width: var(--aps-lw);
  height: var(--aps-lh);
  animation: aps-settle 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) 2.15s both;
}

#app-splash .aps-layer {
  position: absolute;
  inset: 0;
}

#app-splash .aps-mask {
  -webkit-mask: var(--aps-logo) center / 100% 100% no-repeat;
  mask: var(--aps-logo) center / 100% 100% no-repeat;
}

/* The empty "glass": the logo shape in a pale tint. */
#app-splash .aps-ghost {
  z-index: 1;
  background: #f3e2cf;
  opacity: 0;
  animation: aps-fade-in 0.35s ease-out forwards;
}

/* Juice inside the letters. */
#app-splash .aps-fill {
  z-index: 3;
  overflow: hidden;
  animation: aps-fade-out 0.5s ease 2.35s forwards;
}

#app-splash .aps-level {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  transform: translateY(140%); /* below the letters, waves included */
  animation: aps-rise 1.55s cubic-bezier(0.45, 0.05, 0.35, 1) 0.55s forwards;
}

#app-splash .aps-liquid {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #ffb13b 0%, #ff8a1f 42%, #e85d04 100%);
}

#app-splash .aps-wave {
  position: absolute;
  left: 0;
  bottom: calc(100% - 1px);
  width: 200%;
  height: calc(var(--aps-lh) * 0.3);
}

#app-splash .aps-wave-front { fill: #ffb13b; animation: aps-wave 1.1s linear infinite; }
#app-splash .aps-wave-back {
  fill: #ffd08a;
  bottom: calc(100% + var(--aps-lh) * 0.03);
  opacity: 0.85;
  animation: aps-wave 1.7s linear infinite reverse;
}

#app-splash .aps-bubble {
  position: absolute;
  bottom: -12%;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.35) 58%, rgba(255, 255, 255, 0) 72%);
  opacity: 0;
  animation: aps-bubble 1.2s ease-in var(--d) infinite;
}

/* The pour: a glossy stream falling from the top of the screen into the "I". */
#app-splash .aps-stream {
  position: absolute;
  z-index: 2;
  top: 0;
  left: calc(50% - var(--aps-lw) * 0.0017);
  height: calc(50% + var(--aps-lh) * 0.1);
  width: max(5px, calc(var(--aps-lw) * 0.018));
  transform: translateX(-50%);
  clip-path: inset(0 0 100% 0);
  animation: aps-stream 2.2s 0.15s forwards;
}

#app-splash .aps-stream-core {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 0 0 999px 999px;
  clip-path: polygon(0 0, 100% 0, 84% 100%, 16% 100%);
  background: linear-gradient(90deg, #ef7410 0%, #ffb547 30%, #ffdc9a 42%, #ff9a2e 62%, #e2620a 100%);
  transform-origin: top center;
  animation: aps-wobble 0.5s ease-in-out infinite alternate;
}

#app-splash .aps-stream-core::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(180deg,
    rgba(255, 255, 255, 0) 0 16px,
    rgba(255, 255, 255, 0.38) 16px 20px,
    rgba(255, 255, 255, 0) 20px 38px);
  animation: aps-flow 0.32s linear infinite;
}

/* Splash where the stream lands. */
#app-splash .aps-impact {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(50% - var(--aps-lh) * 0.5);
  width: 0;
  height: 0;
}

#app-splash .aps-drop {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--s);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd58a, #ff8a1f 60%, #e85d04);
  opacity: 0;
  animation: aps-drop 0.75s cubic-bezier(0.2, 0.6, 0.4, 1) var(--t) forwards;
}

#app-splash .aps-ring {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--aps-lw) * 0.14);
  height: calc(var(--aps-lh) * 0.4);
  border: 2px solid rgba(232, 93, 4, 0.45);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0;
  animation: aps-ring 0.7s ease-out var(--t) forwards;
}

/* The real logo colours appear as the juice settles. */
#app-splash .aps-real {
  z-index: 4;
  width: 100%;
  height: 100%;
  opacity: 0;
  animation: aps-fade-in 0.6s ease 2.1s forwards;
}

#app-splash .aps-shine {
  z-index: 5;
  background: linear-gradient(110deg, rgba(255, 255, 255, 0) 0 46.5%, rgba(255, 255, 255, 0.7) 50%, rgba(255, 255, 255, 0) 53.5% 100%);
  background-size: 300% 100%;
  background-position: 100% 0;
  animation: aps-shine 0.7s ease-in-out 2.55s forwards;
}

/* Shown only if the app is still loading after the animation. */
#app-splash .aps-wait {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--aps-lh) * 0.5 + 36px);
  display: flex;
  gap: 8px;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#app-splash.is-waiting .aps-wait { opacity: 1; }

#app-splash .aps-wait i {
  width: 7px;
  height: 9px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: #ff8a1f;
  animation: aps-dot 1s ease-in-out infinite;
}

#app-splash .aps-wait i:nth-child(2) { animation-delay: 0.15s; }
#app-splash .aps-wait i:nth-child(3) { animation-delay: 0.3s; }

/* Reduced motion: show the finished logo without the pour. */
html.app-splash-still #app-splash *,
html.app-splash-still #app-splash *::after { animation: none !important; }
html.app-splash-still #app-splash .aps-stream,
html.app-splash-still #app-splash .aps-fill,
html.app-splash-still #app-splash .aps-impact,
html.app-splash-still #app-splash .aps-shine { display: none; }
html.app-splash-still #app-splash .aps-real,
html.app-splash-still #app-splash .aps-ghost { opacity: 1; }

@keyframes aps-fade-in { to { opacity: 1; } }
@keyframes aps-fade-out { to { opacity: 0; } }
@keyframes aps-glow { to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes aps-rise { from { transform: translateY(140%); } to { transform: translateY(-38%); } }
@keyframes aps-settle { 0% { transform: scale(1); } 45% { transform: scale(1.045); } 100% { transform: scale(1); } }
@keyframes aps-wave { from { transform: translateX(0); } to { transform: translateX(-50%); } }

@keyframes aps-bubble {
  0% { transform: translate(0, 0); opacity: 0; }
  20% { opacity: 0.9; }
  100% { transform: translate(var(--drift, 3px), calc(var(--aps-lh) * -1.25)); opacity: 0; }
}

@keyframes aps-stream {
  0% { clip-path: inset(0 0 100% 0); animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  20% { clip-path: inset(0 0 0 0); }
  82% { clip-path: inset(0 0 0 0); animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  100% { clip-path: inset(100% 0 0 0); }
}

@keyframes aps-wobble { from { transform: scaleX(1); } to { transform: scaleX(0.86); } }
@keyframes aps-flow { from { background-position: 0 0; } to { background-position: 0 38px; } }

@keyframes aps-drop {
  0% { opacity: 1; transform: translate(0, 0) scale(0.6); }
  45% { opacity: 1; transform: translate(calc(var(--dx) * 0.6), var(--dy)) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), 14px) scale(0.7); }
}

@keyframes aps-ring {
  0% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}

@keyframes aps-shine { from { background-position: 100% 0; } to { background-position: 0% 0; } }

@keyframes aps-dot {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-6px); opacity: 1; }
}
