/* jetbundle-orchestrate: tokens import */
@import url("./_style/tokens.css");

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

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
    line-height: 1.65;
    color: var(--fg);
    background: var(--bg);
}

a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--link-hover);
}

/* warm lineage links: use the palette gold (link-hover) */
a.link-orange {
    color: var(--link-hover);
}

a.link-orange:hover {
    color: var(--heading);
}

.wrap {
    max-width: 52ch;
    margin: 0 auto;
    padding: 3rem 1.25rem 4rem;
}

.stub {
    max-width: 52ch;
    margin: 0 auto;
    padding: 3rem 1.25rem;
}

.brand {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.22em;
    color: var(--heading);
}

.tagline {
    margin: 0 0 2rem;
    color: var(--dim);
    font-size: 0.95rem;
}

.block {
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
}

.stub h1 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--heading);
    letter-spacing: 0.06em;
}

.stub p {
    margin: 0 0 1rem;
    color: var(--dim);
    font-size: 0.95rem;
}

.back {
    margin-top: 1.5rem;
    font-size: 0.95rem;
}

.dim {
    color: var(--dim);
}

.fg {
    color: var(--fg);
    font-size: 0.95rem;
    line-height: 1.7;
}

.subnav {
    margin: 0 0 1.5rem;
    font-size: 0.9rem;
    color: var(--dim);
}

.subnav-sep {
    margin: 0 0.5rem;
    color: var(--dim);
}

/* Page shell is wide enough for figures; prose is narrowed separately. */
.doc {
    max-width: min(1180px, calc(100vw - 1.5rem));
    margin: 0 auto;
    padding: 2.5rem 1.25rem 4rem;
    overflow-x: visible;
}

/* Keep reading measure for prose; plots fill the shell width.
   Prose is horizontally centered in the wide shell (do NOT use margin shorthand
   later — it would zero margin-left/right and break centering).
   Includes hub-page intros that sit as direct children of main.doc. */
main.doc > .subnav,
main.doc > .doc-header,
main.doc > .doc-intro,
main.doc > .doc-rule,
main.doc > .doc-footer,
main.doc > .toc,
main.doc > p,
main.doc .doc-body > h2,
main.doc .doc-body > h3,
main.doc .doc-body > p,
main.doc .doc-body > figure,
main.doc .doc-body > ul,
main.doc .doc-body > ol,
main.doc .doc-body > table,
main.doc .doc-body > blockquote,
main.doc .doc-section > h2,
main.doc .doc-section > h3,
main.doc .doc-section > p,
main.doc .doc-section > ul,
main.doc .doc-section > ol,
main.doc .doc-section > table,
main.doc .doc-section > blockquote,
main.doc .doc-section > .spine-rail,
main.doc .doc-section > .toc-list {
    max-width: 68ch;
    margin-left: auto;
    margin-right: auto;
}

/* Hub/index intros share the same column as body copy */
main.doc > .doc-intro {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--fg);
}

.doc-header {
    margin-bottom: 2rem;
}

.doc-header h1 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--heading);
}

.doc-lead {
    margin: 0 0 1rem;
    color: var(--dim);
    font-size: 0.95rem;
}

.doc-intro {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    line-height: 1.7;
}

.toc {
    margin: 0 0 2rem;
    padding: 1rem 0 0;
}

.toc-title {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--dim);
}

.toc-list {
    margin: 0;
    padding-left: 1.35rem;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--fg);
}

.toc-list a {
    color: var(--link);
}

.doc-rule {
    border: none;
    border-top: 1px solid #222;
    margin: 0 0 2rem;
}

.doc-body {
    margin: 0;
}

/* definitions and labeled items: bold + underline for scanability */
main.doc .doc-body strong {
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 0.12em;
}

.doc-section {
    margin: 0 0 2.25rem;
    scroll-margin-top: 1.25rem;
}

