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

body {
    background: #060a16;
    background-image: radial-gradient(ellipse at 50% 50%, #0a1428 0%, #060a16 70%);
    color: #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ── Globe Canvas ─────────────────────────── */
#globe-container { position: fixed; inset: 0; }
#globe-container canvas { display: block; }

/* ── Control Panel ────────────────────────── */
#panel {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 280px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: rgba(12, 16, 28, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    padding: 22px;
    z-index: 10;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 150, 255, 0.2) transparent;
}

.panel-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand-logo {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 6px rgba(100, 180, 255, 0.25));
}
#panel h1 {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 3px;
    text-transform: uppercase;
}
#panel .tagline {
    font-size: 11px;
    color: #667a8a;
    margin-top: 2px;
    letter-spacing: 0.5px;
}

.panel-section { margin-top: 18px; }
.panel-section label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #5a7088;
    margin-bottom: 8px;
    font-weight: 600;
}

/* ── Native selects (hidden when JS loads) ── */
select.native-hidden { display: none; }

/* ── Custom Dropdown ──────────────────────── */
.dropdown {
    position: relative;
    width: 100%;
}

.dropdown-trigger {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 8px;
    color: #d0d8e0;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    transition: border-color 0.2s, background 0.2s;
    text-align: left;
}
.dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.16);
}
.dropdown.open .dropdown-trigger {
    border-color: rgba(100, 150, 255, 0.45);
    background: rgba(100, 150, 255, 0.06);
}
.dropdown.disabled .dropdown-trigger {
    opacity: 0.45;
    pointer-events: none;
}
.dropdown-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.dropdown-arrow {
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #5a7088;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.dropdown.open .dropdown-arrow { transform: rotate(180deg); }

/* Menu — positioned fixed in body to escape panel overflow */
.dropdown-menu {
    position: fixed;
    max-height: 0;
    overflow: hidden;
    background: rgba(14, 18, 32, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    z-index: 100;
    opacity: 0;
    transform: translateY(-6px);
    transition: max-height 0.25s ease, opacity 0.18s, transform 0.18s;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 150, 255, 0.25) transparent;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}
.dropdown-menu.open {
    max-height: 300px;
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0);
    padding: 6px 0;
    pointer-events: auto;
}

/* Group labels */
.dropdown-group-label {
    padding: 10px 14px 4px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: #4a6078;
}
.dropdown-group-label:not(:first-child) {
    margin-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 10px;
}

/* Items */
.dropdown-item {
    padding: 8px 14px;
    font-size: 13px;
    color: #9aabb8;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dropdown-item:hover {
    background: rgba(100, 150, 255, 0.1);
    color: #e0e8f0;
}
.dropdown-item.active {
    background: rgba(100, 150, 255, 0.14);
    color: #fff;
    font-weight: 500;
}
.dropdown-item.projected {
    color: #e0a820;
}
.dropdown-item.projected:hover {
    background: rgba(255, 193, 7, 0.1);
    color: #ffd54f;
}
.dropdown-item.projected.active {
    background: rgba(255, 193, 7, 0.14);
    color: #ffd54f;
    font-weight: 500;
}

/* ── Legend ────────────────────────────────── */
.legend-bar-wrap {
    position: relative;
    padding: 6px 0;
}
.legend-bar {
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #d21e1e, #f0781e, #f0d228, #5ac832, #1eb43c);
}
.legend-marker {
    position: absolute;
    top: 0;
    width: 2px;
    height: 20px;
    background: #fff;
    border-radius: 1px;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.6);
    transform: translateX(-1px);
    transition: left 0.3s ease;
}
.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #7a8a9a;
    margin-top: 2px;
}

/* ── Country Info ─────────────────────────── */
#country-info h3 {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}
#country-value {
    font-size: 22px;
    font-weight: 700;
    color: #64b5f6;
    margin-top: 4px;
}
#country-value .cagr-label {
    font-size: 11px;
    font-weight: 500;
    color: #5a7a8a;
    margin-left: 2px;
}
#ai-adjusted {
    font-size: 18px;
    font-weight: 700;
    color: #ce93d8;
    margin-top: 2px;
}
#ai-adjusted .ai-adj-label {
    font-size: 11px;
    font-weight: 500;
    color: #5a7a8a;
    margin-left: 2px;
}
.confidence {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 2px 7px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}
.confidence.high   { color: #66bb6a; background: rgba(102,187,106,0.12); }
.confidence.medium { color: #ffa726; background: rgba(255,167,38,0.12); }
.confidence.low    { color: #ef5350; background: rgba(239,83,80,0.12); }

#country-rank {
    font-size: 12px;
    color: #7a8a9a;
    margin-top: 4px;
}
#country-date {
    font-size: 11px;
    color: #556070;
    margin-top: 2px;
}

/* ── Projected badge ──────────────────────── */
.badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #ffc107;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.25);
    border-radius: 6px;
}

.badge-info {
    color: #64b5f6;
    background: rgba(100, 181, 246, 0.1);
    border: 1px solid rgba(100, 181, 246, 0.25);
    text-transform: none;
    letter-spacing: 0.3px;
    font-weight: 500;
    font-size: 11px;
}

/* ── CAGR line ────────────────────────────── */
#country-cagr {
    font-size: 12px;
    color: #8899aa;
    margin-top: 4px;
}

/* ── AI Narrative ─────────────────────────── */
#ai-narrative {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(100, 150, 255, 0.05);
    border: 1px solid rgba(100, 150, 255, 0.1);
    border-radius: 8px;
}
.ai-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #6496ff;
    margin-bottom: 6px;
}
#ai-text {
    font-size: 12px;
    line-height: 1.55;
    color: #b0bec5;
}
#ai-text.loading {
    color: #5a7088;
    font-style: italic;
}

/* ── Tooltip ──────────────────────────────── */
#tooltip {
    display: none;
    position: fixed;
    padding: 7px 14px;
    background: rgba(12, 16, 28, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 13px;
    color: #d0d8e0;
    pointer-events: none;
    z-index: 20;
    white-space: nowrap;
    transition: opacity 0.12s;
}

/* ── Credit ───────────────────────────────── */
#credit {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #3a4a5a;
    z-index: 10;
    white-space: nowrap;
}
#credit a { color: #5a7a9a; text-decoration: none; transition: color 0.2s; }
#credit a:hover { color: #88aacc; }

/* ── Loading Screen ───────────────────────── */
#loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #060a16;
    background-image: radial-gradient(ellipse at 50% 50%, #0a1428 0%, #060a16 70%);
    z-index: 100;
    transition: opacity 0.6s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loading-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    animation: pulse-glow 2s ease-in-out infinite;
    filter: drop-shadow(0 0 12px rgba(100, 180, 255, 0.3));
}
@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 12px rgba(100, 180, 255, 0.3)); transform: scale(1); }
    50% { filter: drop-shadow(0 0 20px rgba(100, 180, 255, 0.5)); transform: scale(1.04); }
}
.spinner {
    width: 36px; height: 36px;
    border: 3px solid rgba(100, 150, 255, 0.15);
    border-top-color: #6496ff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { margin-top: 14px; font-size: 13px; color: #5a7088; }

/* ── Utilities ────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────── */
@media (max-width: 768px) {
    #panel {
        top: auto; bottom: 0; left: 0; right: 0;
        width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 50vh;
        padding: 18px;
    }
    #credit { bottom: auto; top: 12px; }
}
