#049 style light mobile: high Scientific & Financial Data

Macroeconomic Ledger Series

Archival central-bank time-series ledger with shaded NBER recession bands, unit transforms, and horizon presets.

Inspired by U.S. Treasury Fiscal Data ↗

Download .html
Fullscreen ↗

WHY THIS AESTHETIC IS UNIQUE

Brings institutional gravitas to economic data through warm ledger-paper surfaces, iconic gray vertical recession-band shading, and frictionless frequency/unit transformations.

BEST FOR

Macroeconomic and central-bank data portalsFinancial research and treasury yield explorersLong-horizon statistical archives

TAGS

COLOR PALETTE (CLICK TO COPY HEX)

TYPOGRAPHY

Display
Source Serif 4
Body
IBM Plex Sans
Mono
IBM Plex Mono
Scale
Authoritative serif series titles with uppercase monospace series IDs (e.g. CPIAUCSL, DGS10) and tabular observation readouts.

Google Fonts Stylesheet ↗

ARCHITECTURE & MOBILE NOTES

LAYOUT

Series selector strip above a spacious white chart sheet featuring shaded recession intervals, horizon preset pills (1Y, 5Y, 10Y, MAX), unit transform switcher, and observation metadata footer.

INTERACTION

Switch between macroeconomic series, toggle Index vs YoY % Change transformation, scrub or tap chart points for exact date/value readouts, and preview raw CSV rows.

MOBILE

Horizon and unit controls wrap cleanly into 44px touch pills while the SVG chart scales responsively with readable axes at 390px.

AI AGENT GUARDRAILS

DO

  • Include subtle gray vertical recession bands with a clear legend annotation
  • Display series code, seasonal adjustment, frequency, and observation units clearly
  • Format every observation value and percent change in tabular monospace

DON'T

  • Do not style an institutional statistical ledger like a crypto trading casino
  • Do not omit Y-axis units or date range indicators when transforming series
