/* ========================================
   Sisyphox Blog — 优雅、克制的样式
   ======================================== */

/* --- CSS Variables --- */
:root {
    --bg: #fefdfb;
    --bg-secondary: #f7f5f0;
    --text: #2c2c2c;
    --text-secondary: #6b6b6b;
    --text-muted: #9a9a9a;
    --accent: #4a7c8c;
    --accent-hover: #3a6675;
    --border: #e8e5df;
    --code-bg: #f0ede6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);
    --radius: 8px;
    --max-width: 760px;
    --post-max-width: 1000px;
    --toc-width: 200px;
    --header-height: 72px;
    --font-sans:
        -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial,
        sans-serif;
    --font-serif:
        "Noto Serif CJK SC", "Source Han Serif SC", "STSong", "Songti SC",
        "Times New Roman", Georgia, serif;
    --font-mono:
        "JetBrains Mono", "Fira Code", "SF Mono", "Cascadia Code", Consolas,
        monospace;
}

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1e1e;
        --bg-secondary: #282828;
        --text: #e0dcd4;
        --text-secondary: #b0aca5;
        --text-muted: #6e6e6e;
        --accent: #7eb8c9;
        --accent-hover: #9ccfdd;
        --border: #3a3a3a;
        --code-bg: #2d2d2d;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.3);
    }
}

html.dark-mode {
    --bg: #1e1e1e;
    --bg-secondary: #282828;
    --text: #e0dcd4;
    --text-secondary: #b0aca5;
    --text-muted: #6e6e6e;
    --accent: #7eb8c9;
    --accent-hover: #9ccfdd;
    --border: #3a3a3a;
    --code-bg: #2d2d2d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.3);
}

html.dark-mode .site-header {
    background: rgba(30, 30, 30, 0.92);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.75;
    color: var(--text);
    background: var(--bg);
    transition:
        background 0.3s ease,
        color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Typography --- */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-sans);
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
    margin-top: 1.8em;
    margin-bottom: 0.5em;
    letter-spacing: -0.01em;
}
h1 {
    font-size: 2rem;
    margin-top: 0;
}
h2 {
    font-size: 1.5rem;
}
h3 {
    font-size: 1.2rem;
}
p {
    margin-bottom: 1.2em;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition:
        color 0.2s ease,
        border-color 0.2s ease;
    border-bottom: 1px solid transparent;
}
a:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
}

/* --- Blockquote --- */
blockquote {
    margin: 1.5em 0;
    padding: 0.8em 1.2em;
    border-left: 3px solid var(--accent);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
    font-style: italic;
}
blockquote p:last-child {
    margin-bottom: 0;
}

/* --- Code --- */
code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    color: var(--text);
}
pre {
    margin: 1.5em 0;
    padding: 1.2em 1.4em;
    background: var(--code-bg);
    border-radius: var(--radius);
    overflow-x: auto;
    border: 1px solid var(--border);
    line-height: 1.6;
}
pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    border-radius: 0;
}

img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 1.5em 0;
}
hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2.5em 0;
}
ul,
ol {
    margin-bottom: 1.2em;
    padding-left: 1.5em;
}
li {
    margin-bottom: 0.3em;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
}
th,
td {
    padding: 0.6em 1em;
    border: 1px solid var(--border);
    text-align: left;
}
th {
    background: var(--bg-secondary);
    font-weight: 600;
}

/* ========================================
   Header — 可隐藏
   ======================================== */

.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border);
    background: rgba(254, 253, 251, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    height: var(--header-height);
}

.site-header.hidden {
    transform: translateY(-100%);
}

html.dark-mode .site-header {
    background: rgba(30, 30, 30, 0.92);
}

.site-title {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.02em;
    position: absolute;
    left: 1.5rem;
}
.site-title a {
    color: inherit;
    border-bottom: none;
}
.site-title a:hover {
    color: var(--accent);
}

