:root {
    --bg-paper: #F5ECD7;
    --bg-deep: #2C1810;
    --text-ink: #2A2118;
    --accent-emerald: #1B6B4A;
    --accent-sapphire: #1E3A5F;
    --accent-garnet: #8B1A2B;
    --gold-foil: #8B6914;
    --foxed-amber: #C4A265;
    --annotation-ink: #5C4A2E;
    --font-display: 'Libre Baskerville', Georgia, serif;
    --font-body: 'Lora', Georgia, serif;
    --font-mono: 'Special Elite', monospace;
    --font-drop: 'Playfair Display', Georgia, serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-paper);
    color: var(--text-ink);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Layered paper texture: vignetting + foxing + ruled lines */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 0% 0%, rgba(44, 24, 16, 0.08) 0%, transparent 40%),
        radial-gradient(ellipse at 100% 0%, rgba(44, 24, 16, 0.06) 0%, transparent 35%),
        radial-gradient(ellipse at 0% 100%, rgba(44, 24, 16, 0.07) 0%, transparent 40%),
        radial-gradient(ellipse at 100% 100%, rgba(44, 24, 16, 0.09) 0%, transparent 35%),
        radial-gradient(circle at 20% 30%, rgba(139, 105, 20, 0.04) 0%, transparent 60%),
        radial-gradient(circle at 80% 70%, rgba(139, 105, 20, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 55% 15%, rgba(196, 162, 101, 0.03) 0%, transparent 30%),
        radial-gradient(circle at 35% 80%, rgba(196, 162, 101, 0.025) 0%, transparent 25%),
        radial-gradient(circle at 70% 40%, rgba(139, 105, 20, 0.02) 0%, transparent 20%),
        repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(139, 105, 20, 0.005) 23px, rgba(139, 105, 20, 0.005) 24px);
    pointer-events: none;
    z-index: 2;
}

/* Seasonal color shift overlay */
.seasonal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
    transition: background-color 0.8s ease;
    mix-blend-mode: multiply;
    opacity: 0.06;
}

/* Noise texture overlay for all colored elements */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
    pointer-events: none;
    z-index: 3;
    opacity: 0.4;
}

/* Bookmark Ribbon */
.bookmark-ribbon {
    position: fixed;
    top: -4px;
    right: 32px;
    z-index: 100;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: drop-shadow(1px 2px 3px rgba(44, 24, 16, 0.3));
}

.bookmark-ribbon:hover {
    transform: translateY(-3px);
}

.bookmark-ribbon:active {
    transform: translateY(1px);
}

/* Page base */
.page {
    min-height: 100vh;
    position: relative;
    z-index: 4;
    transition: transform 0.5s ease-out, box-shadow 0.4s ease-out;
}

.page.page-exit {
    transform: translateY(-3%) rotateX(1.5deg);
    box-shadow: 0 6px 24px rgba(44, 24, 16, 0.12);
}

.page.page-enter {
    box-shadow: 0 -4px 16px rgba(44, 24, 16, 0.08);
}

/* ============================
   COVER PAGE
   ============================ */
.cover-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 30% 40%, rgba(139, 105, 20, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 60%, rgba(44, 24, 16, 0.06) 0%, transparent 50%),
        linear-gradient(175deg, #3D2A1C 0%, #2C1810 40%, #3A2518 70%, #2C1810 100%);
}

.cover-leather {
    position: relative;
    width: 70vw;
    max-width: 560px;
    aspect-ratio: 3 / 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background:
        repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.03) 3px, rgba(0,0,0,0.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 8px, rgba(0,0,0,0.015) 8px, rgba(0,0,0,0.015) 9px),
        linear-gradient(170deg, #4A3628 0%, #3D2A1C 30%, #4A3628 60%, #3D2A1C 100%);
    border-radius: 2px;
    box-shadow:
        inset 0 0 60px rgba(0, 0, 0, 0.35),
        inset 2px 0 8px rgba(0, 0, 0, 0.15),
        4px 4px 24px rgba(0, 0, 0, 0.45),
        1px 1px 4px rgba(0, 0, 0, 0.25);
}

.cover-foil-border {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    border: 1px solid var(--gold-foil);
    opacity: 0.45;
    pointer-events: none;
}

.cover-spine-stitch {
    position: absolute;
    top: 20px;
    left: 28px;
    bottom: 20px;
    width: 2px;
    background: repeating-linear-gradient(
        180deg,
        transparent 0px,
        transparent 6px,
        rgba(139, 105, 20, 0.25) 6px,
        rgba(139, 105, 20, 0.25) 12px
    );
}

