/* Tlou Moka cinematic loading screen. Everything is scoped to #tm-loader. */
#tm-loader {
  position: fixed; inset: 0; z-index: 2147483000; overflow: hidden; background: #061525;
  opacity: 1; transition: opacity .6s ease .1s;
  /* If the script ever fails, the page still becomes usable after 15s. */
  animation: tml-failsafe .5s linear 15s forwards;
}
#tm-loader.is-leaving { opacity: 0; pointer-events: none; }

/* Artwork stage: covers the screen like object-fit: cover, weighted towards the top. */
#tm-loader .tml-stage {
  --w: max(100vw, calc(100vh * 16 / 9));
  --h: max(100vh, calc(100vw * 9 / 16));
  position: absolute; width: var(--w); height: var(--h);
  left: calc((100% - var(--w)) / 2); top: calc((100% - var(--h)) * .28);
  transition: transform .75s cubic-bezier(.5, 0, .8, .4);
}
@media (max-aspect-ratio: 1/1) {
  #tm-loader .tml-stage {
    --w: max(100vw, calc(100vh * 1080 / 2340));
    --h: max(100vh, calc(100vw * 2340 / 1080));
  }
}
/* Wider than 16:9 (ultrawide monitors, phones held sideways): fit the height so the logo is never cropped. */
@media (min-aspect-ratio: 19/10) {
  #tm-loader .tml-stage {
    --h: 100%; --w: auto; height: 100%; width: auto; aspect-ratio: 16 / 9; top: 0; left: 50%; margin-left: -88.889vh;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  }
}
#tm-loader.is-leaving .tml-stage { transform: scale(1.07); }
#tm-loader .tml-layer { position: absolute; left: 0; top: 0; width: 100%; height: 100%; max-width: none; margin: 0; display: block; }
#tm-loader .tml-bg, #tm-loader .tml-rays, #tm-loader .tml-hero, #tm-loader .tml-glow { opacity: 0; }
#tm-loader .tml-rays, #tm-loader .tml-glow { mix-blend-mode: screen; }

#tm-loader.is-ready .tml-bg { animation: tml-fade .7s ease both; }
#tm-loader.is-ready .tml-rays { transform-origin: 25% 0; animation: tml-fade 1.4s ease both, tml-rays 7s ease-in-out infinite alternate; }
#tm-loader.is-ready .tml-hero { animation: tml-arrive 1.5s cubic-bezier(.16, .75, .2, 1) .1s both; }
#tm-loader.is-ready .tml-float { animation: tml-float 5s ease-in-out 1.6s infinite alternate; }
#tm-loader.is-ready .tml-glow {
  animation: tml-fade 1s ease .9s both, tml-float 5s ease-in-out 1.6s infinite alternate;
}

/* Light sweep, clipped to the logo's own silhouette. */
#tm-loader .tml-sheen {
  overflow: hidden; mix-blend-mode: screen;
  -webkit-mask-image: var(--tml-logo); mask-image: var(--tml-logo);
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
}
#tm-loader .tml-sheen i {
  position: absolute; top: -10%; bottom: -10%; left: 0; width: 18%; opacity: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 214, 110, .34) 35%, rgba(255, 255, 255, .62) 50%, rgba(140, 195, 255, .3) 68%, transparent);
  transform: translateX(-120%) skewX(-18deg);
}
#tm-loader.is-ready .tml-sheen i { animation: tml-sweep 3.4s cubic-bezier(.4, 0, .5, 1) 1.1s infinite; }
#tm-loader .tml-logo { filter: brightness(.94); }

