/* ===================================================================
   stage.css — Stage, world (cámara), hotspots, player, NPCs, puerta
   corrediza, status-bar inferior, debug overlay.
   =================================================================== */

/* ---------- Stage 2:1, world 125% (cámara horizontal) -----------
   El stage ocupa todo el alto disponible (frame es flex-column).
   Mantenemos aspect-ratio 2:1 con un truco: el ancho es el mínimo entre
   100 % del wrapper y 2 × la altura disponible (viewport menos cromo),
   de forma que NUNCA empuja el HUD/status-bar fuera de pantalla. */
.stage-wrap {
  flex: 1;                /* ocupa el alto restante de la frame */
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
.stage {
  position: relative;
  width: min(100%, calc((100vh - var(--chrome-h)) * 2));
  aspect-ratio: 2 / 1;
  background: #0f0f18;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.world {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: var(--world-w, 125%);
  background-color: #1a1a24;
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 100% 100%;
  will-change: transform;
}
.world.has-bg { background-color: transparent; }

/* ---------- Halo del amigo (NPC_FRIEND) ---------------------------
   Anclado dentro de .npc[data-id="NPC_FRIEND"]. Estados:
     .friend-halo            (oculto por defecto)
     .friend-halo.show       (te ha pedido saludo y no le saludaste) → pulso lento
     .friend-halo.show.near  (además estás dentro del radio) → pulso rápido + opacidad plena
   Se centra en el sprite del NPC con translate(-50%, +50%) — los NPCs
   usan bottom para anclar al suelo, así que el ancla queda en sus pies.
*/
.friend-halo {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 720%;          /* el NPC mide ~2.4% del world; 720% del NPC ≈ 17% del world (≈ talkRadius 14 con margen) */
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  transform: translate(-50%, 50%);
  background: radial-gradient(circle,
    rgba(255, 90, 75, 0.18) 0%,
    rgba(255, 90, 75, 0.08) 60%,
    rgba(255, 90, 75, 0.00) 100%);
  border: 2px solid rgba(255, 90, 75, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: -1;          /* decorativo, debajo del sprite NPC */
}
.friend-halo.show      { opacity: 0.55; animation: friendHaloBlink 1.8s ease-in-out infinite; }
.friend-halo.show.near { opacity: 1;    animation: friendHaloPulse 0.9s ease-in-out infinite; }

@keyframes friendHaloBlink {
  0%, 100% { opacity: 0.30; }
  50%      { opacity: 0.75; }
}
@keyframes friendHaloPulse {
  0%, 100% { transform: translate(-50%, 50%) scale(1);    border-color: rgba(255, 90, 75, 0.55); }
  50%      { transform: translate(-50%, 50%) scale(1.10); border-color: rgba(255, 90, 75, 0.95); }
}

/* ---------- Player --------------------------------------------- */
.player {
  position: absolute;
  bottom: 0;
  left: 6%;
  width: var(--sprite-w, 2.4%);
  /* MISMO aspect-ratio que .npc (3/4) para que el jugador y los NPCs
     tengan idéntica altura cuando están en el mismo Y. El antiguo
     34/54 estaba pensado para el PNG nativo de Pablo (más alto que
     ancho) y deformaba los sprites de DR_CHARACTERS al elegir otro
     personaje. Con object-fit:contain en .sprite el PNG de Pablo se
     centra sin deformarse (queda algo de aire arriba/abajo). */
  aspect-ratio: 3 / 4;
  transform: translateX(-50%);
  z-index: 30;
  pointer-events: none;
}
/* SENTADO: recortamos la parte inferior del sprite (el escritorio
   "tapa" las piernas). --seat-cut es el % oculto desde abajo, default
   40 % → se ve cintura para arriba. Cada puesto puede sobrescribirlo
   por inline style desde JS leyendo seatCutPct del I-point. */
.player.seated {
  clip-path: inset(0 0 var(--seat-cut, 40%) 0);
}
/* Ocultamos también la sombra circular bajo los pies al sentarse —
   no debe verse el "ring" si el agente está detrás del escritorio. */
.player.seated .ring { display: none; }
.player svg, .player .sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* contain: respeta el aspect ratio del PNG (Pablo es más alto que
     ancho; los NPCs son más cuadrados). Sin esto, el PNG se estiraría
     para llenar el contenedor 3/4 y la cabeza quedaría aplastada. */
  object-fit: contain;
}
.player .sprite { display: none; }
.player.has-sprite svg     { display: none; }
.player.has-sprite .sprite { display: block; }
.player .ring {
  position: absolute;
  left: 50%; bottom: -6px;
  width: 90%;
  height: 18%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center,
              rgba(123,93,190,.35) 0%,
              rgba(123,93,190,0) 70%);
  pointer-events: none;
  opacity: .9;
}

