:root {
    --bg-color: #f4f1ea;
    --surface-color: rgba(255, 253, 248, 0.5);
    --surface-strong: rgba(255, 253, 248, 0.7);
    --text-main: #181614;
    --text-muted: #6d665e;
    --border-color: rgba(24, 22, 20, 0.12);
    --accent-color: #a85c3b;
    --shadow-soft: 0 10px 30px rgba(24, 22, 20, 0.04);
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Source Serif 4', serif;
    --header-height: 76px;
    --essay-header-offset: var(--header-height);
    --layout-width: 1240px;
    --transition-smooth: 220ms ease;
}

[data-theme="dark"] {
    --bg-color: #151515;
    --surface-color: rgba(29, 29, 29, 0.55);
    --surface-strong: rgba(29, 29, 29, 0.82);
    --text-main: #f2efe8;
    --text-muted: #afa79d;
    --border-color: rgba(242, 239, 232, 0.1);
    --accent-color: #f2d2b7;
    --shadow-soft: 0 24px 60px rgba(0, 0, 0, 0.28);
}

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

html {
    font-size: 17px;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

body {
    background: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.35s ease, color 0.35s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 80;
    backdrop-filter: blur(10px);
    background: color-mix(in srgb, var(--bg-color) 86%, transparent);
    border-bottom: 1px solid var(--border-color);
}

.header-inner,
.essay-layout {
    width: min(calc(100% - 2rem), var(--layout-width));
    margin: 0 auto;
}

.header-inner {
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    font-family: var(--font-heading);
    font-size: 1.32rem;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    box-shadow: 0 6px 18px rgba(24, 22, 20, 0.08);
    flex: 0 0 auto;
}

.header-link {
    color: var(--text-muted);
    font-size: 0.92rem;
    transition: color var(--transition-smooth);
}

.header-link:hover,
.header-link:focus-visible {
    color: var(--text-main);
}

.icon-btn {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
}

.theme-switch {
    display: inline-block;
    position: relative;
    width: 42px;
    height: 24px;
}

.theme-switch input {
    display: none;
}

.slider {
    position: absolute;
    inset: 0;
    background: var(--text-main);
    border-radius: 999px;
    cursor: pointer;
}

.slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: var(--bg-color);
    transition: transform 0.35s ease, background-color 0.35s ease;
}

[data-theme="dark"] .slider {
    background: #f2efe8;
}

[data-theme="dark"] .slider::before {
    background: #151515;
    transform: translateX(18px);
}

.essay-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 2.5rem;
    padding: 2rem 0 4rem;
    position: relative;
}

.sidebar {
    position: sticky;
    top: calc(var(--essay-header-offset) + 1.25rem);
    align-self: start;
    padding: 0.2rem 0 0;
    max-height: calc(100vh - var(--essay-header-offset) - 2.5rem);
    overflow: auto;
    transition: transform var(--transition-smooth);
}

.sidebar-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    margin-bottom: 0.85rem;
}

.toc-list {
    list-style: none;
    display: grid;
    gap: 0.65rem;
}

.toc-list a {
    display: block;
    color: var(--text-muted);
    font-size: 0.96rem;
    line-height: 1.45;
    padding: 0.2rem 0;
    transition: color var(--transition-smooth);
}

.toc-list a:hover,
.toc-list a:focus-visible {
    color: var(--text-main);
}

.essay-main {
    min-width: 0;
}

.article-shell {
    max-width: 760px;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 1.2rem;
}

.eyebrow::before {
    content: "";
    width: 28px;
    height: 1px;
    background: var(--border-color);
}

.essay-title {
    font-family: var(--font-heading);
    font-size: clamp(3rem, 8vw, 5.4rem);
    font-weight: 600;
    line-height: 0.92;
    letter-spacing: -0.05em;
    max-width: 10ch;
}

.essay-subtitle {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 1.05rem;
    max-width: 42ch;
}

.essay-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    margin-top: 1.4rem;
    margin-bottom: 2.4rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.essay-body p,
.essay-body blockquote {
    font-size: 1.04rem;
    color: var(--text-main);
    margin-bottom: 1.25rem;
    max-width: 66ch;
}

.essay-body h2 {
    font-family: var(--font-heading);
    font-size: clamp(1.75rem, 3vw, 2.1rem);
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin: 3rem 0 1rem;
    scroll-margin-top: calc(var(--essay-header-offset) + 24px);
}

.essay-body em {
    font-style: italic;
}

.mobile-drawer-toggle {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 980px) {
    .essay-layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .sidebar {
        position: fixed;
        top: calc(var(--essay-header-offset) + 0.75rem);
        left: 1rem;
        width: min(320px, calc(100vw - 2rem));
        max-height: calc(100vh - var(--essay-header-offset) - 1.5rem);
        z-index: 90;
        transform: translateX(calc(-100% - 2rem));
        pointer-events: none;
        padding: 1rem 1.1rem;
        border-radius: 16px;
        border: 1px solid var(--border-color);
        background: color-mix(in srgb, var(--bg-color) 92%, transparent);
        box-shadow: var(--shadow-soft);
    }

    .sidebar.active {
        transform: translateX(0);
        pointer-events: auto;
    }

    .mobile-drawer-toggle {
        display: inline-flex;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: transparent;
        pointer-events: none;
        z-index: 85;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }
}

@media (max-width: 720px) {
    .header-inner {
        min-height: auto;
        padding: 0.85rem 0;
        align-items: center;
        justify-content: space-between;
        row-gap: 0.75rem;
        flex-wrap: wrap;
    }

    .header-left {
        gap: 0.7rem;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        align-items: center;
        padding-top: 0.75rem;
        border-top: 1px solid var(--border-color);
    }

    .brand {
        font-size: 1.12rem;
        font-weight: 500;
        letter-spacing: -0.02em;
    }

    .header-link {
        font-size: 0.88rem;
        line-height: 1.2;
    }

    .icon-btn {
        width: 38px;
        height: 38px;
    }

    .essay-layout {
        padding: 1.75rem 0 3rem;
    }

    .essay-body p,
    .essay-body blockquote {
        font-size: 1rem;
    }

    .essay-title {
        font-size: clamp(2.8rem, 14vw, 4rem);
    }
}
