/* ============================================================
   historic.day — Victorian Cartographic Reading Room
   ============================================================ */

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

:root {
    --aged-vellum: #F5ECD7;
    --deep-archive: #1A1209;
    --burnt-umber: #2C1810;
    --oxblood: #6B1D1D;
    --manuscript-gold: #B8944F;
    --cocoa-dust: #5C3D2E;
    --foxed-cream: #EDE0C8;
    --verdigris: #4A7C6F;
    --iron-gall: #1E1510;
    --deep-sepia: #3A2A1F;
    --seal-dark: #4A1515;
    --aged-parchment: #E8D5B0;
    --cool-parchment: #F0E8D0;
    --crisp-cream: #FAF5EA;
    --foxing-spot: #C4A87A;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--deep-archive);
    color: var(--deep-sepia);
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-size: 17px;
    line-height: 1.7;
    font-weight: 400;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Foxing Overlay --- */
#foxing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 1.5s ease;
    mix-blend-mode: multiply;
    background-image:
        radial-gradient(ellipse at 10% 20%, rgba(196,168,122,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 15%, rgba(196,168,122,0.05) 0%, transparent 40%),
        radial-gradient(ellipse at 90% 80%, rgba(196,168,122,0.07) 0%, transparent 45%),
        radial-gradient(ellipse at 5% 90%, rgba(196,168,122,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(196,168,122,0.02) 0%, transparent 60%),
        radial-gradient(ellipse at 30% 70%, rgba(196,168,122,0.04) 0%, transparent 35%),
        radial-gradient(ellipse at 70% 40%, rgba(196,168,122,0.03) 0%, transparent 30%),
        radial-gradient(circle at 15% 55%, rgba(196,168,122,0.05) 0%, transparent 20%),
        radial-gradient(circle at 60% 10%, rgba(196,168,122,0.04) 0%, transparent 25%),
        radial-gradient(circle at 80% 60%, rgba(196,168,122,0.05) 0%, transparent 22%);
}

#foxing-overlay.visible {
    opacity: 1;
}

/* Dark section foxing mode */
body.dark-foxing #foxing-overlay {
    mix-blend-mode: soft-light;
    background-image:
        radial-gradient(ellipse at 10% 20%, rgba(232,213,176,0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 15%, rgba(232,213,176,0.02) 0%, transparent 40%),
        radial-gradient(ellipse at 90% 80%, rgba(232,213,176,0.04) 0%, transparent 45%),
        radial-gradient(ellipse at 5% 90%, rgba(232,213,176,0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(232,213,176,0.01) 0%, transparent 60%);
}

/* --- Background Compass --- */
#bg-compass {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    opacity: 0;
    z-index: 0;
    pointer-events: none;
    animation: compass-spin 120s linear infinite;
    transition: opacity 2s ease;
}

#bg-compass.visible {
    opacity: 0.04;
}

@keyframes compass-spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- Era Indicator --- */
#era-indicator {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    z-index: 500;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

#era-compass-mini {
    position: absolute;
    top: 0;
    left: 0;
    width: 64px;
    height: 64px;
    animation: compass-spin 120s linear infinite;
}

#era-compass-mini svg {
    width: 100%;
    height: 100%;
}

#era-numeral {
    position: relative;
    z-index: 2;
    font-family: 'IM Fell English', serif;
    font-size: 15px;
    color: var(--manuscript-gold);
    letter-spacing: 0.05em;
    text-align: center;
}

/* --- Timeline Overlay --- */
#timeline-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    background: rgba(26,18,9,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    opacity: 1;
    visibility: visible;
}

#timeline-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#timeline-overlay-inner {
    background: var(--aged-vellum);
    border: 1px solid var(--manuscript-gold);
    padding: 48px 56px;
    max-width: 420px;
    width: 90%;
    position: relative;
}

.timeline-overlay-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 1.4rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--burnt-umber);
    margin-bottom: 28px;
    text-align: center;
}

#timeline-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--cocoa-dust);
    cursor: pointer;
    font-family: serif;
    line-height: 1;
    padding: 4px;
}

#timeline-close:hover {
    color: var(--oxblood);
}

#timeline-nav-list {
    list-style: none;
}

#timeline-nav-list li {
    margin-bottom: 16px;
    padding-left: 20px;
    position: relative;
}

