:root {
  --bg: #020306;
  --panel: rgba(9, 11, 17, 0.74);
  --panel-solid: #0b0e15;
  --line: rgba(247, 147, 26, 0.16);
  --line-soft: rgba(255, 255, 255, 0.07);
  --text: #ece6dc;
  --dim: #8f8778;
  --faint: #5e584e;
  --orange: #f7931a;
  --orange-hi: #ffb648;
  --orange-lo: #8a3a0d;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: radial-gradient(ellipse 90% 70% at 72% 28%, #1b1006 0%, #07070b 48%, var(--bg) 100%);
  color: var(--text); font-family: var(--font); font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
#globe { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: grab; }
#globe.dragging { cursor: grabbing; }
button { font-family: inherit; }

/* Carga */
#loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--bg); z-index: 50; transition: opacity .6s;
}
#loading.done { opacity: 0; pointer-events: none; }
#loading p { color: var(--dim); margin: 0; letter-spacing: .02em; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid rgba(247,147,26,.15); border-top-color: var(--orange);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Paneles */
.panel {
  position: fixed; top: 16px; z-index: 10;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
#panel-left {
  left: 16px; width: 340px; max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 18px 18px 12px; display: flex; flex-direction: column; gap: 16px;
}
#panel-right {
  right: 16px; width: 300px; max-height: calc(100vh - 140px); display: flex; flex-direction: column;
  padding: 14px 6px 8px 14px;
}
.panel::-webkit-scrollbar, #ranking::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb, #ranking::-webkit-scrollbar-thumb { background: rgba(247,147,26,.25); border-radius: 3px; }

.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-content: center; font-size: 25px; font-weight: 700; color: #1a0d02;
  background: radial-gradient(circle at 35% 30%, #ffc56b, var(--orange) 55%, #c4660b);
  box-shadow: 0 0 24px rgba(247,147,26,.45);
}
h1 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .01em; }
.sub { margin: 3px 0 0; color: var(--dim); font-size: 12.5px; line-height: 1.35; }

