/* ============================================================
   freedom.study -- Dark-Academia Scholarly Reading Experience
   ============================================================ */

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

:root {
    --library-dark: #1c1612;
    --vellum: #f8f4ed;
    --ink: #2c2418;
    --marginalia-red: #8b3a3a;
    --gilded: #b8860b;
    --aged-paper: #e8e0d0;
    --faded-ink: #7a6f60;
}

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

body {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 400;
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--ink);
    background-color: var(--vellum);
}

/* --- Hero Section --- */
#hero {
    background-color: var(--library-dark);
    color: var(--vellum);
    padding: 5rem 2rem 4rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero-inner {
    max-width: 700px;
    margin: 0 auto;
    position: relative;
}

/* Candle */
.candle {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2.5rem;
}

.candle-body {
    width: 8px;
    height: 40px;
    background: linear-gradient(to bottom, #d4a857, #b8860b);
    border-radius: 2px 2px 0 0;
    position: relative;
}

.candle-body::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 4px;
    background: #b8860b;
    border-radius: 0 0 2px 2px;
}

.candle-flame {
    width: 8px;
    height: 16px;
    background: radial-gradient(ellipse at center bottom, #ffd700 0%, #ff8c00 40%, #ff4500 70%, transparent 100%);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    position: relative;
    top: -2px;
    animation: flicker 2s ease-in-out infinite;
    order: -1;
}

.candle-flame::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    background: radial-gradient(ellipse, rgba(255, 200, 50, 0.15) 0%, transparent 70%);
    border-radius: 50%;
}

@keyframes flicker {
    0%, 100% { opacity: 1; transform: scaleY(1) scaleX(1); }
    25% { opacity: 0.8; transform: scaleY(1.05) scaleX(0.95); }
    50% { opacity: 0.95; transform: scaleY(0.95) scaleX(1.02); }
    75% { opacity: 0.7; transform: scaleY(1.02) scaleX(0.98); }
}

/* Site Title with Bookend Brackets */
.site-title {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    color: var(--vellum);
}

.title-text {
    position: relative;
}

.bookend {
    display: inline-block;
    width: 3px;
    height: 1.8em;
    background: var(--gilded);
    position: relative;
    flex-shrink: 0;
}

.bookend-left::before,
.bookend-left::after,
.bookend-right::before,
.bookend-right::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 3px;
    background: var(--gilded);
}

.bookend-left::before {
    top: 0;
    left: 0;
}

.bookend-left::after {
    bottom: 0;
    left: 0;
}

.bookend-right::before {
    top: 0;
    right: 0;
}

.bookend-right::after {
    bottom: 0;
    right: 0;
}

.current-study {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--faded-ink);
    letter-spacing: 0.05em;
}

.current-study em {
    color: var(--gilded);
    font-style: italic;
}

/* --- Main Content --- */
#content {
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

/* --- Chapter Layout: Three-Column on Wide Screens --- */
.chapter-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin-bottom: 1rem;
    position: relative;
}

@media (min-width: 1200px) {
    #content {
        max-width: 100%;
        padding: 3rem 2rem;
    }

    .chapter-layout {
        grid-template-columns: 180px 540px 180px;
        justify-content: center;
        gap: 2rem;
    }
}

/* --- Chapter Styling --- */
.chapter {
    padding: 0.5rem 0;
}

.chapter h2 {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--ink);
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--aged-paper);
    padding-bottom: 0.75rem;
}

.chapter-num {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 400;
    color: var(--gilded);
    letter-spacing: 0.1em;
    margin-right: 0.5em;
}

.chapter p {
    margin-bottom: 1.25rem;
    text-align: justify;
    hyphens: auto;
}

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

/* --- Drop Caps --- */
.drop-cap {
    float: left;
    font-family: 'Playfair Display', 'Georgia', serif;
    font-size: 4.5rem;
    line-height: 0.8;
    padding-right: 0.15em;
    padding-top: 0.05em;
    color: var(--marginalia-red);
    border-bottom: 2px solid var(--gilded);
}

/* --- Annotated Text --- */
.annotated-text {
    color: var(--marginalia-red);
    border-bottom: 1px dotted var(--faded-ink);
    cursor: help;
    position: relative;
}

/* --- Margin Annotations --- */
.margin-left,
.margin-right {
    display: none;
}

@media (min-width: 1200px) {
    .margin-left,
    .margin-right {
        display: block;
    }
}

