:root {
  --bg: #fff;
  --ink: #111;
  --mute: #8a8a8a;
  --line: #d8d8d8;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  height: 100dvh;
  cursor: grab;
}
#stage:active { cursor: grabbing; }
#stage.pointing { cursor: pointer; }

.head {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  pointer-events: none;
}
.head h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}
.head p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--mute);
}
/* Buscador */
.search {
  position: relative;
  margin-top: 10px;
  width: 220px;
  pointer-events: auto;
}
#q {
  width: 100%;
  font: 12px/1 var(--font);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 8px 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
#q:focus { border-color: var(--ink); }
#q::placeholder { color: var(--mute); }
#q::-webkit-search-cancel-button { filter: grayscale(1); opacity: .5; cursor: pointer; }
#results {
  position: absolute;
  left: 0; right: 0; top: 100%;
  margin: -1px 0 0;
  padding: 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--ink);
  z-index: 3;
}
#results li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
}
#results li b { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results li span { color: var(--mute); font-size: 10px; font-variant-numeric: tabular-nums; flex: none; }
#results li[aria-selected="true"] { background: var(--ink); color: var(--bg); }
#results li[aria-selected="true"] span { color: #bbb; }
#results li.more { color: var(--mute); font-size: 10px; cursor: default; }

.head #filter {
  margin-top: 6px;
  color: var(--ink);
  max-width: min(420px, calc(100vw - 180px));
}

.tools {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
}
.tools button {
  font: 11px/1 var(--font);
  letter-spacing: .04em;
  text-transform: uppercase;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}
.tools button:hover { background: var(--ink); color: var(--bg); }
.tools { display: flex; gap: 6px; }
#swap {
  font: 11px/1 var(--font);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--mute);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 8px 12px;
  background: var(--bg);
}
#swap:hover { color: var(--ink); border-color: var(--ink); }

.foot {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.foot > * { pointer-events: auto; }

.hint {
  margin: 8px 0 0;
  font-size: 10px;
  color: var(--mute);
  pointer-events: none;
}

/* Botones de las 7 proposiciones */
#axes {
  display: flex;
  flex-wrap: wrap;
  gap: 32px 6px;
}
#axes button {
  font: 11px/1 var(--font);
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 7px 10px;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
}
#axes button span { font-weight: 700; }
/* Promedio ± desviación estándar, arriba a la izquierda del botón */
#axes .stat {
  position: absolute;
  left: -1px;
  bottom: calc(100% + 3px);
  text-align: left;
  font: 700 11px/1 var(--font);
  font-style: normal;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  pointer-events: none;
}
#axes .stat small { font-size: 9px; font-weight: 400; color: var(--mute); margin-left: 1px; }
#axes .kw {
  display: block;
  margin-top: 3px;
  font-size: 9px;
  font-weight: 400;
  font-style: normal;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
#axes .kw.close { color: var(--mute); }
#axes .kw.close::after { content: " ≈"; }
#axes .kw.tie::after { content: none; }
#axes button:hover { background: #eee; }
#axes button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Etiquetas de los polos */
.pole {
  font-size: 9.5px;
  line-height: 1.25;
  max-width: 150px;
  color: var(--ink);
  cursor: pointer;
  padding: 2px 4px;
  user-select: none;
  opacity: calc(var(--depth, 1) * var(--fade, 0));
}
.pole b {
  display: block;
  font-size: 8.5px;
  letter-spacing: .06em;
  color: var(--mute);
  font-weight: 400;
}
.pole:hover, .pole.on { background: var(--ink); color: var(--bg); opacity: 1; }
.pole:hover b, .pole.on b { color: #bbb; }
.pole.dim { opacity: calc(var(--depth, 1) * var(--fade, 0) * .22); }

/* Nombre flotante */
.who {
  font-size: 12px;
  font-weight: 700;
  background: var(--ink);
  color: var(--bg);
  padding: 3px 6px;
  white-space: nowrap;
  transform: translate(10px, -14px);
  pointer-events: none;
}

/* Panel de la persona */
#panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 300px;
  max-height: calc(100dvh - 90px);
  overflow: auto;
  background: rgba(255,255,255,.94);
  border: 1px solid var(--ink);
  padding: 14px 16px 12px;
  z-index: 2;
}
#panel h2 { margin: 0; font-size: 18px; }
#p-meta { margin: 2px 0 12px; font-size: 10px; color: var(--mute); }
#close {
  position: absolute; top: 6px; right: 8px;
  border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--ink);
}
#p-rows { list-style: none; margin: 0; padding: 0; }
#p-rows li { margin: 0 0 10px; font-size: 9px; }
#p-rows .t { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); display: flex; justify-content: space-between; }
#p-rows .t strong { color: var(--ink); font-weight: 700; }
#p-rows .bar { position: relative; height: 9px; margin: 3px 0; }
#p-rows .bar::before { content: ""; position: absolute; left: 0; right: 0; top: 4px; border-top: 1px solid var(--line); }
#p-rows .bar::after { content: ""; position: absolute; left: 50%; top: 1px; height: 7px; border-left: 1px solid var(--line); }
#p-rows .dot { position: absolute; top: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--ink); transform: translateX(-50%); }
#p-rows .ends { display: flex; justify-content: space-between; gap: 12px; color: var(--mute); line-height: 1.25; }
#p-rows .ends span:last-child { text-align: right; }
#p-rows .ends .lean { color: var(--ink); }

@media (max-width: 640px) {
  .pole { font-size: 8px; max-width: 96px; }
  .pole b { font-size: 7.5px; }
  #panel { left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 48dvh; z-index: 2; }
  .foot { left: 12px; right: 12px; }
  #axes { gap: 5px; }
  #axes button { flex: 1 1 0; padding: 9px 0; font-size: 12px; }
  #axes button { font-size: 0; }
  #axes button span { font-size: 12px; }
  #axes .stat { font-size: 10px; }
  #axes .stat small { font-size: 8px; }
  #axes .kw { font-size: 7.5px; letter-spacing: -.01em; text-transform: none; }
  #axes .kw.close::after { content: none; }
  .hint { display: none; }
  .search { width: calc(100vw - 32px); }
  #q { font-size: 16px; }
  #swap { padding: 8px 9px; }
}
