/* ============================================
   DARK COSMOS THEME 
   Primary Accent: #38BDF8 (sky blue)
   Space Accent:   #F472B6 (rose pink)
   Success:        #34D399 (emerald)
   Warning:        #FBBF24 (amber)
   Background:     #000000 → #0A0F1A
   ============================================ */

:root {
    --primary-internet: #38BDF8;
    --primary-space: #F472B6;
    --accent-1: #34D399;
    --accent-2: #FBBF24;

    /* Dark surface layers */
    --neutral-dark: #E2E8F0;
    --neutral-light: #1E293B;
    --neutral-bg: #000000;

    /* Surface levels */
    --surface-1: #0A0F1A;
    --surface-2: #0F172A;
    --surface-3: #1E293B;
    --surface-4: #334155;

    /* Borders */
    --border-subtle: rgba(56, 189, 248, 0.12);
    --border-accent: rgba(56, 189, 248, 0.35);

    /* Glows */
    --glow-internet: 0 0 20px rgba(56, 189, 248, 0.25);
    --glow-space: 0 0 20px rgba(244, 114, 182, 0.25);

    --shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--neutral-bg);
    color: var(--neutral-dark);
    line-height: 1.6;
}

/* Header */
.header {
    background: var(--surface-1);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(56, 189, 248, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 50%, rgba(244, 114, 182, 0.06) 0%, transparent 60%),
        linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 50%, rgba(0,0,0,0.4) 100%);
    color: white;
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.8);
    border-bottom: 1px solid var(--border-accent);
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #ffffff;
}

.header .subtitle {
    font-size: 1.2rem;
    opacity: 0.75;
    margin-bottom: 1rem;
    font-weight: 300;
    color: var(--neutral-dark);
}

.header .metadata {
    font-size: 0.9rem;
    opacity: 0.5;
    font-style: italic;
    color: var(--neutral-dark);
}

/* Container & Layout*/
.container {
    max-width: 1600px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Section Titles*/
.section-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--neutral-dark);
    margin: 2rem 0 1.5rem 0;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-accent);
    letter-spacing: 0.5px;
}

.row.full-width {
    display: block;
}

/*Controls Panel*/
.controls-panel {
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.control-group {
    flex: 1;
    min-width: 300px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--neutral-dark);
    font-size: 0.95rem;
}

.button-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.control-btn {
    padding: 0.6rem 1rem;
    border: 1px solid var(--surface-4);
    background: var(--surface-3);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s ease;
    color: #94A3B8;
}

.control-btn:hover {
    border-color: var(--primary-internet);
    background: rgba(56, 189, 248, 0.1);
    color: var(--primary-internet);
    transform: translateY(-2px);
}

.control-btn.active {
    background: rgba(56, 189, 248, 0.15);
    color: var(--primary-internet);
    border-color: var(--primary-internet);
    box-shadow: var(--glow-internet);
}

/* Stats Panel*/
.stats-panel {
    display: flex;
    gap: 1rem;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.06) 0%, rgba(244, 114, 182, 0.06) 100%);
    border: 1px solid var(--border-subtle);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    min-width: 120px;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748B;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary-internet);
}

/*Chart Container */
.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.chart-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7), var(--glow-internet);
    border-color: var(--border-accent);
}

.chart-container svg {
    width: 100%;
    height: auto;
    min-height: 400px;
}

.chart-container.wide {
    grid-column: 1 / -1;
    min-height: 450px;
}

.chart-container.map-container {
    min-height: 500px;
    width: 100%;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--neutral-dark);
    border-bottom: 2px solid var(--border-accent);
    padding-bottom: 0.5rem;
}

.chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--neutral-dark);
    border-bottom: 1px solid var(--border-accent);
    padding-bottom: 0.5rem;
}

/*SVG & D3*/
svg {
    font-family: 'Segoe UI', sans-serif;
}

.axis {
    font-size: 0.9rem;
}

.axis path,
.axis line {
    stroke: var(--surface-4);
    stroke-width: 1px;
}

.axis text {
    fill: #64748B;
    font-size: 0.85rem;
}

.grid-line {
    stroke: var(--surface-3);
    stroke-dasharray: 4;
    opacity: 0.6;
}

