/* ============================================
   bada.quest — Living Scholarly Codex
   Neomorphic + Ma Negative Space + Slab-Serif
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-surface: #F5EDE0;
    --panel-face: #FBF6EF;
    --shadow-warm: #A58C6E;
    --highlight-warm: #FFF8EE;
    --text-primary: #4A3728;
    --text-heading: #5B3A29;
    --accent-gold: #C4944A;
    --accent-warm: #C87B5E;
    --inset-bg: #EDE3D3;
    --margin-note: #8B6B4A;

    --shadow-dark: rgba(165, 140, 110, 0.35);
    --shadow-light: rgba(255, 248, 238, 0.8);
    --shadow-inset-dark: rgba(165, 140, 110, 0.3);
    --shadow-inset-light: rgba(255, 248, 238, 0.7);

    --ease-organic: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --font-display: 'Rokkitt', serif;
    --font-body: 'Source Serif 4', serif;
    --font-annotation: 'Kalam', cursive;
    --font-mono: 'Courier Prime', monospace;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
}

/* Paper grain texture overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.8' numOctaves='4' seed='2' type='fractalNoise'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
}

.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Typography --- */
h1, h2, h3 {
    font-family: var(--font-display);
    color: var(--text-heading);
    line-height: 1.15;
    letter-spacing: 0.02em;
}

h1 {
    font-weight: 700;
    font-size: clamp(2rem, 4.5vw, 3.5rem);
}

h2 {
    font-weight: 600;
    font-size: clamp(1.6rem, 3.5vw, 2.5rem);
}

h3 {
    font-weight: 600;
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
}

p {
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    margin-bottom: 1.5rem;
}

p:last-child {
    margin-bottom: 0;
}

.kalam {
    font-family: var(--font-annotation);
    font-weight: 400;
    color: var(--margin-note);
}

/* --- Codex Grid Layout --- */
.codex-grid {
    display: grid;
    grid-template-columns: 1fr minmax(300px, 720px) 1fr;
    grid-template-areas: "margin-left content margin-right";
    width: 100%;
    min-height: 100%;
    padding: 0 2rem;
}

.margin-left {
    grid-area: margin-left;
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    padding-top: 15vh;
    padding-right: 3rem;
}

.content {
    grid-area: content;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 4rem 0;
}

.margin-right {
    grid-area: margin-right;
    position: relative;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    padding-top: 20vh;
    padding-left: 3rem;
}

/* --- Chapter Sections --- */
.chapter {
    min-height: 100vh;
    scroll-snap-align: start;
    position: relative;
    display: flex;
    align-items: center;
}

.chapter-cover {
    min-height: 100vh;
}

.chapter-heading {
    text-align: center;
    margin-bottom: 3rem;
    width: 100%;
}

