// Direction A — "Deep Water": brand blue + cyan accents, defense-aerospace editorial
// Brand blue derived from existing onNAV site (#0c2bda)

const DW_BG = '#060f24';        // deep navy ground
const DW_BG2 = '#0a1a3a';       // raised surfaces
const DW_BRAND = '#0c2bda';     // onNAV brand blue
const DW_BRAND2 = '#1f47ff';    // brighter, for accents on dark
const DW_INK = '#e8eef7';
const DW_DIM = '#7a8aa3';
const DW_LINE = 'rgba(232,238,247,0.10)';
const DW_CYAN = '#5cc8d7';
const DW_AMBER = '#e8a23c';

const dwStyles = {
  root: {
    background: DW_BG,
    color: DW_INK,
    fontFamily: '"Archivo", system-ui, sans-serif',
    width: '100%',
    minHeight: '100%',
  },
  display: {
    fontFamily: '"Archivo Narrow", "Archivo", sans-serif',
    fontWeight: 600,
    letterSpacing: '-0.02em',
    lineHeight: 0.95,
  },
  mono: {
    fontFamily: '"JetBrains Mono", ui-monospace, monospace',
    fontSize: 11,
    letterSpacing: '0.12em',
    textTransform: 'uppercase',
    color: DW_DIM,
  },
};

function DWLogo({ size = 84 }) {
  return (
    <img src="assets/logo-white.png" alt="onNAV"
         style={{ height: size, width: 'auto', display: 'block' }} />
  );
}

const DW_NAV_LINK_STYLE = {
  fontSize: 13, color: DW_INK, textDecoration: 'none',
};

function DWNav() {
  const items = [
    ['Platform', '#platform'],
    ['Programs', '#programs'],
    ['Marine', '#marine'],
    ['Field Apps', '#field-apps'],
    ['Contact', '#contact'],
  ];
  return (
    <div className="dw-nav" style={{
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: '20px 56px', borderBottom: `1px solid ${DW_LINE}`,
      position: 'sticky', top: 0, background: 'rgba(10,22,40,0.85)',
      backdropFilter: 'blur(12px)', zIndex: 10,
    }}>
      <div className="dw-nav-inner" style={{ display: 'flex', alignItems: 'center', gap: 56 }}>
        <a href="#top" className="dw-nav-logo" style={{ display: 'block' }} aria-label="onNAV home"><DWLogo /></a>
        <nav className="dw-nav-links" style={{ display: 'flex', gap: 28 }}>
          {items.map(([label, href]) => (
            <a key={href} href={href} style={DW_NAV_LINK_STYLE}>{label}</a>
          ))}
        </nav>
      </div>
      <a href="#contact" className="dw-nav-cta" style={{
        display: 'none', fontSize: 12, color: DW_INK, textDecoration: 'none',
        letterSpacing: '0.14em', textTransform: 'uppercase',
        border: `1px solid ${DW_INK}`, padding: '8px 14px',
      }}>Contact</a>
    </div>
  );
}

function DWMap() {
  return (
    <svg viewBox="0 0 1600 760" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%', position: 'absolute', inset: 0 }}>
      <defs>
        <pattern id="dw-grid" width="40" height="40" patternUnits="userSpaceOnUse">
          <path d="M40 0 L0 0 0 40" fill="none" stroke={DW_LINE} strokeWidth="0.5" />
        </pattern>
        <radialGradient id="dw-glow" cx="50%" cy="50%" r="50%">
          <stop offset="0%" stopColor={DW_CYAN} stopOpacity="0.3" />
          <stop offset="100%" stopColor={DW_CYAN} stopOpacity="0" />
        </radialGradient>
      </defs>
      <rect width="1600" height="760" fill={DW_BG} />
      <rect width="1600" height="760" fill="url(#dw-grid)" />
      {[0, 1, 2, 3, 4, 5, 6, 7].map(i => (
        <path key={i} d={`M ${-100 + i * 60} 760 Q ${400 + i * 80} ${500 - i * 40}, ${900 + i * 60} ${600 - i * 30} T ${1700 + i * 60} ${500 - i * 50}`}
              fill="none" stroke={DW_BRAND2} strokeWidth="0.4" opacity={0.18 + i * 0.03} />
      ))}
      <path d="M 0 380 Q 200 360, 380 400 T 720 380 Q 880 350, 1020 400 Q 1200 460, 1380 420 T 1600 440"
            fill="none" stroke={DW_BRAND2} strokeWidth="1.2" opacity="0.7" />
      <path d="M 0 380 Q 200 360, 380 400 T 720 380 Q 880 350, 1020 400 Q 1200 460, 1380 420 T 1600 440 L 1600 0 L 0 0 Z"
            fill={DW_BRAND} opacity="0.18" />
      <path d="M 200 600 Q 600 550, 1100 580 T 1500 540" fill="none" stroke={DW_AMBER} strokeWidth="0.5" strokeDasharray="4 6" opacity="0.5" />
      <path d="M 100 480 Q 500 460, 900 470 T 1500 460" fill="none" stroke={DW_AMBER} strokeWidth="0.5" strokeDasharray="4 6" opacity="0.4" />
      {[
        [340, 540, 'AIS-2247', '12.4 KN'],
        [620, 590, 'AIS-1108', '8.1 KN'],
        [880, 510, 'AIS-3492', '18.7 KN'],
        [1120, 620, 'TAK-014', '0 KN · ANCH'],
        [1340, 470, 'AIS-7821', '22.3 KN'],
        [480, 460, 'SAR-K9', '4.2 KN'],
      ].map(([x, y, id, sp], i) => (
        <g key={i}>
          <circle cx={x} cy={y} r="22" fill="url(#dw-glow)" />
          <circle cx={x} cy={y} r="3" fill={DW_CYAN} />
          <circle cx={x} cy={y} r="6" fill="none" stroke={DW_CYAN} strokeWidth="0.8" opacity="0.6" />
          <line x1={x} y1={y} x2={x + 14} y2={y - 14} stroke={DW_CYAN} strokeWidth="0.5" opacity="0.5" />
          <text x={x + 18} y={y - 16} fill={DW_CYAN} fontSize="9" fontFamily="JetBrains Mono, monospace" letterSpacing="0.08em">{id}</text>
          <text x={x + 18} y={y - 5} fill={DW_DIM} fontSize="8" fontFamily="JetBrains Mono, monospace" letterSpacing="0.08em">{sp}</text>
        </g>
      ))}
      <g opacity="0.45">
        <ellipse cx="1200" cy="280" rx="120" ry="60" fill={DW_AMBER} opacity="0.18" />
        <ellipse cx="1200" cy="280" rx="80" ry="40" fill={DW_AMBER} opacity="0.22" />
        <ellipse cx="1200" cy="280" rx="40" ry="20" fill={DW_AMBER} opacity="0.32" />
      </g>
      <g stroke={DW_INK} strokeWidth="0.4" opacity="0.4" fontFamily="JetBrains Mono, monospace" fontSize="9" fill={DW_DIM}>
        <line x1="56" y1="700" x2="156" y2="700" />
        <line x1="56" y1="696" x2="56" y2="704" />
        <line x1="156" y1="696" x2="156" y2="704" />
        <text x="60" y="694" letterSpacing="0.08em">100 NM</text>
      </g>
    </svg>
  );
}

// --- Live sensor overlay components -----------------------------------------
// Each picks its own update cadence and walks values within plausible ranges so
// the hero reads like a live operating picture without distracting flicker.
function useTick(ms) {
  const [tick, setTick] = React.useState(0);
  React.useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), ms);
    return () => clearInterval(id);
  }, [ms]);
  return tick;
}

