
:root {
    background: var(--text-background);
    color: var(--text-color);
    line-height: 1.6em;
    margin: 0;
    font-family: var(--text-font);
    font-size: clamp(10px, 1vw, 24px);
    --nav-col-width: clamp(32px, 5vw, 80px);
    --scrollbar-width: 4px;
}

html, body{
    background: #1e2129; /* prevent navigation flash */
    height: 100%;
    margin: 0;
    overflow: hidden;
}

[data-theme="dark"] body, [data-theme="dark"] html { background: #1e2129; }
[data-theme="light"] body, [data-theme="light"] html { background: #ffffff !important; }

body {
    display: grid;
    grid-template-rows: 2em 3em 1fr;
    grid-template-areas: "top-buttons"
                         "top-menu"
                         "body-content";
    min-height: 0;
}

#top-buttons {
    grid-area: top-buttons;
    background: var(--menu-background);
    display: flex;
    align-items: center;
    gap: 0.4em;
    padding: 0 0.5em 0 1rem;
}

#toc-button,
#theme-button {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--h2-color);
    font-size: inherit;
    width: 1.28em;
    height: 1.28em;
}

#toc-button svg,
#theme-button svg {
    width: 100%;
    height: 100%;
}

#toc-button:before,
#theme-button:before {
    content: none;
}

table {
    color: var(--text-color);
}

tr {
    vertical-align: baseline;
}

td, th {
    padding: 0 1rem;
}

#preamble {
    grid-area: top-menu;
    background: var(--menu-background);
    display: flex;
} 

.top-menu {
    padding: 0.5em 1em 0.5em 1rem;
    align-self: flex-end;
    font-size: 1.2em;
}

nav h2 {
    display: inline-block;
    margin: 0;
    padding: 0 0 0 1rem;
    font-size: 1.2rem;
}



header {
    /* grid-area: menul; */
    /* background: #1a1c23; */
    padding-left: 1em;
    display: none;
}

#content {
    grid-area: body-content;
    min-height: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-rows: 1fr;
    grid-template-columns: var(--toc-col-width, auto) 1fr;
    grid-template-areas: "nav content";
}

#/*TODO: */able-of-contents {
    grid-area: nav;
    /* transition: all 500ms; */
    /* background: #181a21; */
    /* background: #1b1e25; */
    background: var(--toc-background);
    height: 100%;
    padding-left: 1em;
}

#table-of-contents {
    grid-area: nav;
    width: var(--clamps-dict-toc-width);
    background: var(--toc-background);
    min-height: 0;
    overflow: auto;
    padding-left: 0;
}

.toc-open {
    width: var(--clamps-dict-toc-width);
}

.toc-closed {
    display: none;
}

#page-main-body {
    grid-area: content;
    min-height: 0;
    display: flex;
    overflow: auto;
    scrollbar-gutter: stable;
    padding: 0;
}

#search{
    grid-area: nav;
    height: 1em;
    background: var(--search-background);
}

#page-text-body {
    display: block;
    flex: 1;
    min-width: 0;
    padding: 0;
    overflow: unset;
    box-sizing: border-box;
}


#nav-left {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    height: 100vh;
    width: var(--nav-col-width);
    position: sticky;
    top: 0;
    flex-shrink: 0;
    min-width: var(--nav-col-width);
    color: var(--nav-color);
}

#nav-right {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    height: 100vh;
    width: var(--nav-col-width);
    position: sticky;
    top: 0;
    flex-shrink: 0;
    min-width: var(--nav-col-width);
    color: var(--nav-color);
}



.top-menu-active:hover {
    color: var(--anchor-active);
}


.top-menu-active {
    color: var(--anchor-active);
}

.org-ul {
    padding-left: 1em;
    list-style-type: disc;

}

a {
    color: var(--anchor-toc);
    text-decoration: none;
}


a:hover, i.angle-left:hover, i.angle-right:hover {
    color: var(--anchor-hover);
    text-decoration: none;
}


h1.title {
    line-height: 1.3em;
    font-size: 2em;
    font-weight: normal;
    text-align: left;
//    padding-left: 11em;
}

.title {
    color: var(--title-color);
    font-size: 1em;
    font-weight: normal;
    text-align: left;
    line-height: 6.3 em;
}

.ul-toc-level-1 {
    padding-left: 1rem;
    margin-left: 0;
    list-style-type: none;
}

.ul-toc-level-2 {
    padding-left: 1rem;
    margin-left: 0;
    list-style-type: none;
}

.ul-toc-level-3 {
    padding-left: 2rem;
    margin-left: 0;
    list-style-type: none;
}

.ul-toc-level-4 {
    padding-left: 3rem;
    margin-left: 0;
    list-style-type: none;
}

#text-table-of-contents {
    line-height: 1.3em;
    overflow: hidden;
    white-space: nowrap;
}

