/* ============================================
   historic.quest — Archival Nostalgia Stylesheet
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --aged-parchment: #f5e6c8;
    --warm-cream: #faf0dc;
    --dark-walnut: #3d2b1f;
    --coffee-brown: #4a3728;
    --burnt-sienna: #a0522d;
    --amber-glow: #d4872c;
    --dusty-rose: #b56b6b;
    --sepia-mist: #c8a882;
    --tab-paper: #d4b896;
    --colophon-bg: #e8d4b0;
    --dark-sienna: #5c4033;

    --font-display: 'Bitter', 'Georgia', serif;
    --font-body: 'Lora', 'Times New Roman', serif;
    --font-mono: 'Special Elite', 'Courier New', monospace;
}

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

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--aged-parchment);
    color: var(--coffee-brown);
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    overflow-x: hidden;
}

/* --- Index Tab Navigation --- */
#index-tabs {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#index-tabs.visible {
    opacity: 1;
}

.index-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 80px;
    background-color: var(--tab-paper);
    border-left: 2px solid var(--burnt-sienna);
    border-top: 1px solid var(--sepia-mist);
    border-bottom: 1px solid var(--sepia-mist);
    text-decoration: none;
    color: var(--dark-walnut);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    transition: width 0.3s ease, background-color 0.3s ease;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.index-tab .tab-full {
    display: none;
    writing-mode: vertical-rl;
    white-space: nowrap;
    font-size: 0.65rem;
}

.index-tab:hover {
    width: 60px;
    background-color: var(--warm-cream);
}

.index-tab:hover .tab-short {
    display: none;
}

.index-tab:hover .tab-full {
    display: block;
}

.index-tab.active {
    background-color: var(--warm-cream);
    border-left-color: var(--amber-glow);
    color: var(--amber-glow);
}

/* --- Page Indicator --- */
#page-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99;
    background-color: var(--tab-paper);
    border-top: 2px solid var(--burnt-sienna);
    padding: 6px 12px;
    opacity: 0;
    transition: opacity 0.4s ease;
}

#page-indicator.visible {
    opacity: 1;
}

#page-text {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--sepia-mist);
    letter-spacing: 0.06em;
}

/* --- Document Stack / Main Container --- */
#document-stack {
    position: relative;
}

/* --- Document Page (Section) --- */
.document-page {
    position: relative;
    min-height: 85vh;
    scroll-snap-align: start;
    overflow: hidden;
    border: 1px solid var(--sepia-mist);
    display: flex;
    align-items: center;
    justify-content: center;
}

.document-page:first-child {
    box-shadow: 0 2px 8px rgba(60, 40, 20, 0.08);
}

.document-page:nth-child(2) {
    box-shadow: 0 2px 6px rgba(60, 40, 20, 0.06);
}

.document-page:nth-child(3) {
    box-shadow: 0 2px 4px rgba(60, 40, 20, 0.04);
}

/* --- Paper Texture Layers --- */
.page-paper-texture {
    position: absolute;
    inset: 0;
    background-color: var(--aged-parchment);
    filter: url(#paperNoise);
    z-index: 0;
}

.page-paper-texture.alt {
    background-color: var(--warm-cream);
    filter: url(#paperNoiseAlt);
}

.page-paper-texture.colophon-bg {
    background-color: var(--colophon-bg);
    filter: url(#paperNoise);
}

.page-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 50%, transparent 60%, rgba(168, 136, 98, 0.12) 100%);
    z-index: 1;
    pointer-events: none;
}

/* --- Page Content --- */
.page-content {
    position: relative;
    z-index: 2;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: clamp(3rem, 6vh, 5rem) clamp(1.5rem, 4vw, 3rem);
}

/* Off-center positioning for wide viewports */
@media (min-width: 1200px) {
    .page-content {
        margin-left: 30vw;
        margin-right: 15vw;
    }
}

/* --- Hero Section --- */
#hero {
    min-height: 100vh;
}

.hero-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

/* Typewriter Rule in Hero */
#hero-rule {
    font-family: var(--font-mono);
    color: var(--burnt-sienna);
    font-size: 1rem;
    letter-spacing: 0.06em;
    overflow: hidden;
    white-space: nowrap;
    width: 0;
    margin-bottom: 2rem;
    height: 1.2em;
    line-height: 1.2em;
}