function DWSensorsReadout() {
  const tick = useTick(900);
  const ref = React.useRef({ online: 12, fusion: 0.4, uptime: 99.98 });
  const s = ref.current;
  if (tick % 4 === 0) s.online = 11 + Math.floor(Math.random() * 3); // 11–13
  s.fusion = Math.max(0.25, Math.min(0.85, s.fusion + (Math.random() - 0.5) * 0.12));
  s.uptime = Math.max(99.85, Math.min(99.99, s.uptime + (Math.random() - 0.5) * 0.02));
  const mono = { fontFamily: 'JetBrains Mono, monospace', fontVariantNumeric: 'tabular-nums' };
  return (
    <svg className="dw-hud" style={{ position: 'absolute', top: '14%', left: '38%', width: 320, height: 60, pointerEvents: 'none', opacity: 0.85 }} viewBox="0 0 320 60" fill="none">
      <text x="0" y="14" fill={DW_CYAN} fontSize="10" letterSpacing="0.12em" style={mono}>{`SENSORS · ${s.online} ONLINE`}</text>
      <text x="0" y="28" fill={DW_INK} fontSize="9" letterSpacing="0.08em" opacity="0.75" style={mono}>CTD · ADCP · MET · SAT-LINK</text>
      <text x="0" y="42" fill={DW_DIM} fontSize="9" letterSpacing="0.08em" style={mono}>{`FUSION ${s.fusion.toFixed(2)}s · UPTIME ${s.uptime.toFixed(2)}%`}</text>
    </svg>
  );
}

function DWAISContact() {
  const tick = useTick(800);
  const ref = React.useRef({ kn: 12.4, hdg: 88, rng: 4.2, brg: 247, blink: true });
  const s = ref.current;
  s.kn  = Math.max(8.5, Math.min(15.5, s.kn  + (Math.random() - 0.5) * 0.4));
  s.hdg = (s.hdg + (Math.random() < 0.5 ? -1 : 1) + 360) % 360;
  s.rng = Math.max(2.0, Math.min(7.0, s.rng + (Math.random() - 0.5) * 0.15));
  s.brg = (s.brg + (Math.random() < 0.5 ? -1 : 1) + 360) % 360;
  s.blink = !s.blink;
  const mono = { fontFamily: 'JetBrains Mono, monospace', fontVariantNumeric: 'tabular-nums' };
  const pad = (n, w) => String(Math.round(n)).padStart(w, '0');
  return (
    <svg className="dw-hud" style={{ position: 'absolute', top: '27%', right: '4%', width: 280, height: 130, pointerEvents: 'none', opacity: 0.95 }} viewBox="0 0 280 130" fill="none">
      <circle cx="80" cy="100" r="3.5" fill={DW_AMBER} opacity={s.blink ? 1 : 0.55} />
      <circle cx="80" cy="100" r="10" fill="none" stroke={DW_AMBER} strokeWidth="0.8" opacity="0.9" />
      <circle cx="80" cy="100" r="18" fill="none" stroke={DW_AMBER} strokeWidth="0.5" opacity="0.5" />
      <line x1="80" y1="90" x2="80" y2="56" stroke={DW_AMBER} strokeWidth="0.7" opacity="0.85" />
      <line x1="80" y1="56" x2="120" y2="56" stroke={DW_AMBER} strokeWidth="0.7" opacity="0.85" />
      <text x="128" y="40" fill={DW_AMBER} fontSize="11" letterSpacing="0.14em" fontWeight="500" style={mono}>AIS · M/V LIBRA</text>
      <text x="128" y="54" fill={DW_INK} fontSize="9" letterSpacing="0.08em" opacity="0.85" style={mono}>{`${s.kn.toFixed(1)} KN · HDG ${pad(s.hdg, 3)}°`}</text>
      <text x="128" y="66" fill={DW_DIM} fontSize="9" letterSpacing="0.08em" style={mono}>{`RNG ${s.rng.toFixed(1)} NM · BRG ${pad(s.brg, 3)}°`}</text>
    </svg>
  );
}

function DWUASLabel() {
  const tick = useTick(750);
  const ref = React.useRef({ alt: 412, depth: 38.0, btm: 0 });
  const s = ref.current;
  s.alt = Math.max(380, Math.min(450, s.alt + (Math.random() < 0.5 ? -1 : 1) * (Math.random() < 0.7 ? 1 : 2)));
  s.depth = Math.max(32, Math.min(46, s.depth + (Math.random() - 0.5) * 0.6));
  if (tick % 7 === 0) s.btm = (s.btm + 1) % 3;
  const btmKinds = ['SAND', 'ROCK', 'SILT'];
  const mono = { fontFamily: 'JetBrains Mono, monospace', fontVariantNumeric: 'tabular-nums' };
  return (
    <>
      <text x="108" y="16" fill={DW_CYAN} fontSize="11" letterSpacing="0.14em" fontWeight="500" style={mono}>UAS · K9-04</text>
      <text x="108" y="28" fill={DW_INK} fontSize="9" letterSpacing="0.08em" opacity="0.85" style={mono}>{`${Math.round(s.alt)} FT AGL · MULTIBEAM`}</text>
      <text x="108" y="40" fill={DW_DIM} fontSize="9" letterSpacing="0.08em" style={mono}>{`DEPTH ${s.depth.toFixed(1)}m · BTM ${btmKinds[s.btm]}`}</text>
    </>
  );
}

function DWBuoyLabel() {
  useTick(1000);
  const ref = React.useRef({ sst: 17.8, wave: 2.1, prd: 8.4, wind: 14 });
  const s = ref.current;
  s.sst  = Math.max(16.5, Math.min(19.5, s.sst  + (Math.random() - 0.5) * 0.12));
  s.wave = Math.max(1.4, Math.min(3.0, s.wave + (Math.random() - 0.5) * 0.15));
  s.prd  = Math.max(6.5, Math.min(10.5, s.prd  + (Math.random() - 0.5) * 0.25));
  s.wind = Math.max(8, Math.min(22, s.wind + (Math.random() < 0.5 ? -1 : 1)));
  const mono = { fontFamily: 'JetBrains Mono, monospace', fontVariantNumeric: 'tabular-nums' };
  return (
    <>
      <text x="88" y="10" fill={DW_CYAN} fontSize="11" letterSpacing="0.14em" fontWeight="500" style={mono}>BUOY · NDBC-46025</text>
      <text x="88" y="22" fill={DW_INK} fontSize="9" letterSpacing="0.08em" opacity="0.85" style={mono}>{`SST ${s.sst.toFixed(1)}°C · WAVE ${s.wave.toFixed(1)}m`}</text>
      <text x="88" y="34" fill={DW_DIM} fontSize="9" letterSpacing="0.08em" style={mono}>{`PRD ${s.prd.toFixed(1)}s · WIND ${Math.round(s.wind)} KT`}</text>
    </>
  );
}

function DWHeroLiveStamp() {
  // Upper-right hero stamp, ticks like the rest of the operating picture.
  const tick = useTick(700);
  const ref = React.useRef({ vessels: 1247, networks: 38, sync: 0.4, uptime: 99.98, blink: true });
  const s = ref.current;
  s.vessels  = Math.max(1180, Math.min(1320, s.vessels + Math.floor((Math.random() - 0.5) * 14)));
  if (tick % 5 === 0) s.networks = 36 + Math.floor(Math.random() * 5); // 36–40
  s.sync     = Math.max(0.25, Math.min(0.85, s.sync + (Math.random() - 0.5) * 0.12));
  s.uptime   = Math.max(99.85, Math.min(99.99, s.uptime + (Math.random() - 0.5) * 0.02));
  s.blink = !s.blink;
  return (
    <div style={{ ...dwStyles.mono, textAlign: 'right', fontVariantNumeric: 'tabular-nums' }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 8, justifyContent: 'flex-end' }}>
        <span style={{
          width: 6, height: 6, background: DW_CYAN, borderRadius: '50%',
          boxShadow: `0 0 12px ${DW_CYAN}`, opacity: s.blink ? 1 : 0.45, transition: 'opacity 0.3s',
        }} />
        {`LIVE · ${s.vessels.toLocaleString()} VESSELS · ${s.networks} NETWORKS`}
      </div>
      <div style={{ marginTop: 4 }}>{`SYNC ${s.sync.toFixed(2)}s · ${s.uptime.toFixed(2)}% UPTIME`}</div>
    </div>
  );
}

