@font-face {
    font-family: 'ImprintMTShadow';
    src: url('/fonts/imprint-mt-shadow.ttf') format('truetype');
    font-display: block;
}

@font-face {
    font-family: 'MonotypeModern';
    src: url('/fonts/MonotypeModern.otf') format('opentype');
    font-display: block;
}

/* The layout sets every space as plain glue. Spaces come from their own face so the browser
   cannot kern against them (the font shortens the space after , . : ; and before A T V W Y). */
@font-face {
    font-family: 'MonotypeModern';
    src: url('/fonts/MonotypeModern.otf') format('opentype');
    font-display: block;
    unicode-range: U+0020, U+00A0;
}

html, body {
    margin: 0;
    background: var(--color-card-background);
    color: var(--color-text-primary);
}

body {
    font-family: 'MonotypeModern', Georgia, serif;
    font-kerning: normal;
    font-variant-ligatures: common-ligatures;
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--color-selection); }
/* a page that shows a drawing carrying the spot colour selects its text in that colour */
html:has([data-spot]) ::selection { background: var(--color-spot-selection); }

.doc {
    position: relative;
    margin: 0 auto;
    overflow-x: clip;
}

.doc > *, .note > * { position: absolute; }

.blk {
    margin: 0;
    padding: 0;
    font-weight: normal;
    text-align: left;
}

.ln {
    position: absolute;
    display: block;
    white-space: nowrap;
}

.ln.just { text-align: justify; text-align-last: justify; }

.mk { position: absolute; top: 0; width: 0; height: 0; }

.r.sup { position: relative; }
.r.code {
    font-family: 'Courier New', Courier, monospace;
    background: var(--code-background);
}

.u-dotted { text-decoration: underline dotted; text-underline-offset: 2px; }

.lnk { color: inherit; text-decoration: none; }
.lnk-card, .lnk-jump { cursor: pointer; }
.lnk:hover { color: var(--color-link-hover); }

.atom { display: inline-block; position: relative; height: 0; vertical-align: baseline; }
.atom-inner { position: absolute; left: 0; white-space: nowrap; }
.atom-widget > * { position: absolute; left: 0; top: -1.1em; }

/* A word split across lines is kept whole in the text of its first line (`.tl` holds the rest, at no size) so it can be
   found and copied; the hyphen and the piece on the next line are drawn, not text (the second `content` gives them
   empty alternative text where that is supported). `.sp` is the space or paragraph break after a line: text for
   copying, set outside the line. */
.brk::after, .ct[data-hy]::after, .r[data-hy]::after { content: '-'; content: '-' / ''; white-space: pre; }
.ct::before { content: attr(data-t); content: attr(data-t) / ''; }
.tl { font-size: 0; }
.sp { position: absolute; left: 100%; top: 0; white-space: pre; }

.dropcap { position: absolute; white-space: nowrap; user-select: none; }
.bullet { position: absolute; text-align: right; white-space: nowrap; }

.rule { position: absolute; background: var(--color-border); }
.qrule { position: absolute; background: var(--color-border); }

.codeblock {
    position: absolute;
    margin: 0;
    box-sizing: border-box;
    background: var(--code-background);
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
}
.codeblock code { font: inherit; background: none; }

.mathblock { position: absolute; overflow-x: auto; overflow-y: hidden; text-align: center; }
.mathblock .katex-display { margin: 0; }

.doc .katex { font-size: 1.08em; }

.obj { position: absolute; margin: 0; }
.obj.under { z-index: 0; }
.obj .obj-body > img { display: block; }
.caption { position: absolute; color: var(--color-text-secondary); }

.obj-body.viz-container { width: 100% !important; height: 100% !important; }

