:root {
  color-scheme: dark;
  --bg: #071016;
  --panel: rgba(9, 20, 27, 0.94);
  --panel-soft: rgba(17, 34, 43, 0.8);
  --line: rgba(175, 218, 230, 0.14);
  --text: #edf7f8;
  --muted: #8faab1;
  --cyan: #63e6dd;
  --fresh: #fff3a3;
  --recent: #ffc857;
  --aging: #ff7a59;
  --old: #d85cff;
  --archive: #6d72e8;
  --error: #ff6f77;
  --shadow: 0 22px 65px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
summary {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 9999;
  padding: 10px 14px;
  transform: translateY(-150%);
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  height: 100%;
}

.topbar {
  position: relative;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 66px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 22, 0.94);
  backdrop-filter: blur(20px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(99, 230, 221, 0.34);
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(99, 230, 221, 0.18), rgba(99, 230, 221, 0.03));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.09);
}

.brand-mark svg {
  width: 22px;
  fill: var(--cyan);
  filter: drop-shadow(0 0 9px rgba(99, 230, 221, 0.4));
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-copy strong {
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-copy small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.source-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--recent);
  box-shadow: 0 0 0 4px rgba(255, 200, 87, 0.1);
}

.status-dot.ok {
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(99, 230, 221, 0.1), 0 0 13px rgba(99, 230, 221, 0.7);
}

.status-dot.error {
  background: var(--error);
  box-shadow: 0 0 0 4px rgba(255, 111, 119, 0.12);
}

.map-stage {
  position: relative;
  height: calc(100% - 66px);
}

#map {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 62% 42%, rgba(30, 77, 86, 0.22), transparent 32%),
    #071016;
}

.leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.64) contrast(1.08) saturate(0.78);
}

.leaflet-tile {
  background: #c8ceec;
}

.leaflet-control-attribution {
  border-radius: 7px 0 0 0;
  background: rgba(7, 16, 22, 0.78) !important;
  color: #91a5aa;
  font-size: 10px;
  backdrop-filter: blur(10px);
}

.leaflet-control-attribution a {
  color: #b6d8d8;
}

.leaflet-bar {
  overflow: hidden;
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  border-color: var(--line) !important;
  background: rgba(8, 20, 27, 0.94) !important;
  color: var(--text) !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border: 1px solid var(--line);
  background: rgba(8, 19, 26, 0.97);
  color: var(--text);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}

.leaflet-popup-content-wrapper {
  border-radius: 13px;
}

.leaflet-popup-content {
  min-width: 205px;
  margin: 14px 16px;
}

.strike-popup .popup-kicker {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.strike-popup strong {
  display: block;
  margin-bottom: 10px;
  font-size: 16px;
}

.strike-popup dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  margin: 0;
  font-size: 12px;
}

.strike-popup dt {
  color: var(--muted);
}

.strike-popup dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.control-panel {
  position: absolute;
  z-index: 600;
  top: 18px;
  left: 18px;
  width: min(366px, calc(100vw - 36px));
  max-height: calc(100% - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.2);
  scrollbar-width: thin;
  scrollbar-color: rgba(160, 195, 203, 0.22) transparent;
}

.panel-grabber {
  display: none;
}

.activity-summary,
.control-section,
.legend,
.source-details {
  padding: 18px 20px;
}

.control-section,
.legend,
.source-details {
  border-top: 1px solid var(--line);
}

.section-kicker,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-kicker {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.updated {
  overflow: hidden;
  max-width: 160px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.activity-summary h1 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 12px 0 17px;
}

.activity-summary h1 > span {
  font-size: clamp(42px, 6vw, 58px);
  line-height: 0.95;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}

.activity-summary h1 small {
  max-width: 110px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
  line-height: 1.4;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(175, 218, 230, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.028);
}

.metric span,
.metric strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
}

.metric strong {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.section-title-row h2,
.legend h2 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-title-row span {
  color: var(--muted);
  font-size: 11px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-top: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.18);
}

