/* ==========================================================================
   Main CSS - Consolidated
   ========================================================================== */

/* ==========================================================================
   Variables
   ========================================================================== */

:root {
    /* Palette */
    --color-bg-paper: #F5F3EE;
    --color-text-ink: #2C2D30;
    --color-text-light: #595A5D;
    --color-accent: #B3202A;   /* cinnabar, from the seal paste */
    --color-line: rgba(44, 45, 48, 0.15);

    /* Typography */
    --font-heading: 'Cormorant Garamond', serif;
    --font-body: 'Newsreader', serif;

    /* Spacing */
    --space-sm: 1rem;
    --space-md: 2rem;
    --space-lg: 4rem;
}

/* ==========================================================================
   Reset & Base Body Styles
   ========================================================================== */

body {
    background-color: var(--color-bg-paper);
    color: var(--color-text-ink);
    font-family: var(--font-body);
    font-weight: 400;
    font-variant-numeric: oldstyle-nums;
    line-height: 1.7;
    margin: 0;
    padding: 0;

    /* Paper: the fine bumps of the sheet's surface, lit from the upper left. The bumps are grey and soft-light
       blended, so they lighten and darken the paper colour without tinting it */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeDiffuseLighting surfaceScale='2' lighting-color='%23fff'%3E%3CfeDistantLight azimuth='225' elevation='35'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)' opacity='.35'/%3E%3C/svg%3E");
    background-size: 300px;
    background-blend-mode: soft-light;
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3 {
    font-family: var(--font-heading);
    color: var(--color-text-ink);
    margin-top: 0;
}

a {
    color: var(--color-text-ink);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

::selection {
    background: color-mix(in srgb, var(--color-accent) 22%, transparent);
}

a:hover {
    color: var(--color-accent);
    border-bottom: 1px solid var(--color-accent);
}

/* ==========================================================================
   Layout - Container & Grid
   ========================================================================== */

.l-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem var(--space-md);
}

.l-grid-sidebar {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: var(--space-lg);
    margin-top: var(--space-lg);
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .l-grid-sidebar {
        grid-template-columns: 1fr;
        gap: 3rem;
    }
}

/* ==========================================================================
   Header Component
   ========================================================================== */

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0;
    border-bottom: none !important;
    padding-bottom: 0;
    position: relative;
}

.site-header__branding {
    max-width: 60%;
}

.site-header__branding h1 {
    font-size: 3rem;
    margin-bottom: 0.2rem;
    font-weight: 700;
}

.site-header__title-link {
    border-bottom: none;
}

.site-header__title-link:hover {
    border-bottom: none;
}

.site-header__tagline {
    font-family: var(--font-heading);
    font-style: italic;
    font-size: 1.2rem;
    color: var(--color-text-light);
    margin: 0;
}

.site-header__logo {
    width: 300px;
    height: auto;
    display: block;
    border-radius: 2px;
    position: absolute;
    top: -50px;
    right: -20px;
    z-index: 10;
    pointer-events: none;
}

/* Kea: the painting, replaced by a bird-free plate plus a live 3D head (static/js/kea3d.js) and body of
   feathers (static/js/kea-body.js), each on a canvas */
.c-kea__painting {
    display: block;
    width: 100%;
    height: auto;
}

/* Narrow screens: every page opens with one row, short text on the left (the name, or a post's date and
   author) and the bird on the right. The row is as tall as the bird, so the bird holds still between pages
   and page titles start below it */
@media (max-width: 960px) {
    .l-container {
        padding-top: 1rem;
    }

    .site-header {
        min-height: 120px;
        align-items: flex-end;
        padding-right: 130px;
    }

    .site-header__logo {
        top: 0;
        right: 0;
        width: 120px;
    }

    .site-header__branding {
        max-width: none;
    }

    .site-header__branding h1 {
        font-size: 2.25rem;
        margin-bottom: 0;
    }

    .l-grid-sidebar,
    .l-page {
        margin-top: var(--space-md);
    }
}

/* ==========================================================================
   Footer Component
   ========================================================================== */

.site-footer {
    margin-top: 5rem;
    padding-bottom: var(--space-md);
    font-size: 0.85rem;
    color: var(--color-text-light);
}

/* ==========================================================================
   Post List & Post Preview Components
   ========================================================================== */

/* Section Title (reusable) */
.c-section-title {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 400;
    color: var(--color-text-light);
    margin: 0 0 1.5rem;
}

