/* Global base styles extracted from templates/base.html (S681).
   Verbatim from the original inline <style> blocks, order preserved.
   a[href="/publications/"] is the literal of url_for('personal.publications'). */
        :root {
            --bg: #F8FAFC;
            --text: #1E293B;
            /* S434: light-mode accent = blue-600 (#2563EB, 4.55:1) — the old
               #3B82F6 (3.52:1) failed WCAG AA for text/borders on light surfaces.
               Dark mode keeps the lighter --accent (#60A5FA) below. */
            --accent: #2563EB;
            --surface: #FFFFFF;
            --muted: #4B5563;
            --border: #E2E8F0;
        }
        /* ── Dark mode overrides ── */
        html.dark {
            --bg: #0F172A;
            --text: #F1F5F9;
            --accent: #60A5FA;
            --surface: #1E293B;
            --muted: #B0BEC5;
            --border: #334155;
        }
        /* Dark mode: glass-nav adaptation */
        html.dark .glass-nav {
            background: rgba(30, 41, 59, 0.72);
            border-bottom: 1px solid rgba(51, 65, 85, 0.6);
        }
        html.dark .glass-nav.scrolled {
            background: rgba(30, 41, 59, 0.95);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        }
        /* Dark mode: visitor counter glass */
        html.dark .visitor-counter-glass {
            background: rgba(96, 165, 250, 0.1);
            border: 1px solid rgba(96, 165, 250, 0.2);
        }
        html.dark .visitor-counter-glass:hover {
            background: rgba(96, 165, 250, 0.16);
            border-color: rgba(96, 165, 250, 0.35);
            box-shadow: 0 0 20px rgba(96, 165, 250, 0.15);
        }
        /* Dark mode: footer */
        html.dark .site-footer {
            background: var(--surface);
            border-top: 1px solid var(--border);
        }
        /* Footer readability: brighter text + larger font in dark mode */
        html.dark .site-footer,
        html.dark .site-footer a,
        html.dark .site-footer p,
        html.dark .site-footer span {
            font-size: 1rem;
        }
        html.dark .site-footer a,
        html.dark .site-footer p {
            color: #d1d5db;
        }
        html.dark .site-footer a:hover {
            color: #60a5fa;
        }
        /* Smooth theme transition */
        html {
            transition: color 0.3s ease, background-color 0.3s ease;
        }
        html *, html *::before, html *::after {
            transition: background-color 0.3s ease, border-color 0.3s ease, color 0.2s ease, box-shadow 0.3s ease;
        }
        /* Disable transitions on page load to prevent initial flash */
        html.no-transition,
        html.no-transition *,
        html.no-transition *::before,
        html.no-transition *::after {
            transition: none !important;
        }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        /* S484: overflow-x 必须用 clip 而非 hidden —— hidden 会让 html/body 成为滚动容器，
           Chromium 下其后代的 position: sticky 会全部失效（publications 筛选栏 / #rd-toc /
           about 侧栏 / blog 侧栏）。clip 不创建滚动容器，横向裁切效果等价。
           首行 hidden 作为老浏览器（不支持 clip）的降级，支持 clip 的浏览器由第二行覆盖。 */
        html { overflow-x: hidden; overflow-x: clip; }
        /* S111: Prevent fixed navbar (~64px) from covering anchor targets on all pages */
        main [id] { scroll-margin-top: 5rem; }
        body {
            /* S510: CJK family is language-scoped via --font-cjk (fonts.css):
               zh -> 'Noto Sans SC' (302 KB subset), en -> 'cjk-micro' (18.6 KB
               subset cut from the same Noto source).  Both key off data-lang,
               which the server renders and the pre-paint script above re-applies
               from localStorage, so URL and stored language never disagree. */
            font-family: 'Inter', var(--font-cjk), system-ui, -apple-system, sans-serif;
            background-color: transparent;
            color: var(--text);
            line-height: 1.6;
            min-height: 100vh;
            /* S484: 同 html 规则，overflow-x 用 clip 以免 body 成为滚动容器导致后代 sticky 失效 */
            overflow-x: hidden;
            overflow-x: clip;
            width: 100%;
        }
        /* Glass-morphism navbar */
        .glass-nav {
            background: rgba(255, 255, 255, 0.72);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            border-bottom: 1px solid rgba(226, 232, 240, 0.6);
            transition: background 0.3s ease, box-shadow 0.3s ease;
        }
        .glass-nav.scrolled {
            background: rgba(255, 255, 255, 0.95);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }
        .nav-link {
            position: relative;
            transition: color 0.2s ease;
        }
        .nav-link::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: var(--accent);
            transition: width 0.3s ease;
        }
        .nav-link:hover::after,
        .nav-link.active::after {
            width: 100%;
        }
        .nav-link.active {
            color: var(--accent);
        }
        /* Footer */
        .site-footer {
            background: var(--surface);
            border-top: 1px solid var(--border);
        }
        /* Parallax starfield layers
           S471: z-index MUST stay negative. With body/main `position: static`, a fixed
           layer at z-index >= 0 paints ABOVE in-flow text (CSS paint order) and hides
           glyphs — proven with a 24x24 probe square. body's background propagates to the
           canvas (html has no background), so z-index:-1 still renders the particles
           above the page background while keeping every glyph on top. */
        .starfield-layer {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: -1;
            will-change: opacity;
        }

        /* S473 / S476: stretched-link — a card marked `relative` becomes fully clickable
           through its inner anchor's ::after overlay. The anchor stays the single real
           link (visible text cue + keyboard focusable). */
        .stretched-link::after {
            content: '';
            position: absolute;
            inset: 0;
            z-index: 1;
        }

        /* S434: Tailwind's `accent` token is a fixed hex (#3B82F6 = 3.52:1 on light
           surfaces, below WCAG AA), so in LIGHT mode only, darken the accent TEXT classes
           to blue-600 (#2563EB = 4.55:1). Dark mode keeps blue-400/--accent. */
        html:not(.dark) [class~="text-accent"],
        html:not(.dark) [class~="hover:text-accent"]:hover,
        html:not(.dark) .group:hover [class~="group-hover:text-accent"] {
            color: #2563EB;
        }

        /* S554（用户裁定：浅色 + 深色**一起**收口）: S434 只收了 accent 的「文字」类，本条收口
           accent 的「填充面」—— 三处 `bg-accent`(#3B82F6) + 白字是同一批元素里唯二失守的白字面：
           ① 首页主 CTA「查看论文」（a[href="/publications/"]，16px/500）② 跳过导航链接（.skip-link，
           14px/500，仅键盘 focus 可见也要达标）③ Logo 方块「LY」（.glass-nav 内，14px/700）。
           改前白字实测 3.68:1 < WCAG AA 4.5:1（14–16px，不适用大字豁免），hover 态 hover:bg-accent-dark
           反而是 5.17:1 —— 即「静止不达标、悬浮达标」，故只需抬升静止面。

           精确命中（[class~=] 只做整词匹配）：`bg-accent/10`、`bg-accent/20`、`bg-accent/5`、
           `hover:bg-accent`、`group-hover:bg-accent`、`dark:bg-blue-400` 都是不同令牌，全部不受影响；
           全站其余 bg-accent 装饰性填充（首页进度条 / 圆点 / .blog-tag-btn 芯片 / bibtex 按钮）
           无需改动（部分已由 S434/S547b/S560 单独收口）—— 见 S554 验收的 bg-accent 全站普查。

           浅色：#2563EB（blue-600，= S434 的浅色 --accent）+ 白字 = 5.17:1。
           深色：#60A5FA（blue-400，= 深色 --accent，与站点既有 dark:bg-blue-400 语言一致）作填充面
                 + 文字改用深色 #0F172A（= 深色 --bg）= 7.03:1。**不**沿用 #2563EB 的理由：
                 #2563EB 在 #0F172A 页面上只有 3.46:1 的面/页分离度、按钮发闷压暗（旧观感），
                 而亮蓝 + 深字既满足 ≥4.5:1，又保住「亮蓝按钮」的深色观感。
           :hover 显式抬/压一档（浅色 blue-700 / 深色 blue-300）—— 否则新的浅色静止面与原有
           hover:bg-accent-dark 同色，会让全站最显眼的按钮失去 hover 反馈。 */
        html:not(.dark) [class~="skip-link"],
        html:not(.dark) .glass-nav [class~="bg-accent"],
        html:not(.dark) a[href="/publications/"][class~="bg-accent"] {
            background-color: #2563EB !important;
        }
        html:not(.dark) a[href="/publications/"][class~="bg-accent"]:hover {
            background-color: #1D4ED8 !important;
        }
        html.dark [class~="skip-link"],
        html.dark .glass-nav [class~="bg-accent"],
        html.dark a[href="/publications/"][class~="bg-accent"] {
            background-color: #60A5FA !important;
            color: #0F172A !important;
        }
        html.dark a[href="/publications/"][class~="bg-accent"]:hover {
            background-color: #93C5FD !important;
        }

        /* ===== S607 + S618 + S641（第 1 轮第 1 单，用户全批）=====
           把 S554 已批准的 accent 口径补齐到 S554 选择器集**未覆盖**的其余「实心 accent +
           白字」面，以及 `text-accent` / `hover:text-accent-dark` 的悬停零变化。

           口径（S554，用户已批准，本单沿用、不另立新值）：
             浅色：填充 #2563EB + 白字 = 5.17:1；hover #1D4ED8 + 白字 = 6.70:1
             深色：填充 #60A5FA + 深字 #0F172A = 7.02:1；hover #93C5FD + #0F172A = 9.02:1

           覆盖面（10-18 全站普查；改前白字实测浅 3.68 / 深 2.54:1）：
             · /publications/ #export-all-bibtex、.bibtex-copy、「重置全部」空态按钮
             · /awards/ 空态「清除筛选」按钮
             · /blog/ button.blog-tag-btn（JS 激活态追加 bg-accent text-white）
             · /blog/ 激活语言胶囊 .blog-lang-switcher a.active-lang
               （深色原为 #60A5FA + 白 = 2.54:1，是本批最差的一个面）
             · /research/* TOC 激活胶囊 .rd-toc-link.active
             · 404 返回首页 CTA
             · /about/ 图标圆底、/research/* emoji 圆底（同为 bg-accent + text-white，纯色值统一）

           精确命中（[class~=] 只做**整词**匹配）：`bg-accent/10`、`bg-accent/20`、
           `bg-accent/5`、`hover:bg-accent`、`group-hover:bg-accent`、`bg-accent-dark` 都是
           不同 class 令牌，一律不命中；首页进度条 / 圆点等**装饰性** bg-accent 没有
           text-white 兄弟令牌，同样不被波及（验收已实测改前=改后）。
           hover 显式抬/压一档，避免重演 S554 的「新静止色 == 旧 hover 色」丢反馈。 */
        html:not(.dark) [class~="bg-accent"][class~="text-white"],
        html:not(.dark) .blog-lang-switcher a.active-lang,
        html:not(.dark) .rd-toc-link.active {
            background-color: #2563EB !important;
            color: #FFFFFF !important;
            border-color: #2563EB !important;
        }
        html:not(.dark) [class~="bg-accent"][class~="text-white"]:hover,
        html:not(.dark) .blog-lang-switcher a.active-lang:hover,
        html:not(.dark) .rd-toc-link.active:hover {
            background-color: #1D4ED8 !important;
            color: #FFFFFF !important;
            border-color: #1D4ED8 !important;
        }
        html.dark [class~="bg-accent"][class~="text-white"],
        html.dark .blog-lang-switcher a.active-lang,
        html.dark .rd-toc-link.active {
            background-color: #60A5FA !important;
            color: #0F172A !important;
            border-color: #60A5FA !important;
        }
        html.dark [class~="bg-accent"][class~="text-white"]:hover,
        html.dark .blog-lang-switcher a.active-lang:hover,
        html.dark .rd-toc-link.active:hover {
            background-color: #93C5FD !important;
            color: #0F172A !important;
            border-color: #93C5FD !important;
        }

        /* S641：`text-accent` + `hover:text-accent-dark` 悬停色零变化（10-08 记为 17 处可见
           元素，当前模板命中 23 处 class 组合）。根因：浅色 S434 已把静止态强制为 #2563EB，
           而 Tailwind `accent-dark` 令牌值恰好也是 #2563EB → 静止 == hover，悬停无任何反馈；
           深色态 `dark:text-blue-400`(#60A5FA) 的 hover 落到 #2563EB，对 #0F172A 仅 3.46:1。
           统一 hover 一档：浅 #1D4ED8（白 6.70 / #F8FAFC 6.22:1）、深 #93C5FD（#0F172A 9.02:1）。
           两个态均 ≥4.5:1，且与各自静止态可辨（ΔL > 0.05）。 */
        html:not(.dark) [class~="text-accent"][class~="hover:text-accent-dark"]:hover {
            color: #1D4ED8 !important;
        }
        html.dark [class~="hover:text-accent-dark"]:hover {
            color: #93C5FD !important;
        }

        /* Language-specific visibility for keyword tags */
        html[data-lang="zh"] .lang-en { display: none !important; }
        html[data-lang="en"] .lang-zh { display: none !important; }

        /* S492: hero 姓名改为「单一 h1 容器 + 双语 span」后，字号/字重挂在容器 .hero-name 上并按
           html[data-lang] 切换（span 只负责语言可见性）。数值与原 Tailwind 类逐项一致：
           zh = text-2xl / sm:text-3xl + font-light；en = text-5xl / sm:text-6xl / lg:text-7xl + font-bold。
           目的：h1 自身 computed font-size 与改造前可见姓名一致（zh 30px / en 72px @≥1024px），零视觉变化。 */
        html[data-lang="zh"] .hero-name { font-size: 1.5rem; line-height: 2rem; font-weight: 300; }
        html[data-lang="en"] .hero-name { font-size: 3rem; line-height: 1; font-weight: 700; }
        @media (min-width: 640px) {
            html[data-lang="zh"] .hero-name { font-size: 1.875rem; line-height: 2.25rem; }
            html[data-lang="en"] .hero-name { font-size: 3.75rem; line-height: 1; }
        }
        @media (min-width: 1024px) {
            html[data-lang="en"] .hero-name { font-size: 4.5rem; line-height: 1; }
        }

        /* Visitor counter card — glass morphism */
        .visitor-counter-glass {
            display: inline-flex;
            position: relative;
            align-items: center;
            gap: 0.5rem;
            padding: 0.5rem 1.25rem;
            background: rgba(59, 130, 246, 0.08);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border: 1px solid rgba(59, 130, 246, 0.2);
            border-radius: 9999px;
            font-size: 0.875rem;
            color: var(--text);
            transition: all 0.3s ease;
        }
        .visitor-counter-glass:hover {
            background: rgba(59, 130, 246, 0.14);
            border-color: rgba(59, 130, 246, 0.35);
            box-shadow: 0 0 20px rgba(59, 130, 246, 0.10);
        }
        .visitor-counter-label {
            color: var(--muted);
            font-weight: 400;
        }
        .visitor-counter-divider {
            color: var(--border);
            font-weight: 300;
        }
        .visitor-counter-number {
            font-weight: 700;
            color: var(--accent);
            font-variant-numeric: tabular-nums;
            /* S563（方案 B）：SSR 中性占位「—」宽 16px，真实值「7,983」宽 45.67px ——
               预留宽度须 ≥ 真实值，否则 JS 回填瞬间计数器卡片会被撑宽 ~5.7px（横向 CLS）。
               实测（14px/700/tabular-nums）：1ch=9.05px、逗号≈1.19ch，4 位数字+千分位 = 45.67px，
               故 2.9rem(46.4px) 恰好覆盖整个 4 位区间（0–9,999），占位与回填几何完全一致、零抖动；
               同时与改前「JS 回填后」的稳态宽度只差 0.73px（视觉不可辨，保持零观感变化）。
               不取更宽的 6.2ch(56px)：那会让计数器药丸对所有访客可见变宽 ~10px（观感变化更大）。 */
            min-width: 2.9rem;
            text-align: center;
        }
        /* S451: 统计口径 info 按钮 + tooltip（hover / 键盘 focus 触发，读屏经 aria-describedby） */
        .visitor-info-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            padding: 0;
            margin-left: 0.05rem;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: var(--muted);
            cursor: pointer;
            transition: color 0.2s ease, background 0.2s ease;
        }
        .visitor-info-btn svg { width: 14px; height: 14px; }
        .visitor-info-btn:hover { color: var(--accent); background: rgba(59, 130, 246, 0.12); }
        .visitor-info-btn:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: 2px;
            color: var(--accent);
        }
        .visitor-scope-tip {
            position: absolute;
            bottom: calc(100% + 10px);
            left: 50%;
            transform: translateX(-50%);
            width: max-content;
            max-width: min(88vw, 340px);
            padding: 0.5rem 0.75rem;
            border-radius: 8px;
            background: #1E293B;
            color: #F1F5F9;
            font-size: 0.75rem;
            line-height: 1.5;
            font-weight: 400;
            text-align: left;
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
            transition: opacity 0.2s ease, visibility 0.2s ease;
            z-index: 60;
        }
        .visitor-scope-tip::after {
            content: '';
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            border: 6px solid transparent;
            border-top-color: #1E293B;
        }
        html.dark .visitor-scope-tip {
            background: #0F172A;
            color: #E2E8F0;
            border: 1px solid rgba(148, 163, 184, 0.25);
        }
        html.dark .visitor-scope-tip::after { border-top-color: #0F172A; }
        .visitor-info-btn:hover ~ .visitor-scope-tip,
        .visitor-info-btn:focus-visible ~ .visitor-scope-tip {
            opacity: 1;
            visibility: visible;
        }
        /* S685: Esc 关闭（WCAG 1.4.13 可撤销）—— 临时抑制类由下方内联脚本按需增删；
           仅覆盖「当前已打开」的浮层，blur / mouseleave 即移除，后续 hover/focus 照常打开。 */
        html.visitor-tip-suppressed .visitor-info-btn:hover ~ .visitor-scope-tip,
        html.visitor-tip-suppressed .visitor-info-btn:focus-visible ~ .visitor-scope-tip {
            opacity: 0;
            visibility: hidden;
        }

/* Back-to-top button (was an inline block in <body>; no other rule targets it) */
        /* S466: 不可见基态必须同时 visibility:hidden — 否则 opacity:0 的 fixed 按钮
           仍留在 Tab 顺序里（键盘/读屏会落在看不见的控件上）。visibility 计入 transition，
           保证淡出过程（visible→hidden 在过渡结束时才切换）与原先完全一致，
           淡入时立即可见再走 opacity。 */
        [data-back-to-top].is-visible { opacity: 1 !important; visibility: visible !important; transform: translateY(0) !important; pointer-events: auto !important; }
        [data-back-to-top]:hover { 
            background: #2563EB !important; 
            box-shadow: 0 8px 24px rgba(59,130,246,0.5) !important;
        }
        /* WCAG 1.4.11 非文本对比度：深色态按钮填充 #60A5FA 上 white 图标仅 2.54:1（<3:1）。
           对齐站内 S554 决策：深色填充维持 #60A5FA、图标改 #0F172A（深色页底色，7.03:1），
           深色 hover 用 #93C5FD。浅色态（#2563EB + white）及浅色 hover（#2563EB）保持不变。
           该按钮用内联 style + var(--accent)，S554 的类选择器当初未覆盖到它，本次补齐。 */
        html.dark [data-back-to-top] {
            background-color: #60A5FA !important;
            color: #0F172A !important;
        }
        html.dark [data-back-to-top]:hover {
            background-color: #93C5FD !important;
        }
        [data-back-to-top]:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: 3px;
        }
        @media (max-width: 640px) {
            [data-back-to-top] { right: 16px !important; bottom: 28px !important; }
        }