/* ---------- NPCs ----------------------------------------------- */
.npc-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}
.npc {
  position: absolute;
  bottom: 0;
  width: var(--sprite-w, 2.4%);
  aspect-ratio: 3 / 4;
  transform: translateX(-50%);
  pointer-events: none;
  transition: left .12s linear, bottom .12s linear;
}
.npc img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
}
.npc.interactive { pointer-events: auto; cursor: pointer; }
.npc.idle-sway { animation: npcSway 3.6s ease-in-out infinite; }

/* Etiqueta debug encima de cada NPC (id estable, p.ej. "NPC_OW1").
   Oculta por defecto. La muestra body.npcs-debug — activado por el
   mismo toggle del t-debug-layer (tecla D, ver main.js).
   top:1px (dentro del área kept del clip-path inset(0 0 N% 0)) para
   que NO se recorte cuando el NPC está sentado. Pequeño overlap con la
   cabeza del sprite pero siempre visible. */
.npc-dbg {
  position: absolute;
  top: 1px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .02em;
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  display: none;
  z-index: 5;
}
body.npcs-debug .npc-dbg { display: block; }
/* NOTA: Antes había un override de body.npcs-debug que quitaba el
   clip-path de los NPCs sentados para que las etiquetas no quedaran
   recortadas. Quitado porque interfería con la recepcionista y demás
   NPCs sentados — perdían su clip-path en modo debug.
   Las etiquetas ahora se posicionan dentro del área kept del clip
   (top:1px en lugar de top:-14px) — pequeño overlap con la cabeza
   del sprite pero siempre visibles. */
/* NPCs SENTADOS: misma idea que .player.seated — fallback al 40 % si
   no se setea el inline clip-path (lo aplica npcs.js al renderizar). */
.npc.seated { clip-path: inset(0 0 40% 0); }
@keyframes npcSway {
  0%, 100% { transform: translateX(-50%) rotate(-1deg); }
  50%      { transform: translateX(-50%) rotate(1deg); }
}

/* ---------- NPC callouts (bocadillos sobre NPCs) ---------------
   Lo monta render/npc-callout.js. Se posiciona en (left%, bottom%) igual
   que el NPC al que apunta, con un offset hacia arriba en CSS. Tiene
   colita estilo cómic (triángulo apuntando al NPC).
*/
.npc-callout {
  position: absolute;
  transform: translate(-50%, 0);
  z-index: 30; /* por encima de los NPCs (25) */
  background: #fffbe6;
  color: #1b2333;
  border: 2px solid #1b2333;
  border-radius: 10px;
  padding: 6px 10px;
  font: 600 12px/1.25 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 220px;
  min-width: 90px;
  text-align: center;
  white-space: normal;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.18);
  pointer-events: none;
  animation: npcCalloutIn .25s ease-out;
}
.npc-callout::after {
  /* Colita del bocadillo apuntando hacia abajo (al NPC) */
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 0;
  height: 0;
  margin-left: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid #1b2333;
}
.npc-callout::before {
  /* Relleno interior de la colita (un pelín por encima del borde) */
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 0;
  height: 0;
  margin-left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid #fffbe6;
  z-index: 1;
}
.npc-callout.fade-out {
  opacity: 0;
  transition: opacity .4s ease-out;
}
@keyframes npcCalloutIn {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
/* ---------- Hotspots: círculos concéntricos -------------------- */
/* Cada hotspot se centra EXACTAMENTE en (left%, bottom%) gracias a
   translate(-50%, 50%). Por defecto invisibles; se ven con .show.
   Dos tipos:
     - normal       → círculo suave con pulso sutil (interactivos)
     - .priority    → ripple sonar de dos anillos (puestos S/sentarse) */
.hotspot {
  position: absolute;
  display: block;
  pointer-events: none;
  transform: translate(-50%, 50%);
  z-index: 15;
}
/* Anillo base (todos los hotspots) */
.hotspot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  border-radius: 50%;
  border: 1.5px solid rgba(123,93,190,.55);
  background: rgba(123,93,190,.12);
  opacity: 0;
  pointer-events: none;
}
.hotspot.show::before {
  opacity: 1;
  animation: hotspotPulseSoft 2.4s ease-in-out infinite;
}
@keyframes hotspotPulseSoft {
  0%, 100% { transform: scale(1);    opacity: .85; }
  50%      { transform: scale(1.15); opacity: 1;   }
}

