/* ============================================================
   PBG Micrositio — estilos
   Hereda paleta y tipografías del manifest Spatialnomics.
   ============================================================ */

:root {
    --bg-abyss: #010208;
    --sapphire-depth: #0f172a;
    --titanium-pro: #3A6EA5;
    --emerald-frontier: #10B981;
    --violet-ai: #7C3AED;
    --amber-anomaly: #FF9F00;
    --ruby-collapse: #E11D48;
    --glass-surface: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.06);
    --text-primary: #FFFFFF;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --nav-h: 57px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

html {
    scroll-behavior: smooth;
    /* overflow-x NO se declara en html — cualquier valor crea un scroll container
       alternativo y rompe position:sticky en todos los descendientes */
}

body {
    background-color: var(--bg-abyss);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-variant-numeric: tabular-nums;
    /* clip no crea scroll container → sticky funciona. hidden lo crea y lo rompe.
       Fallback hidden para Safari <16 (clip no soportado), pero en esos browsers
       sticky puede no funcionar de todas formas. */
    overflow-x: hidden;
    overflow-x: clip;
    line-height: 1.6;
    /* Safe area para iPhones con notch/Dynamic Island */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a { color: inherit; text-decoration: none; }

/* ============================================================
   #BG-CANVAS — Volumetric Abyss (radial gradient Titanium Pro)
   ============================================================ */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background:
        radial-gradient(ellipse at 70% 10%, rgba(58, 110, 165, 0.07) 0%, transparent 55%),
        radial-gradient(ellipse at 20% 80%, rgba(16, 185, 129, 0.04) 0%, transparent 50%),
        var(--bg-abyss);
    pointer-events: none;
}

/* ============================================================
   NAV — alineado con landing (transparent → .scrolled)
   ============================================================ */
nav {
    position: fixed;
    top: 0;
    width: 100%;
    /* Safe area horizontal en iPhone con notch */
    padding: 6px calc(5% + env(safe-area-inset-right)) 6px calc(5% + env(safe-area-inset-left));
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    background: linear-gradient(to bottom, rgba(1, 2, 8, 0.9), transparent);
    /* Glassmorphism — manifest: blur 6px permanente */
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-bottom: 1px solid transparent;
    transition: background 0.9s ease, border-bottom-color 0.9s ease;
}
nav.scrolled {
    background: rgba(1, 2, 8, 0.72);
    border-bottom-color: rgba(255, 255, 255, 0.03);
}

.logo {
    font-family: 'Syne', sans-serif;
    font-size: 1.35rem;
    font-weight: 400;
    letter-spacing: 6px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    text-decoration: none;
    color: #ffffff;
}
.logo span { color: var(--emerald-frontier); }
.logo img {
    height: 46px;
    width: auto;
    margin-right: 10px;
    filter: drop-shadow(0 0 8px rgba(16,185,129,0.4));
}

.breadcrumb {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-left: 18px;
    padding-left: 18px;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.breadcrumb b { color: var(--amber-anomaly); font-weight: 700; }

/* Nav links — centrados como en la landing */
.nav-links {
    display: flex;
    gap: 36px;
    list-style: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.nav-links a {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-decoration: none;
    letter-spacing: 0.5px;
    position: relative;
    padding-bottom: 4px;
    transition: color 0.3s ease;
}
.nav-links a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 100%;
    height: 1px;
    background: var(--emerald-frontier);
    transform: translateX(-50%) scaleX(0);
    transform-origin: center;
    transition: transform 0.3s ease;
}
.nav-links a:hover,
.nav-links a.active { color: var(--text-primary); }
.nav-links a:hover::after,
.nav-links a.active::after { transform: translateX(-50%) scaleX(1); }
.nav-links a.active { color: var(--emerald-frontier); }

/* Nav button CTA */
.nav-btn {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--emerald-frontier);
    color: var(--emerald-frontier);
    padding: 10px 24px;
    border-radius: 8px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background 0.3s, color 0.3s, transform 0.15s ease-out, box-shadow 0.3s;
}
.nav-btn:hover {
    background: var(--emerald-frontier);
    color: var(--bg-abyss);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.25);
}