/* Bio Component */
.c-bio p {
    margin-bottom: 1.5rem;
    font-family: var(--font-body);
    font-size: 1.2rem;
}

/* Post List */
.c-post-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Post Preview */
.c-post-preview {
    margin-bottom: var(--space-md);
}

.c-post-preview__title a {
    border-bottom: none;
}

.c-post-preview__title a:hover {
    border-bottom: none;
    color: var(--color-accent);
    text-decoration: underline 1px;
    text-underline-offset: 0.2em;
}

.c-post-preview__date {
    font-size: 0.8rem;
    color: var(--color-text-light);
    display: block;
    margin-bottom: 0.3rem;
}

.c-post-preview__title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
    display: block;
}

.c-post-preview__excerpt {
    font-size: 0.95rem;
    color: var(--color-text-light);
    margin-top: 0.5rem;
    display: block;
}

/* ==========================================================================
   Single Column Layout
   ========================================================================== */

.l-single-column {
    max-width: 65ch;
}

/* Posts fill the room the window gives them, up to 1.5x the usual width. The text starts at 50vw - 450px
   (the centered 900px container), and its 260px sidenote margin plus a 16px gutter must fit to the right,
   which leaves 50vw + 174px. */
.is-post .l-single-column {
    max-width: min(97.5ch, calc(50vw + 174px));
}

/* Single-column pages under the full header (post list, 404) */
.l-page {
    margin-top: var(--space-lg);
}

/* ==========================================================================
   Article Component (Single Posts)
   ========================================================================== */

/* Date and author sit above the title, sized to stay legible in a zoomed-out screenshot */
.c-article__date {
    font-size: 0.85rem;
    color: var(--color-text-light);
    display: block;
}

.c-article__byline {
    font-size: 1.15rem;
    border-bottom: none;
}

.c-article__byline:hover {
    border-bottom: none;
}

.c-article__title {
    font-size: 2.5rem;
    margin: 0.75rem 0 1.5rem;
    line-height: 1.2;
}

/* Wide screens: the painting hangs over the right of the header, about 280px in from the column's edge, so a
   long title wraps before it. Narrow screens give the bird its own row (see the 960px query) */
@media (min-width: 961px) {
    .c-article__title {
        max-width: calc(100% - 290px);
    }
}

.c-article__excerpt {
    font-size: 1.05rem;
    color: var(--color-text-light);
    margin: -1rem 0 1.5rem;
}

/* Bracketed links under the subtitle (`links` front matter), in cinnabar */
.c-article__links {
    font-size: 0.9rem;
    margin: -1rem 0 0.75rem;
}

/* The first paragraph's own top margin would otherwise collapse with the links' and reopen the gap. On narrow
   screens the folded contents sit in between and keep their own spacing */
.c-article__links ~ .c-article__content > :first-child {
    margin-top: 0;
}

.c-article__links a {
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: none;
    background: none;
    margin-right: 0.75em;
}

.c-article__links a:hover {
    color: var(--color-accent);
    border-bottom: none;
    text-decoration: underline 1px;
    text-underline-offset: 0.2em;
}

.c-article__content {
    font-family: var(--font-body);
    font-size: 1.25rem;
    line-height: 1.65;
}

.c-article__content a {
    border-bottom: 1px solid color-mix(in srgb, var(--color-accent) 50%, transparent);
}

/* Alex's seal, stamped in cinnabar: the end mark after a post's last word, and after the name in the
   homepage footer. It links home */
.c-seal,
.c-seal:hover,
.c-article__content .c-seal {
    border-bottom: none;
}

.c-seal img {
    display: inline-block;
    width: 1.05em;
    height: 1.05em;
    margin-left: 0.45em;
    vertical-align: -0.18em;
    mix-blend-mode: multiply;
    transition: opacity 0.2s ease;
}

.c-seal:hover img {
    opacity: 0.7;
}

.c-article__content p {
    margin-bottom: 1.5rem;
}

/* Images and figures in an essay span its full width and keep their own shape. The seal sits inside a
   link, so it stays the size of the text */
.c-article__content > p > img,
.c-article__content figure {
    display: block;
    width: 100%;
    height: auto;
}

/* The odds figure (layouts/partials/figure-odds.html, static/js/odds.js): dots in the painting's ink, and
   cinnabar for the outcomes that pay */
.c-odds,
.c-company,
.c-gradient,
.c-recall {
    margin: 0 0 var(--space-md);
}

