:root {
  --bg-ocean: #0f172a;
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
  --glass-blur: blur(12px);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --accent-cyan: #06b6d4;
  --map-land: #1e293b;
  --map-border: #334155;
  --map-hover: #3b82f6;
}

* { box-sizing: border-box; }

body, html {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-ocean);
  color: var(--text-main);
  overflow: hidden;
  transition: background 0.5s ease, color 0.5s ease;
}

/* Typography & Utilities */
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.025em; }
.text-accent { color: var(--accent-blue); }

/* Glassmorphism */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
}

/* Map Container */
#map {
  width: 100%; height: 100%;
  background-color: var(--bg-ocean); /* Dark navy */
  z-index: 0;
  position: absolute;
  top: 0; left: 0;
}

/* Country SVG Styling */
.leaflet-interactive {
  transition: fill 0.3s ease, fill-opacity 0.3s ease, stroke 0.3s ease, stroke-width 0.3s ease;
}
.country-default {
  fill: var(--bg-land);
  fill-opacity: 0.8;
  stroke: var(--border-country);
  stroke-width: 1px;
}
.country-hover {
  fill: var(--accent-blue);
  fill-opacity: 0.4;
  stroke: var(--accent-cyan);
  stroke-width: 2px;
}

/* Blink animation for selected country */
.blink-path {
  animation: blinkAnimation 1.5s ease-in-out infinite alternate !important;
}
@keyframes blinkAnimation {
  0% { fill-opacity: 0.2; stroke: var(--accent-blue); stroke-width: 2px; }
  100% { fill-opacity: 0.6; stroke: var(--accent-cyan); stroke-width: 4px; filter: drop-shadow(0 0 8px var(--accent-cyan)); }
}

/* UI Layout */
#app-container {
  position: relative;
  width: 100%; height: 100%;
  z-index: 10;
  pointer-events: none; /* Let clicks pass through to map */
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  pointer-events: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  z-index: 1000;
}

.mode-toggles {
  display: flex; gap: 0.5rem;
}
.mode-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-main);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.875rem;
  font-weight: 600;
}
.mode-btn:hover { background: rgba(255,255,255,0.1); }
.mode-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

/* Side Panels */
.panels-container {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem;
  pointer-events: none;
  overflow: hidden;
  position: relative;
}

.panel {
  pointer-events: auto;
  width: 350px;
  max-width: 100%;
  max-height: calc(100% - 3rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

#left-panel { transform: translateX(0); }
#right-panel { transform: translateX(0); }

.panel.hidden-left { transform: translateX(-120%); opacity: 0; pointer-events: none; }
.panel.hidden-right { transform: translateX(120%); opacity: 0; pointer-events: none; }

/* Scrollbar */
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); }
.panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.panel::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

/* Card Typography & Layout */
.card-section { padding: 1.25rem; border-bottom: 1px solid var(--glass-border); }
.card-section:last-child { border-bottom: none; }
.section-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.75rem; }

/* Stat Grids */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem;}
.stat-box {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 0.75rem;
}
.stat-box .label { font-size: 0.65rem; text-transform: uppercase; color: var(--text-muted); }
.stat-box .value { font-size: 1.1rem; font-weight: 700; margin-top: 0.25rem; }