/* Nav toggle — 3 shapes (mobile) */
.nav-toggle {
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 7px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    z-index: 1010;
}
.nav-toggle .dot-circle {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.5px solid var(--text-secondary);
    transition: border-color 0.3s ease;
}
.nav-toggle .dot-triangle {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 8px solid var(--text-secondary);
    transition: border-bottom-color 0.3s ease, border-top-color 0.3s ease;
}
.nav-toggle .dot-hex { width: 8px; height: 9px; position: relative; }
.nav-toggle .dot-hex svg { display: block; transition: stroke 0.3s ease; }
nav.mobile-open .nav-toggle .dot-circle { border-color: var(--emerald-frontier); }
nav.mobile-open .nav-toggle .dot-triangle {
    border-bottom: none;
    border-top: 8px solid var(--emerald-frontier);
}
nav.mobile-open .nav-toggle .dot-hex svg { stroke: var(--emerald-frontier); }

/* Mobile drawer */
.mobile-drawer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(1, 2, 8, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(16, 185, 129, 0.15);
    z-index: 999;
    padding: 80px 8% 32px;
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
nav.mobile-open ~ .mobile-drawer,
nav.mobile-open + .mobile-drawer { transform: translateY(0); }
.mobile-drawer ul { list-style: none; display: flex; flex-direction: column; gap: 0; }
.mobile-drawer ul li { border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.mobile-drawer ul li:first-child { border-top: 1px solid rgba(255, 255, 255, 0.04); }
.mobile-drawer ul a {
    display: block;
    padding: 20px 0;
    font-family: 'Syne', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-decoration: none;
    letter-spacing: -0.5px;
    transition: color 0.3s ease;
}
.mobile-drawer ul a:hover,
.mobile-drawer ul a.active { color: var(--emerald-frontier); }
.mobile-drawer .drawer-cta { margin-top: 28px; }

/* ============================================================
   LAYOUT BASE — secciones
   ============================================================ */
.section {
    padding: 96px 10%;
    position: relative;
    scroll-margin-top: var(--nav-h);
}
.section--tight { padding-top: 52px; padding-bottom: 52px; }

/* Contenedor de texto dentro de las secciones — limita la anchura legible */
.section > p,
.section > .subtitle,
.section > .explorer-lead {
    max-width: 72ch;
}
.section + .section { border-top: 1px solid rgba(255, 255, 255, 0.05); }
#capas { scroll-margin-top: var(--nav-h); }

.accent {
    color: var(--amber-anomaly);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    display: block;
    margin-bottom: 12px;
    opacity: 0.75;
}

h1, h2, h3 {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.01em;
}
h1 { font-size: clamp(2rem, 4vw, 3.4rem); letter-spacing: -0.025em; }
h2 { font-size: clamp(1.5rem, 2.4vw, 2.1rem); margin-bottom: 20px; letter-spacing: -0.02em; }
h3 { font-size: 1.2rem; margin-bottom: 12px; }

p { color: var(--text-secondary); max-width: 72ch; }
p + p { margin-top: 20px; }

/* ============================================================
   HERO REVEAL — animación CSS para elementos above-the-fold (#contexto)
   Igual al blurReveal de la landing, sin depender de JS.
   ============================================================ */
@keyframes blurReveal {
    0%   { opacity: 0; filter: blur(12px); transform: translateY(20px); }
    100% { opacity: 1; filter: blur(0);    transform: translateY(0); }
}
.hero-reveal {
    opacity: 0;
    animation: blurReveal 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ============================================================
   SCROLL REVEAL — mismo que landing
   ============================================================ */
.scroll-reveal {
    opacity: 0;
    transform: translateY(40px);
    filter: blur(10px);
    transition:
        opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.8s cubic-bezier(0.16, 1, 0.3, 1),
        filter 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}
.scroll-reveal.visible {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
}

/* ============================================================
   CONTEXTO — strip de entrada
   ============================================================ */
#contexto {
    padding-top: 148px;
    padding-bottom: 56px;
}
#contexto .subtitle {
    color: var(--text-secondary);
    font-size: 1.05rem;
    line-height: 1.65;
    max-width: 640px;
    margin-top: 22px;
}
.stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 56px;
}
.stat-card {
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 22px 24px;
    /* Glassmorphism — manifest: blur 6px, superficie 0.03 */
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.4s ease, border-color 0.4s ease;
}
.stat-card:hover {
    transform: translateY(-6px) scale(1.02);
    border-color: rgba(16, 185, 129, 0.35);
    background: radial-gradient(ellipse at 50% 0%, rgba(16, 185, 129, 0.07) 0%, transparent 70%), var(--glass-surface);
    box-shadow: inset 0 1px 0 rgba(16, 185, 129, 0.15), 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(16, 185, 129, 0.08);
}
.stat-card .num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 2.1rem;
    color: var(--amber-anomaly);
    line-height: 1;
    letter-spacing: -0.02em;
}
.stat-card .label {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 14px;
    letter-spacing: 0;
    line-height: 1.5;
}
.stat-card .sublabel {
    display: block;
    margin-top: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    opacity: 0.8;
}

