/* ============================================
   continuum.quest — styles.css
   Light Academia / Diagonal Sections / Scholarly
   ============================================ */

/* --- Custom Properties --- */
:root {
    --bg-primary: #FDF8F0;
    --bg-alternate: #F5EDE0;
    --text-primary: #3D3229;
    --text-secondary: #8B6F5E;
    --accent-warm: #C4956A;
    --accent-gold: #8B6914;
    --accent-deep: #6B4226;
    --margin-mute: #A0927B;
    --flare-highlight: #F2D9A0;
    --shadow-warm: #2A1F14;
    --heading-dark: #4A3728;
    --border-light: #D4C4B0;

    --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-body: 'Source Serif 4', 'Georgia', serif;
    --font-ui: 'DM Sans', 'Helvetica Neue', Arial, sans-serif;

    --reading-width: 680px;
    --section-padding: 8vw 5vw;

    --elastic-bezier: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1.05rem, 1.2vw, 1.25rem);
    line-height: 1.78;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

/* --- Progress Bar --- */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-warm), var(--accent-gold));
    transform: scaleX(0);
    transform-origin: left;
    z-index: 1000;
    pointer-events: none;
}

/* --- Chapter Indicator --- */
.chapter-indicator {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 999;
    pointer-events: none;
}

.chapter-indicator__text {
    font-family: var(--font-ui);
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    font-weight: 500;
    color: var(--margin-mute);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.chapter-indicator__text.fading {
    opacity: 0;
}

/* --- Narrative Article --- */
.narrative {
    position: relative;
    counter-reset: chapter;
}

/* --- Chapter Sections --- */
.chapter {
    position: relative;
    min-height: 90vh;
    padding: var(--section-padding);
    overflow: hidden;
}

.chapter--cream {
    background: linear-gradient(170deg, var(--bg-primary) 0%, var(--bg-alternate) 100%);
    clip-path: polygon(0 0, 100% 3vw, 100% 100%, 0 calc(100% - 3vw));
}

.chapter--parchment {
    background: linear-gradient(190deg, var(--bg-alternate) 0%, var(--bg-primary) 100%);
    clip-path: polygon(0 3vw, 100% 0, 100% calc(100% - 3vw), 0 100%);
}

/* First section: no top clip */
.chapter:first-child {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 calc(100% - 3vw));
    padding-top: 12vw;
}

/* Last section: no bottom clip */
.chapter:last-child {
    clip-path: polygon(0 3vw, 100% 0, 100% 100%, 0 100%);
    padding-bottom: 12vw;
}

/* Overlap sections so diagonal edges meet seamlessly */
.chapter + .chapter {
    margin-top: -3vw;
}

/* --- Lens Flare Overlays --- */
.chapter__flare {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.05;
    transition: opacity 2s ease;
    mix-blend-mode: soft-light;
    z-index: 1;
}

.chapter--visible .chapter__flare {
    opacity: 0.12;
}

/* Default flare: upper-left */
.chapter__flare {
    background:
        radial-gradient(ellipse 60% 50% at 10% 5%, var(--flare-highlight) 0%, transparent 70%),
        radial-gradient(ellipse 40% 35% at 15% 10%, var(--accent-warm) 0%, transparent 60%);
}

/* Upper-right flare */
.chapter__flare--right {
    background:
        radial-gradient(ellipse 60% 50% at 90% 5%, var(--flare-highlight) 0%, transparent 70%),
        radial-gradient(ellipse 40% 35% at 85% 10%, var(--accent-warm) 0%, transparent 60%);
}

/* Center-top flare */
.chapter__flare--center {
    background:
        radial-gradient(ellipse 70% 45% at 50% 0%, var(--flare-highlight) 0%, transparent 65%),
        radial-gradient(ellipse 50% 30% at 50% 5%, var(--accent-warm) 0%, transparent 55%);
}

