:root {
    --deep-walnut: #2C1810;
    --antique-cream: #F5EDE0;
    --aged-parchment: #EDE3D1;
    --burnt-sienna: #A0522D;
    --tarnished-gold: #B8860B;
    --lamp-black: #1A120B;
    --warm-ivory: #FFF8EE;
    --faded-ink: #6B5744;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-snap-type: y proximity; }

body {
    background: var(--antique-cream);
    color: var(--deep-walnut);
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: rgba(160, 82, 45, 0.2);
}

/* Running Header */
.running-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: transparent;
    transition: opacity 400ms ease;
}

.running-header.faded {
    opacity: 0.3;
}

.running-header:hover {
    opacity: 1;
}

.header-link {
    font-family: 'Courier Prime', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--faded-ink);
    text-decoration: none;
    transition: color 300ms ease;
}

.header-link:hover {
    color: var(--burnt-sienna);
}

.header-sep {
    color: var(--faded-ink);
    opacity: 0.3;
    font-size: 0.75rem;
}

/* Spine Rule */
.spine-rule {
    position: fixed;
    top: 0;
    left: 61.8%;
    width: 1px;
    height: 100%;
    background: rgba(139, 115, 85, 0.12);
    z-index: 50;
    pointer-events: none;
}

/* Folio Base */
.folio {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(4rem, 8vw, 8rem) clamp(2rem, 8vw, 8rem);
    scroll-snap-align: start;
}

.folio-cream { background: var(--antique-cream); }
.folio-parchment { background: var(--aged-parchment); }
.folio-dark { background: var(--lamp-black); color: var(--warm-ivory); }

.folio-deep {
    background: linear-gradient(180deg, var(--aged-parchment), #D9CCB8);
}

/* Folio Numbers */
.folio-number {
    position: absolute;
    top: 50%;
    left: 2vw;
    transform: translateY(-50%) rotate(-90deg);
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--faded-ink);
    letter-spacing: 0.1em;
}

.folio-number-light {
    color: var(--faded-ink);
    opacity: 0.5;
}

/* Marginal Notes */
.marginal-note {
    position: absolute;
    top: 50%;
    right: 2vw;
    transform: translateY(-50%) rotate(90deg);
    font-family: 'Courier Prime', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--faded-ink);
    opacity: 0.4;
}

/* Folio Reveal Animation */
.folio-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 700ms cubic-bezier(0.25, 0.1, 0.25, 1), transform 700ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

.folio-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Pilcrow Divider */
.pilcrow-divider {
    height: 15vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pilcrow {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--tarnished-gold);
    opacity: 0;
    transition: opacity 2s ease;
}

.pilcrow.visible {
    animation: pilcrow-pulse 4s ease-in-out infinite;
}

@keyframes pilcrow-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

/* Folio I: The Blank Page */
.folio-center {
    text-align: center;
    position: relative;
}

.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--burnt-sienna);
    animation: blink 1s step-end infinite;
    position: absolute;
    top: 50%;
    left: 61.8%;
    transform: translate(-50%, -50%);
}

.typewriter-cursor.hidden { display: none; }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.site-title {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-size: clamp(2.8rem, 6vw, 5.5rem);
    letter-spacing: 0.04em;
    line-height: 1.12;
    color: var(--deep-walnut);
    visibility: hidden;
}

.site-title.typed {
    visibility: visible;
}

.site-subtitle {
    font-family: 'Courier Prime', monospace;
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    letter-spacing: 0.06em;
    color: var(--faded-ink);
    margin-top: 1rem;
    visibility: hidden;
}

.site-subtitle.typed {
    visibility: visible;
}

/* Typewriter typed characters */
.typed-char {
    display: inline-block;
    animation: typeStrike 100ms ease-out forwards;
}