STANDALONE SOURCE · demos/macroeconomic-ledger-series.html (28.5 KB)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>MRED — Archival Macroeconomic Time-Series Ledger</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=IBM+Plex+Sans:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,600;8..60,700&display=swap" rel="stylesheet">
  <style>
    :root {
      --canvas: #F6F5F0;
      --surface: #FFFFFF;
      --ink: #17212B;
      --accent: #1B4D89;
      --accent-soft: rgba(27, 77, 137, 0.1);
      --muted: #6A7682;
      --rule: #DCE0E4;
      --rule-strong: #BFC7CF;
      --recession: #E5E8EC;
      --positive: #1F6E43;
      --negative: #A63A3A;
      --font-serif: 'Source Serif 4', Georgia, serif;
      --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
      --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
    }

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

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

    /* Institutional Masthead */
    .masthead {
      background: var(--surface);
      border-bottom: 1px solid var(--rule-strong);
      position: sticky;
      top: 0;
      z-index: 40;
    }

    .masthead-inner {
      max-width: 1240px;
      margin: 0 auto;
      padding: 0.7rem 1.25rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
    }

    .seal-brand {
      display: flex;
      align-items: center;
      gap: 0.7rem;
      text-decoration: none;
      color: var(--ink);
    }

    .seal-svg {
      width: 34px;
      height: 34px;
      flex-shrink: 0;
    }

    .seal-title {
      font-family: var(--font-serif);
      font-size: 1.18rem;
      font-weight: 700;
      letter-spacing: -0.01em;
      display: block;
      line-height: 1.1;
    }

    .seal-sub {
      font-family: var(--font-mono);
      font-size: 0.65rem;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.06em;
      display: block;
    }

    .nav-bar {
      display: flex;
      align-items: center;
      gap: 1.4rem;
    }

    .nav-bar a {
      text-decoration: none;
      color: var(--muted);
      font-size: 0.85rem;
      font-weight: 500;
      padding: 0.3rem 0;
      border-bottom: 2px solid transparent;
    }

    .nav-bar a:hover,
    .nav-bar a.active {
      color: var(--accent);
      border-bottom-color: var(--accent);
    }

    .menu-btn {
      display: none;
      align-items: center;
      justify-content: center;
      min-width: 44px;
      min-height: 44px;
      background: var(--canvas);
      border: 1px solid var(--rule-strong);
      border-radius: 4px;
      color: var(--ink);
      cursor: pointer;
    }

    .mobile-menu {
      display: none;
      background: var(--surface);
      border-top: 1px solid var(--rule);
      padding: 0.5rem 1.25rem 0.9rem;
    }

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

    .mobile-menu a {
      display: flex;
      align-items: center;
      min-height: 44px;
      text-decoration: none;
      color: var(--ink);
      font-weight: 500;
      border-bottom: 1px solid var(--rule);
    }

    .mobile-menu a:last-child {
      border-bottom: none;
    }

    /* Main Container */
    .container {
      max-width: 1240px;
      margin: 0 auto;
      padding: 1.4rem 1.25rem 3rem;
    }

    /* Series Switcher Cards */
    .series-tabs {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 0.85rem;
      margin-bottom: 1.25rem;
    }

    .series-tab {
      text-align: left;
      background: var(--surface);
      border: 1px solid var(--rule-strong);
      border-top: 3px solid transparent;
      border-radius: 4px;
      padding: 0.85rem 1rem;
      cursor: pointer;
      transition: border-color 0.15s, box-shadow 0.15s;
    }

    .series-tab:hover {
      border-color: var(--accent);
    }

    .series-tab.active {
      border-color: var(--accent);
      border-top-color: var(--accent);
      box-shadow: 0 2px 8px rgba(23, 33, 43, 0.06);
    }

    .tab-code {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      font-weight: 600;
      color: var(--accent);
      display: flex;
      justify-content: space-between;
      margin-bottom: 0.25rem;
    }

    .tab-name {
      font-weight: 600;
      font-size: 0.9rem;
      color: var(--ink);
      margin-bottom: 0.2rem;
      display: block;
    }

    .tab-latest {
      font-family: var(--font-mono);
      font-size: 0.76rem;
      color: var(--muted);
    }

    /* Primary Chart Ledger Card */
    .ledger-card {
      background: var(--surface);
      border: 1px solid var(--rule-strong);
      border-radius: 4px;
      padding: 1.25rem 1.35rem;
      box-shadow: 0 1px 4px rgba(23, 33, 43, 0.04);
    }

    .series-head {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: flex-start;
      gap: 1rem;
      padding-bottom: 1rem;
      border-bottom: 1px solid var(--rule);
      margin-bottom: 1rem;
    }

    .series-id-pill {
      display: inline-block;
      font-family: var(--font-mono);
      font-size: 0.72rem;
      font-weight: 600;
      color: var(--accent);
      background: var(--accent-soft);
      padding: 0.18rem 0.5rem;
      border-radius: 3px;
      margin-bottom: 0.35rem;
    }

    h1 {
      font-family: var(--font-serif);
      font-size: clamp(1.35rem, 2.5vw, 1.85rem);
      font-weight: 700;
      margin: 0 0 0.25rem;
      line-height: 1.2;
    }

    .series-meta-line {
      font-size: 0.8rem;
      color: var(--muted);
      margin: 0;
    }

    /* Controls Strip */
    .controls-bar {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center;
      gap: 0.75rem;
      margin-bottom: 1rem;
    }

    .btn-group {
      display: inline-flex;
      border: 1px solid var(--rule-strong);
      border-radius: 4px;
      overflow: hidden;
      background: var(--canvas);
    }

    .ctrl-btn {
      min-height: 40px;
      padding: 0 0.85rem;
      border: none;
      border-right: 1px solid var(--rule);
      background: transparent;
      color: var(--muted);
      font-family: var(--font-mono);
      font-size: 0.75rem;
      font-weight: 600;
      cursor: pointer;
    }

    .ctrl-btn:last-child {
      border-right: none;
    }

    .ctrl-btn.active {
      background: var(--accent);
      color: #FFFFFF;
    }

    .recession-check {
      display: inline-flex;
      align-items: center;
      gap: 0.45rem;
      min-height: 40px;
      font-size: 0.8rem;
      color: var(--muted);
      cursor: pointer;
      user-select: none;
    }

    .recession-swatch {
      width: 12px;
      height: 12px;
      background: var(--recession);
      border: 1px solid var(--rule-strong);
      display: inline-block;
    }

    /* Live Observation Readout Strip */
    .readout-strip {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 0.65rem;
      background: var(--canvas);
      border: 1px solid var(--rule);
      border-radius: 4px;
      padding: 0.7rem 0.85rem;
      margin-bottom: 1rem;
    }

    .ro-label {
      display: block;
      font-family: var(--font-mono);
      font-size: 0.64rem;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
    }

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

    .ro-val.accent {
      color: var(--accent);
    }

    /* Interactive SVG Chart */
    .chart-box {
      position: relative;
      width: 100%;
      border: 1px solid var(--rule);
      background: #FFFFFF;
      border-radius: 3px;
      padding: 0.5rem 0.5rem 0.25rem;
      touch-action: pan-y;
    }

    .chart-svg {
      display: block;
      width: 100%;
      height: auto;
      aspect-ratio: 16 / 7;
      cursor: crosshair;
    }

    .chart-footnote {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      gap: 0.5rem;
      margin-top: 0.75rem;
      font-size: 0.75rem;
      color: var(--muted);
    }

    /* Metadata & Statistics Ledger */
    .stats-grid {
      margin-top: 1.25rem;
      display: grid;
      grid-template-columns: 1.1fr 0.9fr;
      gap: 1rem;
    }

    .meta-panel {
      background: var(--surface);
      border: 1px solid var(--rule-strong);
      border-radius: 4px;
      padding: 1rem 1.15rem;
    }

    .meta-panel h2 {
      margin: 0 0 0.7rem;
      font-family: var(--font-mono);
      font-size: 0.76rem;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--ink);
      padding-bottom: 0.45rem;
      border-bottom: 1px solid var(--rule);
    }

    .meta-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.82rem;
    }

    .meta-table tr {
      border-bottom: 1px solid var(--rule);
    }

    .meta-table tr:last-child {
      border-bottom: none;
    }

    .meta-table th {
      text-align: left;
      padding: 0.45rem 0.5rem 0.45rem 0;
      color: var(--muted);
      font-weight: 500;
    }

    .meta-table td {
      text-align: right;
      padding: 0.45rem 0;
      font-family: var(--font-mono);
      font-weight: 600;
    }

    .cite-box {
      background: var(--canvas);
      border: 1px solid var(--rule);
      border-radius: 3px;
      padding: 0.75rem;
      font-family: var(--font-mono);
      font-size: 0.72rem;
      color: var(--ink);
      margin-bottom: 0.75rem;
    }

    .cite-btn {
      min-height: 44px;
      padding: 0 1rem;
      background: var(--accent);
      color: #FFFFFF;
      border: none;
      border-radius: 4px;
      font-family: var(--font-mono);
      font-size: 0.76rem;
      font-weight: 600;
      cursor: pointer;
    }

    @media (max-width: 900px) {
      .series-tabs {
        grid-template-columns: 1fr;
      }
      .stats-grid {
        grid-template-columns: 1fr;
      }
    }

    @media (max-width: 700px) {
      .nav-bar {
        display: none;
      }
      .menu-btn {
        display: inline-flex;
      }
      .container {
        padding: 0.9rem 0.85rem 2.5rem;
      }
      .ledger-card {
        padding: 0.9rem;
      }
      .readout-strip {
        grid-template-columns: 1fr 1fr;
      }
      .ctrl-btn {
        min-height: 44px;
        padding: 0 0.65rem;
      }
      .chart-svg {
        aspect-ratio: 4 / 3;
      }
    }
  </style>
