/* ===================================================
   haskell.quest — Scholarly Editorial Design
   =================================================== */

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

:root {
    --parchment-cream: #f5f0e8;
    --bookcloth-charcoal: #2c2c2c;
    --scholarly-burgundy: #6b2d3e;
    --forest-ink: #2d4a3e;
    --faded-ink: #8a8578;
    --warm-linen: #f0ebe0;
    --library-walnut: #3a2a1e;
    --gilt-edge: #c4a35a;
}

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

body {
    font-family: 'Lora', Georgia, serif;
    background-color: var(--parchment-cream);
    color: var(--bookcloth-charcoal);
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    /* Paper grain texture */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.02'/%3E%3C/svg%3E");
}

/* --- Gutter Line (Book Spine) --- */
#gutter-line {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 100vh;
    background-color: var(--bookcloth-charcoal);
    opacity: 0.12;
    z-index: 100;
    pointer-events: none;
    transition: opacity 2s ease;
}

#gutter-line.breathing {
    opacity: 0.20;
}

/* --- Page Number Indicator --- */
#page-indicator {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.5s ease;
}

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

#page-number {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-size: 0.75rem;
    font-variant: small-caps;
    color: var(--faded-ink);
    letter-spacing: 0.02em;
}

/* --- Spreads (Sections) --- */
.spread {
    min-height: 100vh;
    scroll-snap-align: start;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 3rem;
}

.spread-inner {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
}

/* --- 12-Column Grid --- */
.spread-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0 2rem;
    align-items: start;
}

/* --- FRONTISPIECE --- */
#frontispiece {
    background-color: var(--parchment-cream);
    flex-direction: column;
}

.frontispiece-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

#site-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--bookcloth-charcoal);
    letter-spacing: -0.01em;
    line-height: 1.15;
    opacity: 0;
    transition: opacity 1200ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

#site-title.visible {
    opacity: 1;
}

#title-rule {
    width: 120px;
    height: 1px;
    background-color: var(--faded-ink);
    margin: 1.5rem 0;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 800ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

#title-rule.visible {
    transform: scaleX(1);
}

#epigraph {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--faded-ink);
    max-width: 540px;
    line-height: 1.65;
    opacity: 0;
    transition: opacity 900ms cubic-bezier(0.25, 0.1, 0.25, 1);
    margin-bottom: 0.5rem;
}

#epigraph.visible {
    opacity: 1;
}

#epigraph-attribution {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--faded-ink);
    opacity: 0;
    transition: opacity 900ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

#epigraph-attribution.visible {
    opacity: 1;
}

/* --- TABLE OF CONTENTS --- */
#toc {
    background-color: var(--parchment-cream);
}

.toc-left {
    grid-column: 1 / 6;
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
    padding: 2rem 0;
}

.toc-entry {
    display: flex;
    align-items: center;
    gap: 1rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 700ms cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 700ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.toc-entry.in-view {
    opacity: 1;
    transform: translateY(0);
}

.toc-numeral {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-size: 1rem;
    font-variant: small-caps;
    color: var(--faded-ink);
    min-width: 2rem;
    letter-spacing: 0.02em;
}

.toc-rule {
    display: block;
    width: 40px;
    height: 1px;
    background-color: var(--faded-ink);
    opacity: 0.5;
}

.toc-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    color: var(--bookcloth-charcoal);
    letter-spacing: -0.01em;
}

