/* ============================================
   freedom.study — Styles
   Dark-academia aesthetic, forbidden library
   ============================================ */

:root {
    /* Palette */
    --primary-dark: #1C1410;
    --secondary-dark: #0F0C09;
    --interleaf: #2A1F1A;
    --parchment: #E8DCC8;
    --aged-text: #C9B99A;
    --faded-ink: #7B6B52;
    --lamp-amber: #C4956A;
    --ruby-seal: #8B2E3B;
    --verdigris: #3D6B5E;
    --muted-sienna: #6B5D4D;
    --weathered-ink: #8A7A62;

    /* Typography */
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Libre Baskerville', 'Times New Roman', serif;
    --font-marginalia: 'EB Garamond', Georgia, serif;
    --font-ui: 'Inter', Helvetica, Arial, sans-serif;

    /* Spacing */
    --spread-gap: 80px;
    --section-padding: 100px 0;
}

/* ============================================
   Reset & Base
   ============================================ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--primary-dark);
    color: var(--aged-text);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.78;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   Grain Overlay
   ============================================ */

.grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}

/* ============================================
   Navigation
   ============================================ */

.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 48px;
    background: rgba(15, 12, 9, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 900;
}

.wordmark {
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted-sienna);
}

.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
}

.hamburger-line {
    display: block;
    width: 20px;
    height: 1.5px;
    background: var(--muted-sienna);
    transition: all 0.3s ease;
}

.hamburger.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translateY(6.5px) translateX(3px);
}

.hamburger.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translateY(-6.5px) translateX(3px);
}

/* ============================================
   Index Panel (Table of Contents)
   ============================================ */

.index-panel {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100%;
    background: var(--secondary-dark);
    z-index: 950;
    transition: right 0.4s ease;
    padding: 80px 40px 40px;
}

.index-panel.open {
    right: 0;
}

.index-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 12, 9, 0.6);
    z-index: 940;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.index-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.index-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 24px;
    color: var(--parchment);
    margin-bottom: 32px;
    letter-spacing: 0.02em;
}

.index-list {
    list-style: none;
}

.index-list li {
    margin-bottom: 16px;
}

.index-list a {
    font-family: var(--font-marginalia);
    font-style: italic;
    font-size: 16px;
    color: var(--faded-ink);
    text-decoration: none;
    transition: color 0.3s ease;
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.index-list a:hover {
    color: var(--lamp-amber);
}

.roman {
    font-style: normal;
    color: var(--muted-sienna);
    min-width: 28px;
}

/* ============================================
   Cover Section
   ============================================ */

.cover {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--secondary-dark);
    overflow: hidden;
}

.cover::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(44, 33, 22, 0.08) 0%, transparent 50%, rgba(44, 33, 22, 0.05) 100%);
    pointer-events: none;
}

.cover-content {
    text-align: center;
    z-index: 2;
    position: relative;
}

.cover-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(36px, 6vw, 72px);
    color: var(--parchment);
    letter-spacing: 0.08em;
    line-height: 1.15;
    margin-bottom: 24px;
}

.cover-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
}

.cover-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(14px, 2vw, 18px);
    color: var(--weathered-ink);
    opacity: 0;
    transition: opacity 0.8s ease;
    max-width: 500px;
    margin: 0 auto;
}

.cover-subtitle.visible {
    opacity: 1;
}

.cover-seal {
    margin-top: 48px;
    opacity: 0;
    transform: scale(0.5);
}

