/* 枝间 — ambient forest scene, paper grain and slow-moving leaves. */

:root {
  --forest-day: url("./brand/forest-day.svg");
  --forest-night: url("./brand/forest-night.svg");
}

#forest-ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}

.forest-canopy {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 82% -8%, rgba(229, 182, 107, .20), transparent 42%),
    radial-gradient(ellipse at 4% 18%, rgba(63, 125, 92, .14), transparent 42%),
    var(--forest-day) center / cover no-repeat;
  opacity: .9;
}

.forest-canopy::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: linear-gradient(112deg, transparent 28%, rgba(255, 247, 218, .20) 38%, rgba(255, 247, 218, .06) 44%, transparent 52%);
  filter: blur(8px);
  mix-blend-mode: screen;
  animation: forestSun 18s ease-in-out infinite alternate;
}

.forest-mist {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 48% 104%, rgba(63, 125, 92, .22), transparent 52%),
    linear-gradient(180deg, rgba(247, 243, 232, .38), transparent 24%, transparent 78%, rgba(247, 243, 232, .42));
}

.forest-grain {
  position: absolute;
  inset: 0;
  opacity: .16;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

.forest-leaf {
  position: absolute;
  top: -8vh;
  width: 12px;
  height: 7px;
  border-radius: 80% 10% 80% 10%;
  background: linear-gradient(135deg, #7d9b76, #c7b07a);
  opacity: var(--leaf-opacity, .2);
  transform: rotate(var(--leaf-rotate, 30deg));
  filter: blur(.2px);
  animation: forestLeaf var(--leaf-duration, 30s) linear infinite;
  animation-delay: var(--leaf-delay, -8s);
}

@keyframes forestSun {
  from { transform: translate3d(-2%, -1%, 0) rotate(-2deg); opacity: .7; }
  to { transform: translate3d(2%, 1%, 0) rotate(2deg); opacity: 1; }
}

@keyframes forestLeaf {
  0% { transform: translate3d(0, 0, 0) rotate(var(--leaf-rotate, 30deg)); }
  50% { transform: translate3d(var(--leaf-drift, 40px), 50vh, 0) rotate(calc(var(--leaf-rotate, 30deg) + 180deg)); }
  100% { transform: translate3d(calc(var(--leaf-drift, 40px) * -.4), 112vh, 0) rotate(calc(var(--leaf-rotate, 30deg) + 360deg)); }
}

html[data-theme="dark"] .forest-canopy {
  background:
    radial-gradient(ellipse at 82% -8%, rgba(217, 164, 65, .10), transparent 42%),
    radial-gradient(ellipse at 4% 18%, rgba(143, 190, 159, .10), transparent 42%),
    var(--forest-night) center / cover no-repeat;
}

html[data-theme="dark"] .forest-mist {
  background:
    radial-gradient(ellipse at 48% 104%, rgba(47, 107, 85, .22), transparent 52%),
    linear-gradient(180deg, rgba(14, 26, 21, .44), transparent 26%, transparent 74%, rgba(14, 26, 21, .60));
}

html[data-theme="dark"] .forest-grain { opacity: .10; mix-blend-mode: screen; }

/* Keep the application above the ambient layer without changing its layout. */
.home-shell,
.auth-page {
  position: relative;
  z-index: 1;
}

#view-login,
#view-home,
#view-editor {
  z-index: 1;
}

/* Paper-copy atmosphere inside the editor map. */
.map-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(112deg, transparent 30%, rgba(255, 248, 224, .14) 41%, transparent 54%),
    var(--forest-day) center / cover no-repeat;
  opacity: .72;
}

.map-stage #map { position: relative; z-index: 1; }

html[data-theme="dark"] .map-stage::before {
  background:
    linear-gradient(112deg, transparent 30%, rgba(217, 164, 65, .055) 41%, transparent 54%),
    var(--forest-night) center / cover no-repeat;
  opacity: .76;
}

/* The left-hand login illustration gets a subtle canopy of its own. */
.auth-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--forest-night) center / cover no-repeat;
  opacity: .18;
  mix-blend-mode: screen;
}

.auth-visual > * { position: relative; z-index: 1; }

.map-stage .map-container { background: transparent !important; }

@media (prefers-reduced-motion: reduce) {
  .forest-leaf,
  .forest-canopy::after { animation: none; }
  .forest-leaf { opacity: .08; }
}
