@import url("https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap");

/* The book's boxes, figures and type, after Democratizing Linux and Cracking
   the Systems Programming Interview. The chapters use the same class names:
   img.plate, .covers, .callout, .bee, .lld, .listing, figure and .summary.
   The default theme is Night Owl ("navy", in custom.css); the light theme
   gets the colours of the systems books. */

:root {
    --book-ink: #1d2733;
    --book-steel: #5b6b7c;
    --book-pale: #e9eef3;
    --book-navy: #16324f;
    --book-rust: #d9622b;
    --book-brass: #c89b3c;
    --book-teal: #2f7f86;
    --book-rule: #c9d4de;
    --bee-bg: #fff8e6;
    --bee-edge: #f1d79a;
    --content-max-width: 820px;
}

.navy, .coal, .ayu {
    --book-ink: #d6deeb;
    --book-steel: #9db2c9;
    --book-pale: #0b2942;
    --book-navy: #82aaff;
    --book-teal: #7fdbca;
    --book-rule: #1d3b53;
    --bee-bg: #1d1a10;
    --bee-edge: #5c4a1c;
}

/* Type: a book face for reading, a condensed sans for headings. */
.content main {
    font-family: Charter, "Bitstream Charter", "Iowan Old Style", Georgia, serif;
    font-size: 1.72rem;
    line-height: 1.62;
}

.content h1, .content h2, .content h3, .content h4 {
    font-family: "Avenir Next Condensed", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    color: var(--book-navy);
    letter-spacing: 0.01em;
}

.content h1 { font-size: 2.4em; margin-top: 0.4em; }
.content h2 { border-bottom: 1px solid var(--book-rule); padding-bottom: 0.2em; margin-top: 2em; }

