/* Tufte CSS - Adapted with off-white background and dark grey text */

/* CSS Variables for easy customization */
:root,
[data-theme="light"] {
    --bg-color: #fffff8;
    --bg-color-alt: #f9f9f4;
    --text-color: #333333;
    --text-color-light: #555555;
    --text-color-muted: #777777;
    --link-color: #444444;
    --link-hover-color: #111111;
    --border-color: #cccccc;
    --sidenote-color: #666666;
    --code-bg: #f4f4ef;
    --blockquote-border: #999999;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --bg-color-alt: #222222;
    --text-color: #e0e0e0;
    --text-color-light: #c0c0c0;
    --text-color-muted: #999999;
    --link-color: #b0b0b0;
    --link-hover-color: #ffffff;
    --border-color: #444444;
    --sidenote-color: #aaaaaa;
    --code-bg: #2a2a2a;
    --blockquote-border: #666666;
}

/* Smooth transition when switching themes */
body,
a,
.sidenote,
.marginnote,
code,
pre {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Base typography */
@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Source+Sans+Pro:wght@400;600&display=swap');

html {
    font-size: 15px;
}

body {
    max-width: 1300px;
    margin-left: 50px;
    margin-right: auto;
    padding-left: 50px;
    padding-right: 50px;
    font-family: 'EB Garamond', Georgia, serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    counter-reset: sidenote-counter;
    line-height: 1.65;
}

/* Main content column width - scales with 3:1 ratio to margin */
article p,
article > ul,
article > ol,
article > blockquote,
article > h2,
article > h3,
article > h4,
section > p {
    width: clamp(600px, 55vw, 900px);
}

/* Headings */
h1 {
    font-weight: 400;
    margin-top: 4rem;
    margin-bottom: 1.5rem;
    font-size: 3.2rem;
    line-height: 1.15;
    color: var(--text-color);
    max-width: 1200px;
    width: 100%;
}

h2 {
    font-style: normal;
    font-weight: 400;
    margin-top: 2.5rem;
    margin-bottom: 1.4rem;
    font-size: 1.5rem;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-color-muted);
}

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

h4 {
    font-weight: 400;
    font-size: 1.3rem;
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
    color: var(--text-color-light);
}

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

/* Article and section styling */
article {
    padding: 3rem 0;
}

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

p,
dl,
ol,
ul {
    font-size: 1.3rem;
    line-height: 1.85;
}

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

/* Links */
a:link,
a:visited {
    color: var(--link-color);
    text-decoration: none;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.15s ease;
}

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

/* Blockquotes - Tufte style */
blockquote {
    font-size: 1.3rem;
    width: clamp(600px, 55vw, 900px);
    margin-left: 0;
    margin-right: 0;
    padding-left: 1.5rem;
    border-left: 3px solid var(--blockquote-border);
    color: var(--text-color-light);
}

blockquote p {
    width: 100%;
    margin-right: 0;
}

blockquote footer {
    font-size: 1rem;
    text-align: right;
    margin-top: 0.5rem;
    color: var(--text-color-muted);
}

/* Sidenotes and marginnotes - scales 3:1 with main content using viewport units */
.sidenote,
.marginnote {
    float: right;
    clear: right;
    margin-right: clamp(-340px, -24vw, -240px);
    width: clamp(200px, 20vw, 300px);
    margin-top: 1rem;
    margin-bottom: 0;
    font-size: 1rem;
    line-height: 1.5;
    vertical-align: baseline;
    position: relative;
    color: var(--sidenote-color);
}

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

.sidenote-number:after,
.sidenote:before {
    font-family: 'Source Sans Pro', sans-serif;
    position: relative;
    vertical-align: super;
    font-size: 0.75rem;
}

.sidenote-number:after {
    content: counter(sidenote-counter);
    left: 0.1rem;
    color: var(--link-color);
}

.sidenote:before {
    content: counter(sidenote-counter) " ";
    top: 0;
    color: var(--link-color);
}

/* Toggle for sidenotes on narrow screens */
/* Hide checkbox inputs for margin toggles - Safari-compatible */
input.margin-toggle,
input[type="checkbox"].margin-toggle {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -9999px !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

label.sidenote-number {
    display: inline;
    cursor: pointer;
    white-space: nowrap;
}
    max-height: 2rem;
}

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

/* On mobile, show marginnote toggle as inline superscript */
@media (max-width: 760px) {
    label.margin-toggle:not(.sidenote-number) {
        display: inline;
        vertical-align: super;
        font-size: 0.75rem;
        color: var(--link-color);
        cursor: pointer;
        line-height: 0;
        white-space: nowrap;
        margin-left: 0.1rem;
    }
}

/* Figures */
figure {
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
    width: clamp(600px, 55vw, 900px);
    -webkit-margin-start: 0;
    -webkit-margin-end: 0;
    margin: 0 0 3rem 0;
}