#hero-rule.animating {
    width: 100%;
    max-width: 400px;
}

/* Hero Title */
.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.2rem, 5.5vw, 4.5rem);
    color: var(--dark-walnut);
    letter-spacing: 0.02em;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
    margin-bottom: 1.5rem;
}

.hero-title.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Hero Subtitle */
.hero-subtitle {
    font-family: var(--font-mono);
    font-size: clamp(0.85rem, 1.4vw, 1rem);
    color: rgba(92, 64, 51, 0.85);
    letter-spacing: 0.06em;
    min-height: 1.5em;
}

#subtitle-text {
    /* Text typed by JS */
}

.typewriter-cursor {
    display: inline-block;
    width: 1px;
    height: 1em;
    background-color: var(--burnt-sienna);
    margin-left: 2px;
    animation: cursorBlink 530ms steps(1) infinite;
    vertical-align: text-bottom;
    font-size: 0;
    overflow: hidden;
}

.typewriter-cursor.fade-out {
    animation: cursorFadeOut 400ms ease forwards;
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes cursorFadeOut {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* --- Section Headings --- */
.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    color: var(--dark-walnut);
    letter-spacing: 0.01em;
    margin-bottom: 0.5rem;
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.section-heading.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Heading Rule */
.heading-rule {
    width: 0;
    height: 2px;
    background-color: var(--burnt-sienna);
    margin-bottom: 2rem;
    transition: width 0.4s ease-out 0.2s;
}

.heading-rule.visible {
    width: 60px;
}

/* --- Body Text --- */
.body-text {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    color: var(--coffee-brown);
    margin-bottom: 1.5em;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.body-text.visible {
    opacity: 1;
    transform: translateY(0);
}

.body-text strong {
    font-weight: 700;
    color: var(--dark-walnut);
}

.body-text em {
    font-style: italic;
}

/* --- Typewriter Text --- */
.typewriter-text {
    font-family: var(--font-mono);
    font-size: clamp(0.85rem, 1.4vw, 1rem);
    letter-spacing: 0.06em;
    color: rgba(92, 64, 51, 0.85);
}

/* --- Pull Quotes --- */
.pull-quote {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(1.05rem, 1.9vw, 1.2rem);
    line-height: 1.7;
    color: var(--dusty-rose);
    border-left: 3px solid var(--dusty-rose);
    padding: 1em 0 1em 1.5em;
    margin: 2em 0;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.pull-quote.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Strikethrough Correction --- */
.strikethrough-correction {
    position: relative;
    display: inline;
}

.strikethrough-correction .struck {
    text-decoration: line-through;
    text-decoration-color: rgba(74, 55, 40, 0.4);
    opacity: 0.6;
}

.strikethrough-correction .correction {
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--burnt-sienna);
    position: relative;
    top: -0.15em;
    margin-left: 0.3em;
}

/* --- Ink Blot --- */
.ink-blot {
    position: absolute;
    top: 12%;
    left: 5%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--burnt-sienna);
    opacity: 0.06;
    z-index: 3;
}

/* --- Margin Annotations --- */
.margin-annotation {
    display: none;
    position: absolute;
    left: -180px;
    top: 20%;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--dusty-rose);
    letter-spacing: 0.04em;
    width: 160px;
    z-index: 3;
    line-height: 1.4;
}

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

/* --- Section Date --- */
.section-date {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: rgba(92, 64, 51, 0.6);
    letter-spacing: 0.06em;
    margin-top: 2rem;
    text-align: right;
}

/* --- Filed Stamp --- */
.filed-stamp {
    position: absolute;
    bottom: clamp(1.5rem, 3vh, 3rem);
    right: clamp(1.5rem, 4vw, 4rem);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--burnt-sienna);
    opacity: 0.3;
    border: 1.5px solid var(--burnt-sienna);
    border-radius: 3px;
    padding: 4px 12px;
    z-index: 3;
}

/* --- Section Dividers --- */
.section-divider {
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background-color: var(--aged-parchment);
    position: relative;
}

