/* concurrent.quest -- dark academia, occult library descent */

* { margin: 0; padding: 0; box-sizing: border-box; border-radius: 0 !important; }

:root {
    --abyss: #0D0A07;
    --sanctum: #1A1209;
    --burgundy-shadow: #4A0E0E;
    --burgundy-core: #5B1A1A;
    --dried-blood: #6B1E1E;
    --gold-antique: #B8860B;
    --gold-muted: #9A7B4F;
    --parchment-warm: #D4C4A8;
    --parchment-light: #E8D5B7;
    --candlelight: #F5E6C8;
    --void: #080604;
    --ease: cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

html { scroll-behavior: smooth; }

body {
    background: var(--abyss);
    color: var(--parchment-warm);
    font-family: 'EB Garamond', Georgia, serif;
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    line-height: 1.75;
    overflow-x: hidden;
    min-height: 100vh;
}

@media (min-width: 1024px) {
    body, a {
        cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><path d='M14 2 Q19 5 21 12 L18 14 Q16 7 12 4 Z' stroke='%23B8860B' stroke-width='1' fill='none'/><line x1='17' y1='13' x2='22' y2='20' stroke='%23B8860B' stroke-width='1.2'/></svg>") 2 22, default;
    }
}

/* Grain overlay */
.grain-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.45  0 0 0 0 0.3  0 0 0 0.4 0'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='0.5'/></svg>");
    opacity: 0.04;
    mix-blend-mode: overlay;
}

/* Reveal base state */
.reveal {
    filter: blur(8px);
    opacity: 0;
    transform: translateY(20px);
    transition: filter 1200ms var(--ease), opacity 1200ms var(--ease), transform 1200ms var(--ease);
}
.reveal.visible {
    filter: blur(0);
    opacity: 1;
    transform: translateY(0);
}

/* Candle indicator */
.candle-indicator {
    position: fixed;
    top: 50%;
    right: 2.5vw;
    transform: translateY(-50%);
    width: 30px;
    height: 60vh;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}
.candle-glow {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 80px;
    animation: glowPulse 3s ease-in-out infinite;
}
@keyframes glowPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}
.candle-flame {
    width: 18px;
    height: 28px;
    transform-origin: center bottom;
    animation: flicker 2.4s ease-in-out infinite;
    z-index: 2;
    filter: drop-shadow(0 0 6px rgba(245, 230, 200, 0.7));
}
@keyframes flicker {
    0%, 100% { transform: scale(1, 1) rotate(-1deg); opacity: 1; }
    20% { transform: scale(1.05, 0.95) rotate(2deg); opacity: 0.95; }
    40% { transform: scale(0.95, 1.05) rotate(-2deg); opacity: 1; }
    60% { transform: scale(1.02, 0.98) rotate(1deg); opacity: 0.9; }
    80% { transform: scale(0.98, 1.02) rotate(-1deg); opacity: 1; }
}
.candle-body {
    width: 14px;
    flex: 1;
    background: linear-gradient(to bottom,
        var(--candlelight) 0%,
        var(--parchment-light) 6%,
        var(--parchment-warm) 18%,
        var(--gold-muted) 100%);
    position: relative;
    border-left: 1px solid var(--gold-muted);
    border-right: 1px solid var(--gold-muted);
    transition: height 200ms linear;
    box-shadow: inset 0 4px 6px rgba(0,0,0,0.4);
}
.candle-wax {
    position: absolute;
    top: -2px; left: 0; right: 0;
    height: 6px;
    background: var(--gold-antique);
    opacity: 0.4;
}
.candle-drip {
    position: absolute;
    width: 3px;
    background: var(--candlelight);
    opacity: 0.6;
}
.candle-drip-1 { left: -2px; top: 8px; height: 12px; }
.candle-drip-2 { right: -1px; top: 16px; height: 8px; }

/* Section base */
.chamber {
    min-height: 100vh;
    width: 100%;
    position: relative;
    padding: 8vh 12vw;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, var(--burgundy-shadow) 0%, transparent 40%, var(--abyss) 100%);
    opacity: 0.5;
    pointer-events: none;
}

