Scout · Full page

A dark field-ops page: a pinned header with an announcement strip, a drawn terrain hero that parallaxes away, a pinned scene that lights up as steps scroll past, a tabbed product reveal, an accordion with a console and a grid footer.

Blocks
scoutlandingpagetemplatescroll

Interface blocks for work in the field

Watch the tour
Input
Model
Action
Step 1 of 3
  1. 01 / Pick

    Start from a block that already works

    Every block arrives with states, focus styles and motion settings in place, so the first version is already usable.

  2. 02 / Tune

    Describe the change in plain words

    Ask for a calmer palette or a denser table. Props and tokens change together and the preview follows.

  3. 03 / Ship

    Copy the source and take it anywhere

    The code is yours: no runtime, no lock-in, nothing phoning home. Drop it into any React project.

Introducing

Field Kit

A set of rugged blocks for products that live outside the office.

Dashboard · Live tiles, sparklines and alert rails

Built to hold up

COMMANDmake the map darker at night
REPLYDone. 3 tokens changed, contrast still AA.
    • Ask for changes the way you would ask a teammate.
    • Props and tokens update together.
    • No runtime, no network calls, no tracking.
    • Everything ships as static source.
    • Next.js, Vite, Remix and friends.
    • Tailwind-first, tokens as CSS variables.
    • No images: scenes are drawn in SVG and CSS.
    • Animations pause for reduced motion.

Usage

Drop the file into your project, along with the shared files listed below, and import it.

usage.tsx
import { ScoutLanding } from "@/registry/blocks/scout-landing";

export function Example() {
  return <ScoutLanding />;
}

Install prerequisites

Every component here relies only on Tailwind and the cn helper from shadcn/ui.

terminal
npm i clsx tailwind-merge

Also copy these files

Scout · Full page imports these files. Keep the same paths, or update the imports to match.

src/registry/blocks/scout-navbar.tsx
'use client'

import { useState } from 'react'
import { Mono, ScoutMark } from '@/registry/blocks/scout-kit'
import { cn } from '@/lib/utils'

export interface ScoutNavbarProps {
  brand?: string
  /** Leave empty to hide the announcement strip. */
  announcement?: string
  links?: string
  ctaLabel?: string
  className?: string
}

/** A dismissible announcement strip over a dark bar with mono links. */
export function ScoutNavbar({ brand = 'shinUI', announcement = 'Field Kit is out: twelve new blocks for maps, consoles and dashboards', links = 'Blocks, Kits, Changelog', ctaLabel = 'Contact', className }: ScoutNavbarProps) {
  const [shown, setShown] = useState(true)
  const [open, setOpen] = useState(false)
  const items = links.split(',').map((s) => s.trim()).filter(Boolean)
  return (
    <header className={cn('bg-(--sc-bg)/85 backdrop-blur-md', className)}>
      {announcement && shown && (
        <div className="relative flex h-8 items-center justify-center border-b border-(--sc-line) px-10 text-center text-[11.5px] text-(--sc-dim)">
          <a href="#" className="truncate hover:text-(--sc-fg)">{announcement}</a>
          <button type="button" aria-label="Dismiss announcement" onClick={() => setShown(false)} className="absolute right-3 text-(--sc-faint) hover:text-(--sc-fg)">
            ×
          </button>
        </div>
      )}
      <nav aria-label="Main" className="flex h-14 items-center gap-6 border-b border-(--sc-line) px-6">
        <a href="#" className="flex items-center gap-2 text-[15px] font-medium tracking-tight">
          <ScoutMark className="size-5" />
          {brand}
        </a>
        <div className="ml-auto hidden items-center gap-6 md:flex">
          {items.map((l) => (
            <a key={l} href="#" className="text-(--sc-dim) transition-colors hover:text-(--sc-fg)">
              <Mono>{l}</Mono>
            </a>
          ))}
        </div>
        <a href="#" className="ml-auto border border-(--sc-line) px-3 py-1.5 transition-colors hover:border-(--sc-accent) hover:text-(--sc-accent) md:ml-4">
          <Mono>{ctaLabel}</Mono>
        </a>
        <button type="button" aria-expanded={open} onClick={() => setOpen(!open)} className="md:hidden">
          <Mono>{open ? 'Close' : 'Menu'}</Mono>
        </button>
      </nav>
      {open && (
        <div className="flex flex-col gap-3 border-b border-(--sc-line) px-6 py-4 md:hidden">
          {items.map((l) => (
            <a key={l} href="#">
              <Mono>{l}</Mono>
            </a>
          ))}
        </div>
      )}
    </header>
  )
}
src/registry/blocks/scout-hero.tsx
'use client'

