\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{paper}[2025/08/22 Kirino House clean document class]

% --------------------
%   基于 ctexbook 类
% --------------------
\LoadClass[openright]{ctexbook}

% --------------------
%     宏包导入
% --------------------
\RequirePackage{silence}        % 屏蔽警告
\RequirePackage{ifthen}
\RequirePackage{xstring}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{fontspec}       % 字体
\RequirePackage{xeCJK}          % 中文
\RequirePackage{unicode-math}   % 数学字体
\RequirePackage{bm}             % 粗体数学符号
\RequirePackage{amsmath}        % 数学环境
\RequirePackage{tabularx}       % 可自动伸缩列宽的表格
\RequirePackage{setspace}       % 行距控制
\RequirePackage{titlesec}       % 章节标题控制
\RequirePackage{titling}        % 自定义标题页
\RequirePackage{fancyhdr}       % 页眉页脚
\RequirePackage{ragged2e}       % 对齐
\RequirePackage{afterpage}      
\RequirePackage{emptypage}      
\RequirePackage{wallpaper}      
\RequirePackage{tabularray}     
\UseTblrLibrary{amsmath}
\RequirePackage{enumitem}       % 列表控制
\RequirePackage{enumerate}
\RequirePackage{tasks}          
\RequirePackage{multicol}  
\RequirePackage{tabularx}     
\RequirePackage{tikz}           
\usetikzlibrary{
    shapes, shadows, arrows.meta, shapes.geometric, fit, positioning,
    decorations.pathreplacing, angles, quotes, calc
}
\RequirePackage{tcolorbox}      
\tcbuselibrary{skins, breakable, theorems}
\RequirePackage{ulem}           
\normalem
\RequirePackage{paracol}        
\RequirePackage{lipsum}         
\RequirePackage{dashrule}       
\RequirePackage{pifont}         
\RequirePackage{romannum}       
\RequirePackage{newunicodechar} 

% --------------------
%     页面设置
% --------------------
\RequirePackage{geometry}
\geometry{
    a3paper,
    landscape,
    left=2cm,
    right=2cm,
    top=1cm,
    bottom=1cm
}

\setlength{\parindent}{0pt}
\newlength{\minipageheight}
\setlength{\minipageheight}{\paperheight}

% --------------------
%     可视化窗格
% --------------------
%\RequirePackage{showframe}

% --------------------
%     字体设置
% --------------------
\setmainfont{思源黑体}
\setmathfont{XITS Math}

% --------------------
%     颜色设置
% --------------------
\definecolor{dd4d49}{HTML}{DD4D49}
\definecolor{e8a6a3}{HTML}{E8A6A3}
\definecolor{c9c9c9}{HTML}{C9C9C9}

% --------------------
%   自动样式设置
% --------------------

% 分栏调整
\setlength{\columnsep}{0cm} % 栏间距

% 多栏环境拉伸行距开关
\raggedcolumns

