:root {
  --bg: #0a0e14;
  --panel: rgba(18, 24, 34, 0.82);
  --panel-solid: #121822;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #38bdf8;
  --accent-2: #f97316;
}

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

html, body { height: 100%; }
body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#map { position: absolute; inset: 0; background: var(--bg); z-index: 0; }
.leaflet-container { background: #0a0e14; outline: none; }
.leaflet-control-attribution { background: rgba(10,14,20,.7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }

/* Top bar */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 500;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(10,14,20,.92), rgba(10,14,20,0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(249,115,22,.18), 0 0 18px rgba(249,115,22,.6);
}
.brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.brand p { font-size: 12px; color: var(--muted); margin-top: -2px; }

.live {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; backdrop-filter: blur(8px);
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
#panel-toggle {
  display: none; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); width: 38px; height: 38px; border-radius: 10px;
  font-size: 18px; cursor: pointer;
}

/* Side panel */
#panel {
  position: absolute; top: 64px; left: 14px; bottom: 14px; z-index: 450;
  width: 360px; max-width: calc(100vw - 28px);
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto; padding-right: 2px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#panel::-webkit-scrollbar { width: 6px; }
#panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; backdrop-filter: blur(14px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin-bottom: 10px; font-weight: 600; }

.filter-group { margin-bottom: 14px; }
.filter-group:last-child { margin-bottom: 0; }
.filter-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
#mag-val { color: var(--accent); font-weight: 600; }

.segmented { display: flex; gap: 4px; background: rgba(0,0,0,.25);
  padding: 4px; border-radius: 10px; }
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 7px 0; border-radius: 7px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--accent); color: #04222f; }

input[type=range] { width: 100%; accent-color: var(--accent); }

#region {
  width: 100%; background: rgba(0,0,0,.25); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 10px; font-size: 13px; font-family: inherit; cursor: pointer;
}
#region:focus { outline: none; border-color: var(--accent); }
#region optgroup { background: var(--panel-solid); color: var(--muted); }
#region option { background: var(--panel-solid); color: var(--text); }

.stats { display: flex; gap: 8px; margin-top: 14px; }
.stat { flex: 1; background: rgba(0,0,0,.22); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 18px; font-weight: 700; }
.stat span { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.card h2 .hint { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; opacity: .7; }
.chart-box { position: relative; height: 130px; margin-bottom: 12px; }
.chart-box.mag { height: 110px; margin-bottom: 0; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

.list-card { flex: 0 0 auto; }   /* size to content so the box contains the whole list */
#event-list { display: flex; flex-direction: column; gap: 2px; }
.evt {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: 10px; cursor: pointer; transition: .12s;
}
.evt:hover { background: rgba(255,255,255,.05); }
.mag-badge {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #0a0e14;
}
.evt-info { min-width: 0; flex: 1; }
.evt-place { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.evt-meta { font-size: 11px; color: var(--muted); }

#attribution { font-size: 11px; color: var(--muted); padding: 4px 8px 8px; line-height: 1.5; }

#legend {
  position: absolute; right: 14px; bottom: 14px; z-index: 450;
  display: flex; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 12px; backdrop-filter: blur(10px);
  font-size: 11px; color: var(--muted);
}
#legend span { display: flex; align-items: center; gap: 5px; }
#legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* pulsing ring for just-arrived earthquakes */
.pulse-icon { background: none; border: none; overflow: visible; }
.pulse-icon .pulse-ring {
  position: absolute; left: 0; top: 0;
  border: 2px solid #fff; border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: quake-pulse 1.8s cubic-bezier(0.2, 0.6, 0.3, 1) infinite;
  pointer-events: none;
}
.pulse-icon .pulse-ring.d2 { animation-delay: 0.9s; }
@keyframes quake-pulse {
  0%   { width: 6px;  height: 6px;  opacity: 0.9; }
  100% { width: 70px; height: 70px; opacity: 0; }
}

/* highlight just-arrived events in the list */
.evt.evt-new { background: rgba(56, 189, 248, 0.10); box-shadow: inset 2px 0 0 var(--accent); }
.evt.evt-new .evt-place::after {
  content: "NEW"; margin-left: 6px; font-size: 9px; font-weight: 700;
  color: #04222f; background: var(--accent); padding: 1px 5px; border-radius: 5px;
  vertical-align: middle; animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.45; } }

.leaflet-popup-content-wrapper { background: var(--panel-solid); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; }
.leaflet-popup-tip { background: var(--panel-solid); }
.popup-mag { font-size: 20px; font-weight: 700; }
.popup-place { font-size: 13px; margin: 4px 0; }
.popup-meta { font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  #panel-toggle { display: block; margin-left: auto; }
  .live { margin-left: 0; }
  #panel {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-width: 100%;
    max-height: 72vh; border-radius: 18px 18px 0 0;
    background: var(--panel-solid); padding: 12px;
    transform: translateY(100%); transition: transform .25s; }
  #panel.open { transform: translateY(0); }
  #legend { bottom: auto; top: 64px; right: 8px; }
}
