/* ============================================
   PPEBBL.com - Design Tokens & Custom Properties
   ============================================ */

:root {
    --color-bg-primary: #1E1510;
    --color-bg-secondary: #2A1F17;
    --color-bg-accent: #3D2E22;
    --color-accent-primary: #C17F4E;
    --color-accent-secondary: #D4A056;
    --color-highlight: #F2DFC2;
    --color-cool: #6B7B8A;
    --color-text: #D9C7AA;
    --color-text-muted: #8A7560;
    --color-emphasis: #A0522D;
    --color-dark-umber: #3A2E24;
    --font-display: 'Baloo 2', cursive;
    --font-body: 'Nunito', sans-serif;
    --font-mono: 'Courier Prime', monospace;
    --grain-opacity: 0.08;
    --angle-degrees: 4deg;
    --magnetic-range: 60px;
    --magnetic-strength: 5px;
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
    background-color: var(--color-bg-primary);
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.125rem;
    line-height: 1.85;
    color: var(--color-text);
    background-color: var(--color-bg-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--color-accent-primary);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--color-accent-secondary);
}

::selection {
    background: var(--color-accent-primary);
    color: var(--color-highlight);
}

/* ============================================
   Grain Overlay (Film Texture)
   ============================================ */

.grain-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    opacity: var(--grain-opacity);
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    animation: grainShift 8s steps(10) infinite;
}

@keyframes grainShift {
    0%, 100% { background-position: 0 0; }
    10% { background-position: -1px 1px; }
    20% { background-position: 2px -1px; }
    30% { background-position: -2px 2px; }
    40% { background-position: 1px -2px; }
    50% { background-position: -1px -1px; }
    60% { background-position: 2px 1px; }
    70% { background-position: -2px -2px; }
    80% { background-position: 1px 2px; }
    90% { background-position: -1px 0; }
}

/* ============================================
   Navigation
   ============================================ */

.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 2rem;
    background: rgba(30, 21, 16, 0.92);
    border-bottom: 1px solid var(--color-accent-primary);
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.nav-bar.nav-visible {
    transform: translateY(0);
}

.nav-logo {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--color-highlight);
    letter-spacing: 0.02em;
}

.nav-links {
    display: flex;
    gap: 2rem;
}

.nav-link {
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--color-text-muted);
    letter-spacing: 0.03em;
    transition: color 0.3s ease;
}

.nav-link:hover {
    color: var(--color-highlight);
}

.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--color-text-muted);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: color 0.3s ease, border-color 0.3s ease;
}

.nav-toggle:hover {
    color: var(--color-highlight);
    border-color: var(--color-highlight);
}

/* Mobile Nav Overlay */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    background: var(--color-bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.nav-overlay.nav-overlay--active {
    opacity: 1;
    pointer-events: auto;
}

.nav-overlay-content {
    text-align: center;
    padding: 2rem;
}

.nav-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.nav-overlay-title {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--color-text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.nav-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.3s ease;
}

.nav-close:hover {
    color: var(--color-highlight);
}

.nav-overlay-rule {
    width: 60px;
    height: 1px;
    background: var(--color-accent-primary);
    margin: 0 auto 2rem;
}

.nav-overlay-link {
    display: block;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--color-highlight);
    margin-bottom: 1.5rem;
    transition: color 0.3s ease;
}

.nav-overlay-link::before {
    content: attr(data-chapter) ". ";
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    display: block;
    margin-bottom: 0.25rem;
    letter-spacing: 0.1em;
}

.nav-overlay-link:hover {
    color: var(--color-accent-primary);
}

/* ============================================
   Chapter Base Styles
   ============================================ */

.chapter {
    position: relative;
    min-height: 90vh;
    padding: 10vh 2rem;
    overflow: hidden;
}

/* ============================================
   Chapter 1: The Cover
   ============================================ */

.chapter-cover {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--color-bg-primary);
    padding: 0;
}

.cover-content {
    position: relative;
    z-index: 3;
    text-align: center;
}

.cover-title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(4rem, 10vw, 9rem);
    color: var(--color-highlight);
    letter-spacing: 0.02em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.cover-subtitle {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    color: var(--color-text-muted);
    letter-spacing: 0.04em;
}