.chapter-number {
    display: block;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    color: var(--accent-gold);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

/* --- Neomorphic Panels --- */
.neomorphic-panel {
    background: var(--panel-face);
    border-radius: 16px;
    padding: 3rem;
    box-shadow:
        8px 8px 16px rgba(165, 140, 110, 0.35),
        -8px -8px 16px rgba(255, 248, 238, 0.8);
    width: 100%;
    max-width: 720px;
}

/* --- Neomorphic Pills (Index Entries) --- */
.neomorphic-pill {
    background: var(--panel-face);
    border-radius: 50px;
    padding: 1.2rem 2rem;
    box-shadow:
        6px 6px 12px rgba(165, 140, 110, 0.3),
        -6px -6px 12px rgba(255, 248, 238, 0.75);
    transition: box-shadow 300ms var(--ease-organic),
                transform 300ms var(--ease-organic);
    cursor: default;
}

.neomorphic-pill:hover {
    box-shadow:
        inset 3px 3px 6px rgba(165, 140, 110, 0.25),
        inset -3px -3px 6px rgba(255, 248, 238, 0.65);
    transform: scale(0.99);
}

.neomorphic-pill:hover .index-title {
    color: var(--accent-gold);
}

/* --- Inset Wells --- */
.inset-well {
    background: var(--inset-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow:
        inset 4px 4px 8px rgba(165, 140, 110, 0.3),
        inset -4px -4px 8px rgba(255, 248, 238, 0.7);
}

/* ============================================
   CHAPTER I — THE COVER
   ============================================ */
.chapter-cover .content {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.cover-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

/* Book Opening Animation */
.book-open-animation {
    width: 160px;
    height: 120px;
    perspective: 600px;
    margin-bottom: 1rem;
    opacity: 0;
    animation: fadeInBook 0.8s var(--ease-organic) 0.3s forwards;
}

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

.book-cover {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.book-front {
    position: absolute;
    width: 70px;
    height: 100px;
    top: 10px;
    left: 50%;
    background: linear-gradient(135deg, #8B6B4A, #5B3A29);
    border-radius: 2px 6px 6px 2px;
    transform-origin: left center;
    animation: openBookFront 2s var(--ease-organic) 0.5s forwards;
    box-shadow: 2px 2px 8px rgba(91, 58, 41, 0.3);
    z-index: 3;
}

.book-emboss {
    position: absolute;
    top: 20%;
    left: 15%;
    right: 15%;
    bottom: 30%;
    border: 1px solid rgba(196, 148, 74, 0.5);
    border-radius: 2px;
}

.book-emboss::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 20%;
    right: 20%;
    height: 1px;
    background: rgba(196, 148, 74, 0.4);
}

@keyframes openBookFront {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-160deg); }
}

.book-spine {
    position: absolute;
    width: 12px;
    height: 100px;
    top: 10px;
    left: calc(50% - 6px);
    background: linear-gradient(90deg, #5B3A29, #7A5C47, #5B3A29);
    border-radius: 2px;
    z-index: 1;
}

.book-back {
    position: absolute;
    width: 70px;
    height: 100px;
    top: 10px;
    right: 50%;
    background: linear-gradient(225deg, #8B6B4A, #5B3A29);
    border-radius: 6px 2px 2px 6px;
    transform-origin: right center;
    animation: openBookBack 2s var(--ease-organic) 0.5s forwards;
    box-shadow: -2px 2px 8px rgba(91, 58, 41, 0.3);
    z-index: 2;
}

@keyframes openBookBack {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(10deg); }
}

.book-pages {
    position: absolute;
    top: 14px;
    left: calc(50% + 2px);
    width: 62px;
    height: 92px;
    z-index: 2;
}

.book-page {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--panel-face);
    border-radius: 1px 4px 4px 1px;
    transform-origin: left center;
    box-shadow: 1px 1px 3px rgba(165, 140, 110, 0.15);
}

.page-1 {
    animation: fanPage1 2s var(--ease-organic) 0.8s forwards;
}
.page-2 {
    animation: fanPage2 2s var(--ease-organic) 1.0s forwards;
}
.page-3 {
    animation: fanPage3 2s var(--ease-organic) 1.2s forwards;
}

@keyframes fanPage1 {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-140deg); }
}
@keyframes fanPage2 {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-120deg); }
}
@keyframes fanPage3 {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-100deg); }
}

/* Site Title */
.site-title {
    font-size: clamp(2.5rem, 6vw, 5rem);
    font-weight: 700;
    color: var(--text-heading);
    text-shadow:
        2px 2px 4px rgba(165, 140, 110, 0.4),
        -2px -2px 4px rgba(255, 248, 238, 0.9);
    opacity: 0;
    animation: fadeInTitle 1.2s var(--ease-organic) 2s forwards;
    letter-spacing: 0.04em;
}

