/* content/reading.css */
/* Loaded after chrome.css: the Latest panel, spoilers, the reading layout
   and the table of contents. */

/* Latest Post Preview Section
   A panel of its own colour, pushed out past the column edge so it reads as
   a different thing from the home page above it — while the text inside
   stays on exactly the same lines as the article page. It holds the whole
   article (preview.go); theme.js unrolls it as you scroll and fades the
   panel out (--handoff 0 -> 1) on the way into the article itself. */
.latest-post-preview {
    --pv-pad: 1.6rem;
    --pv-fade: calc(1 - var(--handoff, 0));
    margin: 5rem calc(-1 * var(--pv-pad)) 0;
    padding: 1.4rem var(--pv-pad) 0.5rem;
    border-radius: 14px;
    background: color-mix(in srgb, var(--accent-color) calc(9% * var(--pv-fade)), transparent);
    /* inset shadow, not a border, so the text doesn't shift sideways */
    box-shadow:
        inset 4px 0 0 color-mix(in srgb, var(--accent-color) calc(80% * var(--pv-fade)), transparent),
        0 0 0 1px color-mix(in srgb, var(--accent-color) calc(22% * var(--pv-fade)), transparent);
}

.mobile .latest-post-preview {
    --pv-pad: 1rem;
}

.latest-post-preview .latest-label {
    display: inline-block;
    margin: 0 0 0.5rem;
    padding: 0.25em 0.8em;
    border-radius: 999px;
    font-family: var(--font-heading);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-color);
    background: color-mix(in srgb, var(--accent-color) 16%, transparent);
    border-left: 0;
    opacity: var(--pv-fade);
}

.preview-content {
    position: relative;
    max-height: 400px;
    overflow: hidden;
    margin-bottom: 2rem;
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 220px), transparent 100%);
    mask-image: linear-gradient(to bottom, black calc(100% - 220px), transparent 100%);
}

/* The article's own title opens flush under the label. */
.preview-content > h1:first-child {
    margin-top: 0.4rem;
}

/* With JS the panel unrolls instead of offering a button. */
.latest-post-preview.unrolling .read-more-container {
    display: none;
}

/* Cross-document view transitions are on so the Latest -> article handoff
   can cross-fade between two identical-looking pages; every other
   navigation skips it (theme.js pageswap, handoffScript pagereveal). */
@view-transition {
    navigation: auto;
}

.read-more-container {
    text-align: center;
    margin-top: -1rem;
    position: relative;
    z-index: 10;
}

.read-more-btn {
    display: inline-block;
    padding: 10px 24px;
    border: 1px solid var(--sidebar-border);
    text-decoration: none;
    text-transform: uppercase;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    background: var(--bg-color);
    color: var(--text-color);
    border-radius: 3px;
}

.read-more-btn:hover {
    background: var(--link-color);
    color: #fff;
    border-color: var(--link-color);
    text-decoration: none;
}
/* ||spoiler|| — solid bar until clicked (theme.js toggles .revealed) */
.spoiler {
    border-radius: 3px;
    padding: 0 2px;
    background: var(--text-color);
    color: transparent;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}
.spoiler:not(.revealed) * {
    color: transparent !important;
    background: transparent !important;
    border-color: transparent !important;
    pointer-events: none;
}
.spoiler:not(.revealed) img,
.spoiler:not(.revealed) video {
    filter: blur(16px) brightness(0.4);
}
.spoiler:not(.revealed):hover { opacity: 0.85; }
.spoiler:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 1px; }
.spoiler.revealed {
    background: var(--code-bg);
    color: inherit;
    cursor: auto;
}

/* --------------------------------------------------------------------------
   Reading layout: clear segments, marked paragraph starts
   -------------------------------------------------------------------------- */

/* Every prose paragraph opens indented, so a new thought is visible at a
   glance even mid-scroll. Lists, quotes and tables keep their own shape. */
.main-content > p,
.main-content keypoint p,
.preview-content > p {
    text-indent: var(--para-indent);
}

/* Prose sits inset from the column edge, so headings, code blocks, tables
   and images (which keep the full width) frame the text around them. A
   paragraph that only carries an image counts as an image. */
.main-content,
.preview-content {
    --prose-inset: 1.4em;
}
.mobile .main-content,
.mobile .preview-content {
    --prose-inset: 0.6em;
}
:is(.main-content, .preview-content) > :is(p, ul, ol, dl, blockquote, keypoint):not(:has(> img, > a > img, > picture, > video, > iframe)) {
    margin-left: var(--prose-inset);
    margin-right: var(--prose-inset);
}

