:root {
    --color1: #ffffff;
    --color2: #000000;
    --header-height: 5vh;
    --sidebar-collapsed: 5vw;
    --sidebar-toc: 260px;
    --sidebar-bib: 340px;

    color: var(--color2);
    background-color: var(--color1);
    font-size: 16px;
    line-height: 1.5;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    height: 100vh;
    background-color: var(--color1);
    color: var(--color2);
    font-family: "Times New Roman", serif;
    overflow: hidden;
}

/* ── Hidden controls ───────────────────────────────── */

input[name="tab"],
input.sidebar-toggle {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

/* ── Header ────────────────────────────────────────── */

header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--color1);
    border-bottom: 1px solid var(--color2);
    z-index: 100;
    display: flex;
    align-items: center;
}

nav {
    display: flex;
    width: 100%;
    height: 100%;
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-right: 1px solid var(--color2);
    background: transparent;
    color: var(--color2);
    font-family: "Messapia", sans-serif;
    font-size: 1rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition:
        background-color 0.2s,
        color 0.2s;
    user-select: none;
}

.tab:last-child {
    border-right: none;
}

.tab:hover {
    background-color: var(--color2);
    color: var(--color1);
}

#tab-essay:checked ~ header label[for="tab-essay"],
#tab-landing:checked ~ header label[for="tab-landing"],
#tab-docs:checked ~ header label[for="tab-docs"] {
    background-color: var(--color2);
    color: var(--color1);
}

/* ── Panels ────────────────────────────────────────── */

main {
    margin-top: 5vh;
    bottom: 0;
    left: 0;
    right: 0;
    height: 95vh;
    overflow: hidden;
}

.panel {
    display: none;
    height: 100%;
}

#tab-essay:checked ~ main #panel-essay,
#tab-landing:checked ~ main #panel-landing,
#tab-docs:checked ~ main #panel-docs {
    display: block;
}

/* ═══════════════════════════════════════════════════════
   DESKTOP: sidebars always open, no toggle UI
   ═══════════════════════════════════════════════════════ */

.essay-layout {
    display: flex;
    height: 100%;
}

/* Left sidebar */
.sidebar-left {
    width: var(--sidebar-toc);
    min-width: 0;
    border-right: 1px solid var(--color2);
    overflow: hidden;
    background: var(--color1);
}

