/* ============================================
   BipbipDynamicScene v5 — Premium 16:9 Edition
   GPU-only, battery-friendly, edge-blended
   ============================================ */

/* ── CONTAINER — fondu rectangulaire doux, comme la ref ── */
.bds-container {
  --bds-page-bg: #0f172a;
  --bds-page-rgb: 15, 23, 42;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 300px;
  overflow: hidden;
  border-radius: 18px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  contain: layout style paint;
  background: transparent;
  transform: translateZ(0);
  -webkit-mask-image:
    linear-gradient(to right, transparent, black 10%, black 90%, transparent),
    linear-gradient(to bottom, transparent, black 6%, black 65%, transparent);
  -webkit-mask-composite: destination-in;
  mask-image:
    linear-gradient(to right, transparent, black 10%, black 90%, transparent),
    linear-gradient(to bottom, transparent, black 6%, black 65%, transparent);
  mask-composite: intersect;
}

/* Pas de pseudo-élément overlay — le mask-image gère tout */
.bds-container::after {
  display: none;
}

/* ── SCENE LAYERS (crossfade backgrounds) ── */
.bds-scene-layer {
  position: absolute;
  inset: -6px;
  background-size: cover;
  background-position: center 38%;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 2.5s ease;
  will-change: opacity, transform;
}
.bds-scene-layer--active {
 opacity: 1;
 transition: opacity 2.5s ease, transform 0.3s ease-out;
}

/* ── FORCE TRANSPARENCY FOR SCENE OVERLAY IMAGES ── */
.scene-overlay img { background: transparent !important; }
.scene-main-content img { background: transparent !important; }
.bds-container img { background: transparent !important; }

.bds-scene-day { background-image: url('assets/scene-day1.jpg'); z-index: 2; }
.bds-scene-sunset { background-image: url('assets/scene-sunset2.jpg'); z-index: 3; }
.bds-scene-night  { background-image: url('assets/scene-night2.jpg'); z-index: 4; }

/* ── CHARACTER (girl with coffee) ── */
.bds-character {
  position: absolute;
  bottom: 0;
  left: 4%;
  width: 80px;
  height: auto;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(0, 10px, 0);
  transition: opacity 1.5s ease, transform 1.5s ease;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
  image-rendering: auto;
}
.bds-character--visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}
.bds-character--idle {
  animation: bds-breathe 4s ease-in-out infinite;
}

@keyframes bds-breathe {
  0%, 100% { transform: translate3d(0, 0, 0) scaleY(1); }
  50% { transform: translate3d(0, -2px, 0) scaleY(1.008); }
}

/* ── LENS FLARE (day sun glow) ── */
.bds-lens-flare {
  position: absolute;
  top: 6%;
  right: 18%;
  width: 100px;
  height: 100px;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2s ease;
  background: radial-gradient(circle,
    rgba(255,255,220,0.35) 0%,
    rgba(255,200,50,0.12) 30%,
    transparent 70%);
  animation: bds-flarePulse 8s ease-in-out infinite;
}
.bds-lens-flare--visible { opacity: 1; }

.bds-lens-flare::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -50px;
  right: -50px;
  height: 1.5px;
  background: linear-gradient(90deg,
    transparent,
    rgba(255,220,100,0.25) 30%,
    rgba(255,255,200,0.4) 50%,
    rgba(255,220,100,0.25) 70%,
    transparent);
  transform: translateY(-50%);
}

@keyframes bds-flarePulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* ── SHOOTING STARS (night) ── */
.bds-shooting-stars {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 2s ease;
}
.bds-shooting-stars--visible { opacity: 1; }

.bds-shooting-star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  opacity: 0;
}
.bds-shooting-star::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 45px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6));
  transform-origin: right center;
  transform: rotate(-35deg);
}

.bds-shooting-star--1 { animation: bds-shoot 9s ease-in-out infinite 3s; }
.bds-shooting-star--2 { animation: bds-shoot 13s ease-in-out infinite 7s; }

@keyframes bds-shoot {
  0%  { opacity: 0; transform: translate3d(0, 0, 0); }
  2%  { opacity: 1; }
  8%  { opacity: 0; transform: translate3d(-160px, 90px, 0); }
  100%{ opacity: 0; transform: translate3d(-160px, 90px, 0); }
}

