/* Rediseño minimalista: portada con la Luna enorme, vista general con solo los puntos y un panel
 * de configuración. Se carga después de styles.css y reemplaza su disposición: los paneles fijos de la
 * versión anterior (#left, #controls, #sidebar) ya no existen.
 *
 * Idea de diseño: un tomador de decisiones no necesita ver todo a la vez. Lo único siempre visible es la
 * fecha; la ficha de un sitio aparece al elegirlo, y "Comparar" solo cuando hay 2 o más elegidos.
 */

[hidden] {
  display: none !important;
}

/* ---------- Globo de fondo ---------- */

#globe {
  inset: 0;
  height: 100%;
}

.page--hero,
.page--explore {
  position: fixed;
  inset: 0;
  pointer-events: none; /* el globo de atrás recibe el mouse; los hijos lo reactivan */
}

.page--hero > *,
.page--explore > * {
  pointer-events: auto;
}

.page--compare {
  z-index: 5;
  background: var(--bg);
}

.glass {
  background: color-mix(in srgb, var(--bg) 66%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.icon-btn {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
}

/* ---------- Barra superior: transparente, como en la referencia ---------- */

#topnav {
  background: transparent;
  backdrop-filter: none;
  border-bottom: 0;
}

body[data-section="comparar"] #topnav {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 0.78rem;
  font-stretch: 100%;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.nav-links a {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.nav-num {
  display: none;
}

.nav-gear {
  display: none;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  border-color: var(--line-strong);
  font-size: 1.15rem;
}

body[data-section="explorar"] .nav-gear {
  display: grid;
}

.nav-gear[aria-expanded="true"] {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-color: var(--accent);
}

/* ---------- Portada ---------- */

.hero-copy {
  position: absolute;
  left: clamp(28px, 9vw, 150px);
  top: 50%;
  display: grid;
  gap: 44px;
  max-width: min(560px, 46vw);
  transform: translateY(-62%);
}

.hero-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.7vw, 3.7rem);
  font-weight: 600;
  font-stretch: 125%;
  letter-spacing: 0.07em;
  line-height: 1.14;
  text-transform: uppercase;
  text-wrap: balance;
}

.hero-title:focus {
  outline: none;
}

/* Botón con marcos de esquina, como el de la referencia. */
.cta {
  --tick: var(--accent);
  position: relative;
  display: inline-flex;
  width: max-content;
  padding: 22px 36px;
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-decoration: none;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  transition: background 0.2s;
}

.cta::before {
  content: "";
  position: absolute;
  inset: -1px;
  pointer-events: none;
  background:
    linear-gradient(var(--tick), var(--tick)) left top / 11px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) left top / 2px 11px no-repeat,
    linear-gradient(var(--tick), var(--tick)) right top / 11px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) right top / 2px 11px no-repeat,
    linear-gradient(var(--tick), var(--tick)) left bottom / 11px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) left bottom / 2px 11px no-repeat,
    linear-gradient(var(--tick), var(--tick)) right bottom / 11px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) right bottom / 2px 11px no-repeat;
}

.cta:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.cta:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* Regla vertical del borde izquierdo y coordenadas del borde derecho. */
.hero-ruler {
  position: absolute;
  left: 0;
  top: 24%;
  width: 16px;
  height: 52%;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.32) 0 1px, transparent 1px 11px);
}

.hero-ruler::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 2px;
  background: var(--accent);
}

.hero-coords {
  position: absolute;
  right: 18px;
  top: 22%;
  margin: 0;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  white-space: nowrap;
  writing-mode: vertical-rl;
  pointer-events: none;
}

.hero-facts {
  position: absolute;
  left: clamp(28px, 9vw, 150px);
  bottom: 56px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
  width: min(720px, 44vw); /* termina antes de la Luna, para que el texto no pierda contraste */
  margin: 0;
  padding: 0;
  list-style: none;
}

