/* =====================================================================
 * Explorador de la Tierra – estilos
 * Interfaz oscura, paneles flotantes translúcidos, estilo "desde el espacio".
 * ===================================================================== */

:root {
  --bg: #05070c;
  --glass: rgba(14, 19, 30, 0.72);
  --glass-strong: rgba(14, 19, 30, 0.9);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e8edf6;
  --muted: #94a0b4;
  --accent: #6ab0ff;
  --accent-2: #3d7eff;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; flex: none; }

#globe { position: fixed; inset: 0; }
.cesium-widget-credits, .cesium-viewer-bottom { display: none !important; }

.card {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ------------------------------ Barra superior ------------------------------ */
.topbar {
  position: fixed; top: calc(12px + var(--safe-t)); left: 16px; right: 16px; z-index: 20;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .2px;
  padding: 9px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(16px); white-space: nowrap; }
.brand svg { color: var(--accent); width: 20px; height: 20px; }

.search { position: relative; flex: 1; min-width: 0; max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 42px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px); box-shadow: var(--shadow); }
.search svg { color: var(--muted); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; height: 100%; font-size: 15px; }
.search input::placeholder { color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search-results { position: absolute; top: 48px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 14px; backdrop-filter: blur(16px);
  box-shadow: var(--shadow); max-height: 60vh; overflow: auto; }
.search-results li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.search-results li:hover { background: rgba(255,255,255,.07); }
.search-results li.empty { color: var(--muted); cursor: default; }
.search-results b { display: block; font-weight: 600; }
.search-results small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.r-ic { width: 18px; text-align: center; color: #ffd23f; }

.top-actions { display: flex; gap: 8px; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(16px); transition: background .2s, border-color .2s; }
.icon-btn:hover { background: rgba(40, 52, 75, .85); border-color: var(--line-strong); }
.icon-btn.active { color: var(--accent); }

/* ------------------------------ Menú de capas ------------------------------ */
.layers { position: fixed; left: 16px; top: calc(70px + var(--safe-t)); z-index: 15; width: 260px; padding: 12px;
  max-height: calc(100vh - 210px - var(--safe-t) - var(--safe-b)); overflow: auto; }
.card-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 0 4px 8px; font-weight: 600; }
.layer-list { display: grid; gap: 4px; }
.layer-btn { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; background: none;
  border: 1px solid transparent; text-align: left; transition: background .2s, border-color .2s; }
.layer-btn:hover { background: rgba(255,255,255,.05); }
.layer-btn.active { background: rgba(106,176,255,.12); border-color: rgba(106,176,255,.45); }
.layer-btn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); }
.layer-opts { display: grid; gap: 8px; margin: 10px 4px 4px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); }
.opt select { background: rgba(255,255,255,.06); border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px 6px; color: var(--text); }
.opt select option { background: #111827; }
.opt input[type=range] { width: 120px; accent-color: var(--accent); }

.places { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.places summary { cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); font-weight: 600; padding: 4px; list-style: none; }
.places summary::after { content: '▾'; float: right; transition: transform .2s; }
.places:not([open]) summary::after { transform: rotate(-90deg); }
.place-group { margin-top: 6px; }
.pg-title { font-size: 11.5px; color: var(--muted); margin: 6px 4px 2px; }
.place { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border-radius: 8px; background: none; border: 0; text-align: left; font-size: 13px; }
.place:hover { background: rgba(255,255,255,.06); }
.place i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.place small { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }

/* ------------------------------ Leyenda ------------------------------ */
.legend { margin: 12px 0 0; padding: 12px 4px 2px; border-top: 1px solid var(--line); font-size: 12.5px; }
.lg-title { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lg-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.lg-row.col { flex-direction: column; align-items: stretch; gap: 4px; }
.sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.bar { height: 10px; border-radius: 6px; display: block; }
.lg-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.lg-note { color: var(--muted); margin: 6px 0 0; font-size: 11.5px; }

.badge { display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.badge.obs { background: rgba(80, 200, 140, .16); color: #7be0a8; border: 1px solid rgba(80,200,140,.35); }
.badge.rea { background: rgba(255, 160, 80, .14); color: #ffb27a; border: 1px solid rgba(255,160,80,.35); }
.badge.cty { background: rgba(106, 176, 255, .14); color: #9cc8ff; border: 1px solid rgba(106,176,255,.35); }

/* ------------------------------ Línea de tiempo ------------------------------ */
.timeline { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-b)); z-index: 20;
  width: min(920px, calc(100vw - 32px)); padding: 12px 18px 8px; display: grid;
  grid-template-columns: auto auto 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 16px; }
.play { width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 18px rgba(61,126,255,.45); transition: transform .15s; }
.play:hover { transform: scale(1.06); }
.play svg { width: 22px; height: 22px; }
.play .i-pause, body.playing .play .i-play { display: none; }
body.playing .play .i-pause { display: block; }
.year-big { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.5px; min-width: 76px; }
.track-wrap { position: relative; height: 46px; }
#yearSlider { -webkit-appearance: none; appearance: none; width: 100%; height: 46px; margin: 0; background: none; position: relative; z-index: 2; cursor: pointer; }
#yearSlider::-webkit-slider-runnable-track { height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent) 0 var(--pct, 100%), rgba(255,255,255,.14) var(--pct, 100%)); }
#yearSlider::-moz-range-track { height: 6px; border-radius: 6px; background: rgba(255,255,255,.14); }
#yearSlider::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
#yearSlider::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 0 0 6px rgba(106,176,255,.18); }
#yearSlider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.ticks { position: absolute; left: 10px; right: 10px; top: 30px; height: 18px; z-index: 3; pointer-events: none; }
.tick { position: absolute; transform: translateX(-50%); background: none; border: 0; padding: 0 4px; font-size: 11px; color: var(--muted); pointer-events: auto; }
.tick::before { content: ''; position: absolute; left: 50%; top: -9px; width: 2px; height: 6px; background: rgba(255,255,255,.35); border-radius: 1px; }
.tick:hover, .tick.active { color: #fff; font-weight: 600; }
.compare-btn { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 999px; background: rgba(255,255,255,.06);
  border: 1px solid var(--line-strong); font-weight: 500; transition: background .2s; }
.compare-btn:hover { background: rgba(255,255,255,.12); }
.compare-btn.active { background: rgba(106,176,255,.18); border-color: var(--accent); color: #cfe4ff; }
.source-line { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin-top: 4px; min-height: 16px; }
.source-line .src { cursor: help; border-bottom: 1px dotted rgba(255,255,255,.25); }
.source-line em { color: #ffcf7a; font-style: normal; }
.source-line .sep { opacity: .4; }
.source-line.loading::after { content: ''; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .8s linear infinite; align-self: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------ Comparación ------------------------------ */
#splitter { position: fixed; top: 0; bottom: 0; left: 50%; z-index: 12; width: 0; }
.split-line { position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: rgba(255,255,255,.85); box-shadow: 0 0 12px rgba(0,0,0,.6); pointer-events: none; }
.split-handle { position: absolute; top: 50%; left: -22px; width: 44px; height: 44px; margin-top: -22px; border-radius: 50%;
  display: grid; place-items: center; background: #fff; color: #0b1220; font-weight: 700; font-size: 18px; cursor: ew-resize;
  box-shadow: 0 4px 18px rgba(0,0,0,.5); touch-action: none; user-select: none; }
.split-tag { position: absolute; top: calc(72px + var(--safe-t)); padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 16px;
  background: var(--glass-strong); border: 1px solid var(--line-strong); white-space: nowrap; }
.split-tag.left { right: 14px; }
.split-tag.right { left: 14px; }
.split-tag select { background: none; border: 0; font-weight: 700; font-size: 16px; color: var(--text); cursor: pointer; }
.split-tag select option { background: #111827; }
body.comparing .layers { top: calc(122px + var(--safe-t)); }

/* ------------------------------ Panel del lugar ------------------------------ */
.panel { position: fixed; right: 16px; top: calc(70px + var(--safe-t)); bottom: calc(118px + var(--safe-b)); z-index: 16;
  width: 380px; padding: 18px 18px 14px; overflow: auto; animation: slideIn .35s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } }
.panel-close { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.08); font-size: 20px; line-height: 1; }
.panel-close:hover { background: rgba(255,255,255,.16); }
.panel-reopen { position: fixed; right: 16px; top: calc(70px + var(--safe-t)); z-index: 16; padding: 9px 14px; border-radius: 999px;
  background: var(--glass-strong); border: 1px solid var(--line-strong); }
.p-head { padding-right: 32px; }
.p-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--c); }
.p-cat::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.p-head h2 { margin: 4px 0 2px; font-size: 22px; line-height: 1.2; letter-spacing: -.2px; }
.p-head h2.pending { color: var(--muted); }
.p-sub { color: var(--muted); font-size: 12.5px; }
.p-summary { margin: 14px 0 0; }
.p-tip { margin: 10px 0 0; padding: 8px 10px; border-radius: 10px; background: rgba(106,176,255,.1); font-size: 12.5px; }
.p-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.p-block:empty { display: none; }
.p-block h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.p-block p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stat { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.3; margin-top: 2px; }
.stat.neg b { color: #ff7a8f; }
.stat.pos b { color: #7be0a8; }
.chart-label { font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.chart-label b { color: var(--text); }
.chart { width: 100%; height: auto; display: block; }
.chart .c-ax { fill: #7d889c; font-size: 9px; }
.chart .c-base { stroke: rgba(255,255,255,.45); stroke-dasharray: 3 3; stroke-width: 1; }
.chart .c-trend { stroke: #fff; stroke-width: 1.2; opacity: .75; }
.chart .c-hl { stroke: rgba(255,255,255,.35); stroke-width: 1; }
.chart-legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.chart-legend .ln { display: inline-block; width: 14px; height: 0; border-top: 1.5px solid #fff; vertical-align: middle; margin-right: 4px; }
.chart-legend .ln.base { border-top: 1.5px dashed rgba(255,255,255,.6); }
.chart-empty { color: var(--muted); font-size: 12px; }
.skeleton { height: 120px; border-radius: 10px; background: linear-gradient(90deg, rgba(255,255,255,.04), rgba(255,255,255,.09), rgba(255,255,255,.04)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.p-sources ul { margin: 0; padding-left: 18px; font-size: 12.5px; }
.p-sources li { margin: 4px 0; }

/* ------------------------------ Dato curioso, ayuda, créditos ------------------------------ */
.fact { position: fixed; right: 16px; bottom: calc(118px + var(--safe-b)); z-index: 13; max-width: 330px; padding: 10px 14px;
  font-size: 12.5px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px);
  opacity: 0; transform: translateY(8px); transition: opacity .4s, transform .4s; pointer-events: none; }
.fact.show { opacity: 1; transform: none; }
.f-k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #ffd23f; margin-bottom: 2px; }
.f-src { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
body.panel-open .fact { display: none; }

.hint { position: fixed; left: 50%; top: 50%; transform: translate(-50%, 120px); z-index: 11; padding: 10px 18px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #dfe6f3; font-size: 13px; pointer-events: none; transition: opacity .8s; text-align: center; max-width: calc(100vw - 32px); }
.hint.gone { opacity: 0; }

.credits { position: fixed; right: 16px; bottom: calc(2px + var(--safe-b)); z-index: 19; font-size: 9.5px; color: rgba(255,255,255,.45);
  max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.credits:hover { white-space: normal; background: var(--glass-strong); padding: 6px 8px; border-radius: 8px; color: var(--muted); }
.credits * { color: inherit !important; font-size: inherit !important; }
.credits img { display: none; }

/* ------------------------------ Modal ------------------------------ */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.5); }
.modal-card { position: relative; width: min(680px, 100%); max-height: 86vh; overflow: auto; padding: 22px 24px; background: var(--glass-strong); }
.modal-card h2 { margin: 0 0 6px; font-size: 21px; }
.modal-card h3 { margin: 18px 0 6px; font-size: 14px; color: var(--accent); }
.modal-card ul { padding-left: 18px; margin: 6px 0; }
.modal-card li { margin: 5px 0; }
.modal-card p { margin: 6px 0; color: #cfd6e4; }

/* ------------------------------ Responsive ------------------------------ */
@media (max-width: 1100px) {
  .panel { width: 340px; }
  .brand span { display: none; }
}
@media (max-width: 820px) {
  .topbar { left: 12px; right: 12px; gap: 8px; }
  .brand { display: none; }
  .search { height: 40px; }
  .icon-btn { width: 38px; height: 38px; }
  .top-actions { gap: 6px; }
  .layers { top: auto; bottom: calc(150px + var(--safe-b)); left: 12px; width: auto; max-width: calc(100vw - 24px); padding: 6px; max-height: none; overflow: visible; }
  .layers .card-title, .layers .places, .layer-opts, .layers .legend { display: none; }
  .layer-list { grid-auto-flow: column; overflow-x: auto; scrollbar-width: none; }
  .layer-btn { padding: 7px 9px; font-size: 12.5px; white-space: nowrap; }
  .layer-btn .dot { width: 8px; height: 8px; }
  body.comparing .layers { top: auto; }
  .legend { display: none; }
  .fact { display: none; }
  .timeline { width: calc(100vw - 24px); padding: 10px 12px 6px; column-gap: 10px; grid-template-columns: auto auto 1fr; }
  .compare-btn { grid-column: 1 / -1; justify-self: center; margin-top: 4px; padding: 6px 12px; }
  .year-big { font-size: 22px; min-width: 54px; }
  .tick span { font-size: 10px; }
  .panel { left: 12px; right: 12px; width: auto; top: auto; bottom: calc(150px + var(--safe-b)); max-height: 55vh; animation-name: slideUp; }
  @keyframes slideUp { from { opacity: 0; transform: translateY(24px); } }
  body.panel-open .layers { display: none; }
  .panel-reopen { top: auto; bottom: calc(200px + var(--safe-b)); right: 12px; }
  .credits { max-width: 60vw; }
  .split-tag { top: calc(66px + var(--safe-t)); font-size: 14px; }
}
