/* ============================================
   NEUVALIA — town.css
   Estilos para el mundo Phaser embebido en #tab-inicio
   y su HUD. Reutiliza los tokens de marca definidos
   inline en town.html (--marino, --azul, --verde) y
   las convenciones visuales de css/style.css
   (radios 14px/8px, sombras suaves, glassmorphism).
   ============================================ */

/* ── EL MAPA ES EL DASHBOARD ────────────────────────────────────
   El lienzo ocupa toda la pantalla; el sidebar/nav/banner del
   dashboard clásico se ocultan (su lógica sigue intacta — los
   paneles se abren como overlays desde los edificios). */
/* "body #..." da mayor especificidad que las reglas del CSS inline del
   dashboard (incluida su media query móvil con !important). */
body #sidebar, body #mobile-nav, body #banner, body #mobile-streak { display: none !important; }
#main { margin: 0 !important; width: 100% !important; }
body { overflow: hidden; }

/* Arrastrar el mapa ya no selecciona texto del HUD/página (ni saca el menú
   de "copiar" en móvil). Se reactiva la selección solo donde hace falta:
   campos de texto y paneles (kárdex, chat, etc.). */
body {
  -webkit-user-select: none; -moz-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, select, [contenteditable="true"], .tab-section {
  -webkit-user-select: text; -moz-user-select: text; user-select: text;
  -webkit-touch-callout: default;
}

#town-canvas-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  background: #0d2244;
}

#town-canvas-mount { width: 100%; height: 100%; }

#town-canvas-mount canvas {
  display: block;
  cursor: grab;
}
#town-canvas-mount canvas:active { cursor: grabbing; }

/* Paneles del dashboard clásico → overlays sobre el mapa */
.tab-section.active {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg, #f7f9fc);
  overflow-y: auto;
  padding: 76px max(24px, calc((100vw - 1100px) / 2)) 48px;
}

/* Botón para volver al mapa cuando hay un panel abierto */
#town-back-btn {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  background: var(--marino, #123158);
  color: #fff;
  border: none;
  border-radius: 100px;
  padding: 10px 20px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(18, 49, 88, 0.3);
  transition: background 0.2s, transform 0.2s;
}
#town-back-btn:hover { background: var(--azul, #2596BE); transform: translateY(-1px); }
body.panel-open #town-back-btn { display: block; }

/* Bossi flotante sobre el mapa (como la mascota del campus de referencia) */
#town-bossi-fab {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 30;
  width: 92px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  animation: bossiFloat 3s ease-in-out infinite;
  filter: drop-shadow(0 10px 24px rgba(18, 49, 88, 0.45));
  transition: transform 0.2s;
}
#town-bossi-fab:hover { transform: scale(1.08); }
#town-bossi-fab img { width: 100%; display: block; }
body.panel-open #town-bossi-fab { display: none; }
@keyframes bossiFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

/* HUD superpuesto al canvas (ladrillos, nombre del distrito, etc.) */
.town-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.town-hud-chip {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 100px;
  padding: 6px 14px;
  color: #fff;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── CHAT DE RECEPCIÓN CON BOSSI ───────────────────────────────
   Bot scripteado (sin IA): burbujas de chat + botones de respuesta
   rápida. Fondo = Bossi difuminado + acento del edificio (--bl-accent,
   lo fija BossiLobby.js desde zones.json). */
.bl-overlay {
  --bl-accent: #2596BE;
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9985;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.bl-overlay.activo { display: flex; }

.bl-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 20%, color-mix(in srgb, var(--bl-accent) 55%, #0a1a3a) 0%, rgba(10, 26, 58, 0.92) 70%);
  animation: blFade 0.4s ease;
}
.bl-bg img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(70vmin, 520px);
  transform: translate(-50%, -50%) scale(1.15);
  filter: blur(22px) saturate(1.15);
  opacity: 0.4;
  transition: filter 0.85s ease, transform 0.85s ease;
}
@keyframes blFade { from { opacity: 0; } }

/* Con foto del interior: nítida, a pantalla completa, con viñeta suave */
.bl-overlay.bl-has-photo .bl-bg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: none;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.02);
}
.bl-overlay.bl-has-photo .bl-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 60%, transparent 45%, rgba(5, 15, 35, 0.35) 100%);
}
/* Bossi te redirige → el interior se difumina */
.bl-overlay.bl-leaving .bl-bg img {
  filter: blur(20px) saturate(1.1) !important;
  transform: translate(-50%, -50%) scale(1.12) !important;
}

.bl-chat {
  position: relative;
  width: min(430px, 94vw);
  height: min(560px, 86vh);
  display: flex;
  flex-direction: column;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(244, 246, 248, 0.6); /* semi-transparente: se ve el interior */
  backdrop-filter: blur(9px) saturate(1.15);
  -webkit-backdrop-filter: blur(9px) saturate(1.15);
  box-shadow: 0 24px 70px rgba(5, 15, 35, 0.5);
  animation: blcPop 0.45s cubic-bezier(0.34, 1.4, 0.5, 1);
}
@keyframes blcPop {
  from { opacity: 0; transform: translateY(46px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bl-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(120deg, var(--marino, #123158), var(--bl-accent));
  color: #fff;
}
.bl-chat-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.bl-chat-headtxt { flex: 1; min-width: 0; }
.bl-chat-title {
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
}
.bl-chat-sub {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.85;
}
.bl-chat-close {
  background: rgba(255, 255, 255, 0.16);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}
.bl-chat-close:hover { background: rgba(255, 255, 255, 0.32); }

.bl-chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bl-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: blMsgIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.bl-row.user { justify-content: flex-end; }
@keyframes blMsgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bl-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(37, 150, 190, 0.35);
  flex-shrink: 0;
}

.bl-msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.85rem;
  line-height: 1.5;
}
.bl-msg.bossi {
  background: rgba(255, 255, 255, 0.92);
  color: var(--marino, #123158);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 10px rgba(18, 49, 88, 0.08);
}
.bl-msg.user {
  background: var(--bl-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  font-weight: 600;
}

.bl-typing {
  display: flex;
  gap: 4px;
  padding: 13px 14px;
}
.bl-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(18, 49, 88, 0.35);
  animation: blDot 1s infinite;
}
.bl-typing span:nth-child(2) { animation-delay: 0.15s; }
.bl-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blDot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.bl-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px 16px;
  justify-content: flex-end;
}
.bl-chip {
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--bl-accent);
  color: var(--bl-accent);
  border-radius: 999px;
  padding: 9px 16px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.18s;
  animation: blMsgIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1) backwards;
}
.bl-chip:hover {
  background: var(--bl-accent);
  color: #fff;
  transform: translateY(-2px);
}