/*Bar Chart*/
.bar {
    fill: var(--primary-internet);
    transition: fill 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
    cursor: pointer;
}

.bar:hover {
    fill: #7DD3FC;
    opacity: 0.9;
    filter: drop-shadow(0 4px 12px rgba(56, 189, 248, 0.4));
}

.bar.space {
    fill: var(--primary-space);
}

.bar.space:hover {
    fill: #F9A8D4;
    filter: drop-shadow(0 4px 12px rgba(244, 114, 182, 0.4));
}

.bar.highlighted {
    filter: drop-shadow(0 6px 16px rgba(56, 189, 248, 0.6));
    stroke: var(--primary-internet);
    stroke-width: 2;
}

.bar.faded {
    opacity: 0.15;
}

/*Info Panel*/
.info-panel {
    position: fixed;
    right: 20px;
    top: 100px;
    background: var(--surface-2);
    border: 1px solid var(--border-accent);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7), var(--glow-internet);
    z-index: 1000;
    min-width: 320px;
    max-width: 380px;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease;
    border-left: 3px solid var(--primary-internet);
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.75rem;
    flex-shrink: 0;
}

.info-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--neutral-dark);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #475569;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.close-btn:hover {
    color: var(--primary-space);
}

.info-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.5rem;
}

.info-content::-webkit-scrollbar {
    width: 6px;
}

.info-content::-webkit-scrollbar-track {
    background: var(--surface-3);
    border-radius: 3px;
}

.info-content::-webkit-scrollbar-thumb {
    background: var(--surface-4);
    border-radius: 3px;
}

.info-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-internet);
}

.info-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--surface-3);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
}

.info-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #94A3B8;
}

.info-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-internet);
}

/* Profile Sections*/
.profile-section {
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 1rem;
    background: rgba(56, 189, 248, 0.03);
    margin-bottom: 1rem;
}

.profile-section:last-child {
    margin-bottom: 0;
}

.section-header {
    margin: 0 0 0.75rem 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--neutral-dark);
    border-bottom: 1px solid var(--border-accent);
    padding-bottom: 0.5rem;
}

.profile-section .info-stat {
    background: var(--surface-3);
    border: 1px solid var(--border-subtle);
    margin-bottom: 0.5rem;
}

.profile-section .info-stat:last-child {
    margin-bottom: 0;
}

/*Scatter Plot */
.dot {
    fill: var(--primary-internet);
    stroke: var(--surface-2);
    stroke-width: 2px;
    opacity: 0.75;
    cursor: pointer;
    transition: opacity 0.2s ease, r 0.2s ease, filter 0.2s ease;
}

.dot:hover {
    opacity: 1;
    filter: drop-shadow(0 4px 12px rgba(56, 189, 248, 0.5));
}

.dot.highlighted {
    r: 9;
    filter: drop-shadow(0 6px 16px rgba(56, 189, 248, 0.7));
    stroke: var(--primary-internet);
    stroke-width: 3px;
}

.dot.faded {
    opacity: 0.08;
}

.dot-label {
    font-size: 0.75rem;
    text-anchor: middle;
    pointer-events: none;
    opacity: 0;
    fill: var(--neutral-dark);
    transition: opacity 0.2s ease;
}

.dot:hover ~ .dot-label {
    opacity: 1;
}

/* Map*/
.country {
    fill: var(--surface-3);
    stroke: var(--surface-1);
    stroke-width: 0.75px;
    opacity: 1;
    cursor: pointer;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

.country:hover {
    opacity: 0.8;
    stroke-width: 1.5px;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}

.country.internet {
    fill: var(--primary-internet);
}

.country.space {
    fill: var(--primary-space);
}

.country.no-data {
    fill: var(--surface-3);
    opacity: 0.3;
}

.country.highlighted {
    paint-order: stroke;
    stroke: #FFFFFF;
    stroke-width: 2px;
    filter: drop-shadow(0 6px 14px rgba(56, 189, 248, 0.6));
}

.country.faded {
    opacity: 0.08;
}

/*Legend*/
.legend {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    font-size: 0.9rem;
    color: #94A3B8;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.1);
}

/*Tooltip */
.tooltip {
    position: fixed;
    background: var(--surface-2);
    border: 1px solid var(--border-accent);
    color: var(--neutral-dark);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 999;
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6), var(--glow-internet);
}