/* ============================================================
   CAPAS — scroll-stack Apple-style
   ============================================================ */
#capas {
    padding: 0;
    height: 480vh;  /* 6 capas × ~80vh de scroll cada una — más compacto */
    position: relative;
}
.layers-stage {
    position: sticky;
    top: var(--nav-h);
    width: 100%;
    /* dvh: excluye la chrome de Safari en iOS; fallback vh para browsers viejos */
    height: calc(100vh - var(--nav-h));
    height: calc(100dvh - var(--nav-h));
    display: grid;
    grid-template-columns: 60% 40%;
    align-items: center;
    overflow: hidden;
    background: var(--bg-abyss);
}
.layers-canvas {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4% 0 4% 8%;
}
.layer-base, .layer-img {
    position: absolute;
    inset: 4% 0 4% 8%;
    width: calc(100% - 8%);
    height: calc(100% - 8%);
    object-fit: contain;
    object-position: center;
    pointer-events: none;
    will-change: opacity, transform;
}
.layer-base {
    opacity: 0.5;
    z-index: 1;
}
.layer-img {
    opacity: 0;
    transform: translateY(8px) scale(1.02);
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 2;
    mix-blend-mode: screen;
}
.layer-img.active {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.layer-img.dim {
    opacity: 0.3;
    transform: translateY(0) scale(1);
}

/* VIIRS WebGL canvas — mismo inset que el <img>, anima las ciudades (z:3) */
.viirs-gl-canvas {
    position: absolute;
    inset: 4% 0 4% 8%;
    width: calc(100% - 8%);
    height: calc(100% - 8%);
    pointer-events: none;
    mix-blend-mode: screen;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
/* El canvas sigue el estado del <img>: active=1, dim=0.3, sin clase=0 */
.layer-img--viirs.active ~ .viirs-gl-canvas {
    opacity: 1;
}
.layer-img--viirs.dim ~ .viirs-gl-canvas {
    opacity: 0.3;
}


.layer-captions {
    position: relative;
    padding: 0 8% 0 4%;
}
.layer-caption {
    position: absolute;
    top: 50%;
    left: 4%;
    right: 8%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 28px 32px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.layer-caption.active { opacity: 1; }
.layer-caption .tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--amber-anomaly);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 18px;
}
.layer-caption h3 {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: clamp(1.6rem, 2.4vw, 2rem);
    color: var(--text-primary);
    margin-bottom: 16px;
    line-height: 1.15;
}
.layer-caption p {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.55;
    max-width: 32ch;
}
.layer-caption .meta {
    margin-top: 22px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    opacity: 0.7;
}
.layer-footer {
    position: absolute;
    bottom: 2vh;
    left: 8%;
    right: 40%;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    opacity: 0.5;
}

/* ============================================================
   MAPA
   ============================================================ */
.map-wrap {
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    overflow: hidden;
    background: var(--sapphire-depth);
    position: relative;
}
#map {
    height: 72vh;
    min-height: 520px;
    width: 100%;
    background: var(--bg-abyss);
    touch-action: manipulation; /* iOS: evita doble-tap zoom, preserva pinch-to-zoom del mapa */
}
.map-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.mode-toggle {
    display: inline-flex;
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 4px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.mode-toggle button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 8px 18px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.25s;
}
.mode-toggle button:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}
.mode-toggle button.active {
    background: var(--emerald-frontier);
    color: var(--bg-abyss);
    font-weight: 700;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.3);
}
.map-legend {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(1, 2, 8, 0.78);
    border: 1px solid var(--glass-border);
    /* blur canónico 6px; 10px previo era inconsistente con manifest */
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 12px;
    padding: 14px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    z-index: 500;
    max-width: 280px;
}
.map-legend .legend-title {
    color: var(--amber-anomaly);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-size: 0.65rem;
    margin-bottom: 10px;
}
.map-legend .legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.map-legend .swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}
/* Controles zoom Leaflet — tema oscuro */
.leaflet-control-container { z-index: 500 !important; }
#map { isolation: isolate; }
.leaflet-control-zoom {
    border: 1px solid var(--glass-border) !important;
    border-radius: 10px !important;
    overflow: hidden;
}
.leaflet-control-zoom-in,
.leaflet-control-zoom-out,
.leaflet-control-zoom-center {
    background: rgba(1, 2, 8, 0.82) !important;
    color: var(--text-secondary) !important;
    border: none !important;
    border-bottom: 1px solid var(--glass-border) !important;
    font-size: 16px !important;
    line-height: 30px !important;
    width: 30px !important;
    height: 30px !important;
    font-family: 'JetBrains Mono', monospace !important;
    transition: color 0.2s, background 0.2s !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
}
.leaflet-control-zoom-center {
    font-size: 13px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
.leaflet-control-zoom-in:hover,
.leaflet-control-zoom-out:hover,
.leaflet-control-zoom-center:hover {
    background: rgba(16, 185, 129, 0.12) !important;
    color: var(--emerald-frontier) !important;
}
.leaflet-control-zoom-out {
    border-bottom: none !important;
}

.leaflet-tooltip.pbg-tip {
    background: rgba(1, 2, 8, 0.92) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: 10px !important;
    padding: 10px 14px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.82rem !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
}
.leaflet-tooltip.pbg-tip::before { display: none !important; }
.pbg-tip .tip-name {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.pbg-tip .tip-prov { color: var(--text-secondary); font-size: 0.75rem; margin-bottom: 8px; }
.pbg-tip .tip-band {
    font-family: 'JetBrains Mono', monospace;
    color: var(--amber-anomaly);
    font-size: 0.78rem;
    margin-bottom: 4px;
}
.pbg-tip .tip-rank {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* ============================================================
   EXPLORADOR — layout histograma + buscador
   ============================================================ */
.explorer-lead {
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: 600px;
    margin-bottom: 36px;
}
.explorer-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 40px;
    align-items: start;
}

/* Histograma */
.histogram-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.hist-mode-toggle {
    display: inline-flex;
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 4px;
    margin-bottom: 24px;
    align-self: flex-start;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.hist-mode-toggle button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 7px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.25s;
}
.hist-mode-toggle button:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}
.hist-mode-toggle button.active {
    background: var(--emerald-frontier);
    color: var(--bg-abyss);
    font-weight: 700;
}

.histogram {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.hist-bar-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 14px;
    align-items: center;
    padding: 6px 0;
    border-radius: 6px;
    transition: background 0.2s;
}
.hist-bar-row--active {
    background: rgba(255, 255, 255, 0.03);
    outline: 1px solid rgba(16, 185, 129, 0.25);
    outline-offset: 4px;
}
.hist-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-align: right;
    white-space: nowrap;
}
.hist-bar-row--active .hist-label { color: var(--text-primary); }
.hist-track {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 28px;
}
.hist-fill {
    height: 100%;
    border-radius: 4px;
    min-width: 4px;
    transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1), background 0.3s;
}
.hist-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.hist-bar-row--active .hist-count { color: var(--emerald-frontier); font-weight: 700; }
.hist-note {
    margin-top: 18px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0.6;
}

