:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #111827;
  color: #f8fafc;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
main { position: relative; min-height: 0; }
#map { height: 100%; background: #1f2937; }

.panel {
  background: rgb(15 23 42 / 90%);
  border: 1px solid rgb(148 163 184 / 25%);
  border-radius: .65rem;
  box-shadow: 0 .4rem 1.5rem rgb(0 0 0 / 30%);
  backdrop-filter: blur(8px);
}

.app-header {
  position: absolute;
  z-index: 1000;
  top: 1rem;
  left: 3.5rem;
  right: 1rem;
  max-width: 34rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .7rem 1rem;
}

h1 { margin: 0; font-size: 1.15rem; }
.app-header p { margin: .15rem 0 0; color: #cbd5e1; font-size: .8rem; }
.status { display: flex; align-items: center; gap: .45rem; font-size: .75rem; white-space: nowrap; }
.status > span:last-child { display: grid; gap: .05rem; }
.local-clock { font-size: .86rem; font-weight: 650; font-variant-numeric: tabular-nums; }
#status-text { color: #cbd5e1; }
.status-dot { width: .55rem; height: .55rem; border-radius: 50%; background: #f59e0b; }
.status-dot.ok { background: #22c55e; }
.status-dot.simulated { background: #38bdf8; }
.status-dot.error { background: #ef4444; }

.connection-banner {
  position: absolute;
  z-index: 1100;
  top: 5.5rem;
  left: 50%;
  width: min(34rem, calc(100% - 2rem));
  padding: .7rem 1rem;
  transform: translateX(-50%);
  border: 1px solid #fca5a5;
  border-radius: .55rem;
  background: rgb(127 29 29 / 95%);
  box-shadow: 0 .4rem 1.5rem rgb(0 0 0 / 35%);
  color: #fff;
  font-size: .82rem;
  font-weight: 700;
  text-align: center;
}
.connection-banner[hidden] { display: none; }

.location-control {
  display: grid;
  gap: .35rem;
  margin-top: 4.8rem !important;
  position: relative;
}
.location-toggle, .home-location {
  width: 2.1rem;
  height: 2.1rem;
  border: 0;
  border-radius: .3rem;
  background: #0f172a;
  color: #f8fafc;
  font: 700 1.3rem/1 system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 1px 5px rgb(0 0 0 / 45%);
}
.home-location { display: grid; place-items: center; padding: .48rem; }
.home-location svg { width: 100%; height: 100%; fill: currentColor; }
.location-toggle:hover, .location-toggle:focus-visible,
.home-location:hover, .home-location:focus-visible { background: #1e293b; }
.home-location:disabled { cursor: wait; opacity: .65; }
.location-toggle:focus-visible, .home-location:focus-visible, .location-action:focus-visible, .location-close:focus-visible,
.coordinate-form input:focus-visible { outline: 2px solid #38bdf8; outline-offset: 2px; }
.location-panel {
  position: absolute;
  top: 2.45rem;
  left: 2.7rem;
  width: 17rem;
  padding: .75rem;
  color: #f8fafc;
}
.location-panel[hidden] { display: none; }
.location-panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.settings-section {
  min-width: 0;
  margin: 0;
  padding: .65rem 0 0;
  border: 0;
  border-top: 1px solid rgb(148 163 184 / 20%);
}
.settings-section + .settings-section { margin-top: .75rem; }
.settings-section legend { padding: 0 .35rem 0 0; color: #cbd5e1; font-size: .72rem; font-weight: 700; }
.settings-checkbox { display: flex; align-items: center; gap: .45rem; color: #e2e8f0; font-size: .72rem; cursor: pointer; }
.settings-checkbox input { width: 1rem; height: 1rem; accent-color: #38bdf8; }
.settings-checkbox input:focus-visible { outline: 2px solid #38bdf8; outline-offset: 2px; }
.location-close {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  font: 1.25rem/1 system-ui, sans-serif;
  cursor: pointer;
}
.coordinate-form { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; margin: .55rem 0; }
.coordinate-form label { display: grid; gap: .2rem; color: #94a3b8; font-size: .67rem; }
.coordinate-form input {
  width: 100%;
  min-width: 0;
  padding: .4rem;
  border: 1px solid #475569;
  border-radius: .3rem;
  background: #1e293b;
  color: #f8fafc;
  font: inherit;
}
.location-action {
  width: 100%;
  padding: .45rem .55rem;
  border: 1px solid #475569;
  border-radius: .3rem;
  background: #1e293b;
  color: #f8fafc;
  font: 700 .72rem system-ui, sans-serif;
  cursor: pointer;
}
.location-action:hover { background: #334155; }
.location-action:disabled { opacity: .55; cursor: wait; }
.coordinate-form .location-action { grid-column: 1 / -1; }
.location-pick, .location-reset { margin-top: .4rem; }
.location-message { min-height: 1.2em; margin: .55rem 0 0; color: #bae6fd; font-size: .68rem; line-height: 1.35; }
#map.picking-position, #map.picking-position .leaflet-interactive { cursor: crosshair; }

.legend {
  position: absolute;
  z-index: 1000;
  left: 1rem;
  bottom: 1rem;
  display: grid;
  gap: .35rem;
  padding: .65rem .8rem;
  font-size: .75rem;
}
.legend[hidden] { display: none !important; }
.legend span { display: flex; align-items: center; gap: .45rem; }
.legend i { width: .65rem; height: .65rem; border-radius: 50%; display: inline-block; }
.age-new { background: #facc15; }
.age-recent { background: #f97316; }
.age-old { background: #d946ef; }
.age-archive { background: #bae6fd; }

.strike-pane-toggle {
  position: absolute;
  z-index: 1000;
  top: 1rem;
  right: 1rem;
  display: none;
  align-items: center;
  gap: .45rem;
  padding: .65rem .8rem;
  color: #f8fafc;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}

.strike-pane-toggle:hover,
.icon-button:hover,
.strike-entry:hover,
.strike-entry:focus-visible {
  background: rgb(30 41 59 / 96%);
}

.strike-pane-toggle:focus-visible,
.icon-button:focus-visible,
.strike-entry:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.strike-pane {
  position: absolute;
  z-index: 1050;
  top: 1rem;
  right: 1rem;
  bottom: 1rem;
  width: min(22rem, calc(100% - 2rem));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.strike-pane[hidden] { display: none; }
.strike-pane[hidden] + .legend { display: grid; }
.strike-pane-toggle[aria-expanded="false"] { display: flex; }

.strike-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1rem .7rem;
  border-bottom: 1px solid rgb(148 163 184 / 20%);
}

.strike-pane-header h2 { margin: 0; font-size: 1rem; }
.strike-pane-header span { color: #94a3b8; font-size: .72rem; }

.view-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: .45rem 1rem 0;
  background: rgb(15 23 42 / 65%);
}

.view-tabs button {
  padding: .45rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #94a3b8;
  font: 700 .75rem system-ui, sans-serif;
  cursor: pointer;
}

.view-tabs button[aria-selected="true"] { border-color: #38bdf8; color: #f8fafc; }
.view-tabs button:focus-visible { outline: 2px solid #38bdf8; outline-offset: -2px; }

.history-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid rgb(148 163 184 / 20%);
  background: rgb(15 23 42 / 65%);
}

.history-form[hidden] { display: none; }
.history-form label { display: grid; gap: .2rem; min-width: 0; }
.history-form label:first-child { grid-column: 1 / -1; }
.history-form label span { color: #94a3b8; font-size: .68rem; }
.history-form select, .history-form input, .history-form button, .history-load-more {
  min-width: 0;
  padding: .42rem .5rem;
  border: 1px solid #475569;
  border-radius: .35rem;
  background: #1e293b;
  color: #f8fafc;
  font: inherit;
  font-size: .72rem;
}
.history-form button { grid-column: 1 / -1; font-weight: 700; cursor: pointer; }
.history-form button:hover, .history-load-more:hover { background: #334155; }
.history-form select:focus-visible, .history-form input:focus-visible,
.history-form button:focus-visible, .history-load-more:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}
#history-message { grid-column: 1 / -1; margin: 0; color: #94a3b8; font-size: .66rem; line-height: 1.35; }
#statistics-message { grid-column: 1 / -1; margin: 0; color: #94a3b8; font-size: .66rem; line-height: 1.35; }

.statistics-panel {
  min-height: 0;
  padding: .8rem 1rem 1rem;
  overflow-y: auto;
  scrollbar-color: #475569 transparent;
}
.statistics-panel[hidden] { display: none; }
.statistics-panel section + section { margin-top: 1rem; }
.statistics-panel h3 { margin: 0 0 .5rem; font-size: .78rem; }
.statistics-summary { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.statistic-card {
  padding: .55rem;
  border: 1px solid rgb(148 163 184 / 20%);
  border-radius: .4rem;
  background: rgb(30 41 59 / 70%);
  color: inherit;
  font: inherit;
  text-align: left;
}
.statistic-card:is(button) { cursor: pointer; }
.statistic-card:is(button):hover { border-color: #38bdf8; background: #334155; }
.statistic-card:is(button):focus-visible, .statistics-row:is(button):focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}
.statistic-card strong { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.statistic-card span { color: #94a3b8; font-size: .65rem; }
.statistics-ranking { display: grid; gap: .35rem; }
.statistics-row { display: grid; grid-template-columns: minmax(5rem, 1fr) 3fr auto; align-items: center; gap: .4rem; }
.statistics-row:is(button) {
  width: 100%;
  padding: .2rem 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.statistics-row:is(button):hover { background: rgb(56 189 248 / 10%); }
.statistics-row-label { overflow: hidden; color: #cbd5e1; font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.statistics-row-bar { height: .45rem; overflow: hidden; border-radius: 1rem; background: #1e293b; }
.statistics-row-bar i { display: block; height: 100%; border-radius: inherit; background: #38bdf8; }
.statistics-row-count { min-width: 2rem; color: #f8fafc; font-size: .68rem; text-align: right; font-variant-numeric: tabular-nums; }
.statistics-empty { margin: .4rem 0; color: #64748b; font-size: .68rem; }

.strike-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  padding: .65rem 1rem .75rem;
  border-bottom: 1px solid rgb(148 163 184 / 20%);
  background: rgb(15 23 42 / 65%);
}

.strike-filters label { display: grid; gap: .25rem; min-width: 0; }
.strike-filters label span { color: #94a3b8; font-size: .68rem; }
.strike-filters select {
  min-width: 0;
  width: 100%;
  padding: .42rem 1.65rem .42rem .5rem;
  border: 1px solid #475569;
  border-radius: .35rem;
  background: #1e293b;
  color: #f8fafc;
  font: inherit;
  font-size: .72rem;
  text-overflow: ellipsis;
}

.strike-filters select:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}

.icon-button {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: .35rem;
  background: transparent;
  color: #cbd5e1;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.strike-list {
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: #475569 transparent;
}
.strike-list[hidden] { display: none; }

.strike-entry {
  width: 100%;
  display: grid;
  gap: .25rem;
  padding: .7rem 1rem;
  border: 0;
  border-bottom: 1px solid rgb(148 163 184 / 14%);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.strike-entry-new { animation: strike-entry-arrival 1.2s ease-out; }
.strike-entry-selected { animation: strike-entry-selected 1.4s ease-out; }

.strike-entry-primary {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.strike-entry-dot {
  flex: 0 0 auto;
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
}

.strike-entry-time { font-size: .82rem; font-weight: 650; }
.strike-entry-age { margin-left: auto; color: #94a3b8; font-size: .72rem; }
.strike-entry-place { color: #f8fafc; font-size: .78rem; font-weight: 600; }
.strike-entry-metadata { color: #cbd5e1; font-size: .74rem; }
.strike-entry-coordinates { color: #64748b; font-size: .68rem; font-variant-numeric: tabular-nums; }

.current-meter {
  display: grid;
  grid-template-columns: minmax(4rem, 1fr) auto;
  align-items: center;
  gap: .55rem;
  color: #cbd5e1;
}
.current-meter-track {
  height: .42rem;
  overflow: hidden;
  border-radius: 1rem;
  background: #334155;
}
.current-meter-track i { display: block; height: 100%; min-width: .2rem; border-radius: inherit; }
.current-meter strong { min-width: 3.6rem; font-size: .72rem; text-align: right; font-variant-numeric: tabular-nums; }
.current-low .current-meter-track i { background: #38bdf8; }
.current-moderate .current-meter-track i { background: #facc15; }
.current-strong .current-meter-track i { background: #f97316; }
.current-extreme .current-meter-track i { background: #ef4444; box-shadow: 0 0 .4rem #ef4444; }
.popup-current-meter { min-width: 12rem; margin-top: .35rem; }
.popup-current-meter strong { color: #f8fafc; }

.strike-list-empty {
  margin: auto;
  padding: 2rem;
  color: #94a3b8;
  font-size: .8rem;
  text-align: center;
}

.strike-list-empty[hidden] { display: none; }

.history-load-more {
  flex: 0 0 auto;
  margin: .55rem 1rem;
  cursor: pointer;
}
.history-load-more[hidden] { display: none; }

footer { padding: .4rem .8rem; background: #0f172a; color: #94a3b8; font-size: .7rem; text-align: center; }
a { color: #bae6fd; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #0f172a; color: #f8fafc; }

.strike-shockwave-glow { filter: drop-shadow(0 0 .25rem rgb(255 255 255 / 85%)); }

.strike-marker-icon {
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
}

.strike-marker-core {
  width: 1.45rem;
  height: 1.45rem;
  display: grid;
  place-items: center;
  border: 3px solid #020617;
  border-radius: 50%;
  background: var(--strike-color);
  box-shadow:
    0 0 0 2px rgb(255 255 255 / 92%),
    0 0 .85rem .2rem var(--strike-color);
}

.strike-marker-core svg {
  width: .78rem;
  height: .78rem;
  fill: #020617;
  filter: drop-shadow(0 1px 0 rgb(255 255 255 / 20%));
}

.strike-marker-new .strike-marker-core {
  width: 1.7rem;
  height: 1.7rem;
  animation: strike-marker-flash 1.8s ease-in-out infinite;
}

.strike-marker-archive .strike-marker-core {
  box-shadow: 0 0 0 2px rgb(255 255 255 / 92%), 0 0 .45rem rgb(186 230 253 / 70%);
}

@keyframes strike-marker-flash {
  0%, 100% { filter: brightness(1); }
  45% { filter: brightness(1.35); }
}

@keyframes strike-entry-arrival {
  0% { background: rgb(250 204 21 / 55%); box-shadow: inset .25rem 0 #fde047; }
  100% { background: transparent; box-shadow: inset 0 0 transparent; }
}

@keyframes strike-entry-selected {
  0%, 35% { background: rgb(56 189 248 / 55%); box-shadow: inset .25rem 0 #38bdf8; }
  100% { background: transparent; box-shadow: inset 0 0 transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .strike-marker-new .strike-marker-core { animation: none; }
  .strike-entry-new { animation: none; box-shadow: inset .2rem 0 #fde047; }
  .strike-entry-selected { animation: none; box-shadow: inset .2rem 0 #38bdf8; }
}

@media (max-width: 760px) {
  .app-header { left: 3.2rem; top: .6rem; right: 3.7rem; padding: .55rem .7rem; }
  .app-header p { display: none; }
  .status { white-space: normal; justify-content: flex-end; text-align: right; }
  .connection-banner { top: 4.9rem; width: calc(100% - 1.2rem); }
  .location-control { margin-top: 4.2rem !important; }
  .location-panel { width: min(17rem, calc(100vw - 4.5rem)); }
  .legend { left: .6rem; bottom: .6rem; }
  .strike-pane {
    top: .6rem;
    right: .6rem;
    bottom: .6rem;
    width: calc(100% - 1.2rem);
  }
  .strike-pane-toggle { top: .6rem; right: .6rem; padding: .55rem .65rem; }
  .strike-pane-toggle span:last-child { display: none; }
}