@keyframes fadeInTitle {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Site Subtitle */
.site-subtitle {
    font-size: clamp(1rem, 2vw, 1.3rem);
    opacity: 0;
    animation: fadeInSubtitle 1s var(--ease-organic) 2.6s forwards;
    max-width: 480px;
}

.site-subtitle .char {
    display: inline-block;
    opacity: 0;
    animation: revealChar 0.3s var(--ease-organic) forwards;
}

@keyframes fadeInSubtitle {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes revealChar {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Scroll Chevron */
.scroll-chevron {
    opacity: 0;
    animation: fadeInChevron 0.8s var(--ease-organic) 3.2s forwards;
    cursor: pointer;
    padding: 1rem;
    border-radius: 50%;
    box-shadow:
        4px 4px 8px rgba(165, 140, 110, 0.25),
        -4px -4px 8px rgba(255, 248, 238, 0.7);
    transition: box-shadow 300ms var(--ease-organic);
}

.scroll-chevron:hover {
    box-shadow:
        inset 2px 2px 4px rgba(165, 140, 110, 0.2),
        inset -2px -2px 4px rgba(255, 248, 238, 0.6);
}

@keyframes fadeInChevron {
    from { opacity: 0; }
    to { opacity: 1; }
}

.scroll-chevron svg {
    display: block;
    animation: pulseChevron 2.5s ease-in-out infinite;
}

@keyframes pulseChevron {
    0%, 100% { transform: translateY(0); opacity: 0.6; }
    50% { transform: translateY(4px); opacity: 1; }
}

/* ============================================
   SECTION DIVIDERS
   ============================================ */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 4rem;
    gap: 1.5rem;
    opacity: 0;
    transition: opacity 800ms var(--ease-organic);
}

.section-divider.visible {
    opacity: 1;
}

.divider-line {
    flex: 1;
    height: 1px;
    background: rgba(196, 148, 74, 0.4);
    max-width: 200px;
}

.divider-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 600ms var(--ease-organic),
                transform 600ms var(--ease-organic);
}

.section-divider.visible .divider-ornament {
    opacity: 1;
    transform: scale(1);
}

.ornament-compass svg {
    animation: none;
}

.section-divider.visible .ornament-compass svg {
    animation: rotateCompass 8s linear infinite;
}

@keyframes rotateCompass {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ============================================
   CHAPTER II — THE FIRST PAGE
   ============================================ */
.chapter-first-page .content {
    padding: 6rem 0;
}

.reveal-panel {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 800ms var(--ease-organic),
                transform 800ms var(--ease-organic);
}

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

.reveal-lines p {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 600ms var(--ease-organic),
                transform 600ms var(--ease-organic);
}

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

.body-text {
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    color: var(--text-primary);
}

/* --- Margin Annotations --- */
.margin-annotation {
    position: relative;
    max-width: 180px;
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    transform: rotate(-1deg);
    opacity: 0;
    transition: opacity 800ms var(--ease-organic) 400ms;
    line-height: 1.5;
}

.margin-annotation.visible {
    opacity: 1;
}

.annotation-connector {
    position: absolute;
    left: -3rem;
    top: 0.5rem;
    width: 2.5rem;
    height: 0;
    border-top: 2px dotted rgba(196, 148, 74, 0.3);
}

.annotation-text {
    display: block;
    font-style: italic;
}

/* --- Margin Blob --- */
.margin-blob {
    position: absolute;
    width: 120px;
    height: 120px;
    background: rgba(196, 148, 74, 0.08);
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
    animation: morphBlob 20s ease-in-out infinite;
    top: 25vh;
    right: 1rem;
}

/* ============================================
   CHAPTER III — THE INDEX
   ============================================ */
.chapter-index .content {
    padding: 6rem 0;
}

.index-entries {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.index-entry {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 500ms var(--ease-organic),
                transform 500ms var(--ease-organic);
}

.index-entry.visible {
    opacity: 1;
    transform: translateY(0);
}

.index-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.1rem);
    color: var(--text-heading);
    white-space: nowrap;
    transition: color 300ms var(--ease-organic);
}

.index-dots {
    flex: 1;
    height: 0;
    border-bottom: 2px dotted var(--accent-gold);
    opacity: 0.4;
    min-width: 20px;
}

.index-page {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--accent-gold);
    min-width: 24px;
    text-align: right;
}

/* --- CSS Bookstack Illustration --- */
.css-bookstack {
    display: flex;
    flex-direction: column;
    gap: 3px;
    transform: rotate(-3deg);
    margin-top: 10vh;
}

.bookstack-book {
    border-radius: 2px 4px 4px 2px;
    box-shadow: 1px 1px 3px rgba(91, 58, 41, 0.2);
}