import { useRef } from 'react'
import { Cross, Mono, Reticle, ScoutButton, Terrain, useScrollVar } from '@/registry/blocks/scout-kit'
import { cn } from '@/lib/utils'

export interface ScoutHeroProps {
  headline?: string
  ctaLabel?: string
  animate?: boolean
  className?: string
}

/**
 * A full-bleed drawn terrain with a tracking reticle and a headline pinned to
 * the lower left. The ridgelines drift apart as the hero scrolls away.
 */
export function ScoutHero({ headline = 'Interface blocks\nfor work in the field', ctaLabel = 'Watch the tour', animate = true, className }: ScoutHeroProps) {
  const ref = useRef<HTMLElement>(null)
  useScrollVar(ref, { mode: 'exit' })
  return (
    <section ref={ref} className={cn('relative isolate flex min-h-[620px] flex-col justify-end overflow-hidden px-6 pt-28 pb-10 [--sc-p:0]', className)}>
      <Terrain animate={animate} className="-z-10" />
      <Reticle animate={animate} className="top-[30%] left-[58%]" />
      <Mono className="absolute top-[30%] left-[calc(58%+110px)] hidden text-(--sc-faint) md:block">
        37.40N / 122.03W
        <br />
        ALT 0142
      </Mono>
      <Cross className="top-24 left-6" />
      <Cross className="top-24 left-[calc(100%-24px)]" />
      <div className="flex flex-wrap items-end justify-between gap-6">
        <h1 className="max-w-[16ch] text-[clamp(34px,5vw,60px)] leading-[1.04] font-normal tracking-[-0.03em] whitespace-pre-line">{headline}</h1>
        <ScoutButton>{ctaLabel}</ScoutButton>
      </div>
    </section>
  )
}
src/registry/blocks/scout-pinned.tsx
'use client'

import { useRef, useState } from 'react'
import { Mono, Terrain, useScrollVar } from '@/registry/blocks/scout-kit'
import { cn } from '@/lib/utils'

const STEPS = [
  { tag: '01 / Pick', title: 'Start from a block that already works', body: 'Every block arrives with states, focus styles and motion settings in place, so the first version is already usable.' },
  { tag: '02 / Tune', title: 'Describe the change in plain words', body: 'Ask for a calmer palette or a denser table. Props and tokens change together and the preview follows.' },
  { tag: '03 / Ship', title: 'Copy the source and take it anywhere', body: 'The code is yours: no runtime, no lock-in, nothing phoning home. Drop it into any React project.' },
]
const NODES = ['Input', 'Model', 'Action']

export interface ScoutPinnedProps {
  animate?: boolean
  className?: string
}

/**
 * A scroll-driven section: the scene and diagram stay pinned while the steps
 * scroll past, and each step lights up the matching part of the diagram.
 */
