# Live Earth orbit hero

> A space product hero where a real Earth rises from the bottom edge, satellites trace their orbits overhead and live city cards ride the turning globe.

- Category: SaaS
- Version: 1.0
- Source: https://ownlyplans.com/bhaskar/live-earth-orbit-hero/

## Overview

A single-file space product hero built with Three.js. A real-textured Earth with clouds, night lights and a blue atmosphere rises from the bottom edge and turns slowly, two orbits with glowing satellites arc over the horizon, and glass cards pinned to cities ride the globe and fade as they turn away. The headline blurs in word by word, a live UTC clock and telemetry tick along, and one pair of brackets glides between the nav links. It ships with a phone menu and a reduced-motion mode. The demo brand is Terrabeam; edit the copy in the HTML and the cities in CITIES. The Earth textures load from public jsDelivr packages, so there is nothing to host.

## Tech stack

- CSS
- HTML
- JavaScript
- Three.js
- WebGL

## Build steps

### 1. Set the stage and the copy

Lay out the dark sky, the top bar with a live clock and bracket nav, the centred headline with its serif accent, both buttons and the corner telemetry.

Prompt:

```text
Create a single-file HTML hero for a live Earth-observation product called "Terrabeam". Near-black page (#03050a) with a soft blue radial glow rising from the bottom and a light SVG grain on top. Top bar in three columns: on the left a logo (a small gradient planet with a tilted orbit ring and a moon dot) and the wordmark; in the centre a glass pill with a pulsing green dot, "LIVE" and a ticking UTC clock; on the right a nav with Live globe, Missions, Data API, Pricing, a thin divider and a round "Sign in" pill. Centre the copy near the top: a small uppercase eyebrow "Live from orbit · no dish, no setup" between two fading hairlines, a two-line headline "Watch the whole planet / turn in real time." in Inter Tight 500 with "whole planet" in Instrument Serif italic and the last three words fading to grey, one muted line under it, then a glowing blue "Open the live globe →" pill with a light sweep and a glass "Take the 90-second tour" button with a round play icon. Bottom corners: small telemetry (pass number, ground speed, altitude) on the left and a "Next sweep · Bay of Bengal" countdown on the right.
```

**Done when:** The page shows the top bar, the centred copy and both buttons on a dark sky, and the clock ticks.

### 2. Render the Earth with Three.js

Put a transparent WebGL layer behind the copy and build a lit, cloudy Earth with night lights and an atmosphere glow that crests the bottom of the screen.

Prompt:

```text
Load Three.js 0.160 as an ES module through an import map from jsDelivr. Add a transparent WebGLRenderer behind the copy and an orthographic camera measured in pixels, so one unit is one CSS pixel. Add about 1,400 twinkling star points. Build the globe from one SphereGeometry: an Earth ShaderMaterial that mixes the Blue Marble day map, a warm-tinted night-lights map on the dark side and a soft specular highlight on water, plus a blue fresnel rim (load the free textures earth-blue-marble.jpg, earth-night.jpg and earth-water.png from the three-globe package on jsDelivr); a cloud sphere at 1.006x using the alpha of clouds.png from the globe.gl package that spins a little faster; and a back-side additive halo at 1.13x for the atmosphere glow. Light it from the upper right. Size the globe to max(1.12 x width, 1.32 x height) and place it so its top edge sits at 61.5% of the viewport height, so only the top cap shows. Tilt it so the band from Africa to Japan faces the viewer, start with longitude 66 in front and spin it slowly eastward.
```

**Done when:** A lit, cloudy Earth crests the bottom of the screen with a blue atmosphere glow and turns slowly.

### 3. Add orbits, satellites and live city cards

Arc two orbits over the horizon with glowing satellites and trails, and pin glass cards to cities that follow the globe as it turns.

Prompt:

```text
Add two orbit rings around the globe (1.075x solid and 1.15x dashed), each tilted slightly toward the viewer so they arc over the horizon. Give them glowing sprite satellites with a fading 46-point additive trail; depth testing hides them as they pass behind the planet. Keep a CITIES list (name, lat, lon, one stat line such as "29°C · clear · pass in 12m") and convert lat/lon to points on the sphere. Every frame, project each point to the screen, keep only cities that face the camera, sit below the buttons and inside a safe area, and show the three most front-facing as glass cards with a pulsing dot and a thin stem. Ease their opacity in and out as the Earth turns. Drive every pulse and the button light sweep from CSS variables set in the render loop.
```

**Done when:** Satellites sweep across the top of the Earth and three city cards follow their cities, fading out as they rotate away.

### 4. Intro, bracket nav, parallax and the phone version

Play the rise-and-blur intro once the textures load, make the nav brackets glide, add pointer parallax and fit everything on a phone.

Prompt:

```text
When the textures finish loading, play the intro: the globe rises from below over 2.4 s, the header fades down, and each headline word blurs in one after another (opacity, 14px blur, 16px lift), followed by the line under it, the buttons, the telemetry and finally the city cards. Make the nav brackets "[ ]" a single pair that springs between links on hover and focus and settles back on the current link. Ease the globe a few degrees toward the pointer for a gentle parallax. Under 860px hide the clock pill and the nav and show a "[ Menu ]" button that opens a full-screen blurred sheet (aria-expanded, Escape closes it). Under 560px stack the buttons full width and make the globe 2.15x the screen width. Respect prefers-reduced-motion by skipping the intro and slowing the spin.
```

**Done when:** The intro plays once, the brackets glide between nav links, the globe follows the pointer, and on a phone the menu sheet opens and closes.

## Assets

### terrabeam-orbit-hero.html — The finished file. Open it in a browser. Edit the copy in the HTML, the cities in CITIES, and START_LON to face another region.

