/* ============================================================
   CHRONOS — Isochronic Map of North America
   Design System: Dark celestial / neon cartography
   ============================================================ */

:root {
  --bg-primary: #0a0e17;
  --bg-panel: rgba(14, 18, 28, 0.92);
  --bg-panel-hover: rgba(20, 26, 40, 0.94);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-active: rgba(100, 180, 255, 0.3);
  --text-primary: #e8ecf2;
  --text-secondary: #8899b4;
  --text-muted: #556680;
  --accent-cyan: #00d4ff;
  --accent-blue: #4d9fff;
  --accent-purple: #a78bfa;
  --accent-pink: #f472b6;
  --accent-green: #34d399;
  --accent-orange: #fb923c;
  --accent-yellow: #fbbf24;
  --isochrone-1: #00d4ff;
  --isochrone-2: #22c55e;
  --isochrone-3: #fbbf24;
  --isochrone-4: #f97316;
  --isochrone-5: #ef4444;
  --isochrone-6: #a855f7;
  --glow-cyan: 0 0 20px rgba(0, 212, 255, 0.4);
  --glow-blue: 0 0 20px rgba(77, 159, 255, 0.3);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background: var(--bg-primary);
  font-family: var(--font-sans);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Map
   ============================================================ */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: var(--bg-primary);
}

/* CartoDB Dark Matter tile overlay darkening */
.leaflet-tile {
  filter: brightness(0.7) saturate(0.6) hue-rotate(10deg);
}

/* OSM fallback tiles — invert and darken for night-mode look */
.osm-fallback-tile {
  filter: invert(0.9) hue-rotate(180deg) brightness(0.7) saturate(0.5) !important;
}

.leaflet-container {
  background: #0a0e17;
}

/* Hide default leaflet attribution style */
.leaflet-control-attribution {
  background: rgba(10, 14, 23, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  padding: 4px 8px !important;
  border-radius: 4px !important;
}
.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* Custom zoom controls — repositioned to top-right */
.leaflet-control-zoom {
  position: fixed !important;
  top: 16px !important;
  right: 16px !important;
  left: auto !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5) !important;
  z-index: 900 !important;
}
.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text-secondary) !important;
  border-color: var(--border-subtle) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 18px !important;
  transition: var(--transition);
}
.leaflet-control-zoom a:hover {
  background: var(--bg-panel-hover) !important;
  color: var(--text-primary) !important;
}

/* ============================================================
   Control Panel
   ============================================================ */
#panel {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 320px;
  background: var(--bg-panel);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03) inset;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#panel::-webkit-scrollbar { width: 4px; }
#panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* Panel Header */
#panel-header {
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
#panel-header h1 {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 6px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 2px;
}
.subtitle {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ============================================================
   Search
   ============================================================ */
#search-container {
  position: relative;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  z-index: 2;
}
#city-search {
  width: 100%;
  padding: 10px 12px 10px 38px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
#city-search::placeholder { color: var(--text-muted); }
#city-search:focus {
  border-color: var(--border-active);
  background: rgba(255,255,255,0.06);
  box-shadow: var(--glow-cyan);
}
#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  display: none;
  z-index: 10;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#search-results.active { display: block; }
.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-result-item:hover,
.search-result-item.active {
  background: rgba(77, 159, 255, 0.12);
}
.search-result-item .city-name { font-weight: 500; color: var(--text-primary); }
.search-result-item .city-meta { font-size: 11px; color: var(--text-muted); }

/* ============================================================
   Mode Selector
   ============================================================ */
#mode-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.mode-btn {
  padding: 8px 4px;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 500;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.mode-btn .mode-icon { font-size: 16px; }
.mode-btn:hover { background: rgba(255,255,255,0.06); color: var(--text-secondary); }
.mode-btn.active {
  background: rgba(77, 159, 255, 0.15);
  border-color: var(--border-active);
  color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.15);
}

/* ============================================================
   Time Thresholds
   ============================================================ */
#time-thresholds {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.threshold-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.threshold-buttons {
  display: flex;
  gap: 4px;
}
.time-btn {
  flex: 1;
  padding: 6px 0;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  transition: var(--transition);
}
.time-btn:hover { background: rgba(255,255,255,0.06); color: var(--text-secondary); }
.time-btn.active {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.3);
  color: var(--accent-purple);
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.15);
}

/* ============================================================
   Info Panel
   ============================================================ */
#info-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.info-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.info-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

/* ============================================================
   Legend
   ============================================================ */
#legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.legend-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.legend-gradient {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right,
    #00d4ff, #22c55e, #fbbf24, #f97316, #ef4444, #a855f7
  );
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============================================================
   Loading
   ============================================================ */
#loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(10, 14, 23, 0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  backdrop-filter: blur(8px);
}
#loading.active { display: flex; }
#loading span {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 2px;
}
.loader {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   City Markers
   ============================================================ */
.city-marker {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  transition: var(--transition);
}
.city-marker.origin {
  width: 14px;
  height: 14px;
  background: var(--accent-cyan);
  border: 2px solid #fff;
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.6), 0 0 32px rgba(0, 212, 255, 0.3);
  animation: pulse 2s ease-in-out infinite;
}
.city-marker.reachable {
  background: var(--accent-green);
  border-color: rgba(52, 211, 153, 0.5);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.3);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 16px rgba(0, 212, 255, 0.6), 0 0 32px rgba(0, 212, 255, 0.3); }
  50% { box-shadow: 0 0 24px rgba(0, 212, 255, 0.8), 0 0 48px rgba(0, 212, 255, 0.5); }
}

/* ============================================================
   Canvas Overlay
   ============================================================ */
.isochrone-canvas {
  pointer-events: none !important;
}

/* ============================================================
   Leaflet Tooltips
   ============================================================ */
.city-tooltip {
  background: rgba(14, 18, 28, 0.92) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: 6px !important;
  color: #e8ecf2 !important;
  font-family: var(--font-sans) !important;
  font-size: 11px !important;
  padding: 6px 10px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
}
.city-tooltip::before {
  border-top-color: rgba(14, 18, 28, 0.92) !important;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  #panel {
    width: calc(100vw - 16px);
    left: 8px;
    top: 8px;
    right: 8px;
    max-height: 45vh;
    border-radius: var(--radius-md);
    padding: 14px;
    gap: 10px;
    font-size: 12px;
  }
  #panel-header h1 { font-size: 22px; letter-spacing: 4px; }
  .leaflet-control-zoom { display: none; }
}
