/* global React, sinW */
// backgrounds.jsx — full-scene background renderers per song scene.
// Each takes { t } (seconds elapsed in current song) and fills its parent.

const SCENE_W = 1920;
const SCENE_H = 1080;
const TWO_PI = Math.PI * 2;

function seeded(seed) {
  let s = seed;
  return () => { s = (s * 9301 + 49297) % 233280; return s / 233280; };
}

const sinB = (t, hz = 1, p = 0) => Math.sin(t * TWO_PI * hz + p);

// ── Reusable: SVG canvas helper ────────────────────────────────────────────
function SVGLayer({ children, style }) {
  return (
    <svg
      viewBox={`0 0 ${SCENE_W} ${SCENE_H}`}
      preserveAspectRatio="xMidYMid slice"
      style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', ...style }}
    >
      {children}
    </svg>
  );
}

// ── Stars (used by night, also as overlay) ─────────────────────────────────
const NIGHT_STARS = (() => {
  const rng = seeded(42);
  return Array.from({ length: 90 }).map(() => ({
    x: rng() * SCENE_W,
    y: rng() * (SCENE_H * 0.55),
    r: 1 + rng() * 2.4,
    twHz: 0.3 + rng() * 0.6,
    twPh: rng() * TWO_PI,
    sparkle: rng() > 0.85,
  }));
})();

function StarsLayer({ t, opacity = 1 }) {
  return (
    <SVGLayer style={{ opacity }}>
      {NIGHT_STARS.map((s, i) => {
        const tw = 0.55 + 0.45 * (0.5 + 0.5 * sinB(t, s.twHz, s.twPh));
        const r = s.r * (0.85 + 0.3 * tw);
        return (
          <g key={i} opacity={tw}>
            <circle cx={s.x} cy={s.y} r={r} fill="#FFF7E6" />
            {s.sparkle && (
              <g transform={`translate(${s.x} ${s.y}) rotate(${(t * 30) % 360}) scale(${0.6 + 0.6 * tw})`}>
                <path d="M0 -10 L1.5 -1.5 L10 0 L1.5 1.5 L0 10 L-1.5 1.5 L-10 0 L-1.5 -1.5 Z" fill="#FFD43D" />
              </g>
            )}
          </g>
        );
      })}
    </SVGLayer>
  );
}

// ── Clouds (day version + night version) ───────────────────────────────────
const CLOUDS = [
  { y: 140, scale: 1.0, speed: 14, offset: 0,    opacity: 0.85 },
  { y: 260, scale: 0.7, speed: 22, offset: 800,  opacity: 0.7 },
  { y: 360, scale: 1.3, speed: 10, offset: 1500, opacity: 0.55 },
  { y: 200, scale: 0.85, speed: 18, offset: 400, opacity: 0.78 },
  { y: 320, scale: 1.1, speed: 12, offset: 1100, opacity: 0.65 },
];

function CloudShape({ fill = '#FFF7E6', stroke = null }) {
  return (
    <g>
      {stroke && (
        <g stroke={stroke} strokeWidth="5" strokeLinejoin="round" fill={fill}>
          <ellipse cx="0" cy="0" rx="60" ry="26" />
          <ellipse cx="-38" cy="6" rx="28" ry="20" />
          <ellipse cx="36" cy="6" rx="34" ry="22" />
          <ellipse cx="14" cy="-12" rx="24" ry="18" />
        </g>
      )}
      {!stroke && (
        <g fill={fill}>
          <ellipse cx="0" cy="0" rx="60" ry="26" />
          <ellipse cx="-38" cy="6" rx="28" ry="20" />
          <ellipse cx="36" cy="6" rx="34" ry="22" />
          <ellipse cx="14" cy="-12" rx="24" ry="18" />
        </g>
      )}
    </g>
  );
}

function Clouds({ t, fill = '#FFF7E6', stroke = null, list = CLOUDS }) {
  return (
    <SVGLayer>
      {list.map((c, i) => {
        const x = ((c.offset + t * c.speed) % (SCENE_W + 400)) - 200;
        const bob = sinB(t, 0.25, i) * 6;
        return (
          <g key={i} transform={`translate(${x} ${c.y + bob}) scale(${c.scale})`} opacity={c.opacity}>
            <CloudShape fill={fill} stroke={stroke} />
          </g>
        );
      })}
    </SVGLayer>
  );
}

