/*
 * Reading pages: research, about. Builds on base.css.
 *
 * The layout is a single reading column (--measure) with room on wide screens
 * for a sticky contents list on the left and margin notes on the right, the way
 * distill.pub sets an article. Figures and tables may break out to --wide.
 */

.doc-head {
    /* No side padding: the inner grid's middle column keeps the gutter, the
       same way the article's .doc grid does, so the two line up. */
    padding: var(--s-9) 0 var(--s-8);
    /* Every reading page opens in the salon: dark jade, a soft light from
       the table, then the text on bone paper below. */
    background:
        radial-gradient(60rem 26rem at 80% 0%, rgba(143, 217, 182, 0.09), transparent 70%),
        radial-gradient(40rem 20rem at 10% 120%, rgba(216, 206, 178, 0.06), transparent 70%),
        var(--bg);
}
@media (max-width: 600px) {
    .doc-head { padding-top: var(--s-7); padding-bottom: var(--s-7); }
}
/* One grid for every reading page: the title and lead start where the
   article column below them starts. */
.doc-head-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) min(var(--measure), 100% - 2 * var(--gutter)) minmax(0, 1fr);
    column-gap: var(--s-7);
}
.doc-head-inner > * { grid-column: 2 / -1; min-width: 0; }
@media (max-width: 1100px) { .doc-head-inner { column-gap: 0; } }
/* A picture for the empty half of a page's opening: the mark on About, a
   die showing 3 on the 404 ("No six"). */
.doc-head.has-art { position: relative; overflow: hidden; }
.doc-art {
    position: absolute;
    right: calc(var(--gutter) * 2);
    top: 50%;
    width: clamp(9rem, 16vw, 15rem);
    translate: 0 -50%;
    rotate: -8deg;
    filter: drop-shadow(0 30px 50px rgba(0, 0, 0, 0.55));
    pointer-events: none;
}
.doc-art svg { display: block; width: 100%; height: auto; }
.doc-art.die3 { rotate: 12deg; width: clamp(8rem, 13vw, 12rem); }
@media (max-width: 860px) { .doc-art { display: none; } }
.doc-head .eyebrow { display: block; margin-bottom: var(--s-4); font-family: var(--mono); font-size: 0.75rem; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--emph); }
.doc-head h1 { font-size: clamp(3rem, 1.8rem + 5vw, 5.6rem); line-height: 0.98; }
.doc-head h1 { max-width: 16ch; }
.doc-head .lead { max-width: 38rem; margin-top: var(--s-5); }
.doc-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2) var(--s-6);
    margin-top: var(--s-6);
    padding-top: var(--s-4);
    border-top: 1px solid var(--line);
    font-size: var(--t-2);
    color: var(--text-2);
}
.doc-meta dt { font-size: var(--t-1); color: var(--text-3); font-weight: 600; }
.doc-meta dd { margin: 0; }
.doc-meta div { display: grid; gap: 2px; }

/* ── Body grid: [toc] [text] [notes] ─────────────────────────────────── */
.doc {
    display: grid;
    grid-template-columns: minmax(0, 1fr) min(var(--measure), 100% - 2 * var(--gutter)) minmax(0, 1fr);
    column-gap: var(--s-7);
    padding: var(--s-8) 0 var(--s-9);
}
.doc > * { grid-column: 2; }
.doc > .toc { grid-column: 1; grid-row: 1 / span 999; justify-self: end; }
.doc > .wide { grid-column: 1 / -1; width: min(var(--wide), 100% - 2 * var(--gutter)); justify-self: center; }

.toc {
    position: sticky;
    top: calc(var(--bar-h) + var(--s-6));
    align-self: start;
    width: 13rem;
    font-size: var(--t-2);
    padding-left: var(--gutter);
}
.toc h2 { font-family: var(--sans); font-size: var(--t-1); font-weight: 650; color: var(--text-3); margin-bottom: var(--s-3); letter-spacing: 0.02em; }
.toc ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; border-left: 1px solid var(--line); }
.toc a {
    display: block;
    padding: 0.28rem 0 0.28rem var(--s-4);
    margin-left: -1px;
    border-left: 2px solid transparent;
    color: var(--text-3);
    text-decoration: none;
    line-height: 1.35;
    transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--text); }
.toc a[aria-current="true"] { color: var(--text); border-left-color: var(--accent); }
@media (max-width: 1100px) {
    .doc > .toc { display: none; }
    /* Without the contents column the gaps only push the text column past
       the viewport on phones (2 × 3rem of gap > 2 × gutter). */
    .doc { column-gap: 0; }
}

