:root {
    --parchment-black: #0C0A08;
    --manuscript-dark: #1A1610;
    --gold-illuminated: #D4A843;
    --gold-antique: #BFA264;
    --gold-faded: #8A7A4E;
    --manuscript-cream: #E8DCC0;
    --copper-oxidized: #7A5C3A;
    --crimson-seal: #8B2E2E;
}

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

body {
    background: var(--parchment-black);
    color: var(--gold-antique);
    font-family: 'Libre Baskerville', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.75;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Paper texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 3px,
            rgba(58, 42, 26, 0.03) 3px,
            rgba(58, 42, 26, 0.03) 4px
        );
    pointer-events: none;
    z-index: 1000;
}

/* Page Base */
.page {
    position: relative;
    z-index: 1;
}

/* Cover */
.page-cover {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.cover-content {
    text-align: center;
    max-width: 700px;
}

.hero-title {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5rem);
    color: var(--gold-illuminated);
    letter-spacing: 0.08em;
    line-height: 1.1;
    text-shadow: 0 0 20px rgba(212, 168, 67, 0.3);
    opacity: 0;
    animation: fade-up 1.2s ease forwards 1s;
}

.hero-tagline {
    font-family: 'Libre Baskerville', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.35rem);
    color: var(--gold-antique);
    margin-top: 1.5rem;
    opacity: 0;
    animation: fade-up 1.2s ease forwards 1.8s;
}

@keyframes fade-up {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.circuit-ornament {
    width: 100%;
    max-width: 500px;
    margin-top: 3rem;
    opacity: 0;
    animation: fade-up 1s ease forwards 2.6s;
}

.vine-path {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: draw-vine 2.5s ease-in-out forwards 2.8s;
}

.circuit-node {
    opacity: 0;
    animation: node-appear 0.5s ease forwards;
}

.circuit-node:nth-child(1) { animation-delay: 3.5s; }
.circuit-node:nth-child(2) { animation-delay: 3.8s; }
.circuit-node:nth-child(3) { animation-delay: 4.1s; }

@keyframes draw-vine {
    to { stroke-dashoffset: 0; }
}

@keyframes node-appear {
    from { opacity: 0; transform: scale(0); }
    to { opacity: 1; transform: scale(1); }
}

/* Illumination */
.page-illumination {
    min-height: 100vh;
    padding: clamp(6rem, 15vh, 12rem) clamp(2rem, 8vw, 8rem);
    display: flex;
    gap: 4rem;
}

.content-block {
    max-width: 55%;
}

.content-left {
    margin-right: auto;
}

.side-ornament {
    position: absolute;
    right: clamp(3rem, 6vw, 8rem);
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 400px;
}

.vine-vertical {
    width: 100%;
    height: 100%;
}

.vine-draw {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 2s ease-in-out;
}

.vine-draw.drawn {
    stroke-dashoffset: 0;
}

.drop-cap-container {
    float: left;
    margin-right: 0.8rem;
    margin-bottom: 0.3rem;
}

.drop-cap {
    width: 48px;
    height: 48px;
}

.body-text {
    margin-bottom: 1.5rem;
    max-width: 55ch;
}

/* Scroll Reveal */
.scroll-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 800ms ease, transform 800ms ease;
}

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

/* Bestiary */
.page-bestiary {
    padding: clamp(8rem, 20vh, 16rem) clamp(2rem, 8vw, 8rem);
}

.bestiary-entry {
    display: flex;
    gap: 1.5rem;
    max-width: 700px;
    margin-bottom: 4rem;
}

.bestiary-entry:nth-child(odd) {
    margin-left: 5%;
}

.bestiary-entry:nth-child(even) {
    margin-left: 15%;
}

.entry-initial {
    flex-shrink: 0;
}

.entry-initial svg {
    width: 48px;
    height: 48px;
}

.entry-heading {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    color: var(--gold-illuminated);
    letter-spacing: 0.08em;
    line-height: 1.1;
    margin-bottom: 1.5rem;
    text-shadow: 0 0 15px rgba(212, 168, 67, 0.2);
}