.book-1 {
    width: 60px;
    height: 14px;
    background: linear-gradient(90deg, #5B3A29 2px, #7A5C47 2px, #8B6B4A);
}

.book-2 {
    width: 70px;
    height: 10px;
    background: linear-gradient(90deg, #C87B5E 2px, #C4944A 2px);
}

.book-3 {
    width: 55px;
    height: 16px;
    background: linear-gradient(90deg, #A58C6E 2px, #8B6B4A 2px, #7A5C47);
}

.book-4 {
    width: 65px;
    height: 11px;
    background: linear-gradient(90deg, #4A3728 2px, #5B3A29 2px, #7A5C47);
}

.book-5 {
    width: 58px;
    height: 13px;
    background: linear-gradient(90deg, #C4944A 2px, #C87B5E 2px);
}

/* ============================================
   CHAPTER IV — THE COLLECTION
   ============================================ */
.chapter-collection {
    min-height: auto;
    padding: 2rem 0;
}

.chapter-collection .content {
    padding: 4rem 0;
}

.collection-cards {
    display: flex;
    flex-direction: column;
    gap: 3rem;
    width: 100%;
}

.collection-card {
    position: relative;
    padding: 2.5rem;
    overflow: hidden;
}

.collection-card.card-odd {
    margin-right: 2rem;
}

.collection-card.card-even {
    margin-left: 2rem;
}

.card-blob {
    position: absolute;
    top: -20px;
    right: -20px;
    width: 120px;
    height: 120px;
    background: rgba(196, 148, 74, 0.1);
    border-radius: 40% 60% 60% 40% / 40% 40% 60% 60%;
    animation: morphBlob2 25s ease-in-out infinite;
    z-index: 0;
}

.card-even .card-blob {
    top: auto;
    bottom: -20px;
    right: auto;
    left: -20px;
    animation-delay: -10s;
}

.card-title {
    position: relative;
    z-index: 1;
    margin-bottom: 1rem;
    color: var(--text-heading);
}

.card-body {
    position: relative;
    z-index: 1;
    color: var(--text-primary);
}

/* --- CSS Lamp Illustration --- */
.css-lamp {
    position: relative;
    width: 80px;
    height: 120px;
    margin-top: 15vh;
}

.lamp-shade {
    position: absolute;
    top: 0;
    left: 10px;
    width: 60px;
    height: 35px;
    background: linear-gradient(180deg, #C4944A, #8B6B4A);
    border-radius: 50% 50% 5px 5px;
    clip-path: polygon(10% 0%, 90% 0%, 100% 100%, 0% 100%);
}

.lamp-neck {
    position: absolute;
    top: 35px;
    left: 35px;
    width: 10px;
    height: 45px;
    background: linear-gradient(90deg, #7A5C47, #A58C6E, #7A5C47);
    border-radius: 2px;
}

.lamp-base {
    position: absolute;
    bottom: 0;
    left: 15px;
    width: 50px;
    height: 12px;
    background: linear-gradient(90deg, #5B3A29, #7A5C47, #5B3A29);
    border-radius: 3px 3px 6px 6px;
}

.lamp-glow {
    position: absolute;
    top: 20px;
    left: -10px;
    width: 100px;
    height: 100px;
    background: radial-gradient(ellipse at center, rgba(196, 148, 74, 0.2) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

/* ============================================
   CHAPTER V — THE COLOPHON
   ============================================ */
.chapter-colophon {
    background: var(--bg-surface);
    transition: background-color 1.5s var(--ease-organic);
}

.chapter-colophon.dimmed {
    background-color: var(--inset-bg);
}

.colophon-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
}

/* Book Closing Animation */
.book-close-animation {
    width: 140px;
    height: 100px;
    perspective: 600px;
    opacity: 0;
    transition: opacity 1s var(--ease-organic);
}

.book-close-animation.visible {
    opacity: 1;
}

.closing-book {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.closing-cover-back {
    position: absolute;
    width: 60px;
    height: 85px;
    top: 8px;
    right: calc(50% + 2px);
    background: linear-gradient(225deg, #8B6B4A, #5B3A29);
    border-radius: 4px 2px 2px 4px;
    z-index: 1;
}

.closing-cover-front {
    position: absolute;
    width: 60px;
    height: 85px;
    top: 8px;
    left: calc(50% + 2px);
    background: linear-gradient(135deg, #8B6B4A, #5B3A29);
    border-radius: 2px 4px 4px 2px;
    transform-origin: left center;
    z-index: 3;
    box-shadow: 2px 2px 6px rgba(91, 58, 41, 0.3);
}

.closing-pages {
    position: absolute;
    top: 12px;
    left: calc(50% - 55px);
    width: 52px;
    height: 77px;
    z-index: 2;
}

.closing-page {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--panel-face);
    border-radius: 2px;
}

.cp-1 { left: 0; }
.cp-2 { left: 2px; }
.cp-3 { left: 4px; }

.book-close-animation.closing .closing-cover-front {
    animation: closeBookFront 2s var(--ease-organic) forwards;
}

@keyframes closeBookFront {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-170deg); }
}

.colophon-text {
    max-width: 420px;
}

.colophon-line {
    font-size: clamp(1rem, 2vw, 1.2rem);
    margin-bottom: 0.5rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 600ms var(--ease-organic),
                transform 600ms var(--ease-organic);
}

.colophon-line.visible {
    opacity: 1;
    transform: translateY(0);
}

.colophon-spacer {
    color: var(--accent-gold);
    margin: 1rem 0;
}

.colophon-year {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.4rem, 3vw, 2rem);
    color: var(--text-heading);
    letter-spacing: 0.2em;
    margin-top: 2rem;
}

/* ============================================
   ORGANIC BLOBS
   ============================================ */
.blob {
    position: fixed;
    z-index: 0;
    pointer-events: none;
    background: rgba(196, 148, 74, 0.1);
}

.blob-1 {
    width: 350px;
    height: 350px;
    top: 10vh;
    left: -5vw;
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
    animation: morphBlob 20s ease-in-out infinite, driftBlob1 30s ease-in-out infinite;
}

.blob-2 {
    width: 280px;
    height: 280px;
    top: 60vh;
    right: -3vw;
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    animation: morphBlob2 25s ease-in-out infinite, driftBlob2 35s ease-in-out infinite;
    background: rgba(196, 148, 74, 0.08);
}

.blob-3 {
    width: 220px;
    height: 220px;
    top: 30vh;
    right: 10vw;
    border-radius: 40% 60% 50% 50% / 50% 40% 60% 50%;
    animation: morphBlob3 22s ease-in-out infinite, driftBlob3 28s ease-in-out infinite;
    background: rgba(200, 123, 94, 0.06);
}

.blob-4 {
    width: 400px;
    height: 400px;
    bottom: -10vh;
    left: 15vw;
    border-radius: 50% 50% 40% 60% / 40% 60% 40% 60%;
    animation: morphBlob 28s ease-in-out infinite reverse, driftBlob1 32s ease-in-out infinite reverse;
    background: rgba(196, 148, 74, 0.07);
}

@keyframes morphBlob {
    0%, 100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
    25% { border-radius: 50% 50% 40% 60% / 40% 60% 50% 50%; }
    50% { border-radius: 70% 30% 50% 50% / 60% 40% 30% 70%; }
    75% { border-radius: 40% 60% 60% 40% / 50% 50% 40% 60%; }
}

@keyframes morphBlob2 {
    0%, 100% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
    33% { border-radius: 40% 60% 50% 50% / 30% 70% 40% 60%; }
    66% { border-radius: 50% 50% 60% 40% / 50% 40% 60% 50%; }
}

@keyframes morphBlob3 {
    0%, 100% { border-radius: 40% 60% 50% 50% / 50% 40% 60% 50%; }
    33% { border-radius: 60% 40% 40% 60% / 40% 60% 50% 50%; }
    66% { border-radius: 30% 70% 60% 40% / 60% 30% 40% 70%; }
}

@keyframes driftBlob1 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 20px); }
}

@keyframes driftBlob2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-20px, 30px); }
}

@keyframes driftBlob3 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(15px, -25px); }
}

