/* ============================================
   historic.quest - Styles
   Victorian Explorer's Study Aesthetic
   ============================================ */

:root {
    --aged-parchment: #F2E6D0;
    --expedition-navy: #0E1A2B;
    --expedition-ink: #2C1B0E;
    --faded-sepia: #7A5C3E;
    --cartographer-gold: #B8860B;
    --compass-rose-red: #8B2500;
    --dispatch-cream: #E8DCC8;
    --archive-slate: #4A3F35;
    --deep-walnut: #3B2314;
    --muted-border: #5C3A1E;
}

/* ---- Reset & Base ---- */

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background-color: var(--aged-parchment);
    color: var(--expedition-ink);
    font-family: 'Lora', Georgia, serif;
    font-size: clamp(1rem, 1.15vw, 1.15rem);
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
}

/* Paper grain texture overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    filter: url(#paper-grain);
    background: var(--aged-parchment);
}

/* ---- Typography ---- */

h1, h2 {
    font-family: 'Playfair Display', Georgia, serif;
    color: var(--deep-walnut);
    line-height: 1.1;
}

h1 {
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 900;
    letter-spacing: 0.04em;
}

h2 {
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    font-weight: 700;
    letter-spacing: 0.03em;
}

h3 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    font-weight: 700;
    color: var(--deep-walnut);
    letter-spacing: 0.02em;
    line-height: 1.3;
}

/* ---- Compass Rose Watermark ---- */

#compass-watermark {
    position: fixed;
    bottom: -5vh;
    right: -5vh;
    width: 40vh;
    height: 40vh;
    opacity: 0.04;
    z-index: 1;
    pointer-events: none;
    will-change: transform;
}

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

/* ---- Dispatch Common Styles ---- */

.dispatch {
    min-height: 100vh;
    position: relative;
    padding: 4rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.dispatch-header {
    text-align: center;
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.dispatch-header.visible {
    opacity: 1;
    transform: translateY(0);
}

.dispatch-number {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--archive-slate);
    display: block;
    margin-bottom: 0.5rem;
}

/* ---- DISPATCH I: The Map Room (Hero) ---- */

#dispatch-hero {
    padding: 0;
    overflow: hidden;
}

.topographic-contours {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    width: 120%;
    height: 120%;
    opacity: 0.04;
    z-index: 0;
    background:
        radial-gradient(ellipse 60% 50% at 48% 52%, var(--faded-sepia) 0%, transparent 70%),
        radial-gradient(ellipse 55% 45% at 52% 48%, var(--faded-sepia) 0%, transparent 65%),
        radial-gradient(ellipse 70% 55% at 45% 55%, var(--faded-sepia) 0%, transparent 75%),
        radial-gradient(ellipse 50% 40% at 55% 45%, var(--faded-sepia) 0%, transparent 60%),
        radial-gradient(ellipse 80% 60% at 50% 50%, var(--faded-sepia) 0%, transparent 80%);
    border-radius: 45% 55% 52% 48%;
    animation: contourPulse 3s ease-in-out 3s 1;
}

@keyframes contourPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.02); }
}

.cartouche-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
    width: 100%;
    max-width: 700px;
}

#cartouche {
    width: 100%;
    max-width: 600px;
    height: auto;
}

/* Cartouche drawing animation */
.cartouche-frame {
    stroke-dasharray: 1600;
    stroke-dashoffset: 1600;
    animation: drawPath 0.7s ease-out 0.3s forwards;
}

.cartouche-inner {
    stroke-dasharray: 1500;
    stroke-dashoffset: 1500;
    animation: drawPath 0.7s ease-out 0.5s forwards;
}

.scrollwork {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    animation: drawPath 1s ease-out 1s forwards;
}

.ribbon {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: drawPath 0.5s ease-out 2s forwards;
}

.ribbon-fold-l, .ribbon-fold-r {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    animation: drawPath 0.3s ease-out 2.3s forwards;
}

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