/* Left flare */
.chapter__flare--left {
    background:
        radial-gradient(ellipse 55% 55% at 5% 15%, var(--flare-highlight) 0%, transparent 70%),
        radial-gradient(ellipse 35% 40% at 10% 20%, var(--accent-warm) 0%, transparent 60%);
}

/* Top flare */
.chapter__flare--top {
    background:
        radial-gradient(ellipse 80% 40% at 50% -5%, var(--flare-highlight) 0%, transparent 60%),
        radial-gradient(ellipse 50% 25% at 45% 2%, var(--accent-warm) 0%, transparent 50%);
}

/* Settle flare after initial pulse */
.chapter--visible .chapter__flare {
    animation: flarePulse 4s ease forwards;
}

@keyframes flarePulse {
    0% { opacity: 0.05; }
    50% { opacity: 0.12; }
    100% { opacity: 0.08; }
}

/* --- Folio Numbering --- */
.chapter__folio {
    position: absolute;
    top: 50%;
    left: 3vw;
    transform: translateY(-50%);
    font-family: var(--font-ui);
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    font-weight: 400;
    color: var(--margin-mute);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    opacity: 0.6;
    z-index: 2;
}

.chapter__folio--right {
    left: auto;
    right: 3vw;
}

/* --- Reading Column --- */
.reading-column {
    max-width: var(--reading-width);
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

/* Decorative left double-rule border */
.reading-column::before {
    content: '';
    position: absolute;
    left: -2.5rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: var(--border-light);
    opacity: 0.4;
}

.reading-column::after {
    content: '';
    position: absolute;
    left: calc(-2.5rem + 5px);
    top: 0;
    bottom: 0;
    width: 0.5px;
    background-color: var(--border-light);
    opacity: 0.4;
}

/* --- Chapter Labels --- */
.chapter-label {
    display: block;
    font-family: var(--font-ui);
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    font-weight: 500;
    color: var(--margin-mute);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

/* --- Headings --- */
.chapter-heading {
    font-family: var(--font-heading);
    font-size: clamp(2.2rem, 5vw, 4rem);
    font-weight: 700;
    color: var(--heading-dark);
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 0.4em;
}

.chapter-subheading {
    font-family: var(--font-heading);
    font-size: clamp(1.3rem, 2.5vw, 2rem);
    font-weight: 400;
    font-style: italic;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    line-height: 1.35;
    margin-bottom: 2em;
}

/* --- Body Text --- */
.reading-column p {
    margin-bottom: 1.5em;
    color: var(--text-primary);
}

/* First-line indent for consecutive paragraphs (book style) */
.reading-column p + p {
    text-indent: 1.5em;
}

/* Reset indent after non-paragraph elements */
.reading-column hr + p,
.reading-column aside + p,
.reading-column .footnote-tooltip + p,
.reading-column h1 + p,
.reading-column h2 + p,
.reading-column .chapter-subheading + p {
    text-indent: 0;
}

/* First paragraph has no indent */
.reading-column p.first-paragraph {
    text-indent: 0;
}

/* --- Drop Capitals --- */
.reading-column p.first-paragraph::first-letter {
    float: left;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(3.5rem, 6vw, 5.5rem);
    line-height: 0.8;
    color: var(--accent-deep);
    margin-right: 0.15em;
    margin-top: 0.05em;
    text-shadow: 2px 2px 8px rgba(242, 217, 160, 0.5);
}

/* --- Fleuron Dividers --- */
hr.fleuron {
    border: none;
    text-align: center;
    margin: 2.5em 0;
    position: relative;
    height: 1.5em;
    display: flex;
    align-items: center;
    justify-content: center;
}

hr.fleuron::before {
    content: '\2767';
    font-size: 1.2rem;
    color: var(--margin-mute);
    position: relative;
    z-index: 1;
    background: transparent;
    padding: 0 1em;
}

hr.fleuron::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--border-light) 15%,
        var(--border-light) 40%,
        transparent 45%,
        transparent 55%,
        var(--border-light) 60%,
        var(--border-light) 85%,
        transparent 100%
    );
}

