:root {
    --gap: 24px;
    --content-gap: 20px;
    --nav-width: 1024px;
    --main-width: 720px;
    --header-height: 60px;
    --footer-height: 60px;
    --radius: 8px;
    --theme: #fff;
    --entry: #fff;
    --primary: rgba(0, 0, 0, 0.88);
    --secondary: rgba(0, 0, 0, 0.56);
    --tertiary: rgba(0, 0, 0, 0.16);
    --content: rgba(0, 0, 0, 0.88);
    --code-bg: #f5f5f5;
    --border: #eee;
    color-scheme: light;
}

html.dark {
    --theme: #1d1e20;
    --entry: #2e2e33;
    --primary: rgba(255, 255, 255, 0.84);
    --secondary: rgba(255, 255, 255, 0.56);
    --tertiary: rgba(255, 255, 255, 0.16);
    --content: rgba(255, 255, 255, 0.74);
    --code-bg: #37383e;
    --border: #333;
    color-scheme: dark;
}

*,
::after,
::before {
    box-sizing: border-box;
}

html {
    -webkit-tap-highlight-color: transparent;
    overflow-y: scroll;
}

a,
button,
body,
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--primary);
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    font-size: 18px;
    line-height: 1.6;
    word-break: break-word;
    background: var(--theme);
    -webkit-font-smoothing: antialiased;
}

body.list {
    background: var(--code-bg);
}

/* 键盘用户跳过导航 */
.skip-link {
    position: absolute;
    top: -100px;
    left: 8px;
    z-index: 100;
    padding: 10px 16px;
    color: var(--theme);
    background: var(--primary);
    border-radius: var(--radius);
    text-decoration: none;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 8px;
}

/* 仅屏幕阅读器可见 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

html.dark body.list {
    background: var(--theme);
}

article,
aside,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
table {
    display: block;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: 1.2;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
    margin-top: 0;
    margin-bottom: 0;
}

ul {
    margin: 0;
    padding: 0;
}

a {
    text-decoration: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--secondary);
    outline-offset: 2px;
}

table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    word-break: normal;
}

button,
input,
textarea {
    padding: 0;
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
}

input,
textarea {
    outline: 0;
}

button,
input[type="button"],
input[type="submit"] {
    cursor: pointer;
}

img {
    display: block;
    max-width: 100%;
}

::-webkit-scrollbar {
    width: 19px;
    height: 11px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

body.list::-webkit-scrollbar-track {
    background: var(--code-bg);
}

html.dark body.list::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--tertiary);
    border: 5px solid var(--theme);
    border-radius: var(--radius);
}

body.list::-webkit-scrollbar-thumb {
    border-color: var(--code-bg);
}

html.dark body.list::-webkit-scrollbar-thumb {
    border-color: var(--theme);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

/* 导航 */
.header {
    background: transparent;
}

.nav {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    max-width: calc(var(--nav-width) + var(--gap) * 2);
    margin-inline-start: auto;
    margin-inline-end: auto;
    line-height: var(--header-height);
}

.nav a {
    display: block;
}

.logo,
#menu {
    display: flex;
    margin: auto var(--gap);
}

.logo {
    flex-wrap: inherit;
}

.logo a {
    font-size: 24px;
    font-weight: 700;
}

.logo a img {
    display: inline;
    vertical-align: middle;
    pointer-events: none;
    transform: translate(0, -10%);
    border-radius: 6px;
    margin-inline-end: 8px;
}

.logo-switches {
    display: inline-flex;
    flex-wrap: inherit;
    margin: auto 4px;
}

#theme-toggle {
    margin: auto 4px;
    font-size: 26px;
    line-height: 1;
}

/* 移动端菜单按钮 */
.menu-toggle {
    display: none;
    margin: auto 4px;
    line-height: 1;
}

.menu-toggle svg {
    display: block;
    width: 20px;
    height: 20px;
}

#theme-toggle svg {
    display: block;
    width: 18px;
    height: 18px;
}

html.dark #moon {
    display: none;
}

html:not(.dark) #sun {
    display: none;
}

#theme-toggle:focus-visible {
    border-radius: 4px;
}

#menu {
    list-style: none;
    word-break: keep-all;
    overflow-x: auto;
    white-space: nowrap;
    padding: 0;
    scrollbar-width: none;
}

#menu::-webkit-scrollbar {
    display: none;
}

#menu li + li {
    margin-inline-start: var(--gap);
}

#menu a {
    font-size: 16px;
}

