/*
 * EnergyAtlas Wiki styling. It follows design/ui-design-spec.md (section 0 wins): flat, square, rule-framed surfaces;
 * Geist, Geist Mono, and Cormorant Garamond (fonts.css); the EnergyAtlas palette with the contrast adjustments of its
 * section 0.6. Syntax highlighting lives in syntax.css.
 *
 * Layout: a fixed sidebar at the left (brand row, subspace switcher, page tree, tool row) and a framed page shell to its
 * right. The frame's two vertical rules belong to .menu-content; the article and the table of contents are its two
 * columns, and both open with a bar of the same height as the sidebar's brand row, so their bottom rules meet.
 */

/* ---------------------------------------------------------------------------------------------------------------------
 * Tokens
 * ------------------------------------------------------------------------------------------------------------------ */

:root {
    color-scheme: dark;

    --font-sans: "Geist", "Inter", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Geist Mono", "IBM Plex Mono", Consolas, monospace;
    --font-serif: "Cormorant Garamond", "Cormorant", Georgia, serif;

    --ui-primary: #003978;
    --ui-accent: #4da3ff;
    --ui-accent-tint: rgba(77, 163, 255, 0.08);

    --ui-text-primary: #e5e5e5;
    --ui-text-secondary: #b0b0b0;
    --ui-text-muted: #999999;

    --ui-bg-base: #000000;
    --ui-bg-surface-1: #1a1a1a;
    --ui-bg-surface-2: #2a2a2a;
    --ui-bg-surface-3: #3a3a3a;

    --ui-border-subtle: #404040;
    --ui-border-interactive: #6b6b6b;

    --ui-success: #28a745;
    --ui-warning: #ffc107;
    --ui-error: #f44336;

    --ui-scrim: rgba(0, 0, 0, 0.6);
    --ui-scrollbar-thumb: rgba(255, 255, 255, 0.2);
    --ui-scrollbar-thumb-hover: rgba(255, 255, 255, 0.35);

    /* Read by plotly-render.js. */
    --plotly-font-color: #e5e5e5;
    --plotly-grid-color: rgba(255, 255, 255, 0.12);
    --plotly-zeroline-color: rgba(255, 255, 255, 0.2);
    --plotly-paper-bg: rgba(0, 0, 0, 0);
    --plotly-plot-bg: rgba(0, 0, 0, 0);
    --plotly-subtitle-color: #999999;

    --ui-transition: 150ms ease;

    --wiki-sidebar-width: 17rem;
    --wiki-bar-height: 3.5rem;
    --wiki-page-toc-width: 14rem;
    --wiki-article-max-width: 60rem;
    --wiki-full-width-max: 87.5rem;
    --wiki-prose-max: 52rem;
    --wiki-gutter: clamp(1.5rem, 3vw, 3rem);
    --wiki-scroll-progress-height: 2px;
}

:root[data-theme="light"] {
    color-scheme: light;

    --ui-accent: #125dae;
    --ui-accent-tint: rgba(18, 93, 174, 0.08);

    --ui-text-primary: #18202c;
    --ui-text-secondary: #3f4b5b;
    --ui-text-muted: #5f6b7a;

    --ui-bg-base: #ffffff;
    --ui-bg-surface-1: #f8fafc;
    --ui-bg-surface-2: #f4f7fb;
    --ui-bg-surface-3: #e7edf5;

    --ui-border-subtle: #cfd8e5;
    --ui-border-interactive: #768599;

    --ui-success: #188038;
    --ui-warning: #9a6700;
    --ui-error: #c5221f;

    --ui-scrim: rgba(24, 32, 44, 0.4);
    --ui-scrollbar-thumb: rgba(24, 32, 44, 0.24);
    --ui-scrollbar-thumb-hover: rgba(24, 32, 44, 0.4);

    --plotly-font-color: #18202c;
    --plotly-grid-color: rgba(24, 32, 44, 0.14);
    --plotly-zeroline-color: rgba(24, 32, 44, 0.24);
    --plotly-subtitle-color: #5f6b7a;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Base
 * ------------------------------------------------------------------------------------------------------------------ */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Reserve the scrollbar's width on every page, so that moving between short and long pages does not shift the layout. */
html {
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--ui-scrollbar-thumb) transparent;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--ui-scrollbar-thumb);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--ui-scrollbar-thumb-hover);
}

body {
    min-height: 100vh;
    padding-bottom: var(--wiki-scroll-progress-height);
    color: var(--ui-text-primary);
    background: var(--ui-bg-base);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Sidebar: brand row, subspace switcher, page tree, tool row (spec section 0.7)
 * ------------------------------------------------------------------------------------------------------------------ */

.wiki-sidebar {
    position: fixed;
    inset: 0 auto var(--wiki-scroll-progress-height) 0;
    z-index: 3700;
    width: var(--wiki-sidebar-width);
    display: flex;
    flex-direction: column;
    color: var(--ui-text-primary);
    background: var(--ui-bg-base);
    /*
     * The sidebar's rule is drawn just outside it, on the same pixel column as the frame's left rule when the frame
     * touches the sidebar, so the two read as one line; when the frame is centred away from it, both show.
     */
    box-shadow: 1px 0 0 var(--ui-border-subtle);
    transition: width 180ms ease;
}

.wiki-sidebar-header {
    width: var(--wiki-sidebar-width);
    height: var(--wiki-bar-height);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: inset 0 -1px 0 var(--ui-border-subtle);
    transition: opacity 120ms ease, visibility 0s linear 0s;
}

.wiki-sidebar-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ui-text-primary);
    text-decoration: none;
}