export function ScoutPinned({ animate = true, className }: ScoutPinnedProps) {
  const ref = useRef<HTMLElement>(null)
  const [active, setActive] = useState(0)
  useScrollVar(ref, { mode: 'through', name: '--sc-pin', onChange: (p) => setActive(Math.min(STEPS.length - 1, Math.floor(p * STEPS.length))) })
  return (
    <section ref={ref} className={cn('relative grid gap-10 px-6 py-16 md:grid-cols-2 [--sc-pin:0]', className)}>
      <div className="relative h-[420px] overflow-hidden border border-(--sc-line) md:sticky md:top-28">
        <Terrain animate={animate} parallaxVar="--sc-pin" />
        <div className="absolute inset-0 flex flex-col items-center justify-center gap-6 p-6">
          <div className="flex items-center gap-3">
            {NODES.map((n, i) => (
              <div key={n} className="flex items-center gap-3">
                <div className={cn('sc-anim grid h-16 w-24 place-items-center border transition-colors duration-500', i <= active ? 'border-(--sc-accent) bg-(--sc-accent)/10 text-(--sc-accent)' : 'border-(--sc-line) bg-(--sc-bg)/70 text-(--sc-faint)')}>
                  <Mono>{n}</Mono>
                </div>
                {i < NODES.length - 1 && <span className={cn('sc-anim h-px w-8 transition-colors duration-500', i < active ? 'bg-(--sc-accent)' : 'bg-(--sc-line)')} />}
              </div>
            ))}
          </div>
          <div className="h-1 w-60 bg-(--sc-line)">
            <div className="h-full origin-left bg-(--sc-accent)" style={{ transform: 'scaleX(var(--sc-pin))' }} />
          </div>
          <Mono className="text-(--sc-dim)">Step {active + 1} of {STEPS.length}</Mono>
        </div>
      </div>
      <ol className="flex flex-col">
        {STEPS.map((s, i) => (
          <li key={s.tag} className={cn('sc-anim flex min-h-[380px] flex-col justify-center gap-3 border-l pl-6 transition-[opacity,border-color] duration-500', i === active ? 'border-(--sc-accent) opacity-100' : 'border-(--sc-line) opacity-40')}>
            <Mono className="text-(--sc-accent)">{s.tag}</Mono>
            <h3 className="max-w-[20ch] text-[28px] leading-tight tracking-[-0.02em]">{s.title}</h3>
            <p className="max-w-[42ch] text-[14px] leading-relaxed text-(--sc-dim)">{s.body}</p>
          </li>
        ))}
      </ol>
    </section>
  )
}
src/registry/blocks/scout-product.tsx
'use client'

import { useState } from 'react'
import { GridBand, Mono } from '@/registry/blocks/scout-kit'
import { cn } from '@/lib/utils'

const MODELS = {
  D01: { name: 'Dashboard', note: 'Live tiles, sparklines and alert rails' },
  M01: { name: 'Map', note: 'Layers, waypoints and a range ring' },
  C01: { name: 'Console', note: 'A command line with typed replies' },
} as const
type Key = keyof typeof MODELS

function Panel({ k }: { k: Key }) {
  const stroke = { fill: 'none', stroke: 'currentColor', strokeWidth: 1.5 } as const
  return (
    <svg viewBox="0 0 320 180" aria-hidden className="w-full max-w-xl text-(--sc-fg)">
      <rect x="1" y="1" width="318" height="178" {...stroke} opacity="0.4" />
      {k === 'D01' && (
        <>
          {[0, 1, 2].map((i) => (
            <rect key={i} x={16 + i * 100} y="16" width="88" height="56" {...stroke} opacity="0.7" />
          ))}
          <path d="M16 150 L60 120 L100 132 L150 96 L200 110 L250 70 L304 84" {...stroke} className="text-(--sc-accent)" stroke="currentColor" />
        </>
      )}
      {k === 'M01' && (
        <>
          <path d="M10 130 C60 90 90 150 150 110 S250 60 310 90" {...stroke} opacity="0.5" />
          <path d="M10 160 C80 120 120 170 190 140 S280 110 310 130" {...stroke} opacity="0.3" />
          <circle cx="170" cy="86" r="44" {...stroke} className="text-(--sc-accent)" stroke="currentColor" strokeDasharray="4 4" />
          <circle cx="170" cy="86" r="3" fill="currentColor" className="text-(--sc-accent)" />
          <path d="M60 60 L120 74 L170 86" {...stroke} strokeDasharray="2 5" />
        </>
      )}
      {k === 'C01' && (
        <>
          {[0, 1, 2, 3].map((i) => (
            <rect key={i} x="20" y={22 + i * 30} width={[180, 240, 120, 200][i]} height="8" fill="currentColor" opacity={i % 2 ? 0.25 : 0.55} />
          ))}
          <rect x="20" y="150" width="10" height="14" fill="currentColor" className="text-(--sc-accent)" />
        </>
      )}
    </svg>
  )
}

export interface ScoutProductProps {
  eyebrow?: string
  name?: string
  lede?: string
  className?: string
}

