{{- $headers := findRE "<h[1-6].*?>(.|\n])+?</h[1-6]>" .Content -}}
{{- $has_headers := ge (len $headers) 1 -}}
{{- if $has_headers -}}
<!-- Inline TOC (mobile only, fine-line style) -->
<nav class="toc-inline" aria-label="{{- i18n "toc" | default "Table of Contents" | safeHTML }}">
  <div class="toc-inline__label">{{- i18n "toc" | default "Table of Contents" | safeHTML }}</div>
  <ul>
    {{- range $headers -}}
    {{- $headerLevel := index (findRE "[1-6]" . 1) 0 -}}
    {{- $headerLevel := len (seq $headerLevel) -}}
    {{- $id := index (findRE "(id=\"(.*?)\")" . 9) 0 }}
    {{- $cleanedID := replace (replace $id "id=\"" "") "\"" "" }}
    {{- $headerClean := replaceRE "<h[1-6].*?>((.|\n])+?)</h[1-6]>" "$1" . -}}
    <li class="toc-inline__item toc-inline__item--h{{- $headerLevel -}}">
      <a href="#{{- $cleanedID -}}">{{- $headerClean | safeHTML -}}</a>
    </li>
    {{- end -}}
  </ul>
</nav>
{{- end }}

{{/* The desktop Reading Companion / AI panel is rendered by
     layouts/partials/article/editorial-tools.html. Do not duplicate its DOM
     here — duplicate ids break event binding (chip clicks silently attach to
     the hidden copy) and scroll-spy (mutations on two copies fight for
     toc-active, causing flicker on Chinese pages). */}}
