/* MinecraftDocs — site overrides on top of mdBook's theme (book.toml: additional-css).
 *
 * Two problems this fixes, both found in pass 2's read of the live site:
 *  - mdBook's reading column is 750px, so any table with three or four
 *    columns of identifiers scrolled sideways even on a wide screen. Prose
 *    keeps a readable measure; tables, diagrams and figures may use the
 *    whole (wider) column.
 *  - Identifiers in table cells never wrapped, which is what pushed the
 *    tables over the edge in the first place.
 */

:root {
    /* The main column. Prose is capped separately below. */
    --content-max-width: 1100px;
    --prose-max-width: 800px;
}

/* mdBook floats the previous/next chapter chevrons in the page gutters and only
 * hides them, with the sidebar open, below 1380px. The wider column above leaves
 * no gutter for them until about 1640px, so on a 1440px laptop the left chevron
 * is painted twelve pixels inside the prose and sits on top of the words. Found
 * by pass 7, session A, looking at a rendered page; the fix is mdBook's own rule
 * with the breakpoint moved to where the column actually clears them. */
@media only screen and (max-width: 1660px) {
    #mdbook-sidebar-toggle-anchor:checked ~ .page-wrapper .nav-wide-wrapper { display: none; }
    #mdbook-sidebar-toggle-anchor:checked ~ .page-wrapper .nav-wrapper { display: block; }
}

/* Prose keeps a readable measure; everything is left-aligned inside the
 * (centred) main column so wide blocks extend to the right, not both ways. */
.content main > :not(.table-wrapper):not(pre):not(figure):not(.wide) {
    max-width: var(--prose-max-width);
}

/* Tables: use the room, wrap the cells, and stop padding each cell 20px a side. */
.content .table-wrapper {
    max-width: 100%;
}
.content table {
    margin: 0;
    max-width: 100%;
}
.content table td,
.content table th {
    padding: 3px 10px;
    vertical-align: top;
    white-space: normal;
}
.content table code {
    white-space: normal;
    overflow-wrap: anywhere;
}
/* Numeric columns stay right-aligned as the generators emit them. */
.content table td[align="right"],
.content table th[align="right"] {
    white-space: nowrap;
}

/* Diagrams: mermaid scales an SVG to its container, so a nine-lane sequence
 * diagram in a 750px column was unreadable. Let it have the full column. */
.content pre.mermaid {
    max-width: 100%;
    background: transparent;
    overflow-x: auto;
}

/* Click to enlarge (diagram-zoom.js): the overlay sits on the page's own
 * background so mermaid's light/dark palette still reads. */
.content pre.mermaid svg,
.content figure.map svg {
    cursor: zoom-in;
}
.content pre.mermaid::after {
    content: "click to enlarge";
    display: block;
    text-align: right;
    font-size: 0.75em;
    color: var(--icons);
    font-family: inherit;
}
.diagram-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.diagram-lightbox-panel {
    box-sizing: border-box;
    width: 96vw;
    max-height: 96vh;
    overflow: auto;
    padding: 1em;
    border-radius: 6px;
    background: var(--bg);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}
.diagram-lightbox-panel svg {
    display: block;
    width: 100%;
    height: auto;
    max-width: none !important;
    max-height: 90vh;
}

/* Generated figures (inline SVG from tools/, see pass 3): full column,
 * text in the theme's foreground colour. */
.content figure.map,
.content .wide {
    max-width: 100%;
    margin: 1em 0;
}
.content figure.map svg {
    max-width: 100%;
    height: auto;
    color: var(--fg);
}

/* The atlas's generated figures (tools/map_source.py → src/generated/*.svg,
 * pass-3 session B). The SVG carries classes only; every colour lives here so
 * the five themes and the zoom overlay all read. Text is currentColor. */
