/* ==========================================
   1. BASE LAYOUT & TYPOGRAPHY
   (reader-generated.css is linked separately for parallel fetch)
   ========================================== */
html {
    overflow-x: hidden;
    --text-scale: 1;
    --reader-line-height: 1.6;
    --reader-body-font: 'iAWriterMonoV', monospace;
    --reader-em-font: 'iAWriterMonoV', monospace;
}

body {
    font-family: var(--reader-body-font, 'iAWriterMonoV', monospace);
    text-align: justify;
    font-size: calc(18px * var(--text-scale, 1));
    line-height: var(--reader-line-height, 1.6);
    background-color: var(--reader-bg);
    color: var(--reader-text);
    margin-top: 100px;
    margin-bottom: 25px;
    margin-left: 10%;
    margin-right: 10%;
    transition: background-color 0.3s ease, color 0.3s ease, margin 0.3s ease;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    text-align: left !important;
}

body.left-aligned {
    text-align: left !important;
}

body[data-paragraph-indent="on"] main#content p + p,
body[data-paragraph-indent="on"] .reader-preview p + p {
    text-indent: 1.5em;
}

main#content,
.reader-preview {
    hyphens: none;
}

body[data-hyphenation="on"] main#content,
body[data-hyphenation="on"] .reader-preview {
    hyphens: auto;
    -webkit-hyphens: auto;
}

::selection {
    background: var(--reader-selection);
}

html.no-reader-transitions,
html.no-reader-transitions *,
html.no-reader-transitions *::before,
html.no-reader-transitions *::after {
    transition: none !important;
}

em,
i {
    font-family: var(--reader-em-font, 'iAWriterMonoV', monospace);
    font-style: italic;
}

a {
    color: var(--reader-link);
    transition: color 0.3s ease;
}

a:active {
    color: var(--reader-link-active);
}

header,
footer {
    text-align: center;
}

pre {
    background-color: var(--reader-pre-bg);
    white-space: pre-wrap;
    padding: 1rem;
    font-size: calc(18px * var(--text-scale, 1));
    line-height: var(--reader-line-height, 1.6);
    font-family: 'iAWriterMonoV', monospace;
    border: 1px solid var(--reader-pre-border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

code {
    font-family: 'iAWriterMonoV', monospace;
}

blockquote.post-blockquote {
    margin: 1.25rem 0;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--reader-progress);
    background: var(--reader-pre-bg);
    border-top: 1px solid var(--reader-pre-border);
    border-right: 1px solid var(--reader-pre-border);
    border-bottom: 1px solid var(--reader-pre-border);
}

blockquote.post-blockquote p {
    margin: 0.5rem 0;
}

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

blockquote.post-blockquote p:last-child {
    margin-bottom: 0;
}

.post-blockquote-attribution {
    margin: 0.75rem 0 0;
    padding-top: 0.5rem;
    border-top: 1px solid var(--reader-border-subtle);
    font-size: 0.9em;
    opacity: 0.85;
    text-align: right;
}

.post-blockquote-attribution cite {
    font-style: normal;
}

figure.post-image {
    text-align: center;
    margin: 2.5rem auto;
}

figure.post-image :is(img, video),
.post-image-uncaptioned {
    display: block;
    margin: 0 auto;
    width: 100%;
    height: auto;
    cursor: zoom-in;
}

.post-image-uncaptioned {
    margin: 2.5rem auto;
}

figure.post-image figcaption,
.post-image-uncaptioned+figcaption {
    margin-top: 0.75rem;
    font-size: calc(15px * var(--text-scale, 1));
    color: var(--reader-caption);
    font-style: italic;
    font-family: 'iAWriterMonoV', monospace;
}

/* ==========================================
   3. INDEX STYLING
   ========================================== */
.chapter {
    display: block;
    text-decoration: none;
    color: inherit;
    background-color: inherit;
    border: 2px solid var(--reader-text);
    cursor: pointer;
    margin: 10px 0;
    padding-left: 10px;
    padding-right: 10px;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chapter:hover,
.chapter:focus-visible {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.chapter-item {
    margin: 6px 0;
    padding: 8px 10px;
}

.chapter-item h3 {
    margin: 0 0 0.2rem;
    font-size: inherit;
    font-weight: bold;
}

.chapter-item .chapter-kind-badge {
    margin-bottom: 0.2rem;
}

.chapter-item .chapter-description {
    margin: 0;
    font-size: inherit;
    line-height: 1.45;
}

.chapter-item .chapter-meta {
    margin: 0.45rem 0 0;
    padding-top: 0.45rem;
    border-top: 2px solid var(--reader-border);
    font-size: 0.8rem;
    opacity: 0.8;
    line-height: 1.35;
}

.chapter-item:not(:has(.chapter-description)) .chapter-meta {
    margin-top: 0.25rem;
    padding-top: 0;
    border-top: none;
}

.chapter-item:hover .chapter-meta,
.chapter-item:focus-visible .chapter-meta {
    opacity: 0.85;
}

.chapter:hover .chapter-meta,
.chapter:focus-visible .chapter-meta,
.post-card-row:hover .chapter-meta,
.post-card-row:focus-within .chapter-meta {
    border-top-color: color-mix(in srgb, currentColor 22%, transparent);
}

.chapter:hover .chapter-description,
.chapter:focus-visible .chapter-description,
.chapter:hover .card-eyebrow,
.chapter:focus-visible .card-eyebrow {
    opacity: 0.85;
}

.chapter-kind-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
    opacity: 0.85;
}

.chapter-kind-badge img {
    width: 1rem;
    height: 1rem;
    display: block;
    filter: var(--reader-icon-filter);
}

/* Card hover — icons invert like category buttons; progress bar keeps theme colors */
:is(
    .chapter:hover,
    .chapter:focus-visible,
    .post-card-row:hover,
    .post-card-row:focus-within,
    .related-post-link:hover,
    .related-post-link:focus-visible,
    .related-post-card:hover,
    .related-post-card:focus-visible
) :is(.meta-icon, .reason-icon, .chapter-kind-badge img, .card-progress-finished img) {
    filter: invert(1);
}

body:is([data-theme="dark"], [data-theme="solarized"], [data-theme="virtual-boy"]) :is(
    .chapter:hover,
    .chapter:focus-visible,
    .post-card-row:hover,
    .post-card-row:focus-within,
    .related-post-link:hover,
    .related-post-link:focus-visible,
    .related-post-card:hover,
    .related-post-card:focus-visible
) :is(.meta-icon, .reason-icon, .chapter-kind-badge img, .card-progress-finished img) {
    filter: none;
}

.category-filter-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 25px;
}

.taxonomy-filter {
    margin-bottom: 25px;
    --filter-label-width: 5rem;
}

.taxonomy-filter .filter-row {
    display: grid;
    grid-template-columns: var(--filter-label-width) 1fr;
    gap: 10px;
    align-items: start;
    margin-bottom: 12px;
    min-width: 0;
}

.taxonomy-filter .tag-rows {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.25s ease;
}

.taxonomy-filter .tag-rows.has-rows {
    max-height: 800px;
    opacity: 1;
}

.taxonomy-filter .filter-row-tag-depth {
    transition: opacity 0.25s ease, transform 0.25s ease, margin 0.25s ease;
}

.taxonomy-filter .filter-row-tag-depth.is-entering {
    opacity: 0;
    transform: translateY(-6px);
}

.taxonomy-filter .filter-row-tag-depth.is-exiting {
    opacity: 0;
    transform: translateY(-4px);
    margin-bottom: 0;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .taxonomy-filter .tag-rows,
    .taxonomy-filter .filter-row-tag-depth {
        transition: none;
    }

    .taxonomy-filter .filter-row-tag-depth.is-entering,
    .taxonomy-filter .filter-row-tag-depth.is-exiting {
        opacity: 1;
        transform: none;
    }
}

.taxonomy-filter .tag-rows .filter-row:last-child {
    margin-bottom: 0;
}

.taxonomy-filter .filter-row-tags-root {
    margin-bottom: 15px;
}

.taxonomy-filter .filter-label {
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    align-self: start;
    padding-top: 8px;
}

.taxonomy-filter .filter-sublabel {
    font-size: 0.8rem;
    font-weight: normal;
    opacity: 0.65;
    align-self: start;
    padding-top: 8px;
}

.taxonomy-filter .filter-options {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 10px;
    min-width: 0;
}

.taxonomy-filter .category-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .taxonomy-filter {
        --filter-label-width: 4rem;
    }

    .taxonomy-filter .category-btn {
        padding: 6px 12px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .taxonomy-filter .filter-row {
        grid-template-columns: 1fr;
    }

    .taxonomy-filter .filter-label,
    .taxonomy-filter .filter-sublabel {
        padding-top: 0;
        margin-bottom: 4px;
    }
}

.category-btn {
    background: transparent;
    border: 2px solid var(--reader-text);
    color: inherit;
    padding: 8px 16px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.category-btn:hover:not(.active) {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.category-btn.active {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.category-btn.active:hover:not(.suppress-active-hover) {
    background-color: transparent;
    color: inherit;
    border-color: var(--reader-text);
}

.category-btn.active.suppress-active-hover:hover {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

/* Posts index toolbar (filter + search) */
.posts-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 25px;
}

.posts-toolbar .taxonomy-filter {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.posts-search {
    display: block;
    flex: 0 0 auto;
    width: 18rem;
    max-width: 100%;
}

.posts-search-field {
    display: flex;
    align-items: stretch;
    gap: 0;
    min-width: 0;
}

.posts-search-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    background: transparent;
    border: 2px solid var(--reader-text);
    color: inherit;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
}

.posts-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.posts-search-clear-wrap {
    overflow: hidden;
    flex: 0 0 auto;
    max-width: 0;
    opacity: 0;
    transform: translateX(-6px);
    transition:
        max-width 0.28s ease,
        opacity 0.22s ease,
        transform 0.28s ease,
        margin-left 0.28s ease;
    margin-left: 0;
    pointer-events: none;
}

.posts-search-field.has-query .posts-search-clear-wrap {
    max-width: 6.5rem;
    opacity: 1;
    transform: translateX(0);
    margin-left: 8px;
    pointer-events: auto;
}

.posts-search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 8px 14px;
    font-size: 0.9rem;
    white-space: nowrap;
}

.posts-search-clear:focus-visible {
    outline: 2px solid var(--reader-hover-bg);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .posts-search-input,
    .posts-search-clear-wrap {
        transition: none;
    }

    .posts-search-clear-wrap {
        transform: none;
    }
}

.posts-search-input::placeholder {
    opacity: 0.55;
    font-weight: normal;
}

.posts-search-input:focus,
.posts-search-input:focus-visible {
    outline: 2px solid var(--reader-text);
    outline-offset: 2px;
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.posts-search-field.has-query .posts-search-input {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.posts-search-input:focus::placeholder,
.posts-search-field.has-query .posts-search-input::placeholder {
    color: var(--reader-hover-text);
    opacity: 0.55;
}

.posts-search-results {
    margin-bottom: 20px;
}

.posts-search-empty {
    margin: 0 0 20px;
    padding: 12px 16px;
    border: 2px solid var(--reader-text);
    opacity: 0.8;
}

.posts-search-empty[hidden] {
    display: none;
}

.posts-search-results .search-result-item.chapter-item {
    display: block;
    margin-bottom: 12px;
}

.search-highlight,
.posts-search-results mark {
    background: var(--reader-selection);
    color: inherit;
    padding: 0;
}

.search-result-subtitle {
    opacity: 0.85;
}

.search-result-excerpt {
    font-size: 0.95rem;
    opacity: 0.75;
}

.posts-list {
    margin-bottom: 0;
}

.posts-pagination {
    display: flex;
    justify-content: space-between;
    margin-top: 25px;
    gap: 16px;
}

.posts-pagination-link {
    font-weight: bold;
    text-decoration: none;
    color: inherit;
    border: 2px solid var(--reader-text);
    padding: 8px 16px;
}

.posts-pagination-link:hover,
.posts-pagination-link:focus-visible {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
}

@media (max-width: 768px) {
    .posts-search {
        width: 14rem;
    }

    .posts-search-input {
        padding: 6px 12px;
        font-size: 0.9rem;
    }

    .posts-search-field.has-query .posts-search-clear-wrap {
        max-width: 5.75rem;
        margin-left: 6px;
    }

    .posts-search-clear {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .posts-toolbar {
        flex-direction: column;
        gap: 12px;
    }

    .posts-search {
        width: 100%;
    }

    .posts-search-field.has-query .posts-search-clear-wrap {
        max-width: 6.25rem;
        margin-left: 8px;
    }
}

/* ==========================================
   5. TOP NAVIGATION BAR
   ========================================== */
#top-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    font-size: 16px;
    background-color: var(--reader-nav-bg);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-sizing: border-box;
    z-index: 3000;
    /* Elevates navbar and its tooltips over all panels */
    transition: background-color 0.3s ease;
    view-transition-name: top-navbar;
}

/* Rigid bounding areas for the side nav items */
.nav-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 0 0 80px;
    min-width: 80px;
}

.nav-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    flex: 0 0 80px;
    min-width: 80px;
}

/* The middle column spans dynamically between the fixed side blocks */
.nav-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0;
    /* Vital to permit truncation behaviors internally */
    height: 100%;
    margin: 0 16px;
}

#nav-title-wrapper {
    min-width: 0;
    max-width: 100%;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(0.9);
    transition: all 0.3s ease;
}

#nav-title-wrapper.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

#nav-title {
    font-size: 1.1rem;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Truncation activates safely at the box wall */
    width: 100%;
    display: block;
    text-align: center;
    transition: opacity 0.2s ease;
}