/* ── Prose ───────────────────────────────────────────────────────────── */
.prose {
    font-family: var(--sans);
    font-size: 1.0625rem;
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: -0.003em;
}
.prose > * + * { margin-top: 1.1em; }
.prose h2 {
    margin-top: var(--s-8);
    padding-top: var(--s-5);
    border-top: 1px solid var(--line);
    scroll-margin-top: calc(var(--bar-h) + var(--s-4));
}
.prose h2 .sec-n {
    display: block;
    margin-bottom: var(--s-2);
    font-family: var(--mono);
    font-size: var(--t-1);
    font-weight: 500;
    letter-spacing: 0;
    color: var(--text-3);
}
.prose h3 { margin-top: var(--s-7); scroll-margin-top: calc(var(--bar-h) + var(--s-4)); }
.prose h4 { margin-top: var(--s-6); }
.prose h2 + *, .prose h3 + *, .prose h4 + * { margin-top: var(--s-4); }
.prose strong { font-weight: 650; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.4em; }
.prose li::marker { color: var(--text-3); }
.prose a { color: var(--text); text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.prose a:hover { text-decoration-color: var(--accent); }
.prose code {
    font-family: var(--mono);
    font-size: 0.84em;
    padding: 0.08em 0.35em;
    background: var(--surface);
    border-radius: 4px;
}
.prose blockquote {
    padding-left: var(--s-5);
    border-left: 2px solid var(--brass);
    font-style: italic;
    color: var(--text-2);
}
.prose .ui, .prose figcaption, .prose table { font-family: var(--sans); }

/* ── Callouts ───────────────────────────────────────────────────────── */
.callout {
    padding: var(--s-5);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    font-family: var(--sans);
    font-size: var(--t-2);
    line-height: 1.6;
}
.callout > * + * { margin-top: 0.7em; }
.callout-title { font-weight: 650; color: var(--text); font-size: var(--t-3); }
.callout.tldr { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.callout.caveat { border-left: 3px solid var(--brass); }

/* ── Stats row ──────────────────────────────────────────────────────── */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    font-family: var(--sans);
}
.stat { background: var(--bg-raised); padding: var(--s-4) var(--s-5); }
.stat .v {
    display: block;
    font-family: var(--serif);
    font-size: 2rem;
    font-weight: 560;
    font-variation-settings: 'opsz' 72;
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums lining-nums;
}
.stat .k { display: block; margin-top: var(--s-1); font-size: var(--t-1); color: var(--text-2); line-height: 1.4; }

/* ── Figures ────────────────────────────────────────────────────────── */
figure.fig { margin-top: var(--s-7); margin-bottom: var(--s-7); }
.fig-frame {
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    background: var(--bg-raised);
    padding: var(--s-5);
    overflow-x: auto;
}
figure.fig figcaption {
    margin-top: var(--s-3);
    font-size: var(--t-2);
    line-height: 1.55;
    color: var(--text-2);
    max-width: var(--measure);
}
figure.fig figcaption b { color: var(--text); font-weight: 650; }

/* ── Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
    width: 100%;
    font-family: var(--sans);
    font-size: var(--t-2);
    font-variant-numeric: tabular-nums;
}
table.data th, table.data td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
table.data thead th {
    font-size: var(--t-1);
    font-weight: 650;
    color: var(--text-3);
    border-bottom-color: var(--line-2);
    white-space: nowrap;
}
table.data td.n, table.data th.n { text-align: right; font-family: var(--mono); }
table.data tbody tr:last-child td { border-bottom: 0; }

/* ── Definition lists (about page facts) ───────────────────────────── */
dl.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--s-3) var(--s-6);
    font-family: var(--sans);
    font-size: var(--t-2);
}
dl.facts dt { color: var(--text-3); font-weight: 600; }
dl.facts dd { margin: 0; }
@media (max-width: 560px) {
    dl.facts { grid-template-columns: 1fr; gap: 0; }
    dl.facts dd { margin-bottom: var(--s-3); }
}

/* ── End-of-page next steps ─────────────────────────────────────────── */
.next {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--s-4);
    margin-top: var(--s-8);
    font-family: var(--sans);
}
.next a {
    display: block;
    padding: var(--s-5);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    text-decoration: none;
    transition: border-color 0.2s, transform 0.2s var(--ease-out);
}
.next a:hover { border-color: var(--line-2); transform: translateY(-2px); }
.next .k { display: block; font-size: var(--t-1); color: var(--text-3); font-weight: 600; }
.next .t { display: block; margin-top: var(--s-1); font-family: var(--serif); font-size: var(--t-4); font-weight: 560; color: var(--text); }
