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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    overflow: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header {
    background-color: #2c3e50;
    color: white;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

header h1 {
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    margin-bottom: 0.5rem;
}

header p {
    font-size: clamp(0.75rem, 1.5vw, 0.9rem);
    opacity: 0.9;
}

#control-panel {
    background-color: white;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
    overflow-x: auto;
    max-height: 200px; 
    overflow-y: auto;
    flex-shrink: 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 150px; 
    flex: 0 0 auto; 
}

.control-group label {
    font-weight: 600;
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    color: #34495e;
}

.scenario-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap; 
}

.scenario-btn {
    padding: 0.5rem 0.75rem;
    border: 2px solid #3498db;
    background-color: white;
    color: #3498db;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    white-space: nowrap;
}

.scenario-btn:hover {
    background-color: #3498db;
    color: white;
}

.scenario-btn.active {
    background-color: #3498db;
    color: white;
}

#ensemble-select, #sst-select {
    padding: 0.5rem;
    border: 2px solid #3498db;
    border-radius: 4px;
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    background-color: white;
    cursor: pointer;
    min-width: 120px;
}

#ensemble-select:focus, #sst-select:focus {
    outline: none;
    border-color: #2980b9;
}

#sst-selector {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
}

#sst-selector[style*="display: flex"] {
    display: flex !important;
}

.toggle-options {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    max-height: 120px;
    overflow-y: auto;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    color: #555;
    cursor: pointer;
    white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
    flex-shrink: 0;
}

.year-range-container {
    margin-top: 10px;
    margin-bottom: 5px;
    min-width: 250px;
    width: 100%;
    max-width: 400px;
}

.range-slider-container {
    flex: 1;
    position: relative;
    height: 30px;
}

.range-slider {
    position: relative;
    width: calc(100% - 24px); 
    height: 40px;
    display: flex;
    align-items: center;
    margin: 0 12px;
}

.slider-track {
    position: absolute;
    width: 100%;
    height: 6px;
    background-color: #e0e0e0;
    border-radius: 3px;
    z-index: 1;
    top: 50%;
    transform: translateY(-50%);
}

.slider-range {
    position: absolute;
    height: 6px;
    background-color: #3498db;
    border-radius: 3px;
    z-index: 2;
    top: 50%;
    transform: translateY(-50%);
    transition: left 0.1s ease, width 0.1s ease;
}

.year-slider {
    position: absolute;
    width: 100%;
    background: transparent;
    pointer-events: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    z-index: 3;
    margin: 0;
    height: 40px;
}

#year-slider-min {
    z-index: 3;
}

#year-slider-max {
    z-index: 4;
}

.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    pointer-events: all;
    border: 3px solid white;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 4;
}

.year-slider::-webkit-slider-thumb:hover {
    background: #2980b9;
    transform: scale(1.1);
}

.year-slider::-webkit-slider-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.year-slider::-webkit-slider-track {
    -webkit-appearance: none;
    background: transparent;
    height: 40px;
}

.year-slider::-moz-range-track {
    background: transparent;
    height: 40px;
}

.year-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    pointer-events: all;
    border: 3px solid white;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 4;
}

.year-slider::-moz-range-thumb:hover {
    background: #2980b9;
    transform: scale(1.1);
}

.year-slider::-moz-range-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.year-slider:active::-webkit-slider-thumb {
    cursor: grabbing;
}

.year-slider:active::-moz-range-thumb {
    cursor: grabbing;
}

.year-slider:focus {
    outline: none;
}

#year-display, .year-display {
    margin-top: 8px;
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    color: #34495e;
    font-weight: 600;
    text-align: center;
}

.export-btn {
    padding: 0.5rem 1rem;
    background-color: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    white-space: nowrap;
}

.export-btn:hover {
    background-color: #229954;
}

#map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 400px; 
}

#map {
    width: 100%;
    height: 100%;
    background-color: #f0f0f0;
}

#legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 1rem;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 500; 
    max-width: 300px;
    max-height: 400px;
    overflow-y: auto;
}

#legend h4 {
    margin-bottom: 0.5rem;
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    color: #2c3e50;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: clamp(0.7rem, 1vw, 0.8rem);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    flex-shrink: 0;
}

#info-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background-color: rgba(255, 255, 255, 0.98);
    padding: 1rem;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 1100; 
    max-width: 280px;
    max-height: 400px;
    overflow-y: auto;
    transition: opacity 0.3s ease;
}

#info-panel.hidden {
    display: none;
}

#info-panel h3 {
    margin-bottom: 0.5rem;
    font-size: clamp(0.9rem, 1.3vw, 1rem);
    color: #2c3e50;
}

#cyclone-details {
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    line-height: 1.5;
}

#cyclone-details p {
    margin-bottom: 0.3rem;
}

.scenario-comparison {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.98);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    max-width: 280px;
    z-index: 1050; 
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
}

.scenario-comparison.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}

.scenario-comparison h4 {
    margin: 0 0 10px 0;
    font-size: clamp(0.85rem, 1.2vw, 0.95rem);
    color: #2c3e50;
}

.comparison-item {
    margin: 8px 0;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: clamp(0.7rem, 1vw, 0.75rem);
}

.comparison-item .scenario-label {
    font-weight: bold;
    color: #34495e;
}

.comparison-item .metric {
    color: #666;
    margin-top: 4px;
}

.heatmap-active .leaflet-tile-pane {
    opacity: 0.6;
}

#map.zooming .leaflet-heatmap-layer {
    transition: opacity 0.2s ease-in-out;
    opacity: 0.8 !important;
}

.leaflet-heatmap-layer {
    z-index: 400 !important;
}

#map.heatmap-active .leaflet-tile-pane {
    filter: brightness(0.8) contrast(0.9);
    transition: filter 0.3s ease;
}

