/* ============================================================
   KreepCore - Lab viewport (Living World redesign, P1+P2)
   "Visiting the laboratory": the primary research lab as a
   photo-state above the tech tree console. Reacts to level
   (tiered art) and to research activity (lit vs dormant), with a
   one-shot reveal when the lab grows a tier. Restart-safe
   animations only (opacity/brightness), since the pane re-renders
   on every poll.
   ============================================================ */

.lab-vp {
  position: relative;
  width: 100%;
  height: clamp(128px, 19vh, 204px);
  margin: 0 0 8px;
  border-radius: 12px;
  overflow: hidden;
  background: #05070d;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 8px 22px rgba(0, 0, 0, 0.45);
  isolation: isolate;
  contain: paint;
}

.lab-vp-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
  transition: filter 700ms ease;
  z-index: 0;
}

/* Dormant lab: darker, desaturated. Lit lab: full, faint warm-up. */
.lab-vp[data-lab-active="0"] .lab-vp-img { filter: brightness(0.58) saturate(0.82) contrast(1.02); }
.lab-vp[data-lab-active="1"] .lab-vp-img { filter: brightness(1) saturate(1.06); }
.lab-vp.is-empty .lab-vp-img { filter: brightness(0.72) saturate(0.9); }

/* Active-work glow: soft cyan inner rim that breathes. Opacity-only so a
   per-poll DOM rebuild never produces a positional jump. */
.lab-vp-scan {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 60px 2px rgba(56, 235, 255, 0.28), inset 0 0 3px rgba(120, 245, 255, 0.5);
  background: radial-gradient(120% 80% at 50% 8%, rgba(56, 220, 255, 0.14), rgba(56, 220, 255, 0) 60%);
}
.lab-vp[data-lab-active="1"] .lab-vp-scan {
  opacity: 1;
  animation: labBreathe 3.4s ease-in-out infinite;
}
@keyframes labBreathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.lab-vp-grad {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(3, 6, 12, 0.42) 0%, rgba(3, 6, 12, 0) 30%,
    rgba(3, 6, 12, 0) 46%, rgba(3, 6, 12, 0.78) 100%);
}

.lab-vp-rec {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: #cfeaff;
  opacity: 0.85;
}
.lab-vp-rec i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff4d5e;
  box-shadow: 0 0 6px rgba(255, 77, 94, 0.9);
  animation: labRecBlink 1.6s steps(1) infinite;
}
.lab-vp[data-lab-active="0"] .lab-vp-rec i { background: #6b7280; box-shadow: none; animation: none; }
@keyframes labRecBlink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: 0.15; } }

