# #045 — Heliophysics Space Weather

> Amber-on-obsidian solar telemetry rack featuring NOAA R/S/G storm scales, Kp-index gauges, and X-ray flux trace.

## Metadata

- **Index**: #045
- **Slug**: `heliophysics-space-weather`
- **Kind**: `style`
- **Family**: Telemetry & Scientific
- **Theme**: `dark`
- **Mobile Strength**: `high`
- **Tags**: `space-weather`, `telemetry`, `amber-dark`, `scientific`, `dashboard`, `solar`
- **Best For**: Aerospace, satellite operations, and orbital telemetry dashboards, Observatory and radio-propagation status monitors, Mission-control alerting consoles
- **Real-World Inspiration**: [NOAA Space Weather Prediction Center](https://www.swpc.noaa.gov/)
- **Detail Page**: https://templates.michaelpitts.net/t/heliophysics-space-weather
- **Live Demo**: https://templates.michaelpitts.net/demos/heliophysics-space-weather.html
- **JSON API**: https://templates.michaelpitts.net/api/templates/heliophysics-space-weather

## Why This Aesthetic Is Unique

Translates mission-critical solar observatory racks into a clean dark amber-phosphor interface with crisp categorical storm badges instead of generic neon cyberpunk tropes.

## Color Palette

| Role | Name | Hex |
|------|------|-----|
| `canvas` | Coronal Night | `#0B0E14` |
| `surface` | Instrument Rack | `#141923` |
| `ink` | Phosphor Ivory | `#EFECE6` |
| `accent` | Solar Amber | `#F5A623` |
| `muted` | Telemetry Gray | `#7B8596` |

## Typography

- **Display**: `Space Grotesk`
- **Body**: `IBM Plex Sans`
- **Mono**: `IBM Plex Mono`
- **Scale Notes**: High-legibility R/S/G scale codes (24-30px mono) paired with 11-12px uppercase instrument labels and 14px operational bulletins.
- **Google Fonts**: https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap
  ```html
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap">
  ```

## Layout Architecture

Modular instrument rack grid: top R/S/G storm scale strip, 3-hour Planetary Kp-index bar chart, live Canvas GOES X-ray flux plot, and SVG auroral oval monitor.

## Interaction & Micro-Motion Rules

Switch between 24h, 72h, and 7-day solar windows, filter active space-weather alerts by category (Radio, Radiation, Geomagnetic), and inspect Kp-index bars.

## Mobile & Responsive Rules

R/S/G badges arrange into a compact 3-column strip and instrument panels stack cleanly with full-width responsive Canvas/SVG plots at 390px.

## Agent Guardrails

### DO
- Use standardized scale indicators (R1-R5, S1-S5, G1-G5) with clear severity color coding
- Maintain strong contrast between amber/ivory telemetry and deep obsidian instrument panels
- Label every axis with physical units (W/m², nT, km/s, UTC)

### DON'T
- Do not use glowing sci-fi HUD clichés or unreadable translucent text over busy stars
- Do not omit timestamps or cadence metadata on live telemetry plots

## Complete Standalone Starter Code

File: `demos/heliophysics-space-weather.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>SWPC // Heliophysics &amp; Geomagnetic Storm Operations</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
  <style>
    :root {
      --canvas: #0B0E14;
      --surface: #141923;
      --surface-alt: #1A2130;
      --ink: #EFECE6;
      --accent: #F5A623;
      --accent-soft: rgba(245, 166, 35, 0.14);
      --muted: #7B8596;
      --border: rgba(239, 236, 230, 0.11);
      --ok: #34D399;
      --warn: #F5A623;
      --severe: #EF4444;
      --sans: 'Space Grotesk', system-ui, -apple-system, sans-serif;
      --mono: 'IBM Plex Mono', ui-monospace, monospace;
    }

    *, *::before, *::after {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      background: var(--canvas);
      color: var(--ink);
      font-family: var(--sans);
      line-height: 1.5;
      overflow-x: hidden;
    }

    /* Top Command Header */
    .cmd-header {
      background: #0F131C;
      border-bottom: 1px solid var(--border);
      position: sticky;
      top: 0;
      z-index: 30;
    }

    .cmd-inner {
      max-width: 1320px;
      margin: 0 auto;
      padding: 0 20px;
      min-height: 58px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 14px;
    }

    .cmd-brand {
      display: flex;
      align-items: center;
      gap: 11px;
      font-weight: 700;
      font-size: 0.94rem;
      letter-spacing: 0.08em;
      text-transform: uppercase;
    }

    .solar-emblem {
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background: var(--accent);
      box-shadow: 0 0 12px rgba(245, 166, 35, 0.75);
      flex-shrink: 0;
    }

    .cmd-nav {
      display: flex;
      align-items: center;
      gap: 20px;
      font-family: var(--mono);
      font-size: 0.76rem;
    }

    .cmd-nav a {
      color: var(--muted);
      text-decoration: none;
      letter-spacing: 0.04em;
    }

    .cmd-nav a:hover {
      color: var(--accent);
    }

    .cmd-utc {
      font-family: var(--mono);
      font-size: 0.74rem;
      color: var(--accent);
      background: var(--accent-soft);
      border: 1px solid rgba(245, 166, 35, 0.35);
      padding: 4px 10px;
      border-radius: 4px;
    }

    .mobile-menu-btn {
      display: none;
      min-width: 44px;
      min-height: 44px;
      padding: 0 12px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 5px;
      color: var(--ink);
      font-family: var(--mono);
      font-size: 0.76rem;
      cursor: pointer;
    }

    .mobile-nav {
      display: none;
      background: var(--surface);
      border-top: 1px solid var(--border);
      padding: 8px 20px 14px;
    }

    .mobile-nav.open {
      display: block;
    }

    .mobile-nav a {
      display: flex;
      align-items: center;
      min-height: 44px;
      color: var(--ink);
      text-decoration: none;
      font-family: var(--mono);
      font-size: 0.82rem;
      border-bottom: 1px solid var(--border);
    }

    /* Main Workspace */
    .ops-shell {
      max-width: 1320px;
      margin: 0 auto;
      padding: 20px;
      display: flex;
      flex-direction: column;
      gap: 18px;
    }

    /* NOAA R / S / G Scale Strip */
    .scales-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 14px;
    }

    .scale-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 16px 18px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 14px;
    }

    .scale-badge {
      width: 62px;
      height: 62px;
      border-radius: 8px;
      display: grid;
      place-items: center;
      font-family: var(--mono);
      font-size: 1.45rem;
      font-weight: 700;
      flex-shrink: 0;
    }

    .badge-r {
      background: rgba(245, 166, 35, 0.16);
      border: 1px solid var(--warn);
      color: var(--warn);
    }

    .badge-s {
      background: rgba(52, 211, 153, 0.14);
      border: 1px solid var(--ok);
      color: var(--ok);
    }

    .badge-g {
      background: rgba(239, 68, 68, 0.18);
      border: 1px solid var(--severe);
      color: #FCA5A5;
    }

    .scale-info h2 {
      margin: 0 0 3px;
      font-size: 0.96rem;
      font-weight: 600;
    }

    .scale-info p {
      margin: 0;
      font-size: 0.8rem;
      color: var(--muted);
    }

    .scale-meta {
      margin-top: 6px;
      font-family: var(--mono);
      font-size: 0.72rem;
      color: var(--ink);
    }

    /* Telemetry Grid */
    .telemetry-grid {
      display: grid;
      grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
      gap: 18px;
    }

    .panel {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      overflow: hidden;
    }

    .panel-head {
      padding: 13px 16px;
      border-bottom: 1px solid var(--border);
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      background: rgba(255, 255, 255, 0.02);
    }

    .panel-title {
      font-family: var(--mono);
      font-size: 0.78rem;
      font-weight: 600;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: var(--ink);
    }

    .panel-tag {
      font-family: var(--mono);
      font-size: 0.72rem;
      color: var(--accent);
    }

    .panel-body {
      padding: 16px;
    }

    /* Interactive 3-Hour Kp Bar Chart */
    .kp-chart {
      display: grid;
      grid-template-columns: repeat(8, minmax(0, 1fr));
      gap: 8px;
      align-items: end;
      height: 188px;
      padding: 12px 6px 6px;
      background: #0E121A;
      border: 1px solid var(--border);
      border-radius: 6px;
    }

    .kp-col {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-end;
      height: 100%;
      gap: 6px;
      background: transparent;
      border: none;
      padding: 0;
      cursor: pointer;
      color: var(--muted);
    }

    .kp-bar {
      width: 100%;
      max-width: 44px;
      border-radius: 4px 4px 1px 1px;
      transition: transform 0.15s, filter 0.15s;
    }

    .kp-col.selected .kp-bar, .kp-col:hover .kp-bar {
      filter: brightness(1.2);
      outline: 2px solid var(--ink);
    }

    .kp-val {
      font-family: var(--mono);
      font-size: 0.72rem;
      font-weight: 600;
      color: var(--ink);
    }

    .kp-time {
      font-family: var(--mono);
      font-size: 0.64rem;
      color: var(--muted);
    }

    .kp-readout {
      margin-top: 12px;
      padding: 10px 12px;
      background: #0E121A;
      border: 1px solid var(--border);
      border-radius: 6px;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      gap: 8px;
      font-family: var(--mono);
      font-size: 0.76rem;
    }

    /* Live Solar X-Ray Flux Canvas */
    #xrayCanvas {
      width: 100%;
      height: 175px;
      display: block;
      background: #0E121A;
      border: 1px solid var(--border);
      border-radius: 6px;
    }

    /* Auroral Oval SVG */
    .hemi-toggle {
      display: inline-flex;
      gap: 6px;
    }

    .mini-btn {
      min-height: 36px;
      padding: 0 11px;
      border-radius: 5px;
      border: 1px solid var(--border);
      background: #0E121A;
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.72rem;
      cursor: pointer;
    }

    .mini-btn.active {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-soft);
    }

    #auroraSvg {
      width: 100%;
      max-width: 340px;
      margin: 0 auto;
      display: block;
    }

    .aurora-stats {
      margin-top: 12px;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 8px;
      font-family: var(--mono);
      font-size: 0.74rem;
    }

    .stat-tile {
      background: #0E121A;
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 9px 11px;
    }

    .stat-tile span {
      display: block;
      font-size: 0.64rem;
      color: var(--muted);
      margin-bottom: 2px;
    }

    /* Alert Feed & Tabs */
    .alert-tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .tab-btn {
      min-height: 44px;
      padding: 0 13px;
      border-radius: 6px;
      border: 1px solid var(--border);
      background: #0E121A;
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.74rem;
      cursor: pointer;
    }

    .tab-btn.active {
      background: var(--accent-soft);
      border-color: var(--accent);
      color: var(--accent);
    }

    .alert-list {
      list-style: none;
      margin: 0;
      padding: 0;
      display: grid;
      gap: 10px;
    }

    .alert-item {
      background: #0E121A;
      border: 1px solid var(--border);
      border-left: 3px solid var(--accent);
      border-radius: 6px;
      padding: 12px 14px;
    }

    .alert-item.severe {
      border-left-color: var(--severe);
    }

    .alert-top {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      gap: 6px;
      font-family: var(--mono);
      font-size: 0.72rem;
      color: var(--accent);
      margin-bottom: 4px;
    }

    .alert-item.severe .alert-top {
      color: #FCA5A5;
    }

    .alert-msg {
      font-size: 0.86rem;
      color: var(--ink);
      margin: 0;
    }

    @media (max-width: 960px) {
      .scales-grid {
        grid-template-columns: 1fr;
      }

      .telemetry-grid {
        grid-template-columns: 1fr;
      }

      .cmd-nav, .cmd-utc {
        display: none;
      }

      .mobile-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
      }

      .mini-btn {
        min-height: 44px;
      }

      .ops-shell {
        padding: 14px;
      }
    }
  </style>
</head>
<body>
  <header class="cmd-header">
    <div class="cmd-inner">
      <div class="cmd-brand">
        <span class="solar-emblem" aria-hidden="true"></span>
        <span>SWPC // HELIOPHYSICS OPS</span>
      </div>
      <nav class="cmd-nav" aria-label="Space weather sections">
        <a href="#scales">NOAA Scales</a>
        <a href="#kpSection">Kp Index</a>
        <a href="#xraySection">GOES X-Ray</a>
        <a href="#alertsSection">Alerts</a>
      </nav>
      <span class="cmd-utc">DSCOVR L1 · 548 KM/S · Bz −11.4 nT</span>
      <button class="mobile-menu-btn" id="navToggle" type="button" aria-expanded="false" aria-controls="mobileNav">MENU</button>
    </div>
    <nav class="mobile-nav" id="mobileNav" aria-label="Mobile navigation">
      <a href="#scales">NOAA R / S / G Scales</a>
      <a href="#kpSection">3-Hour Planetary Kp Index</a>
      <a href="#xraySection">GOES-18 Solar X-Ray Flux</a>
      <a href="#alertsSection">Space Weather Bulletins</a>
    </nav>
  </header>

  <main class="ops-shell">
    <section class="scales-grid" id="scales" aria-label="NOAA Space Weather Scales">
      <article class="scale-card">
        <div class="scale-info">
          <h2>Radio Blackout</h2>
          <p>Moderate HF degradation on sunlit hemisphere</p>
          <div class="scale-meta">PEAK: M6.8 FLARE · REGION AR3912</div>
        </div>
        <div class="scale-badge badge-r" aria-label="Radio Blackout Scale R2">R2</div>
      </article>

      <article class="scale-card">
        <div class="scale-info">
          <h2>Solar Radiation Storm</h2>
          <p>Minor polar cap HF attenuation (&ge;10 MeV)</p>
          <div class="scale-meta">PROTON FLUX: 14 pfu · NOMINAL</div>
        </div>
        <div class="scale-badge badge-s" aria-label="Solar Radiation Scale S1">S1</div>
      </article>

      <article class="scale-card">
        <div class="scale-info">
          <h2>Geomagnetic Storm</h2>
          <p>Strong CME sheath impact · Aurora to 50° mag lat</p>
          <div class="scale-meta">CURRENT Kp = 7.0 · WARNING ACTIVE</div>
        </div>
        <div class="scale-badge badge-g" aria-label="Geomagnetic Storm Scale G3">G3</div>
      </article>
    </section>

    <section class="telemetry-grid">
      <div style="display:flex;flex-direction:column;gap:18px;">
        <article class="panel" id="kpSection">
          <div class="panel-head">
            <span class="panel-title">Planetary 3-Hour Kp Index (24h Synoptic)</span>
            <span class="panel-tag">STORM THRESHOLD: Kp &ge; 5</span>
          </div>
          <div class="panel-body">
            <div class="kp-chart" id="kpChart" role="group" aria-label="3-hour Kp index bars"></div>
            <div class="kp-readout" aria-live="polite">
              <span id="kpSlotText">WINDOW: 03:00–06:00 UTC</span>
              <span id="kpStatusText" style="color:#FCA5A5">Kp 7.0 — G3 STRONG STORM</span>
            </div>
          </div>
        </article>

        <article class="panel" id="xraySection">
          <div class="panel-head">
            <span class="panel-title">GOES-18 Solar X-Ray Flux (0.1–0.8 nm)</span>
            <span class="panel-tag" id="fluxReadout">LIVE: M4.2 (4.2×10⁻⁵ W/m²)</span>
          </div>
          <div class="panel-body">
            <canvas id="xrayCanvas" width="740" height="175" aria-label="Live GOES-18 solar X-ray flux logarithmic trace"></canvas>
          </div>
        </article>
      </div>

      <article class="panel" aria-label="OVATION Auroral Oval Forecast">
        <div class="panel-head">
          <span class="panel-title">OVATION Auroral Oval</span>
          <div class="hemi-toggle" role="group" aria-label="Hemisphere selector">
            <button class="mini-btn active" type="button" data-hemi="north">NORTH</button>
            <button class="mini-btn" type="button" data-hemi="south">SOUTH</button>
          </div>
        </div>
        <div class="panel-body">
          <svg id="auroraSvg" viewBox="0 0 320 320" role="img" aria-label="Polar projection showing auroral oval expansion"></svg>
          <div class="aurora-stats">
            <div class="stat-tile">
              <span>HEMISPHERIC POWER</span>
              <strong id="hemiPower">148 GW</strong>
            </div>
            <div class="stat-tile">
              <span>EQUATORWARD BOUND</span>
              <strong id="auroraLat">51.4° MAG LAT</strong>
            </div>
            <div class="stat-tile">
              <span>IMF Bz (GSM)</span>
              <strong>−11.4 nT</strong>
            </div>
            <div class="stat-tile">
              <span>SOLAR WIND SPEED</span>
              <strong>548 km/s</strong>
            </div>
          </div>
        </div>
      </article>
    </section>

    <section class="panel" id="alertsSection" aria-label="Space weather alerts and bulletins">
      <div class="panel-head">
        <span class="panel-title">Active Space Weather Bulletins</span>
        <div class="alert-tabs" role="tablist" aria-label="Filter bulletins by category">
          <button class="tab-btn active" type="button" data-cat="all">ALL</button>
          <button class="tab-btn" type="button" data-cat="geo">GEOMAGNETIC</button>
          <button class="tab-btn" type="button" data-cat="xray">SOLAR X-RAY</button>
          <button class="tab-btn" type="button" data-cat="proton">PROTON FLUX</button>
        </div>
      </div>
      <div class="panel-body">
        <ul class="alert-list" id="alertList"></ul>
      </div>
    </section>
  </main>

  <script>
    (() => {
      const KP_DATA = [
        { slot: '06–09 UTC', kp: 3.3, label: 'UNSETTLED (G0)' },
        { slot: '09–12 UTC', kp: 4.0, label: 'ACTIVE (G0)' },
        { slot: '12–15 UTC', kp: 4.7, label: 'ACTIVE (G0)' },
        { slot: '15–18 UTC', kp: 5.3, label: 'G1 MINOR STORM' },
        { slot: '18–21 UTC', kp: 6.0, label: 'G2 MODERATE STORM' },
        { slot: '21–00 UTC', kp: 6.7, label: 'G3 STRONG STORM' },
        { slot: '00–03 UTC', kp: 6.3, label: 'G2 MODERATE STORM' },
        { slot: '03–06 UTC', kp: 7.0, label: 'G3 STRONG STORM' }
      ];

      const ALERTS = [
        { cat: 'geo', severe: true, code: 'ALTK07', time: '04:58 UTC', text: 'ALERT: Geomagnetic K-index of 7 threshold reached (G3 Strong). High-latitude power grid voltage corrections and HF radio intermittency expected.' },
        { cat: 'xray', severe: false, code: 'SUMX01', time: '03:41 UTC', text: 'SUMMARY: M6.8 Solar X-ray flare observed from Active Region 3912 (N14W22). Type II radio sweep at 920 km/s indicates associated halo CME.' },
        { cat: 'proton', severe: false, code: 'ALTPX1', time: '02:15 UTC', text: 'CONTINUED ALERT: Proton Event 10 MeV integral flux exceeded 10 pfu (S1 Minor). Polar aviation HF paths experiencing minor D-region absorption.' },
        { cat: 'geo', severe: true, code: 'WARK06', time: '01:20 UTC', text: 'EXTENDED WARNING: Sustained southward IMF Bz (−11 nT) at L1 supports G2–G3 geomagnetic storming through 12:00 UTC.' }
      ];

      let selectedKpIdx = 7;
      let hemisphere = 'north';
      let activeCat = 'all';

      const kpChart = document.getElementById('kpChart');
      const kpSlotText = document.getElementById('kpSlotText');
      const kpStatusText = document.getElementById('kpStatusText');
      const auroraSvg = document.getElementById('auroraSvg');
      const alertList = document.getElementById('alertList');

      function kpColor(kp) {
        if (kp >= 6.5) return '#EF4444';
        if (kp >= 5.0) return '#F5A623';
        if (kp >= 4.0) return '#EAB308';
        return '#34D399';
      }

      function renderKp() {
        kpChart.innerHTML = '';
        KP_DATA.forEach((d, idx) => {
          const btn = document.createElement('button');
          btn.type = 'button';
          btn.className = `kp-col${idx === selectedKpIdx ? ' selected' : ''}`;
          const pct = Math.round((d.kp / 9) * 100);
          btn.innerHTML = `
            <span class="kp-val">${d.kp.toFixed(1)}</span>
            <span class="kp-bar" style="height:${pct}%;background:${kpColor(d.kp)}"></span>
            <span class="kp-time">${d.slot.slice(0, 5)}</span>`;
          btn.addEventListener('click', () => {
            selectedKpIdx = idx;
            renderKp();
            renderAurora();
          });
          kpChart.appendChild(btn);
        });

        const cur = KP_DATA[selectedKpIdx];
        kpSlotText.textContent = `WINDOW: ${cur.slot}`;
        kpStatusText.textContent = `Kp ${cur.kp.toFixed(1)} — ${cur.label}`;
        kpStatusText.style.color = kpColor(cur.kp);
        document.getElementById('hemiPower').textContent = `${Math.round(35 + cur.kp * 16)} GW`;
        document.getElementById('auroraLat').textContent = `${(67 - cur.kp * 2.2).toFixed(1)}° MAG LAT`;
      }

      function renderAurora() {
        const cur = KP_DATA[selectedKpIdx];
        const ns = 'http://www.w3.org/2000/svg';
        auroraSvg.innerHTML = '';

        // Polar globe background
        const globe = document.createElementNS(ns, 'circle');
        globe.setAttribute('cx', 160);
        globe.setAttribute('cy', 160);
        globe.setAttribute('r', 136);
        globe.setAttribute('fill', '#0D131E');
        globe.setAttribute('stroke', 'rgba(239,236,230,0.18)');
        globe.setAttribute('stroke-width', '1.4');
        auroraSvg.appendChild(globe);

        // Latitude rings
        [45, 85, 118].forEach((r) => {
          const ring = document.createElementNS(ns, 'circle');
          ring.setAttribute('cx', 160);
          ring.setAttribute('cy', 160);
          ring.setAttribute('r', r);
          ring.setAttribute('fill', 'none');
          ring.setAttribute('stroke', 'rgba(239,236,230,0.08)');
          ring.setAttribute('stroke-dasharray', '3 4');
          auroraSvg.appendChild(ring);
        });

        // Auroral oval radius expands with Kp
        const ovalR = 44 + cur.kp * 8.2;
        const ovalCy = hemisphere === 'north' ? 168 : 152;
        const strokeW = 14 + cur.kp * 2.2;
        const color = cur.kp >= 6.0 ? '#EF4444' : cur.kp >= 5.0 ? '#F5A623' : '#34D399';

        const glow = document.createElementNS(ns, 'ellipse');
        glow.setAttribute('cx', 160);
        glow.setAttribute('cy', ovalCy);
        glow.setAttribute('rx', ovalR);
        glow.setAttribute('ry', ovalR * 0.88);
        glow.setAttribute('fill', 'none');
        glow.setAttribute('stroke', color);
        glow.setAttribute('stroke-opacity', '0.32');
        glow.setAttribute('stroke-width', strokeW + 10);
        auroraSvg.appendChild(glow);

        const core = document.createElementNS(ns, 'ellipse');
        core.setAttribute('cx', 160);
        core.setAttribute('cy', ovalCy);
        core.setAttribute('rx', ovalR);
        core.setAttribute('ry', ovalR * 0.88);
        core.setAttribute('fill', 'none');
        core.setAttribute('stroke', cur.kp >= 6 ? '#F5A623' : '#34D399');
        core.setAttribute('stroke-opacity', '0.82');
        core.setAttribute('stroke-width', strokeW * 0.45);
        auroraSvg.appendChild(core);

        const poleLabel = document.createElementNS(ns, 'text');
        poleLabel.setAttribute('x', 160);
        poleLabel.setAttribute('y', 164);
        poleLabel.setAttribute('text-anchor', 'middle');
        poleLabel.setAttribute('fill', '#EFECE6');
        poleLabel.setAttribute('font-family', 'IBM Plex Mono, monospace');
        poleLabel.setAttribute('font-size', '11');
        poleLabel.textContent = hemisphere === 'north' ? 'N MAG POLE' : 'S MAG POLE';
        auroraSvg.appendChild(poleLabel);
      }

      function renderAlerts() {
        const filtered = activeCat === 'all' ? ALERTS : ALERTS.filter((a) => a.cat === activeCat);
        alertList.innerHTML = filtered
          .map(
            (a) => `
          <li class="alert-item${a.severe ? ' severe' : ''}">
            <div class="alert-top">
              <span>${a.code} · ${a.cat.toUpperCase()}</span>
              <span>${a.time}</span>
            </div>
            <p class="alert-msg">${a.text}</p>
          </li>`
          )
          .join('');
      }

      // Live Solar X-Ray Flux Canvas
      const xCanvas = document.getElementById('xrayCanvas');
      const xctx = xCanvas.getContext('2d');
      const fluxSeries = Array.from({ length: 180 }, (_, i) => {
        const flare = Math.exp(-Math.pow((i - 125) / 18, 2)) * 1.9;
        return -5.8 + flare + Math.sin(i * 0.14) * 0.12;
      });
      let tStep = 0;

      function animateXray() {
        tStep += 0.08;
        const flarePulse = Math.exp(-Math.pow(((tStep % 22) - 14) / 2.8, 2)) * 1.4;
        const nextLog = -5.6 + flarePulse + Math.sin(tStep * 1.3) * 0.12 + (Math.random() - 0.5) * 0.06;
        fluxSeries.shift();
        fluxSeries.push(nextLog);

        const w = xCanvas.width;
        const h = xCanvas.height;
        xctx.fillStyle = '#0E121A';
        xctx.fillRect(0, 0, w, h);

        // Flare classification bands (X, M, C, B)
        const bands = [
          { label: 'X', log: -4, color: 'rgba(239,68,68,0.22)' },
          { label: 'M', log: -5, color: 'rgba(245,166,35,0.22)' },
          { label: 'C', log: -6, color: 'rgba(239,236,230,0.12)' },
          { label: 'B', log: -7, color: 'rgba(239,236,230,0.08)' }
        ];

        const logToY = (lv) => {
          const norm = (lv - -7.5) / (-3.2 - -7.5);
          return h - 18 - norm * (h - 32);
        };

        xctx.font = '11px IBM Plex Mono, monospace';
        bands.forEach((b) => {
          const y = logToY(b.log);
          xctx.strokeStyle = b.color;
          xctx.lineWidth = 1;
          xctx.beginPath();
          xctx.moveTo(34, y);
          xctx.lineTo(w - 10, y);
          xctx.stroke();
          xctx.fillStyle = '#7B8596';
          xctx.fillText(b.label, 12, y + 4);
        });

        // Trace line
        xctx.beginPath();
        xctx.strokeStyle = '#F5A623';
        xctx.lineWidth = 2;
        fluxSeries.forEach((lv, i) => {
          const x = 34 + (i / (fluxSeries.length - 1)) * (w - 44);
          const y = Math.max(10, Math.min(h - 14, logToY(lv)));
          if (i === 0) xctx.moveTo(x, y);
          else xctx.lineTo(x, y);
        });
        xctx.stroke();

        const latest = fluxSeries[fluxSeries.length - 1];
        const cls = latest >= -4 ? 'X' : latest >= -5 ? 'M' : latest >= -6 ? 'C' : 'B';
        const mantissa = Math.pow(10, latest - Math.floor(latest)).toFixed(1);
        document.getElementById('fluxReadout').textContent = `LIVE: ${cls}${mantissa} (10^${latest.toFixed(1)} W/m²)`;

        setTimeout(() => requestAnimationFrame(animateXray), 140);
      }

      document.querySelectorAll('[data-hemi]').forEach((btn) => {
        btn.addEventListener('click', () => {
          document.querySelectorAll('[data-hemi]').forEach((b) => b.classList.remove('active'));
          btn.classList.add('active');
          hemisphere = btn.dataset.hemi;
          renderAurora();
        });
      });

      document.querySelectorAll('[data-cat]').forEach((btn) => {
        btn.addEventListener('click', () => {
          document.querySelectorAll('[data-cat]').forEach((b) => b.classList.remove('active'));
          btn.classList.add('active');
          activeCat = btn.dataset.cat;
          renderAlerts();
        });
      });

      const navToggle = document.getElementById('navToggle');
      const mobileNav = document.getElementById('mobileNav');
      navToggle.addEventListener('click', () => {
        const open = mobileNav.classList.toggle('open');
        navToggle.setAttribute('aria-expanded', String(open));
      });

      renderKp();
      renderAurora();
      renderAlerts();
      animateXray();
    })();
  </script>
</body>
</html>
```