/* ── DUST PARTICLES (day — golden dust) ── */
.bds-particles {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 2s ease;
}
.bds-particles--visible { opacity: 1; }

.bds-particle {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 220, 120, 0.6);
  animation: bds-float var(--dur) ease-in-out infinite var(--delay);
}

@keyframes bds-float {
  0%   { transform: translate3d(0, 0, 0) scale(0.5); opacity: 0; }
  25%  { opacity: 0.7; }
  50%  { transform: translate3d(var(--dx), var(--dy), 0) scale(1); opacity: 0.5; }
  100% { transform: translate3d(calc(var(--dx) * 2), calc(var(--dy) * 0.5), 0) scale(0.3); opacity: 0; }
}

/* ── FIREFLIES (sunset) ── */
.bds-fireflies {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 2s ease;
}
.bds-fireflies--visible { opacity: 1; }

.bds-firefly {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe082 25%, rgba(255,224,130,0) 70%);
  animation: bds-fireflyMove var(--dur) ease-in-out infinite var(--delay);
}

@keyframes bds-fireflyMove {
  0%   { transform: translate3d(0, 0, 0); opacity: 0; }
  15%  { opacity: 1; }
  50%  { transform: translate3d(var(--fx), var(--fy), 0); opacity: 0.7; }
  85%  { opacity: 0.9; }
  100% { transform: translate3d(calc(var(--fx) * -0.5), calc(var(--fy) * 0.3), 0); opacity: 0; }
}

/* ── AURORA (night — very subtle) ── */
.bds-aurora {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 3s ease;
  overflow: hidden;
}
.bds-aurora--visible { opacity: 1; }

.bds-aurora-wave {
  position: absolute;
  width: 200%;
  height: 100%;
  left: -50%;
  background: linear-gradient(180deg,
    transparent 0%,
    rgba(80,200,120,0.05) 20%,
    rgba(60,140,220,0.06) 40%,
    rgba(120,80,220,0.04) 60%,
    transparent 80%);
  animation: bds-auroraWave 16s ease-in-out infinite;
}
.bds-aurora-wave:nth-child(2) {
  animation-delay: -6s;
  animation-duration: 20s;
  opacity: 0.6;
}

@keyframes bds-auroraWave {
  0%, 100% { transform: translate3d(-10%, 0, 0) scaleY(0.8); }
  50% { transform: translate3d(10%, -5%, 0) scaleY(1.15); }
}

/* ── STARS (opacity-only = cheap) ── */
.bds-stars {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2s ease;
  contain: layout style paint;
}
.bds-stars--visible { opacity: 1; }

.bds-star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  animation: bds-twinkle var(--dur) ease-in-out infinite var(--delay);
}
.bds-star--big {
  width: 3px;
  height: 3px;
  background: radial-gradient(circle, #fff 40%, rgba(255,255,255,0) 70%);
}

@keyframes bds-twinkle {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 1; }
}

/* ── CLOUDS (transform-only = GPU) ── */
.bds-clouds {
  position: absolute;
  inset: 0;
  z-index: 7;
  overflow: hidden;
  pointer-events: none;
  contain: layout style paint;
}

.bds-cloud {
  position: absolute;
  border-radius: 50px;
  background: rgba(255,255,255,0.5);
  transition: background 2s ease;
}
.bds-cloud::before,
.bds-cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.bds-cloud--1 {
  width: 80px; height: 24px;
  top: 8%;
  animation: bds-cloudMove 60s linear infinite;
}
.bds-cloud--1::before { width: 36px; height: 36px; top: -16px; left: 14px; }
.bds-cloud--1::after  { width: 24px; height: 24px; top: -10px; left: 42px; }

.bds-cloud--2 {
  width: 60px; height: 18px;
  top: 16%;
  animation: bds-cloudMove 75s linear infinite -30s;
  opacity: 0.4;
}
.bds-cloud--2::before { width: 26px; height: 26px; top: -12px; left: 8px; }
.bds-cloud--2::after  { width: 18px; height: 18px; top: -8px; left: 30px; }

