/* ==========================================================================
   TABLE OF CONTENTS
   ==========================================================================
   1.  Setup & Global Styles
   2.  Layout
   3.  Components
       - Header & Footer
       - Article List
       - Asides (Footnotes & TOC)
       - Footnotes System
       - Code & Tables
       - Home Page Styles
       - Header Styles
   4.  Typography & Links
   5.  Responsive Design
   ========================================================================== */

/* ==========================================================================
   1. Setup & Global Styles
   ========================================================================== */

:root {
    --primary-color: #007bff;
    --text-color: #333;
    --text-color-light: #555;
    --bg-color-light: #f8f9fa;
    --border-color: #ddd;
    --link-border-color: #ccc;
    --code-color: #d6336c;
    --white-color: #ffffff;
    --shadow-color-light: rgba(0, 0, 0, 0.05);
    --font-serif: 'EB Garamond', 'Noto Serif SC', serif;
    --font-mono: Consolas, Courier, 'Lucida Console', 'Courier New', 'Kai SC', 'Kai TC', monospace;
    --font-size-zh: 16px;
    --font-size-en: 16px;
}

html {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-serif);
    font-size: var(--font-size-en);
    line-height: 1.6;
    background-color: var(--white-color);
    color: var(--text-color);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

html:lang(zh) body,
html:lang(zh-CN) body {
    font-size: var(--font-size-zh);
}

*:lang(zh),
*:lang(zh-CN),
*:lang(zh-TW),
*:lang(zh-HK) {
    font-family: 'Noto Serif SC', serif;
}

/* ==========================================================================
   2. Layout
   ========================================================================== */

main {
    flex: 1;
    width: 100%;
}

.layout {
    display: grid;
    grid-template-columns: 15% auto 20%;
    gap: 1rem;
    align-items: flex-start;
    max-width: 1400px;
    margin: 0 auto;
}

article {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
    font-size-adjust: 0.46;
}

.home-main {
    max-width: 800px;
    margin: 0.5rem auto;
    padding: 0 1.5rem;
}

/* ==========================================================================
   3. Components
   ========================================================================== */

/* --- Header & Footer --- */
header,
footer {
    background: var(--white-color);
    padding: 1rem 0;
    text-align: center;
    width: 100%;
}

header {
    border-bottom: 1px solid var(--border-color);
}

footer {
    border-top: 1px solid var(--border-color);
    border-bottom: none;
    margin-top: 2rem;
}

.nav-container,
.footer-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1rem;
}

header ul,
.social-links {
    list-style: none;
    display: flex;
    justify-content: center;
    padding: 0;
    margin: 0;
    gap: 2rem;
}

.social-links {
    gap: 1rem;
}

header li a,
.social-links li a {
    color: var(--text-color-light);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
    padding: 0.2rem 0;
}

header li a:hover,
.social-links li a:hover {
    color: var(--primary-color);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.copyright {
    font-size: 0.8rem;
    color: var(--text-color-light);
    margin: 0;
}

/* --- Article List --- */
.article-list {
    margin: 2rem auto;
    padding: 0 1.5rem;
    max-width: 800px;
}

.list-title {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 2rem;
    color: var(--text-color);
}

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

.post-item {
    display: flex;
    align-items: baseline;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0;
    border-bottom: 1px dashed var(--border-color);
}

.post-date {
    font-size: 0.85rem;
    color: var(--text-color-light);
    min-width: 90px;
    margin-right: 1rem;
    font-style: italic;
}

.post-link {
    color: var(--text-color);
    flex: 1;
    transition: color 0.2s ease;
    font-style: italic;
}

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

/* --- Asides (Footnotes & TOC) --- */
aside.footnotes,
aside.toc {
    position: relative;
    padding: 0 1rem;
    font-size: 0.85rem;
    color: var(--text-color-light);
}

aside.toc {
    position: sticky;
    top: 1rem;
    height: fit-content;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
}

aside.toc nav ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

aside.toc nav li {
    margin-bottom: 0.5em;
    font-size: 0.95em;
}

aside.toc nav li a.active {
    color: var(--primary-color);
    font-weight: bold;
}

/* TOC Collapsible Styles */
aside.toc nav li.collapsible {
    position: relative;
    padding-left: 20px;
}

.toc-toggle {
    position: absolute;
    left: 0;
    top: 0.25em;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    line-height: 1;
    color: var(--text-color-light);
    transition: transform 0.2s ease-in-out, color 0.2s ease-in-out;
}

.toc-toggle:hover {
    color: var(--primary-color);
}

.toc-toggle svg {
    width: 14px;
    height: 14px;
}

aside.toc nav li.is-open>.toc-toggle {
    transform: rotate(90deg);
}

.toc-sublist {
    list-style: none;
    padding-left: 10px;
    margin-top: 0.5em;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease-in-out, opacity 0.2s ease-in-out;
}

aside.toc nav li.is-open>.toc-sublist {
    max-height: 1000px;
    opacity: 1;
}

.toc-level-2 {
    font-weight: bold;
    margin-bottom: 0.5em;
}

.toc-level-3 {
    font-size: 0.9em;
    margin-left: 5px;
}

.toc-level-4 {
    font-size: 0.85em;
    margin-left: 15px;
    color: var(--text-color-light);
}

/* --- Footnotes System --- */
#dynamic-footnotes {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

#dynamic-footnotes li {
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: normal;
}