#nav-title-wrapper:hover #nav-title {
    opacity: 0.6;
}

.nav-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: none;
    border: none;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
    color: inherit;
    font: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn img {
    transition: transform 0.15s ease, opacity 0.2s ease, filter 0.3s ease;
    width: 24px;
    height: 24px;
    filter: var(--reader-icon-filter);
}

.nav-btn:hover img {
    opacity: 0.6;
}

.nav-btn:active img {
    transform: scale(0.75);
    opacity: 1;
}

/* Base Tooltip Drawing Styles */
.nav-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(22px);
    background-color: var(--reader-tooltip-bg);
    color: var(--reader-tooltip-text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: normal;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 3100;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* --- THE FIX: Smart anchoring points for text groups --- */

/* Left-side items anchor left and grow rightwards */
.nav-left .nav-btn::after {
    left: 0;
    right: auto;
    transform: translateX(0) translateY(22px);
}

/* Right-side items anchor right and grow leftwards (Stops clipping completely!) */
.nav-right .nav-btn::after {
    left: auto;
    right: 0;
    transform: translateX(0) translateY(22px);
}

/* Hover States limited exclusively to cursor-capable desktop monitors */
@media (hover: hover) and (pointer: fine) {
    .nav-center .nav-btn:hover::after {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(14px);
    }

    .nav-left .nav-btn:hover::after {
        opacity: 1;
        visibility: visible;
        transform: translateX(0) translateY(14px);
    }

    .nav-right .nav-btn:hover::after {
        opacity: 1;
        visibility: visible;
        transform: translateX(0) translateY(14px);
    }
}


/* ==========================================
   6. TABLE OF CONTENTS
   ========================================== */
#toc-container {
    font-size: 0.9rem;
    text-align: left;
    z-index: 998;
    view-transition-name: toc-sidebar;
    position: relative;
}

#toc-scroll-area {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#toc-scroll-area::-webkit-scrollbar {
    display: none;
}

/* Scroll Hint Gradients */
#toc-container[data-scroll="top"] #toc-scroll-area {
    mask-image: linear-gradient(to bottom, black calc(100% - 40px), transparent);
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 40px), transparent);
}

#toc-container[data-scroll="bottom"] #toc-scroll-area {
    mask-image: linear-gradient(to bottom, transparent, black 40px);
    -webkit-mask-image: linear-gradient(to bottom, transparent, black 40px);
}

#toc-container[data-scroll="both"] #toc-scroll-area {
    mask-image: linear-gradient(to bottom, transparent, black 40px, black calc(100% - 40px), transparent);
    -webkit-mask-image: linear-gradient(to bottom, transparent, black 40px, black calc(100% - 40px), transparent);
}

#toc-container[data-scroll="none"] #toc-scroll-area {
    mask-image: none;
    -webkit-mask-image: none;
}

/* Interactive Hover Buttons */
.toc-scroll-indicator {
    position: absolute;
    height: 40px;
    display: none;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 10;
    background: none;
    border: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.toc-scroll-indicator img {
    width: 20px;
    height: 20px;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease, filter 0.3s ease;
    background-color: var(--reader-nav-bg);
    padding: 6px;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    filter: var(--reader-icon-filter);
}

.toc-scroll-indicator.top img {
    transform: translateY(-10px);
}

.toc-scroll-indicator.bottom img {
    transform: translateY(10px);
}

.toc-scroll-indicator:hover img {
    opacity: 1;
    transform: translateY(0);
}

#toc-container[data-scroll="bottom"] .toc-scroll-indicator.top,
#toc-container[data-scroll="both"] .toc-scroll-indicator.top {
    display: flex;
}

