/* ============================================================
   TERRA · Atlas interactivo 3D
   Estética: instrumento astronómico / observatorio nocturno
   ============================================================ */

:root {
  --space-0: #04050a;
  --space-1: #070a14;
  --space-2: #0c1120;
  --ink: #eef2f8;
  --ink-soft: #9aa6bd;
  --ink-faint: #5b647c;

  --amber: #f0c674;
  --amber-bright: #ffd98a;
  --amber-deep: #c8923a;
  --cyan: #6fe0e6;
  --cyan-deep: #2e8e98;

  --line: rgba(240, 198, 116, 0.18);
  --line-soft: rgba(154, 166, 189, 0.14);
  --glass: rgba(10, 14, 26, 0.72);

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Spline Sans", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: radial-gradient(140% 100% at 70% 10%, #0b1226 0%, var(--space-1) 42%, var(--space-0) 100%);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; color: inherit; }

/* ---------- Campo de estrellas ---------- */
.starfield {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 22%, #fff, transparent),
    radial-gradient(1px 1px at 28% 64%, rgba(255,255,255,.8), transparent),
    radial-gradient(1px 1px at 45% 14%, #fff, transparent),
    radial-gradient(1.4px 1.4px at 63% 48%, rgba(255,235,200,.9), transparent),
    radial-gradient(1px 1px at 78% 28%, #fff, transparent),
    radial-gradient(1px 1px at 88% 72%, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 8% 84%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 53% 88%, rgba(180,220,255,.9), transparent),
    radial-gradient(1px 1px at 35% 40%, rgba(255,255,255,.6), transparent),
    radial-gradient(1px 1px at 70% 90%, #fff, transparent);
  animation: twinkle 7s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

/* ---------- Globo ---------- */
#globe {
  position: fixed; inset: 0; z-index: 1;
  cursor: grab;
}
#globe:active { cursor: grabbing; }
#globe canvas { display: block; }

/* ---------- Encabezado / marca ---------- */
.brand {
  position: fixed; top: clamp(16px, 3vw, 30px); left: clamp(16px, 3vw, 32px);
  z-index: 10; display: flex; align-items: center; gap: 14px;
  animation: rise .9s .2s both;
}
.brand__mark { position: relative; width: 38px; height: 38px; }
.brand__ring {
  position: absolute; inset: 0; border: 1.5px solid var(--amber);
  border-radius: 50%; opacity: .85;
  box-shadow: 0 0 18px rgba(240,198,116,.35);
}
.brand__ring::after {
  content: ""; position: absolute; inset: -5px;
  border: 1px solid var(--line-soft); border-radius: 50%;
}
.brand__dot {
  position: absolute; top: 50%; left: 50%; width: 7px; height: 7px;
  background: var(--cyan); border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px var(--cyan);
}
.brand__text h1 {
  font-family: var(--font-display); font-weight: 600; font-size: 1.55rem;
  letter-spacing: .22em; line-height: 1;
}
.brand__text p {
  font-family: var(--font-mono); font-size: .62rem; letter-spacing: .28em;
  text-transform: uppercase; color: var(--amber); margin-top: 5px;
}

/* ---------- Buscador ---------- */
.search {
  position: fixed; top: clamp(16px, 3vw, 30px); right: clamp(16px, 3vw, 32px);
  z-index: 12; width: min(300px, 60vw);
  animation: rise .9s .35s both;
}
.search__icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; fill: none; stroke: var(--ink-faint);
  stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
#search-input {
  width: 100%; padding: 12px 16px 12px 40px;
  background: var(--glass); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 40px;
  color: var(--ink); font-size: .9rem; letter-spacing: .01em;
  outline: none; transition: border-color .25s, box-shadow .25s;
}
#search-input::placeholder { color: var(--ink-faint); }
#search-input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px rgba(240,198,116,.25), 0 8px 30px rgba(0,0,0,.5);
}
.search__results {
  list-style: none; margin-top: 8px; max-height: 46vh; overflow-y: auto;
  background: var(--glass); backdrop-filter: blur(14px);
  border: 1px solid var(--line-soft); border-radius: 16px;
  display: none;
}
.search__results.is-open { display: block; }
.search__results li {
  padding: 10px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line-soft); font-size: .88rem;
  transition: background .15s;
}
.search__results li:last-child { border-bottom: none; }
.search__results li:hover, .search__results li.is-active {
  background: rgba(240,198,116,.1); color: var(--amber-bright);
}
.search__results .flag { font-size: 1.1rem; line-height: 1; }
.search__results .empty { color: var(--ink-faint); font-style: italic; }

/* Scrollbars */
.search__results::-webkit-scrollbar, .panel::-webkit-scrollbar { width: 6px; }
.search__results::-webkit-scrollbar-thumb, .panel::-webkit-scrollbar-thumb {
  background: rgba(240,198,116,.25); border-radius: 3px;
}

/* ---------- Controles ---------- */
.controls {
  position: fixed; left: clamp(16px, 3vw, 32px); bottom: clamp(16px, 3vw, 30px);
  z-index: 10; display: flex; gap: 10px;
  animation: rise .9s .5s both;
}
.ctrl {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 15px; border-radius: 40px;
  background: var(--glass); backdrop-filter: blur(12px);
  border: 1px solid var(--line-soft);
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft);
  transition: all .25s;
}
.ctrl svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctrl:hover { border-color: var(--line); color: var(--ink); }
.ctrl--active { color: var(--amber); border-color: var(--line); box-shadow: 0 0 14px rgba(240,198,116,.18); }

