/* ====================================================
   freedom.study -- Stylesheet
   A scholarly folio rendered in the browser

   Typography: "Playfair Display" (Google Fonts) for display,
   "Cormorant Garamond" for body, "EB Garamond" for marginalia,
   "Libre Baskerville" for references.

   IntersectionObserver triggers fade-reveal animations in JS.
   Threshold 0.6 for spread visibility detection.
   Fade duration: 800ms ease-out for standard spreads.

   Playfair Display Black at 4x the body text size for drop caps.
   Playfair Display at a smaller size (clamp(1.5rem, 3vw, 2.5rem))
   for the colophon title for instant rendering of the typeface.
   Preload fonts via `<link rel="preload">` for optimal loading.

   ==================================================== */

/* Custom Properties */
:root {
    --color-vellum: #F5F0E8;
    --color-folio-black: #1A1612;
    --color-gold: #C4A44A;
    --color-tarnished-gilt: #8B7635;
    --color-ink: #2C2620;
    --color-faded: #6B6054;
    --color-oxblood: #6B1D2A;
    --color-parchment-glow: #E8D5A3;

    --font-display: 'Playfair Display', serif;
    --font-body: 'Cormorant Garamond', serif;
    --font-margin: 'EB Garamond', serif;
    --font-reference: 'Libre Baskerville', serif;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1.05rem, 1.4vw, 1.25rem);
    line-height: 1.75;
    color: var(--color-ink);
    background-color: var(--color-folio-black);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background-color: var(--color-parchment-glow);
    color: var(--color-ink);
}

/* ====================================================
   Spread Base
   ==================================================== */
.spread {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.spread-inner {
    width: 100%;
    max-width: 1200px;
    margin-inline: auto;
    padding-inline: 4rem;
    padding-block: 4rem;
}

/* Light and Dark Spread Variants */
.spread-dark {
    background-color: var(--color-folio-black);
    color: var(--color-parchment-glow);
    color-scheme: dark;
}

/* Leather texture overlay for dark sections -- barely perceptible 3% opacity */
.spread-dark::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

.spread-dark > * {
    position: relative;
    z-index: 1;
}

.spread-light {
    background-color: var(--color-vellum);
    color: var(--color-ink);
}

/* ====================================================
   Fade-Reveal Animation (applied via JS)
   Content appears by transitioning from opacity 0 to 1
   with a slight vertical translate (20px upward)
   ==================================================== */
.spread {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 800ms ease-out, transform 800ms ease-out;
}

.spread.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Titlepage has its own entrance -- longer 1500ms duration */
#spread-titlepage {
    transition-duration: 1500ms;
}

/* Argument spread is faster (600ms) to maintain reading momentum */
#spread-argument {
    transition-duration: 600ms;
}

/* Colophon spread -- background transition over 1000ms */
#spread-colophon {
    transition-duration: 1000ms;
}

/* ====================================================
   Spread 1: Titlepage
   Full-viewport composition on Deep Folio Black
   ==================================================== */
.titlepage-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    gap: 2rem;
    padding-block: 6rem;
}

.titlepage-ornament-top {
    color: var(--color-gold);
    opacity: 0.6;
}

.titlepage-title {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(3.5rem, 8vw, 6rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--color-gold);
    line-height: 1.1;
}

.titlepage-rule {
    display: flex;
    justify-content: center;
}

.gold-rule {
    display: block;
    width: 200px;
    height: 1px;
    background-color: var(--color-gold);
}

.gold-rule-wide {
    width: 300px;
}

.titlepage-epigraph {
    max-width: 600px;
    font-family: var(--font-margin);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1rem, 1.3vw, 1.15rem);
    line-height: 1.8;
    color: var(--color-parchment-glow);
    border: none;
    padding: 0;
}

.titlepage-epigraph cite {
    display: block;
    margin-block-start: 0.75rem;
    font-size: 0.9em;
    color: var(--color-faded);
    font-style: italic;
}

.titlepage-fleuron-bottom {
    margin-block-start: 2rem;
    color: var(--color-gold);
}

/* Pulse-attention: gentle opacity oscillation 2s ease-in-out
   between 0.4 and 1.0 to suggest "continue reading" */
.fleuron-pulse {
    animation: pulseAttention 2s ease-in-out infinite;
}