function DWHero() {
  return (
    <div id="top" className="dw-hero" style={{ position: 'relative', height: 880, overflow: 'hidden', borderBottom: `1px solid ${DW_LINE}` }}>
      <img src="assets/hero-research-vessel.jpeg" alt="" fetchpriority="high" decoding="async" style={{
        position: 'absolute', inset: 0, width: '100%', height: '100%',
        objectFit: 'cover', objectPosition: 'center 40%', filter: 'saturate(0.95) contrast(1.05) brightness(0.78)',
      }} />
      {/* Atmospheric darkening for legibility */}
      <div style={{ position: 'absolute', inset: 0, background: `linear-gradient(180deg, rgba(6,15,36,0.5) 0%, rgba(6,15,36,0.15) 35%, rgba(6,15,36,0.85) 100%)`, pointerEvents: 'none' }} />
      <div style={{ position: 'absolute', inset: 0, background: `linear-gradient(90deg, rgba(6,15,36,0.78) 0%, rgba(6,15,36,0.25) 55%, rgba(6,15,36,0) 100%)`, pointerEvents: 'none' }} />

      {/* Live sensor overlays — each ticks on its own cadence so the page reads as
          real telemetry rather than a synced loop. SVG <text> re-renders cheaply. */}
      <DWSensorsReadout />
      <DWAISContact />

      {/* UAS contact with sonar — left side, original height */}
      {/* UAS contact with sonar — lower-right (swapped with BUOY) */}
      <svg className="dw-hud" style={{ position: 'absolute', bottom: '14%', right: '5%', width: 280, height: 170, pointerEvents: 'none', opacity: 0.95 }} viewBox="0 0 280 170" fill="none">
        {/* Drone glyph anchor */}
        <g transform="translate(60,50)" stroke={DW_CYAN} strokeWidth="0.9" fill="none" opacity="0.95">
          <line x1="-10" y1="0" x2="10" y2="0" />
          <line x1="0" y1="-7" x2="0" y2="7" />
          <circle cx="-10" cy="0" r="2.5" fill={DW_CYAN} />
          <circle cx="10" cy="0" r="2.5" fill={DW_CYAN} />
          <circle cx="0" cy="-7" r="2.5" fill={DW_CYAN} />
          <circle cx="0" cy="7" r="2.5" fill={DW_CYAN} />
          <circle cx="0" cy="0" r="1.5" fill={DW_CYAN} />
        </g>
        {/* Downward sonar swath cone */}
        <path d="M 60 60 L 38 140 L 82 140 Z" fill={DW_CYAN} fillOpacity="0.08" stroke={DW_CYAN} strokeWidth="0.5" strokeDasharray="2 3" opacity="0.7" />
        {/* Sonar return arcs */}
        <path d="M 40 110 Q 60 105 80 110" stroke={DW_CYAN} strokeWidth="0.6" fill="none" opacity="0.7" />
        <path d="M 36 125 Q 60 118 84 125" stroke={DW_CYAN} strokeWidth="0.6" fill="none" opacity="0.55" />
        <path d="M 32 140 Q 60 132 88 140" stroke={DW_CYAN} strokeWidth="0.6" fill="none" opacity="0.4" />
        {/* Leader line up-right to label */}
        <line x1="60" y1="42" x2="60" y2="24" stroke={DW_CYAN} strokeWidth="0.7" opacity="0.85" />
        <line x1="60" y1="24" x2="100" y2="24" stroke={DW_CYAN} strokeWidth="0.7" opacity="0.85" />
        <DWUASLabel />
      </svg>

      {/* Buoy contact — mid-left (swapped with UAS) */}
      <svg className="dw-hud" style={{ position: 'absolute', top: '40%', left: '37.5%', width: 260, height: 130, pointerEvents: 'none', opacity: 0.95 }} viewBox="0 0 260 130" fill="none">
        {/* Buoy glyph anchor */}
        <g transform="translate(40,80)">
          <circle cx="0" cy="0" r="3.5" fill={DW_CYAN} />
          <circle cx="0" cy="0" r="9" fill="none" stroke={DW_CYAN} strokeWidth="0.7" opacity="0.85" />
          <line x1="0" y1="-9" x2="0" y2="-18" stroke={DW_CYAN} strokeWidth="0.7" opacity="0.85" />
          <path d="M -4 -22 L 4 -22 L 0 -28 Z" fill={DW_CYAN} opacity="0.85" />
          {/* Wave ripples */}
          <path d="M -16 4 Q -8 0 0 4 Q 8 8 16 4" stroke={DW_CYAN} strokeWidth="0.5" fill="none" opacity="0.5" />
          <path d="M -22 10 Q -11 6 0 10 Q 11 14 22 10" stroke={DW_CYAN} strokeWidth="0.5" fill="none" opacity="0.35" />
        </g>
        {/* Leader line up-right to label */}
        <line x1="40" y1="48" x2="40" y2="20" stroke={DW_CYAN} strokeWidth="0.7" opacity="0.85" />
        <line x1="40" y1="20" x2="80" y2="20" stroke={DW_CYAN} strokeWidth="0.7" opacity="0.85" />
        <DWBuoyLabel />
      </svg>

      <div className="dw-hero-content" style={{ position: 'absolute', inset: 0, padding: '48px 56px 64px', display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
        <div className="dw-hero-stamps" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
          <div style={dwStyles.mono}>
            <div>8°45′ N · 104°55′ E</div>
            <div style={{ marginTop: 4 }}>CÀ MAU PROVINCE</div>
          </div>
          <DWHeroLiveStamp />
        </div>
        <div style={{ maxWidth: 1100 }}>
          <div className="dw-hero-kicker" style={{ ...dwStyles.mono, marginBottom: 24, color: DW_CYAN }}>GEOSPATIAL SYSTEMS, TERRESTRIAL · MARITIME · SPACE · CYBER</div>
          <h1 className="dw-hero-h1" style={{ ...dwStyles.display, fontSize: 132, margin: 0, color: '#fff', textShadow: '0 2px 24px rgba(0,0,0,0.4)' }}>
            Augmented<br/><em style={{ fontStyle: 'italic', color: DW_CYAN, fontWeight: 400 }}>awareness.</em>
          </h1>
          <p className="dw-hero-sub" style={{ fontSize: 20, lineHeight: 1.5, color: DW_INK, maxWidth: 600, marginTop: 32, textShadow: '0 1px 8px rgba(0,0,0,0.5)' }}>
            Tailored geospatial platforms that integrate satellite, sensor, and mobile telemetry into one operational picture, built for national programs, deployed in the field, refined in austere environments.
          </p>
          <div style={{ display: 'flex', gap: 16, marginTop: 40 }}>
            <a href="#contact" style={{
              background: '#fff', color: DW_BG, border: 'none', padding: '16px 28px',
              fontSize: 14, fontFamily: 'inherit', letterSpacing: '0.04em', cursor: 'pointer', fontWeight: 600,
              textDecoration: 'none', display: 'inline-block',
            }}>CONTACT US →</a>
          </div>
        </div>
      </div>
    </div>
  );
}

function DWStrip() {
  // Live operating-picture marquee with simulated jitter.
  // Each metric ticks at its own cadence so the row reads as live telemetry,
  // not a synchronized loop. Coords drift in seconds; counts walk by small deltas;
  // link latency wobbles around a baseline; mesh status flips occasionally.
  const [tick, setTick] = React.useState(0);
  React.useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), 600);
    return () => clearInterval(id);
  }, []);

  // Use refs so values walk continuously instead of jumping each render.
  const stateRef = React.useRef({
    latSec: 12,
    lonSec: 47,
    sensors: 12,
    nets: 3,
    link: 0.4,
    contacts: 1247,
    meshIdx: 0,
    blink: true,
  });

  const meshStates = ['MESH NOMINAL', 'MESH SYNC', 'MESH NOMINAL', 'MESH NOMINAL', 'MESH RELAY'];
  const s = stateRef.current;

  // Walk values on each tick. Small, asymmetric deltas read as organic.
  s.latSec = Math.max(0, Math.min(59, s.latSec + (Math.random() < 0.5 ? -1 : 1)));
  s.lonSec = Math.max(0, Math.min(59, s.lonSec + (Math.random() < 0.5 ? -1 : 1)));
  if (tick % 3 === 0) s.sensors = 11 + Math.floor(Math.random() * 3); // 11–13
  if (tick % 5 === 0) s.nets = 2 + Math.floor(Math.random() * 3);     // 2–4
  s.link = Math.max(0.2, Math.min(0.9, s.link + (Math.random() - 0.5) * 0.15));
  s.contacts = Math.max(1100, Math.min(1400, s.contacts + Math.floor((Math.random() - 0.5) * 14)));
  if (tick % 4 === 0) s.meshIdx = Math.floor(Math.random() * meshStates.length);
  s.blink = !s.blink;

  const pad = (n) => String(n).padStart(2, '0');
  const items = [
    { k: 'live',     t: '● LIVE', color: DW_BRAND2, opacity: s.blink ? 1 : 0.55 },
    { k: 'coord',    t: `8°45′${pad(s.latSec)}″ N · 104°55′${pad(s.lonSec)}″ E` },
    { k: 'sensors',  t: `${s.sensors} SENSORS ONLINE` },
    { k: 'nets',     t: `${s.nets} NETS` },
    { k: 'link',     t: `LINK ${s.link.toFixed(1)}s` },
    { k: 'contacts', t: `AIS · ${s.contacts.toLocaleString()} CONTACTS` },
    { k: 'mesh',     t: meshStates[s.meshIdx] },
  ];

  return (
    <div className="dw-strip" style={{
      display: 'flex', gap: 0, padding: '24px 56px', borderBottom: `1px solid ${DW_LINE}`,
      ...dwStyles.mono, fontSize: 11, justifyContent: 'space-between', alignItems: 'center',
      fontVariantNumeric: 'tabular-nums',
    }}>
      {items.map((it) => (
        <span
          key={it.k}
          style={{
            color: it.color || DW_INK,
            letterSpacing: '0.14em',
            opacity: it.opacity != null ? it.opacity : 1,
            transition: 'opacity 0.3s linear',
          }}
        >
          {it.t}
        </span>
      ))}
    </div>
  );
}