.cover-seal.visible {
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cover-seal svg {
    width: 100px;
    height: 100px;
}

/* ============================================
   Candlelight Glow
   ============================================ */

.candlelight {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background: radial-gradient(ellipse at 30% 25%, rgba(196, 149, 106, 0.12) 0%, transparent 60%);
    animation: lampDrift 12s ease-in-out infinite alternate;
}

@keyframes lampDrift {
    0% {
        background: radial-gradient(ellipse at 30% 25%, rgba(196, 149, 106, 0.12) 0%, transparent 60%);
    }
    50% {
        background: radial-gradient(ellipse at 32% 23%, rgba(196, 149, 106, 0.10) 0%, transparent 60%);
    }
    100% {
        background: radial-gradient(ellipse at 28% 27%, rgba(196, 149, 106, 0.13) 0%, transparent 60%);
    }
}

/* ============================================
   Editorial Spreads
   ============================================ */

.editorial-spread {
    position: relative;
    padding: var(--section-padding);
    background: var(--primary-dark);
    overflow: hidden;
}

.spread-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: var(--spread-gap);
    padding: 0 40px;
    position: relative;
    z-index: 2;
}

.text-column {
    max-width: 38ch;
}

.chapter-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(32px, 5vw, 56px);
    color: var(--parchment);
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 40px;
}

.chapter-num {
    display: block;
    font-size: 16px;
    letter-spacing: 0.2em;
    color: var(--muted-sienna);
    margin-bottom: 8px;
    font-family: var(--font-ui);
    text-transform: uppercase;
}

.text-column p {
    margin-bottom: 24px;
    font-size: 18px;
    line-height: 1.78;
    color: var(--aged-text);
}

.text-column em {
    font-style: italic;
    color: var(--parchment);
}

/* ============================================
   Marginalia Column
   ============================================ */

.marginalia-column {
    padding-top: 80px;
    border-left: 1px solid rgba(123, 107, 82, 0.2);
    padding-left: 32px;
}

.annotation {
    font-family: var(--font-marginalia);
    font-style: italic;
    font-size: 14px;
    line-height: 1.6;
    color: var(--faded-ink);
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(123, 107, 82, 0.1);
}

.annotation:last-child {
    border-bottom: none;
}

.annotation p {
    margin: 0;
}

.annotation.highlight p {
    color: var(--lamp-amber);
}

.annotation strong {
    font-weight: 400;
    font-style: normal;
    color: var(--aged-text);
}

/* ============================================
   Marginalia Vignettes (SVG Icons)
   ============================================ */

.marginalia-vignette {
    margin-bottom: 24px;
    position: relative;
}

.vignette-icon {
    width: 48px;
    height: 48px;
    transition: transform 0.3s ease-out;
    cursor: pointer;
}

.vignette-icon:hover {
    transform: scale(1.15);
}

.vignette-icon:hover path,
.vignette-icon:hover line,
.vignette-icon:hover circle {
    stroke: var(--lamp-amber);
    transition: stroke 0.3s ease-out;
}

.vignette-tooltip {
    display: block;
    font-family: var(--font-marginalia);
    font-style: italic;
    font-size: 13px;
    color: var(--aged-text);
    opacity: 0;
    transition: opacity 0.2s ease;
    margin-top: 8px;
}

.marginalia-vignette:hover .vignette-tooltip {
    opacity: 1;
}

/* ============================================
   Redacted Text
   ============================================ */

.redacted {
    position: relative;
    cursor: pointer;
}

.redacted::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -2px;
    right: -2px;
    bottom: -1px;
    background: var(--secondary-dark);
    opacity: 0.85;
    transition: opacity 1.5s ease-in-out;
    pointer-events: none;
}

.redacted:hover::after {
    opacity: 0;
}

.redacted.revealed::after {
    opacity: 0;
}

.redacted.revealed,
.redacted:hover {
    color: var(--lamp-amber);
    transition: color 0.5s ease;
}

/* ============================================
   Interleaf Sections
   ============================================ */

.interleaf {
    background: var(--interleaf);
    padding: 80px 40px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.interleaf::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    mix-blend-mode: multiply;
    opacity: 0.10;
    pointer-events: none;
}

.interleaf-content {
    position: relative;
    z-index: 2;
    max-width: 700px;
    margin: 0 auto;
}

