:root {
  --bg: #15181d;
  --panel: rgba(24, 27, 33, 0.94);
  --panel-solid: #1c2027;
  --border: #2d333d;
  --text: #e4e7ec;
  --muted: #9aa3b0;
  --accent: #f0b429;
  --side-w: 290px;
  --top-h: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

#map {
  position: absolute;
  top: var(--top-h);
  left: 0;
  right: var(--side-w);
  bottom: 0;
  background: #0f1115;
}

body.side-hidden #map { right: 0; }
body.side-hidden #sidebar { transform: translateX(100%); }

.leaflet-container { background: #0f1115; font: inherit; }
.leaflet-tile { image-rendering: pixelated; image-rendering: crisp-edges; }

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

#topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toggle-side, #copy-link, select, .tab, input[type=search] {
  background: #252a33;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

#toggle-side { padding: 4px 10px; cursor: pointer; font-size: 16px; }
select { padding: 5px 8px; cursor: pointer; }
#online { margin-left: auto; color: var(--muted); white-space: nowrap; }

#sidebar {
  position: absolute;
  top: var(--top-h);
  right: 0;
  bottom: 0;
  width: var(--side-w);
  background: var(--panel-solid);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 900;
  transition: transform 0.2s ease;
}

.tabs { display: flex; gap: 6px; padding: 10px 10px 0; }
.tab { flex: 1; padding: 6px; cursor: pointer; }
.tab.active { background: #343b47; border-color: var(--accent); color: var(--accent); }

#search { margin: 10px; padding: 7px 10px; }
.tab-body { display: none; overflow-y: auto; flex: 1; }
.tab-body.active { display: block; }

.list { list-style: none; margin: 0; padding: 0 6px 10px; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.list li:hover { background: #262b34; }
.list .sub { color: var(--muted); font-size: 12px; }
.list .grow { flex: 1; min-width: 0; }
.list .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.list .empty { color: var(--muted); cursor: default; justify-content: center; }
.list .empty:hover { background: none; }

.head {
  width: 24px; height: 24px;
  border-radius: 4px;
  flex: none;
  image-rendering: pixelated;
  background: #3a4150;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 13px;
}

#coords, #copy-link {
  position: absolute;
  bottom: 10px;
  z-index: 800;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: Consolas, monospace;
  font-size: 13px;
}
#coords { left: 10px; pointer-events: none; }
#copy-link { left: 190px; cursor: pointer; font-family: inherit; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 50px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 14px;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

/* Leaflet: тёмные попапы и контролы */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border);
}
.leaflet-popup-content { margin: 12px 14px; min-width: 210px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-bar a, .leaflet-control-layers {
  background: var(--panel-solid);
  color: var(--text);
  border-color: var(--border);
}
.leaflet-bar a:hover { background: #2a303a; }
.leaflet-control-layers-expanded { padding: 8px 12px; }
.leaflet-control-layers label { margin: 3px 0; }
.leaflet-tooltip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.leaflet-tooltip-top:before { border-top-color: var(--border); }

.popup h3 { margin: 0 0 6px; font-size: 16px; color: var(--accent); }
.popup .row { display: flex; justify-content: space-between; gap: 12px; margin: 2px 0; }
.popup .row span:first-child { color: var(--muted); }
.popup .tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.popup .tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  background: #2a303a;
  border: 1px solid var(--border);
}
.popup .tag.on { border-color: #4caf50; color: #9be29e; }
.popup .tag.off { color: var(--muted); text-decoration: line-through; }
.popup .names { margin-top: 6px; color: var(--muted); font-size: 12px; max-height: 90px; overflow-y: auto; }
.popup .badge { color: #111; padding: 0 6px; border-radius: 4px; font-size: 12px; font-weight: 600; }

/* Подписи территорий */
.area-label {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000;
  white-space: nowrap;
}
.area-label:before { display: none; }
.nation-label { font-size: 15px; letter-spacing: 1px; text-transform: uppercase; opacity: 0.85; }
#map.zoom-far .area-label.town-label { display: none; }
#map.zoom-very-far .area-label { display: none; }

/* Игроки */
.player-icon { pointer-events: auto; }
.player-icon .pin {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%);
  width: max-content;
}
.player-icon img, .player-icon .head {
  width: 22px; height: 22px;
  border: 2px solid #fff;
  border-radius: 4px;
  box-shadow: 0 0 4px #000;
  image-rendering: pixelated;
}
.player-icon .label {
  margin-top: 2px;
  padding: 0 5px;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 3px;
  font-size: 12px;
  color: #fff;
  white-space: nowrap;
}

.spawn-icon {
  font-size: 22px;
  color: var(--accent);
  text-shadow: 0 0 4px #000;
  text-align: center;
  line-height: 24px;
}

@media (max-width: 700px) {
  :root { --side-w: 100%; }
  #map { right: 0; }
  body:not(.side-hidden) #map { visibility: hidden; }
  #topbar h1 { display: none; }
  #copy-link { left: auto; right: 10px; }
}