/* ============================================
   BOOKMARK TAB
   ============================================ */
.bookmark-tab {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    width: 44px;
    height: 56px;
    background: var(--panel-face);
    border: none;
    border-radius: 12px 0 0 12px;
    cursor: pointer;
    box-shadow:
        -4px 4px 10px rgba(165, 140, 110, 0.3),
        4px -4px 10px rgba(255, 248, 238, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding-right: 4px;
    transition: width 300ms var(--ease-organic),
                box-shadow 300ms var(--ease-organic);
}

.bookmark-tab:hover {
    width: 52px;
    box-shadow:
        -6px 4px 14px rgba(165, 140, 110, 0.4),
        4px -4px 14px rgba(255, 248, 238, 0.7);
}

/* ============================================
   TABLE OF CONTENTS SIDEBAR
   ============================================ */
.toc-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 340px;
    max-width: 85vw;
    height: 100vh;
    background: var(--panel-face);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 500ms var(--ease-organic);
    box-shadow: -8px 0 24px rgba(165, 140, 110, 0.3);
    padding: 3rem 2rem;
    overflow-y: auto;
}

.toc-sidebar.open {
    transform: translateX(0);
}

.toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(74, 55, 40, 0.2);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 400ms var(--ease-organic);
}

.toc-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(196, 148, 74, 0.3);
}