sup {
    vertical-align: top;
    position: relative;
    top: -0.5em;
}

ul {
    padding-left: 1rem;
    margin-left: 0;
    list-style-type: none;
}

h1 {
    display: none;
}

h2 {
    font-size: 2em;
    display: none;
}

h3 {
    font-size: 1.8em;
}

h4 {
    font-size: 1.5em;
}

h5 {
    font-size: 1.3em;
}


h2, h3, h4, h5 {
    color: var(--h2-color);
    font-weight: normal;
    line-height: 1.3em;
}

pre.src-lisp::before {
  content: 'Common Lisp';
}

pre.src::before {
  display: none;
  position: absolute;
  background-color: var(--code-background);
  top: -10px;
  right: 10px;
  padding: 3px;
  border: 1px solid var(--code-border-before);
  color: var(--code-text);
}



pre {
  border: 1px solid var(--code-border);
  box-shadow: none;
  padding: 8pt;
  background-color: var(--code-background);
    padding-top: 8pt;
  font-family: monospace;
  overflow: auto;
  margin: 1.2em;
  color: var(--code-text);
}

img {
    background: var(--img-background);
}

.outline-4, .outline-3, .outline-2, .outline-1 {
//    overflow: auto;
}



a.nav-left {
    display: flex;
    width: 100%;
        justify-content: center;
    align-items: center;
    color: var(--nav-color);
}

a.nav-left:hover, a.nav-right:hover, a.nav-up:hover {
    /* color: #5e8bde; */
    color: var(--nav-hover);
}

a.nav-right::before {
    accesskey: 'n';
}

a.nav-right {
    display: flex;
    width: 100%;
        justify-content: center;
    align-items: center;
    color: var(--nav-color);
}

i.angle-left::before { content: none; }

i.angle-right::before { content: none; }

i.angle-left, i.angle-right {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(20px, 3vw, 56px);
    height: clamp(20px, 3vw, 56px);
    color: var(--nav-color);
}

i.angle-left svg, i.angle-right svg {
    width: clamp(20px, 3vw, 56px);
    height: clamp(20px, 3vw, 56px);
}


i {
    color: var(--i-color);
    font-style: normal;
}

code {
    color: var(--arg-color);
}

#postamble {
    width: 100%;
    height: auto;
    background: var(--menu-background);
    display: flex;
    align-items: center;
    gap: 1.5em;
    padding: 0.2em 0.6em;
    font-size: 0.65em;
}

#postamble p {
    margin: 0;
}

#postamble .validation {
    display: none;
}

#header::before, #header::after, #content::before, #content::after, #footnotes::before, #footnotes::after, #footer::before, #footer::after {
  /* content: " "; */
  /* display: table; */

}

code {
    var(--i-color);    
}

#org-div-nav-menu {
    display: none;
}

.toc-active:hover {
    color: var(--anchor-active);
}


.toc-active {
    color: var(--anchor-active);
}

.toc-hidden {
    display: none;
}

.toc-level-2.toc-hidden {
    display: list-item;
}


.toc-level-1 a {
    color: var(--h2-color);
    pointer-events: none;
}

.toc-level-2 .toc-entry {
    color: var(--anchor-toc);
    pointer-events: auto;
}

.toc-level-2 .toc-entry:hover {
    color: var(--anchor-hover);
    pointer-events: auto;
}

.toc-level-2 .toc-active {
    color: var(--anchor-active);
    pointer-events: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.toc-level-2 .toc-active:hover {
    color: var(--anchor-active);
}

.ul-toc-level-3 {
    /* display: none; */
}
.toc-level-1 {
    margin-top: 0.5em;
    font-size: 1.6em;
    font-weight: bold;
    line-height: 1.6em;
}

.toc-level-2 {
    font-size: 0.625em;
    font-weight: normal;
    line-height: 1.2em;
}


.toc-active {
    color: orange;
}


.toc-active a:hover {
    color: orange;
}

.toc-entry {
    overflow: hidden;
    text-overflow: ellipsis;
    display:inline-block;
    white-space: nowrap;
    max-width: 100%;
}

#footnotes {
  margin-top: 5em;
  border-top: 1pt solid (--footnote-separator);
}

.footpara {
    display: inline;
}

/* Mobile layout — applied immediately via JS before first paint */
html.mobile-layout #page-main-body {
    flex-wrap: wrap;
}
html.mobile-layout #page-text-body {
    order: 1;
    flex: none;
    width: 100%;
    padding: 0 8px;
}
html.mobile-layout #nav-left {
    order: 2;
    flex: 1;
    height: auto;
    width: auto;
    min-width: 0;
    position: static;
    flex-direction: row;
    justify-content: flex-start;
    padding: 0.5em 1em;
}
html.mobile-layout #nav-right {
    order: 3;
    flex: 1;
    height: auto;
    width: auto;
    min-width: 0;
    position: static;
    flex-direction: row;
    justify-content: flex-end;
    padding: 0.5em 1em;
}
html.mobile-layout a.nav-left,
html.mobile-layout a.nav-right {
    width: auto;
    height: auto;
}