/* Full-width figures span main content + margin */
figure.fullwidth {
    width: clamp(800px, 75vw, 1200px);
    max-width: 100%;
}

/* Images inside figures should not exceed figure width */
figure img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Images in sidenotes/marginnotes should fit */
.sidenote img,
.marginnote img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-bottom: 0.5rem;
}

/* Regular images in content should not overflow */
article img:not(figure img):not(.sidenote img):not(.marginnote img) {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem 0;
}

figcaption {
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    line-height: 1.5;
    vertical-align: baseline;
    position: relative;
    width: 100%;
    text-align: left;
    color: var(--text-color-muted);
}

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

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

/* Code styling */
code,
pre > code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', 'Droid Sans Mono', 'Source Code Pro', monospace;
    font-size: 1rem;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

code {
    background-color: var(--code-bg);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    color: var(--text-color-light);
}

pre {
    font-size: 0.9rem;
    width: clamp(600px, 55vw, 900px);
    margin-left: 0;
    overflow-x: auto;
    background-color: var(--code-bg);
    padding: 1rem 1.25rem;
    border-radius: 4px;
}

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

/* Tables */
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: clamp(600px, 55vw, 900px);
    font-size: 1.1rem;
    margin-top: 1.5rem;
}

th {
    border-bottom: 2px solid var(--border-color);
    padding: 0.5rem 1rem 0.5rem 0;
    text-align: left;
    font-weight: 600;
}

td {
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem 0.5rem 0;
}

/* Lists */
ul,
ol {
    width: calc(clamp(600px, 55vw, 900px) - 4rem);
    margin-left: 2.5rem;
    padding-left: 1.5rem;
}

li {
    margin-bottom: 0.4rem;
}

/* Header and Navigation */
header {
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

header h1 {
    margin: 0 0 0.5rem 0;
    font-size: 2.4rem;
}

header h1 a {
    border-bottom: none;
}

header p.subtitle {
    font-style: italic;
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-color-muted);
}

nav {
    margin-top: 1.2rem;
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    width: auto;
}

nav ul li {
    display: inline-block;
    margin-right: 1.5rem;
    margin-bottom: 0;
}

nav ul li a {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-color-muted);
    border-bottom: none;
}

nav ul li a:hover {
    color: var(--text-color);
}

/* Theme toggle button */
#theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.3rem 0.6rem;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

#theme-toggle:hover {
    background-color: var(--bg-color-alt);
    border-color: var(--text-color-muted);
}

/* Article list (index page) */
.article-list {
    list-style: none;
    padding: 0;
    width: clamp(600px, 55vw, 900px);
}