// ── Moon ───────────────────────────────────────────────────────────────────
function Moon({ t }) {
  const x = 1620 + sinB(t, 0.04) * 18;
  const y = 200 + sinB(t, 0.08, 1.2) * 10;
  const blink = ((t % 5) > 4.7) ? 0.08 : 1;
  return (
    <SVGLayer>
      <g transform={`translate(${x} ${y})`}>
        <circle r="160" fill="#FFD43D" opacity="0.08" />
        <circle r="120" fill="#FFD43D" opacity="0.10" />
        <circle r="95" fill="#FFD43D" opacity="0.14" />
        <circle r="90" cy="6" fill="#2A2440" opacity="0.18" />
        <circle r="90" fill="#FFF7E6" stroke="#2A2440" strokeWidth="5" />
        <circle r="78" cx="28" cy="-4" fill="#5470B8" opacity="0.18" />
        <g transform="translate(-22 -6)"><ellipse rx="6" ry={6 * blink} fill="#2A2440" /></g>
        <g transform="translate(18 -6)"><ellipse rx="6" ry={6 * blink} fill="#2A2440" /></g>
        <path d="M-18 18 Q0 32 18 18" stroke="#2A2440" strokeWidth="5" strokeLinecap="round" fill="none" />
        <circle cx="-34" cy="14" r="9" fill="#FF6FB0" opacity="0.55" />
        <circle cx="34" cy="14" r="9" fill="#FF6FB0" opacity="0.55" />
      </g>
    </SVGLayer>
  );
}

// ── Sun (day) ───────────────────────────────────────────────────────────────
function Sun({ t, x = 240, y = 220 }) {
  const dx = sinB(t, 0.06) * 10;
  return (
    <SVGLayer>
      <g transform={`translate(${x + dx} ${y})`}>
        {/* rays */}
        <g transform={`rotate(${(t * 6) % 360})`}>
          {Array.from({ length: 12 }).map((_, i) => {
            const a = (i / 12) * 360;
            return (
              <rect key={i} x="-4" y="-150" width="8" height="36" rx="3" fill="#FFD43D"
                stroke="#2A2440" strokeWidth="3" transform={`rotate(${a})`} />
            );
          })}
        </g>
        <circle r="116" fill="#FFD43D" opacity="0.18" />
        <circle r="92" fill="#FFD43D" opacity="0.32" />
        <circle r="78" fill="#FFD43D" stroke="#2A2440" strokeWidth="5" />
        {/* face */}
        <ellipse cx="-22" cy="-6" rx="6" ry="9" fill="#2A2440" />
        <ellipse cx="22" cy="-6" rx="6" ry="9" fill="#2A2440" />
        <path d="M-18 16 Q0 30 18 16" stroke="#2A2440" strokeWidth="5" strokeLinecap="round" fill="none" />
        <circle cx="-36" cy="14" r="8" fill="#FF6FB0" opacity="0.65" />
        <circle cx="36" cy="14" r="8" fill="#FF6FB0" opacity="0.65" />
      </g>
    </SVGLayer>
  );
}

