/* ==========================================================================
   HOLIDAY STORYTELLING PRELOADER & PAGE TRANSITION CURTAIN
   Synced across phuot4p.com, agvvietnam.com.vn & dainesevietnam.com.vn
   - Pure GPU-composited motion (transform/translate + opacity)
   - Native <progress> accessible spinner (conic-gradient + border-area + mask fallback)
   - Modern @starting-style + transition-behavior: allow-discrete (+ Firefox [data-closing] fallback)
   - Full prefers-reduced-motion & forced-colors compliance
   ========================================================================== */

@property --hl-arc-start {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

@property --hl-arc-end {
  syntax: "<angle>";
  inherits: false;
  initial-value: 158deg;
}

@property --hl-dash-anim {
  syntax: "*";
  inherits: false;
  initial-value: , hl-progress-dash 2.6s ease-in-out infinite;
}

/* Per-holiday velvet luxury backdrop tokens (0 specificity via :where) */
:where(#p4pHolidayLoader) {
  --hl-bg-edge: #07080b;
  --hl-bg-aura: #1c1914;
  --hl-accent: #e5b84b;
  --hl-accent-soft: #fae4a2;
  --hl-glow: rgba(229, 184, 75, 0.36);
  --hl-particle-color: rgba(250, 228, 162, 0.85);
}

:where(#p4pHolidayLoader[data-holiday="noel"]) {
  --hl-bg-edge: #05110d;
  --hl-bg-aura: #0d3225;
  --hl-accent: #d9b25f;
  --hl-accent-soft: #fff2c8;
  --hl-glow: rgba(217, 178, 95, 0.42);
  --hl-particle-color: rgba(255, 255, 255, 0.9);
}

:where(#p4pHolidayLoader[data-holiday="tet"]) {
  --hl-bg-edge: #130507;
  --hl-bg-aura: #420c13;
  --hl-accent: #e0ad38;
  --hl-accent-soft: #fce29a;
  --hl-glow: rgba(224, 173, 56, 0.44);
  --hl-particle-color: rgba(252, 226, 154, 0.88);
}

:where(#p4pHolidayLoader[data-holiday="tet-duong-lich"]) {
  --hl-bg-edge: #070914;
  --hl-bg-aura: #1a2142;
  --hl-accent: #d4af37;
  --hl-accent-soft: #fff0b8;
  --hl-glow: rgba(212, 175, 55, 0.42);
  --hl-particle-color: rgba(255, 240, 184, 0.9);
}

:where(#p4pHolidayLoader[data-holiday="trung-thu"]) {
  --hl-bg-edge: #080d1e;
  --hl-bg-aura: #1e2852;
  --hl-accent: #f0a830;
  --hl-accent-soft: #ffe299;
  --hl-glow: rgba(240, 168, 48, 0.44);
  --hl-particle-color: rgba(255, 226, 153, 0.88);
}

:where(#p4pHolidayLoader[data-holiday="30-4"]),
:where(#p4pHolidayLoader[data-holiday="2-9"]) {
  --hl-bg-edge: #150608;
  --hl-bg-aura: #450b14;
  --hl-accent: #f0c23a;
  --hl-accent-soft: #fff0a8;
  --hl-glow: rgba(240, 194, 58, 0.44);
  --hl-particle-color: rgba(255, 240, 168, 0.88);
}

:where(#p4pHolidayLoader[data-holiday="hung-vuong"]) {
  --hl-bg-edge: #130c06;
  --hl-bg-aura: #3a220e;
  --hl-accent: #d99f3c;
  --hl-accent-soft: #f7da94;
  --hl-glow: rgba(217, 159, 60, 0.42);
  --hl-particle-color: rgba(247, 218, 148, 0.85);
}

/* ==========================================================================
   1. FULL-VIEWPORT CURTAIN WITH @starting-style & allow-discrete EXIT
   ========================================================================== */
.hl-overlay {
  position: fixed;
  inset: 0;
  z-index: 999990;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 40px);
  contain: layout style paint;
  background:
    radial-gradient(ellipse 68% 58% at 50% 44%, var(--hl-bg-aura) 0%, var(--hl-bg-edge) 74%),
    var(--hl-bg-edge);
  color: #ffffff;
  font-family: "Be Vietnam Pro", "Mulish", system-ui, -apple-system, sans-serif;
  overflow: clip;
  opacity: 1;
  scale: 1;
  transition:
    display,
    opacity ease-out,
    scale ease-out;
  transition-duration: 0.28s;
  /* Separate after transition shorthand so older browsers don't drop the whole declaration */
  transition-behavior: allow-discrete;
}

@starting-style {
  .hl-overlay {
    opacity: 0;
    scale: 1.015;
  }
}

.hl-overlay:where([hidden], [data-closing]) {
  opacity: 0;
  scale: 1.02;
  pointer-events: none;
}

.hl-overlay[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .hl-overlay {
    scale: 1;
    transition-duration: 0.16s;
  }
  @starting-style {
    .hl-overlay {
      scale: 1;
    }
  }
  .hl-overlay:where([hidden], [data-closing]) {
    scale: 1;
  }
}

/* Subtle decorative velvet corner framing */
.hl-overlay::before {
  content: "";
  position: absolute;
  inset: clamp(10px, 2vw, 22px);
  border: 1px solid color-mix(in srgb, var(--hl-accent) 26%, transparent);
  pointer-events: none;
}

/* ==========================================================================
   2. AMBIENT HOLIDAY SKY PARTICLES (GPU-ONLY, OPT-IN MOTION)
   ========================================================================== */
.hl-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: clip;
}

