/*
 * Scholarly book style — early 1900s edition
 *
 * Typeface: EB Garamond (body) and IM Fell English (headings)
 * Palette: aged cream paper, dark brown ink, muted gold accents
 *
 * Covers:
 *   - Global page and typography overrides for the Material theme
 *   - Margin note layout (flex on wide screens, stacked on mobile)
 */

@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400;1,500&family=IM+Fell+English+SC&display=swap');

/* ------------------------------------------------------------------ */
/* Colour palette                                                       */
/* ------------------------------------------------------------------ */

:root {
    --book-paper:       #f4efe3;
    --book-paper-dark:  #ede6d5;
    --book-ink:         #1c1208;
    --book-ink-light:   #4a3b28;
    --book-ink-faint:   #8a7a62;
    --book-rule:        #b5a48a;
    --book-accent:      #1c1208;
    --book-note-bg:     #f4efe3;
    --book-note-border: #c9b99a;
}

/* ------------------------------------------------------------------ */
/* Material theme variable overrides                                    */
/* ------------------------------------------------------------------ */

[data-md-color-scheme="default"],
:root {
    --md-default-bg-color:        var(--book-paper);
    --md-default-fg-color:        var(--book-ink);
    --md-default-fg-color--light: var(--book-ink-light);
    --md-default-fg-color--lighter: var(--book-ink-faint);
    --md-default-fg-color--lightest: var(--book-rule);
    --md-primary-fg-color:        var(--book-accent);
    --md-primary-bg-color:        var(--book-paper);
    --md-accent-fg-color:         var(--book-accent);
    --md-code-bg-color:           var(--book-paper-dark);
    --md-typeset-a-color:         var(--book-accent);
    --md-text-font:               "EB Garamond", Georgia, serif;
    --md-code-font:               "Courier New", monospace;
}

/* ------------------------------------------------------------------ */
/* Global typography                                                    */
/* ------------------------------------------------------------------ */

body,
.md-typeset {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 1rem;
    line-height: 1.75;
    color: var(--book-ink);
    background-color: var(--book-paper);
}

/* Justified body text, like a typeset book */
.md-typeset p {
    text-align: justify;
    hyphens: auto;
    margin-bottom: 0.9em;
}

/* Headings in small caps serif */
.md-typeset h1,
.md-typeset h2,
.md-typeset h3 {
    font-family: "IM Fell English SC", "EB Garamond", Georgia, serif;
    font-weight: normal;
    color: var(--book-ink);
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--book-rule);
    padding-bottom: 0.2em;
}

.md-typeset h1 { font-size: 1.9rem; margin-bottom: 1.2rem; }
.md-typeset h2 { font-size: 1.45rem; }
.md-typeset h3 { font-size: 1.15rem; border-bottom: none; }

/* Links: understated, book-like */
.md-typeset a {
    color: var(--book-accent);
    text-decoration: underline;
    text-decoration-color: var(--book-rule);
    text-underline-offset: 2px;
}

.md-typeset a:hover {
    color: var(--book-ink);
    text-decoration-color: var(--book-ink);
}

/* Footnotes */
.md-typeset .footnote {
    font-size: 0.88rem;
    border-top: 1px solid var(--book-rule);
    margin-top: 2rem;
    padding-top: 0.5rem;
    color: var(--book-ink-light);
}

/* Blockquote: indented, no coloured bar */
.md-typeset blockquote {
    border-left: none;
    padding-left: 2.5em;
    font-style: italic;
    color: var(--book-ink-light);
}

/* Navigation sidebar */
.md-nav {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.95rem;
}

.md-nav__title,
.md-header__title {
    font-family: "IM Fell English SC", "EB Garamond", Georgia, serif;
    font-weight: normal;
    letter-spacing: 0.05em;
}

/* Header bar */
.md-header {
    background-color: var(--book-ink);
    color: var(--book-paper);
    box-shadow: 0 2px 4px rgba(0,0,0,0.35);
}

/* Page content area
 *
 * On standard screens: constrain to a readable book-width column.
 * On wide screens: expand to use the full grid width; the margin-note
 * column absorbs the extra space while prose stays at a readable width.
 */