.toc-right {
    grid-column: 7 / 13;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.toc-image-container {
    width: 100%;
    position: relative;
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 900ms cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 900ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.toc-image-container.in-view {
    opacity: 1;
    transform: translateY(0);
}

.nature-image {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid var(--faded-ink);
    filter: saturate(0.2) contrast(1.1) sepia(0.08);
}

.image-caption {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-variant: small-caps;
    font-size: clamp(0.75rem, 1.2vw, 0.85rem);
    color: var(--faded-ink);
    margin-top: 8px;
    letter-spacing: 0.02em;
    line-height: 1.5;
}

/* --- SECTION HEADERS --- */
.section-header {
    margin-bottom: 2rem;
    position: relative;
}

.section-numeral {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-size: 0.9rem;
    font-variant: small-caps;
    color: var(--faded-ink);
    letter-spacing: 0.04em;
    display: block;
    margin-bottom: 0.5rem;
}

.section-heading {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    color: var(--bookcloth-charcoal);
    letter-spacing: -0.01em;
    line-height: 1.15;
}

/* --- Marginalia --- */
.marginalia {
    display: none;
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--faded-ink);
    opacity: 0;
    transform: translateX(10px);
    transition: opacity 300ms ease, transform 300ms ease;
    position: absolute;
    right: -220px;
    top: 0;
    width: 200px;
    line-height: 1.5;
}

@media (min-width: 1100px) {
    .marginalia {
        display: block;
    }

    .section-header:hover .marginalia {
        opacity: 1;
        transform: translateX(0);
    }
}

/* --- SPREAD TYPE A: Text left, pull quote right --- */
.spread-type-a .text-column-left {
    grid-column: 1 / 8;
    padding-right: 2rem;
}

.spread-type-a .pull-quote-column {
    grid-column: 8 / 13;
    display: flex;
    align-items: center;
    padding-left: 1rem;
}

.pull-quote {
    border-top: 1px solid var(--faded-ink);
    border-bottom: 1px solid var(--faded-ink);
    padding: 2rem 0;
    position: relative;
}

.pull-quote p {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.3rem, 2.5vw, 2rem);
    color: var(--bookcloth-charcoal);
    line-height: 1.3;
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
}

.pull-quote cite {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--faded-ink);
    font-style: normal;
    letter-spacing: 0.01em;
}

/* Pull quote animation */
.pull-quote-column {
    opacity: 0;
    transform: translateX(60px);
    transition: opacity 800ms cubic-bezier(0.22, 0.61, 0.36, 1) 400ms,
                transform 800ms cubic-bezier(0.22, 0.61, 0.36, 1) 400ms;
}

.pull-quote-column.in-view {
    opacity: 1;
    transform: translateX(0);
}

.pull-quote::before,
.pull-quote::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--faded-ink);
    transform: scaleX(0);
    transition: transform 600ms cubic-bezier(0.22, 0.61, 0.36, 1) 600ms;
}

.pull-quote::before {
    top: -1px;
    transform-origin: left;
}

.pull-quote::after {
    bottom: -1px;
    transform-origin: right;
}

.pull-quote-column.in-view .pull-quote::before,
.pull-quote-column.in-view .pull-quote::after {
    transform: scaleX(1);
}

/* --- SPREAD TYPE B: Photo left, text right --- */
.spread-type-b .photo-column-left {
    grid-column: 1 / 6;
    position: relative;
}

.spread-type-b .text-column-right {
    grid-column: 7 / 13;
    padding-left: 1rem;
}

.parallax-image-container {
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 900ms cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 900ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.parallax-image-container.in-view {
    opacity: 1;
    transform: translateY(0);
}

.parallax-image-container .nature-image {
    transition: filter 900ms ease;
}

.cream-overlay {
    position: absolute;
    bottom: 40px;
    left: 1rem;
    right: 1rem;
    background-color: rgba(245, 240, 232, 0.88);
    padding: 1.2rem 1.5rem;
}

.overlay-caption {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-variant: small-caps;
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    color: var(--bookcloth-charcoal);
    line-height: 1.5;
    letter-spacing: 0.01em;
}

/* --- Body Text --- */
.body-text {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    color: var(--bookcloth-charcoal);
}

.body-text p {
    margin-bottom: 1.25rem;
}

.body-text p:last-child {
    margin-bottom: 0;
}

.body-text code {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.9em;
    color: var(--scholarly-burgundy);
    background-color: var(--warm-linen);
    padding: 0.15em 0.35em;
    border-radius: 2px;
}

.centered-text {
    max-width: 720px;
    margin: 2rem auto 0;
    text-align: center;
}

/* --- Drop Capitals --- */
.drop-cap {
    float: left;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 700;
    font-size: 4.5rem;
    line-height: 0.8;
    padding-right: 12px;
    padding-top: 0.1em;
    color: var(--faded-ink);
    transition: color 600ms ease;
}

.drop-cap.saturated {
    color: var(--scholarly-burgundy);
}

/* --- Animate-in base --- */
.animate-in {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 700ms cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 700ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.animate-in.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* --- SPREAD TYPE C: Code Specimen --- */
.spread-type-c {
    background-color: var(--parchment-cream);
}

.spread-type-c .spread-inner {
    max-width: 900px;
}

.code-specimen {
    margin: 2.5rem 0;
}

.code-frame {
    background-color: var(--warm-linen);
    padding: 2rem 2.5rem;
    position: relative;
    border-top: 0.5px solid var(--faded-ink);
    border-bottom: 0.5px solid var(--faded-ink);
}

/* Double rule effect */
.code-frame::before,
.code-frame::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 0.5px;
    background-color: var(--faded-ink);
}

.code-frame::before {
    top: 4px;
}

.code-frame::after {
    bottom: 4px;
}

.code-frame pre {
    margin: 0;
    overflow-x: auto;
}

.code-frame code {
    font-family: 'Source Code Pro', monospace;
    font-weight: 400;
    font-size: clamp(0.85rem, 1.4vw, 0.95rem);
    line-height: 1.65;
    letter-spacing: 0em;
    tab-size: 2;
    color: var(--bookcloth-charcoal);
}

/* Syntax highlighting: only 3 colors */
.code-frame .kw {
    color: var(--scholarly-burgundy);
    font-weight: 500;
}

.code-frame .ty {
    color: var(--forest-ink);
}

.code-frame .fn {
    color: var(--bookcloth-charcoal);
    font-weight: 500;
}

.code-frame .co {
    color: var(--faded-ink);
    font-style: italic;
}

/* Code line animation */
.code-frame pre code .code-line {
    display: block;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 300ms ease, transform 300ms ease;
}

.code-frame pre code .code-line.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* --- COLOPHON --- */
#colophon {
    background-color: var(--library-walnut);
    padding: 12vh 3rem;
    transition: background-color 0.5s ease;
}

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