/* ---------- Readout coordenadas ---------- */
.readout {
  position: fixed; right: clamp(16px, 3vw, 32px); bottom: clamp(16px, 3vw, 30px);
  z-index: 10; font-family: var(--font-mono); font-size: .66rem;
  letter-spacing: .14em; color: var(--ink-faint);
  display: flex; gap: 8px; animation: rise .9s .55s both;
}
.readout__sep { color: var(--amber-deep); }

/* ---------- Tooltip hover ---------- */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  padding: 6px 12px; border-radius: 30px;
  background: rgba(8,11,20,.9); border: 1px solid var(--line);
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em;
  color: var(--amber-bright); white-space: nowrap;
  transform: translate(-50%, -150%);
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}

/* ---------- Pista inicial ---------- */
.hint {
  position: fixed; left: 50%; bottom: clamp(70px, 12vh, 110px);
  transform: translateX(-50%); z-index: 9;
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .18em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 8px 18px; border: 1px solid var(--line-soft); border-radius: 30px;
  background: rgba(8,11,20,.5); backdrop-filter: blur(6px);
  animation: pulseHint 2.6s ease-in-out infinite;
  transition: opacity .5s;
}
@keyframes pulseHint { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

/* ---------- Panel de país ---------- */
.panel {
  position: fixed; top: 0; right: 0; z-index: 30;
  width: min(420px, 92vw); height: 100%;
  background: linear-gradient(160deg, rgba(13,18,34,.94), rgba(6,9,18,.96));
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--line);
  box-shadow: -30px 0 80px rgba(0,0,0,.6);
  padding: clamp(24px, 4vw, 38px);
  overflow-y: auto;
  transform: translateX(105%);
  transition: transform .55s cubic-bezier(.22,1,.36,1);
}
.panel.is-open { transform: translateX(0); }

.panel__close {
  position: absolute; top: 20px; right: 20px; width: 34px; height: 34px;
  border: 1px solid var(--line-soft); border-radius: 50%;
  background: transparent; display: grid; place-items: center;
  transition: all .25s;
}
.panel__close svg { width: 15px; height: 15px; stroke: var(--ink-soft); stroke-width: 2; stroke-linecap: round; }
.panel__close:hover { border-color: var(--amber); transform: rotate(90deg); }
.panel__close:hover svg { stroke: var(--amber); }

.panel__head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; padding-right: 30px; }
.panel__flag {
  font-size: 2.6rem; line-height: 1; flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.5));
}
.panel__title h2 {
  font-family: var(--font-display); font-weight: 500; font-size: 1.85rem;
  line-height: 1.05; letter-spacing: -.01em;
}
.panel__title p {
  font-size: .82rem; color: var(--ink-soft); margin-top: 6px; line-height: 1.4;
}