#heatmap-legend{
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    transition: all 0.3s ease;
}

#heatmap-legend h4{
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
}

.heatmap-gradient {
    position: relative;
    margin: 10px 0;
}

.gradient-bar {
    height: 20px;
    background: linear-gradient(to right, 
        rgba(255, 255, 200, 0.9) 0%,
        rgba(255, 255, 0, 1) 15%,
        rgba(255, 220, 0, 1) 30%,
        rgba(255, 165, 0, 1) 45%,
        rgba(255, 69, 0, 1) 60%,
        rgba(255, 0, 0, 1) 75%,
        rgba(139, 0, 0, 1) 90%,
        rgba(0, 0, 0, 1) 100%
    );
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.gradient-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    font-size: clamp(0.65rem, 0.9vw, 0.7rem);
    color: #666;
    font-weight: 500;
}

.zoom-lock-notice {
    position: absolute;
    top: 60px; 
    left: 50%;
    transform: translateX(-50%);
    background: rgba(44, 62, 80, 0.95);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 1200; 
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    pointer-events: none;
    animation: slideDown 0.3s ease-out;
}

.notice-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.notice-icon {
    font-size: 16px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    display: none;
}

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

.loader {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-overlay p {
    color: white;
    margin-top: 1rem;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
}

#loading-overlay.heatmap-loading {
    background: rgba(255, 255, 255, 0.95);
}

#loading-overlay.heatmap-loading p {
    color: #2c3e50;
    font-weight: 500;
}

.cyclone-marker {
    background-color: rgba(52, 152, 219, 0.7);
    border: 2px solid white;
    border-radius: 50%;
    width: 8px;
    height: 8px;
}

.genesis-marker {
    background-color: rgba(231, 76, 60, 0.8);
    border: 2px solid white;
    border-radius: 50%;
    width: 12px;
    height: 12px;
}

@media (max-width: 1440px) {
    .scenario-comparison {
        top: auto;
        bottom: 320px; 
        right: 20px;
        max-width: 250px;
    }
    
    #info-panel {
        max-width: 250px;
    }
    
    #control-panel {
        gap: 1rem;
        padding: 0.75rem;
        max-height: 180px;
    }
}

@media (max-width: 1024px) {
    #control-panel {
        flex-direction: column;
        align-items: stretch;
        max-height: none;
        overflow-y: visible;
    }
    
    .control-group {
        width: 100%;
    }
    
    .scenario-buttons {
        width: 100%;
    }
    
    .scenario-btn {
        flex: 1;
        min-width: 100px;
    }
    
    .scenario-comparison {
        left: 20px;
        right: 20px;
        bottom: auto;
        top: auto;
        bottom: 80px;
        max-width: none;
    }
    
    #legend {
        bottom: 10px;
        right: 10px;
        max-width: 180px;
        padding: 0.75rem;
    }
    
    #info-panel {
        right: 20px;
        left: auto;
        max-width: 220px;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.3rem;
    }
    
    header p {
        font-size: 0.8rem;
    }
    
    #control-panel {
        padding: 0.5rem;
        gap: 0.75rem;
    }
    
    .scenario-buttons {
        flex-direction: column;
    }
    
    .scenario-btn {
        width: 100%;
    }
    
    #legend {
        bottom: 10px;
        right: 10px;
        padding: 0.5rem;
        max-width: 150px;
        font-size: 0.75rem;
    }
    
    .scenario-comparison {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        max-width: none;
        border-radius: 8px 8px 0 0;
        max-height: 40vh;
        overflow-y: auto;
    }
    
    #info-panel {
        position: fixed;
        top: auto;
        bottom: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
        max-height: 30vh;
        overflow-y: auto;
    }
    
    .zoom-lock-notice {
        top: 10px;
        font-size: 12px;
        padding: 8px 15px;
    }
    
    .notice-icon {
        font-size: 14px;
    }
    
    .year-range-container {
        width: 100%;
        max-width: none;
    }
    
    .toggle-options {
        max-height: 80px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0.75rem;
    }
    
    header h1 {
        font-size: 1.1rem;
    }
    
    .control-group label {
        font-size: 0.75rem;
    }
    
    .checkbox-label {
        font-size: 0.7rem;
    }
    
    #legend {
        max-width: 120px;
        font-size: 0.7rem;
    }
    
    .legend-item {
        font-size: 0.65rem;
    }
    
    .legend-color {
        width: 15px;
        height: 15px;
    }
}

.leaflet-control {
    z-index: 800;
}

.leaflet-popup {
    z-index: 900;
}

.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

@media print {
    #control-panel {
        display: none;
    }
    
    header {
        padding: 0.5rem;
    }
    
    #map-container {
        height: 100vh;
    }
}


#density-legend {
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-height: 400px;
    overflow-y: auto;
}

#density-legend h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #2c3e50;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 5px;
}

#density-legend .density-legend-items {
    display: flex;
    flex-direction: column-reverse; /* Show low values at bottom, high at top */
    gap: 1px;
}

#density-legend .legend-item {
    display: flex;
    align-items: center;
    padding: 1px 0;
    transition: background-color 0.2s;
}

#density-legend .legend-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

#density-legend .legend-color {
    flex-shrink: 0;
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Compact view for smaller screens */
@media (max-height: 800px) {
    #density-legend {
        max-height: 300px;
    }
    
    #density-legend .legend-item {
        margin: 1px 0;
    }
    
    #density-legend .legend-color {
        width: 20px !important;
        height: 12px !important;
    }
}

/* Scrollbar styling for legend */
#density-legend::-webkit-scrollbar {
    width: 6px;
}

#density-legend::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 3px;
}

#density-legend::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

#density-legend::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}
#source-file { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }