@font-face {
    font-family: "Source Serif 4";
    font-style: normal;
    font-weight: 200 900;
    font-display: swap;
    src: url("/fonts/source-serif-4.woff2") format("woff2");
}

@font-face {
    font-family: "Source Serif 4";
    font-style: italic;
    font-weight: 200 900;
    font-display: swap;
    src: url("/fonts/source-serif-4-italic.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/inter.woff2") format("woff2");
}

@font-face {
    font-family: "Source Code Pro";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/fonts/source-code-pro.woff2") format("woff2");
}

:root {
    color-scheme: light dark;

    --font-serif: "Source Serif 4", Charter, "Iowan Old Style", Georgia, serif;
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Source Code Pro", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --brand-orange: #f89c0e;
    --brand-navy: #152c66;

    --color-background: light-dark(#fdfcf9, #15181c);
    --color-surface: light-dark(#f5f3ee, #1d2127);
    --color-text: light-dark(#24292c, #e4e2dd);
    --color-muted: light-dark(#5d6368, #a3a8ae);
    --color-line: light-dark(#dedad2, #31363e);
    --color-link: light-dark(#152c66, #f6a935);
    --color-link-hover: light-dark(#a75a00, #ffc670);
    --color-button: light-dark(#152c66, #f89c0e);
    --color-button-text: light-dark(#ffffff, #15181c);
    --color-code-background: light-dark(#f4f2ed, #1c2026);
    --color-code-line: light-dark(#e4e0d8, #2b3038);
    --color-code-comment: light-dark(#637083, #8b97a8);
    --color-code-keyword: light-dark(#7c2d72, #d9a3e3);
    --color-code-string: light-dark(#3c6f1e, #a5d18a);
    --color-code-function: light-dark(#075d75, #7fcfe6);
    --color-code-variable: light-dark(#8a4800, #f0b97a);
    --color-code-number: light-dark(#9a3412, #f29e8a);

    --header-height: 3.25rem;
    --gutter: clamp(1rem, 4vw, 2.5rem);
    --measure: 44rem;
    --radius: 0.5rem;
}

:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 100%;
    scroll-padding-top: calc(var(--header-height) + 1rem);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--color-background);
    color: var(--color-text);
    font-family: var(--font-serif);
    font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.25rem);
    font-optical-sizing: auto;
    line-height: 1.6;
    text-rendering: optimizeLegibility;
}

::selection {
    background: color-mix(in srgb, var(--brand-orange) 35%, transparent);
}

:focus-visible {
    outline: 2px solid var(--color-link);
    outline-offset: 2px;
}

a {
    color: var(--color-link);
    text-decoration-thickness: 0.06em;
    text-underline-offset: 0.18em;
}

a:hover {
    color: var(--color-link-hover);
}

img {
    max-width: 100%;
    height: auto;
}

[hidden] {
    display: none !important;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -4rem;
    z-index: 30;
    padding: 0.5rem 0.75rem;
    background: var(--color-button);
    color: var(--color-button-text);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    border-radius: var(--radius);
}

.skip-link:focus {
    top: 0.5rem;
    color: var(--color-button-text);
}

/* Header */

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: var(--header-height);
    padding: 0 var(--gutter);
    background: color-mix(in srgb, var(--color-background) 92%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--color-line);
    font-family: var(--font-sans);
    font-size: 0.875rem;
}

.site-title {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-right: auto;
    color: var(--color-text);
    font-family: var(--font-serif);
    font-size: 1.125rem;
    font-weight: 650;
    text-decoration: none;
}

.site-title::before {
    content: "";
    width: 0.625rem;
    height: 0.625rem;
    background: var(--brand-orange);
    border-radius: 2px;
}

.site-title:hover {
    color: var(--color-text);
}

.contents-link,
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.theme-toggle {
    width: 2.25rem;
    padding: 0;
}

.contents-link:hover,
.theme-toggle:hover {
    background: var(--color-surface);
    color: var(--color-text);
}

/* Layout */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

.content {
    min-width: 0;
}

main {
    padding: clamp(1.5rem, 4vw, 3.5rem) var(--gutter) 2rem;
}

.page {
    max-width: var(--measure);
    margin-inline: auto;
}

.on-this-page {
    display: none;
}

/* Table of contents */

.toc {
    padding: 1.5rem var(--gutter) 3rem;
    border-top: 1px solid var(--color-line);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.4;
}

.toc-heading,
.on-this-page-heading {
    margin: 0 0 0.75rem;
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.toc-filter {
    width: 100%;
    margin-bottom: 0.75rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    background: var(--color-background);
    color: var(--color-text);
    font: inherit;
}

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

.toc ol ol {
    margin-left: 0.6rem;
    padding-left: 0.4rem;
    border-left: 1px solid var(--color-line);
}

.toc a {
    display: block;
    padding: 0.3rem 0.5rem;
    border-radius: 0.25rem;
    color: var(--color-text);
    text-decoration: none;
    overflow-wrap: anywhere;
}

.toc li > a {
    margin-left: 1.25rem;
}

.toc a:hover {
    background: var(--color-surface);
}

.toc a[aria-current="page"] {
    background: var(--color-surface);
    box-shadow: inset 3px 0 0 var(--brand-orange);
    color: var(--color-link);
    font-weight: 600;
}

.toc > ol > li > a,
.toc > ol > li > details > summary a {
    font-weight: 600;
}

.toc summary {
    display: flex;
    align-items: flex-start;
    list-style: none;
}

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

.toc summary::before {
    content: "›";
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.85rem;
    color: var(--color-muted);
    font-size: 1.1rem;
    cursor: pointer;
}

.toc details[open] > summary::before {
    transform: rotate(90deg);
}

.toc summary a {
    flex: 1;
}

.toc code,
.on-this-page code,
.breadcrumbs code,
.pager code,
.children code {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

/* Breadcrumbs */

.breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0.5rem;
    margin: 0 0 1.25rem;
    padding: 0;
    list-style: none;
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
}

.breadcrumbs li + li::before {
    content: "/";
    margin-right: 0.5rem;
    color: var(--color-line);
}

.breadcrumbs a {
    color: var(--color-muted);
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--color-link-hover);
    text-decoration: underline;
}

/* Book content */

.book-content h1,
.home h1 {
    margin: 0 0 1.5rem;
    font-size: clamp(2rem, 1.5rem + 2.2vw, 2.9rem);
    font-weight: 620;
    letter-spacing: -0.015em;
    line-height: 1.12;
    overflow-wrap: break-word;
    text-wrap: balance;
}

.book-content h2 {
    margin: 1.8em 0 0.6em;
    font-size: 1.45em;
    font-weight: 620;
    letter-spacing: -0.01em;
    line-height: 1.2;
    overflow-wrap: break-word;
    text-wrap: balance;
}

.book-content p,
.book-content ul,
.book-content ol {
    margin: 0 0 1.15em;
    hyphens: manual;
    text-wrap: pretty;
}

.book-content ul,
.book-content ol {
    padding-left: 1.4em;
}

.book-content li {
    margin-bottom: 0.4em;
}

.book-content li::marker {
    color: var(--color-muted);
}

.book-content li > p:last-child {
    margin-bottom: 0;
}

code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    font-variant-ligatures: none;
}

:not(pre) > code {
    padding: 0.08em 0.22em;
    border-radius: 0.25rem;
    background: var(--color-code-background);
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    overflow-wrap: anywhere;
}

h1 code,
.toc code,
.on-this-page code,
.breadcrumbs code,
.pager code,
.children a code {
    padding: 0;
    background: none;
}

pre {
    margin: 1.5em 0;
    padding: 1rem 1.15rem;
    overflow-x: auto;
    border: 1px solid var(--color-code-line);
    border-radius: var(--radius);
    background: var(--color-code-background);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    tab-size: 4;
}

pre code {
    font-size: inherit;
    white-space: pre;
}

pre .c {
    color: var(--color-code-comment);
    font-style: italic;
}

pre .k {
    color: var(--color-code-keyword);
}

pre .s {
    color: var(--color-code-string);
}

pre .f {
    color: var(--color-code-function);
}

pre .v {
    color: var(--color-code-variable);
}

pre .n {
    color: var(--color-code-number);
}

.code {
    position: relative;
}

.copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--color-code-line);
    border-radius: 0.375rem;
    background: var(--color-background);
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
}

.code:hover .copy,
.copy:focus-visible {
    opacity: 1;
}

.copy:hover {
    color: var(--color-text);
}

@media (hover: none) {
    .copy {
        opacity: 1;
    }
}

.book-content table {
    display: block;
    max-width: 100%;
    margin: 1.5em 0;
    overflow-x: auto;
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.45;
}

.book-content th,
.book-content td {
    padding: 0.5rem 0.9rem 0.5rem 0;
    border-bottom: 1px solid var(--color-line);
    text-align: left;
    vertical-align: top;
}

.book-content th {
    border-bottom-width: 2px;
    font-weight: 600;
}

.book-content figure {
    margin: 2em 0;
    text-align: center;
}

.book-content figure img {
    padding: 0.5rem;
    border-radius: var(--radius);
    background: #ffffff;
}

.book-content figcaption {
    margin-top: 0.6rem;
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
}

.book-content .portrait {
    width: 8.5rem;
    border-radius: 50%;
}

/* Generated blocks below the book text */

.children,
.promo,
.pager {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    line-height: 1.5;
}

.children {
    margin-top: 2.5rem;
}

.children h2 {
    margin: 0 0 0.5rem;
    color: var(--color-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.children ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.children li {
    padding: 0.85rem 0;
    border-top: 1px solid var(--color-line);
}

.children a {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
    text-decoration: none;
}

.children a:hover {
    text-decoration: underline;
}

.children p {
    margin: 0.2rem 0 0;
    color: var(--color-muted);
}

.promo {
    margin: 3.5rem 0 2.5rem;
    padding: 1.4rem 1.6rem 1.5rem;
    border: 1px solid var(--color-line);
    border-left: 4px solid var(--brand-orange);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.promo-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.75rem;
    color: var(--color-muted);
    font-size: 0.8125rem;
    font-weight: 600;
}

.promo-label img {
    width: 2.75rem;
    height: auto;
    padding: 0.2rem;
    border-radius: 0.375rem;
    background: #ffffff;
}

.promo h2 {
    margin: 0 0 0.4rem;
    font-family: var(--font-serif);
    font-size: 1.35rem;
    font-weight: 620;
    line-height: 1.25;
    text-wrap: balance;
}

.promo p {
    margin: 0 0 0.75rem;
}

.promo p:last-child {
    margin-bottom: 0;
}

.promo-link {
    font-weight: 600;
}

.promo-link::after {
    content: " \2192";
}

.pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 2.5rem;
}

.pager a {
    display: block;
    padding: 0.8rem 1rem;
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    color: var(--color-text);
    text-decoration: none;
}

.pager a:hover {
    border-color: var(--brand-orange);
}

.pager a[rel="next"] {
    grid-column: 2;
    text-align: right;
}

.pager span {
    display: block;
    color: var(--color-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.pager strong {
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* Footer */

.site-footer {
    padding: 0 var(--gutter) 3rem;
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    line-height: 1.5;
}

.site-footer > div {
    max-width: var(--measure);
    margin-inline: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-line);
}

.site-footer p {
    margin: 0 0 0.4rem;
}

.site-footer a {
    color: inherit;
}

.site-footer a:hover {
    color: var(--color-link-hover);
}

/* Landing page */

.home .page,
.home .site-footer > div {
    max-width: 62rem;
}

.home .edition,
.home .promo {
    max-width: 44rem;
}

.hero {
    display: grid;
    gap: 2rem;
    align-items: center;
}

.hero h1 {
    margin-bottom: 0.5rem;
    font-size: clamp(2.5rem, 1.6rem + 4vw, 4rem);
}

.tagline {
    margin: 0 0 1.5rem;
    color: var(--color-muted);
    font-size: 1.3em;
    font-style: italic;
    line-height: 1.3;
}

.hero p {
    max-width: 34rem;
}

.cover {
    margin: 0;
    padding: 1rem;
    border-radius: 1rem;
    background: light-dark(transparent, #ffffff);
}

.cover img {
    display: block;
    width: 100%;
    mix-blend-mode: multiply;
}

.button {
    display: inline-block;
    padding: 0.75rem 1.4rem;
    border-radius: var(--radius);
    background: var(--color-button);
    color: var(--color-button-text);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
}

.button:hover {
    background: var(--color-link-hover);
    color: var(--color-button-text);
}

.edition {
    margin: 3rem 0;
    padding-left: 1.25rem;
    border-left: 4px solid var(--color-line);
}

.edition h2,
.chapters > h2 {
    margin: 0 0 0.5rem;
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.edition p {
    margin: 0;
}

.chapters ol {
    display: grid;
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.chapters li a {
    display: block;
    height: 100%;
    padding: 1.25rem 1.4rem;
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    color: var(--color-text);
    text-decoration: none;
}

.chapters li a:hover {
    border-color: var(--brand-orange);
}

.chapters h3 {
    margin: 0 0 0.4rem;
    font-size: 1.3em;
    font-weight: 620;
    line-height: 1.2;
}

.chapters p {
    margin: 0;
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    line-height: 1.5;
}

.chapters .count {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.error-page {
    padding-block: 3rem;
}

/* Wider screens */

@media (min-width: 44rem) {
    .hero {
        grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    }

    .chapters ol {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 63.999rem) {
    .js .toc {
        display: none;
    }

    .js.toc-open .toc {
        display: block;
        position: fixed;
        inset: var(--header-height) 0 0 0;
        z-index: 15;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: var(--color-background);
        border-top: 0;
    }

    .js.toc-open body {
        overflow: hidden;
    }
}

@media (min-width: 64rem) {
    .book .layout {
        grid-template-columns: 20rem minmax(0, 1fr);
    }

    .toc {
        grid-column: 1;
        grid-row: 1;
        position: sticky;
        top: var(--header-height);
        align-self: start;
        height: calc(100dvh - var(--header-height));
        padding: 1.5rem 1rem 3rem 1.25rem;
        overflow-y: auto;
        overscroll-behavior: contain;
        border-top: 0;
        border-right: 1px solid var(--color-line);
    }

    .book .content {
        grid-column: 2;
        grid-row: 1;
    }

    .contents-link {
        display: none;
    }
}

@media (min-width: 88rem) {
    .book .layout {
        grid-template-columns: 20rem minmax(0, 1fr) 17rem;
    }

    .on-this-page {
        display: block;
        grid-column: 3;
        grid-row: 1;
        position: sticky;
        top: var(--header-height);
        align-self: start;
        max-height: calc(100dvh - var(--header-height));
        padding: 3.5rem 1.5rem 2rem 0;
        overflow-y: auto;
        font-family: var(--font-sans);
        font-size: 0.8125rem;
        line-height: 1.4;
    }

    .on-this-page ol {
        margin: 0;
        padding: 0;
        list-style: none;
        border-left: 1px solid var(--color-line);
    }

    .on-this-page a {
        display: block;
        padding: 0.3rem 0 0.3rem 0.85rem;
        color: var(--color-muted);
        text-decoration: none;
        overflow-wrap: anywhere;
    }

    .on-this-page a:hover {
        color: var(--color-link-hover);
    }
}

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }

    .toc summary::before {
        transition: transform 0.15s;
    }

    .copy {
        transition: opacity 0.15s;
    }
}

@media print {
    :root {
        color-scheme: light;
    }

    body {
        background: #ffffff;
        color: #000000;
        font-size: 11pt;
    }

    .site-header,
    .skip-link,
    .toc,
    .on-this-page,
    .breadcrumbs,
    .children,
    .promo,
    .pager,
    .copy {
        display: none !important;
    }

    .layout {
        display: block;
    }

    main {
        padding: 0;
    }

    .page {
        max-width: none;
    }

    a {
        color: inherit;
        text-decoration: none;
    }

    pre {
        overflow: visible;
        white-space: pre-wrap;
        break-inside: avoid;
    }

    pre code {
        white-space: pre-wrap;
    }

    h1,
    h2 {
        break-after: avoid;
    }
}