.hl-spark {
  position: absolute;
  top: -12px;
  left: var(--x, 50%);
  inline-size: var(--sz, 5px);
  block-size: var(--sz, 5px);
  border-radius: 50%;
  background: var(--hl-particle-color);
  box-shadow: 0 0 10px var(--hl-glow);
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .hl-overlay:not([hidden]):not([data-closing]) .hl-spark {
    animation: hl-drift var(--dur, 4.5s) linear var(--del, 0s) infinite;
  }
  @keyframes hl-drift {
    0% {
      opacity: 0;
      transform: translate3d(0, 0, 0) scale(0.75);
    }
    15% {
      opacity: 0.78;
    }
    85% {
      opacity: 0.65;
    }
    100% {
      opacity: 0;
      transform: translate3d(var(--dx, -32px), 102svh, 0) scale(1.08);
    }
  }
}

/* ==========================================================================
   3. CENTER EDITORIAL STAGE & STORYTELLING TRACK
   ========================================================================== */
.hl-card {
  position: relative;
  z-index: 2;
  inline-size: min(760px, 94vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 2.2vh, 22px);
  text-align: center;
}

.hl-brand-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.hl-brand-logo-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.hl-brand-logo {
  block-size: 38px;
  inline-size: auto;
  max-inline-size: 164px;
  object-fit: contain;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.55));
}

.hl-brand-logo--invert {
  filter: brightness(0) invert(1) drop-shadow(0 4px 14px rgba(0, 0, 0, 0.45));
}

.hl-brand-wordmark {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #ffffff;
}

.hl-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--hl-accent) 48%, transparent);
  background: rgba(255, 255, 255, 0.04);
  font-family: "Source Code Pro", ui-monospace, monospace;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--hl-accent-soft);
}