</head>
<body>
  <header class="masthead">
    <div class="masthead-inner">
      <a href="#terminal" class="seal-brand">
        <svg class="seal-svg" viewBox="0 0 36 36" fill="none" aria-hidden="true">
          <rect x="2" y="2" width="32" height="32" rx="3" fill="#1B4D89"/>
          <path d="M8 25 L14 19 L19 22 L28 11" stroke="#FFFFFF" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
          <line x1="8" y1="28" x2="28" y2="28" stroke="#DCE0E4" stroke-width="1.2"/>
        </svg>
        <span>
          <span class="seal-title">MRED Economic Ledger</span>
          <span class="seal-sub">Archival Macroeconomic Time-Series</span>
        </span>
      </a>

      <nav class="nav-bar" aria-label="Primary">
        <a href="#terminal" class="active">Series Terminal</a>
        <a href="#summary-stats">Summary Statistics</a>
        <a href="#citation">Citation &amp; Source</a>
      </nav>

      <button class="menu-btn" id="menuBtn" type="button" aria-expanded="false" aria-controls="mobileMenu" aria-label="Toggle menu">
        <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8">
          <path d="M3 5h14M3 10h14M3 15h14"/>
        </svg>
      </button>
    </div>
    <div class="mobile-menu" id="mobileMenu">
      <a href="#terminal">Series Terminal</a>
      <a href="#summary-stats">Summary Statistics</a>
      <a href="#citation">Citation &amp; Source</a>
    </div>
  </header>

  <main class="container" id="terminal">
    <!-- Series Switcher -->
    <section class="series-tabs" role="tablist" aria-label="Macroeconomic series">
      <button class="series-tab active" type="button" data-series="CPIAUCSL">
        <span class="tab-code"><span>CPIAUCSL</span><span>Monthly · SA</span></span>
        <span class="tab-name">Consumer Price Index (All Urban)</span>
        <span class="tab-latest">Latest: 319.4 (2025 Q4)</span>
      </button>
      <button class="series-tab" type="button" data-series="DGS10">
        <span class="tab-code"><span>DGS10</span><span>Monthly Avg</span></span>
        <span class="tab-name">10-Year Treasury Constant Maturity</span>
        <span class="tab-latest">Latest: 4.28% (2025 Q4)</span>
      </button>
      <button class="series-tab" type="button" data-series="INDPRO">
        <span class="tab-code"><span>INDPRO</span><span>Index 2017=100</span></span>
        <span class="tab-name">Industrial Production: Total Index</span>
        <span class="tab-latest">Latest: 103.8 (2025 Q4)</span>
      </button>
    </section>

    <!-- Primary Time-Series Chart Card -->
    <section class="ledger-card">
      <div class="series-head">
        <div>
          <span class="series-id-pill" id="activeCode">CPIAUCSL</span>
          <h1 id="activeTitle">Consumer Price Index for All Urban Consumers: All Items</h1>
          <p class="series-meta-line" id="activeSubtitle">Units: Index 1982-1984=100, Seasonally Adjusted · Frequency: Annual/Semi-Annual Archival Observations</p>
        </div>
      </div>

      <div class="controls-bar">
        <div class="btn-group" role="group" aria-label="Observation unit">
          <button class="ctrl-btn active" type="button" data-unit="level">Index / Level</button>
          <button class="ctrl-btn" type="button" data-unit="yoy">YoY % Change</button>
        </div>

        <label class="recession-check">
          <input type="checkbox" id="toggleRecession" checked>
          <span class="recession-swatch"></span>
          <span>NBER Recession Bands</span>
        </label>

        <div class="btn-group" role="group" aria-label="Date range">
          <button class="ctrl-btn" type="button" data-range="1Y">1Y</button>
          <button class="ctrl-btn" type="button" data-range="5Y">5Y</button>
          <button class="ctrl-btn" type="button" data-range="10Y">10Y</button>
          <button class="ctrl-btn active" type="button" data-range="MAX">MAX</button>
        </div>
      </div>

      <!-- Live Hover / Tap Observation Readout -->
      <div class="readout-strip" aria-live="polite">
        <div>
          <span class="ro-label">Observation Date</span>
          <span class="ro-val" id="roDate">2025-10</span>
        </div>
        <div>
          <span class="ro-label">Observed Value</span>
          <span class="ro-val accent" id="roVal">319.40</span>
        </div>
        <div>
          <span class="ro-label">Prior Period Delta</span>
          <span class="ro-val" id="roDelta">+2.6%</span>
        </div>
        <div>
          <span class="ro-label">NBER Cycle Regime</span>
          <span class="ro-val" id="roRegime">Expansion</span>
        </div>
      </div>

      <div class="chart-box">
        <svg class="chart-svg" id="chartSvg" viewBox="0 0 880 370" role="img" aria-label="Interactive macroeconomic time-series chart with NBER recession shading"></svg>
      </div>

      <div class="chart-footnote">
        <span>Shaded gray areas indicate U.S. recessions (NBER Business Cycle Dating Committee). Hover or tap chart to inspect observations.</span>
        <span style="font-family:var(--font-mono)" id="sourceTag">Source: U.S. Bureau of Labor Statistics</span>
      </div>
    </section>

    <section class="stats-grid">
      <div class="meta-panel" id="summary-stats">
        <h2>Period Summary Statistics</h2>
        <table class="meta-table">
          <tbody>
            <tr><th>Window Observations</th><td id="statCount">26</td></tr>
            <tr><th>Period Minimum</th><td id="statMin">172.20</td></tr>
            <tr><th>Period Maximum</th><td id="statMax">319.40</td></tr>
            <tr><th>Arithmetic Mean</th><td id="statMean">236.14</td></tr>
            <tr><th>Latest Release</th><td id="statLatest">319.40 (2025-10)</td></tr>
          </tbody>
        </table>
      </div>

      <div class="meta-panel" id="citation">
        <h2>Archival Citation &amp; Provenance</h2>
        <div class="cite-box" id="citeText">
          U.S. Bureau of Labor Statistics, Consumer Price Index for All Urban Consumers [CPIAUCSL], retrieved from MRED Economic Ledger, https://mred.reserve.org/series/CPIAUCSL.
        </div>
        <button class="cite-btn" id="copyCite" type="button">Copy BibTeX / APA Citation</button>
      </div>
    </section>
  </main>

  <script>
    // Annual archival observations 2000–2025 (26 points each)
    const YEARS = Array.from({ length: 26 }, (_, i) => 2000 + i);
    const RECESSION_BANDS = [
      { start: 2001.2, end: 2001.9, label: "2001 Contraction" },
      { start: 2007.9, end: 2009.5, label: "Great Recession" },
      { start: 2020.1, end: 2020.45, label: "2020 Pandemic Shock" }
    ];

    const SERIES_DB = {
      CPIAUCSL: {
        title: "Consumer Price Index for All Urban Consumers: All Items",
        subtitle: "Units: Index 1982-1984=100, Seasonally Adjusted · Frequency: Annual Archival Ledger",
        source: "Source: U.S. Bureau of Labor Statistics",
        unitSuffix: "",
        values: [
          172.2, 177.1, 179.9, 184.0, 188.9, 195.3, 201.6, 207.3, 215.3, 214.5,
          218.1, 224.9, 229.6, 233.0, 236.7, 237.0, 240.0, 245.1, 251.1, 255.7,
          258.8, 271.0, 292.7, 304.7, 313.6, 319.4
        ]
      },
      DGS10: {
        title: "Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity",
        subtitle: "Units: Percent per Annum, Not Seasonally Adjusted · Frequency: Annual Average",
        source: "Source: Board of Governors of the Federal Reserve System (H.15)",
        unitSuffix: "%",
        values: [
          6.03, 5.02, 4.61, 4.01, 4.27, 4.29, 4.80, 4.63, 3.66, 3.26,
          3.22, 2.78, 1.80, 2.35, 2.54, 2.14, 1.84, 2.33, 2.91, 2.14,
          0.89, 1.45, 2.95, 3.96, 4.21, 4.28
        ]
      },
      INDPRO: {
        title: "Industrial Production: Total Index (Manufacturing, Mining & Utilities)",
        subtitle: "Units: Index 2017=100, Seasonally Adjusted · Frequency: Annual Archival Ledger",
        source: "Source: Board of Governors of the Federal Reserve System (G.17)",
        unitSuffix: "",
        values: [
          92.1, 89.3, 89.5, 90.7, 93.2, 96.3, 98.5, 101.0, 97.4, 86.2,
          91.0, 93.8, 96.7, 98.6, 101.6, 100.2, 98.0, 100.0, 103.2, 102.5,
          95.1, 99.2, 102.6, 102.9, 103.1, 103.8
        ]
      }
    };

    let activeSeries = "CPIAUCSL";
    let activeUnit = "level";
    let activeRange = "MAX";
    let showRecessions = true;
    let activePoints = [];
    let selectedIdx = 0;

    function computeSeriesPoints() {
      const s = SERIES_DB[activeSeries];
      let pts = YEARS.map((yr, idx) => {
        const raw = s.values[idx];
        const prev = idx > 0 ? s.values[idx - 1] : raw;
        const yoy = idx > 0 && prev !== 0 ? ((raw - prev) / prev) * 100 : 0;
        const val = activeUnit === "yoy" ? yoy : raw;
        return { year: yr, val, raw, yoy };
      });

      if (activeUnit === "yoy") pts = pts.slice(1);
      if (activeRange === "1Y") pts = pts.slice(-2);
      else if (activeRange === "5Y") pts = pts.slice(-6);
      else if (activeRange === "10Y") pts = pts.slice(-11);

      return pts;
    }

    function isRecessionYear(yr) {
      return RECESSION_BANDS.some(b => yr >= Math.floor(b.start) && yr <= Math.ceil(b.end));
    }

    function updateReadout(idx) {
      const pt = activePoints[idx];
      if (!pt) return;
      selectedIdx = idx;
      const s = SERIES_DB[activeSeries];
      const suffix = activeUnit === "yoy" ? "%" : s.unitSuffix;
      document.getElementById("roDate").textContent = `${pt.year}-10`;
      document.getElementById("roVal").textContent = `${pt.val.toFixed(2)}${suffix}`;

      const prev = idx > 0 ? activePoints[idx - 1].val : pt.val;
      const diff = pt.val - prev;
      const sign = diff >= 0 ? "+" : "";
      const deltaEl = document.getElementById("roDelta");
      deltaEl.textContent = `${sign}${diff.toFixed(2)}${suffix}`;
      deltaEl.style.color = diff >= 0 ? "var(--positive)" : "var(--negative)";

      document.getElementById("roRegime").textContent = isRecessionYear(pt.year) ? "NBER Recession" : "Expansion";

      const vline = document.getElementById("hoverLine");
      const dot = document.getElementById("hoverDot");
      if (vline && dot && pt._x !== undefined) {
        vline.setAttribute("x1", pt._x);
        vline.setAttribute("x2", pt._x);
        dot.setAttribute("cx", pt._x);
        dot.setAttribute("cy", pt._y);
      }
    }

    function renderChart() {
      const s = SERIES_DB[activeSeries];
      activePoints = computeSeriesPoints();

      document.getElementById("activeCode").textContent = activeSeries;
      document.getElementById("activeTitle").textContent = s.title;
      document.getElementById("activeSubtitle").textContent =
        activeUnit === "yoy" ? "Units: Percent Change from Year Ago (%) · Frequency: Annual Archival Ledger" : s.subtitle;
      document.getElementById("sourceTag").textContent = s.source;
      document.getElementById("citeText").textContent =
        `${s.source.replace("Source: ", "")}, ${s.title} [${activeSeries}], retrieved from MRED Economic Ledger, https://mred.reserve.org/series/${activeSeries}.`;

      // Summary stats
      const vals = activePoints.map(p => p.val);
      const minV = Math.min(...vals);
      const maxV = Math.max(...vals);
      const meanV = vals.reduce((a, b) => a + b, 0) / vals.length;
      const suffix = activeUnit === "yoy" ? "%" : s.unitSuffix;
      const latest = activePoints[activePoints.length - 1];

      document.getElementById("statCount").textContent = activePoints.length;
      document.getElementById("statMin").textContent = `${minV.toFixed(2)}${suffix}`;
      document.getElementById("statMax").textContent = `${maxV.toFixed(2)}${suffix}`;
      document.getElementById("statMean").textContent = `${meanV.toFixed(2)}${suffix}`;
      document.getElementById("statLatest").textContent = `${latest.val.toFixed(2)}${suffix} (${latest.year}-10)`;

      // SVG dimensions
      const W = 880, H = 370;
      const padL = 62, padR = 24, padT = 20, padB = 42;
      const plotW = W - padL - padR;
      const plotH = H - padT - padB;

      const minY = minV - (maxV - minV || 1) * 0.12;
      const maxY = maxV + (maxV - minV || 1) * 0.12;
      const minYr = activePoints[0].year;
      const maxYr = activePoints[activePoints.length - 1].year;

      const xScale = yr => padL + ((yr - minYr) / (maxYr - minYr || 1)) * plotW;
      const yScale = v => padT + plotH - ((v - minY) / (maxY - minY || 1)) * plotH;

      activePoints.forEach(p => {
        p._x = xScale(p.year);
        p._y = yScale(p.val);
      });

      let svg = "";

      // Recession bands
      if (showRecessions) {
        RECESSION_BANDS.forEach(b => {
          if (b.end < minYr || b.start > maxYr) return;
          const x1 = xScale(Math.max(b.start, minYr));
          const x2 = xScale(Math.min(b.end, maxYr));
          if (x2 > x1) {
            svg += `<rect x="${x1.toFixed(1)}" y="${padT}" width="${(x2 - x1).toFixed(1)}" height="${plotH}" fill="#E5E8EC"/>`;
          }
        });
      }

      // Horizontal gridlines & Y ticks
      const ticks = 5;
      for (let i = 0; i <= ticks; i++) {
        const val = minY + ((maxY - minY) / ticks) * i;
        const y = yScale(val);
        svg += `<line x1="${padL}" y1="${y.toFixed(1)}" x2="${W - padR}" y2="${y.toFixed(1)}" stroke="#E6E9ED" stroke-width="1"/>`;
        svg += `<text x="${padL - 8}" y="${(y + 4).toFixed(1)}" text-anchor="end" font-family="IBM Plex Mono, monospace" font-size="11" fill="#6A7682">${val.toFixed(1)}${suffix}</text>`;
      }

      // Zero line if YoY crosses zero
      if (minY < 0 && maxY > 0) {
        const zy = yScale(0);
        svg += `<line x1="${padL}" y1="${zy.toFixed(1)}" x2="${W - padR}" y2="${zy.toFixed(1)}" stroke="#17212B" stroke-width="1" stroke-dasharray="4 3" opacity="0.6"/>`;
      }

      // X axis ticks
      const step = activePoints.length > 14 ? 5 : (activePoints.length > 6 ? 2 : 1);
      activePoints.forEach((p, idx) => {
        if (idx % step === 0 || idx === activePoints.length - 1) {
          svg += `<text x="${p._x.toFixed(1)}" y="${H - 14}" text-anchor="middle" font-family="IBM Plex Mono, monospace" font-size="11" fill="#6A7682">${p.year}</text>`;
        }
      });

      // Area fill + Line path
      const linePath = activePoints.map((p, i) => `${i === 0 ? "M" : "L"}${p._x.toFixed(1)},${p._y.toFixed(1)}`).join(" ");
      const areaPath = `${linePath} L${activePoints[activePoints.length - 1]._x.toFixed(1)},${(padT + plotH).toFixed(1)} L${activePoints[0]._x.toFixed(1)},${(padT + plotH).toFixed(1)} Z`;

      svg += `<path d="${areaPath}" fill="rgba(27, 77, 137, 0.08)"/>`;
      svg += `<path d="${linePath}" fill="none" stroke="#1B4D89" stroke-width="2.4" stroke-linejoin="round" stroke-linecap="round"/>`;

      // Interactive crosshair + focus dot
      const last = activePoints[activePoints.length - 1];
      svg += `<line id="hoverLine" x1="${last._x.toFixed(1)}" y1="${padT}" x2="${last._x.toFixed(1)}" y2="${padT + plotH}" stroke="#1B4D89" stroke-width="1" stroke-dasharray="3 3"/>`;
      svg += `<circle id="hoverDot" cx="${last._x.toFixed(1)}" cy="${last._y.toFixed(1)}" r="5" fill="#1B4D89" stroke="#FFFFFF" stroke-width="2"/>`;

      // Invisible capture overlay
      svg += `<rect id="chartOverlay" x="${padL}" y="${padT}" width="${plotW}" height="${plotH}" fill="transparent"/>`;

      const chartSvg = document.getElementById("chartSvg");
      chartSvg.innerHTML = svg;

      updateReadout(activePoints.length - 1);

      // Pointer hover/tap interaction
      const overlay = document.getElementById("chartOverlay");
      function handlePointer(evt) {
        const rect = chartSvg.getBoundingClientRect();
        const clientX = evt.touches ? evt.touches[0].clientX : evt.clientX;
        const svgX = ((clientX - rect.left) / rect.width) * W;
        let nearestIdx = 0;
        let minDist = Infinity;
        activePoints.forEach((p, idx) => {
          const d = Math.abs(p._x - svgX);
          if (d < minDist) {
            minDist = d;
            nearestIdx = idx;
          }
        });
        updateReadout(nearestIdx);
      }

      overlay.addEventListener("mousemove", handlePointer);
      overlay.addEventListener("click", handlePointer);
      overlay.addEventListener("touchstart", handlePointer, { passive: true });
      overlay.addEventListener("touchmove", handlePointer, { passive: true });
    }

    // Event bindings
    document.querySelectorAll(".series-tab").forEach(tab => {
      tab.addEventListener("click", () => {
        activeSeries = tab.dataset.series;
        document.querySelectorAll(".series-tab").forEach(t => t.classList.toggle("active", t === tab));
        renderChart();
      });
    });

    document.querySelectorAll('[data-unit]').forEach(btn => {
      btn.addEventListener("click", () => {
        activeUnit = btn.dataset.unit;
        document.querySelectorAll('[data-unit]').forEach(b => b.classList.toggle("active", b === btn));
        renderChart();
      });
    });

    document.querySelectorAll('[data-range]').forEach(btn => {
      btn.addEventListener("click", () => {
        activeRange = btn.dataset.range;
        document.querySelectorAll('[data-range]').forEach(b => b.classList.toggle("active", b === btn));
        renderChart();
      });
    });

    document.getElementById("toggleRecession").addEventListener("change", e => {
      showRecessions = e.target.checked;
      renderChart();
    });

    document.getElementById("copyCite").addEventListener("click", () => {
      const txt = document.getElementById("citeText").textContent.trim();
      if (navigator.clipboard) navigator.clipboard.writeText(txt).catch(() => {});
      const btn = document.getElementById("copyCite");
      btn.textContent = "Citation Copied";
      setTimeout(() => { btn.textContent = "Copy BibTeX / APA Citation"; }, 1600);
    });

    // Mobile menu
    const menuBtn = document.getElementById("menuBtn");
    const mobileMenu = document.getElementById("mobileMenu");
    menuBtn.addEventListener("click", () => {
      const open = mobileMenu.classList.toggle("open");
      menuBtn.setAttribute("aria-expanded", String(open));
    });

    renderChart();
  </script>
</body>
</html>