# Recreate this site as a single HTML file: Fenlight Community Energy

You are an expert creative front-end developer. Build a **single self-contained `index.html`** (inline
CSS and JS, no build step, no framework) that reproduces the community solar co-operative landing page
below: a live three.js solar farm where the sun crosses the sky as you scroll and 840 trackers turn to
follow it, a "today's output" curve that draws itself in step, a roof/field estimator with a compass
dial, a filterable SVG site map, a share calculator with a validated join form, a "where each £1 goes"
bar, an FAQ and a sunset footer. Every number below is a fixed constant; the reference implementation
appended after this spec wins if anything seems to differ.

## What it is

Fenlight is a fictional community energy co-operative in the fens: 1,412 members own 3.56 MWp of
panels on schools, barns and two grazed fields. The page reads as **one day**. Each section is stamped
with a time (06:20, 09:00, 11:30, 14:00, 17:30, 20:00, 21:30) and a tiny sun-arc glyph showing where
the sun is at that hour, and a sun dot on the header's bottom rule travels with page scroll.

**Signature:** the hero is a 280vh scroll track with a sticky 100svh stage. Scrolling drives the clock
from 06:00 to 20:45. The three.js scene (Preetham sky, PMREM sky reflections in the panel glass, soft
sun shadows) puts the sun where it really is on a late-May day; twelve rows of single-axis trackers
rotate to face it, backtrack near the horizon and stow flat at night; the camera leans 0.32 of the sun's
azimuth towards the light; grass moves in a wind shader and eight GLB sheep graze the aisles.
An instrument card draws the fleet's output curve up to the current minute with live MW, MWh-so-far
and homes-powered figures. Same model, same numbers: the 3D, the curve, the stats and the estimator all
come from one sun function.

## Page shell & libraries

- `<html lang="en-GB">`, viewport meta, title "Fenlight Community Energy — solar owned by the fen".
- Google Fonts: **Bricolage Grotesque** (opsz 12–96, wght 400–700) and **IBM Plex Mono** 400/500, `display=swap`.
- **three.js 0.170.0** as ES modules through an import map:
  `"three": "https://unpkg.com/three@0.170.0/build/three.module.js"`,
  `"three/addons/": "https://unpkg.com/three@0.170.0/examples/jsm/"`. Use `objects/Sky.js`,
  `loaders/GLTFLoader.js` and `libs/meshopt_decoder.module.js`. No other libraries (no GSAP, no Lenis).
- Two scripts: a **classic script** that owns all UI, the sun model, the 2D fallback canvas and the
  render loop, and exposes `window.FEN = {state, sunAt, skyAt, RM, stage, pointer, gl, size(), glReady(api),
  glFail(err), glbDone(), wake()}`; and a **module** that builds the 3D scene and calls `FEN.glReady({render,
  resize, busy})`. If the module never loads, the page keeps the 2D canvas.

## Tokens

- **Colour:** paper `#f2ece2`, paper-2 `#e7ddcc`, card `#fbf8f2`, ink `#1e1a15`, muted `#5a5146`,
  line `#d3c6b1`, sun `#f0a830` (fills only), sun-2 `#f7cf7a`, rust `#a03d21` (accent text, focus ring),
  fen `#24394a`, fen-2 `#182836`, reed `#5f7134`, on-dark `#f2ece2`, on-dark-2 `#b9c2c6`.
- **Type:** body Bricolage 17/1.55 at opsz 14. Hero H1 `clamp(42px, 6.6vw, 104px)`/0.93, −0.045em,
  weight 600, opsz 96, max 12.5ch, `text-wrap: balance`. H2 `clamp(34px, 4.6vw, 66px)`/0.98, −0.035em.
  H3 `clamp(22px, 2vw, 28px)`/1.1. Lead `clamp(18px, 1.5vw, 21px)`/1.45 in muted, max 40ch. Labels:
  Plex Mono 12.5px uppercase, +0.06em. All figures in Plex Mono with tabular numerals.
- **Radii:** 6 (images, inputs), 10–12 (cards), 999 (buttons, chips). **Borders:** 1.5px ink on interactive
  cards, 1px `line` rules. **Spacing:** gutter `clamp(16px, 4vw, 40px)`, max width 1320, section padding
  `clamp(64px, 9vw, 128px)`. Ease `cubic-bezier(.2,.8,.2,1)`.
- **Grain:** an inline SVG `feTurbulence` (0.85, 2 octaves) overlay at 16 % `mix-blend-mode: overlay`
  on every photo, so the 11 photos read as one film stock.

## Layout & structure

1. **Preloader.** A full-screen grid of fen-2 squares (12 columns, 5 under 600px; rows to fill) with a
   centred 320px instrument: a dashed sun arc, a horizon line, eleven little panel parallelograms, a sun
   that rises along the arc with progress, a clock (04:58 → 10:58) and a 40px mono percentage. Progress
   is real: fonts ready, window load, 3D ready (counts double), sheep GLB loaded; capped at 6 s. The
   counter eases 8 % of the gap per frame, never backwards. At 100 the squares fold away
   (`scaleY(0)`, 500ms) bottom row first (45ms per row + 18ms per column + up to 60ms jitter).
2. **Header** — fixed, 64px, paper at 94 %, 1px bottom rule carrying the 9px sun dot. Logo (sun on a
   horizon), nav Estimate · Sites · Shares · How we run · Questions (hover: 1.5px underline grows), and
   an ink pill "Become a member →". ≤ 960px: a 44px round menu button opens the nav as a full-width
   panel with 24px links; Esc closes and returns focus.
3. **Hero** (`#top`, 280vh; 240vh ≤ 760px) with a sticky stage: the canvas, H1 "1,412 neighbours own
   the *sunlight* on these roofs." (the word in sun-2 once the sun is down, rust while it is up), lead, two pills
   ("Estimate your roof →", ghost "See our 14 sites"). A top scrim keeps text legible (dark 28 % → 0 at
   night, paper 42 % → 0 by day). Bottom-right **instrument card** (540px, card colour, 1px ink border,
   radius 10): site label, 34px mono clock, sun elevation/azimuth and tracker angle; a 320×86 SVG curve
   (dashed ghost of the whole day, ink line + 35 % sun area clipped to "now", a sun dot); three stats
   with a 2px sun left rule (output now MW, made today MWh, homes running on it); a time slider
   04:30–21:30 step 5, "Play day" and "Now" buttons. Bottom-left a paper pill "Scroll to run the day"
   that fades after 4 % scroll.
4. **01 Who we are** (06:20) — a 42px statement with two highlighter `<mark>`s, a four-row ledger
   (Members 1,412 · £3.9m · 3,344 MWh · £186,400), and a two-photo stack (school 4:3, installer 4:5
   offset 48px down). The school photo carries a **glass tag** "92 MWh made here last year".
5. **02 Estimate** (09:00) — a two-pane card: inputs on card colour, results on fen blue.
   Inputs: Roof/Field segmented radio; area slider (roof 10–400 m² step 5, field 1–30 ha step 0.5);
   **compass dial** (150px SVG `role="slider"`, ticks every 15°, N/E/S/W, a yellow 120° "good" sector,
   a little house plan that rotates with the facing, a sun knob on the ring); pitch select; region
   select. Results: big kWh/year, four KPIs (kWp, homes, t CO₂, payback years), 12 monthly bars, an
   "assumptions" `<details>` that rewrites itself for the current inputs, "Offer this roof/field →"
   (pre-selects "host" in the join form) and an "Estimate only" badge.