// ── Hills helper (3-layer parallax) ─────────────────────────────────────────
function Hills({ t, colors, flowers = false, grass = true }) {
  const beatHz = 2;
  const b1 = sinB(t, beatHz, 0) * 3;
  const b2 = sinB(t, beatHz, 1.3) * 4;
  const b3 = sinB(t, beatHz, 2.0) * 5;
  return (
    <SVGLayer>
      <g transform={`translate(0 ${b1})`}>
        <path d={`M-50 720 C 220 580 480 660 760 620 C 1020 590 1280 660 1480 600 C 1660 560 1820 620 ${SCENE_W + 50} 600 L ${SCENE_W + 50} ${SCENE_H} L -50 ${SCENE_H} Z`}
          fill={colors[0]} stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
      </g>
      <g transform={`translate(0 ${b2})`}>
        <path d={`M-50 820 C 280 700 580 800 880 760 C 1140 730 1380 800 1640 770 C 1780 755 1900 780 ${SCENE_W + 50} 770 L ${SCENE_W + 50} ${SCENE_H} L -50 ${SCENE_H} Z`}
          fill={colors[1]} stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
        {flowers && [160, 380, 720, 1040, 1360, 1540, 1720].map((x, i) => (
          <g key={i} transform={`translate(${x} 800)`}>
            <line x1="0" y1="0" x2="0" y2="14" stroke="#2A8C3A" strokeWidth="3" strokeLinecap="round" />
            <circle r="6" fill={i % 3 === 0 ? '#FF6FB0' : i % 3 === 1 ? '#FFD43D' : '#FFFFFF'} stroke="#2A2440" strokeWidth="2.5" />
          </g>
        ))}
      </g>
      <g transform={`translate(0 ${b3})`}>
        <path d={`M-50 920 C 320 860 660 920 980 890 C 1280 866 1500 900 1740 880 C 1840 870 1900 880 ${SCENE_W + 50} 880 L ${SCENE_W + 50} ${SCENE_H} L -50 ${SCENE_H} Z`}
          fill={colors[2]} stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
        {grass && Array.from({ length: 26 }).map((_, i) => {
          const x = 40 + i * 75 + sinB(t + i, 0.4, i) * 3;
          const sway = sinB(t, 1, i * 0.3) * 4;
          return (
            <g key={i} transform={`translate(${x} 900) rotate(${sway})`}>
              <path d="M0 0 Q-3 -14 -6 -18 M0 0 Q0 -16 0 -22 M0 0 Q3 -14 6 -18"
                stroke="#5DCB6E" strokeWidth="3" strokeLinecap="round" fill="none" />
            </g>
          );
        })}
      </g>
    </SVGLayer>
  );
}

// ── Background: NIGHT ──────────────────────────────────────────────────────
function NightBackground({ t }) {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(to bottom, #1A2255 0%, #2A3A78 35%, #5470B8 70%, #A5BFE8 100%)',
      }} />
      <div style={{
        position: 'absolute', inset: 0,
        background: `radial-gradient(ellipse 60% 40% at ${30 + sinB(t, 0.05) * 6}% 30%, rgba(93,203,110,0.10), transparent 60%),
                     radial-gradient(ellipse 50% 35% at ${72 + sinB(t, 0.04, 1) * 6}% 22%, rgba(255,111,176,0.10), transparent 60%)`,
      }} />
      <StarsLayer t={t} />
      <Moon t={t} />
      <Clouds t={t} fill="#FFF7E6" />
      <Hills t={t} colors={['#3A5090', '#2A3F78', '#1F2F60']} flowers={false} grass={false} />
    </div>
  );
}

// ── Background: MEADOW (day, sunny field) ──────────────────────────────────
function MeadowBackground({ t }) {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(to bottom, #4FB8FF 0%, #87D0FF 40%, #D9F0FF 75%, #FFF2B8 100%)',
      }} />
      <Sun t={t} />
      <Clouds t={t} fill="#FFFFFF" stroke="#2A2440" />
      <Hills t={t} colors={['#6BD17B', '#5DCB6E', '#3FA850']} flowers={true} grass={true} />
      {/* butterflies */}
      <SVGLayer>
        {[0, 1, 2].map(i => {
          const x = 200 + i * 500 + sinB(t, 0.2, i) * 200;
          const y = 400 + sinB(t, 0.4, i * 0.8) * 60;
          const flap = sinB(t, 5, i) * 0.5 + 0.5;
          const colors = ['#FF6FB0', '#FFD43D', '#4FB8FF'];
          return (
            <g key={i} transform={`translate(${x} ${y})`}>
              <ellipse cx="-12" cy="0" rx={12 * flap} ry="16" fill={colors[i]} stroke="#2A2440" strokeWidth="2.5" />
              <ellipse cx="12" cy="0" rx={12 * flap} ry="16" fill={colors[i]} stroke="#2A2440" strokeWidth="2.5" />
              <ellipse cx="0" cy="0" rx="3" ry="10" fill="#2A2440" />
            </g>
          );
        })}
      </SVGLayer>
    </div>
  );
}