.doc-section h2 {
    margin-top: 0;
    margin-bottom: 0.65rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--link);
    letter-spacing: 0.04em;
}

.doc-section p {
    margin-top: 0;
    margin-bottom: 0.95rem;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--fg);
}

.doc-section p:last-child {
    margin-bottom: 0;
}

.doc-section ol {
    margin-top: 0.5rem;
    margin-bottom: 0.85rem;
    /* horizontal centering from main.doc rules; indent via padding */
    padding-left: 1.35rem;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--fg);
}

.doc-section ol li {
    margin: 0.35rem 0;
}

.doc .katex {
    font-size: 1em;
    color: var(--fg);
}

.doc-section h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--link-hover);
    letter-spacing: 0.03em;
}

.doc-section table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.9rem 0 0;
    font-size: 0.9rem;
}

.doc-section th,
.doc-section td {
    border: 1px solid #222;
    padding: 0.55rem 0.6rem;
    vertical-align: top;
}

.doc-section th {
    color: var(--heading);
    font-weight: 600;
}

.doc-footer {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #222;
}

.doc-footer p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--dim);
    line-height: 1.65;
}

/* optional easter-egg / bonus outline entry */
.toc-bonus {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px dashed #333;
}

.toc-bonus a {
    color: var(--dim);
    font-size: 0.88rem;
}

.toc-bonus a:hover {
    color: var(--link);
}

/* architecture-linearity book: spine rails + ledger tables */
.spine-rail {
    margin: 0 0 1.25rem;
    padding: 0.65rem 0 0.65rem 0.85rem;
    border-left: 3px solid color-mix(in srgb, var(--link) 55%, transparent);
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--fg);
}

.spine-rail strong {
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 0.12em;
}

.spine-map {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 1.5rem;
    font-size: 0.88rem;
    line-height: 1.55;
}

.spine-map th,
.spine-map td {
    border: 1px solid #222;
    padding: 0.5rem 0.55rem;
    vertical-align: top;
    text-align: left;
}

.spine-map th {
    color: var(--heading);
    font-weight: 600;
    letter-spacing: 0.06em;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.spine-map td {
    color: var(--fg);
}

.spine-map td.dim {
    color: var(--dim);
    font-size: 0.85rem;
}

/* chapters: headings directly under .doc-body (no .doc-section wrapper) */
main.doc .doc-body>h2 {
    margin-top: 1.6rem;
    margin-bottom: 0.55rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--link);
    letter-spacing: 0.04em;
}

main.doc .doc-body>h2:first-child {
    margin-top: 0;
}

main.doc .doc-body>.spine-rail+h2 {
    margin-top: 0.75rem;
}

main.doc .doc-body>h3 {
    margin-top: 1.1rem;
    margin-bottom: 0.45rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--link-hover);
    letter-spacing: 0.03em;
}

main.doc .doc-body>p,
main.doc .doc-body>ul,
main.doc .doc-body>ol {
    margin-top: 0;
    margin-bottom: 0.85rem;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--fg);
}

main.doc .doc-body>ul,
main.doc .doc-body>ol {
    padding-left: 1.35rem;
}

main.doc .doc-body li {
    margin: 0.3rem 0;
}

/* architecture-linearity book landing */
.architecture-landing {
    position: relative;
    z-index: 1;
    max-width: 72ch;
    margin: 0 auto;
    padding: 3rem 1.25rem 4rem;
}

.architecture-landing__bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.11;
}

.architecture-landing__bg canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.architecture-landing h1 {
    margin: 0 0 0.75rem;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--heading);
}

.architecture-landing .doc-lead {
    margin: 0 0 1.25rem;
    color: var(--dim);
    font-size: 0.95rem;
}

.architecture-landing .doc-intro {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    line-height: 1.75;
}

.architecture-landing .toc-list {
    margin: 1rem 0 0;
    padding-left: 1.35rem;
    font-size: 0.95rem;
    line-height: 1.75;
}