.article-list li {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.article-list li:last-child {
    border-bottom: none;
}

.article-list h2 {
    margin: 0 0 0.5rem 0;
    font-size: 1.6rem;
    font-style: normal;
}

.article-list h2 a {
    border-bottom: none;
}

.article-list .meta {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 0.9rem;
    color: var(--text-color-muted);
    margin-bottom: 0.5rem;
}

.article-list .summary {
    font-size: 1.1rem;
    margin: 0;
    color: var(--text-color-light);
}

/* Article metadata */
.article-meta {
    font-family: 'Source Sans Pro', sans-serif;
    color: var(--text-color-muted);
    font-size: 1rem;
    margin-bottom: 2rem;
}

/* Footer */
footer.site-footer {
    margin-top: 4rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    font-size: 0.95rem;
    color: var(--text-color-muted);
}

/* Pagination */
.pagination {
    font-family: 'Source Sans Pro', sans-serif;
    margin: 2rem 0;
    padding: 1rem 0;
    font-size: 0.95rem;
}

.pagination a {
    margin-right: 1rem;
}

/* Epigraph - Tufte style */
.epigraph {
    margin: 3rem 0;
}

.epigraph blockquote {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

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

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

/* Newthought - Tufte style small caps intro */
.newthought {
    font-variant: small-caps;
    font-size: 1.15em;
    letter-spacing: 0.03em;
}

/* Responsive adjustments - collapse margins when screen too narrow for both */
@media (max-width: 1000px) {
    body {
        width: 90%;
        padding-left: 5%;
    }
    
    article p,
    article > ul,
    article > ol,
    article > blockquote,
    article > h2,
    article > h3,
    article > h4,
    section > p,
    article li {
        width: 100%;
        max-width: 100%;
    }
    
    blockquote {
        width: 90%;
    }
    
    pre {
        width: 90%;
    }
    
    figure {
        max-width: 90%;
    }
    
    /* Hide sidenotes and marginnotes by default on small screens */
    .sidenote,
    .marginnote {
        display: none;
        float: none;
        clear: both;
        width: 95%;
        margin: 1rem 2.5%;
        padding: 0.5rem 0;
        border-top: 1px solid var(--border-color);
        position: relative;
    }
    
    /* Show sidenotes/marginnotes when checkbox is checked */
    .margin-toggle:checked + .sidenote,
    .margin-toggle:checked + .marginnote {
        display: block;
    }
    
    figcaption {
        display: block;
        float: none;
        clear: both;
        width: 95%;
        margin: 1rem 2.5%;
        max-width: none;
    }
    
    table {
        width: 100%;
    }
    
    ul,
    ol {
        width: 85%;
    }
    
    .article-list {
        width: 100%;
    }
}

@media (max-width: 600px) {
    body {
        font-size: 14px;
    }
    
    h1 {
        font-size: 2.4rem;
    }
    
    h2 {
        font-size: 1.8rem;
    }
    
    h3 {
        font-size: 1.4rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
}

/* Print styles */
@media print {
    body {
        width: 100%;
        padding: 0;
        background: white;
    }
    
    .sidenote,
    .marginnote {
        display: block;
        float: none;
        width: 100%;
        margin: 0.5rem 0;
        padding: 0.5rem;
        background: #f9f9f9;
    }
    
    a:link,
    a:visited {
        border-bottom: none;
    }
}

/* Empty state for categories */
.empty-category {
    font-style: italic;
    color: var(--text-color-muted);
    margin: 2rem 0;
}

/* Category page title styling */
section > h1 {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

/* Index page intro */
.intro {
    font-size: 1.4rem;
    color: var(--text-color-light);
    margin-bottom: 2.5rem;
    font-style: italic;
}

/* Recent articles heading on index */
/* Removed special first-of-type h2 styling for consistency
section > h2:first-of-type {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    color: var(--text-color-muted);
    font-style: normal;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
*/

/* HOMEPAGE STYLING - Two-column profile */

.homepage {
    max-width: 900px;
}

/* Profile header with side-by-side layout */
.homepage .profile-header {
    display: flex;
    gap: 3rem;
    padding: 3rem 0 2rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
    align-items: flex-start;
}

.homepage .profile-photo {
    flex: 0 0 auto;
    width: 30%;
    max-width: 250px;
}

.homepage .profile-photo img {
    width: 100%;
    height: auto;
    border-radius: 50%;
    object-fit: cover;
    aspect-ratio: 1;
    display: block;
}

.homepage .profile-info {
    flex: 1;
}

.homepage .profile-info h1 {
    font-size: 2.5rem;
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-weight: 400;
    line-height: 1.2;
}

.homepage .profile-info .position {
    font-size: 1.05rem;
    color: var(--text-color-muted);
    margin: 0 0 1.5rem 0;
    line-height: 1.5;
}

/* Social links */
.homepage .social-links {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.homepage .social-links a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.95rem;
    transition: color 0.2s ease;
}

.homepage .social-links a:hover {
    color: var(--link-color);
}

.homepage .social-links svg {
    fill: currentColor;
    flex-shrink: 0;
}

/* Contact info / email */
.homepage .contact-info {
    margin-top: 1rem;
}

.homepage .contact-info .email {
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
    line-height: 1.5;
}

.homepage .contact-info .email-label {
    color: var(--text-color-muted);
    font-weight: 600;
}

.homepage .contact-info a {
    color: var(--link-color);
    text-decoration: none;
}

.homepage .contact-info a:hover {
    color: var(--link-hover-color);
}

/* Bio section */
.homepage .bio {
    margin: 2rem 0 3rem 0;
}

.homepage .bio p {
    font-size: 1.3rem;
    line-height: 1.65;
    margin-bottom: 1rem;
}

/* Recent Posts Section */
.homepage .recent-posts {
    margin: 3rem 0 2rem 0;
    padding-top: 3rem;
    border-top: 1px solid var(--border-color);
}

.homepage .recent-posts h2 {
    font-size: 1.6rem;
    margin-bottom: 2rem;
    font-weight: 400;
    font-style: italic;
}

.homepage .post-preview {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.homepage .post-preview:last-of-type {
    border-bottom: none;
}

.homepage .post-preview h3 {
    font-size: 1.4rem;
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-weight: 400;
    font-style: normal;
}

.homepage .post-preview h3 a {
    text-decoration: none;
    color: var(--text-color);
}

.homepage .post-preview h3 a:hover {
    color: var(--link-hover-color);
}

.homepage .post-preview .post-meta {
    font-size: 0.95rem;
    color: var(--text-color-muted);
    font-style: italic;
    margin-bottom: 0.5rem;
}

.homepage .post-preview p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin: 0;
}

.homepage .view-all {
    margin-top: 2rem;
    font-size: 1.1rem;
}

/* Responsive adjustments */
@media (max-width: 1000px) {
    .homepage .profile-header {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .homepage .profile-photo {
        width: 40%;
        max-width: 200px;
    }
    
    .homepage .profile-info h1 {
        font-size: 2rem;
    }
    
    .homepage .bio p {
        font-size: 1.2rem;
    }
}

/* ============================================ */
/* Mobile Fix - Reset body positioning         */
/* ============================================ */
@media (max-width: 760px) {
    body {
        box-sizing: border-box !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 5% !important;
        padding-right: 5% !important;
    }
}
