:root {
    --blog-scroll-track: color-mix(in srgb, var(--color-bg) 88%, var(--color-surface-soft));
    --blog-scroll-thumb: color-mix(in srgb, var(--color-text-tertiary) 34%, transparent);
    --blog-scroll-thumb-hover: color-mix(in srgb, var(--color-text-secondary) 54%, transparent);
}

:root[data-theme="dark"] {
    --blog-scroll-track: #0e0d0b;
    --blog-scroll-thumb: #3c3933;
    --blog-scroll-thumb-hover: #5d574d;
}

html {
    scrollbar-color: var(--blog-scroll-thumb) var(--blog-scroll-track);
    scrollbar-width: thin;
}

* {
    scrollbar-color: var(--blog-scroll-thumb) transparent;
    scrollbar-width: thin;
}

*::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--blog-scroll-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--blog-scroll-thumb);
    border: 2px solid var(--blog-scroll-track);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--blog-scroll-thumb-hover);
}

*::-webkit-scrollbar-corner {
    background: var(--blog-scroll-track);
}

*::-webkit-scrollbar-button {
    background: transparent;
    display: none;
    height: 0;
    width: 0;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
    width: 10px;
}

html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track {
    background: var(--blog-scroll-track);
}

html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
    background: var(--blog-scroll-thumb);
    border: 2px solid var(--blog-scroll-track);
    border-radius: 999px;
}

html::-webkit-scrollbar-button,
body::-webkit-scrollbar-button {
    background: transparent;
    display: none;
    height: 0;
    width: 0;
}

body {
    overflow-x: hidden;
}

.blog-main {
    max-width: none;
    min-width: 0;
    width: calc(100% - var(--sidebar-width));
}

.blog-content,
.blog-content * {
    text-transform: none;
}

.blog-content {
    max-width: 820px;
    margin: 0 auto;
    min-width: 0;
    padding: 1rem 0 4rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-accent-text);
    text-decoration: none;
    margin-bottom: 2rem;
    font-weight: 500;
    font-size: 0.95rem;
}

.back-link:hover {
    text-decoration: underline;
}

.blog-header {
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 2.5rem;
    padding-bottom: 1.75rem;
}

.blog-title {
    font-family: var(--font-serif);
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.15;
    margin-bottom: 0.85rem;
    max-width: 100%;
    overflow-wrap: break-word;
    color: var(--color-text-primary);
}

.blog-description {
    color: var(--color-text-secondary);
    font-family: var(--font-sans);
    font-size: 1rem;
    margin: 0;
}

.blog-body {
    color: var(--color-text-primary);
    font-family: var(--font-serif);
    font-size: 1.08rem;
    line-height: 1.82;
}

.blog-body p {
    color: var(--color-text-primary);
    font-size: 1.08rem;
    margin-bottom: 1.25rem;
}

.blog-body h2,
.blog-body h3,
.blog-body h4 {
    color: var(--color-text-primary);
    font-family: var(--font-serif);
    line-height: 1.25;
    margin-bottom: 0.9rem;
}

.blog-body h2 {
    font-size: 2rem;
    margin-top: 3rem;
}

.blog-body h3 {
    font-size: 1.55rem;
    margin-top: 2.35rem;
}

.blog-body h4 {
    font-size: 1.22rem;
    margin-top: 1.9rem;
}

.blog-body h2,
.blog-body h3,
.blog-body h4 {
    scroll-margin-top: 1.25rem;
}

.blog-body a {
    color: var(--color-accent-text);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.18em;
}

.blog-body ul,
.blog-body ol {
    margin: 0 0 1.35rem 1.5rem;
    padding-left: 1rem;
}

.blog-body li {
    margin-bottom: 0.55rem;
    padding-left: 0.15rem;
}

.blog-body li > ul,
.blog-body li > ol {
    margin-top: 0.55rem;
    margin-bottom: 0.55rem;
}

.blog-body figure {
    margin: 2rem 0;
}

.blog-body img {
    border-radius: 8px;
    display: block;
    height: auto;
    max-width: 100%;
    margin: 0 auto;
}

.blog-body code {
    background: var(--color-surface-soft);
    border-radius: 4px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.92em;
    padding: 0.15rem 0.35rem;
}

