/* =========================================================================
   historygrapher.com — candlelit cartography, horizontal timeline
   Palette: #0d0d0d, #0a0e1a, #0a1a1e, #1a1a24 (dark fields)
            #ff2d7b (magenta), #00f0ff (cyan), #c8ff00 (chartreuse) — neon
            #ffb347 (candle amber), #c8c0b8 (warm stone), #6e6680 (ash lavender)
   Fonts:   Anybody (display / era titles), Literata (body), Share Tech Mono (data)
   ========================================================================= */

:root {
    --void:         #0d0d0d;
    --navy:         #0a0e1a;
    --teal:         #0a1a1e;
    --deep:         #1a1a24;
    --magenta:      #ff2d7b;
    --cyan:         #00f0ff;
    --chartreuse:   #c8ff00;
    --amber:        #ffb347;
    --stone:        #c8c0b8;
    --ash:          #6e6680;

    --accent:       var(--magenta);
    --spine-top:    60vh;

    --font-display: "Anybody", "Inter", system-ui, sans-serif;
    --font-body:    "Literata", "Georgia", serif;
    --font-mono:    "Share Tech Mono", "Menlo", monospace;
}

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

html, body {
    height: 100%;
    background: var(--void);
    color: var(--stone);
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 16px;
    line-height: 1.72;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow: hidden;
}

body {
    animation: candle-flicker 4.3s cubic-bezier(.55,.08,.35,.96) infinite;
}

@keyframes candle-flicker {
    0%   { opacity: 1.00; }
    13%  { opacity: 0.97; }
    27%  { opacity: 0.995; }
    43%  { opacity: 0.93; }
    61%  { opacity: 1.00; }
    78%  { opacity: 0.95; }
    100% { opacity: 1.00; }
}

/* ===========================================================================
   Intro overlay — shown on first load, then fades out
   =========================================================================== */
.intro-overlay {
    position: fixed;
    inset: 0;
    background: var(--void);
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 900ms ease-out;
    pointer-events: all;
}
.intro-overlay.is-dismissed {
    opacity: 0;
    pointer-events: none;
}

.intro-candle {
    width: 60px;
    height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    transform: scale(0.9);
    animation: intro-candle-in 300ms ease-out 600ms forwards,
               intro-candle-pulse 500ms ease-in-out 1300ms;
}
.intro-flame {
    width: 18px;
    height: 30px;
    background: var(--amber);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    box-shadow: 0 0 16px 2px rgba(255,179,71,.5);
    margin-bottom: 4px;
}
.intro-wax {
    width: 10px;
    height: 70px;
    background: var(--stone);
}

@keyframes intro-candle-in {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes intro-candle-pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.intro-title {
    font-family: var(--font-display);
    font-variation-settings: "wdth" 125, "wght" 700;
    font-size: clamp(3rem, 7vw, 5.5rem);
    color: var(--stone);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-top: 3rem;
    display: flex;
    gap: 0.02em;
    opacity: 1;
}
.intro-title .letter {
    opacity: 0;
    display: inline-block;
    animation: letter-flash 600ms ease-out forwards;
    animation-delay: calc(1800ms + var(--i) * 80ms);
}

@keyframes letter-flash {
    0%   { opacity: 0; text-shadow: 0 0 24px var(--magenta); }
    40%  { opacity: 1; text-shadow: 0 0 18px var(--magenta), 0 0 40px rgba(255,45,123,.5); }
    100% { opacity: 1; text-shadow: 0 0 0 transparent; }
}

.intro-subtitle {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 1rem;
    color: var(--ash);
    letter-spacing: 0.08em;
    margin-top: 1.5rem;
    opacity: 0;
    animation: subtitle-in 500ms ease-out 3200ms forwards;
}
@keyframes subtitle-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===========================================================================
   Timeline spine — fixed horizontal line at 60vh, glows in accent color
   =========================================================================== */
.timeline-spine {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--spine-top);
    height: 2px;
    background: var(--accent);
    box-shadow:
        0 0 12px 2px var(--accent),
        0 0 30px 4px color-mix(in srgb, var(--accent) 35%, transparent);
    z-index: 15;
    pointer-events: none;
    transform-origin: left center;
    transform: scaleX(0);
    transition: background 600ms ease, box-shadow 600ms ease;
}
.timeline-spine.is-drawn {
    animation: spine-draw 800ms ease-out forwards;
    animation-delay: 1600ms;
}
@keyframes spine-draw {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
}

