:root {
  --bg: #12100c;
  --bg-deep: #0a0906;
  --panel: #1b1813;
  --panel-2: #242019;
  --panel-3: #2d281f;
  --line: #4a422f;
  --line-dark: #090806;
  --text: #f5f1e6;
  --muted: #c2b9a5;
  --accent: #8bd45c;
  --accent-dark: #4f8f32;
  --diamond: #68c7df;
  --gold: #f2c14e;
  --danger: #d96858;
  --font-pixel: "Press Start 2P", monospace;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 2px;
  --shadow: 0 5px 0 rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background:
    radial-gradient(circle at 50% 0%, rgba(139, 212, 92, .05), transparent 45%),
    var(--bg);
}

/* ---------------------------------------------------------------- topbar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 6px),
    linear-gradient(180deg, #2b2118, #1d1711);
  border-bottom: 4px solid var(--line-dark);
  box-shadow: inset 0 -2px 0 #4a3b27, 0 4px 14px rgba(0, 0, 0, .35);
  z-index: 1000;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: block;
  position: relative;
  background: linear-gradient(180deg, #6cbf45 0 27%, #86572f 27% 100%);
  border: 3px solid var(--line-dark);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, .22),
    inset -3px -3px 0 rgba(0, 0, 0, .28),
    0 3px 0 #090806;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: rgba(0, 0, 0, .18);
}
.brand-mark::before { left: 7px; top: 8px; width: 5px; height: 5px; }
.brand-mark::after { right: 8px; bottom: 7px; width: 6px; height: 6px; }
.brand-block {
  position: absolute;
  left: 5px;
  bottom: 5px;
  width: 6px;
  height: 6px;
  background: #5b9e3a;
  box-shadow: 10px 0 0 #97683a, 20px -12px 0 #78cb50;
  opacity: .8;
}
.brand h1 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: .3px;
  text-shadow: 2px 2px 0 #000;
}
.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 12px;
  border: 2px solid var(--line-dark);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .06), inset -2px -2px 0 rgba(0, 0, 0, .55);
  white-space: nowrap;
}
.status .dot {
  width: 9px;
  height: 9px;
  background: var(--gold);
  box-shadow: 0 0 0 2px var(--line-dark);
}
.status.live { color: var(--text); }
.status.live .dot { background: var(--accent); }
.status.error .dot { background: var(--danger); }

/* ---------------------------------------------------------------- search --- */
.search-box {
  position: relative;
  flex: 1 1 300px;
  max-width: 460px;
  min-width: 180px;
}
#search-input {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 40px;
  border: 3px solid var(--line-dark);
  border-radius: var(--radius);
  outline: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .28), transparent 55%),
    var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c2b9a5' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") no-repeat 13px center / 16px 16px;
  color: var(--text);
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, .55), inset -2px -2px 0 rgba(255, 255, 255, .05);
}
#search-input::placeholder { color: #9d947f; }
#search-input:focus {
  border-color: var(--accent-dark);
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, .55), 0 0 0 3px rgba(139, 212, 92, .22);
}

.search-results {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: 0;
  max-height: 330px;
  overflow-y: auto;
  padding: 6px;
  border: 3px solid var(--line-dark);
  background: var(--panel);
  box-shadow: inset 0 0 0 2px var(--line), 0 12px 0 rgba(0, 0, 0, .25), 0 18px 34px rgba(0, 0, 0, .55);
  z-index: 1100;
}
.search-results[hidden] { display: none; }
.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 8px;
  border: 2px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.search-result:hover,
.search-result:focus-visible {
  border-color: var(--line);
  background: var(--panel-3);
}
.search-player {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--diamond), var(--accent));
  border: 2px solid var(--line-dark);
}
.search-pin {
  width: 11px;
  height: 11px;
  margin: 3px 4px;
  flex: 0 0 auto;
  background: var(--danger);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.search-text { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.search-name { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-detail { color: var(--muted); font-size: 11px; }
.search-empty { padding: 12px 10px; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ main --- */
main { display: flex; min-height: 0; flex: 1; position: relative; }

.sidebar {
  width: 318px;
  flex: 0 0 318px;
  overflow-y: auto;
  padding: 16px 16px 22px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .025), transparent 18%, transparent 82%, rgba(0, 0, 0, .18)),
    var(--panel);
  border-right: 4px solid var(--line-dark);
  box-shadow: inset -2px 0 0 #302a20;
}
.sidebar section { margin-bottom: 20px; }
.sidebar h2 {
  margin: 0 0 10px;
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.7;
  letter-spacing: .06em;
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
}
.sidebar h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  background: var(--accent);
  box-shadow: 2px 2px 0 #000;
  vertical-align: 1px;
}

.world-tabs { display: flex; flex-wrap: wrap; gap: 7px; }
.world-tabs button {
  min-height: 40px;
  padding: 8px 11px;
  border: 3px solid var(--line-dark);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #373024, #29231a);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .08), inset -2px -3px 0 rgba(0, 0, 0, .45), 0 3px 0 #090806;
}
.world-tabs button:hover { background: linear-gradient(180deg, #453b2b, #30291e); }
.world-tabs button:active { transform: translateY(2px); box-shadow: inset 2px 2px 0 rgba(0, 0, 0, .35); }
.world-tabs button.active {
  border-color: var(--line-dark);
  background: linear-gradient(180deg, #6aa845, #4b7c30);
  color: #fff;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .22), inset -2px -3px 0 rgba(0, 0, 0, .35), 0 3px 0 #090806;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .45);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 9px 10px;
  border: 3px solid var(--line-dark);
  background: var(--panel-2);
  cursor: pointer;
  user-select: none;
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, .35), inset -2px -2px 0 rgba(255, 255, 255, .04);
}
.toggle-row:hover { background: var(--panel-3); }
.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-dark);
  cursor: pointer;
}
.toggle-row span { font-weight: 600; font-size: 13px; }

.player-list { display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--muted); font-size: 13px; margin: 0; padding: 4px 2px; }

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 7px;
  border: 2px solid transparent;
  background: rgba(0, 0, 0, .12);
  cursor: pointer;
}
.player-card:hover,
.player-card:focus-visible {
  border-color: var(--line);
  background: var(--panel-3);
}
.player-card .meta { min-width: 0; }
.player-card .name { font-size: 13px; font-weight: 700; }
.player-card .where {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.card-face {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line-dark);
  background: var(--bg-deep);
  image-rendering: pixelated;
}