function DWSectionHead({ kicker, title, eyebrow, id }) {
  return (
    <div id={id} className="dw-sec-head" style={{ padding: '120px 56px 56px', borderBottom: `1px solid ${DW_LINE}`, scrollMarginTop: 80 }}>
      <div style={{ ...dwStyles.mono, color: DW_BRAND2, marginBottom: 24 }}>{kicker}</div>
      <h2 style={{ ...dwStyles.display, fontSize: 92, margin: 0, maxWidth: 1100 }}>{title}</h2>
      {eyebrow && <p style={{ fontSize: 18, color: DW_DIM, maxWidth: 680, marginTop: 32, lineHeight: 1.55 }}>{eyebrow}</p>}
    </div>
  );
}

function DWPlatformGrid() {
  const items = [
    { num: 'I', t: 'Sensor Fusion', d: 'Satellite, AIS, ADS-B, NMEA, LoRa, collapsed into one normalized feed.' },
    { num: 'II', t: 'Edge Resilience', d: 'Operates without backhaul. Mesh and local persistence keep teams synced.' },
    { num: 'III', t: 'TAK Interop', d: 'Native Cursor on Target. Bidirectional with ATAK, iTAK, WinTAK.' },
    { num: 'IV', t: 'Custom Programs', d: 'Air-gapped deployments, mission networks, bespoke sensor packages.' },
  ];
  return (
    <div style={{ padding: '0 56px 96px', borderBottom: `1px solid ${DW_LINE}` }}>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr 1fr', gap: 0, borderTop: `1px solid ${DW_LINE}` }}>
        {items.map((it, i) => (
          <div key={it.num} style={{
            padding: '40px 28px 0 0', borderRight: i < 3 ? `1px solid ${DW_LINE}` : 'none', paddingLeft: i > 0 ? 28 : 0,
          }}>
            <div style={{ ...dwStyles.mono, color: DW_BRAND2 }}>CAPABILITY {it.num}</div>
            <h3 style={{ ...dwStyles.display, fontSize: 36, margin: '14px 0 14px' }}>{it.t}</h3>
            <p style={{ color: DW_DIM, fontSize: 14.5, lineHeight: 1.55 }}>{it.d}</p>
          </div>
        ))}
      </div>
    </div>
  );
}

function DWLiveCaption() {
  // Live AIS-feel caption under the Marine description. Vessel count walks +/-a few,
  // message rate breathes around 1.0 msg/s, and a small "● LIVE" dot blinks.
  const [tick, setTick] = React.useState(0);
  React.useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), 700);
    return () => clearInterval(id);
  }, []);
  const stateRef = React.useRef({ vessels: 166, rate: 1.0, blink: true });
  const s = stateRef.current;
  s.vessels = Math.max(140, Math.min(190, s.vessels + Math.floor((Math.random() - 0.5) * 5)));
  s.rate = Math.max(0.6, Math.min(1.6, s.rate + (Math.random() - 0.5) * 0.18));
  s.blink = !s.blink;
  return (
    <div style={{
      marginTop: 36, ...dwStyles.mono, color: DW_DIM,
      display: 'flex', alignItems: 'center', gap: 12, fontVariantNumeric: 'tabular-nums',
    }}>
      <span style={{ color: DW_BRAND2, opacity: s.blink ? 1 : 0.45, transition: 'opacity 0.3s' }}>●</span>
      <span>CHESAPEAKE BAY · {s.vessels} VESSELS TRACKED · {s.rate.toFixed(1)} MSG/S</span>
    </div>
  );
}

