/* ══════════════════════════════════════════════════════
   THE FOREST — this land, c. 1500
   White oak · shagbark hickory · American beech
   + the Then/Now era slider
   Trees are generated by js/forest.js; this file owns layout,
   the day/twilight/night palettes, sway, fireflies, and the slider.
   ══════════════════════════════════════════════════════ */

:root { --era: 1; }   /* 1 = now (present day) · 0 = then (c. 1500) */

/* ── Era crossfade ── */

#neighborhood {
  opacity: var(--era);
  transition: opacity 0.5s ease, visibility 0.5s;
}
#neighborhood.off { visibility: hidden; }
#neighborhood.inactive * { pointer-events: none !important; }

#forest {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: min(52vh, 470px);
  z-index: 14;
  pointer-events: none;
  overflow: hidden;
  opacity: calc(1 - var(--era));
  transform: translateY(calc(var(--era) * 28px));
  transition: opacity 0.5s ease, transform 0.5s ease, visibility 0.5s;
}
#forest.off { visibility: hidden; }

@media (max-width: 600px) {
  #forest { height: min(44vh, 340px); }
}

/* ── Stand structure ── */

.forest-band { position: absolute; inset: 0; }
.band-back { opacity: 0.6; }
.band-mid  { opacity: 0.85; }

.tree {
  position: absolute;
  bottom: -2px;
  width: 0;
}

.tree svg {
  display: block;
  height: 100%;
  width: auto;
  overflow: visible;
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  animation: tree-sway var(--dur, 11s) ease-in-out var(--delay, 0s) infinite alternate;
}

@keyframes tree-sway {
  from { transform: translateX(-50%) rotate(calc(var(--amp, 0.3deg) * -1)); }
  to   { transform: translateX(-50%) rotate(var(--amp, 0.3deg)); }
}

.forest-floor {
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 30px;
}
.floor-svg { display: block; width: 100%; height: 100%; }
.floor-path { fill: var(--floor); transition: fill 3s ease; }

/* ── Species color routing (shared by forest and street trees) ── */

.sp-oak {
  --c-f1: var(--oak-f1); --c-f2: var(--oak-f2); --c-f3: var(--oak-f3);
  --c-trunk: var(--oak-tr); --c-bark: var(--oak-bk); --c-op: var(--oak-op, 1);
}
.sp-hick {
  --c-f1: var(--hick-f1); --c-f2: var(--hick-f2); --c-f3: var(--hick-f3);
  --c-trunk: var(--hick-tr); --c-bark: var(--hick-bk); --c-op: var(--hick-op, 1);
}
.sp-beech {
  --c-f1: var(--beech-f1); --c-f2: var(--beech-f2); --c-f3: var(--beech-f3);
  --c-trunk: var(--beech-tr); --c-bark: var(--beech-bk); --c-op: var(--beech-op, 1);
}

.tree .t-trunk { fill: var(--c-trunk); transition: fill 3s ease; }
.tree .t-limb  { stroke: var(--c-trunk); transition: stroke 3s ease; }
.tree .t-bark  { stroke: var(--c-bark); transition: stroke 3s ease; }
.tree .foliage { opacity: var(--c-op); transition: opacity 3s ease; }
.tree .f1 { fill: var(--c-f1); transition: fill 3s ease; }
.tree .f2 { fill: var(--c-f2); transition: fill 3s ease; }
.tree .f3 { fill: var(--c-f3); transition: fill 3s ease; }

/* ── Night (default) — moonlit silhouettes; beech bark catches the light ── */
#forest,
#neighborhood {
  --oak-f1: #0a0f0b;   --oak-f2: #0d120d;   --oak-f3: #111710;
  --oak-tr: #090b0a;   --oak-bk: #12100d;
  --hick-f1: #0a0f0b;  --hick-f2: #0c110c;  --hick-f3: #101609;
  --hick-tr: #0a0c0a;  --hick-bk: #16130f;
  --beech-f1: #0b100c; --beech-f2: #0e130e; --beech-f3: #121811;
  --beech-tr: #171a19; --beech-bk: #0d0f10;
  --floor: #080b08;
}