/* CHAMBER I - Hero */
.chamber-i {
    background: var(--abyss);
    align-items: center;
    text-align: center;
}
.hero-frame {
    position: relative;
    width: min(900px, 90vw);
    padding: 8vh 6vw;
    z-index: 2;
}
.ornament-corner {
    position: absolute;
    width: 100px;
    height: 100px;
}
.ornament-tl { top: 0; left: 0; }
.ornament-tr { top: 0; right: 0; }
.ornament-bl { bottom: 0; left: 0; }
.ornament-br { bottom: 0; right: 0; }
.ornament-flourish {
    width: min(400px, 70%);
    height: 30px;
    margin: 2.5rem auto;
    display: block;
}
.hero-pretitle {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--gold-muted);
    margin-bottom: 2.5rem;
}
.hero-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(3rem, 8vw, 6.5rem);
    letter-spacing: 0.12em;
    text-transform: lowercase;
    font-variant: small-caps;
    color: var(--gold-antique);
    text-shadow: 0 0 40px rgba(184, 134, 11, 0.3);
    line-height: 1;
}
.hero-dot { color: var(--dried-blood); }
.hero-epigraph {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--parchment-light);
    max-width: 60ch;
    margin: 0 auto;
}
.hero-attribution {
    margin-top: 1.5rem;
    font-family: 'Source Code Pro', monospace;
    font-size: 0.8rem;
    color: var(--gold-muted);
    letter-spacing: 0.1em;
}
.scroll-hint {
    position: absolute;
    bottom: 4vh;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Source Code Pro', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--gold-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.scroll-hint svg { width: 12px; height: 40px; }

/* CHAMBER II - Diagonal split */
.chamber-ii {
    padding: 0;
    overflow: hidden;
    position: relative;
    background: var(--abyss);
}
.diagonal-burgundy {
    position: absolute;
    inset: 0;
    background: var(--burgundy-core);
    clip-path: polygon(0 0, 100% 0, 0 100%);
    padding: 10vh 8vw 4vh 12vw;
    display: flex;
    align-items: flex-start;
    overflow: hidden;
}
.diagonal-parchment {
    position: absolute;
    inset: 0;
    background: var(--parchment-light);
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 4vh 8vw 10vh 12vw;
}
.thesis-text {
    max-width: 50ch;
    color: var(--parchment-light);
}
.thesis-text h2 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3rem);
    color: var(--candlelight);
    margin-bottom: 2rem;
    letter-spacing: 0.04em;
}
.thesis-text .chamber-sub {
    font-style: italic;
    font-weight: 500;
    color: var(--parchment-warm);
    font-size: 0.7em;
}
.thesis-text p { margin-bottom: 1.5rem; }
.thesis-text .marginalia {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.85rem;
    opacity: 0.6;
    color: var(--candlelight);
    margin-top: 3rem;
}
.engraving-gears {
    width: min(500px, 50vw);
    height: auto;
    max-height: 70vh;
}

/* Drop caps */
.dropcap {
    font-family: 'Cinzel Decorative', serif;
    font-weight: 700;
    font-size: 4em;
    line-height: 0.8;
    float: left;
    margin: 0.1em 0.3em 0 0;
    color: var(--dried-blood);
}
.diagonal-burgundy .dropcap { color: var(--candlelight); }
.dropcap-small {
    font-family: 'Cinzel Decorative', serif;
    font-weight: 700;
    font-size: 2.5em;
    line-height: 0.9;
    float: left;
    margin: 0.05em 0.2em 0 0;
    color: var(--dried-blood);
}

/* Section dividers */
.section-divider {
    width: 100%;
    padding: 4vh 12vw;
    background: var(--abyss);
    text-align: center;
}
.section-divider svg {
    width: min(600px, 80%);
    height: 40px;
}

