/* ============================================
   historygrapher.com - Styles
   Color Palette:
     Deep Field:      #0B1120 (Midnight Indigo)
     Surface Dark:    #141C2E (Twilight Slate)
     Warm Gold:       #C9A84C (Astrolabe Brass)
     Parchment Light: #E8D4A2 (Aged Vellum)
     Reading Silver:  #B8B0A0 (Scholar's Ink)
     Deep Crimson:    #8B2D3A (Cardinal Red)
     Verdigris:       #3D7A6E (Oxidized Copper)
     Pale Fog:        #2A3044 (Archive Dust)
   ============================================ */

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

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

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

/* --- Noise Texture Overlay --- */
#noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
    opacity: 0.03;
    mix-blend-mode: soft-light;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' fill='%23E8D4A2'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    background-repeat: repeat;
}

/* --- Deep Background Layer (z:0) --- */
#deep-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 200vh;
    z-index: 0;
    will-change: transform;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#deep-background.visible {
    opacity: 1;
}

#coordinate-grid {
    width: 100%;
    height: 100%;
}

/* --- Foreground Connection Lines Layer (z:2) --- */
#connection-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    will-change: transform;
}

#connection-lines path {
    fill: none;
    stroke: #C9A84C;
    stroke-width: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
    filter: none;
}

#connection-lines path.active {
    opacity: 0.3;
}

#connection-lines path.highlight {
    opacity: 0.6;
    filter: drop-shadow(0 0 3px rgba(201, 168, 76, 0.3));
}

/* Connection line labels */
.connection-label {
    position: fixed;
    z-index: 11;
    background: #141C2E;
    border: 1px solid #C9A84C;
    color: #E8D4A2;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    padding: 4px 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    white-space: nowrap;
}

.connection-label.visible {
    opacity: 1;
}

/* --- Timeline Scrubber --- */
#timeline-scrubber {
    position: fixed;
    top: 0;
    right: 20px;
    width: 30px;
    height: 100vh;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.4s ease;
}

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

#scrubber-line {
    position: absolute;
    top: 10%;
    bottom: 10%;
    width: 2px;
    background: rgba(201, 168, 76, 0.4);
    transform: scaleY(0);
    transform-origin: top;
    transition: transform 1.2s ease-out;
}

#timeline-scrubber.visible #scrubber-line {
    transform: scaleY(1);
}

#scrubber-indicator {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #E8D4A2;
    box-shadow: 0 0 8px rgba(232, 212, 162, 0.5);
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    will-change: top;
    transition: top 0.1s linear;
    z-index: 2;
}

.scrubber-notch {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
}

.scrubber-notch::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(201, 168, 76, 0.5);
    transition: all 0.2s ease;
}

.scrubber-notch:hover::before {
    background: #C9A84C;
    transform: scale(1.5);
}

.notch-tooltip {
    position: absolute;
    right: 24px;
    white-space: nowrap;
    background: #141C2E;
    border: 1px solid #C9A84C;
    color: #E8D4A2;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 4px 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.scrubber-notch:hover .notch-tooltip {
    opacity: 1;
}

/* --- Mobile Timeline Bar --- */
#mobile-timeline-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 40px;
    z-index: 50;
    background: rgba(11, 17, 32, 0.95);
    border-bottom: 1px solid rgba(201, 168, 76, 0.2);
    align-items: center;
    justify-content: space-around;
    padding: 0 10px;
    opacity: 0;
    transition: opacity 0.4s ease;
}

#mobile-timeline-bar.visible {
    opacity: 1;
}

.mobile-notch {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(201, 168, 76, 0.6);
    cursor: pointer;
    padding: 8px 4px;
    transition: color 0.2s ease;
}

.mobile-notch:hover,
.mobile-notch.active {
    color: #E8D4A2;
}

/* --- Content Layer (z:1) --- */
#content-layer {
    position: relative;
    z-index: 5;
    max-width: 820px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* --- Opening Sequence --- */
#opening-sequence {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

#opening-timeline-line {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    background: #C9A84C;
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0.4;
}

#site-title {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: clamp(3rem, 6vw, 5rem);
    font-weight: 600;
    color: #E8D4A2;
    letter-spacing: 0.04em;
    font-feature-settings: 'liga' 1, 'onum' 1;
    position: relative;
    z-index: 2;
    overflow: hidden;
}

#site-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

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

#site-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.75rem, 0.9vw, 0.9rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #C9A84C;
    margin-top: 1rem;
    position: relative;
    z-index: 2;
    overflow: hidden;
    border-right: 2px solid #C9A84C;
    white-space: nowrap;
    width: 0;
}

#site-subtitle.typing {
    animation: blink-caret 0.6s step-end infinite;
}

#site-subtitle.done {
    border-right-color: transparent;
}

