:root {
    --primary-color: #a88157;
    --primary-dark: #855d3a;
    --primary-light: #d4c7b4;
    --bg-color: #f5f0e8;
    --card-bg: #ffffff;
    --text-main: #2d2a26;
    --text-muted: #6b6258;
    --border-color: rgba(224, 214, 200, 0.6);
    --shadow-sm: 0 2px 8px rgba(61, 58, 53, 0.08);
    --shadow-md: 0 4px 16px rgba(61, 58, 53, 0.12);
    --shadow-lg: 0 20px 60px rgba(61, 58, 53, 0.1);
    --header-height: 64px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-color);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Typography */
h1, h2, h3, h4 {
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h1 { font-size: clamp(1.25rem, 5vw, 1.75rem); font-weight: 800; }
h2 { font-size: clamp(1.1rem, 4vw, 1.5rem); font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }

small { font-size: 0.875rem; font-weight: 500; color: var(--text-muted); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.app-header h1 small {
    display: none;
}

/* Version Number Styling */
.app-version {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted);
    opacity: 0.7;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 1001;
}

.menu-icon, .menu-icon::before, .menu-icon::after {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-main);
    transition: var(--transition);
    position: relative;
}

.menu-icon::before, .menu-icon::after {
    content: '';
    position: absolute;
}

.menu-icon::before { top: -8px; }
.menu-icon::after { bottom: -8px; }

.menu-toggle[aria-expanded="true"] .menu-icon { background: transparent; }
.menu-toggle[aria-expanded="true"] .menu-icon::before { transform: rotate(45deg); top: 0; }
.menu-toggle[aria-expanded="true"] .menu-icon::after { transform: rotate(-45deg); bottom: 0; }

.header-controls {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 1rem;
    display: none;
    flex-direction: column;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    border-bottom: 1px solid var(--border-color);
}

.header-controls.active {
    display: flex;
}

.map-toggle {
    display: flex;
    background: var(--bg-color);
    padding: 4px;
    border-radius: 12px;
}

.basemap-btn {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
}

.basemap-btn:hover {
    background: rgba(168, 129, 87, 0.08);
}

.basemap-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.basemap-btn.active {
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
}

.language-toggle {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
    transition: var(--transition);
}

.language-toggle:hover {
    border-color: var(--primary-color);
    background: var(--bg-color);
}

.language-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.map-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    background: var(--card-bg);
    min-width: 0; /* Prevent flex item from overflowing */
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.map-title {
    color: var(--primary-dark);
}

/* Mobile era control removed - timeline now visible on map */

.map-wrapper {
    flex: 1;
    min-height: 400px;
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
}

#historyMap {
    height: 100%;
    width: 100%;
    min-height: 400px; /* Ensure minimum height for Leaflet */
}

.legend {
    padding: 0.75rem 0;
}

.legend h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

/* Sidebar as Bottom Sheet on Mobile */
.sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    z-index: 2000;
    border-top-left-radius: 1.5rem;
    border-top-right-radius: 1.5rem;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
    transform: translateY(calc(100% - 60px));
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.sidebar.expanded {
    transform: translateY(0);
}

.sidebar-handle {
    height: 60px;
    width: 100%;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-main);
    position: relative;
}

/* Drag Indicator */
.sidebar-handle::before {
    content: '';
    position: absolute;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.sidebar-handle::after {
    content: '▲';
    font-size: 0.8rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--primary-color);
}

.sidebar.expanded .sidebar-handle::after {
    transform: rotate(180deg);
}

.sidebar-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tabs {
    display: flex;
    background: var(--bg-color);
    padding: 0 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 1rem 0.5rem;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--text-muted);
    position: relative;
    min-height: 48px;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(168, 129, 87, 0.05);
}

.tab-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.tab-btn.active {
    color: var(--primary-dark);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    transition: opacity 0.15s ease-in-out;
}

/* Timeline (now positioned above map) */
.timeline-viewport {
    width: 100%;
    max-width: 100%; /* Prevent overflow */
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.75rem;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 0.5rem 0;
    position: relative;
}

/* Scroll Fade Indicators */
.timeline-viewport::before,
.timeline-viewport::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    pointer-events: none;
    z-index: 10;
    opacity: 0.7;
}

.timeline-viewport::before {
    left: 0;
    background: linear-gradient(to right, var(--card-bg), transparent);
}

.timeline-viewport::after {
    right: 0;
    background: linear-gradient(to left, var(--card-bg), transparent);
}

.timeline-viewport::-webkit-scrollbar { display: none; }

.timeline-container {
    display: flex;
    padding: 0 1rem;
    gap: 0.75rem;
    position: relative;
    align-items: center;
}

.tl-item {
    flex: 0 0 auto;
    width: 160px;
    padding: 0.75rem;
    padding-left: 1.25rem;
    background: var(--bg-color);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    position: relative;
    min-height: 80px;
}

/* Timeline Progress Dot */
.tl-item::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-color);
    border: 2px solid var(--card-bg);
    transition: var(--transition);
    z-index: 2;
}

/* Horizontal Timeline Connector */
.tl-item::after {
    content: '';
    position: absolute;
    left: calc(100% + 0.375rem);
    top: 50%;
    transform: translateY(-50%);
    width: 0.75rem;
    height: 2px;
    background: var(--border-color);
    transition: var(--transition);
    z-index: 1;
}

.tl-item:last-child::after {
    display: none;
}

.tl-item.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(168, 129, 87, 0.15);
    transform: translateY(-2px);
}