/* Botón de audio */
.panel__audio { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.audio-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 11px 20px; border-radius: 40px;
  background: linear-gradient(120deg, var(--amber-deep), var(--amber));
  border: none; color: #1a1206; font-weight: 600; font-size: .85rem;
  letter-spacing: .01em;
  box-shadow: 0 8px 24px rgba(240,198,116,.28);
  transition: transform .2s, box-shadow .2s, filter .2s;
}
.audio-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(240,198,116,.4); }
.audio-btn:active { transform: translateY(0); }
.audio-btn.is-playing { filter: saturate(1.1); }
.audio-btn svg { width: 16px; height: 16px; fill: #1a1206; }

.audio-wave { display: flex; align-items: center; gap: 3px; height: 22px; }
.audio-wave span {
  width: 3px; height: 100%; background: var(--cyan); border-radius: 3px;
  transform-origin: center; animation: wave 1s ease-in-out infinite;
}
.audio-wave span:nth-child(2) { animation-delay: .15s; }
.audio-wave span:nth-child(3) { animation-delay: .3s; }
.audio-wave span:nth-child(4) { animation-delay: .45s; }
.audio-wave span:nth-child(5) { animation-delay: .6s; }
@keyframes wave { 0%,100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }

/* Cuadrícula de datos */
.panel__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: 14px; overflow: hidden; }
.cell {
  background: rgba(6,9,18,.6); padding: 16px 18px;
  animation: cellIn .5s both;
}
.cell--wide { grid-column: 1 / -1; }
.cell__label {
  font-family: var(--font-mono); font-size: .6rem; letter-spacing: .18em;
  text-transform: uppercase; color: var(--amber); margin-bottom: 7px;
  display: flex; align-items: center; gap: 6px;
}
.cell__value { font-size: 1rem; line-height: 1.35; color: var(--ink); }
.cell__value .sub { font-size: .78rem; color: var(--ink-soft); }
.tag {
  display: inline-block; margin: 3px 5px 0 0; padding: 3px 10px;
  background: rgba(111,224,230,.1); border: 1px solid rgba(111,224,230,.22);
  border-radius: 30px; font-size: .76rem; color: var(--cyan);
}

.panel__source {
  margin-top: 22px; font-size: .65rem; color: var(--ink-faint);
  line-height: 1.5; border-top: 1px solid var(--line-soft); padding-top: 16px;
}

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 100;
  background: var(--space-0); display: grid; place-items: center;
  gap: 0; transition: opacity .8s, visibility .8s;
}
.loader.is-hidden { opacity: 0; visibility: hidden; }
.loader__orbit { position: relative; width: 90px; height: 90px; animation: spin 3.5s linear infinite; }
.loader__planet {
  position: absolute; top: 50%; left: 50%; width: 26px; height: 26px;
  transform: translate(-50%,-50%); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--cyan), var(--cyan-deep) 70%);
  box-shadow: 0 0 20px var(--cyan-deep);
}
.loader__moon {
  position: absolute; top: -4px; left: 50%; width: 9px; height: 9px;
  margin-left: -4.5px; border-radius: 50%; background: var(--amber);
  box-shadow: 0 0 12px var(--amber);
}
.loader__text {
  position: absolute; top: calc(50% + 70px); left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: .22em;
  text-transform: uppercase; color: var(--ink-faint); white-space: nowrap;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Animaciones ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes cellIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive (móvil): panel como hoja inferior ---------- */
@media (max-width: 640px) {
  .panel {
    width: 100%; height: auto; max-height: 82vh; top: auto; bottom: 0;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 24px 24px 0 0;
    transform: translateY(105%);
    box-shadow: 0 -30px 70px rgba(0,0,0,.65);
  }
  .panel.is-open { transform: translateY(0); }
  .brand__text p { display: none; }
  .search { width: min(220px, 52vw); }
  .hint { bottom: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
