/* ═══════════════════════════════════════════════
   3D Planet Earth — Professional UI Stylesheet
   Dark satellite aesthetic with glass-morphism panels
   ═══════════════════════════════════════════════ */

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

:root {
  --bg-deep: #020810;
  --glass-bg: rgba(10, 15, 28, 0.82);
  --glass-border: rgba(76, 201, 240, 0.15);
  --glass-hover: rgba(76, 201, 240, 0.08);
  --text-primary: #e8edf4;
  --text-secondary: #8b97a8;
  --text-muted: #5a6678;
  --accent: #4cc9f0;
  --accent-warm: #f0a500;
  --accent-hot: #e94560;
  --accent-green: #00ff88;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: var(--font-sans);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Globe Container ── */
#globe-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#globe-container canvas {
  display: block;
}

/* ── Atmosphere Glow ── */
.atmosphere-glow {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center,
    transparent 55%,
    rgba(2, 8, 16, 0.4) 75%,
    rgba(2, 8, 16, 0.85) 100%
  );
}

/* ── Loading Screen ── */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  transition: opacity 0.6s ease;
}

.loading-content {
  text-align: center;
  max-width: 360px;
}

.loading-content h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 24px;
  letter-spacing: -0.02em;
}

.loading-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 8px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 3px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-bar {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-top: 24px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-green));
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── Stats Bar ── */
.stats-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 40px;
  padding: 14px 24px;
  background: linear-gradient(180deg,
    rgba(2, 8, 16, 0.95) 0%,
    rgba(2, 8, 16, 0.5) 70%,
    transparent 100%
  );
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

/* ── Control Panel ── */
.control-panel {
  position: fixed;
  top: 120px;
  left: 24px;
  z-index: 10;
  width: 260px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.control-panel:hover {
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--glass-border);
}

.panel-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.globe-icon {
  font-size: 1.3rem;
}

.panel-badge {
  font-size: 0.675rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 3px 10px;
  background: rgba(76, 201, 240, 0.12);
  color: var(--accent);
  border-radius: 20px;
  letter-spacing: 0.04em;
}

.panel-section {
  margin-bottom: 18px;
}

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

.section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Layer Toggles ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.toggle-row:hover {
  background: var(--glass-hover);
}

.toggle-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.15s ease;
}

.toggle-row.active .toggle-label {
  color: var(--text-primary);
}

.toggle-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gdp-dot { background: var(--accent-hot); box-shadow: 0 0 6px var(--accent-hot); }
.trade-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.hexbin-dot { background: #ff6b35; box-shadow: 0 0 6px #ff6b35; }
.hdi-dot { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }

.toggle-switch {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-row.active .toggle-switch {
  background: rgba(76, 201, 240, 0.25);
}

.toggle-row.active .toggle-switch::after {
  transform: translateX(16px);
  background: var(--accent);
}

/* ── Group Chips ── */
.group-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 12px;
  font-size: 0.725rem;
  font-weight: 500;
  font-family: var(--font-sans);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  border-color: rgba(255,255,255,0.3);
  color: var(--text-primary);
}

.chip.active {
  background: rgba(76, 201, 240, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── View Presets ── */
.view-presets {
  display: flex;
  gap: 6px;
}

.preset-btn {
  width: 44px;
  height: 36px;
  font-size: 1.1rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preset-btn:hover {
  border-color: rgba(255,255,255,0.3);
  background: var(--glass-hover);
}

.preset-btn.active {
  border-color: var(--accent);
  background: rgba(76, 201, 240, 0.1);
}

/* ── Info Card ── */
.info-card {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%) translateX(calc(100% + 30px));
  z-index: 10;
  width: 240px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 18px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
  pointer-events: none;
  opacity: 0;
}

.info-card.visible {
  transform: translateY(-50%) translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.info-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--glass-border);
}

.info-country-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.info-country-code {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.info-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.info-label {
  font-size: 0.725rem;
  color: var(--text-muted);
  font-weight: 500;
}

.info-value {
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
  text-align: right;
}

/* ── Legend ── */
.legend {
  position: fixed;
  right: 24px;
  bottom: 50px;
  z-index: 10;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.legend-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: center;
}

.legend-gradient {
  width: 140px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg,
    #1a1a2e 0%,
    #0f3460 20%,
    #533483 40%,
    #e94560 60%,
    #f0a500 80%,
    #00ff88 100%
  );
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Data Source Footer ── */
.data-source {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  padding: 6px 18px;
  background: var(--glass-bg);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
}

/* ── Globe Tooltips ── */
.globe-tooltip {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  line-height: 1.5;
  padding: 8px 12px;
  background: rgba(10, 15, 28, 0.95);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.globe-tooltip strong {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 4px;
  color: var(--accent);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .stats-bar {
    gap: 16px;
    padding: 10px 12px;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .stat-label {
    font-size: 0.6rem;
  }

  .control-panel {
    top: auto;
    bottom: 16px;
    left: 8px;
    right: 8px;
    width: auto;
    flex-direction: row;
    padding: 12px 16px;
    border-radius: var(--radius-md);
  }

  .panel-header {
    display: none;
  }

  .panel-section {
    margin-bottom: 0;
    margin-right: 16px;
  }

  .section-title {
    display: none;
  }

  .info-card {
    right: 8px;
    width: 200px;
  }

  .legend {
    right: 8px;
    bottom: 110px;
  }
}

@media (max-width: 480px) {
  .control-panel {
    bottom: 8px;
    left: 4px;
    right: 4px;
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .stats-bar {
    gap: 12px;
    padding: 8px;
  }

  .info-card {
    right: 4px;
    width: 180px;
    padding: 12px;
  }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
  }

  .info-card {
    transition: opacity 0.15s ease;
  }

  #loading-screen {
    transition: opacity 0.2s ease;
  }
}