/* ── Twilight — a hint of color returns ── */
#forest.twilight,
#neighborhood.twilight {
  --oak-f1: #131810;   --oak-f2: #171d12;   --oak-f3: #1e2416;
  --oak-tr: #120f0a;   --oak-bk: #1c1812;
  --hick-f1: #12170f;  --hick-f2: #161c11;  --hick-f3: #1c2314;
  --hick-tr: #130f0a;  --hick-bk: #1e1913;
  --beech-f1: #141910; --beech-f2: #181e13; --beech-f3: #1f2617;
  --beech-tr: #2a2b28; --beech-bk: #1a1c1a;
  --floor: #10130c;
}

/* ── Daylight — full seasonal palette, provided by forest.js ── */
#forest.daylight,
#neighborhood.daylight {
  --oak-f1: var(--s-oak-f1);     --oak-f2: var(--s-oak-f2);     --oak-f3: var(--s-oak-f3);
  --oak-tr: var(--s-oak-tr);     --oak-bk: var(--s-oak-bk);
  --hick-f1: var(--s-hick-f1);   --hick-f2: var(--s-hick-f2);   --hick-f3: var(--s-hick-f3);
  --hick-tr: var(--s-hick-tr);   --hick-bk: var(--s-hick-bk);
  --beech-f1: var(--s-beech-f1); --beech-f2: var(--s-beech-f2); --beech-f3: var(--s-beech-f3);
  --beech-tr: var(--s-beech-tr); --beech-bk: var(--s-beech-bk);
  --floor: var(--s-floor);
}

/* ── Modern-era street trees — behind the buildings, above the grass ── */

.street-trees {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.street-trees .tree { bottom: 8px; }

/* ── Fireflies — June–September nights ── */

.fireflies { position: absolute; inset: 0; }
#forest.daylight .fireflies,
#forest.twilight .fireflies { display: none; }

.firefly {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #e4f288;
  box-shadow: 0 0 6px 2px rgba(214, 232, 110, 0.45);
  opacity: 0;
  animation:
    firefly-drift var(--fdur, 12s) ease-in-out var(--fdelay, 0s) infinite alternate,
    firefly-blink var(--bdur, 4s) ease-in-out var(--fdelay, 0s) infinite;
}

@keyframes firefly-drift {
  from { transform: translate(0, 0); }
  to   { transform: translate(var(--dx, 30px), var(--dy, -20px)); }
}

@keyframes firefly-blink {
  0%, 38%, 62%, 100% { opacity: 0; }
  46%, 54% { opacity: 0.9; }
}

/* ══════════════════════════════════════════════════════
   THEN / NOW — era slider
   ══════════════════════════════════════════════════════ */

.era-control {
  position: fixed;
  right: 1.4rem;
  bottom: 1.15rem;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-family: 'Fraunces', serif;
}

.era-year {
  position: absolute;
  top: -1.15rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-style: italic;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.era-control:hover .era-year,
.era-control:focus-within .era-year { opacity: 1; }

.era-label {
  background: none;
  border: none;
  padding: 0.25rem 0;
  font-family: inherit;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(200, 195, 180, 0.55);
  text-shadow: 0 1px 3px rgba(10, 12, 18, 0.5);
  cursor: pointer;
  transition: color 0.4s ease;
}
.era-label:hover,
.era-label.active { color: var(--text-soft); }

.era-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 108px;
  height: 16px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.era-slider::-webkit-slider-runnable-track {
  height: 1px;
  background: rgba(200, 195, 180, 0.35);
}
.era-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px;
  height: 9px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--lunar-gold);
  box-shadow: 0 0 6px rgba(196, 169, 106, 0.55);
}
.era-slider::-moz-range-track {
  height: 1px;
  background: rgba(200, 195, 180, 0.35);
}
.era-slider::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: none;
  border-radius: 50%;
  background: var(--lunar-gold);
  box-shadow: 0 0 6px rgba(196, 169, 106, 0.55);
}
.era-slider:focus-visible {
  outline: 1px solid rgba(218, 175, 88, 0.4);
  outline-offset: 3px;
}

@media (max-width: 600px) {
  .era-control { right: 0.75rem; bottom: 0.85rem; gap: 0.5rem; }
  .era-slider { width: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  .tree svg { animation: none; }
  .firefly { animation: none; opacity: 0.4; }
}
