@charset "UTF-8";

/* Import ET Book styles
   adapted from https://github.com/edwardtufte/et-book/blob/gh-pages/et-book.css */

@font-face {
    font-family: "et-book";
    src: url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot");
    src: url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.woff") format("woff"), url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.ttf") format("truetype"), url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.svg#etbookromanosf") format("svg");
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "et-book";
    src: url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot");
    src: url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff") format("woff"), url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.ttf") format("truetype"), url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.svg#etbookromanosf") format("svg");
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: "et-book";
    src: url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot");
    src: url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff") format("woff"), url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.ttf") format("truetype"), url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.svg#etbookromanosf") format("svg");
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "et-book-roman-old-style";
    src: url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot");
    src: url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.woff") format("woff"), url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.ttf") format("truetype"), url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.svg#etbookromanosf") format("svg");
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* CSS Variables for Light/Dark Mode */
:root {
    --bg-color: #fffff9;
    --text-color: #111;
    --link-bg-light: #fffff8;
    --border-color: #ccc;
    --quote-bg: #dcdbd8;
    --proof-bg: #f7f5ee;
    --code-bg: #484848;
    --code-text: #93f28a;
    --code-py-text: #d0fcaf;
    --sidebar-bg: #fffffd;
    --sidebar-border: #e0e0e0;
    --sidebar-hover: #f0f0f0;
    --sidebar-active: #e8e8e8;
    --toggle-bg: #ddd;
    --toggle-thumb: #fff;
}

[data-theme="dark"] {
    --bg-color: #151515;
    --text-color: #ddd;
    --link-bg-light: #151515;
    --border-color: #444;
    --quote-bg: #2a2a2a;
    --proof-bg: #222;
    --code-bg: #2d2d2d;
    --code-text: #f28a8a;
    --code-py-text: #a8e6a1;
    --sidebar-bg: #1a1a1a;
    --sidebar-border: #333;
    --sidebar-hover: #2a2a2a;
    --sidebar-active: #333;
    --toggle-bg: #444;
    --toggle-thumb: #888;
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-color: #151515;
        --text-color: #ddd;
        --link-bg-light: #151515;
        --border-color: #444;
        --quote-bg: #2a2a2a;
        --proof-bg: #222;
        --code-bg: #2d2d2d;
        --code-text: #bbedad;
        --code-py-text: #a8e6a1;
        --sidebar-bg: #1a1a1a;
        --sidebar-border: #333;
        --sidebar-hover: #2a2a2a;
        --sidebar-active: #333;
        --toggle-bg: #444;
        --toggle-thumb: #888;
    }
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    background-color: var(--sidebar-bg);
    color: var(--text-color);
    border: 1px solid var(--sidebar-border);
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background-color: var(--sidebar-hover);
}

.theme-toggle-track {
    width: 50px;
    height: 24px;
    background-color: var(--toggle-bg);
    border-radius: 12px;
    position: relative;
    transition: background-color 0.3s ease;
}

