:root {
  --font: Libre Franklin, sans-serif;
  --light: rgb(161, 227, 253);
  --dark: #0d0000;
  --yellow-orange: rgb(228, 175, 0);
  --orange-light: rgb(255, 234, 166);
  --red: rgb(230, 30, 30);
  --green: rgb(0, 204, 44);
  --yellow: rgb(255, 250, 61);
  --orange: #ff7d18;
  --neutral: rgb(223, 223, 223);  
  --gray: rgba(57, 57, 57, 0.8);
  --background: rgba(25, 25, 25, 0.8);
  --shadow: 0 0 15px rgba(0, 0, 0, 0.2);
  --radius: 5px;
  --border: 1px solid var(--dark);
  --row: #ffd900;
  --studyFill: rgba(227, 223, 166, 0.2);
  --studyStroke: #ffffff;
  --barrier: #00ffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--background);
  font-family: var(--font);
  color: var(--light);
  font-size: 100%;
}

h1 {
  position: absolute;
  z-index: 650;
  top: 10px;
  left: 15px;
  padding: 0px 4px;
  margin: 0;
  font-family: "Libre Franklin", sans-serif;
  font-size: 3em;
  color: whitesmoke;
  text-shadow: 0 0 3px var(--dark), 0 0 5px var(--dark), 0 0 7px var(--dark),
    0 0 10px var(--dark);
}

#map {
  position: absolute;
  width: 100%;
  top: 0;
  bottom: 0;
  background-color: var(--gray);
}

h2 {
  position: absolute;
  z-index: 650;
  top: 10px;
  left: 15px;
  padding: 8px 15px;
  margin: 0;
  color: var(--light);
  font-size: 1em;
  text-transform: uppercase;
  background: var(--background);
  border-radius: var(--radius);
  border: var(--border);
  cursor: pointer;
}

h2:hover {
  background: var(--yellow-orange);
  color: var(--dark);
}

h2:active {
  background: var(--orange-light);
}

.legend {
  /* margin-top: 5px; */
  padding: 10px 12px;
  background: var(--background);
  border: var(--border);
  border-radius: var(--radius);
  color: #ffffff;
}

.legend-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.legend-swatch {
  display: inline-block;
  flex: 0 0 auto;
}

/* Noise Study Area */
.legend-swatch.poly {
  width: 18px;
  height: 18px;
  background: var(--studyFill);
  border: 3px solid var(--studyStroke);
  border-radius: 3px;
}

/* Existing ROW */
.legend-swatch.line {
  width: 28px;
  height: 0;
  border-top: 3px solid var(--row);
}

.legend-swatch.barrier {
  width: 28px;
  height: 0;
  border-top: 3px solid var(--barrier);
}

/* Point Swatches */
.legend-swatch.point {
  width: 15px;
  height: 15px;
  border: 2px solid #eeeeee;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.75);
}

/* Legend point swatches */
.legend-swatch.point.red {
  background: var(--red);
}
.legend-swatch.point.green {
  background: var(--green);
}
.legend-swatch.point.yellow {
  background: var(--yellow);
}
.legend-swatch.point.orange {
  background: var(--orange);
}
.legend-swatch.point.neutral {
  background: var(--neutral);
}

#ui-controls {
  position: absolute;
  z-index: 700;
  bottom: 30px;
  left: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--background);
  border: var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  color: var(--light);
  font-family: var(--font);
}

#ui-controls input[type="range"] {
  width: 120px;
}
#ui-controls span {
  min-width: 2.5rem;
  text-align: right;
  display: inline-block;
}

#ui-controls label {
  font-size: 1rem;
}

#modal {
  display: none;
  position: absolute;
  z-index: 2000;
  padding: 10px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: var(--background);
  color: whitesmoke;
  font-size: 1.5em;
}

#modal .container {
  width: 500px;
  margin: 10px auto;
  padding: 5px 20px;
  position: relative;
  background: var(--background);
  border-radius: var(--radius);
  border: var(--border);
}

#modal .legend {
  position: relative;
  display: block;
  margin: 12px 0;
}

/* Native MathML inside the modal */
#modal math {
  display: block;
  margin: 14px auto; /* space from surrounding <p> */
  padding: 8px 12px; /* inner breathing room */
  text-align: center;
  font-family: var(--font);
  color: var(--light);
  font-size: 1.1rem;
  line-height: 1.35;
  max-width: min(90%, 700px);
  overflow-x: auto; /* guard long equations */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Token styling */