function DWPlatformShowcase() {
  return (
    <div id="marine" className="dw-overwatch" style={{ padding: '96px 56px 120px', borderBottom: `1px solid ${DW_LINE}`, background: '#06122b', scrollMarginTop: 80 }}>
      <div className="dw-overwatch-grid" style={{ display: 'grid', gridTemplateColumns: '0.85fr 1.4fr', gap: 80, alignItems: 'center' }}>
        {/* Copy column */}
        <div>
          <div style={{ ...dwStyles.mono, color: DW_BRAND2, marginBottom: 24 }}>OVERWATCH · LIVE</div>
          <h2 style={{ ...dwStyles.display, fontSize: 64, margin: 0, lineHeight: 0.95 }}>
            Every vessel.<br/><em style={{ fontStyle: 'italic', fontWeight: 400, color: DW_CYAN }}>Every channel.</em><br/>One screen.
          </h2>
          <p style={{ fontSize: 17, color: DW_DIM, maxWidth: 460, marginTop: 28, lineHeight: 1.55 }}>
            Marine Overwatch fuses live AIS, NOAA charts, currents, weather, and your own sensor feeds into a single tactical picture. Tracking thousands of contacts at sub-second update rates, afloat, ashore, or at the watch desk.
          </p>
          <div className="dw-overwatch-features" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20, marginTop: 36, paddingTop: 28, borderTop: `1px solid ${DW_LINE}`, maxWidth: 460 }}>
            <div>
              <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 6 }}>AIS</div>
              <div style={{ color: DW_INK, fontSize: 14.5, lineHeight: 1.5 }}>Live vessel tracking with track history up to 3 hours.</div>
            </div>
            <div>
              <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 6 }}>CHARTS</div>
              <div style={{ color: DW_INK, fontSize: 14.5, lineHeight: 1.5 }}>NOAA ENC + raster, 3D bathymetry, official soundings.</div>
            </div>
            <div>
              <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 6 }}>ENVIRONMENT</div>
              <div style={{ color: DW_INK, fontSize: 14.5, lineHeight: 1.5 }}>Currents, wind, tides, overlaid on the map you're working.</div>
            </div>
            <div>
              <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 6 }}>PLANNER</div>
              <div style={{ color: DW_INK, fontSize: 14.5, lineHeight: 1.5 }}>Routes, waypoints, anchorages, synced across the fleet.</div>
            </div>
          </div>
          <DWLiveCaption />
        </div>

        {/* Tablet device frame with the real Overwatch screenshot */}
        <div style={{ position: 'relative' }}>
          {/* The screenshot already includes its own iPad chassis. Use a soft ambient floor-shadow + faint glow underneath. */}
          <div style={{ position: 'relative' }}>
            {/* Ambient floor shadow — wide, soft ellipse below the device */}
            <div style={{
              position: 'absolute',
              left: '6%',
              right: '6%',
              bottom: '-4%',
              height: '14%',
              background: 'radial-gradient(ellipse at center, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.25) 40%, rgba(0,0,0,0) 75%)',
              filter: 'blur(18px)',
              pointerEvents: 'none',
              zIndex: 0,
            }} />
            <img src="assets/onnav-marine-overwatch.webp"
                 alt="onNAV Marine Overwatch on tablet, Chesapeake Bay AIS view"
                 loading="lazy" decoding="async"
                 style={{
                   position: 'relative',
                   zIndex: 1,
                   width: '100%',
                   height: 'auto',
                   display: 'block',
                 }} />
          </div>
          {/* Caption strip */}
          <div style={{ marginTop: 20, display: 'flex', justifyContent: 'flex-end', ...dwStyles.mono, color: DW_DIM }}>
            <span>onNAV MARINE, OVERWATCH</span>
          </div>
        </div>
      </div>
    </div>
  );
}

function DWHelicopterTelemetry() {
  // Live overlay for the helicopter photo: altitude drifts around 8,400 ft,
  // SAT-LINK latency wobbles around 184 ms, blinking ● to read as live.
  const [tick, setTick] = React.useState(0);
  React.useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), 700);
    return () => clearInterval(id);
  }, []);
  const stateRef = React.useRef({ alt: 8400, link: 184, blink: true });
  const s = stateRef.current;
  s.alt = Math.max(8200, Math.min(8600, s.alt + Math.round((Math.random() - 0.5) * 30)));
  s.link = Math.max(160, Math.min(220, s.link + Math.round((Math.random() - 0.5) * 6)));
  s.blink = !s.blink;
  const fmtAlt = s.alt.toLocaleString('en-US');
  return (
    <div style={{
      position: 'absolute', top: 32, left: 56, ...dwStyles.mono, color: '#fff',
      zIndex: 2, textAlign: 'left', display: 'flex', alignItems: 'flex-start', gap: 10,
      fontVariantNumeric: 'tabular-nums',
    }}>
      <span style={{ color: DW_BRAND2, opacity: s.blink ? 1 : 0.4, transition: 'opacity 0.3s', lineHeight: 1.4 }}>●</span>
      <div>
        <div>UH-60 · {fmtAlt} FT MSL</div>
        <div style={{ marginTop: 4, color: DW_DIM }}>SAT-LINK · {s.link}ms</div>
      </div>
    </div>
  );
}

function DWFeatureSpread() {
  return (
    <div id="programs" className="dw-spread" style={{ position: 'relative', minHeight: 820, borderBottom: `1px solid ${DW_LINE}`, overflow: 'hidden', scrollMarginTop: 80 }}>
      {/* Full-bleed operator photo */}
      <img src="assets/blackhawk-fog.jpeg" alt="Black Hawk over fog-shrouded mountain ridge at sunrise"
           loading="lazy" decoding="async"
           style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 50%', filter: 'saturate(0.92) contrast(1.05) brightness(0.7)', transform: 'scaleX(-1)' }} />
      {/* Side gradient for text legibility — right-anchored to balance flipped photo */}
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(270deg, rgba(6,15,36,0.92) 0%, rgba(6,15,36,0.78) 35%, rgba(6,15,36,0.25) 70%, rgba(6,15,36,0) 100%)', pointerEvents: 'none' }} />
      {/* Top + bottom darkening */}
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, rgba(6,15,36,0.45) 0%, rgba(6,15,36,0) 25%, rgba(6,15,36,0) 75%, rgba(6,15,36,0.6) 100%)', pointerEvents: 'none' }} />

      {/* Photo metadata corners — swapped to left so they don't collide with right-justified copy */}
      <DWHelicopterTelemetry />
      <div style={{ position: 'absolute', bottom: 32, left: 56, ...dwStyles.mono, color: DW_DIM, zIndex: 2 }}>RIDGELINE RESCUE · ALPHA-7</div>

      {/* Content column on right half, right-justified */}
      <div className="dw-spread-content" style={{ position: 'relative', zIndex: 2, padding: '140px 56px', maxWidth: 760, marginLeft: 'auto', textAlign: 'right' }}>
        <div style={{ ...dwStyles.mono, color: DW_BRAND2, marginBottom: 24 }}>BUILT FOR THE OPERATOR</div>
        <h2 style={{ ...dwStyles.display, fontSize: 84, margin: 0, color: '#fff', textShadow: '0 2px 20px rgba(0,0,0,0.4)' }}>
          Custom solutions,<br/>designed for <em style={{ fontStyle: 'italic', fontWeight: 400, color: DW_CYAN }}>geospatial dominance.</em>
        </h2>
        <p style={{ fontSize: 18, color: DW_INK, maxWidth: 560, marginTop: 32, marginLeft: 'auto', lineHeight: 1.55 }}>
          Every program is different. We build to fit the mission, the platform, the environment, and the team, not the other way around. The work spans scoping through sustainment, with the operator at the center of every decision.
        </p>
        <div className="dw-spread-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 36, marginTop: 48, maxWidth: 620, marginLeft: 'auto', textAlign: 'left' }}>
          <div>
            <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 8 }}>CAPABILITY I</div>
            <div style={{ fontSize: 18, color: '#fff', fontWeight: 600 }}>Sensor Fusion</div>
            <div style={{ fontSize: 14, color: DW_DIM, marginTop: 6, lineHeight: 1.5 }}>Satellite, AIS, ADS-B, NMEA, LoRa, collapsed into one normalized feed.</div>
          </div>
          <div>
            <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 8 }}>CAPABILITY II</div>
            <div style={{ fontSize: 18, color: '#fff', fontWeight: 600 }}>Edge Resilience</div>
            <div style={{ fontSize: 14, color: DW_DIM, marginTop: 6, lineHeight: 1.5 }}>Operates without backhaul. Mesh and local persistence keep teams synced.</div>
          </div>
          <div>
            <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 8 }}>CAPABILITY III</div>
            <div style={{ fontSize: 18, color: '#fff', fontWeight: 600 }}>TAK Interop</div>
            <div style={{ fontSize: 14, color: DW_DIM, marginTop: 6, lineHeight: 1.5 }}>Native Cursor on Target. Bidirectional with ATAK and iTAK.</div>
          </div>
          <div>
            <div style={{ ...dwStyles.mono, color: DW_CYAN, marginBottom: 8 }}>CAPABILITY IV</div>
            <div style={{ fontSize: 18, color: '#fff', fontWeight: 600 }}>Custom Programs</div>
            <div style={{ fontSize: 14, color: DW_DIM, marginTop: 6, lineHeight: 1.5 }}>Air-gapped deployments, mission networks, bespoke sensor packages.</div>
          </div>
        </div>
      </div>
    </div>
  );
}