.theme-toggle-thumb {
    width: 20px;
    height: 20px;
    background-color: var(--toggle-thumb);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(26px);
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    z-index: 100;
    padding: 20px;
    box-sizing: border-box;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

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

.sidebar-toggle {
    position: fixed;
    top: 20px;
    right: 90px;
    z-index: 1001;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 6px;
    padding: 9.4px 12px;
    cursor: pointer;
    font-family: et-book;
    font-size: 18px;
    color: var(--text-color);
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    background-color: var(--sidebar-hover);
}

.sidebar h3 {
    margin-top: 0;
    margin-bottom: 0px;
    font-size: 1.4rem;
    color: var(--text-color);
    border-bottom: 1px solid var(--sidebar-border);
    padding-bottom: 10px;
}

.toc {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc li {
    margin-bottom: -15px;
}

.toc a {
    display: block;
    padding: 8px 12px;
    border-radius: 4px;
    color: var(--text-color);
    text-decoration: none;
    font-size: 16px;
    transition: background-color 0.2s ease;
    background: none !important;
    text-shadow: none !important;
}

.toc a:hover {
    background-color: var(--sidebar-hover);
}

.toc a.active {
    background-color: var(--sidebar-active);
    font-weight: 500;
}

.toc .toc-h2 {
    margin-left: 0;
}

.toc .toc-h3 {
    margin-left: 20px;
    font-style: italic;
    font-size: 15px;
}

.toc .toc-h4 {
    margin-left: 40px;
    font-size: 12px;
}

/* Main Content Adjustments */
html {
    font-size: 13px;
}

body {
    width: 100%;
    margin-left: 320px; /* Increased to account for sidebar */
    margin-right: auto;
    padding-left: 40px;
    font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    max-width: 700px;
    counter-reset: sidenote-counter;
    transition: all 0.3s ease;
}

.sidebar-closed {
    margin-left: 120pt;
    padding-left: 0%;
}

/* Rest of the original Tufte styles with color variables */
h1 {
    font-weight: 400;
    margin-top: 4rem;
    margin-bottom: 1.5rem;
    font-size: 3.2rem;
    line-height: 1;
    color: var(--text-color);
}

h2 {
    font-style: italic;
    font-weight: 400;
    margin-top: 2.1rem;
    margin-bottom: 1.4rem;
    font-size: 2.2rem;
    line-height: 1;
    color: var(--text-color);
}

h3 {
    font-style: italic;
    font-weight: 400;
    font-size: 1.7rem;
    margin-top: 2rem;
    margin-bottom: 1.4rem;
    line-height: 1;
    color: var(--text-color);
}

hr {
    display: block;
    height: 1px;
    width: 55%;
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 1em 0;
    padding: 0;
}

p.subtitle {
    font-style: italic;
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-size: 1.8rem;
    display: block;
    line-height: 1;
    color: var(--text-color);
}

.numeral {
    font-family: et-book-roman-old-style;
}

.danger {
    color: red;
}

article {
    padding: 5rem 0rem;
}

section {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

p,
dl,
ol,
ul {
    font-size: 1.4rem;
    line-height: 2rem;
    color: var(--text-color);
}

p {
    margin-top: 1.4rem;
    margin-bottom: 1.4rem;
    padding-right: 0;
    vertical-align: baseline;
}

/* Chapter Epigraphs */
div.epigraph {
    margin: 5em 0;
}

div.epigraph > blockquote {
    margin-top: 3em;
    margin-bottom: 3em;
}

div.epigraph > blockquote,
div.epigraph > blockquote > p {
    font-style: italic;
}

div.epigraph > blockquote > footer {
    font-style: normal;
}

div.epigraph > blockquote > footer > cite {
    font-style: italic;
}

blockquote {
    font-size: 1.4rem;
}

blockquote p {
    width: 55%;
    margin-right: 40px;
}

blockquote footer {
    width: 55%;
    font-size: 1.1rem;
    text-align: right;
}

section > p,
section > footer,
section > table {
    width: 55%;
}

section > dl,
section > ol,
section > ul {
    width: 50%;
    -webkit-padding-start: 5%;
}

dt:not(:first-child),
li:not(:first-child) {
    margin-top: 0.25rem;
}

figure {
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
    max-width: 100%;
    -webkit-margin-start: 0;
    -webkit-margin-end: 0;
    margin: 0 0 3em 0;
}

figcaption {
    float: right;
    clear: right;
    margin-top: 0;
    margin-bottom: 0;
    font-size: 1.1rem;
    line-height: 1.6;
    vertical-align: baseline;
    position: relative;
    max-width: 40%;
    color: var(--text-color);
}

figure.fullwidth figcaption {
    margin-right: 24%;
}

/* Links with updated colors */
a:link,
a:visited {
    color: inherit;
}

.no-tufte-underline:link {
    background: unset;
    text-shadow: unset;
}

a:link, .tufte-underline, .hover-tufte-underline:hover {
    text-decoration: none;
    background: linear-gradient(var(--link-bg-light), var(--link-bg-light)), linear-gradient(var(--link-bg-light), var(--link-bg-light)), linear-gradient(currentColor, currentColor);
    -webkit-background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
    -moz-background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
    background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
    background-repeat: no-repeat, no-repeat, repeat-x;
    text-shadow: 0.03em 0 var(--link-bg-light), -0.03em 0 var(--link-bg-light), 0 0.03em var(--link-bg-light), 0 -0.03em var(--link-bg-light), 0.06em 0 var(--link-bg-light), -0.06em 0 var(--link-bg-light), 0.09em 0 var(--link-bg-light), -0.09em 0 var(--link-bg-light), 0.12em 0 var(--link-bg-light), -0.12em 0 var(--link-bg-light), 0.15em 0 var(--link-bg-light), -0.15em 0 var(--link-bg-light);
    background-position: 0% 93%, 100% 93%, 0% 93%;
}

@media screen and (-webkit-min-device-pixel-ratio: 0) {
    a:link, .tufte-underline, .hover-tufte-underline:hover {
        background-position-y: 87%, 87%, 87%;
    }
}

/* Sidenotes, margin notes, figures, captions */
img {
    max-width: 100%;
}

.sidenote,
.marginnote {
    float: right;
    clear: right;
    margin-right: -40%;
    width: 38%;
    margin-top: 0.3rem;
    margin-bottom: 0;
    font-size: 1.1rem;
    line-height: 1.3;
    vertical-align: baseline;
    position: relative;
    color: var(--text-color);
}

.sidenote-number {
    counter-increment: sidenote-counter;
}

.sidenote-number:after,
.sidenote:before {
    font-family: et-book-roman-old-style;
    position: relative;
    vertical-align: baseline;
}

.sidenote-number:after {
    content: counter(sidenote-counter);
    font-size: 1rem;
    top: -0.5rem;
    left: 0.1rem;
}

.sidenote:before {
    content: counter(sidenote-counter) " ";
    font-size: 1rem;
    top: -0.5rem;
}

blockquote .sidenote,
blockquote .marginnote {
    margin-right: -82%;
    min-width: 59%;
    text-align: left;
}

div.fullwidth,
table.fullwidth {
    width: 100%;
}

div.table-wrapper {
    overflow-x: auto;
    font-family: "Trebuchet MS", "Gill Sans", "Gill Sans MT", sans-serif;
}

.sans {
    font-family: "Gill Sans", "Gill Sans MT", Calibri, sans-serif;
    letter-spacing: .03em;
}

code, pre > code {
    font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 1.3rem;
    line-height: 1.42;
    -webkit-text-size-adjust: 100%;
}

.sans > code {
    font-size: 1.0rem;
}

h1 > code,
h2 > code,
h3 > code {
    font-size: 1.0em;
}

.marginnote > code,
.sidenote > code {
    font-size: 1rem;
}

pre > code {
    font-size: 1.1rem;
    width: 52.5%;
    margin-left: 2.5%;
    overflow-x: auto;
    display: block;
}

pre.fullwidth > code {
    width: 90%;
}

.fullwidth {
    max-width: 90%;
    clear:both;
}

span.newthought {
    font-variant: small-caps;
    font-size: 1.2em;
}

input.margin-toggle {
    display: none;
}

label.sidenote-number {
    display: inline-block;
    max-height: 2rem;
}

label.margin-toggle:not(.sidenote-number) {
    display: none;
}

.iframe-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 25px;
    height: 0;
}

.iframe-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Updated quote and proof styles with CSS variables */
quote p {
    background-color: var(--quote-bg);
    font-size: 1.4rem;
    width: 90%;
    padding: 25px;
    margin-right: 0px;
    margin-left: 5px;
    border-radius: 5px;
}

proof p {
    background-color: var(--proof-bg);
    font-size: 1.4rem;
    width: 92.7%;
    padding: 15px;
    margin-right: 0px;
    margin-left: 5px;
    border-radius: 5px;
}

/* Updated code styles with CSS variables */
pre { 
    background-color: var(--code-bg);
    color: var(--code-text);
    width: 80%;
    font-size: 1.1rem;
    padding: 30px 35px 25px 30px;
    margin: 30px 30px 30px 30px;
    border-radius: 5px;
    line-height: 1.65;
}

pre.cli { 
    background-color: var(--code-bg);
    color: white;
    width: 80%;
    font-size: 1.25rem;
    padding: 25px 35px 0px 25px;
    margin-left: 40px;
    border-radius: 5px;
    line-height: 2;
}

pre.py { 
    background-color: var(--code-bg);
    color: var(--code-py-text);
    width: 80%;
    font-size: 1.25rem;
    padding: 25px;
    margin-left: 40px;
    border-radius: 5px;
}



/* Mobile Responsive */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    body {
        margin-left: 120pt;
        padding-left: 0%;
    }
    
    .sidebar-toggle {
        display: block;
    }
}

@media (max-width: 760px) {
    body {
        width: 84%;
        padding-left: 8%;
        padding-right: 8%;
        margin-left: 0;
    }

    .sidebar {
        width: 100%;
        transform: translateX(-100%);
    }

    .theme-toggle {
        top: 10px;
        right: 10px;
    }

    .sidebar-toggle {
        top: 10px;
        left: 10px;
    }

    hr,
    section > p,
    section > footer,
    section > table {
        width: 100%;
    }

    pre > code {
        width: 97%;
    }

    pre {
        width: 95%;
        margin-left: 10px;
    }

    section > dl,
    section > ol,
    section > ul {
        width: 90%;
    }

    figure {
        max-width: 90%;
    }

    figcaption,
    figure.fullwidth figcaption {
        margin-right: 0%;
        max-width: none;
    }

    blockquote {
        margin-left: 1.5em;
        margin-right: 0em;
    }

    blockquote p,
    blockquote footer {
        width: 100%;
    }

    label.margin-toggle:not(.sidenote-number) {
        display: inline;
    }

    .sidenote,
    .marginnote {
        display: none;
    }

    .margin-toggle:checked + .sidenote,
    .margin-toggle:checked + .marginnote {
        display: block;
        float: left;
        left: 1rem;
        clear: both;
        width: 95%;
        margin: 1rem 2.5%;
        vertical-align: baseline;
        position: relative;
    }

    label {
        cursor: pointer;
    }

    div.table-wrapper,
    table {
        width: 85%;
    }

    img {
        width: 100%;
    }
}

/* Sidebar header with navigation */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--sidebar-border);
}