/* computation treatise */
.invariant {
    color: var(--fg);
    font-style: italic;
    border-left: 3px solid color-mix(in srgb, var(--link) 55%, transparent);
    padding-left: 0.85rem;
}

.invariant-block {
    margin: 0.85rem 0 0;
    padding: 0.65rem 0.85rem;
    background: var(--panel);
    border-left: 3px solid var(--link);
    color: var(--fg);
    font-size: 0.95rem;
    line-height: 1.7;
}

.toc-lab {
    margin-top: 0.75rem;
    padding-top: 0.65rem;
    border-top: 1px dashed #333;
}

.toc-lab a {
    color: var(--link-hover);
}

.code-panel {
    margin: 0.85rem 0;
    padding: 0.75rem 0.9rem;
    background: var(--panel);
    border: 1px solid #222;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--fg);
    overflow-x: auto;
}

.code-panel code {
    font-family: inherit;
}

.code-panel--compact {
    margin-bottom: 0.65rem;
}

.hierarchy-panel {
    margin: 0.85rem 0;
    padding: 0.85rem 1rem;
    background: var(--panel);
    border: 1px solid #222;
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--dim);
}

.warn-text {
    color: var(--warn);
    font-size: 0.95rem;
    margin: 0.75rem 0 0;
}

.widget-panel {
    margin: 1.25rem 0 0;
    padding: 1rem;
    background: var(--panel);
    border: 1px solid #222;
}

.widget-label {
    margin: 0 0 0.65rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--link);
}

.widget-controls {
    margin: 0.75rem 0 0;
}

.widget-btn {
    font-family: inherit;
    font-size: 0.88rem;
    padding: 0.35rem 0.75rem;
    margin-right: 0.5rem;
    color: var(--fg);
    background: #111;
    border: 1px solid #333;
    cursor: pointer;
}

.widget-btn:hover:not(:disabled) {
    color: var(--link-hover);
    border-color: var(--link);
}

.widget-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.widget-btn--dim {
    color: var(--dim);
}

.memory-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.memory-table th,
.memory-table td {
    border: 1px solid #222;
    padding: 0.45rem 0.55rem;
    text-align: left;
}

.memory-table th {
    color: var(--heading);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
}

.memory-row--flash td {
    color: var(--link-hover);
}

/* computational laboratory */
.lab-shell {
    max-width: 96ch;
    margin: 0 auto;
    padding: 2.5rem 1.25rem 4rem;
}

.lab-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
        "theory terminal"
        "viz viz";
}

.lab-pane {
    padding: 1rem;
    background: var(--panel);
    border: 1px solid #222;
}

.lab-pane--theory {
    grid-area: theory;
}

.lab-pane--terminal {
    grid-area: terminal;
}

.lab-pane--viz {
    grid-area: viz;
}

.lab-pane-title {
    margin: 0 0 0.65rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--link);
}

.lab-module-list {
    margin: 0;
    padding-left: 1.25rem;
    font-size: 0.9rem;
    line-height: 1.75;
}

.lab-module-list a {
    color: var(--link);
}

.lab-active {
    color: var(--link-hover) !important;
    font-weight: 600;
}

.lab-terminal {
    margin: 0;
    min-height: 8rem;
}

#lab-terminal-mount {
    height: 220px;
    padding: 0.35rem;
    background: #000;
    border: 1px solid #222;
}

.terminal-status {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
}

.lab-treatise-link {
    font-size: 0.8rem;
    text-decoration: none;
}

.lab-viz-stack {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.widget-btn--active {
    color: var(--link-hover);
    border-color: var(--link-hover);
}

.ca-canvas,
.euler-canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    background: #000;
    border: 1px solid #222;
}

.entropy-bar {
    height: 8px;
    background: #111;
    border: 1px solid #222;
    margin: 0.5rem 0;
}