@keyframes typeStrike {
    0% { transform: translateY(4px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Folio II: Z-Layout */
.z-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 34px;
    max-width: 900px;
    width: 100%;
    min-height: 60vh;
}

.z-top-left { align-self: start; }
.z-top-right { align-self: start; justify-self: end; }
.z-bottom-left { align-self: end; }
.z-bottom-right { align-self: end; justify-self: end; }

.body-text {
    max-width: 680px;
    color: var(--deep-walnut);
}

.drop-cap {
    float: left;
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 4.5rem;
    line-height: 0.8;
    color: var(--tarnished-gold);
    margin-right: 0.15em;
    margin-top: 0.05em;
}

.pull-quote {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.4rem, 3vw, 2rem);
    color: var(--deep-walnut);
    max-width: 20ch;
    line-height: 1.3;
}

.flourish-svg {
    width: 250px;
    height: 250px;
}

.flourish-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.folio-reveal.visible .flourish-path {
    stroke-dashoffset: 0;
}

.ink-dots {
    width: 150px;
    height: 150px;
    opacity: 0.6;
}

/* Folio III: Manuscript */
.folio-manuscript {
    align-items: flex-start;
    padding-top: clamp(6rem, 10vh, 10rem);
}

.ruled-lines {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 680px;
    max-width: 90%;
}

.ruled-line {
    display: block;
    height: 1px;
    background: rgba(139, 115, 85, 0.08);
    margin-bottom: 2rem;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 400ms ease;
}

.folio-manuscript.lines-drawn .ruled-line {
    transform: scaleX(1);
}

.folio-manuscript.lines-drawn .ruled-line:nth-child(1) { transition-delay: 0ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(2) { transition-delay: 30ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(3) { transition-delay: 60ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(4) { transition-delay: 90ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(5) { transition-delay: 120ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(6) { transition-delay: 150ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(7) { transition-delay: 180ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(8) { transition-delay: 210ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(9) { transition-delay: 240ms; }
.folio-manuscript.lines-drawn .ruled-line:nth-child(10) { transition-delay: 270ms; }

.manuscript-column {
    position: relative;
    z-index: 2;
    max-width: 680px;
    margin: 0 auto;
}

.manuscript-block {
    margin-bottom: 55px;
}

.manuscript-art {
    display: flex;
    justify-content: center;
    margin: 55px 0;
}

.calligraphic-form {
    width: 100%;
    max-width: 400px;
    height: auto;
}

.cal-stroke {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 2.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.folio-reveal.visible .cal-stroke {
    stroke-dashoffset: 0;
}

/* Folio IV: Illumination */
.illumination-layout {
    text-align: center;
    max-width: 900px;
    width: 100%;
}

.folio-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: 0.04em;
    color: var(--deep-walnut);
    margin-bottom: 34px;
}

.illumination-canvas {
    display: flex;
    justify-content: center;
    margin-bottom: 34px;
}

.illumination-svg {
    width: 80vw;
    max-width: 600px;
    height: auto;
}

.illum-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.folio-reveal.visible .illum-path {
    stroke-dashoffset: 0;
}

.illumination-caption {
    font-family: 'Courier Prime', monospace;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    color: var(--faded-ink);
    max-width: 45ch;
    margin: 0 auto;
}

/* Horizontal Rule Divider */
.section-rule {
    display: block;
    width: 0;
    height: 1px;
    background: rgba(160, 82, 45, 0.4);
    margin: 34px auto;
    transition: width 800ms ease;
}

.section-rule.visible {
    width: 400px;
}

/* Folio V: Colophon */
.folio-dark {
    position: relative;
    overflow: hidden;
}

.endpaper-pattern {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.08;
    pointer-events: none;
}

.colophon-content {
    position: relative;
    z-index: 2;
    text-align: center;
    max-width: 500px;
}

.colophon-flourish {
    width: 200px;
    height: 60px;
    margin: 0 auto 34px;
}

.colophon-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 0.04em;
    color: var(--warm-ivory);
    margin-bottom: 21px;
}

.colophon-line {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 1.1rem;
    line-height: 1.6;
    color: rgba(255, 248, 238, 0.7);
    max-width: 35ch;
    margin: 0 auto;
}

.colophon-rule {
    width: 200px;
    height: 1px;
    background: var(--tarnished-gold);
    margin: 34px auto;
    opacity: 0.4;
}

.colophon-details {
    font-family: 'Courier Prime', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--faded-ink);
    line-height: 1.8;
}

/* Responsive */
@media (max-width: 768px) {
    .running-header {
        flex-wrap: wrap;
        gap: 0.3rem;
        padding: 0.5rem 1rem;
    }

    .header-sep { display: none; }

    .spine-rule { display: none; }

    .folio-number, .marginal-note { display: none; }

    .z-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 21px;
    }

    .z-top-right, .z-bottom-right { justify-self: start; }

    .flourish-svg { width: 180px; height: 180px; }
    .ink-dots { width: 100px; height: 100px; }

    .folio-manuscript { padding-top: 5rem; }
    .ruled-lines { display: none; }

    .folio {
        padding: 3rem 1.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-snap-type: none; }

    .typewriter-cursor { animation: none; opacity: 1; }
    .pilcrow { animation: none; opacity: 0.5; }

    .folio-reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .flourish-path, .cal-stroke, .illum-path {
        stroke-dashoffset: 0;
        transition: none;
    }

    .ruled-line {
        transform: scaleX(1);
        transition: none;
    }

    .typed-char {
        animation: none;
    }

    .ink-dots circle animate { display: none; }
}