.hero-facts li {
  display: grid;
  gap: 6px;
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.fact-label {
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.hero-sources {
  position: absolute;
  left: clamp(28px, 9vw, 150px);
  bottom: 18px;
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.75rem;
}

.hero-sources a {
  color: var(--ink-muted);
}

/* Entrada en orden de lectura; al apretar "Comenzar" el texto se va mientras la cámara se aleja. */
.page--hero > * {
  animation: hero-in 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.page--hero .hero-copy { animation-delay: 0.15s; }
.page--hero .hero-facts { animation-delay: 0.5s; }
.page--hero .hero-sources { animation-delay: 0.6s; }

@keyframes hero-in {
  from {
    opacity: 0;
    translate: 0 16px;
  }
}

body.hero-leaving .page--hero > * {
  opacity: 0;
  translate: 0 -10px;
  pointer-events: none;
  animation: none;
  transition: opacity 0.6s ease, translate 0.6s ease;
}

/* ---------- Vista general ---------- */

.page--explore {
  animation: hud-in 0.9s ease both;
}

@keyframes hud-in {
  from {
    opacity: 0;
  }
}

/* Fecha: lo único siempre visible. */
#datebar {
  position: fixed;
  top: calc(var(--nav-h) + 8px);
  left: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px 4px 6px;
}

#datebar .step {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-muted);
  font-size: 1.3rem;
  line-height: 1;
}

#datebar .step:hover {
  color: var(--ink);
  background: none;
}

#datebar input {
  width: auto;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 600 0.82rem var(--font-mono);
}

#datebar #status {
  margin: 0 0 0 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Panel del engranaje. */
.drawer {
  position: fixed;
  top: calc(var(--nav-h) + 8px);
  right: 16px;
  bottom: 16px;
  width: min(380px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: drawer-in 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes drawer-in {
  from {
    opacity: 0;
    translate: 24px 0;
  }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
  font-size: 0.78rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.drawer-body {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 14px 14px 24px;
  overflow-y: auto;
}

.drawer .group {
  display: grid;
  gap: 8px;
}

.drawer .group h3 {
  margin: 0;
}

.drawer .buttons {
  margin: 0;
}

.drawer .custom {
  padding: 10px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.drawer .relief {
  margin-top: 4px;
  padding-top: 8px;
}

.drawer .list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 0;
}

.drawer .list-hint {
  margin: 4px 0 8px;
}

.drawer #site-list {
  max-height: 40vh;
  padding: 0;
  overflow-y: auto;
}

/* Detalle completo: a la izquierda, se abre desde la ficha. */
#detail {
  position: fixed;
  top: calc(var(--nav-h) + 64px);
  left: 16px;
  bottom: 16px;
  width: min(400px, calc(100vw - 32px));
  animation: drawer-in 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-name: detail-in;
}

@keyframes detail-in {
  from {
    opacity: 0;
    translate: -24px 0;
  }
}

/* Abajo: ficha del sitio elegido y barra de comparación. */
.hud-bottom {
  position: fixed;
  left: 16px;
  right: 72px;
  bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.hud-bottom > * {
  pointer-events: auto;
}

body.detail-open #sitecard {
  display: none;
}

#sitecard {
  flex: 0 1 350px;
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  animation: rise-card 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes rise-card {
  from {
    opacity: 0;
    translate: 0 12px;
  }
}

#sitecard[aria-busy="true"] {
  opacity: 0.6;
}

#sitecard header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#sitecard h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
}

#sitecard p {
  margin: 0;
}

#sitecard .verdict {
  font-size: 0.88rem;
}

#sitecard .counters {
  margin: 0;
}

#sitecard .mini {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  color: var(--ink-muted);
  font-size: 0.7rem;
}

#sitecard .mini b {
  color: var(--ink);
  font-size: 1.05rem;
}

#sitecard .hint {
  color: var(--ink-muted);
  font-size: 0.76rem;
}

#sitecard .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 0;
}

#selbar {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 12px;
  animation: rise-card 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.chips {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chips li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 0.76rem;
}

.chips button {
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink-muted);
  font-size: 0.7rem;
}

#sel-compare {
  flex: none;
  padding: 10px 20px;
  font-size: 0.82rem;
}

#sel-clear {
  flex: none;
}

/* Leyenda: se abre con el "?". */
.fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  flex: none;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-weight: 700;
  background: color-mix(in srgb, var(--bg) 66%, transparent);
  backdrop-filter: blur(10px);
}

