/*
 * Mộng Giới — launching screen. Figma: MongGioi → LDP.
 *
 * --u = 1 px của Figma. Mọi kích thước / vị trí đều là calc(<px trong Figma> * var(--u)),
 * nên cả màn hình co giãn đồng đều và giữ đúng tỷ lệ thiết kế.
 *
 *   Desktop (ngang, ≥ 768px): khung 1920 × 1080 thu vừa màn hình, không bị cắt.
 *   Mobile  (còn lại):        khung 402 × 874 theo chiều rộng (tối đa 1.5×), cuộn nếu màn thấp.
 *
 * Phần dùng chung ở trên, phần riêng từng layout nằm trong 2 khối @media ở cuối file.
 * Giữ query desktop giống DESKTOP_QUERY trong js/main.js và các <source media> trong index.html.
 */

/* ------------------------------------------------------------------ base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: #f9eff9;
  color: #000;
  font-family: "Nunito Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img {
  display: block;
}

button {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------------ page */

/* clip (không phải hidden): ảnh nền lớn hơn màn hình, hidden vẫn cho cuộn khi focus/scrollIntoView
   làm lệch cả bố cục; clip thì không bao giờ cuộn. */
.page {
  overflow: hidden;
  overflow: clip;
  background: #f9eff9;
}