```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#03050a" />
<title>Terrabeam · Watch the whole planet turn in real time</title>
<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=Instrument+Serif:ital@0;1&family=Inter+Tight:wght@400;500;600&display=swap" rel="stylesheet" />
<style>
:root{
  --bg:#03050a;--ink:#eef3ff;--muted:#8f9bb6;--line:rgba(160,190,255,.15);
  --blue:#5b8cff;--blue2:#a9c8ff;--green:#45e39a;
  --p:0;--shine:-1.4;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);font-family:"Inter Tight",system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased}
body{overflow:hidden}
a{color:inherit}

/* ---------- stage ---------- */
.tb-hero{position:relative;height:100vh;height:100svh;min-height:600px;overflow:hidden;isolation:isolate}
.tb-sky{position:absolute;inset:0;z-index:-2;
  background:
    radial-gradient(90% 60% at 50% 112%,rgba(46,98,235,.34),transparent 62%),
    radial-gradient(50% 35% at 50% -6%,rgba(90,120,210,.12),transparent 70%),
    var(--bg)}
.tb-gl{position:absolute;inset:0;width:100%;height:100%;z-index:-1;display:block}
.tb-grain{position:absolute;inset:0;z-index:0;pointer-events:none;opacity:.07;mix-blend-mode:overlay;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>")}

/* ---------- top bar ---------- */
.tb-top{position:absolute;top:0;left:0;right:0;z-index:6;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:16px;padding:22px clamp(18px,3.4vw,44px)}
.tb-logo{justify-self:start;display:inline-flex;align-items:center;gap:10px;text-decoration:none;font-weight:600;font-size:17px;letter-spacing:-.02em}
.tb-logo svg{width:28px;height:28px;flex:none}
.tb-live{justify-self:center;display:inline-flex;align-items:center;gap:10px;padding:7px 14px;border:1px solid var(--line);border-radius:999px;background:rgba(10,16,32,.45);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:var(--muted);font-variant-numeric:tabular-nums;white-space:nowrap}
.tb-live b{color:var(--ink);font-weight:500}
.tb-live .tb-sep{width:1px;height:12px;background:var(--line)}
.tb-pulse{position:relative;width:7px;height:7px;border-radius:50%;background:var(--green);flex:none}
.tb-pulse::after{content:"";position:absolute;inset:0;border-radius:50%;background:var(--green);transform:scale(calc(1 + var(--p) * 2.4));opacity:calc(.7 - var(--p) * .7)}

.tb-nav{justify-self:end;position:relative;display:flex;align-items:center;gap:2px}
.tb-nav a{position:relative;padding:8px 13px;color:var(--muted);text-decoration:none;font-size:14px;transition:color .2s}
.tb-nav a:hover,.tb-nav a[aria-current="page"]{color:var(--ink)}
.tb-nav a:focus-visible,.tb-cta:focus-visible,.tb-ghost:focus-visible,.tb-menu:focus-visible,.tb-sheet a:focus-visible{outline:2px solid var(--blue2);outline-offset:3px;border-radius:999px}
.tb-br{position:absolute;left:0;top:50%;font-size:15px;line-height:1;color:var(--blue2);pointer-events:none;will-change:transform}
.tb-nav .tb-div{width:1px;height:16px;background:var(--line);margin:0 10px}
.tb-nav .tb-signin{border:1px solid var(--line);border-radius:999px;padding:7px 15px;color:var(--ink);background:rgba(255,255,255,.03)}
.tb-nav .tb-signin:hover{background:rgba(255,255,255,.08)}
.tb-menu{display:none;justify-self:end;align-items:center;gap:6px;height:38px;padding:0 14px;border-radius:999px;border:1px solid var(--line);background:rgba(10,16,32,.5);color:var(--ink);font:inherit;font-size:14px;cursor:pointer}
.tb-menu span{color:var(--blue2)}

/* ---------- copy ---------- */
.tb-copy{position:absolute;left:0;right:0;top:clamp(92px,14vh,140px);z-index:3;display:flex;flex-direction:column;align-items:center;text-align:center;padding:0 20px}
.tb-eyebrow{display:inline-flex;align-items:center;gap:12px;margin:0 0 18px;font-size:11.5px;letter-spacing:.16em;text-transform:uppercase;color:var(--muted)}
.tb-eyebrow i{width:26px;height:1px;background:linear-gradient(90deg,transparent,var(--blue2))}
.tb-eyebrow i:last-child{transform:scaleX(-1)}
.tb-h1{margin:0;font-weight:500;font-size:clamp(38px,5.3vw,74px);line-height:1.02;letter-spacing:-.045em}
.tb-line{display:block}
.tb-h1 .w{display:inline-block;will-change:transform,filter,opacity}
.tb-h1 em{font-family:"Instrument Serif",Georgia,serif;font-style:italic;font-weight:400;letter-spacing:-.015em;font-size:1.1em;padding-right:.04em;
  background:linear-gradient(180deg,#ffffff 20%,#b9d0ff);-webkit-background-clip:text;background-clip:text;color:transparent}
.tb-h1 .dim{background:linear-gradient(180deg,#e9eefb 10%,#6f7c99 95%);-webkit-background-clip:text;background-clip:text;color:transparent}
.tb-sub{max-width:52ch;margin:20px 0 26px;font-size:clamp(15px,1.2vw,16.5px);line-height:1.55;color:var(--muted)}
.tb-actions{display:flex;gap:12px;align-items:center;justify-content:center}
.tb-cta{position:relative;overflow:hidden;display:inline-flex;align-items:center;gap:10px;height:46px;padding:0 18px 0 22px;border-radius:999px;color:#fff;text-decoration:none;font-weight:500;font-size:15px;
  background:linear-gradient(180deg,#77a2ff,#2d5de4);
  box-shadow:inset 0 0 0 1px rgba(190,212,255,.4),inset 0 1px 0 rgba(255,255,255,.35),0 12px 40px -10px rgba(70,120,255,.85),0 0 90px -12px rgba(70,120,255,.65);
  transition:transform .2s,box-shadow .2s}
.tb-cta::before{content:"";position:absolute;inset:0;background:linear-gradient(100deg,transparent 35%,rgba(255,255,255,.42) 50%,transparent 65%);transform:translateX(calc(var(--shine) * 100%));pointer-events:none}
.tb-cta svg{width:16px;height:16px;transition:transform .2s}
.tb-cta:hover{transform:translateY(-1px);box-shadow:inset 0 0 0 1px rgba(200,220,255,.55),inset 0 1px 0 rgba(255,255,255,.4),0 16px 50px -10px rgba(80,130,255,1),0 0 120px -10px rgba(80,130,255,.8)}
.tb-cta:hover svg{transform:translateX(3px)}
.tb-ghost{display:inline-flex;align-items:center;gap:10px;height:46px;padding:0 18px 0 8px;border-radius:999px;border:1px solid var(--line);background:rgba(10,16,32,.45);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);color:var(--ink);text-decoration:none;font-size:15px;transition:background .2s,border-color .2s}
.tb-ghost:hover{background:rgba(30,44,80,.55);border-color:rgba(169,200,255,.35)}
.tb-ghost .tb-play{display:grid;place-items:center;width:30px;height:30px;border-radius:50%;background:rgba(169,200,255,.14)}
.tb-ghost .tb-play svg{width:11px;height:11px;margin-left:2px}

/* ---------- city chips ---------- */
.tb-chips{position:absolute;inset:0;z-index:2;pointer-events:none}
.tb-chip{position:absolute;left:0;top:0;opacity:0;will-change:transform,opacity}
.tb-chip .dot{position:absolute;left:-4px;top:-4px;width:8px;height:8px;border-radius:50%;background:#cfe0ff;box-shadow:0 0 0 3px rgba(91,140,255,.35),0 0 14px #5b8cff}
.tb-chip .dot::after{content:"";position:absolute;inset:-3px;border-radius:50%;border:1px solid rgba(169,200,255,.9);transform:scale(calc(1 + var(--p) * 2.2));opacity:calc(1 - var(--p))}
.tb-chip .stem{position:absolute;left:-.5px;top:-40px;width:1px;height:34px;background:linear-gradient(to top,rgba(169,200,255,.85),rgba(169,200,255,0))}
.tb-chip .card{position:absolute;left:-12px;top:-42px;transform:translateY(-100%);white-space:nowrap;padding:8px 12px 9px;border-radius:12px;background:rgba(7,12,26,.62);border:1px solid rgba(169,200,255,.2);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);box-shadow:0 10px 30px -12px rgba(0,0,0,.8)}
.tb-chip strong{display:block;font-weight:500;font-size:12.5px;letter-spacing:-.005em}
.tb-chip span{display:block;margin-top:2px;font-size:11.5px;color:var(--muted);font-variant-numeric:tabular-nums}

/* ---------- footer telemetry ---------- */
.tb-foot{position:absolute;left:0;right:0;bottom:0;z-index:3;display:flex;justify-content:space-between;align-items:flex-end;gap:20px;padding:0 clamp(18px,3.4vw,44px) 22px;font-size:12px;letter-spacing:.04em;color:#dfe7fb;font-variant-numeric:tabular-nums;text-shadow:0 1px 10px rgba(0,0,0,.7)}
.tb-stats{display:flex;gap:26px}
.tb-foot small{display:block;margin-bottom:4px;font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:rgba(200,214,245,.6)}
.tb-next{text-align:right}

/* ---------- mobile sheet ---------- */
.tb-sheet{position:fixed;inset:0;z-index:5;display:flex;flex-direction:column;justify-content:center;gap:4px;padding:90px 30px;background:rgba(3,5,10,.86);-webkit-backdrop-filter:blur(18px);backdrop-filter:blur(18px);opacity:0;visibility:hidden;transition:opacity .25s,visibility .25s}
.tb-sheet[data-open]{opacity:1;visibility:visible}
.tb-sheet a{padding:8px 0;font-size:30px;letter-spacing:-.03em;color:var(--muted);text-decoration:none}
.tb-sheet a[aria-current="page"]{color:var(--ink)}
.tb-sheet a[aria-current="page"]::before{content:"[ ";color:var(--blue2)}
.tb-sheet a[aria-current="page"]::after{content:" ]";color:var(--blue2)}

.tb-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}

@media (max-width:860px){
  .tb-top{grid-template-columns:1fr auto}
  .tb-live,.tb-nav{display:none}
  .tb-menu{display:inline-flex}
  .tb-next,.tb-stats>div:nth-child(n+3){display:none}
}
@media (max-width:560px){
  .tb-copy{top:110px}
  .tb-h1{font-size:clamp(34px,10.4vw,48px)}
  .tb-sub{font-size:14.5px;margin:16px 0 22px}
  .tb-actions{flex-direction:column;width:100%;max-width:330px}
  .tb-cta,.tb-ghost{width:100%;justify-content:center}
  .tb-chip .card{padding:6px 10px 7px}
}
</style>
</head>
<body>
<section class="tb-hero" aria-labelledby="tb-title">
  <div class="tb-sky" aria-hidden="true"></div>
  <canvas class="tb-gl" aria-hidden="true"></canvas>
  <div class="tb-grain" aria-hidden="true"></div>

  <header class="tb-top" data-in="0">
    <a class="tb-logo" href="#" aria-label="Terrabeam home">
      <svg viewBox="0 0 32 32" fill="none" aria-hidden="true">
        <defs><linearGradient id="tb-lg" x1="6" y1="4" x2="26" y2="28"><stop stop-color="#cfe0ff"/><stop offset="1" stop-color="#3d6cf0"/></linearGradient></defs>
        <circle cx="16" cy="16" r="8.5" fill="url(#tb-lg)"/>
        <ellipse cx="16" cy="16" rx="14" ry="5.2" transform="rotate(-24 16 16)" stroke="#a9c8ff" stroke-opacity=".75" stroke-width="1.3"/>
        <circle cx="27.6" cy="10.4" r="1.9" fill="#fff"/>
      </svg>
      Terrabeam
    </a>
    <div class="tb-live" aria-label="Live feed status">
      <span class="tb-pulse" aria-hidden="true"></span><b>Live</b>
      <span class="tb-sep" aria-hidden="true"></span>
      <span>UTC <b id="tb-clock">00:00:00</b></span>
    </div>
    <nav class="tb-nav" aria-label="Main">
      <span class="tb-br" aria-hidden="true">[</span><span class="tb-br" aria-hidden="true">]</span>
      <a href="#" data-br aria-current="page">Live globe</a>
      <a href="#" data-br>Missions</a>
      <a href="#" data-br>Data API</a>
      <a href="#" data-br>Pricing</a>
      <span class="tb-div" aria-hidden="true"></span>
      <a href="#" class="tb-signin">Sign in</a>
    </nav>
    <button class="tb-menu" type="button" aria-expanded="false" aria-controls="tb-sheet"><span aria-hidden="true">[</span>Menu<span aria-hidden="true">]</span></button>
  </header>

  <div class="tb-sheet" id="tb-sheet" role="dialog" aria-modal="true" aria-label="Menu">
    <a href="#" aria-current="page">Live globe</a>
    <a href="#">Missions</a>
    <a href="#">Data API</a>
    <a href="#">Pricing</a>
    <a href="#">Sign in</a>
  </div>

  <div class="tb-copy">
    <p class="tb-eyebrow" data-in="1"><i></i>Live from orbit · no dish, no setup<i></i></p>
    <h1 class="tb-h1" id="tb-title">
      <span class="tb-line"><span class="w">Watch</span> <span class="w">the</span> <em class="w">whole planet</em></span>
      <span class="tb-line"><span class="w">turn</span> <span class="w dim">in</span> <span class="w dim">real</span> <span class="w dim">time.</span></span>
    </h1>
    <p class="tb-sub" data-in="2">Terrabeam stitches fresh satellite passes into one living globe. Spin it, search any city and share the exact view with a link.</p>
    <div class="tb-actions" data-in="3">
      <a class="tb-cta" href="#">Open the live globe
        <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8h10M9 4l4 4-4 4"/></svg>
      </a>
      <a class="tb-ghost" href="#"><span class="tb-play" aria-hidden="true"><svg viewBox="0 0 10 12" fill="currentColor"><path d="M0 0l10 6-10 6z"/></svg></span>Take the 90-second tour</a>
    </div>
  </div>

  <div class="tb-chips" aria-hidden="true"></div>

  <div class="tb-foot" data-in="4">
    <div class="tb-stats">
      <div><small>Pass</small><span id="tb-pass">#04,812</span></div>
      <div><small>Ground speed</small><span id="tb-speed">27,580 km/h</span></div>
      <div><small>Altitude</small><span id="tb-alt">512.4 km</span></div>
    </div>
    <div class="tb-next"><small>Next sweep · Bay of Bengal</small><span id="tb-count">T-00:42</span></div>
  </div>
  <span class="tb-sr" role="status" aria-live="polite"></span>
</section>

<script type="importmap">
{ "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js" } }
</script>
<script type="module">
import * as THREE from 'three';

/* ---------- config: edit freely ---------- */
const CDN = 'https://cdn.jsdelivr.net/npm/';
const TEX = {
  day:    CDN + 'three-globe@2.45.6/example/img/earth-blue-marble.jpg',
  night:  CDN + 'three-globe@2.45.6/example/img/earth-night.jpg',
  water:  CDN + 'three-globe@2.45.6/example/img/earth-water.png',
  clouds: CDN + 'globe.gl@2.46.2/example/clouds/clouds.png'
};
const START_LON = 66;          // longitude facing the viewer when the page opens
const SPIN = 0.034;            // radians per second
const CITIES = [
  { name: 'Visakhapatnam', lat: 17.69, lon: 83.22,   line: '29°C · clear · pass in 12m' },
  { name: 'Dubai',         lat: 25.20, lon: 55.27,   line: '34°C · haze · pass in 31m' },
  { name: 'Cairo',         lat: 30.04, lon: 31.24,   line: '27°C · clear · live now' },
  { name: 'Lisbon',        lat: 38.72, lon: -9.14,   line: '19°C · cloud · pass in 48m' },
  { name: 'Shanghai',      lat: 31.23, lon: 121.47,  line: '21°C · mist · pass in 19m' },
  { name: 'Tokyo',         lat: 35.68, lon: 139.69,  line: '16°C · rain · pass in 7m' },
  { name: 'New York',      lat: 40.71, lon: -74.00,  line: '12°C · clear · pass in 54m' },
  { name: 'Mexico City',   lat: 19.43, lon: -99.13,  line: '22°C · sun · pass in 26m' },
  { name: 'San Francisco', lat: 37.77, lon: -122.42, line: '15°C · fog · pass in 38m' }
];

const root = document.documentElement;
const hero = document.querySelector('.tb-hero');
const canvas = document.querySelector('.tb-gl');
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
const easeOut = x => 1 - Math.pow(1 - x, 3);

/* ---------- intro targets (hidden until the globe is ready) ---------- */
const intro = [];
const words = [...document.querySelectorAll('.tb-h1 .w')];
document.querySelectorAll('[data-in]').forEach(el => {
  const i = +el.dataset.in;
  const delay = i === 0 ? 0.15 : i === 1 ? 0.2 : i === 2 ? 0.55 + words.length * 0.085 : i === 3 ? 0.75 + words.length * 0.085 : 1.6;
  intro.push({ el, delay, dur: 0.9, blur: i === 0 || i === 4 ? 0 : 6, y: i === 0 ? -8 : 10 });
});
words.forEach((el, i) => intro.push({ el, delay: 0.35 + i * 0.085, dur: 1.0, blur: 14, y: 16 }));
intro.forEach(it => { it.el.style.opacity = 0; });

function runIntro(t) {
  let busy = false;
  for (const it of intro) {
    if (it.done) continue;
    const p = reduce ? 1 : clamp((t - it.delay) / it.dur, 0, 1);
    const e = easeOut(p);
    it.el.style.opacity = e;
    it.el.style.transform = p < 1 ? `translateY(${(1 - e) * it.y}px)` : '';
    it.el.style.filter = p < 1 && it.blur ? `blur(${(1 - e) * it.blur}px)` : '';
    if (p >= 1) it.done = true; else busy = true;
  }
  return busy;
}

/* ---------- bracket nav ---------- */
const nav = document.querySelector('.tb-nav');
const [brL, brR] = nav.querySelectorAll('.tb-br');
const brLinks = [...nav.querySelectorAll('a[data-br]')];
let brTarget = brLinks.find(a => a.getAttribute('aria-current')) || brLinks[0];
const br = { l: 0, r: 0, vl: 0, vr: 0, init: false };
brLinks.forEach(a => {
  a.addEventListener('pointerenter', () => { brTarget = a; });
  a.addEventListener('focus', () => { brTarget = a; });
  a.addEventListener('click', e => {
    e.preventDefault();
    brLinks.forEach(x => x.removeAttribute('aria-current'));
    a.setAttribute('aria-current', 'page');
  });
});
nav.addEventListener('pointerleave', () => { brTarget = brLinks.find(a => a.getAttribute('aria-current')) || brLinks[0]; });
function stepBrackets(dt) {
  if (!nav.offsetParent) return;
  const tl = brTarget.offsetLeft - 1;
  const tr = brTarget.offsetLeft + brTarget.offsetWidth - brR.offsetWidth + 1;
  if (!br.init || reduce) { br.l = tl; br.r = tr; br.init = true; }
  const k = 300, c = 24;
  br.vl += (k * (tl - br.l) - c * br.vl) * dt; br.l += br.vl * dt;
  br.vr += (k * (tr - br.r) - c * br.vr) * dt; br.r += br.vr * dt;
  brL.style.transform = `translate(${br.l}px,-54%)`;
  brR.style.transform = `translate(${br.r}px,-54%)`;
}

/* ---------- mobile menu ---------- */
const menuBtn = document.querySelector('.tb-menu');
const sheet = document.getElementById('tb-sheet');
function setMenu(open) {
  menuBtn.setAttribute('aria-expanded', String(open));
  sheet.toggleAttribute('data-open', open);
  if (open) sheet.querySelector('a').focus(); else menuBtn.focus();
}
menuBtn.addEventListener('click', () => setMenu(menuBtn.getAttribute('aria-expanded') !== 'true'));
document.addEventListener('keydown', e => { if (e.key === 'Escape' && sheet.hasAttribute('data-open')) setMenu(false); });
sheet.addEventListener('click', e => { if (e.target.closest('a')) { e.preventDefault(); setMenu(false); } });

/* ---------- live readouts ---------- */
const $clock = document.getElementById('tb-clock');
const $pass = document.getElementById('tb-pass');
const $speed = document.getElementById('tb-speed');
const $alt = document.getElementById('tb-alt');
const $count = document.getElementById('tb-count');
const utcStart = Date.now();
const pad = n => String(n).padStart(2, '0');
let lastTick = -1;
function readouts(t) {
  const d = new Date(utcStart + t * 1000);
  $clock.textContent = `${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}`;
  const tick = Math.floor(t * 2);
  if (tick === lastTick) return;
  lastTick = tick;
  $pass.textContent = '#' + (4812 + Math.floor(t / 6)).toLocaleString('en-US', { minimumIntegerDigits: 5 });
  $speed.textContent = (27580 + Math.round(Math.sin(t * 1.7) * 9 + Math.sin(t * 4.1) * 4)).toLocaleString('en-US') + ' km/h';
  $alt.textContent = (512.4 + Math.sin(t * 0.6) * 0.6).toFixed(1) + ' km';
  const left = 42 - Math.floor(t % 43);
  $count.textContent = 'T-00:' + pad(left);
}

/* ---------- three.js ---------- */
let renderer;
try {
  renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: 'high-performance' });
} catch (e) {
  intro.forEach(it => { it.el.style.opacity = 1; it.done = true; });
  throw e;
}
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);

const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 1, 20000);
camera.position.z = 6000;

const SUN = new THREE.Vector3(1.25, 0.55, 0.5).normalize();

// stars
const starGeo = new THREE.BufferGeometry();
const STARS = 1400, sp = new Float32Array(STARS * 3), ss = new Float32Array(STARS);
for (let i = 0; i < STARS; i++) {
  sp[i * 3] = Math.random() - 0.5; sp[i * 3 + 1] = Math.random() - 0.5; sp[i * 3 + 2] = -4000;
  ss[i] = Math.random();
}
starGeo.setAttribute('position', new THREE.BufferAttribute(sp, 3));
starGeo.setAttribute('seed', new THREE.BufferAttribute(ss, 1));
const starMat = new THREE.ShaderMaterial({
  transparent: true, depthWrite: false, blending: THREE.AdditiveBlending,
  uniforms: { uTime: { value: 0 }, uSize: { value: new THREE.Vector2(1, 1) }, uPR: { value: 1 } },
  vertexShader: `attribute float seed; uniform float uTime; uniform vec2 uSize; uniform float uPR; varying float vA;
    void main(){ vec3 p = position; p.xy *= uSize;
      vA = (0.25 + 0.75 * seed) * (0.65 + 0.35 * sin(uTime * (0.6 + seed * 1.8) + seed * 40.0));
      gl_PointSize = (seed > 0.94 ? 2.4 : 1.2) * uPR;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0); }`,
  fragmentShader: `varying float vA; void main(){ vec2 c = gl_PointCoord - 0.5; float d = 1.0 - smoothstep(0.2, 0.5, length(c)); gl_FragColor = vec4(vec3(0.85, 0.9, 1.0), d * vA); }`
});
scene.add(new THREE.Points(starGeo, starMat));

// globe
const globe = new THREE.Group();       // placement + parallax
const axis = new THREE.Group();        // fixed tilt so the northern band faces us
axis.rotation.set(-0.52, 0, 0.16);
globe.add(axis);
scene.add(globe);

const sphere = new THREE.SphereGeometry(1, 160, 120);
const earthMat = new THREE.ShaderMaterial({
  uniforms: { dayMap: { value: null }, nightMap: { value: null }, waterMap: { value: null }, sun: { value: SUN } },
  vertexShader: `varying vec2 vUv; varying vec3 vN;
    void main(){ vUv = uv; vN = normalize(mat3(modelMatrix) * normal); gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); }`,
  fragmentShader: `uniform sampler2D dayMap, nightMap, waterMap; uniform vec3 sun; varying vec2 vUv; varying vec3 vN;
    void main(){
      vec3 n = normalize(vN); vec3 V = vec3(0.0, 0.0, 1.0);
      float d = dot(n, sun);
      float dayMix = smoothstep(-0.18, 0.22, d);
      vec3 day = texture2D(dayMap, vUv).rgb * 1.12;
      vec3 night = texture2D(nightMap, vUv).rgb;
      night = pow(night, vec3(1.4)) * vec3(1.0, 0.72, 0.42) * 2.2;
      float lit = clamp(d * 0.85 + 0.32, 0.0, 1.0);
      vec3 col = mix(night, day * lit, dayMix);
      float water = texture2D(waterMap, vUv).r;
      vec3 H = normalize(sun + V);
      col += vec3(0.55, 0.72, 1.0) * pow(max(dot(n, H), 0.0), 60.0) * water * 0.55 * dayMix;
      float fres = pow(1.0 - max(dot(n, V), 0.0), 2.6);
      col = mix(col, vec3(0.32, 0.58, 1.0), fres * (0.25 + 0.55 * dayMix));
      gl_FragColor = vec4(col, 1.0);
      #include <colorspace_fragment>
    }`
});
const earth = new THREE.Mesh(sphere, earthMat);
axis.add(earth);

const cloudMat = new THREE.ShaderMaterial({
  transparent: true, depthWrite: false,
  uniforms: { map: { value: null }, sun: { value: SUN }, uOpacity: { value: 0 } },
  vertexShader: earthMat.vertexShader,
  fragmentShader: `uniform sampler2D map; uniform vec3 sun; uniform float uOpacity; varying vec2 vUv; varying vec3 vN;
    void main(){ vec3 n = normalize(vN); float d = dot(n, sun); float light = smoothstep(-0.12, 0.35, d);
      float a = texture2D(map, vUv).a * uOpacity * (0.15 + 0.75 * light);
      gl_FragColor = vec4(vec3(0.96, 0.98, 1.0) * (0.35 + 0.65 * light), a);
      #include <colorspace_fragment>
    }`
});
const clouds = new THREE.Mesh(sphere, cloudMat);
clouds.scale.setScalar(1.006);
axis.add(clouds);

const haloMat = new THREE.ShaderMaterial({
  side: THREE.BackSide, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending,
  vertexShader: `varying vec3 vN; void main(){ vN = normalize(mat3(modelMatrix) * normal); gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); }`,
  fragmentShader: `varying vec3 vN; uniform vec3 sun;
    void main(){ float k = clamp(-vN.z / 0.47, 0.0, 1.0); float i = pow(k, 3.2);
      float side = 0.55 + 0.45 * smoothstep(-0.6, 0.6, dot(normalize(vec3(vN.xy, 0.0)), normalize(vec3(sun.xy, 0.0))));
      gl_FragColor = vec4(vec3(0.3, 0.56, 1.0) * i * 1.6 * side, i); }`,
  uniforms: { sun: { value: SUN } }
});
const halo = new THREE.Mesh(sphere, haloMat);
halo.scale.setScalar(1.13);
halo.renderOrder = 2;
globe.add(halo);

// orbits + satellites
function glowTexture() {
  const c = document.createElement('canvas'); c.width = c.height = 64;
  const g = c.getContext('2d'); const r = g.createRadialGradient(32, 32, 0, 32, 32, 32);
  r.addColorStop(0, 'rgba(255,255,255,1)'); r.addColorStop(0.18, 'rgba(210,228,255,.95)');
  r.addColorStop(0.45, 'rgba(91,140,255,.35)'); r.addColorStop(1, 'rgba(91,140,255,0)');
  g.fillStyle = r; g.fillRect(0, 0, 64, 64);
  const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
}
const glow = glowTexture();
const TRAIL = 46;
const orbits = [
  { r: 1.075, rx: 0.36, rz: -0.2, speed: 0.13, sats: [0.2, 3.4], dashed: false },
  { r: 1.15, rx: 0.5, rz: 0.24, speed: -0.09, sats: [1.4], dashed: true }
].map(o => {
  const g = new THREE.Group(); g.rotation.set(o.rx, 0, o.rz); globe.add(g);
  const pts = []; for (let i = 0; i <= 256; i++) { const a = i / 256 * Math.PI * 2; pts.push(new THREE.Vector3(Math.cos(a) * o.r, Math.sin(a) * o.r, 0)); }
  const lg = new THREE.BufferGeometry().setFromPoints(pts);
  const lm = o.dashed
    ? new THREE.LineDashedMaterial({ color: 0xa9c8ff, transparent: true, opacity: 0.3, dashSize: 0.012, gapSize: 0.01 })
    : new THREE.LineBasicMaterial({ color: 0xa9c8ff, transparent: true, opacity: 0.22 });
  const line = new THREE.Line(lg, lm); if (o.dashed) line.computeLineDistances(); g.add(line);
  o.sats = o.sats.map(a0 => {
    const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map: glow, blending: THREE.AdditiveBlending, depthWrite: false, transparent: true }));
    g.add(sprite);
    const tp = new Float32Array(TRAIL * 3), tc = new Float32Array(TRAIL * 4);
    for (let i = 0; i < TRAIL; i++) { const f = 1 - i / TRAIL; tc.set([0.66, 0.78, 1.0, f * f * 0.9], i * 4); }
    const tg = new THREE.BufferGeometry();
    tg.setAttribute('position', new THREE.BufferAttribute(tp, 3));
    tg.setAttribute('color', new THREE.BufferAttribute(tc, 4));
    const trail = new THREE.Line(tg, new THREE.LineBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false }));
    g.add(trail);
    return { a0, sprite, trail, tp };
  });
  return o;
});

// city chips
const chipLayer = document.querySelector('.tb-chips');
const tmp = new THREE.Vector3();
CITIES.forEach(c => {
  const phi = (90 - c.lat) * Math.PI / 180, theta = (c.lon + 180) * Math.PI / 180;
  c.v = new THREE.Vector3(-Math.sin(phi) * Math.cos(theta), Math.cos(phi), Math.sin(phi) * Math.sin(theta));
  c.el = document.createElement('div');
  c.el.className = 'tb-chip';
  c.el.innerHTML = `<i class="dot"></i><i class="stem"></i><div class="card"><strong>${c.name}</strong><span>${c.line}</span></div>`;
  chipLayer.appendChild(c.el);
  c.o = 0;
});
// spin so START_LON faces the viewer
{
  const phi = Math.PI / 2, theta = (START_LON + 180) * Math.PI / 180;
  const x = -Math.sin(phi) * Math.cos(theta), z = Math.sin(phi) * Math.sin(theta);
  earth.userData.base = -Math.atan2(x, z);
}

/* ---------- layout ---------- */
const view = { w: 0, h: 0, R: 0, cy: 0, minChipY: 0, mobile: false };
const actions = document.querySelector('.tb-actions');
function layout() {
  const w = hero.clientWidth, h = hero.clientHeight;
  view.w = w; view.h = h; view.mobile = w < 760;
  renderer.setSize(w, h, false);
  camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2; camera.updateProjectionMatrix();
  const D = view.mobile ? w * 2.15 : Math.max(w * 1.12, h * 1.32);
  const topPx = h * (view.mobile ? 0.66 : 0.615);
  view.R = D / 2;
  view.cy = h / 2 - topPx - view.R;
  globe.scale.setScalar(view.R);
  starMat.uniforms.uSize.value.set(w, h);
  starMat.uniforms.uPR.value = renderer.getPixelRatio();
  orbits.forEach(o => o.sats.forEach(s => s.sprite.scale.setScalar((view.mobile ? 30 : 38) / view.R)));
  const ab = actions.getBoundingClientRect(), hb = hero.getBoundingClientRect();
  view.minChipY = ab.bottom - hb.top + (view.mobile ? 70 : 96);
}
new ResizeObserver(layout).observe(hero);
layout();

/* ---------- pointer parallax ---------- */
const ptr = { x: 0, y: 0, sx: 0, sy: 0 };
window.addEventListener('pointermove', e => {
  ptr.x = e.clientX / innerWidth - 0.5;
  ptr.y = e.clientY / innerHeight - 0.5;
});

/* ---------- textures ---------- */
const loader = new THREE.TextureLoader();
const load = (url, srgb) => new Promise((res, rej) => loader.load(url, t => {
  if (srgb) t.colorSpace = THREE.SRGBColorSpace;
  t.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
  res(t);
}, undefined, rej));

let t0 = null, last = 0, cloudsReady = false;
Promise.all([load(TEX.day, true), load(TEX.night, true), load(TEX.water, false)]).then(([day, night, water]) => {
  earthMat.uniforms.dayMap.value = day;
  earthMat.uniforms.nightMap.value = night;
  earthMat.uniforms.waterMap.value = water;
  t0 = performance.now();
  last = t0;
  root.dataset.ready = '1';
  load(TEX.clouds, false).then(c => { cloudMat.uniforms.map.value = c; cloudsReady = true; root.dataset.clouds = '1'; }).catch(() => { root.dataset.clouds = '0'; });
}).catch(() => {
  intro.forEach(it => { it.el.style.opacity = 1; it.el.style.filter = ''; it.el.style.transform = ''; it.done = true; });
});

/* ---------- loop ---------- */
function frame(now) {
  requestAnimationFrame(frame);
  if (t0 === null) return;
  const dt = Math.min(0.05, (now - last) / 1000); last = now;
  const t = (now - t0) / 1000;

  runIntro(t);
  stepBrackets(dt);
  readouts(t);
  root.style.setProperty('--p', ((t % 1.8) / 1.8).toFixed(3));
  const sw = (t % 5.2) / 1.1;
  root.style.setProperty('--shine', (sw < 1 ? -1.4 + sw * 2.8 : 1.4).toFixed(3));

  // globe rise + parallax
  const rise = reduce ? 1 : easeOut(clamp((t - 0.05) / 2.4, 0, 1));
  const f = reduce ? 0 : 1 - Math.exp(-dt * 3);
  ptr.sx += (ptr.x - ptr.sx) * f; ptr.sy += (ptr.y - ptr.sy) * f;
  globe.position.set(-ptr.sx * 24, view.cy - (1 - rise) * view.h * 0.42 + ptr.sy * 14, 0);
  globe.rotation.set(ptr.sy * 0.07, ptr.sx * 0.12, 0);

  const spin = SPIN * (reduce ? 0.35 : 1);
  earth.rotation.y = earth.userData.base + t * spin;
  clouds.rotation.y = earth.rotation.y + t * spin * 0.35;
  if (cloudsReady) cloudMat.uniforms.uOpacity.value = Math.min(1, cloudMat.uniforms.uOpacity.value + dt * 0.6);
  starMat.uniforms.uTime.value = t;

  // satellites
  for (const o of orbits) for (const s of o.sats) {
    const a = s.a0 + t * o.speed;
    s.sprite.position.set(Math.cos(a) * o.r, Math.sin(a) * o.r, 0);
    for (let i = 0; i < TRAIL; i++) {
      const b = a - Math.sign(o.speed) * i * 0.006;
      s.tp[i * 3] = Math.cos(b) * o.r; s.tp[i * 3 + 1] = Math.sin(b) * o.r; s.tp[i * 3 + 2] = 0;
    }
    s.trail.geometry.attributes.position.needsUpdate = true;
  }

  renderer.render(scene, camera);

  // chips: three most-facing cities that sit below the buttons
  earth.updateMatrixWorld();
  const center = new THREE.Vector3().setFromMatrixPosition(globe.matrixWorld);
  const cands = [];
  for (const c of CITIES) {
    tmp.copy(c.v).applyMatrix4(earth.matrixWorld);
    const facing = (tmp.z - center.z) / view.R;
    c.x = view.w / 2 + tmp.x; c.y = view.h / 2 - tmp.y;
    const ok = facing > 0.3 && c.y > view.minChipY && c.y < view.h - (view.mobile ? 60 : 80) && c.x > 40 && c.x < view.w - 190;
    c.score = ok ? facing : -1;
    if (ok) cands.push(c);
  }
  cands.sort((a, b) => b.score - a.score);
  const keep = new Set(cands.slice(0, view.mobile ? 2 : 3));
  const chipIn = reduce ? 1 : clamp((t - 2.2) / 0.6, 0, 1);
  for (const c of CITIES) {
    const target = keep.has(c) ? chipIn : 0;
    c.o += (target - c.o) * Math.min(1, dt * 5);
    c.el.style.opacity = c.o.toFixed(3);
    if (c.o > 0.005) c.el.style.transform = `translate3d(${c.x.toFixed(1)}px,${(c.y + (1 - c.o) * 8).toFixed(1)}px,0)`;
  }
}
requestAnimationFrame(frame);
</script>
</body>
</html>
```


