{{ template "main" . }}
{{- /* prev/next 2-card 푸터 — main.yaml 메뉴 순서 기반 글로벌 순회
(섹션 인덱스 페이지·섹션 간 이동도 자동 처리. 메뉴에 없는 페이지는 .PrevInSection fallback) */ -}}
{{- $prev := false -}}{{- $next := false -}}
{{- $current := .RelPermalink -}}
{{- $curKey := printf "%s/" (trim $current "/") -}}
{{- /* 메뉴 전체 평탄화 */ -}}
{{- $flat := slice -}}
{{- range hugo.Data.menu.main.main -}}
{{- range .sub -}}
{{- if .ref -}}
{{- $refKey := printf "%s/" (trim .ref "/") -}}
{{- $flat = $flat | append (dict "name" .name "ref" .ref "key" $refKey) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* 현재 페이지 위치 찾기 */ -}}
{{- $idx := -1 -}}
{{- range $i, $item := $flat -}}
{{- if eq $item.key $curKey -}}{{- $idx = $i -}}{{- end -}}
{{- end -}}
{{- if ge $idx 0 -}}
{{- /* 메뉴에서 발견 → 글로벌 평탄 순회 적용 */ -}}
{{- if gt $idx 0 -}}
{{- $p := index $flat (sub $idx 1) -}}
{{- $prev = dict "title" $p.name "lbl" "← 이전" "url" $p.ref -}}
{{- end -}}
{{- if lt $idx (sub (len $flat) 1) -}}
{{- $n := index $flat (add $idx 1) -}}
{{- $next = dict "title" $n.name "lbl" "다음 →" "url" $n.ref -}}
{{- end -}}
{{- else if eq .Kind "home" -}}
{{- /* 홈: 메뉴 첫 항목으로 */ -}}
{{- if gt (len $flat) 0 -}}
{{- $n := index $flat 0 -}}
{{- $next = dict "title" $n.name "lbl" "다음 →" "url" $n.ref -}}
{{- end -}}
{{- else -}}
{{- /* 메뉴에 없는 페이지: 같은 섹션 형제 페이지로 fallback (weight 역순 swap) */ -}}
{{- if .NextInSection -}}{{- $prev = dict "title" .NextInSection.Title "lbl" "← 이전" "url" .NextInSection.RelPermalink -}}{{- end -}}
{{- if .PrevInSection -}}{{- $next = dict "title" .PrevInSection.Title "lbl" "다음 →" "url" .PrevInSection.RelPermalink -}}{{- end -}}
{{- end -}}
{{- if or $prev $next -}}
{{- end -}}
{{- /* 우측 TOC rail (디자인 240px) */ -}}
{{- if eq .Kind "home" -}}
{{- else if .TableOfContents -}}
{{- $hasHeadings := gt (len (findRE "