/* ABOUTME: The Manual web edition's reading design: serif typography, contents sidebar, figures and reference tables.
   ABOUTME: Scoped under .manual; colours come from the theme's --md-sys-color-* tokens only. */

.manual {
    --manual-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --manual-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --manual-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    color: var(--md-sys-color-on-surface);
}

.manual-layout {
    display: grid;
    grid-template-columns: 17rem minmax(0, 1fr);
    gap: clamp(1.5rem, 4vw, 3.5rem);
    align-items: start;
}

.manual-main {
    min-width: 0;
    max-width: 46rem;
}

/* ── Reading typography ──────────────────────────────────────────────────── */

.manual-main,
.manual .manual-intro,
.manual .manual-index {
    font-family: var(--manual-serif);
    font-size: 1.0625rem;
    line-height: 1.65;
}

.manual-chapter {
    overflow-wrap: break-word;
}

.manual-chapter h2 {
    font-family: var(--manual-serif);
    font-size: 1.45rem;
    font-weight: 650;
    line-height: 1.3;
    margin: 2.5rem 0 0.75rem;
}

.manual-chapter h3 {
    font-family: var(--manual-serif);
    font-size: 1.1rem;
    font-weight: 650;
    line-height: 1.35;
    margin: 2rem 0 0.5rem;
}

.manual-chapter h2,
.manual-chapter h3 {
    scroll-margin-top: 1rem;
}

.manual-chapter a,
.manual .manual-index a {
    color: var(--md-sys-color-primary);
}

.manual .manual-index {
    padding-inline-start: 1.5rem;
}

.manual .manual-index > li {
    margin-block-end: 1rem;
}

.manual .manual-index > li > p {
    margin-block: 0.25rem 0;
    color: var(--md-sys-color-on-surface-variant);
}

/* ── Code ────────────────────────────────────────────────────────────────── */

.manual-chapter code {
    font-family: var(--manual-mono);
    font-size: 0.85em;
    background: var(--md-sys-color-surface-container-low);
    padding: 0.1em 0.3em;
    border-radius: 4px;
    overflow-wrap: anywhere;
}

.manual-chapter pre {
    background: var(--md-sys-color-surface-container-low);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
}

.manual-chapter pre code {
    background: none;
    padding: 0;
    overflow-wrap: normal;
}

/* ── Figures ─────────────────────────────────────────────────────────────── */

.manual-chapter img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.25rem 0;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 6px;
}

.manual-chapter figure {
    margin: 1.5rem 0;
}

.manual-chapter figure img {
    margin: 0 0 0.5rem;
}

.manual-chapter figcaption {
    font-family: var(--manual-sans);
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface-variant);
}

/* ── Definition lists ────────────────────────────────────────────────────── */

.manual-chapter dt {
    font-weight: 650;
    margin-top: 1rem;
}

.manual-chapter dd {
    margin: 0.25rem 0 0 1.5rem;
}

/* ── Reference tables ────────────────────────────────────────────────────── */

.manual-chapter table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    font-family: var(--manual-sans);
    font-size: 0.84rem;
    line-height: 1.5;
    margin: 1rem 0 2rem;
}

.manual-chapter th {
    text-align: left;
    border-top: 2px solid var(--md-sys-color-on-surface);
    border-bottom: 1px solid var(--md-sys-color-on-surface);
    padding: 0.5rem 0.75rem 0.5rem 0;
}

.manual-chapter td {
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    padding: 0.5rem 0.75rem 0.5rem 0;
    vertical-align: top;
}

/* ── Edition stamp ───────────────────────────────────────────────────────── */

.manual .manual-edition {
    margin-top: 4rem;
    padding-top: 1rem;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    font-family: var(--manual-sans);
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface-variant);
}

/* ── Contents sidebar ────────────────────────────────────────────────────── */

.manual-sidebar {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 12px;
    padding: 1.25rem 1rem;
    font-family: var(--manual-sans);
}

.manual-sidebar .manual-contents-toggle {
    display: none;
}

.manual-contents ol {
    margin: 0;
    padding-left: 1.4rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.manual-contents li {
    margin: 0.45rem 0;
}

.manual-contents .manual-sections,
.manual-contents .manual-sections ol {
    list-style: none;
    padding-left: 0.9rem;
    font-size: 0.8125rem;
}

.manual-contents a {
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
}

.manual-contents a:hover {
    color: var(--md-sys-color-primary);
    text-decoration: underline;
}

.manual-contents a[aria-current="page"] {
    color: var(--md-sys-color-on-surface);
    font-weight: 650;
}

.manual-contents a:focus-visible,
.manual-sidebar .manual-contents-toggle:focus-visible {
    outline: 2px solid var(--md-sys-color-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ── Small screens: the contents fold behind their toggle ────────────────── */

@media (max-width: 52rem) {
    .manual-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .manual-sidebar {
        position: static;
        max-height: none;
        padding: 0.75rem 1rem;
    }

    .manual-sidebar.manual-contents-collapsible .manual-contents-toggle {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        background: none;
        border: none;
        padding: 0.25rem 0;
        font: inherit;
        font-weight: 650;
        color: var(--md-sys-color-on-surface);
        cursor: pointer;
    }

    .manual-sidebar.manual-contents-collapsible .manual-contents-toggle::before {
        content: "▸";
        content: "▸" / "";
    }

    .manual-sidebar.manual-contents-collapsible .manual-contents-toggle[aria-expanded="true"]::before {
        content: "▾";
        content: "▾" / "";
    }

    .manual-sidebar.manual-contents-collapsible .manual-contents-toggle[aria-expanded="false"] + .manual-contents {
        display: none;
    }

    .manual-sidebar.manual-contents-collapsible .manual-contents {
        margin-top: 0.5rem;
    }
}