#toc-container[data-scroll="top"] .toc-scroll-indicator.bottom,
#toc-container[data-scroll="both"] .toc-scroll-indicator.bottom {
    display: flex;
}

/* List Styling */
#toc-container ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#toc-container li {
    margin-bottom: 0;
    line-height: 1.4;
}

.toc-h1 {
    margin-top: 12px;
    font-size: 0.95rem;
}

.toc-h2 {
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--reader-toc-border);
}

.toc-h3 {
    margin-left: 24px;
    padding-left: 12px;
    border-left: 1px solid var(--reader-toc-border);
    font-size: 0.85rem;
    color: var(--reader-toc-muted);
}

.toc-link {
    text-decoration: none;
    color: inherit;
    display: block;
    width: fit-content;
    padding: 2px 0;
    border-radius: 0;
    transition: background-color 0.2s, opacity 0.2s;
}

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

.toc-link.active {
    font-weight: normal;
    background-color: var(--reader-toc-active);
    color: inherit;
}

body[data-theme="solarized"] .toc-link.active {
    color: var(--reader-toc-active-text);
}


/* ==========================================
   7. IMAGE LIGHTBOX
   ========================================== */
#lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 4000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    cursor: zoom-out;

    /* THE MAGIC: CSS Flexbox Layout */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* 70px top for nav, 5vw left/right guarantees max 90% width, 25px bottom padding */
    padding: 70px 5vw 25px 5vw;
    box-sizing: border-box;
}

#lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

#lightbox-nav {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px 24px;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-start;
    z-index: 4002;
}

.lightbox-close {
    background: none;
    border: none;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#lightbox-nav img,
.lightbox-close img {
    width: 24px;
    height: 24px;
    filter: invert(1);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#lightbox-nav img:hover,
.lightbox-close:hover img {
    opacity: 0.6;
}

#lightbox-nav img:active,
.lightbox-close:active img {
    transform: scale(0.75);
}

#lightbox-img,
#lightbox-video {
    /* flex: 1 lets it fill available space, min-height: 0 stops it from overflowing */
    flex: 1 1 auto;
    min-height: 0;
    max-width: 100%;
    object-fit: contain;
    /* Guarantees the image shrinks to fit without squishing */
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 4001;
}

#lightbox-overlay.active :is(#lightbox-img, #lightbox-video) {
    transform: scale(1);
}

#lightbox-caption {
    /* flex: 0 ensures it takes exactly the height of the text and no more */
    flex: 0 0 auto;
    margin-top: 15px;
    /* Creates a clean gap between image and text */
    color: #ccc;
    font-size: 1.1rem;
    font-style: italic;
    text-align: center;
    width: 100%;
    max-width: 800px;
    z-index: 4002;
    opacity: 0;
    transition: opacity 0.3s ease;
    transition-delay: 0.1s;
}

#lightbox-overlay.active #lightbox-caption {
    opacity: 1;
}

body.lightbox-open,
html.lightbox-open {
    overflow: hidden !important;
}


/* ==========================================
   8. VIEW TRANSITIONS
   ========================================== */
@view-transition {
    navigation: auto;
}

::view-transition-old(top-navbar),
::view-transition-new(top-navbar),
::view-transition-old(toc-sidebar),
::view-transition-new(toc-sidebar) {
    animation-duration: 0.35s;
    animation-timing-function: ease;
}

html[data-nav-direction="forward"]::view-transition-old(root) {
    animation: slideOutLeft 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

html[data-nav-direction="forward"]::view-transition-new(root) {
    animation: slideInRight 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

html[data-nav-direction="back"]::view-transition-old(root) {
    animation: slideOutRight 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

html[data-nav-direction="back"]::view-transition-new(root) {
    animation: slideInLeft 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes slideInRight {
    from {
        transform: translateX(50px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-50px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(-50px);
        opacity: 0;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(50px);
        opacity: 0;
    }
}


/* ==========================================
   9. SCROLL PROGRESS TRACKER
   ========================================== */
#scroll-progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    z-index: 3005;
    background: transparent;
    pointer-events: none;
}

#scroll-progress-bar-article,
#scroll-progress-bar-remainder {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    transition: width 0.1s ease-out, opacity 0.3s ease;
}

#scroll-progress-bar-article {
    background-color: var(--reader-progress);
    box-shadow: 0 0 8px var(--reader-progress-shadow);
    z-index: 2;
}

#scroll-progress-bar-remainder {
    background-color: var(--reader-remainder-progress);
    box-shadow: 0 0 8px var(--reader-remainder-progress-shadow);
    z-index: 1;
}

#scroll-progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--reader-progress);
    transition: width 0.1s ease-out;
    box-shadow: 0 0 8px var(--reader-progress-shadow);
}

/* ==========================================
   10. RESPONSIVE BREAKPOINTS
   ========================================== */

/* Tablet & Mobile Layouts */
@media (max-width: 1199px) {
    .toc-scroll-indicator.top {
        top: 25px;
        left: 20px;
        right: 35px;
    }

    .toc-scroll-indicator.bottom {
        bottom: 25px;
        left: 20px;
        right: 35px;
    }

    #toc-container {
        position: fixed;
        top: 70px;
        left: -320px;
        width: 290px;
        height: calc(100vh - 70px);
        background-color: var(--reader-nav-bg);
        border-right: 1px solid var(--reader-border);
        padding: 25px 35px 25px 20px;
        box-sizing: border-box;
        transition: left 0.3s ease;
    }

    body.toc-open #toc-container {
        left: 0;
    }

    #toc-overlay {
        position: fixed;
        top: 70px;
        left: 0;
        width: 100vw;
        height: calc(100vh - 70px);
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 997;
    }

    body.toc-open #toc-overlay {
        opacity: 1;
        visibility: visible;
    }

    body.toc-open {
        overflow: hidden !important;
    }
}

/* Base Desktop Margins - Ensures a consistent 60% wide text block */
@media (min-width: 1024px) {
    body {
        margin-left: 20%;
        margin-right: 20%;
    }
}

/* Sidebar ToC Desktop Margins & Layout Shifts */
@media (min-width: 1200px) {
    #toc-overlay {
        display: none !important;
    }

    .toc-scroll-indicator.top {
        top: 0;
        left: 0;
        right: 15px;
    }

    .toc-scroll-indicator.bottom {
        bottom: 0;
        left: 0;
        right: 15px;
    }

    #toc-container {
        position: fixed;
        top: 100px;
        left: 2%;
        width: 18%;
        bottom: 25px;
        padding-right: 15px;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    body.has-toc #toc-container {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Normal Centered Text Mode */
    body {
        margin-left: 20%;
        margin-right: 20%;
    }

    .nav-center {
        left: 20%;
        width: 60%;
        transform: none;
        /* Mathematical override to match text width */
    }

    /* Active Layout Shift (Pushes 60% wide column to the right) */
    body.has-toc {
        margin-left: 30%;
        margin-right: 10%;
    }

    body.has-toc .nav-center {
        left: 30%;
        width: 60%;
        transform: none;
        /* Keeps the title precisely boxed over the content */
    }
}


/* ==========================================
   11. STYLE MENU PANEL
   ========================================== */
#format-menu-container {
    font-size: 15px;
    font-family: 'iAWriterMonoV', monospace;
    text-align: left;
    z-index: 2990;
    position: fixed;
    top: 70px;
    right: -360px;
    width: 340px;
    max-width: calc(100vw - 24px);
    height: calc(100vh - 70px);
    overflow-y: auto;
    background-color: var(--reader-nav-bg);
    border-left: 1px solid var(--reader-border);
    padding: 24px;
    box-sizing: border-box;
    transition: right 0.3s ease;
    box-shadow: var(--reader-panel-shadow);
}

#format-menu-container .reader-preview,
#format-menu-container .style-segmented,
#format-menu-container .style-stepper,
#format-menu-container .style-align-toggle {
    border-radius: 0;
}

body.format-menu-open #format-menu-container {
    right: 0;
}

body.format-menu-open,
html.format-menu-open {
    overflow: hidden !important;
}

.style-section-reset {
    margin-bottom: 0;
    margin-top: 8px;
}

.style-reset-all-btn {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--reader-border);
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.style-reset-all-btn:hover {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
}