/* Joystick táctil (solo pantallas coarse): abajo-izquierda del mapa */
/* Zona de pilotaje: capta el toque en la mitad inferior-izquierda.
   Invisible; deja pasar el resto de la pantalla a los taps de edificios. */
#town-joystick-zone {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 55%;
  height: 55%;
  z-index: 40;
  touch-action: none;
}
/* Base flotante: JS la coloca en el punto donde el pulgar tocó (left/top),
   por eso se centra con translate(-50%,-50%). Oculta hasta que hay toque. */
#town-joystick {
  position: fixed;
  width: 120px;
  height: 120px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(18, 49, 88, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
}
#town-joystick.activo { opacity: 1; }
#town-joystick-thumb {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(37, 150, 190, 0.9);
  border: 2px solid #fff;
  box-shadow: 0 3px 10px rgba(5, 15, 35, 0.35);
  transition: transform 0.04s linear;
  pointer-events: none;
}
/* Ocultar el joystick cuando hay un panel/overlay abierto */
body.panel-open #town-joystick-zone,
#bossi-lobby-overlay.activo ~ #town-joystick-zone { display: none; }

/* Letrero de instrucciones en DOM: nítido a cualquier zoom del canvas */
#town-hint {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9980;
  max-width: min(92vw, 640px);
  text-align: center;
  background: rgba(18, 49, 88, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.8s ease;
}
#town-hint.oculto { opacity: 0; }

/* Entrada de paneles: sensación de "pasar" del lobby al interior */
body.panel-open .tab-section.active {
  animation: panelEnter 0.38s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes panelEnter {
  from { opacity: 0; transform: translateY(26px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── BOSSI DETECTIVE — overlay de honeypot (cae un atacante en un cebo) ── */
#bossi-detective-overlay {
  position: fixed; inset: 0; z-index: 2147483000;
  display: flex; align-items: center; justify-content: center; padding: 22px;
  background: rgba(8, 18, 34, .82); backdrop-filter: blur(7px);
  animation: bdIn .25s ease;
}
@keyframes bdIn { from { opacity: 0 } to { opacity: 1 } }
#bossi-detective-overlay .bd-card {
  position: relative; width: 100%; max-width: 440px;
  background: #fff; border-radius: 22px; padding: 30px 28px 26px;
  border: 2px solid #2596BE; box-shadow: 0 24px 70px rgba(0,0,0,.5);
  text-align: center; animation: bdPop .32s cubic-bezier(.22,1,.36,1);
}
@keyframes bdPop { from { transform: translateY(16px) scale(.96); opacity: 0 } to { transform: none; opacity: 1 } }
#bossi-detective-overlay .bd-bossi-wrap { position: relative; display: inline-block; margin-bottom: 6px; }
#bossi-detective-overlay .bd-bossi { height: 108px; object-fit: contain; filter: drop-shadow(0 8px 18px rgba(37,150,190,.35)); }
#bossi-detective-overlay .bd-lupa { position: absolute; right: -6px; bottom: 6px; font-size: 1.9rem; transform: rotate(12deg); }
#bossi-detective-overlay .bd-badge {
  display: inline-block; font-size: .68rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: #123158; background: rgba(37,150,190,.12); border: 1px solid rgba(37,150,190,.28);
  padding: 5px 13px; border-radius: 50px; margin-bottom: 12px;
}
#bossi-detective-overlay .bd-title { font-size: 1.7rem; font-weight: 800; color: #123158; margin-bottom: 8px; }
#bossi-detective-overlay .bd-text { font-size: .9rem; color: rgba(18,49,88,.68); line-height: 1.65; margin-bottom: 16px; }
#bossi-detective-overlay .bd-data {
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  background: rgba(18,49,88,.04); border: 1px solid rgba(18,49,88,.08);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 16px;
  font-size: .84rem; color: rgba(18,49,88,.72); font-family: 'Plus Jakarta Sans', monospace;
}
#bossi-detective-overlay .bd-data b { color: #123158; }
#bossi-detective-overlay .bd-warn { font-size: .82rem; color: rgba(18,49,88,.6); line-height: 1.6; margin-bottom: 18px; }
#bossi-detective-overlay .bd-warn b { color: #99BB65; }
#bossi-detective-overlay .bd-btn {
  width: 100%; padding: 13px; border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, #2596BE, #123158); color: #fff;
  font-family: 'Plus Jakarta Sans', sans-serif; font-size: .92rem; font-weight: 700;
  transition: transform .15s;
}
#bossi-detective-overlay .bd-btn:hover { transform: translateY(-1px); }
