/* ============================================================
   PULSE — Live Earthquake Visualization
   ============================================================ */

:root {
  --bg: #05070d;
  --panel: rgba(13, 18, 28, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8edf4;
  --text-dim: #8b96a8;
  --accent: #4de3c1;
  --accent-glow: rgba(77, 227, 193, 0.55);
  --danger: #ff5d5d;
  --radius: 14px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

#map {
  position: absolute;
  inset: 0;
  background: var(--bg);
}

/* Darken/grade the map tiles so panels pop */
#map::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center,
              transparent 40%, rgba(5, 7, 13, 0.55) 100%);
  z-index: 500;
}

/* Leaflet container tweaks */
.leaflet-container {
  background: var(--bg);
  font-family: var(--font-display);
}

/* Dark-mode treatment for the OpenStreetMap tiles.
   Inverting + hue-rotating flips the light basemap into a dark one,
   then we desaturate/darken slightly so the quake markers pop. */
.leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.55);
}
.leaflet-control-attribution {
  background: rgba(5, 7, 13, 0.7) !important;
  color: var(--text-dim) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

/* ---------- Brand ---------- */
.brand {
  position: absolute;
  top: 22px;
  left: 24px;
  z-index: 1000;
  pointer-events: none;
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--text);
  text-shadow: 0 0 24px rgba(77, 227, 193, 0.35);
}
.tagline {
  margin: 4px 0 0 2px;
  font-size: 12.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* Pulsing live dot */
.pulse-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent-glow); }
  70%  { box-shadow: 0 0 0 14px rgba(77, 227, 193, 0); }
  100% { box-shadow: 0 0 0 0 rgba(77, 227, 193, 0); }
}

/* ---------- Range switcher ---------- */
.range-switch {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.range-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.4px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.range-btn:hover { color: var(--text); }
.range-btn.active {
  background: var(--accent);
  color: #04110d;
  font-weight: 700;
  box-shadow: 0 0 18px var(--accent-glow);
}

/* ---------- Stats panel ---------- */
.stats {
  position: absolute;
  top: 100px;
  right: 24px;
  z-index: 1000;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 240px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-wide { grid-column: 1 / -1; }
.stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}
.stat-value.small { font-size: 15px; letter-spacing: 0.3px; }
.stat-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
}

/* ---------- Legend ---------- */
.legend {
  position: absolute;
  left: 24px;
  bottom: 60px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 12px;
  color: var(--text-dim);
}
.legend-row { display: flex; align-items: center; gap: 12px; }
.legend-title {
  width: 74px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 10px;
}
.mag-scale, .depth-scale { display: flex; align-items: center; gap: 6px; }
.mag-dot {
  display: inline-block;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.9;
  margin-right: 2px;
}
.mag-dot.m2 { width: 6px; height: 6px; }
.mag-dot.m4 { width: 11px; height: 11px; }
.mag-dot.m6 { width: 17px; height: 17px; }
.depth-chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 2px;
}
.depth-chip.shallow { background: #ff6b4a; }
.depth-chip.intermediate { background: #ffc14d; }
.depth-chip.deep { background: #6aa9ff; }

/* ---------- Footer / attribution ---------- */
.attribution {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.attribution a { color: var(--accent); text-decoration: none; }
.dot-sep { opacity: 0.4; }

/* ---------- Loader ---------- */
.loader {
  position: absolute;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--bg);
  transition: opacity 0.5s ease;
}
.loader.hidden { opacity: 0; pointer-events: none; }
.loader p {
  color: var(--text-dim);
  letter-spacing: 1px;
  font-size: 14px;
}
.loader-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid rgba(77, 227, 193, 0.15);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Error banner ---------- */
.error-banner {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: rgba(40, 12, 16, 0.92);
  border: 1px solid rgba(255, 93, 93, 0.4);
  border-radius: var(--radius);
  color: #ffd7d7;
  font-size: 13.5px;
  backdrop-filter: blur(10px);
}
.error-banner.hidden { display: none; }
.error-banner button {
  appearance: none;
  border: 1px solid rgba(255, 93, 93, 0.5);
  background: transparent;
  color: #ff9d9d;
  font-family: var(--font-display);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.error-banner button:hover { background: rgba(255, 93, 93, 0.15); }

/* ---------- Earthquake markers ---------- */
.quake-marker {
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.quake-marker:hover { transform: scale(1.25); }

/* Pulsing ring for big / recent quakes */
.quake-ping {
  border-radius: 50%;
  border: 2px solid var(--danger);
  animation: ping 1.8s ease-out infinite;
}
@keyframes ping {
  0%   { transform: scale(0.4); opacity: 0.9; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ---------- Popup ---------- */
.leaflet-popup-content-wrapper {
  background: rgba(13, 18, 28, 0.95);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}
.leaflet-popup-tip { background: rgba(13, 18, 28, 0.95); }
.leaflet-popup-content { margin: 14px 16px; font-family: var(--font-display); }
.quake-pop h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.quake-pop .mag-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  padding: 2px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}
.quake-pop dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12.5px;
}
.quake-pop dt { color: var(--text-dim); }
.quake-pop dd { margin: 0; font-family: var(--font-mono); }
.quake-pop a {
  display: inline-block;
  margin-top: 10px;
  color: var(--accent);
  text-decoration: none;
  font-size: 12.5px;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .brand h1 { font-size: 22px; letter-spacing: 4px; }
  .tagline { font-size: 10.5px; }
  .range-switch { top: auto; bottom: 70px; }
  .stats {
    top: auto;
    bottom: 130px;
    right: 12px;
    width: 190px;
    padding: 12px;
  }
  .stat-value { font-size: 18px; }
  .legend { display: none; }
  .attribution { font-size: 10.5px; padding: 6px 12px; }
}