/* =============================================================
   103 KOTHI PRELOADER
   Recreates "Key images/103kothi preloader video.mp4".

   All emblem measurements come from the 1080x1920 reference video
   and are written in "video units" (--u = 1 video pixel).
   --u scales the whole composition so it keeps the video's
   proportions on every screen:
     phones  -> fits the width  (identical framing to the video)
     desktop -> fits the height (emblem stays centred, never clipped)

   SIZE: to make the whole emblem bigger/smaller, change the 1500 in
   --u (smaller number = bigger emblem).
   POSITION: move everything with --kp-offset-x / --kp-offset-y.
   ============================================================= */

/* Hidden unless the head script switched it on (no JS = no preloader) */
.kp { display: none; }

html.is-preloading .kp { display: block; }

html.is-preloading,
html.is-preloading body { overflow: hidden; }

.kp {
  --u: min(calc(100vw / 1080), calc(100vh / 1500));
  --kp-offset-x: 0px;
  --kp-offset-y: 0px;
  --kp-ink: #351904;

  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow: hidden;
}

/* Parchment background (Key images/background.png, unchanged; stays still) */
.kp-bg {
  position: absolute;
  inset: 0;
  background: #E8D3AE url("../images/background.png") center / cover no-repeat;
}

/* Holds the emblem layers */
.kp-cam {
  position: absolute;
  inset: 0;
}

@supports (height: 100dvh) {
  .kp { --u: min(calc(100vw / 1080), calc(100dvh / 1500)); }
}

/* Every animated piece is anchored to the screen centre.
   --cx/--cy = resting position, --x/--y/--s = animated offset/scale. */
.kp-layer {
  --cx: 0; --cy: 0; --x: 0; --y: 0; --s: 1;
  position: absolute;
  left: calc(50% + var(--kp-offset-x));
  top: calc(50% + var(--kp-offset-y));
  pointer-events: none;
  user-select: none;
  will-change: transform, opacity;
  transform:
    translate(-50%, -50%)
    translate(calc((var(--cx) + var(--x)) * var(--u)), calc((var(--cy) + var(--y)) * var(--u)))
    scale(var(--s));
}

.kp-layer img,
img.kp-layer { display: block; max-width: none; }

/* ---------- Key (key-01_165521.png, 8000x4500) ----------
   One image, split into two layers with clip-path so the bow can
   appear first and the shaft can slide in later. Together they
   rebuild the original key exactly. */
.kp-key {
  --cx: -525.8;
  --cy: -1.8;
  width: calc(1827 * var(--u));
  height: calc(1028 * var(--u));
  transform-origin: 80.175% 50%;      /* centre of the bow: the zoom-out pivots here */
}

.kp-key img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.kp-bow {
  opacity: 0;
  clip-path: polygon(61% 0, 100% 0, 100% 100%, 61% 100%, 61% 57.5%, 72% 57.5%, 72% 43.5%, 61% 43.5%);
}

.kp-shaft {
  --sx: -4000;
  clip-path: polygon(0 0, 61% 0, 61% 43.5%, 72% 43.5%, 72% 57.5%, 61% 57.5%, 61% 100%, 0 100%);
  transform: translateX(calc(var(--sx) * var(--u)));
  will-change: transform;
}

/* ---------- Star (SB .-01_165522.png, 8000x4500) ---------- */
.kp-star {
  --cx: -6;
  --cy: 3;
  --sh: .5;
  width: calc(1184 * var(--u));
  height: calc(666 * var(--u));
  /* soft drop shadow (stays down-right while the star turns) */
  filter: drop-shadow(calc(7 * var(--u)) calc(10 * var(--u)) calc(9 * var(--u)) rgba(35, 16, 2, var(--sh)));
}

.kp-star-img {
  --r: 0;
  width: 100%;
  height: 100%;
  transform: rotate(calc(var(--r) * 1deg));
  will-change: transform;
}

/* ---------- Glint on the star slot ---------- */
.kp-glint {
  --cx: 241.5;
  --cy: -64;
  width: calc(150 * var(--u));
  height: calc(150 * var(--u));
  opacity: 0;
  mix-blend-mode: screen;
  background: radial-gradient(circle, #fff 0, rgba(255, 252, 245, .9) 5%, rgba(255, 236, 210, .45) 14%, rgba(255, 230, 200, .12) 26%, transparent 40%);
}

.kp-glint::before {
  content: "";
  position: absolute;
  left: -40%;
  right: -40%;
  top: 50%;
  height: calc(3 * var(--u));
  margin-top: calc(-1.5 * var(--u));
  background: linear-gradient(90deg, transparent, rgba(255, 250, 240, .85) 50%, transparent);
}

/* ---------- Wordmark (logo.png, 3510x827) ---------- */
.kp-logo {
  --cx: -1;
  --cy: 74.4;
  --m: 0;                               /* reveal half-width in %, 0 -> 55 */
  width: calc(512.5 * var(--u));
  height: auto;
  -webkit-mask-image: linear-gradient(90deg, transparent calc(50% - var(--m) * 1% - 3%), #000 calc(50% - var(--m) * 1%), #000 calc(50% + var(--m) * 1%), transparent calc(50% + var(--m) * 1% + 3%));
          mask-image: linear-gradient(90deg, transparent calc(50% - var(--m) * 1% - 3%), #000 calc(50% - var(--m) * 1%), #000 calc(50% + var(--m) * 1%), transparent calc(50% + var(--m) * 1% + 3%));
}

/* ---------- ESTD / 2026 (text in the video, aligned to the wordmark edges) ---------- */
.kp-tag {
  position: absolute;
  top: calc(50% + var(--kp-offset-y) + -17 * var(--u));
  transform: translateY(-50%);
  opacity: 0;
  font-family: "Jost", system-ui, sans-serif;
  font-weight: 400;
  font-size: max(6px, calc(17 * var(--u)));
  line-height: 1;
  letter-spacing: .02em;
  color: #8A6F52;
  white-space: nowrap;
}

.kp-tag--l { left: calc(50% + var(--kp-offset-x) + -255 * var(--u)); }
.kp-tag--r { right: calc(50% - var(--kp-offset-x) + -253 * var(--u)); }