/* --- Marginal Annotations --- */
.marginal-note {
    display: none;
}

@media (min-width: 1200px) {
    .marginal-note {
        display: block;
        position: absolute;
        width: 180px;
    }

    .marginal-note--right {
        right: -220px;
    }

    .marginal-note--left {
        left: -220px;
    }

    .marginal-note__text {
        font-family: var(--font-body);
        font-style: italic;
        font-weight: 300;
        font-size: 0.8rem;
        line-height: 1.5;
        color: var(--margin-mute);
    }
}

/* On smaller viewports, marginal notes become inline blockquotes */
@media (max-width: 1199px) {
    .marginal-note {
        display: block;
        margin: 1.5em 0;
        padding: 1em 1.5em;
        border-left: 2px solid var(--border-light);
    }

    .marginal-note__text {
        font-family: var(--font-body);
        font-style: italic;
        font-weight: 300;
        font-size: 0.85rem;
        line-height: 1.6;
        color: var(--margin-mute);
    }

    /* Reset text-indent after marginal note blockquote */
    .marginal-note + p {
        text-indent: 0;
    }
}

/* --- Footnote Markers --- */
.footnote-marker {
    color: var(--accent-warm);
    cursor: pointer;
    font-size: 0.75em;
    position: relative;
    transition: color 0.2s ease;
}

.footnote-marker:hover {
    color: var(--accent-gold);
}

/* --- Footnote Tooltips --- */
.footnote-tooltip {
    display: none;
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 1em 1.2em;
    max-width: 320px;
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
    box-shadow: 0 4px 20px rgba(42, 31, 20, 0.08);
    z-index: 100;
    transform: scale(0.9);
    opacity: 0;
    transition:
        transform 0.3s var(--elastic-bezier),
        opacity 0.2s ease;
}

.footnote-tooltip.visible {
    display: block;
    transform: scale(1);
    opacity: 1;
}

.footnote-tooltip em {
    font-style: italic;
}

/* --- Elastic Entrance Animations --- */
.animate-in {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
    transition:
        transform 0.8s var(--elastic-bezier),
        opacity 0.6s ease-out;
}

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

/* --- Closing Mark --- */
.closing-mark {
    text-align: center;
    font-size: 2rem;
    color: var(--accent-deep);
    margin-top: 2em;
    text-indent: 0 !important;
}

/* --- Inline Emphasis --- */
.reading-column em {
    font-weight: 600;
    font-style: italic;
}

/* --- Superscript --- */
.reading-column sup {
    font-size: 0.65em;
    line-height: 0;
    vertical-align: super;
}

/* --- Selection Color --- */
::selection {
    background: var(--flare-highlight);
    color: var(--heading-dark);
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .chapter {
        padding: 12vw 6vw;
    }

    .chapter:first-child {
        padding-top: 16vw;
    }

    .chapter__folio {
        display: none;
    }

    .reading-column::before,
    .reading-column::after {
        display: none;
    }

    .chapter-indicator {
        bottom: 1rem;
        right: 1rem;
    }
}

@media (max-width: 480px) {
    .chapter {
        padding: 14vw 5vw;
    }

    .chapter--cream,
    .chapter--parchment {
        clip-path: polygon(0 0, 100% 2vw, 100% 100%, 0 calc(100% - 2vw));
    }

    .chapter--parchment {
        clip-path: polygon(0 2vw, 100% 0, 100% calc(100% - 2vw), 0 100%);
    }

    .chapter:first-child {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 calc(100% - 2vw));
    }

    .chapter:last-child {
        clip-path: polygon(0 2vw, 100% 0, 100% 100%, 0 100%);
    }

    .chapter + .chapter {
        margin-top: -2vw;
    }
}