.wiki-sidebar-logo {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.wiki-sidebar-brand-name,
.wiki-sidebar-brand-suffix {
    font-size: 1rem;
    line-height: 1;
    letter-spacing: -0.01em;
}

.wiki-sidebar-brand-name {
    font-weight: 650;
}

.wiki-sidebar-brand-suffix {
    color: var(--ui-text-muted);
    font-weight: 400;
}

.wiki-sidebar-body {
    width: var(--wiki-sidebar-width);
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: opacity 120ms ease, visibility 0s linear 0s;
}

/* The subspace switcher: one full-width row; its menu is a flat list with rules between options. */
.wiki-space-switcher {
    position: relative;
    flex-shrink: 0;
}

.wiki-space-switcher-summary {
    height: var(--wiki-bar-height);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    color: var(--ui-text-primary);
    box-shadow: inset 0 -1px 0 var(--ui-border-subtle);
    cursor: pointer;
    list-style: none;
    transition: background-color var(--ui-transition);
}

.wiki-space-switcher-summary::-webkit-details-marker,
.wiki-space-tree-summary::-webkit-details-marker {
    display: none;
}

.wiki-space-switcher-summary:hover,
.wiki-space-switcher[open] > .wiki-space-switcher-summary {
    background: var(--ui-bg-surface-1);
}

.wiki-space-switcher-summary:focus-visible,
.wiki-space-switcher-option:focus-visible,
.wiki-space-tree-summary:focus-visible,
.wiki-space-tree-link:focus-visible {
    outline-offset: -2px;
}

.wiki-space-switcher-copy {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/*
 * Subspace icons: the hand-drawn family (theme/icons/subspaces/). The ink takes the colour of the row's text; the
 * accent takes the theme's accent blue.
 */
.wiki-space-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    display: inline-flex;
}

.wiki-space-icon svg {
    width: 100%;
    height: 100%;
}

/* The dropdown shows the icons larger than the page tree would. */
.wiki-space-switcher-summary .wiki-space-icon,
.wiki-space-switcher-option .wiki-space-icon {
    width: 26px;
    height: 26px;
    flex-basis: 26px;
}

.wiki-space-icon .ink {
    fill: currentColor;
}

.wiki-space-icon .accent {
    fill: var(--ui-accent);
}

/* Subspace names: the primary sans in bold, normal case (spec 0.7). */
.wiki-space-switcher-value,
.wiki-space-switcher-option {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.3;
}

.wiki-space-switcher-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wiki-space-switcher-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    fill: none;
    stroke: var(--ui-text-muted);
    stroke-width: 1.7;
    transition: transform var(--ui-transition);
}

.wiki-space-switcher[open] .wiki-space-switcher-chevron {
    transform: rotate(180deg);
}

.wiki-space-switcher-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 4;
    display: grid;
    background: var(--ui-bg-base);
    box-shadow: 0 1px 0 var(--ui-border-subtle);
}

.wiki-space-switcher-option {
    height: 3.25rem;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    color: var(--ui-text-muted);
    text-decoration: none;
    box-shadow: inset 0 -1px 0 var(--ui-border-subtle);
    transition: background-color var(--ui-transition), color var(--ui-transition);
}

.wiki-space-switcher-option:hover {
    color: var(--ui-text-primary);
    background: var(--ui-bg-surface-1);
}

.wiki-space-switcher-option.active {
    color: var(--ui-text-primary);
    box-shadow: inset 2px 0 0 var(--ui-accent), inset 0 -1px 0 var(--ui-border-subtle);
}

.wiki-space-switcher-option-main {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.wiki-space-switcher-option-main > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wiki-space-switcher-check {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    fill: none;
    stroke: var(--ui-accent);
    stroke-width: 1.8;
}

/* The page tree of the current subspace. */
.wiki-space-navigation {
    min-height: 0;
    flex: 1;
    padding: 0.75rem 0 1.5rem;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.wiki-space-tree-list {
    list-style: none;
}

.wiki-space-tree-list .wiki-space-tree-list {
    margin: 0.125rem 0 0.375rem 1.875rem;
    border-left: 1px solid var(--ui-border-subtle);
}

.wiki-space-tree-summary,
.wiki-space-tree-link {
    min-height: 2rem;
    padding: 0.375rem 1rem 0.375rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--ui-text-muted);
    font-size: 0.875rem;
    line-height: 1.35;
    text-decoration: none;
    cursor: pointer;
    transition: color var(--ui-transition), background-color var(--ui-transition);
}

.wiki-space-tree-list .wiki-space-tree-list .wiki-space-tree-summary,
.wiki-space-tree-list .wiki-space-tree-list .wiki-space-tree-link {
    padding-left: 0.875rem;
}

.wiki-space-tree-summary {
    list-style: none;
    color: var(--ui-text-secondary);
    font-weight: 500;
}

.wiki-space-tree-summary:hover,
.wiki-space-tree-link:hover {
    color: var(--ui-text-primary);
    background: var(--ui-bg-surface-1);
}

.wiki-space-tree-link.active {
    color: var(--ui-text-primary);
    font-weight: 550;
    box-shadow: inset 2px 0 0 var(--ui-accent);
}

.wiki-space-tree-chevron {
    width: 12px;
    height: 12px;
    margin-left: -0.125rem;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    transition: transform var(--ui-transition);
}

.wiki-space-tree-group[open] > .wiki-space-tree-summary .wiki-space-tree-chevron {
    transform: rotate(90deg);
}

/* The tool row: theme toggle, edit, repository, collapse. */
.wiki-sidebar-tools {
    width: var(--wiki-sidebar-width);
    height: var(--wiki-bar-height);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    background: var(--ui-bg-base);
    box-shadow: inset 0 1px 0 var(--ui-border-subtle);
    transition: width 180ms ease;
}

.wiki-sidebar-tools .wiki-theme-toggle {
    margin-right: auto;
}

.wiki-sidebar-tool,
.wiki-sidebar-close,
.wiki-sidebar-toggle {
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--ui-text-secondary);
    background: var(--ui-bg-base);
    border: 1px solid var(--ui-border-interactive);
    border-radius: 0;
    cursor: pointer;
    transition: color var(--ui-transition), border-color var(--ui-transition), background-color var(--ui-transition);
}

.wiki-sidebar-tool:hover,
.wiki-sidebar-close:hover,
.wiki-sidebar-toggle:hover {
    color: var(--ui-text-primary);
    border-color: var(--ui-accent);
}

.wiki-sidebar-tool svg {
    width: 15px;
    height: 15px;
}

.wiki-sidebar-tool .wiki-sidebar-tool-edit-icon {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
}

.wiki-sidebar-tool .wiki-sidebar-tool-github-icon {
    fill: currentColor;
    stroke: none;
}

.wiki-sidebar-collapse svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 180ms ease;
}

.wiki-sidebar-close svg,
.wiki-sidebar-toggle svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
}

.wiki-sidebar-close,
.wiki-sidebar-toggle,
.wiki-sidebar-scrim {
    display: none;
}