// iPhone Pro Max frame — built from the screen outward.
// Screenshot is 460×996 (1:2.165); we lock the screen to that ratio and add a uniform bezel.
function DWPhone({ src, badge, accent = DW_CYAN }) {
  const SCREEN_MAX_W = 304;        // px, the screen's max width
  const BEZEL = 8;                 // px, uniform bezel thickness
  const SCREEN_RADIUS = 44;        // px, screen corner radius
  const DEVICE_RADIUS = SCREEN_RADIUS + BEZEL; // 52

  return (
    <div style={{
      // Outer device wrapper — width = screen + 2*bezel, padding = bezel, no aspectRatio (height = padding + child)
      display: 'inline-block',
      width: SCREEN_MAX_W + BEZEL * 2,
      maxWidth: '100%',
      padding: BEZEL,
      boxSizing: 'border-box',
      background: 'linear-gradient(135deg, #2a2a2c 0%, #16161a 50%, #2a2a2c 100%)',
      borderRadius: DEVICE_RADIUS,
      position: 'relative',
      boxShadow: '0 40px 80px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06), inset 0 0 0 1px rgba(255,255,255,0.04)',
    }}>
      {/* Screen, locked to the screenshot's aspect ratio */}
      <div style={{
        width: '100%',
        aspectRatio: '460 / 996',
        background: '#000',
        borderRadius: SCREEN_RADIUS,
        overflow: 'hidden',
        position: 'relative',
      }}>
        <img src={src} alt="" loading="lazy" decoding="async" style={{
          width: '100%', height: '100%', objectFit: 'cover', display: 'block',
        }} />
        {/* Dynamic Island — sits over the screen, near top center */}
        <div style={{
          position: 'absolute',
          top: 10,
          left: '50%',
          transform: 'translateX(-50%)',
          width: 110,
          height: 28,
          background: '#000',
          borderRadius: 16,
          zIndex: 2,
        }} />
      </div>
      {/* Side buttons */}
      <div style={{ position: 'absolute', left: -2, top: '13%', width: 3, height: 26, background: '#1a1a1c', borderRadius: '2px 0 0 2px' }} />
      <div style={{ position: 'absolute', left: -2, top: '20%', width: 3, height: 42, background: '#1a1a1c', borderRadius: '2px 0 0 2px' }} />
      <div style={{ position: 'absolute', left: -2, top: '30%', width: 3, height: 42, background: '#1a1a1c', borderRadius: '2px 0 0 2px' }} />
      <div style={{ position: 'absolute', right: -2, top: '22%', width: 3, height: 60, background: '#1a1a1c', borderRadius: '0 2px 2px 0' }} />

      {badge && (
        <div style={{
          position: 'absolute', top: 24, right: -16, padding: '6px 12px',
          background: accent, color: DW_BG, ...dwStyles.mono, fontSize: 9,
          transform: 'rotate(2deg)', boxShadow: `0 4px 16px ${accent}40`,
          zIndex: 3,
        }}>{badge}</div>
      )}
    </div>
  );
}

