:root {
  --bg: #12141a; /* same as the server-side fog colour */
  --panel: rgba(24, 26, 32, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e6e6e6;
  --muted: #9aa0a8;
  --accent: #e0b35a;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--bg);
  cursor: grab;
}
#map.leaflet-drag-target, #map:active { cursor: grabbing; }

.leaflet-container { font-family: var(--font); }
.leaflet-tile { image-rendering: auto; }

/* Zoom buttons styled dark */
.leaflet-bar { border: 1px solid var(--panel-border) !important; box-shadow: var(--shadow) !important; }
.leaflet-bar a {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-bottom-color: var(--panel-border) !important;
}
.leaflet-bar a:hover { background: #2a2d35 !important; }
.leaflet-bar a.leaflet-disabled { color: #555 !important; }
.leaflet-control-scale-line {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--muted) !important;
}

/* Top status pill */
.status {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  max-width: calc(100vw - 120px);
  pointer-events: none;
}
.status #world-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.status .clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.status .clock:empty { display: none; }
.render { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.render.hidden { display: none; }
.render .bar { width: 90px; height: 5px; background: rgba(255,255,255,0.12); border-radius: 3px; overflow: hidden; }
.render .bar div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }

/* Player panel */
.panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 260px;
  max-height: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 10px 14px 6px;
}
.panel header #explored { margin-left: auto; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.panel-title { margin: 0; padding: 10px 14px 4px; font-size: 14px; font-weight: 600; }
.tab {
  border: none;
  background: none;
  color: var(--muted);
  font: 600 13px var(--font);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: rgba(255,255,255,0.08); }
.tab-page { display: none; flex-direction: column; min-height: 0; }
.tab-page.active { display: flex; }
.panel ul { list-style: none; margin: 0; padding: 0 6px; overflow-y: auto; }
.panel li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.panel li:hover { background: rgba(255,255,255,0.06); }
.panel li.following { background: rgba(224, 179, 90, 0.16); }
.panel li.hidden-pos { cursor: default; opacity: 0.6; }
.panel li .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c, #fff); box-shadow: 0 0 0 2px rgba(0,0,0,0.5); }
.panel li.hidden-pos .dot { background: transparent; border: 2px dashed var(--muted); }
.panel li .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel li .sub { grid-column: 2 / span 2; color: var(--muted); font-size: 12px; margin-top: -2px; }
.panel li .follow { color: var(--accent); font-size: 12px; }
.panel li .skull { color: #e06060; font-size: 12px; }
.panel li.history { grid-template-columns: 1fr auto; }
.panel li.history .stats { grid-column: 1 / span 2; color: var(--muted); font-size: 12px; }
.panel li.history .online-dot { width: 8px; height: 8px; border-radius: 50%; background: #5fd27a; }
.panel li.history .sessions { grid-column: 1 / span 2; margin: 4px 0 0; padding: 0; list-style: none; font-size: 12px; }
.panel li.history .sessions li { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding: 3px 0; cursor: default; color: var(--muted); }
.panel li.history .sessions li:hover { background: none; }
.panel li.history .sessions .dur { color: var(--text); font-variant-numeric: tabular-nums; }
.panel #no-history { margin: 0; padding: 4px 14px 12px; }
.panel #no-history.hidden { display: none; }
.panel #no-pins { margin: 0; padding: 4px 14px 12px; }
.panel #no-pins.hidden { display: none; }
.marker-filters { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 2px 14px 8px; font-size: 12px; color: var(--muted); }
.marker-filters label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.marker-filters label.hidden { display: none; }
.marker-filters input, .panel li.owner input { accent-color: var(--accent); margin: 0; }
.panel li.owner { grid-template-columns: auto 12px 1fr auto; cursor: pointer; }
.panel li.owner .dot { width: 10px; height: 10px; }
.panel li.owner .count { color: var(--muted); font-size: 12px; }
.panel li.owner .online-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #5fd27a; margin-left: 6px; vertical-align: middle; }
.panel li.owner.unknown .name { color: var(--muted); font-style: italic; }
.panel footer { padding: 8px 14px 10px; font-size: 11px; line-height: 1.4; border-top: 1px solid var(--panel-border); }
.panel #no-players { margin: 0; padding: 4px 14px 12px; }
.panel #no-players.hidden { display: none; }
.muted { color: var(--muted); font-size: 12px; }

.panel-toggle {
  display: none;
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font: 600 14px var(--font);
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* Coordinates readout */
.coords {
  position: absolute;
  left: 10px;
  bottom: 30px;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  pointer-events: none;
}
.coords:empty { display: none; }

/* Player markers */
.player-marker { background: none !important; border: none !important; }
.leaflet-marker-icon.player-marker { transition: transform 1s linear; }
.leaflet-zoom-anim .leaflet-marker-icon.player-marker { transition: none; }
.pm {
  position: relative;
  width: 0;
  height: 0;
}
.pm .pm-arrow {
  position: absolute;
  left: -14px;
  top: -14px;
  width: 28px;
  height: 28px;
  transform: rotate(var(--yaw, 0deg));
  transition: transform 0.6s ease;
}
.pm .pm-arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -3px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--c, #fff);
  filter: drop-shadow(0 0 1px #000);
}
.pm .pm-dot {
  position: absolute;
  left: -7px;
  top: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c, #fff);
  border: 2px solid #111;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.7), 0 2px 6px rgba(0,0,0,0.6);
}
.pm .pm-label {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(10, 12, 16, 0.85);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 1px 1px #000;
  pointer-events: none;
}
.pm.no-heading .pm-arrow { display: none; }
.pm.following .pm-dot { box-shadow: 0 0 0 3px var(--accent), 0 2px 6px rgba(0,0,0,0.6); }

/* Cartography table markers and death markers */
.pin-marker { background: none !important; border: none !important; }
.pin { position: relative; width: 0; height: 0; --pc: #ddd; }
.pin .pin-glyph {
  position: absolute;
  left: -8px;
  top: -8px;
  width: 16px;
  height: 16px;
  background: var(--pc);
  filter: drop-shadow(0 0 1px #000) drop-shadow(0 1px 2px rgba(0,0,0,0.7));
}
.pin-fire { --pc: #f08a3c; }
.pin-fire .pin-glyph { clip-path: polygon(50% 0%, 78% 30%, 92% 62%, 76% 100%, 24% 100%, 8% 62%, 22% 30%); }
.pin-house { --pc: #e8c95a; }
.pin-house .pin-glyph { clip-path: polygon(50% 0%, 100% 42%, 86% 42%, 86% 100%, 14% 100%, 14% 42%, 0% 42%); }
.pin-hammer { --pc: #7fb2e5; }
.pin-hammer .pin-glyph { clip-path: polygon(0% 10%, 60% 10%, 60% 0%, 100% 0%, 100% 45%, 60% 45%, 60% 35%, 42% 35%, 42% 100%, 22% 100%, 22% 35%, 0% 35%); }
.pin-dot { --pc: #d8d8d8; }
.pin-dot .pin-glyph { border-radius: 50%; left: -6px; top: -6px; width: 12px; height: 12px; }
.pin-portal { --pc: #b07de8; }
.pin-portal .pin-glyph { border-radius: 50%; background: transparent; border: 4px solid var(--pc); box-sizing: border-box; }
.pin-boss { --pc: #e05555; }
.pin-boss .pin-glyph { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.pin-hildir { --pc: #ef8fc8; }
.pin-hildir .pin-glyph { border-radius: 50%; }
.pin-bed { --pc: #9fd0a0; }
.pin-bed .pin-glyph { border-radius: 3px; }
.pin-memorial, .pin-other { --pc: #b5b5b5; }
.pin-memorial .pin-glyph, .pin-other .pin-glyph { border-radius: 3px; }
/* Traders: twice the size of a normal marker, a tent shape with a coloured roof */
.pin-trader .pin-glyph {
  left: -16px;
  top: -16px;
  width: 32px;
  height: 32px;
  background: #f2e6c8;
  clip-path: polygon(50% 0%, 100% 48%, 88% 48%, 88% 100%, 12% 100%, 12% 48%, 0% 48%);
}
.pin-trader .pin-glyph::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 48%;
  background: var(--pc);
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.pin-trader .pin-glyph::after {
  content: "";
  position: absolute;
  left: 38%; right: 38%; bottom: 0;
  height: 36%;
  background: #3a2a1a;
}
.pin-trader-haldor { --pc: #e0b35a; }
.pin-trader-hildir { --pc: #ef8fc8; }
.pin-trader-bogwitch { --pc: #7fbf6a; }
.pin-trader-other { --pc: #b5b5b5; }
.pin-trader .pin-label { top: 18px; font-size: 13px; font-weight: 600; }
#map.labels-off .pin-trader .pin-label { display: block; }
.pin-death { --pc: #1a1a1f; }
.pin-death .pin-glyph { border-radius: 50%; border: 2px solid #f2f2f2; box-sizing: border-box; }
.pin-death .pin-glyph::before {
  content: "☠";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  line-height: 1;
}
.pin .pin-label {
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(10, 12, 16, 0.78);
  color: #eee;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}
.pin .pin-label:empty { display: none; }
.pin.checked { opacity: 0.5; }
.pin.checked .pin-label { text-decoration: line-through; }
.pin.checked .pin-glyph::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 2px;
  background: #ff5f5f;
  transform: rotate(-45deg);
}
#map.labels-off .pin-label { display: none; }

.pin-cluster {
  position: absolute;
  --s: 28px;
  left: calc(var(--s) / -2);
  top: calc(var(--s) / -2);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: rgba(20, 22, 28, 0.82);
  border: 2px solid #e6e1d4;
  box-sizing: border-box;
  box-shadow: 0 2px 6px rgba(0,0,0,0.6);
  color: #f2efe6;
  font: 600 12px/1 var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.pin-cluster-md { --s: 34px; font-size: 13px; }
.pin-cluster-lg { --s: 40px; font-size: 14px; }
.pin-cluster:hover { background: rgba(40, 44, 54, 0.92); }

@media (max-width: 720px) {
  /* The status pill spans the top on phones; keep the zoom buttons below it. */
  .leaflet-top .leaflet-control { margin-top: 62px; }
  .panel-toggle { display: block; }
  .panel { display: none; top: 62px; right: 10px; left: 10px; width: auto; max-height: 45%; }
  .panel.open { display: flex; }
  .status { max-width: calc(100vw - 130px); left: 10px; transform: none; }
  .render .bar { width: 50px; }
  .coords { bottom: 26px; }
}
