/* =============================================
   FarmBrawl — Minimap premium panel
   Layout rule: panel width == map width.
   Legend must NEVER stretch the container.
   ============================================= */

:root {
  --mm-map: 148px;          /* compacto: no tapa el mundo jugable */
  --mm-pad: 3px;            /* padding fino alrededor del mapa */
  --mm-panel-w: calc(var(--mm-map) + var(--mm-pad) * 2 + 4px); /* +bordes */
}

#minimap-panel {
  position: absolute;
  bottom: 14px;
  right: 14px;
  z-index: 80;

  /* Ancho FIJO al mapa — la leyenda NO puede estirarlo */
  width: var(--mm-panel-w) !important;
  min-width: var(--mm-panel-w) !important;
  max-width: var(--mm-panel-w) !important;
  box-sizing: border-box !important;

  padding: 0;
  overflow: hidden;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;

  background:
    linear-gradient(165deg, rgba(42, 32, 18, 0.98) 0%, rgba(14, 10, 8, 0.99) 100%);
  border: 2px solid #0a0806;
  border-radius: 4px;
  box-shadow:
    0 0 0 1px #d4a824,
    0 0 0 2px #0a0806,
    0 4px 16px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 220, 140, 0.1) inset;
}

#minimap-panel > * {
  position: relative;
  z-index: 1;
  width: 100%;
  box-sizing: border-box;
}

/* ── Header compacto ── */
#minimap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 3px 5px 2px;
  font-family: var(--font-game, "Courier New", monospace);
  font-size: 6px;
  color: #f0d060;
  text-shadow: 0 1px 0 #000;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: linear-gradient(180deg, rgba(232, 184, 48, 0.16) 0%, transparent 100%);
  border-bottom: 1px solid rgba(232, 184, 48, 0.3);
  flex: 0 0 auto;
}

#minimap-header .mm-title {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 7px;
  letter-spacing: 0.12em;
}

#minimap-header .mm-badge {
  font-size: 6px;
  color: rgba(255, 240, 180, 0.55);
  letter-spacing: 0.04em;
  min-width: 0;
  padding: 1px 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(232, 184, 48, 0.2);
  white-space: nowrap;
}

#minimap-header .mm-badge.mm-compass {
  color: #e8b830;
  border-color: rgba(232, 184, 48, 0.45);
  background: rgba(232, 184, 48, 0.1);
  font-weight: 700;
}

/* ── Body: mapa a todo el ancho del panel ── */
#minimap-body {
  padding: var(--mm-pad) !important;
  flex: 0 0 auto;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(70, 110, 50, 0.12), transparent 70%),
    rgba(0, 0, 0, 0.22);
  display: flex !important;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

#minimap-body .mm-frame {
  position: relative;
  display: block;
  width: var(--mm-map) !important;
  height: var(--mm-map) !important;
  flex: 0 0 var(--mm-map);
  line-height: 0;
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.85),
    0 0 0 2px rgba(232, 184, 48, 0.4);
  overflow: hidden;
  box-sizing: border-box;
}

#minimap-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: var(--mm-map) !important;
  height: var(--mm-map) !important;
  max-width: 100% !important;
  display: block !important;
  border: 0 !important;
  background: #0a120e;
  box-shadow: none !important;
  box-sizing: border-box;
}

/* Esquinas del marco — pegadas al mapa */
#minimap-body .mm-corners {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

#minimap-body .mm-c {
  position: absolute;
  width: 7px;
  height: 7px;
  border-color: #e8b830;
  border-style: solid;
  opacity: 0.9;
}

#minimap-body .mm-c.tl { top: 0; left: 0; border-width: 2px 0 0 2px; }
#minimap-body .mm-c.tr { top: 0; right: 0; border-width: 2px 2px 0 0; }
#minimap-body .mm-c.bl { bottom: 0; left: 0; border-width: 0 0 2px 2px; }
#minimap-body .mm-c.br { bottom: 0; right: 0; border-width: 0 2px 2px 0; }

/* ── Legend: envuelta DENTRO del ancho del mapa ── */
#minimap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 5px;
  justify-content: center;
  align-items: center;
  padding: 2px 4px 4px;
  border-top: 1px solid rgba(232, 184, 48, 0.16);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.18), transparent);
  flex: 0 0 auto;
  /* crítico: no puede expandir el panel */
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

#minimap-legend span {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-game, "Courier New", monospace);
  font-size: 5px;
  color: rgba(255, 245, 220, 0.55);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  flex: 0 0 auto;
}

#minimap-legend i {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 1px;
  border: 1px solid rgba(0, 0, 0, 0.55);
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

#minimap-legend .lg-farm {
  background: linear-gradient(135deg, #82e056, #63c43c);
}
#minimap-legend .lg-forest {
  background: linear-gradient(135deg, #2a6a34, #163a1c);
}
#minimap-legend .lg-path {
  background: linear-gradient(135deg, #e8c888, #c9a45e);
}
#minimap-legend .lg-soil {
  background: linear-gradient(135deg, #b87e3e, #7a4e24);
}
#minimap-legend .lg-you {
  background: radial-gradient(circle at 40% 35%, #fff0c0 0%, #ff2828 55%, #a01010 100%);
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(255, 60, 40, 0.65);
}

/* Sin animación de glow pesada (restaba calidad visual) */
#minimap-panel {
  animation: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

/*
 * Ocultar minimapa en cualquier panel de la sidebar (tienda, intercambio,
 * mercado, etc.). body.panel-open lo setea switchTab() cuando tab !== 'home'.
 * También cubre body.shop-open por compatibilidad.
 */
body.panel-open #minimap-panel,
body.shop-open #minimap-panel {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transform: none !important;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  :root {
    --mm-map: 124px;
    --mm-pad: 3px;
  }
  #minimap-panel {
    bottom: 10px;
    right: 8px;
  }
}

@media (max-width: 600px) and (orientation: portrait) {
  :root {
    --mm-map: 108px;
    --mm-pad: 2px;
  }
  #minimap-panel {
    top: auto;
    bottom: calc(130px + env(safe-area-inset-bottom, 0px));
    right: 6px;
    transform: none;
  }
  #minimap-legend {
    display: none; /* en móvil: solo el mapa, sin chrome de leyenda */
  }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  :root {
    --mm-map: 96px;
    --mm-pad: 2px;
  }
  #minimap-panel {
    top: 4px;
    right: 4px;
    bottom: auto;
  }
  #minimap-legend {
    display: none;
  }
}