/** A product reveal: a huge name, tabbed variants and a line-art panel per variant. */
export function ScoutProduct({ eyebrow = 'Introducing', name = 'Field Kit', lede = 'A set of rugged blocks for products that live outside the office.', className }: ScoutProductProps) {
  const [k, setK] = useState<Key>('D01')
  const keys = Object.keys(MODELS) as Key[]
  return (
    <GridBand className={cn('flex flex-col items-center gap-6 px-6 py-20 text-center', className)}>
      <Mono className="text-(--sc-dim)">{eyebrow}</Mono>
      <h2 className="text-[clamp(56px,11vw,140px)] leading-[0.9] font-semibold tracking-[-0.05em] uppercase">{name}</h2>
      <p className="max-w-[40ch] text-[14px] text-(--sc-dim)">{lede}</p>
      <div role="tablist" aria-label="Variants" className="flex gap-1">
        {keys.map((key) => (
          <button key={key} role="tab" aria-selected={k === key} onClick={() => setK(key)} className={cn('border px-3 py-1.5 transition-colors', k === key ? 'border-(--sc-fg) text-(--sc-fg)' : 'border-(--sc-line) text-(--sc-faint) hover:text-(--sc-fg)')}>
            <Mono>{key}</Mono>
          </button>
        ))}
      </div>
      <Mono className="text-(--sc-accent)">
        {MODELS[k].name} · {MODELS[k].note}
      </Mono>
      <div role="tabpanel" className="flex w-full justify-center">
        <Panel k={k} />
      </div>
    </GridBand>
  )
}
src/registry/blocks/scout-features.tsx
'use client'

import { useState } from 'react'
import { cn } from '@/lib/utils'

const ITEMS = [
  { title: 'Plain-language edits', points: ['Ask for changes the way you would ask a teammate.', 'Props and tokens update together.'], cmd: 'make the map darker at night', reply: 'Done. 3 tokens changed, contrast still AA.' },
  { title: 'Works offline', points: ['No runtime, no network calls, no tracking.', 'Everything ships as static source.'], cmd: 'will this run without a connection?', reply: 'Yes. Nothing in the block calls out.' },
  { title: 'Any framework that renders React', points: ['Next.js, Vite, Remix and friends.', 'Tailwind-first, tokens as CSS variables.'], cmd: 'add the console to my vite app', reply: 'Copied 2 files. Import ScoutConsole.' },
  { title: 'Light on the wire', points: ['No images: scenes are drawn in SVG and CSS.', 'Animations pause for reduced motion.'], cmd: 'how heavy is the hero?', reply: 'About 4 KB of markup, zero image requests.' },
]

export interface ScoutFeaturesProps {
  heading?: string
  className?: string
}

