/* ===========================
   Design Tokens (CSS Custom Properties)
   =========================== */

:root {
    --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
    --max-width: 640px;
    --transition-speed: 0.3s;
}

.theme-light {
    --bg: #f0eee6;
    --text: #2c2c2c;
    --text-muted: #6b6b6b;
    --link: #2c2c2c;
    --link-hover: #000;
    --border: #d4d2ca;
    --code-bg: #e6e4dc;
    --toggle-bg: #d4d2ca;
    --toggle-active-bg: #2c2c2c;
    --toggle-active-text: #f0eee6;
    --toggle-text: #6b6b6b;
    --btn-bg: #2c2c2c;
    --btn-text: #f0eee6;
}

.theme-dark {
    --bg: #1a1a1a;
    --text: #e8e6df;
    --text-muted: #999;
    --link: #e8e6df;
    --link-hover: #fff;
    --border: #333;
    --code-bg: #2a2a2a;
    --toggle-bg: #333;
    --toggle-active-bg: #e8e6df;
    --toggle-active-text: #1a1a1a;
    --toggle-text: #999;
    --btn-bg: #e8e6df;
    --btn-text: #1a1a1a;
}

/* ===========================
   Reset & Base
   =========================== */

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

html {
    font-size: 18px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-serif);
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.7;
    transition: background-color var(--transition-speed) ease,
        color var(--transition-speed) ease;
    min-height: 100vh;
}

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

#site-header {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2.5rem 1.5rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

/* ===========================
   Typography
   =========================== */

.site-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.02em;
    transition: color var(--transition-speed) ease;
}

.site-title:hover {
    color: var(--link-hover);
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
}

p {
    margin-bottom: 1.2rem;
}

a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    transition: color var(--transition-speed) ease;
}

a:hover {
    color: var(--link-hover);
}

.muted {
    color: var(--text-muted);
    font-style: italic;
}

/* ===========================
   Theme Toggle
   =========================== */

.theme-toggle {
    display: flex;
    background: var(--toggle-bg);
    border-radius: 24px;
    padding: 3px;
    gap: 2px;
    transition: background-color var(--transition-speed) ease;
}

.theme-toggle input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-toggle label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--toggle-text);
    transition: all var(--transition-speed) ease;
    user-select: none;
}

.theme-toggle input[type="radio"]:checked+label {
    background: var(--toggle-active-bg);
    color: var(--toggle-active-text);
}

/* ===========================
   Home: Intro
   =========================== */

.intro {
    margin-top: 1rem;
}

.intro p:first-child {
    margin-top: 0;
}

/* ===========================
   Home: Writings List
   =========================== */

.writings ul,
.links-section ul {
    list-style: disc;
    padding-left: 1.2rem;
}

.writings li,
.links-section li {
    margin-bottom: 0.75rem;
}

.writings li a,
.links-section li a {
    text-decoration: underline;
}

.post-date {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

/* ===========================
   Blog Post View
   =========================== */

.back-link {
    display: inline-block;
    margin-bottom: 2rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-decoration: none;
}

.back-link:hover {
    color: var(--text);
}

#post-content h1 {
    font-size: 2.2rem;
    margin-bottom: 0.3rem;
}

#post-content .post-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
    margin-bottom: 2rem;
}

#post-content h2 {
    font-size: 1.4rem;
    margin-top: 2.5rem;
    margin-bottom: 0.8rem;
}

#post-content h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-top: 2rem;
    margin-bottom: 0.6rem;
}

#post-content p {
    margin-bottom: 1.2rem;
}

#post-content ul,
#post-content ol {
    padding-left: 1.5rem;
    margin-bottom: 1.2rem;
}

#post-content li {
    margin-bottom: 0.4rem;
}

#post-content blockquote {
    border-left: 3px solid var(--border);
    padding-left: 1.2rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-style: italic;
}

#post-content code {
    font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
    font-size: 0.85rem;
    background: var(--code-bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    transition: background-color var(--transition-speed) ease;
}