/* Headings anchor the TOC; leave room so a jump doesn't land flush. */
.main-content :is(h1, h2, h3, h4, h5, h6)[id] {
    scroll-margin-top: 1.5rem;
}

/* An H2 starts a new segment: a full-width rule above it in the heading's
   own colour, so sections read as separate blocks rather than one stream. */
.main-content > h2,
.preview-content > h2 {
    margin-top: 3.5em;
    padding-top: 0.9em;
    border-top: 3px solid color-mix(in srgb, var(--h2-color) 25%, transparent);
}

/* An H3 is a sub-segment: a short bar down its left edge. */
.main-content > h3,
.preview-content > h3 {
    margin-top: 2.4em;
    padding-left: 0.7em;
    border-left: 4px solid var(--h3-color);
}

.main-content li {
    margin-bottom: 0.45em;
}

.main-content li > p {
    margin: 0.3em 0;
}

/* !> keypoint — said louder than the prose around it: larger, darker,
   semibold and underlined, with breathing room above and below. Not a
   quote, so no bar and no italics. */
keypoint {
    display: block;
    margin: 2.2em 0;
    font-size: 1.22em;
    font-weight: 600;
    line-height: 1.5;
    color: var(--keypoint-color, #111014);
}

keypoint p {
    margin: 0 0 0.6em;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 0.22em;
    text-decoration-color: color-mix(in srgb, var(--accent-color) 70%, transparent);
    text-decoration-skip-ink: auto;
}

keypoint p:last-child {
    margin-bottom: 0;
}

body.dark-mode keypoint {
    --keypoint-color: #ffffff;
}

/* Table of contents (toc.go). Inline box under the title on narrow
   screens; on wide ones it moves into the left gutter and stays in view. */
.main-content {
    position: relative;
}

/* One thin guide line runs down the list; each entry hangs off it, and the
   section being read lights up its stretch of the line. Hierarchy comes
   from weight, size and colour rather than ever-deeper indents, so long
   titles don't get squeezed into towers of three-word lines. Selectors
   carry .main-content to outrank acord.css's link colour. */
.toc {
    margin: 1.5rem 0 2.5rem;
    padding: 0.9rem 1.1rem 1rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 10px;
    font-family: var(--font-primary);
    font-size: 0.86rem;
    line-height: 1.35;
}

.toc summary {
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.toc ol {
    list-style: none;
    margin: 0.8rem 0 0;
    padding: 0;
    border-left: 1px solid var(--sidebar-border);
}

.toc li {
    margin: 0;
    text-wrap: pretty;
}

.main-content .toc a {
    display: block;
    margin-left: -1px;
    padding: 0.32em 0.4em 0.32em 0.85em;
    border-left: 2px solid transparent;
    color: color-mix(in srgb, var(--text-color) 72%, transparent);
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
}

/* Depth in the list sets the indent... */
.main-content .toc li.toc-l1 > a { padding-left: 1.35em; }
.main-content .toc li.toc-l2 > a { padding-left: 2em; }
.main-content .toc li.toc-l3 > a { padding-left: 2.6em; }

/* ...and the heading's own level sets colour, size and weight, stepping
   down the way the headings do: each entry is its heading's hue blended
   mostly into grey, so levels read apart without shouting. */
.toc li, .drawer-toc li { --toc-hue: var(--text-muted); }
.toc li.toc-h1, .drawer-toc li.toc-h1 { --toc-hue: var(--h1-color); }
.toc li.toc-h2, .drawer-toc li.toc-h2 { --toc-hue: var(--h2-color); }
.toc li.toc-h3, .drawer-toc li.toc-h3 { --toc-hue: var(--h3-color); }
.toc li.toc-h4, .drawer-toc li.toc-h4 { --toc-hue: var(--h4-color); }
.toc li.toc-h5, .drawer-toc li.toc-h5 { --toc-hue: var(--h5-color); }
.toc li.toc-h6, .drawer-toc li.toc-h6 { --toc-hue: var(--h6-color); }

.main-content .toc li > a,
.mobile .drawer-toc li > a {
    color: color-mix(in srgb, var(--toc-hue) 95%, #858585);
}
.main-content .toc li.toc-h1 > a,
.mobile .drawer-toc li.toc-h1 > a {
    font-family: var(--font-heading);
    font-size: 1.04em;
    font-weight: 700;
}
.main-content .toc li.toc-h2 > a,
.mobile .drawer-toc li.toc-h2 > a {
    font-family: var(--font-heading);
    font-size: 0.98em;
    font-weight: 600;
}
.main-content .toc li.toc-h3 > a,
.mobile .drawer-toc li.toc-h3 > a {
    font-size: 0.92em;
    font-weight: 500;
}
.main-content .toc li:is(.toc-h4, .toc-h5, .toc-h6) > a,
.mobile .drawer-toc li:is(.toc-h4, .toc-h5, .toc-h6) > a {
    font-size: 0.86em;
}

/* Notes and References: back matter. Chapter indent, the size of a
   section entry, grey and italic; no rule, no extra gap. */
.main-content .toc li.toc-backmatter > a,
.mobile .drawer-toc li.toc-backmatter > a {
    font-family: var(--font-heading);
    font-size: 0.98em;
    font-weight: 600;
    font-style: italic;
    color: var(--text-muted);
}
.toc li.toc-backmatter,
.drawer-toc li.toc-backmatter {
    --toc-hue: var(--text-muted);
}

/* A chapter-level entry gets a little room above it. */
.toc li.toc-l0:not(:first-child),
.toc li.toc-title + li,
.toc li.toc-backmatter:not(.toc-backmatter + .toc-backmatter) {
    margin-top: 0.5em;
}

.main-content .toc li > a:hover {
    color: color-mix(in srgb, var(--toc-hue) 75%, var(--text-color));
    border-left-color: var(--sidebar-border);
}

/* A section with subsections carries an arrow (theme.js): click to fold
   them away, Option/Alt-click to fold or unfold every section. */
.toc li.toc-has-sub {
    position: relative;
}
.main-content .toc li.toc-has-sub > a {
    padding-right: 1.9em;
}
.toc-fold {
    position: absolute;
    top: 0.15em;
    right: 0.1em;
    width: 1.6em;
    height: 1.6em;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}
.toc-fold::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.38em;
    height: 0.38em;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    /* points right when folded, down when open */
    transform: translate(-65%, -50%) rotate(-45deg);
    transition: transform 0.15s;
}
.toc li.toc-open > .toc-fold::before,
.drawer-toc li.toc-open > .toc-fold::before {
    transform: translate(-50%, -70%) rotate(45deg);
}
.toc-fold:hover,
.toc-fold:focus-visible {
    color: var(--accent-color);
    background: color-mix(in srgb, var(--accent-color) 12%, transparent);
}

/* The section being read, and the chapter it sits in. */
.main-content .toc li.in-path > a {
    color: color-mix(in srgb, var(--toc-hue) 70%, var(--text-color));
}
.main-content .toc li > a.active {
    color: var(--toc-hue);
    border-left-color: var(--toc-hue);
}

@media (min-width: 1380px) {
    /* Posts with a TOC rail keep enough left gutter for it (250px + gap),
       so the centred column stops short of 80% until the window is huge. */
    /* --col is the column the rail leaves room for. The text gets 10% more
       than that and sits 5% further from the rail: its left edge moves right
       by 5% of --col and its right edge by 15%. */
    .main-content:has(.toc-rail) {
        --col: min(var(--content-width), calc(100vw - 600px));
        max-width: calc(var(--col) * 1.1);
        left: calc(var(--col) * 0.1);
    }

    /* The rail hangs off the text's left edge; the extra 5% keeps it where
       it was while the text moves away from it. */
    .toc-rail {
        position: absolute;
        top: 0;
        bottom: 0;
        right: calc(100% + 1.5rem + var(--col, 0px) * 0.05);
        width: 265px;
    }

    /* In the gutter it drops the card: just the list beside the text. */
    .toc {
        position: sticky;
        top: 1.5rem;
        max-height: calc(100vh - 3rem);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        margin: 0;
        padding: 0.2rem 0.4rem 0.5rem 0;
        background: none;
        border: 0;
    }
}

/* Phones: keep the bump but not so far that lines get too short. */
@media (max-width: 600px) {
    .mobile body {
        font-size: 18px;
    }

    .mobile {
        --para-indent: 1.2em;
    }

    .mobile .main-content {
        padding-left: 1.1rem;
        padding-right: 1.1rem;
    }
}

/* Touchscreens: hover effects stick after a tap, so keep them to devices
   that really hover; give tap feedback instead. */
@media (hover: none) {
    .read-more-btn:hover {
        background: var(--bg-color);
        color: var(--text-color);
        border-color: var(--sidebar-border);
    }

    #theme-toggle:hover {
        background: none;
        color: var(--text-color);
        border-color: var(--sidebar-border);
    }

    .read-more-btn:active,
    #theme-toggle:active {
        background: var(--link-color);
        color: #fff;
        border-color: var(--link-color);
    }

    .spoiler:not(.revealed):hover { opacity: 1; }
}
