/* Blog post: a sticky table-of-contents pane beside the rendered markdown. */

/* The frame clips with `overflow: hidden`, which turns it into a scroll
   container and leaves the sticky pane nowhere to travel. `clip` trims the
   same rounded corners without claiming the scroll. */
.blog-page .page-frame-content {
    overflow: clip;
}

.blog-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 24px;
}

.blog-layout > #blog-content {
    min-width: 0;
}

.blog-nav[hidden] {
    display: none;
}

.blog-nav-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    list-style: none;
    color: var(--text-secondary);
    font-family: var(--font-ui, inherit);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.4;
    text-transform: uppercase;
}

.blog-nav-summary::-webkit-details-marker {
    display: none;
}

.blog-nav-summary:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 4px;
}

.blog-nav-chevron {
    flex: none;
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.2s ease;
}

/* The gap under the summary is padding on the fold's contents, not the list's margin, so a
   fold closing on a phone (css/shared.css, "Folds") takes it along instead of dropping it
   at the end. */
.blog-nav-body {
    padding-top: 14px;
}

.blog-toc {
    margin: 0;
    padding: 0;
    list-style: none;
    border-left: 1px solid var(--border-color);
}

/* `li a` is forced to the link color site-wide, so the muted resting state
   and the active state both have to outrank it. */
.blog-toc-link {
    display: block;
    margin-left: -1px;
    padding: 6px 0 6px 14px;
    border-left: 2px solid transparent;
    color: var(--text-secondary) !important;
    font-size: 14px;
    line-height: 1.45;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.blog-toc-link:hover,
.blog-toc-link:focus-visible {
    color: var(--link-color) !important;
    text-decoration: none;
}

.blog-toc-link:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: -2px;
}

.blog-toc-link.is-active {
    border-left-color: var(--link-color);
    color: var(--link-color) !important;
    font-weight: 700;
}

.blog-toc-item-h3 .blog-toc-link {
    padding-left: 26px;
    font-size: 13px;
}

@media (min-width: 992px) {
    .blog-layout.has-nav {
        grid-template-columns: 216px minmax(0, 1fr);
        gap: 48px;
    }

    .blog-nav {
        position: sticky;
        top: 78px;
        max-height: calc(100vh - 108px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .blog-nav-summary {
        cursor: var(--cursor-default, default);
    }

    .blog-nav-chevron {
        display: none;
    }
}

/* No left side to sit in: the pane becomes a collapsed card above the post. */
@media (max-width: 991px) {
    .blog-nav {
        padding: 14px 16px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-card, 12px);
        background: var(--surface, var(--bg-grey));
    }

    .blog-nav-summary {
        cursor: var(--cursor-pointer, pointer);
    }

    .blog-nav-disclosure[open] .blog-nav-chevron {
        transform: translateY(2px) rotate(-135deg);
    }
}

/* A fold in a post: a <details> written as HTML in the markdown (blog.html
   makes sure the Markdown inside it is rendered). Its <summary> holds either a
   section's heading, so the contents pane still lists it (the references at the
   end of a post), or a few words; without one, blog.html adds "详情"/"Details".
   Closed until the summary is clicked; looks like the adverse reactions fold on
   medical.html. */
#blog-content details > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    width: fit-content;
    margin: 0 0 16px;   /* a post's h2 margins */
    list-style: none;
    cursor: var(--cursor-pointer, pointer);
    color: var(--text-secondary);   /* a label in words reads as a control; a heading keeps its color */
    font-weight: 600;
}

#blog-content details > summary:hover {
    color: var(--text-heading);
}

#blog-content details > summary::-webkit-details-marker {
    display: none;
}

#blog-content details > summary:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 4px;
}

#blog-content details > summary > :is(h2, h3) {
    margin: 0;
}

#blog-content details > summary::after {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.2s ease;
}

#blog-content details[open] > summary::after {
    transform: translateY(2px) rotate(-135deg);
}

/* Under a post's title (blog.html): its date and reading time, as on its card in the
   list (css/blog-list.css, .blog-card-date). */
.blog-post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 8px;
    margin: -6px 0 24px;
    color: var(--text-secondary);
    font-size: 14px;
    letter-spacing: var(--ui-tracking, normal);
    text-transform: var(--ui-case, none);
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
}

/* Spans and links take the body font site-wide (with !important); these take the
   theme's UI font, like the list's dates and tags. */
.blog-post-meta,
.blog-post-meta > *,
.blog-post-nav-all,
.blog-post-nav-all > span {
    font-family: var(--font-ui, var(--font-body)) !important;
}

/* The end of a post (blog.html): a link back to the list. */
.blog-post-nav {
    margin-top: 40px;
}

.blog-post-nav > hr {
    margin: 0 0 16px;
}

.blog-post-nav-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: var(--ui-tracking, normal);
    text-transform: var(--ui-case, none);
}

@media (prefers-reduced-motion: reduce) {
    .blog-nav-chevron,
    #blog-content details > summary::after,
    .blog-toc-link {
        transition: none;
    }
}
