/* Edward Tufte-Inspired CSS - Focus on Content, Typography, and Visual Hierarchy */

/* Typography Foundation - Classic Serif with Perfect Proportions */
@charset "UTF-8";

@font-face {
    font-family: 'et-book';
    src: url('https://edwardtufte.github.io/tufte-css/et-book/et-book-roman-line-figures/et-book-roman-line-figures.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'et-book';
    src: url('https://edwardtufte.github.io/tufte-css/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'et-book';
    src: url('https://edwardtufte.github.io/tufte-css/et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}

/* Root Variables - Classic Book Typography */
:root {
    /* Golden ratio and modular scale */
    --ratio: 1.618;
    --base-font-size: 15px;
    --base-line-height: 1.618;
    
    /* Tufte color palette - high contrast, paper-like */
    --text-color: #111111;
    --background-color: #fffff8;
    --link-color: #222222;
    --link-underline: #aaaaaa;
    --code-background: #f9f9f9;
    --border-color: #dddddd;
    --subtle-gray: #666666;
    --faint-gray: #999999;
    
    /* Typography scale based on golden ratio */
    --type-scale-1: calc(var(--base-font-size) * var(--ratio) * var(--ratio) * var(--ratio));
    --type-scale-2: calc(var(--base-font-size) * var(--ratio) * var(--ratio));
    --type-scale-3: calc(var(--base-font-size) * var(--ratio));
    --type-scale-4: var(--base-font-size);
    --type-scale-5: calc(var(--base-font-size) / var(--ratio));
    
    /* Layout measurements */
    --body-width: 87.5%;
    --main-width: 55%;
    --sidenote-width: 40%;
    --margin-width: 40%;
}

/* Base Reset - Minimal and Clean */
* {
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--base-font-size);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Body - Classic Book Layout */
body {
    font-family: 'et-book', 'Palatino', 'Palatino Linotype', 'Georgia', serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    counter-reset: sidenote-counter;
}

/* Main Article Container - Responsive Grid Layout */
article {
    display: grid;
    grid-template-columns: 1fr min(100ch, 100%) 1fr;
    grid-column-gap: 2rem;
    padding: 5rem 2rem;
    margin: 0 auto;
    position: relative;
    max-width: 100vw;
    overflow-x: hidden;
}

/* All main content goes in the center column */
article > * {
    grid-column: 2;
}

/* Typography - Heading Hierarchy */
h1 {
    font-weight: 400;
    margin-top: 4rem;
    margin-bottom: 2rem;
    font-size: 4.5rem;  /* 50% larger for impact */
    line-height: 1.1;
    letter-spacing: -0.02em;
}

h2 {
    font-weight: 400;
    margin-top: 2.1rem;
    margin-bottom: 1.4rem;
    font-size: 2.2rem;
    line-height: 1;
}

h3 {
    font-weight: 400;
    font-size: 1.7rem;
    margin-top: 2rem;
    margin-bottom: 1.4rem;
    line-height: 1;
}

h4 {
    font-weight: 400;
    font-size: 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1;
}

h5, h6 {
    font-weight: 400;
    font-size: 1.4rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1;
}

/* Subtitle Styling */
.subtitle {
    font-style: italic;
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-size: 1.8rem;
    display: block;
    line-height: 1;
}

/* Paragraph and Section Styling */
p, ol, ul {
    font-size: 1.4rem;
    line-height: 2rem;
}

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

/* First Paragraph - No Top Margin */
section > p:first-child,
article > p:first-child {
    margin-top: 0;
}

/* Section Breaks */
section {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

/* Links - Tufte Style */
a:link, a:visited {
    color: inherit;
    text-decoration: none;
    background: linear-gradient(var(--background-color), var(--background-color)), 
                linear-gradient(var(--background-color), var(--background-color)),
                linear-gradient(var(--link-underline), var(--link-underline));
    background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
    background-repeat: no-repeat, no-repeat, repeat-x;
    background-position: 0% 93%, 100% 93%, 0% 93%;
    text-shadow: 0.03em 0 var(--background-color), -0.03em 0 var(--background-color), 
                 0 0.03em var(--background-color), 0 -0.03em var(--background-color),
                 0.06em 0 var(--background-color), -0.06em 0 var(--background-color),
                 0.09em 0 var(--background-color), -0.09em 0 var(--background-color),
                 0.12em 0 var(--background-color), -0.12em 0 var(--background-color),
                 0.15em 0 var(--background-color), -0.15em 0 var(--background-color);
}

a:link::selection, a:visited::selection {
    text-shadow: none;
    background: #b4d5fe;
}

/* Blockquotes - Indented and Elegant */
blockquote {
    font-size: 1.4rem;
    margin-right: var(--margin-width);
}

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

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

/* Lists - Clean and Readable */
ul, ol {
    padding-left: 2rem;
    margin-top: 1.4rem;
    margin-bottom: 1.4rem;
}

li {
    margin-bottom: 0.5rem;
}

/* Figures and Captions */
figure {
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
    max-width: var(--main-width);
    margin: 0 0 3em 0;
}

/* Code figure containers - allow grid positioning */
figure.code {
    display: contents;
}

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: var(--sidenote-width);
    margin-right: -60%;
}

/* Tables - Minimal and Clean */
table {
    font-size: 1.2rem;
    width: auto;
    margin-top: 2rem;
    margin-bottom: 2rem;
    border-collapse: collapse;
    border-spacing: 0;
}

thead {
    border-bottom: 1px solid var(--border-color);
    font-weight: 400;
}

th {
    font-weight: 400;
    padding: 0.5rem 1rem 0.5rem 0;
    text-align: left;
}

td {
    padding: 0.5rem 1rem 0.5rem 0;
    vertical-align: top;
}

tbody tr:first-child td {
    padding-top: 1rem;
}

/* Code - Clean Monospace */
code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 1.0rem;
    line-height: 1.42;
    background-color: var(--code-background);
    padding: 0.125rem 0.25rem;
    border-radius: 2px;
}

/* Pre blocks - Span content and part of margin column */
pre {
    font-size: 0.9rem;
    grid-column: 2 / 4;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    overflow-x: auto;
    background-color: var(--code-background);
    padding: 1rem;
    border-left: 2px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

pre code {
    font-size: 0.9rem;
    background: transparent;
    padding: 0;
}

/* Syntax Highlighting - Tufte Style (Optimized for Scala) */
.codehilite .hll { background-color: #fffbdd }
.codehilite .c { color: #666666; font-style: italic } /* Comment */
.codehilite .err { color: #dc2626 } /* Error */
.codehilite .k { color: #1e40af; font-weight: bold } /* Keyword (def, val, var, object, class, etc.) */
.codehilite .o { color: #374151 } /* Operator */
.codehilite .cm { color: #666666; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #7c2d12 } /* Comment.Preproc */
.codehilite .c1 { color: #666666; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #666666; font-style: italic } /* Comment.Special */
.codehilite .gd { color: #dc2626 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #dc2626 } /* Generic.Error */
.codehilite .gh { color: #111827; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #059669 } /* Generic.Inserted */
.codehilite .go { color: #6b7280 } /* Generic.Output */
.codehilite .gp { color: #111827; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #7c3aed; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #1d4ed8 } /* Generic.Traceback */
.codehilite .kc { color: #1e40af; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #1e40af; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #1e40af; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #1e40af } /* Keyword.Pseudo */
.codehilite .kr { color: #1e40af; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #7c2d12 } /* Keyword.Type */
.codehilite .m { color: #374151 } /* Literal.Number */
.codehilite .s { color: #059669 } /* Literal.String */
.codehilite .na { color: #7c2d12 } /* Name.Attribute */
.codehilite .nb { color: #1e40af } /* Name.Builtin */
.codehilite .nc { color: #1d4ed8; font-weight: bold } /* Name.Class */
.codehilite .no { color: #991b1b } /* Name.Constant */
.codehilite .nd { color: #7c3aed } /* Name.Decorator */
.codehilite .ni { color: #6b7280; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #dc2626; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #1d4ed8 } /* Name.Function */
.codehilite .nl { color: #65a30d } /* Name.Label */
.codehilite .nn { color: #1d4ed8; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #1e40af; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #7c2d12 } /* Name.Variable */
.codehilite .ow { color: #7c3aed; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #9ca3af } /* Text.Whitespace */
.codehilite .mf { color: #374151 } /* Literal.Number.Float */
.codehilite .mh { color: #374151 } /* Literal.Number.Hex */
.codehilite .mi { color: #374151 } /* Literal.Number.Integer */
.codehilite .mo { color: #374151 } /* Literal.Number.Oct */
.codehilite .sb { color: #059669 } /* Literal.String.Backtick */
.codehilite .sc { color: #059669 } /* Literal.String.Char */
.codehilite .sd { color: #059669; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #059669 } /* Literal.String.Double */
.codehilite .se { color: #7c2d12; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #059669 } /* Literal.String.Heredoc */
.codehilite .si { color: #7c2d12; font-weight: bold } /* Literal.String.Interpol */
.codehilite .sx { color: #1e40af } /* Literal.String.Other */
.codehilite .sr { color: #7c2d12 } /* Literal.String.Regex */
.codehilite .s1 { color: #059669 } /* Literal.String.Single */
.codehilite .ss { color: #7c2d12 } /* Literal.String.Symbol */
.codehilite .bp { color: #1e40af } /* Name.Builtin.Pseudo */
.codehilite .vc { color: #7c2d12 } /* Name.Variable.Class */
.codehilite .vg { color: #7c2d12 } /* Name.Variable.Global */
.codehilite .vi { color: #7c2d12 } /* Name.Variable.Instance */

/* Sidenotes and Marginal Notes */
.sidenote, .marginnote {
    grid-column: 3;
    margin-top: 0.3rem;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    line-height: 1.3;
    vertical-align: baseline;
    text-align: right;
    padding-right: 2rem;
    padding-left: 1rem;
}

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

.sidenote-number:after,
.sidenote:before {
    position: relative;
    vertical-align: baseline;
    font-size: 0.7rem;
    top: -0.5rem;
    left: 0.1rem;
}

.sidenote-number:after {
    content: counter(sidenote-counter);
}

.sidenote:before {
    content: counter(sidenote-counter) " ";
}

/* Full Width Elements */
.fullwidth {
    max-width: 90%;
    clear: both;
}

/* Sans Serif Option for Specific Content */
.sans {
    font-family: 'Gill Sans', 'Gill Sans MT', 'Calibri', sans-serif;
    letter-spacing: 0.03em;
}

/* Horizontal Rules - Subtle */
hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 3rem 0;
    width: 55%;
}

/* Print Styles */
@media print {
    body {
        background: white;
        font-size: 10pt;
        max-width: 100%;
    }
    
    .sidenote, .marginnote {
        margin-right: 0;
        width: auto;
        display: block;
        float: none;
        font-size: 9pt;
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
        padding: 0.5rem;
        border: 1px solid var(--border-color);
    }
    
    a:link, a:visited {
        background: none;
        text-decoration: underline;
    }
}

/* Mobile Responsive - Single Column Layout */
@media (max-width: 760px) {
    article {
        display: block;
        padding: 3rem 0.5rem;
        margin: 0;
        max-width: 100vw;
    }
    
    /* Reset all content to normal flow */
    article > * {
        grid-column: auto;
    }
    
    /* Mobile code blocks - full width with proper scrolling */
    pre {
        width: calc(100vw - 1rem);
        margin-left: calc(-0.5rem + 0.5rem);
        margin-right: calc(-0.5rem + 0.5rem);
        font-size: 0.8rem;
        padding: 0.75rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0;
    }
    
    ul, ol {
        padding-left: 1.5rem;
    }
    
    /* Hide all margin notes on mobile */
    .marginnote, .sidenote, .reading-time {
        display: none;
    }
    
    figcaption {
        display: block;
        float: none;
        width: 100%;
        margin: 1rem 0;
        position: relative;
        font-style: italic;
    }
}

/* Special Elements */
.newthought {
    font-variant: small-caps;
    font-size: 1.2em;
}

.margin-toggle {
    display: none;
}

/* Reading Progress Indicator - Subtle */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--background-color);
    z-index: 1000;
}

.reading-progress-bar {
    height: 100%;
    background: var(--text-color);
    width: 0;
    transition: width 0.25s ease;
}

/* Reading time as proper margin note */
.reading-time {
    grid-column: 3;
    margin-top: -3rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    line-height: 1.3;
    vertical-align: baseline;
    font-style: italic;
    color: var(--subtle-gray);
    text-align: right;
    padding-right: 2rem;
    padding-left: 1rem;
}

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

.epigraph > blockquote {
    margin-top: 3em;
    margin-bottom: 3em;
    font-style: italic;
}

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

/* TLDR Box - Tufte Style */
.tldr-box {
    margin: 2rem 0;
    padding: 1.5rem 0;
    border-top: 1px solid var(--text-color);
    border-bottom: 1px solid var(--text-color);
}

.tldr-box h2 {
    font-size: 1.4rem;
    font-variant: small-caps;
    margin-bottom: 1rem;
}

.tldr-box ul {
    width: 100%;
    padding-left: 2rem;
}

/* Table of Contents */
.table-of-contents {
    margin: 3rem 0;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.table-of-contents h2 {
    font-size: 1.4rem;
    font-variant: small-caps;
    margin-bottom: 1.5rem;
    border: none;
}

.table-of-contents nav.toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.table-of-contents nav.toc li {
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.table-of-contents nav.toc li li {
    margin-left: 2rem;
    margin-bottom: 0.5rem;
    font-size: 0.95em;
}

.table-of-contents nav.toc a {
    color: var(--text-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.table-of-contents nav.toc a:hover {
    border-bottom-color: var(--text-color);
}

/* Skip to Content - Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--text-color);
    color: var(--background-color);
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Selection */
::selection {
    background: rgba(255, 255, 0, 0.3);
    text-shadow: none;
}

/* Focus States */
:focus {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}