.bds-container[data-phase="night"] .bds-cloud  { background: rgba(50,60,100,0.3); }
.bds-container[data-phase="sunset"] .bds-cloud { background: rgba(255,170,120,0.4); }

@keyframes bds-cloudMove {
  from { transform: translate3d(-130px, 0, 0); }
  to   { transform: translate3d(calc(100vw + 130px), 0, 0); }
}

/* ── BIRDS (fly across sky at specific hours) ── */
.bds-birds {
  position: absolute;
  inset: 0;
  z-index: 7;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.5s ease;
}
.bds-birds--visible { opacity: 1; }

.bds-bird {
  position: absolute;
  left: -30px;
  width: 18px;
  height: 6px;
  transform: scale(var(--scale, 1));
  animation: bds-birdFly var(--dur) linear infinite var(--delay);
}
/* Bird shape: two flapping wings using pseudo-elements */
.bds-bird::before,
.bds-bird::after {
  content: '';
  position: absolute;
  top: 0;
  width: 9px;
  height: 2px;
  background: rgba(30, 30, 50, 0.7);
  border-radius: 1px;
  transform-origin: center bottom;
  animation: bds-birdFlap 0.4s ease-in-out infinite alternate;
}
.bds-bird::before {
  left: 0;
  transform: rotate(-25deg);
}
.bds-bird::after {
  right: 0;
  transform: rotate(25deg);
  animation-delay: 0.1s;
}

/* Lighter birds at night */
.bds-container[data-phase="night"] .bds-bird::before,
.bds-container[data-phase="night"] .bds-bird::after {
  background: rgba(180, 190, 220, 0.5);
}
.bds-container[data-phase="sunset"] .bds-bird::before,
.bds-container[data-phase="sunset"] .bds-bird::after {
  background: rgba(60, 30, 20, 0.6);
}

@keyframes bds-birdFly {
  0%   { transform: translate3d(0, 0, 0) scale(var(--scale, 1)); opacity: 0; }
  5%   { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translate3d(calc(100vw + 60px), var(--y), 0) scale(var(--scale, 1)); opacity: 0; }
}

@keyframes bds-birdFlap {
  0%   { transform: rotate(-25deg); }
  100% { transform: rotate(25deg); }
}

/* ── RAIN (transform-only = GPU) ── */
.bds-rain {
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
  contain: layout style paint;
}
.bds-rain--active { opacity: 1; }

.bds-raindrop {
  position: absolute;
  width: 1px;
  height: 12px;
  background: rgba(174,194,224,0.45);
  animation: bds-rainFall var(--dur) linear infinite var(--delay);
  left: var(--x);
}

@keyframes bds-rainFall {
  from { transform: translate3d(0, -20px, 0); }
  to   { transform: translate3d(-6px, 280px, 0); }
}

/* ── NIGHT GLOW (city warmth) ── */
.bds-night-glow {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 45%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2s ease;
  background: linear-gradient(180deg, transparent 0%, rgba(255,150,30,0.05) 100%);
}
.bds-night-glow--active { opacity: 1; }

/* ── CITY LIGHT DOTS ── */
.bds-light-dots {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2s ease;
  contain: layout style paint;
}
.bds-light-dots--visible { opacity: 1; }

.bds-light-dot {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #ffd54f;
  animation: bds-lightFlicker 4s ease-in-out infinite var(--delay);
}

@keyframes bds-lightFlicker {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ── SHIMMER (premium gloss — one-shot) ── */
.bds-shimmer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.bds-shimmer--active { opacity: 0.35; }
.bds-shimmer::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(105deg,
    transparent 40%,
    rgba(255,255,255,0.04) 45%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 55%,
    transparent 60%);
  animation: bds-shimmerMove 1.5s ease-in-out forwards;
}

@keyframes bds-shimmerMove {
  0%   { transform: translate3d(-40%, -40%, 0) rotate(25deg); }
  100% { transform: translate3d(40%, 40%, 0) rotate(25deg); }
}

/* ── PREMIUM GLOW RING — désactivé, le mask-image gère le fondu ── */
.bds-glow-ring {
  display: none;
}