/* Chapter plates and the cover. */
img.plate {
    display: block;
    width: 100%;
    border-radius: 4px;
    margin: 0.5em 0 1em 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

img.cover {
    display: block;
    max-width: 520px;
    width: 100%;
    margin: 1em auto;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

/* "This chapter covers". */
.covers {
    background: var(--book-pale);
    border-left: 5px solid var(--book-rust);
    padding: 0.6em 1.2em 0.2em 1.2em;
    margin: 0 0 1.5em 0;
}

.covers > p:first-child,
.lld > p:first-child {
    font-family: "Avenir Next Condensed", "Helvetica Neue", sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--book-navy);
    margin-bottom: 0.3em;
}

.sidebar {
    border: 1px solid var(--book-rule);
    background: var(--book-pale);
    padding: 0.6em 1.2em;
    margin: 1.4em 0;
    font-size: 0.94em;
}

.content blockquote {
    border-left: 4px solid var(--book-brass);
    background: transparent;
    margin: 1em 0;
    padding: 0.2em 1em;
    font-size: 0.95em;
}

/* NOTE, TIP and WARNING. A bee sits in the top right corner. */
.callout {
    position: relative;
    border-left: 5px solid var(--book-navy);
    background: var(--book-pale);
    padding: 0.5em 5.4em 0.5em 1.1em;
    margin: 1.3em 0;
    font-size: 0.95em;
    border-radius: 0 6px 6px 0;
}
.callout.tip { border-left-color: var(--book-teal); }
.callout.warning { border-left-color: var(--book-rust); }
.callout.note { border-left-color: var(--book-brass); }
.callout > p:first-child strong:first-child {
    font-family: "Avenir Next Condensed", "Helvetica Neue", sans-serif;
    letter-spacing: 0.06em;
}
.callout::after {
    content: "";
    position: absolute;
    right: 0.7em;
    top: 0.6em;
    width: 4em;
    height: 3.2em;
    background: url("../art/bee-cute.svg") no-repeat center / contain;
}
.callout.warning::after { background-image: url("../art/bee-shocked.svg"); }

/* A bee in one of 5 moods beside one fact a reader should keep. */
.bee {
    display: flex;
    align-items: center;
    gap: 1em;
    margin: 1.6em 0;
    padding: 0.5em 1.1em 0.5em 0.9em;
    border: 1px solid var(--bee-edge);
    border-left: 5px solid var(--book-brass);
    border-radius: 6px;
    background: var(--bee-bg);
    font-size: 0.95em;
}
.bee::before {
    content: "";
    flex: 0 0 4.6em;
    height: 3.7em;
    background: no-repeat center / contain;
}
.bee > p { margin: 0.3em 0; }
.bee-happy::before { background-image: url("../art/bee-happy.svg"); }
.bee-cute::before { background-image: url("../art/bee-cute.svg"); }
.bee-shocked::before { background-image: url("../art/bee-shocked.svg"); }
.bee-sleepy::before { background-image: url("../art/bee-sleepy.svg"); }
.bee-angry::before { background-image: url("../art/bee-angry.svg"); }

/* A design box: the types, operations or numbers of one thing. */
.lld {
    border: 1px solid var(--book-rule);
    border-top: 4px solid var(--book-navy);
    background: var(--book-pale);
    padding: 0.6em 1.2em 0.4em 1.2em;
    margin: 1.6em 0;
    font-size: 0.94em;
}
.lld > p:first-child code { text-transform: none; }
.lld table { width: 100%; margin: 0.6em 0; background: transparent; }

/* Listing captions. */
.listing {
    font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    font-size: 0.82em;
    margin: 1.6em 0 0.2em 0;
    padding-bottom: 0.25em;
    border-bottom: 2px solid var(--book-navy);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 1em;
}
.listing a { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.86em; }
.listing a:first-of-type { margin-left: auto; }
.listing b, figcaption b { color: var(--book-rust); margin-right: 0.4em; }

.content pre > code { font-size: 0.78em; line-height: 1.5; }

/* Figures. The diagrams carry their own paper background and rounded corners. */
figure { margin: 1.6em 0; text-align: center; }
figure img { max-width: 100%; }
figure:not(.anim) > img { border-radius: 14px; }
figure > img[src$=".svg"] { cursor: zoom-in; }
.navy figure:not(.anim) > img, .coal figure:not(.anim) > img, .ayu figure:not(.anim) > img {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

figcaption {
    font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    font-size: 0.82em;
    text-align: left;
    border-top: 1px solid var(--book-rule);
    margin-top: 0.5em;
    padding-top: 0.3em;
    color: var(--book-steel);
}

.content table { font-size: 0.9em; }
.content table thead th { background: var(--book-navy); color: #ffffff; }
.navy .content table thead th, .coal .content table thead th, .ayu .content table thead th { color: #011627; }

/* The end-of-chapter summary, with a happy bee beside its heading. */
.summary { border-top: 3px solid var(--book-navy); margin-top: 2em; }
.summary h2::after {
    content: "";
    display: inline-block;
    width: 2.2em;
    height: 1.7em;
    margin-left: 0.5em;
    vertical-align: -0.35em;
    background: url("../art/bee-happy.svg") no-repeat center / contain;
}

/* A diagram opened full screen by theme/figures.js. */
.figure-zoom {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(9, 11, 16, 0.94);
    cursor: zoom-out;
    overflow: auto;
    touch-action: pinch-zoom;
}
.figure-zoom img { max-width: 96vw; max-height: 94vh; border-radius: 10px; background: #fbfaf6; }
.figure-zoom.turned img { transform: rotate(90deg); width: 94vh; max-width: none; max-height: 96vw; }
.figure-zoom::after {
    content: "Tap to close";
    position: fixed;
    right: 12px;
    bottom: 10px;
    color: #a6accd;
    font-size: 1.3rem;
}

/* Animations. An animation's caption says "Animation N" in teal, so a reader
   can tell at a glance that the picture moves. The videos have controls a
   reader can use to take them at their own pace. */
figure.anim { margin: 1.4em 0 2em 0; }
figure.anim img { max-width: 100%; border: 2px solid var(--book-rule); border-radius: 6px; }
figure.anim figcaption b { color: var(--book-teal); }

figure.anim video.motion {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    border: 2px solid var(--book-rule);
    border-radius: 6px;
    cursor: pointer;
    background: #ffffff;
}

.motion-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4em 0.9em;
    margin: 0.5em 0 0.2em 0;
    font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    font-size: 0.8em;
    text-align: left;
}
.motion-group { display: inline-flex; flex-wrap: wrap; gap: 0.3em; }
.motion-bar button {
    font: inherit;
    padding: 0.25em 0.7em;
    border: 1px solid var(--book-rule);
    border-radius: 999px;
    background: var(--book-pale);
    color: var(--book-ink);
    cursor: pointer;
}
.motion-bar button:hover { border-color: var(--book-teal); }
.motion-bar button:focus-visible { outline: 2px solid var(--book-brass); outline-offset: 2px; }
.motion-bar button[aria-pressed="true"],
.motion-bar button[aria-current="step"] {
    border-color: var(--book-teal);
    color: var(--book-teal);
    font-weight: 600;
}
.motion-bar .motion-play { min-width: 6.5em; font-weight: 600; }
.motion-stepwise { color: var(--book-steel); cursor: pointer; }

/* Phones. */
@media (max-width: 720px) {
    .content main { font-size: 1.62rem; line-height: 1.58; }
    .content h1 { font-size: 2em; }
    .content h2 { font-size: 1.45em; }
    .content pre > code { font-size: 0.74em; }
    .listing a { display: block; flex-basis: 100%; margin: 0.2em 0 0 0; overflow-wrap: anywhere; }
    .listing a:first-of-type { margin-left: 0; }
    .lld, .covers, .callout { padding-inline: 0.9em; }
    .bee { gap: 0.7em; padding-inline: 0.7em; }
    .bee::before { flex-basis: 3.6em; height: 2.9em; }
    .callout::after { position: static; display: block; margin: 0 0 0.2em auto; width: 3.4em; height: 2.7em; float: right; }
}

/* A worked example: numbered steps with the numbers of the running example. */
.example {
    border: 1px solid var(--book-rule);
    border-top: 4px solid var(--book-teal);
    background: var(--book-pale);
    padding: 0.6em 1.2em 0.3em 1.2em;
    margin: 1.6em 0;
    font-size: 0.95em;
    border-radius: 0 0 6px 6px;
}
.example > p:first-child {
    font-family: "Avenir Next Condensed", "Helvetica Neue", sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--book-teal);
    margin-bottom: 0.3em;
}

/* A question to check understanding; the answer opens on a click. */
details.check {
    border: 1px dashed var(--book-teal);
    border-radius: 6px;
    padding: 0.5em 1.1em;
    margin: 1.4em 0;
    font-size: 0.95em;
}
details.check > summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--book-navy);
}
details.check > summary::before {
    content: "Check your understanding: ";
    font-family: "Avenir Next Condensed", "Helvetica Neue", sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.85em;
    color: var(--book-teal);
}
details.check[open] > summary { margin-bottom: 0.4em; }

/* Code tabs (theme/tabs.js): 1 panel per language, buttons above the panels. */
.code-tabs {
    margin: 1em 0;
}

.code-tab-bar {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--book-rule);
}