.style-shortcuts-hint {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--reader-border);
    font-size: 0.75rem;
    opacity: 0.7;
}

.style-shortcuts-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.style-shortcuts-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.35rem;
}

.style-shortcuts-list kbd {
    display: inline-block;
    padding: 0.1em 0.4em;
    border: 1px solid var(--reader-border);
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.9em;
    line-height: 1.3;
    background: var(--reader-bg);
}

.style-panel-trigger {
    font-family: 'iAWriterMonoV', monospace;
    font-size: 14px;
}

@media (min-width: 1200px) {
    .nav-right {
        flex: 0 0 auto;
        min-width: 0;
    }

    .style-section-preview {
        display: none;
    }
}

#format-menu-container .reader-preview {
    font-family: var(--reader-body-font, 'iAWriterMonoV', monospace);
}

#format-menu-container .style-section-label {
    font-family: var(--reader-body-font, 'iAWriterMonoV', monospace);
}

.reader-preview {
    padding: 14px;
    border: 1px solid var(--reader-border);
    background-color: var(--reader-bg);
    color: var(--reader-text);
    font-size: calc(14px * var(--text-scale, 1));
    line-height: var(--reader-line-height, 1.5);
}

.reader-preview-link {
    color: var(--reader-link);
    text-decoration: underline;
}

.reader-preview p {
    margin: 0 0 0.75em;
}

.reader-preview p:last-child {
    margin-bottom: 0;
}

.style-section {
    margin-bottom: 18px;
}

.style-section-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    opacity: 0.85;
}

.style-segmented {
    display: flex;
    gap: 0;
    border: 1px solid var(--reader-border);
}

.style-segmented--quad {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.style-segmented--grid {
    display: grid;
    grid-template-columns: repeat(var(--segment-cols, 2), 1fr);
}

.style-segmented--quad .style-segment,
.style-segmented--grid .style-segment {
    border-right: 1px solid var(--reader-border);
    border-bottom: 1px solid var(--reader-border);
}

.style-segmented--quad .style-segment:nth-child(2n),
.style-segmented--grid .style-segment:nth-child(2n) {
    border-right: none;
}

.style-segmented--quad .style-segment:nth-last-child(-n+2),
.style-segmented--grid .style-segment:nth-last-child(-n+2) {
    border-bottom: none;
}

.style-segmented--quad .style-segment:last-child,
.style-segmented--grid .style-segment:last-child {
    border-right: none;
}

.style-segmented--has-featured .style-segment-theme--featured {
    grid-column: 1 / -1;
    border-right: none;
}

.style-segmented--has-featured .style-segment:nth-child(2n) {
    border-right: 1px solid var(--reader-border);
}

.style-segmented--has-featured .style-segment:nth-child(2n + 1):not(.style-segment-theme--featured) {
    border-right: none;
}

.style-segment {
    flex: 1;
    min-width: 0;
    padding: 8px 6px;
    border: none;
    border-right: 1px solid var(--reader-border);
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, outline 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    outline: 2px solid transparent;
    outline-offset: -2px;
}

.style-segment:last-child {
    border-right: none;
}

.style-segment[aria-pressed="true"]:not(.style-segment-theme):not(.style-segment-font) {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
}

.style-segment-theme {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    padding: 8px 6px;
}

.style-segment-theme[aria-pressed="true"],
.style-segment-font[aria-pressed="true"] {
    outline-color: currentColor;
    z-index: 1;
}

.style-segment-font[aria-pressed="true"] {
    background-color: transparent;
    color: inherit;
}

.style-segment-font .style-segment-label,
.style-segment-theme .style-segment-label {
    font-size: 11px;
}

.style-segment-font .style-segment-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 14px;
    line-height: 1;
}

.style-segment-font {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 48px;
    padding: 8px 6px;
}

.style-segment-sample {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 22px;
    font-size: 18px;
    line-height: 1;
    overflow: hidden;
}

.style-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--reader-border);
    padding: 6px 10px;
    overflow: visible;
}

.style-stepper-value {
    flex: 1;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.85;
}

.style-stepper-reset {
    position: relative;
    background: none;
    border: none;
    padding: 8px 4px;
    min-height: 44px;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.style-stepper-reset:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.style-stepper-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
    cursor: pointer;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

.style-stepper-btn::after,
.style-stepper-reset::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    background-color: var(--reader-tooltip-bg);
    color: var(--reader-tooltip-text);
    padding: 6px 10px;
    font-size: 12px;
    font-weight: normal;
    font-family: var(--reader-body-font, 'iAWriterMonoV', monospace);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 3100;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

@media (hover: hover) and (pointer: fine) {
    .style-stepper-btn:hover::after,
    .style-stepper-reset:hover::after {
        opacity: 1;
        visibility: visible;
    }
}

.style-stepper-btn:first-child::after {
    left: 0;
    transform: translateY(-6px);
}

.style-stepper-btn:last-child::after {
    left: auto;
    right: 0;
    transform: translateY(-6px);
}

.style-stepper-btn img {
    width: 20px;
    height: 20px;
    filter: var(--reader-icon-filter);
}

.style-align-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--reader-border);
}

.style-align-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 6px;
    border: none;
    border-right: 1px solid var(--reader-border);
    background: transparent;
    color: inherit;
    font-family: 'iAWriterMonoV', monospace;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.style-align-label {
    font-family: 'iAWriterMonoV', monospace;
    font-size: 11px;
}

.style-align-btn:last-child {
    border-right: none;
}

.style-align-btn[aria-pressed="true"] {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
}

.style-align-btn img {
    width: 20px;
    height: 20px;
    filter: var(--reader-icon-filter);
}

.style-align-btn[aria-pressed="true"] img {
    filter: invert(1);
}

body[data-theme="dark"] .style-align-btn[aria-pressed="true"] img {
    filter: none;
}

body[data-theme="solarized"] .style-align-btn[aria-pressed="true"] img {
    filter: none;
}

.style-segment:focus-visible,
.style-stepper-btn:focus-visible,
.style-stepper-reset:focus-visible,
.style-align-btn:focus-visible,
.style-reset-all-btn:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

#format-menu-overlay {
    position: fixed;
    top: 70px;
    left: 0;
    width: 100vw;
    height: calc(100vh - 70px);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 2980;
}

body.format-menu-open #format-menu-overlay {
    opacity: 1;
    visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
    #format-menu-container,
    #format-menu-overlay {
        transition: none;
    }
}

.post-meta {
    font-size: 0.9rem;
    opacity: 0.85;
    margin-bottom: 1.5rem;
    text-align: left;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    align-items: center;
}

main#content > h1:has(+ h3.page-subtitle) {
    margin-bottom: 0;
}

h3.page-subtitle {
    font-style: italic;
    font-weight: normal;
    font-size: calc(24px * var(--text-scale, 1));
    color: var(--reader-caption);
    margin-top: 0;
    margin-bottom: 0.85rem;
}

.post-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.meta-icon {
    width: 0.95em;
    height: 0.95em;
    flex-shrink: 0;
    opacity: 0.75;
    object-fit: contain;
    vertical-align: -0.1em;
    filter: var(--reader-icon-filter);
}

.meta-icon.reason-icon {
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    opacity: 1;
    vertical-align: middle;
}

.reason-icon {
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
    filter: var(--reader-icon-filter);
}

.chapter-meta .post-meta-item,
.chapter-meta .meta-icon {
    vertical-align: middle;
}

.chapter-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    align-items: center;
}

.chapter-kind-badge--part {
    /* inherits badge layout */
}

.collection-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 0 0 16px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--reader-border);
    font-size: 0.85rem;
    opacity: 0.75;
}

.collection-nav--bottom {
    padding: 16px 0 0;
    margin-bottom: 0;
    margin-top: 12px;
    border-bottom: none;
    border-top: 1px solid var(--reader-border);
}

footer .collection-nav {
    text-align: left;
}