/* Priority hotspots (puestos): ripple sonar con dos anillos */
.hotspot.priority::before,
.hotspot.priority::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border-radius: 50%;
  border: 2.5px solid rgba(123,93,190,.95);
  background: rgba(123,93,190,.18);
  opacity: 0;
  pointer-events: none;
  transform: scale(0);
}
.hotspot.priority.show::before,
.hotspot.priority.show::after {
  animation: hotspotRipple 1.8s ease-out infinite;
}
.hotspot.priority.show::after { animation-delay: .9s; }
@keyframes hotspotRipple {
  0%   { transform: scale(0);    opacity: 0;   }
  8%   { transform: scale(0.3);  opacity: 1;   }
  100% { transform: scale(3.6);  opacity: 0;   }
}

/* Pill que aparece sobre cada hotspot al hacer hover */
.hotspot .pill {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -8px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
  box-shadow: var(--shadow-card);
}
.hotspot.show:hover .pill { opacity: 1; }

/* ---------- Puerta corrediza P02 ------------------------------- */
.facility-door {
  position: absolute;
  width: 9px;             /* 1 px más ancho que antes (8 → 9) */
  /* Altura subida de 8 % → 11 %. Como el transform es
     translate(-50%, 50%), el centro vertical sigue cayendo en el
     mismo Y (definido por el `bottom` inline del #facility-door). */
  height: 11%;
  transform: translate(-50%, 50%) rotate(-3.5deg);
  pointer-events: none;
  z-index: 18;
}
.fd-panel {
  position: absolute;
  left: 0; right: 0;
  height: 50%;
  background: linear-gradient(180deg, #444 0%, #2a2a3a 100%);
  border: 1px solid rgba(0,0,0,.5);
  transition: transform .35s ease;
}
.fd-top    { top: 0;    border-bottom: 1px solid rgba(255,255,255,.10); }
.fd-bottom { bottom: 0; border-top:    1px solid rgba(255,255,255,.10); }
/* Al abrirse, cada panel se desplaza 90 % de su altura (antes 100 %),
   así la apertura final es un 10 % menor — los paneles dejan un poco
   menos de hueco en vez de retirarse del todo. */
.facility-door.open .fd-top    { transform: translateY(-90%); }
.facility-door.open .fd-bottom { transform: translateY( 90%); }

/* ---------- Controls bar (overlay con keyhint) ----------------- */
.controls-bar {
  position: absolute;
  top: 6px; left: 8px; right: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 40;
}
.keyhint {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;                /* separación entre cada par tecla+tema */
  background: rgba(255,255,255,.85);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 14px;
  pointer-events: auto;
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 4px rgba(20,22,40,.10);
}
.kh-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-soft);
}
.kh-keys { display: inline-flex; gap: 2px; }
.kh-label { color: var(--text-mute); }

/* ---------- Debug overlay (tecla D) ---------------------------- */
.t-debug-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  font-family: var(--font-ui);
}
/* Áreas T (transitables): label arriba-izquierda con fondo sólido
   para que se lea sobre cualquier color del mapa, también si el área
   es pequeña. */
.t-debug {
  position: absolute;
  border: 2px dashed rgba(47,164,90,.85);
  background: rgba(47,164,90,.12);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
  text-shadow: 0 1px 0 rgba(0,0,0,.55);
  padding: 0;
  overflow: visible;
}
.t-debug::before {
  content: attr(data-id, '');           /* fallback si JS añade data-id */
  /* La t-debug usa textContent, así que mostramos el texto con un
     chip flotante en la esquina superior izquierda. */
}
/* Convertimos el textContent en chip flotante usando display:flex sobre
   el propio elemento — más simple que un ::before. */
