/* Printing and "Save as PDF" for single pages.

   `[output.html.print] enable = false` in book.toml turns off mdBook's
   whole-book print.html, and with it the print stylesheet mdBook would
   otherwise link from every page. The first block restates the parts of that
   stylesheet the site needs (hide the chrome, let the content use the page);
   the rest is specific to the blog. */

@media print {
    /* --- mdBook chrome, as mdBook's own print.css hides it -------------- */

    #mdbook-sidebar,
    #mdbook-menu-bar,
    #mdbook-menu-bar-hover-placeholder,
    #mdbook-search-wrapper,
    #sidebar,
    #menu-bar,
    #menu-bar-hover-placeholder,
    #search-wrapper,
    .nav-wrapper,
    .nav-wide-wrapper,
    .nav-chapters,
    .mobile-nav-chapters,
    .sidebar-resize-handle {
        display: none !important;
    }

    .page-wrapper {
        transform: none !important;
        margin-inline-start: 0 !important;
        overflow-y: initial;
    }

    .content {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .content main {
        max-width: none;
    }

    /* chrome.css pulls the page up under the sticky menu bar; with the bar
       hidden that would cut off the top of the first heading. */
    .page {
        margin-top: 0 !important;
        overflow-y: initial;
    }

    code {
        direction: ltr !important;
    }

    /* --- always print on white ----------------------------------------- */

    /* Readers on navy/coal/ayu would otherwise get light text that vanishes
       once the browser drops background colours. html.<theme> outranks the
       .<theme> rules in variables.css. */
    html,
    html.light,
    html.rust,
    html.navy,
    html.coal,
    html.ayu {
        --bg: #fff;
        --fg: #000;
        --links: #1f5fa6;
        --inline-code-color: #301900;
        --quote-bg: #f5f5f5;
        --quote-border: #ccc;
        --table-border-color: #ccc;
        --table-header-bg: #eee;
        --table-alternate-bg: #f7f7f7;
        --pill-bg: transparent;
        --pill-fg: #000;
        --sidebar-non-existant: #555;
    }

    body {
        background: #fff;
        color: #000;
        font-size: 11pt;
    }

    @page {
        margin: 18mm 16mm;
    }

    /* --- flow ---------------------------------------------------------- */

    h1, h2, h3, h4, h5, h6 {
        break-after: avoid;
        break-inside: avoid;
    }

    pre, blockquote, table, figure, img, svg, .video-embed {
        break-inside: avoid;
    }

    p {
        orphans: 3;
        widows: 3;
    }

    /* Long lines wrap instead of being cut off at the page edge. */
    pre, pre > code {
        overflow: visible !important;
        white-space: pre-wrap !important;
        word-break: break-word;
    }

    pre {
        border: 1px solid #ddd;
    }

    img, svg {
        max-width: 100% !important;
    }

    /* --- things that only make sense on screen ------------------------- */

    pre > .buttons,
    .header > .anchor,
    .site-link,
    .print-hide {
        display: none !important;
    }

    a.header {
        color: inherit;
    }

    /* Pills lose their background on paper; outline them instead. */
    a.taxonomy-pill {
        border: 1px solid #ccc;
        padding: 0 0.5em;
    }

    /* A YouTube iframe prints as an empty box; print its link instead. */
    .video-embed {
        aspect-ratio: auto;
    }

    .video-embed iframe {
        display: none;
    }

    .video-embed .video-link {
        display: inline !important;
    }

    /* --- link targets -------------------------------------------------- */

    /* Paper has no hover: spell out where external links go. In-site links
       and anchors are left alone, they would only add noise. */
    main a[href^="http"]:not(.taxonomy-pill)::after {
        content: " <" attr(href) ">";
        color: #555;
        font-size: 0.8em;
        word-break: break-all;
    }

    main a[href^="http"]:has(img)::after {
        content: none;
    }

    /* --- whole-series print pages (series/<slug>/print.html) ----------- */

    .print-post + .print-post {
        break-before: page;
    }

    .print-cover {
        break-after: page;
    }
}

/* Screen styles for the series print page. */

@media screen {
    .print-cover .print-hint {
        border: 1px solid var(--table-border-color, rgba(0, 0, 0, 0.1));
        border-radius: 4px;
        font-size: 0.9em;
        padding: 0.6em 0.9em;
    }

    .print-post {
        border-top: 1px solid var(--table-border-color, rgba(0, 0, 0, 0.1));
        margin-top: 3em;
        padding-top: 1em;
    }
}

.print-toc {
    padding-left: 2.5em;
}
