/* ============================================
   historygrapher.net - Temporal Observatory
   ============================================ */

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: #0D0B08;
    color: #A89B8C;
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- SVG Defs (hidden) --- */
.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Constellation Grid Background --- */
.constellation-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 800ms ease;
    background:
        radial-gradient(circle 1px at 12% 8%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 27% 15%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 45% 5%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 63% 12%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 78% 7%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 91% 18%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 8% 25%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 22% 32%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 38% 28%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 55% 22%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 72% 30%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 85% 26%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 5% 42%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 18% 48%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 33% 44%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 48% 38%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 65% 45%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 80% 40%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 95% 35%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 10% 58%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 25% 62%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 42% 55%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 58% 60%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 75% 52%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 88% 58%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 3% 72%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 15% 78%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 30% 75%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 47% 70%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 62% 76%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 77% 68%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 92% 74%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 7% 88%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 20% 92%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 35% 85%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 52% 90%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 68% 88%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 83% 82%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 96% 92%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 14% 96%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 40% 95%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 60% 97%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 82% 94%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 50% 50%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 16% 3%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 70% 18%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 36% 65%, #2A2520 1px, transparent 1px),
        radial-gradient(circle 1px at 88% 48%, #2A2520 1px, transparent 1px);
}

.constellation-grid.visible {
    opacity: 0.5;
}

/* --- Lamplight Overlay --- */
.lamplight-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 30%, rgba(200, 184, 138, 0.06) 0%, transparent 70%);
}

/* --- Observation Rail --- */
.observation-rail {
    position: fixed;
    left: 0;
    top: 0;
    width: 48px;
    height: 100vh;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.observation-rail.visible {
    opacity: 1;
    transform: translateX(0);
}

.rail-line {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 1px;
    height: 60%;
    background-color: rgba(74, 103, 65, 0.4);
}

.rail-marker {
    position: relative;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #4A6741;
    border: none;
    cursor: pointer;
    z-index: 2;
    margin: 14px 0;
    transition: width 150ms ease, height 150ms ease, box-shadow 300ms ease;
    padding: 0;
    outline: none;
}

.rail-marker:hover {
    width: 12px;
    height: 12px;
}

.rail-marker.active {
    box-shadow: 0 0 6px rgba(74, 103, 65, 0.6);
}

.rail-tooltip {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #4A6741;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    background: rgba(18, 22, 18, 0.9);
    padding: 2px 8px;
    border-radius: 2px;
}

.rail-marker:hover .rail-tooltip {
    opacity: 1;
}

/* --- Mobile Menu --- */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(74, 103, 65, 0.4);
    background: rgba(18, 22, 18, 0.9);
    cursor: pointer;
    padding: 8px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    border-radius: 2px;
}

.menu-line {
    display: block;
    width: 20px;
    height: 1px;
    background-color: #C8B88A;
    transition: transform 200ms ease;
}

.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 190;
    background: rgba(13, 11, 8, 0.97);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 300ms ease;
}

.mobile-menu-overlay.open {
    display: flex;
    opacity: 1;
}

.mobile-menu-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(74, 103, 65, 0.4);
    background: transparent;
    color: #C8B88A;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
}

.mobile-nav {
    display: flex;
    flex-direction: column;
    gap: 24px;
    text-align: center;
}

.mobile-nav-link {
    font-family: 'Cormorant Garamond', Garamond, serif;
    font-size: 1.4rem;
    font-weight: 600;
    font-variant: small-caps;
    letter-spacing: 0.04em;
    color: #C8B88A;
    text-decoration: none;
    transition: color 200ms ease;
}

.mobile-nav-link:hover {
    color: #3A8F7A;
}

/* --- Section Base --- */
.section {
    position: relative;
    z-index: 2;
    min-height: 100vh;
    width: 100%;
}

/* --- Hero Section --- */
.hero-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
}

.hero-axis-container {
    width: 80%;
    max-width: 900px;
    position: relative;
    overflow: hidden;
}

.hero-axis-line {
    width: 100%;
    height: 4px;
}

.hero-axis-line line {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 1200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.hero-axis-line.animate line {
    stroke-dashoffset: 0;
}

.hero-title {
    font-family: 'Cormorant Garamond', Garamond, serif;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    font-weight: 600;
    font-variant: small-caps;
    letter-spacing: 0.04em;
    color: #C8B88A;
    font-feature-settings: 'liga' 1, 'onum' 1;
    margin-top: 20px;
    opacity: 0;
    transition: opacity 600ms ease;
}

.hero-title.visible {
    opacity: 1;
}

.hero-subtitle {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    color: rgba(168, 155, 140, 0.7);
    margin-top: 12px;
    opacity: 0;
    transition: opacity 600ms ease;
}

.hero-subtitle.visible {
    opacity: 1;
}

/* --- Content Sections --- */
.content-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 60px;
    padding: 80px 48px 80px 80px;
    min-height: 100vh;
}

