/* Theseus essays and reports. Loaded after styles.css, whose tokens, nav, footer and
   theme it reuses. Each essay's figure classes come from its own fig.css. */

:root {
    --measure: 37rem;          /* about 68 characters of Newsreader at 1.2rem */
    --wide: 48rem;             /* figures, tables, boxes */
    --toc: 15rem;
    --toc-gap: 5rem;
    --art-overlap: clamp(3rem, 9vw, 9rem);   /* how far the header art reaches up into the header */
    /* the faintest ink carries small text here (reference numbers, back-links, figure
       labels), so it is darkened to reach 4.5:1 on both backgrounds (WCAG AA) */
    --ink-3: #776A62;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ink-3: #897C74;      /* 4.6:1 on --bg-2 */
        --accent: #DC4E41;     /* 4.6:1 on --bg-2, for citations inside boxes */
        --night: #17110F;      /* header and footer one step lighter than the page */
    }
}

:root[data-theme="dark"] {
    --ink-3: #897C74;
    --accent: #DC4E41;
    --night: #17110F;
}

.article-page .nav-bar.scrolled {
    background: var(--night);
}

html {
    scroll-padding-top: 5.5rem;  /* anchors clear the fixed nav */
}

/* ------------------------------------------------------------ header */

.art-head {
    position: relative;
    overflow: hidden;
    background: var(--night);
    color: var(--on-night);
    padding: calc(var(--space-lg) + 2.5rem) var(--gutter) var(--space-md);
}

/* the mark, large and faint, until the header art exists */
.art-head::before {
    content: "";
    position: absolute;
    right: 6%;
    top: 50%;
    width: min(40vh, 30vw);
    aspect-ratio: 1;
    transform: translateY(-50%);
    background: url("logo-dark.svg") center / contain no-repeat;
    opacity: 0.12;
}

.art-head-inner {
    position: relative;
    max-width: var(--wide);
    margin: 0 auto;
}

.art-kicker {
    font: 500 0.72rem/1.5 var(--mono);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    opacity: 0.85;
    margin-bottom: 1.4rem;
}

.art-title {
    font: 500 clamp(2.6rem, 6.5vw, 5rem)/1 var(--serif);
    letter-spacing: -0.03em;
    max-width: 14ch;
}

.art-dek {
    margin-top: 1.2rem;
    max-width: 34ch;
    font: 400 clamp(1.2rem, 2.2vw, 1.55rem)/1.35 var(--serif);
    color: rgba(237, 229, 218, 0.88);
}