.entropy-bar-fill {
    height: 100%;
    width: 0;
    background: var(--link);
    transition: width 0.2s ease;
}

.entropy-input {
    width: 100%;
    font-family: inherit;
    font-size: 0.88rem;
    padding: 0.5rem;
    color: var(--fg);
    background: #000;
    border: 1px solid #222;
    resize: vertical;
}

.entropy-stats {
    font-size: 0.88rem;
    margin: 0.35rem 0;
}

.euler-status {
    font-size: 0.88rem;
    margin: 0.5rem 0 0;
}

.euler-status--ok {
    color: var(--link);
}

.euler-status--bad {
    color: var(--warn);
}

.euler-dt-row {
    margin: 0.5rem 0;
    font-size: 0.88rem;
}

.euler-dt-row input[type="range"] {
    width: 100%;
    accent-color: var(--link);
}

.rep-tabs {
    margin-bottom: 0.5rem;
}

.rep-lang-name {
    font-size: 0.85rem;
    color: var(--link-hover);
    margin: 0 0 0.35rem;
}

.critique-list {
    margin: 0.5rem 0 0.85rem 1.35rem;
    padding: 0;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--fg);
}

.critique-list li {
    margin: 0.4rem 0;
}

.widget-panel--compact {
    padding: 0.75rem;
    margin-top: 0.85rem;
}

.arch-row--active td {
    color: var(--link-hover);
    background: #111;
}

.hierarchy-list {
    list-style: none;
    margin: 0 0 0.75rem;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.hierarchy-btn {
    font-family: inherit;
    font-size: 0.82rem;
    padding: 0.3rem 0.55rem;
    color: var(--dim);
    background: #111;
    border: 1px solid #333;
    cursor: pointer;
}

.hierarchy-btn:hover,
.hierarchy-btn--active {
    color: var(--link-hover);
    border-color: var(--link-hover);
}

.hierarchy-eq {
    min-height: 2.5rem;
    padding: 0.5rem 0;
}

.doc-footer--egg {
    font-size: 0.88rem;
    line-height: 1.7;
}

.doc-footer--egg p {
    color: var(--dim);
}

@media (max-width: 720px) {
    .lab-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "theory"
            "terminal"
            "viz";
    }
}

/* mechanics chapter interactive figures — full shell width (prose stays 68ch) */
main.doc .doc-widget {
    width: 100%;
    max-width: none;
    margin: 1.45rem 0 1.75rem;
    padding: 0.9rem 1rem 1.05rem;
    border: 1px solid #222;
    background: #000;
    overflow: hidden;
    box-sizing: border-box;
}

/* fallback when not under main.doc */
.doc-widget {
    margin: 1.1rem 0 1.35rem;
    padding: 0.75rem 0.85rem 0.85rem;
    border: 1px solid #222;
    background: #000;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.doc-widget-title {
    margin: 0 0 0.4rem;
    font-size: 0.84rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--link);
    overflow-wrap: anywhere;
}

.doc-widget-caption {
    margin: 0 0 0.75rem;
    font-size: 0.86rem;
    line-height: 1.55;
    color: var(--dim);
    overflow-wrap: anywhere;
    max-width: 88ch;
}

.doc-widget canvas,
.doc-widget-plot {
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 420px;
    height: clamp(420px, 46vw, 620px);
    border: 1px solid #1a1a1a;
    background: #000;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
}

/* dual-panel / 3D figures need extra vertical room */
.doc-widget-plot.tall {
    height: clamp(500px, 52vw, 700px);
    min-height: 500px;
}

.doc-widget-plot .js-plotly-plot,
.doc-widget-plot .plot-container,
.doc-widget-plot .svg-container {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
}

.doc-widget-plot .main-svg {
    overflow: hidden !important;
}

.doc-widget-plot .legend {
    max-width: 100% !important;
}

.doc-widget-plot .modebar {
    top: 4px !important;
    right: 4px !important;
    max-width: calc(100% - 8px) !important;
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 3;
}