/* Star glints, positioned on the artwork. */
#tm-loader .tml-glint {
  position: absolute; width: 5.5%; aspect-ratio: 1; opacity: 0; mix-blend-mode: screen; transform: translate(-50%, -50%) scale(0);
  background:
    radial-gradient(closest-side, #fff, rgba(255, 224, 140, .55) 12%, transparent 42%),
    linear-gradient(90deg, transparent, #fff 50%, transparent) center / 100% 1.5px no-repeat,
    linear-gradient(180deg, transparent, #fff 50%, transparent) center / 1.5px 100% no-repeat;
}
#tm-loader .tml-g1 { left: 34.3%; top: 10.2%; }
#tm-loader .tml-g2 { left: 69.8%; top: 13%; }
#tm-loader .tml-g3 { left: 29.6%; top: 17.4%; }
@media (max-aspect-ratio: 1/1) {
  #tm-loader .tml-glint { width: 13%; }
  #tm-loader .tml-g1 { left: 24%; top: 29.8%; }
  #tm-loader .tml-g2 { left: 83.3%; top: 30.8%; }
  #tm-loader .tml-g3 { left: 16%; top: 32.9%; }
}
#tm-loader.is-ready .tml-glint { animation: tml-glint 3.4s ease-in-out infinite; }
#tm-loader.is-ready .tml-g1 { animation-delay: 1.75s; }
#tm-loader.is-ready .tml-g2 { animation-delay: 2.35s; }
#tm-loader.is-ready .tml-g3 { animation-delay: 3.9s; }

#tm-loader .tml-dust { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

#tm-loader .tml-foot {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(260px, 62vw); text-align: center;
  bottom: calc(clamp(18px, 4vh, 60px) + env(safe-area-inset-bottom, 0px));
}
@media (max-aspect-ratio: 1/1) { #tm-loader .tml-foot { bottom: 16vh; } }
#tm-loader .tml-foot span {
  display: block; margin-bottom: 12px; padding-left: .42em;
  font: 600 12px/1 Montserrat, "Segoe UI", system-ui, sans-serif; letter-spacing: .42em; text-transform: uppercase; color: #F8C901;
}
#tm-loader .tml-bar { height: 2px; border-radius: 2px; background: rgba(255, 255, 255, .14); }
#tm-loader .tml-bar i {
  display: block; height: 100%; border-radius: 2px; transform-origin: left; transform: scaleX(.04);
  background: linear-gradient(90deg, #8a6a00, #F8C901 70%, #fff3b0); box-shadow: 0 0 10px rgba(248, 201, 1, .7);
}
#tm-loader.is-ready .tml-bar i { animation: tml-progress 8s cubic-bezier(.1, .7, .2, 1) forwards; }
#tm-loader.is-leaving .tml-bar i { animation: none; transform: scaleX(1); transition: transform .25s ease; }

@media (max-height: 520px) and (orientation: landscape) {
  #tm-loader .tml-foot { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  #tm-loader .tml-foot span { display: none; }
}

@keyframes tml-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tml-arrive {
  from { opacity: 0; transform: translateY(1.6%) scale(1.14); filter: blur(14px) brightness(1.7); }
  55%  { opacity: 1; }
  to   { opacity: 1; transform: none; filter: none; }
}
@keyframes tml-float { from { transform: none; } to { transform: translateY(-.45%) scale(1.012); } }
@keyframes tml-rays { from { transform: rotate(-1.6deg) scale(1.05); filter: brightness(.7); } to { transform: rotate(1.8deg) scale(1.08); filter: brightness(1.35); } }
@keyframes tml-sweep {
  0%   { transform: translateX(-120%) skewX(-18deg); opacity: 1; }
  48%  { transform: translateX(640%) skewX(-18deg); opacity: 1; }
  49%, 100% { transform: translateX(640%) skewX(-18deg); opacity: 0; }
}
@keyframes tml-glint {
  0%, 24%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0) rotate(0deg); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(22deg); }
}
@keyframes tml-progress { 0% { transform: scaleX(.04); } 18% { transform: scaleX(.55); } 45% { transform: scaleX(.8); } 100% { transform: scaleX(.94); } }
@keyframes tml-failsafe { to { opacity: 0; visibility: hidden; } }

/* Reduced motion: a still frame. The failsafe must survive global "animation: none" resets. */
@media (prefers-reduced-motion: reduce) {
  #tm-loader { animation: tml-failsafe .5s linear 15s forwards !important; }
  #tm-loader .tml-bg, #tm-loader .tml-rays, #tm-loader .tml-hero, #tm-loader .tml-glow { opacity: 1; }
  #tm-loader * { animation: none !important; transition: none !important; }
  #tm-loader .tml-logo { filter: none; }
  #tm-loader .tml-bar i { transform: scaleX(.6); }
}