.fleuron-svg {
    width: 48px;
    height: 48px;
    animation: fleuronSway 8s ease-in-out infinite;
}

@keyframes fleuronSway {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(2deg); }
    75% { transform: rotate(-2deg); }
}

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

.colophon-text p {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--parchment-cream);
    line-height: 1.75;
    margin-bottom: 1rem;
    opacity: 0.85;
}

.colophon-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: 1.4rem;
    font-variant: small-caps;
    letter-spacing: 0.04em;
    color: var(--parchment-cream) !important;
    opacity: 1 !important;
    margin-bottom: 1.5rem !important;
}

.colophon-domain {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--gilt-edge) !important;
    opacity: 0.7 !important;
    letter-spacing: 0.02em;
    margin-top: 1.5rem !important;
}

/* --- Fleuron separator --- */
.section-separator {
    text-align: center;
    margin: 3rem 0;
}

.section-separator svg {
    width: 24px;
    height: 24px;
    opacity: 0.6;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .spread {
        padding: 3rem 1.5rem;
        min-height: auto;
        scroll-snap-align: none;
    }

    .spread-grid {
        grid-template-columns: 1fr;
        gap: 2rem 0;
    }

    .toc-left,
    .toc-right,
    .spread-type-a .text-column-left,
    .spread-type-a .pull-quote-column,
    .spread-type-b .photo-column-left,
    .spread-type-b .text-column-right {
        grid-column: 1 / -1;
    }

    .pull-quote-column {
        transform: none !important;
    }

    #gutter-line {
        display: none;
    }

    .marginalia {
        display: none !important;
    }

    .cream-overlay {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        margin-top: 0.5rem;
    }

    .drop-cap {
        font-size: 3.5rem;
        padding-right: 8px;
    }

    #site-title {
        font-size: clamp(2.2rem, 10vw, 4rem);
    }

    .code-frame {
        padding: 1.5rem 1rem;
    }

    .spread-type-c .spread-inner {
        max-width: 100%;
    }

    #page-indicator {
        bottom: 1rem;
        right: 1rem;
    }

    .toc-right {
        order: -1;
    }
}

@media (max-width: 480px) {
    .spread {
        padding: 2rem 1rem;
    }

    .pull-quote p {
        font-size: 1.2rem;
    }

    .section-heading {
        font-size: 1.6rem;
    }
}

/* --- Selection styling --- */
::selection {
    background-color: rgba(107, 45, 62, 0.15);
    color: var(--bookcloth-charcoal);
}

/* --- Scroll transition for colophon background --- */
#colophon {
    background: linear-gradient(
        to bottom,
        var(--parchment-cream) 0%,
        var(--library-walnut) 30%,
        var(--library-walnut) 100%
    );
}

/* --- Link styles --- */
a {
    color: var(--bookcloth-charcoal);
    text-decoration: none;
    border-bottom: 1px solid var(--faded-ink);
    transition: border-color 300ms ease, color 300ms ease;
}

a:hover {
    color: var(--gilt-edge);
    border-bottom-color: var(--gilt-edge);
}