.cover-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(2.5rem, 6vw, 4rem);
    background: linear-gradient(135deg, var(--gold-foil), var(--foxed-amber), var(--gold-foil));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
    text-shadow: none;
}

.cover-subtitle {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--foxed-amber);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    opacity: 0.65;
}

.cover-bottom-ornament {
    position: absolute;
    bottom: 40px;
}

/* ============================
   ENDPAPER PAGE
   ============================ */
.endpaper-page {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.marbled-pattern {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(27, 107, 74, 0.18) 0%, transparent 45%),
        radial-gradient(ellipse at 70% 20%, rgba(30, 58, 95, 0.14) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 65%, rgba(139, 26, 43, 0.12) 0%, transparent 45%),
        radial-gradient(ellipse at 85% 60%, rgba(27, 107, 74, 0.09) 0%, transparent 35%),
        radial-gradient(ellipse at 10% 80%, rgba(30, 58, 95, 0.11) 0%, transparent 40%),
        radial-gradient(ellipse at 40% 90%, rgba(139, 26, 43, 0.06) 0%, transparent 30%),
        radial-gradient(ellipse at 60% 10%, rgba(139, 105, 20, 0.08) 0%, transparent 35%),
        linear-gradient(var(--bg-paper), var(--bg-paper));
    opacity: 0.85;
}

.endpaper-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.epigraph {
    max-width: 480px;
    padding: 2rem;
    text-align: center;
}

.epigraph p {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    line-height: 1.85;
    color: var(--text-ink);
    letter-spacing: 0.02em;
    font-variant: small-caps;
}

.cedar-branch-ornament {
    margin-top: 2rem;
    opacity: 0.7;
}

/* ============================
   CHAPTER PAGES
   ============================ */
.chapter-page {
    padding: 80px 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
}

.chapter-content {
    display: grid;
    grid-template-columns: auto 1fr 200px;
    gap: 0 2rem;
    max-width: 900px;
    margin-left: 15%;
    padding: 0 2rem;
    position: relative;
}

/* Spine fold line */
.chapter-content::before {
    content: '';
    position: absolute;
    left: 2rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: rgba(139, 105, 20, 0.2);
}

.chapter-marker {
    grid-column: 1;
    grid-row: 1;
    padding-top: 0.5rem;
}

.chapter-number {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-ink);
    border: 1px solid rgba(139, 105, 20, 0.4);
    border-radius: 4px;
    padding: 0.3em 0.6em;
    letter-spacing: 0.05em;
}

.text-column {
    grid-column: 2;
}

.chapter-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.2rem, 5vw, 3.8rem);
    color: var(--text-ink);
    letter-spacing: 0.03em;
    line-height: 1.2;
    margin-bottom: 1.5rem;
}

/* Drop Caps */
.drop-cap {
    float: left;
    font-family: var(--font-drop);
    font-weight: 700;
    font-size: 5.5rem;
    line-height: 0.75;
    padding-right: 0.12em;
    padding-top: 0.06em;
    color: var(--accent-garnet);
    position: relative;
}

.drop-cap::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(139, 105, 20, 0.15) 50%, transparent 100%);
    transform: translateX(-110%);
    pointer-events: none;
}

.drop-cap.shimmer::after {
    animation: goldShimmer 0.8s ease-out forwards;
}

@keyframes goldShimmer {
    to { transform: translateX(110%); }
}

/* Body Text */
.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw + 0.5rem, 1.25rem);
    line-height: 1.75;
    color: var(--text-ink);
    margin-bottom: 1.5em;
    letter-spacing: 0.01em;
}

.body-text + .body-text {
    text-indent: 1.5em;
}

.body-text em {
    font-style: italic;
    color: var(--accent-sapphire);
}

/* Margin Notes */
.margin-notes {
    grid-column: 3;
    grid-row: 1 / -1;
    position: relative;
    padding-top: 4rem;
}

.marginal-note {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--annotation-ink); /* #5C4A2E at 70% opacity via element opacity */
    opacity: 0;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    transform: translateX(12px);
    transition: transform 0.6s ease-out, opacity 0.6s ease-out;
    text-shadow: 0 0 1px rgba(42, 33, 24, 0.3);
}

.marginal-note.visible {
    transform: translateX(0);
    opacity: 1;
}

.margin-sketch {
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateX(12px);
    transition: transform 0.6s ease-out, opacity 0.6s ease-out;
}

.margin-sketch.visible {
    opacity: 0.8;
    transform: translateX(0);
}

/* Pressed Leaf Watermarks */
.pressed-leaf-watermark {
    position: absolute;
    right: 3%;
    top: 15%;
    pointer-events: none;
    z-index: 0;
}