// ── Background: FARM (meadow + red barn) ──────────────────────────────────
function FarmBackground({ t }) {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(to bottom, #4FB8FF 0%, #87D0FF 40%, #D9F0FF 78%, #FFE6A8 100%)',
      }} />
      <Sun t={t} x={300} y={200} />
      <Clouds t={t} fill="#FFFFFF" stroke="#2A2440" />
      {/* Far hill */}
      <SVGLayer>
        <path d={`M-50 720 C 220 580 480 660 760 620 C 1020 590 1280 660 1480 600 C 1660 560 1820 620 ${SCENE_W + 50} 600 L ${SCENE_W + 50} ${SCENE_H} L -50 ${SCENE_H} Z`}
          fill="#6BD17B" stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
        {/* Red barn */}
        <g transform="translate(1380 510)">
          <rect x="-60" y="0" width="120" height="100" fill="#FF5252" stroke="#2A2440" strokeWidth="5" />
          <path d="M-72 0 L0 -50 L72 0 Z" fill="#C53030" stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
          <rect x="-20" y="40" width="40" height="60" fill="#2A2440" />
          <rect x="-50" y="20" width="22" height="22" fill="#FFD43D" stroke="#2A2440" strokeWidth="3" />
          <rect x="28" y="20" width="22" height="22" fill="#FFD43D" stroke="#2A2440" strokeWidth="3" />
          <line x1="-50" y1="31" x2="-28" y2="31" stroke="#2A2440" strokeWidth="2" />
          <line x1="-39" y1="20" x2="-39" y2="42" stroke="#2A2440" strokeWidth="2" />
          <line x1="28" y1="31" x2="50" y2="31" stroke="#2A2440" strokeWidth="2" />
          <line x1="39" y1="20" x2="39" y2="42" stroke="#2A2440" strokeWidth="2" />
          {/* Windmill on top */}
          <g transform={`translate(-40 -78) rotate(${(t * 50) % 360})`}>
            <line x1="0" y1="-22" x2="0" y2="22" stroke="#2A2440" strokeWidth="4" strokeLinecap="round" />
            <line x1="-22" y1="0" x2="22" y2="0" stroke="#2A2440" strokeWidth="4" strokeLinecap="round" />
          </g>
        </g>
        {/* Picket fence */}
        {Array.from({ length: 14 }).map((_, i) => (
          <g key={i} transform={`translate(${100 + i * 80} 760)`}>
            <rect x="-4" y="0" width="8" height="50" fill="#FFF7E6" stroke="#2A2440" strokeWidth="3" />
            <path d="M-6 0 L0 -8 L6 0 Z" fill="#FFF7E6" stroke="#2A2440" strokeWidth="3" strokeLinejoin="round" />
          </g>
        ))}
        <line x1="80" y1="780" x2="1240" y2="780" stroke="#2A2440" strokeWidth="3" />
      </SVGLayer>
      <Hills t={t} colors={['transparent', '#5DCB6E', '#3FA850']} flowers={true} grass={true} />
    </div>
  );
}

