sleeper-hero.html
The finished file. Open it in a browser.
Part of Sleeper night train hero seen through a window by Admin
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="theme-color" content="#15121f"> <title>Sleeper · Overnight train journeys</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Young+Serif&family=Hanken+Grotesk:wght@400;500;600&display=swap"> <style> :root{--cabin:#15121f;--cabin2:#1d1830;--lamp:#ffcf6b;--mist:#cfcbe8;--wood:#2a1f19;--wood2:#4a3829; --serif:"Young Serif",Georgia,"Times New Roman",serif;--sans:"Hanken Grotesk",system-ui,-apple-system,"Segoe UI",sans-serif} {box-sizing:border-box;margin:0} html,body{height:100%;background:var(--cabin);color:#f4f1ff;font-family:var(--sans);-webkit-font-smoothing:antialiased} .hero{position:relative;min-height:100vh;min-height:100svh;overflow:hidden;display:grid;grid-template-rows:auto 1fr; background:radial-gradient(70% 60% at 12% 18%,rgba(255,207,107,.14),transparent 70%),linear-gradient(180deg,#191529,#120f1c)} header{display:flex;justify-content:space-between;align-items:center;padding:clamp(22px,3vw,34px) clamp(22px,5vw,72px)} .logo{font-family:var(--serif);font-size:24px;color:#fff;text-decoration:none;letter-spacing:-.01em} nav{display:flex;gap:26px;align-items:center;font-size:15px} nav a{color:var(--mist);text-decoration:none} nav a:hover,nav a:focus-visible{color:#fff} nav .pill{color:#1b1411;background:var(--lamp);padding:9px 16px;border-radius:999px;font-weight:600} a:focus-visible,button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--lamp);outline-offset:3px;border-radius:6px} .stage{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.12fr);gap:clamp(24px,4vw,64px);align-items:center;padding:0 clamp(22px,5vw,72px) clamp(26px,4vw,48px);min-height:0} .copy{max-width:600px} h1{font-family:var(--serif);font-weight:400;font-size:clamp(38px,5.4vw,78px);line-height:1.04;letter-spacing:-.025em} .lead{margin-top:20px;max-width:42ch;font-size:clamp(16px,1.4vw,18px);line-height:1.6;color:#d6d2ee} form{margin-top:28px;display:grid;grid-template-columns:1fr 1fr 1fr auto;background:#221c38;border:1px solid rgba(255,255,255,.12);border-radius:16px;padding:7px;max-width:640px} label{display:grid;gap:3px;padding:9px 14px;border-right:1px solid rgba(255,255,255,.1);min-width:0} label:nth-of-type(3){border-right:0} label span{font-size:12px;color:var(--mist)} input,select{background:transparent;border:0;color:#fff;font:500 16px var(--sans);padding:2px 0;width:100%;min-width:0;color-scheme:dark} select option{color:#111} button.go{background:var(--lamp);color:#1b1411;font:600 15px var(--sans);border:0;border-radius:11px;padding:0 20px;cursor:pointer} button.go:hover{background:#ffdc8e} .note{margin-top:14px;font-size:14px;color:var(--mist)} / window */ .win{position:relative;width:100%;height:min(74vh,660px);min-height:360px;border-radius:30px;padding:clamp(10px,1.2vw,16px); background:linear-gradient(145deg,#4a3829,#2a1f19 60%,#1d1511);box-shadow:0 30px 80px rgba(0,0,0,.55),inset 0 2px 0 rgba(255,255,255,.1),inset 0 -3px 0 rgba(0,0,0,.4)} .glass{position:relative;width:100%;height:100%;border-radius:20px;overflow:hidden;background:#0b0d24;box-shadow:inset 0 0 0 2px rgba(0,0,0,.6),inset 0 0 60px rgba(0,0,0,.45)} canvas{position:absolute;inset:0;width:100%;height:100%;display:block} .refl{position:absolute;inset:0;pointer-events:none;background:linear-gradient(112deg,rgba(255,255,255,.11) 0%,rgba(255,255,255,0) 22%,rgba(255,255,255,0) 58%,rgba(255,255,255,.07) 70%,rgba(255,255,255,0) 78%)} .blind{position:absolute;left:0;right:0;top:0;height:46%;background:repeating-linear-gradient(180deg,#d9d1c0 0,#d9d1c0 11px,#c4bba7 11px,#c4bba7 13px);box-shadow:0 8px 24px rgba(0,0,0,.45);transition:height 1.4s cubic-bezier(.5,0,.2,1);transform-origin:top;border-bottom:6px solid #a89e88} .blind.up{height:0;border-bottom-width:0;box-shadow:none} .pull{position:absolute;left:50%;bottom:-26px;width:44px;height:20px;margin-left:-22px;border-radius:6px;background:#a89e88;border:0;cursor:pointer;color:transparent;font-size:0;box-shadow:0 2px 6px rgba(0,0,0,.4)} .blind.up .pull{bottom:-34px;opacity:0;pointer-events:none} .tag{position:absolute;left:14px;bottom:14px;z-index:2;max-width:calc(100% - 28px);padding:9px 14px;border-radius:12px;background:rgba(15,12,28,.62);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border:1px solid rgba(255,255,255,.14);font-size:14px;line-height:1.35;color:#f4f1ff} .tag b{display:block;font-weight:600} .tag small{color:var(--mist);font-size:13px} @media (max-width:860px){ nav a:not(.pill){display:none} .stage{grid-template-columns:1fr;gap:22px;align-content:start} .win{order:-1;height:min(46svh,420px);min-height:260px;border-radius:24px} form{grid-template-columns:1fr 1fr} label{border-right:0;border-bottom:1px solid rgba(255,255,255,.1)} label:nth-of-type(1){grid-column:1/-1} label:nth-of-type(3){border-bottom:0} button.go{grid-column:1/-1;padding:15px;margin-top:6px} } @media (prefers-reduced-motion:reduce){.blind{transition:none}} </style> </head> <body> <section class="hero" id="hero"> <header> <a class="logo" href="#">Sleeper</a> <nav><a href="#">Routes</a><a href="#">Berths</a><a href="#">Help</a><a class="pill" href="#">Sign in</a></nav> </header> <div class="stage"> <div class="copy"> <h1>Go to sleep in Delhi. Wake up by the sea.</h1> <p class="lead">Overnight trains across India with real berth maps, honest arrival times and a quiet cabin. Pick a route and see which seats are still free.</p> <form onsubmit="return false" aria-label="Find a night train"> <label><span>From</span><input type="text" value="New Delhi" aria-label="From"></label> <label><span>To</span><input type="text" value="Visakhapatnam" aria-label="To"></label> <label><span>Berth</span><select aria-label="Berth"><option>2 tier AC</option><option>3 tier AC</option><option>1st class</option></select></label> <button class="go" type="submit">Find night trains</button> </form> <p class="note">Tonight: 14 routes leave after 8 pm</p> </div> <div class="win"> <div class="glass"> <canvas id="view" role="img" aria-label="A train window: the countryside at night slowly turns to sunrise over the sea"></canvas> <div class="refl"></div> <div class="blind" id="blind"><button class="pull" id="pull" type="button" aria-label="Raise the blind" aria-expanded="false">Raise the blind</button></div> <div class="tag" aria-live="off"><b id="place">Leaving New Delhi</b><small id="clock">21:40 · 12723 Telangana Express</small></div> </div> </div> </div> </section> <script> (function(){ var reduce=matchMedia('(prefers-reduced-motion:reduce)').matches; var cv=document.getElementById('view'),g=cv.getContext('2d'),W=0,H=0; function size(){var d=Math.min(1.5,devicePixelRatio||1);W=cv.clientWidth;H=cv.clientHeight;cv.width=W*d;cv.height=H*d;g.setTransform(d,0,0,d,0,0)} addEventListener('resize',size);size(); // helpers function lerp(a,b,t){return a+(b-a)*t} function hex(h){return [parseInt(h.slice(1,3),16),parseInt(h.slice(3,5),16),parseInt(h.slice(5,7),16)]} function mix(a,b,t){var A=hex(a),B=hex(b);return 'rgb('+Math.round(lerp(A[0],B[0],t))+','+Math.round(lerp(A[1],B[1],t))+','+Math.round(lerp(A[2],B[2],t))+')'} var seed=7;function rnd(){seed=(seed*16807)%2147483647;return (seed-1)/2147483646} // scenery strips (positions in a looping strip of length L) var L=2400,trees=[],houses=[],poles=[]; for(var i=0;i<40;i++)trees.push({x:rnd()L,s:.7+rnd().8,k:rnd()<.35?'palm':'round'}); for(var j=0;j<9;j++)houses.push({x:rnd()*L,n:2+Math.floor(rnd()*3)}); // state var phase=0,off=(/o=([0-9.]+)/.exec(location.hash)||[0,0])[1]*1,last=performance.now(),pin=/#p=([0-9.]+)/.exec(location.hash); function wrap(x,len){return ((x%len)+len)%len} function hillY(x,base,a1,p1,a2,p2,ph){return base-(a1*Math.sin(x/p1+ph)+a2*Math.sin(x/p2+ph*1.7))} function draw(now){ var dt=Math.min(60,now-last);last=now; if(!reduce)off+=dt*.06; var p=pin?parseFloat(pin[1]):(reduce?.55:(1-Math.cos(now/1000/52*Math.PI*2))/2); phase=p; var hy=H*.54; // sky var sk=g.createLinearGradient(0,0,0,hy); sk.addColorStop(0,mix('#080a20','#3a4a86',p));sk.addColorStop(.55,mix('#1b1a45','#a8708f',p));sk.addColorStop(1,mix('#43346a','#ffc58a',p)); g.fillStyle=sk;g.fillRect(0,0,W,hy+2); // stars var sa=Math.max(0,1-p*1.6); if(sa>0){for(var s=0;s<70;s++){var sx=(s*97.3)%W,sy=((s*53.7)%(hy*.8)),tw=.5+.5*Math.sin(now/900+s);g.fillStyle='rgba(255,246,222,'+(sa*(.3+.6*tw)).toFixed(2)+')';g.fillRect(sx,sy,s%5?1.2:2,s%5?1.2:2)}} // moon var ma=Math.max(0,1-p*1.8); if(ma>0){var mx=W*.2,my=H*.17;var mg=g.createRadialGradient(mx,my,4,mx,my,70);mg.addColorStop(0,'rgba(255,240,200,'+(.5*ma)+')');mg.addColorStop(1,'rgba(255,240,200,0)');g.fillStyle=mg;g.fillRect(mx-80,my-80,160,160);g.fillStyle='rgba(247,232,190,'+ma+')';g.beginPath();g.arc(mx,my,16,0,7);g.fill()} // sun var sunX=W*.72,sunY=lerp(hy+H*.12,hy-H*.07,Math.min(1,Math.max(0,(p-.35)/.65))); var su=Math.max(0,Math.min(1,(p-.3)/.5)); if(su>0){var sg=g.createRadialGradient(sunX,sunY,6,sunX,sunY,H*.5);sg.addColorStop(0,'rgba(255,214,150,'+(.85*su)+')');sg.addColorStop(.3,'rgba(255,150,110,'+(.35*su)+')');sg.addColorStop(1,'rgba(255,120,90,0)');g.fillStyle=sg;g.fillRect(0,0,W,hy+2);g.fillStyle='rgba(255,236,190,'+su+')';g.beginPath();g.arc(sunX,sunY,Math.max(14,H*.04),0,7);g.fill()} // sea var sea=g.createLinearGradient(0,hy,0,H); sea.addColorStop(0,mix('#16254f','#f7b98e',p));sea.addColorStop(.22,mix('#0f1d44','#d9959f',p));sea.addColorStop(.6,mix('#0a1535','#6f86bd',p));sea.addColorStop(1,mix('#070d22','#34548c',p)); g.fillStyle=sea;g.fillRect(0,hy,W,H-hy); // sun/moon glitter on the sea g.fillStyle='rgba(255,236,190,'+(.55*su+.25*ma*.6)+')'; var gx=su>0?sunX:W*.2; for(var q=0;q<26;q++){var gy=hy+4+q*(H*.011)(1+q.06),gw=(10+q*6)*(.6+.4*Math.sin(now/500+q*2.1));g.fillRect(gx-gw/2+Math.sin(now/700+q)5,gy,gw,1.6)} // far headlands: only some stretches, so the sea shows between them var o1=off.12; g.fillStyle=mix('#27264f','#7a6290',p);g.beginPath();g.moveTo(0,hy+2); for(var x=0;x<=W+8;x+=8){var xx=x+o1,gp=Math.sin(xx/310).7+Math.sin(xx/97).3;var v=gp>.55?(gp-.55)H.5*(.8+.2*Math.sin(xx/23)):0;g.lineTo(x,hy-v)} g.lineTo(W,hy+2);g.closePath();g.fill(); // cover below horizon with land strip var o2=off*.3; g.fillStyle=mix('#1a1840','#4f4272',p);g.beginPath();g.moveTo(0,H); for(var x2=0;x2<=W+8;x2+=8){var x3=x2+o2;g.lineTo(x2,hy+H*.25-(H*.03*Math.sin(x3/140)+H*.018*Math.sin(x3/47+2)))} g.lineTo(W,H);g.closePath();g.fill(); // villages on mid layer var la=.25+.75*(1-p*.8); houses.forEach(function(h){var hx=wrap(h.x-o2,L)-120;if(hx<-60||hx>W+60)return;var by=hy+H*.25-H*.02;for(var k=0;k<h.n;k++){var bx=hx+k*20,bw=16,bh=11+(k%2)5;g.fillStyle=mix('#100e2a','#2c2548',p);g.fillRect(bx,by-bh,bw,bh);g.beginPath();g.moveTo(bx-2,by-bh);g.lineTo(bx+bw/2,by-bh-8);g.lineTo(bx+bw+2,by-bh);g.fill();g.fillStyle='rgba(255,207,107,'+la+')';g.fillRect(bx+4,by-bh+4,3,3);if(k%2===0)g.fillRect(bx+10,by-bh+4,3,3)}}); // mid trees var o3=off.55; trees.forEach(function(t,i2){if(i2%2)return;var tx=wrap(t.x-o3,L)-100;if(tx<-40||tx>W+40)return;tree(tx,hy+H*.29,t,.6,mix('#13112c','#352c52',p))}); // near ground var o4=off*1; g.fillStyle=mix('#0c0a1d','#1a1830',p);g.beginPath();g.moveTo(0,H); for(var x4=0;x4<=W+8;x4+=8){var x5=x4+o4*.0;g.lineTo(x4,H*.86-(H*.012*Math.sin((x4+o4)/90)))} g.lineTo(W,H);g.closePath();g.fill(); // near trees (fast) var o5=off*1.5; trees.forEach(function(t,i3){if(i3%2===0)return;var tx=wrap(t.x*1.0-o5,L)-120;if(tx<-60||tx>W+60)return;tree(tx,H*.88,t,1.05,mix('#07060f','#14122a',p))}); // poles + wires var gap2=Math.max(260,W*.5),po=wrap(off*3.2,gap2); g.strokeStyle='#07060f';g.fillStyle='#07060f'; for(var px=-gap2+ (gap2-po);px<W+gap2;px+=gap2){g.lineWidth=5;g.fillRect(px-3,H*.2,6,H*.8);g.fillRect(px-26,H*.24,52,4); g.lineWidth=1.4;[-20,20].forEach(function(dx){g.beginPath();g.moveTo(px+dx,H*.245);g.quadraticCurveTo(px+dx+gap2/2,H*.245+H*.09,px+dx+gap2,H*.245);g.stroke()})} // vignette var vg=g.createRadialGradient(W/2,H/2,Math.min(W,H).3,W/2,H/2,Math.max(W,H).75);vg.addColorStop(0,'rgba(0,0,0,0)');vg.addColorStop(1,'rgba(0,0,0,.42)');g.fillStyle=vg;g.fillRect(0,0,W,H); caption(p); if(!reduce&&!pin)requestAnimationFrame(draw) } function tree(x,y,t,sc,col){ g.fillStyle=col;g.strokeStyle=col;var s=t.s*sc*(H/520); if(t.k==='palm'){var lean=(t.x%7<3.5?-1:1)*6*s,cx=x+lean,cy=y-88*s;g.lineWidth=3.2*s;g.beginPath();g.moveTo(x,y);g.quadraticCurveTo(x+lean*1.6,y-44*s,cx,cy);g.stroke(); g.lineWidth=2.2*s;for(var a=0;a<9;a++){var an=-Math.PI*(.06+a*.111);var dx=Math.cos(an),dy=Math.sin(an);g.beginPath();g.moveTo(cx,cy);g.quadraticCurveTo(cx+dx*26*s,cy+dy*30*s-4*s,cx+dx*50*s,cy+dy*12*s+26*s*Math.abs(dx));g.stroke()}} else{g.fillRect(x-2*s,y-26*s,4*s,26*s);g.beginPath();g.arc(x,y-38*s,17*s,0,7);g.arc(x-12*s,y-30*s,12*s,0,7);g.arc(x+12*s,y-30*s,12*s,0,7);g.fill()} } var place=document.getElementById('place'),clock=document.getElementById('clock'),lastTxt=''; function caption(p){ var a,b;if(p<.28){a='Night run across the Deccan';b='01:20 · 12723 Telangana Express'}else if(p<.56){a='Crossing the Godavari';b='04:55 · 310 km to go'}else if(p<.82){a='First light near Vijayawada';b='05:50 · 120 km to go'}else{a='Sunrise by the Bay of Bengal';b='06:35 · arriving soon'} if(a!==lastTxt){lastTxt=a;place.textContent=a;clock.textContent=b} } requestAnimationFrame(draw); // blind: rises once on load, can be pulled back down var blind=document.getElementById('blind'),pull=document.getElementById('pull'); function setBlind(up){blind.classList.toggle('up',up);pull.setAttribute('aria-expanded',up?'true':'false');pull.setAttribute('aria-label',up?'Lower the blind':'Raise the blind')} pull.addEventListener('click',function(){setBlind(true)}); blind.addEventListener('click',function(e){if(e.target===blind)setBlind(!blind.classList.contains('up'))}); setTimeout(function(){setBlind(true)},reduce?0:900); })(); </script> </body> </html>
Source, 192 lines
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="theme-color" content="#15121f">
<title>Sleeper · Overnight train journeys</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Young+Serif&family=Hanken+Grotesk:wght@400;500;600&display=swap">
<style>
:root{--cabin:#15121f;--cabin2:#1d1830;--lamp:#ffcf6b;--mist:#cfcbe8;--wood:#2a1f19;--wood2:#4a3829;
--serif:"Young Serif",Georgia,"Times New Roman",serif;--sans:"Hanken Grotesk",system-ui,-apple-system,"Segoe UI",sans-serif}
*{box-sizing:border-box;margin:0}
html,body{height:100%;background:var(--cabin);color:#f4f1ff;font-family:var(--sans);-webkit-font-smoothing:antialiased}
.hero{position:relative;min-height:100vh;min-height:100svh;overflow:hidden;display:grid;grid-template-rows:auto 1fr;
background:radial-gradient(70% 60% at 12% 18%,rgba(255,207,107,.14),transparent 70%),linear-gradient(180deg,#191529,#120f1c)}
header{display:flex;justify-content:space-between;align-items:center;padding:clamp(22px,3vw,34px) clamp(22px,5vw,72px)}
.logo{font-family:var(--serif);font-size:24px;color:#fff;text-decoration:none;letter-spacing:-.01em}
nav{display:flex;gap:26px;align-items:center;font-size:15px}
nav a{color:var(--mist);text-decoration:none}
nav a:hover,nav a:focus-visible{color:#fff}
nav .pill{color:#1b1411;background:var(--lamp);padding:9px 16px;border-radius:999px;font-weight:600}
a:focus-visible,button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--lamp);outline-offset:3px;border-radius:6px}
.stage{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.12fr);gap:clamp(24px,4vw,64px);align-items:center;padding:0 clamp(22px,5vw,72px) clamp(26px,4vw,48px);min-height:0}
.copy{max-width:600px}
h1{font-family:var(--serif);font-weight:400;font-size:clamp(38px,5.4vw,78px);line-height:1.04;letter-spacing:-.025em}
.lead{margin-top:20px;max-width:42ch;font-size:clamp(16px,1.4vw,18px);line-height:1.6;color:#d6d2ee}
form{margin-top:28px;display:grid;grid-template-columns:1fr 1fr 1fr auto;background:#221c38;border:1px solid rgba(255,255,255,.12);border-radius:16px;padding:7px;max-width:640px}
label{display:grid;gap:3px;padding:9px 14px;border-right:1px solid rgba(255,255,255,.1);min-width:0}
label:nth-of-type(3){border-right:0}
label span{font-size:12px;color:var(--mist)}
input,select{background:transparent;border:0;color:#fff;font:500 16px var(--sans);padding:2px 0;width:100%;min-width:0;color-scheme:dark}
select option{color:#111}
button.go{background:var(--lamp);color:#1b1411;font:600 15px var(--sans);border:0;border-radius:11px;padding:0 20px;cursor:pointer}
button.go:hover{background:#ffdc8e}
.note{margin-top:14px;font-size:14px;color:var(--mist)}
/* window */
.win{position:relative;width:100%;height:min(74vh,660px);min-height:360px;border-radius:30px;padding:clamp(10px,1.2vw,16px);
background:linear-gradient(145deg,#4a3829,#2a1f19 60%,#1d1511);box-shadow:0 30px 80px rgba(0,0,0,.55),inset 0 2px 0 rgba(255,255,255,.1),inset 0 -3px 0 rgba(0,0,0,.4)}
.glass{position:relative;width:100%;height:100%;border-radius:20px;overflow:hidden;background:#0b0d24;box-shadow:inset 0 0 0 2px rgba(0,0,0,.6),inset 0 0 60px rgba(0,0,0,.45)}
canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
.refl{position:absolute;inset:0;pointer-events:none;background:linear-gradient(112deg,rgba(255,255,255,.11) 0%,rgba(255,255,255,0) 22%,rgba(255,255,255,0) 58%,rgba(255,255,255,.07) 70%,rgba(255,255,255,0) 78%)}
.blind{position:absolute;left:0;right:0;top:0;height:46%;background:repeating-linear-gradient(180deg,#d9d1c0 0,#d9d1c0 11px,#c4bba7 11px,#c4bba7 13px);box-shadow:0 8px 24px rgba(0,0,0,.45);transition:height 1.4s cubic-bezier(.5,0,.2,1);transform-origin:top;border-bottom:6px solid #a89e88}
.blind.up{height:0;border-bottom-width:0;box-shadow:none}
.pull{position:absolute;left:50%;bottom:-26px;width:44px;height:20px;margin-left:-22px;border-radius:6px;background:#a89e88;border:0;cursor:pointer;color:transparent;font-size:0;box-shadow:0 2px 6px rgba(0,0,0,.4)}
.blind.up .pull{bottom:-34px;opacity:0;pointer-events:none}
.tag{position:absolute;left:14px;bottom:14px;z-index:2;max-width:calc(100% - 28px);padding:9px 14px;border-radius:12px;background:rgba(15,12,28,.62);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border:1px solid rgba(255,255,255,.14);font-size:14px;line-height:1.35;color:#f4f1ff}
.tag b{display:block;font-weight:600}
.tag small{color:var(--mist);font-size:13px}
@media (max-width:860px){
nav a:not(.pill){display:none}
.stage{grid-template-columns:1fr;gap:22px;align-content:start}
.win{order:-1;height:min(46svh,420px);min-height:260px;border-radius:24px}
form{grid-template-columns:1fr 1fr}
label{border-right:0;border-bottom:1px solid rgba(255,255,255,.1)}
label:nth-of-type(1){grid-column:1/-1}
label:nth-of-type(3){border-bottom:0}
button.go{grid-column:1/-1;padding:15px;margin-top:6px}
}
@media (prefers-reduced-motion:reduce){.blind{transition:none}}
</style>
</head>
<body>
<section class="hero" id="hero">
<header>
<a class="logo" href="#">Sleeper</a>
<nav><a href="#">Routes</a><a href="#">Berths</a><a href="#">Help</a><a class="pill" href="#">Sign in</a></nav>
</header>
<div class="stage">
<div class="copy">
<h1>Go to sleep in Delhi. Wake up by the sea.</h1>
<p class="lead">Overnight trains across India with real berth maps, honest arrival times and a quiet cabin. Pick a route and see which seats are still free.</p>
<form onsubmit="return false" aria-label="Find a night train">
<label><span>From</span><input type="text" value="New Delhi" aria-label="From"></label>
<label><span>To</span><input type="text" value="Visakhapatnam" aria-label="To"></label>
<label><span>Berth</span><select aria-label="Berth"><option>2 tier AC</option><option>3 tier AC</option><option>1st class</option></select></label>
<button class="go" type="submit">Find night trains</button>
</form>
<p class="note">Tonight: 14 routes leave after 8 pm</p>
</div>
<div class="win">
<div class="glass">
<canvas id="view" role="img" aria-label="A train window: the countryside at night slowly turns to sunrise over the sea"></canvas>
<div class="refl"></div>
<div class="blind" id="blind"><button class="pull" id="pull" type="button" aria-label="Raise the blind" aria-expanded="false">Raise the blind</button></div>
<div class="tag" aria-live="off"><b id="place">Leaving New Delhi</b><small id="clock">21:40 · 12723 Telangana Express</small></div>
</div>
</div>
</div>
</section>
<script>
(function(){
var reduce=matchMedia('(prefers-reduced-motion:reduce)').matches;
var cv=document.getElementById('view'),g=cv.getContext('2d'),W=0,H=0;
function size(){var d=Math.min(1.5,devicePixelRatio||1);W=cv.clientWidth;H=cv.clientHeight;cv.width=W*d;cv.height=H*d;g.setTransform(d,0,0,d,0,0)}
addEventListener('resize',size);size();
// helpers
function lerp(a,b,t){return a+(b-a)*t}
function hex(h){return [parseInt(h.slice(1,3),16),parseInt(h.slice(3,5),16),parseInt(h.slice(5,7),16)]}
function mix(a,b,t){var A=hex(a),B=hex(b);return 'rgb('+Math.round(lerp(A[0],B[0],t))+','+Math.round(lerp(A[1],B[1],t))+','+Math.round(lerp(A[2],B[2],t))+')'}
var seed=7;function rnd(){seed=(seed*16807)%2147483647;return (seed-1)/2147483646}
// scenery strips (positions in a looping strip of length L)
var L=2400,trees=[],houses=[],poles=[];
for(var i=0;i<40;i++)trees.push({x:rnd()*L,s:.7+rnd()*.8,k:rnd()<.35?'palm':'round'});
for(var j=0;j<9;j++)houses.push({x:rnd()*L,n:2+Math.floor(rnd()*3)});
// state
var phase=0,off=(/o=([0-9.]+)/.exec(location.hash)||[0,0])[1]*1,last=performance.now(),pin=/#p=([0-9.]+)/.exec(location.hash);
function wrap(x,len){return ((x%len)+len)%len}
function hillY(x,base,a1,p1,a2,p2,ph){return base-(a1*Math.sin(x/p1+ph)+a2*Math.sin(x/p2+ph*1.7))}
function draw(now){
var dt=Math.min(60,now-last);last=now;
if(!reduce)off+=dt*.06;
var p=pin?parseFloat(pin[1]):(reduce?.55:(1-Math.cos(now/1000/52*Math.PI*2))/2);
phase=p;
var hy=H*.54;
// sky
var sk=g.createLinearGradient(0,0,0,hy);
sk.addColorStop(0,mix('#080a20','#3a4a86',p));sk.addColorStop(.55,mix('#1b1a45','#a8708f',p));sk.addColorStop(1,mix('#43346a','#ffc58a',p));
g.fillStyle=sk;g.fillRect(0,0,W,hy+2);
// stars
var sa=Math.max(0,1-p*1.6);
if(sa>0){for(var s=0;s<70;s++){var sx=(s*97.3)%W,sy=((s*53.7)%(hy*.8)),tw=.5+.5*Math.sin(now/900+s);g.fillStyle='rgba(255,246,222,'+(sa*(.3+.6*tw)).toFixed(2)+')';g.fillRect(sx,sy,s%5?1.2:2,s%5?1.2:2)}}
// moon
var ma=Math.max(0,1-p*1.8);
if(ma>0){var mx=W*.2,my=H*.17;var mg=g.createRadialGradient(mx,my,4,mx,my,70);mg.addColorStop(0,'rgba(255,240,200,'+(.5*ma)+')');mg.addColorStop(1,'rgba(255,240,200,0)');g.fillStyle=mg;g.fillRect(mx-80,my-80,160,160);g.fillStyle='rgba(247,232,190,'+ma+')';g.beginPath();g.arc(mx,my,16,0,7);g.fill()}
// sun
var sunX=W*.72,sunY=lerp(hy+H*.12,hy-H*.07,Math.min(1,Math.max(0,(p-.35)/.65)));
var su=Math.max(0,Math.min(1,(p-.3)/.5));
if(su>0){var sg=g.createRadialGradient(sunX,sunY,6,sunX,sunY,H*.5);sg.addColorStop(0,'rgba(255,214,150,'+(.85*su)+')');sg.addColorStop(.3,'rgba(255,150,110,'+(.35*su)+')');sg.addColorStop(1,'rgba(255,120,90,0)');g.fillStyle=sg;g.fillRect(0,0,W,hy+2);g.fillStyle='rgba(255,236,190,'+su+')';g.beginPath();g.arc(sunX,sunY,Math.max(14,H*.04),0,7);g.fill()}
// sea
var sea=g.createLinearGradient(0,hy,0,H);
sea.addColorStop(0,mix('#16254f','#f7b98e',p));sea.addColorStop(.22,mix('#0f1d44','#d9959f',p));sea.addColorStop(.6,mix('#0a1535','#6f86bd',p));sea.addColorStop(1,mix('#070d22','#34548c',p));
g.fillStyle=sea;g.fillRect(0,hy,W,H-hy);
// sun/moon glitter on the sea
g.fillStyle='rgba(255,236,190,'+(.55*su+.25*ma*.6)+')';
var gx=su>0?sunX:W*.2;
for(var q=0;q<26;q++){var gy=hy+4+q*(H*.011)*(1+q*.06),gw=(10+q*6)*(.6+.4*Math.sin(now/500+q*2.1));g.fillRect(gx-gw/2+Math.sin(now/700+q)*5,gy,gw,1.6)}
// far headlands: only some stretches, so the sea shows between them
var o1=off*.12;
g.fillStyle=mix('#27264f','#7a6290',p);g.beginPath();g.moveTo(0,hy+2);
for(var x=0;x<=W+8;x+=8){var xx=x+o1,gp=Math.sin(xx/310)*.7+Math.sin(xx/97)*.3;var v=gp>.55?(gp-.55)*H*.5*(.8+.2*Math.sin(xx/23)):0;g.lineTo(x,hy-v)}
g.lineTo(W,hy+2);g.closePath();g.fill();
// cover below horizon with land strip
var o2=off*.3;
g.fillStyle=mix('#1a1840','#4f4272',p);g.beginPath();g.moveTo(0,H);
for(var x2=0;x2<=W+8;x2+=8){var x3=x2+o2;g.lineTo(x2,hy+H*.25-(H*.03*Math.sin(x3/140)+H*.018*Math.sin(x3/47+2)))}
g.lineTo(W,H);g.closePath();g.fill();
// villages on mid layer
var la=.25+.75*(1-p*.8);
houses.forEach(function(h){var hx=wrap(h.x-o2,L)-120;if(hx<-60||hx>W+60)return;var by=hy+H*.25-H*.02;for(var k=0;k<h.n;k++){var bx=hx+k*20,bw=16,bh=11+(k%2)*5;g.fillStyle=mix('#100e2a','#2c2548',p);g.fillRect(bx,by-bh,bw,bh);g.beginPath();g.moveTo(bx-2,by-bh);g.lineTo(bx+bw/2,by-bh-8);g.lineTo(bx+bw+2,by-bh);g.fill();g.fillStyle='rgba(255,207,107,'+la+')';g.fillRect(bx+4,by-bh+4,3,3);if(k%2===0)g.fillRect(bx+10,by-bh+4,3,3)}});
// mid trees
var o3=off*.55;
trees.forEach(function(t,i2){if(i2%2)return;var tx=wrap(t.x-o3,L)-100;if(tx<-40||tx>W+40)return;tree(tx,hy+H*.29,t,.6,mix('#13112c','#352c52',p))});
// near ground
var o4=off*1;
g.fillStyle=mix('#0c0a1d','#1a1830',p);g.beginPath();g.moveTo(0,H);
for(var x4=0;x4<=W+8;x4+=8){var x5=x4+o4*.0;g.lineTo(x4,H*.86-(H*.012*Math.sin((x4+o4)/90)))}
g.lineTo(W,H);g.closePath();g.fill();
// near trees (fast)
var o5=off*1.5;
trees.forEach(function(t,i3){if(i3%2===0)return;var tx=wrap(t.x*1.0-o5,L)-120;if(tx<-60||tx>W+60)return;tree(tx,H*.88,t,1.05,mix('#07060f','#14122a',p))});
// poles + wires
var gap2=Math.max(260,W*.5),po=wrap(off*3.2,gap2);
g.strokeStyle='#07060f';g.fillStyle='#07060f';
for(var px=-gap2+ (gap2-po);px<W+gap2;px+=gap2){g.lineWidth=5;g.fillRect(px-3,H*.2,6,H*.8);g.fillRect(px-26,H*.24,52,4);
g.lineWidth=1.4;[-20,20].forEach(function(dx){g.beginPath();g.moveTo(px+dx,H*.245);g.quadraticCurveTo(px+dx+gap2/2,H*.245+H*.09,px+dx+gap2,H*.245);g.stroke()})}
// vignette
var vg=g.createRadialGradient(W/2,H/2,Math.min(W,H)*.3,W/2,H/2,Math.max(W,H)*.75);vg.addColorStop(0,'rgba(0,0,0,0)');vg.addColorStop(1,'rgba(0,0,0,.42)');g.fillStyle=vg;g.fillRect(0,0,W,H);
caption(p);
if(!reduce&&!pin)requestAnimationFrame(draw)
}
function tree(x,y,t,sc,col){
g.fillStyle=col;g.strokeStyle=col;var s=t.s*sc*(H/520);
if(t.k==='palm'){var lean=(t.x%7<3.5?-1:1)*6*s,cx=x+lean,cy=y-88*s;g.lineWidth=3.2*s;g.beginPath();g.moveTo(x,y);g.quadraticCurveTo(x+lean*1.6,y-44*s,cx,cy);g.stroke();
g.lineWidth=2.2*s;for(var a=0;a<9;a++){var an=-Math.PI*(.06+a*.111);var dx=Math.cos(an),dy=Math.sin(an);g.beginPath();g.moveTo(cx,cy);g.quadraticCurveTo(cx+dx*26*s,cy+dy*30*s-4*s,cx+dx*50*s,cy+dy*12*s+26*s*Math.abs(dx));g.stroke()}}
else{g.fillRect(x-2*s,y-26*s,4*s,26*s);g.beginPath();g.arc(x,y-38*s,17*s,0,7);g.arc(x-12*s,y-30*s,12*s,0,7);g.arc(x+12*s,y-30*s,12*s,0,7);g.fill()}
}
var place=document.getElementById('place'),clock=document.getElementById('clock'),lastTxt='';
function caption(p){
var a,b;if(p<.28){a='Night run across the Deccan';b='01:20 · 12723 Telangana Express'}else if(p<.56){a='Crossing the Godavari';b='04:55 · 310 km to go'}else if(p<.82){a='First light near Vijayawada';b='05:50 · 120 km to go'}else{a='Sunrise by the Bay of Bengal';b='06:35 · arriving soon'}
if(a!==lastTxt){lastTxt=a;place.textContent=a;clock.textContent=b}
}
requestAnimationFrame(draw);
// blind: rises once on load, can be pulled back down
var blind=document.getElementById('blind'),pull=document.getElementById('pull');
function setBlind(up){blind.classList.toggle('up',up);pull.setAttribute('aria-expanded',up?'true':'false');pull.setAttribute('aria-label',up?'Lower the blind':'Raise the blind')}
pull.addEventListener('click',function(){setBlind(true)});
blind.addEventListener('click',function(e){if(e.target===blind)setBlind(!blind.classList.contains('up'))});
setTimeout(function(){setBlind(true)},reduce?0:900);
})();
</script>
</body>
</html>