/* === CSS Custom Properties === */
:root {
    --oxblood-noir: #1a0f0f;
    --aged-vellum: #2d2318;
    --garnet-wire: #7b2d3b;
    --burnished-gold: #c9a84c;
    --sapphire-ink: #2a4a7f;
    --emerald-notation: #2d6b4f;
    --parchment-light: #e8dcc8;
    --foxed-page: #9a8b73;
    --amethyst-glow: #6b3fa0;
    --folio-border: #3d2b1f;
    --scroll-y: 0;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--oxblood-noir);
    color: var(--parchment-light);
    font-family: 'Lora', serif;
    font-size: clamp(0.95rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    overflow-x: hidden;
}

/* === Blob Layer === */
.blob-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.blob {
    position: absolute;
    filter: blur(40px);
}

.blob-1 {
    width: 500px;
    height: 500px;
    top: 10%;
    left: -5%;
}

.blob-2 {
    width: 400px;
    height: 400px;
    top: 35%;
    right: -8%;
}

.blob-3 {
    width: 550px;
    height: 550px;
    top: 60%;
    left: 10%;
}

.blob-4 {
    width: 450px;
    height: 450px;
    top: 85%;
    right: 5%;
}

/* === Opening Folio === */
.opening-folio {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.folio-content {
    text-align: center;
    position: relative;
}

.circuit-traces-hero {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 800px;
    height: auto;
    pointer-events: none;
}

.trace {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

.hero-animate .trace {
    animation: drawTrace 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.trace-1 { animation-delay: 0.6s; }
.trace-2 { animation-delay: 0.9s; }
.trace-3 { animation-delay: 0.7s; }
.trace-4 { animation-delay: 1.0s; }
.trace-5 { animation-delay: 0.8s; }
.trace-6 { animation-delay: 1.1s; }
.trace-7 { animation-delay: 0.85s; }
.trace-8 { animation-delay: 1.15s; }

.hero-animate .trace-1 { animation-delay: 0.6s; }
.hero-animate .trace-2 { animation-delay: 0.9s; }
.hero-animate .trace-3 { animation-delay: 0.7s; }
.hero-animate .trace-4 { animation-delay: 1.0s; }
.hero-animate .trace-5 { animation-delay: 0.8s; }
.hero-animate .trace-6 { animation-delay: 1.1s; }
.hero-animate .trace-7 { animation-delay: 0.85s; }
.hero-animate .trace-8 { animation-delay: 1.15s; }

@keyframes drawTrace {
    to { stroke-dashoffset: 0; }
}

.node-pop {
    transform-origin: center;
    transform: scale(0);
    opacity: 0;
}

.hero-animate .node-pop {
    animation: popNode 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.hero-animate .node-1 { animation-delay: 1.2s; }
.hero-animate .node-2 { animation-delay: 1.3s; }
.hero-animate .node-3 { animation-delay: 1.4s; }
.hero-animate .node-4 { animation-delay: 1.5s; }

@keyframes popNode {
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.site-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(3rem, 7vw, 5.5rem);
    letter-spacing: 0.08em;
    color: var(--parchment-light);
    opacity: 0;
    position: relative;
    z-index: 1;
    transition: opacity 0.8s ease;
}

.site-title.visible {
    opacity: 1;
}

.subtitle {
    font-family: 'Lora', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--foxed-page);
    opacity: 0;
    position: relative;
    z-index: 1;
    margin-top: 0.8rem;
    transition: opacity 0.6s ease;
}

.subtitle.visible {
    opacity: 1;
}

/* === Timeline Container === */
.timeline-container {
    position: relative;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 2rem 6rem;
    z-index: 1;
}

.timeline-spine {
    position: absolute;
    left: 50%;
    top: 0;
    width: 4px;
    height: 100%;
    transform: translateX(-50%);
    pointer-events: none;
}

.spine-line {
    stroke-dasharray: 5000;
    stroke-dashoffset: 5000;
    transition: stroke-dashoffset 0.1s linear;
}

/* === Timeline Sections === */
.timeline-section {
    position: relative;
    padding: 4rem 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

/* === Timeline Nodes === */
.timeline-node {
    position: absolute;
    left: 50%;
    top: 4rem;
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    align-items: center;
}

.node-svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.node-svg circle {
    transition: fill 0.2s ease, stroke-width 0.2s ease;
}

.timeline-node:hover .node-svg {
    transform: scale(1.4);
}

.timeline-node:hover .node-svg circle {
    fill: var(--burnished-gold);
}

.connector {
    width: 120px;
    height: 4px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.connector line {
    stroke-dasharray: 120;
    stroke-dashoffset: 120;
    transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.connector.drawn line {
    stroke-dashoffset: 0;
}

.connector-right {
    left: 20px;
}

.connector-left {
    right: 20px;
    left: auto;
    transform: translateY(-50%) scaleX(-1);
}

.timeline-node:hover .connector line {
    stroke-width: 3;
}

/* === Folio Blocks === */
.folio-block {
    position: relative;
    background: var(--aged-vellum);
    padding: 2rem 2.5rem;
    max-width: 380px;
    width: 100%;
    opacity: 0;
}

.folio-block.border-drawn {
    animation: borderDraw 0.8s ease forwards;
}

.folio-block.content-visible {
    opacity: 1;
}

/* Border animation via box-shadow trick — using outline approach */
.folio-block {
    border: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.folio-block.border-drawn {
    border-color: var(--folio-border);
}

.folio-block:hover {
    border-color: var(--garnet-wire);
}

.folio-right {
    margin-left: calc(50% + 80px);
}

.folio-left {
    margin-right: calc(50% + 80px);
    margin-left: auto;
}

.folio-wide {
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 2rem;
}

/* Folio corner fold */
.folio-corner {
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 24px 24px 0;
    border-color: transparent var(--oxblood-noir) transparent transparent;
    z-index: 1;
}

.folio-corner::after {
    content: '';
    position: absolute;
    top: 0;
    right: -24px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 24px 24px;
    border-color: transparent transparent #241c12 transparent;
}

.folio-block:hover .folio-corner::after {
    border-color: transparent transparent #1e1710 transparent;
}

/* === Marginalia === */
.marginalia {
    position: absolute;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--foxed-page);
    white-space: nowrap;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}

.marginalia-left {
    left: -2rem;
    top: 0;
}

.marginalia-right {
    right: -2rem;
    top: 0;
}

/* === Difficulty Sigils === */
.difficulty-sigil {
    width: 12px;
    height: 12px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 0.4rem;
}

/* === Folio Typography === */
.folio-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.3rem, 2.5vw, 1.8rem);
    letter-spacing: 0.03em;
    color: var(--parchment-light);
    margin-bottom: 1rem;
    position: relative;
    display: inline-block;
    cursor: default;
}

.folio-title::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--burnished-gold);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.folio-title:hover::after {
    transform: scaleX(1);
}

.folio-body {
    color: var(--parchment-light);
    margin-bottom: 1rem;
}

.folio-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    color: var(--foxed-page);
    letter-spacing: 0.02em;
}

/* === Proof Section === */
.proof-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 1.5rem;
    position: relative;
}

.proof-statement .folio-body {
    font-weight: 600;
    font-size: 1.05em;
}

.proof-steps {
    position: relative;
    padding-left: 1.5rem;
}

.proof-trace {
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
}

.proof-step {
    margin-bottom: 1.2rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

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

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1.5px solid var(--burnished-gold);
    color: var(--burnished-gold);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
}

.proof-step p {
    font-size: 0.92rem;
    color: var(--parchment-light);
    line-height: 1.65;
}

/* === Lineage Section === */
.lineage-header {
    text-align: center;
    position: relative;
    margin-bottom: 1.5rem;
}

.lineage-header .timeline-node {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    display: inline-flex;
}

.lineage-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.2rem);
    letter-spacing: 0.03em;
    color: var(--parchment-light);
    margin-top: 0.5rem;
}

