/* =====================================================
   mujun.study  --  Studies in Contradiction
   A scholarly monograph in the dark-academia tradition
   ===================================================== */

:root {
    --ivory-paper:    #fdf8f0;
    --ink-black:      #2a2420;
    --crimson:        #8b1a1a;
    --leather-brown:  #5a4f42;
    --aged-paper:     #f0e8d8;
    --scholar-green:  #3a5a3a;
    --foxed-edge:     #d4c8b0;

    --serif:    "EB Garamond", "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --sans:     "Lato", "Helvetica Neue", Arial, sans-serif;

    --measure:        680px;
    --sidenote-gap:   2.25rem;
    --sidenote-width: 200px;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    background: var(--ivory-paper);
    /* faint paper grain */
    background-image:
        radial-gradient(rgba(90, 79, 66, 0.045) 1px, transparent 1px),
        radial-gradient(rgba(139, 26, 26, 0.025) 1px, transparent 1px);
    background-size: 3px 3px, 7px 7px;
    background-position: 0 0, 1px 2px;
    color: var(--ink-black);
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.9;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: "liga" on, "kern" on, "onum" on;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

p { margin: 0 0 1.4rem; hyphens: auto; }
em { font-style: italic; }
strong { font-weight: 600; }

a {
    color: var(--crimson);
    text-decoration: none;
    border-bottom: 0.5px solid rgba(139, 26, 26, 0.35);
    transition: color 0.25s ease, border-color 0.25s ease, background-color 0.25s ease;
}
a:hover {
    color: var(--scholar-green);
    border-bottom-color: var(--scholar-green);
    background: rgba(58, 90, 58, 0.06);
}

::selection {
    background: var(--crimson);
    color: var(--ivory-paper);
}

/* ---------- Running header (sticky) ---------- */
.running-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(253, 248, 240, 0.94);
    backdrop-filter: saturate(180%) blur(6px);
    -webkit-backdrop-filter: saturate(180%) blur(6px);
    border-bottom: 0.5px solid var(--foxed-edge);
    transition: opacity 0.3s ease;
}
.running-header__inner {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 0.65rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1.5rem;
    font-family: var(--sans);
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--leather-brown);
}
.running-header__title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.running-header__progress {
    flex-shrink: 0;
    color: var(--crimson);
    font-variant-numeric: tabular-nums;
}

/* ---------- Monograph container ---------- */
.monograph {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 4rem 1.5rem 6rem;
    counter-reset: chapter;
    position: relative;
}

/* Decorative outer rule down the page */
.monograph::before,
.monograph::after {
    content: "";
    position: fixed;
    top: 5%;
    bottom: 5%;
    width: 0.5px;
    background: var(--foxed-edge);
    opacity: 0.6;
    pointer-events: none;
}
.monograph::before { left: calc(50% - var(--measure) / 2 - 1.25rem); }
.monograph::after  { left: calc(50% + var(--measure) / 2 + 1.25rem); }

@media (max-width: 980px) {
    .monograph::before, .monograph::after { display: none; }
}

/* ---------- Thin rule separators ---------- */
.thin-rule {
    border: 0;
    border-top: 0.5px solid var(--foxed-edge);
    width: 40%;
    margin: 3rem auto;
}

.thin-rule.frontispiece__rule {
    width: 28%;
    margin: 2rem auto;
}

/* ---------- Frontispiece ---------- */
.frontispiece {
    text-align: center;
    padding: 5rem 0 3rem;
}
.frontispiece__pretitle {
    font-family: var(--sans);
    font-size: 0.7rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--leather-brown);
    margin-bottom: 2rem;
}
.frontispiece__title {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: clamp(2.6rem, 7vw, 4.8rem);
    line-height: 1;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--ink-black);
}
.frontispiece__dot {
    color: var(--crimson);
    font-style: normal;
}
.frontispiece__hanzi {
    font-size: clamp(2rem, 5vw, 3rem);
    color: var(--crimson);
    margin: 1rem 0 0;
    letter-spacing: 0.5rem;
    font-family: "EB Garamond", "Songti SC", "STSong", serif;
    opacity: 0.92;
}
.frontispiece__subtitle {
    font-family: var(--serif);
    font-size: 1.4rem;
    color: var(--leather-brown);
    margin: 0 0 2.5rem;
    font-feature-settings: "liga" on;
}
.frontispiece__imprint {
    font-family: var(--serif);
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--ink-black);
    margin-bottom: 3rem;
}
.frontispiece__edition {
    font-family: var(--sans);
    font-size: 0.7rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--leather-brown);
    margin: 0;
}

