#loader {
  position: fixed; inset: 0; z-index: 100; overflow: hidden; background: #05070c; color: var(--text, #f3f1ec);
  font-family: 'Oxanium', sans-serif; -webkit-user-select: none; user-select: none;
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(.2, .8, .2, 1);
}
#loader.out { opacity: 0; transform: scale(1.03); pointer-events: none; }
.ld-bg {
  --ld-art: url('../assets/loading/loading-bg.jpg');
  position: absolute; inset: -3%;
  background:
    var(--ld-art) center / cover no-repeat,
    radial-gradient(ellipse 60% 30% at 50% 44%, rgba(241, 190, 118, 0.25), rgba(241, 190, 118, 0) 70%),
    linear-gradient(180deg, #779bb6 0%, #c4b69c 38%, #b7824f 52%, #302b28 70%, #0b0d12 100%);
  animation: ldDrift 24s ease-in-out infinite alternate;
}
@keyframes ldDrift { from { transform: scale(1) translateY(0); } to { transform: scale(1.06) translateY(-0.8%); } }
.ld-scrim {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(0deg, rgba(4, 6, 12, 0.92) 0%, rgba(4, 6, 12, 0.55) 26%, rgba(4, 6, 12, 0) 52%),
    linear-gradient(90deg, rgba(4, 6, 12, 0.7) 0%, rgba(4, 6, 12, 0.2) 40%, rgba(4, 6, 12, 0) 62%);
}
.ld-scrim::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -40%; width: 30%; transform: skewX(-20deg);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
  animation: ldSweep 5.5s ease-in-out infinite;
}
@keyframes ldSweep { 0% { left: -40%; } 55%, 100% { left: 130%; } }

.ld-logo {
  position: absolute; left: 50%; top: clamp(24px, 7vh, 72px); transform: translateX(-50%);
  width: clamp(260px, 27vw, 440px); max-width: calc(100vw - 44px); height: auto; filter: drop-shadow(0 6px 22px rgba(0, 0, 0, 0.6));
  animation: ldLogoIn 0.9s cubic-bezier(.2, .8, .2, 1) 0.1s backwards;
}
@keyframes ldLogoIn { from { opacity: 0; transform: translate(-50%, -12px); } }
@keyframes ldIn { from { opacity: 0; transform: translateX(-24px); } }

.ld-bottom {
  position: absolute; left: clamp(22px, 4.3vw, 84px); right: clamp(22px, 4.3vw, 84px); bottom: clamp(26px, 7vh, 70px);
  animation: ldIn 0.9s cubic-bezier(.2, .8, .2, 1) 0.25s backwards;
}
.ld-row { display: flex; align-items: flex-end; justify-content: space-between; margin: 0 6px 12px 2px; }
.ld-label { display: flex; align-items: center; gap: 12px; font: 700 12px/1 'Oxanium', sans-serif; letter-spacing: 0.34em; color: rgba(232, 240, 247, 0.7); }
.ld-label::before { content: ""; width: 34px; height: 8px; transform: skewX(-20deg); background: repeating-linear-gradient(-55deg, rgba(255, 255, 255, 0.22) 0 4px, transparent 4px 13px), linear-gradient(90deg, #8aa918, #e8ff31); }
.ld-pct { display: flex; align-items: baseline; font: 400 clamp(64px, 8vw, 120px)/0.82 'Racing Sans One', Impact, sans-serif; letter-spacing: 0.01em; padding-right: 0.06em; font-variant-numeric: tabular-nums; }
.ld-pct i { font-style: normal; font-size: 0.42em; margin-left: 0.08em; }

.ld-track {
  position: relative; height: 34px; transform: skewX(-20deg);
  background: repeating-linear-gradient(90deg, transparent 0 calc(5% - 2px), rgba(233, 243, 255, 0.14) calc(5% - 2px) 5%), rgba(6, 12, 24, 0.66);
  border: 1px solid rgba(220, 230, 255, 0.4); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}
.ld-ticks { position: absolute; inset: 0; z-index: 2; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(233, 243, 255, 0.5) calc(10% - 2px) 10%); pointer-events: none; }
.ld-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%; transform-origin: left; transform: scaleX(0);
  background: repeating-linear-gradient(-55deg, rgba(255, 255, 255, 0.24) 0 4px, transparent 4px 13px), linear-gradient(90deg, #8aa918, #e8ff31);
  background-size: 28px 100%, 100% 100%; animation: ldHatch 0.7s linear infinite;
  box-shadow: 0 0 22px rgba(237, 255, 49, 0.25);
}
@keyframes ldHatch { to { background-position: 28px 0, 0 0; } }
.ld-car { position: absolute; top: 50%; left: 0; z-index: 3; width: 30px; height: 30px; margin: -15px 0 0 -14px; transform: skewX(20deg); color: #fff; filter: drop-shadow(0 0 10px rgba(237, 255, 49, 0.8)) drop-shadow(0 2px 3px #000); }
.ld-car svg { width: 100%; height: 100%; fill: currentColor; transform: rotate(180deg); }
.ld-flag { position: absolute; right: -2px; top: -5px; bottom: -5px; width: 24px; z-index: 3; background: conic-gradient(#fff 25%, #111 0 50%, #fff 0 75%, #111 0) 0 0 / 9px 9px; border: 1px solid #fff; }

.ld-meta { display: flex; justify-content: space-between; gap: 30px; margin: 14px 6px 0 2px; font: 600 11px/1.3 'Oxanium', sans-serif; letter-spacing: 0.24em; }
#ld-status { color: #edff31; white-space: nowrap; }
.ld-tip { color: rgba(232, 240, 247, 0.62); text-align: right; letter-spacing: 0.16em; }
.ld-tip.in { animation: ldTip 0.5s ease backwards; }
@keyframes ldTip { from { opacity: 0; transform: translateY(6px); } }

#loader.ready .ld-fill { animation: none; box-shadow: 0 0 40px rgba(237, 255, 49, 0.6); }
#loader.error #ld-status { color: #ff5a48; }
#loader.error .ld-fill { background: linear-gradient(90deg, #b3170d, #ff5a48); }

body.loading #menu, body.loading #hud, body.loading #finish { display: none !important; }

@media (max-aspect-ratio: 1/1) {
  .ld-bg { --ld-art: url('../assets/loading/loading-bg-mobile.jpg'); }
}
@media (max-aspect-ratio: 2/5) {
  .ld-bg {
    inset: 0; animation: none;
    background-size: auto 250vw, auto, auto;
    background-position: center top, center, center;
  }
}
@media (max-width: 760px) {
  .ld-meta { flex-direction: column; gap: 8px; }
  .ld-tip { text-align: left; }
  .ld-track { height: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .ld-bg, .ld-scrim::after, .ld-fill { animation: none; }
}
