/* Numbered captions for code listings and images (see mdbook-caption.py).
   Listing output mirrors the Rust Book's `trpl-listing` preprocessor:
     <figure class="listing" id="listing-N-M">
       <span class="file-name">Arquivo: …</span>
       <pre>…code…</pre>
       <figcaption><a href="#listing-N-M">Código N-M</a>: …</figcaption>
     </figure>
   Images use the same shape with class="figure" and id="figure-N-M". */

figure.listing,
figure.figure {
    margin: 1.5rem 0;
}

/* Keep the inner block flush with the figure edges. */
figure.listing > pre {
    margin: 0;
}

/* An image figure: center it and never let it overflow the text column. The
   image arrives wrapped in a <p> (the blank line after the opening <figure>
   makes it parse as its own Markdown block). */
figure.figure > p {
    margin: 0;
    text-align: center;
}

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

/* Optional "Arquivo: …" line above a listing, like the Rust Book. */
figure.listing .file-name {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85em;
    font-style: italic;
    color: var(--sidebar-fg, #6e6e6e);
    opacity: 0.85;
}

/* The caption itself: subtle, italic, centered below the code or image. */
figure.listing > figcaption,
figure.figure > figcaption {
    margin-top: 0.5rem;
    font-size: 0.9em;
    font-style: italic;
    text-align: center;
    color: var(--fg, inherit);
    opacity: 0.8;
    line-height: 1.4;
}

/* The caption text arrives wrapped in a <p> (a blank line inside <figcaption>
   makes mdBook render it as Markdown, so `code`, emphasis and links work).
   Strip the paragraph's default margins so spacing stays tight. Inline code in
   a caption shouldn't be italicized by the figcaption rule above. */
figure.listing > figcaption p,
figure.figure > figcaption p {
    margin: 0;
}

figure.listing > figcaption code,
figure.figure > figcaption code {
    font-style: normal;
}

/* "Código N-M" / "Figura N-M" is a live cross-reference target; keep the link
   quiet until hovered so the caption reads as prose, not a button. */
figure.listing > figcaption a,
figure.figure > figcaption a {
    font-style: normal;
    font-weight: 600;
    color: inherit;
    text-decoration: none;
}

figure.listing > figcaption a:hover,
figure.figure > figcaption a:hover {
    text-decoration: underline;
}

/* When a cross-reference jumps to a figure, briefly hint at the target. */
figure.listing:target,
figure.figure:target {
    scroll-margin-top: 1rem;
}

figure.listing:target > figcaption,
figure.figure:target > figcaption {
    opacity: 1;
}