/* The theme toggle: a square two-cell switch whose active cell is inverted. */
.wiki-theme-toggle {
    --wiki-theme-toggle-width: 4rem;
    width: var(--wiki-theme-toggle-width);
    height: 2rem;
    padding: 0;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--ui-border-interactive);
    border-radius: 0;
    cursor: pointer;
    transition: border-color var(--ui-transition);
}

.wiki-theme-toggle:hover {
    border-color: var(--ui-accent);
}

.wiki-theme-toggle-track {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.wiki-theme-toggle-thumb {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    width: 50%;
    background: var(--ui-text-primary);
    transition: transform var(--ui-transition);
}

:root[data-theme="dark"] .wiki-theme-toggle-thumb {
    transform: translateX(100%);
}

.wiki-theme-toggle-end {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ui-text-muted);
    transition: color var(--ui-transition);
}

:root[data-theme="light"] .wiki-theme-toggle-end-light,
:root[data-theme="dark"] .wiki-theme-toggle-end-dark {
    color: var(--ui-bg-base);
}

.wiki-theme-toggle-icon {
    width: 14px;
    height: 14px;
}

/* Desktop collapse: the sidebar folds away; the tool row stays at the bottom left as a framed block. */
:root[data-sidebar-collapsed="true"] .wiki-sidebar {
    width: 0;
    box-shadow: none;
}

:root[data-sidebar-collapsed="true"] .wiki-sidebar-header,
:root[data-sidebar-collapsed="true"] .wiki-sidebar-body {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition-delay: 0s, 120ms;
}

/* The tool row keeps its width and layout, so no control moves when the sidebar folds or unfolds. */
:root[data-sidebar-collapsed="true"] .wiki-sidebar-tools {
    box-shadow: inset 0 1px 0 var(--ui-border-subtle), inset -1px 0 0 var(--ui-border-subtle);
}

:root[data-sidebar-collapsed="true"] .wiki-sidebar-collapse svg {
    transform: rotate(180deg);
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Page shell and frame
 * ------------------------------------------------------------------------------------------------------------------ */

.wiki-page-shell {
    margin-left: var(--wiki-sidebar-width);
    transition: margin-left 180ms ease;
}

:root[data-sidebar-collapsed="true"] .wiki-page-shell {
    margin-left: 0;
}

/*
 * The frame: two thin vertical rules from the top of the window to the bottom of the page, centred in the space to the
 * right of the sidebar, with empty margins outside it.
 */
.wiki-page-shell .menu-content {
    max-width: calc(var(--wiki-article-max-width) + var(--wiki-page-toc-width));
    margin: 0 auto;
    min-height: calc(100vh - var(--wiki-scroll-progress-height));
    border-left: 1px solid var(--ui-border-subtle);
    border-right: 1px solid var(--ui-border-subtle);
}

.wiki-page-shell .menu-content:has(.wiki-grid-full-width) {
    max-width: var(--wiki-full-width-max);
}

.wiki-grid {
    min-height: inherit;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--wiki-page-toc-width);
}

.wiki-grid-full-width {
    grid-template-columns: minmax(0, 1fr);
}

.menu-column-content {
    min-width: 0;
    padding: 0 var(--wiki-gutter) 4rem;
}

/* The article opens with a bar holding the breadcrumbs; its bottom rule meets the sidebar's and the contents'. */
.menu-column-header {
    height: var(--wiki-bar-height);
    margin: 0 calc(-1 * var(--wiki-gutter)) 3rem;
    padding: 0 var(--wiki-gutter);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--ui-border-subtle);
}

.wiki-breadcrumbs {
    min-width: 0;
    overflow: hidden;
    color: var(--ui-text-muted);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    line-height: 1.3;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.wiki-breadcrumbs-sep {
    padding: 0 0.5em;
}

/* The table of contents: its own column behind the frame's inner rule. */
.menu-column-toc {
    min-width: 0;
    border-left: 1px solid var(--ui-border-subtle);
}

.toc-nav {
    position: sticky;
    top: 0;
    max-height: calc(100vh - var(--wiki-scroll-progress-height));
    padding-bottom: 1.5rem;
    overflow-y: auto;
}

.toc-heading {
    height: var(--wiki-bar-height);
    margin-bottom: 0.75rem;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    color: var(--ui-text-muted);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--ui-border-subtle);
}

.toc-list,
.toc-sublist {
    list-style: none;
}

.toc-link {
    display: block;
    padding: 0.25rem 1rem 0.25rem 1.25rem;
    color: var(--ui-text-muted);
    font-size: 0.8125rem;
    line-height: 1.4;
    text-decoration: none;
    transition: color var(--ui-transition);
}

.toc-sublist .toc-link {
    padding-left: 2rem;
}

.toc-sublist .toc-sublist .toc-link {
    padding-left: 2.75rem;
}

.toc-link:hover {
    color: var(--ui-text-primary);
}

.toc-link.active {
    color: var(--ui-text-primary);
    box-shadow: inset 2px 0 0 var(--ui-accent);
}

.toc-link:focus-visible {
    outline-offset: -2px;
}

.toc-empty {
    padding: 0 1.25rem;
    color: var(--ui-text-muted);
    font-size: 0.8125rem;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Typography
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content {
    color: var(--ui-text-secondary);
}

/* Long-form prose keeps a readable measure; tables, code, images, diagrams, strips, and grids use the full column. */
.md-content > :is(p, ul, ol, dl, blockquote, h1, h2, h3, h4, h5, h6) {
    max-width: var(--wiki-prose-max);
}

.wiki-grid-full-width .md-content > * {
    max-width: none;
}

.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4,
.md-content h5,
.md-content h6 {
    color: var(--ui-text-primary);
    font-family: var(--font-sans);
    font-weight: 650;
    letter-spacing: -0.02em;
    line-height: 1.15;
    scroll-margin-top: 1.5rem;
}

.md-content h1 {
    margin: 0 0 1.5rem;
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.05;
}

.md-content h2 {
    margin: 4rem 0 1.25rem;
    font-size: 1.875rem;
}

.md-content h3 {
    margin: 2.5rem 0 1rem;
    font-size: 1.375rem;
}

.md-content h4 {
    margin: 2rem 0 0.75rem;
    font-size: 1.125rem;
}

.md-content h5,
.md-content h6 {
    margin: 1.5rem 0 0.5rem;
    font-size: 1rem;
}

.md-content h1 + h2,
.md-content h2 + h3,
.md-content h3 + h4 {
    margin-top: 1.5rem;
}

.md-content h1 + p {
    color: var(--ui-text-secondary);
    font-size: 1.125rem;
}

/* The permalink of a heading: quiet until the heading is hovered or the link is focused. */
.md-content .headerlink {
    margin-left: 0.35em;
    color: var(--ui-text-muted);
    font-weight: 400;
    text-decoration: none;
    opacity: 0;
    transition: opacity var(--ui-transition), color var(--ui-transition);
}

.md-content :is(h1, h2, h3, h4, h5, h6):hover > .headerlink,
.md-content .headerlink:focus-visible {
    opacity: 1;
}

.md-content .headerlink:hover {
    color: var(--ui-accent);
}

.md-content p,
.md-content ul,
.md-content ol,
.md-content dl {
    margin-bottom: 1.25em;
}

.md-content ul,
.md-content ol {
    padding-left: 1.5em;
}

.md-content li {
    margin-bottom: 0.35em;
}

.md-content li > ul,
.md-content li > ol {
    margin: 0.35em 0 0;
}

.md-content li::marker {
    color: var(--ui-text-muted);
}

.md-content strong {
    color: var(--ui-text-primary);
    font-weight: 600;
}

.md-content a {
    color: var(--ui-accent);
    text-decoration: none;
    text-underline-offset: 0.2em;
    text-decoration-thickness: 1px;
}

.md-content a:hover {
    text-decoration: underline;
}

.md-content hr {
    height: 0;
    margin: 3rem 0;
    border: 0;
    border-top: 1px solid var(--ui-border-subtle);
}

/* Block quotes take the technical-panel treatment: a flat surface with an accent edge. */
.md-content blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    color: var(--ui-text-secondary);
    background: var(--ui-bg-surface-1);
    border: 1px solid var(--ui-border-subtle);
    box-shadow: inset 2px 0 0 var(--ui-accent);
}

.md-content blockquote > :last-child {
    margin-bottom: 0;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Code
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content code {
    padding: 0.1em 0.3em;
    color: var(--ui-text-primary);
    background: var(--ui-bg-surface-1);
    font-family: var(--font-mono);
    font-size: 0.875em;
    border-radius: 0;
}

.md-content pre {
    margin-bottom: 1.25rem;
    padding: 1rem;
    overflow-x: auto;
    background: var(--ui-bg-surface-1);
    border: 1px solid var(--ui-border-subtle);
}

.md-content pre code {
    padding: 0;
    background: transparent;
    font-size: inherit;
}

/* Fenced code blocks, rebuilt by base.html into a header (language, copy) over line numbers and code. */
.code-block-container {
    width: 100%;
    margin: 1.5rem 0;
}

.code-block-inner {
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--ui-bg-surface-1);
    border: 1px solid var(--ui-border-subtle);
}