/** An accordion list beside a console card that answers for the open item. */
export function ScoutFeatures({ heading = 'Built to hold up', className }: ScoutFeaturesProps) {
  const [open, setOpen] = useState(0)
  const item = ITEMS[open]
  return (
    <section className={cn('grid gap-10 px-6 py-20 md:grid-cols-[1fr_1.2fr]', className)}>
      <div className="flex flex-col gap-6">
        <h2 className="text-[34px] leading-tight tracking-[-0.02em]">{heading}</h2>
        <div className="border border-(--sc-line) bg-(--sc-panel) p-4 font-mono text-[12px]" aria-live="polite">
          <div className="flex gap-3">
            <span className="w-16 shrink-0 text-(--sc-faint)">COMMAND</span>
            <span>{item.cmd}</span>
          </div>
          <div className="mt-3 flex gap-3">
            <span className="w-16 shrink-0 text-(--sc-faint)">REPLY</span>
            <span className="text-(--sc-accent)">
              {item.reply}
              <span aria-hidden className="sc-anim ml-1 inline-block h-3 w-1.5 translate-y-0.5 bg-current [animation:sc-blink_1s_steps(1)_infinite]" />
            </span>
          </div>
        </div>
      </div>
      <ul className="border-t border-(--sc-line)">
        {ITEMS.map((it, i) => (
          <li key={it.title} className="border-b border-(--sc-line)">
            <button type="button" aria-expanded={open === i} onClick={() => setOpen(i)} className="flex w-full items-center justify-between gap-4 py-4 text-left text-[15px] hover:text-(--sc-accent)">
              {it.title}
              <span aria-hidden className={cn('sc-anim text-lg transition-transform', open === i && 'rotate-45 text-(--sc-accent)')}>+</span>
            </button>
            <div className={cn('sc-anim grid transition-[grid-template-rows] duration-300', open === i ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]')}>
              <ul className="overflow-hidden text-[13.5px] text-(--sc-dim)">
                {it.points.map((p) => (
                  <li key={p} className="pb-2 pl-4 before:mr-2 before:text-(--sc-accent) before:content-['—']">{p}</li>
                ))}
                <li className="pb-4" />
              </ul>
            </div>
          </li>
        ))}
      </ul>
    </section>
  )
}
src/registry/blocks/scout-footer.tsx
'use client'

import { useState } from 'react'
import { Cross, Mono, ScoutMark } from '@/registry/blocks/scout-kit'
import { cn } from '@/lib/utils'

const LINKS = [
  ['GitHub', 'Changelog', 'Discussions', 'Showcase'],
  ['Blocks', 'Kits', 'Contact', 'Licence'],
]

export interface ScoutFooterProps {
  brand?: string
  className?: string
}

/** A grid footer: signup on the left, a large mark in the middle, links on the right. */
export function ScoutFooter({ brand = 'shinUI', className }: ScoutFooterProps) {
  const [sent, setSent] = useState(false)
  return (
    <footer className={cn('relative border-t border-(--sc-line)', className)}>
      <Cross className="top-0 left-1/3 hidden md:block" />
      <Cross className="top-0 left-2/3 hidden md:block" />
      <div className="grid md:grid-cols-3">
        <div className="flex flex-col justify-between gap-8 border-b border-(--sc-line) p-6 md:border-r md:border-b-0">
          <form
            onSubmit={(e) => {
              e.preventDefault()
              setSent(true)
            }}
            className="flex flex-col gap-2"
          >
            <label htmlFor="sc-email" className="text-[12.5px] text-(--sc-dim)">
              Get new blocks in your inbox
            </label>
            <div className="flex">
              <input id="sc-email" type="email" required placeholder="you@studio.dev" className="h-9 min-w-0 flex-1 border border-(--sc-line) bg-transparent px-3 text-[13px] placeholder:text-(--sc-faint) focus:border-(--sc-accent) focus:outline-none" />
              <button type="submit" aria-label="Subscribe" className="h-9 w-9 bg-(--sc-accent) text-(--sc-accent-ink)">
                →
              </button>
            </div>
            <span aria-live="polite" className="h-4 text-[12px] text-(--sc-accent)">{sent ? 'Thanks, you are on the list.' : ''}</span>
          </form>
          <Mono className="text-(--sc-faint)">Made in the open</Mono>
        </div>
        <div className="grid min-h-56 place-items-center border-b border-(--sc-line) md:border-r md:border-b-0">
          <ScoutMark className="size-20" />
        </div>
        <div className="grid grid-cols-2 gap-2 p-6">
          {LINKS.map((col, i) => (
            <nav key={i} aria-label={i ? 'Product' : 'Community'} className="flex flex-col gap-2">
              {col.map((l) => (
                <a key={l} href="#" className="w-fit text-[14px] text-(--sc-dim) hover:text-(--sc-fg)">{l}</a>
              ))}
            </nav>
          ))}
        </div>
      </div>
      <div className="flex justify-between border-t border-(--sc-line) px-6 py-3 text-(--sc-faint)">
        <Mono>© {brand}</Mono>
        <Mono>MIT licence</Mono>
      </div>
    </footer>
  )
}
src/registry/blocks/scout-kit.tsx
'use client'

import { useEffect, useRef, type ComponentProps, type ReactNode, type RefObject } from 'react'
import { cn } from '@/lib/utils'

/**
 * Scout Kit: shared pieces behind the shinUI "Scout" blocks.
 *
 * A field-ops look: near-black ground, pale lichen text, one signal-green
 * accent, mono labels, hairline grid lines with + marks where they cross, and
 * a drawn terrain scene with a HUD reticle instead of photography. Wrap
 * blocks in <ScoutRoot>.
 */

const VARS = [
  '[--sc-bg:#0a0b0d] [--sc-panel:#121418] [--sc-fg:#e6eae1] [--sc-dim:rgb(230_234_225/0.58)] [--sc-faint:rgb(230_234_225/0.34)]',
  '[--sc-line:rgb(230_234_225/0.12)] [--sc-accent:#3fe0a0] [--sc-accent-ink:#06150f]',
  '[--sc-ridge-1:#1d2a22] [--sc-ridge-2:#16201a] [--sc-ridge-3:#101712] [--sc-sky:#24302a]',
].join(' ')

const KEYFRAMES = `
@keyframes sc-pulse{0%,100%{opacity:.55;transform:scale(1)}50%{opacity:1;transform:scale(1.04)}}
@keyframes sc-blink{50%{opacity:0}}
@keyframes sc-scan{from{transform:translateY(-100%)}to{transform:translateY(100%)}}
@media (prefers-reduced-motion:reduce){.sc-anim{animation:none!important;transition:none!important}.sc-move{transform:none!important}}
`

export function ScoutRoot({ className, children, ...props }: ComponentProps<'div'>) {
  return (
    <div className={cn(VARS, 'bg-(--sc-bg) font-sans text-(--sc-fg) antialiased selection:bg-(--sc-accent) selection:text-(--sc-accent-ink)', className)} {...props}>
      <style>{KEYFRAMES}</style>
      {children}
    </div>
  )
}

export function Mono({ className, children }: { className?: string; children: ReactNode }) {
  return <span className={cn('font-mono text-[10.5px] tracking-[0.14em] uppercase', className)}>{children}</span>
}

/** Original mark: a bracketed square with an upward chevron. */
export function ScoutMark({ className }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" aria-hidden className={cn('size-6', className)}>
      <path d="M3 8V3h5M16 3h5v5M21 16v5h-5M8 21H3v-5" fill="none" stroke="currentColor" strokeWidth="1.8" />
      <path d="M7.5 15 12 9.5l4.5 5.5" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round" />
    </svg>
  )
}