.c-odds svg,
.c-company svg,
.c-gradient svg,
.c-recall svg {
    display: block;
    width: 100%;
    height: auto;
}

.c-odds__dot {
    fill: #373229;
    transform-box: fill-box;
    transform-origin: center;
    transition: fill .6s ease, opacity .6s ease, transform .6s ease;
}

.c-odds__hit {
    fill: var(--color-accent);
}

/* The red spreads out from the one dot until it fills its square; going back, the square clears all at once */
.is-priced .c-odds__col {
    fill: var(--color-accent);
    opacity: 1;
    transform: scale(var(--s));
    transition-delay: var(--d);
}

@media (prefers-reduced-motion: reduce) {
    .c-odds * {
        transition: none;
    }
}

/* The company figure (layouts/partials/figure-company.html, static/js/company.js): people and outcomes in
   the painting's ink, faint lines for the ties between people, and the model in cinnabar */
.c-company__ink {
    fill: #373229;
}

.c-company__ties {
    stroke: #373229;
    stroke-width: .6;
    opacity: .28;
}

.c-company__model {
    fill: var(--color-accent);
}

/* The gradient figure (layouts/partials/figure-gradient.html, static/js/gradient.js): entries in the painting's
   ink and faint bowed lines for the terms of the rote chain-rule sum. The script turns what survives the untangling,
   and the gradient itself, cinnabar */
.c-gradient__ink {
    fill: #373229;
}

.c-gradient__ties {
    fill: none;
    stroke: #373229;
    stroke-width: .5;
    stroke-opacity: .13;
}

/* The recall figure (layouts/partials/figure-recall.html, static/js/recall.js): each store's recalled picture in
   dots, cinnabar while its recall works and the painting's ink once interference outweighs the signal */
.c-recall__pic {
    fill: #373229;
    fill-opacity: .8;
    transition: fill .8s ease;
}

.c-recall__pic.is-recalled {
    fill: var(--color-accent);
}

.c-recall__label {
    font-family: var(--font-body);
    font-size: 11px;
    fill: #373229;
    text-anchor: middle;
}

.c-recall__caption {
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-top: .5rem;
}

/* Other posts to read next, between the end of the essay and the citation */
.c-more {
    margin-top: var(--space-lg);
}

.c-article__content h2 {
    margin-top: var(--space-md);
    margin-bottom: 1rem;
}

/* ==========================================================================
   Footnotes / Sidenotes (sidenotes on wide screens, bottom list otherwise)
   ========================================================================== */

.footnotes {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

/* Plain muted numbers instead of the default underlined-link look */
.c-article__content sup {
    line-height: 0;
}

.footnote-ref,
.footnote-backref,
.sidenote sup {
    color: var(--color-text-light);
    border-bottom: none;
    font-size: 0.75em;
}

.footnote-ref:hover,
.footnote-backref:hover {
    border-bottom: none;
    opacity: 0.7;
}

.sidenote {
    display: none;
}

@media (min-width: 1000px) {
    .sidenote {
        display: block;
        float: right;
        clear: right;
        width: 220px;
        margin: 0.3rem -260px 1rem 0;
        font-size: 0.8rem;
        line-height: 1.5;
        color: var(--color-text-light);
    }

    .footnotes {
        display: none;
    }
}

/* ==========================================================================
   Citation
   ========================================================================== */

.c-citation {
    margin-top: var(--space-md);
    padding-top: 1rem;
    border-top: 1px solid var(--color-line);
    font-size: 0.85rem;
    color: var(--color-text-light);
}

.c-citation summary {
    cursor: pointer;
}

.c-citation pre {
    overflow-x: auto;
    padding: 1rem;
    background: rgba(44, 45, 48, 0.04);
    border-radius: 2px;
}

.c-citation__box {
    position: relative;
}

.c-citation__copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.15rem 0.55rem;
    font: inherit;
    font-size: 0.75rem;
    color: var(--color-text-light);
    background: var(--color-bg-paper);
    border: 1px solid var(--color-line);
    border-radius: 2px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.c-citation__copy:hover,
.c-citation__copy:focus-visible {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

/* ==========================================================================
   Page transitions: an ink flick
   Clicking a link on the site flicks a brush stroke of ink across it, then the page follows
   (layouts/partials/ink-splash.html). Where the browser supports cross-document view transitions, the
   old page, ink and all, fades into the new one. The painting never moves.
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }
}

.c-kea {
    view-transition-name: kea;
}

::view-transition {
    background: var(--color-bg-paper);
}

::view-transition-group(kea),
::view-transition-new(kea),
::view-transition-new(root) {
    animation: none;
}

::view-transition-old(kea) {
    display: none;
}

::view-transition-old(root) {
    animation: ink-lift 180ms ease-in both;
}

@keyframes ink-lift {
    to {
        opacity: 0;
        filter: blur(.6px);
    }
}

.c-ink-splash {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

/* Wide display math scrolls on its own instead of widening the page */
mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

/* Obsidian-style callouts (render-blockquote.html): a rule down the left; folded ones open on click */
.c-callout {
    margin: 0 0 1.5rem;
    padding-left: 1rem;
    border-left: 2px solid var(--color-line);
}

.c-callout__title {
    margin-bottom: 0.75rem;
    font-weight: 600;
}

summary.c-callout__title {
    cursor: pointer;
}

details.c-callout:not([open]) > .c-callout__title {
    margin-bottom: 0;
}

/* Inline code: a smaller monospace set in a thin box */
.c-article__content :not(pre) > code {
    font-size: 0.82em;
    padding: 0.1em 0.35em;
    border: 1px solid var(--color-line);
    border-radius: 3px;
    background: rgba(44, 45, 48, 0.04);
}

/* Tables: rules between rows; a table wider than the column scrolls inside itself */
.c-article__content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    margin: var(--space-sm) 0;
    border-collapse: collapse;
    font-size: 0.9em;
}
.c-article__content th,
.c-article__content td {
    padding: 0.4em 0.75em;
    border-bottom: 1px solid var(--color-line);
    text-align: left;
    vertical-align: top;
}
.c-article__content th { font-weight: 600; border-bottom-color: var(--color-text-light); }

/* Code blocks: Hugo's highlighter sets the dark background; long lines scroll inside it */
.c-article__content pre {
    font-size: 0.8rem;
    line-height: 1.5;
    padding: 1rem 1.25rem;
    border-radius: 4px;
    overflow-x: auto;
}

/* Table of contents (toc: true): folded like the citation box, above the post's text */
.c-toc {
    margin-bottom: var(--space-md);
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.c-toc summary {
    cursor: pointer;
}

.c-toc ul {
    margin: 0.5rem 0 0;
    padding-left: 1.1rem;
    list-style: none;
}

.c-toc ul ul {
    margin-top: 0;
    padding-left: 1rem;
}

.c-toc li {
    margin: 0.2rem 0;
}

.c-toc a {
    color: inherit;
    text-decoration: none;
}

.c-toc a:hover {
    color: var(--color-accent);
}

/* Wide screens: the contents sit open in the left margin, beside the 900px container (1360px is the narrowest window with room), and stay put while
   the post scrolls. The script in posts/single.html opens it and marks the section being read. */
.c-toc a.is-active {
    color: var(--color-accent);
}

@media (min-width: 1360px) {
    .c-toc {
        position: fixed;
        top: 8rem;
        left: calc(50vw - 450px - 210px);
        width: 180px;
        max-height: calc(100vh - 10rem);
        overflow-y: auto;
        margin: 0;
        font-size: 0.8rem;
        line-height: 1.4;
    }

    .c-toc summary {
        pointer-events: none;
        list-style: none;
        font-family: var(--font-heading);
        font-size: 1rem;
        color: var(--color-text-ink);
    }

    .c-toc summary::-webkit-details-marker {
        display: none;
    }

    .c-toc ul {
        padding-left: 0;
    }

    .c-toc ul ul {
        padding-left: 0.8rem;
    }
}

/* Section links (render-heading.html): a # after each heading, shown on hover or focus */
.c-article__content :is(h2, h3, h4) {
    scroll-margin-top: 1.5rem;
}

.c-article__content .c-heading-anchor {
    margin-left: 0.35em;
    border-bottom: none;
    color: var(--color-text-light);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.c-article__content :is(h2, h3, h4):hover .c-heading-anchor,
.c-article__content .c-heading-anchor:focus-visible {
    opacity: 1;
}

.c-article__content .c-heading-anchor:hover {
    color: var(--color-accent);
}

/* No hover on touch screens, so keep the # faintly visible there */
@media (hover: none) {
    .c-article__content .c-heading-anchor {
        opacity: 0.4;
    }
}

/* Crosstalk chart (layouts/shortcodes/crosstalk-chart.html): like the site's other figures, the painting's ink,
   lighter for weaker suppression, and the strongest series in cinnabar. Text in the body font, italic variables */
.c-crosstalk { margin: var(--space-md) 0; }
.c-crosstalk svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font-body); }
.c-crosstalk__grid { stroke: #373229; stroke-opacity: .1; stroke-width: 1; }
.c-crosstalk__one { stroke-opacity: .45; stroke-dasharray: 4 4; }
.c-crosstalk__axis { stroke: #373229; stroke-opacity: .45; stroke-width: 1; }
.c-crosstalk__tick { font-size: 13px; fill: var(--color-text-light); }
.c-crosstalk__label { font-size: 14px; fill: var(--color-text-light); }
.c-crosstalk__series { font-size: 15px; fill: var(--color-text-ink); }
.c-crosstalk__var { font-style: italic; }
.c-crosstalk__sup, .c-crosstalk__sub { font-size: 11px; }
.c-crosstalk__line polyline { fill: none; stroke: #373229; stroke-opacity: var(--op); stroke-width: 1.6; }
.c-crosstalk__line circle { fill: #373229; fill-opacity: var(--op); stroke: var(--color-bg-paper); stroke-width: 1.5; }
.c-crosstalk__line--accent polyline { stroke: var(--color-accent); stroke-opacity: 1; stroke-width: 2; }
.c-crosstalk__line--accent circle { fill: var(--color-accent); fill-opacity: 1; }
.c-crosstalk__line circle:hover { r: 5.5; }
.c-crosstalk__drowned { fill: #373229; opacity: .07; }
.c-crosstalk__drowned-label { font-size: 13px; font-style: italic; fill: var(--color-text-light); }
.c-crosstalk__note { font-size: 13px; fill: var(--color-text-light); }
.c-crosstalk__drop { stroke: #373229; stroke-width: 1.5; stroke-dasharray: 2 3; }

/* The memory-bars figure (layouts/shortcodes/memory-bars.html) */
.c-membars__slider { display: flex; align-items: center; gap: .6em; flex-wrap: wrap; font-size: 0.9rem; color: var(--color-text-light); margin: .25rem 0 0 52px; }
.c-membars input[type=range] { flex: 1 1 160px; max-width: 260px; accent-color: #373229; }
.c-membars { margin: var(--space-md) 0; --ink: #373229; --red: #B3202A; }
.c-membars__controls { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .5rem; }
.c-membars__slider { margin-left: 0; }
.c-membars__modes { border: none; padding: 0; margin: 0; display: flex; gap: 1em; flex-wrap: wrap; font-size: 0.9rem; color: var(--color-text-ink); }
.c-membars__modes legend { float: left; margin-right: .5em; color: var(--color-text-light); }
.c-membars__modes input { accent-color: #373229; }
.c-membars__bars { display: block; width: 100%; height: 220px; border-bottom: 1px solid rgba(55, 50, 41, .2); }
.c-membars__legend { display: flex; gap: 1.5em; flex-wrap: wrap; font-size: 0.85rem; color: var(--color-text-light); margin-top: .35rem; }
.c-membars__swatch { display: inline-block; width: .8em; height: .8em; background: var(--red); margin-right: .4em; vertical-align: -0.05em; }
.c-membars__meter { display: flex; align-items: center; gap: .8em; flex-wrap: wrap; font-size: 0.9rem; color: var(--color-text-ink); margin-top: .5rem; font-variant-numeric: tabular-nums; }
.c-membars__meter-track { position: relative; flex: 1 1 160px; max-width: 320px; height: 8px; background: rgba(55, 50, 41, .08); }
.c-membars__meter-track::after { content: ""; position: absolute; left: 50%; right: 0; top: 0; bottom: 0; background: rgba(55, 50, 41, .1); }
.c-membars__meter-fill { position: absolute; left: 0; top: 0; bottom: 0; background: #373229; opacity: .7; }
.c-membars__meter-one { position: absolute; left: 50%; top: -3px; bottom: -3px; border-left: 1px dashed rgba(55, 50, 41, .6); }
.c-membars__fail { font-size: 0.85rem; font-style: italic; color: var(--color-text-light); visibility: hidden; }
.c-membars.is-failing .c-membars__fail { visibility: visible; }
.c-membars__beta-row[hidden] { display: none; }