:root {
    --map-shared: #3b7dd8;
    --map-client: #e0862e;
    --map-lib: #8f8f8f;
}
.coal, .navy, .ayu {
    --map-shared: #6aa6ee;
    --map-client: #f0a24a;
    --map-lib: #a0a0a0;
}
svg.mapfig {
    font-family: inherit;
    color: var(--fg);
    display: block;
}
svg.mapfig text {
    fill: currentColor;
}
svg.mapfig .muted {
    opacity: 0.65;
}
svg.mapfig .fold {
    opacity: 0.65;
    font-style: italic;
}
svg.mapfig rect.shared { fill: var(--map-shared); fill-opacity: 0.55; }
svg.mapfig rect.client { fill: var(--map-client); fill-opacity: 0.55; }
svg.mapfig rect.lib    { fill: var(--map-lib);    fill-opacity: 0.55; }
svg.mapfig rect.skip   { fill: url(#mapfig-hatch); }
svg.mapfig .hatch      { stroke: currentColor; stroke-width: 1; opacity: 0.35; }
svg.mapfig g.cell rect.shared,
svg.mapfig g.cell rect.client {
    stroke: var(--bg);
    stroke-width: 1;
}
svg.mapfig rect.group {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}
svg.mapfig .edge {
    fill: none;
    stroke: currentColor;
    stroke-width: 1;
    opacity: 0.45;
}
.content figure.map {
    max-width: 100%;
    margin: 1.5em 0;
}
.content figure.map figcaption {
    font-size: 0.85em;
    color: var(--icons);
    margin-top: 0.4em;
}

/* The licence and disclaimer footer (site-footer.js): quiet, and out of the
   way of the prose it follows. */
.content footer.site-footer {
    max-width: 800px;
    margin: 3.5em auto 0;
    padding-top: 1.2em;
    border-top: 1px solid var(--table-border-color, currentColor);
    font-size: 0.8em;
    color: var(--icons);
}
.content footer.site-footer p {
    margin: 0.4em 0;
}

/* ---------------------------------------------------------------------------
 * Figures (pass 7, session A). The whole visual grammar of a diagram lives in
 * this file and in mermaid-init.js; a page carries no `%%{init}%%`, no
 * `classDef`, no `style` and no `linkStyle`.
 *
 * A node says which side of the wire it lives on with one of five class words
 * and no classDef — mermaid puts the class on the node's <g> ("node default
 * server"), so the colour is a rule here and follows the theme, the way the
 * atlas SVGs already do:
 *
 *     A["ServerLevel.tick"]:::server      B["ClientLevel.tick"]:::client
 *     N["Netty event loop"]:::netty       W["Worker-Main-n"]:::worker
 *     D[("region file")]:::disk           (a state diagram: `class Idle server`)
 *
 * The same five words are a sequence diagram's `box` labels and the lane key's
 * word lanes, so a thread is called the same thing in every kind of figure.
 * -------------------------------------------------------------------------*/
:root {
    --fig-server: #dfe9f7;   --fig-server-line: #6f8fc4;
    --fig-client: #fbe9d7;   --fig-client-line: #d08a45;
    --fig-netty:  #e6f2e2;   --fig-netty-line:  #6a9e5b;
    --fig-worker: #efe6f5;   --fig-worker-line: #9a6fb8;
    --fig-disk:   #eeeeee;   --fig-disk-line:   #8f8f8f;
}
.coal, .navy, .ayu {
    --fig-server: #26304a;   --fig-server-line: #6f8fc4;
    --fig-client: #4a3624;   --fig-client-line: #d08a45;
    --fig-netty:  #28402a;   --fig-netty-line:  #6a9e5b;
    --fig-worker: #3b2d47;   --fig-worker-line: #9a6fb8;
    --fig-disk:   #30343a;   --fig-disk-line:   #8f8f8f;
}
.content pre.mermaid g.node.server > *:not(.label), .content pre.mermaid g.node.server > g > rect { fill: var(--fig-server) !important; stroke: var(--fig-server-line) !important; }
.content pre.mermaid g.node.client > *:not(.label), .content pre.mermaid g.node.client > g > rect { fill: var(--fig-client) !important; stroke: var(--fig-client-line) !important; }
.content pre.mermaid g.node.netty  > *:not(.label), .content pre.mermaid g.node.netty  > g > rect { fill: var(--fig-netty)  !important; stroke: var(--fig-netty-line)  !important; }
.content pre.mermaid g.node.worker > *:not(.label), .content pre.mermaid g.node.worker > g > rect { fill: var(--fig-worker) !important; stroke: var(--fig-worker-line) !important; }
.content pre.mermaid g.node.disk   > *:not(.label), .content pre.mermaid g.node.disk   > g > rect { fill: var(--fig-disk)   !important; stroke: var(--fig-disk-line)   !important; }
.content pre.mermaid g.cluster.server > rect { fill: var(--fig-server) !important; stroke: var(--fig-server-line) !important; fill-opacity: 0.35; }
.content pre.mermaid g.cluster.client > rect { fill: var(--fig-client) !important; stroke: var(--fig-client-line) !important; fill-opacity: 0.35; }

/* The caption is the italic paragraph directly after the figure — markdown, so
 * verify_names.py reads its names and llms-full.txt carries it. The counter
 * numbers the figures of a page; a figure that has no caption yet looks exactly
 * as it did before it got one. */
.content main { counter-reset: figure; }
.content pre.mermaid, .content figure.map { counter-increment: figure; }
.content pre.mermaid + p:has(> em:only-child),
.content figure.map + p:has(> em:only-child) {
    font-size: 0.9em;
    color: var(--icons);
    margin-top: -0.4em;
    padding-left: 0.6em;
    border-left: 3px solid var(--table-border-color, #ddd);
    max-width: 800px;
}
.content pre.mermaid + p:has(> em:only-child) > em,
.content figure.map + p:has(> em:only-child) > em { font-style: normal; }
.content pre.mermaid + p:has(> em:only-child)::before,
.content figure.map + p:has(> em:only-child)::before {
    content: "Figure " counter(figure) ". ";
    font-weight: 600;
}