.cover-chevron {
    position: absolute;
    bottom: 3vh;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    animation: chevronPulse 2.5s ease-in-out infinite;
    cursor: pointer;
}

@keyframes chevronPulse {
    0%, 100% { opacity: 0.4; transform: translateX(-50%) translateY(0); }
    50% { opacity: 1; transform: translateX(-50%) translateY(6px); }
}

/* ============================================
   Angular Dividers
   ============================================ */

.angular-divider {
    position: relative;
    height: 6vw;
    min-height: 40px;
    max-height: 80px;
    z-index: 5;
    margin-top: -1px;
    margin-bottom: -1px;
}

.angular-divider--copper {
    background: var(--color-bg-primary);
    clip-path: polygon(0 0, 100% 3vw, 100% 100%, 0 calc(100% - 3vw));
}

.angular-divider--copper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, transparent, var(--color-accent-primary), transparent);
    opacity: 0.15;
}

.angular-divider--dark {
    background: var(--color-bg-secondary);
    clip-path: polygon(0 3vw, 100% 0, 100% calc(100% - 3vw), 0 100%);
}

.angular-divider--dark::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, transparent, var(--color-accent-primary), transparent);
    opacity: 0.1;
}

/* ============================================
   Chapter 2: The Folio
   ============================================ */

.chapter-folio {
    background-color: var(--color-bg-secondary);
    padding: 12vh 2rem;
}

.folio-content {
    position: relative;
    z-index: 3;
    max-width: 1200px;
    margin: 0 auto;
}

.folio-wide {
    width: 75%;
    max-width: 38em;
    margin: 0 auto 6vh;
    position: relative;
}

.folio-narrow {
    width: 45%;
    margin-bottom: 6vh;
    position: relative;
}

.folio-narrow--right {
    margin-left: auto;
    margin-right: 5%;
}

.folio-narrow--left {
    margin-left: 5%;
    margin-right: auto;
}

.folio-text {
    font-family: var(--font-body);
    font-size: 1.125rem;
    line-height: 1.85;
    color: var(--color-text);
    max-width: 38em;
    margin-bottom: 1.5rem;
}

.folio-text--dropcap::first-letter {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 4.5em;
    float: left;
    line-height: 0.8;
    margin-right: 0.1em;
    margin-top: 0.05em;
    color: var(--color-accent-primary);
    text-shadow: 1px 1px 0 var(--color-accent-secondary);
}

.folio-marginalia-text {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--color-text-muted);
    letter-spacing: 0.03em;
    border-left: 2px solid #3A2E24;
    padding-left: 1rem;
}

.decorative-slashes {
    position: absolute;
    right: 2%;
    top: 20%;
    width: 60px;
    height: 200px;
    z-index: 1;
    opacity: 0.6;
}

.folio-slashes {
    right: 3%;
    top: 30%;
}

/* ============================================
   Pull Quotes
   ============================================ */

.pull-quote-container {
    margin: 8vh auto;
    max-width: 800px;
    position: relative;
    z-index: 3;
}

.pull-quote {
    transform: rotate(-2.5deg);
    border-left: 4px solid var(--color-accent-primary);
    padding: 2rem 2rem 2rem 2.5rem;
    position: relative;
    background: rgba(61, 46, 34, 0.3);
}

.pull-quote::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.06;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    pointer-events: none;
}

.pull-quote-text {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 3.375rem);
    color: var(--color-highlight);
    line-height: 1.3;
    display: block;
}

/* ============================================
   Ornamental Rules & Page Numbers
   ============================================ */

.ornamental-rule {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.ornamental-rule::before,
.ornamental-rule::after {
    content: '';
    width: 40px;
    height: 1px;
    background: var(--color-accent-primary);
    opacity: 0.5;
}

.ornamental-diamond {
    width: 6px;
    height: 6px;
    background: var(--color-accent-primary);
    transform: rotate(45deg);
    flex-shrink: 0;
}

.page-number {
    position: absolute;
    right: -3rem;
    top: 0;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.page-number::before {
    content: attr(data-page);
}

.page-number.page-number--visible {
    opacity: 1;
}

/* ============================================
   Section Titles
   ============================================ */

.section-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.5rem);
    color: var(--color-highlight);
    text-align: center;
    letter-spacing: 0.02em;
    margin-bottom: 1rem;
}