/* CHAMBER III - Stacks */
.chamber-iii {
    background: var(--abyss);
    padding: 10vh 8vw;
}
.chamber-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3rem);
    color: var(--parchment-light);
    text-align: center;
    margin-bottom: 1rem;
    letter-spacing: 0.04em;
}
.chamber-sub {
    font-style: italic;
    font-weight: 500;
    color: var(--gold-muted);
    font-size: 0.7em;
}
.chamber-intro {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    text-align: center;
    color: var(--parchment-warm);
    max-width: 60ch;
    margin: 0 auto 6vh;
    font-size: 1.15rem;
}
.stacks-timeline {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 4vh 0;
}
.timeline-line {
    position: absolute;
    top: 0; bottom: 0;
    left: 50%;
    width: 2px;
    background: var(--gold-antique);
    transform: translateX(-50%);
    opacity: 0.6;
}
.stack-entry {
    width: 50%;
    padding: 2vh 4vw;
    position: relative;
}
.stack-left {
    margin-right: auto;
    text-align: right;
    padding-right: 4vw;
}
.stack-right {
    margin-left: 50%;
    text-align: left;
    padding-left: 4vw;
}
.stack-entry::before {
    content: '';
    position: absolute;
    top: 4vh;
    width: 12px;
    height: 12px;
    background: var(--abyss);
    border: 1px solid var(--gold-antique);
    transform: rotate(45deg);
}
.stack-left::before { right: -6px; }
.stack-right::before { left: -6px; }
.stack-card {
    background: var(--sanctum);
    border: 1px solid var(--gold-muted);
    padding: 2.5rem 2rem;
    text-align: left;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5), inset 0 0 40px rgba(74, 14, 14, 0.15);
    position: relative;
}
.stack-number {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--gold-antique);
    font-weight: 700;
    display: block;
    margin-bottom: 0.5rem;
}
.stack-card h3 {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-weight: 600;
    font-size: 1.6rem;
    color: var(--parchment-light);
    margin-bottom: 1rem;
}
.stack-card p { margin-bottom: 1rem; }
.entry-meta {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.75rem;
    color: var(--gold-muted);
    margin-top: 1rem;
    letter-spacing: 0.1em;
}
.mono {
    font-family: 'Source Code Pro', monospace;
    background: rgba(184, 134, 11, 0.08);
    color: var(--gold-muted);
    padding: 0 0.3em;
    font-size: 0.9em;
}

/* CHAMBER IV - Concurrence */
.chamber-iv {
    background: var(--abyss);
    padding: 10vh 6vw;
    overflow: hidden;
}
.concurrence-grid {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6vw;
    max-width: 1300px;
    margin: 4vh auto 0;
}
.thread-column {
    position: relative;
    will-change: transform;
}
.thread-label {
    position: sticky;
    top: 2rem;
    margin-bottom: 1.5rem;
    color: var(--gold-antique);
    border-bottom: 1px solid var(--gold-muted);
    padding-bottom: 0.5rem;
    font-size: 0.85rem;
}
.thread-column p {
    margin-bottom: 2rem;
    color: var(--parchment-warm);
}
.thread-column p[data-link] {
    border-left: 1px solid var(--dried-blood);
    padding-left: 1.5rem;
    transition: border-color 600ms var(--ease);
}
.thread-column p[data-link].linked {
    border-left-color: var(--gold-antique);
    color: var(--parchment-light);
}
.thread-right p[data-link] {
    border-left: none;
    border-right: 1px solid var(--dried-blood);
    padding-left: 0;
    padding-right: 1.5rem;
    text-align: right;
}
.thread-right p[data-link].linked {
    border-right-color: var(--gold-antique);
    color: var(--parchment-light);
}
.concurrence-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.concur-line {
    opacity: 0;
    transition: opacity 800ms var(--ease);
}
.concur-line.active { opacity: 0.7; }

.hourglass-wrap {
    text-align: center;
    margin-top: 8vh;
}
.engraving-hourglass {
    width: min(180px, 30vw);
    height: auto;
    animation: gentleSway 8s ease-in-out infinite;
}
@keyframes gentleSway {
    0%, 100% { transform: rotate(-1deg); }
    50% { transform: rotate(1deg); }
}

/* CHAMBER V - Archive masonry */
.chamber-v {
    background: var(--abyss);
    padding: 10vh 8vw;
}
.archive-masonry {
    columns: 3;
    column-gap: 2.5rem;
    max-width: 1300px;
    margin: 4vh auto 0;
}
@media (max-width: 1024px) { .archive-masonry { columns: 2; } }
@media (max-width: 640px) { .archive-masonry { columns: 1; } }
.manuscript-card {
    background: var(--sanctum);
    border: 1px solid var(--gold-antique);
    padding: 2rem 1.8rem;
    margin-bottom: 2.5rem;
    break-inside: avoid;
    box-shadow: 0 6px 30px rgba(0,0,0,0.6), 0 0 0 1px rgba(184, 134, 11, 0.1);
    position: relative;
    transition: transform 600ms var(--ease), box-shadow 600ms var(--ease);
}
.manuscript-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.8), 0 0 0 1px rgba(184, 134, 11, 0.3);
}
.manuscript-card h3 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-style: italic;
    font-size: 1.4rem;
    color: var(--parchment-light);
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--gold-muted);
    padding-bottom: 0.5rem;
}
.manuscript-card p { margin-bottom: 0.8rem; font-size: 1rem; }
.manuscript-card blockquote {
    border-left: 2px solid var(--dried-blood);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--parchment-light);
}
.manuscript-card blockquote p { font-family: 'Cormorant Garamond', serif; font-size: 1.1rem; }
.card-meta {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.75rem;
    color: var(--gold-muted);
    margin-top: 1rem;
    letter-spacing: 0.05em;
}
.codeblock {
    background: var(--void);
    border: 1px solid var(--burgundy-shadow);
    padding: 1rem;
    font-family: 'Source Code Pro', monospace;
    font-size: 0.85rem;
    color: var(--gold-muted);
    overflow-x: auto;
    margin: 0.5rem 0;
    line-height: 1.5;
}
.codeblock code { color: var(--parchment-warm); }
.manuscript-card svg { width: 100%; height: auto; margin: 0.5rem 0; }

