/* ============================================================
   ANIMATED BUS PRELOADER — theme-aware
   The background, window tint, and accents all pull from the
   CSS variables defined per theme in themes.css:
     --grad-brand  : the theme's primary gradient
     --brand       : the theme's solid brand color
   Fallbacks keep it working even if themes.css is missing.
   ============================================================ */

.bus-preloader{
  position:fixed;inset:0;z-index:99999;
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  background: var(--grad-brand, linear-gradient(135deg,#6366f1 0%,#8b5cf6 50%,#ec4899 100%));
  opacity:0;visibility:hidden;
  transition:opacity .35s ease, visibility .35s ease;
  padding:20px;
}
.bus-preloader.show{opacity:1;visibility:visible}

/* Soft radial glow behind the scene — neutral, works on every theme */
.bus-preloader::before{
  content:"";position:absolute;inset:0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.25), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,.18), transparent 55%);
  pointer-events:none;
}

/* Stage — where the bus animates */
.bp-stage{
  position:relative;width:min(340px,80vw);height:120px;
  margin-bottom:24px;overflow:hidden;
}
.bp-road{
  position:absolute;left:0;right:0;bottom:14px;height:6px;
  background:rgba(255,255,255,.35);
  border-radius:3px;
}
.bp-road::after{
  content:"";position:absolute;left:0;right:0;bottom:-10px;height:6px;
  background-image:linear-gradient(90deg, rgba(255,255,255,.55) 50%, transparent 50%);
  background-size:36px 6px;
  animation:bp-road-move .6s linear infinite;
}
@keyframes bp-road-move{
  from{background-position:0 0}
  to{background-position:-36px 0}
}

/* Bus body */
.bp-bus{
  position:absolute;left:50%;bottom:20px;transform:translateX(-50%);
  animation:bp-bus-bob .45s ease-in-out infinite alternate;
}
@keyframes bp-bus-bob{
  from{transform:translateX(-50%) translateY(0)}
  to{transform:translateX(-50%) translateY(-2px)}
}

.bp-body{
  position:relative;width:180px;height:64px;
  background:linear-gradient(180deg,#fefefe 0%,#e2e8f0 100%);
  border-radius:10px 14px 8px 8px;
  box-shadow:
    0 12px 24px -8px rgba(2,6,23,.35),
    inset 0 -2px 0 rgba(2,6,23,.08);
}

/* ---------- Windshields — use brand color ---------- */
.bp-body::before{
  content:"";position:absolute;right:6px;top:8px;width:26px;height:22px;
  background:linear-gradient(180deg, rgba(255,255,255,.9) 0%, var(--brand, #6366f1) 100%);
  border-radius:4px 6px 6px 4px;
  box-shadow:inset 0 2px 0 rgba(255,255,255,.4);
}
.bp-body::after{
  content:"";position:absolute;left:6px;top:8px;width:20px;height:22px;
  background:linear-gradient(180deg, rgba(255,255,255,.9) 0%, var(--brand, #6366f1) 100%);
  border-radius:4px;
  box-shadow:inset 0 2px 0 rgba(255,255,255,.4);
}

/* Side windows — same treatment */
.bp-windows{
  position:absolute;left:32px;right:36px;top:8px;
  display:flex;gap:4px;
}
.bp-windows span{
  flex:1;height:22px;
  background:linear-gradient(180deg, rgba(255,255,255,.9) 0%, var(--brand, #6366f1) 100%);
  border-radius:3px;
  box-shadow:inset 0 2px 0 rgba(255,255,255,.4);
}

/* Wheels — neutral silver, reads on any background */
.bp-wheel{
  position:absolute;bottom:-8px;width:22px;height:22px;
  border-radius:50%;
  background:radial-gradient(circle at 40% 40%, #475569 0%, #0f172a 80%);
  border:2px solid #1e293b;
  animation:bp-wheel-spin .55s linear infinite;
}
.bp-wheel::before{
  content:"";position:absolute;inset:7px;border-radius:50%;
  background:#94a3b8;
}
.bp-wheel.w1{left:24px}
.bp-wheel.w2{right:24px}
@keyframes bp-wheel-spin{
  to{transform:rotate(360deg)}
}

/* Headlight — warm yellow reads on every theme */
.bp-light{
  position:absolute;bottom:26px;right:-14px;
  width:24px;height:6px;
  background:linear-gradient(90deg, rgba(255,237,100,.9), rgba(255,237,100,0));
  border-radius:4px;
  filter:blur(2px);
  animation:bp-light-pulse .9s ease-in-out infinite;
}
@keyframes bp-light-pulse{
  0%,100%{opacity:.6;transform:scaleX(1)}
  50%{opacity:1;transform:scaleX(1.2)}
}

/* Caption */
.bp-text{
  color:#fff;text-align:center;font-weight:700;
  font-size:16px;letter-spacing:.02em;margin-bottom:14px;
  text-shadow:0 2px 8px rgba(0,0,0,.25);
}
.bp-dots{
  display:inline-flex;gap:4px;margin-left:4px;vertical-align:middle;
}
.bp-dots span{
  width:6px;height:6px;border-radius:50%;background:#fff;opacity:.35;
  animation:bp-dot 1.2s ease-in-out infinite;
}
.bp-dots span:nth-child(2){animation-delay:.2s}
.bp-dots span:nth-child(3){animation-delay:.4s}
@keyframes bp-dot{
  0%,80%,100%{opacity:.35;transform:scale(1)}
  40%{opacity:1;transform:scale(1.3)}
}

/* Progress bar — track is dim white, fill is bright white */
.bp-bar{
  width:min(280px,70vw);height:4px;
  background:rgba(255,255,255,.25);border-radius:2px;
  overflow:hidden;margin-top:6px;
}
.bp-bar > div{
  height:100%;width:0%;
  background:linear-gradient(90deg, rgba(255,255,255,.55) 0%, #fff 100%);
  border-radius:2px;
  transition:width .4s ease;
}

/* Lock page scroll while visible */
body.bp-active{overflow:hidden}

/* ============================================================
   MIDNIGHT theme refinement
   The base --grad-brand on midnight is a mid-purple. Dial it
   darker so the white bus pops and the whole thing feels like
   a proper dark-mode loading screen.
   ============================================================ */
[data-theme="midnight"] .bus-preloader{
  background: linear-gradient(135deg, #0b1020 0%, #1e1b4b 55%, #312e81 100%);
}
[data-theme="midnight"] .bus-preloader::before{
  background:
    radial-gradient(circle at 20% 30%, rgba(129,140,248,.22), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(139,92,246,.18), transparent 55%);
}

/* Small screens — scale the whole scene */
@media (max-width:420px){
  .bp-stage{width:280px;height:100px}
  .bp-body{width:150px;height:54px}
  .bp-windows span{height:18px}
  .bp-wheel{width:18px;height:18px}
  .bp-text{font-size:14px}
}