/* --- Content Cards --- */
.content-card {
    position: relative;
    max-width: 680px;
    width: 100%;
    background: rgba(18, 16, 12, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(74, 103, 65, 0.25);
    padding: 40px 48px 40px 56px;
    opacity: 0;
    transition: opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.content-card.card-left {
    align-self: flex-start;
    margin-left: 10%;
    transform: translateX(-40px);
}

.content-card.card-right {
    align-self: flex-end;
    margin-right: 10%;
    transform: translateX(40px);
}

.content-card.card-center {
    align-self: center;
    transform: translateX(-40px);
}

.content-card.in-view {
    opacity: 1;
    transform: translateX(0);
}

/* --- Card Accent Bar --- */
.card-accent {
    position: absolute;
    left: 0;
    top: 0;
    width: 3px;
    height: 0;
    transition: height 600ms ease 200ms;
}

.content-card.in-view .card-accent {
    height: 100%;
}

/* --- Crosshatch Background --- */
.crosshatch-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
}

.crosshatch-bg + * {
    position: relative;
    z-index: 1;
}

.content-card > *:not(.crosshatch-bg):not(.card-accent) {
    position: relative;
    z-index: 1;
}

/* --- Typography --- */
.section-heading {
    font-family: 'Cormorant Garamond', Garamond, serif;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    font-weight: 600;
    font-variant: small-caps;
    letter-spacing: 0.04em;
    color: #C8B88A;
    font-feature-settings: 'liga' 1, 'onum' 1;
    margin-bottom: 24px;
    line-height: 1.2;
}

.body-text {
    color: #A89B8C;
    margin-bottom: 18px;
    line-height: 1.72;
}

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

.body-text:last-of-type {
    margin-bottom: 0;
}

/* --- Links --- */
a {
    color: #3A8F7A;
    text-decoration: none;
    background-image: linear-gradient(#3A8F7A, #3A8F7A);
    background-size: 0% 1px;
    background-position: left bottom;
    background-repeat: no-repeat;
    transition: background-size 300ms ease;
}

a:hover {
    background-size: 100% 1px;
}

/* --- Marginalia --- */
.marginalia {
    position: absolute;
    right: -200px;
    top: 50%;
    transform: translateY(-50%);
    width: 180px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: rgba(74, 103, 65, 0.6);
    line-height: 1.5;
}

.manicule,
.pilcrow {
    font-size: 0.8rem;
    margin-right: 4px;
    display: inline-block;
}

/* --- Graph Canvas --- */
.graph-canvas {
    position: relative;
    min-height: 50vh;
    height: 60vh;
    background: linear-gradient(180deg, #0D0B08 0%, #12100C 40%, #1A1612 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.graph-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(rgba(42, 37, 32, 0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(42, 37, 32, 0.3) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
}

.graph-svg {
    position: relative;
    z-index: 2;
    width: 90%;
    max-width: 1100px;
    height: 80%;
}

/* --- Timeline Elements --- */
.timeline-spine {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 800ms ease;
}

.graph-canvas.in-view .timeline-spine {
    stroke-dashoffset: 0;
}

.tick-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    fill: #4A6741;
    opacity: 0;
    transition: opacity 400ms ease;
}

.graph-canvas.in-view .tick-label {
    opacity: 1;
}

.tick {
    opacity: 0;
    transition: opacity 300ms ease;
    transform-origin: center;
}

.graph-canvas.in-view .tick {
    opacity: 1;
}

/* --- Epoch Markers --- */
.epoch-marker {
    opacity: 0;
    transition: opacity 400ms ease, transform 200ms ease;
    cursor: pointer;
}

.graph-canvas.in-view .epoch-marker {
    opacity: 1;
    animation: epoch-pulse 2s infinite;
}

@keyframes epoch-pulse {
    0% { filter: drop-shadow(0 0 0 rgba(139, 58, 58, 0.4)); }
    50% { filter: drop-shadow(0 0 8px rgba(139, 58, 58, 0.2)); }
    100% { filter: drop-shadow(0 0 0 rgba(139, 58, 58, 0)); }
}

.epoch-marker:hover {
    transform: scale(1.3);
    transform-origin: center;
}

/* --- Data Lines --- */
.data-line {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 600ms ease;
}

.graph-canvas.in-view .data-line {
    stroke-dashoffset: 0;
}

/* Stagger data line animations */
.graph-canvas.in-view .data-connections .data-line:nth-child(1) { transition-delay: 900ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(2) { transition-delay: 960ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(3) { transition-delay: 1020ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(4) { transition-delay: 1080ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(5) { transition-delay: 1140ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(6) { transition-delay: 1200ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(7) { transition-delay: 1260ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(8) { transition-delay: 1320ms; }
.graph-canvas.in-view .data-connections .data-line:nth-child(9) { transition-delay: 1380ms; }

/* Data points */
.data-points circle {
    opacity: 0;
    transition: opacity 300ms ease;
}

.graph-canvas.in-view .data-points circle {
    opacity: 1;
    transition-delay: 1400ms;
}

/* --- Master Canvas --- */
.master-canvas {
    min-height: 80vh;
    height: 80vh;
    flex-direction: column;
    gap: 30px;
}

.master-svg {
    height: 70%;
}

/* Master graph stagger layers */
.graph-canvas.in-view .layer-political .master-line { transition-delay: 900ms; }
.graph-canvas.in-view .layer-economic .master-line { transition-delay: 1300ms; }
.graph-canvas.in-view .layer-technology .master-line { transition-delay: 1700ms; }
.graph-canvas.in-view .layer-cultural .master-line { transition-delay: 2100ms; }

.graph-canvas.in-view .master-points circle {
    transition-delay: 2500ms;
}

.master-closing-text {
    font-family: 'Cormorant Garamond', Garamond, serif;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    font-weight: 400;
    color: rgba(200, 184, 138, 0.5);
    text-align: center;
    z-index: 3;
    font-style: italic;
    letter-spacing: 0.02em;
}

/* --- Temporal Lens --- */
.temporal-lens {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 1px solid rgba(200, 184, 138, 0.3);
    backdrop-filter: blur(1px) brightness(1.15);
    -webkit-backdrop-filter: blur(1px) brightness(1.15);
    z-index: 5;
    pointer-events: none;
}

/* --- Epoch Tooltip --- */
.epoch-tooltip {
    position: fixed;
    z-index: 300;
    background: rgba(26, 22, 18, 0.95);
    border: 1px solid rgba(139, 58, 58, 0.4);
    padding: 10px 16px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 200ms ease, transform 200ms ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 280px;
}

.epoch-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.tooltip-date {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #8B3A3A;
}

.tooltip-event {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 0.85rem;
    font-weight: 400;
    color: #A89B8C;
}

/* --- Responsive: below 1024px --- */
@media (max-width: 1024px) {
    .observation-rail {
        display: none !important;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .content-section {
        padding: 60px 32px;
    }

    .content-card.card-left,
    .content-card.card-right {
        margin-left: 0;
        margin-right: 0;
        align-self: center;
    }

    .marginalia {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: 100%;
        margin-top: 20px;
        padding-top: 12px;
        border-top: 1px solid rgba(74, 103, 65, 0.15);
    }
}

/* --- Responsive: below 768px --- */
@media (max-width: 768px) {
    .content-section {
        padding: 40px 16px;
        gap: 40px;
    }

    .content-card {
        padding: 24px 20px 24px 28px;
        max-width: 100%;
    }

    .temporal-lens {
        display: none;
    }

    .graph-canvas {
        min-height: 40vh;
        height: 50vh;
    }

    .hero-axis-container {
        width: 90%;
    }
}

/* --- Responsive: below 480px --- */
@media (max-width: 480px) {
    .constellation-grid {
        display: none;
    }

    .content-card {
        padding: 20px 16px 20px 16px;
    }

    .card-accent {
        left: 0;
        top: 0;
        width: 100%;
        height: 3px !important;
        position: absolute;
    }

    .content-card.in-view .card-accent {
        width: 100%;
        height: 3px !important;
    }

    .graph-canvas {
        min-height: auto;
        height: auto;
        aspect-ratio: 16 / 9;
        overflow-x: auto;
    }

    .graph-svg {
        min-width: 600px;
        width: 600px;
    }

    .section-heading {
        font-size: clamp(1.4rem, 6vw, 2rem);
    }

    .master-canvas {
        min-height: auto;
        height: auto;
        aspect-ratio: 16 / 10;
    }
}