## Build instructions by tool

### Claude Code

Open a terminal in an empty folder, run `claude`, then paste the prompt.

```text
Build the "Live Earth orbit hero" app from the OwnlyPlans blueprint at https://ownlyplans.com/bhaskar/live-earth-orbit-hero/.
Stack: CSS, HTML, JavaScript, Three.js, WebGL.
Follow the plan's steps in order: Set the stage and the copy → Render the Earth with Three.js → Add orbits, satellites and live city cards → Intro, bracket nav, parallax and the phone version.
Download the full plan (Markdown) from the link above and keep it in the project root as PLAN.md.
Ask me before adding anything not in the plan. (Prepared for Claude Code.)
```

### Cursor

Open an empty folder in Cursor, start an Agent chat, then paste the prompt.

```text
Build the "Live Earth orbit hero" app from the OwnlyPlans blueprint at https://ownlyplans.com/bhaskar/live-earth-orbit-hero/.
Stack: CSS, HTML, JavaScript, Three.js, WebGL.
Follow the plan's steps in order: Set the stage and the copy → Render the Earth with Three.js → Add orbits, satellites and live city cards → Intro, bracket nav, parallax and the phone version.
Download the full plan (Markdown) from the link above and keep it in the project root as PLAN.md.
Ask me before adding anything not in the plan. (Prepared for Cursor.)
```

### Lovable

Start a new Lovable project and paste the prompt as your first message.

```text
Build the "Live Earth orbit hero" app from the OwnlyPlans blueprint at https://ownlyplans.com/bhaskar/live-earth-orbit-hero/.
Stack: CSS, HTML, JavaScript, Three.js, WebGL.
Follow the plan's steps in order: Set the stage and the copy → Render the Earth with Three.js → Add orbits, satellites and live city cards → Intro, bracket nav, parallax and the phone version.
Download the full plan (Markdown) from the link above and keep it in the project root as PLAN.md.
Ask me before adding anything not in the plan. (Prepared for Lovable.)
```

## Definition of done

- Every build step is complete and the app runs locally.
- The main user flow works end to end.
- Share your build on OwnlyPlans with a demo link, build time and tool.
