/* Custom fonts for The Ghost of SVR4 */

@font-face {
    font-family: 'Alegreya';
    src: url('Alegreya-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Alegreya';
    src: url('Alegreya-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Space Mono';
    src: url('SpaceMono-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* Apply Alegreya to body text */
body {
    font-family: 'Alegreya', serif;
}

/* Apply Space Mono to monospace elements */
code, pre, .hljs {
    font-family: 'Space Mono', monospace;
}

/* Default image styling - base for all images */
.page-wrapper img, .content img,
img {
    height: auto !important;      /* Maintains aspect ratio */
    display: block;               /* Block-level for centering */
    margin: 1em auto;             /* Center with margin */
    page-break-inside: avoid;     /* Prevent breaking across pages */
}

/* Cartoons (illustrative images) - 50% width */
img[src*="cartoon"] {
    max-width: 50% !important;
}

/* Technical diagrams (everything that's NOT a cartoon) - 90% width, height constrained */
img:not([src*="cartoon"]) {
    max-width: 90% !important;
    max-height: 5.5in !important;
}

/* Center image captions - image and caption are in same <p> tag */
p img + strong {
    display: block !important;
    text-align: center !important;
    font-style: italic;
    margin-top: 0.5em;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* Horizontal rules as page breaks */
hr {
    border: none;
    height: 0;
    page-break-after: always;
    margin: 2em 0;
}

/* Print media query for PDF output */
@media print {

    /* Cover image */
    img[src*="cover.png"] {
        width: 100%;
        min-height: 8in !important;
    }

    /* Cartoons in print */
    img[src*="cartoon"] {
        max-width: 50% !important;
        height: auto !important;
        page-break-inside: avoid;
        display: block;
        margin: 1em auto;
    }

    /* Technical diagrams in print */
    img:not([src*="cartoon"]) {
        max-width: 90% !important;
        max-height: 5.5in !important;
        height: auto !important;
        page-break-inside: avoid;
        display: block;
        margin: 1em auto;
    }

    figure {
        page-break-inside: avoid;
    }

    /* Ensure horizontal rules stay as page breaks in print */
    hr {
        border: none;
        height: 0;
        page-break-after: always;
        margin: 0;
    }

    /* Ensure captions are centered in print */
    p img + strong {
        display: block !important;
        text-align: center !important;
        font-style: italic;
        margin-top: 0.5em;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    /* ===========================================
       DIAGRAM-SPECIFIC SIZE ADJUSTMENTS FOR PDF
       =========================================== */

    /* --- Much narrower (30%) --- */
    img[src*="5.3-bottom-half"] {
        max-width: 30% !important;
    }

    /* --- Narrower (70%) --- */
    img[src*="5.3-interrupt-entry"],
    img[src*="5.3-interrupt-return"] {
        max-width: 70% !important;
    }

    /* --- Narrower (73%) --- */
    img[src*="4.2-udp-header"] {
        max-width: 73% !important;
    }

    /* --- Narrower (77%) --- */
    img[src*="1.3-signal-posting"] {
        max-width: 77% !important;
    }

    /* --- Narrower (80%) --- */
    img[src*="4.4-interface-control"] {
        max-width: 80% !important;
    }

    /* --- Narrower (82%) --- */
    img[src*="3.7-specfs-snode"],
    img[src*="4.1-streams-stack"] {
        max-width: 82% !important;
    }

    /* --- Narrower (85%) --- */
    img[src*="4.4-route-resolution"] {
        max-width: 85% !important;
    }

    /* --- Tiny bit narrower (88%) --- */
    img[src*="4.2-socket-queues"],
    img[src*="4.2-tli-connection"],
    img[src*="4.2-socket-flow"] {
        max-width: 88% !important;
    }

    /* --- Slightly wider (94-95%) --- */
    img[src*="3.3-pathname-lookup"] {
        max-width: 94% !important;
    }

    img[src*="2.1-as-map"],
    img[src*="4.1-net-stack-flow"] {
        max-width: 95% !important;
    }

    /* --- Somewhat wider (97%) --- */
    img[src*="1.10-shmat-flow"],
    img[src*="4.3-ifnet-structure"] {
        max-width: 97% !important;
    }

    /* --- Full page width (100%) --- */
    img[src*="2.2-hat-mapping"],
    img[src*="2.2-hat-tlb"],
    img[src*="1.8-msgsnd-flow"],
    img[src*="2.3-page-list"],
    img[src*="2.3-page-hash"],
    img[src*="2.9-swap-management"],
    img[src*="2.9-swap-indirection"],
    img[src*="3.1-ufs-inode"],
    img[src*="3.2-s5fs-inode"],
    img[src*="3.3-nfs-client-arch"],
    img[src*="3.4-dnlc-entry"],
    img[src*="3.4-dnlc-lookup"],
    img[src*="4.2-ip-header"],
    img[src*="4.2-tcp-state-machine"],
    img[src*="5.7-initialization-early"],
    img[src*="5.7-initialization-processes"],
    img[src*="5.7-init-process-creation"],
    img[src*="5.8-callout-flow"],
    img[src*="5.9-dma-bounce-buffer"] {
        max-width: 100% !important;
        max-height: 7.5in !important;
    }

    /* --- Diagrams on their own page (full width) --- */
    img[src*="1.5-pg-detach"],
    img[src*="1.8-msgrcv-flow"],
    img[src*="1.9-semop-flow"],
    img[src*="1.10-shmdt-flow"],
    img[src*="2.1-as-fault"],
    img[src*="2.2-hat-memload"],
    img[src*="2.2-hat-unload"],
    img[src*="2.10-pvn-pageout"],
    img[src*="3.2-s5fs-inode"],
    img[src*="3.4-dnlc-lookup"],
    img[src*="3.7-specfs-open"],
    img[src*="4.3-driver-data-path"],
    img[src*="4.4-route-resolution"],
    img[src*="4.5-rpc-call-flow"],
    img[src*="5.1-boot-sequence"],
    img[src*="5.2-device-switch-dispatch"],
    img[src*="5.8-callout-flow"],
    img[src*="5.10-console-tty-flow"] {
        page-break-before: always;
        max-width: 100% !important;
        max-height: 7.5in !important;
    }

}