.blog-body pre {
    background: var(--color-surface-muted);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin: 1.5rem 0;
    overflow-x: auto;
    padding: 1rem;
}

.blog-body pre code {
    background: transparent;
    border-radius: 0;
    display: block;
    line-height: 1.55;
    padding: 0;
}

.code-block-wrapper {
    position: relative;
}

.copy-button {
    align-items: center;
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    border: 1px solid var(--color-border-strong);
    border-radius: 6px;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: inline-flex;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    gap: 0.35rem;
    padding: 0.4rem 0.65rem;
    position: absolute;
    right: 0.55rem;
    top: 0.55rem;
}

.copy-button:hover,
.copy-button.copied {
    border-color: var(--color-accent-text);
    color: var(--color-accent-text);
}

.blog-toc-shell {
    bottom: 2rem;
    position: fixed;
    right: 0;
    top: 5.25rem;
    width: 224px;
    z-index: 30;
}

.blog-toc-shell[hidden] {
    display: none !important;
}

.blog-toc {
    font-family: var(--font-sans);
    margin-left: auto;
    max-height: calc(100vh - 7rem);
    opacity: 0;
    overflow-y: auto;
    padding: 0.15rem 1rem 0.15rem 0;
    pointer-events: none;
    scrollbar-width: none;
    transform: translateX(0.4rem);
    transition: opacity 0.16s ease, transform 0.16s ease;
    width: 224px;
}

.blog-toc::-webkit-scrollbar {
    height: 0;
    width: 0;
}

.blog-toc::-webkit-scrollbar-track {
    background: transparent;
}

.blog-toc::-webkit-scrollbar-thumb {
    background: transparent;
    border: 0;
}

.blog-toc::-webkit-scrollbar-button {
    background: transparent;
    display: none;
    height: 0;
    width: 0;
}

