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

:root {
    --vellum-cream: #f2e8d5;
    --parchment: #e6d5b8;
    --library-shadow: #2a1f14;
    --dark-leather: #3b2a1a;
    --gilt-edge: #c49a3c;
    --verdigris: #5b8a72;
    --faded-sienna: #7a6248;
    --warm-brown: #8b7355;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--vellum-cream);
    color: var(--library-shadow);
    font-family: 'Crimson Pro', serif;
    font-size: 18px;
    line-height: 1.7;
    overflow-x: hidden;
}

.chapter {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.chapter-light {
    background: var(--vellum-cream);
}

.chapter-dark {
    background: var(--library-shadow);
}

.noise-overlay {
    position: absolute;
    inset: 0;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    pointer-events: none;
}

.chapter-content {
    max-width: 1100px;
    width: 90%;
    padding: 4rem 2rem;
    position: relative;
    z-index: 1;
}

.chapter-label {
    font-family: 'Cormorant Garamond', serif;
    font-variant: small-caps;
    font-size: 1rem;
    letter-spacing: 0.15em;
    color: var(--warm-brown);
    margin-bottom: 0.5rem;
}

.chapter-label.light {
    color: var(--parchment);
}

.chapter-heading {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(2.5rem, 6vw, 5.5rem);
    line-height: 1.12;
    letter-spacing: 0.02em;
    color: var(--dark-leather);
    margin-bottom: 2rem;
}

.chapter-heading.light {
    color: var(--vellum-cream);
}

/* Chapter I — Title Page */
.title-page {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.title-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(4rem, 10vw, 8rem);
    line-height: 1.1;
    letter-spacing: 0.02em;
    color: var(--dark-leather);
    margin-bottom: 2rem;
    opacity: 0;
    animation: fadeSlideUp 1.5s cubic-bezier(0.25, 0.1, 0.25, 1.0) 0.2s forwards;
}

#monopole-diagram {
    width: 200px;
    height: 200px;
    image-rendering: pixelated;
    margin-bottom: 2rem;
    opacity: 0;
    animation: fadeSlideUp 1.5s cubic-bezier(0.25, 0.1, 0.25, 1.0) 0.8s forwards;
}

.subtitle {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
    color: var(--faded-sienna);
    opacity: 0;
    animation: fadeSlideUp 1.5s cubic-bezier(0.25, 0.1, 0.25, 1.0) 1.4s forwards;
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chapter II — The Study */
.study-layout {
    display: flex;
    gap: 4rem;
    align-items: center;
}

.study-text {
    flex: 0 0 60%;
}

.study-illustration {
    flex: 1;
    display: flex;
    justify-content: center;
}

#study-canvas {
    width: 100%;
    max-width: 256px;
    height: auto;
    image-rendering: pixelated;
}

.body-paragraph {
    font-family: 'Crimson Pro', serif;
    font-size: 1.125rem;
    line-height: 1.75;
    color: var(--library-shadow);
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0), transform 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.body-paragraph.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Chapter III — Field Lines */
.field-lines-layout {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#field-lines-svg {
    width: 100%;
    max-width: 800px;
    height: 400px;
    margin: 2rem 0;
}

#field-lines-svg line {
    stroke: var(--gilt-edge);
    stroke-width: 1;
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

#field-lines-svg line.drawn {
    stroke-dashoffset: 0;
}

.field-text {
    max-width: 500px;
    margin-top: 2rem;
}

.field-text p {
    font-family: 'Crimson Pro', serif;
    color: var(--vellum-cream);
    font-size: 1.05rem;
    line-height: 1.75;
    margin-bottom: 1.25rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 1s cubic-bezier(0.25, 0.1, 0.25, 1.0), transform 1s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.field-text p.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Chapter IV — Marginalia */
.marginalia-layout {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    position: relative;
}

.central-column {
    flex: 1;
    max-width: 650px;
    margin: 0 auto;
}

.marginalia-item {
    position: absolute;
    opacity: 0;
    transform: translateY(20px) rotate(-2deg);
    transition: opacity 1s cubic-bezier(0.25, 0.1, 0.25, 1.0), transform 1s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.marginalia-item.visible {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
}

.marginalia-item.left {
    left: 0;
    top: 30%;
}

.marginalia-item.right {
    right: 0;
    top: 50%;
}

.marginalia-icon {
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
}

.entry {
    border-left: 4px solid var(--gilt-edge);
    padding-left: 1.5rem;
    margin-bottom: 2rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0), transform 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.entry.visible {
    opacity: 1;
    transform: translateY(0);
}

.entry-text {
    font-family: 'Crimson Pro', serif;
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--library-shadow);
}

/* Chapter V — Colophon */
.colophon-section {
    min-height: auto;
    padding: 6rem 0;
}

.colophon-layout {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dither-rule {
    width: 100%;
    max-width: 400px;
    height: 8px;
    margin-bottom: 3rem;
    background: repeating-linear-gradient(
        90deg,
        var(--gilt-edge) 0px,
        var(--gilt-edge) 4px,
        transparent 4px,
        transparent 8px
    );
    background-size: 8px 4px;
    background-repeat: repeat;
    image-rendering: pixelated;
}

.colophon-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.colophon-line {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--parchment);
    letter-spacing: 0.03em;
}

.ex-libris {
    margin-top: 1.5rem;
    font-family: 'Cormorant Garamond', serif;
    font-variant: small-caps;
    font-size: 1.1rem;
    color: var(--gilt-edge);
    letter-spacing: 0.1em;
}

#printers-mark {
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
    margin: 1.5rem 0;
    animation: slowRotate 8s linear infinite;
}

@keyframes slowRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .study-layout {
        flex-direction: column;
        gap: 2rem;
    }

    .study-text {
        flex: 1;
    }

    .marginalia-item {
        position: static;
        opacity: 1;
        transform: none;
        margin: 1rem auto;
    }

    .marginalia-layout {
        flex-direction: column;
        align-items: center;
    }

    .chapter-content {
        padding: 3rem 1.5rem;
    }
}

@media (max-width: 480px) {
    .title-text {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .chapter-heading {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .colophon-section {
        min-height: auto;
    }
}