/* CHAMBER VI - Sanctum */
.chamber-vi {
    background: var(--void);
    min-height: 100vh;
    align-items: center;
    text-align: center;
    padding: 12vh 12vw;
    position: relative;
    overflow: hidden;
}
.sanctum-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 0%, var(--void) 70%);
    pointer-events: none;
}
.sanctum-content {
    position: relative;
    z-index: 2;
    max-width: 800px;
    margin: 0 auto;
}
.sanctum-text {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    line-height: 1.8;
    color: var(--parchment-light);
    margin-bottom: 4rem;
}
.sanctum-text .word {
    opacity: 0;
    filter: blur(4px);
    display: inline-block;
    transition: opacity 800ms var(--ease), filter 800ms var(--ease);
}
.sanctum-text .word.visible {
    opacity: 1;
    filter: blur(0);
}
.sanctum-flourish {
    width: min(400px, 80%);
    height: 100px;
    margin: 0 auto 3rem;
    display: block;
}
.engraving-quill {
    width: min(300px, 60%);
    height: auto;
    margin: 0 auto 3rem;
    display: block;
}
.sanctum-signoff {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.8rem;
    color: var(--gold-muted);
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-top: 2rem;
}
.ember {
    color: var(--dried-blood);
    animation: emberPulse 2.5s ease-in-out infinite;
}
@keyframes emberPulse {
    0%, 100% { color: var(--dried-blood); text-shadow: 0 0 4px var(--dried-blood); }
    50% { color: var(--gold-antique); text-shadow: 0 0 12px var(--gold-antique); }
}

/* SVG path-draw setup */
.ornament path,
.ornament circle,
.engraving-gears path,
.engraving-gears circle,
.engraving-gears line,
.engraving-hourglass path,
.engraving-hourglass line,
.engraving-quill path,
.engraving-quill line,
.section-divider path,
.section-divider circle,
.sanctum-flourish path,
.sanctum-flourish circle {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1600ms var(--ease);
}
.draw-active path,
.draw-active circle,
.draw-active line {
    stroke-dashoffset: 0;
}

.gear-large { transform-origin: 160px 200px; animation: spinSlow 30s linear infinite; }
.gear-small { transform-origin: 280px 140px; animation: spinReverse 22s linear infinite; }
.gear-third { transform-origin: 280px 280px; animation: spinSlow 18s linear infinite; }
@keyframes spinSlow { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes spinReverse { from { transform: rotate(0); } to { transform: rotate(-360deg); } }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .reveal { filter: none; opacity: 1; transform: none; transition: none; }
    .sanctum-text .word { opacity: 1; filter: none; }
    .candle-flame, .ember, .gear-large, .gear-small, .gear-third, .candle-glow, .engraving-hourglass { animation: none; }
    .ornament path, .ornament circle, .engraving-gears path, .engraving-gears circle,
    .engraving-gears line, .engraving-hourglass path, .engraving-hourglass line,
    .engraving-quill path, .engraving-quill line, .section-divider path,
    .section-divider circle, .sanctum-flourish path, .sanctum-flourish circle {
        stroke-dasharray: none;
        stroke-dashoffset: 0;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .chamber { padding: 6vh 6vw; }
    .diagonal-burgundy, .diagonal-parchment { padding: 6vh 6vw; }
    .stacks-timeline .timeline-line { left: 16px; }
    .stack-entry { width: 100%; padding-left: 40px; padding-right: 0; text-align: left; margin-left: 0 !important; }
    .stack-entry::before { left: 10px !important; right: auto !important; }
    .concurrence-grid { grid-template-columns: 1fr; gap: 4rem; }
    .candle-indicator { right: 1vw; width: 20px; height: 40vh; }
}