/* ============================================
   Chapter 3: The Gallery
   ============================================ */

.chapter-gallery {
    background-color: var(--color-bg-primary);
    padding: 10vh 2rem 12vh;
}

.gallery-header {
    position: relative;
    z-index: 3;
    text-align: center;
    margin-bottom: 6vh;
}

.gallery-strip {
    position: relative;
    z-index: 3;
    display: flex;
    gap: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.gallery-strip::-webkit-scrollbar {
    display: none;
}

.gallery-item {
    flex: 0 0 calc(25% - 1.125rem);
    min-width: 240px;
}

.gallery-image-wrapper {
    clip-path: polygon(8% 0, 100% 0, 92% 100%, 0 100%);
    overflow: hidden;
}

.gallery-image {
    position: relative;
    width: 100%;
    padding-bottom: 140%;
    filter: sepia(15%) contrast(1.05) saturate(0.9);
    transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.gallery-image-grain {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.12;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    z-index: 2;
}

.gallery-image-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 2rem 1.5rem;
    z-index: 3;
    background: linear-gradient(to top, rgba(30, 21, 16, 0.85) 0%, transparent 100%);
}

.gallery-image-number {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.gallery-image-caption {
    display: block;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-highlight);
    line-height: 1.3;
}

/* ============================================
   Chapter 4: The Marginalia
   ============================================ */

.chapter-marginalia {
    background-color: var(--color-bg-secondary);
    padding: 10vh 2rem 12vh;
}

.marginalia-header {
    position: relative;
    z-index: 3;
    text-align: center;
    margin-bottom: 6vh;
}

.marginalia-columns {
    position: relative;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr 40px 1fr;
    gap: 0;
    max-width: 1100px;
    margin: 0 auto;
}

.marginalia-main {
    position: relative;
    padding-right: 2rem;
}

.marginalia-gutter-slashes {
    display: flex;
    align-items: stretch;
    opacity: 0.5;
}

.marginalia-gutter-slashes svg {
    width: 100%;
    height: 100%;
}

.marginalia-annotations {
    padding-left: 2rem;
    padding-top: 1rem;
}

.annotation {
    margin-bottom: 2.5rem;
    position: relative;
}

.annotation-marker {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-accent-primary);
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 0.3rem;
}

.annotation-text {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--color-text-muted);
    letter-spacing: 0.02em;
}

.pull-quote-container--marginalia {
    grid-column: 1 / -1;
    margin-top: 4vh;
}

/* ============================================
   Chapter 5: The Appendix
   ============================================ */

.chapter-appendix {
    background-color: var(--color-bg-primary);
    padding: 10vh 2rem 12vh;
}

.appendix-header {
    position: relative;
    z-index: 3;
    text-align: center;
    margin-bottom: 6vh;
}

.appendix-grid {
    position: relative;
    z-index: 3;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    max-width: 1100px;
    margin: 0 auto;
}

.appendix-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-bg-accent);
    padding: 2rem;
    position: relative;
    clip-path: polygon(0 4%, 100% 0, 100% 100%, 0 100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.appendix-card--1 {
    transform: rotate(-1.5deg);
}

.appendix-card--2 {
    transform: rotate(1deg);
}

.appendix-card--3 {
    transform: rotate(-2deg);
}

.appendix-card-meta {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.appendix-card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--color-highlight);
    line-height: 1.3;
    margin-bottom: 1rem;
}

.appendix-card-body {
    font-family: var(--font-body);
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--color-text);
    margin-bottom: 1.5rem;
}

.appendix-card-date {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    letter-spacing: 0.05em;
}

/* ============================================
   Chapter 6: The Colophon
   ============================================ */

.chapter-colophon {
    background-color: var(--color-bg-primary);
    min-height: 50vh;
    padding: 8vh 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.colophon-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(8rem, 20vw, 20rem);
    color: var(--color-highlight);
    opacity: 0.03;
    pointer-events: none;
    white-space: nowrap;
    z-index: 1;
}

