/* ============================================================
   freedom.compare -- Styles
   A digital broadsheet in the style of an Enlightenment-era codex

   All-serif typographic system: Playfair Display, Cormorant Garamond,
   Cormorant SC, and Source Serif 4. No sans-serif or monospaced faces
   appears anywhere. This creates a fundamentally different textural
   experience that immediately signals "this is a publication, not a
   product." Fade-reveal is the only animation pattern -- no sliding,
   no parallax, no transforms for content. IntersectionObserver for
   scroll-triggered fade-reveals + one scroll listener for the gold
   thread SVG. fade-ins driven by CSS opacity transitions only.
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --codex-black: #1A140F;
    --parchment-cream: #F5F0E8;
    --gilt-leaf: #C5A55A;
    --bright-foil: #D4AF37;
    --aged-gilt: #8B7D3C;
    --sepia-ink: #2C2418;
    --warm-ivory: #E8E0D2;
    --scholarly-brown: #8B7D6B;
    --liberty-red: #8C2F2F;
    --dark-goldenrod: #B8860B;

    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Cormorant Garamond', Garamond, serif;
    --font-smallcaps: 'Cormorant SC', serif;
    --font-caption: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;

    --spine-width: 6px;
    --gutter: 40px;
    --baseline: 1.5rem;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.65;
    color: var(--sepia-ink);
    background: var(--codex-black);
    overflow-x: hidden;
}

/* --- Spread Layout (Magazine-Spread Diptych) --- */
.spread {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr var(--spine-width) 1fr;
    position: relative;
}

.spread.spread-epigraph {
    grid-template-columns: 1fr;
}

/* Full-spread pages override */
.page.full-spread {
    grid-column: 1 / -1;
}

/* --- The Spine (simulated book gutter) --- */
.spine {
    width: var(--spine-width);
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(26, 20, 15, 0.12) 40%,
        var(--dark-goldenrod) 49.5%,
        var(--dark-goldenrod) 50.5%,
        rgba(26, 20, 15, 0.12) 60%,
        transparent 100%
    );
    position: relative;
    z-index: 2;
}

/* --- Page Base --- */
.page {
    min-height: 100vh;
    padding: 3rem var(--gutter);
    position: relative;
    display: flex;
    flex-direction: column;
}

.page .page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    z-index: 1;
}

/* --- Codex Mode (dark background: #1A140F with ivory text: #E8E0D2) --- */
.codex-mode {
    background: var(--codex-black);
    color: var(--warm-ivory);
}

/* --- Parchment Mode (light background: #F5F0E8 with sepia text: #2C2418) --- */
.parchment-mode {
    background: var(--parchment-cream);
    color: var(--sepia-ink);
}

