/* ==========================================================================
   Blog post layout — Medium-style reading experience
   Shared by the static posts in /blog/ and by article.html
   ========================================================================== */

:root {
    --post-text: #242424;
    --post-muted: #6b6b6b;
    --post-faint: #a8a8a8;
    --post-line: #f2f2f2;
    --post-line-strong: #e6e6e6;
    --post-highlight: rgba(26, 137, 23, 0.12);
    --post-serif: "Source Serif 4", "Source Serif Pro", Georgia, Cambria, "Times New Roman", serif;
    --post-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --post-width: 680px;
    --post-ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

/* overflow-x: hidden on html/body (style.css) would break position: sticky; clip does not */
html:has(body.post-page) { overflow-x: clip; }
body.post-page { background: #fff; overflow-x: clip; }

/* style.css gives every <nav> a flex row, 80px height and full width — undo that here */
.post-toc nav,
nav.post-rail {
    height: auto;
    width: auto;
    justify-content: normal;
    flex-wrap: nowrap;
    gap: 0;
}
.post-toc nav { display: block; }
.post-rail > * { flex-shrink: 0; }
body.post-page main { padding-top: 120px; }

/* ---------- Three-column grid: TOC | article | margin ---------- */
.post-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, var(--post-width)) minmax(0, 1fr);
    column-gap: 48px;
    padding: 0 24px 96px;
}
.post-header,
.post-body { grid-column: 2; min-width: 0; }
.post-header { grid-row: 1; }
.post-body { grid-row: 2; }

/* ---------- Header ---------- */
.post-header { animation: postFadeUp 0.6s var(--post-ease) both; }

.post-kicker {
    display: inline-block;
    font-family: var(--post-sans);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--post-muted);
    text-decoration: none;
    margin-bottom: 20px;
    transition: color 0.2s ease;
}
.post-kicker:hover { color: var(--post-text); }
.post-kicker i { font-size: 11px; margin-right: 6px; }

.post-title {
    font-family: var(--post-sans);
    font-size: 42px;
    line-height: 52px;
    font-weight: 700;
    letter-spacing: -0.011em;
    color: var(--post-text);
    margin: 0 0 12px;
}

.post-subtitle {
    font-family: var(--post-sans);
    font-size: 22px;
    line-height: 30px;
    font-weight: 400;
    letter-spacing: -0.008em;
    color: var(--post-muted);
    margin: 0 0 32px;
}

.post-byline {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--post-sans);
    font-size: 14px;
    line-height: 20px;
    color: var(--post-muted);
    margin-bottom: 32px;
}
.post-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-color, #ce352a);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 17px;
    flex-shrink: 0;
}
.post-author-name { color: var(--post-text); font-weight: 500; }
.post-byline .dot { margin: 0 6px; }
.post-byline time { white-space: nowrap; }

