:root {
    /* Typography */
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Space Mono', 'SF Mono', Monaco, 'Cascadia Code', monospace;

    /* Font Sizes */
    --font-size-xs: 0.5625rem;  /* 9px */
    --font-size-sm: 0.6875rem;  /* 11px */
    --font-size-base: 0.9375rem; /* 15px */
    --font-size-lg: 1.5rem;      /* 24px */
    --font-size-xl: 2rem;        /* 32px */

    /* Colors - Warm Minimal */
    --color-bg: #fafaf9;
    --color-surface: #ffffff;
    --color-text: #1c1917;
    --color-text-muted: #78716c;
    --color-border: #e7e5e4;
    --color-accent: #0f172a;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);

    /* Timeline */
    --timeline-width: 24px;
    --timeline-track-width: 2px;
    --timeline-marker-size: 6px;
    --timeline-color: #d4d4d4;
    --timeline-color-active: #737373;
    --timeline-color-collapsed: #a3a3a3;

    /* Timeline Fade Effect */
    --timeline-selected-width: 48px;
    --timeline-normal-width: 4px;
    --timeline-fade-radius: 240px;

    /* Transitions */
    --transition-fast: 0.1s ease;
    --transition-base: 0.2s ease;
    --transition-smooth: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.6s cubic-bezier(0.4, 0, 0.2, 1);

    /* Spacing - Consistent 4px base scale */
    --spacing-2xs: 4px;
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;

    /* Border Radius */
    --radius-sm: 2px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-xl: 8px;
    --radius-full: 50%;

    /* Canvas colors for JS sync */
    --color-canvas-country: #f8f8f7;
    --color-canvas-border: #a8a29e;
    --color-canvas-shadow: rgba(0, 0, 0, 0.12);
    --color-canvas-text: #ffffff;

    /* Opacity values */
    --opacity-low: 0.3;
    --opacity-medium: 0.4;
    --opacity-high: 0.6;
    --opacity-full: 1.0;

    /* Transform scales */
    --scale-subtle: 1.1;
    --scale-normal: 1.2;
    --scale-medium: 1.3;
    --scale-large: 1.5;
    --scale-xlarge: 1.8;

    /* Z-index layers */
    --z-tooltip: 100;
    --z-timeline: 50;
    --z-thumb: 10;

    /* Line heights */
    --line-height-tight: 1.5;
    --line-height-normal: 1.6;

    /* Letter spacing */
    --letter-spacing-tight: -0.01em;
    --letter-spacing-xtight: -0.02em;

    /* Timeline dimensions */
    --timeline-full-width: 156px;
    --timeline-thumb-size: 14px;
    --timeline-track-left: 108px;
    --timeline-label-width: 100px;
    --timeline-year-left: 116px;
    --timeline-mobile-width: 20px;

    /* RGBA color components */
    --rgb-text: 28, 25, 23;
    --rgb-surface: 255, 255, 255;
}

/* ========================================
   Utility Classes
   ======================================== */

/* Screen reader only content */
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Hide scrollbar */
.hide-scrollbar {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Focus outline styles */
.focus-outline:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.focus-outline-round:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 0;
    border-radius: var(--radius-full);
}

/* ========================================
   Base Styles
   ======================================== */

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    font-weight: 400;
    font-size: var(--font-size-base);
    line-height: 1.6;
    letter-spacing: -0.01em;
    background-color: var(--color-bg);
    color: var(--color-text);
    margin: 0;
    padding: var(--spacing-lg);
    height: 100vh;  /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height for modern browsers */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

h1 {
    font-weight: 700;
    font-size: var(--font-size-xl);
    letter-spacing: -0.02em;
    margin: 0 0 var(--spacing-xs) 0;
}

header {
    margin-bottom: var(--spacing-sm);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#journey {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#journey p {
    margin: 0 0 var(--spacing-md) 0;
}

footer {
    margin-top: var(--spacing-xl);
    flex-shrink: 0;
}

footer p {
    color: var(--color-text-muted);
    margin: 0 0 var(--spacing-xs) 0;
}

footer ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: var(--spacing-lg);
    flex-wrap: wrap;
}

footer li {
    margin: 0;
}

footer a {
    color: var(--color-text);
    text-decoration: none;
    border-bottom: 1px solid var(--color-border);
    transition: border-color var(--transition-base);
}

footer a:hover,
footer a:focus {
    border-bottom-color: var(--color-text);
}

footer a:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

#tooltip {
    position: absolute;
    display: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-sm);
    pointer-events: none;
    z-index: 100;
    line-height: 1.5;
    max-width: 250px;
}

#tooltip strong {
    font-weight: 600;
}

/* Time Machine */
#time-machine-wrapper {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#time-scroll-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    /* Scrollbar hiding handled by .hide-scrollbar utility class in HTML */
}

#time-scroll-spacer {
    width: 100%;
    pointer-events: none;
}

#map-viewport {
    position: absolute;
    top: var(--spacing-xs);
    left: var(--spacing-xs);
    right: var(--spacing-xs);
    bottom: var(--spacing-xs);
    pointer-events: none;
    overflow: visible;
}

#map-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    pointer-events: auto;
}

#map {
    border-radius: var(--radius-xl);
}

#map-overlays {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.map-overlay-btn {
    transition: opacity var(--transition-base);
}

.map-overlay-btn:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 0;
    border-radius: var(--radius-full);
}

.map-overlay-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 0;
}

/* Screen reader text uses .sr-only utility class */

/* Pulsing animation for current position */
@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