/* Buscador */
.search-panel {
    position: sticky;
    top: calc(var(--nav-h) + 20px);
}
.controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 18px;
}
.controls input, .controls select {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 1rem; /* ≥16px: previene autozoom en iOS Safari */
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    appearance: none;
    -webkit-appearance: none;
}
.controls input:focus, .controls select:focus {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.03);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.06);
}
.controls input::placeholder { color: rgba(148, 163, 184, 0.35); font-size: 0.78rem; }
.controls select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8' fill-opacity='0.4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}
.controls select option { background: #0d1117; color: var(--text-primary); }

.search-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 68vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.search-hint, .search-more {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    padding: 16px 0;
    text-align: center;
}

/* Carta de departamento */
.dep-card {
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-left: 2px solid var(--amber-anomaly);
    border-radius: 12px;
    padding: 18px 20px;
    cursor: pointer;
    transition: border-color 0.25s, transform 0.2s, background 0.25s;
}
.dep-card:hover {
    border-color: rgba(255, 159, 0, 0.45);
    transform: translateX(4px);
    background: radial-gradient(ellipse at 0% 50%, rgba(255, 159, 0, 0.05) 0%, transparent 65%), var(--glass-surface);
}
.dep-card--active {
    border-left-color: var(--emerald-frontier);
    background: radial-gradient(ellipse at 0% 50%, rgba(16, 185, 129, 0.06) 0%, transparent 65%), var(--glass-surface);
    border-color: rgba(16, 185, 129, 0.3);
}
.dep-card h4 {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 3px;
    line-height: 1.2;
}
.dep-card .dep-prov {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 12px;
}
.dep-card .dep-stat {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 6px;
}
.dep-card .dep-stat .k {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.dep-card .dep-stat .v {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
    color: var(--text-primary);
    font-weight: 700;
}
.dep-card .dep-badge {
    display: inline-block;
    margin-top: 12px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 159, 0, 0.1);
    border: 1px solid rgba(255, 159, 0, 0.25);
    color: var(--amber-anomaly);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.dep-card--active .dep-badge {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--emerald-frontier);
}

/* ============================================================
   RANKINGS
   ============================================================ */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--glass-border);
}
.tabs button {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    padding: 14px 22px;
    cursor: pointer;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    transition: all 0.25s;
    margin-bottom: -1px;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.active {
    color: var(--emerald-frontier);
    border-bottom-color: var(--emerald-frontier);
}

.rank-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}
.rank-table th {
    text-align: left;
    padding: 14px 16px;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--glass-border);
}
.rank-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
}
.rank-table td:first-child {
    color: var(--amber-anomaly);
    font-weight: 700;
    width: 50px;
}
.rank-table td:nth-child(2) {
    color: var(--text-primary);
    font-family: 'Syne', sans-serif;
    font-weight: 700;
}
.rank-table tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
.rank-table .num { text-align: right; }