.sidebar-left .sidebar-inner {
    width: var(--sidebar-toc);
    height: 100%;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Right sidebar */
.sidebar-right {
    width: var(--sidebar-bib);
    min-width: 0;
    border-left: 1px solid var(--color2);
    overflow: hidden;
    background: var(--color1);
}

.sidebar-right .sidebar-inner {
    width: var(--sidebar-bib);
    height: 100%;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Hide toggle elements on desktop */
.sidebar-toggle-label,
.sidebar-close {
    display: none;
}

/* Centre body */
.essay-body {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.essay-body > * {
    max-width: 70ch;
    width: 100%;
}

/* ═══════════════════════════════════════════════════════
   MOBILE (< 4:3 aspect): overlaying collapsible sidebars
   ═══════════════════════════════════════════════════════ */

@media (max-aspect-ratio: 4/3) {
    /* ── Header ── */
    .tab {
        font-size: 0.65rem;
        letter-spacing: 0.03em;
        padding: 0 0.25rem;
        white-space: normal;
        text-align: center;
        line-height: 1.15;
        word-break: break-word;
    }

    /* ── Layout ── */
    .panel {
        position: relative;
    }

    .essay-layout {
        position: relative;
    }

    /* Sidebars overlay from the sides */
    .sidebar-left,
    .sidebar-right {
        position: absolute;
        top: 0;
        bottom: 0;
        z-index: 10;
        transition: width 0.3s ease;
    }

    .sidebar-left {
        left: 0;
        border-right: 1px solid var(--color2);
    }

    .sidebar-right {
        right: 0;
        border-left: 1px solid var(--color2);
    }

    .sidebar-left .sidebar-inner,
    .sidebar-right .sidebar-inner {
        width: auto;
    }

    /* Essay body always full width */
    .essay-body {
        padding: 1.5rem;
        padding-left: calc(5vw + 1.2rem);
        padding-right: calc(5vw + 1.2rem);
    }

    /* ── Collapsed state ── */

    #toggle-toc:not(:checked) ~ .essay-layout .sidebar-left {
        width: var(--sidebar-collapsed);
    }

    #toggle-toc:not(:checked) ~ .essay-layout .sidebar-left .sidebar-inner {
        visibility: hidden;
        opacity: 0;
    }

    #toggle-bib:not(:checked) ~ .essay-layout .sidebar-right {
        width: var(--sidebar-collapsed);
    }

    #toggle-bib:not(:checked) ~ .essay-layout .sidebar-right .sidebar-inner {
        visibility: hidden;
        opacity: 0;
    }

    /* Expanded: full sidebar width */
    #toggle-toc:checked ~ .essay-layout .sidebar-left {
        width: var(--sidebar-toc);
    }

    #toggle-bib:checked ~ .essay-layout .sidebar-right {
        width: var(--sidebar-bib);
    }

    /* ── Collapsed tab label ── */

    #toggle-toc:not(:checked)
        ~ .essay-layout
        .sidebar-left
        .sidebar-toggle-label,
    #toggle-bib:not(:checked)
        ~ .essay-layout
        .sidebar-right
        .sidebar-toggle-label {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        inset: 0;
        cursor: pointer;
        user-select: none;
        writing-mode: vertical-rl;
        text-orientation: mixed;
        font-family: "Messapia", sans-serif;
        font-size: 0.85rem;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        color: var(--color2);
        background: var(--color1);
        z-index: 2;
        transition:
            background-color 0.2s,
            color 0.2s;
    }

    #toggle-toc:not(:checked)
        ~ .essay-layout
        .sidebar-left
        .sidebar-toggle-label:hover,
    #toggle-bib:not(:checked)
        ~ .essay-layout
        .sidebar-right
        .sidebar-toggle-label:hover {
        background-color: var(--color2);
        color: var(--color1);
    }

    /* ── Close button when expanded ── */

    #toggle-toc:checked ~ .essay-layout .sidebar-left .sidebar-close,
    #toggle-bib:checked ~ .essay-layout .sidebar-right .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 0;
        right: 0;
        width: var(--sidebar-collapsed);
        height: var(--sidebar-collapsed);
        cursor: pointer;
        user-select: none;
        font-family: "Messapia", sans-serif;
        font-size: 1rem;
        color: var(--color2);
        background: var(--color1);
        border-left: 1px solid var(--color2);
        border-bottom: 1px solid var(--color2);
        z-index: 3;
        transition:
            background-color 0.2s,
            color 0.2s;
    }

    #toggle-toc:checked ~ .essay-layout .sidebar-left .sidebar-close:hover,
    #toggle-bib:checked ~ .essay-layout .sidebar-right .sidebar-close:hover {
        background-color: var(--color2);
        color: var(--color1);
    }

    /* Sidebar inner padding on mobile */
    .sidebar-left .sidebar-inner {
        padding: 1rem;
    }

    .sidebar-right .sidebar-inner {
        padding: 1rem;
    }

    /* Docs grid single column */
    .docs-grid {
        grid-template-columns: 1fr;
    }
    .docs-content {
        padding: 1.5rem 1rem 3rem 1rem;
    }
}

/* ── Typography ────────────────────────────────────── */

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: "Messapia", sans-serif;
    font-weight: normal;
}

h1 {
    font-size: 1.6rem;
    margin-top: 2.5rem;
    margin-bottom: 1.5rem;
    line-height: 1.2;
}

h2 {
    font-size: 1.25rem;
    margin: 2rem 0 0.75rem;
    line-height: 1.3;
}

h3 {
    font-size: 1.05rem;
    margin: 1.5rem 0 0.5rem;
    line-height: 1.4;
}

h4 {
    font-size: 1rem;
    margin: 1.25rem 0 0.4rem;
}

h6 {
    font-size: 0.85rem;
    margin: 0.75rem 0 0.4rem;
    line-height: 1.4;
}

p {
    margin-bottom: 0.75rem;
    text-align: justify;
    hyphens: auto;
}

.essay-body > section {
    margin-bottom: 1.5rem;
}

br {
    content: "";
    display: block;
    margin-bottom: 0.5rem;
}

/* ── Footnotes ─────────────────────────────────────── */

sup a {
    font-family: "Messapia", sans-serif;
    text-decoration: none;
    color: var(--color2);
    font-size: 0.7em;
    vertical-align: super;
    line-height: 0;
}

sup a:hover {
    text-decoration: underline;
}

/* ── Bibliography ──────────────────────────────────── */

.bib-list {
    font-family: "Messapia", sans-serif;
    list-style: none;
    padding: 0;
}

.bib-list li {
    margin-bottom: 1rem;
    font-size: 0.8rem;
    line-height: 1.35;
    position: relative;
    scroll-margin-top: 1rem;
}