.toc {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid var(--color-border);
    background: var(--color-card-background);
    pointer-events: none;
}
.toc-hit { position: absolute; display: block; pointer-events: auto; cursor: pointer; }
/* contents entries are a little quiet until pointed at */
.toc-text { opacity: 0.8; transition: opacity 0.12s ease; }
.toc-text.hot { opacity: 1; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

aside.note { position: absolute; color: var(--color-text-primary); }
aside.note a { color: inherit; }

.heading-link {
    position: absolute;
    left: -1.2em;
    top: 0;
    opacity: 0;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: min(0.8em, 18px);
    font-weight: normal;
    transition: opacity 0.15s ease;
}
.blk-heading:hover .heading-link, .heading-link:focus { opacity: 0.6; }
.heading-link:hover { opacity: 1; }

.mk.on::after { background: var(--color-selection); }
/* hovering a marker marks its note with a thin rule, not a fill */
aside.note.on::before { content: ''; position: absolute; top: 0; bottom: 0; left: -8px; width: 2px; background: var(--color-text-primary); }

.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--color-selection); } to { background: transparent; } }

/* the line across the top: the name of the site, then what can be done with the page */
.chrome {
    position: absolute;
    top: 14px;
    left: var(--col-x, 16px);
    width: var(--col-w, calc(100% - 32px));
    z-index: 100;
    font: 14px/24px 'MonotypeModern', Georgia, serif;
    color: var(--color-text-secondary);
}
.chrome .bar { display: flex; align-items: baseline; gap: 18px; }
.chrome .space { flex: 1; }
.chrome a, .chrome button {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}
.chrome a:hover, .chrome button:hover, .chrome a:focus-visible, .chrome button:focus-visible, .chrome button.on { color: var(--color-text-primary); }
.chrome button.on { text-decoration: underline; text-underline-offset: 5px; }
.chrome .name { color: var(--color-text-primary); font-size: 17px; }
.chrome .status { font-size: 12px; }
.chrome .panel {
    position: absolute;
    top: 100%;
    margin-top: 10px;
    box-sizing: border-box;
    padding: 14px 16px;
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
}
.chrome .panel[hidden] { display: none; }
.chrome .panel.settings { right: 0; min-width: 220px; display: flex; flex-direction: column; gap: 12px; }
.chrome .panel.settings[hidden] { display: none; }
.chrome .panel label { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.chrome .panel label[hidden] { display: none; }
.chrome input[type=range] { width: 110px; accent-color: var(--color-text-primary); }
.chrome .panel.index { left: 0; right: 0; }
.chrome .index input {
    width: 100%;
    box-sizing: border-box;
    padding: 2px 0 8px;
    border: 0;
    border-bottom: 1px solid var(--color-border);
    background: none;
    font: inherit;
    color: var(--color-text-primary);
    outline: none;
}
.chrome .index ul { margin: 6px 0 0; padding: 0; list-style: none; max-height: min(60vh, 420px); overflow-y: auto; }
.chrome .index li { display: flex; justify-content: space-between; gap: 16px; padding: 2px 6px; margin: 0 -6px; cursor: pointer; }
.chrome .index li[aria-selected=true] { background: var(--color-selection); }
.chrome .index li .when { color: var(--color-text-secondary); font-size: 12px; white-space: nowrap; }
.chrome .index li.none { color: var(--color-text-secondary); cursor: default; }
@media print { .chrome { display: none; } }


.w-field {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    font: inherit;
    font-size: 0.8em;
    color: var(--color-text-primary);
    background: var(--code-background);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    resize: none;
}
.w-button, .w-toggle {
    font: inherit;
    font-size: 0.8em;
    padding: 4px 14px;
    color: var(--color-text-primary);
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: pointer;
}
.obj-widget .obj-body { display: flex; }

/* editing */
.editor-overlay { position: absolute; left: 0; top: 0; width: 100%; height: 0; z-index: 60; pointer-events: none; }
.editor-box {
    position: absolute;
    box-sizing: border-box;
    color: var(--color-text-primary);
    pointer-events: none;
    hyphens: manual;
}
.editor-box .ex { display: block; pointer-events: none; }
.editor-mirror, .editor-input {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    font: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    text-align: inherit;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
    tab-size: 4;
}
.editor-mirror { position: absolute; top: 0; left: 0; width: 100%; pointer-events: none; color: var(--color-text-primary); }
.ed-syntax { color: var(--color-text-secondary); opacity: 0.7; }
.editor-input {
    position: relative;
    pointer-events: auto;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: var(--color-text-primary);
    -webkit-user-modify: read-write-plaintext-only;
}
.editor-outline { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.editor-outline path { fill: none; stroke: var(--color-text-primary); stroke-width: 1.5; stroke-linejoin: round; opacity: 0.85; }
.editor-input::selection { background: var(--color-selection); color: transparent; }
.editor-slot { visibility: hidden; }


/* article variables and figures */
.var {
    display: inline-block;
    text-align: center;
    text-align-last: center;
    color: var(--color-text-primary);
    border-bottom: 1.5px dotted currentColor;
    cursor: ew-resize;
    touch-action: none;
    user-select: none;
    font-variant-numeric: tabular-nums;
    vertical-align: baseline;
}
.var-ro { cursor: default; border-bottom-style: solid; border-bottom-width: 1px; }
#root.scrubbing { cursor: ew-resize; }
.var:focus-visible { outline: 2px solid var(--color-text-primary); outline-offset: 2px; background: var(--color-selection); }
.fig text { font-family: 'MonotypeModern', Georgia, serif; }
[data-figure] { position: relative; }

.drawing svg { display: block; overflow: visible; }
.drawing { color: var(--color-text-primary); }

.obj img[data-full] { cursor: zoom-in; }
body.editing .obj img[data-full] { cursor: text; }

/* contents rail: ticks in the margin; the titles slide out beside them and fade back, as part of the page */
.toc-rail {
    position: fixed;
    left: 8px;
    top: 84px;
    z-index: 40;
    max-height: calc(100vh - 120px);
    box-sizing: border-box;
    padding: 8px 28px 10px 4px;
    font: 13px/1.35 Georgia, serif;
    color: var(--color-text-secondary);
    opacity: var(--p, 0);
    transform: translateX(calc((1 - var(--p, 0)) * -18px));
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
/* where the titles open over the text, the page colour fades in behind them so they stay readable */
.toc-rail::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(to right, var(--color-card-background) 68%, transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.toc-rail.live { visibility: visible; pointer-events: auto; }
.toc-rail[hidden] { display: none; }
.toc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.toc-item a { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.toc-tick { display: block; height: 2px; width: 14px; background: var(--color-border); transition: width 0.25s ease, background 0.25s ease; flex: none; }
.toc-l3 .toc-tick { width: 8px; margin-left: 6px; }
.toc-item.current .toc-tick { width: 22px; background: var(--color-text-primary); }
.toc-label {
    display: block;
    max-width: 0;
    opacity: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transform: translateX(-6px);
    transition: max-width 0.32s ease, opacity 0.25s ease, transform 0.32s ease;
}
.toc-l3 .toc-label { padding-left: 10px; }
.toc-item a:hover .toc-label { color: var(--color-text-primary); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.toc-item.current .toc-label { color: var(--color-text-primary); }
.toc-controls { display: flex; justify-content: space-between; align-items: baseline; gap: 18px; height: 0; margin-bottom: 0; opacity: 0; overflow: hidden; transition: height 0.25s ease, margin 0.25s ease, opacity 0.25s ease; }
.toc-controls button, .toc-handle { border: none; background: none; color: inherit; cursor: pointer; font: inherit; padding: 2px 4px; }
.toc-controls .toc-pin { letter-spacing: 0.04em; text-transform: uppercase; font-size: 11px; }
.toc-controls button:hover, .toc-handle:hover { color: var(--color-text-primary); }
.toc-handle {
    position: fixed;
    left: 10px;
    top: 84px;
    z-index: 45;
    padding: 2px 6px;
    border: none;
    background: none;
    color: var(--color-text-secondary);
    font: 20px/1 Georgia, serif;
    cursor: pointer;
    transition: opacity 0.2s ease;
}
.toc-handle[hidden] { display: none; }
.toc-handle:hover { opacity: 1 !important; color: var(--color-text-primary); }
.toc-handle.narrow { top: 12px; left: 12px; z-index: 60; }

.toc-rail[data-mode="ticks"]:hover, .toc-rail[data-mode="ticks"]:focus-within, .toc-rail[data-mode="open"] { overflow-y: auto; }
.toc-rail[data-mode="ticks"]:hover::before, .toc-rail[data-mode="ticks"]:focus-within::before, .toc-rail[data-mode="open"]::before { opacity: 1; }
.toc-rail[data-mode="ticks"]:hover .toc-label, .toc-rail[data-mode="ticks"]:focus-within .toc-label, .toc-rail[data-mode="open"] .toc-label { max-width: 250px; opacity: 1; transform: none; }
.toc-rail[data-mode="ticks"]:hover .toc-controls, .toc-rail[data-mode="ticks"]:focus-within .toc-controls,
.toc-rail[data-mode="open"] .toc-controls { height: 24px; margin-bottom: 6px; opacity: 1; }
.toc-rail[data-mode="hidden"] .toc-list, .toc-rail[data-mode="hidden"] .toc-controls { display: none; }
.toc-rail[data-mode="hidden"], .toc-rail[data-mode="button"] { padding: 0; }
.toc-rail[data-mode="button"] .toc-list, .toc-rail[data-mode="button"] .toc-controls { display: none; }

/* small screens: the titles come in as a sheet of page along the left edge, and go back out the same way */
.toc-rail.narrow {
    top: 0;
    left: 0;
    bottom: 0;
    max-height: none;
    width: min(84vw, 340px);
    padding: 56px 22px 24px;
    background: var(--color-card-background);
    overflow-y: auto;
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    transform: translateX(-102%);
    transition: transform 0.32s ease;
}
.toc-rail.narrow::before { display: none; }
.toc-rail.narrow[data-mode="open"] { transform: none; pointer-events: auto; }
.toc-rail.narrow[data-mode="open"] .toc-list { display: flex; }
.toc-rail.narrow[data-mode="open"] .toc-label { max-width: none; opacity: 1; transform: none; white-space: normal; }
.toc-rail.narrow[data-mode="open"] .toc-controls { display: flex; height: 24px; margin-bottom: 8px; opacity: 1; }

/* backstage */
.vault-backdrop { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.35); }
.vault-dialog {
    width: min(440px, 100%);
    max-height: 86vh;
    overflow: auto;
    padding: 22px 24px;
    color: var(--color-text-primary);
    background: var(--color-card-background);
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
    font: 15px/1.5 Georgia, serif;
}
.vault-title { margin-bottom: 14px; font-size: 18px; }
.vault-form { display: flex; flex-direction: column; gap: 12px; }
.vault-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--color-text-secondary); }
.vault-field input {
    padding: 8px 10px;
    font: 15px Georgia, serif;
    color: var(--color-text-primary);
    background: var(--code-background);
    border: 1px solid var(--color-border);
    border-radius: 3px;
}
.vault-check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.vault-note { margin: 0; font-size: 13px; color: var(--color-text-secondary); }
.vault-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.vault-button {
    padding: 6px 14px;
    font: 14px Georgia, serif;
    color: var(--color-text-primary);
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: pointer;
}
.vault-button.primary { color: var(--color-card-background); background: var(--color-text-primary); border-color: var(--color-text-primary); }
.vault-button:disabled, .vault-field input:disabled { opacity: 0.55; cursor: default; }
.vault-status { min-height: 1.4em; margin: 0; font-size: 13px; color: var(--color-text-secondary); }
.vault-status.error { font-style: italic; color: var(--color-text-primary); }
.vault-list { display: flex; flex-direction: column; margin: 0 -6px 12px; }
.vault-row { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 4px; }
.vault-row:hover { background: var(--color-selection); }
.vault-open { display: flex; flex: 1; flex-direction: column; min-width: 0; color: inherit; text-decoration: none; }
.vault-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vault-meta { font-size: 12px; color: var(--color-text-secondary); }
.vault-mini {
    padding: 2px 8px;
    font: 12px Georgia, serif;
    color: var(--color-text-secondary);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: pointer;
}
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 210;
    max-width: min(90vw, 460px);
    padding: 10px 16px;
    font: 14px Georgia, serif;
    color: var(--color-card-background);
    background: var(--color-text-primary);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* capped notes */
aside.note.clipped { overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.note-more {
    position: absolute;
    right: 0;
    bottom: 0;
    padding: 0 4px;
    font: 11px Georgia, serif;
    color: var(--color-text-secondary);
    background: var(--color-card-background);
    border: none;
    cursor: pointer;
}
aside.note.clipped .note-more { -webkit-mask-image: none; }

/* sketches */
.sketch-body svg { overflow: visible; color: var(--color-text-primary); }
body.editing .obj[data-sketch] { outline: 1px dashed var(--color-border); outline-offset: 4px; cursor: crosshair; }
.sketch-pad { position: absolute; inset: 0; z-index: 70; background: var(--color-card-background); outline: 1px solid var(--color-border); cursor: crosshair; }
.sketch-pad svg { width: 100%; height: 100%; display: block; color: var(--color-text-primary); }
.sketch-bar { position: absolute; top: -36px; right: 0; display: flex; gap: 4px; }
.sketch-bar button {
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    font: 14px Georgia, serif;
    color: var(--color-text-primary);
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: pointer;
}
.sketch-bar button.on { color: var(--color-card-background); background: var(--color-text-primary); border-color: var(--color-text-primary); }

/* insert menu */
.insert-plus {
    position: absolute;
    z-index: 80;
    width: 24px;
    height: 24px;
    padding: 0;
    font: 16px/22px Georgia, serif;
    color: var(--color-text-secondary);
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    cursor: pointer;
}
.insert-menu {
    position: absolute;
    z-index: 81;
    display: flex;
    flex-direction: column;
    min-width: 190px;
    padding: 4px;
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
}
.insert-menu button {
    padding: 5px 10px;
    font: 14px Georgia, serif;
    text-align: left;
    color: var(--color-text-primary);
    background: none;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}
.insert-menu button:hover { background: var(--color-selection); }

/* figure tools */
.figure-bar {
    position: absolute;
    z-index: 82;
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.figure-bar button { width: 28px; height: 26px; padding: 0; font-size: 15px; color: var(--color-text-primary); background: none; border: none; border-radius: 3px; cursor: pointer; }
.figure-bar button:hover { background: var(--color-selection); }
.figure-bar .sep { width: 1px; margin: 3px 3px; background: var(--color-border); }
.figure-handle { position: absolute; z-index: 82; width: 18px; height: 18px; background: var(--color-text-primary); border: 2px solid var(--color-card-background); border-radius: 50%; cursor: nwse-resize; touch-action: none; }

/* scatter figure */
.scatter-piece { cursor: grab; touch-action: none; user-select: none; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25); }
.scatter-piece.held { cursor: grabbing; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); }

.figure-bar[hidden], .figure-handle[hidden], .insert-plus[hidden], .insert-menu[hidden] { display: none; }


.toc-hit { z-index: 5; }

/* reading stats and lightbox */
.reading-stats { position: fixed; right: 16px; bottom: 12px; z-index: 20; font: 11px Georgia, serif; color: var(--color-text-secondary); pointer-events: none; }
.reading-stats[hidden] { display: none; }
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    background: rgba(10, 10, 10, 0.92);
    cursor: zoom-out;
    animation: lightbox-in 0.18s ease;
}
.lightbox img { max-width: 94vw; max-height: 86vh; object-fit: contain; cursor: pointer; }
.lightbox-caption { color: #ddd; font: 15px Georgia, serif; text-align: center; min-height: 1.2em; }
@keyframes lightbox-in { from { opacity: 0; } to { opacity: 1; } }
@media print { .reading-stats, .lightbox { display: none; } }

.reading-stats { padding: 1px 6px; background: color-mix(in srgb, var(--color-card-background) 85%, transparent); border-radius: 3px; }

/* margin resize handles */
.margin-handle { position: fixed; top: 0; bottom: 0; width: 10px; z-index: 30; cursor: col-resize; touch-action: none; }
.margin-handle[hidden] { display: none; }
.margin-handle::after { content: ''; position: absolute; top: 0; bottom: 0; width: 2px; background: transparent; transition: background 0.15s ease; }
.margin-handle-left::after { right: 0; }
.margin-handle-right::after { left: 0; }
.margin-handle:hover::after, .margin-handle.dragging::after { background: var(--color-border); }
body.resizing-margins { user-select: none; cursor: col-resize; }
@media print { .margin-handle { display: none; } }

/* moving things */
.move-grip {
    position: absolute;
    z-index: 83;
    width: 22px;
    height: 20px;
    font: 15px/20px Georgia, serif;
    text-align: center;
    color: var(--color-text-secondary);
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.move-grip[hidden] { display: none; }
.figure-bar button.grip { cursor: grab; touch-action: none; }
aside.note.moving, .obj.moving { opacity: 0.75; outline: 1px dashed var(--color-text-primary); outline-offset: 4px; z-index: 90; }

/* figure padding */
.pad-ring {
    position: absolute;
    z-index: 70;
    box-sizing: border-box;
    border: 1px dashed var(--color-text-primary);
    opacity: 0.7;
    pointer-events: none;
}
.pad-ring[hidden] { display: none; }
@media print { .pad-ring { display: none; } }

/* A text block is as big as its lines, not the rectangle around them. */
.blk { pointer-events: none; }
.blk .ln, .blk .heading-link { pointer-events: auto; }

/* the outline shown while editing */
.hover-outline { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 50; }
.hover-outline[hidden] { display: none; }
.hover-outline path {
    fill: color-mix(in srgb, var(--color-selection) 35%, transparent);
    stroke: var(--color-text-secondary);
    stroke-width: 1;
    stroke-dasharray: 3 3;
    stroke-linejoin: round;
}
@media print { .hover-outline { display: none; } }

/* a selected figure */
.fig-frame { position: absolute; z-index: 66; box-sizing: border-box; border: 1.5px solid var(--color-text-primary); pointer-events: none; }
.fig-frame[hidden] { display: none; }

.inspector {
    position: fixed;
    top: 76px;
    right: 16px;
    z-index: 90;
    width: 272px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    padding: 12px 14px 14px;
    color: var(--color-text-primary);
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    font: 13px/1.35 Georgia, serif;
}
.inspector[hidden] { display: none; }
.insp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.insp-title { flex: 1; font-size: 15px; }
.insp-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.insp-label { flex: 0 0 82px; color: var(--color-text-secondary); }
.insp-choices { display: flex; flex-wrap: wrap; gap: 3px; flex: 1; }
.insp-choices button, .insp-small {
    padding: 2px 8px;
    font: 12px Georgia, serif;
    color: var(--color-text-primary);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: pointer;
}
.insp-choices button.on { color: var(--color-card-background); background: var(--color-text-primary); border-color: var(--color-text-primary); }
.inspector input[type=range] { flex: 1; min-width: 0; accent-color: var(--color-text-primary); }
.insp-value { min-width: 28px; text-align: right; color: var(--color-text-secondary); }
.inspector input[type=number], .insp-text, .inspector select {
    min-width: 0;
    padding: 3px 6px;
    font: 13px Georgia, serif;
    color: var(--color-text-primary);
    background: var(--code-background);
    border: 1px solid var(--color-border);
    border-radius: 3px;
}
.inspector input[type=number] { width: 62px; }
.insp-text { flex: 1; }
.insp-group { display: contents; }
@media (max-width: 700px) {
    .inspector { top: auto; bottom: 0; right: 0; left: 0; width: auto; max-height: 45vh; border-radius: 10px 10px 0 0; }
}
@media print { .fig-frame, .inspector { display: none; } }

/* Whatever else happens, none of the editor's overlays show outside editing. */
body:not(.editing) :is(.hover-outline, .move-grip, .insert-plus, .insert-menu, .fig-frame, .figure-bar, .figure-handle, .pad-ring, .inspector, .snap-guides, .editor-overlay, .edit-toolbar) { display: none !important; }

/* alignment guides while dragging */
.snap-guides { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 85; }
.snap-guides[hidden] { display: none; }
.snap-faint { stroke: var(--color-text-secondary); stroke-width: 1; stroke-dasharray: 2 5; opacity: 0.45; }
.snap-hit { stroke: var(--color-text-primary); stroke-width: 1; }
.snap-near { stroke: var(--color-text-primary); stroke-width: 1; opacity: 0.35; }
.snap-label { fill: var(--color-text-primary); font: 11px Georgia, serif; paint-order: stroke; stroke: var(--color-card-background); stroke-width: 3px; stroke-linejoin: round; }
@media print { .snap-guides { display: none; } }

/* the bar along the bottom while editing */
.edit-toolbar {
    position: fixed;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 95;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px;
    background: var(--color-card-background);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}
.edit-toolbar[hidden] { display: none; }
.edit-toolbar button { padding: 4px 10px; font: 13px Georgia, serif; color: var(--color-text-primary); background: none; border: none; border-radius: 4px; cursor: pointer; }
.edit-toolbar button:hover:not(:disabled) { background: var(--color-selection); }
.edit-toolbar button:disabled { opacity: 0.35; cursor: default; }
.edit-toolbar button.on { color: var(--color-card-background); background: var(--color-text-primary); }
.edit-toolbar .sep { width: 1px; height: 18px; margin: 0 4px; background: var(--color-border); }

@media print { .edit-toolbar { display: none; } }

/* nothing is outlined while something is being dragged */
body.dragging-item .hover-outline { display: none; }
body.editing aside.note, body.editing .codeblock, body.editing .mathblock { cursor: text; }
body.editing .obj { cursor: pointer; }

/* code is set in ink too: weight and slant, not colour, tell the parts apart */
.token { color: inherit !important; background: none !important; text-shadow: none; }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--color-text-secondary) !important; font-style: italic; }
.token.keyword, .token.function, .token.class-name, .token.builtin { font-weight: bold; }
.token.string, .token.char, .token.number { text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* october figure: roofs, a moon and crows in one drawing standing on the bottom of its rectangle */
.viz-container[data-figure="october"] { margin: 0; }
.october-svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }

/* umbrella figure: a drawing and a canvas of rain laid over each other, in the ink of the page, clipped to the figure's rectangle */
.viz-container[data-figure="umbrella"] { margin: 0; overflow: hidden; }
.umbrella-svg, .umbrella-rain { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---- paper ----
   Printing does not use the page on screen, which is placed line by line. The page is set again for the sheet
   (app/print.js) and drawn into .print-root as one box per sheet, which is out of the way on screen and is all
   that is shown when printing. */
.paper {
    /* paper is black on white, whatever the theme */
    --color-text-primary: #111111;
    --color-text-secondary: #555555;
    --color-card-background: #ffffff;
    --color-border: #bbbbbb;
    --code-background: #f4f4f4;
    --color-link: #111111;
    --color-figure-spot: #c7323f;
    color: var(--color-text-primary);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
/* a drawing with a colour of its own keeps it on paper (see theme.css) */
.paper [data-spot="october"] { --color-figure-spot: #d8b450; }
.print-root { display: none; }

.sheet { position: relative; overflow: hidden; background: #fff; }
.sheet-body { position: absolute; left: 0; }
.sheet-head, .sheet-foot {
    position: absolute;
    display: flex;
    justify-content: space-between;
    color: var(--color-text-secondary);
    font-size: 10px;
    line-height: 14px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
}
.sheet-head { top: 48px; justify-content: center; }
.sheet-foot { bottom: 48px; }
.sheet-folio { letter-spacing: 0.04em; }
.print-root .heading-link, .print-root .note-more { display: none; }
.print-root .doc { overflow: hidden; }
.print-root .obj, .print-root .codeblock, .print-root .mathblock { break-inside: avoid; }
/* a figure on paper is a picture of it: what can be pressed or dragged is left out, and a button in a line is its words */
.print-root .viz-container :is(input, button, select, textarea, .viz-controls, .viz-3d-controls) { display: none; }
.print-root .atom-widget :is(input, textarea, select) { display: none; }
.print-root .atom-widget button { padding: 0; border: 0; background: none; font: inherit; color: inherit; }
.print-root .figure-missing {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-sizing: border-box;
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    font-size: 11px;
    text-align: center;
}

/* only once the sheets are made does the page give way to them; if they could not be, the page prints as it is */
@media print {
    html.has-sheets, html.has-sheets body { margin: 0; padding: 0; background: #fff; }
    html.has-sheets body > *:not(.print-root) { display: none !important; }
    html.has-sheets .print-root { display: block; }
    .sheet { break-after: page; page-break-after: always; }
    .sheet:last-child { break-after: auto; page-break-after: auto; }
}