/* ============================================================
   METODOLOGÍA / VALIDACIÓN
   ============================================================ */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 56px;
    margin-top: 40px;
}
.two-col > div > p { max-width: 60ch; }
.card-block {
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 32px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.card-block.good { border-left: 2px solid var(--emerald-frontier); }
.card-block.bad { border-left: 2px solid var(--amber-anomaly); }
.card-block h3 {
    font-family: 'Syne', sans-serif;
    margin-bottom: 18px;
    color: var(--text-primary);
}
.card-block ul { list-style: none; }
.card-block li {
    padding: 10px 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.card-block li:last-child { border-bottom: none; }
.card-block li::before {
    content: '';
    flex-shrink: 0;
    width: 5px;
    height: 5px;
    margin-top: 9px;
    border-radius: 50%;
    background: var(--amber-anomaly);
    box-shadow: 0 0 6px var(--amber-anomaly);
}
.card-block.good li::before { background: var(--emerald-frontier); box-shadow: 0 0 6px var(--emerald-frontier); }

.coef-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 24px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
}
.coef-table th, .coef-table td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.coef-table th {
    color: var(--text-muted);
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.coef-table .pos { color: var(--emerald-frontier); }
.coef-table .neg { color: var(--amber-anomaly); }
.coef-table .neutral { color: var(--text-muted); }
.coef-table caption {
    text-align: left;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding-bottom: 12px;
}
.coef-foot {
    margin-top: 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}
.caption-note {
    margin-top: 24px;
    padding-left: 16px;
    border-left: 2px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem;
    line-height: 1.65;
    color: var(--text-muted);
    max-width: 58ch;
}

/* ============================================================
   DATOS — email gate
   ============================================================ */
#datos .gate {
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 52px 56px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    max-width: 680px;
}
.gate h2 { margin-bottom: 16px; }
.gate p { margin-bottom: 24px; }
.gate form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 24px;
}
.gate input, .gate select, .gate textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 1rem; /* ≥16px: previene autozoom en iOS Safari */
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    appearance: none;
    -webkit-appearance: none;
}
.gate input::placeholder, .gate textarea::placeholder {
    color: rgba(148, 163, 184, 0.35);
    font-size: 0.78rem;
}
.gate select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8' fill-opacity='0.4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}
.gate select option { background: #0d1117; color: var(--text-primary); }
.gate textarea { min-height: 90px; resize: vertical; line-height: 1.55; }
.gate input:focus, .gate select:focus, .gate textarea:focus {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.03);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.06);
}
.gate-submit {
    width: 100%;
    padding: 12px 24px;
    background: var(--emerald-frontier);
    border: none;
    border-radius: 8px;
    color: var(--bg-abyss);
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
    margin-top: 8px;
}
.gate-submit:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.2);
}
.gate-submit:active { transform: translateY(0); }
.gate-submit:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.gate-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.gate input.invalid, .gate select.invalid, .gate textarea.invalid {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.04);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.06);
}
.gate-status {
    margin-top: 18px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.5px;
    min-height: 1.4em;
}
.gate-status.error { color: var(--ruby-collapse); }
.gate-status.success { color: var(--emerald-frontier); }
.gate-success {
    padding: 40px 0 8px;
    text-align: center;
}
.gate-success-icon {
    font-size: 2rem;
    color: var(--emerald-frontier);
    margin-bottom: 16px;
    line-height: 1;
}
.gate-success h3 {
    font-family: 'Syne', sans-serif;
    font-size: 1.3rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}
