body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: Arial, sans-serif;
}

#map {
    height: 100vh;
    width: 100vw;
    z-index: 1; /* Keep map beneath the controls */
}

/* =========================================
   DARK THEME: Time Machine Floating Panel 
   ========================================= */
#time-machine-panel {
    position: absolute;
    bottom: 30px;
    left: 10px;
    z-index: 1000;
    
    /* Dark, semi-transparent dashboard background */
    background: rgba(25, 28, 36, 0.80); 
    
    padding: 15px 20px;
    border-radius: 8px;
    /* Stronger shadow and a subtle light border for depth */
    box-shadow: 0 6px 12px rgba(0,0,0,0.6); 
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    width: 33vw; 
    min-width: 380px; 
    max-width: 600px;
    
    color: #ecf0f1; /* Light text */
}

#time-machine-panel h4 {
    margin: 0 0 10px 0;
    color: #ff6b81; /* Brighter accent red for dark mode */
    font-size: 1.2rem;
}

.slider-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* =========================================
   DARK THEME: Map Popups (Volcanoes & Quakes)
   ========================================= */

/* 1. Override Leaflet's default white bubble */
.leaflet-popup-content-wrapper {
    background: rgba(25, 28, 36, 0.90) !important; /* Dark, semi-transparent */
    color: #ecf0f1 !important;
    padding: 0; 
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.6) !important;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* 2. Color the little pointer arrow to match the dark wrapper */
.leaflet-popup-tip {
    background: rgba(25, 28, 36, 0.90) !important;
    box-shadow: none !important;
}

/* 3. Make the default 'X' close button white and visible */
.leaflet-popup-close-button {
    color: #ffffff !important;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    padding: 4px 10px 0 0 !important;
}
.leaflet-popup-close-button:hover {
    color: #ff6b81 !important; /* Accent red on hover */
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important; 
}

/* 4. The Volcano static header (Earthquakes use JS inline styles) */
.volcano-popup-header {
    background-color: rgba(179, 57, 57, 0.95); /* Deep transparent red */
    color: white;
    padding: 12px 15px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.volcano-popup-header h3 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: bold;
}

.volcano-popup-header p {
    margin: 3px 0 0 0;
    font-size: 0.85rem;
    font-style: italic;
    opacity: 0.9;
}

/* 5. The dark transparent body */
.volcano-popup-body {
    padding: 15px;
    background-color: transparent; /* Lets the wrapper's dark transparency show */
}

.volcano-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 0.85rem;
}

/* 6. Dark inset grid boxes matching your Time Machine inputs */
.stat-box {
    background: rgba(0, 0, 0, 0.4); 
    padding: 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.stat-label {
    display: block;
    font-weight: bold;
    color: #a4b0be; /* Light gray for dark theme */
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.stat-value {
    color: #ecf0f1; /* White text */
    font-weight: bold;
}

/* 7. Summary text specific to volcanoes */
.volcano-summary {
    max-height: 120px;
    overflow-y: auto;
    font-size: 0.85rem;
    color: #dcdde1; 
    line-height: 1.4;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Custom scrollbar for the summary text so it doesn't look like an ugly default gray bar */
.volcano-summary::-webkit-scrollbar {
    width: 6px;
}
.volcano-summary::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2); 
}
.volcano-summary::-webkit-scrollbar-thumb {
    background: #576574; 
    border-radius: 3px;
}

/* Dark Theme: Boundary Input Boxes */
.bound-group {
    display: flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.4); /* Dark inset look */
    border: 1px solid #4b4b4b;
    border-radius: 4px;
    overflow: hidden;
}

.year-input {
    width: 45px;
    padding: 4px 2px 4px 6px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #f1f2f6; /* Light text inside inputs */
    border: none;
    background: transparent;
    text-align: right;
}

.year-input:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.1);
}

.era-select {
    border: none;
    border-left: 1px solid #4b4b4b;
    background: #2f3640; /* Slightly lighter gray for dropdown */
    padding: 5px 2px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #f1f2f6;
    cursor: pointer;
    outline: none;
}

/* Hide up/down arrows */
.year-input::-webkit-inner-spin-button, 
.year-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.year-input { -moz-appearance: textfield; }

/* =========================================
   DARK THEME: Native Leaflet Legend 
   ========================================= */
.volcano-legend {
    background: rgba(25, 28, 36, 0.80); /* Matches panel transparency */
    padding: 12px 15px;
    border-radius: 8px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ecf0f1; /* Light text */
    font-size: 0.85rem;
    line-height: 1.5;
}

.volcano-legend h4 {
    margin: 0 0 10px 0;
    font-size: 0.95rem;
    color: #ff6b81; /* Brighter accent */
    text-transform: uppercase;
    border-bottom: 1px solid #4b4b4b; /* Dark divider line */
    padding-bottom: 5px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-item i {
    width: 14px;
    height: 14px;
    border: 1px solid rgba(255,255,255,0.2); /* Soften the border around the color dots */
    border-radius: 50%;
    margin-right: 10px;
    display: inline-block;
    box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Dark Theme: Dual-Handle Range Slider */
.dual-slider-wrapper {
    position: relative;
    flex-grow: 1;
    margin: 0 15px;
    height: 30px;
    display: flex;
    align-items: center;
}

.slider-track {
    position: absolute;
    width: 100%;
    height: 6px;
    background: #576574; /* Darker track */
    border-radius: 3px;
    z-index: 1;
}

.dual-slider-wrapper input[type="range"] {
    position: absolute;
    width: 100%;
    -webkit-appearance: none;
    background: transparent;
    pointer-events: none; 
    z-index: 2;
}

/* Custom Thumbs for Dark Mode */
.dual-slider-wrapper input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #ff4757; /* Vibrant red thumb */
    border: 2px solid #2f3640; /* Dark outline */
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.6);
}