.collection-nav-meta {
    text-align: center;
    flex: 1;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.collection-nav-meta:hover,
.collection-nav-meta:focus-visible {
    text-decoration: underline;
}

.collection-nav-link {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.collection-nav-link:hover,
.collection-nav-link:focus-visible {
    text-decoration: underline;
}

.collection-nav-spacer {
    min-width: 80px;
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    padding: 8px 16px;
    z-index: 9999;
    font-family: inherit;
    font-size: 14px;
    text-decoration: none;
    border: 2px solid currentColor;
}

.skip-link:focus {
    top: 8px;
    left: 8px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.nav-btn:focus-visible,
.category-btn:focus-visible,
.chapter:focus-visible,
.toc-link:focus-visible,
.lightbox-close:focus-visible,
.toc-scroll-indicator:focus-visible,
figure.post-image :is(img, video):focus-visible,
:is(img, video).post-image-uncaptioned:focus-visible,
.posts-pagination-link:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.read-progress-item:focus-within,
.post-card-row.continue-reading-item:focus-within {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

#content:focus {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    @view-transition {
        navigation: none;
    }
}

/* ==========================================
   HEADING ANCHOR LINKS
   ========================================== */
.heading-anchor {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    margin-left: 0.4em;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.heading-anchor img {
    width: 0.85em;
    height: 0.85em;
    display: block;
    filter: var(--reader-icon-filter);
}

main h2:hover .heading-anchor,
main h3:hover .heading-anchor,
main h4:hover .heading-anchor,
main h5:hover .heading-anchor,
main h6:hover .heading-anchor,
main h2:focus-within .heading-anchor,
main h3:focus-within .heading-anchor,
main h4:focus-within .heading-anchor,
main h5:focus-within .heading-anchor,
main h6:focus-within .heading-anchor,
.heading-anchor:focus-visible {
    opacity: 0.45;
}

@media (pointer: coarse) {
    .heading-anchor {
        opacity: 0.35;
    }
}

.heading-anchor:hover,
.heading-anchor:focus-visible,
.heading-anchor.is-copied {
    opacity: 1;
}

.heading-anchor:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    border-radius: 2px;
}

.heading-anchor.is-copied {
    font-size: 0.75em;
    font-family: inherit;
}

/* ==========================================
   READING PROGRESS PROMPT
   ========================================== */
.read-progress-prompt {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3010;
    width: min(100% - 32px, 42rem);
    margin: 0;
    padding: 0;
    pointer-events: none;
}

.read-progress-prompt[hidden] {
    display: none;
}

body.format-menu-open .read-progress-prompt {
    visibility: hidden;
}

.read-progress-item,
.post-card-row.continue-reading-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    margin: 10px 0;
    padding: 0;
    overflow: hidden;
    border: 2px solid var(--reader-text);
    background-color: var(--reader-bg);
    pointer-events: auto;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.18s ease, opacity 0.18s ease;
    touch-action: pan-y;
}

.read-progress-prompt .post-card-row.continue-reading-item {
    margin: 0;
}

.continue-reading-list .post-card-row.continue-reading-item {
    margin: 10px 0;
}

.read-progress-item:hover,
.read-progress-item:focus-within,
.post-card-row.continue-reading-item:hover,
.post-card-row.continue-reading-item:focus-within {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.continue-reading-card,
.read-progress-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.75rem 1.25rem;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 10px;
    padding-right: 0.75rem;
    font-family: inherit;
    font-size: inherit;
    text-align: left;
    text-decoration: none;
    color: inherit;
    background: transparent;
    border: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    min-width: 0;
}

.continue-reading-card:hover,
.read-progress-card:hover,
.continue-reading-card:focus-visible,
.read-progress-card:focus-visible {
    outline: none;
}

.continue-reading-text {
    min-width: 0;
    overflow: hidden;
}

.continue-reading-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.continue-reading-card .continue-reading-text h3,
.continue-reading-card .continue-reading-text .read-progress-label {
    margin: 0;
    font-size: inherit;
    font-weight: bold;
}

.read-progress-hint,
.continue-reading-hint {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    opacity: 0.85;
}

.read-progress-item:hover .read-progress-hint,
.read-progress-item:focus-within .read-progress-hint,
.post-card-row.continue-reading-item:hover .read-progress-hint,
.post-card-row.continue-reading-item:focus-within .read-progress-hint,
.post-card-row.continue-reading-item:hover .continue-reading-hint,
.post-card-row.continue-reading-item:focus-within .continue-reading-hint {
    opacity: 0.85;
}

.continue-reading-progress {
    width: 4rem;
    height: 0.35rem;
    background: transparent;
    border: 2px solid currentColor;
    overflow: hidden;
}

.continue-reading-progress-bar {
    height: 100%;
    background: currentColor;
    transition: width 0.3s ease;
}

.continue-reading-pct {
    font-size: 0.85rem;
    min-width: 0;
    text-align: left;
    font-weight: bold;
    white-space: nowrap;
}

.reading-dismiss {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: stretch;
    min-width: 44px;
    padding: 8px 12px;
    border-top: none;
    border-right: none;
    border-bottom: none;
    border-left: 2px solid currentColor;
    border-radius: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-family: inherit;
}

.reading-dismiss img {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
    filter: var(--reader-icon-filter);
    pointer-events: none;
}

.read-progress-item:hover .reading-dismiss,
.read-progress-item:focus-within .reading-dismiss,
.post-card-row.continue-reading-item:hover .reading-dismiss,
.post-card-row.continue-reading-item:focus-within .reading-dismiss {
    border-left-color: var(--reader-hover-text);
    color: var(--reader-hover-text);
}

.read-progress-item:hover .reading-dismiss img,
.read-progress-item:focus-within .reading-dismiss img,
.post-card-row.continue-reading-item:hover .reading-dismiss img,
.post-card-row.continue-reading-item:focus-within .reading-dismiss img {
    filter: invert(1);
}

body[data-theme="dark"] .read-progress-item:hover .reading-dismiss img,
body[data-theme="dark"] .read-progress-item:focus-within .reading-dismiss img,
body[data-theme="dark"] .post-card-row.continue-reading-item:hover .reading-dismiss img,
body[data-theme="dark"] .post-card-row.continue-reading-item:focus-within .reading-dismiss img,
body[data-theme="solarized"] .read-progress-item:hover .reading-dismiss img,
body[data-theme="solarized"] .read-progress-item:focus-within .reading-dismiss img,
body[data-theme="solarized"] .post-card-row.continue-reading-item:hover .reading-dismiss img,
body[data-theme="solarized"] .post-card-row.continue-reading-item:focus-within .reading-dismiss img {
    filter: none;
}

@media (min-width: 1024px) {
    .read-progress-prompt {
        left: 20%;
        width: 60%;
        max-width: none;
        transform: none;
    }
}

@media (min-width: 1200px) {
    body.has-toc .read-progress-prompt {
        left: 30%;
    }
}

/* Posts index header */
.posts-index-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 1rem;
    margin-bottom: 1.25rem;
}

.posts-index-header h1 {
    margin: 0;
}

.posts-index-header p {
    margin: 0;
    opacity: 0.85;
}

/* Continue reading (index) — shares chapter styling */
.continue-reading {
    margin-bottom: 25px;
}

.continue-reading-label {
    display: block;
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 12px;
}

.continue-reading-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.card-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0 0 0.2rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.65;
    line-height: 1;
    min-height: 14px;
    overflow: visible;
}

