/*
 * Post pages under pages/, on top of site.css. Same paper and ink, a slightly
 * wider column for code and figures, and warm-toned code and callouts.
 */

:root {
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 1.5rem;
}

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

/* A little wider than the other pages: posts carry code and figures. */
.page-post {
    max-width: 56rem;
}

/* ---------- Title block ---------- */

.post-head {
    text-align: center;
    margin: 1rem 0 3rem;
}

.post-head time {
    display: block;
    margin-bottom: 0.9rem;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.post-head h1 {
    font-size: clamp(2.1rem, 5vw, 3rem);
    line-height: 1.1;
    letter-spacing: -0.015em;
    margin: 0 0 1rem;
    text-wrap: balance;
}

.post-head .lede {
    max-width: 34rem;
    margin: 0 auto 1rem;
    font-style: italic;
    text-wrap: balance;
}

.post-tags {
    color: var(--muted);
    margin: 0;
}

/* The squiggle from the footer, as a small ornament under the title. */
.post-head::after {
    content: "";
    display: block;
    width: 4rem;
    height: 0.55rem;
    margin: 2.25rem auto 0;
    background: var(--accent);
    opacity: 0.7;
    -webkit-mask: var(--squiggle) no-repeat center / 100% 100%;
    mask: var(--squiggle) no-repeat center / 100% 100%;
}

/* ---------- Contents ---------- */

.contents {
    margin: 0 0 3rem;
    padding: 0 0 0 1.25rem;
    border-left: 2px solid var(--faint);
    font-size: 1.05rem;
}

.contents summary {
    cursor: pointer;
    margin-bottom: 0.5rem;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.contents summary:hover {
    color: var(--accent);
}

.contents ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.contents li {
    line-height: 1.45;
    padding: 0.15rem 0;
}

.contents .toc-h3 {
    padding-left: 1.25rem;
    font-size: 0.95em;
}

.contents .toc-h4 {
    padding-left: 2.5rem;
    font-size: 0.9em;
}

.contents a {
    text-decoration: none;
}

/* ---------- Body text ---------- */

.post-body {
    font-size: 1.2rem;
    line-height: 1.7;
    overflow-wrap: break-word;
}

.post-body > :first-child {
    margin-top: 0;
}

.post-body h2,
.post-body h3,
.post-body h4 {
    font-weight: 500;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.post-body h2 {
    font-size: 1.75rem;
    margin: 3.5rem 0 1rem;
}

.post-body h3 {
    font-size: 1.35rem;
    font-style: italic;
    margin: 2.5rem 0 0.75rem;
}

.post-body h4 {
    font-size: 1.15rem;
    margin: 2rem 0 0.5rem;
}

.post-body p,
.post-body ul,
.post-body ol {
    margin: 0 0 1.3rem;
}

.post-body ul,
.post-body ol {
    padding-left: 1.4rem;
}

.post-body li {
    margin-bottom: 0.35rem;
}

.post-body li::marker {
    color: var(--accent);
}

.post-body a {
    text-decoration-color: var(--accent-soft);
    text-decoration-thickness: 2px;
}

.post-body a:hover {
    text-decoration-color: currentColor;
}

.post-body strong {
    font-weight: 650;
}

.post-body blockquote:not(.twitter-tweet) {
    margin: 2rem 0;
    padding: 0 0 0 1.25rem;
    border-left: 2px solid var(--accent);
    color: var(--muted);
    font-style: italic;
}

/* An X post before (or without) X's script: just a link to the post. */
.post-body blockquote.twitter-tweet {
    margin: 1.5rem 0;
    font-style: italic;
}

.post-body blockquote.twitter-tweet::before {
    content: "\2192\00a0";
    color: var(--accent);
}

.post-body blockquote.twitter-tweet p {
    display: inline;
}

/* A section break: the same squiggle, not a hard line. */
.post-body hr {
    border: 0;
    width: 4rem;
    height: 0.55rem;
    margin: 3rem auto;
    background: var(--faint);
    -webkit-mask: var(--squiggle) no-repeat center / 100% 100%;
    mask: var(--squiggle) no-repeat center / 100% 100%;
}

/* ---------- Images ---------- */

/* Keep the image box at its natural proportions. Portrait screenshots
   fit within the viewport and sit in the centre; wide figures fit the column.
   Click any image for full size. */
.post-body img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: min(75vh, 720px);
    max-height: min(75svh, 720px);
    object-fit: contain;
    margin: 2.25rem auto;
    border-radius: 6px;
    cursor: zoom-in;
}

.post-body p > img:only-child {
    margin: 0 auto;
}

.post-body p:has(> img:only-child) {
    margin: 2.25rem 0;
}

/* Consecutive image-only paragraphs form a captioned grid. */
.post-body .image-figure {
    min-width: 0;
    margin: 2.25rem 0;
}
.post-body .image-figure img { margin: 0 auto; }
.post-body .image-figure figcaption {
    margin-top: 0.75rem;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.85rem;
    line-height: 1.5;
    text-align: center;
}
.post-body .gallery {
    display: grid;
    grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
    align-items: start;
    gap: 2rem 1.25rem;
    margin: 2.25rem 0;
}
/* Let desktop galleries use the available screen without widening prose.
   100% of the viewport minus generous gutters, capped at 1200px. */
@media (min-width: 960px) {
    .post-body > .gallery {
        width: min(75rem, calc(100vw - 5rem));
        margin-left: calc((100% - min(75rem, calc(100vw - 5rem))) / 2);
    }
}
.post-body .gallery .image-figure { margin: 0; }
.post-body .gallery img {
    width: 100%;
    height: auto;
    max-height: none;
}
@media (prefers-reduced-motion: no-preference) and (hover: hover) {
    .post-body .gallery img { transition: transform 0.18s ease; }
    .post-body .gallery img:hover { transform: translateY(-4px); }
}
@media (max-width: 640px) {
    .post-body .gallery {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1.5rem 0.75rem;
    }
}

/* ---------- Code ---------- */

.post-body code {
    font-family: var(--mono);
    font-size: 0.82em;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: var(--code-bg);
}

.post-body pre {
    margin: 1.75rem 0;
    padding: 1.1rem 1.35rem;
    border-radius: 8px;
    background: var(--code-bg);
    overflow-x: auto;
    font-size: 0.95rem;
    line-height: 1.6;
    tab-size: 4;
    scrollbar-width: thin;
    scrollbar-color: var(--faint) transparent;
}

.post-body pre code {
    padding: 0;
    background: none;
    font-size: 0.92em;
}

/* Chroma's token classes, coloured from the palette above. */
.chroma {
    color: var(--ink);
}

.chroma .k,
.chroma .kc,
.chroma .kd,
.chroma .kn,
.chroma .kp,
.chroma .kr,
.chroma .kt,
.chroma .ow {
    color: var(--syn-keyword);
}

.chroma .s,
.chroma .s1,
.chroma .s2,
.chroma .sa,
.chroma .sb,
.chroma .sc,
.chroma .sd,
.chroma .sh,
.chroma .sr,
.chroma .ss,
.chroma .sx {
    color: var(--syn-string);
}

.chroma .se,
.chroma .si {
    color: var(--syn-keyword);
}

.chroma .m,
.chroma .mb,
.chroma .mf,
.chroma .mh,
.chroma .mi,
.chroma .il,
.chroma .mo {
    color: var(--syn-number);
}

.chroma .c,
.chroma .c1,
.chroma .ch,
.chroma .cm,
.chroma .cs,
.chroma .cp,
.chroma .cpf {
    color: var(--syn-comment);
    font-style: italic;
}

.chroma .nb,
.chroma .bp,
.chroma .nn,
.chroma .nc,
.chroma .nv,
.chroma .vc,
.chroma .vg,
.chroma .vi,
.chroma .nt,
.chroma .na {
    color: var(--syn-name);
}

.chroma .nf,
.chroma .fm,
.chroma .nd {
    color: var(--syn-function);
}

.chroma .o,
.chroma .p {
    color: var(--syn-operator);
}

.chroma .gd {
    color: var(--c-danger);
}

.chroma .gi {
    color: var(--c-tip);
}

.chroma .err {
    color: inherit;
    background: none;
}

.chroma .line {
    display: inline;
}

/* ---------- Callouts ---------- */

.callout {
    --tone: var(--c-note);
    margin: 2rem 0;
    padding: 1rem 1.25rem 1.05rem;
    border-left: 3px solid var(--tone);
    border-radius: 0 8px 8px 0;
    background: color-mix(in srgb, var(--tone) 13%, var(--paper));
    font-size: 1.1rem;
}

.callout::before {
    display: block;
    margin-bottom: 0.3rem;
    color: var(--tone);
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    content: "Note";
}

.callout > p:empty {
    display: none;
}

.callout > :last-child {
    margin-bottom: 0;
}

.callout-info {
    --tone: var(--c-info);
}

.callout-info::before {
    content: "Info";
}

.callout-tip {
    --tone: var(--c-tip);
}

.callout-tip::before {
    content: "Tip";
}

.callout-success {
    --tone: var(--c-tip);
}

.callout-success::before {
    content: "Success";
}

.callout-warning {
    --tone: var(--c-warning);
}

.callout-warning::before {
    content: "Warning";
}

.callout-caution {
    --tone: var(--c-warning);
}

.callout-caution::before {
    content: "Caution";
}

.callout-danger,
.callout-error {
    --tone: var(--c-danger);
}

.callout-danger::before {
    content: "Danger";
}

.callout-error::before {
    content: "Error";
}

.callout-important {
    --tone: var(--c-important);
}

.callout-important::before {
    content: "Important";
}

/* ---------- Tables ---------- */

.post-body table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--faint) transparent;
    margin: 2rem 0;
    border-collapse: collapse;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.post-body th,
.post-body td {
    padding: 0.5rem 1rem 0.5rem 0;
    border-bottom: 1px solid var(--faint);
    text-align: left;
    vertical-align: top;
}

.post-body th {
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-bottom-color: var(--muted);
}

/* ---------- End of post ---------- */

.post-end {
    margin: 4rem 0 0;
    font-style: italic;
}

/* ---------- Image lightbox ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3.5rem 1rem;
    background: rgba(28, 26, 23, 0.9);
    cursor: zoom-out;
}

.lightbox[hidden] {
    display: none;
}

.lightbox img {
    max-width: 95vw;
    max-height: calc(100vh - 7rem);
    max-height: calc(100dvh - 7rem);
    border-radius: 6px;
    background: #fff;
    cursor: default;
    touch-action: pan-y pinch-zoom;
}

@media (prefers-reduced-motion: no-preference) {
    .lightbox:not([hidden]) {
        animation: lightbox-fade 0.2s ease;
    }

    .lightbox img.from-next {
        animation: lightbox-from-next 0.3s ease;
    }

    .lightbox img.from-prev {
        animation: lightbox-from-prev 0.3s ease;
    }
}

@keyframes lightbox-fade {
    from { opacity: 0; }
}

@keyframes lightbox-from-next {
    from { opacity: 0; transform: translateX(3rem); }
}

@keyframes lightbox-from-prev {
    from { opacity: 0; transform: translateX(-3rem); }
}

.lightbox-nav {
    position: fixed;
    top: calc(50% - 1.5rem);
    width: 3rem;
    height: 3rem;
    padding: 0 0 0.2rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    background: rgba(20, 18, 16, 0.6);
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
}

.lightbox-nav.prev {
    left: 1rem;
}

.lightbox-nav.next {
    right: 1rem;
}

.lightbox-nav:hover,
.lightbox-nav:focus-visible {
    background: rgba(20, 18, 16, 0.85);
}

.lightbox-count {
    position: fixed;
    bottom: 1rem;
    left: 0;
    right: 0;
    margin: 0;
    color: rgba(255, 255, 255, 0.75);
    font-family: var(--sans);
    font-size: 0.85rem;
    text-align: center;
    cursor: default;
}

.lightbox.single .lightbox-nav,
.lightbox.single .lightbox-count {
    display: none;
}

.lightbox-close {
    position: fixed;
    top: 1rem;
    right: 1.25rem;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    background: rgba(20, 18, 16, 0.6);
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
    background: rgba(20, 18, 16, 0.85);
}

/* ---------- Small screens ---------- */

@media (max-width: 520px) {
    .post-body {
        font-size: 1.1rem;
    }

    .post-body h2 {
        font-size: 1.5rem;
    }

    .post-body pre {
        margin-left: -1.25rem;
        margin-right: -1.25rem;
        padding: 1rem 1.25rem;
        border-radius: 0;
    }
}

.lightbox-caption {
    position: fixed;
    bottom: 3rem;
    left: 4rem;
    right: 4rem;
    margin: 0;
    color: white;
    font-family: var(--sans);
    font-size: 0.9rem;
    text-align: center;
}
.lightbox img { max-height: calc(100dvh - 11rem); }
/* Geometry-based zoom is handled by the viewer script. */
.lightbox img { transform-origin: center; }
