{{- /* Head custom content area start */ -}}
{{- /*     Insert any custom code (web-analytics, resources, etc.) - it will appear in the <head></head> section of every page. */ -}}
{{- /*     Can be overwritten by partial with the same name in the global layouts. */ -}}

{{- /* Enable reveal-on-scroll states only when motion is allowed.
       Runs before <body> paints so there is no content flash and no
       layout shift for reduced-motion / no-JS visitors. */ -}}
<script>
  (function () {
    try {
      if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
      var de = document.documentElement;
      de.classList.add('motion-reveal');
      // Failsafe: if the enhancement script never initialises (e.g. it
      // failed to load), drop the reveal class so content is never stuck
      // hidden. No-op when micro-interactions.js runs normally.
      window.addEventListener('load', function () {
        setTimeout(function () {
          if (!window.__microInteractionsReady) de.classList.remove('motion-reveal');
        }, 1500);
      });
    } catch (e) {}
  })();
</script>

{{- /* Preconnect hints for external resources */ -}}
<link rel="preconnect" href="https://www.googletagmanager.com" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="dns-prefetch" href="//www.google-analytics.com" />
<link rel="dns-prefetch" href="//www.googletagmanager.com" />

{{- /* Google Fonts — async (non-render-blocking) */ -}}
{{- /* Space Grotesk + the 700 weights of Inter / JetBrains Mono moved here
       from a render-blocking @import that used to live in
       homepage-daypage.css — one consolidated async request. */ -}}
{{- $baseFonts := "https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,700;1,9..144,300;1,9..144,400;1,9..144,700&family=Inter:wght@400;500;600;700&family=Noto+Serif:ital,wght@0,400;0,700;1,400&family=JetBrains+Mono:wght@400;500;700&family=Space+Grotesk:wght@500;600;700&display=swap" -}}
{{- /* Google Fonts — fully async via preload + noscript fallback.
       Use media="print" on the noscript fallback to prevent Chrome's
       speculative parser from issuing a duplicate request (the preload
       already triggers one). The tiny media-query mismatch guarantees
       the print vs screen conflict is harmless — anything that actually
       reads the print stylesheet will still render the fonts correctly. */ -}}
<link rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'" href="{{ $baseFonts }}">
<noscript><link rel="stylesheet" href="{{ $baseFonts }}" media="print" onload="this.media='all'"></noscript>
{{- if eq .Lang "zh" }}
{{- $zhFonts := "https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;700&display=swap" -}}
<link rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'" href="{{ $zhFonts }}">
<noscript><link rel="stylesheet" href="{{ $zhFonts }}" media="print" onload="this.media='all'"></noscript>
{{- end }}

{{- /* SEO Structured Data handled by seo.html → seo/structured-data.html */ -}}

{{- /* Language Auto-Detection Script */ -}}
<script src="{{ "/js/lang-redirect.js" | relURL }}" defer></script>

{{- /* Preload hero/LCP image on homepage */ -}}
{{- if .IsHome }}
{{- with site.Params.profileMode.imageUrl }}
<link rel="preload" href="{{ . | absURL }}" as="image" fetchpriority="high">
{{- end }}
{{- end }}

{{- /* Search Command Palette dependencies.
       fuse.js is self-hosted (assets/js/vendor/fuse.min.js): jsdelivr is
       unreliable from mainland China and cost an extra third-party
       connection on every page. Fingerprinted → 1-year immutable cache. */ -}}
{{- $fuseJS := resources.Get "js/vendor/fuse.min.js" | fingerprint }}
<script defer src="{{ $fuseJS.RelPermalink }}" integrity="{{ $fuseJS.Data.Integrity }}"></script>
{{- $searchPaletteJS := resources.Get "js/search-palette.js" | minify | fingerprint }}
<script defer src="{{ $searchPaletteJS.RelPermalink }}" integrity="{{ $searchPaletteJS.Data.Integrity }}"></script>

{{- /* Head custom content area end */ -}}