.interleaf-quote {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(20px, 3vw, 28px);
    color: var(--parchment);
    line-height: 1.5;
    margin-bottom: 16px;
}

.interleaf-attribution {
    font-family: var(--font-marginalia);
    font-style: italic;
    font-size: 16px;
    color: var(--faded-ink);
}

.interleaf-seal {
    margin-top: 32px;
    display: inline-block;
}

.interleaf-seal svg {
    width: 40px;
    height: 40px;
}

/* Wipe-reveal animation */
.wipe-reveal {
    position: relative;
}

.wipe-reveal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--interleaf);
    z-index: 10;
    transform-origin: left;
    transition: none;
}

.wipe-reveal.revealed::before {
    animation: wipeAway 0.8s ease-in-out forwards;
}

@keyframes wipeAway {
    0% {
        transform: scaleX(1);
        transform-origin: right;
    }
    100% {
        transform: scaleX(0);
        transform-origin: right;
    }
}

/* ============================================
   Scroll Reveal Animations
   ============================================ */

.reveal-left {
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

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

.reveal-right {
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    transition-delay: 0.2s;
}

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

/* ============================================
   Fleuron Divider
   ============================================ */

.fleuron {
    text-align: center;
    margin-bottom: 32px;
}

.fleuron-element {
    display: inline-block;
    width: 24px;
    height: 24px;
    position: relative;
}

.fleuron-element::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    background: var(--faded-ink);
    transform: translate(-50%, -50%) rotate(45deg);
}

.fleuron-element::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-dark);
    transform: translate(-50%, -50%);
}

/* ============================================
   Colophon (Footer)
   ============================================ */

.colophon {
    background: var(--secondary-dark);
    padding: 80px 40px;
    text-align: center;
    position: relative;
}

.colophon-text {
    max-width: 520px;
    margin: 0 auto 32px;
}

.colophon-text p {
    font-family: var(--font-ui);
    font-size: 13px;
    letter-spacing: 0.04em;
    color: var(--muted-sienna);
    line-height: 1.7;
    margin-bottom: 12px;
}

.colophon-secondary {
    color: var(--faded-ink) !important;
    font-size: 12px !important;
}

.colophon-seal {
    display: inline-block;
    margin-bottom: 24px;
}

.colophon-seal svg {
    width: 24px;
    height: 24px;
}

.finis {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.15em;
    color: var(--faded-ink);
    margin-top: 16px;
}

/* ============================================
   Blockquote (if used)
   ============================================ */

blockquote {
    border-left: 2px solid var(--verdigris);
    padding-left: 20px;
    margin: 24px 0;
    font-style: italic;
}

/* ============================================
   Links
   ============================================ */

a {
    color: var(--lamp-amber);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--parchment);
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .spread-inner {
        grid-template-columns: 1fr;
        gap: 40px;
        padding: 0 24px;
    }

    .text-column {
        max-width: 100%;
    }

    .marginalia-column {
        border-left: none;
        border-top: 1px solid rgba(123, 107, 82, 0.2);
        padding-left: 0;
        padding-top: 32px;
    }

    .interleaf {
        padding: 60px 24px;
    }

    .cover-seal svg {
        width: 72px;
        height: 72px;
    }

    .colophon {
        padding: 60px 24px;
    }

    .index-panel {
        width: 280px;
        right: -280px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 16px;
    }

    .text-column p {
        font-size: 16px;
    }

    .spread-inner {
        padding: 0 16px;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .reveal-left,
    .reveal-right {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .cover-title .letter {
        opacity: 1;
        transform: none;
    }

    .cover-subtitle {
        opacity: 1;
    }

    .cover-seal {
        opacity: 1;
        transform: scale(1);
    }

    .candlelight {
        animation: none;
    }

    .wipe-reveal::before {
        display: none;
    }

    .redacted::after {
        transition: opacity 0.1s ease;
    }

    .grain-overlay {
        opacity: 0.06 !important;
    }
}