/* --- Running Headers (Cormorant SC, 0.65rem) --- */
.running-header {
    position: absolute;
    top: 1.5rem;
    font-family: var(--font-smallcaps);
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: var(--scholarly-brown);
    text-transform: uppercase;
    max-width: calc(100% - 2 * var(--gutter));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.verso .running-header {
    left: var(--gutter);
}

.recto .running-header {
    right: var(--gutter);
    text-align: right;
}

.full-spread .running-header {
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

/* --- Folio Numbers (Cormorant SC, small caps, outer bottom corner) --- */
.folio-number {
    position: absolute;
    bottom: 1.5rem;
    font-family: var(--font-smallcaps);
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: var(--scholarly-brown);
}

.verso-folio {
    left: var(--gutter);
}

.recto-folio {
    right: var(--gutter);
    text-align: right;
}

/* ============================================================
   FRONTISPIECE (Spread I)
   Full-viewport split: left=typography, right=archival photo
   ============================================================ */
.spread-frontispiece {
    position: relative;
}

.spread-frontispiece .verso {
    min-height: 100vh;
}

.frontispiece-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* "FREEDOM" in massive Playfair Display Black */
.title-freedom {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(4rem, 12vw, 10rem);
    line-height: 0.9;
    color: var(--warm-ivory);
    letter-spacing: 0.02em;
    margin-bottom: 1.5rem;
}

/* "COMPARE" in Cormorant SC tracked wide */
.title-compare {
    font-family: var(--font-smallcaps);
    font-weight: 400;
    font-size: clamp(1.2rem, 3vw, 2.5rem);
    letter-spacing: 0.3em;
    color: var(--gilt-leaf);
}

/* Frontispiece image side */
.frontispiece-image {
    justify-content: center;
    align-items: center;
}

.frontispiece-photo {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
}

/* Parchment overlay on frontispiece: #F5F0E8 at 40% opacity */
.parchment-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(245, 240, 232, 0.4);
    pointer-events: none;
}

/* Fleuron navigation -- gilt ornament, fades in after 2s, pulses */
.fleuron-nav {
    position: absolute;
    bottom: 4rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    color: var(--gilt-leaf);
    cursor: pointer;
    z-index: 10;
    opacity: 0;
    animation: fleuronFadeIn 0.5s ease 2s forwards, fleuronPulse 3s ease-in-out 2.5s infinite;
    transition: color 200ms ease;
}

.fleuron-nav:hover {
    color: var(--bright-foil);
}

@keyframes fleuronFadeIn {
    from { opacity: 0; }
    to { opacity: 0.6; }
}

@keyframes fleuronPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ============================================================
   EPIGRAPH (Spread II)
   Centered quote, word-by-word reveal, arabesque rule
   ============================================================ */
.spread-epigraph {
    grid-template-columns: 1fr;
}

.spread-epigraph .page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.epigraph-content {
    text-align: center;
    max-width: 50rem;
    margin: 0 auto;
    padding: 0 2rem;
}

.epigraph-quote {
    margin-bottom: 3rem;
}

.epigraph-words {
    font-family: var(--font-body);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    line-height: 1.5;
    color: var(--sepia-ink);
}

.epigraph-words .word {
    opacity: 0;
    transition: opacity 0.6s ease;
    display: inline-block;
}

.epigraph-words .word.visible {
    opacity: 1;
}

.epigraph-cite {
    display: block;
    margin-top: 2rem;
    font-family: var(--font-body);
    font-weight: 400;
    font-style: normal;
    font-size: 1rem;
    letter-spacing: 0.05em;
    color: var(--scholarly-brown);
    opacity: 0;
    transition: opacity 0.8s ease;
}

.epigraph-cite.visible {
    opacity: 1;
}

/* Arabesque rule: ornamental dot pattern that draws left-to-right */
.arabesque-rule {
    border: none;
    height: 1.5rem;
    background: none;
    position: relative;
    overflow: hidden;
    margin-top: 2rem;
}

.arabesque-rule::before {
    content: '\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7\2022\00B7';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--gilt-leaf);
    letter-spacing: 0.3em;
    white-space: nowrap;
    clip-path: inset(0 100% 0 0);
    animation: none;
}

.arabesque-rule.animate::before {
    animation: arabesqueDraw 2s ease forwards;
}

@keyframes arabesqueDraw {
    from { clip-path: inset(0 100% 0 0); }
    to { clip-path: inset(0 0 0 0); }
}

/* ============================================================
   CHAPTER SPREADS (Spreads III-VIII)
   ============================================================ */

/* Chapter title watermark (behind text on parchment pages) */
.chapter-title-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 20vw;
    color: var(--gilt-leaf);
    opacity: 0.08;
    line-height: 1;
    pointer-events: none;
    z-index: 0;
}

/* Chapter number watermark on codex title pages: 20vw, #C5A55A at 0.15 opacity */
.chapter-number-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 20vw;
    color: var(--gilt-leaf);
    opacity: 0.15;
    line-height: 1;
    pointer-events: none;
    z-index: 0;
}

/* Chapter title page (codex mode) */
.chapter-title-page .page-content {
    align-items: center;
    text-align: center;
    z-index: 1;
}

.chapter-heading-display {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5rem);
    line-height: 1.15;
    color: var(--warm-ivory);
    margin-bottom: 1rem;
}

.chapter-subtitle-display {
    font-family: var(--font-smallcaps);
    font-weight: 400;
    font-size: 1.1rem;
    letter-spacing: 0.15em;
    color: var(--scholarly-brown);
    margin-bottom: 2rem;
}

