/* PulseCore — full-manuscript / print view.
   Self-contained and light-on-white: this is the document edition, not the
   site. Screen and paper share one stylesheet so what you preview is what
   comes out of the printer. */

:root {
    --ink:      #16181d;
    --ink-soft: #4a4f5a;
    --ink-mute: #767c88;
    --rule:     #d9dce2;
    --accent:   #0d8f8a;
    --accent-2: #c02a52;
    --paper:    #ffffff;
}

* { box-sizing: border-box; }

body.bookprint {
    margin: 0;
    background: #eceef1;
    color: var(--ink);
    font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
    line-height: 1.66;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Screen toolbar ---------- */

.pp-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #16181d;
    color: #e8eaef;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 0.88rem;
}
.pp-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.pp-toolbar a { color: #35e8e0; text-decoration: none; }
.pp-toolbar a:hover { text-decoration: underline; }
.pp-toolbar button {
    padding: 7px 14px;
    font: inherit;
    color: #07080a;
    background: #35e8e0;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

/* ---------- The document ---------- */

.pp-doc {
    max-width: 44em;
    margin: 28px auto 60px;
    padding: 60px 64px;
    background: var(--paper);
    box-shadow: 0 2px 18px rgba(0,0,0,.09);
}

.pp-title-page {
    padding: 60px 0 70px;
    margin-bottom: 40px;
    border-bottom: 2px solid var(--ink);
    text-align: center;
}
.pp-title-page h1 {
    margin: 0 0 16px;
    font-size: 2.9rem;
    line-height: 1.1;
    letter-spacing: -0.015em;
}
.pp-sub { margin: 0 0 26px; font-size: 1.16rem; color: var(--ink-soft); font-style: italic; }
.pp-meta { margin: 0; font-size: 0.86rem; color: var(--ink-mute); letter-spacing: 0.05em; }

.pp-contents { margin-bottom: 56px; }
.pp-contents h2 {
    margin: 0 0 18px;
    font-size: 1.25rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.pp-contents ol { list-style: none; margin: 0; padding: 0; }
.pp-toc-chapter {
    margin: 22px 0 8px;
    font-size: 0.8rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}
.pp-toc-item { padding: 4px 0; padding-left: 14px; }
.pp-toc-item a { color: var(--ink); text-decoration: none; }
.pp-toc-item a:hover { text-decoration: underline; }
.pp-toc-item em { color: var(--ink-mute); font-size: 0.85em; }

.pp-section { margin-bottom: 52px; }
.pp-chapter-label {
    margin: 0 0 6px;
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
}
.pp-section h2 {
    margin: 0 0 12px;
    font-size: 1.72rem;
    line-height: 1.22;
    letter-spacing: -0.01em;
}
.pp-draft {
    font-size: 0.6em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-2);
    vertical-align: middle;
}
.pp-summary {
    margin: 0 0 22px;
    color: var(--ink-soft);
    font-style: italic;
}
.pp-empty { padding: 60px 0; text-align: center; color: var(--ink-mute); }

/* ---------- Prose ---------- */

.pp-body { font-size: 1.04rem; }
.pp-body p { margin: 0 0 18px; }
.pp-body h2 { margin: 34px 0 12px; font-size: 1.32rem; }
.pp-body h3 { margin: 26px 0 10px; font-size: 1.12rem; }
.pp-body h4 { margin: 22px 0 8px; font-size: 1rem; }
.pp-body ul, .pp-body ol { margin: 0 0 18px; padding-left: 24px; }
.pp-body li { margin-bottom: 6px; }
.pp-body a { color: var(--accent); }
.pp-body hr { margin: 32px 0; border: 0; border-top: 1px solid var(--rule); }
.pp-body img { max-width: 100%; height: auto; }

.pp-body blockquote {
    margin: 22px 0;
    padding-left: 18px;
    border-left: 3px solid var(--rule);
    color: var(--ink-soft);
    font-style: italic;
}

.pp-body pre {
    margin: 20px 0;
    padding: 14px 16px;
    background: #f5f6f8;
    border: 1px solid var(--rule);
    border-radius: 5px;
    overflow-x: auto;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.55;
}
.pp-body code {
    padding: 1px 5px;
    background: #f5f6f8;
    border-radius: 4px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.88em;
}
.pp-body pre code { padding: 0; background: none; }

.pp-body table {
    width: 100%;
    margin: 22px 0;
    border-collapse: collapse;
    font-size: 0.94rem;
}
.pp-body th, .pp-body td { padding: 8px 10px; border: 1px solid var(--rule); text-align: left; }
.pp-body th { background: #f5f6f8; }

/* ---------- Site blocks, in document form ---------- */

.pp-body .cx { margin: 24px 0; }
.pp-body .cx-label {
    margin: 0 0 6px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}
.pp-body .cx-note, .pp-body .cx-key,
.pp-body .cx-warning, .pp-body .cx-aside {
    padding: 16px 18px;
    border: 1px solid var(--rule);
    border-left-width: 3px;
    border-radius: 4px;
    background: #fafbfc;
    font-size: 0.97rem;
}
.pp-body .cx-note    { border-left-color: var(--accent); }
.pp-body .cx-note    .cx-label { color: var(--accent); }
.pp-body .cx-key     { border-left-color: #7a4bb8; background: #faf7fd; }
.pp-body .cx-key     .cx-label { color: #7a4bb8; }
.pp-body .cx-warning { border-left-color: var(--accent-2); background: #fdf6f8; }
.pp-body .cx-warning .cx-label { color: var(--accent-2); }
.pp-body .cx-aside   { border-left-color: var(--ink-mute); color: var(--ink-soft); }
.pp-body .cx p:last-child { margin-bottom: 0; }

.pp-body .cx-quote { margin: 30px 0; text-align: center; }
.pp-body .cx-quote blockquote {
    margin: 0; padding: 0; border: 0;
    font-size: 1.24rem; font-style: normal; color: var(--ink);
}
.pp-body .cx-quote figcaption { margin-top: 8px; font-size: 0.85rem; color: var(--ink-mute); }

.pp-body .cx-figure { margin: 26px 0; }
.pp-body .cx-figure img { border: 1px solid var(--rule); }
.pp-body .cx-figure figcaption { margin-top: 8px; font-size: 0.86rem; color: var(--ink-mute); }
.pp-body .cx-figure figcaption p { margin: 0; }

.pp-body .cx-sim {
    padding: 16px 18px;
    border: 1px solid var(--rule);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    background: #f4fbfb;
    font-size: 0.97rem;
}
.pp-body .cx-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.pp-body .cx-chip {
    padding: 2px 8px;
    border: 1px solid var(--rule);
    border-radius: 12px;
    background: #fff;
    font-family: -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    font-size: 0.74rem;
    color: var(--ink-soft);
}
.pp-body .cx-chip b { color: var(--accent); }
.pp-body .cx-sim-go { display: inline-block; margin-top: 8px; font-size: 0.9rem; color: var(--accent); }

.pp-body .cx-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }

/* ---------- Paper ---------- */

@media print {
    @page { margin: 20mm 18mm; }

    body.bookprint { background: #fff; font-size: 11pt; }
    .no-print { display: none !important; }

    .pp-doc {
        max-width: none;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .pp-title-page { padding-top: 0; break-after: page; page-break-after: always; }
    .pp-contents   { break-after: page; page-break-after: always; }

    /* A new chapter starts on a fresh sheet; sections within it flow on. */
    .pp-chapter-start { break-before: page; page-break-before: always; }
    .pp-section { margin-bottom: 30px; }

    /* Never strand a heading at the foot of a page. */
    h1, h2, h3, h4 { break-after: avoid; page-break-after: avoid; }
    p, li, blockquote { orphans: 3; widows: 3; }
    .pp-body .cx, .pp-body pre, .pp-body table, .pp-body figure {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Links are useless on paper unless the address is visible. */
    .pp-body a { color: var(--ink); text-decoration: underline; }
    .pp-body a[href^="/"]::after      { content: " (pulsecore.one" attr(href) ")"; font-size: 0.82em; color: var(--ink-mute); }
    .pp-body a[href^="http"]::after   { content: " (" attr(href) ")"; font-size: 0.82em; color: var(--ink-mute); }
    .pp-toc-item a::after             { content: none; }

    .pp-body .cx-note, .pp-body .cx-key,
    .pp-body .cx-warning, .pp-body .cx-sim { background: #fff; }
}

@media (max-width: 720px) {
    .pp-doc { padding: 34px 22px; margin: 12px 10px 40px; }
    .pp-title-page { padding: 24px 0 34px; }
    .pp-title-page h1 { font-size: 2rem; }
    .pp-body .cx-columns { grid-template-columns: 1fr; }
}

/* The part's number in the printed contents, in a fixed column so the
   titles line up down the page. */
.pp-toc-num {
    display: inline-block;
    min-width: 2.6em;
    font-variant-numeric: tabular-nums;
}

/* References, at the back of the book where a bibliography belongs. */
.pp-refs-list { margin: 0; padding-left: 26px; font-size: 0.92em; line-height: 1.5; }
.pp-refs-list li { margin-bottom: 8px; }
.pp-refs-missing { margin-top: 20px; font-size: 0.86em; font-style: italic; }
/* In print a citation is a page reference, not a link to follow. */
.pp-body a.cite { color: inherit; text-decoration: none; }

/* A display equation must not be split across a page break. */
.pp-body .pc-eq {
    margin: 14px 0;
    padding: 8px 12px;
    border-left: 2px solid #999;
    text-align: center;
    break-inside: avoid;
    page-break-inside: avoid;
}
.pp-body thead th { text-align: left; border-bottom: 1.5px solid #333; font-weight: 600; }

/* Back matter. Set tighter than the body: these are looked up, not read. */
.pp-nt { width: 100%; border-collapse: collapse; font-size: 0.86em; }
.pp-nt th, .pp-nt td { padding: 3px 8px; border-bottom: 0.5pt solid #ccc; text-align: left; vertical-align: top; }
.pp-nt-sym { font-size: 1.15em; white-space: nowrap; }
.pp-gl { margin: 0; font-size: 0.88em; }
.pp-gl dt { margin-top: 9px; font-weight: 600; break-after: avoid; page-break-after: avoid; }
.pp-gl dd { margin: 0 0 0 18px; }
.pp-gl-sym { font-size: 1.1em; }
.pp-gl-formal { display: block; margin-top: 2px; color: #444; }
/* In print a symbol's link is not followable; it reads as the symbol. */
.pp-body a.pc-sym { color: inherit; text-decoration: none; }
