/**
 * 全站公共样式：色板、字体、导航、容器、按钮、卡片、米字格、分页。
 * 用于所有页面的头尾与通用组件。
 */

/*
 * 罕见字 Web 字体（叠字 / 笔画最多 / 汉字详情米字格）
 * 源：遍黑体 Plangothic 子集 → style/fonts/rare-cjk.woff2
 * unicode-range 限定扩展区，页面无生僻字时浏览器不下字体
 */
@font-face {
    font-family: "Rare CJK";
    src: url("fonts/rare-cjk.woff2") format("woff2");
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
    /* Ext B / C / E / G（站内生僻字所在平面） */
    unicode-range:
        U+20000-2A6DF,
        U+2A700-2B73F,
        U+2B820-2CEAF,
        U+30000-3134F;
}

/* ---------- 色板与字体 ---------- */
:root {
    --paper: #e8eef2;          /* 青白纸：页面底，偏冷，避免暖米色模板 */
    --paper-2: #f6fafc;        /* 格内纸：卡片、米字格内部 */
    --ink: #1a2740;            /* 青墨：正文 */
    --muted: #5e7688;          /* 次要文字、拼音 */
    --grid: #8fb4c9;           /* 田字格内部十字与米线 */
    --azurite: #2a6280;        /* 石青：链接、主按钮、格框 */
    --azurite-deep: #1e4a62;   /* 石青按下 */
    --cinnabar: #c4352a;       /* 印泥：当前导航、揭谜；不做大色块 */
    --line: #c5d5df;           /* 分割线 */
    --max: 1080px;
    --header-h: 64px;
    --font-ui: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    /* Rare CJK 优先：手机系统字体常缺 ExtB+ 字形 */
    --font-kai: "Rare CJK", KaiTi, "Kaiti SC", STKaiti, "Noto Serif SC", serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.7;
    color: var(--ink);
    background: var(--paper);
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--azurite);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

a:hover {
    color: var(--azurite-deep);
}

:focus-visible {
    outline: 2px solid var(--azurite);
    outline-offset: 3px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.wrap {
    width: min(100% - 32px, var(--max));
    margin-inline: auto;
}

/* 正文用青白纸实色，头尾加白素底，只靠深浅区分、不再铺纹 */
main {
    flex: 1;
    padding-bottom: 28px;
    background: var(--paper);
}

/* ---------- 顶栏：Logo 小米字格 + 栏目 + 搜索 ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    min-height: var(--header-h);
    background: color-mix(in srgb, var(--paper) 88%, #fff);
    border-bottom: 1px solid var(--line);
    -webkit-backdrop-filter: blur(8px); /* Safari 毛玻璃 */
    backdrop-filter: blur(8px);
}

.header-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    min-height: var(--header-h);
    padding-block: 8px;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px; /* 与导航链接同高，站名和栏目才能水平对齐 */
    color: var(--ink);
    text-decoration: none;
    flex-shrink: 0;
}

.logo:hover {
    color: var(--ink);
}

.logo-name {
    /* 与导航同字号，靠字重区分站名；不同字号时汉字基线很难水平对齐 */
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1;
    white-space: nowrap;
}

/* 顶栏 Logo 图尺寸 */
.logo-img {
    width: 36px;
    height: 36px;
    display: block;
    object-fit: contain;
}

/* 手机顶栏：三横菜单，无边框；展开时收成叉 */
.nav-toggle {
    margin-left: auto;
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    min-height: 44px;
    min-width: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
}

.nav-toggle__bar {
    display: block;
    width: 22px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(2) {
    opacity: 0;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.site-nav {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    gap: 4px;
}

.site-nav.is-open {
    display: flex;
}

.site-nav__link {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 10px;
    color: var(--ink);
    text-decoration: none;
    line-height: 1; /* 与站名一致，按墨迹中线水平对齐 */
    border-top: 2px solid transparent; /* 与底边框对称，避免文字被顶上去 */
    border-bottom: 2px solid transparent;
}

.site-nav__link.is-current {
    color: var(--cinnabar);
    border-bottom-color: var(--cinnabar);
}

.suggest-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.suggest-wrap input {
    width: 100%;
    min-height: 44px;
    min-width: 0;
    padding: 0 12px;
    border: 1px solid var(--line);
    background: var(--paper-2);
    color: var(--ink);
    font: inherit;
}

/* 搜索下拉建议，顶栏与首页共用 */
.suggest-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 60;
    max-height: min(70vh, 420px);
    overflow: auto;
    background: var(--paper-2);
    border: 1px solid var(--line);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 12%, transparent);
}