/* ---------- Chapter markers ---------- */
.chapter-marker {
    font-family: var(--sans);
    font-size: 0.72rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--scholar-green);
    margin: 0 0 0.5rem;
    font-variant-numeric: oldstyle-nums;
    font-weight: 700;
}
.chapter-marker--green { color: var(--scholar-green); }

/* ---------- Section titles ---------- */
.section-title {
    font-family: var(--serif);
    font-weight: 500;
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    line-height: 1.2;
    color: var(--ink-black);
    margin: 0.25rem 0 2rem;
    letter-spacing: -0.005em;
}
.section-title em { font-style: italic; }

/* ---------- Preface ---------- */
.preface .lead {
    font-size: 1.15rem;
    line-height: 1.85;
    color: var(--ink-black);
    position: relative;
}

/* ---------- Table of Contents ---------- */
.contents {
    margin: 4rem 0;
    counter-reset: tocItem;
}
.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.toc-list__item {
    counter-increment: tocItem;
    position: relative;
    margin: 0 0 1.6rem;
    padding-left: 3rem;
}
.toc-list__item::before {
    content: counter(tocItem, upper-roman) ".";
    position: absolute;
    left: 0;
    top: 0;
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    color: var(--scholar-green);
    font-size: 1rem;
    letter-spacing: 0.05em;
    width: 2.4rem;
    text-align: right;
    padding-right: 0.6rem;
}

.toc-list__link {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    font-family: var(--serif);
    font-size: 1.1rem;
    color: var(--ink-black);
    border-bottom: none;
    padding: 0.1rem 0;
}
.toc-list__link:hover { background: transparent; }
.toc-list__link:hover .toc-list__title {
    color: var(--crimson);
}

.toc-list__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc-list__leader {
    flex: 1;
    border-bottom: 0.5px dotted var(--foxed-edge);
    transform: translateY(-0.35em);
    min-width: 1.5rem;
}
.toc-list__page {
    font-family: var(--sans);
    font-size: 0.82rem;
    letter-spacing: 0.15em;
    color: var(--leather-brown);
    font-variant-numeric: oldstyle-nums tabular-nums;
}

.toc-list--sub {
    margin: 0.6rem 0 0;
    padding-left: 0.5rem;
    counter-reset: subItem;
}
.toc-list--sub li {
    list-style: none;
    margin: 0.2rem 0;
}
.toc-list--sub a {
    font-family: var(--serif);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--leather-brown);
    border-bottom: none;
}
.toc-list--sub a:hover {
    color: var(--crimson);
    background: transparent;
}

/* ---------- Chapters ---------- */
.chapter {
    counter-increment: chapter;
    margin: 4rem 0;
    position: relative;
}

.chapter .chapter-marker::before {
    content: "";
}

.chapter__epigraph {
    font-style: italic;
    font-size: 1rem;
    color: var(--leather-brown);
    text-align: right;
    margin: 0 0 2.5rem;
    padding-right: 1rem;
    border-right: 0.5px solid var(--foxed-edge);
    line-height: 1.6;
}
.chapter__epigraph-attr {
    display: inline-block;
    margin-top: 0.4rem;
    font-style: normal;
    font-family: var(--sans);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--leather-brown);
}

.chapter__body {
    font-size: 1.05rem;
    line-height: 1.9;
    color: var(--ink-black);
    text-align: justify;
    hyphens: auto;
    position: relative;
}

/* Drop cap on the first paragraph of each chapter body */
.chapter__body--dropcap::first-letter {
    float: left;
    font-family: var(--serif);
    font-weight: 500;
    font-size: 4.6rem;
    line-height: 0.9;
    color: var(--crimson);
    margin: 0.3rem 0.6rem -0.2rem 0;
    padding-top: 0.2rem;
    text-transform: uppercase;
    font-feature-settings: "liga" on;
}

/* ---------- Footnote markers (raised) ---------- */
.footnote-marker {
    font-family: var(--sans);
    font-size: 0.65rem;
    color: var(--crimson);
    vertical-align: super;
    line-height: 0;
    margin-left: 0.1rem;
    letter-spacing: 0.05em;
    font-variant-numeric: tabular-nums;
}

