/* ============================================
   Rain cinema — living still + weather FX
   ============================================ */

:root {
  --cinema-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

body.has-cinema {
  background: #000;
}

body.has-cinema::before,
body.has-cinema::after {
  display: none;
}

.rain-cinema {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background: #000;
  isolation: isolate;
}

.rain-bloom {
  position: absolute;
  inset: -18%;
  background:
    center / cover no-repeat url('../assets/cinema/ferrari-rain.jpg');
  filter: blur(52px) saturate(1.35) brightness(0.38);
  transform: scale(1.08);
  opacity: 0.9;
}

@media (min-width: 769px) {
  .rain-bloom {
    background-image: url('../assets/cinema/ferrari-rain-wide.jpg');
  }
}

.rain-camera {
  position: absolute;
  inset: 0;
  transform-origin: 58% 62%;
  will-change: transform;
}

.rain-camera picture {
  position: absolute;
  inset: 0;
  display: block;
}

@media (min-width: 769px) {
  .rain-camera {
    transform-origin: 64% 68%;
  }
}

.rain-still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 58%;
  display: block;
  filter: contrast(1.08) saturate(1.12) brightness(0.92);
  transition: opacity 0.8s var(--cinema-ease);
}

.rain-drive {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 55% 62%;
  display: block;
  opacity: 1;
  background: #000;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.rain-drive::-webkit-media-controls,
.rain-drive::-webkit-media-controls-enclosure,
.rain-drive::-webkit-media-controls-start-playback-button,
.rain-drive::-webkit-media-controls-overlay-play-button {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.rain-cinema.is-driving .rain-still,
.rain-cinema.is-driving .rain-camera picture {
  opacity: 0;
}

.rain-cinema.is-driving .rain-bloom {
  visibility: hidden;
  opacity: 0;
}

@media (min-width: 769px) {
  .rain-still {
    object-position: 62% 72%;
  }

  .rain-drive {
    object-position: 58% 68%;
  }
}

.rain-veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.28) 38%, rgba(0, 0, 0, 0.08) 62%, rgba(0, 0, 0, 0.35) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.42) 0%, transparent 28%, transparent 62%, rgba(0, 0, 0, 0.7) 100%);
  pointer-events: none;
}

.rain-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 78% 72% at 55% 58%, transparent 28%, rgba(0, 0, 0, 0.62) 100%);
  pointer-events: none;
  mix-blend-mode: multiply;
}

.rain-grain {
  position: absolute;
  inset: -10%;
  opacity: 0.11;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  animation: rain-grain 0.42s steps(2) infinite;
  mix-blend-mode: overlay;
}

@keyframes rain-grain {
  to { transform: translate3d(1.4%, -1.1%, 0); }
}

/* Intro camera is tighter; site framing eases out */
html.cin-playing .rain-camera,
html.cin-pending .rain-camera {
  transform-origin: 60% 64%;
}

html.cin-playing .rain-veil,
html.cin-pending .rain-veil {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.2) 0%, transparent 30%, transparent 70%, rgba(0, 0, 0, 0.45) 100%);
}

html.cin-playing .rain-vignette,
html.cin-pending .rain-vignette {
  background: radial-gradient(ellipse 70% 65% at 55% 60%, transparent 20%, rgba(0, 0, 0, 0.72) 100%);
}

/* Content stacking — reuse circuit overlay language */
body.has-cinema .header,
body.has-cinema main,
body.has-cinema .footer {
  position: relative;
  z-index: 3;
}

body.has-cinema .hero-bg,
body.has-cinema .hero-grid,
body.has-cinema .hero-glow,
body.has-cinema .page-hero-bg {
  opacity: 0 !important;
  background: transparent !important;
}

body.has-cinema .hero {
  background: transparent;
  min-height: 100vh;
}

body.has-cinema .hero-content {
  max-width: min(38rem, 52vw);
  text-shadow: 0 2px 28px rgba(0, 0, 0, 0.65);
}

body.has-cinema[data-page="home"] .rain-grain {
  animation: none;
  opacity: 0.06;
}

body.has-cinema:not([data-page="home"]) .rain-veil {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.42) 42%, rgba(0, 0, 0, 0.28) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.18) 40%, rgba(0, 0, 0, 0.72) 100%);
}

body.has-cinema:not([data-page="home"]) .rain-still,
body.has-cinema:not([data-page="home"]) .rain-drive {
  filter: contrast(1.06) saturate(1.05) brightness(0.72);
}

/* Keep cinema visible while the title sequence plays */
html.cin-pending body > .rain-cinema,
html.cin-playing body > .rain-cinema {
  opacity: 1 !important;
  visibility: visible !important;
}

@media (max-width: 768px) {
  body.has-cinema .hero-content {
    max-width: none;
  }

  body.has-cinema[data-page="home"] .hero-shell {
    align-items: flex-end;
    padding-bottom: 5.5rem;
  }

  .rain-veil {
    background:
      linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0.18) 32%, rgba(0, 0, 0, 0.55) 70%, rgba(0, 0, 0, 0.82) 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rain-grain,
  .rain-bloom {
    animation: none !important;
  }

  .rain-drive {
    display: none;
  }
}