@keyframes pulseAttention {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* ====================================================
   Fleuron / SVG Ornament Base
   ==================================================== */
.fleuron {
    display: block;
    color: var(--color-gold);
}

.gold-rule-ornament {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-block: 1.5rem;
    color: var(--color-gold);
}

/* SVG path-draw animation -- ornaments draw themselves
   into existence over 1500ms as their spread enters viewport */
.fleuron-draw path,
.fleuron-draw circle,
.fleuron-draw line {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 1500ms ease;
}

.is-visible .fleuron-draw path,
.is-visible .fleuron-draw circle,
.is-visible .fleuron-draw line {
    stroke-dashoffset: 0;
}

/* ====================================================
   7/5 Grid Layout (Recto-Verso)
   Magazine-spread: wider column (recto) for primary text,
   narrower column (verso) for marginalia and annotations
   ==================================================== */
.spread-grid {
    display: grid;
    grid-template-columns: 7fr 5fr;
    gap: 2.5rem;
    align-items: start;
}

.spread-recto {
    padding-inline-end: 1rem;
}

.spread-verso {
    position: relative;
    padding-inline-start: 1.5rem;
}

/* ====================================================
   Typography -- Body Text
   Cormorant Garamond at weight 400, line-height 1.75
   ==================================================== */
.body-text p {
    margin-block-end: 1.5rem;
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
}

.body-text em {
    font-style: italic;
    font-weight: 400;
}

/* Drop Caps -- Playfair Display Black at 4x body text size,
   floated left, colored Oxblood (#6B1D2A), occupies 3 lines */
.drop-cap {
    float: left;
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 4em;
    line-height: 0.8;
    padding-block-end: 0.05em;
    padding-inline-end: 0.5em;
    color: var(--color-oxblood);
}

/* ====================================================
   Marginalia
   ==================================================== */
.marginalia-rule {
    position: absolute;
    left: 0;
    top: 10%;
    width: 1px;
    height: 60%;
    background-color: var(--color-gold);
}

.marginalia {
    padding-block-start: 2rem;
}

/* Pull Quote (tilted -1.5deg, as if penciled in by an engaged reader) */
.pull-quote-tilted {
    font-family: var(--font-margin);
    font-style: italic;
    font-weight: 400;
    font-size: 1.3em;
    line-height: 1.6;
    color: var(--color-tarnished-gilt);
    transform: rotate(-1.5deg);
    border: none;
    padding: 0;
    margin-block-end: 1.5rem;
}

.pull-quote-tilted p {
    margin: 0;
}

/* Blur-focus animation for pull quotes --
   text enters at filter: blur(2px) and resolves to blur(0)
   over 600ms as the spread comes into view */
.pull-quote-tilted {
    filter: blur(2px);
    opacity: 0;
    transition: filter 600ms ease, opacity 600ms ease;
}

.is-visible .pull-quote-tilted {
    filter: blur(0);
    opacity: 1;
}

/* Pencil mark SVG -- thin, slightly wavy line */
.pencil-mark {
    color: var(--color-tarnished-gilt);
    margin-block: 1rem;
    opacity: 0.6;
}

/* Margin note -- EB Garamond Italic at reduced size */
.margin-note {
    font-family: var(--font-margin);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    line-height: 1.6;
    color: var(--color-faded);
    margin-block-start: 1.5rem;
}

/* ====================================================
   Spread 3: The Plate
   Full-width photographic composition with gold border
   and cream mat treatment
   ==================================================== */
.plate-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    padding-block: 4rem;
}

.plate-figure {
    width: 80vw;
    max-width: 1000px;
    margin-inline: auto;
}

/* Engraved plate treatment: 1px gold border, 1.5rem cream mat */
.plate-mat {
    border: 1px solid var(--color-gold);
    padding: 1.5rem;
    background-color: var(--color-vellum);
}

.plate-image {
    width: 100%;
    overflow: hidden;
}

.plate-illustration {
    width: 100%;
    height: auto;
    display: block;
}

/* Scale transition for plate -- settles into position
   from scale(1.02) to scale(1.0) over 1200ms */
.plate-figure {
    transform: scale(1.02);
    opacity: 0;
    transition: transform 1200ms ease, opacity 1200ms ease;
}

.is-visible .plate-figure {
    transform: scale(1);
    opacity: 1;
}

/* Caption -- EB Garamond Italic, small-caps, centered */
.plate-caption {
    font-family: var(--font-margin);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    color: var(--color-faded);
    margin-block-start: 1.25rem;
    letter-spacing: 0.02em;
    line-height: 1.6;
}

.small-caps {
    font-variant: small-caps;
    letter-spacing: 0.06em;
}

.plate-rule-top {
    margin-block-end: 2rem;
}

.plate-rule-bottom {
    margin-block-start: 2rem;
}

/* ====================================================
   Spread 4: The Argument -- Footnotes & Pull Quote Box
   ==================================================== */

/* Footnote references -- Cormorant Garamond SemiBold, Oxblood */
.footnote-ref {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.75em;
    color: var(--color-oxblood);
    vertical-align: super;
    line-height: 0;
}

.footnote-link {
    color: var(--color-oxblood);
    text-decoration: none;
    position: relative;
    display: inline-block;
}

/* Underline-draw animation on footnote hover --
   a thin Oxblood line extending from left to right over 300ms */