#timeline-nav-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid var(--manuscript-gold);
    background: transparent;
}

#timeline-nav-list a {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.2rem;
    font-weight: 400;
    color: var(--burnt-umber);
    text-decoration: none;
    transition: color 0.2s ease;
    display: block;
}

#timeline-nav-list a:hover {
    color: var(--oxblood);
}

.era-date {
    display: block;
    font-family: 'IM Fell English', serif;
    font-size: 0.8rem;
    color: var(--cocoa-dust);
    margin-top: 2px;
}

/* --- Timeline Spine --- */
#timeline-spine {
    position: fixed;
    left: 40px;
    top: 0;
    bottom: 0;
    width: 20px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#timeline-spine.visible {
    opacity: 1;
}

#timeline-svg {
    width: 20px;
    height: 100%;
}

.timeline-node {
    transition: fill 0.2s ease, filter 0.3s ease;
}

.timeline-node.active {
    fill: var(--manuscript-gold);
    filter: drop-shadow(0 0 4px rgba(184,148,79,0.4));
}

/* --- Era Sections --- */
.era-section {
    position: relative;
    z-index: 1;
    padding: 80px 80px 80px 100px;
    max-width: 1100px;
    margin: 0 auto;
    min-height: 100vh;
    transition: background-color 0.8s ease;
}

/* Era-specific background tones */
.era-section[data-bg="#F0E8D0"] { background-color: var(--cool-parchment); }
.era-section[data-bg="#F5ECD7"] { background-color: var(--aged-vellum); }
.era-section[data-bg="#FAF5EA"] { background-color: var(--crisp-cream); }
.era-section[data-bg="#1A1209"] { background-color: var(--deep-archive); }

/* Opening section */
#opening {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--deep-archive);
    padding: 0;
    max-width: 100%;
}

.opening-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

#opening-line {
    width: 2px;
    height: 120px;
    margin-bottom: 20px;
    overflow: visible;
}

#opening-line line {
    transition: stroke-dashoffset 1.5s ease;
}

#opening-compass {
    width: 160px;
    height: 160px;
    opacity: 0;
    transition: opacity 0.8s ease;
    margin-bottom: 24px;
}

#opening-compass.visible {
    opacity: 1;
}

.compass-draw * {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 2s ease;
}

.compass-draw.drawn * {
    stroke-dashoffset: 0;
}

#site-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(2rem, 4.5vw, 3.8rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--aged-parchment);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 1s ease, transform 1s ease;
    font-feature-settings: 'liga' 1, 'onum' 1;
}

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

#site-subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-weight: 300;
    font-size: clamp(1.1rem, 2.5vw, 1.6rem);
    color: var(--manuscript-gold);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 1s ease 0.3s, transform 1s ease 0.3s;
    margin-top: 12px;
}

#site-subtitle.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Era Titles --- */
.era-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(2rem, 4.5vw, 3.8rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--burnt-umber);
    margin-bottom: 8px;
    font-feature-settings: 'liga' 1, 'onum' 1;
    text-align: center;
}

.era-title .word {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    margin-right: 0.25em;
}

.era-title .word.revealed {
    opacity: 1;
    transform: translateY(0);
}

.era-subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--cocoa-dust);
    text-align: center;
    margin-bottom: 48px;
    line-height: 1.35;
}

/* --- Era Transitions / Dividers --- */
.era-transition {
    display: flex;
    justify-content: center;
    margin-bottom: 48px;
}

.era-divider {
    width: 100%;
    max-width: 600px;
    height: 40px;
}

.divider-draw * {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 1.5s ease;
}

.divider-draw.drawn * {
    stroke-dashoffset: 0;
}