.tooltip.active {
    opacity: 1;
}

.tooltip-title {
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--primary-internet);
}

.tooltip-line {
    font-size: 0.85rem;
    color: #94A3B8;
}

/*Timeline Controls*/
.timeline-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(56, 189, 248, 0.05);
    border: 1px solid var(--border-accent);
    border-radius: 6px;
    margin-bottom: 1.5rem;
}

.timeline-btn {
    background: rgba(56, 189, 248, 0.15);
    color: var(--primary-internet);
    border: 1px solid var(--primary-internet);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.timeline-btn:hover {
    background: var(--primary-internet);
    color: #000000;
}

.timeline-label {
    font-weight: 600;
    color: var(--neutral-dark);
    min-width: 120px;
}

.timeline-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, var(--surface-4), var(--primary-internet));
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-internet);
    cursor: pointer;
    border: 2px solid var(--surface-2);
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.4);
}

.timeline-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-internet);
    cursor: pointer;
    border: 2px solid var(--surface-2);
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.4);
}

/*Comparison Controls*/
.comparison-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 250px;
    padding: 0.75rem;
    border: 1px solid var(--surface-4);
    background: var(--surface-3);
    color: var(--neutral-dark);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input::placeholder {
    color: #475569;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-internet);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

.country-selector {
    position: relative;
    display: inline-block;
    width: 100%;
}

.country-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-2);
    border: 1px solid var(--border-accent);
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

.country-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    color: #94A3B8;
}

.country-item:hover {
    background-color: rgba(56, 189, 248, 0.08);
    color: var(--neutral-dark);
}

.country-item input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--primary-internet);
}

.country-item label {
    cursor: pointer;
    flex: 1;
}

/* Comparison Panel*/
.comparison-panel {
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.comparison-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.comparison-card {
    background: var(--surface-3);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 1rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    transition: all 0.2s ease;
}

.comparison-card:hover {
    border-color: var(--primary-internet);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5), var(--glow-internet);
}

.comp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-accent);
    padding-bottom: 0.5rem;
}

.comp-header h4 {
    margin: 0;
    color: var(--neutral-dark);
    font-size: 1.1rem;
}

.comp-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #475569;
    transition: color 0.2s ease;
}

.comp-close:hover {
    color: var(--primary-space);
}

.comp-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-subtle);
}

.comp-label {
    font-weight: 600;
    color: #64748B;
}

.comp-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-internet);
}

.comp-rank {
    background: rgba(56, 189, 248, 0.1);
    color: var(--primary-internet);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    min-width: 50px;
    text-align: right;
}

.comp-diff {
    font-weight: 700;
    font-size: 1rem;
}

/* Responsive*/
@media (max-width: 1200px) {
    .row {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .chart-container.map-container {
        min-height: 50rem;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1.8rem;
    }

    .header .subtitle {
        font-size: 1rem;
    }

    .controls-panel {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .stats-panel {
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }

    .stat-item {
        min-width: 100px;
    }

    .container {
        padding: 0 0.5rem;
    }

    .chart-container {
        padding: 1rem;
    }

    .info-panel {
        position: static;
        min-width: auto;
        max-width: none;
        max-height: none;
        margin-top: 2rem;
        border-left: none;
        border-top: 3px solid var(--primary-internet);
    }

    .chart-container.map-container {
        min-height: 40rem;
    }
}

@media (max-width: 480px) {
    .row {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        flex-direction: column;
    }

    .button-group {
        flex-direction: column;
        width: 100%;
    }

    .control-btn {
        width: 100%;
    }

    .info-panel {
        padding: 1rem;
    }

    .timeline-controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    .timeline-slider {
        width: 100%;
    }

    .comparison-controls {
        flex-direction: column;
    }

    .search-input {
        min-width: 100%;
    }

    .comparison-cards {
        grid-template-columns: 1fr;
    }
   .tick text, svg text {
    fill: #ffffff;
   }
   .axis text {
    fill: #ffffff;
   }
}