% 难度星级样式
\ExplSyntaxOn
\clist_set:Nn \l_tmpa_clist {72,72,72,72,72,73,73,73,73,73}
\cs_new:Npn \__ljguo_get_rating:n #1 {
    \int_set:Nn \l_tmpa_int { 6 - #1 }
    \int_set:Nn \l_tmpb_int { 10 - #1 }
    \group_begin:
    \color_select:n { black }
    \int_step_inline:nnn { \l_tmpa_int } { \l_tmpb_int }
    {
        \large
        \ding{\clist_item:Nn \l_tmpa_clist { ##1 }}
    }
    \group_end:
}
\let\getRating\__ljguo_get_rating:n
\ExplSyntaxOff

% 选择题标签样式
\newcommand{\taskupS}[2]{% #1=标签 #2=内容
  \shortstack{ #1\\[0.0em]#2}%
}

% 选择题涂卡样式
\settasks{
    label=\textbf{$\arabic*$},
    label-offset=1em,
    label-align=right,
    column-sep=13pt,
    label-width=3ex,
    item-indent=20pt
}

\newcommand{\drawfourrects}{
    \vspace{-1.2em}
    \begin{tikzpicture}[baseline=(current bounding box.center)]
        \def\rectwidth{15pt}
        \def\rectheight{3mm}
        \def\spacing{1.5mm} 
        \foreach \i/\letter in {0/$\mathsf{A}$,1/$\mathsf{B}$,2/$\mathsf{C}$,3/$\mathsf{D}$} {
            % 改成纵向排列：x 固定，y 随 i 变化
            \draw[thick, dd4d49] (0,-\i*\rectheight - \i*\spacing) 
                rectangle ++(\rectwidth,-\rectheight);
            \node[anchor=west] at (0.0*\rectwidth,-\i*\rectheight - \i*\spacing -0.5*\rectheight)
                {\textbf{\fontsize{8pt}{9pt}\selectfont\color{dd4d49}\letter}};
        }
    \end{tikzpicture}
    \vspace{-1.5em}
}

% 添加图片命令
\newcommand{\AddImage}[3]{%
    \IfFileExists{image/#1.png}{%
        \node[anchor=north east] at #3 {%
            \includegraphics[width=#2]{image/#1.png}%
        };
    }{}%
}

% --------------------
%     分栏样式
% --------------------

% 正面左栏内容
\newcommand{\DrawAnswerSheetA}{
    \begin{tikzpicture}[remember picture,overlay]

        % 页眉封线
        \draw[line width=3mm, dash pattern=on 15pt off 9.5pt]
            (36pt,0) -- (0.99*\linewidth-36pt,0);
        \draw[line width=5mm]
            (0,1mm) -- ++(25pt,0);
        \draw[line width=5mm]
            (0.99*\linewidth-25pt,1mm) -- ++(25pt,0);
    
        % 标题栏
        \node[anchor=north, align=center, text width=0.8\linewidth] at (0.5\linewidth, -1.5em) {
            \bfseries
            \fontsize{18pt}{27pt}\selectfont {\color{dd4d49} 雾之宅落每周数学试卷作业} \\[0.3em]
            \fontsize{14pt}{21pt}\selectfont \papername 答题卡
        };

        % 姓名栏
        \node[anchor=north west, font=\bfseries] at (0, -7em) {%
            姓\hspace{2em}名\hspace{5pt}{\color{dd4d49}\underline{\hspace{120.5pt}}}%
        };

        % 准考证号栏
        \node[anchor=north west, font=\bfseries] at (0, -8.5em) {%
            准考证号\hspace{2.6pt}
            \raisebox{-0.25\height}{%
                \begin{tikzpicture}
                    \def\squaresize{12pt}
                    \newcommand{\mytext}{9876547210}
                    \foreach \x in {1,...,10} {
                        \draw[thick, dd4d49, fill=white] 
                            (\x*\squaresize, 0) rectangle ++(\squaresize, \squaresize) 
                            node[pos=0.5, anchor=center] {\color{black}$\StrChar{\mytext}{\x}$};
                    }
                \end{tikzpicture}%
            }
        };

        % logo 栏
        \def\minipagewidth{0.475\linewidth}
        \draw[thick, dash pattern=on 1pt off 1pt, dd4d49, rounded corners] (0.15, -10.7em) rectangle (\minipagewidth, -16.7em);
        \node[anchor=center] at (0.5*\minipagewidth+1, -13.7em) {
            \includegraphics[width=5cm]{image/logo.png}
        };

        % 试卷难度栏
        \draw[thick, dd4d49] (0.15, -17.4em) rectangle (\minipagewidth, -19.0em);
        \draw[thick, dd4d49] (1.8, -17.4em) -- (1.8,-19.0em);
        \node[anchor=north west, align=left] at (0.1, -17.4em) {\bfseries 试题难度};
        \node[anchor=north west] at (1.9, -17.4em) {\getRating{\difficulty}};

        % 注意事项栏
        \fill[e8a6a3!40] (1.05*\minipagewidth, -17.4em) rectangle (0.99\linewidth, -19.0em);
        \draw[thick, dd4d49] (1.05*\minipagewidth, -7em) rectangle (0.99\linewidth, -19.0em);
        \draw[thick, dd4d49] (1.05*\minipagewidth, -8.4em) -- (0.99\linewidth,-8.4em);
        \node[anchor=north west, dd4d49, font=\fontsize{7pt}{8.4pt}\selectfont] at (1.055*\minipagewidth, -7.2em) {%
            \bfseries
            \raisebox{-0.1\height}{$\blacktriangle$}\hspace{0.85em}注意事项
        };
        \node[anchor=north west, text width=4*\linewidth/8, align=left, font=\fontsize{7pt}{8.4pt}\bfseries\selectfont, text=dd4d49] at (0.97*\minipagewidth, -7.6em) {%
            \begin{itemize}[align=right, labelwidth=2em, itemsep=-0.5em]
                \item[$1.$] 答题时间$120$分钟，建议计时完成。
                \item[$2.$] 选填题建议每题不超过$3$分钟，解答题建议每题不超过$12$分钟。
                \item[$3.$] 选择题按考试标准填涂，非选择题要求书写工整清晰，有必要的文字说明。
                \item[$4.$] 答案过于潦草无法识别，或将答题区域当作草纸用于演算，试题零分处理。
            \end{itemize}
        };
        \node[anchor=north west, font=\fontsize{7pt}{8.4pt}\selectfont] at (1.055*\minipagewidth, -17.6em) {%
            \bfseries
            \raisebox{-0.1\height}{$\blacktriangle$}\hspace{0.85em}求助专区
        };

        % 选择题
        \draw[thick, dd4d49, rounded corners=1em] (0.15, -21em) rectangle (0.99\linewidth, -31em);
        \node[anchor=north west, fill=white, font=\bfseries] at (0.7, -20em) {\color{dd4d49}选择题};
        \draw[thick] (0.3, -21.6em) rectangle ({0.99\linewidth-0.15cm}, -30.1em);
        \node[anchor=north, dd4d49, font=\fontsize{7pt}{8.4pt}\selectfont] at (0.5\linewidth, -29.9em) {%
            \bfseries
            选择题请按题号用2B铅笔填涂方框，修改时用橡皮擦干净，不留痕迹
        };
        % 框内选项
        \node[anchor=north west, text width=0.9\linewidth, inner sep=5pt] at (0.8, -21.6em) {
            \settasks{
                label=\relax,      % 关闭左侧默认标签
                label-width=0pt,
                label-offset=0pt,
                item-indent=0pt,
                column-sep=-55pt
            }
            \begin{tasks}(12)[before-skip=0pt, after-skip=0pt]
                \task{\taskupS{1}{\drawfourrects}}
                \task{\taskupS{2}{\drawfourrects}}
                \task{\taskupS{3}{\drawfourrects}}
                \task{\taskupS{4}{\drawfourrects}}
                \task{\taskupS{5}{\drawfourrects}}
                \task{\taskupS{6}{\drawfourrects}}
                \task{\taskupS{7}{\drawfourrects}}
                \task{\taskupS{8}{\drawfourrects}}
                \task{}
                \task{\taskupS{9}{\drawfourrects}}
                \task{\taskupS{10}{\drawfourrects}}
                \task{\taskupS{11}{\drawfourrects}}
            \end{tasks}
        };
        \draw[line width=3mm, dd4d49]
            (0.89\linewidth,-23.3em) -- ++(15pt,0);
        \draw[line width=3mm, c9c9c9]
            (0.89\linewidth,-25.8em) -- ++(15pt,0);
        \draw[line width=3mm]
            (0.89\linewidth,-28.3em) -- ++(15pt,0);

        % 非选择题（填空题与 15 题）
        \draw[thick, dd4d49, fill=e8a6a3!40, rounded corners=1em] (0.15, -32em) rectangle (0.99\linewidth, -\textheight);
        \draw[thick, fill=white] (0.3, -33.6em) rectangle ({0.99\linewidth-0.15cm}, -\textheight+1.3em);
        \node[anchor=north west, font=\bfseries] at (0.7, -32em) {\color{dd4d49}非选择题};
        \node[anchor=north west, font=\bfseries\fontsize{7pt}{8.4pt}\selectfont] at (2.4, -32.3em) {\color{dd4d49}（请使用0.5毫米黑色墨水签字笔书写）};
        \node[anchor=north west, font=\bfseries] at (0.3, -34em) {填空题};
        \node[anchor=north west, text width=0.9\linewidth, inner sep=5pt] at (0.35,-35.3em){%
            \begingroup
                \renewcommand{\arraystretch}{2}% 行距（越小越紧）
                \setlength{\tabcolsep}{6pt}% 列间距
                \bfseries
                \begin{tabular}{@{}r l @{\hspace{2em}} r l @{}}
                    $12.$ & {\color{dd4d49}\underline{\hspace{4cm}}} & $13.$ & {\color{dd4d49}\underline{\hspace{4cm}}} \\
                    $14.$ & {\color{dd4d49}\underline{\hspace{4cm}}} &      & \\
                \end{tabular}%
            \endgroup
        };
        \draw[thick] (0.3, -42.5em) -- ({0.99\linewidth-0.15cm},-42.5em);
        \node[anchor=north west, font=\bfseries] at (0.4, -43.5em) {$15.$};
        \AddImage{15}{\imgwidthA}{({0.99\linewidth-0.3cm},-43.5em)}
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, -\textheight+1.4em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };

    \end{tikzpicture}
}

% 正面中栏内容
\newcommand{\DrawAnswerSheetB}{
    \begin{tikzpicture}[remember picture,overlay]

        \draw[thick, dd4d49, fill=e8a6a3!40, rounded corners=1em] (0.15, -0em) rectangle (0.99\linewidth, -\textheight);
        \draw[thick, fill=white] (0.3, -1.3em) rectangle ({0.99\linewidth-0.15cm}, -\textheight+1.3em);
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, 0.1em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };
        \node[anchor=north west, dd4d49, font=\bfseries] at (0.4, -2.3em) {（续$15$题）};
        \draw[thick] (0.3, -23em) -- ({0.99\linewidth-0.15cm},-23em);
        \node[anchor=north west, font=\bfseries] at (0.4, -24em) {$16.$};
        \AddImage{16}{\imgwidthB}{({0.99\linewidth-0.3cm},-24em)}
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, -\textheight+1.4em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };

    \end{tikzpicture}
}

% 正面右栏内容
\newcommand{\DrawAnswerSheetC}{
    \begin{tikzpicture}[remember picture,overlay]

        \draw[thick, dd4d49, fill=e8a6a3!40, rounded corners=1em] (0.15, -0em) rectangle (0.99\linewidth, -\textheight);
        \draw[thick, fill=white] (0.3, -1.3em) rectangle ({0.99\linewidth-0.15cm}, -\textheight+1.3em);
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, 0.1em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };
        \node[anchor=north west, font=\bfseries] at (0.4, -2.3em) {$17.$};
        \AddImage{17}{\imgwidthC}{({0.99\linewidth-0.3cm},-2.3em)}
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, -\textheight+1.4em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };

    \end{tikzpicture}
}

