* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* font-family: "Times New Roman", "Microsoft YaHei", "Sans Serif"; */
    -webkit-tap-highlight-color: transparent;
    /* color: #808080; */
}

html {
    overflow-anchor: none;
    scroll-padding-top: calc(var(--topbar-h) + 1rem);
}

#btn {
    display: none;
}

a {
    text-decoration: none;
    display: inline-block;
    vertical-align: text-top;
    max-width: calc(100vw - 30px);
    overflow-x: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

hr {
    width: 100%;
    margin: 0;
    height: 1px;
    background-color: #808080;
    border: none;
}

.bold {
    font-weight: 500;
    /* font-size: large; */
}

pre {
    margin: 1rem 0;
    padding: 1rem;
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
    max-height: 50vh;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    background-color: #fcfcfc;
}

/* 以上为全局元素样式 */

.top {
    display: flex;
    flex-direction: column;
    /* background-color: rgb(250, 250, 250); */
    background-color: #fff;
    padding: .4rem .8rem;
    border-bottom: 1px solid rgb(230, 230, 230);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar {
    display: flex;
    align-items: center;
    /* margin-top: 2px; */
    /* transform: translateX(8rem); */
    margin-left: 8rem;
    /* transition: margin-left 0.25s ease; */
}

.description {
    margin-left: 2rem;
    margin-right: auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    /* overflow: auto; */
}

.search {
    font-size: 14px;
    color: #808080;
    margin-left: auto;
    margin-right: 2rem;
    width: 30%;
    max-width: 300px;
    padding: 0.2rem 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: calc(14px + 1em);
}

.search svg {
    margin-right: 0.2rem;
}

.user {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.user-img {
    width: 30px;
    border-radius: 100%;
    border: 3px solid #e0e0e0;
    /* margin: 1rem 0.5rem; */
}

.user i {
    color: black;
    margin-left: auto;
}

.top ul {
    display: flex;
    flex: 1;
    margin-top: 0.4rem;
    margin-left: 6rem;
    margin-right: 2rem;
    /* overflow-x: hidden; */
    overflow-y: hidden;
    max-height: 50px;
    transition: max-height 0.25s ease, margin 0.25s ease, opacity 0.2s ease;
    opacity: 1;
}

body.resizing .top ul {
    transition: none;
}

.top.nav-collapsed ul {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
}

.top ul li {
    position: relative;
    list-style-type: none;
    height: 30px;
    padding-left: 1rem;
    /* width: 90%; */
}

.top ul a {
    color: #808080;
    display: flex;
    padding: 0.1rem 0.6rem;
    align-items: center;
    justify-content: flex-start;
    border-radius: 0.8rem;
    height: inherit;
}

.top ul a.active {
    background-color: #e0e0e0;
}

@media (hover: hover) and (pointer: fine) {
    .top ul a:hover {
        background-color: #f0f0f0;
    }

    .top ul a.active:hover {
        background-color: #e0e0e0;
    }
}

.top ul .divider {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 10px;
}

.top ul a svg {
    text-align: center;
    border-radius: 12px;
    margin-right: 0.5rem;
    /* margin-left: 2rem; */
}

.top .nav-item {
    white-space: nowrap;
}

/* 以上为顶部栏样式 */

.container {
    display: grid;
    grid-template-columns: 
        [left-start] 250px 
        [left-end content-start] 1fr 
        [content-end right-start] 250px 
        [right-end];
    gap: 10px;
    width: 100%;
    background-color: rgb(250, 250, 250);
    min-height: 100vh;
}

/* 主内容区 */

.main-content {
    grid-column: content-start / content-end;
}

.sidebar-left {
    grid-column: left-start / left-end;
}

.sidebar-right {
    grid-column: right-start / right-end;
}

.sidebar-left, .sidebar-right {
    padding-top: 1rem;
    position: sticky;
    top: var(--topbar-h, 0px);
    align-self: start;               /* 让它按内容高度显示，而不是被拉伸到跟主内容一样高 */
    max-height: calc(100vh - var(--topbar-h, 0px) - 1rem);
    overflow-y: auto;
}

/* 桌面端默认不显示手机端专属的这些元素 */
.left-sidebar-toggle,
.toc-dashes {
    display: none;
}

.toc-list {
    display: flex;
    flex-direction: column;
}

/* ---- 目录文字的默认与激活样式 ---- */
.toc-item {
    color: #808080;
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

/* 文章大标题（class="title"）的目录项居中 */
.toc-item-title, .toc-item-h1 {
    text-align: center;
}

/* h3 标题的目录项略微缩进 */
.toc-item-h3 {
    padding-left: 24px;
    font-size: 14px;
}

/* 侧边栏展开时，当前所处小节文字的特殊样式：加粗、变色、加背景 */
.toc-item.active {
    color: #000; /* 文字变黑 */
    font-weight: bold; /* 加粗 */
    background-color: #f0f0f0; /* 给一点浅灰背景突出显示 */
}

.main-content {
    display: flex;
    flex-direction: column;
    padding: 0 15px 15px 15px;
    margin-top: 1rem;
    min-width: 0; /* 让子元素的宽度不会超过父元素 */
}

.main-content .header {
    font-family: "Times New Roman", "KaiTi", "Microsoft YaHei", "Sans Serif";
    margin-top: .5rem;
    margin-bottom: .5rem;
    text-align: center;
    color: #404040;
    font-size: large;
}

.main-content ul {
    padding-left: 20px;
    list-style-position: inside;
}

.main-content ol {
    padding-left: 20px;
    /* list-style-position: inside; */
}

.article-preview {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin: 1rem 0;
}

article {
    display: flex;
    background-color: #fefefe;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    margin-top: 1rem;
}

article:hover {
    background-color: #f0f0f0;
}

article a {
    color: #404040;
    flex: 1;
    padding: 1rem 1.5rem 0.5rem 1.5rem;
}

article svg {
    margin-right: 0.5rem;
}

.partial-content {
    margin-top: 0.5rem;
    display: -webkit-box; /* 将对象作为弹性伸缩盒子模型显示 */
    -webkit-box-orient: vertical; /* 设置伸缩盒子的子元素排列方式：垂直 */
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis; /* 溢出时显示省略号(...) */
    white-space: normal; /* 覆盖 a 标签继承下来的 nowrap */
}

.meta-data {
    margin-top: 0.5rem;
}

.timestamp {
    font-size: 12px;
    text-align: right;
    font-weight: 500;
}

/* 以上是文章预览页面的css */
/* 以下为具体文章的css */

.timestamp p {
    margin-bottom: 0.5rem;
}

.content {
    display: flex;
    flex-direction: column;
    /* align-items: flex-start; */
    /* border: 3px solid #e0e0e0; */
    border-radius: 10px;
    padding: 1rem 2rem;
    background-color: #fff;
}

.content h1, .content h2 {
    margin: 1rem 0;
    align-self: center;                      
}

.content h3, .content h4, .content h5, .content h6 {
    margin: 1rem 0;
    align-self: flex-start;
}

.content .title {
    font-size: 1.6rem;
}

.content p {
    margin: 0.5rem 0 0.5rem 0;
}

.content a {
    color: #0060E0;
    padding: 0 0.1rem;
}

.content a:hover {
    color: #ff6600;
}

.content hr {
    width: 30%;
    align-self: center;
    margin: 0.5rem 0;
}

.content code {
    font-family: Arial, Helvetica, sans-serif;
    padding: 2px;
    border-radius: 3px;
    border: 1px solid #e0e0e0;
}

.content pre code {
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.4;
    border: none;
}

.content img {
    max-width: 90%;
    display: block;
    margin: 1rem auto;
}

.content .math.display {
    display: block;
    overflow-x: auto;
}

.content blockquote {
    margin-left: 2rem;
    background-color: #f0f0f0;
    padding: 0 1rem;
    border-radius: 10px;
}

.content ul {
    margin: 0.5rem 0;
}

@media (max-width: 1000px) {
    .top-bar {
        /* transform: translateX(1rem); */
        margin-left: 1rem;
    }

    .description {
        margin-left: 1rem;
    }

    .top ul {
        margin-left: 0;
        margin-right: 0;
    }

    .top ul a svg {
        display: none;
    }

    .top ul li {
        padding-left: 0.1rem;
        /* width: 90%; */
    }

    .search {
        margin-right: 0.2rem;
        padding-left: 0.4rem;
    }

    /* 在手机屏幕上，侧边栏不再整体隐藏，而是变成可以调出的抽屉 */
    .container {
        grid-template-columns: 1fr;
        padding: 0;
        background-color: #fff;
    }

    .main-content {
        grid-column: 1;
    }

    /* 左侧栏：默认收起在屏幕外，作为从左侧滑出的抽屉。
       z-index 比 .top（100）高，展开时会挡住一部分 .top */
    .sidebar-left {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        max-height: none;
        overflow-y: auto;
        background-color: #fff;
        padding: 1rem;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .sidebar-left.mobile-active {
        transform: translateX(0);
    }

    /* 左侧栏调出按钮：固定在 .top 下方左上角 */
    .left-sidebar-toggle {
        display: flex;
        position: fixed;
        top: calc(var(--topbar-h, 0px) + 0.5rem);
        left: 0.5rem;
        align-items: center;
        justify-content: center;
        z-index: 150;
    }

    /* 右侧栏：默认收起为屏幕右边缘的一排短横线，
       展开后作为抽屉滑出，z-index 比 .top（100）低，所以不会挡住 .top */
    .sidebar-right {
        display: block;
        position: fixed;
        top: var(--topbar-h, 0px);
        right: 0;
        width: 70%;
        max-width: 280px;
        height: calc(100vh - var(--topbar-h, 0px));
        max-height: none;
        overflow-y: auto;
        background-color: #fafafa;
        padding: 1rem;
        z-index: 90;
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }

    .sidebar-right.mobile-active {
        transform: translateX(0);
    }

    /* 收起状态：只显示短横线，不显示完整目录 */
    .toc-dashes {
        display: flex;
        position: fixed;
        top: var(--topbar-h, 0px);
        top: 50%;
        transform: translateY(-50%);
        /* top: 0;
        bottom: 0;
        margin-top: auto;
        margin-bottom: auto;
        height: fit-content; */
        right: 5px;
        flex-direction: column;
        gap: 2rem;
        padding: 1rem 0rem;
        z-index: 90;
        width: 15px;
        align-items: center;
    }

    .toc-dash {
        width: 10px;
        height: 2px;
        background-color: #d0d0d0;
        border-radius: 2px;
        display: block; /* 必须加这一行：span 默认是行内元素，转为 block 才能生效宽高 */
        transition: all 0.3s ease;
    }

    /* 当前所处小节的短横线：变长、加粗、颜色加深 */
    .toc-dash.active {
        width: 15px;
        height: 3px;
        background-color: #808080;
    }

    .toc-list {
        display: none;
    }

    /* 展开状态：显示完整目录，隐藏短横线 */
    .sidebar-right.mobile-active .toc-list {
        display: flex;
        flex-direction: column;
    }

    .sidebar-right.mobile-active + .toc-dashes {
        display: none;
    }

    /* 窗口缩放时禁用侧边栏过渡动画，避免内容划过 */
    body.resizing .sidebar-left,
    body.resizing .sidebar-right {
        transition: none;
    }

    article a {
        padding-right: 0.7rem;
        padding-left: 0.7rem;
    }

    .content {
        padding: 0;
        background-color: transparent;
    }
}