@media (max-width: 540px) {
    .continue-reading-card,
    .read-progress-card {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: 0.5rem;
        align-items: start;
    }

    .continue-reading-card .continue-reading-text h3,
    .read-progress-label {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .continue-reading-card .continue-reading-text p,
    .read-progress-hint,
    .continue-reading-hint {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .continue-reading-meta {
        width: 100%;
    }

    .continue-reading-progress {
        width: 3rem;
        flex-shrink: 0;
    }
}

/* Chapter index sort */
/* chapter-sort-toolbar defined above */


/* Spoilers */
.spoiler {
    display: inline;
    border: none;
    background: var(--reader-spoiler-bg, rgba(128, 128, 128, 0.25));
    color: transparent;
    text-shadow: none;
    border-radius: 2px;
    padding: 0 0.15em;
    cursor: pointer;
    font: inherit;
    line-height: inherit;
    vertical-align: baseline;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.spoiler.is-revealed {
    color: inherit;
    background: var(--reader-spoiler-revealed-bg, rgba(128, 128, 128, 0.12));
    border-radius: 2px;
}

.spoiler:not(.is-revealed):hover,
.spoiler:not(.is-revealed):focus-visible {
    background: var(--reader-spoiler-hover-bg, rgba(128, 128, 128, 0.35));
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

/* Content warnings */
.content-warning {
    position: relative;
    margin: 1rem 0 1.25rem;
    padding: 0.85rem 2.75rem 0.85rem 0.85rem;
    border: 2px solid var(--reader-warning-border, #c62828);
    background: var(--reader-warning-bg, rgba(198, 40, 40, 0.12));
    color: inherit;
}

.content-warning-label {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--reader-warning-border, #c62828);
}

.content-warning ul,
.content-warning p {
    margin: 0;
}

.content-warning ul {
    padding-left: 1.25rem;
}

.content-warning-dismiss {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* Footnotes */
.footnote-ref {
    font-size: 0.75em;
    line-height: 0;
    vertical-align: super;
}

.footnote-link {
    color: inherit;
    text-decoration: none;
    padding: 0 0.1em;
}

.footnote-link:hover,
.footnote-link:focus-visible {
    text-decoration: underline;
}

.footnotes {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--reader-pre-border);
    font-size: 0.9rem;
}

.footnotes-heading {
    font-size: 1rem;
    font-weight: normal;
    margin: 0 0 0.75rem;
    opacity: 0.85;
}

.footnotes ol {
    margin: 0;
    padding-left: 1.5rem;
}

.footnotes li {
    margin: 0.35rem 0;
}

.footnote-backref {
    color: inherit;
    text-decoration: none;
    margin-left: 0.25rem;
}

.footnote-preview {
    position: absolute;
    z-index: 4000;
    max-width: 20rem;
    padding: 0.6rem 0.75rem;
    border: 2px solid currentColor;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 0.85rem;
    line-height: 1.45;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.footnote-preview[hidden] {
    display: none !important;
}

/* Sources */
.source-ref {
    font-size: 0.75em;
    line-height: 0;
    vertical-align: super;
}

.source-link {
    color: inherit;
    text-decoration: none;
    padding: 0 0.1em;
}

.source-link:hover,
.source-link:focus-visible {
    text-decoration: underline;
}

.sources {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--reader-pre-border);
    font-size: 0.9rem;
}

.sources-heading {
    font-size: 1rem;
    font-weight: normal;
    margin: 0 0 0.75rem;
    opacity: 0.85;
}

.sources ol {
    margin: 0;
    padding-left: 1.5rem;
}

.sources li {
    margin: 0.35rem 0;
}

.source-backref {
    color: inherit;
    text-decoration: none;
    margin-left: 0.25rem;
}

/* Chapter sort toggle */
.chapter-sort-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.chapter-sort-toggle {
    min-height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.35rem 0.65rem;
}

.chapter-sort-toggle img {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
    flex-shrink: 0;
    object-fit: contain;
    filter: var(--reader-icon-filter);
}

.chapter-sort-label {
    font-size: 0.8rem;
    font-weight: bold;
    white-space: nowrap;
}

.chapter-sort-toggle.category-btn:hover img,
.chapter-sort-toggle.category-btn:focus-visible img {
    filter: invert(1);
}

body[data-theme="dark"] .chapter-sort-toggle.category-btn:hover img,
body[data-theme="dark"] .chapter-sort-toggle.category-btn:focus-visible img,
body[data-theme="solarized"] .chapter-sort-toggle.category-btn:hover img,
body[data-theme="solarized"] .chapter-sort-toggle.category-btn:focus-visible img {
    filter: none;
}

/* Card progress indicators */
.chapter-item,
.part-item {
    position: relative;
}

.chapter-item.has-reading-progress,
.part-item.has-reading-progress {
    overflow: hidden;
}

.chapter-item.has-reading-progress::after,
.part-item.has-reading-progress::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    pointer-events: none;
    z-index: 3;
    background: linear-gradient(
        to right,
        var(--reader-progress) 0,
        var(--reader-progress) var(--card-progress, 0%),
        var(--reader-progress-track, rgba(128, 128, 128, 0.28)) var(--card-progress, 0%),
        var(--reader-progress-track, rgba(128, 128, 128, 0.28)) 100%
    );
    box-shadow: 0 -1px 3px var(--reader-card-progress-shadow, rgba(0, 0, 0, 0.12));
}

.chapter-item.has-reading-progress:hover::after,
.chapter-item.has-reading-progress:focus-visible::after,
.part-item.has-reading-progress:hover::after,
.part-item.has-reading-progress:focus-visible::after,
.post-card-row:hover .chapter-item.has-reading-progress::after,
.post-card-row:focus-within .chapter-item.has-reading-progress::after {
    background: linear-gradient(
        to right,
        var(--reader-progress) 0,
        var(--reader-progress) var(--card-progress, 0%),
        var(--reader-progress-track, rgba(128, 128, 128, 0.28)) var(--card-progress, 0%),
        var(--reader-progress-track, rgba(128, 128, 128, 0.28)) 100%
    );
    box-shadow: 0 -1px 3px var(--reader-card-progress-shadow, rgba(0, 0, 0, 0.12));
}

.part-item p {
    margin: 0.45rem 0 0;
    padding-top: 0.45rem;
    border-top: 2px solid var(--reader-border);
    opacity: 0.85;
    line-height: 1.35;
}

.card-progress-pct,
.card-progress-finished {
    position: absolute;
    right: 0.45rem;
    bottom: 0.5rem;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.card-progress-pct {
    font-size: 0.85rem;
    font-weight: bold;
    line-height: 1;
}

.card-progress-finished {
    width: 1.1rem;
    height: 1.1rem;
}

.card-progress-finished img {
    width: 0.85rem;
    height: 0.85rem;
    display: block;
    filter: var(--reader-icon-filter);
}

#share-button.is-copied,
#rss-button.is-copied {
    font-size: 0.75rem;
    width: auto;
    padding: 0 0.35rem;
}

/* Post comments (ATProto / Bluesky replies) */
.comments-mount {
    min-height: 1px;
}

.post-comments {
    margin-top: 3rem;
    padding-top: 0;
    overflow: visible;
}

.post-comments ::selection {
    background: var(--reader-comments-selection);
}

.post-comments .comments-toggle.category-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Keep filled active/hover state; global .category-btn.active:hover clears the fill */
.post-comments .category-btn.active:hover,
.post-comments .category-btn.active:focus-visible {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.post-comments .category-btn img {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
    filter: var(--reader-icon-filter);
    transition: filter 0.2s ease;
}

.post-comments .comments-sort-btn img {
    width: 1rem;
    height: 1rem;
}

.post-comments .category-btn:hover img,
.post-comments .category-btn:focus-visible img,
.post-comments .category-btn.active img {
    filter: invert(1);
}

body[data-theme="dark"] .post-comments .category-btn:hover img,
body[data-theme="dark"] .post-comments .category-btn:focus-visible img,
body[data-theme="dark"] .post-comments .category-btn.active img,
body[data-theme="solarized"] .post-comments .category-btn:hover img,
body[data-theme="solarized"] .post-comments .category-btn:focus-visible img,
body[data-theme="solarized"] .post-comments .category-btn.active img {
    filter: none;
}

.comments-panel {
    display: grid;
    grid-template-rows: 0fr;
    margin-top: 0;
    min-width: 0;
    transition: grid-template-rows 0.35s ease, margin-top 0.35s ease;
}

.comments-panel.is-open {
    grid-template-rows: 1fr;
    margin-top: 0.875rem;
}

.comments-panel-inner {
    overflow-x: visible;
    overflow-y: hidden;
    min-height: 0;
    min-width: 0;
}

.comments-panel.is-open .comments-panel-inner {
    overflow: visible;
}

.comments-leave-link {
    margin-bottom: 1.125rem;
}

.post-comments .comments-bsky-link {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.post-comments .comments-bsky-link .link-card-header {
    min-width: 0;
}

.comments-sort-wrap {
    margin-top: 1.25rem;
    margin-bottom: 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--reader-border);
}

.comments-sort-label {
    margin-bottom: 0.75rem;
}

.comments-sort {
    display: flex;
    gap: 0.5rem;
}

.comments-sort-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
}

.comments-view-full-link {
    margin-top: 1rem;
    margin-bottom: 0;
}

.comment-truncated-wrap {
    position: relative;
    margin-bottom: 0.5rem;
    min-height: 3.5em;
}

.comment-body--faded {
    max-height: 4.8em;
    overflow: hidden;
    margin-bottom: 0;
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 30%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0%, #000 30%, transparent 100%);
}

.comment-continue-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 1rem 0 0;
    background: linear-gradient(to bottom, transparent 0%, color-mix(in srgb, var(--reader-bg) 50%, transparent) 40%, var(--reader-bg) 85%);
    pointer-events: none;
}

.comment-continue-btn {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    line-height: 1.3;
    font-family: inherit;
    color: var(--reader-text);
    text-decoration: none;
    border: 1px solid var(--reader-border);
    background: var(--reader-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.comment-continue-btn:hover,
.comment-continue-btn:focus-visible {
    color: var(--reader-link-active);
    border-color: var(--reader-link);
}

.comments-bsky-link h3 {
    font-size: 1rem;
    min-width: 0;
}

.comments-empty {
    color: var(--reader-caption);
    margin: 0.5rem 0 0;
    font-style: italic;
}

.post-comments a:focus-visible,
.post-comments button:focus-visible {
    outline: 2px solid var(--reader-link);
    outline-offset: 2px;
}

.comment-tree {
    display: flex;
    flex-direction: column;
    margin-top: 0.25rem;
    --comment-top-gap: 0.5rem;
    --comment-nest-indent: 1.25rem;
}

.comment-tree > .comment-node {
    padding-top: 1.25rem;
}

.comment-tree > .comment-node:first-child {
    padding-top: 0;
}

.comment-collapse-inner {
    overflow: hidden;
    min-height: 0;
}

.comment-collapse-inner > .comment-children {
    margin-top: 0.75rem;
    padding-left: var(--comment-nest-indent);
}

.comment-collapse-target {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.28s ease, opacity 0.28s ease;
}

.comment-node.is-collapsed .comment-collapse-target {
    grid-template-rows: 0fr;
    opacity: 0.55;
}

.comment-children > .comment-node {
    padding-top: 0.875rem;
}

.comment-children > .comment-node:first-child {
    padding-top: 0;
}

.comment-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--comment-top-gap);
    --comment-header-size: 0.9rem;
    --comment-icon-size: var(--comment-header-size);
    --comment-avatar-size: var(--comment-icon-size);
    --comment-control-size: var(--comment-icon-size);
    --comment-leader-width: calc(
        var(--comment-control-size) + var(--comment-avatar-size) + 2 * var(--comment-top-gap)
    );
    font-size: var(--comment-header-size);
}

.comment-layout > .comment-header,
.comment-layout > .comment-collapse-slot,
.comment-layout > .comment-profile-link {
    line-height: 1;
}

.comment-collapse-slot {
    flex: 0 0 var(--comment-control-size);
    width: var(--comment-control-size);
    height: var(--comment-control-size);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.comment-layout > .comment-profile-link,
.comment-layout > .comment-avatar,
.comment-layout > .comment-avatar--fallback {
    flex: 0 0 var(--comment-avatar-size);
}

.comment-layout > .comment-profile-link {
    display: block;
    line-height: 0;
    width: var(--comment-avatar-size);
    height: var(--comment-avatar-size);
}

.comment-layout > .comment-header {
    flex: 1 1 0;
    min-width: 0;
    margin-bottom: 0;
}

.comment-content {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    padding-left: var(--comment-leader-width);
    padding-top: 0.25rem;
    box-sizing: border-box;
    font-size: 1rem;
    line-height: var(--reader-line-height, 1.6);
}

.comment-node--compact .comment-layout {
    --comment-leader-width: calc(var(--comment-avatar-size) + var(--comment-top-gap));
}

.comment-node--compact .comment-layout > .comment-profile-link {
    width: var(--comment-avatar-size);
    height: var(--comment-avatar-size);
}

.comment-header {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.35rem 0.5rem;
    min-width: 0;
    line-height: 1;
}

.comment-header .comment-author {
    flex: 0 1 auto;
    min-width: 0;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.comment-time {
    flex: 0 0 auto;
    margin-left: auto;
    white-space: nowrap;
    color: var(--reader-caption);
    font-size: 0.85rem;
}

.comment-collapse-btn {
    flex-shrink: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.comment-collapse-icon {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 0.62em;
    line-height: 1;
    font-weight: 700;
    font-family: var(--reader-body-font, 'iAWriterMonoV', monospace);
}

.comment-collapse-btn[aria-expanded="true"] .comment-collapse-icon::before {
    content: '−';
    display: block;
    transform: translateY(-0.5px);
}

.comment-collapse-btn[aria-expanded="false"] .comment-collapse-icon::before {
    content: '+';
    display: block;
    transform: translateY(-0.5px);
}

@media (hover: none) {
    .comment-collapse-slot {
        width: var(--comment-control-size);
        overflow: visible;
    }

    .comment-collapse-slot .comment-collapse-btn {
        margin-left: 0;
    }

    .comment-collapse-btn::before {
        content: '';
        position: absolute;
        inset: -0.875rem;
    }

    .comment-actions {
        gap: 0.5rem 1rem;
    }

    .comment-action-link {
        min-height: 2.75rem;
        padding: 0.35rem 0.15rem;
    }

    .comments-sort-btn {
        min-height: 2.75rem;
        padding: 0.5rem 0.65rem;
    }

    .comment-tree > .comment-node {
        padding-top: 1rem;
    }
}

@media (max-width: 540px) {
    .post-comments {
        margin-top: 2rem;
    }

    .comments-leave-link {
        margin-bottom: 1rem;
    }

    .comment-tree {
        --comment-nest-indent: 0.375rem;
    }

    .comment-node--compact .comment-layout {
        --comment-top-gap: 0.35rem;
    }

    .comment-layout {
        --comment-header-size: 0.85rem;
        --comment-top-gap: 0.4rem;
    }

    .comment-content {
        font-size: 0.95rem;
    }
}

.comment-collapse-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    top: auto;
    bottom: calc(100% + 4px);
    left: 0;
    transform: none;
    background-color: var(--reader-tooltip-bg);
    color: var(--reader-tooltip-text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: normal;
    font-family: var(--reader-body-font, 'iAWriterMonoV', monospace);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 3100;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

@media (hover: hover) and (pointer: fine) {
    .comment-collapse-btn:hover::after,
    .comment-collapse-btn:focus-visible::after {
        opacity: 1;
        visibility: visible;
    }
}

@media (prefers-reduced-motion: reduce) {
    .comments-panel,
    .comment-collapse-target {
        transition: none;
    }

    .comment-body--faded {
        -webkit-mask-image: none;
        mask-image: none;
        max-height: 4.8em;
    }

    .comment-continue-overlay {
        background: var(--reader-bg);
    }
}

.comment-profile-link {
    color: inherit;
    text-decoration: none;
}

.comment-profile-link:hover,
.comment-profile-link:focus-visible {
    text-decoration: underline;
}

.comment-avatar {
    flex-shrink: 0;
    box-sizing: border-box;
    width: var(--comment-avatar-size);
    height: var(--comment-avatar-size);
    border-radius: 50%;
    object-fit: cover;
    margin: 0;
    border: 1px solid var(--reader-border-subtle);
}

.comment-avatar--fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: var(--comment-avatar-size);
    height: var(--comment-avatar-size);
    border-radius: 50%;
    border: 1px solid var(--reader-border-subtle);
    background: var(--reader-pre-bg);
}

.comment-avatar--fallback img {
    width: 55%;
    height: 55%;
    filter: var(--reader-icon-filter);
}

.comment-header--collapsible {
    cursor: pointer;
}

.comment-author .comment-display-name,
.comment-author .comment-handle,
.comment-author .comment-author-badge {
    display: inline;
    white-space: inherit;
}

.comment-author .comment-handle {
    margin-left: 0.35em;
}

.comment-display-name {
    font-weight: bold;
    line-height: 1;
}

.comment-handle {
    color: var(--reader-caption);
    font-size: 0.9rem;
}

.comment-author-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: bold;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.1rem 0.35rem;
    border: 1px solid var(--reader-border);
    color: var(--reader-caption);
}

.comment-body {
    margin-bottom: 0.35rem;
    line-height: var(--reader-line-height, 1.6);
    white-space: pre-wrap;
    word-break: break-word;
}

.comment-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    font-size: 0.85rem;
}

.comment-action-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--reader-link);
    text-decoration: none;
}

.comment-action-link img {
    width: 0.95rem;
    height: 0.95rem;
    filter: var(--reader-icon-filter);
}

.comment-like-link {
    color: var(--reader-comments-like, #EC4899);
}

.comment-like-icon {
    display: inline-block;
    flex-shrink: 0;
    width: 0.95rem;
    height: 0.95rem;
    background-color: var(--reader-comments-like, #EC4899);
    -webkit-mask-image: url(/svg/ui/favorite.svg);
    mask-image: url(/svg/ui/favorite.svg);
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.comment-action-link:hover,
.comment-action-link:focus-visible {
    color: var(--reader-link-active);
}

.comment-like-link:hover,
.comment-like-link:focus-visible {
    color: var(--reader-comments-like, #EC4899);
    opacity: 0.85;
}

.comments-loading,
.comments-error {
    color: var(--reader-caption);
    margin: 0.5rem 0 0;
}

.comments-retry-btn {
    margin-top: 0.5rem;
}

/* Related posts — reuses continue-reading card layout */
.related-posts {
    margin-top: 3rem;
    padding-top: 0;
    border-top: none;
}

.related-posts .continue-reading-label {
    margin-bottom: 0.75rem;
}

.related-posts-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.related-posts-list .related-post-card {
    display: block;
    margin: 6px 0;
    padding: 10px;
    text-decoration: none;
}

.related-post-link {
    display: block;
    text-decoration: none;
    color: inherit;
    border: 2px solid var(--reader-text);
    padding: 0.65rem 0.75rem;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.related-post-link:hover {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
}

.related-post-link:focus-visible {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.related-post-link h3 {
    margin: 0;
    font-size: 1rem;
}

.related-post-link p {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    opacity: 0.8;
}

.series-up-next {
    margin-top: 3rem;
    padding-top: 0;
    border-top: none;
}

.series-up-next-link {
    padding: 1rem 0.85rem;
}

.series-up-next--end {
    margin-top: 3rem;
}

.series-up-next-link--disabled {
    display: block;
    border: 2px solid var(--reader-text);
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.series-up-next-link--disabled p {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    opacity: 0.8;
}

.series-up-next-link--disabled .card-eyebrow,
.series-up-next-link--disabled .related-post-reason {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.chapter-kind-badge--series {
    /* inherits collection badge layout */
}

/* Search result keyboard focus */
.search-result-item:focus-visible {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
    border-color: var(--reader-text);
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* ==========================================
   HOMEPAGE
   ========================================== */
body[data-homepage] {
    text-align: left;
}

body[data-homepage] header {
    text-align: center;
    margin-bottom: 0;
}

.logo {
    height: 128px;
    transition: filter 0.2s ease;
    filter: var(--reader-icon-filter);
}

.pronouns {
    text-align: center;
    margin-top: 4px;
    margin-bottom: 0;
}

.divider {
    border: none;
    border-top: 1px solid var(--reader-border-subtle);
    margin: 24px 0;
}

.section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 16px;
    text-align: left;
}

.link-card {
    display: block;
    text-decoration: none;
    color: inherit;
    background-color: inherit;
    border: 2px solid currentColor;
    cursor: pointer;
    margin: 10px 0;
    padding: 10px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.link-card:hover,
.link-card:focus-visible {
    background-color: var(--reader-hover-bg);
    color: var(--reader-hover-text);
}

.link-card[data-brand]:hover,
.link-card[data-brand]:focus-visible {
    background-color: var(--link-brand-accent);
    color: var(--reader-bg);
    border-color: var(--link-brand-accent);
}

.link-card[data-brand]:hover .link-icon,
.link-card[data-brand]:focus-visible .link-icon {
    background-color: var(--reader-bg);
}

.link-card:not([data-brand]):hover .link-icon,
.link-card:not([data-brand]):focus-visible .link-icon {
    filter: invert(1);
}

body[data-theme="dark"] .link-card:not([data-brand]):hover .link-icon,
body[data-theme="dark"] .link-card:not([data-brand]):focus-visible .link-icon,
body[data-theme="solarized"] .link-card:not([data-brand]):hover .link-icon,
body[data-theme="solarized"] .link-card:not([data-brand]):focus-visible .link-icon {
    filter: none;
}

.link-card[data-brand] {
    color: var(--reader-text);
    border-color: var(--link-brand-accent);
}

.link-card[data-brand="bluesky"] { --link-brand-accent: var(--brand-bluesky); }
.link-card[data-brand="lastfm"] { --link-brand-accent: var(--brand-lastfm); }
.link-card[data-brand="letterboxd"] { --link-brand-accent: var(--brand-letterboxd); }
.link-card[data-brand="storygraph"] { --link-brand-accent: var(--brand-storygraph); }
.link-card[data-brand="backloggd"] { --link-brand-accent: var(--brand-backloggd); }

.link-card[data-brand] .link-icon {
    filter: none;
    background-color: var(--link-brand-accent);
    -webkit-mask: center / contain no-repeat;
    mask: center / contain no-repeat;
}

.link-card[data-brand="bluesky"] .link-icon {
    -webkit-mask-image: url(/svg/social/bluesky.svg);
    mask-image: url(/svg/social/bluesky.svg);
}

.link-card[data-brand="lastfm"] .link-icon {
    -webkit-mask-image: url(/svg/social/lastfm.svg);
    mask-image: url(/svg/social/lastfm.svg);
}

.link-card[data-brand="letterboxd"] .link-icon {
    -webkit-mask-image: url(/svg/social/letterboxd.svg);
    mask-image: url(/svg/social/letterboxd.svg);
}

.link-card[data-brand="storygraph"] .link-icon {
    -webkit-mask-image: url(/svg/social/storygraph.svg);
    mask-image: url(/svg/social/storygraph.svg);
}

.link-card[data-brand="backloggd"] .link-icon {
    -webkit-mask-image: url(/svg/social/backloggd.svg);
    mask-image: url(/svg/social/backloggd.svg);
}

.link-card:hover p,
.link-card:focus-visible p {
    opacity: 0.8;
    color: inherit;
}

.link-card:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.link-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.link-icon {
    display: block;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    transition: background-color 0.2s ease, filter 0.2s ease;
    filter: var(--reader-icon-filter);
}

.link-card h3 {
    font-size: 1rem;
    font-weight: bold;
    margin: 0;
}

.link-card p {
    margin: 4px 0 0 0;
    font-size: 0.9rem;
    opacity: 0.7;
}

.link-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    column-gap: 10px;
    row-gap: 8px;
}

.link-grid-col {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    gap: 8px;
}

.link-grid-col--solo {
    grid-column: 1 / -1;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.link-grid-col--solo .link-card {
    margin: 0;
}

.link-grid-col .link-card {
    margin: 0;
}

.link-grid-col .link-stat-row {
    align-items: flex-start;
}

.link-grid-col .link-stat-row .stat-icon {
    margin-top: 0.15em;
}

.link-stat-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    opacity: 0.8;
}

.stat-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: filter 0.2s ease;
    filter: var(--reader-icon-filter);
}

.link-stat-row .primary {
    opacity: 1;
}

.link-stat-link {
    color: inherit;
    text-decoration: none;
}

.link-stat-link:hover .primary,
.link-stat-link:focus-visible .primary {
    text-decoration: underline;
}

.link-stat-when {
    opacity: 0.55;
    white-space: nowrap;
}

.link-stat-when::before {
    content: ' · ';
    opacity: 1;
}

.chapter-item--external h3 {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.external-link-icon {
    font-size: 0.85em;
    opacity: 0.7;
    line-height: 1;
}

.chapter-item--external:hover .external-link-icon,
.chapter-item--external:focus-visible .external-link-icon {
    opacity: 0.9;
}

body[data-homepage] .continue-reading-label {
    display: none;
}

body[data-homepage] footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--reader-border-subtle);
    opacity: 0.4;
    font-size: 0.85rem;
}

body[data-homepage] footer a {
    color: inherit;
    text-decoration: none;
}

body[data-homepage] footer a:hover {
    opacity: 0.6;
}

@media (max-width: 768px) {
    .link-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        gap: 20px;
    }

    .link-grid-col {
        display: flex;
        flex-direction: column;
        gap: 8px;
        grid-row: auto;
    }

    .link-grid .link-card {
        margin: 0;
    }
}

@media (max-width: 600px) {
    .logo {
        height: 96px;
    }
}

/* ==========================================
   PRINT / EXPORT
   ========================================== */
@media print {
    #top-nav,
    #scroll-progress-container,
    #toc-container,
    #toc-overlay,
    #format-menu-container,
    #format-menu-overlay,
    #lightbox-overlay,
    .skip-link,
    .collection-nav,
    .read-progress-prompt,
    .heading-anchor,
    .continue-reading,
    .post-comments,
    .chapter-sort-toolbar,
    .related-posts,
    .series-up-next {
        display: none !important;
    }

    html,
    body {
        background: #fff !important;
        color: #000 !important;
        margin: 1.5cm !important;
        font-size: 12pt !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body[data-theme="dark"],
    body[data-theme="sepia"],
    body[data-theme="solarized"],
    body.has-toc,
    body.left-aligned {
        background: #fff !important;
        color: #000 !important;
        margin: 1.5cm !important;
        text-align: left !important;
    }

    main {
        width: 100% !important;
        max-width: none !important;
    }

    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        color: #000 !important;
    }

    figure.post-image,
    pre,
    .post-image-uncaptioned {
        page-break-inside: avoid;
    }

    :is(img, video) {
        max-width: 100% !important;
    }

    a {
        color: #000 !important;
    }

    footer {
        border-top-color: #ccc !important;
    }
}