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

:root {
  --bg: #0a0e17;
  --surface: rgba(13, 19, 32, 0.85);
  --surface-border: rgba(56, 189, 248, 0.12);
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.25);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --positive: #34d399;
  --negative: #f87171;
  --yellow: #fbbf24;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--text);
}

/* === Canvas (background) === */
#globe-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* === UI Overlay === */
#ui-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: grid;
  grid-template-rows: 56px 1fr 48px;
  grid-template-columns: 260px 1fr 320px;
  grid-template-areas:
    "top    top    top"
    "left   center right"
    "bottom bottom bottom";
  gap: 0;
}

#ui-overlay > * {
  pointer-events: auto;
}

/* === Top Bar === */
#top-bar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: linear-gradient(180deg, rgba(10,14,23,0.95) 0%, rgba(10,14,23,0.7) 100%);
  border-bottom: 1px solid var(--surface-border);
  backdrop-filter: blur(12px);
  z-index: 20;
}

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

.logo-icon {
  font-size: 22px;
  color: var(--accent);
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 2.5px;
  color: var(--text);
}

.top-nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  text-decoration: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--positive);
  animation: pulse 2s ease-in-out infinite;
}

.live-text {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--positive);
}

#clock {
  font-family: var(--font-display);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* === Side Panels === */
#left-panel, #right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  scrollbar-width: none;
}

#left-panel::-webkit-scrollbar,
#right-panel::-webkit-scrollbar {
  display: none;
}

#left-panel {
  grid-area: left;
  background: linear-gradient(90deg, rgba(10,14,23,0.92) 0%, rgba(10,14,23,0.3) 100%);
  border-right: 1px solid var(--surface-border);
}

#right-panel {
  grid-area: right;
  background: linear-gradient(270deg, rgba(10,14,23,0.92) 0%, rgba(10,14,23,0.3) 100%);
  border-left: 1px solid var(--surface-border);
}

/* === Panel Cards === */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 14px;
  backdrop-filter: blur(8px);
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.panel-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.panel-change {
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}

.panel-change.positive { color: var(--positive); }
.panel-change.negative { color: var(--negative); }

.panel-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Mini Charts */
.mini-chart {
  margin-top: 10px;
  height: 36px;
  position: relative;
}

.mini-chart canvas {
  width: 100% !important;
  height: 100% !important;
}

/* === Country Detail Panel === */
.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 12px;
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
  color: var(--text-dim);
  font-weight: 500;
}

.detail-val {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
}

.hint-text {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* HDI Bar */
.hdi-bar-wrap {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.hdi-bar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.hdi-bar-track {
  height: 8px;
  background: linear-gradient(90deg, #f87171 0%, #fbbf24 35%, #38bdf8 60%, #34d399 100%);
  border-radius: 4px;
  position: relative;
  overflow: visible;
}

.hdi-bar-fill {
  position: absolute;
  top: -3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  border: 2px solid var(--accent);
  transform: translateX(-50%);
  transition: left 0.5s ease;
  box-shadow: 0 0 8px rgba(56,189,248,0.5);
}

.hdi-bar-scale {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* === Legend === */
.legend-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

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

/* === Bar Chart === */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 85px;
  font-weight: 500;
}

.bar-track {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 1.5s ease;
  background: linear-gradient(90deg, var(--accent), #818cf8);
}

.bar-fill.green { background: linear-gradient(90deg, #34d399, #38bdf8); }
.bar-fill.yellow { background: linear-gradient(90deg, #fbbf24, #fb923c); }
.bar-fill.red { background: linear-gradient(90deg, #f87171, #ef4444); }

.bar-pct {
  font-size: 11px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-dim);
  min-width: 30px;
  text-align: right;
}

/* === Bottom Ticker === */
#bottom-panel {
  grid-area: bottom;
  background: linear-gradient(0deg, rgba(10,14,23,0.95) 0%, rgba(10,14,23,0.7) 100%);
  border-top: 1px solid var(--surface-border);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  overflow: hidden;
}

.ticker-strip {
  display: flex;
  gap: 32px;
  padding: 0 24px;
  animation: ticker-scroll 40s linear infinite;
  white-space: nowrap;
}

.ticker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.ticker-label {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.5px;
}

.ticker-val {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
}

.ticker-change {
  font-weight: 600;
  font-size: 12px;
}

.ticker-change.positive { color: var(--positive); }
.ticker-change.negative { color: var(--negative); }

@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* === Globe Label Tooltip === */
.globe-label {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  backdrop-filter: blur(8px);
  z-index: 100;
  transition: opacity 0.2s;
  max-width: 280px;
  line-height: 1.4;
}

.globe-label.hidden {
  opacity: 0;
}

/* === Country label sprites (CSS2D) === */
.country-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 0 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: 0.5px;
  user-select: none;
  transform: translate(-50%, -50%);
}

.country-label.major {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
}

/* === Responsive === */
@media (max-width: 1024px) {
  #ui-overlay {
    grid-template-columns: 220px 1fr 260px;
  }
  .panel-value { font-size: 22px; }
}

@media (max-width: 768px) {
  #ui-overlay {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto auto 48px;
    grid-template-areas:
      "top"
      "center"
      "left"
      "right"
      "bottom";
  }

  #left-panel, #right-panel {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(10,14,23,0.9);
    border: none;
    border-top: 1px solid var(--surface-border);
    padding: 12px;
  }

  .panel-card {
    min-width: 200px;
    flex-shrink: 0;
  }

  .top-nav { display: none; }
}