.code-block-header {
    min-height: 2.25rem;
    padding: 0 0.5rem 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.code-block-lang {
    color: var(--ui-text-muted);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.code-block-sep {
    height: 1px;
    background: var(--ui-border-subtle);
}

.code-block-body {
    width: 100%;
    display: flex;
    align-items: flex-start;
}

.code-block-inner .highlight,
.code-block-inner pre {
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: transparent;
    border: none;
}

.code-block-body pre,
.code-block-body code {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.6;
}

.code-block-lines {
    padding: 0.75rem 0.75rem 0.75rem 1rem;
    flex-shrink: 0;
    color: var(--ui-text-muted);
    text-align: right;
    user-select: none;
}

.code-block-lines pre {
    white-space: pre;
}

.code-block-content {
    min-width: 0;
    flex: 1;
    padding: 0.75rem 1rem 0.75rem 0.25rem;
    overflow-x: auto;
}

.code-block-content pre {
    white-space: pre;
}

.linenodiv pre,
.linenodiv a,
.linenums a {
    pointer-events: none;
    color: var(--ui-text-muted);
    text-decoration: none;
}

/* Compact technical buttons: copy, dismiss. */
.copy-button,
.plotly-playground-copy,
.wiki-dev-notice-ok {
    min-height: 1.75rem;
    padding: 0 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ui-text-secondary);
    background: transparent;
    border: 1px solid var(--ui-border-interactive);
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color var(--ui-transition), border-color var(--ui-transition), background-color var(--ui-transition);
}

.copy-button:hover,
.plotly-playground-copy:hover {
    color: var(--ui-text-primary);
    border-color: var(--ui-accent);
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Tables: technical data sheets
 *
 * Tables keep normal table layout and stretch to the column. base.html wraps each one in .table-scroll-wrapper, which
 * scrolls horizontally when the table is still wider than the column; tables of five or more columns keep their cells
 * on one line (.table-scroll-wrapper-wide).
 * ------------------------------------------------------------------------------------------------------------------ */

.table-scroll-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 1.5rem 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

.table-scroll-wrapper > table {
    margin: 0;
}

.table-scroll-wrapper-wide > table {
    width: max-content;
    min-width: 100%;
    max-width: none;
    table-layout: auto;
}

.table-scroll-wrapper-wide > table th,
.table-scroll-wrapper-wide > table td {
    white-space: nowrap;
    overflow-wrap: normal;
}

.table-scroll-wrapper.is-scrollable:focus-visible {
    outline-offset: -2px;
}

.md-content table {
    width: 100%;
    margin: 1.5rem 0;
    border-collapse: collapse;
    font-size: 0.875rem;
    line-height: 1.5;
}

.md-content table th,
.md-content table td {
    padding: 0.625rem 0.875rem;
    text-align: left;
    vertical-align: top;
    border: 1px solid var(--ui-border-subtle);
    overflow-wrap: break-word;
}

.md-content table th {
    color: var(--ui-text-muted);
    background: var(--ui-bg-surface-1);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    vertical-align: bottom;
}

.md-content table td {
    color: var(--ui-text-secondary);
}

.md-content table tbody tr {
    transition: background-color var(--ui-transition);
}

.md-content table tbody tr:hover {
    background: var(--ui-accent-tint);
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Images
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content img {
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
    display: block;
}

.md-content p:has(img) {
    max-width: none;
    text-align: center;
}

.md-content img + em,
.md-content img + p em {
    display: block;
    margin-top: 0.25rem;
    color: var(--ui-text-muted);
    font-size: 0.75rem;
    text-align: center;
}

.md-content img.full-width {
    width: 100%;
}

.md-content img.small {
    max-width: 300px;
}

.md-content img.medium {
    max-width: 500px;
}

.md-content img.large {
    max-width: 800px;
}

.md-content img.float-left {
    float: left;
    margin: 1rem 1rem 1rem 0;
}

.md-content img.float-right {
    float: right;
    margin: 1rem 0 1rem 1rem;
}

.md-content .image-container {
    margin: 1.5rem 0;
    text-align: center;
}

.md-content .image-container img {
    margin: 0 auto;
}

.md-content .image-container p {
    margin-top: 0.25rem;
    color: var(--ui-text-muted);
    font-size: 0.75rem;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Plotly charts and the plotting playground
 * ------------------------------------------------------------------------------------------------------------------ */

.plotly-chart {
    width: 100%;
    min-height: 360px;
    margin: 1.5rem 0;
}

.plotly-playground {
    position: relative;
}

.plotly-playground-error {
    margin-bottom: 0.5rem;
    color: var(--ui-error);
    font-size: 0.875rem;
}

.plotly-playground-chart {
    margin-bottom: 1rem;
}

.plotly-playground-editor {
    width: 100%;
    min-height: 260px;
    padding: 0.75rem 0;
    overflow-x: auto;
    color: var(--ui-text-primary);
    background: transparent;
    border: none;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre;
    resize: vertical;
}

.plotly-playground-editor:focus-visible {
    outline: none;
}

.plotly-playground .code-block-inner:focus-within {
    border-color: var(--ui-accent);
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Live LikeC4 diagrams
 *
 * <likec4-view> renders into a shadow root and carries its own aspect ratio, so the figure supplies chrome only. The
 * host's box model is set here rather than left at the element default, so a narrow viewport can give it a floor width
 * and scroll instead of shrinking a wide view down to an unreadable strip.
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content .likec4-figure {
    margin: 1.5rem 0;
    overflow: hidden;
    background: var(--ui-bg-surface-1);
    border: 1px solid var(--ui-border-subtle);
}

.md-content .likec4-figure-canvas {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

.md-content .likec4-figure-canvas > likec4-view {
    display: block;
}

.md-content .likec4-figure figcaption {
    padding: 0.625rem 1rem;
    color: var(--ui-text-secondary);
    background: var(--ui-bg-base);
    border-top: 1px solid var(--ui-border-subtle);
    font-size: 0.875rem;
}

/* Shown only where the diagram is scrolled rather than fully visible. */
.md-content .likec4-figure-hint {
    display: none;
    margin-top: 0.25rem;
    color: var(--ui-text-muted);
}

/* Without JavaScript the custom element never upgrades, leaving an empty frame. */
.md-content .likec4-figure .likec4-figure-fallback {
    padding: 1rem;
    color: var(--ui-text-muted);
    font-size: 0.875rem;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Section strips (spec sections 7 and 0.9). On pages with `overview: true` every `##` heading becomes a numbered strip
 * that runs from frame to frame; `{data-note="..."}` on the heading adds a right-hand annotation.
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content.wiki-overview {
    counter-reset: wiki-strip;
}

.md-content.wiki-overview > h2 {
    min-height: 3rem;
    max-width: none;
    margin: 4rem calc(-1 * var(--wiki-gutter)) 2rem;
    padding: 0.75rem var(--wiki-gutter);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ui-text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    line-height: 1.3;
    text-transform: uppercase;
    border-top: 1px solid var(--ui-border-subtle);
    border-bottom: 1px solid var(--ui-border-subtle);
    counter-increment: wiki-strip;
}

.md-content.wiki-overview > h2::before {
    content: counter(wiki-strip, decimal-leading-zero) "\00a0/";
}

.md-content.wiki-overview > h2[data-note]::after {
    content: attr(data-note);
    margin-left: auto;
    text-align: right;
}

.md-content.wiki-overview > h2 .headerlink {
    margin-left: 0;
}

/* A strip directly after the page's opening rules (title, lead) keeps the same rhythm as one after prose. */
.md-content.wiki-overview > h1 + h2 {
    margin-top: 2.5rem;
}

/* A strip followed directly by a grid shares its bottom rule with the grid. */
.md-content.wiki-overview > h2 + .ui-grid {
    margin-top: -2rem;
    border-top: 0;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Grids of cells (spec sections 6, 8, and 0.13). `<div class="ui-grid" markdown>` around a list: the block draws the
 * top and bottom rules from frame to frame; the list is the grid, and each cell draws its right and bottom rule, which
 * the list clips at its outer edge. Cells pad their text by the gutter, so it lines up with the strip labels.
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content .ui-grid {
    max-width: none;
    margin: 2rem calc(-1 * var(--wiki-gutter));
    border-top: 1px solid var(--ui-border-subtle);
    border-bottom: 1px solid var(--ui-border-subtle);
}

.md-content .ui-grid > :is(ul, ol) {
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
    overflow: hidden;
    list-style: none;
    counter-reset: ui-cell;
}

.md-content .ui-grid > :is(ul, ol) > li {
    position: relative;
    margin: 0;
    padding: 1.25rem var(--wiki-gutter) 1.5rem;
    display: flex;
    flex-direction: column;
    box-shadow: 1px 0 0 var(--ui-border-subtle), 0 1px 0 var(--ui-border-subtle);
    counter-increment: ui-cell;
    transition: background-color var(--ui-transition);
}

.md-content .ui-grid > :is(ul, ol) > li:is(:hover, :focus-within) {
    background: var(--ui-bg-surface-1);
}

/* The cell index: A, B, C in a list; 01, 02, 03 in a numbered list. */
.md-content .ui-grid > :is(ul, ol) > li::before {
    margin-bottom: 1.25rem;
    color: var(--ui-text-muted);
    content: counter(ui-cell, upper-alpha);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.14em;
}

.md-content .ui-grid > ol > li::before {
    content: counter(ui-cell, decimal-leading-zero);
}

.md-content .ui-grid > :is(ul, ol) > li > p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.55;
}

/* The first line of a cell is its title. */
.md-content .ui-grid > :is(ul, ol) > li > p:first-of-type {
    margin-bottom: 0.5rem;
    color: var(--ui-text-primary);
    font-size: 1.125rem;
    font-weight: 650;
    letter-spacing: -0.015em;
    line-height: 1.25;
}

.md-content .ui-grid > :is(ul, ol) > li > p:first-of-type a {
    color: inherit;
    text-decoration: none;
}

/*
 * A cell whose title is a link is a link as a whole: the title link stretches over the cell. Other links in the cell
 * stay above it and keep their own targets.
 */
.md-content .ui-grid > :is(ul, ol) > li > p:first-of-type > a:only-of-type::after {
    content: "";
    position: absolute;
    inset: 0;
}

.md-content .ui-grid > :is(ul, ol) > li a:not(p:first-of-type > a:only-of-type) {
    position: relative;
    z-index: 1;
}

.md-content .ui-grid > :is(ul, ol) > li:hover > p:first-of-type > a,
.md-content .ui-grid > :is(ul, ol) > li > p:first-of-type > a:focus-visible {
    color: var(--ui-accent);
}

/* The stretched link gives the cell its focus ring, so a keyboard user sees the whole cell selected. */
.md-content .ui-grid > :is(ul, ol) > li > p:first-of-type > a:only-of-type:focus-visible {
    outline: none;
}

.md-content .ui-grid > :is(ul, ol) > li > p:first-of-type > a:only-of-type:focus-visible::after {
    outline: 2px solid var(--ui-accent);
    outline-offset: -2px;
}

/*
 * Icon cards (`ui-grid ui-cards`, spec 0.13): no letter index; the subspace icon sits above the title (inlined by
 * hooks/icons.py). On hover the card fills with a soft accent gradient and a faint, oversized copy of its icon, centred
 * towards the card's lower right and cropped by the card.
 */
.md-content .ui-icon,
.md-content .ui-card-backdrop {
    display: none;
}

.md-content .ui-cards > :is(ul, ol) > li {
    overflow: hidden;
    isolation: isolate;
}

.md-content .ui-cards > :is(ul, ol) > li::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    margin: 0;
    background: linear-gradient(140deg, transparent 30%, color-mix(in srgb, var(--ui-accent) 16%, transparent) 100%);
    opacity: 0;
    transition: opacity 180ms ease;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) {
    background: transparent;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within)::before {
    opacity: 1;
}

.md-content .ui-cards .ui-icon {
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 1rem;
    display: block;
}

.md-content .ui-cards .ui-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.md-content .ui-cards .ui-icon .ink {
    fill: var(--ui-text-primary);
}

.md-content .ui-cards .ui-icon .accent,
.md-content .ui-cards .ui-card-backdrop :is(.ink, .accent) {
    fill: var(--ui-accent);
}

.md-content .ui-cards .ui-card-backdrop {
    position: absolute;
    left: 70%;
    top: 72%;
    z-index: -1;
    width: 105%;
    aspect-ratio: 1;
    display: block;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%);
    transition: opacity 180ms ease;
}

.md-content .ui-cards .ui-card-backdrop svg {
    width: 100%;
    height: 100%;
    display: block;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-card-backdrop {
    opacity: 0.14;
}

.md-content .ui-cards > :is(ul, ol) > li > p:not(:first-of-type) {
    color: var(--ui-text-secondary);
}

/*
 * Icon card animations (spec 0.13): every subspace icon has its own short animation, played once when its card is
 * hovered or focused. The marks are the light icon's paths in drawing order (design/icons/generate_subspace_icons.py);
 * tests/test_ui_design.py checks that each icon still has the marks these rules address.
 */
.md-content .ui-cards .ui-icon :is(g, path) {
    transform-box: fill-box;
    transform-origin: center;
}

/* Quick Start: the needle (ink 2, accent 1) swings about the compass centre and settles. */
.md-content .ui-cards .ui-icon-quick-start :is(.ink path:nth-of-type(2), .accent path) {
    transform-box: view-box;
    transform-origin: 50% 50%;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-quick-start :is(.ink path:nth-of-type(2), .accent path) {
    animation: ui-icon-swing 500ms ease-in-out;
}

/* Workflows: the arrow (ink 2) draws from the start ring, its head (ink 3) lands, and the node (accent) pops. */
.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-workflows .ink path:nth-of-type(2) {
    animation: ui-icon-draw-up-right 240ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-workflows .ink path:nth-of-type(3) {
    animation: ui-icon-land-right 320ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-workflows .accent path {
    animation: ui-icon-pop 410ms ease-out;
}

/* Architecture: the connectors (ink 3, 4) draw downwards; the blocks (ink 1, ink 2, accent) pop in turn. */
.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-architecture .ink path:nth-of-type(1) {
    animation: ui-icon-pop-early 230ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-architecture .ink path:is(:nth-of-type(3), :nth-of-type(4)) {
    animation: ui-icon-draw-down 270ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-architecture .ink path:nth-of-type(2) {
    animation: ui-icon-pop 360ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-architecture .accent path {
    animation: ui-icon-pop 430ms ease-out;
}

/* Python: the two snakes (ink, accent) pull apart and lock back together. */
.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-python .ink {
    animation: ui-icon-part-up-left 360ms ease-in-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-python .accent {
    animation: ui-icon-part-down-right 360ms ease-in-out;
}

/* WebAPI: the brackets (ink 1, 2) spread; the slash (accent) tilts. */
.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-web-api .ink path:nth-of-type(1) {
    animation: ui-icon-nudge-left 320ms ease-in-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-web-api .ink path:nth-of-type(2) {
    animation: ui-icon-nudge-right 320ms ease-in-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-web-api .accent path {
    animation: ui-icon-tilt 320ms ease-in-out;
}

/* Library: the leaning book (ink 2) straightens up and settles back; the accent book lifts. */
.md-content .ui-cards .ui-icon-library .ink path:nth-of-type(2) {
    transform-origin: 0% 100%;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-library .ink path:nth-of-type(2) {
    animation: ui-icon-straighten 410ms ease-in-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-library .accent path {
    animation: ui-icon-lift 410ms ease-in-out;
}

/* User Stories: the speech bubble (accent) pops out from its tail; the head (ink 1) nods. */
.md-content .ui-cards .ui-icon-user-stories .accent path {
    transform-origin: 0% 100%;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-user-stories .accent path {
    animation: ui-icon-speak 290ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-user-stories .ink path:nth-of-type(1) {
    animation: ui-icon-nod 320ms ease-in-out;
}

/* Wiki Guide: the ribbon (accent) drops in from the top edge; the right page (ink 2) flutters at the spine. */
.md-content .ui-cards .ui-icon-wiki-guide .accent path {
    transform-origin: 50% 0%;
}

.md-content .ui-cards .ui-icon-wiki-guide .ink path:nth-of-type(2) {
    transform-origin: 0% 50%;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-wiki-guide .accent path {
    animation: ui-icon-drop 320ms ease-out;
}

.md-content .ui-cards > :is(ul, ol) > li:is(:hover, :focus-within) .ui-icon-wiki-guide .ink path:nth-of-type(2) {
    animation: ui-icon-page 360ms ease-in-out;
}

@keyframes ui-icon-swing {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-40deg); }
    50% { transform: rotate(24deg); }
    72% { transform: rotate(-10deg); }
    88% { transform: rotate(4deg); }
    100% { transform: rotate(0deg); }
}

@keyframes ui-icon-draw-up-right {
    from { clip-path: inset(100% 100% 0 0); }
    to { clip-path: inset(0 0 0 0); }
}

@keyframes ui-icon-draw-down {
    0%, 25% { clip-path: inset(0 0 100% 0); }
    100% { clip-path: inset(0 0 0 0); }
}

@keyframes ui-icon-land-right {
    0%, 55% { opacity: 0; transform: translateX(-1.2px); }
    100% { opacity: 1; transform: none; }
}

@keyframes ui-icon-pop {
    0%, 55% { transform: scale(1); }
    78% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

@keyframes ui-icon-pop-early {
    0% { transform: scale(1); }
    45% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes ui-icon-part-up-left {
    0%, 100% { transform: none; }
    45% { transform: translate(-1.4px, -1.4px); }
}

@keyframes ui-icon-part-down-right {
    0%, 100% { transform: none; }
    45% { transform: translate(1.4px, 1.4px); }
}

@keyframes ui-icon-nudge-left {
    0%, 100% { transform: none; }
    45% { transform: translateX(-1.6px); }
}

@keyframes ui-icon-nudge-right {
    0%, 100% { transform: none; }
    45% { transform: translateX(1.6px); }
}

@keyframes ui-icon-tilt {
    0%, 100% { transform: none; }
    45% { transform: rotate(16deg); }
}

@keyframes ui-icon-straighten {
    0%, 100% { transform: none; }
    45% { transform: rotate(-15deg); }
    70% { transform: rotate(3deg); }
}

@keyframes ui-icon-lift {
    0%, 100% { transform: none; }
    40% { transform: translateY(-1.8px); }
}

@keyframes ui-icon-speak {
    0% { opacity: 0.2; transform: scale(0.35); }
    60% { opacity: 1; transform: scale(1.12); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes ui-icon-nod {
    0%, 100% { transform: none; }
    35% { transform: translateY(0.9px); }
    65% { transform: translateY(-0.4px); }
}

@keyframes ui-icon-drop {
    0% { transform: scaleY(0.2); }
    60% { transform: scaleY(1.12); }
    100% { transform: scaleY(1); }
}

@keyframes ui-icon-page {
    0%, 100% { transform: none; }
    40% { transform: scaleX(0.84) skewY(-3deg); }
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Welcome hero (spec sections 17 and 0.8)
 * ------------------------------------------------------------------------------------------------------------------ */

.md-content .ui-hero {
    max-width: none;
    padding: 1rem 0 3rem;
    container-type: inline-size;
}

/* Sized to the hero's own width: the serif line is about 21 em wide, so 7cqi keeps it to two lines. */
.md-content .ui-hero h1 {
    max-width: none;
    margin: 0 0 2rem;
    font-size: clamp(2.25rem, 7cqi, 4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
}

.md-content .ui-hero h1 > span,
.md-content .ui-hero h1 > em {
    display: block;
}

.md-content .ui-hero h1 > em {
    margin-top: 0.12em;
    color: var(--ui-text-primary);
    font-family: var(--font-serif);
    font-size: 1.05em;
    font-style: italic;
    font-weight: 500;
    letter-spacing: -0.01em;
    line-height: 1.02;
}

.md-content .ui-hero p {
    max-width: 36rem;
    margin: 0;
    color: var(--ui-text-secondary);
    font-size: 1.125rem;
    line-height: 1.6;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Page footer: previous and next articles, then the meta lines
 * ------------------------------------------------------------------------------------------------------------------ */

.wiki-page-footer {
    max-width: none;
    margin-top: 5rem;
    color: var(--ui-text-muted);
}

.wiki-article-nav {
    margin-bottom: 2rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.md-content .wiki-article-nav-button {
    min-width: 0;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.375rem;
    color: var(--ui-text-primary);
    text-decoration: none;
    border: 1px solid var(--ui-border-subtle);
    transition: background-color var(--ui-transition);
}

.md-content .wiki-article-nav-button + .wiki-article-nav-button,
.md-content .wiki-article-nav-placeholder + .wiki-article-nav-button {
    margin-left: -1px;
}

.md-content .wiki-article-nav-button:hover {
    background: var(--ui-bg-surface-1);
    text-decoration: none;
}

.md-content .wiki-article-nav-button:focus-visible {
    outline-offset: -2px;
}

.wiki-article-nav-button-next {
    align-items: flex-end;
    text-align: right;
}

.wiki-article-nav-title {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-weight: 600;
    line-height: 1.35;
    transition: color var(--ui-transition);
}

.md-content .wiki-article-nav-button:hover .wiki-article-nav-title {
    color: var(--ui-accent);
}

.wiki-article-nav-symbol {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--ui-text-muted);
}

.wiki-article-nav-icon {
    display: block;
    width: 0.9em;
    height: 0.9em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.wiki-article-nav-label {
    color: var(--ui-text-muted);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.wiki-page-footer-separator {
    padding-top: 1.25rem;
    border-top: 1px solid var(--ui-border-subtle);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.7;
}

.wiki-page-footer p {
    margin-bottom: 0.75rem;
}

.wiki-page-footer p:last-child {
    margin-bottom: 0;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Scroll progress and the development notice
 * ------------------------------------------------------------------------------------------------------------------ */

.scroll-progress-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--wiki-scroll-progress-height);
    z-index: 3800;
    background: var(--ui-bg-base);
}

.scroll-progress-fill {
    width: 0;
    height: 100%;
    background: var(--ui-accent);
}

/*
 * The development notice: a floating window at the bottom right, flat and square, with a title bar. The same message
 * sits permanently at the bottom of the sidebar (.wiki-sidebar-notice).
 */
.wiki-dev-notice-banner {
    position: fixed;
    right: 1.5rem;
    bottom: calc(1.5rem + var(--wiki-scroll-progress-height));
    z-index: 3500;
    width: min(24rem, calc(100vw - 2rem));
    background: var(--ui-bg-surface-1);
    border: 1px solid var(--ui-border-interactive);
}

.wiki-dev-notice-banner[hidden] {
    display: none;
}

.wiki-dev-notice-title {
    height: 2.75rem;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    color: var(--ui-text-primary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--ui-border-subtle);
}

.wiki-dev-notice-text {
    padding: 1rem 1.25rem 0;
    color: var(--ui-text-secondary);
    font-size: 0.875rem;
    line-height: 1.55;
}

.wiki-dev-notice-banner-actions {
    padding: 1rem 1.25rem 1.25rem;
}

.wiki-dev-notice-link,
.wiki-sidebar-notice a {
    color: var(--ui-accent);
    text-decoration: none;
}

.wiki-dev-notice-link:hover,
.wiki-sidebar-notice a:hover {
    text-decoration: underline;
}

.wiki-dev-notice-ok {
    min-height: 2rem;
    color: var(--ui-bg-base);
    background: var(--ui-text-primary);
    border-color: var(--ui-text-primary);
}

.wiki-dev-notice-ok:hover {
    color: var(--ui-text-primary);
    background: transparent;
}

/* The same notice at the bottom of the sidebar, above the tool row. */
.wiki-sidebar-notice {
    padding: 1rem 1.25rem 1.125rem;
    flex-shrink: 0;
    box-shadow: inset 0 1px 0 var(--ui-border-subtle);
}

.wiki-sidebar-notice-title {
    margin-bottom: 0.5rem;
    color: var(--ui-text-primary);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    line-height: 1.3;
    text-transform: uppercase;
}

.wiki-sidebar-notice-text {
    color: var(--ui-text-muted);
    font-size: 0.8125rem;
    line-height: 1.5;
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Responsive behaviour
 * ------------------------------------------------------------------------------------------------------------------ */

/* Below 1280px the table of contents gives its width to the article. */
@media (max-width: 1280px) {
    .wiki-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .wiki-page-shell .menu-content {
        max-width: var(--wiki-article-max-width);
    }

    .menu-column-toc {
        display: none;
    }
}

/* Below 1081px the sidebar becomes a drawer (wiki-shell.js); the desktop collapse control does not apply. */
@media (max-width: 1080px) {
    .wiki-sidebar {
        width: var(--wiki-sidebar-width);
        border-right: 1px solid var(--ui-border-subtle);
        box-shadow: none;
        transform: translateX(-100%);
        transition: transform 180ms ease;
    }

    :root[data-sidebar-collapsed="true"] .wiki-sidebar {
        width: var(--wiki-sidebar-width);
    }

    :root[data-sidebar-collapsed="true"] .wiki-sidebar-header,
    :root[data-sidebar-collapsed="true"] .wiki-sidebar-body {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transition-delay: 0s;
    }

    :root[data-sidebar-collapsed="true"] .wiki-sidebar-tools {
        width: var(--wiki-sidebar-width);
        box-shadow: inset 0 1px 0 var(--ui-border-subtle);
    }

    .wiki-sidebar-collapse {
        display: none;
    }

    body.wiki-sidebar-open {
        overflow: hidden;
    }

    body.wiki-sidebar-open .wiki-sidebar {
        transform: translateX(0);
    }

    .wiki-sidebar-close {
        display: inline-flex;
    }

    .wiki-sidebar-toggle {
        position: fixed;
        top: calc((var(--wiki-bar-height) - 2.25rem) / 2);
        left: 1rem;
        z-index: 3650;
        width: 2.25rem;
        height: 2.25rem;
        display: inline-flex;
    }

    .wiki-sidebar-scrim {
        position: fixed;
        inset: 0 0 var(--wiki-scroll-progress-height);
        z-index: 3660;
        display: block;
        background: var(--ui-scrim);
    }

    .wiki-sidebar-scrim[hidden] {
        display: none;
    }

    .wiki-page-shell,
    :root[data-sidebar-collapsed="true"] .wiki-page-shell {
        margin-left: 0;
    }

    .wiki-page-shell .menu-content {
        max-width: none;
        border-left: 0;
        border-right: 0;
    }

    /* The bar makes room for the drawer button at its left. */
    .menu-column-header {
        padding-left: calc(1rem + 2.25rem + 1rem);
    }

}

@media (max-width: 719px) {
    .md-content .likec4-figure-canvas > likec4-view {
        min-width: 640px;
    }

    .md-content .likec4-figure-hint {
        display: block;
    }
}

@media (max-width: 640px) {
    :root {
        --wiki-gutter: 1rem;
    }

    .md-content h1 {
        font-size: 2rem;
    }

    .md-content h2 {
        margin-top: 3rem;
        font-size: 1.5rem;
    }

    .md-content.wiki-overview > h2[data-note]::after {
        display: none;
    }

    .wiki-article-nav {
        grid-template-columns: minmax(0, 1fr);
    }

    .md-content .wiki-article-nav-button + .wiki-article-nav-button {
        margin-left: 0;
        margin-top: -1px;
    }

    .md-content .wiki-article-nav-placeholder {
        display: none;
    }

    .md-content .wiki-article-nav-placeholder + .wiki-article-nav-button {
        margin-left: 0;
    }

    .wiki-dev-notice-banner {
        right: 1rem;
        bottom: calc(1rem + var(--wiki-scroll-progress-height));
    }
}

/* ---------------------------------------------------------------------------------------------------------------------
 * Motion: none for visitors who ask for less
 * ------------------------------------------------------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}