.site-nav {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}
.site-nav a {
    font-size: 0.88rem;
    color: var(--text-secondary);
    border-bottom: none;
    padding: 0.2em 0;
    position: relative;
}
.site-nav a::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--accent);
    transition: width 0.25s ease;
}
.site-nav a:hover::after,
.site-nav a.active::after {
    width: 100%;
}
.site-nav a:hover,
.site-nav a.active {
    color: var(--accent);
}

.theme-toggle {
    position: absolute;
    right: 1.5rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    cursor: pointer;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}
.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ========================================
   Layout
   ======================================== */

/* 主内容区域偏移，为固定 header 留空 */
body {
    padding-top: var(--header-height);
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    flex: 1;
}

main {
    padding: 2.5rem 0 4rem;
}

/* ========================================
   Search Bar
   ======================================== */

.search-wrapper {
    margin-bottom: 1.8rem;
}

.search-input {
    width: 100%;
    padding: 0.7em 1em 0.7em 2.5em;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    border: 1px solid var(--border);
    border-radius: 100px;
    background: var(--bg-secondary);
    color: var(--text);
    outline: none;
    transition: all 0.25s ease;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74, 124, 140, 0.12);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 1em;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

.search-wrapper {
    position: relative;
}

.search-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ========================================
   Homepage — Post List
   ======================================== */

.page-title {
    font-family: var(--font-serif);
    font-size: 2.2rem;
    margin-bottom: 0.2rem;
}
.page-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 1.2rem;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.category-tab {
    display: inline-block;
    padding: 0.35em 1em;
    font-size: 0.85rem;
    border-radius: 100px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
}
.category-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.category-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.post-list {
    list-style: none;
    padding: 0;
}
.post-item {
    padding: 1.4rem 0;
    border-bottom: 1px solid var(--border);
    transition: transform 0.2s ease;
}
.post-item:first-child {
    padding-top: 0;
}
.post-item:hover {
    transform: translateX(4px);
}
.post-item a {
    display: block;
    border-bottom: none;
    color: inherit;
}
.post-item a:hover {
    color: inherit;
}

.post-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
    color: var(--text);
    transition: color 0.2s ease;
}
.post-item:hover .post-title {
    color: var(--accent);
}

.post-meta {
    font-size: 0.83rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}
.post-tag {
    display: inline-block;
    font-size: 0.73rem;
    padding: 0.12em 0.55em;
    background: var(--bg-secondary);
    border-radius: 100px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}
.post-tag:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.post-excerpt {
    margin-top: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.93rem;
    line-height: 1.6;
}
.post-category {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--accent);
}
.post-category-link {
    display: inline-block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent);
    border-bottom: none;
}
.post-category-link:hover {
    text-decoration: underline;
    border-bottom: none;
}

/* ========================================
   Post Page — 两栏布局 (正文 + TOC 侧边栏)
   ======================================== */

body.has-toc .container {
    max-width: var(--post-max-width);
}

.post-page-layout {
    display: flex;
    gap: 2rem;
    position: relative;
}

.post-main {
    flex: 1;
    min-width: 0;
}

.toc-sidebar {
    width: var(--toc-width);
    flex-shrink: 0;
    order: -1;
}

.toc-sticky {
    position: fixed;
    top: calc(var(--header-height) + 2rem);
    width: var(--toc-width);
    max-height: calc(100vh - var(--header-height) - 4rem);
    overflow-y: auto;
    padding-right: 0.8rem;
    border-right: 2px solid var(--border);
    font-size: 0.84rem;
    line-height: 1.7;
}

.toc-title {
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.7rem;
}

.toc-sticky ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.toc-sticky li {
    margin-bottom: 0.15rem;
}
.toc-sticky a {
    display: block;
    padding: 0.18em 0;
    color: var(--text-secondary);
    border-bottom: none;
    transition: color 0.2s ease;
    border-right: 2px solid transparent;
    margin-right: -0.8rem;
    padding-right: 0.8rem;
}
.toc-sticky a:hover,
.toc-sticky a.active {
    color: var(--accent);
}
.toc-sticky a.active {
    border-right-color: var(--accent);
    font-weight: 600;
}