function DWProductRow({ idx, name, kicker, blurb, features, photoSrc, photoSrc2, photoSrc3, photoSide = 'right', accent, ambient, cta }) {
  // Full-bleed ambient photo with text + phone overlaid on top.
  const textOnLeft = photoSide === 'right';
  const gradientDir = textOnLeft
    ? 'linear-gradient(90deg, rgba(6,15,36,0.92) 0%, rgba(6,15,36,0.78) 35%, rgba(6,15,36,0.25) 70%, rgba(6,15,36,0.05) 100%)'
    : 'linear-gradient(270deg, rgba(6,15,36,0.92) 0%, rgba(6,15,36,0.78) 35%, rgba(6,15,36,0.25) 70%, rgba(6,15,36,0.05) 100%)';
  return (
    <div className="dw-prow" style={{
      position: 'relative', minHeight: 820, borderBottom: `1px solid ${DW_LINE}`,
      overflow: 'hidden', background: DW_BG2,
    }}>
      {ambient && (
        <img src={ambient} alt="" loading="lazy" decoding="async" style={{
          position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover',
        }} />
      )}
      <div style={{ position: 'absolute', inset: 0, background: gradientDir }} />
      <div style={{
        position: 'absolute', top: 32, left: 56, ...dwStyles.mono, color: '#fff',
        textShadow: '0 1px 6px rgba(0,0,0,0.6)', zIndex: 3,
      }}>0{idx} · {name.toUpperCase()}</div>
      <div className="dw-prow-grid" style={{
        position: 'relative', zIndex: 2, padding: '120px 56px',
        display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 64, alignItems: 'center', minHeight: 820,
        direction: textOnLeft ? 'ltr' : 'rtl',
      }}>
        <div style={{ direction: 'ltr' }}>
          <div style={{ ...dwStyles.mono, color: accent, marginBottom: 24 }}>{kicker}</div>
          <h3 className="dw-prow-h3" style={{ ...dwStyles.display, fontSize: 88, margin: 0, color: '#fff' }}>{name}</h3>
          <p style={{ fontSize: 18, color: DW_INK, lineHeight: 1.5, maxWidth: 520, marginTop: 24 }}>{blurb}</p>
          <div className="dw-prow-features" style={{ marginTop: 40, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px 32px', maxWidth: 540 }}>
            {features.map(f => (
              <div key={f.t}>
                <div style={{ ...dwStyles.mono, color: DW_DIM, marginBottom: 6 }}>{f.k}</div>
                <div style={{ fontSize: 16, fontWeight: 500, color: '#fff' }}>{f.t}</div>
              </div>
            ))}
          </div>
          <div style={{ marginTop: 40, display: 'flex', gap: 12 }}>
            {cta && cta.href ? (
              <a
                href={cta.href}
                {...(cta.href.startsWith('#') ? {} : { target: '_blank', rel: 'noopener' })}
                style={{
                  background: 'transparent', color: '#fff', border: `1px solid #fff`, padding: '14px 22px',
                  fontSize: 13, fontFamily: 'inherit', letterSpacing: '0.04em', textDecoration: 'none',
                  display: 'inline-block',
                }}
              >{cta.label}</a>
            ) : cta ? (
              <span style={{
                background: 'transparent', color: 'rgba(255,255,255,0.55)',
                border: `1px solid rgba(255,255,255,0.35)`, padding: '14px 22px',
                fontSize: 13, fontFamily: 'inherit', letterSpacing: '0.04em',
                display: 'inline-block', cursor: 'default',
              }}>{cta.label}</span>
            ) : null}
          </div>
        </div>
        <div className="dw-prow-phones" style={{ direction: 'ltr', display: 'flex', justifyContent: 'center', alignItems: 'flex-end', gap: photoSrc2 ? 18 : 0 }}>
          {photoSrc3 && (
            <div className="dw-prow-phone-secondary" style={{ transform: 'translateY(40px) rotate(-5deg)', opacity: 0.85 }}>
              <DWPhone src={photoSrc3} accent={accent} />
            </div>
          )}
          {photoSrc2 && (
            <div className="dw-prow-phone-secondary" style={{ transform: 'translateY(20px) rotate(-2deg)', opacity: 0.95, zIndex: 1 }}>
              <DWPhone src={photoSrc2} accent={accent} />
            </div>
          )}
          <div style={{ transform: photoSrc2 ? 'rotate(2deg)' : 'none', zIndex: 2 }}>
            <DWPhone src={photoSrc} accent={accent} />
          </div>
        </div>
      </div>
    </div>
  );
}

function DWConsumerHeader() {
  return (
    <div id="field-apps" className="dw-consumer" style={{ position: 'relative', borderBottom: `1px solid ${DW_LINE}`, overflow: 'hidden', scrollMarginTop: 80 }}>
      <img src="assets/sailing-helm.jpeg" alt="" loading="lazy" decoding="async" style={{
        position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover',
        filter: 'saturate(0.85) contrast(1.05)',
      }} />
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, rgba(10,22,40,0.5) 0%, rgba(10,22,40,0.4) 50%, rgba(10,22,40,0.95) 100%)' }} />
      <div className="dw-consumer-content" style={{ position: 'relative', padding: '200px 56px 100px' }}>
        <div style={{ ...dwStyles.mono, color: DW_AMBER, marginBottom: 32 }}>FIELD APPLICATIONS · iOS</div>
        <h2 className="dw-consumer-h2" style={{ ...dwStyles.display, fontSize: 168, margin: 0, lineHeight: 0.92 }}>
          On the<br/>water,<br/><em style={{ fontStyle: 'italic', fontWeight: 400, color: DW_AMBER }}>off the grid.</em>
        </h2>
        <p style={{ fontSize: 20, color: DW_INK, maxWidth: 620, marginTop: 40, lineHeight: 1.5 }}>
          Built on experience from national programs, onNAV powers a line of hardware and software systems for sailors, search-and-rescue teams, and operators.
        </p>
      </div>
    </div>
  );
}

function DWField({ label, val, on, type = 'text', textarea, required }) {
  const [focus, setFocus] = React.useState(false);
  const Cmp = textarea ? 'textarea' : 'input';
  return (
    <label style={{ display: 'block' }}>
      <div style={{ ...dwStyles.mono, color: DW_DIM, marginBottom: 8 }}>
        {label}{required && ' *'}
      </div>
      <Cmp
        type={type}
        value={val}
        onChange={(e) => on(e.target.value)}
        onFocus={() => setFocus(true)}
        onBlur={() => setFocus(false)}
        rows={textarea ? 4 : undefined}
        required={required}
        style={{
          width: '100%', background: 'transparent', border: 'none',
          borderBottom: `1px solid ${focus ? DW_CYAN : 'rgba(232,238,247,0.25)'}`,
          padding: '10px 0', color: DW_INK,
          fontFamily: 'inherit', fontSize: 16, outline: 'none',
          resize: 'vertical', transition: 'border-color .2s',
        }}
      />
    </label>
  );
}

function DWContact() {
  const [sent, setSent] = React.useState(false);
  const [sending, setSending] = React.useState(false);
  const [error, setError] = React.useState(null);
  const [form, setForm] = React.useState({ name: '', org: '', email: '', msg: '', _hp: '' });

  async function submit(e) {
    e.preventDefault();
    if (!form.email || !form.msg || sending) return;
    setSending(true);
    setError(null);
    try {
      const res = await fetch('/api/contact', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(form),
      });
      if (!res.ok) {
        const body = await res.json().catch(() => ({}));
        throw new Error(body.error || 'send_failed');
      }
      setSent(true);
    } catch (err) {
      setError('We could not send that. Please try again in a moment.');
    } finally {
      setSending(false);
    }
  }

  return (
    <section id="contact" className="dw-contact" style={{
      background: '#06101e', borderTop: `1px solid ${DW_LINE}`,
      padding: '120px 56px', scrollMarginTop: 80,
    }}>
      <div style={{ ...dwStyles.mono, color: DW_BRAND2, marginBottom: 24 }}>CONTACT</div>
      <div className="dw-contact-grid" style={{ display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 80, maxWidth: 1280 }}>
        <div>
          <h2 className="dw-contact-h2" style={{ ...dwStyles.display, fontSize: 84, margin: 0 }}>
            Brief us on your <em style={{ fontStyle: 'italic', fontWeight: 400, color: DW_CYAN }}>mission.</em>
          </h2>
          <p style={{ fontSize: 18, color: DW_INK, lineHeight: 1.55, marginTop: 28, maxWidth: 460 }}>
            Programs, integrators, and operators. We work directly with the team flying the mission.
          </p>
        </div>

        <form onSubmit={submit} style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
          {sent ? (
            <div style={{ padding: '32px 0' }}>
              <div style={{ ...dwStyles.mono, color: DW_CYAN }}>TRANSMISSION RECEIVED</div>
              <h3 style={{ ...dwStyles.display, fontSize: 36, margin: '14px 0 12px', color: DW_INK }}>
                Thank you, {form.name || 'friend'}.
              </h3>
              <p style={{ fontSize: 15, color: DW_DIM, maxWidth: '36ch', lineHeight: 1.5 }}>
                We will be in touch within two business days.
              </p>
            </div>
          ) : (
            <>
              <DWField label="Name" val={form.name} on={v => setForm({ ...form, name: v })} />
              <DWField label="Organization" val={form.org} on={v => setForm({ ...form, org: v })} />
              <DWField label="Email" type="email" val={form.email} on={v => setForm({ ...form, email: v })} required />
              <DWField label="Message" textarea val={form.msg} on={v => setForm({ ...form, msg: v })} required />
              {/* Honeypot, hidden from humans, catches naive bots. */}
              <input
                type="text"
                name="company_website"
                tabIndex={-1}
                autoComplete="off"
                value={form._hp}
                onChange={e => setForm({ ...form, _hp: e.target.value })}
                style={{ position: 'absolute', left: '-10000px', width: 1, height: 1, opacity: 0 }}
                aria-hidden="true"
              />
              {error && (
                <div style={{ ...dwStyles.mono, color: DW_AMBER, letterSpacing: '0.08em' }}>
                  {error}
                </div>
              )}
              <button type="submit" disabled={sending} style={{
                marginTop: 8, padding: '16px 24px',
                background: DW_INK, color: DW_BG, border: 'none',
                fontSize: 12, fontFamily: 'inherit', letterSpacing: '0.14em', textTransform: 'uppercase',
                fontWeight: 600, cursor: sending ? 'wait' : 'pointer', textAlign: 'left',
                opacity: sending ? 0.6 : 1,
              }}>
                {sending ? 'Sending…' : 'Send Transmission →'}
              </button>
            </>
          )}
        </form>
      </div>
    </section>
  );
}

function DWFooter() {
  return (
    <div className="dw-footer" style={{ padding: '64px 56px 40px', background: '#06101e', borderTop: `1px solid ${DW_LINE}` }}>
      <div style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 24,
        ...dwStyles.mono, flexWrap: 'wrap',
      }}>
        <DWLogo size={60} />
        <div>© 2026 onNAV LLC</div>
        <div>TAILORED AUGMENTED AWARENESS</div>
      </div>
    </div>
  );
}