.annotation {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--faded-ink);
    background: var(--aged-paper);
    padding: 0.75rem;
    border-left: 2px solid var(--marginalia-red);
    margin-bottom: 1rem;
    position: relative;
}

.annotation-marker {
    font-weight: 600;
    color: var(--marginalia-red);
    margin-right: 0.25em;
}

/* Dotted connector lines on wide screens */
@media (min-width: 1200px) {
    .margin-left .annotation::after {
        content: '';
        position: absolute;
        top: 1rem;
        right: -2rem;
        width: 2rem;
        border-top: 1px dotted var(--faded-ink);
    }

    .margin-right .annotation::before {
        content: '';
        position: absolute;
        top: 1rem;
        left: -2rem;
        width: 2rem;
        border-top: 1px dotted var(--faded-ink);
    }
}

/* --- Inline Annotations for Medium Screens --- */
@media (min-width: 768px) and (max-width: 1199px) {
    .margin-left,
    .margin-right {
        display: none;
    }

    .annotated-text {
        cursor: pointer;
    }

    .annotation-inline {
        display: none;
        font-family: 'Source Serif 4', 'Georgia', serif;
        font-size: 0.85rem;
        line-height: 1.6;
        color: var(--faded-ink);
        background: var(--aged-paper);
        padding: 0.75rem 1rem;
        border-left: 2px solid var(--marginalia-red);
        margin: 0.75rem 0;
    }

    .annotation-inline.visible {
        display: block;
    }
}

/* --- Mobile Footnotes --- */
@media (max-width: 767px) {
    .margin-left,
    .margin-right {
        display: none;
    }

    .chapter-footnotes {
        margin-top: 1.5rem;
        padding-top: 1rem;
        border-top: 1px solid var(--aged-paper);
    }

    .chapter-footnotes .annotation {
        font-size: 0.8rem;
        margin-bottom: 0.75rem;
    }
}

/* --- Fleuron Divider --- */
.fleuron {
    width: 16px;
    height: 16px;
    background: var(--gilded);
    transform: rotate(45deg);
    margin: 2.5rem auto;
    position: relative;
}

.fleuron::before,
.fleuron::after {
    content: '';
    position: absolute;
    background: var(--gilded);
}

.fleuron::before {
    width: 32px;
    height: 2px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
}

.fleuron::after {
    width: 2px;
    height: 32px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
}

.fleuron-small {
    width: 10px;
    height: 10px;
}

.fleuron-small::before {
    width: 22px;
    height: 2px;
}

.fleuron-small::after {
    width: 2px;
    height: 22px;
}

/* --- Footer / Colophon --- */
#colophon {
    text-align: center;
    padding: 3rem 2rem 4rem;
    background: var(--library-dark);
    color: var(--faded-ink);
}

#colophon .fleuron {
    background: var(--faded-ink);
    margin-bottom: 2rem;
}

#colophon .fleuron::before,
#colophon .fleuron::after {
    background: var(--faded-ink);
}

.colophon-text {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 1rem;
    font-style: italic;
    margin-bottom: 0.5rem;
    color: var(--aged-paper);
}

.colophon-sub {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-size: 0.8rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--faded-ink);
}

/* --- Scroll Fade-In Animation --- */
.chapter {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

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

/* --- Selection Styling --- */
::selection {
    background: rgba(139, 58, 58, 0.2);
    color: var(--ink);
}

/* --- Responsive Typography --- */
@media (max-width: 767px) {
    body {
        font-size: 1rem;
        line-height: 1.7;
    }

    #hero {
        padding: 3rem 1.5rem 2.5rem;
    }

    .site-title {
        gap: 0.5rem;
    }

    .bookend {
        height: 1.4em;
    }

    #content {
        padding: 2rem 1.25rem;
    }

    .chapter h2 {
        font-size: 1.4rem;
    }

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

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

@media (min-width: 768px) and (max-width: 1199px) {
    #content {
        max-width: 680px;
    }
}

/* --- Smooth Link Transitions --- */
a {
    color: var(--marginalia-red);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

a:hover {
    border-bottom-color: var(--marginalia-red);
}

/* --- Annotation Hover Effect on Wide Screens --- */
@media (min-width: 1200px) {
    .annotation {
        opacity: 0.7;
        transition: opacity 0.3s ease;
    }

    .annotation:hover,
    .annotation.highlight {
        opacity: 1;
    }
}

/* --- Candle glow on hero --- */
#hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 200px;
    background: radial-gradient(ellipse at center top, rgba(255, 200, 50, 0.06) 0%, transparent 70%);
    pointer-events: none;
}
