:root {
    --espresso-bark: #3B2412;
    --walnut: #6B4C33;
    --fieldstone: #8B7355;
    --parchment-gold: #C4B49A;
    --pressed-linen: #F5EDE0;
    --vellum: #FAF6F0;
    --specimen-leaf: #4A6741;
    --pressed-rose: #8B3A3A;
    --herbarium-gold: #D4A853;
}

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

body {
    background: linear-gradient(to bottom, var(--vellum), #F0E8D8);
    color: #4A3728;
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw, 1.2rem);
    line-height: 1.72;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Grain overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 23px,
            rgba(139, 115, 85, 0.02) 23px,
            rgba(139, 115, 85, 0.02) 24px
        );
    pointer-events: none;
    z-index: 1000;
}

/* Binding Stitches */
.binding-stitches {
    position: fixed;
    left: 24px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 20px,
        var(--parchment-gold) 20px,
        var(--parchment-gold) 24px
    );
    opacity: 0.5;
    z-index: 50;
}

/* Bookmark Navigation */
.bookmarks {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bookmark {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 6px 12px 6px 8px;
    background: var(--walnut);
    color: var(--pressed-linen);
    text-decoration: none;
    font-family: 'Playfair Display', serif;
    font-size: 0.75rem;
    border-radius: 2px 0 0 2px;
    transform: translateX(calc(100% - 28px));
    transition: transform 200ms ease, box-shadow 200ms ease;
}

.bookmark:hover,
.bookmark.active {
    transform: translateX(0);
}

.bookmark.active {
    box-shadow: 0 0 8px rgba(212, 168, 83, 0.4);
    background: var(--herbarium-gold);
    color: var(--espresso-bark);
}

.bm-num {
    font-weight: 900;
    min-width: 16px;
    text-align: center;
}

.bm-label {
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    white-space: nowrap;
}

/* Lens Flare */
.lens-flare {
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    animation: flare-pulse 12s ease-in-out infinite;
}

.flare-hero {
    top: 5%;
    right: 10%;
    background:
        radial-gradient(circle, rgba(212, 168, 83, 0.35) 0%, transparent 60%),
        radial-gradient(circle at 60% 40%, rgba(245, 237, 224, 0.2) 0%, transparent 50%);
}

.flare-mid {
    top: auto;
    bottom: 20%;
    left: 15%;
    background:
        radial-gradient(circle, rgba(212, 168, 83, 0.25) 0%, transparent 55%),
        radial-gradient(circle at 40% 60%, rgba(139, 58, 58, 0.06) 0%, transparent 50%);
}

@keyframes flare-pulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* Folio */
.folio {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: #2C1810;
    position: relative;
}

.folio-spread {
    display: flex;
    max-width: 1000px;
    width: 100%;
    position: relative;
}

.folio-page {
    flex: 1;
    background: var(--vellum);
    padding: clamp(2rem, 5vw, 4rem);
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    animation: folio-open 1200ms ease forwards;
}

.folio-left {
    transform-origin: right center;
    animation-name: folio-left-open;
}

.folio-right {
    transform-origin: left center;
    animation-name: folio-right-open;
    align-items: center;
}

@keyframes folio-left-open {
    from { transform: perspective(800px) rotateY(5deg); }
    to { transform: perspective(800px) rotateY(0); }
}

@keyframes folio-right-open {
    from { transform: perspective(800px) rotateY(-5deg); }
    to { transform: perspective(800px) rotateY(0); }
}

.folio-spine {
    width: 4px;
    background: linear-gradient(to bottom, rgba(59, 36, 18, 0.3), rgba(59, 36, 18, 0.1), rgba(59, 36, 18, 0.3));
    flex-shrink: 0;
}

.folio-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(3rem, 7vw, 6.5rem);
    color: var(--espresso-bark);
    letter-spacing: 0.04em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.folio-subtitle {
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--walnut);
}

.specimen-tree {
    width: 100%;
    max-width: 350px;
    height: auto;
}

/* Plates */
.plate {
    min-height: 90vh;
    padding: clamp(4rem, 10vh, 8rem) clamp(2rem, 6vw, 6rem);
    position: relative;
}

.plate-odd { padding-left: 8%; }
.plate-even { padding-right: 8%; display: flex; flex-direction: column; align-items: flex-end; }

.plate-label {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 0.85rem;
    letter-spacing: 0.3em;
    color: var(--parchment-gold);
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.plate-rule {
    display: inline-block;
    width: 40px;
    height: 1px;
    background: var(--parchment-gold);
}

/* Specimen Cards */
.specimen-card {
    background: var(--pressed-linen);
    border: 0.5px solid var(--fieldstone);
    border-radius: 4px;
    padding: clamp(2rem, 4vw, 3rem);
    max-width: 700px;
    box-shadow:
        0 2px 4px rgba(87, 62, 36, 0.15),
        0 12px 32px rgba(87, 62, 36, 0.08);
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2rem;
}

.card-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    color: var(--espresso-bark);
    letter-spacing: 0.04em;
    line-height: 1.1;
    margin-bottom: 1.5rem;
}

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

.card-illustration {
    display: flex;
    align-items: center;
}

.card-illustration svg {
    width: clamp(100px, 15vw, 180px);
    height: auto;
}

.code-specimen {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    color: #2C1810;
    background: var(--pressed-linen);
    border: 1px dashed var(--parchment-gold);
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    white-space: pre-wrap;
}

.code-danger {
    border-color: var(--pressed-rose);
    color: var(--pressed-rose);
}

.margin-annotation {
    position: absolute;
    right: -220px;
    top: 50%;
    transform: translateY(-50%);
    width: 180px;
    font-family: 'Caveat', cursive;
    font-size: 0.9rem;
    color: #7B6348;
    opacity: 0.8;
    line-height: 1.4;
}

.page-curl {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, transparent 50%, rgba(196, 180, 154, 0.3) 50%);
    border-radius: 0 0 4px 0;
    transition: width 300ms ease, height 300ms ease;
}

.specimen-card:hover .page-curl {
    width: 35px;
    height: 35px;
}

/* Slide Animation */
.slide-card {
    opacity: 0;
    transition: opacity 500ms ease, transform 600ms cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.plate-odd .slide-card {
    transform: translateX(-100%);
}

.plate-even .slide-card {
    transform: translateX(100%);
}

.slide-card.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Colophon */
.colophon {
    min-height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.colophon-ornament {
    width: 80px;
    margin-bottom: 2rem;
}

.colophon-text {
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--walnut);
    max-width: 40ch;
    margin-bottom: 1.5rem;
}

.colophon-domain {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    color: var(--parchment-gold);
}

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

    .folio-left, .folio-right {
        animation: none;
        transform: none;
    }

    .folio-spine { display: none; }
    .binding-stitches { display: none; }

    .bookmarks { display: none; }

    .plate-odd { padding-left: clamp(1.5rem, 4vw, 3rem); }
    .plate-even {
        padding-right: clamp(1.5rem, 4vw, 3rem);
        align-items: flex-start;
    }

    .specimen-card {
        grid-template-columns: 1fr;
    }

    .margin-annotation {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: 100%;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px dashed var(--parchment-gold);
    }
}

@media (prefers-reduced-motion: reduce) {
    .folio-left, .folio-right {
        animation: none;
        transform: none;
    }
    .slide-card {
        opacity: 1;
        transform: none;
        transition: none;
    }
    .lens-flare { animation: none; opacity: 0.7; }
    .page-curl { transition: none; }
}
