/* ========================================
   cbdc.bar — Hand-illustrated timeline
   Coastal-blend palette, scholarly tone
   ======================================== */

:root {
    --deep-ocean-ink: #1B3A4B;
    --tidal-teal: #2C5F6E;
    --weathered-slate: #6B8F9E;
    --seafoam-mist: #A8C5B8;
    --warm-sand: #F4EDE4;
    --golden-sand: #E8C47C;
    --coral-ink: #C47A6C;
    --driftwood: #7A5C4F;
    --tidal-charcoal: #2D4A5A;
}

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

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 400;
    color: var(--deep-ocean-ink);
    background-color: var(--warm-sand);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    line-height: 1.65;
    letter-spacing: 0.005em;
    font-size: clamp(0.95rem, 1.8vw, 1.1rem);
    overflow-x: hidden;
    transition: background-color 800ms ease;
}

/* ---- Opening Section ---- */

.opening-section {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

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

.title-svg {
    width: clamp(280px, 60vw, 700px);
    height: auto;
}

.title-letter {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawLetter 1800ms ease-out forwards;
}

.title-letter:nth-child(1) { animation-delay: 200ms; }
.title-letter:nth-child(2) { animation-delay: 400ms; }
.title-letter:nth-child(3) { animation-delay: 600ms; }
.title-letter:nth-child(4) { animation-delay: 800ms; }

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

.subtitle {
    font-family: 'Kalam', cursive;
    font-size: 1.2rem;
    color: var(--weathered-slate);
    opacity: 0;
    animation: fadeIn 600ms ease-out 1200ms forwards;
}

.opening-rule {
    width: clamp(200px, 40vw, 400px);
    height: auto;
    opacity: 0;
    animation: fadeIn 600ms ease-out 1600ms forwards;
}

.opening-rule path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    animation: drawLine 600ms ease-out 1600ms forwards;
}

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

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

.scroll-arrow {
    opacity: 0;
    animation: fadeIn 600ms ease-out 2400ms forwards, pulse 2s ease-in-out 3000ms infinite;
}

@keyframes pulse {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

/* ---- Timeline ---- */

.timeline {
    position: relative;
    max-width: 1100px;
    margin: 0 auto;
    padding: 60px 20px 120px;
}

.timeline-spine {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 1;
}

.timeline-spine path {
    stroke-dasharray: var(--spine-length, 10000);
    stroke-dashoffset: var(--spine-offset, 10000);
    transition: stroke-dashoffset 100ms linear;
}

/* ---- Timeline Entries ---- */

.timeline-entry {
    position: relative;
    display: flex;
    align-items: flex-start;
    margin-bottom: 80px;
    opacity: 0;
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

.timeline-entry.left {
    justify-content: flex-start;
    padding-right: calc(50% + 32px);
    transform: translateX(-24px);
}

.timeline-entry.right {
    justify-content: flex-end;
    padding-left: calc(50% + 32px);
    transform: translateX(24px);
}

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

/* ---- Timeline Node ---- */

.timeline-node {
    position: absolute;
    left: 50%;
    top: 20px;
    width: 12px;
    height: 12px;
    background: var(--golden-sand);
    border-radius: 50%;
    transform: translate(-50%, 0) scale(0);
    transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
    box-shadow: 0 0 0 3px var(--warm-sand), 0 0 0 5px var(--tidal-teal);
}

.timeline-entry.visible .timeline-node {
    transform: translate(-50%, 0) scale(1);
}

/* ---- Timeline Card ---- */

.timeline-card {
    position: relative;
    max-width: 460px;
    padding: 28px 32px;
    background: var(--warm-sand);
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Crect x='2' y='2' width='calc(100%25-4)' height='calc(100%25-4)' rx='2' fill='none' stroke='%237A5C4F' stroke-width='1.5' stroke-dasharray='none'/%3E%3C/svg%3E");
    border: none;
    overflow: visible;
}

.timeline-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 1.5px solid var(--driftwood);
    border-radius: 2px;
    pointer-events: none;
    /* Simulate hand-drawn border with slight asymmetry */
    clip-path: polygon(
        0.5% 0.8%,
        99.2% 0.3%,
        99.6% 99.5%,
        0.3% 99.8%
    );
}

.timeline-card h3 {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.3rem, 2.5vw, 1.6rem);
    color: var(--deep-ocean-ink);
    letter-spacing: 0.01em;
    line-height: 1.2;
    margin-bottom: 16px;
}

