:root {
  --bg:        #0c0e16;
  --bg-soft:   #141826;
  --bg-panel:  #11141f;
  --bg-elev:   #1b2030;
  --line:      #262c3f;
  --text:      #e8e9f0;
  --text-dim:  #9aa0b6;
  --text-mut:  #6b7186;
  --accent:    #d05148;
  --accent-2:  #b3324a;
  --gold:      #d8b45a;
  --shadow:    0 6px 24px rgba(0,0,0,.45);
  --sidebar-w: 348px;
}

* { box-sizing: border-box; }
html, body { margin:0; height:100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { position: fixed; inset: 0; display: flex; }

/* ---------- Map ---------- */
#map { flex: 1; height: 100%; background: #05060a; outline: none; }
.leaflet-container { background: #05060a; font: inherit; }
.leaflet-control-zoom a {
  background: var(--bg-elev); color: var(--text);
  border-color: var(--line) !important;
}
.leaflet-control-zoom a:hover { background: var(--accent); color:#fff; }
.leaflet-control-attribution {
  background: rgba(10,12,20,.7) !important; color: var(--text-mut) !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-bar { box-shadow: var(--shadow); }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 1000; box-shadow: var(--shadow);
  transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}
#sidebar:not(.open) { margin-left: calc(-1 * var(--sidebar-w) - 4px); }

.sidebar-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 18px 12px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #171b2b, var(--bg-panel));
}
.brand h1 {
  margin: 0; font-size: 26px; letter-spacing: .5px; font-weight: 800;
  background: linear-gradient(90deg, #fff, var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand p { margin: 3px 0 0; font-size: 12px; color: var(--text-dim); }
.brand .game { color: var(--accent); font-weight: 600; }

.icon-btn {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--line);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  font-size: 17px; line-height: 1; display: grid; place-items: center;
  transition: background .15s, transform .15s;
}
.icon-btn:hover { background: var(--accent); border-color: var(--accent); }
.icon-btn.floating {
  position: absolute; top: 14px; left: 14px; z-index: 1001;
  width: 38px; height: 38px; font-size: 18px; box-shadow: var(--shadow);
  display: none;
}
#sidebar:not(.open) ~ #sidebar-open { display: grid; }

/* ---------- Search ---------- */
.search-wrap { position: relative; padding: 12px 14px 6px; }
#search {
  width: 100%; padding: 10px 12px; border-radius: 9px;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--text); font-size: 14px; outline: none;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text-mut); }
#search-results {
  position: absolute; left: 14px; right: 14px; top: 100%; margin-top: -2px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 9px;
  max-height: 320px; overflow-y: auto; z-index: 20; display: none;
  box-shadow: var(--shadow);
}
#search-results.show { display: block; }
.sr-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 11px;
  cursor: pointer; border-bottom: 1px solid var(--line);
}
.sr-item:last-child { border-bottom: 0; }
.sr-item:hover, .sr-item.active { background: var(--accent-2); }
.sr-item .sr-icon { flex: 0 0 22px; }
.sr-item .sr-txt { overflow: hidden; }
.sr-item .sr-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-item .sr-cat { font-size: 11px; color: var(--text-dim); }
.sr-empty { padding: 12px; color: var(--text-mut); font-size: 13px; text-align: center; }

/* ---------- Toolbar / progress ---------- */
.toolbar { display: flex; gap: 8px; padding: 4px 14px 8px; flex-wrap: wrap; }
.pill {
  font-size: 12px; padding: 6px 10px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text-dim);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; user-select: none;
}
.pill:hover { color: var(--text); border-color: var(--accent); }
.pill.checkbox input { accent-color: var(--accent); margin: 0; }

.progress-global {
  display: flex; align-items: center; gap: 9px; padding: 4px 16px 12px;
  border-bottom: 1px solid var(--line); font-size: 12px; color: var(--text-dim);
}
.progress-global .bar {
  flex: 1; height: 7px; background: var(--bg-elev); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--line);
}
.progress-global .bar span {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--gold)); transition: width .3s;
}
.link-btn { background: none; border: 0; color: var(--text-mut); cursor: pointer; font-size: 11px; text-decoration: underline; padding: 0; }
.link-btn:hover { color: var(--accent); }

/* ---------- Groups / categories ---------- */
.groups { flex: 1; overflow-y: auto; padding: 6px 8px 16px; }
.group { margin-bottom: 4px; }
.group-head {
  display: flex; align-items: center; gap: 9px; padding: 9px 8px;
  cursor: pointer; border-radius: 8px; user-select: none;
}
.group-head:hover { background: var(--bg-soft); }
.group-swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; box-shadow: 0 0 0 2px rgba(255,255,255,.06); }
.group-title { flex: 1; font-size: 13px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; color: var(--text); }
.group-count { font-size: 11px; color: var(--text-mut); }
.group-caret { color: var(--text-mut); font-size: 11px; transition: transform .2s; }
.group.collapsed .group-caret { transform: rotate(-90deg); }
.group.collapsed .cat-list { display: none; }