@keyframes blink-caret {
    from, to { border-right-color: #C9A84C; }
    50% { border-right-color: transparent; }
}

/* --- Graph Breaks --- */
.graph-break {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: clamp(3rem, 6vh, 6rem) 0;
    gap: 0;
}

.graph-break-line {
    flex: 1;
    height: 1px;
    background: rgba(201, 168, 76, 0.2);
}

.graph-break-node {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #C9A84C;
    background: #0B1120;
    flex-shrink: 0;
}

/* --- History Sections --- */
.history-section {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: clamp(4rem, 8vh, 8rem);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.history-section.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* --- Node Markers --- */
.node-marker {
    position: relative;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    margin-top: 0.4rem;
    cursor: pointer;
}

.node-outer {
    position: absolute;
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid #C9A84C;
}

.node-inner {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #C9A84C;
}

/* Category-specific colors */
.node-marker[data-category="conflict"] .node-inner {
    background: #8B2D3A;
}

.node-marker[data-category="cultural"] .node-inner {
    background: #3D7A6E;
}

.node-marker[data-category="political"] .node-inner {
    background: #C9A84C;
}

.node-marker[data-category="pivotal"] .node-inner {
    background: #E8D4A2;
}

/* Node pulse animation */
.history-section.in-center .node-marker .node-outer {
    animation: node-pulse 3s ease-in-out infinite;
}

@keyframes node-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Node marker scale entrance */
.node-marker {
    transform: scale(0.5);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.history-section.in-view .node-marker {
    transform: scale(1);
    opacity: 1;
}

/* --- Node Tooltip --- */
.node-marker .node-tooltip {
    position: absolute;
    left: 24px;
    top: -8px;
    background: #141C2E;
    border: 1px solid #C9A84C;
    padding: 10px 14px;
    min-width: 220px;
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

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

.node-tooltip .tooltip-date {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #C9A84C;
    margin-bottom: 4px;
}

.node-tooltip .tooltip-title {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 1rem;
    font-weight: 600;
    color: #E8D4A2;
    margin-bottom: 4px;
}

.node-tooltip .tooltip-summary {
    font-family: 'Source Serif 4', serif;
    font-size: 0.8rem;
    color: #B8B0A0;
    line-height: 1.4;
}

/* Category-specific top border on tooltips */
.node-marker[data-category="conflict"] .node-tooltip {
    border-top: 4px solid #8B2D3A;
}

.node-marker[data-category="cultural"] .node-tooltip {
    border-top: 4px solid #3D7A6E;
}

.node-marker[data-category="political"] .node-tooltip {
    border-top: 4px solid #C9A84C;
}

.node-marker[data-category="pivotal"] .node-tooltip {
    border-top: 4px solid #E8D4A2;
}

/* --- Section Content --- */
.section-content {
    flex: 1;
    min-width: 0;
}

.epoch-label {
    display: inline-block;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.75rem, 0.9vw, 0.9rem);
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #C9A84C;
    margin-bottom: 0.5rem;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.history-section.in-view .epoch-label {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 0.1s;
}

.section-title {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: clamp(2.2rem, 5vw, 4rem);
    font-weight: 600;
    color: #E8D4A2;
    letter-spacing: 0.04em;
    font-feature-settings: 'liga' 1, 'onum' 1;
    line-height: 1.15;
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.history-section.in-view .section-title {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.2s;
}

.section-body p {
    margin-bottom: 1.2rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.history-section.in-view .section-body p {
    opacity: 1;
    transform: translateY(0);
}

.history-section.in-view .section-body p:nth-child(1) { transition-delay: 0.3s; }
.history-section.in-view .section-body p:nth-child(2) { transition-delay: 0.4s; }
.history-section.in-view .section-body p:nth-child(3) { transition-delay: 0.5s; }
.history-section.in-view .section-body p:nth-child(4) { transition-delay: 0.6s; }

/* --- Minard Flow Visualizations --- */
.minard-flow {
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    height: 80px;
    margin-bottom: clamp(2rem, 4vh, 4rem);
    opacity: 0.7;
}

.minard-flow svg {
    width: 100%;
    height: 100%;
}

.minard-path {
    transition: stroke-width 1.2s ease-in-out;
}

.minard-flow.in-view .minard-path {
    stroke-width: 6;
}

/* --- Closing Section --- */
#closing {
    text-align: center;
    padding: clamp(4rem, 10vh, 10rem) 0;
}

.closing-text {
    font-family: 'Source Serif 4', serif;
    font-size: clamp(1.1rem, 1.5vw, 1.4rem);
    color: #B8B0A0;
    font-style: italic;
    margin-bottom: 2rem;
    line-height: 1.8;
}

.closing-label {
    display: inline-block;
    opacity: 1;
    transform: translateX(0);
}

/* --- Selection Styling --- */
::selection {
    background: rgba(201, 168, 76, 0.3);
    color: #E8D4A2;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: #0B1120;
}

::-webkit-scrollbar-thumb {
    background: rgba(201, 168, 76, 0.3);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(201, 168, 76, 0.5);
}

/* --- Responsive: Below 768px --- */
@media (max-width: 768px) {
    #timeline-scrubber {
        display: none;
    }

    #mobile-timeline-bar {
        display: flex;
    }

    #content-layer {
        padding: 0 1.2rem;
        padding-top: 40px;
    }

    .history-section {
        flex-direction: column;
        gap: 0.8rem;
    }

    .node-marker {
        margin-top: 0;
        margin-bottom: 0.3rem;
    }

    .graph-break {
        margin: clamp(2rem, 4vh, 4rem) 0;
    }

    .minard-flow {
        height: 50px;
    }

    #opening-sequence {
        height: calc(100vh - 40px);
    }

    .node-marker .node-tooltip {
        left: 0;
        top: 24px;
        min-width: 180px;
    }
}