.section-lineage {
    flex-direction: column;
    align-items: center;
}

.lineage-entries {
    position: relative;
    width: 100%;
}

.lineage-entry {
    position: relative;
    padding: 0.4rem 0;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.lineage-entry.visible {
    opacity: 1;
}

.lineage-node {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.lineage-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--foxed-page);
    letter-spacing: 0.02em;
    margin-left: 0.6rem;
}

.lineage-right {
    justify-content: flex-start;
    margin-left: calc(50% + 20px);
}

.lineage-left {
    justify-content: flex-end;
    flex-direction: row-reverse;
    margin-right: calc(50% + 20px);
}

.lineage-left .lineage-label {
    margin-left: 0;
    margin-right: 0.6rem;
}

/* === Colophon === */
.section-colophon {
    flex-direction: column;
    align-items: center;
    padding-top: 3rem;
}

.section-colophon .timeline-node {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
}

.colophon-flourish {
    margin: 2rem 0;
}

.flourish-svg {
    width: 400px;
    max-width: 100%;
    height: auto;
}

.flourish-trace {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.flourish-trace.drawn {
    stroke-dashoffset: 0;
}

.colophon-text {
    text-align: center;
    max-width: 500px;
}

.colophon-line {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.92rem;
    color: var(--foxed-page);
    margin-bottom: 0.4rem;
}

.colophon-note {
    margin-top: 1rem;
    font-style: italic;
}

.colophon-finis {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--foxed-page);
    margin-top: 2rem;
    font-variant: small-caps;
}

/* === Section Dividers (circuit trace style) === */
.timeline-section + .timeline-section::before {
    content: '';
    display: block;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    .trace,
    .spine-line,
    .connector line,
    .flourish-trace {
        stroke-dashoffset: 0 !important;
        stroke-dasharray: none !important;
        transition: none !important;
        animation: none !important;
    }

    .site-title,
    .subtitle,
    .folio-block,
    .proof-step,
    .lineage-entry,
    .node-pop {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
        animation: none !important;
    }
}

/* === Responsive === */
@media (max-width: 768px) {
    .folio-right,
    .folio-left {
        margin-left: auto;
        margin-right: auto;
        max-width: 85%;
    }

    .timeline-node {
        display: none;
    }

    .marginalia {
        display: none;
    }

    .proof-columns {
        grid-template-columns: 1fr;
    }

    .lineage-right,
    .lineage-left {
        margin-left: auto;
        margin-right: auto;
        justify-content: center;
        flex-direction: row;
    }

    .lineage-left .lineage-label {
        margin-left: 0.6rem;
        margin-right: 0;
    }
}
