:root {
    --bg-cool: #f4f0e8;
    --bg-warm: #e8dcc8;
    --ink: #2c2416;
    --green: #4a6741;
    --purple: #7b5ea7;
    --copper: #b8733e;
    --sepia: #8b7355;
    --petal: #d4a0b0;
    --white: #ffffff;
}

::selection {
    background: var(--petal);
    color: var(--ink);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Serif 4', serif;
    font-size: clamp(1rem, 1.1vw + 0.5rem, 1.2rem);
    line-height: 1.7;
    color: var(--ink);
    overflow-x: hidden;
}

#bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, var(--bg-cool), var(--bg-warm));
    z-index: -2;
    transition: opacity 0.3s;
}

/* Stem Progress Indicator */
#stem-indicator {
    position: fixed;
    right: 1.5rem;
    top: 10vh;
    height: 80vh;
    width: 40px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.6s;
}

#stem-indicator.visible {
    opacity: 1;
}

#stem-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

.stem-leaf {
    transform-origin: center bottom;
    transform: scale(0);
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stem-leaf.sprouted {
    transform: scale(1);
}

.stem-flower {
    transform-origin: center center;
    transform: scale(0);
    transition: transform 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stem-flower.bloomed {
    transform: scale(1);
}

/* Cover */
#cover {
    position: relative;
    width: 100%;
    height: 100vh;
    background: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    z-index: 1;
}

#cover-border {
    position: absolute;
    inset: 2rem;
    width: calc(100% - 4rem);
    height: calc(100% - 4rem);
}

.border-path {
    stroke-dasharray: 4000;
    stroke-dashoffset: 4000;
    animation: drawBorder 2s ease-in-out 0.6s forwards;
}

@keyframes drawBorder {
    to { stroke-dashoffset: 0; }
}

#cover-content {
    text-align: center;
    z-index: 2;
}

#cover-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(3rem, 9vw, 7rem);
    color: var(--bg-cool);
    opacity: 0;
    animation: fadeIn 0.8s ease 1.2s forwards;
    letter-spacing: 0.02em;
    line-height: 1.05;
}

#cover-subtitle {
    font-family: 'Caveat', cursive;
    font-size: 1.3rem;
    color: var(--sepia);
    opacity: 0;
    animation: fadeIn 0.6s ease 1.6s forwards;
    transform: rotate(-2deg);
}

@keyframes fadeIn {
    to { opacity: 1; }
}

#scroll-arrow {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    animation: fadeIn 0.5s ease 2.2s forwards, pulse 2s ease-in-out 2.7s infinite;
}

@keyframes pulse {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

/* Folio Sections */
.folio-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 6rem 2rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

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

.folio-section.recto {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 3rem;
}

.folio-section.verso {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 3rem;
}

.illustration-col {
    position: sticky;
    top: 2rem;
    align-self: start;
}

.botanical-illustration {
    width: 100%;
    max-width: 300px;
    height: auto;
}

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

.draw-path.detail {
    transition-duration: 1.5s;
}

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

.annotation {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: var(--sepia);
    line-height: 1.4;
    margin-top: 1rem;
    transform: rotate(-1.5deg);
}

.musical-label {
    font-family: 'EB Garamond', serif;
    font-weight: 500;
    font-variant: small-caps;
    font-size: 0.8rem;
    letter-spacing: 0.15em;
    color: var(--purple);
}

.text-col h2 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(2.8rem, 7vw + 0.3rem, 6rem);
    letter-spacing: 0.02em;
    line-height: 1.05;
    margin-bottom: 1.5rem;
    color: var(--ink);
}

.drop-cap {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-style: italic;
    font-size: 4.5em;
    float: left;
    line-height: 0.7;
    margin-right: 0.1em;
    margin-top: 0.05em;
    color: var(--copper);
}

.text-col p {
    margin-bottom: 1.2rem;
}

.text-col p em {
    font-style: italic;
}

.musical-term {
    font-family: 'EB Garamond', serif;
    font-weight: 500;
    font-variant: small-caps;
    font-size: 0.9em;
    letter-spacing: 0.15em;
    color: var(--purple);
}

.marginalia {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: var(--sepia);
    line-height: 1.4;
    transform: rotate(-1.5deg);
    border-left: 2px solid var(--copper);
    padding-left: 1rem;
    margin-top: 2rem;
}

/* Musical Stave Interstitials */
.musical-stave {
    max-width: 900px;
    margin: 2rem auto;
    padding: 2rem;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.musical-stave.visible {
    opacity: 1;
}

.musical-stave svg {
    width: 100%;
    height: auto;
}

.note-element {
    opacity: 0;
    transform: scale(0);
    transform-origin: center center;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition-delay: calc(var(--note-delay) * 150ms);
}

.musical-stave.visible .note-element {
    opacity: 1;
    transform: scale(1);
}

/* Coda */
#coda {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to bottom, transparent, var(--white));
}

#coda-content {
    text-align: center;
}

#coda-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-size: clamp(4rem, 12vw, 9rem);
    color: var(--ink);
    opacity: 0.15;
    letter-spacing: 0.02em;
    line-height: 1.05;
}

#coda-fin {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--sepia);
    margin-top: 1rem;
}

/* Mobile */
@media (max-width: 768px) {
    .folio-section.recto,
    .folio-section.verso {
        grid-template-columns: 1fr;
    }

    .illustration-col {
        position: static;
    }

    .folio-section.verso .text-col {
        order: -1;
    }

    #stem-indicator {
        display: none;
    }

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