/* ===========================================================================
   Horizontal corridor — scroll-snap x mandatory
   =========================================================================== */
.corridor {
    position: relative;
    height: 100vh;
    width: 100vw;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-wrap: nowrap;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
}
.corridor::-webkit-scrollbar { display: none; }

/* Each era fills the viewport */
.era {
    position: relative;
    flex: 0 0 100vw;
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    overflow: hidden;
}

.era-ancient     { background: var(--void); }
.era-medieval    { background: var(--navy); }
.era-industrial  { background: var(--teal); }
.era-electric    { background: var(--void); }
.era-digital     { background: var(--navy); }
.era-horizon     { background: var(--teal); }

/* ---------- Gradient-mesh atmospheric backgrounds ---------- */
.mesh {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}
.mesh-ancient {
    background:
        radial-gradient(ellipse at 20% 40%, rgba(255,45,123,0.06) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 70%, rgba(0,240,255,0.04) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 15%, rgba(255,179,71,0.05) 0%, transparent 45%);
}
.mesh-medieval {
    background:
        radial-gradient(ellipse at 75% 35%, rgba(0,240,255,0.07) 0%, transparent 55%),
        radial-gradient(ellipse at 15% 75%, rgba(255,45,123,0.04) 0%, transparent 55%),
        radial-gradient(ellipse at 55% 85%, rgba(200,255,0,0.03) 0%, transparent 45%);
}
.mesh-industrial {
    background:
        radial-gradient(ellipse at 25% 25%, rgba(200,255,0,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 85% 60%, rgba(255,179,71,0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 40% 90%, rgba(0,240,255,0.04) 0%, transparent 45%);
}
.mesh-electric {
    background:
        radial-gradient(ellipse at 60% 30%, rgba(255,45,123,0.07) 0%, transparent 55%),
        radial-gradient(ellipse at 10% 80%, rgba(200,255,0,0.05) 0%, transparent 55%),
        radial-gradient(ellipse at 90% 80%, rgba(0,240,255,0.05) 0%, transparent 50%);
}
.mesh-digital {
    background:
        radial-gradient(ellipse at 30% 80%, rgba(0,240,255,0.07) 0%, transparent 55%),
        radial-gradient(ellipse at 75% 25%, rgba(255,45,123,0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(200,255,0,0.03) 0%, transparent 45%);
}
.mesh-horizon {
    background:
        radial-gradient(ellipse at 50% 50%, rgba(200,255,0,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 20% 20%, rgba(255,179,71,0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(0,240,255,0.04) 0%, transparent 50%);
}

/* ---------- Era icon ---------- */
.era-icon {
    position: absolute;
    left: 3vw;
    top: calc(var(--spine-top) - 24px);
    width: 48px;
    height: 48px;
    z-index: 5;
    animation: era-icon-breath 3.5s ease-in-out infinite;
}
@keyframes era-icon-breath {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50%      { opacity: 1;    transform: scale(1.04); }
}

/* ---------- Era head (title + summary) ---------- */
.era-head {
    position: absolute;
    top: 8vh;
    left: 8vw;
    max-width: 38ch;
    z-index: 6;
}
.era-index {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.28em;
    color: var(--ash);
    margin-bottom: 0.8rem;
}
.era-title {
    font-family: var(--font-display);
    font-variation-settings: "wdth" 125, "wght" 700;
    font-size: clamp(2.8rem, 6vw, 5rem);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    line-height: 1;
    margin-bottom: 1.2rem;
}
.era-ancient    .era-title,
.era-ancient    .era-icon,
.era-electric   .era-title,
.era-electric   .era-icon    { color: var(--magenta); }
.era-medieval   .era-title,
.era-digital    .era-title   { color: var(--cyan); }
.era-industrial .era-title,
.era-horizon    .era-title   { color: var(--chartreuse); }

.era-summary {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 1.05rem;
    color: var(--stone);
    line-height: 1.72;
}

/* ===========================================================================
   Timeline nodes inside each era
   =========================================================================== */
.timeline-nodes {
    position: absolute;
    inset: 0;
    z-index: 7;
    pointer-events: none;
}

.node {
    position: absolute;
    left: var(--x);
    top: 0;
    height: 100vh;
    width: 22ch;
    transform: translateX(-50%);
    pointer-events: auto;
}

.node-marker {
    position: absolute;
    top: var(--spine-top);
    left: 50%;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid currentColor;
    transform: translate(-50%, -50%);
    background: transparent;
    color: var(--accent);
    box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 50%, transparent);
    animation: node-breath 2.2s ease-in-out infinite;
    transition: background 300ms ease, box-shadow 300ms ease, transform 300ms ease;
    cursor: pointer;
    z-index: 3;
}
.era-ancient  .node-marker,
.era-electric .node-marker  { color: var(--magenta); }
.era-medieval .node-marker,
.era-digital  .node-marker  { color: var(--cyan); }
.era-industrial .node-marker,
.era-horizon    .node-marker { color: var(--chartreuse); }

@keyframes node-breath {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
    50%      { box-shadow: 0 0 0 8px color-mix(in srgb, currentColor 0%,  transparent),
                            0 0 14px 2px color-mix(in srgb, currentColor 45%, transparent); }
}

/* Radial candlelight halo — shown on hover/focus/active */
.node::before {
    content: "";
    position: absolute;
    top: var(--spine-top);
    left: 50%;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,179,71,0.10) 0%, rgba(255,179,71,0) 65%);
    transform: translate(-50%, -50%) scale(0);
    transition: transform 300ms ease-out;
    pointer-events: none;
    z-index: 1;
}
.node.is-hot::before,
.node:hover::before {
    transform: translate(-50%, -50%) scale(1);
}

.node.is-hot .node-marker,
.node:hover .node-marker {
    background: color-mix(in srgb, currentColor 20%, transparent);
    box-shadow: 0 0 12px 2px currentColor, 0 0 32px 6px color-mix(in srgb, currentColor 40%, transparent);
    transform: translate(-50%, -50%) scale(1.2);
}

/* Above-line text (cause) */
.node-above {
    position: absolute;
    bottom: calc(100vh - var(--spine-top) + 28px);
    left: 50%;
    width: 22ch;
    transform: translateX(-50%);
    text-align: left;
    opacity: 0.72;
    transition: opacity 300ms ease;
}
.node.is-hot .node-above,
.node:hover  .node-above { opacity: 1; }

.node-date {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    margin-bottom: 0.5rem;
}
.era-ancient  .node-date,
.era-electric .node-date  { color: var(--magenta); }
.era-medieval .node-date,
.era-digital  .node-date  { color: var(--cyan); }
.era-industrial .node-date,
.era-horizon    .node-date { color: var(--chartreuse); }

.node-cause {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.92rem;
    color: var(--stone);
    line-height: 1.55;
}

/* Below-line text (effect) */
.node-below {
    position: absolute;
    top: calc(var(--spine-top) + 28px);
    left: 50%;
    width: 22ch;
    transform: translateX(-50%);
    opacity: 0.72;
    transition: opacity 300ms ease;
}
.node.is-hot .node-below,
.node:hover  .node-below { opacity: 1; }

.node-effect {
    font-family: var(--font-body);
    font-weight: 300;
    font-style: italic;
    font-size: 0.92rem;
    color: var(--chartreuse);
    line-height: 1.55;
}

/* ===========================================================================
   Navigation candle (bottom-right) + radial menu
   =========================================================================== */
.nav-candle {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
    width: 44px;
    height: 56px;
    background: transparent;
    border: 0;
    cursor: pointer;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 0;
}
.nav-candle .flame {
    width: 12px;
    height: 20px;
    background: var(--amber);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    box-shadow: 0 0 12px 2px rgba(255,179,71,.6);
    margin-bottom: 2px;
    transition: background 600ms ease, box-shadow 600ms ease, transform 400ms ease;
    animation: flame-wobble 2.7s ease-in-out infinite;
}
.nav-candle .wax {
    width: 6px;
    height: 32px;
    background: var(--stone);
}
.nav-candle:hover .flame { transform: scale(1.15); }

.nav-candle[data-era="era-ancient"]    .flame,
.nav-candle[data-era="era-electric"]   .flame {
    background: var(--magenta);
    box-shadow: 0 0 12px 2px color-mix(in srgb, var(--magenta) 60%, transparent);
}
.nav-candle[data-era="era-medieval"]   .flame,
.nav-candle[data-era="era-digital"]    .flame {
    background: var(--cyan);
    box-shadow: 0 0 12px 2px color-mix(in srgb, var(--cyan) 60%, transparent);
}
.nav-candle[data-era="era-industrial"] .flame,
.nav-candle[data-era="era-horizon"]    .flame {
    background: var(--chartreuse);
    box-shadow: 0 0 12px 2px color-mix(in srgb, var(--chartreuse) 60%, transparent);
}

@keyframes flame-wobble {
    0%, 100% { transform: translateX(0) scale(1); }
    25%      { transform: translateX(-1px) scale(1.02); }
    60%      { transform: translateX(1px)  scale(0.98); }
}

/* Radial menu */
.radial-menu {
    position: fixed;
    inset: 0;
    z-index: 35;
    pointer-events: none;
    background: rgba(13,13,13,0);
    transition: background 400ms ease;
}
.radial-menu.is-open {
    pointer-events: all;
    background: rgba(13,13,13,0.82);
}

.radial-center {
    position: absolute;
    right: 2rem;
    bottom: 2rem;
    width: 44px;
    height: 56px;
    transform: translate(0, 0);
}

.radial-list {
    list-style: none;
    position: absolute;
    right: calc(2rem + 22px);
    bottom: calc(2rem + 28px);
    width: 0;
    height: 0;
    pointer-events: none;
}

.radial-item {
    position: absolute;
    top: 0;
    left: 0;
    transform:
        rotate(var(--angle))
        translateX(0)
        rotate(calc(-1 * var(--angle)));
    opacity: 0;
    transition: transform 500ms cubic-bezier(.2,.8,.2,1), opacity 300ms ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    pointer-events: none;
}
.radial-menu.is-open .radial-item {
    opacity: 1;
    pointer-events: auto;
    transform:
        rotate(var(--angle))
        translateX(-180px)
        rotate(calc(-1 * var(--angle)));
}

.radial-dot {
    display: block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--c);
    background: transparent;
    box-shadow: 0 0 10px 1px color-mix(in srgb, var(--c) 60%, transparent);
    transition: background 300ms ease;
}
.radial-item:hover .radial-dot,
.radial-item.is-current .radial-dot {
    background: var(--c);
}

.radial-label {
    font-family: var(--font-display);
    font-variation-settings: "wdth" 75, "wght" 500;
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    color: var(--stone);
    text-transform: uppercase;
    white-space: nowrap;
}

/* ===========================================================================
   Progress readout (top-left)
   =========================================================================== */
.progress-readout {
    position: fixed;
    top: 1.5rem;
    left: 1.8rem;
    z-index: 40;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    color: var(--ash);
    display: flex;
    gap: 0.6rem;
    align-items: center;
    pointer-events: none;
}
.readout-label { color: var(--ash); }
.readout-value { color: var(--stone); min-width: 4ch; }
.readout-sep   { color: var(--ash); opacity: 0.6; }

/* ===========================================================================
   Transition candle (briefly flashes center during era snap)
   =========================================================================== */
.transition-candle {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    z-index: 25;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}
.transition-candle.is-flash {
    animation: transition-flash 600ms ease-out forwards;
}
.tc-flame {
    width: 30px;
    height: 52px;
    background: var(--amber);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    box-shadow: 0 0 28px 4px rgba(255,179,71,.55);
    margin-bottom: 4px;
}
.tc-wax {
    width: 14px;
    height: 64px;
    background: var(--stone);
}
@keyframes transition-flash {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
    30%  { opacity: 1; }
    45%  { transform: translate(-50%, -50%) scale(1.08); }
    60%  { transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}

/* ===========================================================================
   Colophon (inside last era)
   =========================================================================== */
.colophon {
    position: absolute;
    bottom: 6vh;
    right: 6vw;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    color: var(--ash);
    text-transform: uppercase;
    z-index: 6;
}
.colophon-mono { opacity: 0.7; }

/* ===========================================================================
   Responsive: narrow viewports
   =========================================================================== */
@media (max-width: 700px) {
    .era-head { top: 6vh; left: 6vw; max-width: 28ch; }
    .era-title { font-size: clamp(2rem, 9vw, 3rem); }
    .era-summary { font-size: 0.95rem; }
    .node { width: 18ch; }
    .node-above, .node-below { width: 18ch; }
    .node-cause, .node-effect { font-size: 0.85rem; }
    .progress-readout { font-size: 0.65rem; letter-spacing: 0.14em; }
    .nav-candle { right: 1.2rem; bottom: 1.2rem; }
}