/* 子标题缩进 */
.toc-sticky .toc-h2 {
    padding-right: 1.5rem;
    font-size: 0.82rem;
}
.toc-sticky .toc-h3 {
    padding-right: 2.5rem;
    font-size: 0.78rem;
}

/* 移动端隐藏 TOC 侧边栏 */
@media (max-width: 1024px) {
    .toc-sidebar {
        display: none;
    }
    .post-page-layout {
        display: block;
    }
}

/* --- Post Header --- */
.post-header {
    margin-bottom: 2rem;
    text-align: center;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.post-header h1 {
    font-family: var(--font-serif);
    font-size: 2.2rem;
    margin-bottom: 0.6rem;
}
.post-header .post-meta {
    justify-content: center;
}

/* --- Post Content --- */
.post-content {
    font-family: var(--font-serif);
    font-size: 1.05rem;
    line-height: 1.9;
}
.post-content p {
    margin-bottom: 1.4em;
}
.post-content > p:first-of-type::first-letter {
    font-size: 3.5em;
    float: left;
    line-height: 0.8;
    padding-right: 0.12em;
    padding-top: 0.05em;
    font-weight: 700;
    color: var(--accent);
}
.post-content h2 {
    font-family: var(--font-sans);
    font-size: 1.4rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.35em;
}
.post-content h3 {
    font-family: var(--font-sans);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-bottom: none;
    transition: color 0.2s ease;
}
.back-link:hover {
    color: var(--accent);
    border-bottom: none;
}

/* --- Post Navigation --- */
.post-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 3.5rem;
    padding-top: 1.8rem;
    border-top: 1px solid var(--border);
    gap: 1rem;
}
.post-nav-item {
    flex: 1;
    max-width: 48%;
}
.post-nav-item.next {
    text-align: right;
    margin-left: auto;
}
.post-nav-label {
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
.post-nav-title {
    font-size: 0.93rem;
    font-weight: 600;
    color: var(--text);
    transition: color 0.2s ease;
}
.post-nav-item a {
    border-bottom: none;
}
.post-nav-item a:hover .post-nav-title {
    color: var(--accent);
}

/* ========================================
   Footer
   ======================================== */
.site-footer {
    text-align: center;
    padding: 1.8rem 1rem;
    color: var(--text-muted);
    font-size: 0.83rem;
    border-top: 1px solid var(--border);
}

/* ========================================
   Loading & Empty States
   ======================================== */
.loading {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.loading-dots {
    display: inline-flex;
    gap: 0.3em;
}
.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.2s infinite ease-in-out;
}
.loading-dots span:nth-child(2) {
    animation-delay: 0.15s;
}
.loading-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 640px) {
    :root {
        --header-height: 60px;
    }
    .site-header {
        padding: 0.7rem 1rem;
    }
    .site-title {
        font-size: 1.15rem;
        left: 0.8rem;
    }
    .site-nav {
        gap: 1rem;
    }
    .site-nav a {
        font-size: 0.82rem;
    }
    .post-header h1 {
        font-size: 1.5rem;
    }
    .page-title {
        font-size: 1.5rem;
    }
    .post-content {
        font-size: 1rem;
    }
    .post-content > p:first-of-type::first-letter {
        font-size: 2.5em;
    }
    .post-navigation {
        flex-direction: column;
    }
    .post-nav-item {
        max-width: 100%;
    }
    .post-nav-item.next {
        text-align: left;
    }
    .theme-toggle {
        right: 0.7rem;
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }
    .toc-sidebar {
        display: none !important;
    }
}

@media (max-width: 400px) {
    .site-nav {
        gap: 0.6rem;
    }
    .site-nav a {
        font-size: 0.78rem;
    }
}

/* ========================================
   Print
   ======================================== */
@media print {
    .site-header,
    .site-footer,
    .back-link,
    .post-navigation,
    .theme-toggle,
    .toc-sidebar,
    .category-tabs,
    .search-wrapper {
        display: none;
    }
    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
        padding-top: 0;
    }
    .post-content {
        font-family: "Times New Roman", serif;
    }
}
