/* The printed booklet: a 5e-style book, whatever theme the reader picked
   (Tia, 28 Sep 2026: "homebrewery style booklet"). Loaded only by
   /blog/booklet/. blog-booklet.js fills #booklet-print and sets
   html.booklet-ready; everything here is inside @media print, so the page on
   screen is untouched. A .extra.css file is not a selectable theme
   (THEME_NAMES skips it), and colours may be written here because it sits
   in themes/. Brief: docs/features/12-blog-booklet.md.

   No image files and no font files. The parchment is gradients over a base
   colour; the body face is the site's own stack ('Bookinsanity' where the
   reader has it installed, Georgia otherwise) and the cover title is celticg,
   which the site already ships. Margins fit A4 and US Letter alike. */

@media print {
    :root {
        --bk-paper: #eee5ce;
        --bk-stain: rgba(196, 160, 98, 0.22);
        --bk-stain-2: rgba(160, 120, 70, 0.14);
        --bk-red: #58180d;
        --bk-gold: #c9ad6a;
        --bk-ink: #1d1a14;
        --bk-note: #e0e5c1;
        --bk-rule: #9c2b1b;
    }

    /* The parchment is a flat colour on @page (it covers the margins too)
       and gradients on the root. Gradients on @page itself crash Chrome's
       print (checked 28 Sep 2026, Chrome and headless: "Printing failed"). */
    @page {
        margin: 16mm 15mm 18mm;
        background-color: #eee5ce;
        @bottom-center {
            content: counter(page);
            font-family: Georgia, serif;
            font-size: 9pt;
            color: #58180d;
        }
    }
    @page :first {
        @bottom-center { content: none; }
    }

    html.booklet-ready {
        background-color: #eee5ce !important;
        background-image:
            radial-gradient(ellipse at 18% 12%, rgba(196, 160, 98, 0.22), transparent 45%),
            radial-gradient(ellipse at 85% 78%, rgba(160, 120, 70, 0.16), transparent 50%),
            radial-gradient(ellipse at center, transparent 62%, rgba(133, 98, 52, 0.22)) !important;
    }
    html.booklet-ready,
    html.booklet-ready body {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    html.booklet-ready body { background: transparent !important; }
    html.booklet-ready body > *:not(#booklet-print) { display: none !important; }
    html.booklet-ready #booklet-print { display: block !important; }

    #booklet-print,
    #booklet-print * {
        font-family: 'Bookinsanity', Georgia, 'Times New Roman', serif;
        line-height: 1.38;
        color: var(--bk-ink);
    }
    #booklet-print { font-size: 9.6pt; }
    #booklet-print * { text-shadow: none; }

    /* ── cover ─────────────────────────────────────────── */
    .bk-cover {
        break-after: page;
        min-height: 240mm;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding-top: 45mm;
        box-sizing: border-box;
    }
    .bk-cover-kicker {
        font-variant: small-caps;
        letter-spacing: .25em;
        font-size: 12pt;
        color: var(--bk-red);
        margin: 0 0 6mm;
    }
    #booklet-print .bk-cover-title {
        font-family: 'celticg', 'Bookinsanity', Georgia, serif;
        font-size: 40pt;
        line-height: 1.1;
        color: var(--bk-red);
        margin: 0 0 8mm;
        padding: 0 10mm 6mm;
        border-bottom: 3px solid var(--bk-gold);
    }
    .bk-cover-sub {
        font-style: italic;
        font-size: 12pt;
        margin: 0 0 22mm;
    }
    #booklet-print .bk-contents-title {
        font-variant: small-caps;
        color: var(--bk-red);
        font-size: 15pt;
        margin: 0 0 3mm;
        border: 0;
    }
    .bk-contents {
        list-style: none;
        counter-reset: bkc;
        padding: 0;
        margin: 0;
        width: 70%;
        text-align: left;
        font-size: 11pt;
    }
    .bk-contents li {
        counter-increment: bkc;
        padding: 1.4mm 0;
        border-bottom: 1px dotted var(--bk-gold);
    }
    .bk-contents li::before {
        content: counter(bkc) ".";
        display: inline-block;
        width: 8mm;
        color: var(--bk-red);
        font-weight: 700;
    }

    /* ── one article per chapter ───────────────────────── */
    .bk-article { break-before: page; }
    .bk-article:first-of-type { break-before: auto; }
    .bk-head { margin-bottom: 3mm; }
    #booklet-print .bk-title {
        font-variant: small-caps;
        font-size: 24pt;
        line-height: 1.1;
        font-weight: 700;
        color: var(--bk-red);
        margin: 0 0 1.5mm;
    }
    #booklet-print .bk-byline {
        font-style: italic;
        font-size: 9.5pt;
        margin: 0;
        padding-bottom: 2mm;
        border-bottom: 3px solid var(--bk-gold);
    }
    .bk-cover-image {
        display: block;
        width: 100%;
        max-height: 85mm;
        object-fit: cover;
        margin: 0 0 4mm;
        border: 1px solid var(--bk-gold);
    }
    .bk-body {
        column-count: 2;
        column-gap: 8mm;
        column-fill: balance;
    }
    #booklet-print .bk-body p { margin: 0 0 2.2mm; text-align: left; orphans: 2; widows: 2; }
    #booklet-print .bk-body h2,
    #booklet-print .bk-body h3,
    #booklet-print .bk-body h4 {
        font-variant: small-caps;
        font-weight: 700;
        color: var(--bk-red);
        break-after: avoid;
        margin: 3.5mm 0 1.5mm;
        line-height: 1.15;
    }
    #booklet-print .bk-body h2 {
        font-size: 14pt;
        padding-bottom: .8mm;
        border-bottom: 2px solid var(--bk-gold);
    }
    #booklet-print .bk-body h3 { font-size: 11.5pt; }
    #booklet-print .bk-body h4 { font-size: 10pt; }
    #booklet-print .bk-body ul,
    #booklet-print .bk-body ol { margin: 0 0 2.2mm; padding-left: 5mm; }
    #booklet-print .bk-body li { margin: 0 0 .8mm; }
    #booklet-print .bk-body a { color: var(--bk-ink); text-decoration: none; }
    #booklet-print .bk-body strong { color: var(--bk-ink); }
    #booklet-print .bk-body img {
        display: block;
        max-width: 100%;
        height: auto;
        margin: 2mm 0;
        break-inside: avoid;
    }
    /* Notes read like the book's green-grey sidebar boxes. */
    #booklet-print .bk-body blockquote {
        margin: 2.5mm 0;
        padding: 2mm 3mm;
        background: var(--bk-note);
        border-top: 2px solid var(--bk-ink);
        border-bottom: 2px solid var(--bk-ink);
        break-inside: avoid;
    }
    #booklet-print .bk-body blockquote p:last-child { margin-bottom: 0; }
    /* The roller's global table rules (flex rows, fixed-height celtic th)
       are undone here, as .post-body undoes them on screen. */
    #booklet-print .bk-body table {
        display: table;
        width: 100%;
        border-collapse: collapse;
        margin: 2mm 0 3mm;
        font-size: 8.4pt;
        break-inside: avoid;
    }
    #booklet-print .bk-body tr { display: table-row; }
    #booklet-print .bk-body th {
        display: table-cell;
        height: auto;
        width: auto;
        font-size: 1em;
        vertical-align: bottom;
        text-align: left;
        font-weight: 700;
        padding: .8mm 1.2mm;
        border: 0;
        border-bottom: 1px solid var(--bk-red);
    }
    #booklet-print .bk-body td { padding: .8mm 1.2mm; border: 0; vertical-align: top; }
    #booklet-print .bk-body tbody tr:nth-child(odd) { background: var(--bk-note); }
    #booklet-print .bk-body pre,
    #booklet-print .bk-body code {
        font-family: Consolas, 'Courier New', monospace;
        font-size: 8.4pt;
        white-space: pre-wrap;
        word-break: break-word;
    }
    #booklet-print .bk-body hr {
        border: 0;
        border-top: 2px solid var(--bk-rule);
        margin: 3mm 0;
    }
    #booklet-print .bk-source {
        column-span: all;
        margin: 4mm 0 0;
        font-size: 8pt;
        font-style: italic;
        text-align: right;
        color: var(--bk-red);
    }

    /* Paper is never this narrow; a phone's print preview can be. One
       column there, so a table is never wider than the page. */
    @media (max-width: 600px) {
        .bk-body { column-count: 1; }
        #booklet-print .bk-cover-title { font-size: 28pt; }
    }
}