.dual-slider-wrapper input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 18px;
    height: 18px;
    background: #ff4757;
    border: 2px solid #2f3640;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.6);
}

/* =========================================
   DARK THEME: Loading Overlay 
   ========================================= */
#loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    /* Matches the dark dashboard transparency */
    background: rgba(25, 28, 36, 0.80); 
    
    padding: 15px 25px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1); 
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 2000; 
    transition: opacity 0.4s ease;
}

.loading-text {
    font-family: Arial, sans-serif;
    color: #ecf0f1; /* Light text for dark mode */
}

.loading-text strong {
    font-size: 1rem;
    color: #ff6b81; /* Brighter accent red */
}

.loading-text span {
    font-size: 0.8rem;
    color: #a4b0be; /* Lighter grey for subtext */
}

/* The animated CSS ring (Updated for dark mode) */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #4b4b4b; /* Dark grey track */
    border-top: 3px solid #ff6b81; /* Bright red spinning accent */
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* =========================================
   DARK THEME: Leaflet Panel Layers Override 
   ========================================= */

/* Main Container */
.leaflet-control.leaflet-panel-layers {
    background: rgba(25, 28, 36, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 8px !important;
    box-shadow: 0 6px 12px rgba(0,0,0,0.6) !important;
    color: #ecf0f1 !important;
}

/* Ensure inner wrappers don't block the background */
.leaflet-panel-layers-base,
.leaflet-panel-layers-overlays {
    background: transparent !important;
}

/* The "Available Layers" Title */
.leaflet-panel-layers-title {
    color: #ecf0f1 !important;
    border-bottom: 1px solid #4b4b4b !important;
}

/* The Accordion Headers (Solid dark slate) */
.leaflet-panel-layers-grouplabel {
    background: #2f3640 !important; 
    color: #ff6b81 !important;
    border-top: 1px solid #4b4b4b !important;
    border-bottom: 1px solid #4b4b4b !important;
}

/* The Accordion Body Container */
.leaflet-panel-layers-group {
    background: #191c24 !important; /* Forces the entire background dark */
}

/* Individual Layer Rows (Radio buttons area) */
.leaflet-panel-layers-item {
    background: #191c24 !important; /* Solid dark color completely hides the gray! */
    color: #ecf0f1 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.leaflet-panel-layers-item:last-child {
    border-bottom: none !important;
}

.leaflet-panel-layers-item:hover {
    background: #2f3640 !important; /* Slightly lighter dark gray on hover */
}

/* Turn the black expand/collapse arrows white */
.leaflet-panel-layers-icon {
    filter: invert(1) brightness(0.9) !important;
}

/* =========================================
   DARK THEME: Top Navigation & Modal
   ========================================= */

/* Center the buttons at the top of the map */
#top-nav-buttons {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    gap: 10px;
}

/* Compact, scalable button design */
.nav-btn {
    background: rgba(25, 28, 36, 0.90);
    color: #ecf0f1;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    
    /* Target scale constraints */
    min-width: 60px; 
    min-height: 50px;
    transition: all 0.2s ease;
}

.nav-btn i {
    font-size: 1.1rem;
    margin-bottom: 4px;
    color: #a4b0be;
}

.nav-btn span {
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
}

.nav-btn:hover {
    background: #2f3640;
    border-color: #ff6b81;
}

.nav-btn:hover i, .nav-btn:hover span {
    color: #ff6b81; /* Accent color on hover */
}

/* Document Modal Styling */
#doc-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background: rgba(25, 28, 36, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.8);
    width: 320px;
    max-width: 90vw;
    padding: 20px;
    color: #ecf0f1;
    display: none; /* Hidden by default */
}

#doc-modal.modal-visible {
    display: block;
}

.close-modal {
    float: right;
    cursor: pointer;
    font-size: 1.5rem;
    color: #a4b0be;
    line-height: 1;
}

.close-modal:hover {
    color: #ff6b81;
}

#modal-title {
    margin: 0 0 15px 0;
    border-bottom: 1px solid #4b4b4b;
    padding-bottom: 10px;
    color: #ff6b81;
    font-size: 1.2rem;
}

#modal-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

#modal-list li {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
}

#modal-list i {
    margin-right: 10px;
    color: #74b9ff; /* Blue icon for documents */
}

#modal-list a {
    color: #ecf0f1;
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

#modal-list a:hover {
    color: #74b9ff;
    text-decoration: underline;
}

/* Custom scrollbar for the document list */
#modal-list::-webkit-scrollbar { width: 6px; }
#modal-list::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); }
#modal-list::-webkit-scrollbar-thumb { background: #576574; border-radius: 3px; }
