/* ==========================================================================
   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;
}

/* 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;
}

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

.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 {
    margin: 0 0 var(--space-md);
}

.c-odds svg,
.c-company svg,
.c-gradient 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;
}

/* 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);
}

/* 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);
}

/* 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;
    }
}
