/* ========================================
   HHASSL.com — Illuminated Manuscript Theme
   ======================================== */

/* CSS Custom Properties (Palette from DESIGN.md) */
:root {
    --deep-parchment: #F5ECD7;
    --aged-vellum: #E8D9B8;
    --scholarly-ink: #2C1810;
    --burnt-sienna: #A0522D;
    --antique-gold: #C4956A;
    --library-shadow: #3E2117;
    --margin-whisper: #8B8B6E;
    --candlelight-glow: #E8A84C;
    --foxed-page: #D4C09E;
    --dark-umber: #8B5A2B;

    /* Mesh gradient positions */
    --mesh-x: 50%;
    --mesh-y: 50%;
    --mesh-x2: 30%;
    --mesh-y2: 70%;
}

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

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

body {
    font-family: 'Lora', Georgia, serif;
    font-size: 1.125rem;
    line-height: 1.78;
    color: var(--scholarly-ink);
    background: linear-gradient(175deg, var(--deep-parchment) 0%, var(--aged-vellum) 40%, var(--deep-parchment) 70%, var(--aged-vellum) 100%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ===== Parallax Container ===== */
.parallax-container {
    position: relative;
    width: 100%;
    min-height: 100vh;
}

/* ===== Gradient Mesh Background ===== */
.mesh-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.35;
}

.mesh-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.mesh-layer-1 {
    background:
        radial-gradient(ellipse at var(--mesh-x) var(--mesh-y), var(--antique-gold) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, var(--candlelight-glow) 0%, transparent 40%),
        radial-gradient(ellipse at 20% 80%, var(--foxed-page) 0%, transparent 45%);
}

.mesh-layer-2 {
    background:
        radial-gradient(ellipse at var(--mesh-x2) var(--mesh-y2), var(--burnt-sienna) 0%, transparent 35%),
        radial-gradient(ellipse at 70% 60%, var(--foxed-page) 0%, transparent 50%);
    opacity: 0.5;
}

.mesh-layer-3 {
    background:
        conic-gradient(from 45deg at 50% 50%, transparent 0deg, var(--antique-gold) 60deg, transparent 120deg, var(--candlelight-glow) 200deg, transparent 280deg, var(--foxed-page) 340deg, transparent 360deg);
    opacity: 0.15;
}

/* ===== Table of Contents Bookmark ===== */
.toc-bookmark {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    flex-direction: row-reverse;
}

.toc-icon {
    width: 44px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s ease;
    filter: drop-shadow(-2px 2px 4px rgba(62, 33, 23, 0.3));
}

.toc-bookmark:hover .toc-icon {
    transform: scale(1.05);
}

.toc-list {
    background: var(--deep-parchment);
    border: 2px solid var(--antique-gold);
    border-right: none;
    border-radius: 8px 0 0 8px;
    padding: 20px 24px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
    box-shadow: -4px 4px 16px rgba(62, 33, 23, 0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 200px;
}

.toc-bookmark:hover .toc-list {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.toc-title {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-variant: small-caps;
    font-size: 1rem;
    color: var(--burnt-sienna);
    letter-spacing: 0.1em;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--foxed-page);
    margin-bottom: 4px;
}

.toc-item {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-size: 0.875rem;
    color: var(--scholarly-ink);
    text-decoration: none;
    transition: color 0.2s ease;
    display: block;
    padding: 2px 0;
}

.toc-item:hover {
    color: var(--burnt-sienna);
}

.toc-numeral {
    font-variant: small-caps;
    color: var(--antique-gold);
    margin-right: 8px;
    font-weight: 600;
}

/* ===== Title Page ===== */
.title-page {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
}

.title-ornament-top,
.title-ornament-bottom {
    width: 100%;
    max-width: 400px;
    margin: 20px auto;
}

.title-ornament-top .ornament-svg,
.title-ornament-bottom .ornament-svg {
    width: 100%;
    height: auto;
}

.title-main {
    font-family: 'Libre Baskerville', 'Baskerville', serif;
    font-size: clamp(3rem, 8vw, 6rem);
    font-weight: 700;
    color: var(--library-shadow);
    letter-spacing: 0.06em;
    text-shadow: 0 2px 4px rgba(139, 90, 43, 0.2);
    margin: 10px 0;
}

.title-subtitle {
    margin: 10px 0 20px;
}

.subtitle-text {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-variant: small-caps;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: var(--burnt-sienna);
    letter-spacing: 0.15em;
}

.title-year {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-variant: small-caps;
    font-size: 1rem;
    color: var(--margin-whisper);
    letter-spacing: 0.2em;
    margin-top: 30px;
}

/* ===== Chapters ===== */
.chapter {
    position: relative;
    z-index: 1;
    max-width: 780px;
    margin: 0 auto;
    padding: 80px 40px 60px;
    counter-increment: chapter;
}

/* ===== Folio Numbers ===== */
.folio-number {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-variant: small-caps;
    font-size: 0.875rem;
    color: var(--margin-whisper);
    text-align: center;
    letter-spacing: 0.15em;
    padding-bottom: 20px;
    opacity: 0.7;
}

/* ===== Chapter Headers ===== */
.chapter-header {
    text-align: center;
    margin-bottom: 50px;
}

.chapter-number {
    font-family: 'Libre Baskerville', 'Baskerville', serif;
    font-size: 1rem;
    color: var(--antique-gold);
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 10px;
}

.chapter-number em {
    font-style: italic;
}

.chapter-divider {
    width: 100%;
    max-width: 500px;
    margin: 15px auto;
}

.divider-svg {
    width: 100%;
    height: auto;
}

.chapter-title {
    font-family: 'Libre Baskerville', 'Baskerville', serif;
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 700;
    color: var(--library-shadow);
    letter-spacing: 0.02em;
    text-shadow: 0 1px 2px rgba(139, 90, 43, 0.15);
    margin-top: 15px;
}

/* ===== SVG Ornament Stroke Animation ===== */
.ornament-stroke {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1.2s ease-out;
}

.ornament-animated .ornament-stroke {
    stroke-dashoffset: 0;
}

/* ===== Content Blocks ===== */
.content-block {
    position: relative;
    margin: 30px 0;
}

.body-text {
    font-family: 'Lora', Georgia, serif;
    font-size: 1.125rem;
    line-height: 1.78;
    color: var(--scholarly-ink);
    margin-bottom: 1.6em;
    text-indent: 1.5em;
}

.body-text:first-child {
    text-indent: 0;
}

/* ===== Drop Caps ===== */
.drop-cap {
    font-family: 'Playfair Display', 'Didot', serif;
    font-size: 4.5rem;
    float: left;
    line-height: 0.75;
    margin-right: 8px;
    margin-top: 8px;
    color: transparent;
    background: linear-gradient(180deg, var(--dark-umber), var(--antique-gold));
    -webkit-background-clip: text;
    background-clip: text;
    transform: scale(0.8) rotate(-5deg);
    transition: transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.drop-cap-animated {
    transform: scale(1) rotate(0deg);
}

/* ===== Book Plate Frames ===== */
.book-plate {
    border: 2px solid var(--antique-gold);
    border-radius: 4px;
    padding: 40px 35px;
    position: relative;
    background: rgba(245, 236, 215, 0.4);
    box-shadow: inset 0 0 0 4px transparent, inset 0 0 0 5px var(--foxed-page);
}

.corner-ornament {
    position: absolute;
    width: 20px;
    height: 20px;
}

.corner-ornament.corner-tl {
    top: -2px;
    left: -2px;
}

.corner-ornament.corner-tr {
    top: -2px;
    right: -2px;
}

.corner-ornament.corner-bl {
    bottom: -2px;
    left: -2px;
}

.corner-ornament.corner-br {
    bottom: -2px;
    right: -2px;
}

.pulse-ornament {
    animation: pulseOrnament 4s ease-in-out infinite;
}

@keyframes pulseOrnament {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* ===== Pull Quotes ===== */
.pull-quote {
    position: relative;
    margin: 50px 0 50px 40px;
    padding: 20px 30px 20px 35px;
    border-left: 3px solid var(--burnt-sienna);
}

.pull-quote-mark {
    font-family: 'Playfair Display', serif;
    font-size: 4rem;
    color: var(--antique-gold);
    position: absolute;
    top: -15px;
    left: 5px;
    line-height: 1;
    opacity: 0.6;
}

.pull-quote-text {
    font-family: 'Libre Baskerville', 'Baskerville', serif;
    font-size: 1.25rem;
    font-style: italic;
    line-height: 1.7;
    color: var(--dark-umber);
}

/* ===== Marginalia ===== */
.marginalia {
    position: absolute;
    width: 160px;
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.5s ease 0.3s, transform 0.5s ease 0.3s;
}

.marginalia-visible {
    opacity: 0.65;
    transform: translateX(0);
}

.marginalia-left {
    left: -190px;
    text-align: right;
}

.marginalia-right {
    right: -190px;
    text-align: left;
}

.marginalia-text {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-style: italic;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--margin-whisper);
    display: block;
    transform: rotate(-2deg);
}

/* ===== Colophon ===== */
.colophon {
    position: relative;
    z-index: 1;
    max-width: 780px;
    margin: 0 auto;
    padding: 100px 40px 120px;
    text-align: center;
}

.colophon-divider {
    max-width: 300px;
    margin: 0 auto 50px;
}

.colophon-divider .ornament-svg {
    width: 100%;
    height: auto;
}

.wax-seal {
    margin: 0 auto 40px;
    width: 100px;
    height: 100px;
    filter: drop-shadow(0 4px 8px rgba(62, 33, 23, 0.35));
}

.colophon-text {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--margin-whisper);
    letter-spacing: 0.02em;
    margin-bottom: 30px;
}

.colophon-domain {
    font-family: 'Libre Baskerville', 'Baskerville', serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--library-shadow);
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

.colophon-year {
    font-family: 'Cormorant Garamond', 'Garamond', serif;
    font-variant: small-caps;
    font-size: 0.875rem;
    color: var(--antique-gold);
    letter-spacing: 0.2em;
}

/* ===== Reveal Animations ===== */
.reveal-element {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

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

/* Staggered delay for body text */
.content-block .body-text.reveal-element:nth-child(2) {
    transition-delay: 0.15s;
}

.content-block .body-text.reveal-element:nth-child(3) {
    transition-delay: 0.3s;
}

.content-block .body-text.reveal-element:nth-child(4) {
    transition-delay: 0.45s;
}

/* Chapter header stagger */
.chapter-header .chapter-number {
    transition-delay: 0s;
}

.chapter-header .chapter-divider {
    transition-delay: 0.2s;
}

.chapter-header .chapter-title {
    transition-delay: 0.4s;
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    .reveal-element {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .ornament-stroke {
        stroke-dasharray: none;
        stroke-dashoffset: 0;
        transition: none;
    }

    .drop-cap {
        transform: none;
        transition: none;
    }

    .marginalia {
        opacity: 0.65;
        transform: none;
        transition: none;
    }

    .pulse-ornament {
        animation: none;
    }
}

/* ===== Responsive ===== */
@media screen and (max-width: 1100px) {
    .marginalia {
        position: relative;
        left: auto;
        right: auto;
        width: 100%;
        text-align: left;
        margin: 15px 0;
        padding: 10px 20px;
        border-left: 2px solid var(--foxed-page);
    }

    .marginalia-left,
    .marginalia-right {
        left: auto;
        right: auto;
    }

    .marginalia-text {
        transform: none;
    }
}

@media screen and (max-width: 768px) {
    .chapter {
        padding: 60px 24px 40px;
    }

    .colophon {
        padding: 80px 24px 100px;
    }

    .book-plate {
        padding: 30px 20px;
    }

    .pull-quote {
        margin-left: 10px;
        padding-left: 20px;
    }

    .toc-bookmark {
        display: none;
    }

    .title-main {
        letter-spacing: 0.03em;
    }

    .body-text {
        font-size: 1rem;
    }
}

@media screen and (max-width: 480px) {
    .chapter {
        padding: 40px 16px 30px;
    }

    .colophon {
        padding: 60px 16px 80px;
    }

    .drop-cap {
        font-size: 3.5rem;
    }

    .pull-quote-text {
        font-size: 1.1rem;
    }

    .book-plate {
        padding: 24px 16px;
    }

    .corner-ornament {
        display: none;
    }
}
