/* ---- the title screen's entrance (js/title_intro.js) ----
   Owner, 2026-11-02, after walking through another game's title screen ("พวกหน้าจะ
   อนิเมชั่นตอนเข้าเกม ... ชอบอะ เอามาใช้บาง"): the login screen used to be simply
   there. Now it arrives - the painting dawns out of the dark, the logo drops in,
   the panel rises under it - and when the player is let in, the whole thing zooms
   away into the game instead of dimming.

   Everything here is one-shot and runs off the classes js/title_intro.js puts on
   `.login`; the idle loops already in style.css (login-drift, login-float,
   login-twinkle) are re-declared after each one-shot so they take over when it
   ends. Nothing is drawn per frame, so a phone pays for this once.
   A player who asked their phone for less motion gets the plain screen. */

/* ---------- the way in ---------- */
.login.ti-intro .login-scene {
  animation: ti-dawn 1.1s ease-out both,
             login-drift 40s ease-in-out 1.1s infinite alternate;
}
.login.ti-intro .login-logo {
  animation: ti-slam 0.62s cubic-bezier(0.25, 1.5, 0.45, 1) both,
             login-float 3s steps(6) 0.62s infinite;
}
.login.ti-intro .login-sub { animation: ti-fade 0.5s ease-out 0.5s both; }
.login.ti-intro .login-box,
.login.ti-intro .login-reopen { animation: ti-rise 0.62s cubic-bezier(0.2, 1.3, 0.4, 1) 0.42s both; }
.login.ti-intro .login-foot,
.login.ti-intro .login-social { animation: ti-fade 0.6s ease-out 0.8s both; }

@keyframes ti-dawn {
  from { filter: brightness(0.25) saturate(0.5); transform: scale(1.14); }
  to   { filter: none; transform: scale(1); }
}
@keyframes ti-slam {
  0%   { opacity: 0; transform: scale(2.2); filter: blur(10px) drop-shadow(0 4px 0 rgba(16, 22, 38, 0.6)); }
  65%  { opacity: 1; transform: scale(0.95); filter: blur(0) drop-shadow(0 4px 0 rgba(16, 22, 38, 0.6)); }
  100% { opacity: 1; transform: scale(1); filter: blur(0) drop-shadow(0 4px 0 rgba(16, 22, 38, 0.6)); }
}
/* the panel and the reopen chip are centred with translateX(-50%): a keyframe that
   forgets it would throw them to the right for the length of the animation */
@keyframes ti-rise {
  from { opacity: 0; transform: translateX(-50%) translateY(70px) scale(0.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes ti-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- the light that walks over the logo ---------- */
/* the bar lives in its own box clipped to the logo's corner, and spends most of
   each turn parked off to the left, so it reads as an occasional glint */
.login-shine {
  position: absolute; inset: 0;
  overflow: hidden; pointer-events: none;
  mix-blend-mode: screen;
}
.login-shine i {
  position: absolute; top: 50%; left: 0;
  width: 38%; height: 260%;
  background: linear-gradient(90deg, transparent, rgba(255, 252, 226, 0.72) 45%, rgba(255, 255, 255, 0.9) 50%, rgba(255, 252, 226, 0.72) 55%, transparent);
  transform: translate(-160%, -50%) rotate(-18deg);
  animation: ti-shine 6s ease-in-out 1.4s infinite;
}
@keyframes ti-shine {
  0%, 62%   { transform: translate(-160%, -50%) rotate(-18deg); }
  88%, 100% { transform: translate(380%, -50%) rotate(-18deg); }
}

/* the Login button breathes, so the eye finds it without being shouted at */
.login-go { animation: ti-ready 2.6s ease-in-out infinite; }
@keyframes ti-ready {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 206, 110, 0)); }
  50%      { filter: drop-shadow(0 0 10px rgba(255, 206, 110, 0.8)); }
}

/* ---------- the parallax (js/title_intro.js writes --px / --py, -1..1) ---------- */
/* `translate` is its own property, so these never fight the transforms above */
.login-scene { translate: calc(var(--px, 0) * -22px) calc(var(--py, 0) * -14px); transition: translate 0.45s ease-out; }
.login-hero  { translate: calc(var(--px, 0) * 12px) calc(var(--py, 0) * 8px);   transition: translate 0.5s ease-out; }
.login-box   { translate: calc(var(--px, 0) * 6px) calc(var(--py, 0) * 4px);    transition: translate 0.55s ease-out; }

/* ---------- the way out ---------- */
/* style.css fades `.login.leaving` over 0.25s and js/login.js hides it at 260ms:
   these stay inside that window */
.login.leaving .login-scene { animation: ti-zoom 0.26s ease-in both; }
.login.leaving .login-hero,
.login.leaving .login-box,
.login.leaving .login-reopen { animation: ti-out 0.26s ease-in both; }
@keyframes ti-zoom { to { transform: scale(1.22); filter: brightness(1.7); } }
/* all three are centred with translateX(-50%), so the keyframe carries it */
@keyframes ti-out  { to { opacity: 0; transform: translateX(-50%) scale(1.3); filter: blur(3px); } }

/* phone landscape (style.css: max-height 460px puts .login-box lower-right with transform: none):
   the centred keyframes above carry translateX(-50%), which here would throw the panel half its
   width to the left for the length of the animation (review, 2026-11-08) - so the panel takes
   flat ones, the hero and the reopen chip keep theirs */
@media (max-height: 460px) {
  .login.ti-intro .login-box { animation-name: ti-rise-flat; }
  .login.leaving .login-box  { animation-name: ti-out-flat; }
  @keyframes ti-rise-flat {
    from { opacity: 0; transform: translateY(70px) scale(0.9); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }
  @keyframes ti-out-flat { to { opacity: 0; transform: scale(1.3); filter: blur(3px); } }
}

@media (prefers-reduced-motion: reduce) {
  .login.ti-intro .login-scene,
  .login.ti-intro .login-logo,
  .login.ti-intro .login-sub,
  .login.ti-intro .login-box,
  .login.ti-intro .login-reopen,
  .login.ti-intro .login-foot,
  .login.ti-intro .login-social,
  .login.leaving .login-scene,
  .login.leaving .login-hero,
  .login.leaving .login-box,
  .login.leaving .login-reopen,
  .login-go { animation: none; }
  .login-shine { display: none; }
  .login-scene, .login-hero, .login-box { translate: none; }
}