6. **03 Sites** (11:30) — filter chips (All 14 · Roofs 9 · Fields 2 · Being planned 3, `aria-pressed`),
   a live totals line, an 800×560 SVG fen map (hatched and dotted parcels, three straight drains,
   the meandering River Wend, roads, seven village names in mono, compass, 2-mile scale) with HTML
   pin buttons (30px; roof = sun fill + house glyph, field = reed fill, planned = dashed paper), a
   two-column list of all sites under it, and a detail card (16:10 photo with grain, badge, name, host,
   size/year/MWh/members grid, a one-line story and the host's saving).
7. **04 Shares** (14:00) — a 64px mono amount input (£50–£20,000) with a log slider and quick
   amounts; a 12×4 grid of panel cells that fill (fractionally) with the panels your money buys
   (£1,050 per kWp, 430 W panels); an ink "1 vote" block; an illustration card (interest year one,
   over 20 years, capital back years 5–20, kWh a year, Warmth Fund share) with its method spelled out.
   Then **Join the co-op**: name, email, UK postcode, "I'd like to" (shares / host / news), amount,
   16+ checkbox, submit.
8. **05 How we run** (17:30) — a full-width **£1 bar** of five pressable segments (30p capital back,
   20p interest, 22p upkeep, 12p Fen Warmth Fund, 16p reserves), a detail line, five numbered rules,
   and the AGM photo with a dark glass tag "188 hands for the Hythe Lode field".
9. **06 Questions** (20:00) — six `<details>` with a ring-plus icon that turns 45°.
10. **Footer** (21:30) — a sunset gradient (`#e7a15a` → `#b8664a` → `#4a3a4c` → fen-2), a half-set sun
    on a horizon line, a 200px "Fenlight" wordmark, four columns, and a fine-print line stating the
    co-op is fictional and figures are illustrative.

## Behaviour & interaction

- **Sun model** (minutes since midnight `t`): `h = (t − 780)/480`; elevation `e = 62·cos(h·π/2)`°;
  azimuth `az = 180 + 130·clamp(h, −1.25, 1.25)`°. Fleet output `P = 3.558·0.84·sin(e)^0.9` MW with
  three cloud dips `×(1 − d·exp(−((t−c)/w)²))` at (690, 22, .32), (905, 35, .22), (1010, 14, .40).
  Today's MWh is a per-minute cumulative sum. Homes now = P / 0.42 kW, rounded to 10.
- **Scroll → time:** progress `p` through the hero maps 06:00 → 20:45. After the slider or Play sets a
  time, scroll moves time *relatively* (Δp × range) so it never jumps; p = 0 or 1 snaps to the ends.
  Play advances 0.09 min/ms (0.05 with reduced motion) and stops off-screen, on hidden tabs or at 21:30.
  "Now" jumps to the real local time.
- **3D scene:** ACES filmic tone mapping, sRGB output, PCF soft shadows (2048 map; 1024 under 760px),
  pixel ratio ≤ 1.75. Sky: turbidity 2.4, Rayleigh 2.6, Mie 0.0045 / g 0.84; a second Sky sharing the
  material feeds `PMREMGenerator.fromScene`, regenerated when elevation moves > 1.2° or azimuth > 5°
  (≥ 120ms apart). FogExp2 0.00055 tinted to the horizon colour of the 2D sky ramp. Sun light 3.4 ×
  smoothstep(−0.5°, 10°), colour `#ff8a45` → `#fff3e2` over 1–22°; hemisphere 0.12 + 0.75 ×
  smoothstep(−6°, 14°); exposure 0.62, dropping 0.14 towards noon.
  - **Trackers:** rows every 6 m from −33 to 33, 72 panels per row (2.1 × 0.04 × 1.1 m, hub 1.55 m) as one
    InstancedMesh with a box material array (aluminium frame, dark #2b2f35 backsheet, top = MeshPhysicalMaterial
    with a canvas cell texture: 12 × 6 cells, three busbars each, clearcoat 0.35, roughness 0.2, envMapIntensity 0.7). Target
    tilt `θ = −atan2(sunX, sunY)` clamped ±55°, scaled by e/6 under 6°, 0 at night. The rows glide to it
    at `θ += (target − θ)·min(1, dt·3.2)` like a slow motor. Torque tubes, posts every 7 panels, one
    motor box per row.
  - **Ground:** a 2048² canvas patchwork (fen parcels with furrows, hedges and a drain), a 110 × 150 m
    grass detail plane with a radial alpha fade, a mirror-metal drain strip reflecting the sky, 22,000
    instanced grass blades (9,000 on phones) swaying in a vertex shader (two sines plus a slow gust).
  - **Horizon:** ~700 instanced trees and poplars on hedge lines, a church with a pyramid spire, three
    barns and a windpump whose sails turn 0.9 rad/s. 900 stars fade in below −1°.
  - **Sheep:** `assets/sheep.glb` (Meshopt, ~770 KB) normalised to 1.25 m, cloned 8× (5 on phones),
    walking the aisles at 0.35 m/s with pauses to graze (body pitch bob), turning at the array ends.
  - **Camera:** desktop (0, 9.5, 27) looking at y 5.2, z −126, fov 46; portrait (0, 12, 34), fov 64.
    It yaws `0.32 × (az − 180)`, clamped ±40°, easing at `dt·2.4`. Pointer parallax ±1.4 m sideways,
    ±0.6 m vertical, eased at `dt·2.5`.
  - Render on demand: the classic loop calls `render` only while the stage is on screen and the tab
    visible, every frame when ambient motion is on, otherwise only when time changes.
- **2D fallback canvas** (runs first, stays if WebGL fails): the same sky ramp, a sun disc and glow,
  drifting clouds, a horizon silhouette (poplars, church, turning windpump), a perspective field
  patchwork, a sky-reflecting drain and 10 rows of projected 3D tracker quads with sun shadows.
- **Number tweens:** 380ms ease-out cubic between values (instant with reduced motion).
- **Estimator maths:** roof kWp = area × 0.7 × 0.21; field kWp = ha × 500. Orientation factor
  `(1 − k) + k·cos(dir − 180°)` × pitch peak, with (k, peak) flat (0, 0.89), shallow (0.12, 0.97),
  standard (0.21, 1), steep (0.30, 0.94). kWh = kWp × region yield (960 Fens, 1,040 south coast, 990
  south-west, 920 Midlands, 870 north, 820 Scotland) × factor. Homes = kWh / 2,700. CO₂ = kWh × 0.15 kg.
  Roof payback = kWp × clamp(1,500 − 4·(kWp − 10), 1,100, 1,500) / (kWh × £0.21). Field payback =
  kWp × 650 / (kWh × £0.085 − kWp × 12); landowner rent £900/ha/yr. Months: 3,5,8,11,13,14,13,11,9,6,4,3 %.
- **Dial:** pointer capture drag (angle `atan2(x, −y)`, snapped to 5°), arrows ±5° (Shift ±45°),
  PageUp/Down ±45°, Home = N, End = S; disabled for flat roofs and fields.
- **Map:** chips filter pins and list rows, totals read "Showing n sites · x MWp · about y GWh a year";
  if the selected site is filtered out the first visible one is selected.
- **Shares:** slider is logarithmic (£50 × 400^(r/1000)), rounded to £10/£50/£250 by band. Interest 4 %
  on the balance, nothing back in years 1–4, then 1/16 a year. Panels = (£/1,050)/0.43.
- **Form:** validates name (≥ 2 chars), email, UK postcode regex, amount 50–20,000 (only for shares),
  16+ box; messages sit under each field (`aria-invalid`, `aria-describedby`), focus goes to the first
  error; success replaces the form with a focused status panel whose text depends on the choice.
- **£1 bar:** the pressed segment grows by 8 flex units and shows its explanation.
- **Module reveal on photos:** each photo is covered by an 8 × 4 grid of fen-blue cells with hairline
  edges that collapse (`scaleX(0)`, 550ms) east to west (55ms per column, 35ms per row, small jitter)
  when 35 % of the photo is on screen, like a panel being uncovered. Text blocks rise 18px and fade (700ms).

## Responsive

- **1440:** stamp gutter 200px beside content; hero copy left, instrument bottom-right; estimator two
  panes; map 1.55 : 1 with the card; shares two columns.
- **768:** stamps sit above each section in a row; heads stack; estimator, map and shares go single
  column; menu button replaces the nav.
- **390:** hero H1 ~42px, the instrument card spans the width at the bottom; the 3D camera switches to
  the portrait preset and 9,000 blades / 5 sheep / 1024 shadows; dial 120px; £1 bar becomes a vertical
  list; form fields single column; pins 26px. No horizontal scroll at any width.

## Accessibility & reduced motion

Skip link; landmarks; every control is a real button, input, select or `role="slider"` with
`aria-valuetext`; chips and £1 segments use `aria-pressed`; results regions are `aria-live="polite"`;
2px rust focus ring 3px off; photos have specific alt text; decorative canvases are `aria-hidden`.
`prefers-reduced-motion`: no sticky scroll track (the stage is a normal 100svh block at the real local
time), no ambient 3D motion (no wind, sheep or parallax; trackers snap), cells and reveals off, the
preloader just fades, number tweens are instant, smooth scrolling off. Play still works, stepping slower.

## Fallbacks

The 2D canvas draws from the first frame; the WebGL canvas fades in over it (900ms) once its first
frame is ready. If three.js fails to load, WebGL is unavailable or the context is lost, the 2D canvas
stays and nothing else changes. If the module has not started 3 s after the preloader begins, the
preloader finishes on the 2D landscape and the 3D fades in whenever it arrives. `?still` renders only
on change (useful for screenshots on software GL). If even 2D canvas fails, the stage shows a CSS sky/field gradient.
The GLB is optional (a failed load just means no sheep). Fonts fall back to system sans and mono.

## Assets

- `assets/sheep.glb` — a grazing ewe (image-to-3D, Meshopt + WebP textures, ~770 KB).
- `assets/school.webp` — low brick primary school with a solar roof across a reedy drain.
- `assets/installer.webp` — volunteer in a harness clamping a panel rail on a barn roof (portrait).
- `assets/sheep.webp` — sheep grazing between tracker rows at sunrise, church on the horizon.
- `assets/maltings.webp` — brick maltings with a solar roof, narrowboat on the river.
- `assets/frost.webp` — frost crystals on a panel at a pink winter sunrise (portrait).
- `assets/agm.webp` — members in a village hall holding up green voting cards.
- `assets/leisure.webp`, `firestation.webp`, `church.webp`, `hall.webp`, `surgery.webp` — the other
  host buildings with solar roofs, in the same overcast documentary grade.
All photos: 1400px wide (900 for portraits), WebP q74, desaturated 16 % with a slightly warm blue cut.

## Make it yours

This prompt rebuilds one exact design. If everyone ships it unchanged, the sites will look alike.
Change these before you paste it; the structure and the interactions stay intact.

1. **Brand and offer.** Swap Fenlight, the Wend valley and the 14 sites for your own co-op, farm, school
   trust or installer. Keep 10–16 sites, three pin types and a headline that states one hard number
   ("1,412 neighbours…") so the hero and the map stay balanced.
2. **The signature scene.** Keep "scroll runs the day" but change what the sun drives: rooftop panels on
   a terraced street, a floating array on a reservoir, an agrivoltaic orchard, a solar carport with EVs
   charging, or a wind-and-solar hybrid. Keep the tracker logic, the camera yaw and the output curve.
3. **The animals and ambient life.** Replace the GLB sheep with geese, cattle, bees over wildflowers
   or cyclists on a lane; generate one clean studio image, turn it into a GLB and keep the amble/pause loop.
4. **Palette.** Replace paper, ink, sun, rust and fen with your own five; keep muted text ≥ 4.5:1 on the
   paper and keep one warm fill colour that only ever means "sun".
5. **Type pairing.** Swap Bricolage Grotesque + IBM Plex Mono for another characterful display sans or
   serif with a mono for figures (e.g. Instrument Serif + JetBrains Mono, Schibsted Grotesk + DM Mono).
6. **The day.** Change the date and place: a December day (sun max 15°, sunrise 08:05) makes a moodier
   hero; a southern-hemisphere site turns the camera north. Update the time stamps on each section.
7. **Photos.** Regenerate the 11 site photos for your own buildings in one consistent light and grade;
   keep no text or logos in them and keep the glass tags and cell reveals.
8. **Copy.** Rewrite every line in your own voice with your real figures and say exactly what a member
   gets ("12p in every £1 goes to loft insulation", not "make an impact").

Tell your AI: *"Build exactly as specified, but with these changes: …"*, then list your edits.

---

## Reference implementation (use verbatim)

The complete working `index.html`. Every number in the spec above is in this file; if the two ever seem to differ, the code wins. Images and models referenced as `assets/...` can be downloaded from https://copytheprompt.design/demos/solar-cooperative-landing/assets/ or replaced with your own (see Make it yours).

````html
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fenlight Community Energy — solar owned by the fen</title>
<meta name="description" content="Fenlight is a community solar co-operative: 1,412 members own panels on schools, barns and two grazed fields across the Wend valley.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400..700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root{
  --paper:#f2ece2; --paper-2:#e7ddcc; --card:#fbf8f2; --ink:#1e1a15; --muted:#5a5146; --line:#d3c6b1;
  --sun:#f0a830; --sun-2:#f7cf7a; --rust:#a03d21; --fen:#24394a; --fen-2:#182836; --reed:#5f7134; --on-dark:#f2ece2; --on-dark-2:#b9c2c6;
  --f-display:"Bricolage Grotesque", "Arial Narrow", system-ui, sans-serif;
  --f-mono:"IBM Plex Mono", ui-monospace, Menlo, monospace;
  --gutter:clamp(16px,4vw,40px); --max:1320px; --r:6px;
  --ease:cubic-bezier(.2,.8,.2,1);
}
*{box-sizing:border-box}
html{scroll-behavior:smooth;-webkit-text-size-adjust:100%}
@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
body{margin:0;background:var(--paper);color:var(--ink);font:400 17px/1.55 var(--f-display);font-variation-settings:"opsz" 14;overflow-x:hidden}
img{max-width:100%;display:block}
a{color:inherit}
button,input,select{font:inherit;color:inherit}
:focus-visible{outline:2px solid var(--rust);outline-offset:3px;border-radius:2px}
.sr{position:absolute!important;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.skip{position:absolute;left:12px;top:-60px;background:var(--ink);color:var(--paper);padding:10px 14px;z-index:100;border-radius:var(--r)}
.skip:focus{top:12px}
.mono{font-family:var(--f-mono);font-size:12.5px;letter-spacing:.06em;text-transform:uppercase}
.wrap{max-width:var(--max);margin:0 auto;padding:0 var(--gutter)}
h1,h2,h3{font-weight:600;margin:0;font-variation-settings:"opsz" 96}
h2{font-size:clamp(34px,4.6vw,66px);line-height:.98;letter-spacing:-.035em}
h3{font-size:clamp(22px,2vw,28px);line-height:1.1;letter-spacing:-.02em}
p{margin:0 0 1em}
.lead{font-size:clamp(18px,1.5vw,21px);line-height:1.45;color:var(--muted);max-width:40ch}
.num{font-family:var(--f-mono);font-variant-numeric:tabular-nums}

/* buttons */
.btn{display:inline-flex;align-items:center;gap:10px;min-height:48px;padding:0 20px;border-radius:999px;border:1.5px solid var(--ink);background:var(--ink);color:var(--paper);text-decoration:none;font-weight:600;cursor:pointer;transition:background .2s var(--ease),color .2s var(--ease),transform .1s}
.btn:hover{background:var(--rust);border-color:var(--rust)}
.btn:active{transform:scale(.98)}
.btn.ghost{background:transparent;color:inherit;border-color:currentColor}
.btn.ghost:hover{background:var(--ink);color:var(--paper);border-color:var(--ink)}
.btn .arr{display:inline-block;transition:transform .25s var(--ease)}
.btn:hover .arr{transform:translateX(3px)}

/* header */
.hdr{position:fixed;inset:0 0 auto 0;z-index:50;background:rgba(242,236,226,.94);border-bottom:1px solid var(--line);backdrop-filter:saturate(1.2)}
.hdr .wrap{display:flex;align-items:center;gap:24px;height:64px}
.brand{display:flex;align-items:center;gap:10px;text-decoration:none;font-weight:700;font-size:20px;letter-spacing:-.02em;margin-right:auto}
.brand svg{flex:none}
.brand small{font-family:var(--f-mono);font-weight:400;font-size:11px;letter-spacing:.08em;text-transform:uppercase;color:var(--muted)}
.nav{display:flex;gap:22px}
.nav a{text-decoration:none;font-weight:500;font-size:15px;padding:6px 0;background:linear-gradient(currentColor,currentColor) 0 100%/0 1.5px no-repeat;transition:background-size .25s var(--ease)}
.nav a:hover{background-size:100% 1.5px}
.hdr .btn{min-height:42px;padding:0 16px;font-size:15px}
.menu-btn{display:none;width:44px;height:44px;border:1.5px solid var(--ink);border-radius:50%;background:none;cursor:pointer;position:relative}
.menu-btn span{position:absolute;left:12px;right:12px;height:1.5px;background:var(--ink);transition:transform .25s var(--ease)}
.menu-btn span:first-child{top:17px}.menu-btn span:last-child{top:25px}
.menu-btn[aria-expanded="true"] span:first-child{transform:translateY(4px) rotate(45deg)}
.menu-btn[aria-expanded="true"] span:last-child{transform:translateY(-4px) rotate(-45deg)}
.dayline{position:absolute;left:0;right:0;bottom:-1px;height:1px}
.dayline i{position:absolute;top:-4px;width:9px;height:9px;border-radius:50%;background:var(--sun);box-shadow:0 0 0 3px rgba(240,168,48,.25);left:0;transform:translateX(-50%)}
@media (max-width:960px){
  .nav{position:fixed;top:64px;left:0;right:0;flex-direction:column;gap:0;background:var(--paper);border-bottom:1px solid var(--line);padding:8px var(--gutter) 20px;display:none}
  .nav.open{display:flex}
  .nav a{font-size:24px;font-weight:600;padding:12px 0;border-bottom:1px solid var(--line);background:none}
  .menu-btn{display:block}
  .hdr .btn{display:none}
  .nav .btn{display:inline-flex;margin-top:16px;align-self:flex-start;font-size:17px;border-bottom:1.5px solid var(--ink)}
}
@media (min-width:961px){.nav .btn{display:none}}

/* HERO */
.hero{position:relative;height:280vh;background:#0f1b2b}
.stage{position:sticky;top:0;height:100vh;height:100svh;overflow:hidden}
.stage canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
.stage.nocanvas{background:linear-gradient(#7fa9cf,#e4ecee 55%,#7d8a4a 56%,#5d6b39)}
.hero-copy{position:absolute;left:0;right:0;top:calc(64px + clamp(28px,6vh,72px));color:var(--on-dark);transition:color .6s var(--ease)}
.stage.day .hero-copy{color:var(--ink)}
.hero h1{font-size:clamp(42px,6.6vw,104px);line-height:.93;letter-spacing:-.045em;max-width:12.5ch;text-wrap:balance}
.hero h1 em{font-style:normal;color:var(--sun-2);transition:color .6s}
.stage.day h1 em{color:var(--rust)}
.hero-copy .lead{color:inherit;margin-top:22px;max-width:44ch;width:fit-content;padding:12px 16px;margin-left:-16px;border-radius:10px;background:rgba(15,22,32,.72);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}
.stage.day .hero-copy .lead{background:rgba(242,236,226,.82)}
.stage:not(.day) .hero-cta .btn.ghost{background:rgba(15,22,32,.72)}
.stage.day .hero-cta .btn.ghost{background:rgba(242,236,226,.82);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}
.hero-cta{display:flex;gap:12px;flex-wrap:wrap;margin-top:26px}
.stage:not(.day) .hero-cta .btn{background:var(--paper);color:var(--ink);border-color:var(--paper)}
.stage:not(.day) .hero-cta .btn.ghost{color:var(--paper)}
.stage:not(.day) .hero-cta .btn:hover{background:var(--sun);border-color:var(--sun);color:var(--ink)}

.inst{position:absolute;right:var(--gutter);bottom:var(--gutter);width:min(540px,calc(100% - 2*var(--gutter)));background:var(--card);color:var(--ink);border:1px solid var(--ink);border-radius:10px;padding:16px 18px 14px;box-shadow:0 18px 40px -20px rgba(0,0,0,.45)}
.inst-top{display:flex;align-items:flex-end;justify-content:space-between;gap:12px;border-bottom:1px solid var(--line);padding-bottom:10px}
.clock{font-family:var(--f-mono);font-size:34px;line-height:1;letter-spacing:-.02em;font-variant-numeric:tabular-nums}
.inst-top .mono{color:var(--muted);font-size:11px;text-align:right;line-height:1.5}
.curve{display:block;width:100%;height:auto;margin:10px 0 4px}
.curve .axis{stroke:var(--line);stroke-width:1}
.curve .ghostline{fill:none;stroke:#b7a993;stroke-width:1.2;stroke-dasharray:2 3}
.curve .area{fill:rgba(240,168,48,.35)}
.curve .line{fill:none;stroke:var(--ink);stroke-width:1.6}
.curve text{font:10px var(--f-mono);fill:var(--muted)}
.stats{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:6px 0 10px}
.stats div{border-left:2px solid var(--sun);padding-left:9px}
.stats b{display:block;font-family:var(--f-mono);font-weight:500;font-size:19px;font-variant-numeric:tabular-nums;letter-spacing:-.02em}
.stats span{font-size:12px;color:var(--muted);line-height:1.25;display:block}
.scrub{display:flex;align-items:center;gap:10px}
.scrub label{white-space:nowrap}
.scrub .tiny{min-height:36px;padding:0 12px;font-size:13px;border-width:1px;white-space:nowrap}
input[type=range]{-webkit-appearance:none;appearance:none;width:100%;height:28px;background:transparent;cursor:pointer;margin:0}
input[type=range]::-webkit-slider-runnable-track{height:2px;background:var(--ink)}
input[type=range]::-moz-range-track{height:2px;background:var(--ink)}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border-radius:50%;background:var(--sun);border:2px solid var(--ink);margin-top:-9px}
input[type=range]::-moz-range-thumb{width:16px;height:16px;border-radius:50%;background:var(--sun);border:2px solid var(--ink)}
.hint{position:absolute;left:var(--gutter);bottom:var(--gutter);color:var(--ink);background:rgba(242,236,226,.82);padding:8px 14px;border-radius:999px;margin:0;display:flex;gap:10px;align-items:center;transition:opacity .4s}

.hint svg{animation:bob 1.8s ease-in-out infinite}
@keyframes bob{50%{transform:translateY(4px)}}
@media (max-width:1100px){.hint{display:none}}
@media (max-width:760px){
  .hero{height:240vh}
  .inst{padding:12px 14px 10px}
  .inst-top .mono{display:none}
  .inst-top{padding-bottom:6px}
  .curve{margin:6px 0 2px}
  .stats span{font-size:11px}
  .hero-cta .btn.ghost{display:none}
  .clock{font-size:26px}
  .stats b{font-size:16px}
  .hero-copy .lead{font-size:16px;margin-top:14px;padding:10px 12px;margin-left:-12px}
  .hero-cta{margin-top:16px}
  .hero-cta .btn{min-height:44px;padding:0 16px;font-size:15px}
}
@media (max-height:700px) and (max-width:760px){.hero-copy .lead{display:none}}

/* sections */
.sec{border-top:1px solid var(--line);padding:clamp(64px,9vw,128px) 0}
.sec-grid{display:grid;grid-template-columns:200px 1fr;gap:var(--gutter)}
.stamp{position:sticky;top:96px;align-self:start;display:flex;flex-direction:column;gap:8px}
.stamp .t{font-family:var(--f-mono);font-size:30px;letter-spacing:-.03em;line-height:1}
.stamp .mono{color:var(--muted);font-size:11.5px}
.stamp svg{width:96px;height:40px;overflow:visible}
.stamp svg path{fill:none;stroke:var(--line);stroke-width:1.5;stroke-dasharray:2 3}
.stamp svg line{stroke:var(--ink);stroke-width:1}
.stamp svg circle{fill:var(--sun);stroke:var(--ink);stroke-width:1}
.head{display:grid;grid-template-columns:1.2fr 1fr;gap:var(--gutter);align-items:end;margin-bottom:clamp(36px,5vw,64px)}
.head .lead{margin:0}
@media (max-width:960px){
  .sec-grid{grid-template-columns:1fr;gap:20px}
  .stamp{position:static;flex-direction:row;align-items:center;gap:14px}
  .stamp .t{font-size:22px}
  .head{grid-template-columns:1fr;gap:16px}
}

/* about */
.about-grid{display:grid;grid-template-columns:.95fr 1.05fr;gap:clamp(24px,4vw,56px);align-items:start}
.statement{font-size:clamp(26px,2.6vw,38px);line-height:1.12;letter-spacing:-.025em;font-weight:500;font-variation-settings:"opsz" 60;margin:0 0 36px;text-wrap:pretty}
.statement mark{background:linear-gradient(transparent 62%,rgba(240,168,48,.55) 62%);color:inherit;padding:0 .05em}
.ledger{border-top:1.5px solid var(--ink);margin:0}
.ledger div{display:grid;grid-template-columns:1fr auto;gap:16px;padding:14px 0;border-bottom:1px solid var(--line);align-items:baseline}
.ledger dt{color:var(--muted)}
.ledger dd{margin:0;font-family:var(--f-mono);font-size:22px;letter-spacing:-.02em;font-variant-numeric:tabular-nums}
.photos{position:relative;display:grid;grid-template-columns:1fr .62fr;gap:12px;align-items:end}
.photos figure{margin:0}
.photos img{width:100%;height:auto;border-radius:var(--r);background:var(--paper-2)}
.photos .p1 img{aspect-ratio:4/3;object-fit:cover}
.photos .p2{margin-bottom:-48px}
.photos .p2 img{aspect-ratio:4/5;object-fit:cover}
figcaption{font-family:var(--f-mono);font-size:11px;letter-spacing:.04em;color:var(--muted);margin-top:8px;line-height:1.45}
@media (max-width:960px){.about-grid{grid-template-columns:1fr}.photos .p2{margin-bottom:0}}

/* estimator */
.est{display:grid;grid-template-columns:minmax(0,.95fr) minmax(0,1.05fr);border:1.5px solid var(--ink);border-radius:12px;overflow:hidden;background:var(--card)}
.est-in{padding:clamp(20px,2.6vw,36px);border-right:1.5px solid var(--ink)}
.est-out{padding:clamp(20px,2.6vw,36px);background:var(--fen);color:var(--on-dark);display:flex;flex-direction:column;gap:18px}
.seg{display:inline-grid;grid-template-columns:1fr 1fr;border:1.5px solid var(--ink);border-radius:999px;padding:3px;margin-bottom:26px;position:relative}
.seg input{position:absolute;opacity:0;pointer-events:none}
.seg label{padding:9px 22px;border-radius:999px;cursor:pointer;font-weight:600;text-align:center;transition:background .2s,color .2s}
.seg input:checked+label{background:var(--ink);color:var(--paper)}
.seg input:focus-visible+label{outline:2px solid var(--rust);outline-offset:2px}
.field{margin-bottom:24px}
.field-head{display:flex;justify-content:space-between;align-items:baseline;gap:12px;margin-bottom:6px}
.field-head label,.field-head .lbl{font-weight:600}
.field-head output{font-family:var(--f-mono);font-size:15px}
.help{font-size:13.5px;color:var(--muted);margin:6px 0 0;line-height:1.4}
select{appearance:none;-webkit-appearance:none;width:100%;min-height:46px;border:1.5px solid var(--ink);border-radius:var(--r);background:var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231e1a15' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 14px center;padding:0 40px 0 14px;cursor:pointer}
.dialrow{display:grid;grid-template-columns:150px 1fr;gap:20px;align-items:center}
.dial{width:150px;height:150px;touch-action:none;cursor:grab;border-radius:50%}
.dial:active{cursor:grabbing}
.dial[aria-disabled="true"]{opacity:.45;cursor:not-allowed}
.dial .ring{fill:var(--paper);stroke:var(--ink);stroke-width:1.5}
.dial .tick{stroke:var(--ink);stroke-width:1}
.dial text{font:500 11px var(--f-mono);fill:var(--ink);text-anchor:middle;dominant-baseline:middle}
.dial .arc{fill:rgba(240,168,48,.28)}
.dial .knob{fill:var(--sun);stroke:var(--ink);stroke-width:1.5}
.compass-out b{display:block;font-size:22px;letter-spacing:-.02em}
.est-out .big{font-family:var(--f-mono);font-size:clamp(40px,5vw,68px);letter-spacing:-.04em;line-height:1;font-variant-numeric:tabular-nums}
.est-out .big small{font-size:.32em;letter-spacing:0;margin-left:6px;color:var(--on-dark-2)}
.est-out .mono{color:var(--on-dark-2)}
.kpis{display:grid;grid-template-columns:repeat(2,1fr);gap:1px;background:rgba(242,236,226,.18);border:1px solid rgba(242,236,226,.18);border-radius:8px;overflow:hidden}
.kpis div{background:var(--fen);padding:12px 14px}
.kpis b{display:block;font-family:var(--f-mono);font-weight:500;font-size:22px;letter-spacing:-.02em;font-variant-numeric:tabular-nums}
.kpis span{font-size:13px;color:var(--on-dark-2)}
.months{display:grid;grid-template-columns:repeat(12,1fr);gap:4px;align-items:end;height:110px;border-bottom:1px solid rgba(242,236,226,.4);padding-top:6px}
.months div{position:relative;background:var(--sun);border-radius:2px 2px 0 0;transition:height .45s var(--ease);min-height:2px}
.months div:hover::after,.months div:focus::after{content:attr(data-v);position:absolute;bottom:calc(100% + 4px);left:50%;transform:translateX(-50%);font:11px var(--f-mono);white-space:nowrap;background:var(--paper);color:var(--ink);padding:2px 5px;border-radius:3px}
.mlabels{display:grid;grid-template-columns:repeat(12,1fr);gap:4px;font:10.5px var(--f-mono);color:var(--on-dark-2);text-align:center;margin-top:4px}
details.assume{border-top:1px solid rgba(242,236,226,.25);padding-top:12px;font-size:14px;color:var(--on-dark-2)}
details.assume summary{cursor:pointer;color:var(--on-dark);font-weight:600}
details.assume ul{margin:10px 0 0;padding-left:18px;line-height:1.55}
.est-cta{display:flex;flex-wrap:wrap;gap:10px;align-items:center}
.est-out .btn{background:var(--sun);border-color:var(--sun);color:var(--ink)}
.est-out .btn:hover{background:var(--paper);border-color:var(--paper)}
.badge{display:inline-block;font:500 10.5px var(--f-mono);letter-spacing:.08em;text-transform:uppercase;border:1px solid currentColor;border-radius:999px;padding:3px 8px}
@media (max-width:960px){.est{grid-template-columns:1fr}.est-in{border-right:0;border-bottom:1.5px solid var(--ink)}}
@media (max-width:420px){.dialrow{grid-template-columns:120px 1fr;gap:14px}.dial{width:120px;height:120px}}

/* map */
.filters{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:16px}
.chip{min-height:40px;padding:0 14px;border:1.5px solid var(--ink);border-radius:999px;background:transparent;cursor:pointer;font-weight:600;font-size:15px;display:inline-flex;gap:8px;align-items:center}
.chip .c{font:500 12px var(--f-mono)}
.chip[aria-pressed="true"]{background:var(--ink);color:var(--paper)}
.chip i{width:10px;height:10px;border-radius:50%;display:inline-block;border:1.5px solid currentColor}
.chip .roof{background:var(--sun)} .chip .field{background:var(--reed)} .chip .plan{background:transparent;border-style:dashed}
.maptotals{font-family:var(--f-mono);font-size:13px;color:var(--muted);margin:0 0 16px}
.maplayout{display:grid;grid-template-columns:minmax(0,1.55fr) minmax(0,1fr);gap:clamp(16px,2vw,28px);align-items:start}
.map{position:relative;aspect-ratio:800/560;border:1.5px solid var(--ink);border-radius:12px;overflow:hidden;background:#e9e1d1}
.map svg{position:absolute;inset:0;width:100%;height:100%}
.pin{position:absolute;width:30px;height:30px;margin:-15px 0 0 -15px;border-radius:50%;border:2px solid var(--ink);background:var(--sun);cursor:pointer;padding:0;transition:transform .2s var(--ease),opacity .25s;display:grid;place-items:center}
.pin svg{position:static;width:14px;height:14px}
.pin.field{background:var(--reed);color:var(--paper)}
.pin.plan{background:var(--paper);border-style:dashed}
.pin:hover{transform:scale(1.15)}
.pin[aria-pressed="true"]{transform:scale(1.25);box-shadow:0 0 0 4px var(--paper),0 0 0 6px var(--ink)}
.pin[hidden]{display:none}
.card{border:1.5px solid var(--ink);border-radius:12px;background:var(--card);overflow:hidden}
.card .ph{aspect-ratio:16/10;isolation:isolate;background:var(--paper-2);position:relative;overflow:hidden}
.card .ph img{width:100%;height:100%;object-fit:cover}
.card .ph .noimg{position:absolute;inset:0;display:grid;place-items:center;font:12px var(--f-mono);color:var(--muted);background:repeating-linear-gradient(135deg,var(--paper-2) 0 10px,#ddd2bf 10px 11px)}
.card .body{padding:18px 20px 20px}
.card h3{margin:8px 0 6px}
.card .host{color:var(--muted);margin:0 0 14px}
.card dl{display:grid;grid-template-columns:1fr 1fr;gap:0;margin:0;border-top:1px solid var(--line)}
.card dl div{padding:10px 0;border-bottom:1px solid var(--line)}
.card dl div:nth-child(odd){padding-right:10px}
.card dt{font-size:12.5px;color:var(--muted)}
.card dd{margin:0;font-family:var(--f-mono);font-size:17px}
.card .story{margin:14px 0 0;font-size:15.5px}
.sitelist{margin-top:18px;columns:2;column-gap:24px;padding:0;list-style:none;font-size:14.5px}
.sitelist li{break-inside:avoid;border-bottom:1px solid var(--line)}
.sitelist button{background:none;border:0;padding:8px 0;cursor:pointer;width:100%;text-align:left;display:flex;justify-content:space-between;gap:8px}
.sitelist button:hover{color:var(--rust)}
.sitelist .num{font-size:12.5px;color:var(--muted)}
@media (max-width:960px){.maplayout{grid-template-columns:1fr}.sitelist{columns:1}}
@media (max-width:520px){.pin{width:26px;height:26px;margin:-13px 0 0 -13px}}

/* shares */
.shares{display:grid;grid-template-columns:1fr 1fr;gap:clamp(20px,3vw,40px);align-items:start}
.amount{display:flex;align-items:baseline;gap:6px;border-bottom:1.5px solid var(--ink);padding-bottom:6px;margin-bottom:10px}
.amount span{font-family:var(--f-mono);font-size:clamp(36px,5vw,64px);letter-spacing:-.04em;line-height:1}
.amount input{font-family:var(--f-mono);font-size:clamp(36px,5vw,64px);letter-spacing:-.04em;line-height:1;border:0;background:transparent;width:100%;min-width:0;padding:0}
.amount input:focus-visible{outline:none}
.amount:focus-within{border-color:var(--rust)}
.quick{display:flex;flex-wrap:wrap;gap:8px;margin:14px 0 22px}
.quick button{min-height:38px;padding:0 14px;border-radius:999px;border:1.5px solid var(--ink);background:none;cursor:pointer;font:500 14px var(--f-mono)}
.quick button:hover{background:var(--ink);color:var(--paper)}
.vote{display:flex;gap:16px;align-items:center;background:var(--ink);color:var(--paper);border-radius:10px;padding:16px 18px;margin-top:22px}
.vote b{font-family:var(--f-mono);font-size:42px;line-height:1;color:var(--sun)}
.vote p{margin:0;font-size:15px}
.panelgrid{display:grid;grid-template-columns:repeat(12,1fr);gap:3px;margin:14px 0 6px;max-width:440px}
.panelgrid i{aspect-ratio:1/1.6;background:#d8ccb8;border-radius:2px;position:relative;overflow:hidden}
.panelgrid i b{position:absolute;inset:0 auto 0 0;background:var(--fen);transition:width .3s var(--ease)}
.share-out{border:1.5px solid var(--ink);border-radius:12px;padding:clamp(18px,2.4vw,28px);background:var(--card)}
.share-out .row{display:flex;justify-content:space-between;gap:12px;padding:11px 0;border-bottom:1px solid var(--line);align-items:baseline}
.share-out .row b{font-family:var(--f-mono);font-weight:500;font-size:20px;font-variant-numeric:tabular-nums;white-space:nowrap}
.share-out .note{font-size:13px;color:var(--muted);margin:12px 0 0}
@media (max-width:960px){.shares{grid-template-columns:1fr}}

/* join form */
.join{margin-top:clamp(40px,6vw,72px);display:grid;grid-template-columns:.8fr 1.2fr;gap:clamp(20px,3vw,40px);border-top:1.5px solid var(--ink);padding-top:28px}
form .grid2{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.inp{display:flex;flex-direction:column;gap:6px;margin-bottom:16px}
.inp label{font-weight:600;font-size:15px}
.inp input[type=text],.inp input[type=email],.inp input[type=number]{min-height:48px;border:1.5px solid var(--ink);border-radius:var(--r);background:var(--paper);padding:0 14px}
.inp input[aria-invalid="true"],.inp select[aria-invalid="true"]{border-color:var(--rust);background:#f7e6dd}
.err{color:var(--rust);font-size:13.5px;min-height:0}
.check{display:flex;gap:10px;align-items:flex-start;font-size:15px;margin:4px 0 18px}
.check input{width:20px;height:20px;accent-color:var(--ink);margin-top:2px;flex:none}
.ok{border:1.5px solid var(--ink);background:var(--sun-2);border-radius:12px;padding:22px}
.ok h3{margin-bottom:8px}
@media (max-width:960px){.join{grid-template-columns:1fr}}
@media (max-width:520px){form .grid2{grid-template-columns:1fr;gap:0}}

/* how */
.pound{display:flex;height:84px;border:1.5px solid var(--ink);border-radius:10px;overflow:hidden;margin:8px 0 14px}
.pound button{border:0;border-right:1.5px solid var(--ink);cursor:pointer;padding:10px;text-align:left;display:flex;flex-direction:column;justify-content:space-between;transition:filter .2s,flex-grow .35s var(--ease);min-width:0;overflow:hidden}
.pound button:last-child{border-right:0}
.pound button b{font-family:var(--f-mono);font-size:20px;font-weight:500}
.pound button span{font-size:12.5px;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pound button[aria-pressed="true"]{box-shadow:inset 0 -6px 0 var(--ink)}
.pound button:hover{filter:brightness(1.06)}
.pound-detail{min-height:4.5em;max-width:62ch}
.pound-detail h3{margin-bottom:6px}
.how-grid{display:grid;grid-template-columns:1fr 1fr;gap:clamp(24px,4vw,56px);margin-top:clamp(40px,5vw,64px);align-items:start}
.rules{list-style:none;margin:0;padding:0;counter-reset:r;border-top:1.5px solid var(--ink)}
.rules li{display:grid;grid-template-columns:44px 1fr;gap:8px;padding:16px 0;border-bottom:1px solid var(--line)}
.rules li::before{counter-increment:r;content:counter(r,decimal-leading-zero);font:500 13px var(--f-mono);color:var(--rust);padding-top:4px}
.rules b{display:block;font-size:19px;letter-spacing:-.01em}
.rules span{color:var(--muted);font-size:15.5px}
.agm img{border-radius:var(--r);aspect-ratio:3/2;object-fit:cover;width:100%;height:auto}
@media (max-width:960px){.how-grid{grid-template-columns:1fr}}
@media (max-width:640px){.pound{height:auto;flex-direction:column}.pound button{flex:none!important;border-right:0;border-bottom:1.5px solid var(--ink);flex-direction:row;align-items:center;min-height:46px}.pound button:last-child{border-bottom:0}.pound button span{white-space:normal}}

/* faq */
.faq{border-top:1.5px solid var(--ink)}
.faq details{border-bottom:1px solid var(--line)}
.faq summary{list-style:none;cursor:pointer;display:grid;grid-template-columns:1fr 28px;gap:16px;padding:20px 0;font-size:clamp(19px,1.7vw,23px);font-weight:600;letter-spacing:-.015em}
.faq summary::-webkit-details-marker{display:none}
.faq summary::after{content:"";width:22px;height:22px;justify-self:end;margin-top:3px;background:linear-gradient(var(--ink),var(--ink)) center/14px 1.5px no-repeat,linear-gradient(var(--ink),var(--ink)) center/1.5px 14px no-repeat;border:1.5px solid var(--ink);border-radius:50%;transition:transform .3s var(--ease)}
.faq details[open] summary::after{transform:rotate(45deg)}
.faq .a{padding:0 44px 22px 0;color:var(--muted);max-width:70ch}
.faq .a p:last-child{margin:0}

/* footer */
.foot{background:linear-gradient(180deg,#e7a15a 0,#b8664a 70px,#4a3a4c 160px,var(--fen-2) 300px);color:var(--on-dark);padding:200px 0 36px;position:relative;overflow:hidden}
.foot .horizon{position:absolute;left:0;right:0;top:118px;height:2px;background:rgba(24,40,54,.6)}
.foot .sunset{position:absolute;left:62%;top:96px;width:44px;height:44px;border-radius:50%;background:#f7c46c;box-shadow:0 0 60px 20px rgba(247,196,108,.35);clip-path:inset(0 0 50% 0)}
.foot-big{font-size:clamp(56px,13vw,200px);line-height:.85;letter-spacing:-.06em;font-weight:700;margin:0 0 48px;color:var(--on-dark)}
.foot-grid{display:grid;grid-template-columns:1.3fr 1fr 1fr 1fr;gap:var(--gutter);border-top:1px solid rgba(242,236,226,.25);padding-top:28px;font-size:15px}
.foot-grid h4{font:500 11.5px var(--f-mono);letter-spacing:.08em;text-transform:uppercase;color:var(--on-dark-2);margin:0 0 12px}
.foot-grid a{color:var(--on-dark);text-decoration:none;display:block;padding:3px 0}
.foot-grid a:hover{color:var(--sun-2)}
.foot .fine{margin-top:40px;font-size:13px;color:var(--on-dark-2);display:flex;justify-content:space-between;gap:16px;flex-wrap:wrap}
.foot :focus-visible{outline-color:var(--sun-2)}
@media (max-width:860px){.foot-grid{grid-template-columns:1fr 1fr}}

/* 3D layer */
.stage canvas.gl{opacity:0;transition:opacity .9s var(--ease)}
.stage.gl-on canvas.gl{opacity:1}
.stage.gl-on #sky{opacity:0;transition:opacity .9s}
.stage::after{content:"";position:absolute;inset:0;pointer-events:none;background:linear-gradient(180deg,rgba(10,16,26,.28),rgba(10,16,26,0) 38%);transition:opacity .6s}
.stage::after{background:linear-gradient(90deg,rgba(10,16,26,.5),rgba(10,16,26,.2) 42%,rgba(10,16,26,0) 62%),linear-gradient(180deg,rgba(10,16,26,.3),rgba(10,16,26,0) 40%)}
.stage.day::after{background:linear-gradient(90deg,rgba(242,236,226,.7),rgba(242,236,226,.35) 40%,rgba(242,236,226,0) 60%),linear-gradient(180deg,rgba(242,236,226,.4),rgba(242,236,226,0) 40%)}
@media (max-width:760px){.stage.day::after{background:linear-gradient(180deg,rgba(242,236,226,.75),rgba(242,236,226,.5) 45%,rgba(242,236,226,0) 62%)}.stage::after{background:linear-gradient(180deg,rgba(10,16,26,.55),rgba(10,16,26,.3) 45%,rgba(10,16,26,0) 62%)}}
.hero-copy,.inst,.hint{z-index:2}
/* preloader: sunrise over a panel grid */
.pre{position:fixed;inset:0;z-index:200;display:grid;grid-template-columns:repeat(var(--c,12),1fr);grid-auto-rows:1fr;pointer-events:none}
.pre i{background:var(--fen-2);border:1px solid rgba(185,194,198,.13);transition:transform .5s var(--ease),opacity .5s var(--ease);transform-origin:50% 0}
.pre.go i{transform:scaleY(0);opacity:.2}
.pre-ui{position:fixed;inset:0;z-index:201;display:grid;place-items:center;color:var(--on-dark);transition:opacity .4s;pointer-events:none}
.pre-ui.go{opacity:0}
.pre[hidden],.pre-ui[hidden]{display:none}
.pre-ui .box{width:min(320px,80vw)}
.pre-ui svg{width:100%;height:auto;display:block}
.pre-ui .row{display:flex;justify-content:space-between;margin-top:12px}
.pre-ui .pct{font-family:var(--f-mono);font-size:40px;letter-spacing:-.03em;line-height:1}
/* module reveal: photos open cell by cell like a panel being uncovered */
.cellwrap{position:relative;overflow:hidden;border-radius:var(--r)}
.cells{position:absolute;inset:0;display:grid;grid-template-columns:repeat(8,1fr);grid-auto-rows:1fr;pointer-events:none}
.cells i{background:var(--fen);border:.5px solid rgba(185,194,198,.25);transition:transform .55s var(--ease);transition-delay:var(--d,0s);transform-origin:0 50%}
.in .cells i,.cells.in i{transform:scaleX(0)}
.glass{position:absolute;left:12px;bottom:12px;right:auto;max-width:calc(100% - 24px);padding:10px 14px;border-radius:8px;color:var(--ink);background:linear-gradient(180deg,rgba(255,255,255,.18),rgba(255,255,255,0) 60%),rgba(242,236,226,.55);backdrop-filter:blur(14px) saturate(1.2);-webkit-backdrop-filter:blur(14px) saturate(1.2);border:1px solid rgba(255,255,255,.45);font-size:14px;line-height:1.35}
.glass b{display:block;font-family:var(--f-mono);font-weight:500;font-size:18px;letter-spacing:-.02em}
.glass.dark{color:var(--on-dark);background:linear-gradient(180deg,rgba(255,255,255,.12),rgba(255,255,255,0) 60%),rgba(24,40,54,.45);border-color:rgba(255,255,255,.2)}
.grain{position:relative}
.grain::after{content:"";position:absolute;inset:0;pointer-events:none;opacity:.16;mix-blend-mode:overlay;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E")}

/* reveal */
.rv{opacity:0;transform:translateY(18px);transition:opacity .7s var(--ease),transform .7s var(--ease)}
.rv.in{opacity:1;transform:none}
@media (prefers-reduced-motion:reduce){
  .cells{display:none}
  .rv{opacity:1;transform:none;transition:none}
  .hero{height:auto}
  .stage{position:relative;height:100vh;height:100svh;min-height:640px}
  .hint{display:none}
  .hint svg{animation:none}
  *{transition-duration:.01ms!important}
}
</style>
</head>
<body>
<a class="skip" href="#main">Skip to content</a>
<div class="pre" id="pre" aria-hidden="true"></div>
<div class="pre-ui" id="preUi" role="status" aria-label="Loading">
  <div class="box">
    <svg viewBox="0 0 320 120" aria-hidden="true"><defs><clipPath id="preClip"><rect x="0" y="0" width="320" height="96"/></clipPath></defs>
      <path d="M20 96 Q160 -40 300 96" fill="none" stroke="rgba(185,194,198,.35)" stroke-dasharray="2 4"/>
      <g clip-path="url(#preClip)"><circle id="preSun" cx="20" cy="110" r="12" fill="#f0a830"/></g>
      <line x1="0" y1="96" x2="320" y2="96" stroke="#f2ece2" stroke-width="1.2"/>
      <g stroke="rgba(242,236,226,.6)" stroke-width="1"><path d="M20 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M46 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M72 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M98 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M124 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M150 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M176 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M202 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M228 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M254 116 l12 -12 h10 l-12 12z" fill="none"/><path d="M280 116 l12 -12 h10 l-12 12z" fill="none"/></g></svg>
    <div class="row"><span class="mono" id="preTime">04:58 · sunrise</span><span class="pct" id="prePct">0</span></div>
  </div>
</div>

<header class="hdr">
  <div class="wrap">
    <a class="brand" href="#top" aria-label="Fenlight Community Energy, back to top">
      <svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path d="M2 20h26" stroke="#1e1a15" stroke-width="1.6"/><path d="M7 20a8 8 0 0 1 16 0" fill="#f0a830" stroke="#1e1a15" stroke-width="1.6"/><path d="M4 25h22M8 28.5h14" stroke="#1e1a15" stroke-width="1.6"/><path d="M15 3v4M5.5 7.5l2.6 2.6M24.5 7.5l-2.6 2.6" stroke="#1e1a15" stroke-width="1.6" stroke-linecap="round"/></svg>
      <span>Fenlight <small>Community Energy</small></span>
    </a>
    <nav class="nav" id="nav" aria-label="Main">
      <a href="#estimate">Estimate</a>
      <a href="#sites">Sites</a>
      <a href="#shares">Shares</a>
      <a href="#how">How we run</a>
      <a href="#faq">Questions</a>
      <a class="btn" href="#join">Become a member <span class="arr" aria-hidden="true">→</span></a>
    </nav>
    <a class="btn" href="#join">Become a member <span class="arr" aria-hidden="true">→</span></a>
    <button class="menu-btn" aria-expanded="false" aria-controls="nav" aria-label="Open menu"><span></span><span></span></button>
  </div>
  <div class="dayline" aria-hidden="true"><i id="dayDot"></i></div>
</header>

<main id="main">
<section class="hero" id="top" aria-labelledby="heroTitle">
  <div class="stage" id="stage">
    <canvas id="sky" aria-hidden="true"></canvas>
    <div class="hero-copy wrap">
      <h1 id="heroTitle">1,412 neighbours own the <em>sunlight</em> on these roofs.</h1>
      <p class="lead">Fenlight is a community energy co-operative in the Wend valley. Members buy shares, we put panels on schools, barns and two grazed fields, and the money stays in the fen.</p>
      <div class="hero-cta">
        <a class="btn" href="#estimate">Estimate your roof <span class="arr" aria-hidden="true">→</span></a>
        <a class="btn ghost" href="#sites">See our 14 sites</a>
      </div>
    </div>
    <p class="hint mono" id="hint"><svg width="14" height="20" viewBox="0 0 14 20" aria-hidden="true"><rect x="1" y="1" width="12" height="18" rx="6" fill="none" stroke="currentColor" stroke-width="1.4"/><path d="M7 5v4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>Scroll to run the day</p>
    <div class="inst" role="group" aria-label="Today's output across all Fenlight sites">
      <div class="inst-top">
        <div>
          <div class="mono" style="color:var(--muted);font-size:11px;margin-bottom:6px">All 11 working sites · a clear May day</div>
          <div class="clock" id="clock" aria-live="off">06:00</div>
        </div>
        <div class="mono" id="sunInfo">Sun 4° · az 68°<br>Trackers 52° east</div>
      </div>
      <svg class="curve" id="curve" viewBox="0 0 320 86" role="img" aria-label="Output curve for the day">
        <defs><clipPath id="past"><rect id="pastRect" x="0" y="0" width="0" height="86"/></clipPath></defs>
        <line class="axis" x1="0" y1="72" x2="320" y2="72"/>
        <path class="ghostline" id="ghost"/>
        <g clip-path="url(#past)"><path class="area" id="curveArea"/><path class="line" id="line"/></g>
        <circle id="dot" r="3.5" fill="#f0a830" stroke="#1e1a15" stroke-width="1.4" cx="0" cy="72"/>
        <text x="0" y="84">05:00</text><text x="146" y="84">13:00</text><text x="290" y="84">21:00</text>
      </svg>
      <div class="stats">
        <div><b id="sNow">0.00 MW</b><span>output now</span></div>
        <div><b id="sToday">0.0 MWh</b><span>made so far today</span></div>
        <div><b id="sHomes">0</b><span>homes running on it now</span></div>
      </div>
      <div class="scrub">
        <label for="timeRange" class="mono" style="font-size:11px">Time</label>
        <input type="range" id="timeRange" min="270" max="1290" step="5" value="360" aria-valuetext="06:00">
        <button class="btn ghost tiny" id="playBtn" aria-pressed="false">Play day</button>
        <button class="btn ghost tiny" id="nowBtn">Now</button>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="about" aria-labelledby="aboutTitle">
  <div class="wrap sec-grid">
    <div class="stamp" data-time="380"><span class="t">06:20</span><span class="mono">01 — Who we are</span><svg viewBox="0 0 96 40" aria-hidden="true"></svg></div>
    <div class="about-grid">
      <div class="rv">
        <h2 id="aboutTitle" class="sr">Who we are</h2>
        <p class="statement">We started in 2015 with £31,000 from <mark>212 people</mark> and one school roof in Wendham. Now the fen owns <mark>3.56 megawatts</mark> of panels, and every pound they earn is counted at an AGM in a village hall.</p>
        <dl class="ledger">
          <div><dt>Members</dt><dd>1,412</dd></div>
          <div><dt>Raised in community shares</dt><dd>£3.9m</dd></div>
          <div><dt>Made last year</dt><dd>3,344 MWh</dd></div>
          <div><dt>Paid to the Fen Warmth Fund since 2016</dt><dd>£186,400</dd></div>
        </dl>
      </div>
      <div class="photos rv">
        <figure class="p1"><div class="cellwrap grain"><img src="assets/school.webp" width="1400" height="939" alt="A low brick primary school with a solar-covered roof across a reedy drain, under a big pale sky" loading="lazy" decoding="async"><div class="glass"><b>92 MWh</b>made here last year · 98 kWp</div><div class="cells"></div></div><figcaption>Site 01 · Wendham Primary, 98 kWp, our first roof</figcaption></figure>
        <figure class="p2"><div class="cellwrap grain"><img src="assets/installer.webp" width="900" height="1117" alt="A volunteer installer in a harness tightening a panel clamp on a corrugated barn roof" loading="lazy" decoding="async"><div class="cells"></div></div><figcaption>Burrow Fen barns, fitting day</figcaption></figure>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="estimate" aria-labelledby="estTitle">
  <div class="wrap sec-grid">
    <div class="stamp" data-time="540"><span class="t">09:00</span><span class="mono">02 — Estimate</span><svg viewBox="0 0 96 40" aria-hidden="true"></svg></div>
    <div>
      <div class="head rv">
        <h2 id="estTitle">What would your roof, or your field, make?</h2>
        <p class="lead">Set the area, turn the dial to the way it faces and pick your region. These are rough estimates with every assumption shown underneath; a volunteer surveyor checks the real thing for free.</p>
      </div>
      <div class="est rv">
        <form class="est-in" id="estForm" onsubmit="return false" aria-label="Estimator inputs">
          <fieldset style="border:0;padding:0;margin:0">
            <legend class="sr">What are you estimating?</legend>
            <div class="seg">
              <input type="radio" name="kind" id="kRoof" value="roof" checked><label for="kRoof">A roof</label>
              <input type="radio" name="kind" id="kField" value="field"><label for="kField">A field</label>
            </div>
          </fieldset>
          <div class="field">
            <div class="field-head"><label for="area" id="areaLbl">Usable roof area</label><output id="areaOut" for="area">40 m²</output></div>
            <input type="range" id="area" min="10" max="400" step="5" value="40">
            <p class="help" id="areaHelp">The part with no chimneys, skylights or shade. A 3-bed semi has about 20 m² on the sunny side.</p>
          </div>
          <div class="field" id="dirField">
            <div class="field-head"><span class="lbl" id="dirLbl">Which way does it face?</span></div>
            <div class="dialrow">
              <svg class="dial" id="dial" viewBox="0 0 150 150" role="slider" tabindex="0" aria-labelledby="dirLbl" aria-valuemin="0" aria-valuemax="355" aria-valuenow="180" aria-valuetext="South, 180 degrees"></svg>
              <div class="compass-out"><b id="dirName">South</b><span class="num" id="dirDeg" style="color:var(--muted);font-size:14px">180° · 100% of best</span><p class="help">Drag the yellow knob, or focus the dial and use the arrow keys.</p></div>
            </div>
          </div>
          <div class="field" id="pitchField">
            <div class="field-head"><label for="pitch">Roof pitch</label></div>
            <select id="pitch">
              <option value="flat">Flat (under 10°)</option>
              <option value="shallow">Shallow (10–25°)</option>
              <option value="standard" selected>Standard (25–45°)</option>
              <option value="steep">Steep (over 45°)</option>
            </select>
          </div>
          <div class="field" style="margin-bottom:0">
            <div class="field-head"><label for="region">Region</label></div>
            <select id="region">
              <option value="960" selected>The Fens &amp; East Anglia</option>
              <option value="1040">South coast</option>
              <option value="990">South West</option>
              <option value="920">Midlands</option>
              <option value="870">North of England</option>
              <option value="820">Scotland</option>
            </select>
          </div>
        </form>
        <div class="est-out" aria-live="polite" aria-atomic="false">
          <div>
            <div class="mono">Estimated output a year</div>
            <div class="big"><span id="oKwh">0</span><small>kWh</small></div>
          </div>
          <div class="kpis">
            <div><b id="oKwp">0</b><span>system size (kWp)</span></div>
            <div><b id="oHomes">0</b><span>homes' worth of power</span></div>
            <div><b id="oCo2">0</b><span>tonnes CO₂ avoided a year</span></div>
            <div><b id="oPay">0</b><span id="oPayLbl">years to pay back</span></div>
          </div>
          <div>
            <div class="mono" style="margin-bottom:6px">By month</div>
            <div class="months" id="months" aria-hidden="true"></div>
            <div class="mlabels" aria-hidden="true"><span>J</span><span>F</span><span>M</span><span>A</span><span>M</span><span>J</span><span>J</span><span>A</span><span>S</span><span>O</span><span>N</span><span>D</span></div>
          </div>
          <details class="assume">
            <summary>The assumptions behind these numbers</summary>
            <ul id="assumeList"></ul>
          </details>
          <div class="est-cta">
            <a class="btn" href="#join" id="hostLink"><span>Offer this <span id="hostWord">roof</span> to the co-op</span> <span class="arr" aria-hidden="true">→</span></a>
            <span class="badge">Estimate only</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="sites" aria-labelledby="sitesTitle">
  <div class="wrap sec-grid">
    <div class="stamp" data-time="690"><span class="t">11:30</span><span class="mono">03 — Sites</span><svg viewBox="0 0 96 40" aria-hidden="true"></svg></div>
    <div>
      <div class="head rv">
        <h2 id="sitesTitle">Fourteen sites, all within cycling distance.</h2>
        <p class="lead">Eleven are working, three are coming. Pick a pin for who hosts it, what it made last year and how many members paid for it.</p>
      </div>
      <div class="filters" role="group" aria-label="Filter sites">
        <button class="chip" data-f="all" aria-pressed="true">All <span class="c">14</span></button>
        <button class="chip" data-f="roof" aria-pressed="false"><i class="roof"></i>Roofs <span class="c">9</span></button>
        <button class="chip" data-f="field" aria-pressed="false"><i class="field"></i>Fields <span class="c">2</span></button>
        <button class="chip" data-f="plan" aria-pressed="false"><i class="plan"></i>Being planned <span class="c">3</span></button>
      </div>
      <p class="maptotals" id="mapTotals" aria-live="polite"></p>
      <div class="maplayout">
        <div>
          <div class="map" id="map">
            <svg viewBox="0 0 800 560" aria-hidden="true" id="mapSvg"></svg>
          </div>
          <ul class="sitelist" id="siteList" aria-label="All sites as a list"></ul>
        </div>
        <article class="card" id="siteCard" aria-live="polite"></article>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="shares" aria-labelledby="sharesTitle">
  <div class="wrap sec-grid">
    <div class="stamp" data-time="840"><span class="t">14:00</span><span class="mono">04 — Shares</span><svg viewBox="0 0 96 40" aria-hidden="true"></svg></div>
    <div>
      <div class="head rv">
        <h2 id="sharesTitle">Buy a few panels. Get a vote either way.</h2>
        <p class="lead">Shares cost £1 each, from £50 to £20,000. They pay a target interest and you get your money back over the life of the panels. They are not a bank account, and the interest is a target, not a promise.</p>
      </div>
      <div class="shares">
        <div class="rv">
          <label for="amt" class="mono" style="color:var(--muted)">How much would you put in?</label>
          <div class="amount"><span aria-hidden="true">£</span><input type="number" id="amt" min="50" max="20000" step="10" value="500" inputmode="numeric" aria-describedby="amtErr"></div>
          <p class="err" id="amtErr" role="alert"></p>
          <input type="range" id="amtRange" min="0" max="1000" value="390" aria-label="Share amount slider" aria-valuetext="£500">
          <div class="quick" role="group" aria-label="Quick amounts">
            <button type="button" data-v="100">£100</button><button type="button" data-v="500">£500</button><button type="button" data-v="2000">£2,000</button><button type="button" data-v="10000">£10,000</button>
          </div>
          <div class="mono" style="color:var(--muted)">What your money builds</div>
          <div class="panelgrid" id="panelGrid" aria-hidden="true"></div>
          <p class="num" style="font-size:14px;margin:0" id="panelText">About 1.1 panels at 430 W</p>
          <div class="vote"><b>1</b><p><strong>vote</strong> at the AGM, whether you put in £50 or £20,000. A co-op counts members, not money.</p></div>
        </div>
        <div class="share-out rv" aria-live="polite">
          <div class="mono" style="color:var(--muted);margin-bottom:6px">Illustration at a 4% target</div>
          <div class="row"><span>Interest in year one</span><b id="rY1">£20</b></div>
          <div class="row"><span>Interest over 20 years</span><b id="rTot">£280</b></div>
          <div class="row"><span>Capital back, years 5 to 20</span><b id="rCap">£31 a year</b></div>
          <div class="row"><span>Power your share makes a year</span><b id="rKwh">450 kWh</b></div>
          <div class="row"><span>Of which goes to the Fen Warmth Fund</span><b id="rFund">£3 a year</b></div>
          <p class="note">How we worked it out: interest at 4% on the balance still invested; no capital back in years 1–4, then 1/16 a year. £1,050 builds 1 kWp; 1 kWp makes about 940 kWh a year here. Community shares can lose value and are not covered by the FSCS.</p>
          <a class="btn" href="#join" id="toJoin" style="margin-top:16px">Apply for £500 of shares <span class="arr" aria-hidden="true">→</span></a>
        </div>
      </div>

      <div class="join" id="join">
        <div>
          <h3>Join the co-op</h3>
          <p style="color:var(--muted);margin-top:10px">We send you the share offer document first. Nothing is taken until you have read it and signed. Hosting a roof or field? Pick that below and a surveyor will ring you.</p>
        </div>
        <form id="joinForm" novalidate>
          <div class="grid2">
            <div class="inp"><label for="fName">Full name</label><input type="text" id="fName" autocomplete="name" aria-describedby="eName"><span class="err" id="eName"></span></div>
            <div class="inp"><label for="fEmail">Email</label><input type="email" id="fEmail" autocomplete="email" aria-describedby="eEmail"><span class="err" id="eEmail"></span></div>
          </div>
          <div class="grid2">
            <div class="inp"><label for="fPost">Postcode</label><input type="text" id="fPost" autocomplete="postal-code" aria-describedby="ePost" placeholder="PE14 9AB"><span class="err" id="ePost"></span></div>
            <div class="inp"><label for="fWant">I'd like to</label>
              <select id="fWant"><option value="shares">Buy shares</option><option value="host">Host panels on my roof or field</option><option value="news">Just hear about the next share offer</option></select></div>
          </div>
          <div class="inp" id="fAmtWrap"><label for="fAmt">Amount (£50 – £20,000)</label><input type="number" id="fAmt" min="50" max="20000" value="500" aria-describedby="eAmt"><span class="err" id="eAmt"></span></div>
          <label class="check"><input type="checkbox" id="fAge" aria-describedby="eAge"><span>I'm 16 or over and I understand community shares can lose value.</span></label>
          <span class="err" id="eAge" style="display:block;margin:-12px 0 14px"></span>
          <button class="btn" type="submit">Send me the share offer <span class="arr" aria-hidden="true">→</span></button>
        </form>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="how" aria-labelledby="howTitle">
  <div class="wrap sec-grid">
    <div class="stamp" data-time="1050"><span class="t">17:30</span><span class="mono">05 — How we run</span><svg viewBox="0 0 96 40" aria-hidden="true"></svg></div>
    <div>
      <div class="head rv">
        <h2 id="howTitle">Where every pound of sunlight goes.</h2>
        <p class="lead">Our hosts buy the power at 18p a kWh, below their old tariff. What's left is shared out like this every year, and the split is voted on at the AGM.</p>
      </div>
      <div class="pound rv" id="pound" role="group" aria-label="How £1 of income is spent"></div>
      <div class="pound-detail" id="poundDetail" aria-live="polite"></div>
      <div class="how-grid">
        <ol class="rules rv">
          <li><div><b>One member, one vote</b><span>Shares change what you're paid back, never how much say you have.</span></div></li>
          <li><div><b>Nine volunteer directors</b><span>Elected by members at the AGM, three seats up each March. Anyone with a share can stand.</span></div></li>
          <li><div><b>Interest is capped at 5%</b><span>The rules stop us paying more than that, so the surplus goes to the fund, not to investors.</span></div></li>
          <li><div><b>Twelve pence in every pound</b><span>The Fen Warmth Fund pays for loft insulation and heating advice in the parishes we serve.</span></div></li>
          <li><div><b>An asset lock</b><span>If Fenlight ever closes, the panels pass to another community energy group, not to a buyer.</span></div></li>
        </ol>
        <figure class="agm rv" style="margin:0"><div class="cellwrap grain"><img src="assets/agm.webp" width="1400" height="939" alt="Members on stacking chairs in a village hall holding up green voting cards" loading="lazy" decoding="async"><div class="glass dark"><b>188 hands</b>for the Hythe Lode field</div><div class="cells"></div></div><figcaption>AGM, Saltmere village hall, March 2026: 188 members voted on the Hythe Lode field.</figcaption></figure>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="faq" aria-labelledby="faqTitle">
  <div class="wrap sec-grid">
    <div class="stamp" data-time="1200"><span class="t">20:00</span><span class="mono">06 — Questions</span><svg viewBox="0 0 96 40" aria-hidden="true"></svg></div>
    <div>
      <div class="head rv"><h2 id="faqTitle">Asked at the last open evening.</h2><p class="lead">Ring Maggie on the members' line if yours isn't here. She answers on Tuesdays and Thursdays.</p></div>
      <div class="faq rv">
        <details><summary>Do I have to live in the fen to buy shares?</summary><div class="a"><p>No, anyone over 16 in the UK can join. Local members get first refusal when an offer is oversubscribed, and about 70% of members live within ten miles.</p></div></details>
        <details><summary>Can I get my money out early?</summary><div class="a"><p>You can ask to withdraw after three years. The board pays withdrawals from the reserve when it can, usually within six months; it can say no if paying out would put the co-op at risk. You can't sell shares to someone else.</p></div></details>
        <details><summary>We host panels on our roof. Who fixes them?</summary><div class="a"><p>We do. The co-op owns, insures and maintains everything for 20 years. You buy the power the panels make at a fixed price, and at the end the panels are yours for £1 if you want them.</p></div></details>
        <details><summary>What happens to the sheep at Saltmere Drove?</summary><div class="a"><p>They stay. The panels sit 1.1 m off the ground and Tom Pell's flock grazes under them from April to October. The grass is shorter and the vet bills, he says, are the same.</p></div></details>
        <details><summary>Why trackers on the fields but not on the roofs?</summary><div class="a"><p>On a field the rows can turn east in the morning and west in the evening, which gets about 15% more out of a long summer day. Roofs face where they face, so we fix the panels to them.</p></div></details>
        <details><summary>Is the estimator accurate?</summary><div class="a"><p>It's within about 15% for most roofs. It ignores shading from trees and chimneys and assumes average weather, which is why a surveyor visits before anything is signed.</p></div></details>
      </div>
    </div>
  </div>
</section>
</main>

<footer class="foot">
  <div class="sunset" aria-hidden="true"></div><div class="horizon" aria-hidden="true"></div>
  <div class="wrap">
    <p class="foot-big">Fenlight</p>
    <div class="foot-grid">
      <div><h4>21:30 · Sunset over Hythe Lode</h4><p style="margin:0;color:var(--on-dark-2)">The panels are flat for the night. Tomorrow's sunrise is at 04:58.</p></div>
      <div><h4>Visit</h4><p style="margin:0">The Old Pump House<br>Saltmere Drove<br>Open Tuesday &amp; Thursday, 10–4</p></div>
      <div><h4>Members' line</h4><a href="mailto:members@fenlight.example">members@fenlight.example</a><a href="#join">Join or host panels</a><a href="#faq">Questions</a></div>
      <div><h4>Read</h4><a href="#how">Our rules, in plain English</a><a href="#sites">Last year's output by site</a><a href="#top">Back to sunrise ↑</a></div>
    </div>
    <div class="fine"><span>Fenlight Community Energy is a fictional co-operative made for this design. All figures are illustrative.</span><span>Registered as a community benefit society (demo).</span></div>
  </div>
</footer>

<script>
(()=>{
"use strict";
const RM = matchMedia('(prefers-reduced-motion: reduce)');
const $ = s=>document.querySelector(s), $$ = s=>[...document.querySelectorAll(s)];
const clamp=(v,a,b)=>Math.max(a,Math.min(b,v)), lerp=(a,b,t)=>a+(b-a)*t;
const fmt=(n,d=0)=>n.toLocaleString('en-GB',{minimumFractionDigits:d,maximumFractionDigits:d});
const hhmm=m=>{m=Math.round(m);const h=Math.floor(m/60)%24,mm=m%60;return String(h).padStart(2,'0')+':'+String(mm).padStart(2,'0')};

/* ---------- Sun model: a clear late-May day in the fens ---------- */
const NOON=780, HALF=480, MAXE=62, T0=270, T1=1290;
function sunAt(t){
  const h=(t-NOON)/HALF;                       // -1 sunrise, +1 sunset
  const e=MAXE*Math.cos(h*Math.PI/2);          // elevation in degrees
  const az=180+130*clamp(h,-1.25,1.25);        // azimuth, degrees from north
  return {h,e,az};
}
const CAP=3.558; // MWp across 11 working sites
const clouds=[[690,22,.32],[905,35,.22],[1010,14,.4]];
function powerAt(t){
  const {e}=sunAt(t); if(e<=0) return 0;
  let p=CAP*.84*Math.pow(Math.sin(e*Math.PI/180),.9);
  for(const [c,w,d] of clouds) p*=1-d*Math.exp(-(((t-c)/w)**2));
  return p;
}
// cumulative MWh per minute
const CUM=new Float32Array(T1-T0+2);
for(let t=T0+1;t<=T1+1;t++) CUM[t-T0]=CUM[t-T0-1]+powerAt(t)/60;

/* ---------- colour helpers ---------- */
const hex=h=>[parseInt(h.slice(1,3),16),parseInt(h.slice(3,5),16),parseInt(h.slice(5,7),16)];
const mix=(a,b,t)=>[lerp(a[0],b[0],t),lerp(a[1],b[1],t),lerp(a[2],b[2],t)];
const rgb=(c,a=1)=>`rgba(${c[0]|0},${c[1]|0},${c[2]|0},${a})`;
const SKY=[ // elevation, zenith, horizon
  [-10,'#0d1726','#1d2940'],[-3,'#1f2f4a','#a86450'],[1,'#3d5878','#ee9a5c'],[6,'#5a7ea3','#f4c58e'],
  [14,'#6f98c0','#efdcbc'],[28,'#7aa6cf','#e3e8e2'],[62,'#6a9dd0','#e2ebee']].map(r=>[r[0],hex(r[1]),hex(r[2])]);
function skyAt(e){
  for(let i=0;i<SKY.length-1;i++){const a=SKY[i],b=SKY[i+1];
    if(e<=b[0]){const t=clamp((e-a[0])/(b[0]-a[0]),0,1);return [mix(a[1],b[1],t),mix(a[2],b[2],t)];}}
  const l=SKY[SKY.length-1];return [l[1],l[2]];
}

/* ---------- HERO canvas ---------- */
const stage=$('#stage'), cv=$('#sky');
let ctx=null; try{ctx=cv.getContext('2d');}catch(e){}
if(!ctx) stage.classList.add('nocanvas');
let W=0,H=0,DPR=1, state={t:360}, dirty=true;
function resize(){
  DPR=Math.min(2,window.devicePixelRatio||1);
  W=stage.clientWidth;H=stage.clientHeight;
  if(ctx){cv.width=Math.round(W*DPR);cv.height=Math.round(H*DPR);ctx.setTransform(DPR,0,0,DPR,0,0);}
  dirty=true;
}
// seeded random
function rng(s){return()=>{s=(s*16807)%2147483647;return (s-1)/2147483646}}
const R=rng(7); const STARS=Array.from({length:90},()=>[R(),R()*.55,R()*1.2+.3]);
const CLOUDS=Array.from({length:7},(_,i)=>[R(),.08+R()*.28,90+R()*170,.5+R()*.5]);

function draw(){
  if(!ctx) return;
  const t=state.t, {e,az}=sunAt(t);
  const [zen,hor]=skyAt(e);
  const mobile=W<760;
  const HY=Math.round(H*(mobile?.6:.6));
  const f=Math.max(W,H*1.1)*.62;
  const camH=4.2, cx=W*(mobile?.62:.5);
  const L=clamp((e+5)/26,.1,1);          // ground light
  const warm=clamp(1-(e-2)/16,0,1)*(e>-4?1:0); // golden hour warmth

  // sky
  let g=ctx.createLinearGradient(0,0,0,HY);
  g.addColorStop(0,rgb(zen));g.addColorStop(1,rgb(hor));
  ctx.fillStyle=g;ctx.fillRect(0,0,W,HY+1);
  // stars
  if(e<-1){const a=clamp((-1-e)/6,0,1)*.85;ctx.fillStyle=`rgba(242,236,226,${a})`;
    for(const s of STARS){ctx.beginPath();ctx.arc(s[0]*W,s[1]*HY,s[2],0,7);ctx.fill();}}
  // sun
  const sx=cx+((az-180)/130)*W*(mobile?.5:.44), sy=HY-(e/MAXE)*(HY-90);
  const sunC=mix(hex('#ff8a3d'),hex('#fff4d8'),clamp((e-1)/14,0,1));
  if(e>-6){
    const rg=ctx.createRadialGradient(sx,sy,0,sx,sy,Math.max(W,H)*.45);
    rg.addColorStop(0,rgb(sunC,.55*clamp((e+6)/6,0,1)));rg.addColorStop(.12,rgb(sunC,.18));rg.addColorStop(1,rgb(sunC,0));
    ctx.fillStyle=rg;ctx.fillRect(0,0,W,HY);
    ctx.save();ctx.beginPath();ctx.rect(0,0,W,HY);ctx.clip();
    ctx.fillStyle=rgb(sunC);ctx.beginPath();ctx.arc(sx,sy,mobile?13:18,0,7);ctx.fill();ctx.restore();
  }
  // clouds (drift with time of day)
  for(const c of CLOUDS){
    const x=((c[0]+t/2400)%1.2-.1)*W, y=c[1]*HY+60, w=c[2]*(mobile?.7:1);
    const col=mix(mix(hor,[255,255,255],.35*L),hex('#e9a27a'),warm*.5);
    ctx.fillStyle=rgb(col,.5*c[3]*clamp((e+8)/10,.25,1));
    for(let k=0;k<4;k++){ctx.beginPath();ctx.ellipse(x+k*w*.28,y-(k%2)*8,w*.32,w*.09,0,0,7);ctx.fill();}
  }
  // distant land silhouette
  const far=mix(mix(hor,hex('#2d3a3a'),.55),hex('#11161c'),1-L);
  ctx.fillStyle=rgb(far);
  ctx.fillRect(0,HY-3,W,4);
  const sil=(x,w,h)=>ctx.fillRect(x,HY-h,w,h+1);
  for(let i=0;i<26;i++){const x=W*(.03+i*.011);ctx.beginPath();ctx.ellipse(x,HY-12-(i%3)*2,5,13+(i%4)*2,0,0,7);ctx.fill();} // poplars
  const ct=W*.79; sil(ct,12,30);sil(ct+2,8,36);ctx.beginPath();ctx.moveTo(ct+1,HY-36);ctx.lineTo(ct+6,HY-52);ctx.lineTo(ct+11,HY-36);ctx.fill(); // church
  sil(ct-60,46,9);sil(ct+30,70,7);sil(W*.44,36,8);ctx.beginPath();ctx.moveTo(W*.44,HY-8);ctx.lineTo(W*.44+18,HY-15);ctx.lineTo(W*.44+36,HY-8);ctx.fill();
  const wp=W*.6;sil(wp,3,24);ctx.strokeStyle=rgb(far);ctx.lineWidth=1.5;for(let k=0;k<4;k++){const a=k*Math.PI/2+t/40;ctx.beginPath();ctx.moveTo(wp+1.5,HY-24);ctx.lineTo(wp+1.5+Math.cos(a)*11,HY-24+Math.sin(a)*11);ctx.stroke();}

  // ground
  const P=(X,Y,Z)=>[cx+X*f/Z, HY+(camH-Y)*f/Z];
  const base=[hex('#6f7d3e'),hex('#8a7a4c'),hex('#5d6b35'),hex('#9b8a55')];
  const tint=c=>{let k=mix(c,hex('#d08a4a'),warm*.28);k=mix(hex('#0f141a'),k,L);return k;};
  ctx.fillStyle=rgb(tint(base[0]));ctx.fillRect(0,HY,W,H-HY);
  const Zn=3.2,Zf=4000;
  for(let k=-24;k<24;k++){
    const x0=k*34,x1=x0+34;
    const a=P(x0,0,Zf),b=P(x1,0,Zf),c=P(x1,0,Zn),d=P(x0,0,Zn);
    ctx.fillStyle=rgb(tint(base[(k+48)%4]));
    ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.lineTo(...c);ctx.lineTo(...d);ctx.fill();
  }
  // cross boundaries
  ctx.strokeStyle=rgb(tint(hex('#3e4a26')),.55);ctx.lineWidth=1;
  for(const z of [46,95,170,320,640]){const y=HY+camH*f/z;ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(W,y);ctx.stroke();}
  // drain reflecting the sky
  {const x0=-42,x1=-39.5;const a=P(x0,0,Zf),b=P(x1,0,Zf),c=P(x1,0,Zn),d=P(x0,0,Zn);
   const wg=ctx.createLinearGradient(0,HY,0,H);wg.addColorStop(0,rgb(hor));wg.addColorStop(1,rgb(mix(zen,[0,0,0],.25)));
   ctx.fillStyle=wg;ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.lineTo(...c);ctx.lineTo(...d);ctx.fill();}
  // haze
  g=ctx.createLinearGradient(0,HY-30,0,HY+60);g.addColorStop(0,rgb(hor,0));g.addColorStop(.4,rgb(hor,.45));g.addColorStop(1,rgb(hor,0));
  ctx.fillStyle=g;ctx.fillRect(0,HY-30,W,90);

  // trackers
  const er=e*Math.PI/180, ar=az*Math.PI/180;
  const sv=[Math.cos(er)*Math.sin(ar-Math.PI), Math.sin(er), -Math.cos(er)*Math.cos(ar)]; // x=west+, y=up, z=south+
  let th=0;
  if(e>0){th=Math.atan2(sv[0],sv[1]);th=clamp(th,-.96,.96);if(e<6)th*=e/6;}
  state.tilt=th;
  const n=[Math.sin(th),Math.cos(th),0];
  const lit=Math.max(0,n[0]*sv[0]+n[1]*sv[1]+n[2]*sv[2])*(e>0?1:0);
  const pw=2.3, pl=2.0, hub=1.5;
  const rows=[];for(let X=-30;X<=30;X+=6.4)rows.push(X+2.2);
  const zs=[];for(let z=74;z>=5;z-=2.25)zs.push(z);
  const cw=Math.cos(th)*pw/2, sw=Math.sin(th)*pw/2;
  // shadows
  if(e>.5){
    const k=1/Math.max(sv[1],.12);
    ctx.fillStyle=`rgba(15,20,18,${.28*L})`;
    for(const z of zs)for(const X of rows){
      const pts=[[X-cw,hub+sw,z-pl/2],[X+cw,hub-sw,z-pl/2],[X+cw,hub-sw,z+pl/2],[X-cw,hub+sw,z+pl/2]].map(p=>{
        const s=p[1]*k;return P(p[0]-sv[0]*s,0,Math.max(1.5,p[2]-sv[2]*s));});
      ctx.beginPath();ctx.moveTo(...pts[0]);for(let i=1;i<4;i++)ctx.lineTo(...pts[i]);ctx.fill();
    }
  }
  const panelBase=hex('#16243a'), panelLit=hex('#56799e');
  const refl=mix(hor,zen,.5);
  const pc=mix(mix(panelBase,panelLit,lit*L*.9),refl,.18+.12*L);
  const edge=mix(pc,hex('#e8e2d6'),.45);
  for(const z of zs){
    const near=z<26;
    for(const X of rows){
      const q=[P(X-cw,hub+sw,z-pl/2),P(X+cw,hub-sw,z-pl/2),P(X+cw,hub-sw,z+pl/2),P(X-cw,hub+sw,z+pl/2)];
      if(q[0][0]>W+40&&q[3][0]>W+40)continue; if(q[1][0]<-40&&q[2][0]<-40)continue;
      if(near){const a=P(X,hub,z),b=P(X,0,z);ctx.strokeStyle=rgb(mix(hex('#2a2a2a'),edge,.3));ctx.lineWidth=Math.max(1,f/z*.08);ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.stroke();}
      const sh=(X<0?1:-1)*sv[0]>0?0:.04;
      ctx.fillStyle=rgb(mix(pc,[255,255,255],sh));
      ctx.beginPath();ctx.moveTo(...q[0]);for(let i=1;i<4;i++)ctx.lineTo(...q[i]);ctx.closePath();ctx.fill();
      if(z<40){ctx.strokeStyle=rgb(edge,.7);ctx.lineWidth=Math.max(.5,f/z*.03);ctx.stroke();}
    }
  }
  // sun glint on panels at golden hour
  if(e>0&&e<20){ctx.globalCompositeOperation='lighter';const gg=ctx.createRadialGradient(sx,H*.86,0,sx,H*.86,W*.35);gg.addColorStop(0,rgb(sunC,.16*(1-e/20)));gg.addColorStop(1,rgb(sunC,0));ctx.fillStyle=gg;ctx.fillRect(0,HY,W,H-HY);ctx.globalCompositeOperation='source-over';}
  // night veil
  if(e<0){ctx.fillStyle=`rgba(8,14,24,${clamp(-e/10,0,.45)})`;ctx.fillRect(0,HY,W,H-HY);}
}

/* ---------- instrument panel ---------- */
const X0=T0,X1=T1, cX=t=>(t-X0)/(X1-X0)*320, cY=p=>72-p/CAP*66;
(function buildCurve(){
  let d='';for(let t=X0;t<=X1;t+=5){d+=(t===X0?'M':'L')+cX(t).toFixed(1)+' '+cY(powerAt(t)).toFixed(1);}
  $('#ghost').setAttribute('d',d);$('#line').setAttribute('d',d);
  $("#curveArea").setAttribute("d",d+' L320 72 L0 72Z');
})();
const tr=$('#timeRange');
let shownT=-1;
function updateUI(){
  const t=state.t; if(Math.abs(t-shownT)<.2) return; shownT=t;
  const {e,az}=sunAt(t), p=powerAt(t);
  $('#clock').textContent=hhmm(t);
  const tiltDeg=Math.round(Math.abs((state.tilt||0)*180/Math.PI));
  $('#sunInfo').innerHTML=(e>0?`Sun ${Math.round(e)}° · az ${Math.round(az)}°`:`Sun below horizon`)+'<br>'+(e>0&&tiltDeg>1?`Trackers ${tiltDeg}° ${state.tilt<0?'east':'west'}`:'Trackers stowed flat');
  $('#pastRect').setAttribute('width',cX(t));
  $('#dot').setAttribute('cx',cX(t));$('#dot').setAttribute('cy',cY(p));
  $('#sNow').textContent=fmt(p,2)+' MW';
  $('#sToday').textContent=fmt(CUM[clamp(Math.round(t)-T0,0,CUM.length-1)],1)+' MWh';
  $('#sHomes').textContent=fmt(Math.round(p*1000/.42/10)*10);
  tr.value=Math.round(t/5)*5; tr.setAttribute('aria-valuetext',hhmm(t)+', '+fmt(p,2)+' megawatts');
  stage.classList.toggle('day',e>=0);
}

/* ---------- time driving: scroll, slider, play ---------- */
const hero=$('#top');
const sticky=()=>!RM.matches;
const S0=360,S1=1245; // scroll maps 06:00 -> 20:45
let lastP=null;
function scrollP(){const r=hero.getBoundingClientRect();const span=r.height-innerHeight;return span>0?clamp(-r.top/span,0,1):0;}
function onScroll(){
  if(sticky()){
    const p=scrollP();
    if(lastP===null) state.t=lerp(S0,S1,p);
    else if(p!==lastP){ // relative, so a slider-set time is not thrown away
      if(p<=0) state.t=S0; else if(p>=1) state.t=S1; else state.t=clamp(state.t+(p-lastP)*(S1-S0),T0,T1);
      stopPlay();
    }
    lastP=p; $('#hint').style.opacity=p>.04?0:1;
  }
  const doc=document.documentElement;const pp=clamp(scrollY/(doc.scrollHeight-innerHeight),0,1);
  $('#dayDot').style.left=(pp*100)+'%';
  dirty=true;
}
tr.addEventListener('input',()=>{state.t=+tr.value;stopPlay();dirty=true;});
$('#nowBtn').addEventListener('click',()=>{const d=new Date();state.t=clamp(d.getHours()*60+d.getMinutes(),T0,T1);stopPlay();dirty=true;});
let playing=false;
const playBtn=$('#playBtn');
function stopPlay(){if(!playing)return;playing=false;playBtn.setAttribute('aria-pressed','false');playBtn.textContent='Play day';}
playBtn.addEventListener('click',()=>{
  if(playing){stopPlay();return;}
  if(state.t>=T1-5) state.t=T0;
  playing=true;playBtn.setAttribute('aria-pressed','true');playBtn.textContent='Pause';
});
let heroVisible=true, last=performance.now();
new IntersectionObserver(es=>{heroVisible=es[0].isIntersecting; if(!heroVisible) stopPlay();}).observe(stage);
document.addEventListener('visibilitychange',()=>{if(document.hidden)stopPlay();});
function frame(now){
  const dt=Math.min(64,now-last);last=now;
  if(playing){state.t=Math.min(T1,state.t+dt*(RM.matches?.05:.09));if(state.t>=T1)stopPlay();dirty=true;}
  if(heroVisible&&!document.hidden){
    const GL=FEN.gl;
    if(GL){ if(dirty||GL.busy()) GL.render(state.t,now,dirty); }
    else if(dirty) draw();
    if(dirty) updateUI();
    dirty=false;
  }
  requestAnimationFrame(frame);
}
stage.addEventListener('pointermove',e=>{const r=stage.getBoundingClientRect();FEN.pointer.x=(e.clientX-r.left)/r.width*2-1;FEN.pointer.y=(e.clientY-r.top)/r.height*2-1;});
stage.addEventListener('pointerleave',()=>{FEN.pointer.x=0;FEN.pointer.y=0;});
addEventListener('scroll',onScroll,{passive:true});
addEventListener('resize',()=>{resize();FEN.gl&&FEN.gl.resize(W,H);onScroll();});
/* shared with the three.js module */
const FEN=window.FEN={state,sunAt,skyAt,RM,stage,pointer:{x:0,y:0},gl:null,
  size:()=>[W,H],
  glReady(api){FEN.gl=api;api.resize(W,H);dirty=true;done('gl');},
  glFail(err){console.info('Fenlight: 3D scene unavailable, using the 2D landscape.',err&&err.message||'');done('gl');done('glb');},
  glbDone(){done('glb');},
  wake(){dirty=true;}};

/* ---------- preloader: real progress, sunrise counter, panel-cell wipe ---------- */
const pre=$('#pre'),preUi=$('#preUi');
const steps={fonts:0,load:0,gl:0,glb:0};
function done(k){steps[k]=1;}
const cols=innerWidth<600?5:12, rows=Math.ceil(innerHeight/(innerWidth/cols));
pre.style.setProperty('--c',cols);
for(let i=0;i<cols*rows;i++){const c=document.createElement('i');pre.appendChild(c);}
document.fonts&&document.fonts.ready.then(()=>done('fonts'));
if(document.readyState==='complete')done('load');else addEventListener('load',()=>done('load'));
const preStart=performance.now();let shown=0,preDone=false;
function preTick(now){
  if(preDone)return;
  const real=(steps.fonts+steps.load+steps.gl*2+steps.glb)/5*100;
  const target=now-preStart>6000?100:real;
  shown+=Math.max(target>shown?.6:0,(target-shown)*.08);shown=Math.min(shown,target);
  $('#prePct').textContent=Math.floor(shown);
  const k=shown/100, x=20+k*280, y=96-Math.sin(k*Math.PI)*92;
  const sun=$('#preSun');sun.setAttribute('cx',x);sun.setAttribute('cy',Math.min(y+(k<.08?14*(1-k/.08):0),110));
  $('#preTime').textContent=hhmm(298+k*360)+(k<.1?' · sunrise':'');
  if(shown>=99.5){finishPre();return;}
  requestAnimationFrame(preTick);
}
function finishPre(){
  preDone=true;$('#prePct').textContent='100';
  preUi.classList.add('go');
  const cells=[...pre.children];
  if(RM.matches){pre.style.transition='opacity .2s';pre.style.opacity=0;}
  else cells.forEach((c,i)=>{const col=i%cols,row=Math.floor(i/cols);c.style.transitionDelay=((rows-row)*45+col*18+Math.random()*60)+'ms';});
  requestAnimationFrame(()=>pre.classList.add('go'));
  setTimeout(()=>{pre.hidden=true;preUi.hidden=true;document.documentElement.classList.add('loaded');},RM.matches?300:rows*45+cols*18+700);
}
requestAnimationFrame(preTick);
// if the 3D module has not even started after 3 s (blocked CDN, old browser), finish on the 2D landscape; 3D can still fade in later
setTimeout(()=>{if(!window.FEN_3D_STARTED){done("gl");done("glb");}},3000);
RM.addEventListener?.('change',()=>{lastP=null;onScroll();});
resize();
if(!sticky()){const d=new Date();const m=d.getHours()*60+d.getMinutes();state.t=(m>T0&&m<T1)?m:780;}
onScroll();
requestAnimationFrame(frame);

/* ---------- section stamps: tiny sun arcs ---------- */
$$('.stamp').forEach(s=>{
  const t=+s.dataset.time, {e,az}=sunAt(t), svg=s.querySelector('svg');
  const x=48+((az-180)/130)*44, y=36-(e/MAXE)*32;
  svg.innerHTML=`<path d="M4 36 Q48 -28 92 36"/><line x1="0" y1="36" x2="96" y2="36"/><circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="5"/>`;
});

/* ---------- module cells on photos ---------- */
$$('.cells').forEach(c=>{const r=4;for(let y=0;y<r;y++)for(let x=0;x<8;x++){const i=document.createElement('i');i.style.setProperty('--d',((7-x)*55+y*35+((x*7+y*3)%5)*20)+'ms');c.appendChild(i);}});
const io2=new IntersectionObserver(es=>es.forEach(en=>{if(en.isIntersecting){en.target.classList.add('in');io2.unobserve(en.target);}}),{threshold:.35});
$$('.cells').forEach(c=>io2.observe(c));
/* ---------- reveal ---------- */
const io=new IntersectionObserver(es=>es.forEach(en=>{if(en.isIntersecting){en.target.classList.add('in');io.unobserve(en.target);}}),{rootMargin:'0px 0px -8% 0px'});
$$('.rv').forEach(el=>io.observe(el));

/* ---------- number tween ---------- */
function tween(el,to,d=0,suffix=''){
  const from=parseFloat(el.dataset.v||'0'); el.dataset.v=to;
  if(RM.matches||!isFinite(from)){el.textContent=fmt(to,d)+suffix;return;}
  const st=performance.now();
  const step=n=>{const k=clamp((n-st)/380,0,1),q=1-Math.pow(1-k,3);el.textContent=fmt(lerp(from,to,q),d)+suffix;if(k<1)requestAnimationFrame(step);};
  requestAnimationFrame(step);
}

/* ---------- ESTIMATOR ---------- */
const MONTH=[.03,.05,.08,.11,.13,.14,.13,.11,.09,.06,.04,.03];
const months=$('#months');MONTH.forEach(()=>{const d=document.createElement('div');months.appendChild(d);});
const dial=$('#dial');
let dir=180;
(function buildDial(){
  let s='<circle class="ring" cx="75" cy="75" r="68"/><path class="arc" id="dArc"/>';
  for(let a=0;a<360;a+=15){const r=a%90?62:57,ra=a*Math.PI/180;s+=`<line class="tick" x1="${75+Math.sin(ra)*r}" y1="${75-Math.cos(ra)*r}" x2="${75+Math.sin(ra)*67}" y2="${75-Math.cos(ra)*67}"/>`;}
  [['N',0],['E',90],['S',180],['W',270]].forEach(([l,a])=>{const ra=a*Math.PI/180;s+=`<text x="${75+Math.sin(ra)*46}" y="${75-Math.cos(ra)*46}">${l}</text>`;});
  s+='<g id="house"><rect x="62" y="64" width="26" height="22" fill="#e7ddcc" stroke="#1e1a15" stroke-width="1.4"/><line x1="62" y1="75" x2="88" y2="75" stroke="#1e1a15" stroke-width="1.4"/><rect x="63.5" y="76" width="23" height="8.5" fill="#24394a"/><path d="M75 88 l-4 6 h8z" fill="#a03d21"/></g>';
  s+='<circle class="knob" id="knob" r="9" cx="75" cy="7"/>';
  dial.innerHTML=s;
})();
const DIRS=['North','North-east','East','South-east','South','South-west','West','North-west'];
function orientK(){const p=$('#pitch').value;return {flat:[0,.89],shallow:[.12,.97],standard:[.21,1],steep:[.3,.94]}[p];}
function setDir(a){dir=((Math.round(a/5)*5)%360+360)%360;estimate();}
function estimate(){
  const kind=document.querySelector('input[name=kind]:checked').value, roof=kind==='roof';
  const area=+$('#area').value, yieldK=+$('#region').value;
  const [k,pk]=orientK();
  const factor=roof?(k===0?pk:pk*((1-k)+k*Math.cos((dir-180)*Math.PI/180))):1;
  const kwp=roof?area*.7*.21:area*500;
  const kwh=kwp*yieldK*factor;
  let cost,value,pay;
  if(roof){cost=kwp*clamp(1500-Math.max(0,kwp-10)*4,1100,1500);value=kwh*.21;pay=cost/value;}
  else{cost=kwp*650;value=kwh*.085-kwp*12;pay=cost/value;}
  $('#areaOut').textContent=roof?fmt(area)+' m²':fmt(area,1)+' ha';
  tween($('#oKwh'),Math.round(kwh/10)*10);
  tween($('#oKwp'),kwp,kwp<100?1:0);
  tween($('#oHomes'),kwh/2700,kwh/2700<10?1:0);
  tween($('#oCo2'),kwh*.15/1000,1);
  tween($('#oPay'),pay,1);
  $('#oPayLbl').textContent=roof?'years to pay back (if you buy it)':'years for the co-op to pay back';
  const max=Math.max(...MONTH);
  [...months.children].forEach((d,i)=>{d.style.height=(MONTH[i]/max*100)+'%';d.dataset.v=fmt(Math.round(kwh*MONTH[i]))+' kWh';});
  // dial
  const ra=dir*Math.PI/180;
  $('#knob').setAttribute('cx',75+Math.sin(ra)*68);$('#knob').setAttribute('cy',75-Math.cos(ra)*68);
  $('#house').setAttribute('transform',`rotate(${dir-180} 75 75)`);
  // good-direction arc: south-ish ±60
  const arc=(a0,a1,r)=>{const p=a=>[75+Math.sin(a*Math.PI/180)*r,75-Math.cos(a*Math.PI/180)*r];const s=p(a0),e=p(a1);return `M75 75 L${s[0]} ${s[1]} A${r} ${r} 0 0 1 ${e[0]} ${e[1]}Z`;};
  $('#dArc').setAttribute('d',arc(120,240,67));
  const name=DIRS[Math.round(dir/45)%8];
  const pct=Math.round(factor/(pk||1)*100);
  $('#dirName').textContent=k===0?'Any direction':name;
  $('#dirDeg').textContent=k===0?'Flat roofs: racked east–west':`${dir}° · ${pct}% of the best`;
  dial.setAttribute('aria-valuenow',dir);dial.setAttribute('aria-valuetext',`${name}, ${dir} degrees`);
  dial.setAttribute('aria-disabled',String(!roof||k===0));
  $('#dirField').hidden=!roof; $('#pitchField').hidden=!roof;
  $('#hostWord').textContent=roof?'roof':'field';
  const A=roof?[
    `Panels cover 70% of the area you give, at 0.21 kWp per m² (430 W panels).`,
    `Your region makes ${fmt(yieldK)} kWh per kWp a year facing south at 35°, with average weather.`,
    `Direction and pitch scale that by ${fmt(factor*100)}% (${k===0?'flat roof, east–west racking':name.toLowerCase()+', '+$('#pitch').selectedOptions[0].text.toLowerCase()}).`,
    `A typical home uses 2,700 kWh a year. Grid carbon is taken as 0.15 kg CO₂ per kWh.`,
    `Payback assumes you pay about £${fmt(Math.round(cost/kwp))} per kWp installed, use half the power at 27p and export half at 15p. If the co-op funds it, you pay nothing up front and buy the power at 18p.`,
    `Ignores shading, panel ageing (about 0.5% a year) and future prices.`]:[
    `Ground-mounted arrays fit about 500 kWp per hectare, leaving room to graze between rows.`,
    `Your region makes ${fmt(yieldK)} kWh per kWp a year; single-axis trackers and spacing roughly cancel out.`,
    `A typical home uses 2,700 kWh a year. Grid carbon is taken as 0.15 kg CO₂ per kWh.`,
    `Payback is the co-op's: £650 per kWp including the grid connection, power sold at 8.5p, £12 per kWp a year upkeep.`,
    `The landowner is paid £900 per hectare a year (that's £${fmt(area*900)} for this field) and keeps grazing rights.`,
    `A grid connection offer is the real limit on fields; we check it first.`];
  $('#assumeList').innerHTML=A.map(x=>`<li>${x}</li>`).join('');
}
['area','pitch','region'].forEach(id=>$('#'+id).addEventListener('input',estimate));
$$('input[name=kind]').forEach(r=>r.addEventListener('change',()=>{
  const roof=r.value==='roof'&&r.checked||(r.value==='field'&&!r.checked);
  const a=$('#area');
  if($('#kRoof').checked){a.min=10;a.max=400;a.step=5;a.value=40;$('#areaLbl').textContent='Usable roof area';$('#areaHelp').textContent='The part with no chimneys, skylights or shade. A 3-bed semi has about 20 m² on the sunny side.';}
  else{a.min=1;a.max=30;a.step=.5;a.value=6;$('#areaLbl').textContent='Field size';$('#areaHelp').textContent='Flat, unshaded land within a mile of a substation works best. Sheep can keep grazing it.';}
  estimate();
}));
function dialFromEvent(ev){const r=dial.getBoundingClientRect();const x=ev.clientX-r.left-r.width/2,y=ev.clientY-r.top-r.height/2;setDir(Math.atan2(x,-y)*180/Math.PI);}
dial.addEventListener('pointerdown',ev=>{if(dial.getAttribute('aria-disabled')==='true')return;dial.setPointerCapture(ev.pointerId);dialFromEvent(ev);dial.focus({preventScroll:true});});
dial.addEventListener('pointermove',ev=>{if(dial.hasPointerCapture(ev.pointerId))dialFromEvent(ev);});
dial.addEventListener('keydown',ev=>{
  if(dial.getAttribute('aria-disabled')==='true')return;
  const step=ev.shiftKey?45:5, map={ArrowRight:step,ArrowUp:step,ArrowLeft:-step,ArrowDown:-step,PageUp:45,PageDown:-45};
  if(ev.key in map){ev.preventDefault();setDir(dir+map[ev.key]);}
  else if(ev.key==='Home'){ev.preventDefault();setDir(0);} else if(ev.key==='End'){ev.preventDefault();setDir(180);}
});
$('#hostLink').addEventListener('click',()=>{$('#fWant').value='host';syncWant();});
estimate();

/* ---------- SITES MAP ---------- */
const SITES=[
 {id:1,n:'Wendham Primary School',k:'roof',x:300,y:236,kwp:98,yr:2015,mem:212,host:'Wendham Primary, Church Lane',img:'school',s:'Our first roof. The Year 6 class reads the meter every Friday and posts it in the hall.',save:'£11,400'},
 {id:2,n:'Saltmere Drove field',k:'field',x:552,y:356,kwp:1450,yr:2021,mem:604,host:'The Pell family, Drove Farm',img:'sheep',s:'4.2 hectares of trackers on grazing land. Tom Pell\'s 60 ewes keep the grass down from April to October.',save:'£3,780 rent'},
 {id:3,n:'Coldhythe Maltings',k:'roof',x:196,y:398,kwp:140,yr:2019,mem:150,host:'Coldhythe Brewing, River Wharf',img:'maltings',s:'The brewery mashes in at 7am in summer to match the panels. Its old malt floor is now the bottling line.',save:'£16,200'},
 {id:4,n:'Burrow Fen barns',k:'roof',x:640,y:188,kwp:210,yr:2018,mem:233,host:'Burrow Fen Farm',img:'installer',s:'Three grain-store roofs, fitted in nine days by two installers and a rota of member volunteers.',save:'£19,800'},
 {id:5,img:'leisure',n:'Wendham Leisure Centre',k:'roof',x:338,y:200,kwp:180,yr:2020,mem:176,host:'Wendham Parish Council',s:'Runs the pool pumps through the summer; the café roof was added in 2023.',save:'£21,300'},
 {id:6,img:'church',n:'St Agnes church hall',k:'roof',x:432,y:300,kwp:24,yr:2016,mem:58,host:'Parish of St Agnes, Coldhythe',s:'Listed building, so the panels sit on the 1970s extension at the back where no one sees them.',save:'£2,900'},
 {id:7,img:'firestation',n:'Marram End fire station',k:'roof',x:706,y:430,kwp:36,yr:2022,mem:41,host:'County fire service',s:'Charges the station\'s two electric vans between call-outs.',save:'£4,100'},
 {id:8,img:'surgery',n:'Little Gosling surgery',k:'roof',x:110,y:150,kwp:42,yr:2023,mem:66,host:'Little Gosling Medical Practice',s:'Covers the vaccine fridges and most of the daytime load.',save:'£5,600'},
 {id:9,n:'Ketton Drove field',k:'field',x:240,y:478,kwp:1200,yr:2024,mem:521,host:'Ketton Drove Estate',img:'frost',s:'Our newest field, planted with wildflowers between the rows. It still makes power on a frosty January morning.',save:'£2,700 rent'},
 {id:10,img:'hall',n:'Saltmere village hall',k:'roof',x:520,y:268,kwp:18,yr:2016,mem:39,host:'Saltmere Village Hall Trust',s:'Where we hold the AGM. The hall now pays nothing for daytime electricity from April to September.',save:'£2,200'},
 {id:11,n:'Coldhythe Academy',k:'roof',x:150,y:330,kwp:160,yr:2024,mem:198,host:'Coldhythe Academy Trust',s:'Sixth-formers helped design the monitoring screen in the reception.',save:'£18,100'},
 {id:12,n:'Hythe Lode field + battery',k:'plan',x:690,y:290,kwp:2000,yr:2027,mem:0,host:'Hythe Lode Farm',s:'Voted through at the March 2026 AGM. Grid connection offered for spring 2027; share offer opens in January.'},
 {id:13,n:'Wendham bus depot',k:'plan',x:384,y:146,kwp:300,yr:2027,mem:0,host:'Fenways Buses',s:'Largest roof in the valley. Survey done; the depot wants the power for its first six electric buses.'},
 {id:14,n:'Burrow Fen pumping station',k:'plan',x:610,y:96,kwp:60,yr:2026,mem:0,host:'Internal Drainage Board',s:'The pumps that keep the fen dry run hardest in winter, so this one pairs panels with a small battery.'}
];
const mapSvg=$('#mapSvg');
(function drawMap(){
  let s='<defs><pattern id="hatch" width="7" height="7" patternUnits="userSpaceOnUse" patternTransform="rotate(32)"><line x1="0" y1="0" x2="0" y2="7" stroke="#cdbfa6" stroke-width="1.2"/></pattern><pattern id="dots" width="9" height="9" patternUnits="userSpaceOnUse"><circle cx="2" cy="2" r="1" fill="#b8a98d"/></pattern></defs>';
  s+='<rect width="800" height="560" fill="#ece4d4"/>';
  const fields=[[40,40,180,90],[250,60,90,120],[460,40,140,110],[640,250,140,110],[60,420,120,110],[330,400,170,120],[600,470,160,80],[470,150,90,90]];
  fields.forEach(([x,y,w,h],i)=>s+=`<rect x="${x}" y="${y}" width="${w}" height="${h}" fill="url(#${i%2?'dots':'hatch'})" transform="rotate(${(i%3-1)*6} ${x+w/2} ${y+h/2})"/>`);
  // drains: long straight cuts
  s+='<g stroke="#8fa3ad" stroke-width="2.2" fill="none"><path d="M-10 128 L810 286"/><path d="M90 570 L520 -10"/><path d="M430 570 L790 120"/></g>';
  s+='<g stroke="#8fa3ad" stroke-width="1" fill="none" stroke-dasharray="1 0"><path d="M-10 210 L560 330"/><path d="M200 -10 L120 570"/></g>';
  // river Wend
  s+='<path d="M-10 420 C 90 380, 150 440, 230 400 S 330 300, 420 330 S 520 420, 600 390 S 720 300, 810 330" fill="none" stroke="#6f8c9b" stroke-width="9" stroke-linecap="round"/>';
  s+='<path d="M-10 420 C 90 380, 150 440, 230 400 S 330 300, 420 330 S 520 420, 600 390 S 720 300, 810 330" fill="none" stroke="#a9bfc8" stroke-width="3"/>';
  // roads
  s+='<g stroke="#1e1a15" stroke-width="1" fill="none" opacity=".45"><path d="M0 250 C 200 240, 300 200, 420 220 S 650 200, 800 180"/><path d="M330 0 C 340 160, 300 300, 260 560"/><path d="M520 0 L540 560"/></g>';
  // villages
  const V=[['WENDHAM',318,226],['COLDHYTHE',170,372],['SALTMERE',532,250],['MARRAM END',700,458],['LITTLE GOSLING',96,132],['BURROW FEN',650,166],['KETTON DROVE',250,512]];
  V.forEach(([n,x,y])=>s+=`<circle cx="${x}" cy="${y}" r="16" fill="#d9cdb8"/><text x="${x}" y="${y-22}" text-anchor="middle" font-family="IBM Plex Mono, monospace" font-size="11" letter-spacing="1.2" fill="#5a5146">${n}</text>`);
  s+='<text x="470" y="356" font-family="Bricolage Grotesque, sans-serif" font-style="italic" font-size="14" fill="#4b6674" transform="rotate(-8 470 356)">River Wend</text>';
  s+='<text x="610" y="270" font-family="IBM Plex Mono, monospace" font-size="10" fill="#4b6674" transform="rotate(-50 610 270)">FORTY FOOT DRAIN</text>';
  // compass + scale
  s+='<g transform="translate(752 48)"><circle r="18" fill="#fbf8f2" stroke="#1e1a15"/><path d="M0 -13 L5 4 L0 0 L-5 4Z" fill="#1e1a15"/><text y="-22" text-anchor="middle" font-family="IBM Plex Mono" font-size="10" fill="#1e1a15">N</text></g>';
  s+='<g transform="translate(24 536)"><path d="M0 0h100" stroke="#1e1a15" stroke-width="2"/><path d="M0 -4v8M50 -3v6M100 -4v8" stroke="#1e1a15"/><text x="108" y="4" font-family="IBM Plex Mono" font-size="10" fill="#1e1a15">2 miles</text></g>';
  mapSvg.innerHTML=s;
})();
const ICON={roof:'<svg viewBox="0 0 14 14" aria-hidden="true"><path d="M1.5 7 7 2l5.5 5v5.5h-11z" fill="none" stroke="#1e1a15" stroke-width="1.5"/></svg>',
  field:'<svg viewBox="0 0 14 14" aria-hidden="true"><path d="M1 10l4-6h8l-4 6z" fill="none" stroke="#f2ece2" stroke-width="1.5"/><path d="M4 7h7" stroke="#f2ece2" stroke-width="1.2"/></svg>',
  plan:'<svg viewBox="0 0 14 14" aria-hidden="true"><path d="M7 2v10M2 7h10" stroke="#1e1a15" stroke-width="1.5"/></svg>'};
const KIND={roof:'Roof',field:'Field',plan:'Being planned'};
const mapEl=$('#map'), list=$('#siteList'), card=$('#siteCard');
let filter='all', current=1;
SITES.forEach(st=>{
  const b=document.createElement('button');b.className='pin '+st.k;b.style.left=(st.x/8)+'%';b.style.top=(st.y/5.6)+'%';
  b.innerHTML=ICON[st.k];b.setAttribute('aria-label',`${st.n}, ${KIND[st.k].toLowerCase()}, ${fmt(st.kwp)} kWp`);b.setAttribute('aria-pressed','false');b.dataset.id=st.id;
  b.addEventListener('click',()=>select(st.id));mapEl.appendChild(b);st.pin=b;
  const li=document.createElement('li');li.innerHTML=`<button type="button"><span>${st.n}</span><span class="num">${fmt(st.kwp)} kWp</span></button>`;
  li.firstChild.addEventListener('click',()=>{select(st.id);if(innerWidth<961)card.scrollIntoView({behavior:RM.matches?'auto':'smooth',block:'nearest'});});
  list.appendChild(li);st.li=li;
});
function select(id){
  current=id;const st=SITES.find(s=>s.id===id);
  SITES.forEach(s=>s.pin.setAttribute('aria-pressed',String(s.id===id)));
  const made=st.k==='plan'?null:Math.round(st.kwp*.94*(st.yr>=2025?.5:1));
  card.innerHTML=`<div class="ph grain">${st.img?`<img src="assets/${st.img}.webp" alt="${({school:'Wendham Primary School roof with panels',sheep:'Sheep grazing between tracker rows at sunrise',maltings:'Brick maltings with a solar roof beside the river',installer:'Installer fixing a panel rail on a barn roof',frost:'Frost on a panel at sunrise',leisure:'Low leisure centre with a solar roof beside its car park',church:'Flint church with solar panels on its flat-roofed hall extension',firestation:'Brick fire station with two red doors and panels on the roof',surgery:'Grey-clad village surgery with a solar roof among birch trees',hall:'Brick and timber village hall with a solar roof beside a drain at dusk'})[st.img]}" loading="lazy" decoding="async">`:`<div class="noimg">${st.k==='plan'?'Not built yet':'Photo to follow'}</div>`}</div>
   <div class="body"><span class="badge">${KIND[st.k]}${st.k==='plan'?' · '+st.yr:''}</span><h3>${st.n}</h3><p class="host">${st.host}</p>
   <dl><div><dt>Size</dt><dd>${fmt(st.kwp)} kWp</dd></div><div><dt>${st.k==='plan'?'Target build':'Switched on'}</dt><dd>${st.yr}</dd></div>
   <div><dt>${st.k==='plan'?'Expected a year':'Made last year'}</dt><dd>${fmt(made??Math.round(st.kwp*.94))} MWh</dd></div>
   <div><dt>${st.k==='plan'?'Members funding':'Members who paid for it'}</dt><dd>${st.mem?fmt(st.mem):'Offer opens soon'}</dd></div></dl>
   <p class="story">${st.s}${st.save?` <strong>Host saving: ${st.save} a year.</strong>`:''}</p></div>`;
}
function applyFilter(){
  let n=0,kwp=0,mwh=0;
  SITES.forEach(s=>{const on=filter==='all'||s.k===filter;s.pin.hidden=!on;s.li.hidden=!on;if(on){n++;kwp+=s.kwp;if(s.k!=='plan')mwh+=s.kwp*.94;}});
  $('#mapTotals').textContent=`Showing ${n} site${n>1?'s':''} · ${fmt(kwp/1000,2)} MWp`+(mwh?` · about ${fmt(mwh/1000,2)} GWh a year`:' · not generating yet');
  const cur=SITES.find(s=>s.id===current);
  if(cur.pin.hidden){select(SITES.find(s=>!s.pin.hidden).id);}
}
$$('.chip').forEach(c=>c.addEventListener('click',()=>{filter=c.dataset.f;$$('.chip').forEach(x=>x.setAttribute('aria-pressed',String(x===c)));applyFilter();}));
select(1);applyFilter();

/* ---------- SHARES ---------- */
const amt=$('#amt'), amtR=$('#amtRange'), grid=$('#panelGrid');
for(let i=0;i<48;i++){const c=document.createElement('i');c.innerHTML='<b></b>';grid.appendChild(c);}
const toR=v=>Math.round(Math.log(v/50)/Math.log(400)*1000), fromR=r=>{const v=50*Math.pow(400,r/1000);return v<1000?Math.round(v/10)*10:v<5000?Math.round(v/50)*50:Math.round(v/250)*250;};
function shares(v,src){
  const ok=v>=50&&v<=20000&&Number.isFinite(v);
  $('#amtErr').textContent=ok?'':'Shares go from £50 to £20,000 per member.';
  amt.setAttribute('aria-invalid',String(!ok));
  if(!ok) return; v=Math.round(v);
  if(src!=='range'){amtR.value=toR(v);}
  amtR.setAttribute('aria-valuetext','£'+fmt(v));
  if(src!=='input') amt.value=v;
  let bal=v,tot=0;const cap=v/16;for(let y=1;y<=20;y++){tot+=bal*.04;if(y>=5)bal-=cap;}
  tween($('#rY1'),v*.04,0);$('#rY1').dataset.v=v*.04;
  $('#rY1').textContent='£'+fmt(v*.04,v<250?2:0);
  $('#rTot').textContent='£'+fmt(tot);
  $('#rCap').textContent='£'+fmt(cap,cap<100?2:0)+' a year';
  const kwp=v/1050;
  $('#rKwh').textContent=fmt(kwp*940)+' kWh';
  $('#rFund').textContent='£'+fmt(kwp*940*.18*.12,2)+' a year';
  const panels=kwp/.43;
  [...grid.children].forEach((c,i)=>{c.firstChild.style.width=(clamp(panels-i,0,1)*100)+'%';});
  $('#panelText').textContent=panels>48?`About ${fmt(panels)} panels at 430 W. That's more than this grid shows: ${fmt(panels/48,1)} rows like it.`:`About ${fmt(panels,1)} panel${panels>=1.05?'s':''} at 430 W, ${fmt(kwp,2)} kWp`;
  $('#toJoin').firstChild.textContent=`Apply for £${fmt(v)} of shares `;
  $('#fAmt').value=v;
}
amt.addEventListener('input',()=>shares(+amt.value,'input'));
amtR.addEventListener('input',()=>shares(fromR(+amtR.value),'range'));
$$('.quick button').forEach(b=>b.addEventListener('click',()=>shares(+b.dataset.v)));
$('#toJoin').addEventListener('click',()=>{$('#fWant').value='shares';syncWant();});
shares(500);

/* ---------- JOIN FORM ---------- */
const form=$('#joinForm');
function syncWant(){$('#fAmtWrap').hidden=$('#fWant').value!=='shares';}
$('#fWant').addEventListener('change',syncWant);
function setErr(input,errEl,msg){input.setAttribute('aria-invalid',msg?'true':'false');$(errEl).textContent=msg;return !msg;}
form.addEventListener('submit',ev=>{
  ev.preventDefault();
  const name=$('#fName'),email=$('#fEmail'),post=$('#fPost'),a=$('#fAmt'),age=$('#fAge');
  const checks=[
    setErr(name,'#eName',name.value.trim().length<2?'Tell us your full name.':''),
    setErr(email,'#eEmail',/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email.value.trim())?'':'That email doesn\'t look complete.'),
    setErr(post,'#ePost',/^[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}$/i.test(post.value.trim())?'':'Use a UK postcode, like PE14 9AB.'),
    $('#fWant').value!=='shares'?setErr(a,'#eAmt',''):setErr(a,'#eAmt',(+a.value>=50&&+a.value<=20000)?'':'Pick an amount between £50 and £20,000.'),
    setErr(age,'#eAge',age.checked?'':'Please confirm this before we send the offer.')
  ];
  const firstBad=[name,email,post,a,age][checks.indexOf(false)];
  if(firstBad){firstBad.focus();return;}
  const want=$('#fWant').value, first=name.value.trim().split(/\s+/)[0];
  const msg={shares:`We'll email the share offer for £${fmt(+a.value)} to ${email.value.trim()} within two working days. Read it, then sign; nothing is taken before.`,
    host:`A volunteer surveyor will ring within a week to arrange a visit near ${post.value.trim().toUpperCase()}. It's free and there's no obligation.`,
    news:`You're on the list. We'll write when the Hythe Lode share offer opens in January.`}[want];
  const ok=document.createElement('div');ok.className='ok';ok.setAttribute('role','status');ok.setAttribute('tabindex','-1');
  ok.innerHTML=`<h3>Thanks, ${first.replace(/[<>&"]/g,'')}.</h3><p style="margin:0">${msg.replace(/[<>]/g,'')}</p>`;
  form.replaceWith(ok);ok.focus();
});
syncWant();

/* ---------- POUND BAR ---------- */
const POUND=[
 ['Members\' capital back',30,'#f0a830','Thirty pence returns the money members put in, spread over years 5 to 20 so the co-op is debt-free when the panels are.'],
 ['Members\' interest',20,'#f7cf7a','Twenty pence pays interest at the target rate, voted each year. It was 4% in 2025 and 3.5% in the two cold, dull years before.'],
 ['Upkeep, insurance, rent',22,'#d8ccb8','Inverter swaps, cleaning, insurance, the two field leases and our one part-time member officer.'],
 ['Fen Warmth Fund',12,'#9fb07a','Twelve pence goes to insulation, draught-proofing and energy advice. Last winter it paid for 64 lofts in five parishes.'],
 ['Reserves for the next site',16,'#8fa3ad','Sixteen pence builds the reserve that pays early withdrawals and the survey costs of the next site.']];
const pound=$('#pound');
POUND.forEach((p,i)=>{const b=document.createElement('button');b.type='button';b.style.background=p[2];b.style.flex=p[1]+' 1 0';
  b.innerHTML=`<b>${p[1]}p</b><span>${p[0]}</span>`;b.setAttribute('aria-pressed','false');b.addEventListener('click',()=>pick(i));pound.appendChild(b);});
function pick(i){[...pound.children].forEach((b,j)=>{b.setAttribute('aria-pressed',String(i===j));b.style.flexGrow=POUND[j][1]+(i===j?8:0);});
  $('#poundDetail').innerHTML=`<h3>${POUND[i][1]}p · ${POUND[i][0]}</h3><p style="color:var(--muted)">${POUND[i][3]}</p>`;}
pick(0);

/* ---------- menu ---------- */
const mb=$('.menu-btn'),nav=$('#nav');
function closeMenu(){nav.classList.remove('open');mb.setAttribute('aria-expanded','false');mb.setAttribute('aria-label','Open menu');}
mb.addEventListener('click',()=>{const o=!nav.classList.contains('open');nav.classList.toggle('open',o);mb.setAttribute('aria-expanded',String(o));mb.setAttribute('aria-label',o?'Close menu':'Open menu');if(o)nav.querySelector('a').focus();});
nav.addEventListener('click',e=>{if(e.target.closest('a'))closeMenu();});
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&nav.classList.contains('open')){closeMenu();mb.focus();}});
})();
</script>
<script type="importmap">{"imports":{"three":"https://unpkg.com/three@0.170.0/build/three.module.js","three/addons/":"https://unpkg.com/three@0.170.0/examples/jsm/"}}</script>
<script type="module">
/* Fenlight hero: a live three.js scene. Preetham sky driven by the sun model, PMREM sky reflections in
   the panel glass, soft sun shadows, 840 single-axis trackers, wind in the grass and grazing sheep. */
import * as THREE from 'three';
import {Sky} from 'three/addons/objects/Sky.js';
import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js';
import {MeshoptDecoder} from 'three/addons/libs/meshopt_decoder.module.js';
const F=window.FEN;window.FEN_3D_STARTED=1;
try{ build(); }catch(err){ F.glFail(err); }

function build(){
  const stage=F.stage;
  const canvas=document.createElement('canvas');canvas.className='gl';canvas.setAttribute('aria-hidden','true');
  const renderer=new THREE.WebGLRenderer({canvas,antialias:true,powerPreference:'high-performance'});
  if(!renderer.getContext()) throw new Error('no webgl');
  const flat=document.getElementById('sky');flat.after(canvas);
  const mobile=()=>innerWidth<760;
  renderer.setPixelRatio(Math.min(devicePixelRatio||1,mobile()?1.5:1.75));
  renderer.toneMapping=THREE.ACESFilmicToneMapping;
  renderer.outputColorSpace=THREE.SRGBColorSpace;
  renderer.shadowMap.enabled=true;renderer.shadowMap.type=THREE.PCFSoftShadowMap;

  const scene=new THREE.Scene();
  const camera=new THREE.PerspectiveCamera(46,1,.3,9000);
  const sky=new Sky();sky.scale.setScalar(8000);scene.add(sky);
  const U=sky.material.uniforms;
  U.turbidity.value=2.4;U.rayleigh.value=2.6;U.mieCoefficient.value=.0045;U.mieDirectionalG.value=.84;
  const envScene=new THREE.Scene();const sky2=new Sky();sky2.material=sky.material;sky2.scale.setScalar(8000);envScene.add(sky2);
  const pmrem=new THREE.PMREMGenerator(renderer);let envRT=null;

  scene.fog=new THREE.FogExp2(0xdfe3e0,.00055);
  const hemi=new THREE.HemisphereLight(0xcfe0f0,0x4b4a2c,.6);scene.add(hemi);
  const sun=new THREE.DirectionalLight(0xffffff,3);
  sun.castShadow=true;const sm=mobile()?1024:2048;sun.shadow.mapSize.set(sm,sm);
  Object.assign(sun.shadow.camera,{left:-50,right:50,top:58,bottom:-58,near:1,far:460});
  sun.shadow.bias=-.0004;sun.shadow.normalBias=.03;
  sun.target.position.set(0,0,-40);scene.add(sun,sun.target);

  const rnd=(s=>()=>(s=(s*16807)%2147483647)/2147483647)(11);
  const cnv=(w,h,fn)=>{const c=document.createElement('canvas');c.width=w;c.height=h;fn(c.getContext('2d'),w,h);return c;};

  /* ground: fen patchwork, 1 px = 1.6 m */
  const fieldTex=new THREE.CanvasTexture(cnv(2048,2048,(g,w,h)=>{
    g.fillStyle='#5d6a33';g.fillRect(0,0,w,h);
    const pal=['#6b7838','#8b8748','#a7955f','#57472f','#7a8a43','#b4a46a','#4e5d2e','#93904f','#6e5a3c'];
    for(let y=0;y<h;){const bh=40+rnd()*110;for(let x=0;x<w;){const bw=90+rnd()*260;
      g.fillStyle=pal[(rnd()*pal.length)|0];g.fillRect(x,y,bw,bh);
      g.strokeStyle='rgba(30,30,15,.18)';g.lineWidth=.6;const vert=rnd()>.5;
      for(let k=0;k<(vert?bw:bh);k+=2.2){g.beginPath();vert?(g.moveTo(x+k,y),g.lineTo(x+k,y+bh)):(g.moveTo(x,y+k),g.lineTo(x+bw,y+k));g.stroke();}
      g.strokeStyle='rgba(38,46,24,.75)';g.lineWidth=1.4;g.strokeRect(x,y,bw,bh);x+=bw;}y+=bh;}
    // grazed grass under the array (camera sits at the centre)
    g.fillStyle='#62742f';g.fillRect(w/2-26,h/2-60,52,66);
    g.strokeStyle='rgba(120,140,150,.9)';g.lineWidth=2.4;g.beginPath();g.moveTo(w/2-30,0);g.lineTo(w/2-30,h);g.stroke();
  }));
  fieldTex.colorSpace=THREE.SRGBColorSpace;fieldTex.anisotropy=8;
  const ground=new THREE.Mesh(new THREE.PlaneGeometry(3277,3277),new THREE.MeshStandardMaterial({map:fieldTex,roughness:1}));
  ground.rotation.x=-Math.PI/2;ground.receiveShadow=true;scene.add(ground);
  // near grass detail with a soft edge
  const grassTex=new THREE.CanvasTexture(cnv(512,512,(g,w,h)=>{g.fillStyle='#5f702e';g.fillRect(0,0,w,h);
    for(let i=0;i<9000;i++){const v=rnd();g.fillStyle=v<.5?'rgba(120,140,60,.55)':v<.8?'rgba(60,72,30,.5)':'rgba(170,160,90,.4)';g.fillRect(rnd()*w,rnd()*h,1+rnd()*2,1+rnd()*3);}}));
  grassTex.colorSpace=THREE.SRGBColorSpace;grassTex.wrapS=grassTex.wrapT=THREE.RepeatWrapping;grassTex.repeat.set(26,34);grassTex.anisotropy=8;
  const fade=new THREE.CanvasTexture(cnv(256,256,(g,w,h)=>{const r=g.createRadialGradient(w/2,h/2,w*.3,w/2,h/2,w/2);r.addColorStop(0,'#fff');r.addColorStop(1,'#000');g.fillStyle=r;g.fillRect(0,0,w,h);}));
  const near=new THREE.Mesh(new THREE.PlaneGeometry(110,150),new THREE.MeshStandardMaterial({map:grassTex,alphaMap:fade,transparent:true,roughness:1,depthWrite:false}));
  near.rotation.x=-Math.PI/2;near.position.set(0,.02,-38);near.receiveShadow=true;scene.add(near);
  // drain: a long mirror of sky
  const water=new THREE.Mesh(new THREE.PlaneGeometry(4,3000),new THREE.MeshStandardMaterial({color:0x6d7b84,metalness:1,roughness:.06}));
  water.rotation.x=-Math.PI/2;water.position.set(-48,.04,-1400);scene.add(water);

  /* trackers */
  const cellTex=new THREE.CanvasTexture(cnv(512,256,(g,w,h)=>{
    g.fillStyle='#c9ced4';g.fillRect(0,0,w,h);
    const cx=12,cy=6,gx=w/cx,gy=h/cy;
    for(let i=0;i<cx;i++)for(let j=0;j<cy;j++){const gr=g.createLinearGradient(0,j*gy,0,(j+1)*gy);gr.addColorStop(0,'#1d2e4c');gr.addColorStop(1,'#132036');
      g.fillStyle=gr;g.fillRect(i*gx+1.5,j*gy+1.5,gx-3,gy-3);
      g.strokeStyle='rgba(150,165,185,.35)';g.lineWidth=.8;for(let b=1;b<4;b++){g.beginPath();g.moveTo(i*gx+b*gx/4,j*gy+2);g.lineTo(i*gx+b*gx/4,(j+1)*gy-2);g.stroke();}}
    g.strokeStyle='#d8dce0';g.lineWidth=6;g.strokeRect(0,0,w,h);}));
  cellTex.colorSpace=THREE.SRGBColorSpace;cellTex.anisotropy=8;
  const glass=new THREE.MeshPhysicalMaterial({map:cellTex,roughness:.2,metalness:0,clearcoat:.35,clearcoatRoughness:.06,envMapIntensity:.7});
  const frame=new THREE.MeshStandardMaterial({color:0xb9bdc2,metalness:.85,roughness:.32});
  const back=new THREE.MeshStandardMaterial({color:0x2b2f35,roughness:.6});
  const PW=2.1,PD=1.1,HUB=1.55,ROWS=[],NP=72;
  for(let x=-33;x<=33;x+=6)ROWS.push(x);
  const panels=new THREE.InstancedMesh(new THREE.BoxGeometry(PW,.04,PD),[frame,frame,glass,back,frame,frame],ROWS.length*NP);
  panels.castShadow=true;panels.receiveShadow=true;scene.add(panels);
  const dummy=new THREE.Object3D();
  function setTilt(th){let k=0;for(const x of ROWS)for(let i=0;i<NP;i++){dummy.position.set(x,HUB,-2-i*(PD+.025));dummy.rotation.set(0,0,th);dummy.updateMatrix();panels.setMatrixAt(k++,dummy.matrix);}panels.instanceMatrix.needsUpdate=true;}
  const steel=new THREE.MeshStandardMaterial({color:0x8d9196,metalness:.7,roughness:.45});
  const tube=new THREE.InstancedMesh(new THREE.CylinderGeometry(.06,.06,NP*(PD+.025),8),steel,ROWS.length);
  ROWS.forEach((x,i)=>{dummy.position.set(x,HUB-.06,-2-NP*(PD+.025)/2+PD/2);dummy.rotation.set(Math.PI/2,0,0);dummy.updateMatrix();tube.setMatrixAt(i,dummy.matrix);});
  tube.castShadow=true;scene.add(tube);
  const postsPer=Math.ceil(NP/7);
  const posts=new THREE.InstancedMesh(new THREE.BoxGeometry(.13,HUB,.13),steel,ROWS.length*postsPer);
  {let k=0;ROWS.forEach(x=>{for(let p=0;p<postsPer;p++){dummy.position.set(x,HUB/2-.05,-2-p*7*(PD+.025));dummy.rotation.set(0,0,0);dummy.updateMatrix();posts.setMatrixAt(k++,dummy.matrix);}});}
  posts.castShadow=true;scene.add(posts);
  const motors=new THREE.InstancedMesh(new THREE.BoxGeometry(.34,.34,.5),new THREE.MeshStandardMaterial({color:0x2a3a4a,roughness:.5}),ROWS.length);
  ROWS.forEach((x,i)=>{dummy.position.set(x,HUB-.45,-2-3*7*(PD+.025));dummy.updateMatrix();motors.setMatrixAt(i,dummy.matrix);});scene.add(motors);

  /* grass blades with wind in the vertex shader */
  const blade=new THREE.PlaneGeometry(.06,.34,1,3);blade.translate(0,.17,0);
  {const p=blade.attributes.position;for(let i=0;i<p.count;i++){const y=p.getY(i);p.setX(i,p.getX(i)*(1-y/.36));}}
  const NB=mobile()?9000:22000;
  const bladeMat=new THREE.MeshLambertMaterial({side:THREE.DoubleSide});
  const wind={value:0};
  bladeMat.onBeforeCompile=sh=>{sh.uniforms.uTime=wind;sh.vertexShader='uniform float uTime;\n'+sh.vertexShader.replace('#include <begin_vertex>',
    `#include <begin_vertex>
     vec4 wp0=instanceMatrix*vec4(0.,0.,0.,1.);
     float hh=position.y/.34;
     float gust=sin(uTime*.7+wp0.x*.05+wp0.z*.08)*.5+.5;
     transformed.x+=(sin(uTime*2.1+wp0.x*.6+wp0.z*.35)*.05+gust*.07)*hh*hh;`);};
  const blades=new THREE.InstancedMesh(blade,bladeMat,NB);
  const col=new THREE.Color();
  for(let i=0;i<NB;i++){const z=24-Math.pow(rnd(),1.5)*100, x=(rnd()*2-1)*(16+(24-z)*.32);
    dummy.position.set(x,0,z);dummy.rotation.set((rnd()-.5)*.3,rnd()*Math.PI,(rnd()-.5)*.3);const s=.6+rnd()*1;dummy.scale.set(1,s,1);dummy.updateMatrix();blades.setMatrixAt(i,dummy.matrix);
    col.setHSL(.17+rnd()*.07,.45,.2+rnd()*.16);blades.setColorAt(i,col);}
  blades.receiveShadow=true;scene.add(blades);

  /* the horizon: hedges, poplars, a church, a windpump, barns */
  const treeMat=new THREE.MeshStandardMaterial({color:0x4a5a35,roughness:1});
  const trees=new THREE.InstancedMesh(new THREE.IcosahedronGeometry(1,1),treeMat,700);
  {let k=0;const add=(x,z,sx,sy)=>{if(k>=700)return;dummy.position.set(x,sy*.85,z);dummy.rotation.set(0,rnd()*3,0);dummy.scale.set(sx,sy,sx);dummy.updateMatrix();trees.setMatrixAt(k++,dummy.matrix);};
    for(const [z,gap] of [[-330,.45],[-520,.25],[-800,.1],[-1250,.05]])for(let x=-900;x<900;x+=8+rnd()*14){if(rnd()<gap)continue;const pop=rnd()<.3;add(x,z+(rnd()-.5)*10,pop?1.6:2.6+rnd()*2.4,pop?8+rnd()*4:2.6+rnd()*2.2);}
    for(const x of [-190,-420,260,520])for(let z=100;z>-900;z-=10+rnd()*14){if(rnd()<.35)continue;const pop=rnd()<.25;add(x+(rnd()-.5)*8,z,pop?1.6:2.6+rnd()*2.4,pop?8+rnd()*4:2.6+rnd()*2.2);}
    trees.count=k;}
  trees.castShadow=true;scene.add(trees);
  const stone=new THREE.MeshStandardMaterial({color:0x8d8676,roughness:.95});
  const church=new THREE.Group();
  const tw=new THREE.Mesh(new THREE.BoxGeometry(7,26,7),stone);tw.position.y=13;church.add(tw);
  const nave=new THREE.Mesh(new THREE.BoxGeometry(9,10,26),stone);nave.position.set(0,5,16);church.add(nave);
  const roof=new THREE.Mesh(new THREE.CylinderGeometry(0,7,7,4),new THREE.MeshStandardMaterial({color:0x5b4a42,roughness:.9}));roof.position.y=29.5;roof.rotation.y=Math.PI/4;church.add(roof);
  church.position.set(190,0,-700);scene.add(church);
  const barnMat=new THREE.MeshStandardMaterial({color:0x6b3d2c,roughness:.9});
  [[-150,-380,30,9,14],[-110,-372,18,7,12],[300,-520,40,10,18]].forEach(([x,z,w,h,d])=>{const b=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),barnMat);b.position.set(x,h/2,z);b.castShadow=true;scene.add(b);});
  const pump=new THREE.Group();const pmat=new THREE.MeshStandardMaterial({color:0x3a3a36,roughness:.8});
  const pt=new THREE.Mesh(new THREE.CylinderGeometry(.5,1.6,12,6),pmat);pt.position.y=6;pump.add(pt);
  const rotor=new THREE.Group();rotor.position.set(0,12,1.2);for(let i=0;i<4;i++){const s=new THREE.Mesh(new THREE.BoxGeometry(.5,6,.1),pmat);s.position.y=3;const a=new THREE.Group();a.rotation.z=i*Math.PI/2;a.add(s);rotor.add(a);}pump.add(rotor);
  pump.position.set(-70,0,-330);pump.rotation.y=.4;scene.add(pump);

  /* stars for the ends of the day */
  const sg=new THREE.BufferGeometry();const sp=[];for(let i=0;i<900;i++){const a=rnd()*Math.PI*2,b=Math.acos(rnd()*.92);sp.push(Math.sin(b)*Math.cos(a)*6000,Math.cos(b)*6000,Math.sin(b)*Math.sin(a)*6000);}
  sg.setAttribute('position',new THREE.Float32BufferAttribute(sp,3));
  const starMat=new THREE.PointsMaterial({color:0xf2ece2,size:1.6,sizeAttenuation:false,transparent:true,opacity:0,fog:false,depthWrite:false});
  scene.add(new THREE.Points(sg,starMat));

  /* sheep: a real GLB, cloned and grazing along the aisles */
  const flock=[];
  new GLTFLoader().setMeshoptDecoder(MeshoptDecoder).load('assets/sheep.glb',gltf=>{
    const src=gltf.scene;const box=new THREE.Box3().setFromObject(src);const size=box.getSize(new THREE.Vector3());
    const s=1.25/Math.max(size.x,size.z);src.scale.setScalar(s);
    box.setFromObject(src);src.position.y-=box.min.y;const c=box.getCenter(new THREE.Vector3());src.position.x-=c.x;src.position.z-=c.z;
    src.traverse(o=>{if(o.isMesh){o.castShadow=true;o.receiveShadow=true;if(o.material){o.material.envMapIntensity=.6;}}});
    const length=size.x>size.z?'x':'z';
    const spots=[[0,-7],[0.6,-17],[-6.2,-11],[6,-24],[-12,-20],[12.3,-9],[-0.4,-33],[5.8,-40]];
    for(const [x,z] of spots.slice(0,mobile()?5:8)){
      const holder=new THREE.Group();const inner=src.clone();inner.rotation.y=length==='x'?Math.PI/2:0;holder.add(inner);
      holder.position.set(x,0,z);const dir=rnd()>.5?1:-1;holder.rotation.y=dir>0?0:Math.PI;
      scene.add(holder);flock.push({g:holder,inner,x0:x,z,dir,ph:rnd()*10,sp:.12+rnd()*.12});
    }
    F.glbDone();F.wake();
  },undefined,()=>F.glbDone());

  /* sun & light per time of day */
  const sunDir=new THREE.Vector3();
  let tilt=0,targetTilt=0,lastEnv={e:999,az:999,at:0};
  const cLow=new THREE.Color(0xff8a45),cHigh=new THREE.Color(0xfff3e2),fogC=new THREE.Color();
  const ss=(a,b,x)=>{const t=Math.min(1,Math.max(0,(x-a)/(b-a)));return t*t*(3-2*t);};
  function setTime(t,now){
    const {e,az}=F.sunAt(t);
    const er=THREE.MathUtils.degToRad(e),ar=THREE.MathUtils.degToRad(az);
    // x = west, y = up, z = north (camera looks south, down -z)
    sunDir.set(Math.cos(er)*Math.sin(ar-Math.PI),Math.sin(er),Math.cos(er)*Math.cos(ar));
    U.sunPosition.value.copy(sunDir);
    const day=ss(-1,8,e);
    sun.position.copy(sun.target.position).addScaledVector(sunDir,200);
    sun.intensity=3.4*ss(-.5,10,e);
    sun.color.copy(cLow).lerp(cHigh,ss(1,22,e));
    hemi.intensity=.12+.75*ss(-6,14,e);
    hemi.color.setHSL(.58,.35,.35+.4*day);
    renderer.toneMappingExposure=e<0?.62:.62-.14*ss(4,40,e);
    const hor=F.skyAt(e)[1];fogC.setRGB(hor[0]/255,hor[1]/255,hor[2]/255,THREE.SRGBColorSpace);scene.fog.color.copy(fogC);
    starMat.opacity=.85*ss(-1,-7,e);
    // single-axis trackers face the sun, backtrack near the horizon, stow at night
    let th=0;if(e>0){th=-Math.atan2(sunDir.x,sunDir.y);th=Math.max(-.96,Math.min(.96,th));if(e<6)th*=e/6;}
    targetTilt=th;F.state.tilt=-th;
    if(Math.abs(e-lastEnv.e)>1.2||Math.abs(az-lastEnv.az)>5){if(now-lastEnv.at>120||!envRT){const old=envRT;envRT=pmrem.fromScene(envScene,0,1,9000);scene.environment=envRT.texture;old&&old.dispose();lastEnv={e,az,at:now};}}
  }

  /* camera */
  const camBase=new THREE.Vector3(),look=new THREE.Vector3(),par={x:0,y:0};
  function resize(w,h){renderer.setSize(w,h,false);camera.aspect=w/h;
    const m=w/h<.9;camera.fov=m?64:46;
    camBase.set(0,m?12:9.5,m?34:27);look.set(0,m?7.5:5.2,-126);
    camera.updateProjectionMatrix();}

  let lastT=-1,lastNow=0,yaw=0;const RM=F.RM;
  const STILL=/[?&]still\b/.test(location.search); // screenshot mode: render on change only
  function render(t,now){
    const dt=Math.min(.05,(now-(lastNow||now))/1000);lastNow=now;
    if(Math.abs(t-lastT)>.01){setTime(t,now);lastT=t;}
    const still=RM.matches||STILL;
    // trackers glide to their target like a slow motor (critically damped)
    tilt+=(targetTilt-tilt)*(still?1:Math.min(1,dt*3.2));
    if(Math.abs(targetTilt-tilt)>1e-4||!setTilt.done){setTilt(tilt);setTilt.done=true;}
    if(!still){
      wind.value=now/1000;
      par.x+=(F.pointer.x-par.x)*Math.min(1,dt*2.5);par.y+=(F.pointer.y-par.y)*Math.min(1,dt*2.5);
      rotor.rotation.z-=dt*.9;
      for(const s of flock){ // amble, pause and graze
        const ph=now/1000*s.sp+s.ph, walking=Math.sin(ph*.9)>.1;
        if(walking){s.z+=s.dir*dt*.35;if(s.z<-44||s.z>-4)s.dir*=-1,s.g.rotation.y=s.dir>0?0:Math.PI;}
        s.g.position.z=s.z;s.g.position.x=s.x0+Math.sin(ph*.5)*.35;
        s.inner.rotation.x=walking?Math.sin(now/180)*.02:.05+Math.sin(now/400)*.03;
      }
    }
    // the view leans with the sun: 0.32 of its azimuth away from south (max 40°)
    const azNow=F.sunAt(t).az, want=THREE.MathUtils.degToRad(Math.max(-40,Math.min(40,(azNow-180)*.32)));
    yaw+=(want-yaw)*(still?1:Math.min(1,dt*2.4));
    camera.position.set(camBase.x+par.x*1.4,camBase.y-par.y*.6,camBase.z);
    const ly=look.y-camBase.y, lz=look.z-camBase.z, yy=yaw+par.x*.03;
    camera.lookAt(camera.position.x-Math.sin(yy)*-lz*-1,camBase.y+ly,camera.position.z+Math.cos(yy)*lz);
    renderer.render(scene,camera);
    if(!stage.classList.contains('gl-on'))stage.classList.add('gl-on');
  }
  const api={render,resize,busy:()=>(!RM.matches&&!STILL)||Math.abs(targetTilt-tilt)>1e-3};
  const [w,h]=F.size();resize(w,h);
  setTime(F.state.t,performance.now());tilt=targetTilt;setTilt(tilt);
  render(F.state.t,performance.now());
  canvas.addEventListener('webglcontextlost',e=>{e.preventDefault();F.gl=null;stage.classList.remove('gl-on');F.wake();});
  if(/[?&]debug\b/.test(location.search))window.__gl={renderer,scene,blades,panels,flock};
  F.glReady(api);
}
</script>
</body>
</html>

````