/* --- Folio Cards --- */
.folio-card {
    max-width: 720px;
    margin: 0 auto 40px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.folio-card.revealed {
    opacity: 1;
    transform: translateY(0);
}

.folio-left {
    margin-left: 0;
    margin-right: auto;
}

.folio-right {
    margin-left: auto;
    margin-right: 0;
    padding-left: 12px;
}

.folio-left.revealed {
    transform: translateX(0);
}

.folio-right.revealed {
    transform: translateX(0);
}

.folio-inner {
    background: var(--aged-vellum);
    padding: 36px 40px;
    position: relative;
    box-shadow: 2px 3px 12px rgba(30,21,16,0.12), 0 1px 3px rgba(30,21,16,0.08);
    clip-path: polygon(
        0% 0%,
        99.2% 0.3%,
        100% 1.2%,
        99.8% 99%,
        99.3% 99.7%,
        0.5% 100%,
        0% 99.5%,
        0.2% 0.8%
    );
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.folio-inner:hover {
    transform: translateY(-3px);
    box-shadow: 3px 5px 18px rgba(30,21,16,0.18), 0 2px 6px rgba(30,21,16,0.1);
}

.folio-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.1rem, 2.5vw, 1.6rem);
    color: var(--burnt-umber);
    margin-bottom: 4px;
    line-height: 1.35;
}

.folio-date {
    font-family: 'IM Fell English', serif;
    font-size: 0.85rem;
    color: var(--manuscript-gold);
    margin-bottom: 16px;
    display: block;
}

.folio-text {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-size: 17px;
    line-height: 1.7;
    color: var(--deep-sepia);
    max-width: 65ch;
    font-feature-settings: 'kern' 1, 'liga' 1;
}

/* --- Marginalia --- */
.marginalia-container {
    position: relative;
    max-width: 720px;
    margin: 0 auto 24px;
    min-height: 40px;
}

.marginalia {
    position: absolute;
    right: -200px;
    top: 0;
    width: 180px;
    font-family: 'IM Fell English', serif;
    font-size: 12.5px;
    color: var(--cocoa-dust);
    line-height: 1.5;
    transform: rotate(-2deg) translateX(20px);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.marginalia:nth-child(2) {
    top: 28px;
}

.marginalia:nth-child(3) {
    top: 56px;
}

.marginalia.revealed {
    opacity: 0.75;
    transform: rotate(-2deg) translateX(0);
}

/* --- Wax Seals --- */
.wax-seal {
    text-align: center;
    margin: 48px auto;
    transform: scale(0);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wax-seal.revealed {
    transform: scale(1);
}

.wax-seal svg {
    width: 52px;
    height: 52px;
}

/* --- Closing Section --- */
#closing {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    background-color: var(--deep-archive);
    padding: 80px 40px;
    max-width: 100%;
}

.closing-content {
    text-align: center;
}

.closing-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    color: var(--aged-parchment);
    line-height: 1.6;
    margin-bottom: 32px;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.closing-text.revealed {
    opacity: 1;
    transform: translateY(0);
}

.closing-line {
    width: 60px;
    height: 1px;
    background: var(--manuscript-gold);
    margin: 0 auto 24px;
    opacity: 0;
    transition: opacity 0.8s ease 0.3s;
}

.closing-line.revealed {
    opacity: 1;
}

.closing-attribution {
    font-family: 'IM Fell English', serif;
    font-size: 0.9rem;
    color: var(--manuscript-gold);
    letter-spacing: 0.1em;
    opacity: 0;
    transition: opacity 0.8s ease 0.5s;
}

.closing-attribution.revealed {
    opacity: 1;
}

/* --- Responsive adjustments --- */
@media (max-width: 1100px) {
    .marginalia {
        position: relative;
        right: auto;
        top: auto;
        width: auto;
        margin-bottom: 8px;
        display: block;
        transform: rotate(-1deg);
        text-align: right;
        padding-right: 12px;
    }

    .marginalia:nth-child(2),
    .marginalia:nth-child(3) {
        top: auto;
    }

    .marginalia-container {
        min-height: auto;
    }

    .marginalia.revealed {
        transform: rotate(-1deg) translateX(0);
    }
}

@media (max-width: 768px) {
    .era-section {
        padding: 60px 24px 60px 24px;
    }

    #timeline-spine {
        display: none;
    }

    .folio-right {
        padding-left: 0;
    }

    .folio-inner {
        padding: 28px 24px;
    }

    #era-indicator {
        top: 12px;
        right: 12px;
        width: 48px;
        height: 48px;
    }

    #era-compass-mini {
        width: 48px;
        height: 48px;
    }

    #era-numeral {
        font-size: 12px;
    }

    #bg-compass {
        width: 300px;
        height: 300px;
    }

    #timeline-overlay-inner {
        padding: 32px 24px;
    }
}
