/* prototype.quest -- Alchemical Grimoire */
:root {
    --vellum: #F2E8D5;
    --foxed: #E6D5B8;
    --sepia-black: #2C2416;
    --dried-blood: #4A0E0E;
    --walnut-ink: #3B2F20;
    --iron-gall: #6B3A2A;
    --burnished-gold: #C9A84C;
    --faded-iron: #8A7E6B;
    --leather-spine: #1A1409;
}
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-size: 18px;
    line-height: 1.75;
    color: var(--sepia-black);
    background: linear-gradient(170deg, #F2E8D5 0%, #E6D5B8 40%, #F2E8D5 60%, #E8D4B0 100%);
    min-height: 100vh;
    overflow-x: hidden;
    cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M20 2C18 4 14 8 10 14C8 18 6 20 4 22L5 20C6 18 7 16 8 14L6 16C8 12 12 6 20 2Z" fill="%232C2416" stroke="%23C9A84C" stroke-width="0.5"/></svg>') 2 22, auto;
}

.parchment-bg {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 15% 25%, #C4A87A 0%, transparent 8px),
        radial-gradient(circle at 72% 18%, #C4A87A 0%, transparent 12px),
        radial-gradient(circle at 45% 62%, #C4A87A 0%, transparent 10px),
        radial-gradient(circle at 88% 75%, #C4A87A 0%, transparent 14px),
        radial-gradient(circle at 30% 85%, #C4A87A 0%, transparent 9px);
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
    filter: url(#paper-grain);
}

.scroll-content {
    position: relative;
    z-index: 1;
    max-width: 680px;
    margin: 0 auto;
    padding: 100vh 24px 120px;
}

/* Intro line animation */
.intro-line {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 680px;
    max-width: 90vw;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.5s;
    pointer-events: none;
}
.intro-line.active { opacity: 1; }
.intro-line.fade-out { opacity: 0; }

.draw-line {
    stroke-dasharray: 680;
    stroke-dashoffset: 680;
    animation: none;
}
.intro-line.active .draw-line {
    animation: draw-horizontal 1s ease-out forwards;
    animation-delay: 1.5s;
}

@keyframes draw-horizontal {
    to { stroke-dashoffset: 0; }
}

/* Folios */
.folio {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
    margin-bottom: 0;
}
.folio.visible {
    opacity: 1;
    transform: translateY(0);
}

.folio-title {
    font-family: 'Cinzel', serif;
    font-weight: 600;
    font-size: 32px;
    letter-spacing: 0.06em;
    color: var(--walnut-ink);
    margin-bottom: 16px;
}

.body-text {
    color: var(--sepia-black);
    font-weight: 400;
    margin-bottom: 16px;
}
.body-text:last-child { margin-bottom: 0; }

/* Illuminated initial */
.illuminated-wrap {
    display: flex;
    gap: 0;
    align-items: flex-start;
}
.illuminated-cap {
    width: 200px;
    height: 200px;
    flex-shrink: 0;
    float: left;
    margin-right: 16px;
    margin-bottom: 8px;
}

.vine-draw {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}
.folio.visible .vine-draw {
    animation: draw-vine 2s ease-out forwards;
}
@keyframes draw-vine {
    to { stroke-dashoffset: 0; }
}

.opening-text {
    padding-top: 20px;
}
.text-line {
    display: block;
    opacity: 0;
}
.folio.visible .text-line {
    animation: line-fade 0.6s ease-out forwards;
}
.folio.visible .text-line:nth-child(1) { animation-delay: 0.3s; }
.folio.visible .text-line:nth-child(2) { animation-delay: 0.4s; }
.folio.visible .text-line:nth-child(3) { animation-delay: 0.5s; }
.folio.visible .text-line:nth-child(4) { animation-delay: 0.6s; }
.folio.visible .text-line:nth-child(5) { animation-delay: 0.7s; }

@keyframes line-fade {
    to { opacity: 1; }
}

/* Knotwork dividers */
.knotwork-divider {
    display: flex;
    justify-content: center;
    padding: 60px 0;
}
.knotwork-divider svg {
    width: 400px;
    max-width: 100%;
    height: 24px;
}
.knot-draw {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
}
.knotwork-divider.visible .knot-draw {
    animation: draw-knot 1.2s ease-out forwards;
}
@keyframes draw-knot {
    to { stroke-dashoffset: 0; }
}

/* Diagram folio */
.folio-diagram { text-align: center; }
.diagram-svg {
    width: 300px;
    height: 300px;
    margin: 0 auto 16px;
    display: block;
}
.diagram-draw {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
}
.folio.visible .diagram-draw {
    animation: draw-diagram 2s ease-out forwards;
}
@keyframes draw-diagram {
    to { stroke-dashoffset: 0; }
}

.diagram-caption {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 16px;
    color: var(--iron-gall);
}

/* Marginal note folio */
.folio-marginal {
    display: flex;
    gap: 40px;
    align-items: flex-start;
}
.folio-body { flex: 1; }
.marginal-note {
    width: 200px;
    flex-shrink: 0;
    font-family: 'Caveat', cursive;
    font-size: 18px;
    color: var(--iron-gall);
    transform: rotate(-1deg);
    padding-top: 40px;
    line-height: 1.5;
}

/* Marginalia illustrations */
.marginalia {
    position: fixed;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s;
}
.marginalia.drawn { opacity: 1; }
.marginalia-left { left: calc((100vw - 680px) / 2 - 120px); }
.marginalia-right { right: calc((100vw - 680px) / 2 - 120px); }
.marginalia-1 { top: 20%; width: 80px; }
.marginalia-2 { top: 40%; width: 80px; }
.marginalia-3 { top: 55%; width: 60px; }
.marginalia-4 { top: 72%; width: 60px; }

.margin-draw {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}
.marginalia.drawn .margin-draw {
    animation: draw-margin 2.5s ease-out forwards;
}
@keyframes draw-margin {
    to { stroke-dashoffset: 0; }
}

/* Alchemical seal */
.folio-seal {
    display: flex;
    justify-content: center;
    padding: 60px 0;
}
.alchemical-seal {
    width: 300px;
    height: 300px;
}
.seal-ring, .seal-star {
    stroke-dasharray: 900;
    stroke-dashoffset: 900;
}
.folio.visible .seal-ring-1 {
    animation: draw-seal 1s ease-out forwards;
}
.folio.visible .seal-ring-2 {
    animation: draw-seal 1s ease-out 0.5s forwards;
}
.folio.visible .seal-ring-3 {
    animation: draw-seal 1s ease-out 1s forwards;
}
.folio.visible .seal-star {
    animation: draw-seal 1s ease-out 1.5s forwards;
}
.folio.visible .seal-glyph {
    animation: glyph-appear 1s ease-out 2s forwards;
}
@keyframes draw-seal {
    to { stroke-dashoffset: 0; }
}
@keyframes glyph-appear {
    to { opacity: 1; }
}

.folio-seal.visible .alchemical-seal {
    animation: seal-pulse 4s ease-in-out 3s infinite;
}
@keyframes seal-pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.02); opacity: 1; }
}

/* Quill navigation */
.quill-nav {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--vellum);
    border: 1px solid var(--faded-iron);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    transition: transform 0.3s, box-shadow 0.3s;
}
.quill-nav:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.quill-nav svg {
    width: 24px;
    height: 24px;
}

/* Navigation overlay */
.nav-overlay {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100vh;
    background: rgba(26, 20, 9, 0.92);
    z-index: 200;
    transition: right 0.4s ease-out;
    display: flex;
    align-items: center;
}
.nav-overlay.open { right: 0; }

.nav-overlay-content {
    padding: 40px 32px;
    width: 100%;
}
.nav-close {
    display: block;
    font-size: 28px;
    color: var(--burnished-gold);
    cursor: pointer;
    margin-bottom: 32px;
    text-align: right;
}
.nav-link {
    display: block;
    font-family: 'Caveat', cursive;
    font-size: 20px;
    color: var(--burnished-gold);
    text-decoration: none;
    padding: 12px 0;
    cursor: pointer;
    transition: color 0.3s;
}
.nav-link:hover { color: var(--vellum); }

/* Link styling */
a {
    color: var(--sepia-black);
    text-decoration: underline dashed var(--burnished-gold);
    transition: color 0.3s, text-decoration 0.3s;
}
a:hover {
    color: var(--dried-blood);
    text-decoration: underline solid var(--burnished-gold);
}

@media (max-width: 1100px) {
    .marginalia { display: none; }
}

@media (max-width: 768px) {
    .scroll-content { padding-top: 60vh; }
    .illuminated-cap { width: 120px; height: 120px; }
    .folio-title { font-size: 24px; }
    .folio-marginal { flex-direction: column; gap: 16px; }
    .marginal-note { width: 100%; }
    .diagram-svg { width: 200px; height: 200px; }
    .alchemical-seal { width: 200px; height: 200px; }
}