.art-meta {
    margin-top: 2.2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.8rem;
    font: 500 0.7rem/1.5 var(--mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(237, 229, 218, 0.7);
}

/* header art: a plate that straddles the foot of the dark header */
.art-head.has-art {
    padding-bottom: calc(var(--space-md) + var(--art-overlap));
}

.art-head.has-art::before {
    display: none;
}

.art-hero {
    position: relative;
    max-width: calc(var(--toc) + var(--toc-gap) + var(--wide) + 2 * var(--gutter));
    margin: calc(-1 * var(--art-overlap)) auto 0;
    padding: 0 var(--gutter);
}

.art-hero img {
    display: block;
    width: 100%;
    height: auto;
    box-shadow: 0 22px 48px -28px rgba(13, 10, 9, 0.6);
}

.art-hero + .draft-note {
    margin-top: var(--space-md);
}

.draft-note {
    background: var(--accent);
    color: var(--accent-ink);
    text-align: center;
    font: 600 0.72rem/1.4 var(--sans);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.7rem var(--gutter);
}

/* ------------------------------------------------------------ the writing list */

.w-head .art-title {
    max-width: none;
}

.w-main {
    background: var(--bg);
    padding: var(--space-md) var(--gutter) var(--space-xl);
}

.w-main:focus {
    outline: none;
}

.w-list {
    list-style: none;
    max-width: var(--wide);
    margin: 0 auto;
    padding: 0;
}

.w-item {
    display: grid;
    gap: 1.4rem;
    padding: 2.4rem 0;
    border-bottom: 1px solid var(--rule);
}

.w-item:first-child {
    padding-top: 0.5rem;
}

@media (min-width: 761px) {
    .w-item {
        grid-template-columns: minmax(0, 18rem) minmax(0, 1fr);
        gap: 2.2rem;
        align-items: start;
    }
}

.w-art img {
    display: block;
    width: 100%;
    height: auto;
}

.w-meta {
    font: 500 0.7rem/1.5 var(--mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.w-title {
    margin-top: 0.5rem;
    font: 500 clamp(1.6rem, 3vw, 2.1rem)/1.15 var(--serif);
    letter-spacing: -0.02em;
}

.w-title a {
    color: var(--ink);
    text-decoration: none;
}

.w-title a:hover {
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.18em;
}

.w-dek {
    margin-top: 0.7rem;
    font: 400 1.1rem/1.5 var(--serif);
    color: var(--ink-2);
    max-width: 40rem;
}

/* ------------------------------------------------------------ layout */

.art-layout {
    background: var(--bg);
    padding: var(--space-md) var(--gutter) var(--space-lg);
}

.art-body {
    max-width: var(--wide);
    margin: 0 auto;
    font: 400 1.2rem/1.68 var(--serif);
    color: var(--ink);
    font-kerning: normal;
    hyphens: manual;
}

/* prose keeps the measure; figures, tables and boxes take the wider column */
.art-body :is(p, ul, ol, dl, h2, h3, details.fig-data) {
    max-width: var(--measure);
    margin-left: auto;
    margin-right: auto;
}

.art-body :is(figure, .table-wrap, aside, .endmatter) {
    max-width: var(--wide);
    margin-left: auto;
    margin-right: auto;
}

.art-body section + section,
.art-body .part + section {
    margin-top: 0;
}

.art-body p {
    margin-bottom: 1.05em;
}

.art-body em {
    font-style: italic;
}

.art-body strong {
    font-weight: 500;
}

.art-body a {
    color: var(--accent);
}

.art-body a.xref:hover,
.art-body .endmatter a:hover {
    text-decoration: underline;
    text-underline-offset: 0.18em;
}

/* ------------------------------------------------------------ headings */

.art-body h2 {
    font: 500 clamp(1.75rem, 3vw, 2.25rem)/1.18 var(--serif);
    letter-spacing: -0.015em;
    margin-top: var(--space-md);
    margin-bottom: 1.3rem;
}

/* the skip link moves focus to the text; the text itself needs no ring */
main.art-body:focus {
    outline: none;
}

/* a back-link from the references lands with the sentence in view, not under the nav */
.cite-ref {
    scroll-margin-top: 40vh;
}

.h-num {
    display: block;
    margin-bottom: 0.7rem;
    font: 500 0.7rem/1.5 var(--mono);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.art-body h3 {
    font: 500 1.42rem/1.3 var(--serif);
    letter-spacing: -0.01em;
    margin-top: 2.6rem;
    margin-bottom: 0.9rem;
}

.h-anchor {
    margin-left: 0.4em;
    font: 400 0.6em/1 var(--sans);
    color: var(--ink-3) !important;
    opacity: 0;
    transition: opacity 0.2s ease;
}

h2:hover > .h-anchor,
h3:hover > .h-anchor,
.h-anchor:focus-visible {
    opacity: 1;
}

/* Part I, Part II */
.art-body .part {
    max-width: var(--measure);
    margin: var(--space-lg) auto 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    font: 600 0.84rem/1.5 var(--mono);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink);
}

.art-body .part::after {
    content: "";
    flex: 1;
    height: 1px;
    background: currentColor;
    opacity: 0.35;
}

.art-body .part + section > h2 {
    margin-top: 1.4rem;
}

/* ------------------------------------------------------------ in brief, boxes */

.in-brief {
    max-width: calc(var(--measure) + 3.6rem) !important;
    margin-bottom: var(--space-md);
    padding: 1.5rem 1.8rem 1.4rem;
    background: var(--bg-2);
    border: 1px solid var(--rule);
    border-top: 2px solid var(--ink);
}

.art-body .in-brief h2,
.art-body aside.box h3 {
    margin: 0 0 0.9rem;
    font: 500 0.72rem/1.5 var(--mono);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.in-brief ul {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 1.06rem;
    line-height: 1.6;
}

.in-brief li + li {
    margin-top: 0.55rem;
}

.in-brief li::marker {
    color: var(--accent);
}

.art-body aside.box {
    max-width: calc(var(--measure) + 3.6rem);
    margin-top: 2.2rem;
    margin-bottom: 2.2rem;
    padding: 1.4rem 1.8rem 0.5rem;
    background: var(--bg-2);
    border: 1px solid var(--rule);
    border-radius: 6px;
    font-size: 1.08rem;
}

.art-body .eq {
    text-align: center;
    font-size: 1.35rem;
    letter-spacing: 0.02em;
    margin: 1.1rem auto 1.3rem;
}

/* ------------------------------------------------------------ figures */

.art-body figure {
    margin-top: 2.6rem;
    margin-bottom: 2.6rem;
}

.art-body figcaption {
    max-width: var(--measure);
    margin: 1rem auto 0;
    font: 400 0.86rem/1.55 var(--sans);
    color: var(--ink-2);
}

.fig-label {
    font-weight: 600;
    color: var(--ink);
}

.art-body figure img {
    display: block;
    width: min(100%, 29.5rem);   /* a definite width, so the space is kept before the image loads */
    max-width: 100%;
    height: auto;
    max-height: 34rem;
    object-fit: contain;
    margin: 0 auto;
    padding: 1rem;
    background: var(--bg-2);
    border: 1px solid var(--rule);
    border-radius: 6px;
}

/* a scan on white paper stays a light plate in the dark theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .art-body figure img {
        background: #FBF8F3;
        border-color: transparent;
    }
}

:root[data-theme="dark"] .art-body figure img {
    background: #FBF8F3;
    border-color: transparent;
}

/* a raster figure keeps the text measure, so it sits under the column it illustrates */
.art-body figure.raster {
    max-width: var(--measure);
}

.fig-wrap {
    position: relative;
}

/* boxes drawn to the very edge of a figure keep their full stroke */
.art-body .fig-scroll {
    padding-inline: 2px;
}

.art-body svg.fig {
    overflow: visible;
}

/* a figure drawn narrow enough for a phone (class "fit") does not scroll */
@media (max-width: 680px) {
    .art-body .fig-scroll svg.fig.fit {
        min-width: 0;
    }
}

/* on a phone a figure keeps its width and scrolls; a fade marks the hidden part */
@media (max-width: 680px) {
    .fig-wrap::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 2.5rem;
        background: linear-gradient(90deg, transparent, var(--bg));
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .fig-wrap.at-end::after {
        opacity: 0;
    }
}

.art-body figure.step {
    margin-top: 1.6rem;
    margin-bottom: 1.8rem;
}

.art-body figure.closing {
    max-width: 7rem;
    margin-top: var(--space-md);
}

.art-body figure.closing figcaption {
    text-align: center;
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-3);
}

details.fig-data {
    margin-top: 0;
    margin-bottom: 2.6rem;
    font: 400 0.84rem/1.5 var(--sans);
}

/* the numbers follow their figure closely */
.art-body figure:has(+ details.fig-data) {
    margin-bottom: 0.9rem;
}

details.fig-data summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500;
}

/* in a Source column the reference numbers are the content, so they sit on the line at full size */
details.fig-data td.src sup.cite {
    font-size: 1em;
    vertical-align: baseline;
    margin-left: 0;
}

details.fig-data .table-wrap {
    margin: 0.8rem 0 0;
}

/* ------------------------------------------------------------ tables */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* the caption sits above the frame, so it stays in view while a wide table scrolls */
.art-body figure.table-fig figcaption {
    margin: 0 0 0.9rem;
}

.art-body table {
    width: 100%;
    border-collapse: collapse;
    font: 400 0.84rem/1.5 var(--sans);
}

.art-body th,
.art-body td {
    text-align: left;
    vertical-align: top;
    padding: 0.55rem 0.75rem 0.55rem 0;
    border-bottom: 1px solid color-mix(in srgb, var(--rule), var(--ink-3) 30%);
}

.art-body thead th {
    font-weight: 600;
    font-size: 0.76rem;
    letter-spacing: 0.04em;
    border-bottom: 1.5px solid var(--ink);
}

.art-body tbody th {
    font-weight: 600;
}

.art-body td.num {
    white-space: nowrap;
}

@media (max-width: 680px) {
    .art-body table {
        min-width: 34rem;
    }

    /* a table wider than the screen shows a soft shadow on the side that has more */
    .table-wrap {
        background:
            linear-gradient(90deg, var(--bg) 40%, transparent) left / 2rem 100% no-repeat local,
            linear-gradient(270deg, var(--bg) 40%, transparent) right / 2rem 100% no-repeat local,
            radial-gradient(farthest-side at 0 50%, color-mix(in srgb, var(--ink) 18%, transparent), transparent) left / 0.75rem 100% no-repeat scroll,
            radial-gradient(farthest-side at 100% 50%, color-mix(in srgb, var(--ink) 18%, transparent), transparent) right / 0.75rem 100% no-repeat scroll;
    }
}

/* ------------------------------------------------------------ citations */

sup.cite {
    color: var(--accent);      /* the commas between numbers match the numbers */
    font: 500 0.62em/0 var(--sans);
    vertical-align: super;
    margin-left: 0.08em;
    white-space: nowrap;
}

sup.cite a {
    color: var(--accent);
    padding: 0 0.05em;
}

sup.cite a:hover,
sup.cite a:focus-visible {
    text-decoration: underline;
}

.cite-pop {
    position: absolute;
    z-index: 200;
    max-width: min(27rem, calc(100vw - 2rem));
    padding: 0.8rem 1rem;
    background: var(--bg-2);
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: 6px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    font: 400 0.8rem/1.5 var(--sans);
    overflow-wrap: anywhere;
}

.cite-pop-n {
    font-family: var(--mono);
    color: var(--accent);
    margin-right: 0.4rem;
}

/* ------------------------------------------------------------ glossary */

.glossary dl {
    font-size: 1.08rem;
}

.glossary dt {
    margin-top: 1.1rem;
    font: 600 0.92rem/1.4 var(--sans);
}

.glossary dd {
    margin: 0.25rem 0 0;
}

/* ------------------------------------------------------------ end matter */

.art-body .endmatter {
    margin-top: var(--space-lg);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--ink-3);
}

.art-body .endmatter--small {
    margin-top: var(--space-md);
    border-top-width: 1px;
    border-top-color: var(--rule);
}

.art-body .endmatter h2 {
    font-size: 1.5rem;
    margin-top: 0;
}

.art-body .endmatter {
    max-width: 42rem;             /* about 90 characters of the small type */
}

.art-body .endmatter :is(h2, p, ul, ol, details) {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
}

.refs,
.credits,
.endmatter p {
    font: 400 0.84rem/1.55 var(--sans);
    color: var(--ink-2);
}

.refs {
    padding-left: 2.4rem;
}

.refs li {
    margin-bottom: 0.55rem;
    padding-left: 0.3rem;
    overflow-wrap: anywhere;
}

.refs li::marker {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--ink-3);
}