.md-content__inner {
    max-width: 1100px;
}

/* ------------------------------------------------------------------ */
/* Margin note layout                                                   */
/* ------------------------------------------------------------------ */

.annotated-paragraph {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 0.9em;
}

.annotated-body {
    flex: 1 1 auto;
    min-width: 200px;
}

.annotated-body p {
    margin-bottom: 0;
}

.margin-note {
    flex: 0 0 340px;
    width: 340px;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--book-ink-light);
    background-color: var(--book-note-bg);
    border-top: 1px solid var(--book-note-border);
    border-bottom: 1px solid var(--book-note-border);
    padding: 0.5rem 0.7rem;
}

/* All headings inside a note — reset Material theme sizes to fit the note column */
.margin-note h1,
.margin-note h2,
.margin-note h3,
.margin-note h4,
.margin-note h5,
.margin-note h6 {
    font-family: "IM Fell English SC", "EB Garamond", Georgia, serif;
    font-size: 0.82rem;
    font-weight: normal;
    font-style: normal;
    letter-spacing: 0.04em;
    line-height: 1.3;
    margin: 0 0 0.3em 0;
    padding-bottom: 0.2em;
    border-bottom: 1px solid var(--book-note-border);
    border-top: none;
    color: var(--book-ink);
}

.margin-note p {
    text-align: left;
    margin-bottom: 0.4em;
}

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

.margin-note a {
    color: var(--book-accent);
    text-decoration: underline;
    text-decoration-color: var(--book-rule);
}

.margin-note-item {
    display: block;
}

.margin-note-item + .margin-note-item {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--book-note-border);
}

/* Label for the matched name at the start of a note or back-reference */
.note-label,
.ref-label {
    font-family: "IM Fell English SC", "EB Garamond", Georgia, serif;
    font-style: normal;
    letter-spacing: 0.03em;
}

/* Back-reference: compact link back to first note occurrence */
.margin-note-item--ref {
    font-size: 0.78rem;
    color: var(--book-ink-faint);
}

.margin-note-item--ref .ref-label {
    font-style: normal;
}

.margin-note-item--ref a {
    color: var(--book-ink-faint);
    text-decoration: none;
    font-style: normal;
}

/* ------------------------------------------------------------------ */
/* Expandable note details (topics index)                               */
/* ------------------------------------------------------------------ */

details {
    margin-top: 0.4em;
    margin-bottom: 0.6em;
}

details summary {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.82rem;
    font-style: italic;
    color: var(--book-ink-faint);
    cursor: pointer;
    list-style: none;
    padding: 0.1em 0;
}

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

details summary::before {
    content: "+ ";
    font-style: normal;
    color: var(--book-rule);
}

details[open] summary::before {
    content: "- ";
}

details[open] {
    border-left: 1px solid var(--book-note-border);
    padding-left: 0.8em;
    margin-left: 0.1em;
}

details[open] p,
details[open] li {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.5 rem;
    line-height: 1.55;
    color: var(--book-ink-light);
    margin-bottom: 0.4em;
}

/* ------------------------------------------------------------------ */
/* Narrow screens: stack note below the paragraph                       */
/* ------------------------------------------------------------------ */

@media (max-width: 768px) {
    .annotated-paragraph {
        flex-direction: column;
        gap: 0.5rem;
    }

    .margin-note {
        flex: 0 0 auto;
        width: 100%;
        border-top: 2px solid var(--book-note-border);
        border-bottom: 1px solid var(--book-note-border);
    }

    .pull-quote {
        float: none;
        max-width: 100%;
        margin: 1em 0;
    }
}

/* ------------------------------------------------------------------ */
/* Paragraph line numbers                                               */
/* ------------------------------------------------------------------ */

a.line-number {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.6rem;
    color: var(--book-rule);
    text-decoration: none;
    margin-right: 0.35em;
    vertical-align: 0.15em;
    user-select: none;
    font-variant-numeric: tabular-nums;
}

a.line-number:hover {
    color: var(--book-ink-faint);
    text-decoration: underline;
}

