:root {
  --bg: #061720;
  --panel: #0b2230;
  --panel2: #11303f;
  --ink: #dce9f0;
  --dim: #7f9aa8;
  --accent: #f5d681;
  --line: #1c3a4a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
body { display: flex; flex-direction: column; }
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
#brand .t1 { color: var(--accent); font-weight: 800; letter-spacing: .06em; }
#brand .t2 { color: var(--ink); font-weight: 600; letter-spacing: .12em; font-size: 12px; }
#topactions { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; justify-content: flex-end; }
#topactions button {
  background: var(--panel2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
}
#langbar {
  display: flex;
  gap: 4px;
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  /* 14 languages: the row scrolls sideways instead of squeezing the top bar. */
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: thin;
}
#langbar button {
  background: none;
  border: none;
  color: var(--dim);
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  flex: 0 0 auto;
}
#langbar button.on {
  background: var(--accent);
  color: #09202c;
  font-weight: 700;
}
#maptabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
#maptabs button {
  flex: 0 0 auto;
  background: var(--panel);
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
#maptabs button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #09202c;
  font-weight: 700;
}
#maptabs button .rot {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  vertical-align: 1px;
  background: rgba(245, 214, 129, 0.16);
  color: var(--accent);
}
#maptabs button.on .rot { background: rgba(9, 32, 44, 0.16); color: #09202c; }
#stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
#panelbtn {
  position: absolute;
  z-index: 1000;
  right: 10px;
  top: 10px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}
#panel {
  position: absolute;
  z-index: 1001;
  right: 0;
  top: 0;
  bottom: 0;
  width: 272px;
  max-width: 85vw;
  background: rgba(8, 28, 40, .96);
  border-left: 1px solid var(--line);
  padding: 12px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .18s ease;
}
#panel.open { transform: none; }
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.chip.on { color: var(--ink); background: var(--panel2); }
#unselectall {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 10px;
  margin-top: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
#unselectall:hover { background: var(--panel2); }
.bb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(4, 16, 24, .75);
  color: #07202c;
}
.bb svg { display: block; width: 70%; height: 70%; fill: currentColor; }
.chip .bb, .lrow .bb { width: 20px; height: 20px; flex: 0 0 auto; }
.chip .bb { opacity: .35; }
.chip.on .bb { opacity: 1; }
.chip .cnt { margin-left: auto; font-size: 11px; color: var(--dim); }
.mbadge .bb {
  width: 100%;
  height: 100%;
  box-shadow: 0 0 0 1px rgba(230, 245, 255, .3), 0 1px 2px rgba(0, 0, 0, .5);
  transform: scale(var(--mks, 1));
}
#legendbtn {
  position: absolute;
  z-index: 1000;
  left: 10px;
  bottom: 10px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}
#legend[hidden] { display: none; }
#legend {
  position: absolute;
  z-index: 1002;
  left: 10px;
  bottom: 54px;
  width: 300px;
  max-width: calc(100vw - 20px);
  max-height: 65%;
  display: flex;
  flex-direction: column;
  background: rgba(8, 28, 40, .96);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#legendhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  font-weight: 700;
  color: var(--accent);
}
#legendclose {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
#legendrows { overflow-y: auto; padding: 2px 12px 12px; }
.lrow {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 5px 0;
}
.lrow .bb { margin-top: 1px; }
.lrow .ln { font-size: 13px; }
.lrow .ld { font-size: 11px; color: var(--dim); }
/* Narrow screens: the language bar drops to its own full-width row under the
   brand and scrolls horizontally, so About stays reachable and the map keeps
   its height. */
@media (max-width: 720px) {
  #topbar { flex-wrap: wrap; row-gap: 6px; }
  /* display:contents lifts the About button and the language bar up into
     #topbar's own flex flow: row 1 = brand + About, row 2 = full-width
     scrollable language bar. */
  #topactions { display: contents; }
  #aboutbtn { order: 1; margin-left: auto; }
  #langbar { order: 2; flex: 1 1 100%; }
}
@media (max-width: 640px) {
  #legend {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    max-height: 55vh;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
}
#editbox { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
#edittoggle { display: flex; gap: 8px; align-items: center; cursor: pointer; }
#editcontrols select,
#editcontrols button {
  width: 100%;
  margin-top: 8px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
}
#edithint { margin-top: 8px; font-size: 11px; color: var(--dim); }
#about[hidden] { display: none; }
#about {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(2, 10, 16, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#aboutcard {
  position: relative;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px;
}
#aboutcard h2 { margin-top: 0; color: var(--accent); }
#aboutcard a { color: #78c8ee; }
#aboutclose {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 22px;
  cursor: pointer;
}
.leaflet-container { background: var(--bg); font: inherit; }
.leaflet-popup-content-wrapper {
  background: var(--panel2);
  color: var(--ink);
  border-radius: 8px;
}
.leaflet-popup-tip { background: var(--panel2); }
.leaflet-popup-content { margin: 10px 14px; font-size: 13px; }
.pop .ttl { font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.pop .sub { color: var(--dim); font-size: 12px; }
.placelabel {
  width: 0;
  height: 0;
  overflow: visible;
}
.placelabel span {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  display: block;
  text-align: center;
  color: #eef6fa;
  text-shadow: 0 1px 3px #000, 0 0 6px #000;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: .03em;
}
@media (min-width: 900px) {
  #panel { transform: none; }
  #panelbtn { display: none; }
  #map { right: 272px; }
}