/* Hero text */
.hero-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    text-align: center;
    opacity: 0;
    animation: fadeInUp 0.6s ease-out 2.5s forwards;
    z-index: 3;
    width: 80%;
}

.hero-title {
    color: var(--deep-walnut);
    margin-bottom: 0.25rem;
    white-space: nowrap;
}

.hero-subtitle {
    font-family: 'IM Fell English', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    color: var(--faded-sepia);
    opacity: 0;
    animation: fadeInUp 0.6s ease-out 2.7s forwards;
    margin-top: 0.5rem;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate(-50%, -52%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -60%);
    }
}

/* Subtitle standalone fade */
.hero-subtitle {
    animation-name: fadeIn;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Ornamental Dividers ---- */

.ornamental-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80%;
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 0;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.ornamental-divider.visible {
    opacity: 1;
}

.divider-line {
    flex: 1;
    height: 0;
    position: relative;
}

.divider-line::before,
.divider-line::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--archive-slate);
    opacity: 0.4;
}

.divider-line::before {
    top: -2px;
}

.divider-line::after {
    top: 2px;
}

.divider-ornament {
    width: 32px;
    height: 32px;
    margin: 0 1.5rem;
    flex-shrink: 0;
}

.divider-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 1.2s ease-out;
}

.ornamental-divider.visible .divider-path {
    stroke-dashoffset: 0;
}

/* ---- DISPATCH II: The Chronicle ---- */

#dispatch-chronicle {
    padding: 4rem 2rem;
}

.chronicle-layout {
    display: flex;
    gap: 2rem;
    max-width: 1000px;
    width: 100%;
    position: relative;
}

.chronicle-main {
    flex: 0 0 65%;
    text-align: justify;
    hyphens: auto;
}

.chronicle-main p {
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.chronicle-main p.visible {
    opacity: 1;
    transform: translateY(0);
}

.chronicle-marginalia {
    flex: 0 0 calc(35% - 2rem);
    position: relative;
    padding-left: 2rem;
    border-left: 1px solid rgba(92, 58, 30, 0.3); /* #5C3A1E at 30% */
}

.marginalia-item {
    margin-bottom: 2rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.marginalia-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.sticky-note {
    position: sticky;
    top: 2rem;
}

.marginalia-date {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--archive-slate);
    display: block;
    margin-bottom: 0.3rem;
}

.marginalia-text {
    font-family: 'IM Fell English', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.6;
    color: var(--faded-sepia);
}

/* Marginalia box ornament */
.marginalia-item {
    padding: 1rem;
    background: var(--dispatch-cream);
    border: 1px solid rgba(92, 58, 30, 0.15);
    position: relative;
}

.marginalia-item::before,
.marginalia-item::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border-color: var(--cartographer-gold);
    border-style: solid;
}

.marginalia-item::before {
    top: -1px;
    left: -1px;
    border-width: 2px 0 0 2px;
}

.marginalia-item::after {
    bottom: -1px;
    right: -1px;
    border-width: 0 2px 2px 0;
}

/* Drop cap */
.drop-cap-paragraph::first-letter {
    float: left;
    font-size: 4.5em;
    line-height: 0.85;
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 900;
    color: var(--compass-rose-red);
    text-shadow: 2px 2px 0 rgba(184, 134, 11, 0.15);
    margin-right: 0.1em;
    margin-top: 0.05em;
    transform: scale(0.8);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.drop-cap-paragraph.visible::first-letter {
    transform: scale(1);
}

/* ---- DISPATCH III: The Expedition Ledger ---- */

#dispatch-ledger {
    min-height: auto;
    padding: 4rem 2rem 6rem;
}

.ledger-background {
    width: 100%;
    max-width: 900px;
    position: relative;
    background:
        repeating-linear-gradient(
            transparent,
            transparent 28px,
            rgba(92, 58, 30, 0.08) 28px,
            rgba(92, 58, 30, 0.08) 29px
        );
    padding: 2rem;
}