.t-debug {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 2px 5px;
  line-height: 1.1;
}
.t-debug.casa {
  border-color: rgba(86,140,255,.9);
  background:   rgba(86,140,255,.14);
}
.t-debug.puente {
  border-color: rgba(220,150,20,.95);
  background:   rgba(245,184,0,.18);
  color:        #fff;
  text-shadow:  0 1px 0 rgba(0,0,0,.55);
}

/* I-points: punto pequeño en la coordenada exacta + chip con el ID
   flotando junto al punto, fácil de leer. */
.t-debug-ipoint {
  position: absolute;
  transform: translate(-50%, 50%);
  pointer-events: none;
  z-index: 2;
}
.t-debug-ipoint .ipt-dot {
  position: absolute;
  left: 0; top: 0;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--bad);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.55), 0 0 8px rgba(198,64,56,.55);
}
.t-debug-ipoint .ipt-lbl {
  position: absolute;
  left: 10px;
  top: -22px;
  background: #1c1d2a;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.35);
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
  line-height: 1.15;
}

/* =====================================================================
   Status bar inferior: sistemas (3 LEDs) + área de avisos
   ===================================================================== */
.status-bar {
  background: var(--bg-frame);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  /* Solapamos el status-bar un pelín sobre el world, dándole una
     sombrita superior para que se note la superposición. */
  position: relative;
  z-index: 5;
  margin-top: -16px;
  box-shadow: 0 -4px 14px rgba(20,22,40,.12),
              0 1px 2px rgba(20,22,40,.06);
}
.status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.status-row .head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-mute);
  min-width: 78px;
}
.status-row.books .lights {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.session-light {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-soft);
}
.session-light .led {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #d8dae3;
  border: 1px solid rgba(20,22,40,.18);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.6);
}
.session-light.on .led {
  background: var(--ok);
  box-shadow: 0 0 6px rgba(78,192,123,.7);
}
.session-light.exposed .led {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(227,179,65,.85);
  animation: exposedPulse 1s ease-in-out infinite;
}
@keyframes exposedPulse {
  0%, 100% { transform: scale(1);   }
  50%      { transform: scale(1.25); }
}

/* Fila de avisos (nudge ámbar / serious rojo) */
.status-row.notice {
  background: var(--warn-soft);
  border: 1px solid rgba(227,179,65,.45);
  border-radius: var(--r-md);
  padding: 5px 10px;
  color: var(--warn);
}
.status-row.notice .head { color: var(--warn); }
.status-row.notice .notice-text {
  font-size: 13px;
  font-weight: 600;
}
.status-row.notice.serious {
  background: var(--bad-soft);
  border-color: rgba(224,98,90,.55);
  color: var(--bad);
  animation: noticeSeriousPulse 1.6s ease-in-out infinite;
}
.status-row.notice.serious .head        { color: var(--bad); }
.status-row.notice.serious .notice-text { color: var(--bad); }
@keyframes noticeSeriousPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,98,90,.4); }
  50%      { box-shadow: 0 0 0 6px rgba(224,98,90,0); }
}
.status-row[hidden] { display: none; }

/* Fila de incidencia personal pendiente (recordatorio discreto): aparece
   mientras S.incidencia && !S.incidencia.avisada. Estilo ámbar más claro
   que .notice, sin pulsar (el icono superior es el que llama la atención). */
.status-row.incident {
  background: var(--warn-soft);
  border: 1px solid rgba(227,179,65,.35);
  border-radius: var(--r-md);
  padding: 5px 10px;
  color: var(--warn);
}
.status-row.incident .head { color: var(--warn); }
.status-row.incident .incident-text {
  font-size: 13px;
  font-weight: 600;
}

/* Icono intermitente del HUD superior: aparece mientras S.incidencia &&
   !S.incidencia.avisada. Mismo tamaño que los mini-icon-btn de al lado.
   Pulse de fondo ámbar para que destaque sin ser ruidoso. */
.incident-flag {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--warn-soft);
  border: 1px solid rgba(227,179,65,.5);
  color: var(--warn);
  font-size: 16px;
  animation: incidentFlagPulse 1.2s ease-in-out infinite;
  cursor: help;
  user-select: none;
}
.incident-flag[hidden] { display: none; }
@keyframes incidentFlagPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(227,179,65,.55); transform: scale(1);    }
  50%      { box-shadow: 0 0 0 6px rgba(227,179,65,0); transform: scale(1.08); }
}