.divider-rule {
    font-family: var(--font-mono);
    color: var(--burnt-sienna);
    font-size: 0.8rem;
    letter-spacing: 0.15em;
    opacity: 0.5;
    line-height: 1;
}

.divider-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

/* --- Corner Ornaments --- */
.corner-ornament {
    position: absolute;
    z-index: 3;
    pointer-events: none;
}

.corner-top-left {
    top: clamp(1rem, 2vh, 2rem);
    left: clamp(1rem, 2vw, 2rem);
}

.corner-bottom-right {
    bottom: clamp(1rem, 2vh, 2rem);
    right: clamp(1rem, 2vw, 2rem);
}

/* --- Interactive Links --- */
.page-content a {
    color: var(--burnt-sienna);
    text-decoration: none;
    position: relative;
    transition: color 0.3s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='4' viewBox='0 0 100 4'%3E%3Cpath d='M0 3 Q 5 1, 10 3 Q 15 5, 20 3 Q 25 1, 30 3 Q 35 5, 40 3 Q 45 1, 50 3 Q 55 5, 60 3 Q 65 1, 70 3 Q 75 5, 80 3 Q 85 1, 90 3 Q 95 5, 100 3' fill='none' stroke='%23d4872c' stroke-width='1'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: bottom left;
    background-size: 0% 4px;
    padding-bottom: 2px;
    transition: background-size 0.3s ease, color 0.2s ease;
}

.page-content a:hover {
    color: var(--amber-glow);
    background-size: 100% 4px;
}

/* --- Colophon --- */
.colophon-page {
    min-height: 70vh;
}

.colophon-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.colophon-border {
    border: 1px solid var(--sepia-mist);
    padding: 3rem 2rem;
    position: relative;
    max-width: 480px;
    width: 100%;
}

.colophon-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.colophon-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--dark-walnut);
    letter-spacing: 0.02em;
}

.colophon-rule {
    width: 40px;
    height: 2px;
    background-color: var(--burnt-sienna);
    opacity: 0.6;
}

.colophon-text {
    font-family: var(--font-display);
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--dark-walnut);
    letter-spacing: 0.02em;
}

.colophon-date {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: rgba(92, 64, 51, 0.85);
    letter-spacing: 0.06em;
}

.colophon-credit {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: rgba(92, 64, 51, 0.6);
    letter-spacing: 0.04em;
    line-height: 1.6;
}

.colophon-ornament {
    margin-top: 1rem;
    opacity: 0.4;
}

/* --- Retro-Pattern Decorative Borders for Dividers --- */
.section-divider::before,
.section-divider::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: min(400px, 80%);
    height: 1px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='2' viewBox='0 0 20 2'%3E%3Ccircle cx='2' cy='1' r='0.8' fill='%23c8a882'/%3E%3Cline x1='5' y1='1' x2='15' y2='1' stroke='%23c8a882' stroke-width='0.5'/%3E%3Ccircle cx='18' cy='1' r='0.8' fill='%23c8a882'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-size: 20px 2px;
    opacity: 0.5;
}

.section-divider::before {
    top: 0;
}

.section-divider::after {
    bottom: 0;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    #index-tabs {
        display: none;
    }

    #page-indicator {
        right: 10px;
        bottom: 10px;
    }

    .filed-stamp {
        bottom: 1rem;
        right: 1rem;
        font-size: 0.6rem;
    }

    .corner-ornament {
        display: none;
    }
}

/* --- Animation Stagger Delays (applied via JS) --- */
.body-text:nth-child(4) { transition-delay: 0ms; }
.body-text:nth-child(5) { transition-delay: 150ms; }
.body-text:nth-child(6) { transition-delay: 300ms; }
.body-text:nth-child(7) { transition-delay: 450ms; }
.body-text:nth-child(8) { transition-delay: 600ms; }
.pull-quote { transition-delay: 300ms; }

/* --- Ensure smooth transitions don't jank --- */
.animate-in {
    will-change: opacity, transform;
}

/* --- Selection styling --- */
::selection {
    background-color: rgba(200, 168, 130, 0.4);
    color: var(--dark-walnut);
}