.timeline-card p {
    color: var(--tidal-charcoal);
    margin-bottom: 14px;
    line-height: 1.65;
}

.timeline-card p:last-child {
    margin-bottom: 0;
}

.timeline-card em {
    font-style: italic;
}

/* ---- Pull Quote ---- */

.pull-quote {
    position: relative;
    margin: 20px 0;
    padding: 20px 24px;
    border-left: 4px solid var(--coral-ink);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0,8 L8,0' stroke='%237A5C4F' stroke-width='0.5' opacity='0.15'/%3E%3C/svg%3E");
    background-color: rgba(244, 237, 228, 0.6);
}

.pull-quote::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--coral-ink);
    /* Slightly wavy left border via clip-path */
    clip-path: polygon(
        0% 0%, 100% 0.5%,
        80% 10%, 100% 20%,
        70% 30%, 100% 40%,
        80% 50%, 100% 60%,
        70% 70%, 100% 80%,
        80% 90%, 100% 100%,
        0% 99.5%
    );
}

.pull-quote p {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: 1.15em;
    color: var(--deep-ocean-ink);
    line-height: 1.5;
}

.pull-quote cite {
    display: block;
    margin-top: 12px;
    font-family: 'Kalam', cursive;
    font-style: normal;
    font-size: 0.85rem;
    color: var(--weathered-slate);
}

/* ---- Footnotes ---- */

.footnote-marker {
    display: inline-block;
    font-size: 0.75em;
    vertical-align: super;
    color: var(--coral-ink);
    font-weight: 600;
    cursor: pointer;
    transition: transform 150ms ease, color 150ms ease;
    line-height: 1;
}

.footnote-marker:hover,
.footnote-marker.active {
    transform: scale(1.2);
    color: var(--coral-ink);
}

.footnote-panel {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 250ms ease-out;
    overflow: hidden;
    margin: 0 0 14px;
}

.footnote-panel > * {
    overflow: hidden;
}

.footnote-panel.open {
    grid-template-rows: 1fr;
}

.footnote-panel-inner {
    padding: 14px 16px;
    background: var(--warm-sand);
    border: 1.5px solid var(--driftwood);
    border-radius: 2px;
    font-size: 0.9rem;
    color: var(--deep-ocean-ink);
    opacity: 0;
    transition: opacity 200ms ease-out 100ms;
}

.footnote-panel.open .footnote-panel-inner {
    opacity: 1;
}

.footnote-panel strong {
    color: var(--tidal-teal);
}

/* ---- Era Dividers ---- */

.era-divider {
    text-align: center;
    margin: 80px 0 60px;
    padding: 40px 20px;
    position: relative;
}

.era-line {
    width: 100%;
    max-width: 800px;
    height: auto;
    margin: 0 auto;
    display: block;
}

.era-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(2rem, 4vw, 3.25rem);
    color: var(--deep-ocean-ink);
    letter-spacing: 0.01em;
    line-height: 1.15;
    margin: 24px 0 16px;
}

.era-ornament {
    display: block;
    margin: 0 auto 24px;
}

.era-canvas {
    display: block;
    margin: 24px auto 0;
    max-width: 100%;
    height: auto;
    border-radius: 2px;
}

/* ---- Era Index Tabs ---- */

.era-index-tab {
    position: fixed;
    right: 0;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: 'Kalam', cursive;
    font-size: 0.8rem;
    color: var(--warm-sand);
    background: var(--coral-ink);
    padding: 12px 6px;
    border-radius: 4px 0 0 4px;
    transform: translateX(100%);
    transition: transform 300ms ease-out;
    z-index: 100;
    cursor: default;
    pointer-events: none;
}

