:root {
  --mar: #1d52f1;
  --cristal: rgba(9, 15, 34, 0.74);
  --cristal-fuerte: rgba(9, 15, 34, 0.9);
  --borde: rgba(255, 255, 255, 0.09);
  --borde-fuerte: rgba(255, 255, 255, 0.16);
  --texto: #eef2ff;
  --suave: #9ba8c9;
  --oro: #f5c451;
  --oro-2: #e3a52b;
  --sombra: 0 18px 50px rgba(0, 4, 20, 0.45), 0 2px 8px rgba(0, 4, 20, 0.35);
  --radio: 16px;
  --c-aldea: #f5c451;
  --c-mazmorra: #ff5f6d;
  --c-mina: #f0a46a;
  --c-portal: #b685ff;
  --c-lugar: #5fc8ff;
  --escala: 0.5;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --titulo: "Cinzel", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--mar); color: var(--texto); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

/* ── El mapa ─────────────────────────────────────────────────────────── */
#mapa {
  position: fixed; inset: 0;
  background: var(--mar);
  outline: none;
}
.leaflet-container { font-family: var(--sans); background: transparent; }
.leaflet-tile { image-rendering: auto; }
.leaflet-fade-anim .leaflet-tile { transition: opacity 0.35s ease; }

/* ── Pines ───────────────────────────────────────────────────────────── */
.pin-envoltorio { background: none; border: 0; }
.pin {
  --t: clamp(14px, calc(80px * var(--escala)), 36px);
  --c: var(--c-lugar);
  position: absolute; left: 0; top: 0;
  width: var(--t); height: var(--t);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.18), rgba(255,255,255,0) 60%), rgba(10, 16, 36, 0.82);
  border: 2px solid var(--c);
  box-shadow: 0 0 0 3px rgba(0,0,0,.18), 0 4px 14px rgba(0,0,0,.45), 0 0 18px color-mix(in srgb, var(--c) 45%, transparent);
  transition: transform .18s cubic-bezier(.3,1.6,.5,1), box-shadow .18s;
  cursor: pointer;
}
.pin svg { width: 58%; height: 58%; fill: var(--c); stroke: none; }
.pin svg.trazo { fill: none; stroke: var(--c); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.pin:hover, .pin.activo { transform: translate(-50%, -50%) scale(1.22); box-shadow: 0 0 0 4px rgba(0,0,0,.2), 0 6px 20px rgba(0,0,0,.5), 0 0 26px var(--c); }
.pin--aldea { --c: var(--c-aldea); }
.pin--mazmorra { --c: var(--c-mazmorra); }
.pin--mina { --c: var(--c-mina); }
.pin--portal { --c: var(--c-portal); }
.pin--portal svg { animation: gira 6s linear infinite; }
.pin--lugar { --c: var(--c-lugar); }
@keyframes gira { to { transform: rotate(360deg); } }

/* ── Nombres sobre el mapa ───────────────────────────────────────────── */
.etiqueta-envoltorio { background: none; border: 0; }
.etiqueta {
  position: absolute; left: 0; top: 0;
  transform: translate(calc(-50% + var(--ex, 0px)), calc(-50% + var(--ey, 0px)));
  white-space: nowrap;
  font-weight: 800;
  font-size: clamp(11px, calc(46px * var(--escala)), 21px);
  letter-spacing: 0.01em;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,.7), 0 2px 8px rgba(0,0,0,.55), 0 0 2px rgba(0,0,0,.6);
  cursor: pointer;
  user-select: none;
  transition: opacity .25s, color .15s;
}
.etiqueta:hover { color: var(--oro); }
.etiqueta--region {
  font-family: var(--titulo);
  font-weight: 800;
  font-size: clamp(12px, calc(52px * var(--escala)), 26px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 248, 225, 0.95);
  cursor: default;
}
.etiqueta--region:hover { color: rgba(255, 248, 225, 0.95); }
.lejos .etiqueta--menor { opacity: 0; pointer-events: none; }
.muy-lejos .etiqueta:not(.etiqueta--region) { opacity: 0; pointer-events: none; }
.muy-lejos .pin--portal, .muy-lejos .pin--mina { opacity: .75; }
.sin-nombres .etiqueta { opacity: 0; pointer-events: none; }
.etiqueta.tapada { opacity: 0; pointer-events: none; }