.toc-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.6rem;
    color: var(--text-heading);
    letter-spacing: 0.05em;
}

.toc-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--margin-note);
    cursor: pointer;
    padding: 0.3rem;
    line-height: 1;
    transition: color 300ms var(--ease-organic);
}

.toc-close:hover {
    color: var(--accent-warm);
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.toc-entry {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    transition: background 300ms var(--ease-organic);
}

.toc-entry:hover {
    background: rgba(196, 148, 74, 0.08);
}

.toc-chapter-num {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--accent-gold);
    min-width: 24px;
}

.toc-chapter-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.05rem;
    color: var(--text-heading);
    white-space: nowrap;
}

.toc-dots {
    flex: 1;
    height: 0;
    border-bottom: 1px dotted var(--accent-gold);
    opacity: 0.4;
    min-width: 15px;
    align-self: center;
    margin-bottom: 2px;
}

.toc-link {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--accent-gold);
    text-decoration: none;
    min-width: 16px;
    text-align: right;
    transition: color 300ms var(--ease-organic);
}

.toc-link:hover {
    color: var(--accent-warm);
}

/* ============================================
   SCROLL PROGRESS QUILL
   ============================================ */
.scroll-quill {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 50;
    opacity: 0.5;
    transition: opacity 300ms var(--ease-organic);
}

.scroll-quill:hover {
    opacity: 0.8;
}

.quill-stroke {
    transition: d 100ms linear;
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
        scroll-snap-type: none;
    }

    .blob { display: none; }

    .reveal-panel,
    .reveal-lines p,
    .index-entry,
    .margin-annotation,
    .colophon-line,
    .section-divider,
    .divider-ornament,
    .site-title,
    .site-subtitle,
    .scroll-chevron,
    .book-open-animation,
    .book-close-animation {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .codex-grid {
        grid-template-columns: 1fr minmax(280px, 680px) 1fr;
        padding: 0 1.5rem;
    }

    .margin-left,
    .margin-right {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }

    .margin-annotation {
        max-width: 140px;
        font-size: 0.85rem;
    }

    .annotation-connector {
        width: 1.5rem;
        left: -1.5rem;
    }
}

@media (max-width: 768px) {
    .codex-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "content"
            "margin-right";
        padding: 0 1.5rem;
    }

    .margin-left {
        display: none;
    }

    .margin-right {
        padding: 0;
        padding-top: 0;
        justify-content: center;
    }

    .margin-annotation {
        max-width: 100%;
        transform: rotate(0deg);
        text-align: center;
        margin: 1.5rem 0;
    }

    .annotation-connector {
        display: none;
    }

    .neomorphic-panel {
        padding: 2rem 1.5rem;
    }

    .collection-card.card-odd,
    .collection-card.card-even {
        margin-left: 0;
        margin-right: 0;
    }

    .css-bookstack,
    .css-lamp {
        display: none;
    }

    .toc-sidebar {
        width: 280px;
    }

    .chapter {
        min-height: auto;
        padding: 4rem 0;
    }

    .chapter-cover {
        min-height: 100vh;
        padding: 0;
    }
}

@media (max-width: 480px) {
    .neomorphic-panel {
        padding: 1.5rem 1rem;
        border-radius: 12px;
    }

    .neomorphic-pill {
        padding: 0.8rem 1.2rem;
    }

    .site-title {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .bookmark-tab {
        width: 38px;
        height: 48px;
    }
}