.nav-buttons {
    display: flex;
    gap: 8px;
}

.nav-btn {
    background: var(--sidebar-hover);
    border: 1px solid var(--sidebar-border);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.nav-btn:hover {
    background-color: var(--sidebar-active);
}

/* Hierarchical TOC styles */
.toc-item {
    list-style: none;
    margin: 0;
}

.toc-item-container {
    display: flex;
    align-items: center;
    padding: 4px 0;
}

.toc-toggle {
    cursor: pointer;
    width: 20px;
    text-align: center;
    user-select: none;
    color: var(--text-color);
    opacity: 0.6;
    font-size: 12px;
}

.toc-toggle:hover {
    opacity: 1;
}

.toc-spacer {
    width: 20px;
    display: inline-block;
}

.toc-children {
    margin-left: 20px;
    padding-left: 0;
    list-style: none;
    transition: all 0.3s ease;
}

/* Adjust link styling in container */
.toc-item-container a {
    flex: 1;
    padding: 4px 8px;
}

/* Indentation by heading level */
.toc-h2 > .toc-item-container { padding-left: 0px; }
.toc-h3 > .toc-item-container { padding-left: 20px; }
.toc-h4 > .toc-item-container { padding-left: 40px; }
.toc-h5 > .toc-item-container { padding-left: 60px; }

/* Navigation Buttons */
.nav-home, .nav-up {
    position: fixed;
    z-index: 1001;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 4px;
    padding: 3px 3px;
    cursor: pointer;
    font-family: et-book;
    font-size: 10px;
    color: var(--text-color);
    transition: all 0.3s ease;
    text-decoration: none !important;
    background-image: none !important;
    text-shadow: none !important;
}

/*.nav-home {
    top: 43px;
    right: 128.5px;
}

.nav-up {
    top: 20px;
    right: 128.5px;
}

.nav-home:hover, .nav-up:hover {
    background-color: var(--sidebar-hover);
}

/* Hide UP button if we're at the top level */
.nav-up.hidden {
    display: none;
}

/* Mobile adjustments */
@media (max-width: 760px) {
    .nav-home {
        right: 140px;
        padding: 8px 10px;
        font-size: 16px;
    }
    
    .nav-up {
        right: 200px;
        padding: 8px 10px;
        font-size: 16px;
    }
}