export function ScoutButton({ variant = 'outline', className, children, ...props }: ComponentProps<'a'> & { variant?: 'outline' | 'accent' }) {
  return (
    <a
      href="#"
      className={cn(
        'group inline-flex h-9 items-stretch font-mono text-[10.5px] tracking-[0.14em] uppercase focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--sc-accent)',
        className,
      )}
      {...props}
    >
      <span className={cn('flex items-center border px-4 transition-colors', variant === 'accent' ? 'border-(--sc-accent) bg-(--sc-accent) text-(--sc-accent-ink)' : 'border-(--sc-line) bg-(--sc-bg)/60 group-hover:border-(--sc-fg)')}>{children}</span>
      <span className="grid w-9 place-items-center bg-(--sc-accent) text-(--sc-accent-ink) transition-[width] group-hover:w-11" aria-hidden>
        ↗
      </span>
    </a>
  )
}

/** A small + where grid lines cross. Position it with className. */
export function Cross({ className }: { className?: string }) {
  return (
    <span aria-hidden className={cn('pointer-events-none absolute size-2.5 -translate-x-1/2 -translate-y-1/2 text-(--sc-faint)', className)}>
      <span className="absolute inset-x-0 top-1/2 h-px bg-current" />
      <span className="absolute inset-y-0 left-1/2 w-px bg-current" />
    </span>
  )
}

/** A hairline-bordered band with + marks at its four corners. */
export function GridBand({ className, children }: { className?: string; children: ReactNode }) {
  return (
    <div className={cn('relative border-y border-(--sc-line)', className)}>
      <Cross className="top-0 left-6" />
      <Cross className="top-0 left-[calc(100%-24px)]" />
      <Cross className="top-full left-6" />
      <Cross className="top-full left-[calc(100%-24px)]" />
      {children}
    </div>
  )
}

function ridge(seed: number, base: number, amp: number) {
  let d = `M0 600 L0 ${base}`
  for (let x = 0; x <= 1200; x += 20) {
    const y = base - amp * (Math.sin(x / (90 + seed * 13) + seed) * 0.55 + Math.sin(x / (37 + seed * 5) + seed * 2) * 0.3 + Math.sin(x / 11 + seed) * 0.08)
    d += ` L${x} ${y.toFixed(1)}`
  }
  return d + ' L1200 600 Z'
}
const RIDGES = [ridge(1, 300, 70), ridge(2, 380, 90), ridge(3, 470, 80)]

/**
 * A drawn terrain scene: hazy sky, three ridgelines, scanlines and a slow
 * scan bar. `parallax` (0 to 1, usually a scroll value) shifts the layers.
 */