#modal math mi {
  font-style: italic;
} /* variables */
#modal math mn {
  font-variant-numeric: tabular-nums;
} /* numbers align */
#modal math mo {
  padding: 0 0.35em;
} /* operator spacing */
#modal math mtext {
  font-style: normal;
} /* plain text */

/* Fractions */
#modal math mfrac {
  margin: 0 0.15em;
}
#modal math mfrac > :first-child,
#modal math mfrac > :last-child {
  padding: 0 0.25em;
  text-align: center;
}

/* Sub/Sup spacing */
#modal math msub,
#modal math msup,
#modal math msubsup {
  margin: 0 0.1em;
}

/* Tables (if you use aligned equations) */
#modal math mtable {
  margin: 6px auto;
}
#modal math mtd {
  padding: 0 0.4em;
  text-align: center;
}

/* Mobile */
@media (max-width: 576px) {
  #modal math {
    font-size: 1rem;
  }
}

#modal a:link,
#modal a:visited {
  color: var(--yellow-orange);
}

#modal a:hover {
  color: var(--orange-light);
}

#modal div {
  margin: 20px 0;
}

#modal h1 {
  display: none;
}

#modal p {
  font-size: 1.1rem;
  line-height: 1.5rem;
  margin: 5px 0;
}

#modal .footer {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 16px;
}

#modal .footer img {
  max-width: 240px;
  height: auto;
  opacity: 0.95;
}

#modal .container > span {
  position: absolute;
  top: 7px;
  right: 7px;
  cursor: pointer;
}

#modal pre {
  font-size: 1rem;
}

#modal .receptor-groups {
  margin: 8px 0 16px 1.2rem;
  padding: 0;
}
#modal .receptor-groups li {
  margin: 4px 0;
  font-size: 1.1rem;
}

#modal .receptor-groups li::marker {
  color: var(--neutral);
}

/* === MapLibre popup styling (replacing Leaflet selectors) === */

.ml-tooltip-own {
  font-size: 1.2em;
  font-family: var(--font);
}

.ml-tooltip-own h3 {
  font-size: 1.4em;
  font-weight: bold;
  line-height: 1em;
  color: var(--light);
  margin: 0.5em 0 0.8em 0;
}

.maplibregl-popup {
 max-width: 750px !important;
}

.maplibregl-popup-content {
  background: var(--background);
  color: var(--light);
  box-shadow: var(--shadow);
  border: var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  max-width: none;
  width: auto;
}

.maplibregl-popup-tip {
  background: var(--background);
}

.maplibregl-popup-close-button {
  color: var(--light);
}

.kv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
  margin: 2px 0;
}

/* left label */
.kv-row .key {
  /* white-space: nowrap; */
  font-weight: 600;
  text-decoration: underline;
}

/* dotted leader filler */
.kv-row .dots {
  flex: 1 1 auto;
  border-bottom: 1px dotted rgba(183, 232, 251, 0.75);
  height: 0;
  min-width: 8px;
  transform: translateY(-1px);
}

/* right value chip */
.kv-row .value {
  text-align: right;
}

.popup-content,
.kv-row {
  min-width: 0;
}
.kv-row .key,
.kv-row .dots,
.kv-row .value {
  min-width: 0;
}

/* Popup value chip colors */
.kv-row .value.red {
  background: var(--red);
  color: var(--dark);
}
.kv-row .value.green {
  background: var(--green);
  color: var(--dark);
}

/* Hover scale for divIcon markers */
.leaflet-marker-icon.hovered {
  transform: scale(3);
}

/* Small devices (portrait phones, 576px and below) */
@media (max-width: 576px) and (orientation: portrait) {
  h1 {
    display: none;
  }

  #modal .container {
    width: 90%;
  }

  #modal h1 {
    display: block;
    position: relative;
    margin: 20px auto;
    padding: 0;
    font-size: 1.6rem;
    top: unset;
    left: unset;
    background: unset;
    border-radius: unset;
    border: unset;
  }

  #modal pre {
    font-size: 0.7rem;
  }
  #ui-controls {
    top: auto !important;
    bottom: calc(env(safe-area-inset-bottom, 0) + 20px) !important;
    right: 12px;
    left: auto;
  }

    .maplibregl-popup {
    max-width: min(92vw, 520px) !important;
  }
}