.gate-success p {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 36ch;
    margin: 0 auto;
    line-height: 1.6;
}
.gate-license {
    margin-top: 18px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

/* ============================================================
   FOOTER
   ============================================================ */
footer {
    padding: 56px 10%;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: var(--bg-abyss);
    color: var(--text-muted);
    font-size: 0.85rem;
}
footer .foot-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 32px;
    flex-wrap: wrap;
}
footer .cite {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.6;
    max-width: 560px;
}
footer .foot-links {
    display: flex;
    gap: 24px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    flex-shrink: 0;
}
footer .foot-links a { color: var(--text-secondary); transition: color 0.3s; }
footer .foot-links a:hover { color: var(--emerald-frontier); }
footer .foot-license {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 20px;
    opacity: 0.55;
}

/* Rankings: columna de banda condensada solo visible en mobile */
.rank-secondary { display: none; }
.rank-prov-inline { display: none; color: var(--text-muted); font-size: 0.78em; }

/* ============================================================
   RESPONSIVE — largest breakpoint first (desktop-first cascade)
   ============================================================ */
@media (max-width: 900px) {
    .section { padding: 64px 6%; }
    .section--tight { padding-top: 40px; padding-bottom: 40px; }
    .stat-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .two-col { grid-template-columns: 1fr; gap: 28px; }
    .two-col > div > p { max-width: 100%; }
    .explorer-layout { grid-template-columns: 1fr; }
    .search-panel { position: static; }
    .hist-bar-row { grid-template-columns: 140px 1fr; }
    #datos .gate { padding: 32px; }
    .gate-row { grid-template-columns: 1fr; }
    footer { padding: 40px 6%; }

    /* Scroll-stack mobile */
    #capas { height: 360vh; }
    /* Mobile: imagen y card se superponen en el mismo espacio.
       layers-canvas ocupa el fondo completo; layer-captions encima con z-index.
       backdrop-filter de la glass card actúa sobre la imagen satelital. */
    .layers-stage {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
    }
    .layers-canvas {
        grid-row: 1;
        grid-column: 1;
        padding: 4%;
    }
    .layer-base, .layer-img { inset: 4%; width: calc(100% - 8%); height: calc(100% - 8%); }
    .layer-base { opacity: 0.9; filter: drop-shadow(0 0 1.5px rgba(255,255,255,0.8)); }
    .viirs-gl-canvas { inset: 4%; width: calc(100% - 8%); height: calc(100% - 8%); }
    .layer-captions {
        grid-row: 1;
        grid-column: 1;
        padding: 0;
        z-index: 5;
        pointer-events: none;
        align-self: stretch;
    }
    .layer-caption {
        top: unset;
        bottom: 22%;
        left: 5%;
        right: 5%;
        transform: none;
        padding: 20px 24px;
        z-index: 6;
    }
    .layer-caption h3 { font-size: 1.4rem; margin-bottom: 10px; }
    .layer-caption p { font-size: 0.9rem; }
    .layer-footer { display: none; }

    #map { height: 60vh; min-height: 420px; }
}