/* --- Animated Scenic Track --- */
.hl-stage {
  position: relative;
  inline-size: 100%;
  block-size: clamp(168px, 26vw, 232px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-block-end: 20px;
  overflow: visible;
}

/* Subtle radiant aurora pool beneath the track */
.hl-stage::before {
  content: "";
  position: absolute;
  inset-inline: 4%;
  inset-block-end: 6px;
  block-size: 86px;
  background: radial-gradient(ellipse 52% 60% at 50% 100%, var(--hl-glow) 0%, transparent 72%);
  pointer-events: none;
}

/* Character lane (spans left edge up to showroom edge) */
.hl-lane {
  position: relative;
  flex: 1 1 auto;
  block-size: 100%;
  min-inline-size: 0;
  overflow: visible;
}

/* Moving Character Sprite Container */
.hl-rider-track {
  position: absolute;
  inset-inline-start: 0;
  inset-block-end: 12px;
  inline-size: clamp(220px, 39vw, 344px);
  block-size: clamp(120px, 19vw, 174px);
  /* Static fallback & reduced-motion resting position */
  transform: translate3d(38%, 0, 0);
}

@media (prefers-reduced-motion: no-preference) {
  .hl-overlay.is-running .hl-rider-track {
    will-change: transform;
    animation: hl-journey var(--hl-journey-ms, 920ms) cubic-bezier(0.22, 0.85, 0.36, 1) forwards;
  }
  .hl-overlay.is-navigating .hl-rider-track {
    will-change: transform;
    animation: hl-journey-nav 1200ms cubic-bezier(0.25, 0.8, 0.35, 1) forwards;
  }

  @keyframes hl-journey {
    0% {
      transform: translate3d(-14%, 0, 0);
    }
    76% {
      transform: translate3d(calc(100cqi - 94%), 0, 0);
    }
    100% {
      transform: translate3d(calc(100cqi - 92%), 0, 0);
    }
  }

  @keyframes hl-journey-nav {
    0% {
      transform: translate3d(-10%, 0, 0);
    }
    100% {
      transform: translate3d(calc(100cqi - 98%), 0, 0);
    }
  }

  /* Organic galloping / riding bob on inner figure */
  .hl-overlay.is-running .hl-rider-bob,
  .hl-overlay.is-navigating .hl-rider-bob {
    will-change: transform;
    animation: hl-gallop 0.44s ease-in-out infinite;
  }

  @keyframes hl-gallop {
    0%, 100% {
      transform: translate3d(0, 0, 0) rotate(-0.8deg);
    }
    50% {
      transform: translate3d(0, -7px, 0) rotate(1.1deg);
    }
  }
}

/* Container query context on lane so 100cqi tracks exact travel width cleanly */
.hl-lane {
  container-type: inline-size;
}

.hl-rider-bob {
  inline-size: 100%;
  block-size: 100%;
}

/* True RGBA transparent WebP cutout sprite — zero dark box on any backdrop */
.hl-rider-img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
  object-position: center bottom;
  display: block;
  filter: drop-shadow(0 8px 22px var(--hl-glow));
  user-select: none;
  pointer-events: none;
}

/* --- Glowing Boutique Showroom Destination (Right End of Track) --- */
.hl-dest {
  position: relative;
  flex: 0 0 auto;
  inline-size: clamp(104px, 16vw, 138px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-inline-start: 6px;
  z-index: 3;
}

.hl-dest-halo {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--hl-glow) 0%, transparent 70%);
  opacity: 0.45;
  transform: scale(0.92);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}

.hl-overlay.is-arrived .hl-dest-halo {
  opacity: 1;
  transform: scale(1.22);
}

.hl-dest-svg {
  position: relative;
  inline-size: clamp(78px, 11vw, 102px);
  block-size: auto;
  filter: drop-shadow(0 0 14px var(--hl-glow));
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.hl-overlay.is-arrived .hl-dest-svg {
  transform: scale(1.07);
}

.hl-dest-tag {
  position: relative;
  font-family: "Source Code Pro", ui-monospace, monospace;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--hl-accent-soft);
  white-space: nowrap;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9);
}

/* --- Luminous Road Rail + GPU Progress Fill --- */
.hl-rail {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 10px;
  block-size: 2.5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: clip;
}

.hl-rail-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--hl-accent) 45%, var(--hl-accent-soft) 100%);
  transform-origin: left center;
  transform: scaleX(0.62);
  box-shadow: 0 0 14px var(--hl-accent);
}

@media (prefers-reduced-motion: no-preference) {
  .hl-overlay.is-running .hl-rail-fill {
    will-change: transform;
    animation: hl-rail-run var(--hl-journey-ms, 920ms) cubic-bezier(0.22, 0.85, 0.36, 1) forwards;
  }
  .hl-overlay.is-navigating .hl-rail-fill {
    will-change: transform;
    animation: hl-rail-nav 1200ms cubic-bezier(0.25, 0.8, 0.35, 1) forwards;
  }
  @keyframes hl-rail-run {
    0% { transform: scaleX(0.06); }
    78% { transform: scaleX(0.92); }
    100% { transform: scaleX(1); }
  }
  @keyframes hl-rail-nav {
    0% { transform: scaleX(0.08); }
    100% { transform: scaleX(0.86); }
  }
}

/* ==========================================================================
   4. SEMANTIC <progress> SPINNER + STORYTELLING CAPTION + SKIP CONTROL
   Follows modern-web-guidance `spinner` (conic-gradient + border-area + fallback)
   ========================================================================== */
.hl-status-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-inline-size: 92%;
}