/* Red margin line */
.ledger-background::before {
    content: '';
    position: absolute;
    top: 0;
    left: 60px;
    width: 1px;
    height: 100%;
    background: rgba(139, 37, 0, 0.12);
}

.timeline {
    position: relative;
    padding: 2rem 0;
}

.timeline-spine {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--faded-sepia);
    opacity: 0.4;
    transform: translateX(-50%);
}

.timeline-entry {
    display: flex;
    align-items: flex-start;
    margin-bottom: 3rem;
    position: relative;
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.timeline-entry-left {
    flex-direction: row-reverse;
    transform: translateX(-30px);
}

.timeline-entry-right {
    transform: translateX(30px);
}

.timeline-entry.visible {
    opacity: 1;
    transform: translateX(0);
}

.timeline-waypoint {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid var(--faded-sepia);
    background: var(--aged-parchment);
    position: absolute;
    left: 50%;
    top: 0.5rem;
    transform: translateX(-50%);
    z-index: 2;
    transition: background-color 0.3s ease;
}

.timeline-entry.active .timeline-waypoint {
    background: var(--compass-rose-red);
    border-color: var(--compass-rose-red);
}

.timeline-content {
    width: calc(50% - 2rem);
    padding: 1rem 1.5rem;
}

.timeline-entry-left .timeline-content {
    text-align: right;
    margin-right: auto;
}

.timeline-entry-right .timeline-content {
    margin-left: auto;
}

.timeline-date {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--archive-slate);
    display: block;
    margin-bottom: 0.3rem;
}

.timeline-content h3 {
    margin-bottom: 0.5rem;
}

.timeline-content p {
    font-size: clamp(0.9rem, 1vw, 1rem);
    color: var(--expedition-ink);
    line-height: 1.7;
}

/* ---- DISPATCH IV: The Cabinet of Curiosities ---- */

#dispatch-cabinet {
    min-height: auto;
    padding: 4rem 2rem 6rem;
}

.cabinet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    max-width: 1000px;
    width: 100%;
}

.cabinet-card {
    padding: 1.5rem;
    border: 1px solid rgba(92, 58, 30, 0.2);
    background: transparent;
    position: relative;
    transition: border-width 0.3s ease, background-color 0.5s ease, box-shadow 0.5s ease;
    overflow: hidden;
}

.cabinet-card.unfolded {
    border-width: 2px;
    background: var(--dispatch-cream);
    box-shadow: 3px 3px 0 rgba(92, 58, 30, 0.08);
}

.cabinet-card h3 {
    margin-bottom: 0.3rem;
}

.card-date {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--archive-slate);
    display: block;
    margin-bottom: 1rem;
}

.card-content {
    font-family: 'IM Fell English', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.6;
    color: var(--faded-sepia);
    min-height: 3rem;
}

.card-content .cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--cartographer-gold);
    margin-left: 2px;
    animation: blink 0.6s infinite;
    vertical-align: text-bottom;
}

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

/* Card aspect ratio variations */
.card-tall {
    grid-row: span 2;
}

.card-wide {
    grid-column: span 2;
}

/* Layered depth offset effect */
.cabinet-card:nth-child(2) { transform: rotate(-0.3deg); }
.cabinet-card:nth-child(3) { transform: rotate(0.2deg); }
.cabinet-card:nth-child(5) { transform: rotate(0.4deg); }
.cabinet-card:nth-child(6) { transform: rotate(-0.2deg); }

/* ---- DISPATCH V: The Colophon ---- */

#dispatch-colophon {
    background: var(--expedition-navy);
    color: var(--dispatch-cream);
    min-height: 100vh;
    text-align: center;
    padding: 6rem 2rem;
    position: relative;
    overflow: hidden;
}

#dispatch-colophon::before {
    content: '';
    position: absolute;
    top: -200px;
    left: 0;
    right: 0;
    height: 200px;
    background: linear-gradient(to bottom, var(--aged-parchment), var(--expedition-navy));
    pointer-events: none;
}