.bib-list li:target {
    outline: 2px solid var(--color2);
    outline-offset: 4px;
}

.bib-list .bib-id {
    font-weight: normal;
    display: block;
    margin-bottom: 0.15rem;
    font-size: 0.75rem;
    opacity: 0.6;
}

.bib-backlinks {
    font-size: 0.7rem;
    margin-top: 0.2rem;
}

.bib-backlinks a {
    color: var(--color2);
    text-decoration: none;
    margin-right: 0.3em;
}

.bib-backlinks a:hover {
    text-decoration: underline;
}

/* ── Table of Contents ─────────────────────────────── */

.toc-list {
    font-family: "Messapia", sans-serif;
    list-style: none;
    padding: 0;
}

.toc-list li {
    margin-bottom: 0.35rem;
    font-size: 0.82rem;
}

.toc-list a {
    color: var(--color2);
    text-decoration: none;
}

.toc-list a:hover {
    text-decoration: underline;
}

.toc-list .toc-h2 {
    font-weight: normal;
    margin-top: 0.6rem;
}

.toc-list .toc-h3 {
    padding-left: 1rem;
    font-size: 0.78rem;
}

/* ── Landing page ──────────────────────────────────── */

.landing-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100%;
    padding: 12vh 2rem 4rem 2rem;
    text-align: center;
    overflow-y: auto;
}

.landing-hero h1 {
    margin-top: 0;
    margin-bottom: 0.3rem;
    font-size: 2.8rem;
    line-height: 1.15;
}

.landing-author {
    font-family: "Messapia", sans-serif;
    font-size: 1.1rem;
    margin-bottom: 20vh;
    font-weight: normal;
}

.landing-hero h2 {
    font-family: "Messapia", sans-serif;
    font-size: 1.3rem;
    font-weight: normal;
    margin-top: 0;
    margin-bottom: 1.2rem;
}

.landing-quote {
    margin-bottom: 0.5rem;
    margin-top: 2vh;
}

.landing-quote p {
    font-family: "Messapia", sans-serif;
    font-size: 1.4rem;
    margin-bottom: 0.3rem;
}

.landing-quote cite {
    font-style: normal;
}

.landing-footnote {
    font-size: 0.75rem;
    max-width: 50ch;
    margin-top: 30vh;
    margin-bottom: 20vh;
}

.landing-abstract {
    max-width: 65ch;
    line-height: 1.6;
}

/* ── Docs grid ─────────────────────────────────────── */

#panel-docs {
    overflow-y: auto;
}

.docs-content {
    padding: 2.5rem 2rem 4rem 2rem;
}

.docs-content > h1,
.docs-content > h2,
.docs-content > h3,
.docs-content > h6,
.docs-content > p,
.docs-content > ul,
.docs-content > hr,
.docs-content > section {
    max-width: 70ch;
    margin-left: auto;
    margin-right: auto;
}

.docs-content h1 {
    font-size: 1.6rem;
    margin-top: 2.5rem;
    margin-bottom: 1.5rem;
}

.docs-content h1:first-child {
    margin-top: 0;
}

.docs-content h2 {
    font-size: 1.25rem;
    margin: 2rem 0 0.75rem;
}

.docs-content h3 {
    font-size: 1.05rem;
    margin: 1.5rem 0 0.5rem;
}

.docs-content h6 {
    font-size: 0.85rem;
    margin: 0.75rem 0 0.4rem;
}

.docs-content p {
    margin-bottom: 0.75rem;
    text-align: justify;
    hyphens: auto;
}

.docs-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem auto;
    border: 1px solid var(--color2);
}

.docs-content img + span {
    display: block;
    font-family: "Messapia", sans-serif;
    font-size: 0.75rem;
    text-align: center;
    margin-top: 0.2rem;
    margin-bottom: 1rem;
    max-width: 100%;
}

.docs-content ul {
    padding-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.docs-content .bb {
    margin-top: 1.5rem;
}

.docs-grid {
    display: grid;
    gap: 1rem;
    padding: 2rem 0;
    max-width: none;
}

.docs-grid figure {
    margin: 0;
}

.docs-grid img {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid var(--color2);
    margin: 0;
}

.docs-grid figcaption {
    font-family: "Messapia", sans-serif;
    font-size: 0.75rem;
    margin-top: 0.4rem;
    text-align: center;
}

@media (min-aspect-ratio: 4/3) {
    .docs-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Scroll behaviour ──────────────────────────────── */

html {
    scroll-behavior: smooth;
}