@media (max-width: 768px) {
    .nav-links { display: none; }
    nav > .nav-btn { display: none; }
    .nav-toggle { display: flex; }
    .mobile-drawer { display: block; }
    .breadcrumb { display: none; }

    /* Rankings: tabla colapsada a 2 columnas funcionales */
    .rank-hide-mobile { display: none; }
    .rank-secondary { display: table-cell; }
    .rank-prov-inline { display: inline; }

    .rank-table { font-size: 0.78rem; }
    .rank-table th, .rank-table td { padding: 11px 10px; }
    .rank-table td:first-child { width: 32px; }

    /* Tabs: texto más pequeño y padding reducido */
    .tabs button { padding: 12px 14px; font-size: 0.65rem; letter-spacing: 1px; }

    /* Sección rankings: menos padding lateral */
    #rankings.section--tight { padding-left: 4%; padding-right: 4%; }

    /* Gate: padding reducido en pantallas pequeñas */
    #datos .gate { padding: 24px 20px; }
}

@media (max-width: 480px) {
    .section { padding: 56px 5%; }
    .section--tight { padding-top: 32px; padding-bottom: 32px; }
    #rankings.section--tight { padding-left: 3%; padding-right: 3%; }

    h1 { font-size: clamp(1.7rem, 8vw, 2.4rem); }
    h2 { font-size: clamp(1.3rem, 6vw, 1.8rem); }

    .stat-row { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 16px 14px; }
    .stat-card .num { font-size: 1.7rem; }
    .stat-card .label { font-size: 0.72rem; }

    .tabs { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .tabs::-webkit-scrollbar { display: none; }
    .tabs button { white-space: nowrap; padding: 10px 12px; font-size: 0.6rem; }

    .rank-table th, .rank-table td { padding: 10px 8px; }

    footer { padding: 32px 5%; }
    footer .foot-row { flex-direction: column; gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .layer-img {
        transition: opacity 0.2s linear;
        transform: none !important;
    }
    .layer-caption { transition: opacity 0.2s linear; }
}