#post-content pre {
    background: var(--code-bg);
    padding: 1.2rem;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    transition: background-color var(--transition-speed) ease;
}

#post-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85rem;
}

#post-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1rem 0;
}

#post-content strong {
    font-weight: 700;
}

#post-content em {
    font-style: italic;
}

#post-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2.5rem 0;
}

/* ===========================
   404 View
   =========================== */

.not-found {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60vh;
}

.not-found-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    margin-bottom: 0.5rem;
}

.not-found h1 {
    font-size: 2.8rem;
    margin-bottom: 0.8rem;
}

.not-found p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    max-width: 360px;
}

.go-home-btn {
    display: inline-block;
    background: var(--btn-bg);
    color: var(--btn-text);
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-serif);
    transition: opacity 0.2s ease,
        background-color var(--transition-speed) ease,
        color var(--transition-speed) ease;
}

.go-home-btn:hover {
    opacity: 0.85;
    color: var(--btn-text);
}

/* ===========================
   Table of Contents Sidebar
   =========================== */

.toc-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 220px;
    height: 100vh;
    background: var(--bg);
    z-index: 50;
    overflow-y: auto;
    padding: 6rem 1.5rem 3rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease,
                visibility 0.3s ease,
                background-color var(--transition-speed) ease;
}

.toc-sidebar.has-headings {
    opacity: 1;
    visibility: visible;
}

.toc-overlay {
    display: none;
}

.toc-close {
    display: none;
}

.toc-heading {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text);
    margin-bottom: 1rem;
    margin-top: 0;
}

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

.toc-list li {
    margin-bottom: 0.6rem;
}

.toc-list a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    line-height: 1.4;
    transition: color 0.2s ease;
}

.toc-list a:hover,
.toc-list a.toc-active {
    color: var(--text);
    font-weight: 700;
}

.toc-toggle {
    display: none;
}

/* ===========================
   Responsive
   =========================== */

@media (max-width: 900px) {
    .toc-sidebar {
        width: 300px;
        padding: 2rem 2rem 3rem;
        z-index: 100;
        opacity: 1;
        visibility: visible;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                    background-color var(--transition-speed) ease;
        border-right: 1px solid var(--border);
    }

    .toc-sidebar.has-headings {
        opacity: 1;
        visibility: visible;
    }

    .toc-sidebar.is-open {
        transform: translateX(0);
    }

    .toc-heading {
        font-size: 1.2rem;
        text-transform: none;
        letter-spacing: normal;
        color: var(--text);
    }

    .toc-list a {
        font-size: 1rem;
    }

    .toc-list li {
        margin-bottom: 0.8rem;
    }

    .toc-close {
        display: block;
        background: none;
        border: none;
        font-size: 1.3rem;
        cursor: pointer;
        color: var(--text);
        padding: 0.2rem;
        margin-bottom: 1.5rem;
        transition: opacity 0.2s ease;
    }

    .toc-close:hover {
        opacity: 0.6;
    }

    .toc-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.3);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.35s ease, visibility 0.35s ease;
    }

    .toc-overlay.is-visible {
        opacity: 1;
        visibility: visible;
    }

    .toc-toggle {
        display: none;
        background: none;
        border: none;
        font-size: 1.4rem;
        cursor: pointer;
        color: var(--text);
        padding: 0.3rem;
        margin-bottom: 1rem;
        line-height: 1;
        transition: opacity 0.2s ease;
    }

    .toc-toggle.has-headings {
        display: block;
    }

    .toc-toggle:hover {
        opacity: 0.6;
    }
}

@media (max-width: 600px) {
    html {
        font-size: 16px;
    }

    #site-header {
        padding: 1.5rem 1rem 0;
    }

    main {
        padding: 1.5rem 1rem 3rem;
    }

    .not-found h1 {
        font-size: 2rem;
    }

    .toc-sidebar {
        width: 85vw;
    }
}