:root {
  --bg: #05080f;
  --bg-2: #0b1220;
  --surface: rgba(15, 23, 38, 0.72);
  --surface-solid: #0f1726;
  --border: rgba(148, 163, 184, 0.14);
  --text: #e5edf7;
  --muted: #8a98ad;
  --accent: #5eead4;
  --accent-2: #38bdf8;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background:
    radial-gradient(1200px 700px at 35% 45%, rgba(56, 189, 248, 0.10), transparent 60%),
    radial-gradient(900px 600px at 70% 80%, rgba(94, 234, 212, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Cabecera ---------- */
.top {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; gap: 2px; }
.name { color: var(--text); text-decoration: none; font-weight: 600; letter-spacing: -0.01em; }
.name:hover { color: var(--accent); }
.sub { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.dot.stale { background: var(--warn); }
.dot.error { background: var(--danger); }

.lock-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer;
  backdrop-filter: blur(10px);
}
.lock-btn svg { width: 16px; height: 16px; }
.lock-btn:hover { border-color: var(--accent); }
.lock-btn.unlocked { color: var(--accent); border-color: rgba(94, 234, 212, 0.4); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  height: 100dvh;
}

.stage { position: relative; min-height: 0; overflow: hidden; }
#body-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.panel {
  overflow-y: auto;
  padding: 84px 20px 24px;
  border-left: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(11, 18, 32, 0.6), rgba(5, 8, 15, 0.8));
}

/* ---------- Hotspots ---------- */
.hotspots { position: absolute; inset: 0; pointer-events: none; }
.hotspot {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--text); font: inherit;
  transition: opacity 0.25s;
  will-change: transform;
}
.hotspot .pin {
  position: absolute; left: -7px; top: -7px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(94, 234, 212, 0.18), 0 0 16px rgba(94, 234, 212, 0.8);
  pointer-events: auto;
}
.hotspot .pin::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 1px solid rgba(94, 234, 212, 0.6);
  animation: ping 2.4s ease-out infinite;
}
.hotspot .tag {
  position: absolute; top: -13px; left: 16px;
  pointer-events: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px; white-space: nowrap;
  backdrop-filter: blur(8px);
}
.hotspot .tag b { font-family: var(--mono); font-weight: 500; color: var(--accent); margin-left: 6px; }
.hotspot.left .tag { left: auto; right: 16px; }
.hotspot.locked .pin { background: var(--muted); box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.15); }
.hotspot.locked .pin::after { display: none; }
.hotspot.locked .tag b { color: var(--muted); }
.hotspot.active .tag { border-color: var(--accent); }
.hotspot.hidden { opacity: 0; pointer-events: none; }
.hotspot:focus-visible { outline: none; }
.hotspot:focus-visible .tag { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes ping { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }

/* ---------- Popover ---------- */
.popover {
  position: absolute; z-index: 5;
  width: min(300px, calc(100% - 32px));
  background: rgba(10, 16, 28, 0.92);
  border: 1px solid rgba(94, 234, 212, 0.35);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 30px rgba(94, 234, 212, 0.08);
  backdrop-filter: blur(12px);
}
.popover h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.popover dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.popover dt { color: var(--muted); font-size: 13.5px; }
.popover dd { margin: 0; font-family: var(--mono); font-size: 13.5px; text-align: right; }
.popover .close { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }

/* ---------- Hint y timeline ---------- */
.hint {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  margin: 0; max-width: min(440px, calc(100% - 32px));
  text-align: center; color: var(--muted); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px;
}
.timeline {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 16px 12px; backdrop-filter: blur(10px);
}
.timeline-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; margin-bottom: 6px; }
.timeline-title { color: var(--muted); }
.timeline-readout { font-family: var(--mono); font-size: 12.5px; text-align: right; }
.timeline input { width: 100%; accent-color: var(--accent); }

.webgl-error { position: absolute; inset: 40% 16px auto; text-align: center; color: var(--muted); }

/* ---------- Panel de métricas ---------- */
.group {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.group.highlight { border-color: rgba(94, 234, 212, 0.55); box-shadow: 0 0 24px rgba(94, 234, 212, 0.10); }
.group h2 {
  margin: 0 0 10px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}
.group h2 .when { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.metric { min-width: 0; }
.metric .label { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .value { font-family: var(--mono); font-size: 19px; letter-spacing: -0.02em; }
.metric .unit { color: var(--muted); font-size: 12px; margin-left: 3px; font-family: var(--font); }
.metric.locked .value { color: var(--muted); font-size: 14px; font-family: var(--font); }
.metric.empty .value { color: var(--muted); }

.spark { margin-top: 12px; }
.spark svg { width: 100%; height: 56px; display: block; }
.spark .caption { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin-top: 4px; }

.locked-group p { margin: 0; color: var(--muted); font-size: 13.5px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }


/* ---------- Diálogo de clave ---------- */
.unlock {
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface-solid); color: var(--text);
  padding: 22px; width: min(380px, calc(100% - 32px));
}
.unlock::backdrop { background: rgba(2, 4, 8, 0.7); backdrop-filter: blur(4px); }
.unlock h2 { margin: 0 0 6px; font-size: 18px; }
.unlock p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.unlock input {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font: inherit;
}
.unlock input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.unlock .error { color: var(--danger); margin: 10px 0 0; }
.unlock .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.unlock button {
  border-radius: 10px; padding: 9px 16px; font: inherit; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #04211d; font-weight: 600;
}
.unlock button.ghost { background: none; color: var(--text); border-color: var(--border); font-weight: 400; }
.unlock button:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Móvil ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 68dvh auto; height: auto; }
  .stage { height: 68dvh; }
  .panel { border-left: 0; border-top: 1px solid var(--border); padding: 18px 16px 32px; overflow: visible; }
  .hotspot .tag { font-size: 11.5px; padding: 3px 8px; }
  .hotspot .tag .label-text { display: none; }
  .hotspot .tag b { margin-left: 0; }
  .timeline { bottom: 12px; }
  .timeline-title { display: none; }
  .timeline-readout { text-align: left; }
  .hint { bottom: 12px; border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .hotspot .pin::after { animation: none; }
}
.hotspot.hidden .pin, .hotspot.hidden .tag { pointer-events: none; }