.background {
  position: absolute;
  max-width: none;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

/* Mobile 962:8709: lớp mờ dần rgba(249,239,249,0) → #f9eff9 khi mở video. */
.fade {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: calc(874 * var(--u));
  background: linear-gradient(to bottom, rgb(249 239 249 / 0), #f9eff9 61.681%);
  pointer-events: none;
}

/* "Rectangle 1" — khung SVG đã gồm phần viền tràn ra ngoài. */
.header-plate {
  position: absolute;
  left: 50%;
  top: calc(-2 * var(--u));
  translate: -50% 0;
  max-width: none;
}

.logo {
  position: absolute;
  object-fit: cover;
}

/* ------------------------------------------------------------------ hero */

.hero {
  position: absolute;
  left: 50%;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
}

.title {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  line-height: normal;
  text-align: center;
}

.title-main {
  font-weight: 900;
  white-space: nowrap;
}

.date-pill {
  margin: 0;
  border-radius: calc(60 * var(--u));
  background-image: linear-gradient(to bottom, #efccf9, #f0def1);
  color: #000;
  line-height: normal;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ countdown (962:7901) */

.countdown {
  display: flex;
  align-items: flex-start;
  gap: calc(32 * var(--u));
  padding: calc(20 * var(--u)) calc(20 * var(--u)) 0;
}

.unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(8 * var(--u));
}

.box {
  position: relative;
  width: calc(74 * var(--u));
  height: calc(74 * var(--u));
  overflow: hidden;
  background: #fff;
  border: calc(4 * var(--u)) solid #a9b0f4;
  border-radius: calc(16 * var(--u));
}

.box-lower {
  position: absolute;
  left: 0;
  top: calc(37 * var(--u));
  width: calc(74 * var(--u));
  height: calc(37 * var(--u));
  background: #d5ceeb;
}

.value {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 27 * var(--u));
  font-size: calc(40 * var(--u));
  font-weight: 700;
  line-height: normal;
  color: #263c80;
  text-align: center;
  white-space: nowrap;
}

.label {
  font-size: calc(16 * var(--u));
  font-weight: 900;
  line-height: normal;
  color: #cd3fd1;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ gift box */

/* Ghi chú Figma: "Hộp quà có hiệu ứng rung lắc". */
.gift {
  position: absolute;
  object-fit: cover;
  transform-origin: 50% 90%;
  animation: gift-shake 2.8s ease-in-out infinite;
  pointer-events: none;
}

@keyframes gift-shake {
  0%,
  60%,
  100% {
    rotate: 0deg;
  }
  66% {
    rotate: -5deg;
  }
  72% {
    rotate: 5deg;
  }
  78% {
    rotate: -4deg;
  }
  84% {
    rotate: 3deg;
  }
  90% {
    rotate: -1deg;
  }
}

/* ------------------------------------------------------------------ CTA "XEM NGAY" */

/* 962:7917 desktop; mobile 962:8315 = desktop × 0.68 (--k). Hiệu ứng: phóng to + sáng lên. */
.cta {
  --k: 1;
  position: absolute;
  width: calc(459.211 * var(--k) * var(--u));
  height: calc(100 * var(--k) * var(--u));
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  translate: -50% 0;
  animation: cta-pulse 1.6s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

.cta:hover {
  filter: brightness(1.12);
}

.cta:focus-visible {
  outline: calc(3 * var(--u)) solid #fac67b;
  outline-offset: calc(4 * var(--u));
  border-radius: calc(24 * var(--u));
}

/* "Layer 30 1": ảnh được cắt trong khung giống hệt Figma. */
.cta-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.cta-art img {
  position: absolute;
  left: -16.62%;
  top: -73.68%;
  width: 132.95%;
  height: 256.58%;
  max-width: none;
}

.cta-label {
  position: absolute;
  left: calc(117.105 * var(--k) * var(--u));
  top: calc(28.947 * var(--k) * var(--u));
  font-size: calc(47.368 * var(--k) * var(--u));
  font-weight: 900;
  line-height: normal;
  white-space: nowrap;
  background-image: linear-gradient(to bottom, #fffbf5, #fac67b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

@keyframes cta-pulse {
  0%,
  100% {
    scale: 1;
    filter: brightness(1);
  }
  50% {
    scale: 1.06;
    filter: brightness(1.2);
  }
}

/* ------------------------------------------------------------------ teaser video */

/* Chỉ hiện sau khi bấm "XEM NGAY" (JS thêm class .is-teaser vào .page). */
.teaser {
  display: none;
}

.is-teaser .teaser {
  display: block;
}

/* 962:8228 (desktop popup) / 962:8790 (mobile). Số đo riêng nằm trong biến của từng layout. */
.teaser-video {
  position: absolute;
  overflow: hidden;
  background: #fff;
  border: calc(var(--border) * var(--u)) solid #f9eff9;
}

/* Ảnh chụp bắt đầu từ mép ngoài (-border) và bị cắt bởi khung, như Figma. */
.poster {
  position: absolute;
  left: calc(var(--border) * -1 * var(--u));
  top: calc(var(--border) * -1 * var(--u));
  width: calc(var(--poster-w) * var(--u));
  height: calc(var(--poster-h) * var(--u));
  max-width: none;
  object-fit: cover;
  pointer-events: none;
}

.teaser-video video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.is-playing .poster,
.is-playing .play,
.is-playing .maximize {
  display: none;
}

.play,
.maximize,
.close {
  position: absolute;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.play:disabled,
.maximize:disabled {
  cursor: not-allowed;
}

.play {
  left: 50%;
  top: 50%;
  width: calc(var(--play) * var(--u));
  height: calc(var(--play) * var(--u));
  translate: -50% -50%;
  border-radius: 50%;
  transition: scale 0.2s ease;
}

.play:not(:disabled):hover {
  scale: 1.08;
}

/* Mobile: "maximize" 24 × 24 tại (353, 183) trong khung video. */
.maximize {
  left: calc(353 * var(--u));
  top: calc(183 * var(--u));
  width: calc(24 * var(--u));
  height: calc(24 * var(--u));
}

/* Desktop: "x-close" 48 × 48 tại (1656, 105). */
.close {
  left: calc(1656 * var(--u));
  top: calc(105 * var(--u));
  width: calc(48 * var(--u));
  height: calc(48 * var(--u));
  border-radius: 50%;
}

.play img,
.maximize img,
.close img {
  width: 100%;
  height: 100%;
}

.play:focus-visible,
.maximize:focus-visible,
.close:focus-visible {
  outline: calc(2 * var(--u)) solid #fff;
  outline-offset: calc(2 * var(--u));
}

/* ------------------------------------------------------------------ social links */

/* 962:8110 (desktop) / 962:8355 (mobile). Số đo riêng nằm trong biến của từng layout. */
.socials {
  position: absolute;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(12 * var(--u));
  color: #000;
}

.socials-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  line-height: normal;
}

.socials-heading {
  margin: 0;
  font-size: calc(var(--heading-size) * var(--u));
  font-weight: 900;
  line-height: normal;
  white-space: nowrap;
}

.socials-subtitle {
  width: 100%;
  margin: 0;
  font-size: calc(var(--subtitle-size) * var(--u));
  font-weight: 400;
  line-height: normal;
  text-align: center;
}

.socials-rows {
  display: flex;
  gap: calc(12 * var(--u));
}

.socials-row {
  display: flex;
  justify-content: center;
  gap: calc(12 * var(--u));
  margin: 0;
  padding: 0;
  list-style: none;
}

.pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--pill-gap) * var(--u));
  padding: calc(var(--pill-pad-y) * var(--u)) calc(var(--pill-pad-right) * var(--u))
    calc(var(--pill-pad-y) * var(--u)) calc(var(--pill-pad-left) * var(--u));
  border: calc(1 * var(--u)) solid #0c0b0c;
  border-radius: calc(var(--pill-radius) * var(--u));
  background-image: linear-gradient(to top, #efdef1, #efccf9);
  color: #000;
  text-decoration: none;
  transition:
    filter 0.2s ease,
    translate 0.2s ease;
}

.pill:hover {
  filter: brightness(1.05);
  translate: 0 calc(-2 * var(--u));
}

.pill:focus-visible {
  outline: calc(2 * var(--u)) solid #cd3fd1;
  outline-offset: calc(2 * var(--u));
}

.pill-label {
  font-size: calc(var(--label-size) * var(--u));
  font-weight: 700;
  line-height: normal;
  white-space: nowrap;
}

.icon {
  position: relative;
  flex: none;
  width: calc(var(--icon-size) * var(--u));
  height: calc(var(--icon-size) * var(--u));
}

.icon-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* TikTok / Telegram trong Figma = ô nền gradient + glyph đặt lệch vào trong. */
.icon-tiktok::before,
.icon-telegram::before {
  content: "";
  position: absolute;
  border-radius: calc(var(--tile-radius) * var(--u));
}

.icon-tiktok::before {
  inset: 0;
  background-image: linear-gradient(141.384deg, #000 0.9%, #323232 99%);
}

.icon-telegram::before {
  inset: 0 0.27% 0.27% 0;
  background-image: linear-gradient(137.237deg, #0088cc 8.1%, #0083c5 94.96%);
}

.icon-glyph {
  position: absolute;
}

.icon-tiktok .icon-glyph {
  left: 25.745%;
  top: 23.04%;
  width: 47.919%;
  height: 54.201%;
}

.icon-telegram .icon-glyph {
  left: 15.79%;
  top: 18.92%;
  width: 60.81%;
  height: 60.81%;
}

.socials-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(8 * var(--u));
  width: 100%;
  margin: 0;
  font-size: calc(14 * var(--u));
  font-weight: 500;
  line-height: normal;
  text-align: center;
  white-space: nowrap;
}

.dot {
  width: calc(4 * var(--u));
  height: calc(4 * var(--u));
}

/* ================================================================== MOBILE — 402 × 874 */

@media not all and (min-width: 768px) and (min-aspect-ratio: 1/1) {
  .page {
    --u: min(100vw / 402, 1.5px);
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .stage {
    position: relative;
    width: calc(402 * var(--u));
    height: calc(874 * var(--u));
    margin: 0 auto;
  }

  /* Nền của frame: cùng ảnh, cắt 405.53% × 104.92% tại (-152.76%, -11.76%). */
  .background {
    left: calc(50% - 815.096 * var(--u));
    top: calc(-102.782 * var(--u));
    width: calc(1630.231 * var(--u));
    height: calc(917.001 * var(--u));
  }

  .is-teaser .fade {
    display: block;
  }

  .header-plate {
    width: calc(350.405 * var(--u));
    height: calc(94 * var(--u));
  }

  .logo {
    left: calc(113 * var(--u));
    top: calc(11 * var(--u));
    width: calc(175.231 * var(--u));
    height: calc(68 * var(--u));
  }

  .hero {
    top: calc(128 * var(--u));
  }

  .title-lead {
    font-size: calc(24 * var(--u));
    font-weight: 700;
  }

  .title-main {
    font-size: calc(36 * var(--u));
  }

  .date-pill {
    padding: calc(4 * var(--u)) calc(32 * var(--u));
    font-size: calc(32 * var(--u));
    font-weight: 800;
  }

  .gift {
    left: calc(85 * var(--u));
    top: calc(369 * var(--u));
    width: calc(218 * var(--u));
    height: calc(198 * var(--u));
  }

  .cta {
    --k: 0.68;
    left: calc(50% + 0.13 * var(--u));
    top: calc(577 * var(--u));
  }

  /* Sau khi bấm "XEM NGAY": đồng hồ, hộp quà, nút nhường chỗ cho video. */
  .is-teaser .countdown,
  .is-teaser .gift,
  .is-teaser .cta {
    display: none;
  }

  .teaser-video {
    --border: 1;
    --poster-w: 386.168;
    --poster-h: 217.125;
    --play: 60;
    left: 50%;
    top: calc(294 * var(--u));
    width: calc(386 * var(--u));
    height: calc(216 * var(--u));
    translate: -50% 0;
  }

  .close {
    display: none;
  }

  .socials {
    --heading-size: 14;
    --subtitle-size: 14;
    --icon-size: 20;
    --label-size: 16;
    --pill-pad-y: 4;
    --pill-pad-left: 4;
    --pill-pad-right: 8;
    --pill-gap: 4;
    --pill-radius: 28;
    --tile-radius: 8.13;
    left: 50%;
    top: calc(663 * var(--u));
    width: calc(386 * var(--u));
  }

  .is-teaser .socials {
    top: calc(548 * var(--u));
  }

  .socials-copy {
    align-items: flex-start;
  }

  .socials-rows {
    flex-direction: column;
  }

  .socials-row {
    width: calc(386 * var(--u));
  }

  .pill {
    height: calc(32 * var(--u));
  }
}

/* ================================================================== DESKTOP — 1920 × 1080 */

@media (min-width: 768px) and (min-aspect-ratio: 1/1) {
  /*
   * --c: tỷ lệ của ảnh nền. Bằng --u trên màn 16:9, chỉ lớn hơn khi màn rộng hơn ảnh
   * (2063 px thiết kế) để nền luôn phủ kín chiều ngang. Nền neo vào bục đứng của hộp quà
   * (điểm 947,804 của thiết kế ↔ điểm 1015,850 của ảnh) nên hộp quà luôn nằm trên bục.
   * Khung bám mép trên; màn cao hơn 16:9 thì phần dưới là #f9eff9 (đúng màu mép dưới ảnh).
   */
  .page {
    --u: min(100vw / 1920, 100vh / 1080);
    --c: max(var(--u), 100vw / 2040);
    position: fixed;
    inset: 0;
  }

  @supports (height: 100dvh) {
    .page {
      --u: min(100vw / 1920, 100dvh / 1080);
    }
  }

  .stage {
    position: absolute;
    left: 50%;
    top: 0;
    width: calc(1920 * var(--u));
    height: calc(1080 * var(--u));
    translate: -50% 0;
  }

  /* "Group 272 1": 2063 × 1160 tại (-68, -46) trên màn 16:9. */
  .background {
    left: calc(50% - 13 * var(--u) - 1015 * var(--c));
    top: calc(804 * var(--u) - 850 * var(--c));
    width: calc(2063 * var(--c));
    height: calc(1160 * var(--c));
  }

  .header-plate {
    width: calc(564.432 * var(--u));
    height: calc(150 * var(--u));
  }

  .logo {
    left: calc(826 * var(--u));
    top: calc(21 * var(--u));
    width: calc(268 * var(--u));
    height: calc(104 * var(--u));
  }

  .hero {
    top: calc(166 * var(--u));
    width: calc(637 * var(--u));
  }

  .title-lead {
    font-size: calc(40 * var(--u));
    font-weight: 900;
  }

  .title-main {
    font-size: calc(64 * var(--u));
  }

  .date-pill {
    padding: calc(4 * var(--u)) calc(40 * var(--u));
    font-size: calc(40 * var(--u));
    font-weight: 900;
  }

  .gift {
    left: calc(782 * var(--u));
    top: calc(504 * var(--u));
    width: calc(330 * var(--u));
    height: calc(300 * var(--u));
  }

  .cta {
    left: calc(50% - 0.39 * var(--u));
    top: calc(781 * var(--u));
  }

  /* Popup video (962:8155): chỉ còn nền + video + nút đóng. */
  .is-teaser .header-plate,
  .is-teaser .logo,
  .is-teaser .hero,
  .is-teaser .gift,
  .is-teaser .cta,
  .is-teaser .socials {
    display: none;
  }

  .teaser-video {
    --border: 4;
    --poster-w: 1440;
    --poster-h: 810;
    --play: 100;
    left: calc(240 * var(--u));
    top: calc(129 * var(--u));
    width: calc(1440 * var(--u));
    height: calc(810 * var(--u));
  }

  .maximize {
    display: none;
  }

  .socials {
    --heading-size: 24;
    --subtitle-size: 16;
    --icon-size: 32;
    --label-size: 24;
    --pill-pad-y: 8;
    --pill-pad-left: 8;
    --pill-pad-right: 16;
    --pill-gap: 10;
    --pill-radius: 40;
    --tile-radius: 13.008;
    left: calc(50% + 0.5 * var(--u));
    top: calc(911 * var(--u));
  }
}

/* ------------------------------------------------------------------ reduced motion */

@media (prefers-reduced-motion: reduce) {
  .gift,
  .cta {
    animation: none;
  }
}