.colophon-content {
    max-width: 600px;
    margin: 0 auto;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.colophon-content.visible {
    opacity: 1;
    transform: translateY(0);
}

.colophon-title {
    font-family: 'Playfair Display', Georgia, serif;
    color: var(--dispatch-cream);
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    font-weight: 700;
    letter-spacing: 0.03em;
    margin-bottom: 2rem;
}

.colophon-text {
    font-family: 'IM Fell English', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.8;
    color: var(--dispatch-cream);
    margin-bottom: 1.5rem;
}

.small-caps {
    font-variant: small-caps;
    font-style: normal;
    font-size: 1.2em;
    letter-spacing: 0.08em;
}

.colophon-meta {
    font-family: 'IM Fell English', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.8rem, 0.9vw, 0.95rem);
    line-height: 2;
    color: rgba(232, 220, 200, 0.6);
    margin-top: 2rem;
}

.mono-accent {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-style: normal;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--archive-slate);
}

#dispatch-colophon .mono-accent {
    color: rgba(232, 220, 200, 0.5);
}

/* Colophon fleurons */
.colophon-fleuron {
    margin: 1.5rem auto;
    width: 24px;
    height: 24px;
    opacity: 0.6;
}

.colophon-fleuron svg {
    width: 100%;
    height: 100%;
}

/* Tailpiece chevrons */
.colophon-tailpiece {
    margin-top: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    opacity: 0;
    transition: opacity 1s ease 0.5s;
}

.colophon-content.visible .colophon-tailpiece {
    opacity: 1;
}

.tailpiece-chevron {
    border-style: solid;
    border-color: var(--cartographer-gold);
    border-width: 0 2px 2px 0;
    display: inline-block;
    transform: rotate(45deg);
}

.tailpiece-chevron:nth-child(1) { width: 24px; height: 24px; opacity: 0.9; }
.tailpiece-chevron:nth-child(2) { width: 20px; height: 20px; opacity: 0.7; }
.tailpiece-chevron:nth-child(3) { width: 16px; height: 16px; opacity: 0.5; }
.tailpiece-chevron:nth-child(4) { width: 12px; height: 12px; opacity: 0.35; }
.tailpiece-chevron:nth-child(5) { width: 8px; height: 8px; opacity: 0.2; }

/* ---- Scroll Animations (base states) ---- */

.fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Reduced Motion ---- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .cartouche-frame,
    .cartouche-inner,
    .scrollwork,
    .ribbon,
    .ribbon-fold-l,
    .ribbon-fold-r {
        stroke-dashoffset: 0;
    }
    .hero-text,
    .hero-subtitle {
        opacity: 1;
    }
    .topographic-contours {
        animation: none;
    }
    .divider-path {
        stroke-dashoffset: 0;
    }
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    .chronicle-layout {
        flex-direction: column;
    }

    .chronicle-main {
        flex: 1;
        text-align: left;
    }

    .chronicle-marginalia {
        flex: 1;
        border-left: none;
        padding-left: 0;
        border-top: 1px solid rgba(92, 58, 30, 0.3);
        padding-top: 2rem;
    }

    .sticky-note {
        position: static;
    }

    .timeline-spine {
        left: 20px;
    }

    .timeline-entry {
        flex-direction: row !important;
        padding-left: 40px;
    }

    .timeline-entry-left,
    .timeline-entry-right {
        transform: translateX(30px);
    }

    .timeline-entry.visible {
        transform: translateX(0);
    }

    .timeline-waypoint {
        left: 20px;
    }

    .timeline-content {
        width: 100%;
        text-align: left !important;
    }

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

    .card-tall {
        grid-row: span 1;
    }

    .card-wide {
        grid-column: span 1;
    }

    .ledger-background::before {
        left: 20px;
    }

    .ornamental-divider {
        width: 90%;
    }
}

@media (max-width: 480px) {
    .dispatch {
        padding: 3rem 1rem;
    }

    #dispatch-colophon {
        padding: 4rem 1rem;
    }

    .hero-title {
        white-space: normal;
    }
}