.code-tab-bar button {
    font: inherit;
    font-size: 0.9em;
    padding: 0.35em 1em;
    color: var(--book-steel);
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    margin-bottom: -2px;
}

.code-tab-bar button.active {
    color: var(--book-ink);
    background: var(--book-pale);
    border-color: var(--book-rule);
    border-bottom: 2px solid var(--book-rust);
    font-weight: 600;
}

.code-tab-bar button:focus-visible {
    outline: 2px solid var(--book-teal);
    outline-offset: 1px;
}

.code-tabs > .code-tab > pre:first-child {
    margin-top: 0.5em;
}

/* Without the script, and in print, every panel is shown with its language as a label. */
.code-tabs:not(.ready) > .code-tab::before {
    content: attr(data-lang);
    display: block;
    font-weight: 600;
    color: var(--book-steel);
    margin-top: 0.75em;
}

@media print {
    .code-tab-bar {
        display: none;
    }

    .code-tabs > .code-tab[hidden] {
        display: block !important;
    }

    .code-tabs > .code-tab::before {
        content: attr(data-lang);
        display: block;
        font-weight: 600;
    }
}

/* Paper-style algorithm elements. */
.algo {
    margin: 1.2em 0;
    padding: 0.6em 1em 0.7em;
    border-top: 2px solid var(--book-ink);
    border-bottom: 1px solid var(--book-rule);
    overflow-x: auto;
}

/* Pseudocode is set in Atkinson Hyperlegible, a typeface designed for low-vision and
   dyslexic readers. Procedure names and keywords are bold, and math is upright and slightly
   heavier, so the structure of each line stands out. */
.algo {
    font-family: "Atkinson Hyperlegible", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 1.02em;
}

.algo > .algo-name {
    margin: 0 0 0.4em;
    font-variant: small-caps;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.algo b.kw {
    font-weight: 700;
}

.algo .sc {
    font-weight: 700;
}

.algo .MathJax,
.algo mjx-container {
    -webkit-text-stroke: 0.35px currentColor;
}

.algo > ol {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: algo-line;
}

.algo > ol > li {
    counter-increment: algo-line;
    position: relative;
    padding-left: calc(2.4em + var(--d, 0) * 1.6em);
    line-height: 1.6;
    white-space: nowrap;
}

.algo > ol > li.gap {
    margin-top: 0.9em;
}

/* The number is an inline box on the same baseline as the text of its line, so the two stay
   aligned whatever the line contains. It sits in the left padding of the line. */
.algo > ol > li::before {
    content: counter(algo-line);
    display: inline-block;
    width: 1.6em;
    margin-left: calc(-2.4em - var(--d, 0) * 1.6em);
    margin-right: calc(0.8em + var(--d, 0) * 1.6em);
    text-align: right;
    color: var(--book-steel);
    font-variant-numeric: tabular-nums;
}

.algo .sc {
    font-variant: small-caps;
}

.algo .c {
    float: right;
    margin-left: 2em;
    color: var(--book-steel);
    font-style: italic;
}

.definition,
.theorem,
.key-observation,
.rule-box {
    margin: 1.2em 0;
    padding: 0.7em 1em;
    border-left: 4px solid var(--book-navy);
    background: var(--book-pale);
}

.key-observation {
    border-left-color: var(--book-brass);
}

.rule-box {
    border-left-color: var(--book-rust);
}

.definition > p:first-child::first-line,
.theorem > p:first-child::first-line {
    font-weight: normal;
}

.box-label {
    font-weight: 700;
    font-variant: small-caps;
    letter-spacing: 0.04em;
    margin-right: 0.5em;
}

.proof > p:last-child::after {
    content: " \220E";
}

.exercises {
    margin: 1.4em 0;
    padding: 0.5em 1em;
    border-top: 1px solid var(--book-rule);
    border-bottom: 1px solid var(--book-rule);
    font-size: 0.95em;
}

.exercises > p:first-child {
    font-variant: small-caps;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 0.3em;
}