.map-overlay-btn.i-am-here::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: var(--radius-full);
    background: rgba(28, 25, 23, 0.3);
    animation: pulse-ring 2s ease-out infinite;
}

/* Current Date Display */
#current-date-display {
    position: absolute;
    top: var(--spacing-sm);
    left: var(--spacing-sm);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(var(--spacing-xs));
    -webkit-backdrop-filter: blur(var(--spacing-xs));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-2xs) var(--spacing-sm);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    font-weight: 400;
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    z-index: 50;
    pointer-events: none;
}

/* Timeline - Universal Vertical Design */
#timeline {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-lg);
    bottom: var(--spacing-sm);
    width: 156px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    pointer-events: auto;
    z-index: 50;

    /* Performance optimization */
    contain: layout style paint;
    will-change: transform;
}

#timeline-track {
    position: absolute;
    top: var(--spacing-sm);
    bottom: var(--spacing-sm);
    left: 108px;
    width: var(--timeline-track-width);
    background: var(--timeline-color);
    border-radius: var(--radius-sm);
    /* Prevent mobile browsers from treating timeline scrubs as page scroll/gestures */
    touch-action: none;
}

#timeline-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: var(--timeline-color-active);
    border-radius: var(--radius-sm);
}

#timeline-thumb {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--color-surface);
    border: 2px solid var(--timeline-color-active);
    border-radius: var(--radius-full);
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    transition: transform var(--transition-smooth), box-shadow var(--transition-fast);
    box-shadow: var(--shadow-sm);
    z-index: 10;
    /* Critical for smooth dragging on mobile (prevents scroll/zoom gestures during drag) */
    touch-action: none;
}

#timeline-thumb:hover {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: var(--shadow-md);
}

#timeline-thumb:active,
#timeline-thumb.dragging {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: var(--shadow-md);
}

/* Timeline Elements - Scroll Reveal */
#timeline-markers,
#timeline-years,
#timeline-labels {
    position: absolute;
    top: var(--spacing-sm);
    bottom: var(--spacing-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

#timeline[data-revealed="true"][data-scrolling="true"] #timeline-markers,
#timeline[data-revealed="true"][data-scrolling="true"] #timeline-years,
#timeline[data-revealed="true"][data-scrolling="true"] #timeline-labels {
    opacity: 1;
    pointer-events: auto;
}

#timeline[data-revealed="true"][data-scrolling="false"] #timeline-markers,
#timeline[data-revealed="true"][data-scrolling="false"] #timeline-years,
#timeline[data-revealed="true"][data-scrolling="false"] #timeline-labels {
    opacity: 0;
    pointer-events: none;
}

/* Collapsed mode styling - thinner line, thinner circle, lighter progress */
#timeline[data-scrolling="false"] #timeline-track {
    width: 1px;
    transition: width var(--transition-base);
}

#timeline[data-scrolling="false"] #timeline-progress {
    background: var(--timeline-color-collapsed);
    transition: background var(--transition-base);
}

#timeline[data-scrolling="false"] #timeline-thumb {
    border-width: 1px;
    border-color: var(--timeline-color-collapsed);
    transition: border-color var(--transition-base), border-width var(--transition-base);
}

/* Timeline Markers - Hidden */
#timeline-markers {
    display: none;
}

.timeline-marker {
    position: absolute;
    width: var(--timeline-marker-size);
    height: var(--timeline-marker-size);
    background: var(--timeline-color);
    border-radius: var(--radius-full);
    left: 0;
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: background-color var(--transition-base), transform var(--transition-smooth);
}

.timeline-marker:hover {
    transform: translate(-50%, -50%) scale(1.5);
}

.timeline-marker.active {
    background: var(--timeline-color-active);
    transform: translate(-50%, -50%) scale(1.3);
}

.timeline-marker.visible {
    background: var(--timeline-color-active);
}

/* Timeline Year Labels */
#timeline-years {
    left: 116px;
    width: 40px;
}

.timeline-year {
    position: absolute;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    text-align: left;
    transform: translateY(-50%);
    white-space: nowrap;
    opacity: 0.4;
    cursor: pointer;
}

.timeline-year:hover {
    opacity: 1;
}

/* Timeline City Labels */
#timeline-labels {
    left: 0;
    width: 100px;
    text-align: right;
    pointer-events: none;
}

.timeline-label {
    position: absolute;
    right: 0;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    white-space: nowrap;
    text-align: right;
    transform: translateY(-50%);
    opacity: 0.4;
}

@media (max-width: 768px) {
    body {
        padding: var(--spacing-md);
    }

    h1 {
        font-size: var(--font-size-lg);
    }

    footer ul {
        gap: var(--spacing-md);
    }

    /* Timeline - Vertical Mobile Adjustments */
    :root {
        --timeline-selected-width: 36px;
        --timeline-fade-radius: 180px;
    }

    #timeline {
        position: fixed;
        right: var(--spacing-2xs);
        width: 20px;
        /* height and top set dynamically via JS to match map container */
    }

    #timeline-track {
        left: var(--spacing-xs);
    }

    #timeline-years {
        display: none;
    }

    #timeline-labels {
        display: none;
    }

    .timeline-year {
        font-size: var(--font-size-xs);
    }

    .timeline-label {
        font-size: var(--font-size-xs);
    }

    #current-date-display {
        top: var(--spacing-xs);
        left: var(--spacing-xs);
        padding: var(--spacing-2xs) var(--spacing-xs);
        font-size: var(--font-size-xs);
    }
}
