/* ─── Agipo Regular (headings) ────────────────────────────────── */
@font-face {
    font-family: 'Agipo Regular';
    src: url('fonts/AgipoRegular.woff2') format('woff2'),
         url('fonts/AgipoRegular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ─── Agipo Mono (dates) ──────────────────────────────────────── */
@font-face {
    font-family: 'Agipo Mono';
    src: url('fonts/AgipoMono.woff2') format('woff2'),
         url('fonts/AgipoMono.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ─── Epicene Text (body) ─────────────────────────────────────── */
@font-face {
    font-family: 'Epicene Text';
    src: url('fonts/EpiceneText-Regular.woff2') format('woff2'),
         url('fonts/EpiceneText-Regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Epicene Text';
    src: url('fonts/EpiceneText-RegularItalic.woff2') format('woff2'),
         url('fonts/EpiceneText-RegularItalic.otf') format('opentype');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'Epicene Text';
    src: url('fonts/EpiceneText-Bold.woff2') format('woff2'),
         url('fonts/EpiceneText-Bold.otf') format('opentype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Epicene Text', Georgia, 'Times New Roman', Times, serif;
    line-height: 1.6;
    color: #222;
    margin: 0 auto;
    padding: 0 1rem;
    padding-top: 6rem; /* Space for fixed header */
    background: #f8f8f6;
    max-width: 1200px;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Agipo Regular', Georgia, serif;
    font-weight: normal;
}

/* Dates — Agipo Mono */
time.post-date {
    font-family: 'Agipo Mono', monospace;
}

a {
    color: #000;
    text-decoration: none;
}

a:hover {
    opacity: 0.7;
}

/* ─── Article Content Styles ─── */

figure {
    margin: 2rem 0;
    text-align: center;
}

figure img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

figcaption {
    margin-top: 0.75rem;
    font-family: 'Agipo Regular', Georgia, serif;
    font-size: 0.85rem;
    color: #666; /* Grey like footnotes */
    text-align: center;
    line-height: 1.4;
}

hr {
    border: 0;
    border-top: 1px solid #ccc;
    margin: 3rem auto;
    width: 100%;
}

blockquote {
    padding-left: 1.25rem;
    margin: 2rem 0;
    color: #444;
}

.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    text-align: center;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 2rem;
    background: #f8f8f6;
    max-width: 1200px;
    margin: 0 auto;
    transition: all 0.3s ease;
}

.site-header.scrolled {
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 0.25rem 1rem;
    left: 0;
    right: 0;
    max-width: 100%;
}

.site-header.scrolled:hover {
    background: #ebebea;
}

.site-header.scrolled .site-description {
    display: none;
}

.site-header.scrolled .site-title {
    font-size: 0.9rem;
    margin: 0;
}

/* Article title in header (for article pages when scrolled) */
.article-title-in-header {
    display: none;
    font-size: 0.9rem;
    color: #555;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.site-header.scrolled .article-title-in-header {
    display: inline;
    margin-left: 0.5rem;
}

/* Scroll to top arrow */
.scroll-to-top-arrow {
    margin-left: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    font-size: 1.2rem;
    color: #422f33;
}

.site-header.scrolled .scroll-to-top-arrow {
    opacity: 1;
}

.site-title {
    font-family: 'Agipo Regular', Georgia, serif;
    font-size: 1.5rem;
    margin: 0;
    line-height: 1.2;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.site-description {
    font-size: 0.9rem;
    color: inherit;
    margin: 0.25rem 0 0 0;
}

.site-branding {
    text-align: left;
    flex-shrink: 1;
    min-width: 0;
    position: relative;
    align-self: stretch;
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
}

.site-branding-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.site-logo-link {
    display: flex;
    align-self: center;
    flex-shrink: 0;
}

.site-logo-img {
    height: 32px;
    width: auto;
    display: block;
}

/* Meta Navigation */
.meta-nav {
    display: flex;
    gap: 1.5rem;
    align-items: flex-end;
    flex-grow: 1;
}

.meta-nav a {
    font-family: 'Agipo Mono', monospace;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.meta-nav a:hover {
    opacity: 0.6;
}

/* Hamburger Menu */
.hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    padding: 0.5rem;
    background: none;
    border: none;
    z-index: 1001;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: #422f33;
    transition: all 0.3s;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.header-nav {
    display: flex;
    gap: 2rem;
    align-items: flex-end;
    align-self: flex-end;
}

/* Search Toggle Button */
.search-toggle {
    display: none; /* Hidden by default, shown on mobile */
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: #000;
    transition: opacity 0.2s;
}

.search-toggle:hover {
    opacity: 0.6;
}

/* Search Box Styles */
.search-container {
    position: relative;
    width: 250px;
}

.search-box {
    width: 100%;
    padding: 0.5rem 0;
    font-size: 0.9rem;
    border: none;
    border-bottom: 1px solid #94b3a9;
    font-family: inherit;
    background: transparent;
}

.search-box:focus {
    outline: none;
    border-bottom-color: #422f33;
}

.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #f8f8f6;
    border: 2px solid #94b3a9;
    border-top: none;
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.autocomplete-results.active {
    display: block;
}

.autocomplete-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background-color: #ebebea;
}

.autocomplete-title {
    font-weight: normal;
    margin: 0;
    font-size: 1rem;
}

.autocomplete-author {
    font-size: 0.85rem;
    color: #555;
    font-style: italic;
    margin-top: 0.25rem;
}

.highlight {
    background-color: #422f33;
    color: #fff;
    font-weight: bold;
}

@media (min-width: 1025px) {
    .site-branding-text {
        flex-direction: row;
        align-items: baseline;
        gap: 0.6rem;
    }
}

@media (max-width: 1024px) {
    .site-description {
        display: none;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0 0.5rem;
        padding-top: 5rem;
    }

    .site-branding-text {
        flex-direction: row;
        align-items: baseline;
        gap: 0.6rem;
    }

    .site-header {
        flex-wrap: nowrap;
        padding: 0.75rem 0.5rem;
    }

    .site-branding {
        flex: 1;
        min-width: 0;
    }

    .hamburger {
        display: flex;
        flex-shrink: 0;
    }

    .header-nav {
        position: fixed;
        top: 0;
        right: -100%;
        height: 100vh;
        width: 250px;
        background: #f8f8f6;
        flex-direction: column;
        align-items: flex-start;
        padding: 4rem 2rem 2rem;
        gap: 1.5rem;
        transition: right 0.3s ease;
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
        z-index: 1000;
    }

    .header-nav.active {
        right: 0;
    }

    .meta-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .search-toggle {
        display: block; /* Show search toggle on mobile */
        order: -2;      /* Move above meta-nav links */
    }

    .search-container {
        display: none; /* Hide search by default on mobile */
        width: 100%;
        order: -1;     /* Just below search toggle, above meta-nav */
    }

    .search-container.active {
        display: block; /* Show when toggled */
    }

    .header-nav .meta-nav {
        order: 0;
    }
}

@media (max-width: 600px) {
    .site-title {
        font-size: 1.25rem;
    }

    .site-description {
        font-size: 0.8rem;
    }
}

/* Tufte-CSS Sidenote Styles */
.sidenote,
.marginnote {
    float: right;
    clear: right;
    margin-right: -60%;
    width: 50%;
    margin-top: 0.3rem;
    margin-bottom: 0;
    font-size: 0.9rem;
    line-height: 1.3;
    vertical-align: baseline;
    position: relative;
    color: #2e2f34;
}

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

.sidenote-number:after,
.sidenote:before {
    position: relative;
    vertical-align: baseline;
}

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

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

/* For body elements that contain sidenotes */
body {
    counter-reset: sidenote-counter;
}

/* Hide the checkbox */
input.margin-toggle {
    display: none;
}

/* Label for margin toggle (appears on narrow screens) */
label.margin-toggle:not(.sidenote-number) {
    display: none;
}

/* Responsive behavior for sidenotes */
@media (max-width: 1200px) {
    .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%;
        position: relative;
    }

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

    label.sidenote-number {
        display: inline;
        text-decoration: underline;
    }
}