/* Original book page numbers — shown inline at the point of each page break */
span.page-number {
    display: block;
    text-align: center;
    margin: 2em 0;
    padding: 0.5em 0;
    border-top: 1px solid var(--book-rule);
    border-bottom: 1px solid var(--book-rule);
    font-size: 0.75rem;
    color: var(--book-ink-faint);
    background: rgba(0,0,0,0.02);
}

span.page-number::before { content: "["; }
span.page-number::after  { content: "]"; }

/* ------------------------------------------------------------------ */
/* MapLibre attribution — compact, palette-matched                      */
/* ------------------------------------------------------------------ */

.maplibregl-ctrl-attrib.maplibregl-compact {
    background-color: rgba(244, 236, 216, 0.85) !important;
    border-radius: 3px !important;
}

.maplibregl-ctrl-attrib-button {
    background-color: var(--book-ink-faint) !important;
}

.maplibregl-ctrl-attrib-inner {
    font-family: "EB Garamond", Georgia, serif !important;
    font-size: 0.65rem !important;
    color: var(--book-ink-light) !important;
}

.maplibregl-ctrl-attrib-inner a {
    color: var(--book-ink-light) !important;
}

/* ------------------------------------------------------------------ */
/* Note badge on FMT entries that have an associated note              */
/* ------------------------------------------------------------------ */

.note-badge {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.72rem;
    font-style: italic;
    color: var(--book-ink-faint);
    border: 1px solid var(--book-rule);
    padding: 0.05em 0.45em;
    vertical-align: middle;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Pull quotes                                                          */
/* ------------------------------------------------------------------ */

.pull-quote {
    float: left;
    max-width: 33%;
    min-width: 200px;
    margin: 0.3em 1.6em 0.6em 0;
    padding: 0.5em 0.8em;
    border-top: 1px solid var(--book-rule);
    border-bottom: 1px solid var(--book-rule);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--book-ink-light);
}

.pull-quote p {
    margin: 0;
    hyphens: none;
}

/* ------------------------------------------------------------------ */
/* Images inside margin notes                                           */
/* ------------------------------------------------------------------ */

.note-image {
    margin: 0.5em 0 0.2em 0;
    padding: 0;
}

.note-image a {
    display: block;
    text-decoration: none;
}

.note-image img {
    display: block;
    width: 100%;
    cursor: zoom-in;
    border: 1px solid var(--book-note-border);
}

.note-image figcaption {
    font-size: 0.72rem;
    text-align: center;
    color: var(--book-ink-faint);
    font-style: italic;
    margin-top: 0.25em;
}

/* ------------------------------------------------------------------ */
/* Image lightbox overlay                                               */
/* ------------------------------------------------------------------ */

#note-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    cursor: zoom-out;
    align-items: center;
    justify-content: center;
}

#note-lightbox.note-lightbox--open {
    display: flex;
}

#note-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.6);
    cursor: zoom-out;
}

/* ------------------------------------------------------------------ */
/* Build timestamp in footer                                            */
/* ------------------------------------------------------------------ */

.md-build-time {
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.75rem;
    font-style: italic;
    color: var(--book-ink-faint);
    margin-top: 0.4rem;
}

/* ------------------------------------------------------------------ */
/* Wide screen layout (must come last to override base rules above)    */
/* ------------------------------------------------------------------ */

@media (min-width: 1280px) {
    /* Hide the secondary (table of contents) sidebar */
    .md-sidebar--secondary {
        display: none;
    }

    /* Stretch the Material grid to use the full viewport width */
    .md-main__inner {
        max-width: none;
    }

    .md-content {
        max-width: none;
    }

    .md-content__inner {
        max-width: none;
        padding-right: 2rem;
    }

    /* Annotated paragraph: body 65%, note 32% */
    .annotated-paragraph {
        width: 100%;
    }

    .annotated-body {
        flex: 65 1 0;
        min-width: 0;
    }

    .margin-note {
        flex: 32 1 0;
        min-width: 280px;
        width: auto;
        font-size: 0.85rem;
    }
}