.stats { display: flex; flex-direction: column; gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .k { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; }
.stat.big .v { font-size: 24px; font-weight: 600; color: var(--orange-hi); letter-spacing: -.01em; }
.stat .v.accent { color: var(--orange); }
.stat .v small { display: block; color: var(--dim); font-size: 11px; margin-top: 1px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.note { margin: 0; font-size: 12.5px; color: var(--dim); line-height: 1.45; border-left: 2px solid var(--orange); padding-left: 10px; }
.note b { color: var(--text); font-weight: 600; }

.controls { display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; background: rgba(255,255,255,.04); border: 1px solid var(--line-soft); border-radius: 9px; padding: 3px; }
.seg button {
  flex: 1; border: 0; background: none; color: var(--dim); padding: 7px 6px; border-radius: 6px;
  font-size: 13px; cursor: pointer; transition: background .2s, color .2s;
}
.seg.small button { font-size: 12px; padding: 5px 4px; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--orange); color: #1a0d02; font-weight: 600; }
.slider { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--dim); }
.slider b { color: var(--orange-hi); font-family: var(--mono); font-weight: 500; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--orange-lo), var(--orange)); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff3e0; border: 3px solid var(--orange); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff3e0; border: 3px solid var(--orange); cursor: pointer; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 13px; color: var(--dim); }
.toggles label { display: flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.toggles input { accent-color: var(--orange); width: 14px; height: 14px; margin: 0; }

.card {
  border: 1px solid var(--line); border-radius: 11px; padding: 12px 13px; background: rgba(247,147,26,.045);
  display: flex; flex-direction: column; gap: 8px;
}
.card.hidden { display: none; }
.card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h3 { margin: 0; font-size: 15px; }
.card .x { border: 0; background: none; color: var(--dim); font-size: 18px; cursor: pointer; line-height: 1; padding: 0 2px; }
.card .x:hover { color: var(--text); }
.card .main { font-family: var(--mono); font-size: 20px; color: var(--orange-hi); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.src { font-size: 11.5px; color: var(--faint); line-height: 1.4; }
.src b { color: var(--dim); font-weight: 500; }

.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.link { border: 0; background: none; color: var(--orange); cursor: pointer; padding: 0; font-size: 13px; }
.link:hover { text-decoration: underline; }
.dim { color: var(--faint); }

/* Ranking */
.rank-head { display: flex; flex-direction: column; gap: 10px; padding-right: 8px; margin-bottom: 8px; }
#search {
  width: 100%; background: rgba(255,255,255,.05); border: 1px solid var(--line-soft); border-radius: 8px;
  color: var(--text); padding: 7px 10px; font-size: 13px; outline: none;
}
#search:focus { border-color: var(--orange); }
#ranking { list-style: none; margin: 0; padding: 0 8px 0 0; overflow-y: auto; flex: 1; }
#ranking li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 8px; align-items: center;
  padding: 6px 6px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
#ranking li:hover, #ranking li.sel { background: rgba(247,147,26,.09); }
#ranking .n { color: var(--faint); font-family: var(--mono); font-size: 11px; text-align: right; }
#ranking .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ranking .pct { font-family: var(--mono); font-size: 12px; color: var(--orange-hi); text-align: right; }
#ranking .bar { grid-column: 2 / 4; height: 3px; border-radius: 2px; background: rgba(255,255,255,.05); overflow: hidden; }
#ranking .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--orange-lo), var(--orange)); }
#ranking .sub2 { grid-column: 2 / 4; display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); font-family: var(--mono); }

/* Leyenda */
#legend {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 9;
  width: min(560px, calc(100vw - 32px)); padding: 10px 14px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.legend-title { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; display: flex; justify-content: space-between; }
.legend-bar { position: relative; height: 14px; }
.legend-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--faint); margin-top: 2px; }
.legend-foot .chip { display: inline-block; width: 9px; height: 9px; border-radius: 2px; background: rgb(34,37,45); border: 1px solid #3a3e48; margin-right: 5px; vertical-align: -1px; }
#legend-canvas { width: 100%; height: 14px; border-radius: 4px; display: block; }
#legend-homo, #legend-hover { position: absolute; top: -4px; width: 2px; height: 22px; transform: translateX(-1px); }
#legend-homo { background: #fff; box-shadow: 0 0 6px rgba(255,255,255,.7); }
#legend-homo::after { content: attr(data-label); position: absolute; top: -15px; left: 50%; transform: translateX(-50%); font-size: 10px; color: #fff; white-space: nowrap; opacity: .8; }
#legend-hover { background: var(--orange-hi); display: none; box-shadow: 0 0 8px var(--orange); }
.legend-ticks { position: relative; height: 16px; margin-top: 4px; font-family: var(--mono); font-size: 10.5px; color: var(--dim); }
.legend-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

/* Tooltip */
#tooltip {
  position: fixed; z-index: 20; pointer-events: none; min-width: 210px; max-width: 280px;
  background: rgba(8,10,15,.92); border: 1px solid rgba(247,147,26,.35); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
#tooltip.hidden { display: none; }
#tooltip .t-place { font-weight: 600; margin-bottom: 2px; }
#tooltip .t-sub { color: var(--dim); font-size: 11.5px; margin-bottom: 6px; }
#tooltip .t-main { font-family: var(--mono); font-size: 17px; color: var(--orange-hi); }
#tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
#tooltip .t-row b { color: var(--text); font-weight: 500; }

/* Etiquetas de ciudades */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.city {
  position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 11px; color: #f5e9d6;
  text-shadow: 0 0 4px #000, 0 0 8px #000; will-change: transform; padding-left: 9px;
}
.city::before { content: ""; position: absolute; left: 0; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; background: var(--orange-hi); box-shadow: 0 0 6px var(--orange); }
.city em { font-style: normal; color: var(--orange-hi); font-family: var(--mono); font-size: 10px; margin-left: 5px; }

/* Modal */
#modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; }
#modal.hidden { display: none; }
.modal-box {
  position: relative; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 26px 30px;
  line-height: 1.55; font-size: 14px;
}
.modal-box h2 { font-size: 20px; margin-bottom: 4px; color: var(--orange-hi); }
.modal-box h3 { font-size: 15px; margin: 22px 0 6px; color: var(--orange); }
.modal-box p, .modal-box li { color: #d8d1c5; }
.modal-box code, .modal-box .f { font-family: var(--mono); font-size: 12.5px; background: rgba(247,147,26,.08); padding: 1px 5px; border-radius: 4px; color: var(--orange-hi); }
.modal-box .f { display: block; padding: 8px 12px; margin: 8px 0; white-space: pre-wrap; }
.modal-box table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 8px 0; }
.modal-box td, .modal-box th { border-bottom: 1px solid var(--line-soft); padding: 5px 6px; text-align: left; vertical-align: top; }
.modal-box th { color: var(--dim); font-weight: 500; }
.modal-box td.r { text-align: right; font-family: var(--mono); white-space: nowrap; }
.modal-box a { color: var(--orange); }
.close { position: absolute; top: 12px; right: 14px; border: 0; background: none; color: var(--dim); font-size: 26px; cursor: pointer; line-height: 1; }
.close:hover { color: var(--text); }

.fab { display: none; }

@media (max-width: 900px) {
  #panel-right { display: none; }
  #panel-right.open { display: flex; left: 16px; right: 16px; width: auto; top: auto; bottom: 90px; max-height: 55vh; z-index: 30; background: var(--panel-solid); }
  .fab {
    display: block; position: fixed; right: 16px; top: 16px; z-index: 12;
    background: var(--orange); color: #1a0d02; border: 0; border-radius: 20px; padding: 8px 14px; font-weight: 600; font-size: 13px;
  }
}
@media (max-width: 640px) {
  #panel-left { left: 8px; right: 8px; top: 8px; width: auto; max-height: 42vh; padding: 12px; gap: 10px; font-size: 13px; }
  .sub, .foot .dim, .note, .toggles, .slider { display: none; }
  .brand .logo { width: 34px; height: 34px; font-size: 20px; }
  h1 { font-size: 17px; }
  .stat.big .v { font-size: 19px; }
  .stat .v { font-size: 12.5px; }
  .stat-grid { gap: 6px 10px; }
  .legend-foot { display: none; }
  #legend-homo::after { display: none; }
  .fab { top: auto; bottom: 84px; }
  #legend { bottom: 8px; }
  #tooltip { max-width: 230px; }
}

/* Idioma (es · en · de, compartido con la portada de sats4ads) */
.brand-text { flex: 1; min-width: 0; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.langs { display: flex; gap: 1px; flex: none; }
.langs button {
  border: 0; background: none; color: var(--faint); cursor: pointer;
  font: 600 10.5px var(--font); letter-spacing: .04em; padding: 3px 4px; border-radius: 5px;
}
.langs button:hover { color: var(--text); }
.langs button.on { background: var(--orange); color: #1a0d02; }