.doc-widget-readout .katex {
    font-size: 1em;
}

.doc-widget-readout .katex-display {
    margin: 0.2em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.doc-widget-plot .modebar-btn path {
    fill: #6a6a6a !important;
}

.doc-widget-plot .modebar-btn:hover path {
    fill: #ae93ec !important;
}

.doc-widget-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.15rem;
    margin: 0.75rem 0 0.4rem;
    font-size: 0.86rem;
    color: var(--dim);
    max-width: 100%;
    box-sizing: border-box;
}

.doc-widget-controls label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    flex: 1 1 9rem;
    max-width: 18rem;
}

.doc-widget-controls select {
    font: inherit;
    color: var(--fg);
    background: #000;
    border: 1px solid #222;
    padding: 0.25rem 0.35rem;
    max-width: 100%;
    box-sizing: border-box;
}

.doc-widget-controls input[type="range"] {
    width: 100%;
    max-width: 100%;
    accent-color: var(--link);
    box-sizing: border-box;
}

.doc-widget-controls button,
.doc-widget-button {
    align-self: flex-end;
    font: inherit;
    font-size: 0.86rem;
    color: var(--fg);
    background: #000;
    border: 1px solid #333;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    flex: 0 0 auto;
}

.doc-widget-controls button:hover,
.doc-widget-button:hover {
    border-color: var(--link);
    color: var(--link);
}

.doc-widget-readout {
    margin: 0.45rem 0 0;
    font-size: 0.82rem;
    color: var(--fg);
    line-height: 1.55;
    max-width: 100%;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* KaTeX MathML is screen-reader only; never participate in layout overflow */
.doc-widget .katex-mathml {
    position: absolute !important;
    clip: rect(0, 0, 0, 0) !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    white-space: nowrap !important;
}

@media (max-width: 720px) {
    .doc {
        max-width: 100%;
        padding: 1.5rem 0.85rem 3rem;
    }

    main.doc .doc-widget {
        margin: 1.1rem 0 1.35rem;
        padding: 0.6rem 0.55rem 0.75rem;
    }

    .doc-widget-controls label {
        flex: 1 1 100%;
        max-width: 100%;
    }

    .doc-widget-plot {
        height: clamp(360px, 78vw, 480px);
        min-height: 360px;
    }

    .doc-widget-plot.tall {
        height: clamp(420px, 88vw, 560px);
        min-height: 420px;
    }
}

/* finance reading list: book covers after the matching paragraph */
main.doc .doc-body > figure.book-cover {
    margin: 0.65rem auto 1.35rem;
    max-width: 220px;
    width: 220px;
    text-align: center;
}

main.doc .doc-body > figure.book-cover img {
    display: block;
    width: 220px;
    max-width: 100%;
    height: auto;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid color-mix(in srgb, var(--fg) 12%, transparent);
    box-shadow: 0 2px 10px color-mix(in srgb, #000 18%, transparent);
}

main.doc .doc-body > figure.book-cover figcaption {
    margin-top: 0.35rem;
    font-size: 0.72rem;
    line-height: 1.3;
    color: color-mix(in srgb, var(--fg) 62%, transparent);
    text-align: center;
}


/* optional theme toggle (default remains dark) */
.theme-toggle {
    position: fixed;
    right: 0.85rem;
    bottom: 0.85rem;
    z-index: 60;
    margin: 0;
    padding: 0.3rem 0.55rem;
    font: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    line-height: 1.2;
    color: var(--dim);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    border: 1px solid var(--wireframe);
    cursor: pointer;
}

.theme-toggle:hover {
    color: var(--link-hover);
    border-color: color-mix(in srgb, var(--link-hover) 45%, var(--wireframe));
}

.theme-toggle:focus-visible {
    outline: 1px solid var(--link);
    outline-offset: 2px;
}