/* Gold rule with diamond terminals */
.gold-rule {
    border: none;
    height: 1px;
    background: var(--gilt-leaf);
    width: 120px;
    margin: 0 auto;
    position: relative;
}

.gold-rule::before,
.gold-rule::after {
    content: '\25C6';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.5rem;
    color: var(--gilt-leaf);
}

.gold-rule::before {
    left: -12px;
}

.gold-rule::after {
    right: -12px;
}

.gold-rule.short {
    width: 80px;
}

/* Chapter headings on text pages */
.chapter-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.5rem);
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.parchment-mode .chapter-heading {
    color: var(--sepia-ink);
}

.codex-mode .chapter-heading {
    color: var(--warm-ivory);
}

.chapter-subtitle {
    font-family: var(--font-smallcaps);
    font-weight: 400;
    font-size: 0.9rem;
    letter-spacing: 0.15em;
    color: var(--scholarly-brown);
    margin-bottom: 2rem;
}

/* ============================================================
   BODY TEXT
   Cormorant Garamond, weight 400, 1.65 line-height, max-width 38em
   ============================================================ */
.body-text {
    max-width: 38em;
    position: relative;
    z-index: 1;
}

.body-text p {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.65;
    margin-bottom: var(--baseline);
}

.parchment-mode .body-text p {
    color: var(--sepia-ink);
}

.codex-mode .body-text p {
    color: var(--warm-ivory);
}

/* --- Drop Capitals --- */
/* 4-line drop cap in Playfair Display Black, gold on parchment, bright gold on codex */
/* Bordered box: 1px #C5A55A border with 8px padding */
.has-drop-cap::first-letter {
    font-family: var(--font-display);
    font-weight: 900;
    float: left;
    font-size: 4.2em;
    line-height: 0.8;
    padding: 8px;
    margin-right: 12px;
    margin-top: 4px;
    border: 1px solid var(--gilt-leaf);
}

.parchment-mode .has-drop-cap::first-letter {
    color: var(--gilt-leaf);
}

.codex-mode .has-drop-cap::first-letter {
    color: var(--bright-foil);
}

/* ============================================================
   MARGIN NOTES
   120px-wide column, Cormorant Garamond italic at 0.75rem
   Vertical rule in #C5A55A, position: sticky
   ============================================================ */
.margin-notes {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 140px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.verso-margin {
    left: calc(100% - 160px);
}

.recto-margin {
    right: calc(100% - 160px);
}

.margin-note {
    font-family: var(--font-body);
    font-weight: 300;
    font-style: italic;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--scholarly-brown);
    position: sticky;
    top: 40%;
}

.margin-rule {
    width: 30px;
    height: 1px;
    background: var(--gilt-leaf);
    margin-bottom: 0.5rem;
}

.margin-source {
    display: block;
    font-style: normal;
    font-size: 0.65rem;
    color: var(--scholarly-brown);
    margin-top: 0.3rem;
    opacity: 0.7;
}

/* Colophon marks (SVG icons in margins) */
.colophon-mark {
    width: 20px;
    height: 20px;
    display: block;
    margin-bottom: 0.5rem;
}

/* ============================================================
   ARCHIVAL PHOTOGRAPHY
   Ornamental frames: 2px solid #C5A55A border + 12px padding,
   then 1px solid #8B7D6B outer frame
   Sepia filter: sepia(0.3) saturate(0.7) contrast(1.1)
   ============================================================ */
.archival-photo {
    margin-bottom: 2rem;
}

.photo-inner {
    position: relative;
    border: 2px solid var(--gilt-leaf);
    padding: 12px;
    background: transparent;
}

.photo-inner::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 1px solid var(--scholarly-brown);
    pointer-events: none;
    margin: -14px;
}

.photo-placeholder {
    position: relative;
    overflow: hidden;
}

.placeholder-svg {
    display: block;
    width: 100%;
    height: auto;
    filter: sepia(0.3) saturate(0.7) contrast(1.1);
}

/* Caption: Source Serif 4 italic, museum-label style */
.photo-caption {
    font-family: var(--font-caption);
    font-weight: 400;
    font-style: italic;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--scholarly-brown);
    margin-top: 0.75rem;
    text-align: center;
}