.footnote-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background-color: var(--color-oxblood);
    transition: width 300ms ease;
}

.footnote-link:hover::after {
    width: 100%;
}

/* Footnotes block */
.footnotes {
    margin-block-start: 2.5rem;
    padding-block-start: 1.5rem;
    border-block-start: 1px solid var(--color-tarnished-gilt);
}

.footnote {
    font-family: var(--font-margin);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    line-height: 1.6;
    color: var(--color-faded);
    margin-block-end: 0.5rem;
}

.footnote sup {
    font-weight: 600;
    color: var(--color-oxblood);
    margin-inline-end: 0.25em;
}

.footnote em {
    font-style: italic;
}

/* Ornamental initial in verso */
.ornamental-initial {
    margin-block-end: 1.5rem;
    opacity: 0.85;
}

.ornamental-initial svg {
    display: block;
}

/* Pull quote box -- thin gold border on all four sides, 1.5rem padding,
   Cormorant Garamond SemiBold Italic, centered */
.pull-quote-box {
    border: 1px solid var(--color-gold);
    padding: 1.5rem;
    margin-block: 1.5rem;
    text-align: center;
}

.pull-quote-box p {
    font-family: var(--font-body);
    font-weight: 600;
    font-style: italic;
    font-size: clamp(1rem, 1.3vw, 1.15rem);
    line-height: 1.7;
    color: var(--color-ink);
    margin: 0;
}

/* ====================================================
   Spread 5: The Colophon
   Centered composition on Deep Folio Black
   ==================================================== */
.colophon-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    gap: 1.5rem;
    padding-block: 6rem;
}

.colophon-rule {
    margin-block-end: 1rem;
}

/* Colophon title -- Playfair Display at smaller size clamp(1.5rem, 3vw, 2.5rem) */
.colophon-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-gold);
}

.colophon-meta {
    margin-block: 0.5rem;
}

/* Colophon text -- EB Garamond Italic, Parchment Glow */
.colophon-line {
    font-family: var(--font-margin);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.1vw, 1.05rem);
    color: var(--color-parchment-glow);
    margin-block-end: 0.25rem;
}

.colophon-links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-block: 1rem;
}

.colophon-link {
    font-family: var(--font-margin);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.85rem, 1vw, 1rem);
    color: var(--color-parchment-glow);
    text-decoration: none;
    position: relative;
    display: inline-block;
}

/* Underline-draw animation on colophon links --
   a gold line that extends from left to right on hover, 400ms ease */
.colophon-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background-color: var(--color-gold);
    transition: width 400ms ease;
}

.colophon-link:hover::after {
    width: 100%;
}

.colophon-separator {
    color: var(--color-tarnished-gilt);
    font-size: 0.8em;
}

.colophon-device {
    margin-block: 1.5rem;
    color: var(--color-gold);
}

.colophon-printer-mark {
    font-family: var(--font-margin);
    font-size: clamp(0.75rem, 0.9vw, 0.85rem);
    color: var(--color-faded);
    line-height: 1.7;
}

/* ====================================================
   Responsive (mobile: single-column scroll)
   Collapses recto-verso to a single-page scroll
   ==================================================== */
@media (max-width: 768px) {
    .spread-inner {
        padding-inline: 1.5rem;
        padding-block: 3rem;
    }

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

    .spread-recto {
        padding-inline-end: 0;
    }

    .spread-verso {
        padding-inline-start: 0;
    }

    .marginalia-rule {
        display: none;
    }

    .titlepage-title {
        letter-spacing: 0.08em;
    }

    .plate-figure {
        width: 95vw;
    }

    .plate-mat {
        padding: 0.75rem;
    }

    .colophon-links {
        flex-direction: column;
        gap: 0.5rem;
    }

    .colophon-separator {
        display: none;
    }

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

    .body-text p {
        text-align: left;
        hyphens: none;
    }
}

@media (max-width: 480px) {
    .titlepage-content {
        padding-block: 4rem;
    }

    .drop-cap {
        font-size: 3em;
    }
}

/* ====================================================
   Print Stylesheet
   Removes all animation, reduces margins, sets text
   to pure black on white
   ==================================================== */
@media print {
    .spread {
        opacity: 1 !important;
        transform: none !important;
        min-height: auto;
        page-break-inside: avoid;
    }

    .spread-dark {
        background-color: #fff;
        color: #000;
    }

    .spread-dark::before {
        display: none;
    }

    .fleuron-pulse {
        animation: none;
    }

    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    .titlepage-title,
    .colophon-title {
        color: #000;
    }

    .gold-rule,
    .gold-rule-wide {
        background-color: #999;
    }

    .pull-quote-tilted {
        filter: none;
        opacity: 1;
    }

    .plate-figure {
        transform: none;
        opacity: 1;
    }
}