/* Action bar (between hairlines, like Medium) */
.post-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--post-line);
    border-bottom: 1px solid var(--post-line);
    padding: 6px 8px;
    margin-bottom: 40px;
    font-family: var(--post-sans);
    font-size: 13px;
    color: var(--post-muted);
}
.post-actions-group { display: flex; align-items: center; gap: 4px; }
.post-action {
    width: 36px;
    height: 36px;
    border: 0;
    background: none;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--post-muted);
    font-size: 16px;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.2s ease, background-color 0.2s ease;
}
.post-action:hover { color: var(--post-text); background: #f7f7f7; }
.post-action.copied { color: #1a8917; }

/* Cover image: never cropped */
.post-cover { margin: 0 0 48px; }
.post-cover img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    object-fit: contain;
    border-radius: 4px;
}
.post-cover figcaption {
    font-family: var(--post-sans);
    font-size: 14px;
    line-height: 20px;
    color: var(--post-muted);
    text-align: center;
    margin-top: 10px;
}

/* ---------- Body typography ---------- */
.post-content {
    font-family: var(--post-serif);
    font-size: 20px;
    line-height: 32px;
    letter-spacing: -0.003em;
    color: var(--post-text);
    overflow-wrap: break-word;
    word-break: normal;
}
.post-content > *:first-child { margin-top: 0; }

.post-content p {
    margin: 2.14em 0 -0.46em;
}
.post-content > p:first-child,
.post-content h2 + p,
.post-content h3 + p,
.post-content h2 + ul,
.post-content h3 + ul { margin-top: 0.94em; }
.post-content > p:first-child { margin-top: 0; }

.post-content h2 {
    font-family: var(--post-sans);
    font-size: 24px;
    line-height: 30px;
    font-weight: 700;
    letter-spacing: -0.016em;
    color: var(--post-text);
    margin: 1.95em 0 -0.28em;
    scroll-margin-top: 110px;
}
.post-content h3 {
    font-family: var(--post-sans);
    font-size: 20px;
    line-height: 24px;
    font-weight: 700;
    letter-spacing: 0;
    color: var(--post-text);
    margin: 1.72em 0 -0.31em;
    scroll-margin-top: 110px;
}
.post-content h2 + h3 { margin-top: 1.2em; }

.post-content strong { font-weight: 700; color: inherit; }
.post-content em { font-style: italic; }

.post-content a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
}
.post-content a:hover { color: var(--primary-color, #ce352a); }

.post-content ul,
.post-content ol {
    margin: 1.4em 0 0;
    padding-left: 30px;
    list-style: disc;
}
.post-content ol { list-style: decimal; }
.post-content li {
    margin-top: 1.14em;
    padding-left: 4px;
    margin-bottom: 0;
    position: static;
}
.post-content li::before { content: none; display: none; }
.post-content li::marker { color: var(--post-text); }
.post-content ul + p,
.post-content ol + p,
.post-content .table-wrap + p { margin-top: 1.8em; }

/* Blockquote — italic serif with a dark rule (Medium style) */
.post-content blockquote {
    position: relative;
    margin: 2em 0 0 -20px;
    padding: 0 0 0 23px;
    border-left: 3px solid var(--post-text);
    font-style: italic;
    font-size: 20px;
    line-height: 32px;
    color: var(--post-text);
}
.post-content blockquote p { margin: 0; }
.post-content blockquote + p { margin-top: 2em; }

/* Highlighted passage with a margin note */
.post-content .post-highlight { position: relative; }
.post-content mark {
    background: var(--post-highlight);
    color: inherit;
    padding: 2px 0;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.post-margin-note {
    position: absolute;
    top: 4px;
    left: calc(100% + 40px);
    width: 140px;
    font-family: var(--post-sans);
    font-size: 14px;
    line-height: 20px;
    font-style: normal;
    color: var(--post-muted);
}
@media (max-width: 1279px) {
    .post-margin-note { display: none; }
}

/* Tables */
.post-content .table-wrap {
    margin: 2em 0 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.post-content table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--post-sans);
    font-size: 15px;
    line-height: 22px;
}
.post-content th,
.post-content td {
    text-align: left;
    vertical-align: top;
    padding: 12px 16px 12px 0;
    border-bottom: 1px solid var(--post-line-strong);
}
.post-content th {
    font-weight: 600;
    color: var(--post-text);
    border-bottom: 1px solid var(--post-text);
    white-space: nowrap;
}
.post-content td { color: #3d3d3d; }
.post-content td:first-child { font-weight: 500; color: var(--post-text); min-width: 120px; }

/* Call to action */
.post-content .cta-box {
    margin: 2.4em 0 0;
    padding: 28px 32px;
    border-radius: 8px;
    background: #fafafa;
    border: 1px solid var(--post-line-strong);
}
.post-content .cta-box p {
    margin: 0 0 18px;
    font-family: var(--post-sans);
    font-size: 18px;
    line-height: 28px;
    font-weight: 500;
}
.post-content .cta-box .btn,
.post-content .cta-box a {
    display: inline-flex;
    align-items: center;
    padding: 10px 20px;
    border-radius: 99px;
    background: var(--post-text);
    color: #fff;
    font-family: var(--post-sans);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.2s ease, transform 0.2s ease;
}
.post-content .cta-box a:hover { background: var(--primary-color, #ce352a); color: #fff; }

/* ---------- Left sidebar: "In this article" ---------- */
.post-toc {
    grid-column: 1;
    grid-row: 2;
    justify-self: end;
    width: 100%;
    max-width: 240px;
    align-self: start;
    position: sticky;
    top: 120px;
    font-family: var(--post-sans);
    animation: postFade 0.8s var(--post-ease) 0.2s both;
}
.post-toc summary {
    list-style: none;
    cursor: default;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--post-text);
    margin-bottom: 14px;
}
.post-toc summary::-webkit-details-marker { display: none; }
.post-toc summary i { display: none; }
.post-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    border-left: 1px solid var(--post-line-strong);
    scrollbar-width: thin;
}
.post-toc li { margin: 0; padding: 0; }
.post-toc li::before { content: none; }
.post-toc a {
    display: block;
    padding: 6px 0 6px 16px;
    margin-left: -1px;
    border-left: 2px solid transparent;
    font-size: 14px;
    line-height: 20px;
    color: var(--post-muted);
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: color 0.2s ease, border-color 0.25s ease;
}
.post-toc a:hover { color: var(--post-text); }
.post-toc a.is-active {
    color: var(--post-text);
    font-weight: 500;
    border-left-color: var(--post-text);
}

/* Narrow screens: TOC becomes a collapsible block above the body */
@media (max-width: 1199px) {
    .post-layout {
        grid-template-columns: minmax(0, 1fr) minmax(0, var(--post-width)) minmax(0, 1fr);
        column-gap: 0;
    }
    .post-toc {
        grid-column: 2;
        grid-row: 2;
        position: static;
        justify-self: stretch;
        max-width: none;
        margin-bottom: 40px;
        border: 1px solid var(--post-line-strong);
        border-radius: 8px;
        padding: 0;
    }
    .post-body { grid-row: 3; }
    .post-toc summary {
        cursor: pointer;
        margin: 0;
        padding: 16px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .post-toc summary i { display: inline-block; transition: transform 0.25s var(--post-ease); }
    .post-toc[open] summary i { transform: rotate(180deg); }
    .post-toc ol {
        max-height: none;
        border-left: 0;
        padding: 0 20px 16px;
    }
    .post-toc a { padding-left: 0; border-left: 0; margin-left: 0; }
    .post-toc a.is-active { border-left: 0; }
}

/* ---------- Right rail: vertical section navigator ---------- */
.post-rail {
    position: fixed;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    z-index: 900;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.4s var(--post-ease);
}
.post-rail.is-ready { opacity: 1; }
.post-rail.is-hidden { opacity: 0; pointer-events: none; }

.post-rail-ticks {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    padding: 6px 0 6px 12px;
    list-style: none;
    margin: 0;
}
.post-rail-ticks li { margin: 0; padding: 0; }
.post-rail-ticks li::before { content: none; }
/* Compact Medium-style dashes: 10px rows, 16px / 8px dashes, 1.5px thick */
.post-rail-tick {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 24px;
    height: 10px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}
.post-rail-tick span {
    display: block;
    height: 1.5px;
    width: 8px;
    border-radius: 1px;
    background: #bdbdbd;
    transition: width 0.3s var(--post-ease), background-color 0.3s var(--post-ease);
}
.post-rail-tick.is-h2 span { width: 16px; }
.post-rail-tick:hover span { background: #8a8a8a; }
.post-rail-tick.is-active span { background: var(--post-text); width: 16px; height: 2px; }

/* Hover panel with section names */
.post-rail-panel {
    position: absolute;
    right: calc(100% - 8px);
    top: 50%;
    width: 300px;
    max-height: 72vh;
    overflow-y: auto;
    padding: 12px 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
    opacity: 0;
    visibility: hidden;
    transform: translate(10px, -50%);
    transition: opacity 0.2s var(--post-ease), transform 0.25s var(--post-ease), visibility 0s linear 0.25s;
    list-style: none;
    margin: 0;
    font-family: var(--post-sans);
}
.post-rail:hover .post-rail-panel,
.post-rail:focus-within .post-rail-panel {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
    transition-delay: 0s;
}
.post-rail-panel li { margin: 0; padding: 0; }
.post-rail-panel li::before { content: none; }
.post-rail-panel a {
    display: block;
    padding: 7px 20px;
    font-size: 14px;
    line-height: 20px;
    color: var(--post-muted);
    text-decoration: none;
    transition: color 0.15s ease, background-color 0.15s ease;
}
.post-rail-panel a.is-h3 { padding-left: 34px; font-size: 13px; }
.post-rail-panel a:hover { background: #f7f7f7; color: var(--post-text); }
.post-rail-panel a.is-active { color: var(--post-text); font-weight: 600; }

@media (max-width: 1023px) {
    .post-rail { display: none; }
}

/* ---------- Footer of the post ---------- */
.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 48px 0 0;
    padding: 0;
    list-style: none;
}
.post-tags li { margin: 0; padding: 0; }
.post-tags li::before { content: none; }
.post-tags a,
.post-tags span {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 100px;
    background: #f2f2f2;
    font-family: var(--post-sans);
    font-size: 14px;
    line-height: 20px;
    color: var(--post-text);
    text-decoration: none;
}

.post-end-actions { margin-top: 32px; margin-bottom: 0; }

.post-author-card {
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--post-line-strong);
    display: flex;
    gap: 16px;
    align-items: flex-start;
    font-family: var(--post-sans);
}
.post-author-card .post-avatar { width: 64px; height: 64px; font-size: 24px; }
.post-author-card .label { font-size: 13px; color: var(--post-muted); margin: 0 0 2px; }
.post-author-card h4 {
    font-family: var(--post-sans);
    font-size: 20px;
    line-height: 26px;
    font-weight: 600;
    color: var(--post-text);
    margin: 0 0 8px;
}
.post-author-card p.bio { font-size: 14px; line-height: 21px; color: var(--post-muted); margin: 0; }
.post-author-card a { color: var(--post-text); text-decoration: underline; text-underline-offset: 3px; }

.post-more {
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--post-line-strong);
    font-family: var(--post-sans);
}
.post-more h3 { font-size: 16px; font-weight: 600; color: var(--post-text); margin: 0 0 24px; }
.post-more-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 32px; }
.post-more a { text-decoration: none; color: inherit; display: block; }
.post-more img {
    width: 100%;
    aspect-ratio: 1200 / 630;
    height: auto;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 12px;
    transition: opacity 0.2s ease;
}
.post-more a:hover img { opacity: 0.85; }
.post-more h4 { font-size: 18px; line-height: 24px; font-weight: 700; color: var(--post-text); margin: 0 0 6px; }
.post-more .meta { font-size: 13px; color: var(--post-muted); }

/* ---------- Animations ---------- */
@keyframes postFadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}
@keyframes postFade {
    from { opacity: 0; }
    to { opacity: 1; }
}
.post-body { animation: postFade 0.8s var(--post-ease) 0.15s both; }
@media (prefers-reduced-motion: reduce) {
    .post-header, .post-body, .post-toc { animation: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 728px) {
    .post-layout { padding: 0 16px 72px; }
    body.post-page main { padding-top: 130px; }
    .post-title { font-size: 32px; line-height: 40px; letter-spacing: -0.016em; }
    .post-subtitle { font-size: 18px; line-height: 26px; }
    .post-content { font-size: 18px; line-height: 28px; }
    .post-content h2 { font-size: 20px; line-height: 24px; }
    .post-content h3 { font-size: 18px; line-height: 22px; }
    .post-content blockquote { margin-left: 0; padding-left: 20px; font-size: 18px; line-height: 28px; }
    .post-content .cta-box { padding: 22px; }
    .post-cover { margin-left: -16px; margin-right: -16px; }
    .post-cover img { border-radius: 0; }
}

/* ==========================================================================
   Blog listing (blog.html) — Medium-style feed
   ========================================================================== */
.post-list-wrap {
    max-width: 728px;
    margin: 0 auto;
    padding: 24px 24px 96px;
    font-family: var(--post-sans);
}
.post-list-head {
    padding-bottom: 32px;
    border-bottom: 1px solid var(--post-line-strong);
    animation: postFadeUp 0.6s var(--post-ease) both;
}
.post-list-head h1 {
    font-family: var(--post-sans);
    font-size: 42px;
    line-height: 52px;
    font-weight: 700;
    letter-spacing: -0.011em;
    color: var(--post-text);
    margin: 0 0 8px;
}
.post-list-head p {
    font-size: 18px;
    line-height: 28px;
    color: var(--post-muted);
    margin: 0;
}
.post-list { animation: postFade 0.8s var(--post-ease) 0.15s both; }
.post-list-item { border-bottom: 1px solid var(--post-line); }
.post-list-link {
    display: flex;
    align-items: center;
    gap: 48px;
    padding: 32px 0;
    color: inherit;
    text-decoration: none;
}
.post-list-text { flex: 1; min-width: 0; }
.post-list-author {
    display: flex;
    align-items: center;
    font-size: 13px;
    line-height: 20px;
    color: var(--post-text);
    margin-bottom: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.post-list-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color, #ce352a);
    color: #fff;
    font-size: 9px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    flex-shrink: 0;
}
.post-list-author .dot,
.post-list-meta .dot { margin: 0 6px; color: var(--post-muted); }
.post-list-cat { color: var(--post-muted); }
.post-list-item h2 {
    font-family: var(--post-sans);
    font-size: 22px;
    line-height: 28px;
    font-weight: 700;
    letter-spacing: -0.016em;
    color: var(--post-text);
    margin: 0 0 8px;
    transition: color 0.2s ease;
}
.post-list-item p {
    font-size: 16px;
    line-height: 24px;
    color: var(--post-muted);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.post-list-meta {
    margin-top: 16px;
    font-size: 13px;
    line-height: 20px;
    color: var(--post-muted);
}
.post-list-thumb {
    width: 160px;
    flex-shrink: 0;
    aspect-ratio: 1200 / 630;
    border-radius: 4px;
    overflow: hidden;
    background: #f2f2f2;
}
.post-list-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.2s ease;
}
.post-list-link:hover h2 { color: #000; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.post-list-link:hover .post-list-thumb img { opacity: 0.88; }

@media (max-width: 728px) {
    .post-list-wrap { padding: 16px 16px 72px; }
    .post-list-head h1 { font-size: 32px; line-height: 40px; }
    .post-list-head p { font-size: 16px; line-height: 24px; }
    .post-list-link { gap: 20px; padding: 24px 0; align-items: flex-start; }
    .post-list-item h2 { font-size: 18px; line-height: 23px; }
    .post-list-item p { font-size: 14px; line-height: 20px; }
    .post-list-thumb { width: 96px; margin-top: 32px; }
}