// ── Background: POND (water + reeds + boat) ───────────────────────────────
function PondBackground({ t }) {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(to bottom, #4FB8FF 0%, #87D0FF 40%, #6BD17B 70%, #3A8CC7 78%, #1A6FB8 100%)',
      }} />
      <Sun t={t} x={1620} y={220} />
      <Clouds t={t} fill="#FFFFFF" stroke="#2A2440" />
      {/* Far hills */}
      <SVGLayer>
        <path d={`M-50 720 C 220 580 480 660 760 620 C 1020 590 1280 660 1480 600 C 1660 560 1820 620 ${SCENE_W + 50} 600 L ${SCENE_W + 50} 760 L -50 760 Z`}
          fill="#6BD17B" stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
        {/* Water ripples */}
        {Array.from({ length: 12 }).map((_, i) => {
          const y = 800 + i * 25;
          const offset = sinB(t, 0.5, i * 0.7) * 30;
          return (
            <path key={i}
              d={`M${-50 + offset} ${y} Q300 ${y - 4} 600 ${y} T1200 ${y} T${SCENE_W + 50} ${y}`}
              stroke="#FFFFFF" strokeWidth="2" opacity={0.5 - i * 0.03} fill="none" />
          );
        })}
        {/* Lily pads */}
        {[180, 480, 900, 1280, 1640].map((x, i) => {
          const bob = sinB(t, 0.4, i) * 8;
          return (
            <g key={i} transform={`translate(${x} ${900 + i * 22 + bob})`}>
              <ellipse rx="50" ry="14" fill="#3FA850" stroke="#2A2440" strokeWidth="3" />
              <path d="M-10 -10 L0 -2 L10 -10" stroke="#2A2440" strokeWidth="2.5" fill="none" strokeLinecap="round" />
              {i % 2 === 0 && (
                <g transform="translate(-8 -16)">
                  <ellipse rx="14" ry="6" fill="#FFFFFF" stroke="#2A2440" strokeWidth="2.5" />
                  <ellipse cy="-4" rx="10" ry="5" fill="#FFD43D" />
                </g>
              )}
            </g>
          );
        })}
        {/* Reeds */}
        {[40, 90, 1820, 1860, 1900].map((x, i) => {
          const sway = sinB(t, 0.8, i) * 5;
          return (
            <g key={i} transform={`translate(${x} 940) rotate(${sway})`}>
              <line x1="0" y1="0" x2="0" y2="-80" stroke="#3FA850" strokeWidth="4" strokeLinecap="round" />
              <ellipse cy="-86" rx="6" ry="14" fill="#8B5A2B" stroke="#2A2440" strokeWidth="2.5" />
            </g>
          );
        })}
      </SVGLayer>
    </div>
  );
}

// ── Background: RAIN (gray sky + rain particles + rainbow) ────────────────
const RAIN_DROPS = (() => {
  const rng = seeded(99);
  return Array.from({ length: 80 }).map(() => ({
    x: rng() * SCENE_W,
    delay: rng() * 1,
    speed: 0.7 + rng() * 0.6,
  }));
})();

function RainBackground({ t }) {
  // Stops at ~28s — rainbow comes out
  const rainOpacity = t < 28 ? 1 : Math.max(0, 1 - (t - 28) / 3);
  const rainbowOpacity = t > 28 ? Math.min(1, (t - 28) / 3) : 0;
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: t < 28
          ? 'linear-gradient(to bottom, #5C6B85 0%, #7C8AA8 40%, #A8B5CC 70%, #C9D5E8 100%)'
          : 'linear-gradient(to bottom, #87D0FF 0%, #B8E5FF 40%, #D9F0FF 75%, #FFF2B8 100%)',
        transition: 'background 1.5s ease',
      }} />
      {rainbowOpacity > 0 && <Sun t={t} x={1620} y={240} />}
      {/* rainbow */}
      {rainbowOpacity > 0 && (
        <SVGLayer style={{ opacity: rainbowOpacity }}>
          {['#FF5252', '#FF8A00', '#FFD43D', '#5DCB6E', '#4FB8FF', '#9B5FD9'].map((c, i) => (
            <path key={i}
              d={`M -100 ${SCENE_H - 100} A ${1100 - i * 30} ${1100 - i * 30} 0 0 1 ${SCENE_W + 100} ${SCENE_H - 100}`}
              stroke={c} strokeWidth="36" fill="none" opacity="0.85" />
          ))}
        </SVGLayer>
      )}
      <Clouds t={t} fill={t < 28 ? '#5C6B85' : '#FFFFFF'} stroke="#2A2440" />
      <Hills t={t} colors={['#3FA850', '#5DCB6E', '#3FA850']} flowers={true} grass={true} />
      {/* rain drops */}
      {rainOpacity > 0 && (
        <SVGLayer style={{ opacity: rainOpacity }}>
          {RAIN_DROPS.map((d, i) => {
            const cycle = ((t * d.speed + d.delay) % 1.4) / 1.4;
            const y = cycle * (SCENE_H + 100) - 50;
            const x = d.x + cycle * -40; // slight wind drift
            return (
              <line key={i} x1={x} y1={y} x2={x - 6} y2={y + 18}
                stroke="#A5BFE8" strokeWidth="2" strokeLinecap="round" opacity="0.85" />
            );
          })}
        </SVGLayer>
      )}
    </div>
  );
}

