/* Welcome film shown before the app loads (laptops and larger screens only).
   Markup and script are in index.html.
   Timeline: black letterbox → the drone shot fades up (.is-playing) → title
   card "Ertak shu yerda boshlanadi" → at the cut to the fireworks (.is-cut)
   the emblem and "Afsonalar vodiysiga xush kelibsiz" → the letterbox opens →
   fade to the site (.is-leaving). */

html.intro-on,
html.intro-on body {
  overflow: hidden;
}

#intro {
  /* cinema letterbox (2.39:1) */
  --bar: max(0px, calc((100vh - 100vw / 2.39) / 2));

  position: fixed;
  inset: 0;
  z-index: 2147483000;
  overflow: hidden;
  background: #000;
  color: #fff;
  cursor: pointer;
  transition: opacity 1s ease, visibility 1s ease;
}

#intro.is-leaving {
  opacity: 0;
  visibility: hidden;
}

#intro i {
  display: block;
}

/* ---------- the film ---------- */
.intro-film {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.intro-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: contrast(1.12) saturate(1.2) brightness(1.06);
}

/* fade up from black. No CSS zoom on the video: the footage is steady, and
   rescaling it makes the small night lights jump and shimmer. */
#intro.is-playing .intro-video {
  animation: intro-fade-in 1.8s ease 0.1s forwards;
}

/* colour grade: cool sky, warm ground */
.intro-grade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(20, 60, 110, 0.35) 0%, rgba(0, 0, 0, 0) 45%, rgba(120, 60, 10, 0.22) 100%);
  mix-blend-mode: soft-light;
}

.intro-dust {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 1.4s ease;
}

#intro.is-cut .intro-dust {
  opacity: 1;
}

.intro-grain {
  position: absolute;
  inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.12;
  mix-blend-mode: overlay;
  animation: intro-grain 0.6s steps(1) infinite;
}

.intro-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.72) 100%);
}

/* ---------- letterbox ---------- */
.intro-bar {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 3;
  height: calc(var(--bar) + 2px);
  background: #000;
}

.intro-bar--top {
  top: 0;
}

.intro-bar--bottom {
  bottom: 0;
}

#intro.is-cut .intro-bar--top {
  animation: intro-bar-up 1.1s cubic-bezier(0.65, 0, 0.35, 1) 1.8s forwards;
}

#intro.is-cut .intro-bar--bottom {
  animation: intro-bar-down 1.1s cubic-bezier(0.65, 0, 0.35, 1) 1.8s forwards;
}

/* ---------- title cards ---------- */
.intro-card {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 6vw;
  text-align: center;
  pointer-events: none;
}

.intro-tagline {
  margin: 0;
  padding-left: 0.42em; /* balances the letter-spacing after the last letter */
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(20px, 2.1vw, 34px);
  font-weight: 500;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #f3ead8;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
  opacity: 0;
}

#intro.is-playing .intro-tagline {
  animation: intro-tagline 3s cubic-bezier(0.25, 0.6, 0.3, 1) 0.8s forwards;
}

/* soft shade behind the name so it reads over the fireworks */
.intro-card--title::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -1;
  width: 95vw;
  height: 70vh;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));
  opacity: 0;
}

#intro.is-cut .intro-card--title::before {
  animation: intro-fade-in 1s ease forwards;
}

.intro-mark {
  position: relative;
  width: clamp(92px, 7.6vw, 132px);
  opacity: 0;
  transform: scale(0.92);
  /* clip the light sweep to the emblem's shape */
  -webkit-mask: url("/intro-emblem.png") center / contain no-repeat;
  mask: url("/intro-emblem.png") center / contain no-repeat;
}

.intro-mark img {
  display: block;
  width: 100%;
  height: auto;
}

.intro-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.85) 50%, transparent 65%);
  transform: translateX(-120%);
}

#intro.is-cut .intro-mark {
  animation: intro-mark 1s ease 0.05s forwards;
}

#intro.is-cut .intro-mark::after {
  animation: intro-sweep 1s ease 0.5s forwards;
}

.intro-name-wrap {
  position: relative;
  margin-top: clamp(18px, 2vw, 30px);
}