/* ── El jugador ──────────────────────────────────────────────────────── */
.yo-envoltorio { background: none; border: 0; }
.yo {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  pointer-events: none;
}
.yo-onda {
  position: absolute; left: -40px; top: -40px; width: 80px; height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245,196,81,.55), rgba(245,196,81,0) 70%);
  animation: onda 2.2s ease-out infinite;
}
@keyframes onda { 0% { transform: scale(.35); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
.yo-cono {
  position: absolute; left: -62px; top: -62px; width: 124px; height: 124px;
  background: conic-gradient(from -30deg, rgba(255,222,120,.85) 0deg, rgba(255,222,120,.5) 30deg, rgba(255,222,120,0) 60deg, rgba(255,222,120,0) 360deg);
  -webkit-mask: radial-gradient(circle, transparent 17px, #000 19px, rgba(0,0,0,.7) 40px, transparent 62px);
          mask: radial-gradient(circle, transparent 17px, #000 19px, rgba(0,0,0,.7) 40px, transparent 62px);
  border-radius: 50%;
  will-change: transform;
}
.yo-cara {
  position: absolute; left: -20px; top: -20px; width: 40px; height: 40px;
  border-radius: 10px;
  border: 3px solid var(--oro);
  background: #2a3350;
  box-shadow: 0 0 0 3px rgba(0,0,0,.25), 0 6px 18px rgba(0,0,0,.55), 0 0 22px rgba(245,196,81,.6);
  image-rendering: pixelated;
  object-fit: cover;
}
.yo.fuera .yo-cara { border-color: #8a93ad; filter: grayscale(1) brightness(.8); box-shadow: 0 6px 18px rgba(0,0,0,.55); }
.yo.fuera .yo-onda, .yo.fuera .yo-cono { display: none; }
.rastro { filter: drop-shadow(0 0 4px rgba(245,196,81,.6)); }

/* ── Paneles ─────────────────────────────────────────────────────────── */
.panel {
  position: fixed; z-index: 1000;
  background: var(--cristal);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
          backdrop-filter: blur(16px) saturate(1.5);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}
.boton-icono {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: transparent; border: 0;
  transition: background .15s, transform .1s;
}
.boton-icono:hover { background: rgba(255,255,255,.08); }
.boton-icono:active { transform: scale(.94); }
.boton-icono svg, .boton svg, .buscador > svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 11px;
  background: rgba(255,255,255,.07); border: 1px solid var(--borde);
  font-weight: 600; font-size: 13.5px;
  transition: background .15s, border-color .15s, transform .1s, color .15s;
}
.boton:hover { background: rgba(255,255,255,.12); border-color: var(--borde-fuerte); }
.boton:active { transform: scale(.97); }
.boton[aria-pressed="true"] { background: rgba(245,196,81,.16); border-color: rgba(245,196,81,.55); color: var(--oro); }
.boton-oro { background: linear-gradient(180deg, #ffd56e, var(--oro-2)); color: #2a1a00; border-color: transparent; }
.boton-oro:hover { background: linear-gradient(180deg, #ffe08c, #eeb23a); border-color: transparent; }
.boton-claro { background: transparent; }

/* Marca + buscador */
.panel-marca { top: 16px; left: 16px; width: 330px; padding: 14px; }
.marca { display: flex; align-items: center; gap: 12px; }
.marca h1 { margin: 0; font-family: var(--titulo); font-size: 20px; letter-spacing: .06em; line-height: 1.1;
  background: linear-gradient(180deg, #fff3cf, var(--oro)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.marca p { margin: 2px 0 0; font-size: 12px; color: var(--suave); letter-spacing: .04em; }
.marca .solo-movil { margin-left: auto; }
.buscador { position: relative; margin-top: 12px; display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.06); border: 1px solid var(--borde); border-radius: 12px; padding: 0 10px; height: 42px;
  transition: border-color .15s, background .15s; }
.buscador:focus-within { border-color: rgba(245,196,81,.6); background: rgba(255,255,255,.09); }
.buscador > svg { color: var(--suave); flex: none; }
.buscador input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--texto); font: 500 14px var(--sans); }
.buscador input::placeholder { color: #7f8bab; }
.buscador input::-webkit-search-cancel-button { display: none; }
.buscador kbd { font: 600 11px var(--sans); color: var(--suave); border: 1px solid var(--borde-fuerte); border-radius: 6px; padding: 1px 6px; }
#resultados { position: absolute; left: -1px; right: -1px; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none;
  background: var(--cristal-fuerte); border: 1px solid var(--borde); border-radius: 12px; box-shadow: var(--sombra);
  max-height: 320px; overflow: auto; display: none; }
#resultados.abierto { display: block; }
#resultados li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
#resultados li small { margin-left: auto; color: var(--suave); font-size: 11.5px; }
#resultados li.marcado, #resultados li:hover { background: rgba(255,255,255,.08); }
#resultados li .punto { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#resultados .vacio { color: var(--suave); cursor: default; }

/* Filtros */
.filtros { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.filtro {
  --c: var(--suave);
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 10px 0 8px; border-radius: 999px;
  background: rgba(255,255,255,.05); border: 1px solid var(--borde);
  font-size: 12.5px; font-weight: 600; color: var(--texto);
  transition: opacity .15s, background .15s, border-color .15s;
}
.filtro i { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 22%, transparent); }
.filtro i svg { width: 12px; height: 12px; fill: var(--c); }
.filtro i svg.trazo { fill: none; stroke: var(--c); stroke-width: 2.6; stroke-linecap: round; }
.filtro small { color: var(--suave); font-weight: 600; }
.filtro:hover { border-color: var(--borde-fuerte); }
.filtro[aria-pressed="false"] { opacity: .42; }
.filtro--nombres i { background: rgba(255,255,255,.1); }
.filtro--nombres i svg { fill: #fff; }

/* Idioma */
.panel-idioma { top: 16px; right: 16px; padding: 4px; display: flex; gap: 2px; border-radius: 13px; }
.panel-idioma button { height: 32px; min-width: 42px; border: 0; border-radius: 9px; background: none; font-weight: 700; font-size: 12.5px; color: var(--suave); letter-spacing: .04em; transition: background .15s, color .15s; }
.panel-idioma button.activo { background: rgba(245,196,81,.18); color: var(--oro); }

/* Zoom */
.panel-zoom { right: 16px; bottom: 16px; padding: 4px; display: flex; flex-direction: column; gap: 2px; border-radius: 14px; }

/* Cursor */
.panel-cursor { left: 16px; bottom: 16px; padding: 8px 12px; font: 600 12.5px var(--sans); color: var(--suave); border-radius: 11px; font-variant-numeric: tabular-nums; }
.panel-cursor b { color: var(--texto); }

/* Jugador */
.panel-yo {
  left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 12px;
  max-width: calc(100vw - 32px);
}
.yo-quien { display: flex; align-items: center; gap: 10px; padding-right: 12px; margin-right: 4px; border-right: 1px solid var(--borde); min-width: 0; }
.yo-quien > div:last-child { display: flex; flex-direction: column; min-width: 0; }
.yo-quien b { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.yo-quien span { font-size: 12px; color: var(--suave); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.yo-avatar { position: relative; width: 38px; height: 38px; flex: none; }
.yo-avatar img { width: 38px; height: 38px; border-radius: 10px; image-rendering: pixelated; background: #2a3350; border: 2px solid rgba(245,196,81,.7); }
.yo-avatar i { position: absolute; right: -3px; bottom: -3px; width: 12px; height: 12px; border-radius: 50%; background: #8a93ad; border: 2px solid #0b1226; }
.yo-avatar i.vivo { background: #3ddc84; box-shadow: 0 0 0 0 rgba(61,220,132,.7); animation: latido 1.8s infinite; }
.yo-avatar i.lejos { background: #f5c451; }
@keyframes latido { 0% { box-shadow: 0 0 0 0 rgba(61,220,132,.6); } 70% { box-shadow: 0 0 0 8px rgba(61,220,132,0); } 100% { box-shadow: 0 0 0 0 rgba(61,220,132,0); } }
.yo-dato { display: flex; flex-direction: column; padding: 0 12px; min-width: 0; }
.yo-dato small { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--suave); font-weight: 700; }
.yo-dato b { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; font-variant-numeric: tabular-nums; }
.yo-botones { display: flex; gap: 6px; padding-left: 8px; }

/* Aviso */
.panel-aviso { left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 10px 8px 10px 12px; max-width: min(560px, calc(100vw - 32px)); }
.panel-aviso p { margin: 0; font-size: 13.5px; line-height: 1.45; color: #d8def0; }
.panel-aviso p code, .panel-calibrar code { font: 700 13px ui-monospace, Consolas, monospace; color: var(--oro); background: rgba(245,196,81,.12); padding: 1px 6px; border-radius: 6px; }
.aviso-icono { width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center; background: rgba(245,196,81,.14); }
.aviso-icono svg { width: 20px; height: 20px; fill: none; stroke: var(--oro); stroke-width: 2; }

/* Ficha (popup) */
.leaflet-popup.ficha-popup .leaflet-popup-content-wrapper {
  background: var(--cristal-fuerte); color: var(--texto);
  -webkit-backdrop-filter: blur(16px) saturate(1.5); backdrop-filter: blur(16px) saturate(1.5);
  border: 1px solid var(--borde); border-radius: 16px; box-shadow: var(--sombra); padding: 0;
}
.leaflet-popup.ficha-popup .leaflet-popup-content { margin: 0; width: 260px !important; font-size: 13.5px; line-height: 1.45; }
.leaflet-popup.ficha-popup .leaflet-popup-tip { background: var(--cristal-fuerte); box-shadow: none; border: 1px solid var(--borde); }
.leaflet-popup.ficha-popup a.leaflet-popup-close-button { color: var(--suave); top: 8px; right: 8px; width: 26px; height: 26px; font: 400 20px/24px var(--sans); border-radius: 8px; }
.leaflet-popup.ficha-popup a.leaflet-popup-close-button:hover { background: rgba(255,255,255,.08); color: #fff; }
.ficha { padding: 16px 16px 14px; --c: var(--c-lugar); }
.ficha-tipo { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--c); }
.ficha-tipo svg { width: 14px; height: 14px; fill: var(--c); }
.ficha-tipo svg.trazo { fill: none; stroke: var(--c); stroke-width: 2.6; stroke-linecap: round; }
.ficha h3 { margin: 6px 0 0; font-size: 19px; font-weight: 800; letter-spacing: -.01em; padding-right: 20px; }
.ficha .otro { margin: 1px 0 0; color: var(--suave); font-size: 12.5px; }
.ficha .desc { margin: 10px 0 0; color: #d0d7ea; }
.ficha-datos { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--borde); }
.ficha-datos span { font: 700 13px ui-monospace, Consolas, monospace; color: #dfe5f5; }
.ficha-datos .boton { height: 30px; padding: 0 10px; font-size: 12px; }
.ficha .dist { margin-top: 8px; font-size: 12.5px; color: var(--oro); font-weight: 600; }

/* Diálogo de renovar */
.velo { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 7, 20, .55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: aparece .25s ease; }
.dialogo { width: min(400px, 100%); text-align: center; padding: 28px 24px 22px;
  background: var(--cristal-fuerte); border: 1px solid var(--borde-fuerte); border-radius: 22px; box-shadow: var(--sombra);
  animation: sube .35s cubic-bezier(.2,1.3,.4,1); }
.dialogo h2 { margin: 16px 0 6px; font-size: 21px; }
.dialogo p { margin: 0; color: var(--suave); font-size: 14px; line-height: 1.5; }
.dialogo-botones { display: flex; gap: 8px; justify-content: center; margin-top: 20px; }
.dialogo-botones .boton { height: 42px; padding: 0 18px; font-size: 14px; }
.cuenta { position: relative; width: 96px; height: 96px; margin: 0 auto; }
.cuenta svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.cuenta circle { fill: none; stroke-width: 8; }
.cuenta-fondo { stroke: rgba(255,255,255,.08); }
.cuenta-arco { stroke: var(--oro); stroke-linecap: round; stroke-dasharray: 326.73; transition: stroke-dashoffset 1s linear; }
.cuenta b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
@keyframes aparece { from { opacity: 0; } }
@keyframes sube { from { opacity: 0; transform: translateY(16px) scale(.96); } }

/* Calibración */
.panel-calibrar { top: 70px; right: 16px; width: 320px; padding: 16px; font-size: 13px; max-height: calc(100vh - 170px); overflow: auto; }
.panel-calibrar h2 { margin: 0 0 8px; font-size: 16px; color: var(--oro); }
.panel-calibrar ol { margin: 0; padding-left: 18px; color: #cdd5ea; line-height: 1.45; }
.cal-entrada { display: flex; gap: 8px; margin: 12px 0 8px; }
.cal-entrada label { flex: 1; display: flex; align-items: center; gap: 6px; font-weight: 700; }
.cal-entrada input, .panel-calibrar textarea { width: 100%; background: rgba(255,255,255,.06); border: 1px solid var(--borde); border-radius: 9px; color: var(--texto); padding: 8px; font: 600 13px ui-monospace, Consolas, monospace; }
#cal-puntos { list-style: none; margin: 0 0 8px; padding: 0; font: 600 12px ui-monospace, Consolas, monospace; color: #cdd5ea; }
#cal-puntos li { padding: 4px 0; border-bottom: 1px solid var(--borde); display: flex; justify-content: space-between; }
#cal-puntos li em { color: var(--oro); font-style: normal; }
.cal-marca { width: 18px; height: 18px; margin: -9px; border: 2px solid #ff4fd8; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0,0,0,.4); }

/* Tostadas */
.tostadas { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 4000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.tostada { padding: 10px 16px; border-radius: 12px; background: var(--cristal-fuerte); border: 1px solid var(--borde-fuerte); box-shadow: var(--sombra);
  font-size: 13.5px; font-weight: 600; animation: sube .3s cubic-bezier(.2,1.3,.4,1); transition: opacity .3s, transform .3s; }
.tostada.fuera { opacity: 0; transform: translateY(-8px); }

/* ── Móvil ───────────────────────────────────────────────────────────── */
.solo-movil { display: none; }
@media (max-width: 760px) {
  .panel-marca { top: 12px; left: 12px; right: 76px; width: auto; padding: 10px 12px; }
  .marca img { width: 28px; height: 28px; }
  .marca h1 { font-size: 17px; }
  .solo-movil { display: grid; }
  .panel-marca.plegado .buscador, .panel-marca.plegado .filtros { display: none; }
  .panel-marca.plegado #plegar svg { transform: rotate(0); }
  #plegar svg { transform: rotate(180deg); transition: transform .2s; }
  .panel-idioma { top: 12px; right: 12px; flex-direction: column; }
  .panel-idioma button { min-width: 44px; }
  .panel-zoom { right: 12px; bottom: auto; top: 112px; }
  .panel-zoom #zoom-mas, .panel-zoom #zoom-menos { display: none; }
  .panel-zoom #pantalla { display: none; }
  .panel-cursor { display: none; }
  .panel-yo { left: 12px; right: 12px; bottom: 12px; transform: none; flex-wrap: wrap; row-gap: 10px; max-width: none; padding: 10px; }
  .yo-quien { flex: 1 1 100%; border-right: 0; padding-right: 0; margin-right: 0; }
  .yo-dato { flex: 1 1 30%; padding: 0 4px; }
  .yo-dato.ancho { display: none; }
  .yo-dato b { max-width: none; font-size: 13px; }
  .yo-botones { position: absolute; top: 10px; right: 10px; padding: 0; }
  .yo-botones .boton span { display: none; }
  .yo-botones .boton { width: 38px; padding: 0; }
  .panel-aviso { left: 12px; right: 12px; bottom: 12px; transform: none; max-width: none; }
  .panel-calibrar { top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 50vh; }
  .leaflet-popup.ficha-popup .leaflet-popup-content { width: 230px !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