.blog-toc-shell:hover .blog-toc,
.blog-toc-shell:focus-within .blog-toc {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

.blog-toc-scrollbar {
    background: color-mix(in srgb, var(--color-text-tertiary) 14%, transparent);
    border-radius: 999px;
    bottom: 0.35rem;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    right: 0.45rem;
    top: 0.35rem;
    transition: opacity 0.16s ease;
    width: 3px;
}

.blog-toc-scrollbar[hidden] {
    display: none !important;
}

.blog-toc-scrollbar-thumb {
    background: color-mix(in srgb, var(--color-text-secondary) 42%, transparent);
    border-radius: inherit;
    min-height: 28px;
    transform: translateY(0);
    width: 100%;
}

.blog-toc-shell:hover .blog-toc-scrollbar,
.blog-toc-shell:focus-within .blog-toc-scrollbar {
    opacity: 0.92;
}

.blog-toc-title {
    color: var(--color-text-tertiary);
    font-size: 0.72rem;
    font-weight: 600;
    margin: 0 0 0.45rem;
}

.blog-toc-list {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.blog-toc-link {
    border-radius: 6px;
    color: var(--color-text-tertiary);
    display: block;
    font-size: 0.78rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    padding: 0.32rem 0.5rem;
    text-decoration: none;
    transition: background-color 0.16s ease, color 0.16s ease;
}

.blog-toc-link:hover,
.blog-toc-link:focus-visible {
    background: var(--color-surface-soft);
    color: var(--color-text-primary);
    outline: none;
}

.blog-toc-link.is-active {
    background: color-mix(in srgb, var(--color-accent-bg) 58%, transparent);
    color: var(--color-text-primary);
    font-weight: 600;
}

.blog-toc-h3 {
    padding-left: 1.15rem;
}

.blog-toc-h4 {
    font-size: 0.74rem;
    padding-left: 1.75rem;
}

.equation {
    margin: 1.25rem 0;
    overflow-x: auto;
}

.table-wrap {
    margin: 1.5rem 0;
    overflow-x: auto;
}

.blog-body table {
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    min-width: 100%;
}

.blog-body th,
.blog-body td {
    border: 1px solid var(--color-border);
    padding: 0.65rem 0.75rem;
    text-align: left;
    vertical-align: top;
}

.blog-body th {
    background: var(--color-surface-muted);
    font-weight: 600;
}

.blog-body blockquote {
    border-left: 3px solid var(--color-border-strong);
    color: var(--color-text-secondary);
    margin: 1.5rem 0;
    padding: 0.1rem 0 0.1rem 1.1rem;
}

.blog-body blockquote p {
    color: var(--color-text-secondary);
}

.blog-body hr {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: 2.25rem 0;
}

.toggle {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin: 1.25rem 0;
    padding: 0.85rem 1rem;
}

.toggle summary {
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 600;
}

.toggle > *:not(summary) {
    margin-top: 1rem;
}

.callout {
    align-items: flex-start;
    background: var(--color-surface-soft);
    border-radius: 8px;
    display: flex;
    gap: 0.75rem;
    margin: 1.5rem 0;
    padding: 1rem;
}

.callout-icon {
    flex: 0 0 auto;
    line-height: 1.5;
}

.callout-body {
    min-width: 0;
}

.notion-page-link,
.notion-bookmark {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-primary) !important;
    display: block;
    font-family: var(--font-sans);
    font-weight: 600;
    margin: 1rem 0;
    padding: 0.8rem 0.9rem;
    text-decoration: none;
}

.notion-page-link:hover,
.notion-bookmark:hover {
    background: var(--color-surface-muted);
}

.notion-highlight {
    border-radius: 3px;
    padding: 0.05rem 0.15rem;
}

.notion-highlight-yellow_background,
.notion-highlight-yellow {
    background: #fff7cc;
}

.notion-highlight-blue_background,
.notion-highlight-blue {
    background: #e5f2ff;
}

.notion-highlight-green_background,
.notion-highlight-green {
    background: #e4f7e8;
}

.notion-highlight-red_background,
.notion-highlight-red {
    background: #ffe8e8;
}

.notion-highlight-pink_background,
.notion-highlight-pink {
    background: #fde8f4;
}

.notion-highlight-purple_background,
.notion-highlight-purple {
    background: #efe7ff;
}

.notion-highlight-gray_background,
.notion-highlight-gray {
    background: #f1f1ef;
}

:root[data-theme="dark"] .notion-highlight-yellow_background,
:root[data-theme="dark"] .notion-highlight-yellow {
    background: #4a3f18;
}

:root[data-theme="dark"] .notion-highlight-blue_background,
:root[data-theme="dark"] .notion-highlight-blue {
    background: #1d3557;
}

:root[data-theme="dark"] .notion-highlight-green_background,
:root[data-theme="dark"] .notion-highlight-green {
    background: #1f3d2a;
}

:root[data-theme="dark"] .notion-highlight-red_background,
:root[data-theme="dark"] .notion-highlight-red {
    background: #4a2323;
}

:root[data-theme="dark"] .notion-highlight-pink_background,
:root[data-theme="dark"] .notion-highlight-pink {
    background: #46233a;
}

:root[data-theme="dark"] .notion-highlight-purple_background,
:root[data-theme="dark"] .notion-highlight-purple {
    background: #332447;
}

:root[data-theme="dark"] .notion-highlight-gray_background,
:root[data-theme="dark"] .notion-highlight-gray {
    background: var(--color-surface-soft);
}

:root[data-theme="dark"] .blog-toc-link.is-active {
    background: color-mix(in srgb, var(--color-accent-bg) 38%, transparent);
}

.blog-spacer {
    height: 1rem;
}

@media (max-width: 1439px), (hover: none), (pointer: coarse) {
    .blog-toc-shell {
        display: none;
    }
}

@media (max-width: 768px) {
    .blog-main {
        margin-left: 0;
        max-width: none;
        padding: 1.5rem;
        width: 100%;
    }

    .blog-content {
        margin: 0;
        max-width: 100%;
        padding-top: 1rem;
        padding-bottom: 2rem;
        width: 100%;
    }

    .blog-body {
        font-size: 1rem;
        line-height: 1.72;
    }

    .blog-body p {
        font-size: 1rem;
    }

    .blog-body h2 {
        font-size: 1.7rem;
    }

    .blog-body h3 {
        font-size: 1.35rem;
    }

    .blog-title {
        font-size: 1.85rem;
        line-height: 1.2;
        max-width: 100%;
    }
}