/* Active Timeline Dot - Filled */
.tl-item.active::before {
    background: var(--primary-color);
    border-color: var(--primary-light);
    width: 12px;
    height: 12px;
    box-shadow: 0 0 0 3px rgba(168, 129, 87, 0.2);
}

/* Active Connector - Solid Line */
.tl-item.active::after {
    background: var(--primary-color);
    height: 3px;
}

/* Hover State */
.tl-item:hover:not(.active) {
    background: var(--card-bg);
    border-color: var(--primary-light);
    transform: scale(1.02);
    box-shadow: var(--shadow-sm);
}

/* Focus State for Accessibility */
.tl-item:focus,
.tl-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(168, 129, 87, 0.1);
}

.tl-section-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 800;
    line-height: 1.3;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.tl-period {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    opacity: 0.85;
    line-height: 1.4;
}

.tl-summary, .accuracy-badge {
    display: none;
}

/* Accuracy Badge Base Styling */
.accuracy-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
    margin-left: 0.35rem;
    vertical-align: middle;
    opacity: 0.8;
}

.accuracy-high { background: rgba(34, 197, 94, 0.15); color: #15803d; }
.accuracy-medium { background: rgba(251, 191, 36, 0.15); color: #b45309; }
.accuracy-low { background: rgba(239, 68, 68, 0.15); color: #b91c1c; }

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-in;
}

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

.loading-overlay.active { display: flex; }

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--primary-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.sidebar-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Leaflet Customization */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-md) !important;
    border-radius: 8px !important;
    overflow: hidden !important;
}

.leaflet-control-zoom a {
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
    background: var(--card-bg) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color) !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    transition: var(--transition) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-color) !important;
    color: var(--primary-color) !important;
}

.leaflet-control-zoom a:focus {
    outline: 2px solid var(--primary-color) !important;
    outline-offset: -2px !important;
}

/* Responsive Overrides */

/* Tablets & Desktop (min-width: 768px) */
@media (min-width: 768px) {
    :root {
        --header-height: 80px;
    }

    .app-header h1 small { 
        display: inline; 
        margin-left: 0.75rem;
    }

    .menu-toggle { display: none; }

    .header-controls {
        position: static;
        display: flex;
        flex-direction: row;
        box-shadow: none;
        border: none;
        padding: 0;
        width: auto;
    }

    .main-content {
        flex-direction: row;
        height: calc(100vh - var(--header-height));
    }

    .map-section {
        flex: 1;
        padding: 1.5rem;
    }

    .mobile-era-control { display: none; }

    .sidebar {
        position: static;
        width: 380px;
        transform: none;
        border-radius: 0;
        border-left: 1px solid var(--border-color);
        max-height: none;
        box-shadow: none;
    }

    .sidebar-handle {
        pointer-events: none;
        padding: 1.5rem;
        height: auto;
    }

    .sidebar-handle::after { display: none; }

    .sidebar-backdrop { display: none; }

    .tl-item {
        width: 240px;
        gap: 0.5rem;
    }

    .tl-summary {
        display: block;
        font-size: 0.75rem;
        margin-top: 0.5rem;
        color: var(--text-muted);
        line-height: 1.4;
        opacity: 0.9;
    }
    
    .accuracy-badge {
        display: inline-block;
    }
}

/* Large Screens */
@media (min-width: 1200px) {
    .sidebar {
        width: 440px;
    }

    .tl-item {
        width: 300px;
    }
    
    .timeline-container {
        gap: 1rem;
    }
    
    .tl-item::after {
        width: 1rem;
    }
}

/* Cards & Content Styles (from existing app.css but refactored) */
.sub-event, .scholar-card {
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    transition: var(--transition);
    cursor: pointer;
}

.sub-event:hover, .scholar-card:hover,
.sub-event.selected {
    border-color: var(--primary-color);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.sub-event.selected {
    background: var(--primary-light);
    border-width: 2px;
}

.sub-event:focus, .scholar-card:focus,
.sub-event:focus-visible, .scholar-card:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.scholar-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.scholar-initials {
    width: 48px;
    height: 48px;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 800;
}

.scholar-info h4 { font-size: 1rem; margin-bottom: 0.2rem; }
.scholar-info p { font-size: 0.85rem; color: var(--text-muted); }

.detail-header { 
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem; 
}

.detail-avatar {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.detail-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
}

.detail-summary { margin-bottom: 1.5rem; }

.back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: none;
    color: var(--primary-dark);
    font-weight: 700;
    cursor: pointer;
    padding: 0.5rem 0;
    transition: var(--transition);
}

.back-btn:hover {
    color: var(--primary-color);
    gap: 0.75rem;
}

.back-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 4px;
    border-radius: 4px;
}

.map-action-btn {
    background: transparent;
    color: var(--primary-color);
    border: 1.5px solid var(--primary-color);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.map-action-btn:hover { 
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(168, 129, 87, 0.25);
    transform: translateY(-1px);
}

.map-action-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.map-action-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

/* New detail sections */
.detail-reference, .detail-video {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.detail-reference:hover, .detail-video:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.video-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
    overflow: hidden;
    max-width: 100%;
    background: #000;
    margin-bottom: 0.75rem;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.video-caption {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.4;
    padding-top: 0.25rem;
}

.detail-reference strong {
    display: block;
    color: var(--text-main);
    font-size: 0.95rem;
}

.detail-reference span {
    display: block;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

.detail-work {
    background: #f8f5f2;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--primary-color);
}