.suggest-label {
    margin: 0;
    padding: 8px 12px 4px;
    font-size: 12px;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.suggest-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 44px;
    padding: 8px 12px;
    color: var(--ink);
    text-decoration: none;
}

.suggest-item:hover,
.suggest-item:focus-visible {
    background: var(--paper);
}

.suggest-item small {
    color: var(--muted);
    font-size: 13px;
}

.btn {
    min-height: 35px;
    padding: 0 16px;
    border: 0;
    background: var(--azurite);
    color: #fff;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    background: var(--azurite-deep);
}

.btn-ghost {
    background: transparent;
    color: var(--azurite);
    border: 1px solid var(--azurite);
}

.btn-ghost:hover {
    background: var(--azurite);
    color: #fff;
}

/* 链接做成按钮时，去掉下划线，高度与 button 对齐 */
a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-sizing: border-box;
}

/* 列表分页：古诗词、古籍等频道共用（上一页 / 第 n 页 / 下一页） */
.site-pager,
.gsc-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 28px auto 8px;
    color: var(--muted);
}

a.btn:hover {
    color: #fff;
    text-decoration: none;
}

/* ---------- 卡片、按钮组 ---------- */
.card {
    background: var(--paper-2);
    border: 1px solid var(--line);
    padding: 20px;
}

.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.card.card-link:hover {
    border-color: var(--azurite);
}

.today-word {
    font-family: var(--font-kai);
    font-size: 2.4rem;
    line-height: 1.2;
    margin: 8px 0;
}

.today-chengyu {
    font-family: var(--font-kai);
    font-size: 1.6rem;
    margin: 8px 0 4px;
}

.riddle-face {
    font-size: 1.25rem;
    margin: 8px 0;
}

.riddle-answer {
    min-height: 1.7em;
    margin: 0 0 12px;
    color: var(--muted);
}

.riddle-answer.is-hidden {
    filter: blur(6px);
    -webkit-user-select: none;
    user-select: none;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 13px;
    letter-spacing: 0.08em;
    color: var(--muted);
}

h1,
h2,
h3 {
    font-weight: 700;
    line-height: 1.3;
}

h1 {
    font-size: clamp(1.6rem, 3vw, 2.1rem);
    margin: 0 0 12px;
}

h2 {
    font-size: 1.25rem;
    margin: 0 0 16px;
}

.lead {
    margin: 0 0 20px;
    color: var(--muted);
}

.pinyin {
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--muted);
}

/* 米字格：用 SVG 画十字与米字斜线，小尺寸也清晰 */
.mige {
    position: relative;
    width: min(72vw, 260px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 2px solid var(--azurite);
    background-color: var(--paper-2);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cline x1='0' y1='50' x2='100' y2='50' stroke='%237aa3b8' stroke-width='1'/%3E%3Cline x1='50' y1='0' x2='50' y2='100' stroke='%237aa3b8' stroke-width='1'/%3E%3Cline x1='0' y1='0' x2='100' y2='100' stroke='%23a8c9d6' stroke-width='0.8'/%3E%3Cline x1='100' y1='0' x2='0' y2='100' stroke='%23a8c9d6' stroke-width='0.8'/%3E%3C/svg%3E");
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.mige__char {
    position: relative;
    z-index: 1;
    font-family: var(--font-kai);
    font-size: clamp(4.5rem, 18vw, 7.5rem);
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
}

.mige--sm {
    width: 72px;
    border-width: 1.5px;
}

.mige--sm .mige__char {
    font-size: 2.4rem;
}

/* ---------- 底栏：素底居中，与顶栏同色、与正文青纸区分 ---------- */
.site-footer {
    border-top: 1px solid var(--line);
    padding: 28px 0;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    background: color-mix(in srgb, var(--paper) 88%, #fff);
}

.footer-inner p {
    margin: 0 0 8px;
}

.footer-copy {
    letter-spacing: 0.12em;
    color: var(--ink);
}

/* ---------- 空状态、提示 ---------- */
.empty {
    padding: 32px 20px;
    background: var(--paper-2);
    border: 1px dashed var(--line);
    color: var(--muted);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(80px);
    padding: 10px 16px;
    background: var(--ink);
    color: #fff;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
    z-index: 80;
}

.toast.is-on {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ---------- Pad ---------- */
@media (min-width: 768px) {
    .wrap {
        width: min(100% - 48px, var(--max));
    }

    .nav-toggle {
        display: none;
    }

    .site-nav {
        display: flex;
        flex-basis: auto;
        flex-direction: row;
        flex: 0 0 auto;
        gap: 4px;
        margin-left: auto; /* 栏目导航靠右 */
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .toast {
        transition: none;
    }

    .nav-toggle__bar {
        transition: none;
    }
}