sup.footnote-ref {
    font-size: 0.8rem;
    vertical-align: super;
    cursor: pointer;
    color: var(--primary-color);
}

sup.footnote-ref:hover {
    text-decoration: underline;
}

div.footnotes {
    display: none;
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--text-color-light);
}

div.footnotes hr {
    border: none;
    border-top: 1px solid var(--border-color);
}

div.footnotes ol {
    list-style: decimal;
    padding-left: 1.5rem;
}

.inserted-footnotes-container {
    box-sizing: border-box;
    width: calc(100% - 1.5rem);
    margin: 1rem 0 1rem 1.5rem;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--primary-color);
    background-color: var(--bg-color-light);
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--text-color-light);
    overflow-x: auto;
}

.inserted-footnotes-container ol {
    padding-left: 1.2rem;
    margin: 0;
}

.inserted-footnotes-container li {
    margin-bottom: 0.5rem;
}

.inserted-footnotes-container li:last-child {
    margin-bottom: 0;
}

.inserted-footnotes-container p {
    margin: 0;
    display: inline;
}

/* --- Code & Tables --- */
code {
    font-family: var(--font-mono);
    font-size: 14px;
}

h code {
    font-size: 100%;
}

.highlight {
    background: var(--white-color);
    padding: 2px 15px;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    box-shadow: 0 4px 6px var(--shadow-color-light);
    overflow-x: auto;
}

.highlight pre {
    margin: 0;
    padding: 0;
}

article table {
    display: block;
    width: 100%;
    border-collapse: collapse;
    overflow-x: auto;
    margin-bottom: 1rem;
}

article table th,
article table td {
    padding: 10px;
    border: 1px solid var(--border-color);
    text-align: left;
}

/* --- Home Page Styles --- */
.home-content {
    font-size: 1rem;
    line-height: 1.8;
}

.home-content>p:first-of-type {
    margin: 1rem 0;
    text-align: center;
    font-style: italic;
    color: #555;
    font-size: 1.1rem;
    position: relative;
}

.home-content>p:first-of-type::before,
.home-content>p:first-of-type::after {
    content: '';
    display: block;
    width: 50px;
    height: 1px;
    background: var(--border-color);
    margin: 1.5rem auto;
}

.home-content>p:last-of-type {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.95rem;
    color: #666;
}

/* --- Home Footer Styles --- */
.home-footer {
    max-width: 800px;
    margin: 0;
    padding: 0;
    text-align: center;
    color: var(--text-color-light);
    font-size: 0.85rem;
}