/* ---------- Sidenotes ---------- */
.sidenote {
    position: absolute;
    right: calc(-1 * var(--sidenote-width) - var(--sidenote-gap));
    width: var(--sidenote-width);
    font-family: var(--sans);
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--leather-brown);
    text-align: left;
    font-style: normal;
    margin-top: 0.3rem;
    padding-left: 0.6rem;
    border-left: 0.5px solid var(--foxed-edge);
    transition: color 0.3s ease, border-color 0.3s ease;
}
.sidenote__marker {
    display: inline-block;
    color: var(--crimson);
    margin-right: 0.3rem;
    font-family: var(--serif);
    font-size: 0.95rem;
    line-height: 1;
    vertical-align: baseline;
}

/* On narrower viewports, fall back to inline parenthetical-style notes */
@media (max-width: 1100px) {
    .sidenote {
        position: static;
        display: block;
        width: auto;
        margin: 1.2rem 0 1.2rem 1.5rem;
        padding: 0.5rem 0.9rem;
        border-left: 2px solid var(--scholar-green);
        background: var(--aged-paper);
        font-size: 0.78rem;
    }
}

/* ---------- Pull quote / blockquote ---------- */
.pull-quote {
    margin: 2.5rem 0;
    padding: 1.5rem 1.75rem 1.2rem;
    background: var(--aged-paper);
    border-left: 2px solid var(--crimson);
    font-style: italic;
    font-size: 1rem;
    line-height: 1.75;
    color: var(--ink-black);
    position: relative;
}
.pull-quote::before {
    content: "\201C";
    position: absolute;
    top: -0.5rem;
    left: 0.5rem;
    font-family: var(--serif);
    font-style: italic;
    font-size: 4rem;
    color: var(--crimson);
    opacity: 0.25;
    line-height: 1;
}
.pull-quote p { margin: 0 0 0.8rem; }
.pull-quote cite {
    display: block;
    font-family: var(--sans);
    font-style: normal;
    font-size: 0.74rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--leather-brown);
    text-align: right;
}

/* ---------- Footnote apparatus ---------- */
.footnote-list {
    list-style: none;
    padding: 0;
    margin: 1.5rem 0 0;
    counter-reset: fn;
    font-family: var(--sans);
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--leather-brown);
}
.footnote-list li {
    counter-increment: fn;
    margin: 0 0 1rem;
    padding-left: 1.8rem;
    position: relative;
}
.footnote-list li::before {
    content: counter(fn) ".";
    position: absolute;
    left: 0;
    top: 0;
    color: var(--crimson);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ---------- Colophon ---------- */
.colophon {
    text-align: center;
    margin: 4rem 0 0;
    padding: 2rem 0 0;
}
.colophon__text {
    max-width: 480px;
    margin: 0 auto 2rem;
    font-style: italic;
    font-size: 0.95rem;
    color: var(--leather-brown);
    line-height: 1.8;
}
.colophon__ornament {
    color: var(--crimson);
    font-size: 1.6rem;
    letter-spacing: 0.6rem;
    margin: 0 0 2rem;
    opacity: 0.85;
}
.colophon__finis {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.1rem;
    color: var(--leather-brown);
    margin: 0;
    letter-spacing: 0.05em;
}

/* ---------- Chapter title scroll-target offset ---------- */
.chapter,
section[data-chapter] {
    scroll-margin-top: 4.5rem;
}

/* ---------- Reveal animation (subtle fade-in for chapters) ---------- */
.chapter,
.preface,
.contents,
.footnotes,
.colophon {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.9s ease, transform 0.9s ease;
}
.chapter.is-visible,
.preface.is-visible,
.contents.is-visible,
.footnotes.is-visible,
.colophon.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Frontispiece always visible from the start */
.frontispiece { opacity: 1; transform: none; }

/* ---------- Highlighted active chapter in TOC ---------- */
.toc-list__link.is-current .toc-list__title {
    color: var(--crimson);
    font-style: italic;
}
.toc-list__link.is-current .toc-list__page {
    color: var(--crimson);
}

/* ---------- Small screens ---------- */
@media (max-width: 600px) {
    html { font-size: 17px; }
    .monograph { padding: 2.5rem 1.25rem 4rem; }
    .frontispiece { padding: 3rem 0 2rem; }
    .chapter__body { text-align: left; }
    .chapter__body--dropcap::first-letter {
        font-size: 3.5rem;
    }
    .chapter__epigraph {
        text-align: left;
        border-right: none;
        border-left: 0.5px solid var(--foxed-edge);
        padding-right: 0;
        padding-left: 1rem;
    }
    .toc-list__link {
        flex-wrap: wrap;
    }
    .toc-list__leader { display: none; }
}