html.mobile-layout {
    font-size: clamp(20px, 2vw, 48px) !important;
}

/* Mobile font size — targets phones regardless of JS detection */
@media screen and (max-device-width: 1024px) and (pointer: coarse) {
    :root {
        font-size: clamp(20px, 2vw, 48px) !important;
    }
}

/* Mobile scrolling layout */
html.mobile-layout,
html.mobile-layout body {
    position: relative;
    overflow: auto !important;
    height: auto !important;
    min-height: 100% !important;
}

html.mobile-layout body {
    position: relative;
    display: block !important;
    min-height: 100vh !important;
}

html.mobile-layout #content,
html.mobile-layout #cm-outer-content {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
}

html.mobile-layout #table-of-contents {
    display: none !important;
}

html.mobile-layout #page-main-body {
    display: flex !important;
    flex-wrap: wrap !important;
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
}

html.mobile-layout #page-text-body {
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
}

/* Mobile menu button — hidden on desktop, shown on mobile in top-buttons */
#menu-button {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--h2-color);
    font-size: inherit;
    width: 1.28em;
    height: 1.28em;
    padding: 0;
    margin-left: auto;
    flex-shrink: 0;
}
#menu-button svg { width: 100%; height: 100%; }

html.mobile-layout #menu-button { display: flex !important; }
@media (pointer: coarse) { #menu-button { display: flex !important; } }
@media (pointer: coarse) { #preamble > a.top-menu { display: none !important; } }
html.mobile-layout #preamble > a.top-menu { display: none !important; }

/* Popup — fixed position top right */
#mobile-menu-popup {
    display: none !important;
    position: fixed;
    top: 5em;
    right: 0;
    z-index: 9999;
    background: var(--menu-background);
    border: 1px solid var(--h2-color);
    padding: 0.5em 0;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    flex-direction: column;
}
#mobile-menu-popup.open { display: flex !important; }
#mobile-menu-popup a {
    display: block !important;
    padding: 0.8em 1.5em !important;
    font-size: 1.4em !important;
    color: var(--anchor-toc) !important;
    text-decoration: none !important;
    border-bottom: 1px solid var(--h2-color);
    white-space: nowrap;
}
#mobile-menu-popup a:last-child { border-bottom: none; }
#mobile-menu-popup a.top-menu-active { color: var(--anchor-active) !important; }

/* Mobile TOC: show as overlay when toggled */
html.mobile-layout #table-of-contents {
    display: none !important;
    position: fixed !important;
    top: 5em !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 80vw !important;
    max-width: 320px !important;
    z-index: 9998 !important;
    overflow-y: auto !important;
    box-shadow: 4px 0 12px rgba(0,0,0,0.5) !important;
}
html.mobile-layout #table-of-contents.toc-open {
    display: block !important;
}
html.mobile-layout .toc-closed {
    display: none !important;
}
/* Overlay backdrop */
#mobile-toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9997;
    background: rgba(0,0,0,0.4);
}
#mobile-toc-overlay.open { display: block; }

@media (pointer: coarse) {
    #page-text-body { padding: 0 8px !important; }
}

/* TOC overlay for coarse pointer devices (fallback for mobile-layout class) */
@media (pointer: coarse) {
    #table-of-contents {
        display: none !important;
        position: fixed !important;
        top: 5em !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 80vw !important;
        max-width: 320px !important;
        z-index: 9998 !important;
        overflow-y: auto !important;
        box-shadow: 4px 0 12px rgba(0,0,0,0.5) !important;
        background: var(--toc-background) !important;
    }
    #table-of-contents.toc-open {
        display: block !important;
    }
}

[data-theme="light"] html.mobile-layout body,
[data-theme="light"] html.mobile-layout { background: #ffffff !important; }
[data-theme="dark"] html.mobile-layout body,
[data-theme="dark"] html.mobile-layout { background: #1e2129 !important; }

/* Thin scrollbar — hidden until hover (Chromium) */
::-webkit-scrollbar {
    width: 4px;    /* keep in sync with --scrollbar-width */
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 2px;
    transition: background 0.2s;
}
#table-of-contents:hover::-webkit-scrollbar-thumb,
#page-main-body:hover::-webkit-scrollbar-thumb {
    background: var(--h2-color);
}

/* Firefox — thin scrollbar, hidden until hover */
#table-of-contents {
    scrollbar-width: none;
}
#table-of-contents:hover {
    scrollbar-width: thin;
    scrollbar-color: var(--h2-color) transparent;
}
#page-main-body {
    scrollbar-width: none;
}
#page-main-body:hover {
    scrollbar-width: thin;
    scrollbar-color: var(--h2-color) transparent;
}