.legend p {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 7px 0;
  color: var(--muted);
  font-size: 12px;
}
.swatch {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  display: inline-block;
  border: 2px solid var(--line-dark);
}
.legend .swatch.player { background: linear-gradient(135deg, var(--diamond), var(--accent)); }
.legend .swatch.banner {
  width: 12px;
  height: 12px;
  margin: 0 1px;
  background: var(--danger);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}
.legend .swatch.unknown {
  background:
    repeating-linear-gradient(45deg, #27221a 0 2px, #1a1711 2px 4px);
  border: 2px solid var(--line);
}
.hint { color: #a89f8b; font-size: 11px; margin-top: 10px; line-height: 1.5; }

/* ------------------------------------------------------------------- map --- */
#map {
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(circle at 50% 45%, #1b1913, #0a0906 78%);
}
.leaflet-container {
  background: #0a0906;
  font-family: var(--font-body);
}
.leaflet-container::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, .45);
  z-index: 500;
}
.leaflet-control-attribution {
  background: rgba(12, 10, 8, .85) !important;
  color: var(--muted) !important;
  border: 1px solid var(--line);
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-bar a {
  background: var(--panel-2) !important;
  color: var(--text) !important;
  border-color: var(--line-dark) !important;
  border-width: 2px !important;
}
.leaflet-bar a:hover { background: var(--panel-3) !important; }

.terrain-tile {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Player marker */
.player-marker { background: transparent; border: 0; }
.player-chip {
  transform: translate(-50%, calc(-100% + 14px));
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .65));
  pointer-events: auto;
}
.player-chip .label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 7px;
  margin-bottom: 3px;
  border: 2px solid var(--line-dark);
  background: rgba(20, 17, 12, .94);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.player-chip .face {
  width: 24px;
  height: 24px;
  border: 2px solid var(--diamond);
  background: var(--bg-deep);
  image-rendering: pixelated;
  box-shadow: 0 0 0 2px var(--line-dark);
}

/* Banner pins: Google-Maps-style shape, Minecraft label treatment. */
.banner-marker { background: transparent; border: 0; }
.banner-marker-wrap {
  display: flex;
  width: max-content;
  align-items: flex-start;
  gap: 6px;
  transform: translate(-12px, -32px);
  pointer-events: auto;
}
.banner-pin-svg {
  display: block;
  width: 24px;
  height: 32px;
  flex: 0 0 auto;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .55));
}
.banner-label {
  flex: 0 0 auto;
  width: max-content;
  max-width: 240px;
  margin-top: 3px;
  padding: 3px 8px;
  border: 2px solid var(--line-dark);
  background: #f3ead4;
  color: #2b2418;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7), 0 3px 0 rgba(0, 0, 0, .3);
}

/* Leaflet tooltips */
.leaflet-tooltip {
  background: #17140f;
  border: 2px solid var(--line);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05), 0 8px 22px rgba(0, 0, 0, .55);
  border-radius: 0;
  padding: 8px 10px;
  font-size: 12px;
}
.leaflet-tooltip-top:before { border-top-color: var(--line); }
.tooltip-title { font-weight: 700; margin-bottom: 3px; }
.tooltip-dim { color: var(--muted); margin-top: 4px; }

.map-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 800;
  max-width: 340px;
  padding: 16px 18px;
  border: 3px solid var(--line-dark);
  background: rgba(20, 17, 12, .94);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  box-shadow: inset 0 0 0 2px var(--line), 0 10px 30px rgba(0, 0, 0, .5);
  pointer-events: none;
}
.map-empty[hidden] { display: none; }

/* Crop the 8x8 face out of the full 64x64 skin sheet. */
.face-crop {
  display: inline-block;
  box-sizing: content-box;
  border-radius: 0;
  flex: 0 0 auto;
  background-repeat: no-repeat;
  background-color: var(--bg-deep);
  image-rendering: pixelated;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line) var(--panel); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--panel); }
*::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--panel); }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .brand { min-width: 0; }
  .search-box { order: 3; flex-basis: 100%; max-width: none; }
  .status { margin-left: auto; }
  .sidebar { width: 100%; flex: 0 0 45%; border-right: 0; border-top: 4px solid var(--line-dark); }
  main { flex-direction: column-reverse; }
  #map { flex: 1 1 55%; }
}

@media (max-width: 480px) {
  .brand h1 { font-size: 11px; }
  .brand p { display: none; }
  .sidebar { flex-basis: 48%; padding: 12px; }
  .player-chip .label { max-width: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