.cat-list { padding: 2px 0 6px 6px; }
.cat {
  display: flex; align-items: center; gap: 9px; padding: 5px 8px;
  border-radius: 7px; cursor: pointer; user-select: none;
}
.cat:hover { background: var(--bg-soft); }
.cat input { accent-color: var(--accent); margin: 0; flex: 0 0 auto; }
.cat-icon { flex: 0 0 24px; height: 30px; display: grid; place-items: center; }
.cat-name { flex: 1; font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat.on .cat-name { color: var(--text); }
.cat-count { font-size: 11px; color: var(--text-mut); background: var(--bg-elev); padding: 1px 7px; border-radius: 999px; }

.sidebar-foot {
  padding: 10px 16px 14px; font-size: 10.5px; color: var(--text-mut);
  border-top: 1px solid var(--line); line-height: 1.5;
}
.sidebar-foot a { color: var(--text-dim); }

/* ---------- Sprite marker icons ---------- */
.spr {
  background-image: url("markers.png");
  background-repeat: no-repeat;
  width: 33px; height: 44px;
  image-rendering: auto;
  transition: transform .12s ease, filter .15s ease;
  transform-origin: bottom center;
}
.spr.mini { width: 24.75px; height: 33px; background-size: 247.5px 264px; }

/* NB: Leaflet usa transform:translate3d en .mg-marker para posicionar.
   El hover escala el .spr interno para no romper esa posición. */
.mg-marker { cursor: pointer; }
.mg-marker:hover { z-index: 10000 !important; }
.mg-marker:hover .spr { transform: scale(1.15); filter: drop-shadow(0 0 5px var(--gold)); }
.mg-marker.found .spr { filter: grayscale(1) brightness(.55); opacity: .6; }
.mg-marker.found:hover .spr { filter: drop-shadow(0 0 5px var(--gold)) grayscale(.4); opacity: .85; }
.mg-marker.found::after {
  content: "✓"; position: absolute; top: -3px; right: -3px;
  width: 15px; height: 15px; border-radius: 50%;
  background: #2e8b57; color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- Popups ---------- */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 0; width: 280px !important; }
.leaflet-popup-tip { background: var(--bg-panel); border: 1px solid var(--line); }
.leaflet-popup-close-button { color: var(--text-dim) !important; padding: 8px 8px 0 0 !important; }
.leaflet-popup-close-button:hover { color: var(--accent) !important; }

.pop { font-size: 13px; line-height: 1.5; }
.pop-media { width: 100%; height: 150px; object-fit: cover; display: block; background: var(--bg-elev); border-radius: 11px 11px 0 0; }
.pop-body { padding: 11px 14px 13px; }
.pop-head { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.pop-title { font-size: 16px; font-weight: 700; margin: 0; line-height: 1.2; }
.pop-cat { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; white-space: nowrap; }
.pop-desc { color: var(--text); margin: 8px 0 0; }
.pop-desc a { color: var(--gold); }
.pop-info { color: var(--text-dim); font-size: 12px; margin: 8px 0 0; border-left: 2px solid var(--line); padding-left: 9px; }
.pop-tmpl { color: var(--text-dim); font-size: 12px; margin: 8px 0 0; white-space: pre-line; }
.pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.pop-found-btn {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text); cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.pop-found-btn:hover { border-color: #2e8b57; color: #6ee7a0; }
.pop-found-btn.is-found { background: #1d3a2a; border-color: #2e8b57; color: #6ee7a0; }
.pop-coords { font-size: 10px; color: var(--text-mut); white-space: nowrap; }

/* ---------- Loading ---------- */
.loading {
  position: absolute; inset: 0; z-index: 2000;
  background: radial-gradient(circle at 50% 40%, #161a28, #06080e);
  display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 14px; transition: opacity .4s;
}
.loading.hide { opacity: 0; pointer-events: none; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* tooltips */
.leaflet-tooltip.mg-tip {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 12px; font-weight: 600;
}
.leaflet-tooltip.mg-tip::before { display:none; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  :root { --sidebar-w: 86vw; }
  #sidebar { position: absolute; inset: 0 auto 0 0; }
}

/* scrollbars */
.groups::-webkit-scrollbar, #search-results::-webkit-scrollbar { width: 9px; }
.groups::-webkit-scrollbar-thumb, #search-results::-webkit-scrollbar-thumb { background: var(--bg-elev); border-radius: 9px; }
.groups::-webkit-scrollbar-track { background: transparent; }