.entry-danger {
    color: var(--crimson-seal);
    text-shadow: 0 0 15px rgba(139, 46, 46, 0.2);
}

.code-element {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.9em;
    letter-spacing: 0.05em;
    color: var(--gold-faded);
    margin-top: 1rem;
}

.code-danger {
    color: var(--crimson-seal);
}

.circuit-divider {
    width: 80%;
    max-width: 600px;
    margin: 2rem auto 4rem;
    display: block;
}

.circuit-divider .vine-path {
    animation: none;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 2s ease-in-out;
}

.circuit-divider.drawn .vine-path {
    stroke-dashoffset: 0;
}

/* Provenance Map */
.page-provenance {
    min-height: 100vh;
    padding: clamp(6rem, 15vh, 12rem) clamp(2rem, 6vw, 6rem);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.section-heading {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    color: var(--gold-illuminated);
    letter-spacing: 0.08em;
    text-shadow: 0 0 15px rgba(212, 168, 67, 0.2);
    margin-bottom: 4rem;
    text-align: center;
}

.tree-container {
    width: 100%;
    max-width: 600px;
    position: relative;
}

.dep-tree {
    width: 100%;
    height: auto;
}

.tree-node {
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), r 0.3s ease;
}

.tree-node:hover {
    filter: drop-shadow(0 0 8px rgba(212, 168, 67, 0.6));
}

.tree-branch {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease-in-out;
}

.tree-branch.drawn {
    stroke-dashoffset: 0;
}

.tree-tooltip {
    position: fixed;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--manuscript-cream);
    background: var(--manuscript-dark);
    padding: 4px 10px;
    border: 1px solid var(--copper-oxidized);
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease;
    z-index: 100;
    white-space: nowrap;
}

.tree-tooltip.active {
    opacity: 1;
}

/* Seal */
.page-seal {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    background: linear-gradient(to bottom, var(--parchment-black), #060503);
}

.seal-content {
    text-align: center;
}

.seal-statement {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    color: var(--gold-illuminated);
    letter-spacing: 0.04em;
    line-height: 1.3;
    max-width: 20ch;
    margin: 0 auto 3rem;
    text-shadow: 0 0 30px rgba(212, 168, 67, 0.2);
}

.seal-ornament {
    width: 120px;
    height: 120px;
    margin: 0 auto 2rem;
    display: block;
}

.seal-circle {
    stroke-dasharray: 320;
    stroke-dashoffset: 320;
    transition: stroke-dashoffset 2s ease-in-out;
}

.seal-ornament.visible .seal-circle {
    stroke-dashoffset: 0;
}

.seal-vine {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 1.5s ease-in-out 0.5s;
}

.seal-ornament.visible .seal-vine {
    stroke-dashoffset: 0;
}

.seal-domain {
    font-family: 'Libre Baskerville', serif;
    font-weight: 400;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--gold-faded);
    letter-spacing: 0.12em;
    margin-bottom: 0.5rem;
}

.seal-year {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--gold-faded);
    letter-spacing: 0.1em;
    opacity: 0.5;
}

/* Responsive */
@media (max-width: 768px) {
    .page-illumination {
        flex-direction: column;
    }

    .content-block {
        max-width: 100%;
    }

    .side-ornament {
        display: none;
    }

    .bestiary-entry {
        flex-direction: column;
        gap: 1rem;
    }

    .bestiary-entry:nth-child(odd),
    .bestiary-entry:nth-child(even) {
        margin-left: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hero-title, .hero-tagline, .circuit-ornament {
        opacity: 1;
        animation: none;
        transform: none;
    }
    .vine-path {
        stroke-dashoffset: 0;
        animation: none;
    }
    .circuit-node {
        opacity: 1;
        animation: none;
    }
    .scroll-reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }
    .vine-draw {
        stroke-dashoffset: 0;
        transition: none;
    }
    .circuit-divider .vine-path {
        stroke-dashoffset: 0;
        transition: none;
    }
    .tree-branch {
        stroke-dashoffset: 0;
        transition: none;
    }
    .seal-circle, .seal-vine {
        stroke-dashoffset: 0;
        transition: none;
    }
    .tree-node { transition: none; }
}