/* ── TRIGGER BADGE ── */
.bds-trigger-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(0, -6px, 0);
  transition: opacity 0.5s ease, transform 0.5s ease;
  font-family: 'Inter', sans-serif;
}
.bds-trigger-badge--visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}
.bds-trigger-badge--morning {
  background: linear-gradient(135deg, rgba(246,211,101,0.9), rgba(253,160,133,0.9));
  color: #5a3200;
}
.bds-trigger-badge--evening {
  background: linear-gradient(135deg, rgba(161,140,209,0.9), rgba(251,194,235,0.9));
  color: #3d1a5c;
}
.bds-trigger-badge--night {
  background: rgba(20,30,60,0.85);
  color: #a0b4e0;
  border: 1px solid rgba(160,180,224,0.15);
}

/* ── VIGNETTE — légère, le mask gère l'essentiel ── */
.bds-vignette {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  box-shadow: inset 0 0 40px 15px rgba(var(--bds-page-rgb), 0.2);
  border-radius: inherit;
}

/* ── TIME PILL ── */
.bds-time {
  position: absolute;
  bottom: 8px;
  left: 10px;
  z-index: 20;
  font-family: 'Inter', monospace;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  pointer-events: none;
  background: rgba(0,0,0,0.35);
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}

/* ── LOW-END DEVICE OVERRIDES ── */
.bds-container[data-perf="low"] .bds-shimmer,
.bds-container[data-perf="low"] .bds-aurora,
.bds-container[data-perf="low"] .bds-lens-flare,
.bds-container[data-perf="low"] .bds-particles,
.bds-container[data-perf="low"] .bds-glow-ring { display: none; }
.bds-container[data-perf="low"] .bds-firefly { width: 4px; height: 4px; }
.bds-container[data-perf="low"] .bds-vignette { box-shadow: none; }
.bds-container[data-perf="low"] .bds-character { animation: none !important; }

/* Masques CSS + grosses transitions = coûteux sur GPU intégré faible */
.bds-container[data-perf="low"] {
  mask-image: none !important;
  -webkit-mask-image: none !important;
  mask-composite: unset;
  -webkit-mask-composite: unset;
  contain: layout style;
}
.bds-container[data-perf="low"] .bds-scene-layer {
  transition: opacity 1s ease !important;
  will-change: auto;
}
.bds-container[data-perf="low"] .bds-scene-layer--active {
  transition: opacity 1s ease, transform 0.25s ease-out !important;
  will-change: auto;
}
.bds-container[data-perf="low"] .bds-star {
  animation: none !important;
  opacity: 0.5;
}
.bds-container[data-perf="low"] .bds-cloud {
  animation: none !important;
  opacity: 0.3;
  transform: translate3d(12vw, 0, 0);
}
.bds-container[data-perf="low"] .bds-birds {
  display: none !important;
}
.bds-container[data-perf="low"] .bds-light-dot {
  animation: none !important;
  opacity: 0.6;
}
.bds-container[data-perf="low"] .bds-shooting-stars {
  display: none !important;
}

/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  .bds-star, .bds-cloud, .bds-raindrop, .bds-light-dot,
  .bds-shooting-star, .bds-particle, .bds-firefly,
  .bds-aurora-wave, .bds-shimmer::after, .bds-character,
  .bds-bird, .bds-bird::before, .bds-bird::after { animation: none !important; }
  .bds-scene-layer,
  .bds-scene-layer--active { transition: opacity 0.45s ease !important; }
  .bds-star { opacity: 0.6; }
  .bds-light-dot { opacity: 0.7; }
  .bds-container {
    mask-image: none !important;
    -webkit-mask-image: none !important;
  }
}

/* ── RESPONSIVE ── */
@media (max-width: 360px) {
  .bds-container { max-height: 220px; }
  .bds-character { width: 60px; }
  .bds-lens-flare { width: 70px; height: 70px; }
}
@media (min-width: 768px) {
  .bds-container { max-height: 400px; }
  .bds-character { width: 100px; }
}
@media (min-width: 1024px) {
  .bds-container { max-height: 480px; }
  .bds-character { width: 120px; }
}