.legend {
  position: fixed;
  right: 16px;
  bottom: 64px;
  z-index: 4;
  width: min(350px, calc(100vw - 32px));
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

body.drawer-open .fab {
  right: calc(min(380px, 100vw - 32px) + 32px);
}

body.drawer-open .legend {
  right: calc(min(380px, 100vw - 32px) + 32px);
}

body.drawer-open .hud-bottom {
  right: calc(min(380px, 100vw - 32px) + 88px);
}

/* Vistas adicionales (topografía): a pantalla completa sobre el globo. */
.stage {
  position: fixed;
  inset: var(--nav-h) 0 0 0;
  z-index: 6;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
}

.stage-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}

.stage-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.stage-body {
  position: relative;
  min-height: 0;
  overflow: auto;
}

/* ---------- Teléfono ---------- */

@media (max-width: 480px) {
  #topnav {
    gap: 4px;
    padding: 0 8px;
  }

  .nav-links {
    margin: 0 auto 0 0;
  }

  .nav-links a {
    padding: 8px 5px;
    font-size: 0.6rem;
    letter-spacing: 0.1em;
  }

  .nav-gear {
    width: 30px;
    height: 30px;
  }
}

@media (max-width: 760px) {
  #datebar {
    left: 8px;
    right: 8px;
    top: calc(var(--nav-h) + 4px);
  }

  #datebar input {
    flex: 1;
    min-width: 0;
  }

  .drawer {
    top: calc(var(--nav-h) + 4px);
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
  }

  #detail {
    top: calc(var(--nav-h) + 56px);
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
  }

  body.drawer-open #detail,
  body.drawer-open .hud-bottom,
  body.drawer-open .fab {
    display: none;
  }

  .hud-bottom {
    left: 8px;
    right: 8px;
    bottom: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  #sitecard {
    flex: none;
  }

  #selbar {
    order: -1;
    max-width: none;
    margin: 0;
    flex-wrap: wrap;
  }

  .chips {
    flex-basis: 100%;
  }

  .fab {
    top: calc(var(--nav-h) + 56px);
    right: 8px;
    bottom: auto;
  }

  .legend {
    top: calc(var(--nav-h) + 100px);
    right: 8px;
    bottom: auto;
  }

  .hero-copy {
    left: 24px;
    top: calc(var(--nav-h) + 8vh);
    max-width: calc(100vw - 48px);
    gap: 28px;
    transform: none;
  }

  .hero-title {
    font-size: clamp(1.6rem, 8vw, 2.4rem);
  }

  .hero-facts,
  .hero-sources,
  .hero-ruler,
  .hero-coords {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page--hero > *,
  .page--explore,
  .drawer,
  #detail,
  #sitecard,
  #selbar {
    animation: none;
  }

  body.hero-leaving .page--hero > * {
    transition: none;
  }
}

/* ---------- Fase 3: fecha protagonista, leyenda mínima, bloques plegables ---------- */

#datebar {
  padding: 8px 16px 8px 10px;
  gap: 6px;
}

#datebar input {
  font-size: 1.05rem;
}

#datebar .step {
  width: 34px;
  height: 34px;
  font-size: 1.6rem;
}

#datebar #status {
  font-size: 0.82rem;
  color: var(--ink);
}

#legend-mini {
  position: fixed;
  top: calc(var(--nav-h) + 68px);
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  max-width: min(520px, calc(100vw - 96px));
  margin: 0;
  padding: 6px 12px;
  list-style: none;
  font-size: 0.74rem;
  color: var(--ink-muted);
}

#legend-mini li { display: inline-flex; align-items: center; gap: 4px; }
body.drawer-open #legend-mini { display: none; }

.layer-legend { display: grid; gap: 4px; }
.layer-legend p { margin: 0; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.layer-legend .swatch, #legend-mini .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

.fold { margin: var(--space-3, 12px) 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.fold > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.fold-body { margin-top: 8px; }

/* Foco visible en todo lo interactivo (accesibilidad por teclado). */
a:focus-visible, button:focus-visible, summary:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
body.detail-open #legend-mini { display: none; }