// ── Background: ROAD (Wheels on the Bus) ──────────────────────────────────
function RoadBackground({ t }) {
  // City rolls past
  const offset = -(t * 80) % 400;
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(to bottom, #4FB8FF 0%, #87D0FF 40%, #D9F0FF 70%, #FFE6A8 100%)',
      }} />
      <Sun t={t} x={1620} y={200} />
      <Clouds t={t} fill="#FFFFFF" stroke="#2A2440" />
      {/* City silhouette */}
      <SVGLayer>
        <g transform={`translate(${offset} 0)`}>
          {Array.from({ length: 16 }).map((_, i) => {
            const x = i * 280;
            const h = 180 + ((i * 53) % 7) * 32;
            const colors = ['#FF6FB0', '#4FB8FF', '#FFD43D', '#5DCB6E', '#FF5252'];
            const c = colors[i % colors.length];
            return (
              <g key={i} transform={`translate(${x} ${720 - h})`}>
                <rect width="220" height={h} fill={c} stroke="#2A2440" strokeWidth="5" />
                {/* Roof */}
                <path d={`M-10 0 L110 ${-40} L230 0 Z`} fill="#2A2440" stroke="#2A2440" strokeWidth="5" strokeLinejoin="round" />
                {/* Windows grid */}
                {Array.from({ length: Math.floor(h / 56) }).map((_, r) =>
                  Array.from({ length: 3 }).map((_, q) => (
                    <rect key={r + '-' + q} x={28 + q * 60} y={28 + r * 56} width="32" height="32" rx="4"
                      fill="#FFD43D" stroke="#2A2440" strokeWidth="3" />
                  ))
                )}
              </g>
            );
          })}
        </g>
        {/* Trees along the road */}
        <g transform={`translate(${offset * 1.3} 0)`}>
          {Array.from({ length: 20 }).map((_, i) => (
            <g key={i} transform={`translate(${i * 200 + 100} 740)`}>
              <rect x="-6" y="0" width="12" height="40" fill="#8B5A2B" stroke="#2A2440" strokeWidth="3" />
              <circle cy="-16" r="34" fill="#5DCB6E" stroke="#2A2440" strokeWidth="4" />
            </g>
          ))}
        </g>
        {/* Road */}
        <rect x="0" y="820" width={SCENE_W} height="260" fill="#3D3559" />
        <rect x="0" y="820" width={SCENE_W} height="14" fill="#2A2440" />
        {/* Lane stripes scrolling */}
        {Array.from({ length: 12 }).map((_, i) => {
          const x = (i * 220 + offset * 4) % (SCENE_W + 220) - 110;
          return <rect key={i} x={x} y={930} width="100" height="14" rx="3" fill="#FFD43D" />;
        })}
        {/* Curb */}
        <rect x="0" y="900" width={SCENE_W} height="6" fill="#FFF7E6" />
      </SVGLayer>
    </div>
  );
}

// ── Master dispatcher ───────────────────────────────────────────────────────
function BackgroundFor({ kind, t }) {
  switch (kind) {
    case 'night':  return <NightBackground t={t} />;
    case 'meadow': return <MeadowBackground t={t} />;
    case 'farm':   return <FarmBackground t={t} />;
    case 'pond':   return <PondBackground t={t} />;
    case 'rain':   return <RainBackground t={t} />;
    case 'road':   return <RoadBackground t={t} />;
    default:       return <MeadowBackground t={t} />;
  }
}

Object.assign(window, {
  BackgroundFor,
  NightBackground, MeadowBackground, FarmBackground, PondBackground, RainBackground, RoadBackground,
  SCENE_W, SCENE_H, sinB, SVGLayer,
});