progress.hl-spinner:indeterminate::-webkit-progress-inner-element,
progress.hl-spinner:indeterminate::-webkit-progress-bar,
progress.hl-spinner:indeterminate::-webkit-progress-value,
progress.hl-spinner:indeterminate::-moz-progress-bar,
progress.hl-spinner:indeterminate::slider-fill {
  display: none;
  background: none;
}

progress.hl-spinner:indeterminate {
  --_from: calc(90deg + var(--hl-arc-start, 0deg));
  --_to: calc(90deg + var(--hl-arc-end, 158deg));
  --hl-spin-size: 20px;
  --hl-spin-thick: 2.5px;
  --hl-spin-color: var(--hl-accent-soft, #fae4a2);
  --hl-spin-track: rgba(255, 255, 255, 0.16);
  --hl-spin-duration: 1.35s;
  --_used-hl-spin-duration: var(--hl-spin-duration);

  position: relative;
  flex: 0 0 auto;
  inline-size: var(--hl-spin-size);
  block-size: var(--hl-spin-size);
  border-radius: 50%;
  border: 0;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  background:
    conic-gradient(
      from var(--_from),
      var(--hl-spin-color) calc(var(--_to) - var(--_from)),
      transparent 0
    )
    var(--hl-spin-track);

  animation:
    hl-progress-spin var(--_used-hl-spin-duration) linear infinite
    var(--hl-dash-anim, );
}

@supports (background-clip: border-area) {
  progress.hl-spinner:indeterminate {
    background-clip: border-area;
    border: var(--hl-spin-thick) solid transparent;
    background-origin: border-box;
  }
}

@supports not (background-clip: border-area) {
  progress.hl-spinner:indeterminate {
    --hl-clip-boundary: calc(100% - var(--hl-spin-thick));
    mask-image: radial-gradient(
      farthest-side,
      transparent var(--hl-clip-boundary),
      black var(--hl-clip-boundary)
    );
    -webkit-mask-image: radial-gradient(
      farthest-side,
      transparent var(--hl-clip-boundary),
      black var(--hl-clip-boundary)
    );
    border: 0;
  }
}

@media (forced-colors: active) {
  progress.hl-spinner:indeterminate {
    forced-color-adjust: none;
    --hl-spin-color: CanvasText;
    --hl-spin-track: Canvas;
  }
}

@keyframes hl-progress-spin {
  to {
    rotate: 1turn;
  }
}

@keyframes hl-progress-dash {
  from {
    --hl-arc-start: 0deg;
    --hl-arc-end: 8deg;
  }
  50% {
    --hl-arc-start: 100deg;
    --hl-arc-end: 356deg;
  }
  to {
    --hl-arc-start: 360deg;
    --hl-arc-end: 368deg;
  }
}

@media (prefers-reduced-motion: reduce) {
  progress.hl-spinner:indeterminate {
    --_used-hl-spin-duration: 6s;
    --hl-dash-anim: ;
    --hl-arc-end: 158deg;
  }
}

.hl-caption {
  margin: 0;
  font-size: clamp(13px, 1.45vw, 15.5px);
  font-weight: 500;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.01em;
}

.hl-caption strong {
  color: var(--hl-accent-soft);
  font-weight: 700;
}

.hl-skip-btn {
  margin-block-start: 4px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.78);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.hl-skip-btn:hover,
.hl-skip-btn:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--hl-accent-soft);
  color: #ffffff;
  outline: 2px solid var(--hl-accent-soft);
  outline-offset: 2px;
}

/* Discreet 3px golden top ribbon shown ONLY while departing an internal link (prevents double full-screen loader!) */
#p4pHlTopBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 999995;
  pointer-events: none;
  opacity: 0;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #b8892a 0%, #fae4a2 55%, #ffffff 100%);
  box-shadow: 0 0 10px rgba(229, 184, 75, 0.7);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.16s ease;
}
#p4pHlTopBar.is-active {
  opacity: 1;
  transform: scaleX(0.76);
}

@media (max-width: 640px) {
  .hl-stage {
    block-size: 154px;
  }
  .hl-rider-track {
    inline-size: min(210px, 56vw);
  }
  .hl-dest {
    inline-size: 86px;
  }
  .hl-dest-svg {
    inline-size: 66px;
  }
  .hl-dest-tag {
    font-size: 8.5px;
    letter-spacing: 0.08em;
  }
  .hl-pill {
    font-size: 9.5px;
    padding: 4px 12px;
    letter-spacing: 0.11em;
  }
}