.segmented-control button {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.segmented-control button:hover {
  color: var(--text);
}

.segmented-control button.active {
  background: rgba(99, 230, 221, 0.12);
  color: var(--cyan);
  box-shadow: inset 0 0 0 1px rgba(99, 230, 221, 0.18);
}

.map-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-button {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.action-button:hover {
  border-color: rgba(99, 230, 221, 0.35);
  background: rgba(99, 230, 221, 0.08);
}

.action-button svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.legend {
  display: grid;
  grid-template-columns: auto repeat(5, 1fr);
  align-items: center;
  gap: 10px;
}

.legend h2 {
  margin-right: 4px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

.legend-dot.fresh { color: var(--fresh); background: var(--fresh); }
.legend-dot.recent { color: var(--recent); background: var(--recent); }
.legend-dot.aging { color: var(--aging); background: var(--aging); }
.legend-dot.old { color: var(--old); background: var(--old); }
.legend-dot.archive { color: var(--archive); background: var(--archive); }

.source-details {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.source-details summary {
  color: #bfd0d4;
  cursor: pointer;
  font-weight: 700;
}

.source-details p {
  margin: 11px 0 0;
}

.source-details a {
  color: var(--cyan);
}

.source-details .disclaimer {
  color: #c9b78a;
}

.map-message {
  position: absolute;
  z-index: 700;
  top: 20px;
  left: 50%;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 111, 119, 0.25);
  border-radius: 10px;
  background: rgba(55, 20, 25, 0.92);
  box-shadow: var(--shadow);
  color: #ffd8db;
  font-size: 12px;
  text-align: center;
  backdrop-filter: blur(14px);
}

.user-location-marker {
  width: 15px;
  height: 15px;
  border: 3px solid #e8ffff;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 8px rgba(99, 230, 221, 0.14), 0 0 18px rgba(99, 230, 221, 0.75);
}

.alert-card {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: linear-gradient(105deg, rgba(113, 112, 255, 0.08), rgba(99, 230, 221, 0.025));
}

.alert-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(130, 143, 255, 0.24);
  border-radius: 10px;
  background: rgba(113, 112, 255, 0.1);
  color: #aeb6ff;
}

.alert-icon svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.alert-copy {
  min-width: 0;
}

.alert-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.alert-title-row h2 {
  overflow: hidden;
  margin: 0;
  color: var(--text);
  font-size: 11px;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-state {
  flex: none;
  padding: 2px 5px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.alert-state.on {
  border-color: rgba(99, 230, 221, 0.25);
  background: rgba(99, 230, 221, 0.08);
  color: var(--cyan);
}

.alert-state.limited {
  border-color: rgba(255, 200, 87, 0.25);
  color: var(--recent);
}

.alert-copy p {
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#alert-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(130, 143, 255, 0.3);
  border-radius: 8px;
  background: rgba(113, 112, 255, 0.14);
  color: #d8dcff;
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
}

#alert-button:hover,
#alert-button.active {
  border-color: rgba(99, 230, 221, 0.35);
  background: rgba(99, 230, 221, 0.1);
  color: var(--cyan);
}

#alert-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.alert-card > small {
  grid-column: 2 / -1;
  color: #687f86;
  font-size: 9px;
  line-height: 1.35;
}

.map-actions {
  grid-template-columns: repeat(4, 1fr);
}

.legend {
  display: block;
}

.legend-title-row,
.legend-scale {
  display: flex;
  align-items: center;
}

.legend-title-row {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.legend-scale {
  justify-content: space-between;
  gap: 8px;
}

.sound-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #9ba6ff;
  font-size: 9px;
  white-space: nowrap;
}

.sound-key i {
  width: 13px;
  height: 13px;
  border: 1px solid #828fff;
  border-radius: 50%;
  box-shadow: 0 0 7px rgba(130, 143, 255, 0.6), inset 0 0 5px rgba(130, 143, 255, 0.2);
}

.map-message.alert {
  border-color: rgba(255, 200, 87, 0.35);
  background: rgba(42, 31, 11, 0.94);
  color: #fff0c5;
}

.map-message.success {
  border-color: rgba(99, 230, 221, 0.3);
  background: rgba(8, 38, 38, 0.94);
  color: #d8fffb;
}

.poland-outline {
  filter: drop-shadow(0 0 5px rgba(99, 230, 221, 0.3));
}

.sound-front-ring {
  filter: drop-shadow(0 0 5px rgba(130, 143, 255, 0.7));
}

.alert-radius-ring {
  filter: drop-shadow(0 0 5px rgba(99, 230, 221, 0.45));
}

.strike-flash {
  position: relative;
  width: 12px;
  height: 12px;
}

.strike-flash::before,
.strike-flash::after {
  position: absolute;
  inset: 1px;
  border: 1.5px solid var(--fresh);
  border-radius: 50%;
  content: "";
  opacity: 0;
  animation: strike-arrival 1.8s ease-out 1;
}

.strike-flash::after {
  animation-delay: 0.28s;
}

@keyframes strike-arrival {
  0% { opacity: 0.95; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(8); }
}

@media (max-width: 760px) {
  .topbar {
    height: 60px;
    padding: 0 14px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-copy small {
    display: none;
  }

  .source-pill {
    max-width: 48vw;
    padding: 6px 10px;
  }

  #source-state {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .map-stage {
    height: calc(100% - 60px);
  }

  .control-panel {
    top: auto;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    max-height: 52%;
    border-radius: 17px;
  }

  .panel-grabber {
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 999px;
    background: rgba(180, 210, 215, 0.2);
  }

  .activity-summary,
  .alert-card,
  .control-section,
  .legend,
  .source-details {
    padding: 13px 15px;
  }

  .activity-summary h1 {
    margin: 9px 0 12px;
  }

  .activity-summary h1 > span {
    font-size: 38px;
  }

  .activity-summary h1 small {
    max-width: 135px;
  }

  .metric {
    padding: 8px;
  }

  .alert-card {
    padding-top: 11px;
    padding-bottom: 11px;
  }

  .alert-card > small {
    display: none;
  }

  .legend {
    grid-template-columns: auto repeat(5, 1fr);
    gap: 6px;
  }

  .legend-row {
    flex-direction: column;
    gap: 3px;
  }

  .map-message {
    top: 10px;
  }

  .leaflet-bottom.leaflet-right {
    bottom: calc(52vh + 6px);
  }
}

@media (max-width: 390px), (max-height: 670px) {
  .legend,
  .source-details {
    display: none;
  }

  .control-panel {
    max-height: 56%;
  }

  .activity-summary h1 small {
    max-width: 115px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