.pressed-leaf-alt {
    right: auto;
    left: 3%;
    top: 25%;
}

/* Page Numbers */
.page-number {
    position: absolute;
    bottom: 2rem;
    right: 15%;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-ink);
    opacity: 0.5;
}

.page-number span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(139, 105, 20, 0.3);
    text-shadow: 0 0 3px rgba(42, 33, 24, 0.2);
}

/* ============================
   GROWTH RING DIVIDERS
   ============================ */
.growth-ring-divider {
    text-align: center;
    padding: 3rem 0;
    color: rgba(139, 105, 20, 0.35);
    position: relative;
    z-index: 4;
}

/* ============================
   COLOPHON PAGE
   ============================ */
.colophon-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.colophon-content {
    text-align: center;
    max-width: 420px;
    padding: 2rem;
}

.hanko-stamp {
    margin-bottom: 1.5rem;
    opacity: 0.85;
}

.colophon-rule {
    width: 60px;
    height: 1px;
    background: rgba(139, 105, 20, 0.3);
    margin: 0 auto 1.5rem;
}

.colophon-text {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--annotation-ink); /* #5C4A2E */
    opacity: 0.7;
    line-height: 1.7;
    margin-bottom: 1.5rem;
}

.colophon-edition {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: rgba(92, 74, 46, 0.55);
    line-height: 1.7;
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

.colophon-date {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--foxed-amber);
    letter-spacing: 0.1em;
}

/* ============================
   TYPEWRITER EFFECT
   ============================ */
.typewriter-text .char {
    opacity: 0;
    transform: translateY(2px);
    display: inline-block;
    transition: opacity 0.15s ease, transform 0.15s ease;
    text-shadow: 0 0 1px rgba(42, 33, 24, 0.3);
}

.typewriter-text .char.typed {
    opacity: 1;
    transform: translateY(0);
}

.typewriter-text .char.space {
    width: 0.3em;
}

.typewriter-cursor {
    display: inline-block;
    border-right: 2px solid var(--text-ink);
    margin-left: 1px;
    animation: blink 0.8s steps(1) infinite;
}

.typewriter-cursor.done {
    animation: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

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

/* ============================
   FADE REVEAL ANIMATION
   ============================ */
.fade-reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}

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

/* ============================
   LINKS
   ============================ */
a {
    color: var(--accent-emerald);
    text-decoration-style: wavy;
    text-decoration-color: var(--accent-emerald);
    text-underline-offset: 3px;
    transition: text-decoration-style 0.2s ease;
}

a:hover {
    text-decoration-style: solid;
}

/* ============================
   PAGE TURN SHADOWS
   ============================ */
.page.turning-out {
    box-shadow: 0 6px 24px rgba(44, 24, 16, 0.15);
}

.page.turning-in {
    box-shadow: inset 0 4px 16px rgba(44, 24, 16, 0.06);
}

/* ============================
   RESPONSIVE - TABLET
   ============================ */
@media (max-width: 960px) {
    .chapter-content {
        grid-template-columns: auto 1fr 160px;
        margin-left: 8%;
    }
}

/* ============================
   RESPONSIVE - MOBILE
   ============================ */
@media (max-width: 768px) {
    .chapter-content {
        grid-template-columns: 1fr;
        margin-left: auto;
        margin-right: auto;
        padding: 0 1.5rem;
        max-width: 640px;
    }

    .chapter-content::before {
        display: none;
    }

    .chapter-marker {
        grid-column: 1;
        margin-bottom: 1rem;
    }

    .text-column {
        grid-column: 1;
    }

    .margin-notes {
        grid-column: 1;
        padding-top: 1rem;
        border-top: 1px solid rgba(139, 105, 20, 0.2);
        margin-top: 1.5rem;
    }

    .marginal-note {
        transform: none;
    }

    .margin-sketch {
        transform: none;
    }

    .cover-leather {
        width: 85vw;
    }

    .page-number {
        right: 2rem;
    }

    .bookmark-ribbon {
        right: 16px;
    }

    .pressed-leaf-watermark {
        display: none;
    }

    .cover-spine-stitch {
        left: 18px;
    }
}

@media (max-width: 480px) {
    .body-text {
        font-size: 1rem;
    }

    .drop-cap {
        font-size: 4rem;
    }

    .chapter-heading {
        font-size: 1.8rem;
    }

    .chapter-page {
        padding: 60px 0;
    }

    .epigraph {
        padding: 1.5rem 1rem;
    }

    .colophon-content {
        padding: 1.5rem 1rem;
    }
}