.home-footer a {
    color: var(--text-color-light);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

.separator {
    margin: 0 0.5rem;
    color: var(--border-color);
}

/* --- Header Styles --- */
header {
    position: fixed;
    top: 0;
    right: 0;
    width: auto;
    background: transparent;
    z-index: 1000;
    border: none;
    padding: 0;
}

.nav-container {
    position: relative;
    padding: 0;
    margin: 0;
}

.nav-bar {
    width: 2px;
    height: 80px;
    background-color: rgba(128, 128, 128, 0.4);
    margin: 8px 8px 0 0;
    transition: background-color 0.3s ease;
}

.nav-menu {
    position: absolute;
    top: 0;
    right: 20px;
    list-style: none;
    background-color: var(--white-color);
    padding: 0.2rem 0;
    margin: 0;
    border-radius: 3px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    min-width: 120px;
}

.nav-menu li {
    padding: 0;
    margin: 0;
    text-align: left;
}

.nav-menu li a {
    display: block;
    padding: 0.25rem 1rem;
    color: var(--text-color);
    font-size: 0.85rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-menu li a:hover {
    color: var(--primary-color);
    background-color: var(--bg-color-light);
    padding-left: 1.3rem;
}

.nav-container:hover .nav-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.nav-container:hover .nav-bar {
    background-color: rgba(128, 128, 128, 0.6);
}

/* ==========================================================================
   4. Typography & Links
   ========================================================================== */

p {
    margin-top: 0;
    margin-bottom: 1rem;
}

.highlight+p,
.highlight+blockquote {
    margin-top: 1rem;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-color);
    line-height: 1.2;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

h1 {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
}

h2 {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
}

h3 {
    font-size: clamp(0.95rem, 2vw, 1.05rem);
}

article>h1 {
    text-align: center;
    margin: 20px 0;
}

blockquote {
    color: #666;
    margin: 0;
    padding: 1px 1em;
    border-left: .2em solid #eee;
}

.last-modified {
    display: flex;
    justify-content: flex-end;
    font-size: 0.8em;
    color: #666;
    margin-top: 2em;
    font-style: italic;
}

/* Link Styles */
a {
    color: inherit;
    text-decoration: none;
}

article a:not(.footnote-ref):not(.footnote-return),
.article-list a {
    border-bottom: 1px dashed var(--link-border-color);
    transition: border-bottom-color 0.2s ease, border-bottom-style 0.2s ease;
}

article a:not(.footnote-ref):not(.footnote-return):hover,
.article-list a:hover {
    border-bottom-style: solid;
    border-bottom-color: var(--text-color);
}

header a,
footer a,
aside.toc a,
aside.footnotes a,
.inserted-footnotes-container a,
sup.footnote-ref a {
    border-bottom: none;
}

aside.toc a:hover {
    color: var(--primary-color);
}

aside.footnotes a:hover,
.inserted-footnotes-container a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   5. Responsive Design
   ========================================================================== */

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: auto 25%;
    }

    aside.footnotes {
        display: none;
    }
}

@media (max-width: 800px) {
    .layout {
        grid-template-columns: 1fr;
    }

    aside.footnotes,
    aside.toc {
        display: none;
    }

    .inserted-footnotes-container {
        transition: background-color 0.3s ease;
    }
}

@media (min-width: 1440px) {
    main {
        max-width: 1400px;
        margin: 0 auto;
    }
}

@media (max-width: 600px) {
    body {
        font-size: 15px;
        line-height: 1.7;
    }

    article {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        width: 100vw;
    }

    header,
    footer {
        padding: 15px;
    }

    header ul,
    footer ul {
        flex-direction: row;
        gap: 15px;
        flex-wrap: wrap;
        justify-content: center;
    }

    header li a,
    .social-links li a {
        font-size: 0.85rem;
    }

    .footer-content {
        gap: 1rem;
    }

    .social-links {
        gap: 0.8rem;
    }

    .post-item {
        flex-direction: column;
        gap: 0.2rem;
    }

    .post-date {
        font-size: 0.8rem;
    }

    .nav-bar {
        width: 2px;
        height: 60px;
    }

    .nav-menu {
        width: 140px;
    }

    .home-main {
        margin: 1rem auto;
        padding: 0 1rem;
    }

    .home-content>p:first-of-type {
        margin: 2rem 0;
        font-size: 1rem;
    }

    .home-footer {
        margin: 0;
        padding: 0;
    }
}