:root {
    --bg-cream: #f4ede4;
    --bg-sand: #ebe3d5;
    --bg-olive: #e5e2d4;
    --bg-ash: #ddd8ce;
    --text-primary: #3d3225;
    --text-secondary: #5a5145;
    --text-caption: #8a7e6f;
    --accent-amber: #9b6b3a;
    --accent-teal: #4a8b7a;
    --accent-lagoon: #2e6b7a;
    --accent-coral: #c47d5e;
    --shadow-kelp: #6b5e4a;
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Work Sans', sans-serif;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    color: var(--text-secondary);
    background-color: var(--bg-cream);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='4' height='4' fill='%23f4ede4'/%3E%3Crect x='0' y='0' width='1' height='1' fill='%23000' opacity='0.03'/%3E%3Crect x='2' y='2' width='1' height='1' fill='%23000' opacity='0.02'/%3E%3C/svg%3E");
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.72;
    -webkit-font-smoothing: antialiased;
}

/* ===== BOUNCE ANIMATION ===== */

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.85) translateY(12px);
    }
    60% {
        opacity: 1;
        transform: scale(1.03) translateY(-2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.bounce-target {
    opacity: 0;
}

.bounce-target.is-visible {
    animation: bounceIn 700ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ===== CHAPTER 1: THE CABINET (HERO) ===== */

.chapter-1 {
    width: 100%;
    height: 100vh;
    min-height: 600px;
    background-color: var(--bg-cream);
    overflow: hidden;
    position: relative;
}

.hero-grid {
    display: grid;
    grid-template-rows: 1fr;
    grid-template-columns: 1fr;
    width: 100%;
    height: 100%;
    position: relative;
}

.hero-element {
    grid-row: 1 / -1;
    grid-column: 1 / -1;
    position: relative;
}

.hero-angelfish {
    justify-self: center;
    align-self: center;
    z-index: 2;
}

.angelfish-svg {
    width: 40vw;
    max-width: 500px;
    height: auto;
    opacity: 0.9;
}

.hero-title {
    justify-self: center;
    align-self: center;
    z-index: 5;
    transform: translateY(-5vh);
}

.torn-strip {
    background-color: var(--bg-cream);
    padding: 12px 40px 16px;
    position: relative;
    clip-path: polygon(2% 8%, 8% 0%, 15% 5%, 25% 2%, 35% 7%, 45% 1%, 55% 6%, 65% 0%, 75% 4%, 85% 1%, 92% 6%, 98% 2%, 100% 15%, 99% 85%, 97% 92%, 93% 98%, 88% 95%, 80% 100%, 72% 96%, 62% 100%, 52% 95%, 42% 99%, 32% 94%, 22% 100%, 12% 96%, 5% 100%, 0% 92%, 1% 12%);
}

.torn-strip h1 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    letter-spacing: -0.02em;
    color: var(--text-primary);
    text-transform: none;
    white-space: nowrap;
}

.hero-card-1 {
    justify-self: start;
    align-self: end;
    z-index: 3;
    margin-left: 8vw;
    margin-bottom: 12vh;
    transform: rotate(-2deg);
}

.hero-card-2 {
    justify-self: end;
    align-self: start;
    z-index: 3;
    margin-right: 10vw;
    margin-top: 10vh;
    transform: rotate(1.5deg);
}

.hero-stamp-1 {
    justify-self: start;
    align-self: start;
    z-index: 4;
    margin-left: 15vw;
    margin-top: 8vh;
}

.hero-stamp-2 {
    justify-self: end;
    align-self: end;
    z-index: 4;
    margin-right: 8vw;
    margin-bottom: 8vh;
}

.hero-seahorse {
    justify-self: end;
    align-self: center;
    z-index: 3;
    margin-right: 5vw;
    transform: rotate(8deg);
}

.seahorse-small {
    width: 60px;
    height: auto;
}

.hero-fragment {
    justify-self: start;
    align-self: center;
    z-index: 4;
    margin-left: 5vw;
    transform: rotate(-4deg);
}

.paper-fragment {
    background: var(--bg-sand);
    padding: 10px 18px;
    clip-path: polygon(3% 0%, 97% 4%, 100% 95%, 5% 100%);
    box-shadow: 2px 3px 8px rgba(107, 94, 74, 0.1);
}

.fragment-text {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.9rem;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

/* ===== INDEX CARDS ===== */

.index-card {
    width: 180px;
    height: 120px;
    background: var(--bg-cream);
    border-radius: 2px;
    box-shadow: 2px 3px 8px rgba(107, 94, 74, 0.1);
    position: relative;
    padding: 12px 14px;
    overflow: hidden;
}

.index-card.large {
    width: 220px;
    height: 150px;
    padding: 16px 18px;
}

.index-card.small-card {
    width: 150px;
    height: 90px;
    padding: 10px 12px;
}

.card-lines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 23px,
        rgba(138, 126, 111, 0.06) 23px,
        rgba(138, 126, 111, 0.06) 24px
    );
    pointer-events: none;
}

.card-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.handwritten {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 1.1rem;
    color: var(--text-primary);
    line-height: 1.5;
}

.handwritten.small {
    font-size: 0.85rem;
    color: var(--text-caption);
}

.rotate-slight {
    display: inline-block;
    transform: rotate(-1.5deg);
}

.pin-mark {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-amber);
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 1px 3px rgba(107, 94, 74, 0.2);
}