.refs li:target {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.ref-back {
    margin-left: 0.2rem;
    font-family: var(--mono);
    font-size: 0.76rem;
    color: var(--ink-3);
    white-space: nowrap;
}

.ref-back a {
    padding: 0 0.12rem;
}

.credits {
    list-style: none;
}

.credits li + li {
    margin-top: 0.4rem;
}

.credits + p {
    margin-top: 0.9rem;
}

.cite-apa {
    color: var(--ink) !important;
}

.cite-bib summary {
    cursor: pointer;
    font: 500 0.84rem/1.5 var(--sans);
    color: var(--accent);
    margin-bottom: 0.8rem;
}

.cite-bib pre {
    overflow-x: auto;
    padding: 1rem 1.2rem;
    background: var(--bg-2);
    border: 1px solid var(--rule);
    border-radius: 6px;
    font: 400 0.78rem/1.6 var(--mono);
    color: var(--ink);
}

.licence {
    margin-top: 1.4rem;
}

/* ------------------------------------------------------------ contents */

.toc {
    max-width: var(--measure);
    margin: 0 auto var(--space-md);
    font: 400 0.84rem/1.45 var(--sans);
}

.toc details {
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
}

.toc summary {
    padding: 0.85rem 0;
    cursor: pointer;
    font: 500 0.72rem/1.5 var(--mono);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.toc ol {
    list-style: none;
}

.toc-list {
    padding-bottom: 0.8rem;
}

.toc a {
    display: flex;
    gap: 0.5rem;
    padding: 0.26rem 0;
    color: var(--ink-2);
}

.toc a:hover,
.toc a.active {
    color: var(--ink);
}

.toc a.active .toc-num {
    color: var(--accent);
}

.toc-num {
    flex: none;
    width: 1.5rem;
    padding-top: 0.12rem;
    font: 500 0.7rem/1.45 var(--mono);
    color: var(--ink-3);
}

.toc-sub {
    padding: 0 0 0.3rem 2rem;
}

.toc-sub a {
    padding: 0.16rem 0;
    font-size: 0.78rem;
}

.toc-end {
    padding-top: 0.7rem;
    border-top: 1px solid var(--rule);
}

@media (min-width: 1200px) {
    .art-layout {
        display: grid;
        grid-template-columns: var(--toc) minmax(0, var(--wide));
        justify-content: center;
        column-gap: var(--toc-gap);
        align-items: start;
    }

    .art-head-inner {
        max-width: calc(var(--toc) + var(--toc-gap) + var(--wide));
        padding-left: calc(var(--toc) + var(--toc-gap));
    }

    .art-body {
        margin: 0;
    }

    .art-body :is(p, ul, ol, dl, h2, h3, figure, .table-wrap, aside, .endmatter, details.fig-data, figcaption),
    .art-body .part {
        margin-left: 0;
        margin-right: 0;
    }

    .art-body figure.closing {
        margin-left: calc((var(--measure) - 7rem) / 2);
    }

    .toc {
        position: sticky;
        top: 5.5rem;
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
        margin: 0;
        padding-right: 0.5rem;
        scrollbar-width: thin;
    }

    .toc details {
        border: 0;
    }

    .toc summary {
        list-style: none;
        pointer-events: none;
        padding-top: 0;
    }

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

/* ------------------------------------------------------------ phone */

@media (max-width: 760px) {
    .art-head::before {
        right: -14%;
        top: 4.5rem;
        width: 42vw;
        transform: none;
        opacity: 0.08;
    }

    .art-body {
        font-size: 1.1rem;
    }

    .in-brief,
    .art-body aside.box {
        padding-left: 1.2rem;
        padding-right: 1.2rem;
    }

    .refs {
        padding-left: 1.9rem;
    }
}

/* ------------------------------------------------------------ print */

@media print {
    :root,
    :root[data-theme="dark"],
    :root:not([data-theme="light"]) {
        --bg: #FFFFFF;
        --bg-2: #FFFFFF;
        --ink: #1D1613;
        --ink-2: #4A3F39;
        --ink-3: #7A6E66;
        --rule: #D9CFC3;
        --accent: #B5382B;
        color-scheme: light;
    }

    .nav-bar,
    .skip,
    .toc,
    .h-anchor,
    .site-footer,
    .cite-pop,
    .ref-back,
    .cite-bib,
    .fig-wrap::after {
        display: none !important;
    }

    body {
        font-size: 10.5pt;
    }

    .art-head {
        background: none;
        color: var(--ink);
        padding: 0 0 1.5rem;
    }

    .art-head::before {
        display: none;
    }

    .art-head.has-art {
        padding-bottom: 1rem;
    }

    .art-hero {
        margin: 0 0 1.5rem;
        padding: 0;
        max-width: none;
        break-inside: avoid;
    }

    .art-hero img {
        box-shadow: none;
    }

    .art-dek,
    .art-meta {
        color: var(--ink-2);
    }

    .art-layout {
        display: block;
        padding: 0;
    }

    .art-body {
        max-width: none;
        font-size: 11pt;
    }

    .fig-scroll svg.fig {
        min-width: 0 !important;
    }

    /* the nine step figures repeat one diagram, so they print smaller */
    .art-body figure.step .fig-wrap {
        max-width: 78%;
        margin: 0 auto;
    }

    figure,
    table,
    aside,
    .refs li {
        break-inside: avoid;
    }

    h2,
    h3 {
        break-after: avoid;
    }

    details.fig-data:not([open]) {
        display: none;
    }
}

/* a step figure follows its heading closely */
.art-body h3 + figure.step {
    margin-top: 0.6rem;
}

/* the section being read is marked in the contents */
.toc a.active {
    color: var(--accent);
}