/* Tags / Badges */
.badges { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.badge {
  font-size: 0.7rem; padding: 0.25rem 0.6rem; border-radius: 4px; font-weight: 600; background: rgba(255,255,255,0.1);
}
.badge.ally { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge.enemy { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.badge.frenemy { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }

/* Legend */
.legend {
  position: absolute; bottom: 1.5rem; left: 1.5rem;
  pointer-events: auto; padding: 1rem;
}
.legend-item { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.8rem; }
.legend-item:last-child { margin-bottom: 0; }
.legend-color { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.2); }

/* Tooltip */
.leaflet-tooltip.custom-tooltip {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: white;
  border-radius: 8px;
  padding: 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  box-shadow: var(--glass-shadow);
  white-space: nowrap;
}
.custom-tooltip::before { display: none; }
.custom-tooltip strong { color: var(--accent-cyan); font-size: 1rem; display: block; margin-bottom: 0.25rem;}
.custom-tooltip div { font-size: 0.75rem; color: #cbd5e1; }

/* Loading Screen */
#loader {
  position: fixed; inset: 0; background: var(--bg-ocean);
  z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: opacity 0.5s;
}
.spinner {
  width: 50px; height: 50px; border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent-blue); border-radius: 50%;
  animation: spin 1s linear infinite; margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile adjustments */
@media (max-width: 768px) {
  .panels-container { flex-direction: column; }
  .panel { width: 100%; max-height: 50vh; position: absolute; bottom: 0; left: 0; transform: translateY(0); border-radius: 16px 16px 0 0; z-index: 1050; }
  .panel.hidden-left, .panel.hidden-right { transform: translateY(110%); }
  
  #main-header { 
    flex-wrap: wrap; 
    gap: 0.75rem !important; 
    padding: 0.5rem 1rem !important;
  }
  #header-brand { flex: 100% !important; justify-content: center; }
  #header-modes { flex: 0 0 auto !important; order: 2; justify-content: flex-start !important; }
  #header-search { flex: 1 1 0 !important; order: 3; max-width: none !important; margin: 0 !important; position: relative !important; top: auto !important; left: auto !important; transform: none !important; }
  
  .mode-text { display: none; }
  .mode-btn { padding: 0.5rem 0.6rem; display: flex; align-items: center; justify-content: center; }
  
  #legend-content {
    top: 9rem !important;
    width: 90%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem !important;
    padding: 1px 0.5rem !important;
  }

  footer { 
    justify-content: center !important; 
    padding: 0.2rem 0.75rem !important; 
    bottom: 0.5rem !important;
    font-size: 0.65rem !important;
    width: fit-content !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 20px !important;
    white-space: nowrap !important;
  }
  footer > div:first-child, footer > div:last-child { display: none !important; }

  .leaflet-bottom {
    bottom: calc(0.5rem + 1.2rem + 4px) !important;
  }
  .leaflet-right { margin-right: 6px !important; }
  .leaflet-left { margin-left: 6px !important; }
  .leaflet-control-attribution {
    background: transparent !important;
    color: var(--text-muted) !important;
    font-size: 8px !important;
    border: none !important;
  }
}

@keyframes header-glow {
  0% { box-shadow: 0 0 0 0px var(--accent-blue), var(--glass-shadow); }
  50% { box-shadow: 0 0 0 2px var(--accent-blue), var(--glass-shadow); }
  100% { box-shadow: 0 0 0 0px var(--accent-blue), var(--glass-shadow); }
}

#main-header {
  animation: header-glow 3s infinite ease-in-out;
  border: 1px solid rgba(59, 130, 246, 0.4) !important;
}

.panel-close {
  position: absolute; right: 1rem; top: 1rem;
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1.25rem; transition: color 0.2s;
}
.panel-close:hover { color: white; }

.search-container {
  pointer-events: auto;
  position: absolute;
  top: 5rem; left: 50%;
  transform: translateX(-50%);
  width: 300px;
  max-width: 90%;
  z-index: 1000;
}
.search-input {
  width: 100%;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 20px;
  outline: none;
  font-family: inherit;
  box-shadow: var(--glass-shadow);
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent-blue); }

#search-results {
  position: absolute;
  top: 100%; left: 0; right: 0;
  margin-top: 0.5rem;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  overflow: hidden;
  display: none;
}
.search-result-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  transition: background 0.2s;
}
.search-result-item:hover { background: rgba(255,255,255,0.1); }
.search-result-item:last-child { border-bottom: none; }

.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-orange { color: var(--accent-orange); }
.text-cyan { color: var(--accent-cyan); }

/* Prevent Leaflet controls from overlapping footer */
.leaflet-bottom.leaflet-right {
  margin-bottom: 4.5rem !important;
  margin-right: 1.5rem !important;
}