/* ===== RUBBER STAMPS ===== */

.rubber-stamp {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-coral);
    opacity: 0.7;
    display: inline-block;
    transform: rotate(-3deg);
}

.rubber-stamp.small-stamp {
    font-size: 0.65rem;
}

.rubber-stamp.large-stamp {
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    transform: rotate(-5deg);
}

/* ===== TRUTH TABLES ===== */

.truth-table {
    border-collapse: collapse;
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.truth-table th {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    padding: 4px 10px;
    border-bottom: 1px solid rgba(138, 126, 111, 0.25);
    text-align: center;
    color: var(--text-primary);
}

.truth-table td {
    padding: 3px 10px;
    text-align: center;
    color: var(--text-secondary);
}

.truth-table tr.alt {
    background-color: var(--bg-sand);
}

/* ===== TORN DIVIDERS ===== */

.torn-divider {
    width: 100%;
    margin-top: -40px;
    position: relative;
    z-index: 10;
    line-height: 0;
}

.torn-divider svg {
    width: 100%;
    height: 80px;
    display: block;
}

/* ===== CHAPTER 2: PROPOSITIONS ===== */

.chapter-2 {
    background-color: var(--bg-sand);
    padding: 80px 0 100px;
}

/* ===== TWO-COLUMN LAYOUT ===== */

.two-column {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 40px;
    gap: 40px;
}

.notebook-column {
    flex: 0 0 55%;
    max-width: 55%;
    padding-left: 80px;
}

.specimen-column {
    flex: 0 0 45%;
    max-width: 45%;
    padding-top: 60px;
    position: relative;
}

.chapter-marker {
    margin-bottom: 24px;
}

.chapter-label {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-amber);
}

.chapter-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    letter-spacing: -0.02em;
    color: var(--text-primary);
    text-transform: none;
    margin-bottom: 40px;
    line-height: 1.15;
}

.center-title {
    text-align: center;
}

.notebook-content {
    max-width: 540px;
}

.notebook-content p {
    margin-bottom: 0;
    color: var(--text-secondary);
}

.pencil-line {
    border: none;
    height: 1px;
    background: var(--text-caption);
    opacity: 0.2;
    margin: 28px 0;
}

/* ===== SPECIMEN ITEMS ===== */

.specimen-item {
    margin-bottom: 40px;
    position: relative;
}

.specimen-card-1 {
    transform: rotate(2deg);
    margin-left: 20px;
}

.specimen-seahorse {
    margin-left: -15px;
    margin-top: -10px;
}

.specimen-notation {
    margin-left: 40px;
    transform: rotate(-1deg);
    margin-top: -20px;
}

.corkboard-panel {
    width: 160px;
    padding: 20px;
    background: #c4a882;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='4' height='4' fill='%23c4a882'/%3E%3Crect x='0' y='0' width='1' height='1' fill='%23000' opacity='0.04'/%3E%3Crect x='2' y='1' width='1' height='1' fill='%23000' opacity='0.03'/%3E%3Crect x='1' y='3' width='1' height='1' fill='%23000' opacity='0.02'/%3E%3C/svg%3E");
    border-radius: 2px;
    box-shadow: 2px 3px 10px rgba(107, 94, 74, 0.15);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.seahorse-specimen {
    width: 80px;
    height: auto;
}

/* ===== CHAPTER 3: GATES ===== */

.chapter-3 {
    background-color: var(--bg-sand);
    padding: 80px 40px 100px;
    text-align: center;
}

.gates-intro {
    max-width: 640px;
    margin: 0 auto 60px;
    color: var(--text-secondary);
    font-weight: 300;
    text-align: center;
}

.gates-row {
    display: flex;
    justify-content: center;
    gap: 4vw;
    flex-wrap: wrap;
    max-width: 1100px;
    margin: 0 auto;
}

.gate-specimen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 20vw;
    min-width: 180px;
    max-width: 240px;
}

.gate-fish {
    width: 100%;
    height: auto;
}

.gate-name {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--text-caption);
    font-style: italic;
}

.gate-table {
    margin-top: 8px;
}