#menu .active {
    font-weight: 500;
    border-bottom: 2px solid;
}

/* 主体 */
.main {
    position: relative;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    min-height: calc(100dvh - var(--header-height) - var(--footer-height));
    max-width: calc(var(--main-width) + var(--gap) * 2);
    margin: auto;
    padding: var(--gap);
}

/* 首页信息 */
.first-entry {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 320px;
    margin: var(--gap) 0 calc(var(--gap) * 2);
}

.first-entry .entry-header {
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.home-info .entry-header,
.home-info .entry-content {
    display: block;
    overflow: visible;
    -webkit-line-clamp: unset;
}

.first-entry .entry-header h1 {
    font-size: 34px;
    line-height: 1.3;
}

.first-entry .entry-content {
    margin: 14px 0;
    color: var(--secondary);
    font-size: 16px;
    -webkit-line-clamp: 3;
}

.first-entry .entry-footer {
    font-size: 14px;
}

.social-icons {
    padding: 12px 0;
}

.social-icons a:not(:last-of-type) {
    margin-inline-end: 12px;
}

.social-icons a svg {
    height: 26px;
    width: 26px;
}

/* 文章列表卡片 */
.post-entry {
    position: relative;
    margin-bottom: var(--gap);
    padding: var(--gap);
    background: var(--entry);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: transform 0.1s;
}

.post-entry:active {
    transform: scale(0.96);
}

.entry-header h2 {
    margin: 0;
    font-size: 24px;
}

.entry-content {
    margin: 8px 0;
    color: var(--secondary);
    font-size: 14px;
    line-height: 1.6;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.entry-content p {
    margin: 0;
}

.entry-footer {
    color: var(--secondary);
    font-size: 13px;
}

.entry-link {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    border-radius: var(--radius);
}

.entry-link:focus-visible {
    outline: 2px solid var(--secondary);
    outline-offset: 2px;
}

.post-entry:hover {
    border-color: var(--tertiary);
}

/* 归档页头 */
.page-header,
.post-header {
    margin: 24px auto var(--content-gap);
}

.page-header h1 {
    font-size: 40px;
}

/* 单篇文章 */
.post-title {
    margin-bottom: 2px;
    font-size: 40px;
}

.post-meta,
.breadcrumbs {
    color: var(--secondary);
    font-size: 14px;
    display: flex;
    flex-wrap: wrap;
}

.breadcrumbs a {
    font-size: 16px;
}

.post-content {
    color: var(--content);
}

.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
    margin: 24px 0 16px;
}

.post-content h1 {
    margin: 40px auto 32px;
    font-size: 40px;
}

.post-content h2 {
    margin: 32px auto 24px;
    font-size: 32px;
}

.post-content h3 {
    font-size: 24px;
}

.post-content h4 {
    font-size: 16px;
}

.post-content h5 {
    font-size: 14px;
}

.post-content h6 {
    font-size: 12px;
}

.post-content a,
.toc a:hover {
    box-shadow: 0 1px 0 var(--primary);
}

.post-content a code {
    margin: auto 0;
    border-radius: 0;
    box-shadow: 0 -1px 0 var(--primary) inset;
}

.post-content del {
    text-decoration: none;
    background: linear-gradient(to right, var(--primary) 100%, transparent 0) 0/1px 1px repeat-x;
}

.post-content dl,
.post-content ol,
.post-content p,
.post-content figure,
.post-content ul {
    margin-bottom: var(--content-gap);
}

.post-content ol,
.post-content ul {
    padding-inline-start: 20px;
}

.post-content li {
    margin-top: 5px;
}

.post-content li p {
    margin-bottom: 0;
}

.post-content dl {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
}

.post-content dt {
    width: 25%;
    font-weight: 700;
}

.post-content dd {
    width: 75%;
    margin-inline-start: 0;
    padding-inline-start: 10px;
}

.post-content dd ~ dd,
.post-content dt ~ dt {
    margin-top: 10px;
}

.post-content table {
    display: block;
    width: 100%;
    margin-bottom: 32px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.post-content table th,
.post-content table:not(.highlighttable, .highlight table, .gist .highlight) td {
    min-width: 80px;
    padding: 12px 8px;
    line-height: 1.5;
    border-bottom: 1px solid var(--border);
}

.post-content table th {
    font-size: 14px;
    text-align: start;
}

.post-content code {
    direction: ltr;
    margin: auto 4px;
    padding: 4px 6px;
    font-size: 0.78em;
    line-height: 1.5;
    background: var(--code-bg);
    border-radius: 2px;
}

.post-content pre {
    position: relative;
    margin: 10px auto;
    padding: 10px;
    background: #1c1d21;
    border-radius: var(--radius);
    overflow-x: auto;
}

.post-content pre code {
    display: block;
    margin: auto 0;
    padding: 0;
    color: rgba(255, 255, 255, 0.8);
    background: transparent;
    border-radius: 0;
    word-break: normal;
}

.post-content blockquote {
    margin: 20px 0;
    padding: 0 14px;
    border-inline-start: 3px solid var(--primary);
}

.post-content hr {
    margin: 30px 0;
    height: 2px;
    background: var(--tertiary);
    border-top: 0;
    border-bottom: 0;
}

.post-content iframe {
    max-width: 100%;
}

.post-content img {
    border-radius: 4px;
    margin: 1rem 0;
}

.post-content img[src*="#center"] {
    margin: 1rem auto;
}

.post-content figure.align-center {
    text-align: center;
}

.post-content figure > figcaption {
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
    margin: 8px 0 16px;
}

.post-content figure > figcaption > p {
    color: var(--secondary);
    font-size: 14px;
    font-weight: 400;
}

/* 标签与上下篇 */
.post-footer {
    margin-top: 56px;
}

.post-tags {
    list-style: none;
    padding: 0;
}

.post-tags li {
    display: inline-block;
    margin-inline-end: 3px;
    margin-bottom: 5px;
}

.post-tags a {
    display: block;
    padding-inline-start: 14px;
    padding-inline-end: 14px;
    color: var(--secondary);
    font-size: 14px;
    line-height: 34px;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.post-tags a:hover {
    background: var(--border);
}

.paginav {
    display: flex;
    gap: 12px;
    margin: 24px 0 10px;
    padding: 12px;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.paginav-item {
    width: 50%;
    padding: 2px 6px;
    font-size: 14px;
    line-height: 1.6;
}

.paginav-item.next {
    margin-inline-start: auto;
    text-align: right;
}

.paginav .title {
    letter-spacing: 1px;
    text-transform: uppercase;
    font-size: small;
    color: var(--secondary);
}

.paginav a {
    display: block;
    color: var(--primary);
}

.paginav a:hover {
    box-shadow: 0 1px 0 var(--primary);
}

/* 分页 */
.page-navigator {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 20px 0;
    padding: 0;
    list-style: none;
}

.page-navigator li a,
.page-navigator li span {
    display: block;
    padding: 0 14px;
    font-size: 13px;
    line-height: 34px;
    color: var(--secondary);
    background: var(--entry);
    border: 1px solid var(--border);
    border-radius: 17px;
}

.page-navigator li a:hover {
    background: var(--border);
}

.page-navigator li.current a,
.page-navigator li.current span {
    color: var(--theme);
    background: var(--primary);
    border-color: var(--primary);
}

/* 标签云 */
.terms-tags {
    list-style: none;
    padding: 0;
}

.terms-tags li {
    display: inline-block;
    margin: 10px;
    font-weight: 500;
}

.terms-tags a {
    display: block;
    padding: 3px 10px;
    background: var(--tertiary);
    border-radius: 6px;
    transition: transform 0.1s;
}

.terms-tags a:active {
    transform: scale(0.96);
}

.empty-state {
    color: var(--secondary);
}

/* 评论 */
.comments {
    margin-top: 56px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.comments-title,
.comment-reply-title {
    margin-bottom: 20px;
    font-size: 22px;
}

.comment-list {
    list-style: none;
    padding: 0;
    margin-bottom: 32px;
}

.comment-list .comment-list,
.comment-children .comment-list {
    padding-inline-start: 24px;
}

.comment-body {
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}

.comment-author {
    display: flex;
    align-items: center;
    gap: 10px;
    font-style: normal;
    font-size: 15px;
    font-weight: 600;
}

.comment-author img {
    border-radius: 50%;
}

.comment-author cite {
    font-style: normal;
}

.comment-meta {
    margin: 4px 0 8px;
    font-size: 13px;
    color: var(--secondary);
}

.comment-content {
    color: var(--content);
    font-size: 16px;
}

.comment-content p {
    margin-bottom: 10px;
}

.comment-reply {
    margin-top: 8px;
    font-size: 13px;
}

.comment-reply a {
    color: var(--secondary);
    border-bottom: 1px solid var(--tertiary);
}

.comment-reply a:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.comment-awaiting-moderation {
    color: var(--secondary);
    font-size: 13px;
    font-style: normal;
}

.cancel-comment-reply {
    margin-bottom: 12px;
    font-size: 14px;
}

.cancel-comment-reply a {
    color: var(--secondary);
}

.comment-form p {
    margin-bottom: 16px;
}

.comment-form-row {
    display: flex;
    gap: 16px;
}

.comment-form-row p {
    flex: 1;
    min-width: 0;
}

.comment-form label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--secondary);
}

.comment-form .required {
    color: var(--secondary);
}

.comment-form input[type="text"],
.comment-form input[type="email"],
.comment-form input[type="url"],
.comment-form textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}

.comment-form input:focus,
.comment-form textarea:focus {
    border-color: var(--secondary);
}

.comment-form textarea {
    resize: vertical;
    min-height: 120px;
}

.form-submit {
    margin-bottom: 0;
}

.comment-form .submit {
    padding: 0 20px;
    line-height: 38px;
    font-size: 14px;
    color: var(--theme);
    background: var(--primary);
    border-radius: 19px;
    transition: opacity 0.15s;
}

.comment-form .submit:hover {
    opacity: 0.8;
}

.logged-in-as {
    font-size: 14px;
    color: var(--secondary);
}

/* 页脚 */
.footer,
.top-link {
    font-size: 12px;
    color: var(--secondary);
}

.footer {
    max-width: calc(var(--main-width) + var(--gap) * 2);
    margin: auto;
    padding: calc((var(--footer-height) - var(--gap)) / 2) var(--gap);
    text-align: center;
    line-height: 24px;
}

.footer span {
    display: block;
    margin-inline-start: 1px;
    margin-inline-end: 1px;
}

.footer a {
    color: inherit;
    border-bottom: 1px solid var(--secondary);
}

.footer a:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* 回到顶部 */
.top-link {
    visibility: hidden;
    display: block;
    position: fixed;
    bottom: 60px;
    right: 30px;
    z-index: 99;
    width: 42px;
    height: 42px;
    padding: 12px;
    background: var(--tertiary);
    border-radius: 64px;
    opacity: 0;
    transition: visibility 0.5s, opacity 0.8s linear;
}

.top-link svg {
    display: block;
    width: 100%;
    height: auto;
}

.top-link:hover {
    color: var(--primary);
}

/* 404 */
.not-found {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: calc(100vh - var(--header-height) - var(--footer-height) - var(--gap) * 2);
    min-height: calc(100dvh - var(--header-height) - var(--footer-height) - var(--gap) * 2);
    text-align: center;
}

.not-found h1 {
    margin: 0;
    font-size: clamp(88px, 22vw, 160px);
    font-weight: 700;
    line-height: 1.1;
}

.not-found p {
    margin: 0;
    color: var(--secondary);
}

.not-found-home {
    margin-top: 12px;
    padding: 0 18px;
    line-height: 38px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 19px;
}

.not-found-home:hover {
    background: var(--tertiary);
}

@media screen and (max-width: 768px) {
    :root {
        --gap: 14px;
    }

    .nav {
        flex-wrap: nowrap;
    }

    html.js .menu-toggle {
        display: block;
    }

    html.js #menu {
        display: none;
        position: absolute;
        top: var(--header-height);
        left: 8px;
        right: 8px;
        z-index: 20;
        flex-direction: column;
        margin: 0;
        padding: 8px var(--gap) 12px;
        overflow: visible;
        line-height: 1.6;
        background: var(--entry);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    }

    html.js #menu.open {
        display: flex;
    }

    html.js #menu li + li {
        margin-inline-start: 0;
    }

    html.js #menu a {
        padding: 10px 4px;
    }

    .first-entry {
        min-height: 260px;
    }

    .post-title,
    .page-header h1 {
        font-size: 32px;
    }

    .entry-header h2 {
        font-size: 20px;
    }

    .paginav {
        flex-direction: column;
    }

    .paginav-item {
        width: 100%;
    }

    .comment-form-row {
        flex-direction: column;
        gap: 0;
    }

    .post-content h1,
    .post-content h2 {
        font-size: 26px;
    }

    .footer {
        padding: calc((var(--footer-height) - var(--gap) - 10px) / 2) var(--gap);
    }

    .footer span {
        white-space: normal;
    }
}

@media screen and (max-width: 900px) {
    body.list .top-link {
        transform: translateY(-5rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .terms-tags a:active,
    .post-entry:active,
    .top-link {
        transform: none;
        transition: none;
    }
}