.era-index-tab[data-era="pre-digital"] { top: 20%; }
.era-index-tab[data-era="blockchain"] { top: 35%; }
.era-index-tab[data-era="cbdc-emergence"] { top: 50%; }
.era-index-tab[data-era="future"] { top: 65%; }

.era-index-tab.peeking {
    transform: translateX(calc(100% - 4px));
}

.era-index-tab.active {
    transform: translateX(0);
}

/* ---- Margin Annotations ---- */

.margin-annotation {
    position: absolute;
    font-family: 'Kalam', cursive;
    font-size: clamp(0.75rem, 1.4vw, 0.875rem);
    color: var(--weathered-slate);
    line-height: 1.5;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 400ms ease-out;
}

.margin-annotation.visible {
    opacity: 1;
}

.margin-annotation.left-margin {
    left: 10px;
}

.margin-annotation.right-margin {
    right: 10px;
}

/* ---- Progress Indicator ---- */

.progress-indicator {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 200;
    opacity: 0;
    transition: opacity 400ms ease-out;
}

.progress-indicator.visible {
    opacity: 1;
}

.progress-era-name {
    font-family: 'Kalam', cursive;
    font-size: 0.75rem;
    color: var(--weathered-slate);
    white-space: nowrap;
}

.progress-track {
    position: relative;
    height: 80px;
}

.progress-dot {
    position: absolute;
    left: 50%;
    top: 0;
    width: 8px;
    height: 8px;
    background: var(--golden-sand);
    border-radius: 50%;
    transform: translateX(-50%);
    transition: top 200ms ease-out;
    box-shadow: 0 0 0 2px var(--warm-sand);
}

/* ---- Timeline End ---- */

.timeline-end {
    text-align: center;
    padding-top: 40px;
    opacity: 0.6;
}

/* ---- Closing Note ---- */

.closing-note {
    font-family: 'Kalam', cursive;
    color: var(--weathered-slate);
    font-style: italic;
    margin-top: 8px;
}

/* ---- Background tinting per era ---- */

body.era-pre-digital {
    background-color: #F4EDE4;
}

body.era-blockchain {
    background-color: #F2EDE6;
}

body.era-cbdc-emergence {
    background-color: #F0EDE8;
}

body.era-future {
    background-color: #F4EDE2;
}

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

@media (max-width: 768px) {
    .timeline-spine {
        left: 40px;
    }

    .timeline-entry {
        padding-left: 72px !important;
        padding-right: 16px !important;
        justify-content: flex-start !important;
    }

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

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

    .timeline-node {
        left: 40px;
    }

    .timeline-card {
        max-width: 100%;
    }

    .margin-annotation {
        display: none;
    }

    .era-index-tab {
        font-size: 0.7rem;
        padding: 8px 4px;
    }

    .progress-indicator {
        bottom: 16px;
        right: 16px;
    }

    .era-canvas {
        max-height: 250px;
    }
}

@media (max-width: 480px) {
    .title-svg {
        width: 90vw;
    }

    .era-title {
        font-size: clamp(1.6rem, 6vw, 2.2rem);
    }

    .timeline-card {
        padding: 20px 18px;
    }

    .timeline-entry {
        margin-bottom: 50px;
    }
}

/* ---- Crosshatch pattern utility ---- */

.crosshatch-bg {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0,8 L8,0' stroke='%237A5C4F' stroke-width='0.5' opacity='0.15'/%3E%3C/svg%3E");
}

/* ---- Selection ---- */

::selection {
    background: var(--seafoam-mist);
    color: var(--deep-ocean-ink);
}

/* ---- Scrollbar styling ---- */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--warm-sand);
}

::-webkit-scrollbar-thumb {
    background: var(--weathered-slate);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--tidal-teal);
}