.gate-table tr:not(.alt) td {
    background-color: var(--bg-cream);
}

/* ===== PUFFERFISH (CSS-only) ===== */

.pufferfish {
    width: 120px;
    height: 120px;
    position: relative;
    margin: 30px auto;
}

.puffer-body {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--accent-coral);
    opacity: 0.7;
    background-image: repeating-conic-gradient(
        from 0deg,
        transparent 0deg 8deg,
        rgba(107, 94, 74, 0.15) 8deg 10deg
    );
    position: relative;
}

.puffer-body::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 75%;
    height: 75%;
    border-radius: 50%;
    background: var(--accent-coral);
    opacity: 0.8;
}

.puffer-eye {
    position: absolute;
    top: 35%;
    left: 38%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-primary);
    opacity: 0.7;
}

.cabinet-puffer .pufferfish,
.cabinet-puffer {
    margin: 10px auto;
}

.cabinet-puffer .puffer-body {
    width: 90px;
    height: 90px;
}

/* ===== CHAPTER 4: PROOFS ===== */

.chapter-4 {
    background-color: var(--bg-olive);
    padding: 80px 0 100px;
}

.proof-sequence {
    margin: 20px 0;
    counter-reset: proof-step;
}

.proof-step {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(138, 126, 111, 0.1);
}

.proof-step .step-number {
    counter-increment: proof-step;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--accent-amber);
    min-width: 24px;
}

.proof-step .step-number::before {
    content: counter(proof-step) '.';
}

.proof-step .step-content {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.05rem;
    color: var(--text-primary);
    flex: 1;
}

.proof-step .step-justification {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.8rem;
    color: var(--text-caption);
    font-style: italic;
}

.specimen-lionfish {
    margin-left: 20px;
}

.lionfish-diagram {
    width: 160px;
    height: auto;
}

.specimen-proof-card {
    transform: rotate(1.5deg);
    margin-left: 30px;
    margin-top: -15px;
}

.specimen-stamp-block {
    margin-left: 10px;
    margin-top: 20px;
}

.specimen-card-bottom {
    transform: rotate(-2deg);
    margin-left: 50px;
    margin-top: -10px;
}

/* ===== CHAPTER 5: THE COLLECTION ===== */

.chapter-5 {
    background-color: var(--bg-ash);
    padding: 80px 40px 0;
    text-align: center;
}

.specimen-cabinet {
    display: grid;
    grid-template-columns: 1fr 1fr;
    max-width: 90vmin;
    margin: 40px auto;
    border: 1px solid rgba(138, 126, 111, 0.2);
}

.cabinet-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    border: 1px solid rgba(138, 126, 111, 0.2);
    max-width: 45vmin;
}

.cabinet-fish {
    width: 60%;
    height: auto;
}

.cabinet-label {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.8rem;
    color: var(--text-caption);
    font-style: italic;
    letter-spacing: 0.02em;
}

.colophon {
    max-width: 640px;
    margin: 60px auto 0;
    text-align: left;
}

.colophon p {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 1.2rem;
    line-height: 1.72;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.visual-exhale {
    height: 30vh;
}

/* ===== MOBILE RESPONSIVE ===== */

@media (max-width: 768px) {
    .two-column {
        flex-direction: column;
        padding: 0 24px;
    }

    .notebook-column {
        flex: 1;
        max-width: 100%;
        padding-left: 24px;
    }

    .specimen-column {
        flex: 1;
        max-width: 100%;
        padding-top: 20px;
    }

    .hero-angelfish .angelfish-svg {
        width: 60vw;
    }

    .hero-card-1 {
        margin-left: 4vw;
        margin-bottom: 6vh;
    }

    .hero-card-2 {
        margin-right: 4vw;
        margin-top: 6vh;
    }

    .hero-stamp-1 {
        margin-left: 5vw;
    }

    .hero-stamp-2 {
        margin-right: 4vw;
    }

    .hero-seahorse {
        margin-right: 3vw;
    }

    .hero-fragment {
        margin-left: 3vw;
    }

    .gates-row {
        flex-direction: column;
        align-items: center;
    }

    .gate-specimen {
        width: 70vw;
        max-width: 300px;
    }

    .specimen-cabinet {
        max-width: 95vw;
    }

    .chapter-3 {
        padding: 60px 20px 80px;
    }

    .chapter-5 {
        padding: 60px 20px 0;
    }

    .colophon {
        padding: 0 10px;
    }
}

@media (max-width: 480px) {
    .torn-strip h1 {
        font-size: 2rem;
    }

    .index-card {
        width: 150px;
        height: 100px;
    }

    .index-card.large {
        width: 180px;
        height: 120px;
    }

    .notebook-column {
        padding-left: 12px;
    }

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

    .cabinet-cell {
        max-width: 100%;
    }
}