export function Terrain({ parallaxVar = '--sc-p', animate = true, className }: { parallaxVar?: string; animate?: boolean; className?: string }) {
  const layer = (i: number) => ({ transform: `translateY(calc(var(${parallaxVar}, 0) * ${(i + 1) * -40}px))` })
  return (
    <div aria-hidden className={cn('pointer-events-none absolute inset-0 overflow-hidden', className)}>
      <div className="absolute inset-0" style={{ background: 'radial-gradient(80% 60% at 70% 20%, var(--sc-sky), var(--sc-bg) 70%)' }} />
      <svg viewBox="0 0 1200 600" preserveAspectRatio="none" className="absolute inset-0 size-full">
        {RIDGES.map((d, i) => (
          <path key={i} d={d} className="sc-move" style={{ ...layer(i), fill: `var(--sc-ridge-${i + 1})` }} />
        ))}
      </svg>
      <div className="absolute inset-0 opacity-30" style={{ backgroundImage: 'repeating-linear-gradient(0deg, rgb(0 0 0/0.5) 0 1px, transparent 1px 3px)' }} />
      {animate && <div className="sc-anim absolute inset-x-0 h-1/3 [animation:sc-scan_7s_linear_infinite]" style={{ background: 'linear-gradient(180deg, transparent, rgb(63 224 160/0.06), transparent)' }} />}
      <div className="absolute inset-0" style={{ background: 'linear-gradient(180deg, transparent 55%, var(--sc-bg))' }} />
    </div>
  )
}

/** A HUD reticle with a label, gently pulsing. */
export function Reticle({ label = 'TRK 04', animate = true, className }: { label?: string; animate?: boolean; className?: string }) {
  return (
    <div aria-hidden className={cn('pointer-events-none absolute size-24 text-(--sc-accent)', className)}>
      <div className={cn('absolute inset-0', animate && 'sc-anim [animation:sc-pulse_2.6s_ease-in-out_infinite]')}>
        <ScoutMark className="size-full opacity-80 [&_path:last-child]:hidden" />
      </div>
      <span className="absolute top-1/2 left-1/2 size-1.5 -translate-1/2 rounded-full bg-current" />
      <Mono className="absolute -bottom-5 left-0 text-[9px] text-(--sc-accent)">{label}</Mono>
    </div>
  )
}

/**
 * Writes a 0 to 1 scroll value into a CSS variable on the element, measured
 * against the nearest scrolling ancestor (a preview frame) or the window.
 * mode "through": 0 when the element's top reaches the top, 1 when its bottom
 * reaches the bottom (for pinned sections). mode "exit": 0 at rest, 1 when
 * it has scrolled fully out the top (for parallax). `onChange` gets the value.
 */
export function useScrollVar<T extends HTMLElement>(ref: RefObject<T | null>, { name = '--sc-p', mode = 'through', onChange }: { name?: string; mode?: 'through' | 'exit'; onChange?: (p: number) => void } = {}) {
  const cb = useRef(onChange)
  useEffect(() => {
    cb.current = onChange
  })
  useEffect(() => {
    const el = ref.current
    if (!el) return
    let sp: HTMLElement | null = el.parentElement
    while (sp && !/(auto|scroll)/.test(getComputedStyle(sp).overflowY)) sp = sp.parentElement
    const target: HTMLElement | Window = sp ?? window
    let raf = 0
    const update = () => {
      raf = 0
      const top = sp ? sp.getBoundingClientRect().top : 0
      const vh = sp ? sp.clientHeight : window.innerHeight
      const r = el.getBoundingClientRect()
      const span = mode === 'exit' ? r.height : r.height - vh
      const p = span > 0 ? Math.min(1, Math.max(0, (top - r.top) / span)) : 0
      el.style.setProperty(name, p.toFixed(4))
      cb.current?.(p)
    }
    const queue = () => {
      if (!raf) raf = requestAnimationFrame(update)
    }
    update()
    target.addEventListener('scroll', queue, { passive: true })
    window.addEventListener('resize', queue)
    return () => {
      cancelAnimationFrame(raf)
      target.removeEventListener('scroll', queue)
      window.removeEventListener('resize', queue)
    }
  }, [ref, name, mode])
}

More in Blocks