/* ── paperpages.css ──────────────────────────────────────────────────────────
   Supplemental styles for the academic-paper-to-HTML pipeline.
   Loaded after tufte.css; corrects elements that tufte.css does not target.
   ─────────────────────────────────────────────────────────────────────────── */

/* LaTeX \begin{center} environments */
div.center {
    width: 55%;
    text-align: center;
}
figure div.center {
    width: 100%;
}

/* Abstract: same width as main text column */
#abstract {
    width: 55%;
}

/* Figure, table, and section counters (body + appendix) */
article {
    counter-reset: figure-counter table-counter section-counter
                   appendix-section-counter appendix-figure-counter appendix-table-counter;
}

/* Body sections: numeric */
section.level2 {
    counter-increment: section-counter;
}
section.level2 > h2::before {
    content: counter(section-counter) ". ";
}
/* Appendix sections: alphabetic — overrides body rule */
section.level2.appendix {
    counter-increment: appendix-section-counter;
}
section.level2.appendix > h2::before {
    content: counter(appendix-section-counter, upper-alpha) ". ";
}

/* Body figures: "Figure N" */
figure {
    display: flex;
    flex-direction: column;
    counter-increment: figure-counter;
}
figure figcaption::before {
    content: "Figure " counter(figure-counter) ". ";
}
/* Appendix figures: "Figure A.N" — overrides body rule */
section.level2.appendix figure {
    counter-increment: appendix-figure-counter;
}
section.level2.appendix figure figcaption::before {
    content: "Figure " counter(appendix-section-counter, upper-alpha)
             "." counter(appendix-figure-counter) ". ";
}

/* Body tables: "Table N" */
table {
    counter-increment: table-counter;
}
caption::before {
    content: "Table " counter(table-counter) ". ";
}
/* Appendix tables: "Table A.N" — overrides body rule */
section.level2.appendix table {
    counter-increment: appendix-table-counter;
}
section.level2.appendix caption::before {
    content: "Table " counter(appendix-section-counter, upper-alpha)
             "." counter(appendix-table-counter) ". ";
}

/* Figure images: fill the figure container width.
   LaTeX \includegraphics widths (e.g. 0.75\textwidth) are meaningless in
   HTML where the figure is already constrained to the body column. */
figure img {
    width: 100% !important;
}

/* Figure captions: above the image, body text size */
figure figcaption {
    order: -1;
    float: none;
    max-width: 100%;
    font-size: 1.4rem;
    text-align: center;
}

/* Tables: match body text size (Tufte only sets 1.4rem on p/dl/ol/ul) */
table, caption {
    font-size: 1.4rem;
}

/* Table and figure notes (pandoc renders \begin{minipage} as div.minipage) */
div.minipage {
    width: 55%;
}
div.minipage p {
    font-size: 1.1rem;
    line-height: 1.6;
}

/* Notes inside a constrained container should fill it */
figure div.minipage,
div.center div.minipage {
    width: 100%;
}

/* Eliminate the whitespace character that HTML renders between inline text
   and the sidenote label element. */
label.sidenote-number {
    margin-left: -0.3em;
}

/* The \thanks{} label sits inside <h1>. Tufte CSS hides label.margin-toggle
   on wide screens, but we want the "*" to remain visible as a superscript. */
h1 label.margin-toggle {
    display: inline;
    vertical-align: super;
    font-size: 0.7em;
}

/* Bibliography (pandoc citeproc) */
div.csl-entry {
    clear: both;
}
.hanging-indent div.csl-entry {
    margin-left: 2em;
    text-indent: -2em;
}

/* Mobile: let both fill the available width */
@media (max-width: 760px) {
    #abstract,
    div.center,
    div.minipage,
    h1 .marginnote {
        width: 100%;
    }

    h1 label.margin-toggle:not(.sidenote-number) {
        display: none;
    }

    /* The \thanks{} marginnote: its label is hidden above, so it can never be
       toggled. Prevent it from showing even if the checkbox is somehow checked. */
    [id^="sn-thanks-"] + .marginnote {
        display: none !important;
    }

    /* Tables wider than the text column scroll horizontally rather than
       expanding the page. display:block is required for overflow-x to work
       on a table element. */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