.colophon-content {
    position: relative;
    z-index: 3;
    text-align: center;
    max-width: 600px;
}

.colophon-rule {
    width: 80px;
    height: 1px;
    background: var(--color-accent-primary);
    margin: 0 auto 3rem;
    opacity: 0.5;
}

.colophon-text {
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

.colophon-diamond-rule {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.5rem 0;
}

.colophon-imprint {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    letter-spacing: 0.1em;
    margin-top: 2rem;
    opacity: 0.7;
}

.colophon-angular-rules {
    width: 100%;
    max-width: 400px;
    margin: 2rem auto 0;
    opacity: 0.4;
}

.colophon-angular-rules svg {
    width: 100%;
    height: 20px;
}

/* ============================================
   Reveal Animations
   ============================================ */

.reveal-element {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.5s cubic-bezier(0.25, 0.1, 0.25, 1.0),
                transform 0.5s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.reveal-element.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Gallery items have staggered delay */
.gallery-item.reveal-element {
    transition-delay: 0ms;
}

.gallery-item.reveal-element[data-delay="150"] {
    transition-delay: 150ms;
}

.gallery-item.reveal-element[data-delay="300"] {
    transition-delay: 300ms;
}

.gallery-item.reveal-element[data-delay="450"] {
    transition-delay: 450ms;
}

/* ============================================
   Marginalia Vertical Text (decorative)
   ============================================ */

.marginalia-main::after {
    content: 'PPEBBL FOLIO MMXXIV';
    position: absolute;
    left: -3rem;
    top: 50%;
    transform: rotate(-90deg) translateX(-50%);
    transform-origin: left center;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-text-muted);
    opacity: 0.3;
    letter-spacing: 0.15em;
    white-space: nowrap;
    pointer-events: none;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
    .appendix-grid {
        grid-template-columns: 1fr 1fr;
    }

    .appendix-card--3 {
        grid-column: 1 / -1;
        max-width: 500px;
        margin: 0 auto;
    }

    .marginalia-columns {
        grid-template-columns: 1fr;
        gap: 3rem;
    }

    .marginalia-gutter-slashes {
        display: none;
    }

    .marginalia-main {
        padding-right: 0;
    }

    .marginalia-annotations {
        padding-left: 0;
        border-top: 1px solid var(--color-bg-accent);
        padding-top: 2rem;
    }

    .pull-quote-container--marginalia {
        grid-column: auto;
    }
}

@media (max-width: 768px) {
    .chapter {
        padding: 8vh 1.25rem;
    }

    .nav-links {
        display: none;
    }

    .nav-toggle {
        display: block;
    }

    .folio-wide {
        width: 100%;
    }

    .folio-narrow {
        width: 80%;
    }

    .folio-narrow--right {
        margin-right: 0;
    }

    .folio-narrow--left {
        margin-left: 0;
    }

    .gallery-strip {
        padding: 0;
    }

    .gallery-item {
        flex: 0 0 70%;
        min-width: 200px;
    }

    .appendix-grid {
        grid-template-columns: 1fr;
    }

    .appendix-card--1,
    .appendix-card--2,
    .appendix-card--3 {
        transform: rotate(0);
        max-width: 100%;
    }

    .appendix-card--3 {
        grid-column: auto;
    }

    .pull-quote-text {
        font-size: clamp(1.4rem, 5vw, 2rem);
    }

    .pull-quote {
        transform: rotate(-1.5deg);
    }

    .page-number {
        right: -1.5rem;
    }

    .decorative-slashes {
        display: none;
    }

    .marginalia-main::after {
        display: none;
    }

    .cover-title {
        font-size: clamp(3rem, 15vw, 6rem);
    }
}

@media (max-width: 480px) {
    .cover-title {
        font-size: clamp(2.5rem, 18vw, 4rem);
    }

    .section-title {
        font-size: clamp(1.6rem, 8vw, 2.5rem);
    }

    .chapter {
        padding: 6vh 1rem;
    }

    .gallery-item {
        flex: 0 0 85%;
    }

    .folio-narrow {
        width: 95%;
    }

    .pull-quote {
        padding: 1.5rem;
        transform: rotate(-1deg);
    }
}
