% Copyright (c) 2026 Wang Yang (王阳) and contributors
% SPDX-License-Identifier: CC-BY-SA-4.0
% HUST names and institutional marks are excluded from this license grant.
% See LICENSE and NOTICE.md for details.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerouterthemehust}[2026/07/20 v0.7.1 HUST outer theme]

\mode<presentation>

\providecommand{\tikzexternaldisable}{}
\providecommand{\tikzexternalenable}{}

% The title is drawn against the physical page rather than the flow box.
% The empty 21 mm box preserves the compact title field; no decorative rule.
\setbeamertemplate{frametitle}{%
  \nointerlineskip%
  \begin{beamercolorbox}[
    wd=\paperwidth,
    ht=21mm,
    dp=0pt,
    sep=0pt
  ]{frametitle}%
    \tikzexternaldisable
    \begin{tikzpicture}[remember picture,overlay]
      \node[
        anchor=north west,
        xshift=\hust@frametitlemargin,
        yshift=-4.8mm,
        text width=\hust@frametitlewidth,
        align=left,
        inner sep=0pt,
        font=\usebeamerfont{hust frame label},
        text=HUSTFrameBlueSoft
      ] at (current page.north west) {%
        \ifx\secname\@empty
          学术报告
        \else
          \hust@twodigits{\insertsectionnumber}
          \hspace{1.1mm}{\color{HUSTFrameRule}/}\hspace{1.1mm}%
          \secname
        \fi
      };
      \node[
        anchor=north west,
        xshift=\hust@frametitlemargin,
        yshift=-10.2mm,
        text width=\hust@frametitlewidth,
        align=left,
        inner sep=0pt,
        font=\usebeamerfont{frametitle},
        text=fg
      ] at (current page.north west) {\insertframetitle};
    \end{tikzpicture}%
    \tikzexternalenable
  \end{beamercolorbox}%
}

% Light pages carry pagination only. School identity is reserved for the
% cover, section dividers, and closing page.
\newcommand{\hust@drawlightpagenumber}{%
  \node[
    anchor=south east,
    xshift=-\hust@margin,
    yshift=2.45mm,
    text=HUSTFrameBlue,
    font=\usebeamerfont{footline}
  ] at (current page.south east) {\bfseries\hust@displaypagenumber};
}

\setbeamertemplate{footline}{%
  \ifbool{moloch@standout}{}{%
    \leavevmode%
    \begin{beamercolorbox}[
      wd=\paperwidth,
      ht=3.3ex,
      dp=1.55ex
    ]{footline}%
      \tikzexternaldisable
      \begin{tikzpicture}[remember picture,overlay]
        \hust@drawlightpagenumber
      \end{tikzpicture}%
      \tikzexternalenable
    \end{beamercolorbox}%
  }%
}

\setbeamersize{
  text margin left=\hust@bodymarginleft,
  text margin right=\hust@bodymarginright
}

\mode<all>
\endinput
