<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{TITLE}}</title>
  <link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500;600&display=swap" rel="stylesheet">
  <style>
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --color-paper:   #f5f4ed;
      --color-paper-2: #efeee5;
      --color-ink:     #0b0d0b;
      --color-muted:   #52534e;
      --color-soft:    #65655c;
      --color-rule:    rgba(11,13,11,0.10);
      --color-accent:  #f7591f;
      --color-link:    #1a70c7;
      --font-sans:     'Geist', system-ui, sans-serif;
      --font-serif:    'Instrument Serif', serif;
      --font-mono:     'Geist Mono', ui-monospace, monospace;
    }
    html, body {
      font-family: var(--font-sans);
      background: var(--color-paper);
      color: var(--color-ink);
      line-height: 1.6;
    }
    body { padding: 3rem 2rem 6rem; }
    .frame { max-width: 980px; margin: 0 auto; }

    .eyebrow {
      font-family: var(--font-mono);
      font-size: 0.66rem;
      font-weight: 500;
      letter-spacing: 0.18em;
      text-transform: uppercase;
      color: var(--color-muted);
      margin-bottom: 0.5rem;
    }
    h1 {
      font-family: var(--font-serif);
      font-size: clamp(2rem, 3vw + 1rem, 2.8rem);
      font-weight: 400;
      letter-spacing: -0.02em;
      line-height: 1.1;
      margin-bottom: 0.5rem;
    }
    h2 {
      font-family: var(--font-serif);
      font-size: 1.6rem;
      font-weight: 400;
      letter-spacing: -0.01em;
      margin: 2.8rem 0 0.6rem;
      display: flex;
      align-items: baseline;
      gap: 0.8rem;
    }
    h2 .section-num {
      font-family: var(--font-mono);
      font-size: 0.7rem;
      font-weight: 500;
      letter-spacing: 0.15em;
      color: var(--color-accent);
    }
    h3 {
      font-family: var(--font-sans);
      font-size: 1.05rem;
      font-weight: 600;
      margin: 1.8rem 0 0.4rem;
      letter-spacing: -0.005em;
    }
    p {
      font-size: 0.98rem;
      margin-bottom: 0.9rem;
      color: var(--color-ink);
    }
    .sub {
      font-family: var(--font-sans);
      font-size: 0.92rem;
      color: var(--color-muted);
      margin-bottom: 2rem;
    }
    .sub a, .sub a:visited {
      color: var(--color-link);
      text-decoration: underline;
      text-decoration-thickness: 1px;
      text-underline-offset: 2px;
    }

    .aside {
      font-family: var(--font-serif);
      font-style: italic;
      font-size: 1.05rem;
      color: var(--color-soft);
      border-left: 2px solid var(--color-accent);
      padding: 0.4rem 0 0.4rem 1rem;
      margin: 1.4rem 0;
    }

    code, kbd {
      font-family: var(--font-mono);
      font-size: 0.88em;
      background: rgba(11,13,11,0.05);
      padding: 1px 5px;
      border-radius: 3px;
    }
    pre {
      font-family: var(--font-mono);
      font-size: 0.84rem;
      background: #ffffff;
      border: 1px solid var(--color-rule);
      border-radius: 6px;
      padding: 0.9rem 1rem;
      overflow-x: auto;
      margin: 0.6rem 0 1.2rem;
      line-height: 1.5;
    }
    pre code { background: transparent; padding: 0; }

    ul { margin: 0.4rem 0 1rem 1.4rem; }
    li { margin-bottom: 0.3rem; font-size: 0.96rem; }

    a, a:visited {
      color: var(--color-link);
      text-decoration: underline;
      text-decoration-thickness: 1px;
      text-underline-offset: 2px;
    }
    a:hover { color: var(--color-accent); }

    .diagram {
      background: var(--color-paper-2);
      border: 1px solid var(--color-rule);
      border-radius: 8px;
      padding: 1.2rem 1rem;
      margin: 1.2rem 0 1.6rem;
    }
    .diagram svg { display: block; width: 100%; min-width: 600px; }
    .caption {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      letter-spacing: 0.08em;
      color: var(--color-muted);
      text-transform: uppercase;
      margin-top: 0.6rem;
      text-align: center;
    }

    table {
      width: 100%;
      border-collapse: collapse;
      margin: 0.8rem 0 1.6rem;
      font-size: 0.94rem;
    }
    table th, table td {
      text-align: left;
      padding: 0.55rem 0.9rem;
      border-bottom: 1px solid var(--color-rule);
      vertical-align: top;
    }
    table th {
      font-family: var(--font-mono);
      font-size: 0.68rem;
      letter-spacing: 0.14em;
      text-transform: uppercase;
      color: var(--color-muted);
      font-weight: 500;
      border-bottom: 1px solid rgba(11,13,11,0.2);
    }

    .sources {
      margin-top: 3rem;
      padding-top: 1.6rem;
      border-top: 1px solid var(--color-rule);
    }
    .sources h2 { margin-top: 0; }
    .sources ul { list-style: none; margin-left: 0; }
    .sources li {
      font-size: 0.88rem;
      font-family: var(--font-mono);
      padding: 0.3rem 0;
      display: flex;
      gap: 0.8rem;
    }
    .sources .kind {
      color: var(--color-muted);
      flex-shrink: 0;
      width: 10em;
    }

    hr {
      border: 0;
      border-top: 1px solid var(--color-rule);
      margin: 2.4rem 0;
    }
    .footer {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      color: var(--color-muted);
      letter-spacing: 0.1em;
      text-align: center;
      margin-top: 4rem;
    }

    /* v3: wiki pages — one .wiki-page per entity / concept / source
       summary. Grouped under .wiki-root between the numbered sections
       and Sources. */
    .wiki-root {
      margin-top: 3rem;
      padding-top: 1.6rem;
      border-top: 1px solid var(--color-rule);
    }
    .wiki-root > h2 { margin-top: 0; }
    .wiki-toc {
      background: var(--color-paper-2);
      border: 1px solid var(--color-rule);
      border-radius: 6px;
      padding: 1rem 1.1rem 1.2rem;
      margin: 1rem 0 2rem;
    }
    .wiki-toc-label {
      font-family: var(--font-mono);
      font-size: 0.68rem;
      font-weight: 500;
      letter-spacing: 0.14em;
      text-transform: uppercase;
      color: var(--color-muted);
      margin-bottom: 0.6rem;
    }
    .wiki-toc ul {
      list-style: none;
      margin: 0;
      padding: 0;
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 0.3rem 0.9rem;
    }
    .wiki-toc li { margin: 0; }
    .wiki-toc a {
      display: flex;
      align-items: baseline;
      gap: 0.5rem;
      padding: 0.3rem 0;
      text-decoration: none;
      border-bottom: 1px dotted transparent;
      color: var(--color-ink);
    }
    .wiki-toc a:hover { border-bottom-color: var(--color-accent); }
    .wiki-toc-kind {
      font-family: var(--font-mono);
      font-size: 0.64rem;
      letter-spacing: 0.12em;
      text-transform: uppercase;
      color: var(--color-muted);
      background: rgba(11,13,11,0.04);
      padding: 1px 6px;
      border-radius: 2px;
      flex-shrink: 0;
      min-width: 5.5em;
      text-align: center;
    }
    .wiki-toc-name {
      font-family: var(--font-sans);
      font-size: 0.9rem;
      font-weight: 500;
      flex-grow: 1;
    }
    .wiki-toc-updated {
      font-family: var(--font-mono);
      font-size: 0.7rem;
      color: var(--color-muted);
    }
    .wiki-page {
      margin: 1.6rem 0 2rem;
      padding-left: 1rem;
      border-left: 2px solid var(--color-rule);
    }
    .wiki-page > h3 {
      font-family: var(--font-serif);
      font-size: 1.25rem;
      margin: 0 0 0.4rem;
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 1rem;
    }
    .wiki-page-back {
      font-family: var(--font-mono);
      font-size: 0.68rem;
      letter-spacing: 0.1em;
      text-transform: uppercase;
      color: var(--color-muted);
      text-decoration: none;
      font-weight: 400;
      padding: 0.15rem 0.5rem;
      border: 1px solid var(--color-rule);
      border-radius: 3px;
      white-space: nowrap;
    }
    .wiki-page-back:hover {
      color: var(--color-accent);
      border-color: var(--color-accent);
    }
    .wiki-link {
      text-decoration: none;
      border-bottom: 1px dotted var(--color-accent);
    }
    .wiki-broken {
      color: var(--color-accent);
      background: rgba(247,89,31,0.08);
      padding: 0 3px;
      border-radius: 3px;
      font-family: var(--font-mono);
      font-size: 0.82em;
    }

    /* Diagram placeholder — author referenced a diagrams/*.svg file
       that was never written (or was rejected by svg_safety). Show a
       graceful "pending" card instead of a broken-image icon. */
    .diagram-missing {
      background: repeating-linear-gradient(
        45deg,
        var(--color-paper-2),
        var(--color-paper-2) 6px,
        var(--color-paper) 6px,
        var(--color-paper) 12px
      );
      border: 1px dashed var(--color-rule);
      text-align: center;
      min-height: 140px;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    .diagram-missing-label {
      font-family: var(--font-mono);
      font-size: 0.7rem;
      letter-spacing: 0.18em;
      text-transform: uppercase;
      color: var(--color-accent);
      margin-bottom: 0.4rem;
    }

    /* Bilingual toggle — default hides .tr-zh; clicking 中文 reveals
       each Chinese paragraph directly below its English sibling. */
    .lang-switch {
      position: sticky;
      top: 1rem;
      float: right;
      display: flex;
      gap: 0;
      background: var(--color-paper);
      border: 1px solid var(--color-rule);
      border-radius: 999px;
      padding: 2px;
      font-family: var(--font-mono);
      font-size: 0.7rem;
      letter-spacing: 0.1em;
      z-index: 10;
    }
    .lang-switch button {
      border: 0;
      background: transparent;
      color: var(--color-muted);
      padding: 0.35rem 0.85rem;
      cursor: pointer;
      border-radius: 999px;
      font-family: inherit;
      font-size: inherit;
      letter-spacing: inherit;
    }
    .lang-switch button.active {
      background: var(--color-ink);
      color: var(--color-paper);
    }
    .lang-switch button:disabled {
      cursor: not-allowed;
      opacity: 0.45;
    }
    .tr-zh {
      display: none;
      color: var(--color-muted);
      font-size: 0.94rem;
      margin-top: -0.4rem;
      margin-bottom: 0.9rem;
      padding-left: 0.75rem;
      border-left: 2px solid var(--color-accent);
    }
    body.bilingual .tr-zh {
      display: block;
    }
    body.bilingual .tr-zh:empty {
      display: none;
    }
  </style>
</head>
<body>
  {{LANG_SWITCH_HTML}}
  <div class="frame">

    <p class="eyebrow">Research report</p>
    <h1>{{TITLE}}</h1>
    <p class="sub">{{SUBTITLE}}</p>

    {{ASIDE_QUOTE}}

    {{BODY_HTML}}

    <div class="sources">
      <h2><span class="section-num">SOURCES</span><span>All linked</span></h2>
      {{SOURCES_HTML}}
    </div>

    <p class="footer">
      {{SESSION_FOOTER}} · generated {{GENERATED_AT}}
    </p>
  </div>
</body>
</html>