.intro-name {
  margin: 0;
  padding-left: 0.14em;
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(36px, 4.2vw, 76px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff;
  background: linear-gradient(100deg, #e9d6a6 0%, #fff8e6 30%, #ffd77a 45%, #fff8e6 60%, #e9d6a6 100%);
  background-size: 300% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  opacity: 0;
  filter: blur(12px) drop-shadow(0 6px 30px rgba(0, 0, 0, 0));
}

#intro.is-cut .intro-name {
  animation:
    intro-name 1.5s cubic-bezier(0.2, 0.65, 0.25, 1) 0.3s forwards,
    intro-shimmer 1.6s ease-in-out 1s forwards;
}

/* anamorphic lens flare sweeping across the name */
.intro-flare {
  position: absolute;
  top: 52%;
  left: 50%;
  width: 130vw;
  height: 2px;
  margin: -1px 0 0 -65vw;
  background: linear-gradient(90deg, rgba(90, 150, 255, 0) 0%, rgba(110, 170, 255, 0.35) 30%, rgba(170, 210, 255, 0.95) 49%, #fff 50%, rgba(170, 210, 255, 0.95) 51%, rgba(110, 170, 255, 0.35) 70%, rgba(90, 150, 255, 0) 100%);
  box-shadow: 0 0 10px 1px rgba(120, 175, 255, 0.55);
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
}

.intro-flare::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 180px;
  height: 180px;
  margin: -90px 0 0 -90px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95) 0%, rgba(170, 205, 255, 0.45) 18%, rgba(120, 170, 255, 0) 60%);
}

#intro.is-cut .intro-flare {
  animation: intro-flare 1.3s cubic-bezier(0.3, 0.1, 0.3, 1) 0.85s forwards;
}

.intro-welcome {
  margin: clamp(14px, 1.4vw, 22px) 0 0;
  padding-left: 0.55em;
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(16px, 1.55vw, 25px);
  font-weight: 500;
  letter-spacing: 0.55em;
  text-transform: uppercase;
  color: #f2c97a;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
  opacity: 0;
}

#intro.is-cut .intro-welcome {
  animation: intro-up 0.9s ease 0.95s forwards;
}

#intro.is-cut .intro-card--title {
  animation: intro-card-out 0.7s ease 1.95s forwards;
}

/* ---------- skip ---------- */
.intro-skip {
  position: absolute;
  right: 32px;
  bottom: max(18px, calc(var(--bar) / 2 - 15px));
  z-index: 4;
  padding: 6px 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  font: 500 13px/1.4 "Fira Sans Condensed", system-ui, sans-serif;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.6);
  opacity: 0;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  animation: intro-fade-in 0.6s ease 1s forwards;
}

.intro-skip:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

/* ---------- keyframes ---------- */
@keyframes intro-fade-in {
  to { opacity: 1; }
}

@keyframes intro-grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-8%, 4%); }
  40% { transform: translate(5%, -6%); }
  60% { transform: translate(-3%, 7%); }
  80% { transform: translate(7%, 2%); }
  100% { transform: translate(0, 0); }
}

@keyframes intro-bar-up {
  to { transform: translateY(-100%); }
}

@keyframes intro-bar-down {
  to { transform: translateY(100%); }
}

@keyframes intro-tagline {
  0% { opacity: 0; letter-spacing: 0.8em; filter: blur(8px); }
  40% { opacity: 1; letter-spacing: 0.45em; filter: blur(0); }
  78% { opacity: 1; letter-spacing: 0.4em; filter: blur(0); }
  100% { opacity: 0; letter-spacing: 0.38em; filter: blur(6px); }
}

@keyframes intro-mark {
  to { opacity: 1; transform: none; }
}

@keyframes intro-sweep {
  to { transform: translateX(120%); }
}

@keyframes intro-name {
  0% { opacity: 0; letter-spacing: 0.32em; filter: blur(12px) drop-shadow(0 6px 30px rgba(0, 0, 0, 0)); }
  100% { opacity: 1; letter-spacing: 0.14em; filter: blur(0) drop-shadow(0 6px 30px rgba(0, 0, 0, 0.65)); }
}

@keyframes intro-shimmer {
  to { background-position: 0 0; }
}

@keyframes intro-flare {
  0% { opacity: 0; transform: translateX(-38vw) scaleX(0.6); }
  30% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateX(38vw) scaleX(1); }
}

@keyframes intro-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes intro-card-out {
  to { opacity: 0; transform: scale(1.04); filter: blur(4px); }
}

/* Reduced motion: a still frame with the name, then a quick fade. */
@media (prefers-reduced-motion: reduce) {
  #intro * {
    animation: none !important;
    transition: none !important;
  }
  #intro {
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
  }
  .intro-video,
  .intro-mark,
  .intro-name,
  .intro-welcome,
  .intro-skip {
    opacity: 1;
    transform: none;
    filter: none;
  }
  .intro-card--first,
  .intro-flare,
  .intro-dust,
  .intro-grain {
    display: none;
  }
}