function DWResponsiveStyles() {
  // One stylesheet, two breakpoints. Targets the classes added to each section
  // and uses !important to override the inline styles the design ships with.
  return (
    <style>{`
      img, svg, video { max-width: 100%; }

      /* Tablet, 760-1080px: tighten gutters, scale display type, allow product
         rows to stack so the staggered phone trio doesn't overflow. */
      @media (max-width: 1080px) {
        .dw-nav { padding: 16px 24px !important; }
        .dw-strip { padding: 16px 24px !important; gap: 16px !important; flex-wrap: wrap !important; row-gap: 8px !important; }
        .dw-sec-head { padding: 80px 24px 40px !important; }
        .dw-sec-head h2 { font-size: clamp(40px, 7vw, 80px) !important; }
        .dw-spread-content { padding: 96px 24px !important; max-width: 100% !important; }
        .dw-spread-content h2 { font-size: clamp(40px, 7vw, 72px) !important; }
        .dw-overwatch { padding: 64px 24px 80px !important; }
        .dw-overwatch-grid { grid-template-columns: 1fr !important; gap: 48px !important; }
        .dw-overwatch h2 { font-size: clamp(36px, 6vw, 56px) !important; }
        .dw-consumer-content { padding: 140px 24px 72px !important; }
        .dw-consumer-h2 { font-size: clamp(72px, 14vw, 140px) !important; }
        .dw-prow-grid { grid-template-columns: 1fr !important; gap: 56px !important; padding: 80px 24px !important; min-height: 0 !important; }
        .dw-prow { min-height: 0 !important; }
        .dw-prow-h3 { font-size: clamp(56px, 10vw, 80px) !important; }
        .dw-contact { padding: 80px 24px !important; }
        .dw-contact-grid { grid-template-columns: 1fr !important; gap: 40px !important; }
        .dw-contact-h2 { font-size: clamp(40px, 7vw, 72px) !important; }
        .dw-footer { padding: 40px 24px !important; }
      }

      /* Phone, <=760px: hide HUD overlays, hide secondary nav links in favor of
         a compact Contact pill, collapse all multi-column grids, shrink type. */
      @media (max-width: 760px) {
        .dw-nav { padding: 12px 16px !important; }
        .dw-nav-inner { gap: 0 !important; }
        .dw-nav-links { display: none !important; }
        .dw-nav-cta { display: inline-block !important; }
        .dw-nav-logo img { height: 32px !important; }

        /* Hero: drop the fixed 880px height, hide the 4 absolutely-positioned
           HUD overlays (they would land on text), shrink the headline. */
        .dw-hero { height: auto !important; min-height: 88vh !important; }
        .dw-hud { display: none !important; }
        .dw-hero-content { padding: 24px 16px 40px !important; gap: 32px !important; }
        .dw-hero-stamps { flex-direction: column !important; gap: 12px !important; }
        .dw-hero-stamps > * { text-align: left !important; }
        .dw-hero-kicker { font-size: 10px !important; }
        .dw-hero-h1 { font-size: clamp(56px, 16vw, 96px) !important; line-height: 1 !important; }
        .dw-hero-sub { font-size: 16px !important; margin-top: 20px !important; }

        .dw-strip { padding: 12px 16px !important; gap: 10px 14px !important; font-size: 10px !important; justify-content: flex-start !important; }

        .dw-sec-head { padding: 64px 16px 32px !important; }
        .dw-sec-head h2 { font-size: clamp(32px, 9vw, 56px) !important; }
        .dw-sec-head p { font-size: 16px !important; margin-top: 20px !important; }

        .dw-spread-content { padding: 72px 16px !important; text-align: left !important; }
        .dw-spread-content h2 { font-size: clamp(32px, 10vw, 56px) !important; text-align: left !important; }
        .dw-spread-content p { margin-left: 0 !important; text-align: left !important; }
        .dw-spread-grid { grid-template-columns: 1fr !important; gap: 24px !important; max-width: 100% !important; margin-left: 0 !important; }

        .dw-overwatch { padding: 48px 16px 64px !important; }
        .dw-overwatch h2 { font-size: clamp(28px, 9vw, 48px) !important; }
        .dw-overwatch p { font-size: 15px !important; }
        .dw-overwatch-features { grid-template-columns: 1fr 1fr !important; gap: 16px !important; max-width: 100% !important; }

        .dw-consumer-content { padding: 96px 16px 56px !important; }
        .dw-consumer-h2 { font-size: clamp(56px, 18vw, 104px) !important; }
        .dw-consumer-content p { font-size: 16px !important; margin-top: 24px !important; }

        .dw-prow-grid { padding: 64px 16px !important; gap: 40px !important; }
        .dw-prow-h3 { font-size: clamp(44px, 13vw, 72px) !important; }
        .dw-prow p { font-size: 16px !important; }
        .dw-prow-features { grid-template-columns: 1fr 1fr !important; gap: 16px 20px !important; }
        /* Drop the staggered tilt and hide the secondary phones, keep one. */
        .dw-prow-phones { transform: none !important; }
        .dw-prow-phones > div { transform: none !important; }
        .dw-prow-phone-secondary { display: none !important; }

        .dw-contact { padding: 64px 16px !important; }
        .dw-contact-h2 { font-size: clamp(32px, 10vw, 56px) !important; }
        .dw-contact p { font-size: 16px !important; }

        .dw-footer { padding: 32px 16px !important; }
        .dw-footer > div { flex-direction: column !important; gap: 16px !important; text-align: center; }
      }
    `}</style>
  );
}

function DeepWater() {
  return (
    <div style={dwStyles.root}>
      <DWResponsiveStyles />
      <DWNav />
      <DWHero />
      <DWStrip />

      <DWSectionHead
        id="platform"
        kicker="THE PLATFORM"
        title={<>One operating picture for <em style={{ fontStyle: 'italic', fontWeight: 400, color: DW_CYAN }}>a complex global environment.</em></>}
        eyebrow="A custom-built geospatial system that fuses sensors, maps the operating environment, and runs the mission from one screen."
      />
      <DWFeatureSpread />
      <DWPlatformShowcase />

      <DWConsumerHeader />
      <DWProductRow
        idx={1} name="MarNAV" kicker="ON THE WATER · iOS"
        blurb="Anchor Alert™, lightning alerts, live tides, and modern charts, for the sailor who treats their boat like an instrument."
        features={[
          { k: 'ALERTS', t: 'Anchor Alert™ · lightning' },
          { k: 'TIDES', t: 'Live NOAA station data' },
          { k: 'WX', t: 'Radar overlays' },
          { k: 'CHARTS', t: 'Custom Vector Charts' },
        ]}
        photoSrc="assets/marnav-3d-chart.jpg"
        photoSrc2="assets/marnav-sea-conditions.jpg"
        photoSrc3="assets/marnav-buoy.jpg"
        ambient="assets/anchored-fleet-aerial.jpeg"
        accent={DW_BRAND2}
        photoSide="right"
        cta={{ label: 'APP STORE ↗', href: 'https://apps.apple.com/us/app/onnav-marine/id1557830177' }}
      />
      <DWProductRow
        idx={2} name="SARtac" kicker="SEARCH & RESCUE · iOS"
        blurb="Tactical search-and-rescue coordination. Off-grid mesh comms, TAK interoperability, real-time PTT, encrypted messaging, one app, field-ready."
        features={[
          { k: 'COMMS', t: 'Meshtastic LoRa' },
          { k: 'INTEROP', t: 'Cursor on Target' },
          { k: 'VOICE', t: 'Real-time PTT' },
          { k: 'MISSION', t: 'Search patterns' },
        ]}
        photoSrc="assets/sartac-screenshot.jpg"
        photoSrc2="assets/sartac-comms.jpg"
        ambient="assets/sar-team.jpeg"
        accent={DW_AMBER}
        photoSide="left"
        cta={{ label: 'PRIVATE BETA · REQUEST ACCESS', href: '#contact' }}
      />
      <DWProductRow
        idx={3} name="SAIL LINK" kicker="SAILING INSTRUMENTS · iOS"
        blurb="Your iPhone becomes the tactical display. Bluetooth and WiFi to wind, GPS, and Signal K. Polar performance and trip recording, the way race nav should feel."
        features={[
          { k: 'BLUETOOTH', t: 'Calypso · RaceBox' },
          { k: 'NETWORKS', t: 'Signal K · NMEA 0183' },
          { k: 'POLARS', t: 'Multi-boat library' },
          { k: 'TRIPS', t: 'GPX export · playback' },
        ]}
        photoSrc="assets/saillink-screenshot.jpg"
        photoSrc2="assets/saillink-trip.jpg"
        ambient="assets/hero-sailboat-aerial.jpeg"
        accent={DW_CYAN}
        photoSide="right"
        cta={{ label: 'APP STORE ↗', href: 'https://apps.apple.com/us/app/onnav-saillink/id6759585299' }}
      />

      <DWContact />
      <DWFooter />
    </div>
  );
}

window.DeepWater = DeepWater;