.fig-ref {
    font-style: normal;
    font-weight: 600;
    letter-spacing: 0.05em;
}

/* ============================================================
   COMPARATIVE DATA / BAR CHARTS
   CSS-only bar charts: gold bars on codex black
   ============================================================ */
.comparative-data {
    margin: 2rem 0;
}

.data-title {
    font-family: var(--font-smallcaps);
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    color: var(--scholarly-brown);
    margin-bottom: 1rem;
    text-transform: uppercase;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.bar-row {
    display: grid;
    grid-template-columns: 120px 1fr 50px;
    align-items: center;
    gap: 0.75rem;
}

.bar-label {
    font-family: var(--font-caption);
    font-size: 0.8rem;
    color: var(--warm-ivory);
    text-align: right;
}

.parchment-mode .bar-label {
    color: var(--sepia-ink);
}

.bar-track {
    height: 8px;
    background: rgba(139, 125, 107, 0.2);
    position: relative;
}

.bar-fill {
    height: 100%;
    background: var(--gilt-leaf);
    transition: width 1.5s ease;
}

.bar-fill-low {
    background: var(--liberty-red);
}

.bar-value {
    font-family: var(--font-caption);
    font-size: 0.75rem;
    color: var(--scholarly-brown);
}

/* ============================================================
   PULL QUOTES
   ============================================================ */
.pull-quote {
    margin: 2rem 0;
    padding: 1.5rem 0;
    border-top: 1px solid var(--aged-gilt);
    border-bottom: 1px solid var(--aged-gilt);
    text-align: center;
}

.pull-quote .fleuron-mark {
    display: block;
    font-size: 1.5rem;
    color: var(--gilt-leaf);
    margin-bottom: 0.75rem;
}

.pull-quote p {
    font-family: var(--font-body);
    font-weight: 400;
    font-style: italic;
    font-size: 1.1rem;
    line-height: 1.55;
    color: var(--warm-ivory);
    max-width: 30em;
    margin: 0 auto;
}

.parchment-mode .pull-quote p {
    color: var(--sepia-ink);
}

.pull-quote cite {
    display: block;
    margin-top: 0.75rem;
    font-family: var(--font-caption);
    font-weight: 400;
    font-style: normal;
    font-size: 0.8rem;
    color: var(--scholarly-brown);
}

/* ============================================================
   COLOPHON (Spread IX)
   ============================================================ */
.spread-colophon {
    position: relative;
}

.colophon-authors-note {
    padding: 4rem var(--gutter);
    max-width: 36em;
    margin: 0 auto;
}

.section-end {
    display: block;
    text-align: center;
    font-size: 1.5rem;
    color: var(--gilt-leaf);
    margin-bottom: 2rem;
}

.colophon-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.8rem;
    color: var(--warm-ivory);
    margin-bottom: 2rem;
    text-align: center;
}

.authors-note-text p {
    font-family: var(--font-body);
    font-weight: 400;
    font-style: italic;
    font-size: 1rem;
    line-height: 1.65;
    color: var(--warm-ivory);
    margin-bottom: var(--baseline);
    opacity: 0.9;
}

/* Colophon details */
.colophon-details {
    padding: 4rem var(--gutter);
    align-items: center;
}

.colophon-block {
    max-width: 32em;
    text-align: center;
}

.colophon-section-title {
    font-family: var(--font-smallcaps);
    font-weight: 400;
    font-size: 1.2rem;
    letter-spacing: 0.2em;
    color: var(--gilt-leaf);
    text-transform: uppercase;
    margin-bottom: 1.5rem;
}

.colophon-entry {
    margin: 2rem 0;
}

.colophon-label {
    display: block;
    font-family: var(--font-smallcaps);
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    color: var(--gilt-leaf);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.colophon-value {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--warm-ivory);
    opacity: 0.85;
}

/* Closing ornament (figure-eight knot) */
.closing-ornament {
    margin-top: 3rem;
    text-align: center;
}

.knot-svg {
    width: 120px;
    height: 60px;
}