.lab-vp-tag {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 3;
  max-width: 72%;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(207, 234, 255, 0.82);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-vp-id {
  position: absolute;
  left: 12px;
  bottom: 10px;
  right: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.lab-vp-name {
  font-size: 15px;
  font-weight: 700;
  color: #f2f7ff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
  line-height: 1.15;
}
.lab-vp-sub {
  font-size: 11px;
  color: rgba(215, 226, 240, 0.78);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.lab-vp[data-lab-active="1"] .lab-vp-sub {
  color: #8fe9ff;
  font-weight: 600;
}
.lab-vp.is-empty .lab-vp-sub { color: #ffcf8f; font-weight: 600; }

/* One-shot arrival: colony surface dive (approach shot zooms in and hands off)
   into the lab settling from a slight push, HUD lighting up last. Emitted only
   on renders that enter the surface, so poll re-renders never replay it. */
.lab-vp-approach {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 55%;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
}
.lab-vp[data-lab-arrive="1"] .lab-vp-approach {
  animation: labApproach 640ms cubic-bezier(0.5, 0.05, 0.6, 0.6) both;
}
@keyframes labApproach {
  0% { opacity: 1; transform: scale(1); }
  55% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.26); }
}
.lab-vp[data-lab-arrive="1"] .lab-vp-img {
  animation: labArriveSettle 980ms cubic-bezier(0.16, 0.7, 0.2, 1) both;
}
@keyframes labArriveSettle {
  0% { transform: scale(1.16); }
  100% { transform: scale(1); }
}
/* HUD connects after touchdown. No 100% frame: each element eases back to
   its own natural opacity. */
.lab-vp[data-lab-arrive="1"] .lab-vp-rec,
.lab-vp[data-lab-arrive="1"] .lab-vp-tag,
.lab-vp[data-lab-arrive="1"] .lab-vp-id {
  animation: labArriveHud 950ms ease-out both;
}
@keyframes labArriveHud {
  0%, 50% { opacity: 0; }
}

/* One-shot tier-up reveal: a brief warm-up flash + settle. Emitted only on the
   render where the tier increased, so it plays once and does not loop. */
.lab-vp[data-lab-reveal="1"] .lab-vp-img { animation: labRevealImg 1500ms ease-out both; }
.lab-vp[data-lab-reveal="1"] .lab-vp-scan { animation: labRevealScan 1500ms ease-out both; }
@keyframes labRevealImg {
  0% { filter: brightness(2) saturate(1.3); transform: scale(1.06); }
  55% { filter: brightness(1.25) saturate(1.15); transform: scale(1.02); }
  100% { filter: brightness(1) saturate(1.06); transform: scale(1); }
}
@keyframes labRevealScan {
  0% { opacity: 1; box-shadow: inset 0 0 90px 6px rgba(120, 245, 255, 0.6); }
  100% { opacity: 0.45; box-shadow: inset 0 0 60px 2px rgba(56, 235, 255, 0.28); }
}

/* One-shot completion handoff: the lab flares as the finished research
   lands, then settles to its steady look. Filter/opacity only, so a
   per-poll rebuild mid-flare stays visually coherent. */
.lab-vp[data-lab-handoff="1"] .lab-vp-img { animation: labHandoffImg 2400ms ease-out both; }
.lab-vp[data-lab-handoff="1"] .lab-vp-scan { animation: labHandoffScan 2400ms ease-out both; }
@keyframes labHandoffImg {
  0% { filter: brightness(2.1) saturate(1.4); }
  35% { filter: brightness(1.2) saturate(1.12); }
  100% { filter: brightness(0.58) saturate(0.82); }
}
@keyframes labHandoffScan {
  0% { opacity: 1; box-shadow: inset 0 0 110px 10px rgba(140, 250, 255, 0.75); }
  100% { opacity: 0; box-shadow: inset 0 0 60px 2px rgba(56, 235, 255, 0.28); }
}

/* Fleet scene: the port breathes amber traffic light instead of research cyan. */
.lab-vp[data-scene="fleet"] .lab-vp-scan {
  box-shadow: inset 0 0 60px 2px rgba(255, 186, 92, 0.26), inset 0 0 3px rgba(255, 214, 140, 0.5);
  background: radial-gradient(120% 80% at 50% 8%, rgba(255, 186, 92, 0.13), rgba(255, 186, 92, 0) 60%);
}

/* Militar scene: alert red rim. */
.lab-vp[data-scene="militar"] .lab-vp-scan {
  box-shadow: inset 0 0 60px 2px rgba(248, 113, 113, 0.22), inset 0 0 3px rgba(252, 165, 165, 0.45);
  background: radial-gradient(120% 80% at 50% 8%, rgba(248, 113, 113, 0.11), rgba(248, 113, 113, 0) 60%);
}

@media (prefers-reduced-motion: reduce) {
  .lab-vp-scan, .lab-vp-rec i,
  .lab-vp[data-lab-reveal="1"] .lab-vp-img,
  .lab-vp[data-lab-reveal="1"] .lab-vp-scan,
  .lab-vp[data-lab-handoff="1"] .lab-vp-img,
  .lab-vp[data-lab-handoff="1"] .lab-vp-scan,
  .lab-vp[data-lab-arrive="1"] .lab-vp-img,
  .lab-vp[data-lab-arrive="1"] .lab-vp-approach,
  .lab-vp[data-lab-arrive="1"] .lab-vp-rec,
  .lab-vp[data-lab-arrive="1"] .lab-vp-tag,
  .lab-vp[data-lab-arrive="1"] .lab-vp-id { animation: none !important; }
}

/* Details button on pinned item scenes (opens the collection detail) */
.lab-vp-info {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cyan, #00f0ff);
  background: rgba(2, 10, 18, 0.62);
  border: 1px solid rgba(0, 240, 255, 0.45);
  border-radius: 6px;
  cursor: pointer;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.lab-vp-info svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.lab-vp-info:hover { background: rgba(0, 240, 255, 0.16); }
.lab-vp-info:active { transform: scale(0.95); }
.lab-vp-info:disabled { opacity: 0.45; cursor: default; }
.lab-vp:has(.lab-vp-info) .lab-vp-id { right: 112px; }

/* Governor scene (Imperio landing): recommendation strip over the hero */
.gov-vp .lab-vp-img { object-position: center 22%; }
.gov-vp .lab-vp-sub { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.gov-vp .lab-vp-sub .kc-res-gain { font-family: var(--font-mono); font-size: 12.5px; }
.gov-vp-cool { display: inline-flex; align-items: center; gap: 4px; color: #93c5fd; }
.gov-vp-cool svg { width: 12px; height: 12px; fill: currentColor; flex: none; }
.gov-vp-wait { color: rgba(215, 226, 240, 0.85); }