% 背面左栏内容
\newcommand{\DrawAnswerSheetD}{
    \begin{tikzpicture}[remember picture,overlay]

        \draw[thick, dd4d49, fill=e8a6a3!40, rounded corners=1em] (0.15, -0em) rectangle (0.99\linewidth, -\textheight);
        \draw[thick, fill=white] (0.3, -1.3em) rectangle ({0.99\linewidth-0.15cm}, -\textheight+1.3em);
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, 0.1em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };
        \node[anchor=north west, font=\bfseries] at (0.4, -2.3em) {$18.$};
        \AddImage{18}{\imgwidthD}{({0.99\linewidth-0.3cm},-2.3em)}
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, -\textheight+1.4em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };

    \end{tikzpicture}
}

% 背面中栏内容
\newcommand{\DrawAnswerSheetE}{
    \begin{tikzpicture}[remember picture,overlay]

        \draw[thick, dd4d49, fill=e8a6a3!40, rounded corners=1em] (0.15, -0em) rectangle (0.99\linewidth, -\textheight);
        \draw[thick, fill=white] (0.3, -1.3em) rectangle ({0.99\linewidth-0.15cm}, -\textheight+1.3em);
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, 0.1em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };
        \node[anchor=north west, dd4d49, font=\bfseries] at (0.4, -2.3em) {（续$18$题）};
        \draw[thick] (0.3, -0.5\textheight) -- ({0.99\linewidth-0.15cm},-0.5\textheight);
        \node[anchor=north west, font=\bfseries] at (0.4, -0.5\textheight-1em) {$19.$};
        \AddImage{19}{\imgwidthE}{({0.99\linewidth-0.3cm},-0.5\textheight-1em)}
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, -\textheight+1.4em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };

    \end{tikzpicture}
}

% 背面右栏内容
\newcommand{\DrawAnswerSheetF}{
    \begin{tikzpicture}[remember picture,overlay]

        \draw[thick, dd4d49, fill=e8a6a3!40, rounded corners=1em] (0.15, -0em) rectangle (0.99\linewidth, -\textheight);
        \draw[thick, fill=white] (0.3, -1.3em) rectangle ({0.99\linewidth-0.15cm}, -\textheight+1.3em);
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, 0.1em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };
        \node[anchor=north west, dd4d49, font=\bfseries] at (0.4, -2.3em) {（续$19$题）};
        \node[anchor=north, dd4d49, font=\fontsize{10pt}{12pt}\selectfont] at (0.5\linewidth, -\textheight+1.4em) {%
            \bfseries
            请在各题指定区域内答题，超出黑色矩形边框限定区域的答案无效
        };

    \end{tikzpicture}
}