.knot-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 3s ease;
}

.knot-path.drawn {
    stroke-dashoffset: 0;
}

.knot-terminal {
    opacity: 0;
    transition: opacity 0.8s ease 2.5s;
}

.knot-terminal.drawn {
    opacity: 1;
}

/* Vignette overlay on colophon: radial gradient to rgba(26,20,15,0.4) */
.vignette-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(26, 20, 15, 0.4) 100%);
    pointer-events: none;
    z-index: 5;
}

/* ============================================================
   GOLD THREAD
   Single continuous decorative line in #C5A55A, scroll-driven
   stroke-dashoffset animation
   ============================================================ */
.gold-thread {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: var(--spine-width);
    height: 100vh;
    z-index: 3;
    pointer-events: none;
    opacity: 0.4;
}

#gold-thread-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

/* ============================================================
   FADE ELEMENTS
   Primary transition: opacity 0->1 over 800ms
   ============================================================ */
.fade-element {
    opacity: 0;
    transition: opacity 800ms ease;
}

.fade-element.visible {
    opacity: 1;
}

/* Drop cap delayed fade -- 400ms delay after rest of paragraph */
.has-drop-cap.fade-element {
    opacity: 0;
    transition: opacity 800ms ease;
    transition-delay: 400ms;
}

.has-drop-cap.fade-element.visible {
    opacity: 1;
}

/* ============================================================
   FLEURON MARKS (section separators)
   ============================================================ */
.fleuron-mark {
    font-size: 1.5rem;
    color: var(--gilt-leaf);
    display: inline-block;
}

/* ============================================================
   RESPONSIVE (Mobile < 1024px)
   Single column, spine hidden, spreads become sequential pages
   ============================================================ */
@media (max-width: 1024px) {
    .spread {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .spine {
        display: none;
    }

    .page {
        min-height: auto;
        padding: 3rem 1.5rem;
    }

    .page .page-content {
        justify-content: flex-start;
    }

    .verso .running-header,
    .recto .running-header {
        left: 1.5rem;
        right: 1.5rem;
        text-align: center;
    }

    .folio-number {
        position: relative;
        bottom: auto;
        margin-top: 2rem;
        text-align: center;
    }

    .verso-folio,
    .recto-folio {
        left: auto;
        right: auto;
        text-align: center;
    }

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

    .title-compare {
        font-size: clamp(1rem, 4vw, 1.8rem);
    }

    .margin-notes {
        position: relative;
        top: auto;
        transform: none;
        width: 100%;
        padding: 1.5rem 0;
        border-top: 1px solid var(--aged-gilt);
        margin-top: 2rem;
    }

    .verso-margin,
    .recto-margin {
        left: auto;
        right: auto;
    }

    .margin-note {
        font-size: 0.85rem;
        position: relative;
        top: auto;
    }

    .chapter-title-watermark,
    .chapter-number-watermark {
        font-size: 30vw;
    }

    .fleuron-nav {
        bottom: 2rem;
    }

    .bar-row {
        grid-template-columns: 90px 1fr 40px;
    }

    .gold-thread {
        display: none;
    }

    .spread-frontispiece {
        grid-template-rows: auto auto;
    }

    .spread-frontispiece .verso {
        min-height: 60vh;
    }

    .spread-frontispiece .recto {
        min-height: 40vh;
    }

    .colophon-authors-note {
        padding: 3rem 1.5rem;
    }

    .colophon-details {
        padding: 3rem 1.5rem;
    }

    .spread-epigraph .running-header {
        left: 1.5rem;
        right: 1.5rem;
    }

    /* Page turn markers on mobile */
    .spread + .spread::before {
        content: '';
        display: block;
        width: 60px;
        height: 1px;
        background: var(--gilt-leaf);
        margin: 0 auto;
    }
}

/* --- Selection styling --- */
::selection {
    background: rgba(197, 165, 90, 0.3);
    color: var(--sepia-ink);
}

/* --- Scrollbar styling (webkit) --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--codex-black);
}

::-webkit-scrollbar-thumb {
    background: var(--aged-gilt);
    border-radius: 0;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gilt-leaf);
}
